All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3] staging: iio: meter: add check on return variables
@ 2015-03-03 11:27 Aya Mahfouz
       [not found] ` <CAEnQRZDFF_mvL=hUbC4T3S04kwUq1SZDqQdvWrd1_35Y8q_Uuw@mail.gmail.com>
  2015-03-03 12:01 ` Julia Lawall
  0 siblings, 2 replies; 7+ messages in thread
From: Aya Mahfouz @ 2015-03-03 11:27 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
occured and hence a message is printed through dev_err. Labels
have been added too, since the check is done more than once.

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.

 drivers/staging/iio/meter/ade7758_core.c | 35 ++++++++++++++++++++------------
 1 file changed, 22 insertions(+), 13 deletions(-)

diff --git a/drivers/staging/iio/meter/ade7758_core.c b/drivers/staging/iio/meter/ade7758_core.c
index 70e96b2..cab392f 100644
--- a/drivers/staging/iio/meter/ade7758_core.c
+++ b/drivers/staging/iio/meter/ade7758_core.c
@@ -303,14 +303,18 @@ 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) {
+		dev_err(dev, "failed to read from device");
+		goto error_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);
+	if (ret < 0) {
+		dev_err(dev, "failed to reset device");
+		goto error_ret;
+	}
+error_ret:
 	return ret;
 }
 
@@ -444,14 +448,19 @@ 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) {
+		dev_err(dev, "failed to read from device");
+		goto error_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);
+	if (ret < 0) {
+		dev_err(dev, "failed to stop device");
+		goto error_ret;
+	}
 
+error_ret:
 	return ret;
 }
 
-- 
1.9.3


-- 
Kind Regards,
Aya Saif El-yazal Mahfouz


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

* Re: [Outreachy kernel] [PATCH v3] staging: iio: meter: add check on return variables
       [not found] ` <CAEnQRZDFF_mvL=hUbC4T3S04kwUq1SZDqQdvWrd1_35Y8q_Uuw@mail.gmail.com>
@ 2015-03-03 11:57   ` Daniel Baluta
  0 siblings, 0 replies; 7+ messages in thread
From: Daniel Baluta @ 2015-03-03 11:57 UTC (permalink / raw)
  To: Aya Mahfouz, outreachy-kernel

+ list :)

On Tue, Mar 3, 2015 at 1:57 PM, Daniel Baluta <daniel.baluta@gmail.com> wrote:
> On Tue, Mar 3, 2015 at 1:27 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
>> occured and hence a message is printed through dev_err. Labels
>> have been added too, since the check is done more than once.
>>
>> 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.
>>
>>  drivers/staging/iio/meter/ade7758_core.c | 35 ++++++++++++++++++++------------
>>  1 file changed, 22 insertions(+), 13 deletions(-)
>>
>> diff --git a/drivers/staging/iio/meter/ade7758_core.c b/drivers/staging/iio/meter/ade7758_core.c
>> index 70e96b2..cab392f 100644
>> --- a/drivers/staging/iio/meter/ade7758_core.c
>> +++ b/drivers/staging/iio/meter/ade7758_core.c
>> @@ -303,14 +303,18 @@ 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) {
>> +               dev_err(dev, "failed to read from device");
>> +               goto error_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);
>> +       if (ret < 0) {
>> +               dev_err(dev, "failed to reset device");
>> +               goto error_ret;
>> +       }
>> +error_ret:
>>         return ret;
>>  }
>>
>> @@ -444,14 +448,19 @@ 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) {
>> +               dev_err(dev, "failed to read from device");
>> +               goto error_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);
>> +       if (ret < 0) {
>> +               dev_err(dev, "failed to stop device");
>> +               goto error_ret;
>> +       }
>>
>> +error_ret:
>>         return ret;
>>  }
>
> Is there any particular reason for which you preferred gotos here?
> I don't think we need them. Just directly return ret;.
>
> Daniel.


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

