Re: [PATCH 2/3] iio: accel: kionix-kx022a: Add chip_info structure

Andy Shevchenko
2023-03-20T12:03:06Z

On Mon, Mar 20, 2023 at 11:35:06AM +0200, Matti Vaittinen wrote:
> On 3/17/23 01:48, Mehdi Djait wrote:
> > Refactor the kx022a driver implementation to make it more
> > generic and extensible.
> > Add the chip_info structure will to the driver's private
> > data to hold all the device specific infos.
> > Move the enum, struct and constants definitions to the header
> > file.

...

> Something like:
>
> enum {
> KIONIX_IC_KX022A,
> KIONIX_IC_KX132_xxx, /* xxx denotes accurate model suffix */
> };
>
> static const struct of_device_id kx022a_of_match[] = {
> { .compatible = "kionix,kx022a", .data = KIONIX_IC_KX022A },
> ...
>
> chip_id = device_get_match_data(&i2c->dev);

No, please avoid putting plain integers as pointers of driver_data.

The problem you introduced with your suggestion is impossibility
to distinguish 0 and NULL, beyond other not good things (like missing
castings which are ugly).

--
With Best Regards,
Andy Shevchenko