* [PATCH v4] staging: iio: meter: add check on return variables
@ 2015-03-03 13:36 Aya Mahfouz
2015-03-03 13:43 ` [Outreachy kernel] " Daniel Baluta
0 siblings, 1 reply; 3+ messages in thread
From: Aya Mahfouz @ 2015-03-03 13:36 UTC (permalink / raw)
To: outreachy-kernel
Adds checks on variables that are used to return values. If
the value is less than zero, this indicates that an error
occurred and hence a message is printed through dev_err.
Checks are made on negative values only since spi_* functions
return negative error codes.
The functions were found using the following script but the
aforementioned modification was what was carried out in the end:
@@
identifier len,f;
@@
-int len;
... when != len
when strict
-len =
+return
f(...);
-return len;
Signed-off-by: Aya Mahfouz <mahfouz.saif.elyazal@gmail.com>
---
v1: added checks on last calls only.
v2: added checks on all calls that return values along with labels.
v3: added changelog that was missed in v2.
v4: adjusted the patch to state how the problem was discovered, simplify
the if conditions and avoid redundant error messages.
drivers/staging/iio/meter/ade7758_core.c | 22 ++++++++--------------
1 file changed, 8 insertions(+), 14 deletions(-)
diff --git a/drivers/staging/iio/meter/ade7758_core.c b/drivers/staging/iio/meter/ade7758_core.c
index 70e96b2..f696188 100644
--- a/drivers/staging/iio/meter/ade7758_core.c
+++ b/drivers/staging/iio/meter/ade7758_core.c
@@ -303,14 +303,11 @@ static int ade7758_reset(struct device *dev)
int ret;
u8 val;
- ade7758_spi_read_reg_8(dev,
- ADE7758_OPMODE,
- &val);
+ ret = ade7758_spi_read_reg_8(dev, ADE7758_OPMODE, &val);
+ if (ret < 0)
+ return ret;
val |= 1 << 6; /* Software Chip Reset */
- ret = ade7758_spi_write_reg_8(dev,
- ADE7758_OPMODE,
- val);
-
+ ret = ade7758_spi_write_reg_8(dev, ADE7758_OPMODE, val);
return ret;
}
@@ -444,14 +441,11 @@ static int ade7758_stop_device(struct device *dev)
int ret;
u8 val;
- ade7758_spi_read_reg_8(dev,
- ADE7758_OPMODE,
- &val);
+ ret = ade7758_spi_read_reg_8(dev, ADE7758_OPMODE, &val);
+ if (ret < 0)
+ return ret;
val |= 7 << 3; /* ADE7758 powered down */
- ret = ade7758_spi_write_reg_8(dev,
- ADE7758_OPMODE,
- val);
-
+ ret = ade7758_spi_write_reg_8(dev, ADE7758_OPMODE, val);
return ret;
}
--
1.9.3
--
Kind Regards,
Aya Saif El-yazal Mahfouz
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [Outreachy kernel] [PATCH v4] staging: iio: meter: add check on return variables
2015-03-03 13:36 [PATCH v4] staging: iio: meter: add check on return variables Aya Mahfouz
@ 2015-03-03 13:43 ` Daniel Baluta
2015-03-03 14:12 ` Aya Mahfouz
0 siblings, 1 reply; 3+ messages in thread
From: Daniel Baluta @ 2015-03-03 13:43 UTC (permalink / raw)
To: Aya Mahfouz; +Cc: outreachy-kernel
On Tue, Mar 3, 2015 at 3:36 PM, Aya Mahfouz
<mahfouz.saif.elyazal@gmail.com> wrote:
> Adds checks on variables that are used to return values. If
> the value is less than zero, this indicates that an error
> occurred and hence a message is printed through dev_err.
> Checks are made on negative values only since spi_* functions
> return negative error codes.
>
> The functions were found using the following script but the
> aforementioned modification was what was carried out in the end:
> @@
> identifier len,f;
> @@
>
> -int len;
> ... when != len
> when strict
> -len =
> +return
> f(...);
> -return len;
>
> Signed-off-by: Aya Mahfouz <mahfouz.saif.elyazal@gmail.com>
Commit message looks good to me.
> ---
> v1: added checks on last calls only.
> v2: added checks on all calls that return values along with labels.
> v3: added changelog that was missed in v2.
> v4: adjusted the patch to state how the problem was discovered, simplify
> the if conditions and avoid redundant error messages.
>
> drivers/staging/iio/meter/ade7758_core.c | 22 ++++++++--------------
> 1 file changed, 8 insertions(+), 14 deletions(-)
>
> diff --git a/drivers/staging/iio/meter/ade7758_core.c b/drivers/staging/iio/meter/ade7758_core.c
> index 70e96b2..f696188 100644
> --- a/drivers/staging/iio/meter/ade7758_core.c
> +++ b/drivers/staging/iio/meter/ade7758_core.c
> @@ -303,14 +303,11 @@ static int ade7758_reset(struct device *dev)
> int ret;
> u8 val;
>
> - ade7758_spi_read_reg_8(dev,
> - ADE7758_OPMODE,
> - &val);
> + ret = ade7758_spi_read_reg_8(dev, ADE7758_OPMODE, &val);
> + if (ret < 0)
> + return ret;
I think we should keep the warning messages. Here we could say
something like this
dev_err( ... "Failed to read opmode reg\n");
> val |= 1 << 6; /* Software Chip Reset */
> - ret = ade7758_spi_write_reg_8(dev,
> - ADE7758_OPMODE,
> - val);
> -
> + ret = ade7758_spi_write_reg_8(dev, ADE7758_OPMODE, val);
Then also:
if (ret)
dev_err( ... "FAiled to write opmode reg\n");
> return ret;
> }
>
> @@ -444,14 +441,11 @@ static int ade7758_stop_device(struct device *dev)
> int ret;
> u8 val;
>
> - ade7758_spi_read_reg_8(dev,
> - ADE7758_OPMODE,
> - &val);
> + ret = ade7758_spi_read_reg_8(dev, ADE7758_OPMODE, &val);
> + if (ret < 0)
> + return ret;
> val |= 7 << 3; /* ADE7758 powered down */
> - ret = ade7758_spi_write_reg_8(dev,
> - ADE7758_OPMODE,
> - val);
> -
> + ret = ade7758_spi_write_reg_8(dev, ADE7758_OPMODE, val);
> return ret;
The same here.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Outreachy kernel] [PATCH v4] staging: iio: meter: add check on return variables
2015-03-03 13:43 ` [Outreachy kernel] " Daniel Baluta
@ 2015-03-03 14:12 ` Aya Mahfouz
0 siblings, 0 replies; 3+ messages in thread
From: Aya Mahfouz @ 2015-03-03 14:12 UTC (permalink / raw)
To: Daniel Baluta; +Cc: outreachy-kernel
On Tue, Mar 03, 2015 at 03:43:48PM +0200, Daniel Baluta wrote:
> On Tue, Mar 3, 2015 at 3:36 PM, Aya Mahfouz
> <mahfouz.saif.elyazal@gmail.com> wrote:
> > Adds checks on variables that are used to return values. If
> > the value is less than zero, this indicates that an error
> > occurred and hence a message is printed through dev_err.
> > Checks are made on negative values only since spi_* functions
> > return negative error codes.
> >
> > The functions were found using the following script but the
> > aforementioned modification was what was carried out in the end:
> > @@
> > identifier len,f;
> > @@
> >
> > -int len;
> > ... when != len
> > when strict
> > -len =
> > +return
> > f(...);
> > -return len;
> >
> > Signed-off-by: Aya Mahfouz <mahfouz.saif.elyazal@gmail.com>
>
> Commit message looks good to me.
>
> > ---
> > v1: added checks on last calls only.
> > v2: added checks on all calls that return values along with labels.
> > v3: added changelog that was missed in v2.
> > v4: adjusted the patch to state how the problem was discovered, simplify
> > the if conditions and avoid redundant error messages.
> >
> > drivers/staging/iio/meter/ade7758_core.c | 22 ++++++++--------------
> > 1 file changed, 8 insertions(+), 14 deletions(-)
> >
> > diff --git a/drivers/staging/iio/meter/ade7758_core.c b/drivers/staging/iio/meter/ade7758_core.c
> > index 70e96b2..f696188 100644
> > --- a/drivers/staging/iio/meter/ade7758_core.c
> > +++ b/drivers/staging/iio/meter/ade7758_core.c
> > @@ -303,14 +303,11 @@ static int ade7758_reset(struct device *dev)
> > int ret;
> > u8 val;
> >
> > - ade7758_spi_read_reg_8(dev,
> > - ADE7758_OPMODE,
> > - &val);
> > + ret = ade7758_spi_read_reg_8(dev, ADE7758_OPMODE, &val);
> > + if (ret < 0)
> > + return ret;
>
> I think we should keep the warning messages. Here we could say
> something like this
> dev_err( ... "Failed to read opmode reg\n");
>
> > val |= 1 << 6; /* Software Chip Reset */
> > - ret = ade7758_spi_write_reg_8(dev,
> > - ADE7758_OPMODE,
> > - val);
> > -
> > + ret = ade7758_spi_write_reg_8(dev, ADE7758_OPMODE, val);
> Then also:
>
> if (ret)
> dev_err( ... "FAiled to write opmode reg\n");
>
ok, will do. Thanks Daniel!
> > return ret;
> > }
> >
> > @@ -444,14 +441,11 @@ static int ade7758_stop_device(struct device *dev)
> > int ret;
> > u8 val;
> >
> > - ade7758_spi_read_reg_8(dev,
> > - ADE7758_OPMODE,
> > - &val);
> > + ret = ade7758_spi_read_reg_8(dev, ADE7758_OPMODE, &val);
> > + if (ret < 0)
> > + return ret;
> > val |= 7 << 3; /* ADE7758 powered down */
> > - ret = ade7758_spi_write_reg_8(dev,
> > - ADE7758_OPMODE,
> > - val);
> > -
> > + ret = ade7758_spi_write_reg_8(dev, ADE7758_OPMODE, val);
> > return ret;
>
> The same here.
--
Kind Regards,
Aya Saif El-yazal Mahfouz
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2015-03-03 14:12 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-03-03 13:36 [PATCH v4] staging: iio: meter: add check on return variables Aya Mahfouz
2015-03-03 13:43 ` [Outreachy kernel] " Daniel Baluta
2015-03-03 14:12 ` Aya Mahfouz
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.