RE: [PATCH v2 1/4] iio: adc: ltc2309: Introduce chip_info structure
From: Jones, Carlos jr
Date: Tue Mar 24 2026 - 20:02:23 EST
> On Tue, Mar 24, 2026 at 03:13:28PM +0800, Carlos Jones Jr wrote:
> > Introduce a chip_info structure to facilitate adding support for chip
> > variants with different channel configurations and timing
> > requirements.
> >
> > The chip_info structure contains:
> > - Device name for proper sysfs identification
> > - Channel specifications and count
> > - Read delay timing for variants requiring settling time
> >
> > The ltc2309 struct is modified to store only the read_delay_us value
> > rather than a pointer to the full chip_info, as this is the only
> > runtime-accessed field after probe.
> >
> > This preparatory refactoring does not modify existing LTC2309
> > functionality.
>
> ...
> > +struct ltc2309_chip_info {
> > + const char *name;
> > + unsigned int num_channels;
> > + const struct iio_chan_spec *channels
> __counted_by_ptr(num_channels);
> > + unsigned int read_delay_us;
>
> Now on some architectures this might have gaps. Have you run `pahole`?
> Even if it's fine, I would rather see
>
> const char *name;
> const struct iio_chan_spec *channels
> __counted_by_ptr(num_channels);
> unsigned int num_channels;
> unsigned int read_delay_us;
>
> OR (if there are limitations of __counted_by_ptr() attribute)
>
> const char *name;
> unsigned int read_delay_us;
> unsigned int num_channels;
> const struct iio_chan_spec *channels
> __counted_by_ptr(num_channels);
>
> > +};
> ...
Thanks, Andy. The previous arrangement has hole but the latter of the
two recommendations above have none (pahole output shown below).
I will update accordingly.
struct ltc2309_chip_info {
const char * name; /* 0 8 */
unsigned int read_delay_us; /* 8 4 */
unsigned int num_channels; /* 12 4 */
const struct iio_chan_spec * channels; /* 16 8 */
/* size: 24, cachelines: 1, members: 4 */
/* last cacheline: 24 bytes */
};
Will also revise the static declaration to align with the change.
static const struct ltc2309_chip_info ltc2305_chip_info = {
.name = "ltc2305",
.read_delay_us = 2,
.num_channels = ARRAY_SIZE(ltc2305_channels),
.channels = ltc2305_channels,
};
And noted on the comments about the alphabetical arrangement
of headers, extra space, and xmas tree order of local variables,
revised as shown below.
static int ltc2309_probe(struct i2c_client *client)
{
const struct ltc2309_chip_info *chip_info;
struct iio_dev *indio_dev;
struct ltc2309 *ltc2309;
int ret;
Kind regards.