[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <YzqgqERDTLVkJH67@smile.fi.intel.com>
Date: Mon, 3 Oct 2022 11:43:20 +0300
From: Andy Shevchenko <andriy.shevchenko@...ux.intel.com>
To: Matti Vaittinen <mazziesaccount@...il.com>
Cc: Matti Vaittinen <matti.vaittinen@...rohmeurope.com>,
Lars-Peter Clausen <lars@...afoo.de>,
Michael Hennerich <Michael.Hennerich@...log.com>,
Cosmin Tanislav <cosmin.tanislav@...log.com>,
Jonathan Cameron <jic23@...nel.org>,
Eugen Hristev <eugen.hristev@...rochip.com>,
Nicolas Ferre <nicolas.ferre@...rochip.com>,
Alexandre Belloni <alexandre.belloni@...tlin.com>,
Claudiu Beznea <claudiu.beznea@...rochip.com>,
Benson Leung <bleung@...omium.org>,
Guenter Roeck <groeck@...omium.org>,
Alexandru Ardelean <alexandru.ardelean@...log.com>,
Nathan Chancellor <nathan@...nel.org>,
Miquel Raynal <miquel.raynal@...tlin.com>,
Miaoqian Lin <linmq006@...il.com>,
Uwe Kleine-König
<u.kleine-koenig@...gutronix.de>,
Paul Cercueil <paul@...pouillou.net>,
Mihail Chindris <mihail.chindris@...log.com>,
Gwendal Grignou <gwendal@...omium.org>,
linux-iio@...r.kernel.org, linux-kernel@...r.kernel.org,
linux-arm-kernel@...ts.infradead.org,
chrome-platform@...ts.linux.dev
Subject: Re: [RFT PATCH v3 10/10] iio: Don't silently expect attribute types
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
Powered by blists - more mailing lists