Skip to contentSkip to conversation

media: v4l: Fix dereference before NULL check

PATCH In review Chandra Mohan Sundar 2 participants 4 messages Aug 18, 2025 – Aug 22, 2025 1 message not in the archive

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 media: v4l: Fix dereference before NULL check

In 'stm32_csi_start', 'csidev->s_subdev' is dereferenced directly while assigning a value to the 'src_pad'. However the same value is being checked against NULL at a later point of time indicating that there are chances that the value can be NULL.

Move the dereference after the NULL check.

Fixes e7bad98c205d1 ("media: v4l: Convert the users of v4l2_get_link_freq to call it on a pad")
---
 drivers/media/platform/st/stm32/stm32-csi.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/media/platform/st/stm32/stm32-csi.c +2 -2
index b69048144cc1..fd2b6dfbd44c 100644
@@ -443,8 +443,7 @@ static void stm32_csi_phy_reg_write(struct stm32_csi_dev *csidev,
 static int stm32_csi_start(struct stm32_csi_dev *csidev,
 			   struct v4l2_subdev_state *state)
 {
-	struct media_pad *src_pad =
-		&csidev->s_subdev->entity.pads[csidev->s_subdev_pad_nb];
+	struct media_pad *src_pad;
 	const struct stm32_csi_mbps_phy_reg *phy_regs = NULL;
 	struct v4l2_mbus_framefmt *sink_fmt;
 	const struct stm32_csi_fmts *fmt;
@@ -466,6 +465,7 @@ static int stm32_csi_start(struct stm32_csi_dev *csidev,
 	if (!csidev->s_subdev)
 		return -EIO;
 
+	src_pad = &csidev->s_subdev->entity.pads[csidev->s_subdev_pad_nb];
 	link_freq = v4l2_get_link_freq(src_pad,
 				       fmt->bpp, 2 * csidev->num_lanes);
 	if (link_freq < 0)
Signature · 1 line
2.43.0

A message that is not in the archive (sent off-list or not yet received): [email protected]

#2 lore raw

Hi Team,

Regarding my below patch :
https://patchwork.linuxtv.org/project/linux-media/patch/[email protected]/

Quoted 8 lines

For more details, check the full report at:
https://linux-media.pages.freedesktop.org/-/users/patchwork/-/jobs/82645328/artifacts/report.htm .

Best regards, and Happy Hacking!
Media CI robot on behalf of the linux-media community.

Quoted 8 lines

---
Check the latest rules for contributing your patches at:
https://docs.kernel.org/driver-api/media/maintainer-entry-profile.html

If you believe that the CI is wrong, kindly open an issue at
https://gitlab.freedesktop.org/linux-media/media-ci/-/issues or reply-all to this message.

I went through the logs but I could not find any issues related to my change. I see that some of the artifact upload failed in the CI tests. Could you please help me on what I need to do from my side for the patch to proceed ?

Thanks,
Chandra Mohan Sundar

#3 lore raw
In reply to Chandra Mohan Sundar

Hi Chandra,

Please choose an appropriate subject on the next time, this is missing what the patch is for -- see git log if in doubt.

Quoted 8 lines · Chandra Mohan Sundar

In 'stm32_csi_start', 'csidev->s_subdev' is dereferenced directly while assigning a value to the 'src_pad'. However the same value is being checked against NULL at a later point of time indicating that there are chances that the value can be NULL.

Move the dereference after the NULL check.

Fixes e7bad98c205d1 ("media: v4l: Convert the users of v4l2_get_link_freq to call it on a pad")

Fixes: requires Cc: stable. I've fixed these this time. See Documentation/process/submitting-patches.rst .

Quoted 27 lines
---
 drivers/media/platform/st/stm32/stm32-csi.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/media/platform/st/stm32/stm32-csi.c +2 -2
index b69048144cc1..fd2b6dfbd44c 100644
@@ -443,8 +443,7 @@ static void stm32_csi_phy_reg_write(struct stm32_csi_dev *csidev,
 static int stm32_csi_start(struct stm32_csi_dev *csidev,
 			   struct v4l2_subdev_state *state)
 {
-	struct media_pad *src_pad =
-		&csidev->s_subdev->entity.pads[csidev->s_subdev_pad_nb];
+	struct media_pad *src_pad;
 	const struct stm32_csi_mbps_phy_reg *phy_regs = NULL;
 	struct v4l2_mbus_framefmt *sink_fmt;
 	const struct stm32_csi_fmts *fmt;
@@ -466,6 +465,7 @@ static int stm32_csi_start(struct stm32_csi_dev *csidev,
 	if (!csidev->s_subdev)
 		return -EIO;
 
+	src_pad = &csidev->s_subdev->entity.pads[csidev->s_subdev_pad_nb];
 	link_freq = v4l2_get_link_freq(src_pad,
 				       fmt->bpp, 2 * csidev->num_lanes);
 	if (link_freq < 0)
Signature · 3 lines
Regards,

Sakari Ailus
#4 lore raw

Hi Sakari Ailus,

Thanks a lot for your review and suggestions. Sure, I will choose an appropriate subject.

Thanks,
Chandra Mohan Sundar

Quoted 51 lines · Sakari Ailus

Hi Chandra,

Please choose an appropriate subject on the next time, this is missing what the patch is for -- see git log if in doubt.

Quoted 8 lines · Chandra Mohan Sundar

In 'stm32_csi_start', 'csidev->s_subdev' is dereferenced directly while assigning a value to the 'src_pad'. However the same value is being checked against NULL at a later point of time indicating that there are chances that the value can be NULL.

Move the dereference after the NULL check.

Fixes e7bad98c205d1 ("media: v4l: Convert the users of v4l2_get_link_freq to call it on a pad")

Fixes: requires Cc: stable. I've fixed these this time. See Documentation/process/submitting-patches.rst .

Quoted 20 lines
---
 drivers/media/platform/st/stm32/stm32-csi.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/media/platform/st/stm32/stm32-csi.c +1 -2
index b69048144cc1..fd2b6dfbd44c 100644
@@ -443,8 +443,7 @@ static void stm32_csi_phy_reg_write(struct stm32_csi_dev *csidev,
 static int stm32_csi_start(struct stm32_csi_dev *csidev,
                         struct v4l2_subdev_state *state)
 {
-     struct media_pad *src_pad =
-             &csidev->s_subdev->entity.pads[csidev->s_subdev_pad_nb];
+     struct media_pad *src_pad;
      const struct stm32_csi_mbps_phy_reg *phy_regs = NULL;
      struct v4l2_mbus_framefmt *sink_fmt;
      const struct stm32_csi_fmts *fmt;

drivers/media/platform/st/stm32/stm32-csi.c static int stm32_csi_start(struct stm32_csi_dev *csidev, · line 471

Quoted 7 lines
drivers/media/platform/st/stm32/stm32-csi.c +1 -0
@@ -466,6 +465,7 @@ static int stm32_csi_start(struct stm32_csi_dev *csidev,
      if (!csidev->s_subdev)
              return -EIO;
 
+     src_pad = &csidev->s_subdev->entity.pads[csidev->s_subdev_pad_nb];
      link_freq = v4l2_get_link_freq(src_pad,
                                     fmt->bpp, 2 * csidev->num_lanes);
      if (link_freq < 0)

--
Regards,

Sakari Ailus