Skip to content

Commit 7e1da86

Browse files
arndbjic23
authored andcommitted
iio: ade7753: avoid uninitialized data
The ade7753_spi_read_reg_16() will either successfully read a value from SPI, or return a failure code without delivering data. However, the ade7753_stop_device() and ade7753_reset() functions use the returned data without checking for an error condition first. Gcc detects this as a possible bug and warns about it: drivers/staging/iio/meter/ade7753.c: In function 'ade7753_remove': drivers/staging/iio/meter/ade7753.c:348:6: error: 'val' may be used uninitialized in this function [-Werror=maybe-uninitialized] val |= BIT(4); /* AD converters can be turned off */ ^ drivers/staging/iio/meter/ade7753.c:345:6: note: 'val' was declared here u16 val; ^ drivers/staging/iio/meter/ade7753.c: In function 'ade7753_probe': drivers/staging/iio/meter/ade7753.c:222:6: error: 'val' may be used uninitialized in this function [-Werror=maybe-uninitialized] In both cases, we can avoids the warning by checking the return code before using the data. Signed-off-by: Arnd Bergmann <[email protected]> Signed-off-by: Jonathan Cameron <[email protected]>
1 parent 431386e commit 7e1da86

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

drivers/staging/iio/meter/ade7753.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,8 +217,12 @@ static ssize_t ade7753_write_16bit(struct device *dev,
217217
static int ade7753_reset(struct device *dev)
218218
{
219219
u16 val;
220+
int ret;
221+
222+
ret = ade7753_spi_read_reg_16(dev, ADE7753_MODE, &val);
223+
if (ret)
224+
return ret;
220225

221-
ade7753_spi_read_reg_16(dev, ADE7753_MODE, &val);
222226
val |= BIT(6); /* Software Chip Reset */
223227

224228
return ade7753_spi_write_reg_16(dev, ADE7753_MODE, val);
@@ -343,8 +347,12 @@ static int ade7753_set_irq(struct device *dev, bool enable)
343347
static int ade7753_stop_device(struct device *dev)
344348
{
345349
u16 val;
350+
int ret;
351+
352+
ret = ade7753_spi_read_reg_16(dev, ADE7753_MODE, &val);
353+
if (ret)
354+
return ret;
346355

347-
ade7753_spi_read_reg_16(dev, ADE7753_MODE, &val);
348356
val |= BIT(4); /* AD converters can be turned off */
349357

350358
return ade7753_spi_write_reg_16(dev, ADE7753_MODE, val);

0 commit comments

Comments
 (0)