* Re: [Outreachy kernel] [PATCH v3] staging: iio: meter: add check on return variables
  2015-03-03 11:27 [PATCH v3] staging: iio: meter: add check on return variables Aya Mahfouz
       [not found] ` <CAEnQRZDFF_mvL=hUbC4T3S04kwUq1SZDqQdvWrd1_35Y8q_Uuw@mail.gmail.com>
@ 2015-03-03 12:01 ` Julia Lawall
  2015-03-03 12:13   ` Arnd Bergmann
  2015-03-03 13:10   ` Aya Mahfouz
  1 sibling, 2 replies; 7+ messages in thread
From: Julia Lawall @ 2015-03-03 12:01 UTC (permalink / raw)
  To: Aya Mahfouz; +Cc: outreachy-kernel

On Tue, 3 Mar 2015, Aya Mahfouz wrote:

> Adds checks on variables that are used to return values. If
> the value is less than zero, this indicates that an error
> occured and hence a message is printed through dev_err. Labels
> have been added too, since the check is done more than once.

How did you find the functions that have this property?

julia

> 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.
>
>  drivers/staging/iio/meter/ade7758_core.c | 35 ++++++++++++++++++++------------
>  1 file changed, 22 insertions(+), 13 deletions(-)
>
> diff --git a/drivers/staging/iio/meter/ade7758_core.c b/drivers/staging/iio/meter/ade7758_core.c
> index 70e96b2..cab392f 100644
> --- a/drivers/staging/iio/meter/ade7758_core.c
> +++ b/drivers/staging/iio/meter/ade7758_core.c
> @@ -303,14 +303,18 @@ 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) {
> +		dev_err(dev, "failed to read from device");
> +		goto error_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);
> +	if (ret < 0) {
> +		dev_err(dev, "failed to reset device");
> +		goto error_ret;
> +	}
> +error_ret:
>  	return ret;
>  }
>
> @@ -444,14 +448,19 @@ 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) {
> +		dev_err(dev, "failed to read from device");
> +		goto error_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);
> +	if (ret < 0) {
> +		dev_err(dev, "failed to stop device");
> +		goto error_ret;
> +	}
>
> +error_ret:
>  	return ret;
>  }
>
> --
> 1.9.3
>
>
> --
> Kind Regards,
> Aya Saif El-yazal Mahfouz
>
> --
> You received this message because you are subscribed to the Google Groups "outreachy-kernel" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to outreachy-kernel+unsubscribe@googlegroups.com.
> To post to this group, send email to outreachy-kernel@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/20150303112705.GA11879%40waves.
> For more options, visit https://groups.google.com/d/optout.
>


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

* Re: [Outreachy kernel] [PATCH v3] staging: iio: meter: add check on return variables
  2015-03-03 12:01 ` Julia Lawall
@ 2015-03-03 12:13   ` Arnd Bergmann
  2015-03-03 13:11     ` Aya Mahfouz
  2015-03-03 13:10   ` Aya Mahfouz
  1 sibling, 1 reply; 7+ messages in thread
From: Arnd Bergmann @ 2015-03-03 12:13 UTC (permalink / raw)
  To: outreachy-kernel; +Cc: Julia Lawall, Aya Mahfouz

On Tuesday 03 March 2015 07:01:47 Julia Lawall wrote:
> > -     ade7758_spi_read_reg_8(dev,
> > -                     ADE7758_OPMODE,
> > -                     &val);
> > +     ret = ade7758_spi_read_reg_8(dev, ADE7758_OPMODE, &val);
> > +     if (ret < 0) {
> > +             dev_err(dev, "failed to read from device");
> > +             goto error_ret;
> > +     }
> 

The ade7758_spi_read_reg_8 already prints an error message, I don't
think we want to see two messages about the same error.

	Arnd


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

* Re: [Outreachy kernel] [PATCH v3] staging: iio: meter: add check on return variables
  2015-03-03 12:01 ` Julia Lawall
  2015-03-03 12:13   ` Arnd Bergmann
