staging: iio: meter: add check on return variables
authorAya Mahfouz <mahfouz.saif.elyazal@gmail.com>
Tue, 3 Mar 2015 14:27:37 +0000 (16:27 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 6 Mar 2015 17:54:33 +0000 (09:54 -0800)
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>
Reviewed-by: Daniel Baluta <daniel.baluta@intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/iio/meter/ade7758_core.c

index 70e96b20c2ebfbc8f57e6f280ddc4a9989bffce3..7e287dae7b444e903136facdbd091d5031127753 100644 (file)
@@ -303,14 +303,15 @@ 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 opmode reg\n");
+               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);
+       if (ret < 0)
+               dev_err(dev, "Failed to write opmode reg\n");
        return ret;
 }
 
@@ -444,14 +445,15 @@ 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 opmode reg\n");
+               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);
+       if (ret < 0)
+               dev_err(dev, "Failed to write opmode reg\n");
        return ret;
 }