linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] media: v4l: Fix dereference before NULL check
@ 2025-08-18  9:31 Chandra Mohan Sundar
  2025-08-21 17:25 ` Sakari Ailus
  0 siblings, 1 reply; 3+ messages in thread
From: Chandra Mohan Sundar @ 2025-08-18  9:31 UTC (permalink / raw)
  To: alain.volmat, mchehab, mcoquelin.stm32, alexandre.torgue,
	linux-media, linux-arm-kernel, shuah
  Cc: Chandra Mohan Sundar, linux-kernel-mentees

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")
Signed-off-by: Chandra Mohan Sundar <chandramohan.explore@gmail.com>
---
 drivers/media/platform/st/stm32/stm32-csi.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/media/platform/st/stm32/stm32-csi.c b/drivers/media/platform/st/stm32/stm32-csi.c
index b69048144cc1..fd2b6dfbd44c 100644
--- a/drivers/media/platform/st/stm32/stm32-csi.c
+++ b/drivers/media/platform/st/stm32/stm32-csi.c
@@ -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)
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] media: v4l: Fix dereference before NULL check
  2025-08-18  9:31 [PATCH] media: v4l: Fix dereference before NULL check Chandra Mohan Sundar
@ 2025-08-21 17:25 ` Sakari Ailus
  2025-08-22  3:11   ` Chandra Mohan Sundar
  0 siblings, 1 reply; 3+ messages in thread
From: Sakari Ailus @ 2025-08-21 17:25 UTC (permalink / raw)
  To: Chandra Mohan Sundar
  Cc: alain.volmat, mchehab, mcoquelin.stm32, alexandre.torgue,
	linux-media, linux-arm-kernel, shuah, linux-kernel-mentees

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.

On Mon, Aug 18, 2025 at 03:01:57PM +0530, Chandra Mohan Sundar wrote:
> 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 .

> Signed-off-by: Chandra Mohan Sundar <chandramohan.explore@gmail.com>
> ---
>  drivers/media/platform/st/stm32/stm32-csi.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/media/platform/st/stm32/stm32-csi.c b/drivers/media/platform/st/stm32/stm32-csi.c
> index b69048144cc1..fd2b6dfbd44c 100644
> --- a/drivers/media/platform/st/stm32/stm32-csi.c
> +++ b/drivers/media/platform/st/stm32/stm32-csi.c
> @@ -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)

-- 
Regards,

Sakari Ailus


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] media: v4l: Fix dereference before NULL check
  2025-08-21 17:25 ` Sakari Ailus
@ 2025-08-22  3:11   ` Chandra Mohan Sundar
  0 siblings, 0 replies; 3+ messages in thread
From: Chandra Mohan Sundar @ 2025-08-22  3:11 UTC (permalink / raw)
  To: Sakari Ailus
  Cc: alain.volmat, mchehab, mcoquelin.stm32, alexandre.torgue,
	linux-media, linux-arm-kernel, shuah, linux-kernel-mentees

Hi Sakari Ailus,

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

Thanks,
Chandra Mohan Sundar

On Thu, Aug 21, 2025 at 10:57 PM Sakari Ailus <sakari.ailus@iki.fi> wrote:
>
> 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.
>
> On Mon, Aug 18, 2025 at 03:01:57PM +0530, Chandra Mohan Sundar wrote:
> > 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 .
>
> > Signed-off-by: Chandra Mohan Sundar <chandramohan.explore@gmail.com>
> > ---
> >  drivers/media/platform/st/stm32/stm32-csi.c | 4 ++--
> >  1 file changed, 2 insertions(+), 2 deletions(-)
> >
> > diff --git a/drivers/media/platform/st/stm32/stm32-csi.c b/drivers/media/platform/st/stm32/stm32-csi.c
> > index b69048144cc1..fd2b6dfbd44c 100644
> > --- a/drivers/media/platform/st/stm32/stm32-csi.c
> > +++ b/drivers/media/platform/st/stm32/stm32-csi.c
> > @@ -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)
>
> --
> Regards,
>
> Sakari Ailus


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-08-22 11:22 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-18  9:31 [PATCH] media: v4l: Fix dereference before NULL check Chandra Mohan Sundar
2025-08-21 17:25 ` Sakari Ailus
2025-08-22  3:11   ` Chandra Mohan Sundar

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).