Skip to content

Commit

Permalink
media: stm32-dcmi: fix crash when subdev do not expose any formats
Browse files Browse the repository at this point in the history
[ Upstream commit 33dfeb6 ]

Do not access sd_formats[] if num_of_sd_formats is zero, ie
subdev sensor didn't expose any formats.

Signed-off-by: Hugues Fruchet <[email protected]>
Signed-off-by: Hans Verkuil <[email protected]>
Signed-off-by: Mauro Carvalho Chehab <[email protected]>
Signed-off-by: Sasha Levin <[email protected]>
  • Loading branch information
Hugues Fruchet authored and gregkh committed May 31, 2019
1 parent 6c21fa8 commit 2096b3b
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions drivers/media/platform/stm32/stm32-dcmi.c
Original file line number Diff line number Diff line change
Expand Up @@ -808,6 +808,9 @@ static int dcmi_try_fmt(struct stm32_dcmi *dcmi, struct v4l2_format *f,

sd_fmt = find_format_by_fourcc(dcmi, pix->pixelformat);
if (!sd_fmt) {
if (!dcmi->num_of_sd_formats)
return -ENODATA;

sd_fmt = dcmi->sd_formats[dcmi->num_of_sd_formats - 1];
pix->pixelformat = sd_fmt->fourcc;
}
Expand Down Expand Up @@ -986,6 +989,9 @@ static int dcmi_set_sensor_format(struct stm32_dcmi *dcmi,

sd_fmt = find_format_by_fourcc(dcmi, pix->pixelformat);
if (!sd_fmt) {
if (!dcmi->num_of_sd_formats)
return -ENODATA;

sd_fmt = dcmi->sd_formats[dcmi->num_of_sd_formats - 1];
pix->pixelformat = sd_fmt->fourcc;
}
Expand Down

0 comments on commit 2096b3b

Please sign in to comment.