From: Carlos Jones Jr Date: Tue, 31 Mar 2026 01:24:57 +0000 (+0800) Subject: iio: adc: ltc2309: Optimize chip_info structure layout X-Git-Tag: v7.2-rc1~67^2~5^2~252 X-Git-Url: http://git.ipfire.org/gitweb/index.cgi?a=commitdiff_plain;h=7a89047a361c347cafe98f432d3df1686592ecce;p=thirdparty%2Flinux.git iio: adc: ltc2309: Optimize chip_info structure layout Improve the ltc2309_chip_info structure with better type safety and memory efficiency: - Add __counted_by_ptr() annotation to the channels pointer, linking it to num_channels for improved bounds checking and kernel hardening - Reorder structure fields to minimize padding: * Place read_delay_us before num_channels * This reduces struct size and eliminates internal gaps - Reorder field initialization to match the structure definition order The __counted_by_ptr() attribute enables compile-time and runtime verification that array accesses to channels[] stay within the bounds specified by num_channels, improving memory safety. Signed-off-by: Carlos Jones Jr Reviewed-by: Nuno Sá Reviewed-by: Andy Shevchenko Signed-off-by: Jonathan Cameron --- diff --git a/drivers/iio/adc/ltc2309.c b/drivers/iio/adc/ltc2309.c index 0949662899225..87b78d0353f19 100644 --- a/drivers/iio/adc/ltc2309.c +++ b/drivers/iio/adc/ltc2309.c @@ -121,22 +121,22 @@ static const struct iio_chan_spec ltc2309_channels[] = { struct ltc2309_chip_info { const char *name; - const struct iio_chan_spec *channels; unsigned int read_delay_us; int num_channels; + const struct iio_chan_spec *channels __counted_by_ptr(num_channels); }; static const struct ltc2309_chip_info ltc2305_chip_info = { .name = "ltc2305", - .channels = ltc2305_channels, .read_delay_us = 2, .num_channels = ARRAY_SIZE(ltc2305_channels), + .channels = ltc2305_channels, }; static const struct ltc2309_chip_info ltc2309_chip_info = { .name = "ltc2309", - .channels = ltc2309_channels, .num_channels = ARRAY_SIZE(ltc2309_channels), + .channels = ltc2309_channels, }; static int ltc2309_read_raw_channel(struct ltc2309 *ltc2309,