Re: [PATCH v7 5/7] iio: accel: kionix-kx022a: Refactor driver and add chip_info structure

From: Andy Shevchenko
Date: Fri Aug 11 2023 - 05:46:29 EST


On Wed, Aug 09, 2023 at 09:11:36PM +0200, Mehdi Djait wrote:
> Add the chip_info structure to the driver's private data to hold all
> the device specific infos.
> Refactor the kx022a driver implementation to make it more generic and
> extensible.

...

> + chip_info = device_get_match_data(&i2c->dev);
> + if (!chip_info) {
> + const struct i2c_device_id *id = i2c_client_get_device_id(i2c);

Missing blank line.

> + chip_info = (const struct kx022a_chip_info *)id->driver_data;
> + if (!chip_info)
> + return -EINVAL;
> + }

...

> - if (val > KX022A_FIFO_LENGTH)
> - val = KX022A_FIFO_LENGTH;
> + val = min_t(unsigned int, data->chip_info->fifo_length, val);

min_t() is a beast. Please, use min() if no special requirement for
min_t() here, otherwise explain why.

...

> + data->fifo_buffer = kmalloc(data->chip_info->fifo_length *
> + KX022A_FIFO_SAMPLES_SIZE_BYTES, GFP_KERNEL);

kmalloc_array()

> + if (!data->fifo_buffer)
> + return -ENOMEM;

--
With Best Regards,
Andy Shevchenko