Add IIO_STATIC_CONST_DEVICE_ATTR macro for creating an read-only
iio_dev_attr which returns constant value. This macro is intended to be
used when replacing the IIO_CONST_ATTR - attributes for triggered
buffers because the triggered buffer attributes must be of type
iio_dev_attr.
Signed-off-by: Matti Vaittinen <[email protected]>
---
I am not thrilled about how keyword 'static' is handled here but in my
calendar this day seems to be called the day of the developer without
working ideas. Feel free to suggest something if you guys have more
luck with ideas. :) And I still think this macro is better than adding
the summy 'show' callback in each individual driver :/
include/linux/iio/sysfs.h | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/include/linux/iio/sysfs.h b/include/linux/iio/sysfs.h
index e51fba66de4b..de5bb125815c 100644
--- a/include/linux/iio/sysfs.h
+++ b/include/linux/iio/sysfs.h
@@ -97,6 +97,17 @@ struct iio_const_attr {
= { .string = _string, \
.dev_attr = __ATTR(_name, S_IRUGO, iio_read_const_attr, NULL)}
+#define IIO_STATIC_CONST_DEVICE_ATTR(_name, _string) \
+ static ssize_t iio_const_dev_attr_show_##_name( \
+ struct device *dev, \
+ struct device_attribute *attr, \
+ char *buf) \
+ { \
+ return sysfs_emit(buf, "%s\n", _string); \
+ } \
+ static IIO_DEVICE_ATTR(_name, 0444, \
+ iio_const_dev_attr_show_##_name, NULL, 0)
+
/* Generic attributes of onetype or another */
/**
--
2.37.3
--
Matti Vaittinen, Linux device drivers
ROHM Semiconductors, Finland SWDC
Kiviharjunlenkki 1E
90220 OULU
FINLAND
~~~ "I don't think so," said Rene Descartes. Just then he vanished ~~~
Simon says - in Latin please.
~~~ "non cogito me" dixit Rene Descarte, deinde evanescavit ~~~
Thanks to Simon Glass for the translation =]
The iio_triggered_buffer_setup_ext() was 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().
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.
Signed-off-by: Matti Vaittinen <[email protected]>
Fixes: 15097c7a1adc ("iio: buffer: wrap all buffer attributes into iio_dev_attr")
---
The fix is only superficially tested by a ROHM/kionix KX022A driver.
Proper testing with real in-tree IIO stuff is _highly_ appreciated.
---
drivers/iio/accel/adxl367.c | 16 ++++++++--------
drivers/iio/accel/adxl372.c | 16 ++++++++--------
drivers/iio/accel/bmc150-accel-core.c | 18 +++++++++---------
drivers/iio/adc/at91-sama5d2_adc.c | 16 ++++++++--------
.../iio/buffer/industrialio-triggered-buffer.c | 4 ++--
drivers/iio/buffer/kfifo_buf.c | 2 +-
.../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 +++---
11 files changed, 53 insertions(+), 49 deletions(-)
diff --git a/drivers/iio/accel/adxl367.c b/drivers/iio/accel/adxl367.c
index 47feb375b70b..0922ac0fad9e 100644
--- a/drivers/iio/accel/adxl367.c
+++ b/drivers/iio/accel/adxl367.c
@@ -1185,19 +1185,19 @@ static ssize_t adxl367_get_fifo_watermark(struct device *dev,
return sysfs_emit(buf, "%d\n", fifo_watermark);
}
-static IIO_CONST_ATTR(hwfifo_watermark_min, "1");
-static IIO_CONST_ATTR(hwfifo_watermark_max,
- __stringify(ADXL367_FIFO_MAX_WATERMARK));
+IIO_STATIC_CONST_DEVICE_ATTR(hwfifo_watermark_min, "1");
+IIO_STATIC_CONST_DEVICE_ATTR(hwfifo_watermark_max,
+ __stringify(ADXL367_FIFO_MAX_WATERMARK));
static IIO_DEVICE_ATTR(hwfifo_watermark, 0444,
adxl367_get_fifo_watermark, NULL, 0);
static IIO_DEVICE_ATTR(hwfifo_enabled, 0444,
adxl367_get_fifo_enabled, NULL, 0);
-static const struct attribute *adxl367_fifo_attributes[] = {
- &iio_const_attr_hwfifo_watermark_min.dev_attr.attr,
- &iio_const_attr_hwfifo_watermark_max.dev_attr.attr,
- &iio_dev_attr_hwfifo_watermark.dev_attr.attr,
- &iio_dev_attr_hwfifo_enabled.dev_attr.attr,
+static const struct iio_dev_attr *adxl367_fifo_attributes[] = {
+ &iio_dev_attr_hwfifo_watermark_min,
+ &iio_dev_attr_hwfifo_watermark_max,
+ &iio_dev_attr_hwfifo_watermark,
+ &iio_dev_attr_hwfifo_enabled,
NULL,
};
diff --git a/drivers/iio/accel/adxl372.c b/drivers/iio/accel/adxl372.c
index e3ecbaee61f7..c4193286eb05 100644
--- a/drivers/iio/accel/adxl372.c
+++ b/drivers/iio/accel/adxl372.c
@@ -998,19 +998,19 @@ static ssize_t adxl372_get_fifo_watermark(struct device *dev,
return sprintf(buf, "%d\n", st->watermark);
}
-static IIO_CONST_ATTR(hwfifo_watermark_min, "1");
-static IIO_CONST_ATTR(hwfifo_watermark_max,
- __stringify(ADXL372_FIFO_SIZE));
+IIO_STATIC_CONST_DEVICE_ATTR(hwfifo_watermark_min, "1");
+IIO_STATIC_CONST_DEVICE_ATTR(hwfifo_watermark_max,
+ __stringify(ADXL372_FIFO_SIZE));
static IIO_DEVICE_ATTR(hwfifo_watermark, 0444,
adxl372_get_fifo_watermark, NULL, 0);
static IIO_DEVICE_ATTR(hwfifo_enabled, 0444,
adxl372_get_fifo_enabled, NULL, 0);
-static const struct attribute *adxl372_fifo_attributes[] = {
- &iio_const_attr_hwfifo_watermark_min.dev_attr.attr,
- &iio_const_attr_hwfifo_watermark_max.dev_attr.attr,
- &iio_dev_attr_hwfifo_watermark.dev_attr.attr,
- &iio_dev_attr_hwfifo_enabled.dev_attr.attr,
+static const struct iio_dev_attr *adxl372_fifo_attributes[] = {
+ &iio_dev_attr_hwfifo_watermark_min,
+ &iio_dev_attr_hwfifo_watermark_max,
+ &iio_dev_attr_hwfifo_watermark,
+ &iio_dev_attr_hwfifo_enabled,
NULL,
};
diff --git a/drivers/iio/accel/bmc150-accel-core.c b/drivers/iio/accel/bmc150-accel-core.c
index 57e8a8350cd1..110591804b4c 100644
--- a/drivers/iio/accel/bmc150-accel-core.c
+++ b/drivers/iio/accel/bmc150-accel-core.c
@@ -925,19 +925,19 @@ static const struct iio_chan_spec_ext_info bmc150_accel_ext_info[] = {
{ }
};
-static IIO_CONST_ATTR(hwfifo_watermark_min, "1");
-static IIO_CONST_ATTR(hwfifo_watermark_max,
- __stringify(BMC150_ACCEL_FIFO_LENGTH));
+IIO_STATIC_CONST_DEVICE_ATTR(hwfifo_watermark_min, "1");
+IIO_STATIC_CONST_DEVICE_ATTR(hwfifo_watermark_max,
+ __stringify(BMC150_ACCEL_FIFO_LENGTH));
static IIO_DEVICE_ATTR(hwfifo_enabled, S_IRUGO,
bmc150_accel_get_fifo_state, NULL, 0);
static IIO_DEVICE_ATTR(hwfifo_watermark, S_IRUGO,
bmc150_accel_get_fifo_watermark, NULL, 0);
-static const struct attribute *bmc150_accel_fifo_attributes[] = {
- &iio_const_attr_hwfifo_watermark_min.dev_attr.attr,
- &iio_const_attr_hwfifo_watermark_max.dev_attr.attr,
- &iio_dev_attr_hwfifo_watermark.dev_attr.attr,
- &iio_dev_attr_hwfifo_enabled.dev_attr.attr,
+static const struct iio_dev_attr *bmc150_accel_fifo_attributes[] = {
+ &iio_dev_attr_hwfifo_watermark_min,
+ &iio_dev_attr_hwfifo_watermark_max,
+ &iio_dev_attr_hwfifo_watermark,
+ &iio_dev_attr_hwfifo_enabled,
NULL,
};
@@ -1665,7 +1665,7 @@ int bmc150_accel_core_probe(struct device *dev, struct regmap *regmap, int irq,
enum bmc150_type type, const char *name,
bool block_supported)
{
- const struct attribute **fifo_attrs;
+ const struct iio_dev_attr **fifo_attrs;
struct bmc150_accel_data *data;
struct iio_dev *indio_dev;
int ret;
diff --git a/drivers/iio/adc/at91-sama5d2_adc.c b/drivers/iio/adc/at91-sama5d2_adc.c
index 279430c1d88c..f994366b0778 100644
--- a/drivers/iio/adc/at91-sama5d2_adc.c
+++ b/drivers/iio/adc/at91-sama5d2_adc.c
@@ -1846,8 +1846,8 @@ static IIO_DEVICE_ATTR(hwfifo_enabled, 0444,
static IIO_DEVICE_ATTR(hwfifo_watermark, 0444,
at91_adc_get_watermark, NULL, 0);
-static IIO_CONST_ATTR(hwfifo_watermark_min, "2");
-static IIO_CONST_ATTR(hwfifo_watermark_max, AT91_HWFIFO_MAX_SIZE_STR);
+IIO_STATIC_CONST_DEVICE_ATTR(hwfifo_watermark_min, "2");
+IIO_STATIC_CONST_DEVICE_ATTR(hwfifo_watermark_max, AT91_HWFIFO_MAX_SIZE_STR);
static IIO_CONST_ATTR(oversampling_ratio_available,
__stringify(AT91_OSR_1SAMPLES) " "
@@ -1863,11 +1863,11 @@ static const struct attribute_group at91_adc_attribute_group = {
.attrs = at91_adc_attributes,
};
-static const struct attribute *at91_adc_fifo_attributes[] = {
- &iio_const_attr_hwfifo_watermark_min.dev_attr.attr,
- &iio_const_attr_hwfifo_watermark_max.dev_attr.attr,
- &iio_dev_attr_hwfifo_watermark.dev_attr.attr,
- &iio_dev_attr_hwfifo_enabled.dev_attr.attr,
+static const struct iio_dev_attr *at91_adc_fifo_attributes[] = {
+ &iio_dev_attr_hwfifo_watermark_min,
+ &iio_dev_attr_hwfifo_watermark_max,
+ &iio_dev_attr_hwfifo_watermark,
+ &iio_dev_attr_hwfifo_enabled,
NULL,
};
@@ -1884,7 +1884,7 @@ static int at91_adc_buffer_and_trigger_init(struct device *dev,
struct iio_dev *indio)
{
struct at91_adc_state *st = iio_priv(indio);
- const struct attribute **fifo_attrs;
+ const struct iio_dev_attr **fifo_attrs;
int ret;
if (st->selected_trig->hw_trig)
diff --git a/drivers/iio/buffer/industrialio-triggered-buffer.c b/drivers/iio/buffer/industrialio-triggered-buffer.c
index 8d4fc97d1005..c7671b1f5ead 100644
--- a/drivers/iio/buffer/industrialio-triggered-buffer.c
+++ b/drivers/iio/buffer/industrialio-triggered-buffer.c
@@ -41,7 +41,7 @@ int iio_triggered_buffer_setup_ext(struct iio_dev *indio_dev,
irqreturn_t (*thread)(int irq, void *p),
enum iio_buffer_direction direction,
const struct iio_buffer_setup_ops *setup_ops,
- const struct attribute **buffer_attrs)
+ const struct iio_dev_attr **buffer_attrs)
{
struct iio_buffer *buffer;
int ret;
@@ -110,7 +110,7 @@ int devm_iio_triggered_buffer_setup_ext(struct device *dev,
irqreturn_t (*thread)(int irq, void *p),
enum iio_buffer_direction direction,
const struct iio_buffer_setup_ops *ops,
- const struct attribute **buffer_attrs)
+ const struct iio_dev_attr **buffer_attrs)
{
int ret;
diff --git a/drivers/iio/buffer/kfifo_buf.c b/drivers/iio/buffer/kfifo_buf.c
index 35d8b4077376..05b285f0eb22 100644
--- a/drivers/iio/buffer/kfifo_buf.c
+++ b/drivers/iio/buffer/kfifo_buf.c
@@ -270,7 +270,7 @@ static struct iio_buffer *devm_iio_kfifo_allocate(struct device *dev)
int devm_iio_kfifo_buffer_setup_ext(struct device *dev,
struct iio_dev *indio_dev,
const struct iio_buffer_setup_ops *setup_ops,
- const struct attribute **buffer_attrs)
+ const struct iio_dev_attr **buffer_attrs)
{
struct iio_buffer *buffer;
diff --git a/drivers/iio/common/hid-sensors/hid-sensor-trigger.c b/drivers/iio/common/hid-sensors/hid-sensor-trigger.c
index 1151434038d4..ad8910e6ad59 100644
--- a/drivers/iio/common/hid-sensors/hid-sensor-trigger.c
+++ b/drivers/iio/common/hid-sensors/hid-sensor-trigger.c
@@ -75,9 +75,9 @@ static IIO_DEVICE_ATTR(hwfifo_timeout, 0644,
static IIO_DEVICE_ATTR(hwfifo_enabled, 0444,
_hid_sensor_get_fifo_state, NULL, 0);
-static const struct attribute *hid_sensor_fifo_attributes[] = {
- &iio_dev_attr_hwfifo_timeout.dev_attr.attr,
- &iio_dev_attr_hwfifo_enabled.dev_attr.attr,
+static const struct iio_dev_attr *hid_sensor_fifo_attributes[] = {
+ &iio_dev_attr_hwfifo_timeout,
+ &iio_dev_attr_hwfifo_enabled,
NULL,
};
@@ -231,7 +231,7 @@ static const struct iio_trigger_ops hid_sensor_trigger_ops = {
int hid_sensor_setup_trigger(struct iio_dev *indio_dev, const char *name,
struct hid_sensor_common *attrb)
{
- const struct attribute **fifo_attrs;
+ const struct iio_dev_attr **fifo_attrs;
int ret;
struct iio_trigger *trig;
diff --git a/drivers/iio/industrialio-buffer.c b/drivers/iio/industrialio-buffer.c
index acc2b6c05d57..cc7ebafae571 100644
--- a/drivers/iio/industrialio-buffer.c
+++ b/drivers/iio/industrialio-buffer.c
@@ -1599,6 +1599,7 @@ static int __iio_buffer_alloc_sysfs_and_mask(struct iio_buffer *buffer,
{
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;
struct attribute **attr;
int ret, i, attrn, scan_el_attrcount, buffer_attrcount;
const struct iio_chan_spec *channels;
@@ -1608,6 +1609,7 @@ static int __iio_buffer_alloc_sysfs_and_mask(struct iio_buffer *buffer,
while (buffer->attrs[buffer_attrcount] != NULL)
buffer_attrcount++;
}
+ buffer_attrcount += ARRAY_SIZE(iio_buffer_attrs);
scan_el_attrcount = 0;
INIT_LIST_HEAD(&buffer->buffer_attr_list);
@@ -1650,7 +1652,7 @@ static int __iio_buffer_alloc_sysfs_and_mask(struct iio_buffer *buffer,
}
}
- attrn = buffer_attrcount + scan_el_attrcount + ARRAY_SIZE(iio_buffer_attrs);
+ attrn = buffer_attrcount + scan_el_attrcount;
attr = kcalloc(attrn + 1, sizeof(*attr), GFP_KERNEL);
if (!attr) {
ret = -ENOMEM;
@@ -1665,10 +1667,11 @@ static int __iio_buffer_alloc_sysfs_and_mask(struct iio_buffer *buffer,
attr[2] = &dev_attr_watermark_ro.attr;
if (buffer->attrs)
- memcpy(&attr[ARRAY_SIZE(iio_buffer_attrs)], buffer->attrs,
- sizeof(struct attribute *) * buffer_attrcount);
+ for (i = 0, id_attr = buffer->attrs[i];
+ (id_attr = buffer->attrs[i]); i++)
+ attr[ARRAY_SIZE(iio_buffer_attrs) + i] =
+ (struct attribute *)&id_attr->dev_attr.attr;
- buffer_attrcount += ARRAY_SIZE(iio_buffer_attrs);
buffer->buffer_group.attrs = attr;
for (i = 0; i < buffer_attrcount; i++) {
diff --git a/include/linux/iio/buffer_impl.h b/include/linux/iio/buffer_impl.h
index e2ca8ea23e19..89c3fd7c29ca 100644
--- a/include/linux/iio/buffer_impl.h
+++ b/include/linux/iio/buffer_impl.h
@@ -123,7 +123,7 @@ struct iio_buffer {
struct attribute_group buffer_group;
/* @attrs: Standard attributes of the buffer. */
- const struct attribute **attrs;
+ const struct iio_dev_attr **attrs;
/* @demux_bounce: Buffer for doing gather from incoming scan. */
void *demux_bounce;
diff --git a/include/linux/iio/kfifo_buf.h b/include/linux/iio/kfifo_buf.h
index 8a83fb58232d..22874da0c8be 100644
--- a/include/linux/iio/kfifo_buf.h
+++ b/include/linux/iio/kfifo_buf.h
@@ -5,6 +5,7 @@
struct iio_buffer;
struct iio_buffer_setup_ops;
struct iio_dev;
+struct iio_dev_attr;
struct device;
struct iio_buffer *iio_kfifo_allocate(void);
@@ -13,7 +14,7 @@ void iio_kfifo_free(struct iio_buffer *r);
int devm_iio_kfifo_buffer_setup_ext(struct device *dev,
struct iio_dev *indio_dev,
const struct iio_buffer_setup_ops *setup_ops,
- const struct attribute **buffer_attrs);
+ const struct iio_dev_attr **buffer_attrs);
#define devm_iio_kfifo_buffer_setup(dev, indio_dev, setup_ops) \
devm_iio_kfifo_buffer_setup_ext((dev), (indio_dev), (setup_ops), NULL)
diff --git a/include/linux/iio/triggered_buffer.h b/include/linux/iio/triggered_buffer.h
index 7490b05fc5b2..29e1fe146879 100644
--- a/include/linux/iio/triggered_buffer.h
+++ b/include/linux/iio/triggered_buffer.h
@@ -5,8 +5,8 @@
#include <linux/iio/buffer.h>
#include <linux/interrupt.h>
-struct attribute;
struct iio_dev;
+struct iio_dev_attr;
struct iio_buffer_setup_ops;
int iio_triggered_buffer_setup_ext(struct iio_dev *indio_dev,
@@ -14,7 +14,7 @@ int iio_triggered_buffer_setup_ext(struct iio_dev *indio_dev,
irqreturn_t (*thread)(int irq, void *p),
enum iio_buffer_direction direction,
const struct iio_buffer_setup_ops *setup_ops,
- const struct attribute **buffer_attrs);
+ const struct iio_dev_attr **buffer_attrs);
void iio_triggered_buffer_cleanup(struct iio_dev *indio_dev);
#define iio_triggered_buffer_setup(indio_dev, h, thread, setup_ops) \
@@ -28,7 +28,7 @@ int devm_iio_triggered_buffer_setup_ext(struct device *dev,
irqreturn_t (*thread)(int irq, void *p),
enum iio_buffer_direction direction,
const struct iio_buffer_setup_ops *ops,
- const struct attribute **buffer_attrs);
+ const struct iio_dev_attr **buffer_attrs);
#define devm_iio_triggered_buffer_setup(dev, indio_dev, h, thread, setup_ops) \
devm_iio_triggered_buffer_setup_ext((dev), (indio_dev), (h), (thread), \
--
2.37.3
--
Matti Vaittinen, Linux device drivers
ROHM Semiconductors, Finland SWDC
Kiviharjunlenkki 1E
90220 OULU
FINLAND
~~~ "I don't think so," said Rene Descartes. Just then he vanished ~~~
Simon says - in Latin please.
~~~ "non cogito me" dixit Rene Descarte, deinde evanescavit ~~~
Thanks to Simon Glass for the translation =]
Hi Matti,
I love your patch! Yet something to improve:
[auto build test ERROR on v6.0-rc7]
[also build test ERROR on linus/master]
[cannot apply to jic23-iio/togreg next-20220929]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Matti-Vaittinen/iio-Add-IIO_STATIC_CONST_DEVICE_ATTR/20220930-191558
base: f76349cf41451c5c42a99f18a9163377e4b364ff
config: sh-allmodconfig
compiler: sh4-linux-gcc (GCC) 12.1.0
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# https://github.com/intel-lab-lkp/linux/commit/71aecc2b7a59a431f1a4ca7f6e4670f6ca889cb0
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Matti-Vaittinen/iio-Add-IIO_STATIC_CONST_DEVICE_ATTR/20220930-191558
git checkout 71aecc2b7a59a431f1a4ca7f6e4670f6ca889cb0
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=sh SHELL=/bin/bash drivers/iio/
If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <[email protected]>
All errors (new ones prefixed by >>):
drivers/iio/buffer/industrialio-buffer-dmaengine.c: In function 'iio_dmaengine_buffer_alloc':
>> drivers/iio/buffer/industrialio-buffer-dmaengine.c:204:46: error: assignment to 'const struct iio_dev_attr **' from incompatible pointer type 'const struct attribute **' [-Werror=incompatible-pointer-types]
204 | dmaengine_buffer->queue.buffer.attrs = iio_dmaengine_buffer_attrs;
| ^
cc1: some warnings being treated as errors
--
drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c: In function 'cros_ec_sensors_core_init':
>> drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c:336:63: error: passing argument 4 of 'devm_iio_kfifo_buffer_setup_ext' from incompatible pointer type [-Werror=incompatible-pointer-types]
336 | cros_ec_sensor_fifo_attributes);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| |
| const struct attribute **
In file included from drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c:13:
include/linux/iio/kfifo_buf.h:17:65: note: expected 'const struct iio_dev_attr **' but argument is of type 'const struct attribute **'
17 | const struct iio_dev_attr **buffer_attrs);
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~
cc1: some warnings being treated as errors
vim +204 drivers/iio/buffer/industrialio-buffer-dmaengine.c
4538c185680996 Lars-Peter Clausen 2019-12-11 149
2d6ca60f328450 Lars-Peter Clausen 2015-10-13 150 /**
2d6ca60f328450 Lars-Peter Clausen 2015-10-13 151 * iio_dmaengine_buffer_alloc() - Allocate new buffer which uses DMAengine
2d6ca60f328450 Lars-Peter Clausen 2015-10-13 152 * @dev: Parent device for the buffer
2d6ca60f328450 Lars-Peter Clausen 2015-10-13 153 * @channel: DMA channel name, typically "rx".
2d6ca60f328450 Lars-Peter Clausen 2015-10-13 154 *
2d6ca60f328450 Lars-Peter Clausen 2015-10-13 155 * This allocates a new IIO buffer which internally uses the DMAengine framework
2d6ca60f328450 Lars-Peter Clausen 2015-10-13 156 * to perform its transfers. The parent device will be used to request the DMA
2d6ca60f328450 Lars-Peter Clausen 2015-10-13 157 * channel.
2d6ca60f328450 Lars-Peter Clausen 2015-10-13 158 *
2d6ca60f328450 Lars-Peter Clausen 2015-10-13 159 * Once done using the buffer iio_dmaengine_buffer_free() should be used to
2d6ca60f328450 Lars-Peter Clausen 2015-10-13 160 * release it.
2d6ca60f328450 Lars-Peter Clausen 2015-10-13 161 */
25918a9c641c3c Alexandru Ardelean 2020-09-23 162 static struct iio_buffer *iio_dmaengine_buffer_alloc(struct device *dev,
2d6ca60f328450 Lars-Peter Clausen 2015-10-13 163 const char *channel)
2d6ca60f328450 Lars-Peter Clausen 2015-10-13 164 {
2d6ca60f328450 Lars-Peter Clausen 2015-10-13 165 struct dmaengine_buffer *dmaengine_buffer;
2d6ca60f328450 Lars-Peter Clausen 2015-10-13 166 unsigned int width, src_width, dest_width;
2d6ca60f328450 Lars-Peter Clausen 2015-10-13 167 struct dma_slave_caps caps;
2d6ca60f328450 Lars-Peter Clausen 2015-10-13 168 struct dma_chan *chan;
2d6ca60f328450 Lars-Peter Clausen 2015-10-13 169 int ret;
2d6ca60f328450 Lars-Peter Clausen 2015-10-13 170
2d6ca60f328450 Lars-Peter Clausen 2015-10-13 171 dmaengine_buffer = kzalloc(sizeof(*dmaengine_buffer), GFP_KERNEL);
2d6ca60f328450 Lars-Peter Clausen 2015-10-13 172 if (!dmaengine_buffer)
2d6ca60f328450 Lars-Peter Clausen 2015-10-13 173 return ERR_PTR(-ENOMEM);
2d6ca60f328450 Lars-Peter Clausen 2015-10-13 174
f339f979bb333e Peter Ujfalusi 2019-11-13 175 chan = dma_request_chan(dev, channel);
2d6ca60f328450 Lars-Peter Clausen 2015-10-13 176 if (IS_ERR(chan)) {
2d6ca60f328450 Lars-Peter Clausen 2015-10-13 177 ret = PTR_ERR(chan);
2d6ca60f328450 Lars-Peter Clausen 2015-10-13 178 goto err_free;
2d6ca60f328450 Lars-Peter Clausen 2015-10-13 179 }
2d6ca60f328450 Lars-Peter Clausen 2015-10-13 180
2d6ca60f328450 Lars-Peter Clausen 2015-10-13 181 ret = dma_get_slave_caps(chan, &caps);
2d6ca60f328450 Lars-Peter Clausen 2015-10-13 182 if (ret < 0)
2d6ca60f328450 Lars-Peter Clausen 2015-10-13 183 goto err_free;
2d6ca60f328450 Lars-Peter Clausen 2015-10-13 184
2d6ca60f328450 Lars-Peter Clausen 2015-10-13 185 /* Needs to be aligned to the maximum of the minimums */
2d6ca60f328450 Lars-Peter Clausen 2015-10-13 186 if (caps.src_addr_widths)
2d6ca60f328450 Lars-Peter Clausen 2015-10-13 187 src_width = __ffs(caps.src_addr_widths);
2d6ca60f328450 Lars-Peter Clausen 2015-10-13 188 else
2d6ca60f328450 Lars-Peter Clausen 2015-10-13 189 src_width = 1;
2d6ca60f328450 Lars-Peter Clausen 2015-10-13 190 if (caps.dst_addr_widths)
2d6ca60f328450 Lars-Peter Clausen 2015-10-13 191 dest_width = __ffs(caps.dst_addr_widths);
2d6ca60f328450 Lars-Peter Clausen 2015-10-13 192 else
2d6ca60f328450 Lars-Peter Clausen 2015-10-13 193 dest_width = 1;
2d6ca60f328450 Lars-Peter Clausen 2015-10-13 194 width = max(src_width, dest_width);
2d6ca60f328450 Lars-Peter Clausen 2015-10-13 195
2d6ca60f328450 Lars-Peter Clausen 2015-10-13 196 INIT_LIST_HEAD(&dmaengine_buffer->active);
2d6ca60f328450 Lars-Peter Clausen 2015-10-13 197 dmaengine_buffer->chan = chan;
2d6ca60f328450 Lars-Peter Clausen 2015-10-13 198 dmaengine_buffer->align = width;
2d6ca60f328450 Lars-Peter Clausen 2015-10-13 199 dmaengine_buffer->max_size = dma_get_max_seg_size(chan->device->dev);
2d6ca60f328450 Lars-Peter Clausen 2015-10-13 200
2d6ca60f328450 Lars-Peter Clausen 2015-10-13 201 iio_dma_buffer_init(&dmaengine_buffer->queue, chan->device->dev,
2d6ca60f328450 Lars-Peter Clausen 2015-10-13 202 &iio_dmaengine_default_ops);
2d6ca60f328450 Lars-Peter Clausen 2015-10-13 203
5e6dc43e2caa14 Alexandru Ardelean 2020-09-29 @204 dmaengine_buffer->queue.buffer.attrs = iio_dmaengine_buffer_attrs;
2d6ca60f328450 Lars-Peter Clausen 2015-10-13 205 dmaengine_buffer->queue.buffer.access = &iio_dmaengine_buffer_ops;
2d6ca60f328450 Lars-Peter Clausen 2015-10-13 206
2d6ca60f328450 Lars-Peter Clausen 2015-10-13 207 return &dmaengine_buffer->queue.buffer;
2d6ca60f328450 Lars-Peter Clausen 2015-10-13 208
2d6ca60f328450 Lars-Peter Clausen 2015-10-13 209 err_free:
2d6ca60f328450 Lars-Peter Clausen 2015-10-13 210 kfree(dmaengine_buffer);
2d6ca60f328450 Lars-Peter Clausen 2015-10-13 211 return ERR_PTR(ret);
2d6ca60f328450 Lars-Peter Clausen 2015-10-13 212 }
2d6ca60f328450 Lars-Peter Clausen 2015-10-13 213
--
0-DAY CI Kernel Test Service
https://01.org/lkp
Hi dee Ho peeps,
On 9/30/22 17:17, kernel test robot wrote:
> Hi Matti,
>
> I love your patch! Yet something to improve:
Ouch.
I overlooked the fact that the buffer was also used by iio-dmaengine
(which I had not configured to be compiled). Also the
cros_ec_sensors_core.c evaded my grep.
Changing these to use iio_dev_attrs as well seems trivial - but I am
afraid there may be other culprits if the pointers to those buffer
attributes are memcpy()-ed somewhere else as well... (The attribute wrap
function did this).
I will include cros_ec_sensors_core.c and industrialio-dmaengine.c
changes and re-spin the series - but I guess I need to add [RFT] here...
Best regards
-- Matti
--
Matti Vaittinen
Linux kernel developer at ROHM Semiconductors
Oulu Finland
~~ When things go utterly wrong vim users can always type :help! ~~
Hi Matti,
I love your patch! Yet something to improve:
[auto build test ERROR on v6.0-rc7]
[also build test ERROR on linus/master]
[cannot apply to jic23-iio/togreg next-20220930]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Matti-Vaittinen/iio-Add-IIO_STATIC_CONST_DEVICE_ATTR/20220930-191558
base: f76349cf41451c5c42a99f18a9163377e4b364ff
config: i386-randconfig-a006
compiler: clang version 14.0.6 (https://github.com/llvm/llvm-project f28c006a5895fc0e329fe15fead81e37457cb1d1)
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# https://github.com/intel-lab-lkp/linux/commit/71aecc2b7a59a431f1a4ca7f6e4670f6ca889cb0
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Matti-Vaittinen/iio-Add-IIO_STATIC_CONST_DEVICE_ATTR/20220930-191558
git checkout 71aecc2b7a59a431f1a4ca7f6e4670f6ca889cb0
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=i386 SHELL=/bin/bash
If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <[email protected]>
All errors (new ones prefixed by >>):
>> drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c:336:14: error: incompatible pointer types passing 'const struct attribute *[3]' to parameter of type 'const struct iio_dev_attr **' [-Werror,-Wincompatible-pointer-types]
cros_ec_sensor_fifo_attributes);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/linux/iio/kfifo_buf.h:17:37: note: passing argument to parameter 'buffer_attrs' here
const struct iio_dev_attr **buffer_attrs);
^
1 error generated.
vim +336 drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c
aa984f1ba4a477 Gwendal Grignou 2020-03-27 228
d9452adcc5b485 Gwendal Grignou 2020-03-27 229 /**
d9452adcc5b485 Gwendal Grignou 2020-03-27 230 * cros_ec_sensors_core_init() - basic initialization of the core structure
0b4ae3f6d1210c Gwendal Grignou 2022-07-11 231 * @pdev: platform device created for the sensor
d9452adcc5b485 Gwendal Grignou 2020-03-27 232 * @indio_dev: iio device structure of the device
d9452adcc5b485 Gwendal Grignou 2020-03-27 233 * @physical_device: true if the device refers to a physical device
aa984f1ba4a477 Gwendal Grignou 2020-03-27 234 * @trigger_capture: function pointer to call buffer is triggered,
aa984f1ba4a477 Gwendal Grignou 2020-03-27 235 * for backward compatibility.
d9452adcc5b485 Gwendal Grignou 2020-03-27 236 *
d9452adcc5b485 Gwendal Grignou 2020-03-27 237 * Return: 0 on success, -errno on failure.
d9452adcc5b485 Gwendal Grignou 2020-03-27 238 */
974e6f02e27e1b Enric Balletbo i Serra 2016-08-01 239 int cros_ec_sensors_core_init(struct platform_device *pdev,
974e6f02e27e1b Enric Balletbo i Serra 2016-08-01 240 struct iio_dev *indio_dev,
aa984f1ba4a477 Gwendal Grignou 2020-03-27 241 bool physical_device,
0b4ae3f6d1210c Gwendal Grignou 2022-07-11 242 cros_ec_sensors_capture_t trigger_capture)
974e6f02e27e1b Enric Balletbo i Serra 2016-08-01 243 {
974e6f02e27e1b Enric Balletbo i Serra 2016-08-01 244 struct device *dev = &pdev->dev;
974e6f02e27e1b Enric Balletbo i Serra 2016-08-01 245 struct cros_ec_sensors_core_state *state = iio_priv(indio_dev);
d60ac88a62df71 Gwendal Grignou 2019-11-19 246 struct cros_ec_sensorhub *sensor_hub = dev_get_drvdata(dev->parent);
d60ac88a62df71 Gwendal Grignou 2019-11-19 247 struct cros_ec_dev *ec = sensor_hub->ec;
974e6f02e27e1b Enric Balletbo i Serra 2016-08-01 248 struct cros_ec_sensor_platform *sensor_platform = dev_get_platdata(dev);
56e4f2dda23c6d Gwendal Grignou 2020-06-30 249 u32 ver_mask, temp;
317a0ebe53f465 Gwendal Grignou 2020-03-27 250 int frequencies[ARRAY_SIZE(state->frequencies) / 2] = { 0 };
22087c850e8e56 Gwendal Grignou 2019-08-26 251 int ret, i;
974e6f02e27e1b Enric Balletbo i Serra 2016-08-01 252
974e6f02e27e1b Enric Balletbo i Serra 2016-08-01 253 platform_set_drvdata(pdev, indio_dev);
974e6f02e27e1b Enric Balletbo i Serra 2016-08-01 254
974e6f02e27e1b Enric Balletbo i Serra 2016-08-01 255 state->ec = ec->ec_dev;
974e6f02e27e1b Enric Balletbo i Serra 2016-08-01 256 state->msg = devm_kzalloc(&pdev->dev,
974e6f02e27e1b Enric Balletbo i Serra 2016-08-01 257 max((u16)sizeof(struct ec_params_motion_sense),
974e6f02e27e1b Enric Balletbo i Serra 2016-08-01 258 state->ec->max_response), GFP_KERNEL);
974e6f02e27e1b Enric Balletbo i Serra 2016-08-01 259 if (!state->msg)
974e6f02e27e1b Enric Balletbo i Serra 2016-08-01 260 return -ENOMEM;
974e6f02e27e1b Enric Balletbo i Serra 2016-08-01 261
974e6f02e27e1b Enric Balletbo i Serra 2016-08-01 262 state->resp = (struct ec_response_motion_sense *)state->msg->data;
974e6f02e27e1b Enric Balletbo i Serra 2016-08-01 263
974e6f02e27e1b Enric Balletbo i Serra 2016-08-01 264 mutex_init(&state->cmd_lock);
974e6f02e27e1b Enric Balletbo i Serra 2016-08-01 265
3cf9df00957fb2 Fabien Lahoudere 2019-07-02 266 ret = cros_ec_get_host_cmd_version_mask(state->ec,
3cf9df00957fb2 Fabien Lahoudere 2019-07-02 267 ec->cmd_offset,
3cf9df00957fb2 Fabien Lahoudere 2019-07-02 268 EC_CMD_MOTION_SENSE_CMD,
3cf9df00957fb2 Fabien Lahoudere 2019-07-02 269 &ver_mask);
3cf9df00957fb2 Fabien Lahoudere 2019-07-02 270 if (ret < 0)
3cf9df00957fb2 Fabien Lahoudere 2019-07-02 271 return ret;
3cf9df00957fb2 Fabien Lahoudere 2019-07-02 272
974e6f02e27e1b Enric Balletbo i Serra 2016-08-01 273 /* Set up the host command structure. */
3cf9df00957fb2 Fabien Lahoudere 2019-07-02 274 state->msg->version = fls(ver_mask) - 1;
974e6f02e27e1b Enric Balletbo i Serra 2016-08-01 275 state->msg->command = EC_CMD_MOTION_SENSE_CMD + ec->cmd_offset;
974e6f02e27e1b Enric Balletbo i Serra 2016-08-01 276 state->msg->outsize = sizeof(struct ec_params_motion_sense);
974e6f02e27e1b Enric Balletbo i Serra 2016-08-01 277
974e6f02e27e1b Enric Balletbo i Serra 2016-08-01 278 indio_dev->name = pdev->name;
974e6f02e27e1b Enric Balletbo i Serra 2016-08-01 279
974e6f02e27e1b Enric Balletbo i Serra 2016-08-01 280 if (physical_device) {
7cbb6681d7e5b8 Gwendal Grignou 2022-04-27 281 enum motionsensor_location loc;
7cbb6681d7e5b8 Gwendal Grignou 2022-04-27 282
974e6f02e27e1b Enric Balletbo i Serra 2016-08-01 283 state->param.cmd = MOTIONSENSE_CMD_INFO;
974e6f02e27e1b Enric Balletbo i Serra 2016-08-01 284 state->param.info.sensor_num = sensor_platform->sensor_num;
f53199c0bc6265 Gwendal Grignou 2019-07-18 285 ret = cros_ec_motion_send_host_cmd(state, 0);
f53199c0bc6265 Gwendal Grignou 2019-07-18 286 if (ret) {
974e6f02e27e1b Enric Balletbo i Serra 2016-08-01 287 dev_warn(dev, "Can not access sensor info\n");
f53199c0bc6265 Gwendal Grignou 2019-07-18 288 return ret;
974e6f02e27e1b Enric Balletbo i Serra 2016-08-01 289 }
974e6f02e27e1b Enric Balletbo i Serra 2016-08-01 290 state->type = state->resp->info.type;
7cbb6681d7e5b8 Gwendal Grignou 2022-04-27 291 loc = state->resp->info.location;
7cbb6681d7e5b8 Gwendal Grignou 2022-04-27 292 if (loc == MOTIONSENSE_LOC_BASE)
7cbb6681d7e5b8 Gwendal Grignou 2022-04-27 293 indio_dev->label = "accel-base";
7cbb6681d7e5b8 Gwendal Grignou 2022-04-27 294 else if (loc == MOTIONSENSE_LOC_LID)
7cbb6681d7e5b8 Gwendal Grignou 2022-04-27 295 indio_dev->label = "accel-display";
7cbb6681d7e5b8 Gwendal Grignou 2022-04-27 296 else if (loc == MOTIONSENSE_LOC_CAMERA)
7cbb6681d7e5b8 Gwendal Grignou 2022-04-27 297 indio_dev->label = "accel-camera";
12bf745c9afb67 Gwendal Grignou 2019-07-15 298
12bf745c9afb67 Gwendal Grignou 2019-07-15 299 /* Set sign vector, only used for backward compatibility. */
12bf745c9afb67 Gwendal Grignou 2019-07-15 300 memset(state->sign, 1, CROS_EC_SENSOR_MAX_AXIS);
ae7b02ad2f32d3 Fabien Lahoudere 2019-07-16 301
22087c850e8e56 Gwendal Grignou 2019-08-26 302 for (i = CROS_EC_SENSOR_X; i < CROS_EC_SENSOR_MAX_AXIS; i++)
22087c850e8e56 Gwendal Grignou 2019-08-26 303 state->calib[i].scale = MOTION_SENSE_DEFAULT_SCALE;
22087c850e8e56 Gwendal Grignou 2019-08-26 304
ae7b02ad2f32d3 Fabien Lahoudere 2019-07-16 305 /* 0 is a correct value used to stop the device */
ae7b02ad2f32d3 Fabien Lahoudere 2019-07-16 306 if (state->msg->version < 3) {
ae7b02ad2f32d3 Fabien Lahoudere 2019-07-16 307 get_default_min_max_freq(state->resp->info.type,
317a0ebe53f465 Gwendal Grignou 2020-03-27 308 &frequencies[1],
317a0ebe53f465 Gwendal Grignou 2020-03-27 309 &frequencies[2],
cb87556068146d Gwendal Grignou 2020-03-27 310 &state->fifo_max_event_count);
56e4f2dda23c6d Gwendal Grignou 2020-06-30 311 } else {
56e4f2dda23c6d Gwendal Grignou 2020-06-30 312 if (state->resp->info_3.max_frequency == 0) {
56e4f2dda23c6d Gwendal Grignou 2020-06-30 313 get_default_min_max_freq(state->resp->info.type,
56e4f2dda23c6d Gwendal Grignou 2020-06-30 314 &frequencies[1],
56e4f2dda23c6d Gwendal Grignou 2020-06-30 315 &frequencies[2],
56e4f2dda23c6d Gwendal Grignou 2020-06-30 316 &temp);
ae7b02ad2f32d3 Fabien Lahoudere 2019-07-16 317 } else {
317a0ebe53f465 Gwendal Grignou 2020-03-27 318 frequencies[1] = state->resp->info_3.min_frequency;
317a0ebe53f465 Gwendal Grignou 2020-03-27 319 frequencies[2] = state->resp->info_3.max_frequency;
56e4f2dda23c6d Gwendal Grignou 2020-06-30 320 }
56e4f2dda23c6d Gwendal Grignou 2020-06-30 321 state->fifo_max_event_count = state->resp->info_3.fifo_max_event_count;
ae7b02ad2f32d3 Fabien Lahoudere 2019-07-16 322 }
317a0ebe53f465 Gwendal Grignou 2020-03-27 323 for (i = 0; i < ARRAY_SIZE(frequencies); i++) {
317a0ebe53f465 Gwendal Grignou 2020-03-27 324 state->frequencies[2 * i] = frequencies[i] / 1000;
317a0ebe53f465 Gwendal Grignou 2020-03-27 325 state->frequencies[2 * i + 1] =
317a0ebe53f465 Gwendal Grignou 2020-03-27 326 (frequencies[i] % 1000) * 1000;
317a0ebe53f465 Gwendal Grignou 2020-03-27 327 }
aa984f1ba4a477 Gwendal Grignou 2020-03-27 328
aa984f1ba4a477 Gwendal Grignou 2020-03-27 329 if (cros_ec_check_features(ec, EC_FEATURE_MOTION_SENSE_FIFO)) {
aa984f1ba4a477 Gwendal Grignou 2020-03-27 330 /*
aa984f1ba4a477 Gwendal Grignou 2020-03-27 331 * Create a software buffer, feed by the EC FIFO.
aa984f1ba4a477 Gwendal Grignou 2020-03-27 332 * We can not use trigger here, as events are generated
aa984f1ba4a477 Gwendal Grignou 2020-03-27 333 * as soon as sample_frequency is set.
aa984f1ba4a477 Gwendal Grignou 2020-03-27 334 */
f67c6c73cb07a4 Miquel Raynal 2022-02-07 335 ret = devm_iio_kfifo_buffer_setup_ext(dev, indio_dev, NULL,
80346b2b55fcbb Gwendal Grignou 2021-03-18 @336 cros_ec_sensor_fifo_attributes);
17395ce299211a Alexandru Ardelean 2021-02-15 337 if (ret)
17395ce299211a Alexandru Ardelean 2021-02-15 338 return ret;
aa984f1ba4a477 Gwendal Grignou 2020-03-27 339
aa984f1ba4a477 Gwendal Grignou 2020-03-27 340 /* Timestamp coming from FIFO are in ns since boot. */
aa984f1ba4a477 Gwendal Grignou 2020-03-27 341 ret = iio_device_set_clock(indio_dev, CLOCK_BOOTTIME);
aa984f1ba4a477 Gwendal Grignou 2020-03-27 342 if (ret)
aa984f1ba4a477 Gwendal Grignou 2020-03-27 343 return ret;
165aea80e2e2c7 Alexandru Ardelean 2020-09-29 344
80346b2b55fcbb Gwendal Grignou 2021-03-18 345 } else {
aa984f1ba4a477 Gwendal Grignou 2020-03-27 346 /*
aa984f1ba4a477 Gwendal Grignou 2020-03-27 347 * The only way to get samples in buffer is to set a
d18ffd83745a74 Keyur Patel 2020-06-09 348 * software trigger (systrig, hrtimer).
aa984f1ba4a477 Gwendal Grignou 2020-03-27 349 */
80346b2b55fcbb Gwendal Grignou 2021-03-18 350 ret = devm_iio_triggered_buffer_setup(dev, indio_dev,
80346b2b55fcbb Gwendal Grignou 2021-03-18 351 NULL, trigger_capture, NULL);
aa984f1ba4a477 Gwendal Grignou 2020-03-27 352 if (ret)
aa984f1ba4a477 Gwendal Grignou 2020-03-27 353 return ret;
aa984f1ba4a477 Gwendal Grignou 2020-03-27 354 }
974e6f02e27e1b Enric Balletbo i Serra 2016-08-01 355 }
974e6f02e27e1b Enric Balletbo i Serra 2016-08-01 356
974e6f02e27e1b Enric Balletbo i Serra 2016-08-01 357 return 0;
974e6f02e27e1b Enric Balletbo i Serra 2016-08-01 358 }
974e6f02e27e1b Enric Balletbo i Serra 2016-08-01 359 EXPORT_SYMBOL_GPL(cros_ec_sensors_core_init);
974e6f02e27e1b Enric Balletbo i Serra 2016-08-01 360
--
0-DAY CI Kernel Test Service
https://01.org/lkp
Hi Matti,
I love your patch! Yet something to improve:
[auto build test ERROR on v6.0-rc7]
[also build test ERROR on linus/master]
[cannot apply to jic23-iio/togreg next-20220930]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Matti-Vaittinen/iio-Add-IIO_STATIC_CONST_DEVICE_ATTR/20220930-191558
base: f76349cf41451c5c42a99f18a9163377e4b364ff
config: i386-randconfig-a002
compiler: clang version 14.0.6 (https://github.com/llvm/llvm-project f28c006a5895fc0e329fe15fead81e37457cb1d1)
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# https://github.com/intel-lab-lkp/linux/commit/71aecc2b7a59a431f1a4ca7f6e4670f6ca889cb0
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Matti-Vaittinen/iio-Add-IIO_STATIC_CONST_DEVICE_ATTR/20220930-191558
git checkout 71aecc2b7a59a431f1a4ca7f6e4670f6ca889cb0
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=i386 SHELL=/bin/bash
If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <[email protected]>
All errors (new ones prefixed by >>):
>> drivers/iio/buffer/industrialio-buffer-dmaengine.c:204:39: error: incompatible pointer types assigning to 'const struct iio_dev_attr **' from 'const struct attribute *[2]' [-Werror,-Wincompatible-pointer-types]
dmaengine_buffer->queue.buffer.attrs = iio_dmaengine_buffer_attrs;
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.
vim +204 drivers/iio/buffer/industrialio-buffer-dmaengine.c
4538c185680996 Lars-Peter Clausen 2019-12-11 149
2d6ca60f328450 Lars-Peter Clausen 2015-10-13 150 /**
2d6ca60f328450 Lars-Peter Clausen 2015-10-13 151 * iio_dmaengine_buffer_alloc() - Allocate new buffer which uses DMAengine
2d6ca60f328450 Lars-Peter Clausen 2015-10-13 152 * @dev: Parent device for the buffer
2d6ca60f328450 Lars-Peter Clausen 2015-10-13 153 * @channel: DMA channel name, typically "rx".
2d6ca60f328450 Lars-Peter Clausen 2015-10-13 154 *
2d6ca60f328450 Lars-Peter Clausen 2015-10-13 155 * This allocates a new IIO buffer which internally uses the DMAengine framework
2d6ca60f328450 Lars-Peter Clausen 2015-10-13 156 * to perform its transfers. The parent device will be used to request the DMA
2d6ca60f328450 Lars-Peter Clausen 2015-10-13 157 * channel.
2d6ca60f328450 Lars-Peter Clausen 2015-10-13 158 *
2d6ca60f328450 Lars-Peter Clausen 2015-10-13 159 * Once done using the buffer iio_dmaengine_buffer_free() should be used to
2d6ca60f328450 Lars-Peter Clausen 2015-10-13 160 * release it.
2d6ca60f328450 Lars-Peter Clausen 2015-10-13 161 */
25918a9c641c3c Alexandru Ardelean 2020-09-23 162 static struct iio_buffer *iio_dmaengine_buffer_alloc(struct device *dev,
2d6ca60f328450 Lars-Peter Clausen 2015-10-13 163 const char *channel)
2d6ca60f328450 Lars-Peter Clausen 2015-10-13 164 {
2d6ca60f328450 Lars-Peter Clausen 2015-10-13 165 struct dmaengine_buffer *dmaengine_buffer;
2d6ca60f328450 Lars-Peter Clausen 2015-10-13 166 unsigned int width, src_width, dest_width;
2d6ca60f328450 Lars-Peter Clausen 2015-10-13 167 struct dma_slave_caps caps;
2d6ca60f328450 Lars-Peter Clausen 2015-10-13 168 struct dma_chan *chan;
2d6ca60f328450 Lars-Peter Clausen 2015-10-13 169 int ret;
2d6ca60f328450 Lars-Peter Clausen 2015-10-13 170
2d6ca60f328450 Lars-Peter Clausen 2015-10-13 171 dmaengine_buffer = kzalloc(sizeof(*dmaengine_buffer), GFP_KERNEL);
2d6ca60f328450 Lars-Peter Clausen 2015-10-13 172 if (!dmaengine_buffer)
2d6ca60f328450 Lars-Peter Clausen 2015-10-13 173 return ERR_PTR(-ENOMEM);
2d6ca60f328450 Lars-Peter Clausen 2015-10-13 174
f339f979bb333e Peter Ujfalusi 2019-11-13 175 chan = dma_request_chan(dev, channel);
2d6ca60f328450 Lars-Peter Clausen 2015-10-13 176 if (IS_ERR(chan)) {
2d6ca60f328450 Lars-Peter Clausen 2015-10-13 177 ret = PTR_ERR(chan);
2d6ca60f328450 Lars-Peter Clausen 2015-10-13 178 goto err_free;
2d6ca60f328450 Lars-Peter Clausen 2015-10-13 179 }
2d6ca60f328450 Lars-Peter Clausen 2015-10-13 180
2d6ca60f328450 Lars-Peter Clausen 2015-10-13 181 ret = dma_get_slave_caps(chan, &caps);
2d6ca60f328450 Lars-Peter Clausen 2015-10-13 182 if (ret < 0)
2d6ca60f328450 Lars-Peter Clausen 2015-10-13 183 goto err_free;
2d6ca60f328450 Lars-Peter Clausen 2015-10-13 184
2d6ca60f328450 Lars-Peter Clausen 2015-10-13 185 /* Needs to be aligned to the maximum of the minimums */
2d6ca60f328450 Lars-Peter Clausen 2015-10-13 186 if (caps.src_addr_widths)
2d6ca60f328450 Lars-Peter Clausen 2015-10-13 187 src_width = __ffs(caps.src_addr_widths);
2d6ca60f328450 Lars-Peter Clausen 2015-10-13 188 else
2d6ca60f328450 Lars-Peter Clausen 2015-10-13 189 src_width = 1;
2d6ca60f328450 Lars-Peter Clausen 2015-10-13 190 if (caps.dst_addr_widths)
2d6ca60f328450 Lars-Peter Clausen 2015-10-13 191 dest_width = __ffs(caps.dst_addr_widths);
2d6ca60f328450 Lars-Peter Clausen 2015-10-13 192 else
2d6ca60f328450 Lars-Peter Clausen 2015-10-13 193 dest_width = 1;
2d6ca60f328450 Lars-Peter Clausen 2015-10-13 194 width = max(src_width, dest_width);
2d6ca60f328450 Lars-Peter Clausen 2015-10-13 195
2d6ca60f328450 Lars-Peter Clausen 2015-10-13 196 INIT_LIST_HEAD(&dmaengine_buffer->active);
2d6ca60f328450 Lars-Peter Clausen 2015-10-13 197 dmaengine_buffer->chan = chan;
2d6ca60f328450 Lars-Peter Clausen 2015-10-13 198 dmaengine_buffer->align = width;
2d6ca60f328450 Lars-Peter Clausen 2015-10-13 199 dmaengine_buffer->max_size = dma_get_max_seg_size(chan->device->dev);
2d6ca60f328450 Lars-Peter Clausen 2015-10-13 200
2d6ca60f328450 Lars-Peter Clausen 2015-10-13 201 iio_dma_buffer_init(&dmaengine_buffer->queue, chan->device->dev,
2d6ca60f328450 Lars-Peter Clausen 2015-10-13 202 &iio_dmaengine_default_ops);
2d6ca60f328450 Lars-Peter Clausen 2015-10-13 203
5e6dc43e2caa14 Alexandru Ardelean 2020-09-29 @204 dmaengine_buffer->queue.buffer.attrs = iio_dmaengine_buffer_attrs;
2d6ca60f328450 Lars-Peter Clausen 2015-10-13 205 dmaengine_buffer->queue.buffer.access = &iio_dmaengine_buffer_ops;
2d6ca60f328450 Lars-Peter Clausen 2015-10-13 206
2d6ca60f328450 Lars-Peter Clausen 2015-10-13 207 return &dmaengine_buffer->queue.buffer;
2d6ca60f328450 Lars-Peter Clausen 2015-10-13 208
2d6ca60f328450 Lars-Peter Clausen 2015-10-13 209 err_free:
2d6ca60f328450 Lars-Peter Clausen 2015-10-13 210 kfree(dmaengine_buffer);
2d6ca60f328450 Lars-Peter Clausen 2015-10-13 211 return ERR_PTR(ret);
2d6ca60f328450 Lars-Peter Clausen 2015-10-13 212 }
2d6ca60f328450 Lars-Peter Clausen 2015-10-13 213
--
0-DAY CI Kernel Test Service
https://01.org/lkp