Skip to contentSkip to conversation

staging: iio: Add error code handling

PATCH In review Cristina Moraru 2 participants 5 messages Oct 21, 2015 – Oct 22, 2015

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 staging: iio: Add error code handling

Write function can return non-zero values indicating errors. This values must be caught and handled.

---
 drivers/staging/iio/addac/adt7316.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
drivers/staging/iio/addac/adt7316.c +7 -4
index 3adc451..6d67edf 100644
@@ -1850,10 +1850,11 @@ static ssize_t adt7316_set_int_mask(struct device *dev,
 		mask = ADT7316_INT_MASK2_VDD;	/* disable vdd int */
 
 	ret = chip->bus.write(chip->bus.client, ADT7316_INT_MASK2, mask);
-	if (!ret) {
-		chip->int_mask &= ~ADT7316_VDD_INT_MASK;
-		chip->int_mask |= data & ADT7316_VDD_INT_MASK;
-	}
+	if (ret)
+		return -EIO;
+
+	chip->int_mask &= ~ADT7316_VDD_INT_MASK;
+	chip->int_mask |= data & ADT7316_VDD_INT_MASK;
 
 	if (data & ADT7316_TEMP_AIN_INT_MASK) {
 		if ((chip->id & ID_FAMILY_MASK) == ID_ADT73XX)
@@ -1864,6 +1865,8 @@ static ssize_t adt7316_set_int_mask(struct device *dev,
 			mask = (~data) & ADT7316_TEMP_AIN_INT_MASK;
 	}
 	ret = chip->bus.write(chip->bus.client, ADT7316_INT_MASK1, mask);
+	if (ret)
+		return -EIO;
 
 	chip->int_mask = mask;
 
Signature · 1 line
1.9.1
#1 lore raw
Quoted 2 lines · Cristina Moraru

Write function can return non-zero values indicating errors. This values must be caught and handled.

Why? Sometimes it is possible to tolerate errors. At least in the first case it seems possible that the developer considered the possibility that an error occurred and felt that this was not a problem. Maybe it is correct that the errors are not tolearble, but more explanation is needed.

julia

Quoted 45 lines
---
 drivers/staging/iio/addac/adt7316.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
drivers/staging/iio/addac/adt7316.c +7 -4
index 3adc451..6d67edf 100644
@@ -1850,10 +1850,11 @@ static ssize_t adt7316_set_int_mask(struct device *dev,
 		mask = ADT7316_INT_MASK2_VDD;	/* disable vdd int */
 
 	ret = chip->bus.write(chip->bus.client, ADT7316_INT_MASK2, mask);
-	if (!ret) {
-		chip->int_mask &= ~ADT7316_VDD_INT_MASK;
-		chip->int_mask |= data & ADT7316_VDD_INT_MASK;
-	}
+	if (ret)
+		return -EIO;
+
+	chip->int_mask &= ~ADT7316_VDD_INT_MASK;
+	chip->int_mask |= data & ADT7316_VDD_INT_MASK;
 
 	if (data & ADT7316_TEMP_AIN_INT_MASK) {
 		if ((chip->id & ID_FAMILY_MASK) == ID_ADT73XX)
@@ -1864,6 +1865,8 @@ static ssize_t adt7316_set_int_mask(struct device *dev,
 			mask = (~data) & ADT7316_TEMP_AIN_INT_MASK;
 	}
 	ret = chip->bus.write(chip->bus.client, ADT7316_INT_MASK1, mask);
+	if (ret)
+		return -EIO;
 
 	chip->int_mask = mask;
 
Signature · 8 lines
1.9.1

-- 
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 [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/1445463010-3525-1-git-send-email-cristina.moraru09%40gmail.com.
For more options, visit https://groups.google.com/d/optout.
#2 lore raw

2015-10-22 9:43 GMT+03:00 Julia Lawall <[email protected]>:

Quoted 5 lines · Cristina Moraru
Quoted 3 lines

Write function can return non-zero values indicating errors. This values must be caught and handled.

Quoted 8 lines

Why? Sometimes it is possible to tolerate errors. At least in the first case it seems possible that the developer considered the possibility that an error occurred and felt that this was not a problem. Maybe it is correct that the errors are not tolearble, but more explanation is needed.

julia

I didn't know that there are errors that are tolerated and, analyzing the whole file, for me it looked like an error the fact that all functions were returning an error code when write function failed and this one didn't. Is there a way to figure out when a return value is ignored on purpose ?

Quoted 53 lines

Review

Quoted 7 lines
---
 drivers/staging/iio/addac/adt7316.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
(quoted diff) +0 -0

b/drivers/staging/iio/addac/adt7316.c

drivers/staging/iio/addac/adt7316.c static ssize_t adt7316_set_int_mask(struct

Quoted 4 lines

index 3adc451..6d67edf 100644

drivers/staging/iio/addac/adt7316.c +0 -0
@@ -1850,10 +1850,11 @@ static ssize_t adt7316_set_int_mask(struct

device *dev,

drivers/staging/iio/addac/adt7316.c static ssize_t adt7316_set_int_mask(struct device

Quoted 16 lines
drivers/staging/iio/addac/adt7316.c +5 -4
              mask = ADT7316_INT_MASK2_VDD;   /* disable vdd int */
 
      ret = chip->bus.write(chip->bus.client, ADT7316_INT_MASK2, mask);
-     if (!ret) {
-             chip->int_mask &= ~ADT7316_VDD_INT_MASK;
-             chip->int_mask |= data & ADT7316_VDD_INT_MASK;
-     }
+     if (ret)
+             return -EIO;
+
+     chip->int_mask &= ~ADT7316_VDD_INT_MASK;
+     chip->int_mask |= data & ADT7316_VDD_INT_MASK;
 
      if (data & ADT7316_TEMP_AIN_INT_MASK) {
              if ((chip->id & ID_FAMILY_MASK) == ID_ADT73XX)
@@ -1864,6 +1865,8 @@ static ssize_t adt7316_set_int_mask(struct device

*dev,

Quoted 11 lines
drivers/staging/iio/addac/adt7316.c +2 -1
                      mask = (~data) & ADT7316_TEMP_AIN_INT_MASK;
      }
      ret = chip->bus.write(chip->bus.client, ADT7316_INT_MASK1, mask);
+     if (ret)
+             return -EIO;
 
      chip->int_mask = mask;
 
--

1.9.1

Quoted 2 lines

--
You received this message because you are subscribed to the Google

Groups "outreachy-kernel" group.

Quoted 1 line

To unsubscribe from this group and stop receiving emails from it, send

an email to [email protected].

Quoted 2 lines

To post to this group, send email to [email protected]. To view this discussion on the web visit

https://groups.google.com/d/msgid/outreachy-kernel/1445463010-3525-1-git-send-email-cristina.moraru09%40gmail.com
.

Quoted 2 lines

For more options, visit https://groups.google.com/d/optout.

#3 lore raw
Quoted 17 lines · Cristina-Gabriela Moraru

2015-10-22 9:43 GMT+03:00 Julia Lawall <[email protected]>:
On Thu, 22 Oct 2015, Cristina Moraru wrote:

> Write function can return non-zero values indicating > errors. This values must be caught and handled.

Why?  Sometimes it is possible to tolerate errors.  At least in the first
case it seems possible that the developer considered the possibility that
an error occurred and felt that this was not a problem.  Maybe it is
correct that the errors are not tolearble, but more explanation is needed.

Quoted 7 lines

julia

I didn't know that there are errors that are tolerated and, analyzing the whole file, for me it looked like an error the fact that all functions were returning an error code when write function failed and this one didn't. Is there a way to figure out when a return value is ignored on purpose ?

I think you would have to understand the behavior of the device.

The fact that in one case there was a test on the return value and an action in the success case suggests that the developer thought about the failure case and decided that it isn't a problem.

The problem with a write is that the effect of the failure on the rest of the execution is not clear from the rest of the code. If a memory allocation fails and that is not tested for and there is a later access to the memory, then it is clear that there is a problem.

julia

Quoted 69 lines
      >
      > Signed-off-by: Cristina Moraru <[email protected]>
      > ---
      >  drivers/staging/iio/addac/adt7316.c | 11 +++++++----
      >  1 file changed, 7 insertions(+), 4 deletions(-)
      >
      > diff --git a/drivers/staging/iio/addac/adt7316.c
      b/drivers/staging/iio/addac/adt7316.c
      > index 3adc451..6d67edf 100644
      > --- a/drivers/staging/iio/addac/adt7316.c
      > +++ b/drivers/staging/iio/addac/adt7316.c
      > @@ -1850,10 +1850,11 @@ static ssize_t
      adt7316_set_int_mask(struct device *dev,
      >               mask = ADT7316_INT_MASK2_VDD;   /* disable vdd
      int */
      >
      >       ret = chip->bus.write(chip->bus.client,
      ADT7316_INT_MASK2, mask);
      > -     if (!ret) {
      > -             chip->int_mask &= ~ADT7316_VDD_INT_MASK;
      > -             chip->int_mask |= data & ADT7316_VDD_INT_MASK;
      > -     }
      > +     if (ret)
      > +             return -EIO;
      > +
      > +     chip->int_mask &= ~ADT7316_VDD_INT_MASK;
      > +     chip->int_mask |= data & ADT7316_VDD_INT_MASK;
      >
      >       if (data & ADT7316_TEMP_AIN_INT_MASK) {
      >               if ((chip->id & ID_FAMILY_MASK) == ID_ADT73XX)
      > @@ -1864,6 +1865,8 @@ static ssize_t
      adt7316_set_int_mask(struct device *dev,
      >                       mask = (~data) &
      ADT7316_TEMP_AIN_INT_MASK;
      >       }
      >       ret = chip->bus.write(chip->bus.client,
      ADT7316_INT_MASK1, mask);
      > +     if (ret)
      > +             return -EIO;
      >
      >       chip->int_mask = mask;
      >
      > --
      > 1.9.1
      >
Quoted 2 lines

--
You received this message because you are subscribed to the Google

Groups "outreachy-kernel" group.

Quoted 1 line

To unsubscribe from this group and stop receiving emails from it,

send an email to [email protected].

Quoted 1 line

To post to this group, send email to

[email protected].

Quoted 1 line

To view this discussion on the web visithttps://groups.google.com/d/msgid/outreachy-kernel/1445463010-3525-1-git-se

nd-email-cristina.moraru09%40gmail.com.

Quoted 2 lines

For more options, visit https://groups.google.com/d/optout.

--
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 [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visithttps://groups.google.com/d/msgid/outreachy-kernel/CAGZ2q2x9iTaFL3Lefy8PUbW e4OHqSQyV1W%3DPyrhZ8hgeM0C5ug%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

#4 lore raw

2015-10-22 11:16 GMT+03:00 Julia Lawall <[email protected]>:

Quoted 34 lines · Cristina-Gabriela Moraru
Quoted 18 lines

2015-10-22 9:43 GMT+03:00 Julia Lawall <[email protected]>:
On Thu, 22 Oct 2015, Cristina Moraru wrote:

> Write function can return non-zero values indicating > errors. This values must be caught and handled.

Why? Sometimes it is possible to tolerate errors. At least in the first
case it seems possible that the developer considered the possibility that
an error occurred and felt that this was not a problem. Maybe it is
correct that the errors are not tolearble, but more explanation is needed.

Quoted 5 lines

julia

I didn't know that there are errors that are tolerated and, analyzing the whole file, for me it looked like an error the fact that all functions

were

Quoted 2 lines

returning an error code when write function failed and this one didn't. Is there a way to figure out when a return value is ignored on purpose ?

I think you would have to understand the behavior of the device.

The fact that in one case there was a test on the return value and an action in the success case suggests that the developer thought about the failure case and decided that it isn't a problem.

Quoted 8 lines

The problem with a write is that the effect of the failure on the rest of the execution is not clear from the rest of the code. If a memory allocation fails and that is not tested for and there is a later access to the memory, then it is clear that there is a problem.

julia

Ok. Understood. Thanks !

Cristina

Quoted 73 lines
Quoted 46 lines
      >
      > Signed-off-by: Cristina Moraru <[email protected]>
      > ---
      >  drivers/staging/iio/addac/adt7316.c | 11 +++++++----
      >  1 file changed, 7 insertions(+), 4 deletions(-)
      >
      > diff --git a/drivers/staging/iio/addac/adt7316.c
      b/drivers/staging/iio/addac/adt7316.c
      > index 3adc451..6d67edf 100644
      > --- a/drivers/staging/iio/addac/adt7316.c
      > +++ b/drivers/staging/iio/addac/adt7316.c
      > @@ -1850,10 +1850,11 @@ static ssize_t
      adt7316_set_int_mask(struct device *dev,
      >               mask = ADT7316_INT_MASK2_VDD;   /* disable vdd
      int */
      >
      >       ret = chip->bus.write(chip->bus.client,
      ADT7316_INT_MASK2, mask);
      > -     if (!ret) {
      > -             chip->int_mask &= ~ADT7316_VDD_INT_MASK;
      > -             chip->int_mask |= data & ADT7316_VDD_INT_MASK;
      > -     }
      > +     if (ret)
      > +             return -EIO;
      > +
      > +     chip->int_mask &= ~ADT7316_VDD_INT_MASK;
      > +     chip->int_mask |= data & ADT7316_VDD_INT_MASK;
      >
      >       if (data & ADT7316_TEMP_AIN_INT_MASK) {
      >               if ((chip->id & ID_FAMILY_MASK) == ID_ADT73XX)
      > @@ -1864,6 +1865,8 @@ static ssize_t
      adt7316_set_int_mask(struct device *dev,
      >                       mask = (~data) &
      ADT7316_TEMP_AIN_INT_MASK;
      >       }
      >       ret = chip->bus.write(chip->bus.client,
      ADT7316_INT_MASK1, mask);
      > +     if (ret)
      > +             return -EIO;
      >
      >       chip->int_mask = mask;
      >
      > --
      > 1.9.1
      >
Quoted 8 lines
Quoted 2 lines

--
You received this message because you are subscribed to the Google

Groups "outreachy-kernel" group.

Quoted 1 line

To unsubscribe from this group and stop receiving emails from it,

send an email to [email protected].

Quoted 1 line

To post to this group, send email to

[email protected].

Quoted 1 line

To view this discussion on the web visithttps://

groups.google.com/d/msgid/outreachy-kernel/1445463010-3525-1-git-se

Quoted 5 lines

nd-email-cristina.moraru09%40gmail.com.

Quoted 2 lines

For more options, visit https://groups.google.com/d/optout.

Quoted 7 lines

--
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 [email protected].
To post to this group, send email to [email protected]. To view this discussion on the web visithttps://

groups.google.com/d/msgid/outreachy-kernel/CAGZ2q2x9iTaFL3Lefy8PUbW

Quoted 4 lines

e4OHqSQyV1W%3DPyrhZ8hgeM0C5ug%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.