@ 2015-03-03 13:10   ` Aya Mahfouz
  2015-03-03 22:37     ` Julia Lawall
  1 sibling, 1 reply; 7+ messages in thread
From: Aya Mahfouz @ 2015-03-03 13:10 UTC (permalink / raw)
  To: Julia Lawall; +Cc: outreachy-kernel

On Tue, Mar 03, 2015 at 07:01:47AM -0500, Julia Lawall wrote:
> On Tue, 3 Mar 2015, Aya Mahfouz wrote:
> 
> > Adds checks on variables that are used to return values. If
> > the value is less than zero, this indicates that an error
> > occured and hence a message is printed through dev_err. Labels
> > have been added too, since the check is done more than once.
> 
> How did you find the functions that have this property?
>
Do you mean that I should state that I found it using coccinelle?
> julia
> 
> > 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.
> >
> >  drivers/staging/iio/meter/ade7758_core.c | 35 ++++++++++++++++++++------------
> >  1 file changed, 22 insertions(+), 13 deletions(-)
> >
> > diff --git a/drivers/staging/iio/meter/ade7758_core.c b/drivers/staging/iio/meter/ade7758_core.c
> > index 70e96b2..cab392f 100644
> > --- a/drivers/staging/iio/meter/ade7758_core.c
> > +++ b/drivers/staging/iio/meter/ade7758_core.c
> > @@ -303,14 +303,18 @@ 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) {
> > +		dev_err(dev, "failed to read from device");
> > +		goto error_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);
> > +	if (ret < 0) {
> > +		dev_err(dev, "failed to reset device");
> > +		goto error_ret;
> > +	}
> > +error_ret:
> >  	return ret;
> >  }
> >
> > @@ -444,14 +448,19 @@ 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) {
> > +		dev_err(dev, "failed to read from device");
> > +		goto error_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);
> > +	if (ret < 0) {
> > +		dev_err(dev, "failed to stop device");
> > +		goto error_ret;
> > +	}
> >
> > +error_ret:
> >  	return ret;
> >  }
> >
> > --
> > 1.9.3
> >
> >
> > --
> > Kind Regards,
> > Aya Saif El-yazal Mahfouz
> >
> > --
> > You received this message because you are subscribed to the Google Groups "outreachy-kernel" group.
> > To unsubscribe from this group and stop receiving emails from it, send an email to outreachy-kernel+unsubscribe@googlegroups.com.
> > To post to this group, send email to outreachy-kernel@googlegroups.com.
> > To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/20150303112705.GA11879%40waves.
> > For more options, visit https://groups.google.com/d/optout.
> >

-- 
Kind Regards,
Aya Saif El-yazal Mahfouz


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

* Re: [Outreachy kernel] [PATCH v3] staging: iio: meter: add check on return variables
  2015-03-03 12:13   ` Arnd Bergmann
@ 2015-03-03 13:11     ` Aya Mahfouz
  0 siblings, 0 replies; 7+ messages in thread
From: Aya Mahfouz @ 2015-03-03 13:11 UTC (permalink / raw)
  To: Arnd Bergmann; +Cc: outreachy-kernel, Julia Lawall

On Tue, Mar 03, 2015 at 01:13:09PM +0100, Arnd Bergmann wrote:
> On Tuesday 03 March 2015 07:01:47 Julia Lawall wrote:
> > > -     ade7758_spi_read_reg_8(dev,
> > > -                     ADE7758_OPMODE,
> > > -                     &val);
> > > +     ret = ade7758_spi_read_reg_8(dev, ADE7758_OPMODE, &val);
> > > +     if (ret < 0) {
> > > +             dev_err(dev, "failed to read from device");
> > > +             goto error_ret;
> > > +     }
> > 
> 
> The ade7758_spi_read_reg_8 already prints an error message, I don't
> think we want to see two messages about the same error.
>
good to know. Thanks Arnd!
> 	Arnd

