[PATCH v4 5/8] iio: core: Use new helpers from overflow.h in iio_device_alloc()
Nuno Sá
noname.nuno at gmail.com
Thu Feb 29 07:29:43 PST 2024
On Wed, 2024-02-28 at 22:41 +0200, Andy Shevchenko wrote:
> We have two new helpers struct_size_with_data() and struct_data_pointer()
> that we can utilize in iio_device_alloc(). Do it so.
>
> Signed-off-by: Andy Shevchenko <andriy.shevchenko at linux.intel.com>
> Reviewed-by: Nuno Sa <nuno.sa at analog.com>
> ---
> drivers/iio/industrialio-core.c | 5 ++---
> 1 file changed, 2 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
> index 1986b3386307..223013725e32 100644
> --- a/drivers/iio/industrialio-core.c
> +++ b/drivers/iio/industrialio-core.c
> @@ -1644,7 +1644,7 @@ struct iio_dev *iio_device_alloc(struct device *parent,
> int sizeof_priv)
> size_t alloc_size;
>
> if (sizeof_priv)
> - alloc_size = ALIGN(alloc_size, IIO_DMA_MINALIGN) +
> sizeof_priv;
> + alloc_size = struct_size_with_data(iio_dev_opaque,
> IIO_DMA_MINALIGN, sizeof_priv);
> else
> alloc_size = sizeof(struct iio_dev_opaque);
>
> @@ -1655,8 +1655,7 @@ struct iio_dev *iio_device_alloc(struct device *parent,
> int sizeof_priv)
> indio_dev = &iio_dev_opaque->indio_dev;
>
> if (sizeof_priv)
> - indio_dev->priv = (char *)iio_dev_opaque +
> - ALIGN(sizeof(struct iio_dev_opaque),
> IIO_DMA_MINALIGN);
> + indio_dev->priv = struct_data_pointer(iio_dev_opaque,
> IIO_DMA_MINALIGN);
I'd +1 for implementing what Kees suggested in IIO. Only thing is (I think), we
need to move struct iio_dev indioo_dev to the end of struct iio_dev_opaque.
- Nuno Sá
More information about the linux-arm-kernel
mailing list