Re: [RFT PATCH v3 10/10] iio: Don't silently expect attribute types

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, Oct 03, 2022 at 11:13:53AM +0300, Matti Vaittinen wrote:
> The iio_triggered_buffer_setup_ext() and the
> devm_iio_kfifo_buffer_setup_ext() were changed by
> commit 15097c7a1adc ("iio: buffer: wrap all buffer attributes into iio_dev_attr")
> to silently expect that all attributes given in buffer_attrs array are
> device-attributes. This expectation was not forced by the API - and some
> drivers did register attributes created by IIO_CONST_ATTR().
> 
> When using IIO_CONST_ATTRs the added attribute "wrapping" does not copy
> the pointer to stored string constant and when the sysfs file is read the
> kernel will access to invalid location.
> 
> Change the function signatures to expect an array of iio_dev_attrs to
> avoid similar errors in the future.

...


Wouldn't be better to split this on per driver basis or is it impossible?

>  drivers/iio/accel/adxl367.c                          | 10 +++++-----
>  drivers/iio/accel/adxl372.c                          | 10 +++++-----
>  drivers/iio/accel/bmc150-accel-core.c                | 12 ++++++------
>  drivers/iio/adc/at91-sama5d2_adc.c                   | 12 ++++++------
>  drivers/iio/buffer/industrialio-buffer-dmaengine.c   |  4 ++--
>  drivers/iio/buffer/industrialio-triggered-buffer.c   |  4 ++--
>  drivers/iio/buffer/kfifo_buf.c                       |  2 +-
>  .../common/cros_ec_sensors/cros_ec_sensors_core.c    |  6 +++---
>  drivers/iio/common/hid-sensors/hid-sensor-trigger.c  |  8 ++++----
>  drivers/iio/industrialio-buffer.c                    | 11 +++++++----
>  include/linux/iio/buffer_impl.h                      |  2 +-
>  include/linux/iio/kfifo_buf.h                        |  3 ++-
>  include/linux/iio/triggered_buffer.h                 |  6 +++---

...

>  	struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev);
>  	struct iio_dev_attr *p;

> +	const struct iio_dev_attr *id_attr;

I'm wondering if we may keep this upper, so "longer line goes first" rule would
be satisfied.

>  	struct attribute **attr;
>  	int ret, i, attrn, scan_el_attrcount, buffer_attrcount;
>  	const struct iio_chan_spec *channels;

...

> +		for (i = 0, id_attr = buffer->attrs[i];
> +		     (id_attr = buffer->attrs[i]); i++)

Not sure why we have additional parentheses...

> +			attr[ARRAY_SIZE(iio_buffer_attrs) + i] =
> +				(struct attribute *)&id_attr->dev_attr.attr;

...and explicit casting here. Isn't attr is already of a struct attribute?

-- 
With Best Regards,
Andy Shevchenko





[Index of Archives]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Input]     [Linux Kernel]     [Linux SCSI]     [X.org]

  Powered by Linux