-- 
Kind Regards,
Aya Saif El-yazal Mahfouz


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

* Re: [Outreachy kernel] [PATCH v3] staging: iio: meter: add check on return variables
  2015-03-03 13:10   ` Aya Mahfouz
@ 2015-03-03 22:37     ` Julia Lawall
  0 siblings, 0 replies; 7+ messages in thread
From: Julia Lawall @ 2015-03-03 22:37 UTC (permalink / raw)
  To: Aya Mahfouz; +Cc: outreachy-kernel



On Tue, 3 Mar 2015, Aya Mahfouz wrote:

> On Tue, Mar 03, 2015 at 07:01:47AM -0500, Julia Lawall wrote:
> > On Tue, 3 Mar 2015, Aya Mahfouz wrote:
> >
> > > Adds checks on variables that are used to return values. If
> > > the value is less than zero, this indicates that an error
> > > occured and hence a message is printed through dev_err. Labels
> > > have been added too, since the check is done more than once.
> >
> > How did you find the functions that have this property?
> >
> Do you mean that I should state that I found it using coccinelle?

No, I meant that there are millions offunctions used in this code, so what
motivated you to look at these ones.  But the explanation you put in a
later message is fine.

julia


> > julia
> >
> > > 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.
> > >
> > >  drivers/staging/iio/meter/ade7758_core.c | 35 ++++++++++++++++++++------------
> > >  1 file changed, 22 insertions(+), 13 deletions(-)
> > >
> > > diff --git a/drivers/staging/iio/meter/ade7758_core.c b/drivers/staging/iio/meter/ade7758_core.c
> > > index 70e96b2..cab392f 100644
> > > --- a/drivers/staging/iio/meter/ade7758_core.c
> > > +++ b/drivers/staging/iio/meter/ade7758_core.c
> > > @@ -303,14 +303,18 @@ 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) {
> > > +		dev_err(dev, "failed to read from device");
> > > +		goto error_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);
> > > +	if (ret < 0) {
> > > +		dev_err(dev, "failed to reset device");
> > > +		goto error_ret;
> > > +	}
> > > +error_ret:
> > >  	return ret;
> > >  }
> > >
> > > @@ -444,14 +448,19 @@ 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) {
> > > +		dev_err(dev, "failed to read from device");
> > > +		goto error_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);
> > > +	if (ret < 0) {
> > > +		dev_err(dev, "failed to stop device");
> > > +		goto error_ret;
> > > +	}
> > >
> > > +error_ret:
> > >  	return ret;
> > >  }
> > >
> > > --
> > > 1.9.3
> > >
> > >
> > > --
> > > Kind Regards,
> > > Aya Saif El-yazal Mahfouz
> > >
> > > --
> > > You received this message because you are subscribed to the Google Groups "outreachy-kernel" group.
> > > To unsubscribe from this group and stop receiving emails from it, send an email to outreachy-kernel+unsubscribe@googlegroups.com.
> > > To post to this group, send email to outreachy-kernel@googlegroups.com.
> > > To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/20150303112705.GA11879%40waves.
> > > For more options, visit https://groups.google.com/d/optout.
> > >
>
> --
> Kind Regards,
> Aya Saif El-yazal Mahfouz
>


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

end of thread, other threads:[~2015-03-03 22:37 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-03-03 11:27 [PATCH v3] staging: iio: meter: add check on return variables Aya Mahfouz
     [not found] ` <CAEnQRZDFF_mvL=hUbC4T3S04kwUq1SZDqQdvWrd1_35Y8q_Uuw@mail.gmail.com>
2015-03-03 11:57   ` [Outreachy kernel] " Daniel Baluta
2015-03-03 12:01 ` Julia Lawall
2015-03-03 12:13   ` Arnd Bergmann
2015-03-03 13:11     ` Aya Mahfouz
2015-03-03 13:10   ` Aya Mahfouz
2015-03-03 22:37     ` Julia Lawall

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.