linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH][next] media: i2c: imx334: Fix a read of the uninitialized variable ret
@ 2021-02-10 19:07 Colin King
  2021-02-10 21:03 ` Sakari Ailus
  0 siblings, 1 reply; 4+ messages in thread
From: Colin King @ 2021-02-10 19:07 UTC (permalink / raw)
  To: Paul J . Murphy, Daniele Alessandrelli, Mauro Carvalho Chehab,
	Sakari Ailus, Martina Krasteva, Gjorgji Rosikopulos, linux-media
  Cc: kernel-janitors, linux-kernel

From: Colin Ian King <colin.king@canonical.com>

Currently there is a dev_err error message that is printing the
error status in variable ret (that has not been set) instead of
the correct error status from imx334->reset_gpio.  Fix this.

Addresses-Coverity: ("Uninitialized scalar variable")
Fixes: 9746b11715c3 ("media: i2c: Add imx334 camera sensor driver")

Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 drivers/media/i2c/imx334.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/media/i2c/imx334.c b/drivers/media/i2c/imx334.c
index 07e31bc2ef18..f8b1caf26c9b 100644
--- a/drivers/media/i2c/imx334.c
+++ b/drivers/media/i2c/imx334.c
@@ -790,7 +790,8 @@ static int imx334_parse_hw_config(struct imx334 *imx334)
 	imx334->reset_gpio = devm_gpiod_get_optional(imx334->dev, "reset",
 						     GPIOD_OUT_LOW);
 	if (IS_ERR(imx334->reset_gpio)) {
-		dev_err(imx334->dev, "failed to get reset gpio %d", ret);
+		dev_err(imx334->dev, "failed to get reset gpio %ld",
+			IS_ERR_VALUE(imx334->reset_gpio));
 		return PTR_ERR(imx334->reset_gpio);
 	}
 
-- 
2.30.0


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

* Re: [PATCH][next] media: i2c: imx334: Fix a read of the uninitialized variable ret
  2021-02-10 19:07 [PATCH][next] media: i2c: imx334: Fix a read of the uninitialized variable ret Colin King
@ 2021-02-10 21:03 ` Sakari Ailus
  2021-02-11 10:41   ` Dan Carpenter
  0 siblings, 1 reply; 4+ messages in thread
From: Sakari Ailus @ 2021-02-10 21:03 UTC (permalink / raw)
  To: Colin King
  Cc: Paul J . Murphy, Daniele Alessandrelli, Mauro Carvalho Chehab,
	Martina Krasteva, Gjorgji Rosikopulos, linux-media,
	kernel-janitors, linux-kernel

Hi Colin,

On Wed, Feb 10, 2021 at 07:07:52PM +0000, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
> 
> Currently there is a dev_err error message that is printing the
> error status in variable ret (that has not been set) instead of
> the correct error status from imx334->reset_gpio.  Fix this.
> 
> Addresses-Coverity: ("Uninitialized scalar variable")
> Fixes: 9746b11715c3 ("media: i2c: Add imx334 camera sensor driver")
> 
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>  drivers/media/i2c/imx334.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/media/i2c/imx334.c b/drivers/media/i2c/imx334.c
> index 07e31bc2ef18..f8b1caf26c9b 100644
> --- a/drivers/media/i2c/imx334.c
> +++ b/drivers/media/i2c/imx334.c
> @@ -790,7 +790,8 @@ static int imx334_parse_hw_config(struct imx334 *imx334)
>  	imx334->reset_gpio = devm_gpiod_get_optional(imx334->dev, "reset",
>  						     GPIOD_OUT_LOW);
>  	if (IS_ERR(imx334->reset_gpio)) {
> -		dev_err(imx334->dev, "failed to get reset gpio %d", ret);
> +		dev_err(imx334->dev, "failed to get reset gpio %ld",
> +			IS_ERR_VALUE(imx334->reset_gpio));
>  		return PTR_ERR(imx334->reset_gpio);
>  	}

Thanks for the patch. This has been already addressed by another patch
here, and has just been applied to linux-media master.

commit c702e2f70275dbc5373aef50c450cf9c5730636c
Author: Hans Verkuil <hverkuil@xs4all.nl>
Date:   Mon Feb 8 12:32:29 2021 +0100

    media: imx334: 'ret' is uninitialized, should have been PTR_ERR()
    
    Fix this compiler warning:
    
    drivers/media/i2c/imx334.c: In function 'imx334_parse_hw_config':
    include/linux/dev_printk.h:112:2: warning: 'ret' may be used uninitialized in this function [-Wmaybe-uninitialized]
      112 |  _dev_err(dev, dev_fmt(fmt), ##__VA_ARGS__)
          |  ^~~~~~~~
    drivers/media/i2c/imx334.c:783:6: note: 'ret' was declared here
      783 |  int ret;
          |      ^~~
    
    Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
    Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
    Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>

-- 
Kind regards,

Sakari Ailus

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

* Re: [PATCH][next] media: i2c: imx334: Fix a read of the uninitialized variable ret
  2021-02-10 21:03 ` Sakari Ailus
@ 2021-02-11 10:41   ` Dan Carpenter
  2021-02-11 10:50     ` Colin Ian King
  0 siblings, 1 reply; 4+ messages in thread
From: Dan Carpenter @ 2021-02-11 10:41 UTC (permalink / raw)
  To: Sakari Ailus
  Cc: Colin King, Paul J . Murphy, Daniele Alessandrelli,
	Mauro Carvalho Chehab, Martina Krasteva, Gjorgji Rosikopulos,
	linux-media, kernel-janitors, linux-kernel

On Wed, Feb 10, 2021 at 11:03:03PM +0200, Sakari Ailus wrote:
> Hi Colin,
> 
> On Wed, Feb 10, 2021 at 07:07:52PM +0000, Colin King wrote:
> > From: Colin Ian King <colin.king@canonical.com>
> > 
> > Currently there is a dev_err error message that is printing the
> > error status in variable ret (that has not been set) instead of
> > the correct error status from imx334->reset_gpio.  Fix this.
> > 
> > Addresses-Coverity: ("Uninitialized scalar variable")
> > Fixes: 9746b11715c3 ("media: i2c: Add imx334 camera sensor driver")
> > 
> > Signed-off-by: Colin Ian King <colin.king@canonical.com>
> > ---
> >  drivers/media/i2c/imx334.c | 3 ++-
> >  1 file changed, 2 insertions(+), 1 deletion(-)
> > 
> > diff --git a/drivers/media/i2c/imx334.c b/drivers/media/i2c/imx334.c
> > index 07e31bc2ef18..f8b1caf26c9b 100644
> > --- a/drivers/media/i2c/imx334.c
> > +++ b/drivers/media/i2c/imx334.c
> > @@ -790,7 +790,8 @@ static int imx334_parse_hw_config(struct imx334 *imx334)
> >  	imx334->reset_gpio = devm_gpiod_get_optional(imx334->dev, "reset",
> >  						     GPIOD_OUT_LOW);
> >  	if (IS_ERR(imx334->reset_gpio)) {
> > -		dev_err(imx334->dev, "failed to get reset gpio %d", ret);
> > +		dev_err(imx334->dev, "failed to get reset gpio %ld",
> > +			IS_ERR_VALUE(imx334->reset_gpio));

IS_ERR_VALUE() isn't right.  It would always print 1 here.  It should
just be PTR_ERR().

IS_ERR_VALUE() is like IS_ERR() but for when you're storing memory
addresses in an unsigned long variable.  get_unmapped_area(), for
example, returns unsigned longs.

regards,
dan carpenter

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

* Re: [PATCH][next] media: i2c: imx334: Fix a read of the uninitialized variable ret
  2021-02-11 10:41   ` Dan Carpenter
@ 2021-02-11 10:50     ` Colin Ian King
  0 siblings, 0 replies; 4+ messages in thread
From: Colin Ian King @ 2021-02-11 10:50 UTC (permalink / raw)
  To: Dan Carpenter, Sakari Ailus
  Cc: Paul J . Murphy, Daniele Alessandrelli, Mauro Carvalho Chehab,
	Martina Krasteva, Gjorgji Rosikopulos, linux-media,
	kernel-janitors, linux-kernel

On 11/02/2021 10:41, Dan Carpenter wrote:
> On Wed, Feb 10, 2021 at 11:03:03PM +0200, Sakari Ailus wrote:
>> Hi Colin,
>>
>> On Wed, Feb 10, 2021 at 07:07:52PM +0000, Colin King wrote:
>>> From: Colin Ian King <colin.king@canonical.com>
>>>
>>> Currently there is a dev_err error message that is printing the
>>> error status in variable ret (that has not been set) instead of
>>> the correct error status from imx334->reset_gpio.  Fix this.
>>>
>>> Addresses-Coverity: ("Uninitialized scalar variable")
>>> Fixes: 9746b11715c3 ("media: i2c: Add imx334 camera sensor driver")
>>>
>>> Signed-off-by: Colin Ian King <colin.king@canonical.com>
>>> ---
>>>  drivers/media/i2c/imx334.c | 3 ++-
>>>  1 file changed, 2 insertions(+), 1 deletion(-)
>>>
>>> diff --git a/drivers/media/i2c/imx334.c b/drivers/media/i2c/imx334.c
>>> index 07e31bc2ef18..f8b1caf26c9b 100644
>>> --- a/drivers/media/i2c/imx334.c
>>> +++ b/drivers/media/i2c/imx334.c
>>> @@ -790,7 +790,8 @@ static int imx334_parse_hw_config(struct imx334 *imx334)
>>>  	imx334->reset_gpio = devm_gpiod_get_optional(imx334->dev, "reset",
>>>  						     GPIOD_OUT_LOW);
>>>  	if (IS_ERR(imx334->reset_gpio)) {
>>> -		dev_err(imx334->dev, "failed to get reset gpio %d", ret);
>>> +		dev_err(imx334->dev, "failed to get reset gpio %ld",
>>> +			IS_ERR_VALUE(imx334->reset_gpio));
> 
> IS_ERR_VALUE() isn't right.  It would always print 1 here.  It should
> just be PTR_ERR().
> 
> IS_ERR_VALUE() is like IS_ERR() but for when you're storing memory
> addresses in an unsigned long variable.  get_unmapped_area(), for
> example, returns unsigned longs.
> 
> regards,
> dan carpenter
> 
Thanks, that was a brown paper bug mistake for sure :-/

Colin


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

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

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-10 19:07 [PATCH][next] media: i2c: imx334: Fix a read of the uninitialized variable ret Colin King
2021-02-10 21:03 ` Sakari Ailus
2021-02-11 10:41   ` Dan Carpenter
2021-02-11 10:50     ` Colin Ian King

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).