Re: [PATCH] iio: Initialize i2c_device_id structures by name

Andy Shevchenko
2024-12-05T08:24:06Z

On Wed, Dec 04, 2024 at 04:00:36PM +0100, Uwe Kleine-König wrote:
> I intend to change the definition of struct i2c_device_id to look as
> follows:
>
> struct i2c_device_id {
> char name[I2C_NAME_SIZE];
> /* Data private to the driver */
> union {
> kernel_ulong_t driver_data;
> const void *driver_data_ptr;
> };
> };
>
> That the initializers for these structures also work with this new
> definition, they must use named members.
>
> The motivation for that change is to be able to drop many casts from
> pointer to kernel_ulong_t. So once the definition is updated,
> initializers that today use:
>
> { "fxls8471", (kernel_ulong_t)&mma_chip_info_table[fxls8471], },
>
> or
>
> { .name = "fxls8471", .driver_data = (kernel_ulong_t)&mma_chip_info_table[fxls8471], },
>
> can be changed to
>
> { .name = "fxls8471", .driver_data_ptr = &mma_chip_info_table[fxls8471], }
>
> and some more casts when the driver data is used can be dropped, too.

...

> static const struct i2c_device_id adxl345_i2c_id[] = {
> - { "adxl345", (kernel_ulong_t)&adxl345_i2c_info },
> - { "adxl375", (kernel_ulong_t)&adxl375_i2c_info },
> + { .name = "adxl345", .driver_data = (kernel_ulong_t)&adxl345_i2c_info, },
> + { .name = "adxl375", .driver_data = (kernel_ulong_t)&adxl375_i2c_info, },

Redundant inner trailing commas. And they were absent in the original code.
And I find that better style as usually we leave commas (or add them) only in
multi-line cases.

> { }
> };

--
With Best Regards,
Andy Shevchenko