media: stm32-dcmi: fix crash when subdev do not expose any formats

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 <hugues.fruchet@st.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
This commit is contained in:
Hugues Fruchet 2019-04-01 04:56:09 -04:00 committed by Mauro Carvalho Chehab
parent 1be0a2b702
commit 33dfeb62e2
1 changed files with 6 additions and 0 deletions

View File

@ -831,6 +831,9 @@ static int dcmi_try_fmt(struct stm32_dcmi *dcmi, struct v4l2_format *f,
sd_fmt = find_format_by_fourcc(dcmi, pix->pixelformat); sd_fmt = find_format_by_fourcc(dcmi, pix->pixelformat);
if (!sd_fmt) { if (!sd_fmt) {
if (!dcmi->num_of_sd_formats)
return -ENODATA;
sd_fmt = dcmi->sd_formats[dcmi->num_of_sd_formats - 1]; sd_fmt = dcmi->sd_formats[dcmi->num_of_sd_formats - 1];
pix->pixelformat = sd_fmt->fourcc; pix->pixelformat = sd_fmt->fourcc;
} }
@ -1009,6 +1012,9 @@ static int dcmi_set_sensor_format(struct stm32_dcmi *dcmi,
sd_fmt = find_format_by_fourcc(dcmi, pix->pixelformat); sd_fmt = find_format_by_fourcc(dcmi, pix->pixelformat);
if (!sd_fmt) { if (!sd_fmt) {
if (!dcmi->num_of_sd_formats)
return -ENODATA;
sd_fmt = dcmi->sd_formats[dcmi->num_of_sd_formats - 1]; sd_fmt = dcmi->sd_formats[dcmi->num_of_sd_formats - 1];
pix->pixelformat = sd_fmt->fourcc; pix->pixelformat = sd_fmt->fourcc;
} }