Linux IIO development
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: David Lechner <dlechner@baylibre.com>
Cc: "Dan Carpenter" <dan.carpenter@linaro.org>,
	oe-kbuild@lists.linux.dev, linux-iio@vger.kernel.org,
	lkp@intel.com, oe-kbuild-all@lists.linux.dev,
	"Michael Hennerich" <Michael.Hennerich@analog.com>,
	"Angelo Dureghello" <adureghello@baylibre.com>,
	"Alexandru Ardelean" <aardelean@baylibre.com>,
	"Beniamin Bia" <beniamin.bia@analog.com>,
	"Stefan Popa" <stefan.popa@analog.com>,
	linux-kernel@vger.kernel.org, "Nuno Sá" <nuno.sa@analog.com>
Subject: Re: [PATCH v2 09/10] iio: adc: ad7606: dynamically allocate channel info
Date: Sun, 30 Mar 2025 19:07:03 +0100	[thread overview]
Message-ID: <20250330190703.51e97942@jic23-huawei> (raw)
In-Reply-To: <4854b569-5032-4b75-80a6-8c5822845dc7@baylibre.com>

On Mon, 24 Mar 2025 08:50:15 -0500
David Lechner <dlechner@baylibre.com> wrote:

> On 3/22/25 12:25 PM, Dan Carpenter wrote:
> > Hi David,
> > 
> > kernel test robot noticed the following build warnings:
> > 
> > url:    https://github.com/intel-lab-lkp/linux/commits/David-Lechner/iio-adc-ad7606-check-for-NULL-before-calling-sw_mode_config/20250319-065737
> > base:   9f36acefb2621d980734a5bb7d74e0e24e0af166
> > patch link:    https://lore.kernel.org/r/20250318-iio-adc-ad7606-improvements-v2-9-4b605427774c%40baylibre.com
> > patch subject: [PATCH v2 09/10] iio: adc: ad7606: dynamically allocate channel info
> > config: arm64-randconfig-r071-20250322 (https://download.01.org/0day-ci/archive/20250322/202503222246.RafigmhQ-lkp@intel.com/config)
> > compiler: clang version 21.0.0git (https://github.com/llvm/llvm-project c2692afc0a92cd5da140dfcdfff7818a5b8ce997)
> > 
> > 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@intel.com>
> > | Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
> > | Closes: https://lore.kernel.org/r/202503222246.RafigmhQ-lkp@intel.com/
> > 
> > smatch warnings:
> > drivers/iio/adc/ad7606.c:1270 ad7606_probe_channels() warn: potentially one past the end of array 'channels[i]'
> > 
> > vim +1270 drivers/iio/adc/ad7606.c
> > 
> > 87cf5705725eeb David Lechner      2025-03-18  1196  static int ad7606_probe_channels(struct iio_dev *indio_dev)
> > e571c1902116a3 Alexandru Ardelean 2024-09-19  1197  {
> > e571c1902116a3 Alexandru Ardelean 2024-09-19  1198  	struct ad7606_state *st = iio_priv(indio_dev);
> > 87cf5705725eeb David Lechner      2025-03-18  1199  	struct device *dev = indio_dev->dev.parent;
> > 87cf5705725eeb David Lechner      2025-03-18  1200  	struct iio_chan_spec *channels;
> > 87cf5705725eeb David Lechner      2025-03-18  1201  	bool slow_bus;
> > 87cf5705725eeb David Lechner      2025-03-18  1202  	int ret, i;
> > 87cf5705725eeb David Lechner      2025-03-18  1203  
> > 87cf5705725eeb David Lechner      2025-03-18  1204  	slow_bus = !st->bops->iio_backend_config;
> > 87cf5705725eeb David Lechner      2025-03-18  1205  	indio_dev->num_channels = st->chip_info->num_adc_channels;
> > 87cf5705725eeb David Lechner      2025-03-18  1206  
> > 87cf5705725eeb David Lechner      2025-03-18  1207  	/* Slow buses also get 1 more channel for soft timestamp */
> > 87cf5705725eeb David Lechner      2025-03-18  1208  	if (slow_bus)
> > 87cf5705725eeb David Lechner      2025-03-18  1209  		indio_dev->num_channels++;
> > 87cf5705725eeb David Lechner      2025-03-18  1210  
> > 87cf5705725eeb David Lechner      2025-03-18  1211  	channels = devm_kcalloc(dev, indio_dev->num_channels, sizeof(*channels),
> > 87cf5705725eeb David Lechner      2025-03-18  1212  				GFP_KERNEL);
> > 87cf5705725eeb David Lechner      2025-03-18  1213  	if (!channels)
> > f3838e934dfff2 Alexandru Ardelean 2024-09-19  1214  		return -ENOMEM;
> > f3838e934dfff2 Alexandru Ardelean 2024-09-19  1215  
> > 87cf5705725eeb David Lechner      2025-03-18  1216  	for (i = 0; i < indio_dev->num_channels; i++) {  
> 
> The fix is to change this line to:
> 
> 							for (i = 0; i < st->chip_info->num_adc_channels; i++) {
> 
Tweaked and applied.

> > 87cf5705725eeb David Lechner      2025-03-18  1217  		struct iio_chan_spec *chan = &channels[i];
> > 87cf5705725eeb David Lechner      2025-03-18  1218  
> > 87cf5705725eeb David Lechner      2025-03-18  1219  		chan->type = IIO_VOLTAGE;
> > 87cf5705725eeb David Lechner      2025-03-18  1220  		chan->indexed = 1;
> > 87cf5705725eeb David Lechner      2025-03-18  1221  		chan->channel = i;
> > 87cf5705725eeb David Lechner      2025-03-18  1222  		chan->scan_index = i;
> > 87cf5705725eeb David Lechner      2025-03-18  1223  		chan->scan_type.sign = 's';
> > 87cf5705725eeb David Lechner      2025-03-18  1224  		chan->scan_type.realbits = st->chip_info->bits;
> > 87cf5705725eeb David Lechner      2025-03-18  1225  		chan->scan_type.storagebits = st->chip_info->bits > 16 ? 32 : 16;
> > 87cf5705725eeb David Lechner      2025-03-18  1226  		chan->scan_type.endianness = IIO_CPU;
> > f3838e934dfff2 Alexandru Ardelean 2024-09-19  1227  
> > 87cf5705725eeb David Lechner      2025-03-18  1228  		if (indio_dev->modes & INDIO_DIRECT_MODE)
> > 87cf5705725eeb David Lechner      2025-03-18  1229  			chan->info_mask_separate |= BIT(IIO_CHAN_INFO_RAW);
> > 87cf5705725eeb David Lechner      2025-03-18  1230  
> > 87cf5705725eeb David Lechner      2025-03-18  1231  		if (st->sw_mode_en) {
> > 87cf5705725eeb David Lechner      2025-03-18  1232  			chan->info_mask_separate |= BIT(IIO_CHAN_INFO_SCALE);
> > 87cf5705725eeb David Lechner      2025-03-18  1233  			chan->info_mask_separate_available |=
> > 87cf5705725eeb David Lechner      2025-03-18  1234  				BIT(IIO_CHAN_INFO_SCALE);
> > 87cf5705725eeb David Lechner      2025-03-18  1235  
> > 87cf5705725eeb David Lechner      2025-03-18  1236  			/*
> > 87cf5705725eeb David Lechner      2025-03-18  1237  			 * All chips with software mode support oversampling,
> > 87cf5705725eeb David Lechner      2025-03-18  1238  			 * so we skip the oversampling_available check. And the
> > 87cf5705725eeb David Lechner      2025-03-18  1239  			 * shared_by_type instead of shared_by_all on slow
> > 87cf5705725eeb David Lechner      2025-03-18  1240  			 * buses is for backward compatibility.
> > 87cf5705725eeb David Lechner      2025-03-18  1241  			 */
> > 87cf5705725eeb David Lechner      2025-03-18  1242  			if (slow_bus)
> > 87cf5705725eeb David Lechner      2025-03-18  1243  				chan->info_mask_shared_by_type |=
> > 87cf5705725eeb David Lechner      2025-03-18  1244  					BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO);
> > 87cf5705725eeb David Lechner      2025-03-18  1245  			else
> > 87cf5705725eeb David Lechner      2025-03-18  1246  				chan->info_mask_shared_by_all |=
> > 87cf5705725eeb David Lechner      2025-03-18  1247  					BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO);
> > 87cf5705725eeb David Lechner      2025-03-18  1248  
> > 87cf5705725eeb David Lechner      2025-03-18  1249  			chan->info_mask_shared_by_all_available |=
> > 87cf5705725eeb David Lechner      2025-03-18  1250  				BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO);
> > 87cf5705725eeb David Lechner      2025-03-18  1251  		} else {
> > 87cf5705725eeb David Lechner      2025-03-18  1252  			chan->info_mask_shared_by_type |=
> > 87cf5705725eeb David Lechner      2025-03-18  1253  				BIT(IIO_CHAN_INFO_SCALE);
> > 87cf5705725eeb David Lechner      2025-03-18  1254  
> > 87cf5705725eeb David Lechner      2025-03-18  1255  			if (st->chip_info->oversampling_avail)
> > 87cf5705725eeb David Lechner      2025-03-18  1256  				chan->info_mask_shared_by_all |=
> > 87cf5705725eeb David Lechner      2025-03-18  1257  					BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO);
> > 87cf5705725eeb David Lechner      2025-03-18  1258  		}
> > 87cf5705725eeb David Lechner      2025-03-18  1259  
> > 87cf5705725eeb David Lechner      2025-03-18  1260  		if (!slow_bus)
> > 87cf5705725eeb David Lechner      2025-03-18  1261  			chan->info_mask_shared_by_all |=
> > 87cf5705725eeb David Lechner      2025-03-18  1262  				BIT(IIO_CHAN_INFO_SAMP_FREQ);
> > 87cf5705725eeb David Lechner      2025-03-18  1263  
> > 87cf5705725eeb David Lechner      2025-03-18  1264  		ret = st->chip_info->scale_setup_cb(indio_dev, chan);
> > e571c1902116a3 Alexandru Ardelean 2024-09-19  1265  		if (ret)
> > e571c1902116a3 Alexandru Ardelean 2024-09-19  1266  			return ret;
> > e571c1902116a3 Alexandru Ardelean 2024-09-19  1267  	}
> > e571c1902116a3 Alexandru Ardelean 2024-09-19  1268  
> > 87cf5705725eeb David Lechner      2025-03-18  1269  	if (slow_bus)
> > 87cf5705725eeb David Lechner      2025-03-18 @1270  		channels[i] = (struct iio_chan_spec)IIO_CHAN_SOFT_TIMESTAMP(i);
> >                                                                 ^^^^^^^^^^^
> > i is == indio_dev->num_channels so this is out of bounds by one element.
> > 
> > 87cf5705725eeb David Lechner      2025-03-18  1271  
> > 87cf5705725eeb David Lechner      2025-03-18  1272  	indio_dev->channels = channels;
> > 87cf5705725eeb David Lechner      2025-03-18  1273  
> > e571c1902116a3 Alexandru Ardelean 2024-09-19  1274  	return 0;
> > e571c1902116a3 Alexandru Ardelean 2024-09-19  1275  }
> >   
> 


  reply	other threads:[~2025-03-30 18:07 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-18 22:52 [PATCH v2 00/10] iio: adc: ad7606: improvements and ad7606c parallel interface support David Lechner
2025-03-18 22:52 ` [PATCH v2 01/10] iio: adc: ad7606: check for NULL before calling sw_mode_config() David Lechner
2025-03-30 17:56   ` Jonathan Cameron
2025-03-18 22:52 ` [PATCH v2 02/10] iio: adc: ad7606_spi: check error in ad7606B_sw_mode_config() David Lechner
2025-03-30 17:58   ` Jonathan Cameron
2025-03-18 22:52 ` [PATCH v2 03/10] iio: adc: ad7606: add missing max sample rates David Lechner
2025-03-18 22:52 ` [PATCH v2 04/10] iio: adc: ad7606: use devm_mutex_init() David Lechner
2025-03-18 22:52 ` [PATCH v2 05/10] iio: adc: ad7606: fix kernel-doc comments David Lechner
2025-03-18 22:52 ` [PATCH v2 06/10] iio: adc: ad7606: use kernel identifier name style David Lechner
2025-03-18 22:52 ` [PATCH v2 07/10] iio: adc: ad7606: don't use address field David Lechner
2025-03-18 22:52 ` [PATCH v2 08/10] iio: adc: ad7606: drop ch param from ad7606_scale_setup_cb_t David Lechner
2025-03-30 18:01   ` Jonathan Cameron
2025-03-18 22:52 ` [PATCH v2 09/10] iio: adc: ad7606: dynamically allocate channel info David Lechner
2025-03-22 17:25   ` Dan Carpenter
2025-03-24 13:50     ` David Lechner
2025-03-30 18:07       ` Jonathan Cameron [this message]
2025-03-18 22:52 ` [PATCH v2 10/10] iio: adc: ad7606_par: add ad7606c chips David Lechner
2025-03-30 18:08   ` Jonathan Cameron

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250330190703.51e97942@jic23-huawei \
    --to=jic23@kernel.org \
    --cc=Michael.Hennerich@analog.com \
    --cc=aardelean@baylibre.com \
    --cc=adureghello@baylibre.com \
    --cc=beniamin.bia@analog.com \
    --cc=dan.carpenter@linaro.org \
    --cc=dlechner@baylibre.com \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lkp@intel.com \
    --cc=nuno.sa@analog.com \
    --cc=oe-kbuild-all@lists.linux.dev \
    --cc=oe-kbuild@lists.linux.dev \
    --cc=stefan.popa@analog.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox