2021-07-09 03:18:07

by Souptick Joarder

[permalink] [raw]
Subject: [PATCH] iio: accel: fxls8962af: Initialize return value

kernel test robot throws below warning ->

smatch warnings:
drivers/iio/accel/fxls8962af-core.c:640
fxls8962af_i2c_raw_read_errata3() error: uninitialized symbol 'ret'.

Initialize it.

Reported-by: kernel test robot <[email protected]>
Reported-by: Dan Carpenter <[email protected]>
Signed-off-by: Souptick Joarder <[email protected]>
---
drivers/iio/accel/fxls8962af-core.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/iio/accel/fxls8962af-core.c b/drivers/iio/accel/fxls8962af-core.c
index 078d87865fde..8af1c8f58e83 100644
--- a/drivers/iio/accel/fxls8962af-core.c
+++ b/drivers/iio/accel/fxls8962af-core.c
@@ -628,7 +628,7 @@ static int fxls8962af_i2c_raw_read_errata3(struct fxls8962af_data *data,
u16 *buffer, int samples,
int sample_length)
{
- int i, ret;
+ int i, ret = -EINVAL;

for (i = 0; i < samples; i++) {
ret = regmap_raw_read(data->regmap, FXLS8962AF_BUF_X_LSB,
--
2.25.1


2021-07-09 03:37:58

by Fabio Estevam

[permalink] [raw]
Subject: Re: [PATCH] iio: accel: fxls8962af: Initialize return value

Hi Souptick,

On Fri, Jul 9, 2021 at 12:17 AM Souptick Joarder <[email protected]> wrote:
>
> kernel test robot throws below warning ->
>
> smatch warnings:
> drivers/iio/accel/fxls8962af-core.c:640
> fxls8962af_i2c_raw_read_errata3() error: uninitialized symbol 'ret'.
>
> Initialize it.
>
> Reported-by: kernel test robot <[email protected]>
> Reported-by: Dan Carpenter <[email protected]>
> Signed-off-by: Souptick Joarder <[email protected]>
> ---
> drivers/iio/accel/fxls8962af-core.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/iio/accel/fxls8962af-core.c b/drivers/iio/accel/fxls8962af-core.c
> index 078d87865fde..8af1c8f58e83 100644
> --- a/drivers/iio/accel/fxls8962af-core.c
> +++ b/drivers/iio/accel/fxls8962af-core.c
> @@ -628,7 +628,7 @@ static int fxls8962af_i2c_raw_read_errata3(struct fxls8962af_data *data,
> u16 *buffer, int samples,
> int sample_length)
> {
> - int i, ret;
> + int i, ret = -EINVAL;
>
> for (i = 0; i < samples; i++) {
> ret = regmap_raw_read(data->regmap, FXLS8962AF_BUF_X_LSB,

Would the change below work?

--- a/drivers/iio/accel/fxls8962af-core.c
+++ b/drivers/iio/accel/fxls8962af-core.c
@@ -637,7 +637,7 @@ static int fxls8962af_i2c_raw_read_errata3(struct
fxls8962af_data *data,
return ret;
}

- return ret;
+ return 0;
}

2021-07-09 06:49:28

by Sean Nyekjaer

[permalink] [raw]
Subject: Re: [PATCH] iio: accel: fxls8962af: Initialize return value

Hi Souptick and Fabio.

On Fri, Jul 09, 2021 at 12:36:25AM -0300, Fabio Estevam wrote:
> Hi Souptick,
>
> On Fri, Jul 9, 2021 at 12:17 AM Souptick Joarder <[email protected]> wrote:
> >
> > kernel test robot throws below warning ->
> >
> > smatch warnings:
> > drivers/iio/accel/fxls8962af-core.c:640
> > fxls8962af_i2c_raw_read_errata3() error: uninitialized symbol 'ret'.
> >
> > Initialize it.
> >
> > Reported-by: kernel test robot <[email protected]>
> > Reported-by: Dan Carpenter <[email protected]>
> > Signed-off-by: Souptick Joarder <[email protected]>
Missing fixes-tag ;)

[ ... ]

>
> Would the change below work?
>
> --- a/drivers/iio/accel/fxls8962af-core.c
> +++ b/drivers/iio/accel/fxls8962af-core.c
> @@ -637,7 +637,7 @@ static int fxls8962af_i2c_raw_read_errata3(struct
> fxls8962af_data *data,
> return ret;
> }
>
> - return ret;
> + return 0;
> }

I have already submitted a patch for this :)
https://patchwork.kernel.org/project/linux-iio/patch/[email protected]/

/Sean

2021-07-09 14:39:11

by Sean Nyekjaer

[permalink] [raw]
Subject: Re: [PATCH] iio: accel: fxls8962af: Initialize return value

On Fri, Jul 09, 2021 at 07:50:48PM +0530, Souptick Joarder wrote:
> On Fri, 9 Jul, 2021, 9:06 am Fabio Estevam, <[email protected]> wrote:
>
> > Hi Souptick,
> >
> > On Fri, Jul 9, 2021 at 12:17 AM Souptick Joarder <[email protected]>
> > wrote:
> > >
> > > kernel test robot throws below warning ->
> > >
> > > smatch warnings:
> > > drivers/iio/accel/fxls8962af-core.c:640
> > > fxls8962af_i2c_raw_read_errata3() error: uninitialized symbol 'ret'.
> > >
> > > Initialize it.
> > >
> > > Reported-by: kernel test robot <[email protected]>
> > > Reported-by: Dan Carpenter <[email protected]>
> > > Signed-off-by: Souptick Joarder <[email protected]>
> > > ---
> > > drivers/iio/accel/fxls8962af-core.c | 2 +-
> > > 1 file changed, 1 insertion(+), 1 deletion(-)
> > >
> > > diff --git a/drivers/iio/accel/fxls8962af-core.c
> > b/drivers/iio/accel/fxls8962af-core.c
> > > index 078d87865fde..8af1c8f58e83 100644
> > > --- a/drivers/iio/accel/fxls8962af-core.c
> > > +++ b/drivers/iio/accel/fxls8962af-core.c
> > > @@ -628,7 +628,7 @@ static int fxls8962af_i2c_raw_read_errata3(struct
> > fxls8962af_data *data,
> > > u16 *buffer, int samples,
> > > int sample_length)
> > > {
> > > - int i, ret;
> > > + int i, ret = -EINVAL;
> > >
> > > for (i = 0; i < samples; i++) {
> > > ret = regmap_raw_read(data->regmap, FXLS8962AF_BUF_X_LSB,
> >
> > Would the change below work?
> >
>
> This function returns -ERRNO when failed. If it is not entering loop,
> ideally it should return -ERRNO, not 0. No ?

samples can't be 0, as fxls8962af_fifo_transfer() is never called if
samples are 0 :)

>
> >
> > --- a/drivers/iio/accel/fxls8962af-core.c
> > +++ b/drivers/iio/accel/fxls8962af-core.c
> > @@ -637,7 +637,7 @@ static int fxls8962af_i2c_raw_read_errata3(struct
> > fxls8962af_data *data,
> > return ret;
> > }
> >
> > - return ret;
> > + return 0;
> > }
> >

2021-07-09 17:14:30

by Dan Carpenter

[permalink] [raw]
Subject: Re: [PATCH] iio: accel: fxls8962af: Initialize return value

On Fri, Jul 09, 2021 at 04:35:05PM +0200, Sean Nyekjaer wrote:
> On Fri, Jul 09, 2021 at 07:50:48PM +0530, Souptick Joarder wrote:
> > On Fri, 9 Jul, 2021, 9:06 am Fabio Estevam, <[email protected]> wrote:
> >
> > > Hi Souptick,
> > >
> > > On Fri, Jul 9, 2021 at 12:17 AM Souptick Joarder <[email protected]>
> > > wrote:
> > > >
> > > > kernel test robot throws below warning ->
> > > >
> > > > smatch warnings:
> > > > drivers/iio/accel/fxls8962af-core.c:640
> > > > fxls8962af_i2c_raw_read_errata3() error: uninitialized symbol 'ret'.
> > > >
> > > > Initialize it.
> > > >
> > > > Reported-by: kernel test robot <[email protected]>
> > > > Reported-by: Dan Carpenter <[email protected]>
> > > > Signed-off-by: Souptick Joarder <[email protected]>
> > > > ---
> > > > drivers/iio/accel/fxls8962af-core.c | 2 +-
> > > > 1 file changed, 1 insertion(+), 1 deletion(-)
> > > >
> > > > diff --git a/drivers/iio/accel/fxls8962af-core.c
> > > b/drivers/iio/accel/fxls8962af-core.c
> > > > index 078d87865fde..8af1c8f58e83 100644
> > > > --- a/drivers/iio/accel/fxls8962af-core.c
> > > > +++ b/drivers/iio/accel/fxls8962af-core.c
> > > > @@ -628,7 +628,7 @@ static int fxls8962af_i2c_raw_read_errata3(struct
> > > fxls8962af_data *data,
> > > > u16 *buffer, int samples,
> > > > int sample_length)
> > > > {
> > > > - int i, ret;
> > > > + int i, ret = -EINVAL;
> > > >
> > > > for (i = 0; i < samples; i++) {
> > > > ret = regmap_raw_read(data->regmap, FXLS8962AF_BUF_X_LSB,
> > >
> > > Would the change below work?
> > >
> >
> > This function returns -ERRNO when failed. If it is not entering loop,
> > ideally it should return -ERRNO, not 0. No ?
>
> samples can't be 0, as fxls8962af_fifo_transfer() is never called if
> samples are 0 :)
>

Yeah, you're right. Smatch can figure that out if you build the cross
function DB, but it's a little bit trick for kbuild to use the DB when
it runs on so many git trees. The DB takes hours to build so kbuild
doesn't use it.

regards,
dan carpenter

2021-07-10 17:21:41

by Fabio Estevam

[permalink] [raw]
Subject: Re: [PATCH] iio: accel: fxls8962af: Initialize return value

Hi Sean,

On Fri, Jul 9, 2021 at 3:48 AM Sean Nyekjaer <[email protected]> wrote:

> I have already submitted a patch for this :)
> https://patchwork.kernel.org/project/linux-iio/patch/[email protected]/

Please resubmit your patch with a commit log.

Thanks