]> git.proxmox.com Git - mirror_ubuntu-disco-kernel.git/commitdiff
media: stm32-dcmi: fix crash when subdev do not expose any formats
authorHugues Fruchet <hugues.fruchet@st.com>
Mon, 1 Apr 2019 08:56:09 +0000 (04:56 -0400)
committerStefan Bader <stefan.bader@canonical.com>
Tue, 13 Aug 2019 12:11:36 +0000 (14:11 +0200)
BugLink: https://bugs.launchpad.net/bugs/1837517
[ Upstream commit 33dfeb62e23c31619d2197850f7e8b50e8cc5466 ]

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>
Signed-off-by: Sasha Levin <sashal@kernel.org>
Signed-off-by: Khalid Elmously <khalid.elmously@canonical.com>
Signed-off-by: Stefan Bader <stefan.bader@canonical.com>
drivers/media/platform/stm32/stm32-dcmi.c

index 918e49f27c7ed8ac83ba99006256ec510cf0e870..a33d497bd5b71f08401badddbf9815dc09392aaf 100644 (file)
@@ -811,6 +811,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;
        }
@@ -989,6 +992,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;
        }