]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
iio: adc: ltc2309: Optimize chip_info structure layout
authorCarlos Jones Jr <carlosjr.jones@analog.com>
Tue, 31 Mar 2026 01:24:57 +0000 (09:24 +0800)
committerJonathan Cameron <jic23@kernel.org>
Mon, 27 Apr 2026 08:58:17 +0000 (09:58 +0100)
commit7a89047a361c347cafe98f432d3df1686592ecce
treed8f65ea58dbddc4c9e386fe99d7bbabea3673fb1
parent671b8541c7d62818e0fb8ac7fe8a4086fc7c842e
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 <carlosjr.jones@analog.com>
Reviewed-by: Nuno Sá <nuno.sa@analog.com>
Reviewed-by: Andy Shevchenko <andy@kernel.org>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
drivers/iio/adc/ltc2309.c