Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

staging: iio: ad5933: avoid uninitialized variable in error case

The ad5933_i2c_read function returns an error code to indicate
whether it could read data or not. However ad5933_work() ignores
this return code and just accesses the data unconditionally,
which gets detected by gcc as a possible bug:

drivers/staging/iio/impedance-analyzer/ad5933.c: In function 'ad5933_work':
drivers/staging/iio/impedance-analyzer/ad5933.c:649:16: warning: 'status' may be used uninitialized in this function [-Wmaybe-uninitialized]

This adds minimal error handling so we only evaluate the
data if it was correctly read.

Link: https://patchwork.kernel.org/patch/8110281/
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Acked-by: Lars-Peter Clausen <lars@metafoo.de>
Cc: <Stable@vger.kernel.org>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>

authored by

Arnd Bergmann and committed by
Jonathan Cameron
34eee70a e866dd8a

+10 -7
+10 -7
drivers/staging/iio/impedance-analyzer/ad5933.c
··· 655 655 __be16 buf[2]; 656 656 int val[2]; 657 657 unsigned char status; 658 + int ret; 658 659 659 660 mutex_lock(&indio_dev->mlock); 660 661 if (st->state == AD5933_CTRL_INIT_START_FREQ) { ··· 663 662 ad5933_cmd(st, AD5933_CTRL_START_SWEEP); 664 663 st->state = AD5933_CTRL_START_SWEEP; 665 664 schedule_delayed_work(&st->work, st->poll_time_jiffies); 666 - mutex_unlock(&indio_dev->mlock); 667 - return; 665 + goto out; 668 666 } 669 667 670 - ad5933_i2c_read(st->client, AD5933_REG_STATUS, 1, &status); 668 + ret = ad5933_i2c_read(st->client, AD5933_REG_STATUS, 1, &status); 669 + if (ret) 670 + goto out; 671 671 672 672 if (status & AD5933_STAT_DATA_VALID) { 673 673 int scan_count = bitmap_weight(indio_dev->active_scan_mask, 674 674 indio_dev->masklength); 675 - ad5933_i2c_read(st->client, 675 + ret = ad5933_i2c_read(st->client, 676 676 test_bit(1, indio_dev->active_scan_mask) ? 677 677 AD5933_REG_REAL_DATA : AD5933_REG_IMAG_DATA, 678 678 scan_count * 2, (u8 *)buf); 679 + if (ret) 680 + goto out; 679 681 680 682 if (scan_count == 2) { 681 683 val[0] = be16_to_cpu(buf[0]); ··· 690 686 } else { 691 687 /* no data available - try again later */ 692 688 schedule_delayed_work(&st->work, st->poll_time_jiffies); 693 - mutex_unlock(&indio_dev->mlock); 694 - return; 689 + goto out; 695 690 } 696 691 697 692 if (status & AD5933_STAT_SWEEP_DONE) { ··· 703 700 ad5933_cmd(st, AD5933_CTRL_INC_FREQ); 704 701 schedule_delayed_work(&st->work, st->poll_time_jiffies); 705 702 } 706 - 703 + out: 707 704 mutex_unlock(&indio_dev->mlock); 708 705 } 709 706