diff mbox

[media] soc_camera: avoid potential null-dereference

Message ID 1420597628-317-1-git-send-email-andy.shevchenko@gmail.com (mailing list archive)
State New, archived
Headers show

Commit Message

Andy Shevchenko Jan. 7, 2015, 2:27 a.m. UTC
We have to check the pointer before dereferencing it.

Signed-off-by: Andy Shevchenko <andy.shevchenko@gmail.com>
---
 drivers/media/platform/soc_camera/soc_camera.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Comments

Guennadi Liakhovetski Jan. 7, 2015, 7:44 p.m. UTC | #1
Hi Andy,

Thanks for the patch. Will queue for the next pull request.

Regards
Guennadi

On Wed, 7 Jan 2015, Andy Shevchenko wrote:

> We have to check the pointer before dereferencing it.
> 
> Signed-off-by: Andy Shevchenko <andy.shevchenko@gmail.com>
> ---
>  drivers/media/platform/soc_camera/soc_camera.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/media/platform/soc_camera/soc_camera.c b/drivers/media/platform/soc_camera/soc_camera.c
> index b3db51c..8c665c4 100644
> --- a/drivers/media/platform/soc_camera/soc_camera.c
> +++ b/drivers/media/platform/soc_camera/soc_camera.c
> @@ -2166,7 +2166,7 @@ static int soc_camera_video_start(struct soc_camera_device *icd)
>  static int soc_camera_pdrv_probe(struct platform_device *pdev)
>  {
>  	struct soc_camera_desc *sdesc = pdev->dev.platform_data;
> -	struct soc_camera_subdev_desc *ssdd = &sdesc->subdev_desc;
> +	struct soc_camera_subdev_desc *ssdd;
>  	struct soc_camera_device *icd;
>  	int ret;
>  
> @@ -2177,6 +2177,8 @@ static int soc_camera_pdrv_probe(struct platform_device *pdev)
>  	if (!icd)
>  		return -ENOMEM;
>  
> +	ssdd = &sdesc->subdev_desc;
> +
>  	/*
>  	 * In the asynchronous case ssdd->num_regulators == 0 yet, so, the below
>  	 * regulator allocation is a dummy. They are actually requested by the
> -- 
> 1.8.3.101.g727a46b
> 
--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Andy Shevchenko Jan. 7, 2015, 8:05 p.m. UTC | #2
On Wed, Jan 7, 2015 at 9:44 PM, Guennadi Liakhovetski
<g.liakhovetski@gmx.de> wrote:
> Hi Andy,
>
> Thanks for the patch. Will queue for the next pull request.

If you didn't do that please wait. It seems it has one more place with
similar issue. Moreover, I would like to add a person's name who
reported this.

>
> Regards
> Guennadi
>
> On Wed, 7 Jan 2015, Andy Shevchenko wrote:
>
>> We have to check the pointer before dereferencing it.
>>
>> Signed-off-by: Andy Shevchenko <andy.shevchenko@gmail.com>
>> ---
>>  drivers/media/platform/soc_camera/soc_camera.c | 4 +++-
>>  1 file changed, 3 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/media/platform/soc_camera/soc_camera.c b/drivers/media/platform/soc_camera/soc_camera.c
>> index b3db51c..8c665c4 100644
>> --- a/drivers/media/platform/soc_camera/soc_camera.c
>> +++ b/drivers/media/platform/soc_camera/soc_camera.c
>> @@ -2166,7 +2166,7 @@ static int soc_camera_video_start(struct soc_camera_device *icd)
>>  static int soc_camera_pdrv_probe(struct platform_device *pdev)
>>  {
>>       struct soc_camera_desc *sdesc = pdev->dev.platform_data;
>> -     struct soc_camera_subdev_desc *ssdd = &sdesc->subdev_desc;
>> +     struct soc_camera_subdev_desc *ssdd;
>>       struct soc_camera_device *icd;
>>       int ret;
>>
>> @@ -2177,6 +2177,8 @@ static int soc_camera_pdrv_probe(struct platform_device *pdev)
>>       if (!icd)
>>               return -ENOMEM;
>>
>> +     ssdd = &sdesc->subdev_desc;
>> +
>>       /*
>>        * In the asynchronous case ssdd->num_regulators == 0 yet, so, the below
>>        * regulator allocation is a dummy. They are actually requested by the
>> --
>> 1.8.3.101.g727a46b
>>
Andy Shevchenko Jan. 7, 2015, 8:14 p.m. UTC | #3
On Wed, Jan 7, 2015 at 10:05 PM, Andy Shevchenko
<andy.shevchenko@gmail.com> wrote:
> On Wed, Jan 7, 2015 at 9:44 PM, Guennadi Liakhovetski
> <g.liakhovetski@gmx.de> wrote:
>> Hi Andy,
>>
>> Thanks for the patch. Will queue for the next pull request.
>
> If you didn't do that please wait. It seems it has one more place with
> similar issue. Moreover, I would like to add a person's name who
> reported this.

Okay, the second one is false positive.
And
Reported-by: Andrey Karpov <karpov@viva64.com>

>
>>
>> Regards
>> Guennadi
>>
>> On Wed, 7 Jan 2015, Andy Shevchenko wrote:
>>
>>> We have to check the pointer before dereferencing it.
>>>
>>> Signed-off-by: Andy Shevchenko <andy.shevchenko@gmail.com>
>>> ---
>>>  drivers/media/platform/soc_camera/soc_camera.c | 4 +++-
>>>  1 file changed, 3 insertions(+), 1 deletion(-)
>>>
>>> diff --git a/drivers/media/platform/soc_camera/soc_camera.c b/drivers/media/platform/soc_camera/soc_camera.c
>>> index b3db51c..8c665c4 100644
>>> --- a/drivers/media/platform/soc_camera/soc_camera.c
>>> +++ b/drivers/media/platform/soc_camera/soc_camera.c
>>> @@ -2166,7 +2166,7 @@ static int soc_camera_video_start(struct soc_camera_device *icd)
>>>  static int soc_camera_pdrv_probe(struct platform_device *pdev)
>>>  {
>>>       struct soc_camera_desc *sdesc = pdev->dev.platform_data;
>>> -     struct soc_camera_subdev_desc *ssdd = &sdesc->subdev_desc;
>>> +     struct soc_camera_subdev_desc *ssdd;
>>>       struct soc_camera_device *icd;
>>>       int ret;
>>>
>>> @@ -2177,6 +2177,8 @@ static int soc_camera_pdrv_probe(struct platform_device *pdev)
>>>       if (!icd)
>>>               return -ENOMEM;
>>>
>>> +     ssdd = &sdesc->subdev_desc;
>>> +
>>>       /*
>>>        * In the asynchronous case ssdd->num_regulators == 0 yet, so, the below
>>>        * regulator allocation is a dummy. They are actually requested by the
>>> --
>>> 1.8.3.101.g727a46b
>>>
>
>
>
> --
> With Best Regards,
> Andy Shevchenko
Guennadi Liakhovetski Jan. 18, 2015, 10:10 p.m. UTC | #4
On Wed, 7 Jan 2015, Guennadi Liakhovetski wrote:

> Hi Andy,
> 
> Thanks for the patch. Will queue for the next pull request.

Actually no, I won't. I don't think there's currently a but there. the 
pointer isn't dereferenced before being checked. Only an address of a 
field in a struct, it's pointing to is calculated. So, if it's NULL just a 
small offset will be calculated, but no dereferencing will take place.

Thanks
Guennadi

> Regards
> Guennadi
> 
> On Wed, 7 Jan 2015, Andy Shevchenko wrote:
> 
> > We have to check the pointer before dereferencing it.
> > 
> > Signed-off-by: Andy Shevchenko <andy.shevchenko@gmail.com>
> > ---
> >  drivers/media/platform/soc_camera/soc_camera.c | 4 +++-
> >  1 file changed, 3 insertions(+), 1 deletion(-)
> > 
> > diff --git a/drivers/media/platform/soc_camera/soc_camera.c b/drivers/media/platform/soc_camera/soc_camera.c
> > index b3db51c..8c665c4 100644
> > --- a/drivers/media/platform/soc_camera/soc_camera.c
> > +++ b/drivers/media/platform/soc_camera/soc_camera.c
> > @@ -2166,7 +2166,7 @@ static int soc_camera_video_start(struct soc_camera_device *icd)
> >  static int soc_camera_pdrv_probe(struct platform_device *pdev)
> >  {
> >  	struct soc_camera_desc *sdesc = pdev->dev.platform_data;
> > -	struct soc_camera_subdev_desc *ssdd = &sdesc->subdev_desc;
> > +	struct soc_camera_subdev_desc *ssdd;
> >  	struct soc_camera_device *icd;
> >  	int ret;
> >  
> > @@ -2177,6 +2177,8 @@ static int soc_camera_pdrv_probe(struct platform_device *pdev)
> >  	if (!icd)
> >  		return -ENOMEM;
> >  
> > +	ssdd = &sdesc->subdev_desc;
> > +
> >  	/*
> >  	 * In the asynchronous case ssdd->num_regulators == 0 yet, so, the below
> >  	 * regulator allocation is a dummy. They are actually requested by the
> > -- 
> > 1.8.3.101.g727a46b
> > 
> 
--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/drivers/media/platform/soc_camera/soc_camera.c b/drivers/media/platform/soc_camera/soc_camera.c
index b3db51c..8c665c4 100644
--- a/drivers/media/platform/soc_camera/soc_camera.c
+++ b/drivers/media/platform/soc_camera/soc_camera.c
@@ -2166,7 +2166,7 @@  static int soc_camera_video_start(struct soc_camera_device *icd)
 static int soc_camera_pdrv_probe(struct platform_device *pdev)
 {
 	struct soc_camera_desc *sdesc = pdev->dev.platform_data;
-	struct soc_camera_subdev_desc *ssdd = &sdesc->subdev_desc;
+	struct soc_camera_subdev_desc *ssdd;
 	struct soc_camera_device *icd;
 	int ret;
 
@@ -2177,6 +2177,8 @@  static int soc_camera_pdrv_probe(struct platform_device *pdev)
 	if (!icd)
 		return -ENOMEM;
 
+	ssdd = &sdesc->subdev_desc;
+
 	/*
 	 * In the asynchronous case ssdd->num_regulators == 0 yet, so, the below
 	 * regulator allocation is a dummy. They are actually requested by the