Re: [PATCH v3 2/6] iio: adc: ad4030: add driver for ad4030-24

From: Dan Carpenter
Date: Sun Feb 02 2025 - 07:31:12 EST


Hi Esteban,

kernel test robot noticed the following build warnings:

url: https://github.com/intel-lab-lkp/linux/commits/Esteban-Blanc/dt-bindings-iio-adc-add-ADI-ad4030-ad4630-and-ad4632/20250130-191153
base: ffd294d346d185b70e28b1a28abe367bbfe53c04
patch link: https://lore.kernel.org/r/20250130-eblanc-ad4630_v1-v3-2-052e8c2d897d%40baylibre.com
patch subject: [PATCH v3 2/6] iio: adc: ad4030: add driver for ad4030-24
config: um-randconfig-r071-20250202 (https://download.01.org/0day-ci/archive/20250202/202502021354.T5JOCCcy-lkp@xxxxxxxxx/config)
compiler: gcc-12 (Debian 12.2.0-14) 12.2.0

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@xxxxxxxxx>
| Reported-by: Dan Carpenter <dan.carpenter@xxxxxxxxxx>
| Closes: https://lore.kernel.org/r/202502021354.T5JOCCcy-lkp@xxxxxxxxx/

smatch warnings:
drivers/iio/adc/ad4030.c:263 ad4030_spi_read() warn: calling memset(x, y, ARRAY_SIZE());

vim +263 drivers/iio/adc/ad4030.c

8cfce061c9e580 Esteban Blanc 2025-01-30 242 static int ad4030_spi_read(void *context, const void *reg, size_t reg_size,
8cfce061c9e580 Esteban Blanc 2025-01-30 243 void *val, size_t val_size)
8cfce061c9e580 Esteban Blanc 2025-01-30 244 {
8cfce061c9e580 Esteban Blanc 2025-01-30 245 int ret;
8cfce061c9e580 Esteban Blanc 2025-01-30 246 struct ad4030_state *st = context;
8cfce061c9e580 Esteban Blanc 2025-01-30 247 struct spi_transfer xfer = {
8cfce061c9e580 Esteban Blanc 2025-01-30 248 .tx_buf = st->tx_data,
8cfce061c9e580 Esteban Blanc 2025-01-30 249 .rx_buf = st->rx_data.raw,
8cfce061c9e580 Esteban Blanc 2025-01-30 250 .bits_per_word = 8,
8cfce061c9e580 Esteban Blanc 2025-01-30 251 .len = reg_size + val_size,
8cfce061c9e580 Esteban Blanc 2025-01-30 252 .speed_hz = AD4030_SPI_MAX_REG_XFER_SPEED,
8cfce061c9e580 Esteban Blanc 2025-01-30 253 };
8cfce061c9e580 Esteban Blanc 2025-01-30 254
8cfce061c9e580 Esteban Blanc 2025-01-30 255 if (xfer.len > ARRAY_SIZE(st->tx_data) ||

These ARRAY_SIZE() checks work fine before ->tx_data is a u8 but really
is should be sizeof().

8cfce061c9e580 Esteban Blanc 2025-01-30 256 xfer.len > ARRAY_SIZE(st->rx_data.raw))

Same.

8cfce061c9e580 Esteban Blanc 2025-01-30 257 return -EINVAL;
8cfce061c9e580 Esteban Blanc 2025-01-30 258
8cfce061c9e580 Esteban Blanc 2025-01-30 259 ret = ad4030_enter_config_mode(st);
8cfce061c9e580 Esteban Blanc 2025-01-30 260 if (ret)
8cfce061c9e580 Esteban Blanc 2025-01-30 261 return ret;
8cfce061c9e580 Esteban Blanc 2025-01-30 262
8cfce061c9e580 Esteban Blanc 2025-01-30 @263 memset(st->tx_data, 0, ARRAY_SIZE(st->tx_data));
^^^^^^^^^^^^^^^^^^^^^^^
same.

8cfce061c9e580 Esteban Blanc 2025-01-30 264 memcpy(st->tx_data, reg, reg_size);
8cfce061c9e580 Esteban Blanc 2025-01-30 265
8cfce061c9e580 Esteban Blanc 2025-01-30 266 ret = spi_sync_transfer(st->spi, &xfer, 1);
8cfce061c9e580 Esteban Blanc 2025-01-30 267 if (ret)
8cfce061c9e580 Esteban Blanc 2025-01-30 268 return ret;
8cfce061c9e580 Esteban Blanc 2025-01-30 269
8cfce061c9e580 Esteban Blanc 2025-01-30 270 memcpy(val, &st->rx_data.raw[reg_size], val_size);
8cfce061c9e580 Esteban Blanc 2025-01-30 271
8cfce061c9e580 Esteban Blanc 2025-01-30 272 return ad4030_exit_config_mode(st);
8cfce061c9e580 Esteban Blanc 2025-01-30 273 }

--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki