[iio:testing 26/30] drivers/iio/adc/at91-sama5d2_adc.c:722:11: warning: variable 'val' is used uninitialized whenever 'if' condition is false

From: kernel test robot
Date: Mon Aug 30 2021 - 13:57:46 EST


tree: https://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio.git testing
head: 4fd351a1ce67ab1229d392047c3ef8e524dab3dd
commit: 29edec2b98fff8ce5145a8585dfc363564704d14 [26/30] iio: adc: at91-sama5d2_adc: convert to platform specific data structures
config: hexagon-buildonly-randconfig-r004-20210830 (attached as .config)
compiler: clang version 14.0.0 (https://github.com/llvm/llvm-project 4b1fde8a2b681dad2ce0c082a5d6422caa06b0bc)
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# https://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio.git/commit/?id=29edec2b98fff8ce5145a8585dfc363564704d14
git remote add iio https://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio.git
git fetch --no-tags iio testing
git checkout 29edec2b98fff8ce5145a8585dfc363564704d14
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=hexagon

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@xxxxxxxxx>

All warnings (new ones prefixed by >>):

>> drivers/iio/adc/at91-sama5d2_adc.c:722:11: warning: variable 'val' is used uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized]
else if (reg == st->soc_info.platform->layout->YPOSR)
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/iio/adc/at91-sama5d2_adc.c:725:7: note: uninitialized use occurs here
if (!val)
^~~
drivers/iio/adc/at91-sama5d2_adc.c:722:7: note: remove the 'if' if its condition is always true
else if (reg == st->soc_info.platform->layout->YPOSR)
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/iio/adc/at91-sama5d2_adc.c:711:9: note: initialize the variable 'val' to silence this warning
u32 val;
^
= 0
1 warning generated.


vim +722 drivers/iio/adc/at91-sama5d2_adc.c

708
709 static u16 at91_adc_touch_pos(struct at91_adc_state *st, int reg)
710 {
711 u32 val;
712 u32 scale, result, pos;
713
714 /*
715 * to obtain the actual position we must divide by scale
716 * and multiply with max, where
717 * max = 2^AT91_SAMA5D2_MAX_POS_BITS - 1
718 */
719 /* first half of register is the x or y, second half is the scale */
720 if (reg == st->soc_info.platform->layout->XPOSR)
721 val = at91_adc_readl(st, XPOSR);
> 722 else if (reg == st->soc_info.platform->layout->YPOSR)
723 val = at91_adc_readl(st, YPOSR);
724
725 if (!val)
726 dev_dbg(&st->indio_dev->dev, "pos is 0\n");
727
728 pos = val & AT91_SAMA5D2_XYZ_MASK;
729 result = (pos << AT91_SAMA5D2_MAX_POS_BITS) - pos;
730 scale = (val >> 16) & AT91_SAMA5D2_XYZ_MASK;
731 if (scale == 0) {
732 dev_err(&st->indio_dev->dev, "scale is 0\n");
733 return 0;
734 }
735 result /= scale;
736
737 return result;
738 }
739

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@xxxxxxxxxxxx

Attachment: .config.gz
Description: application/gzip