Skip to contentSkip to conversation

iio: buffer: use sysfs_attr_init() on allocated attrs

PATCH In review Alexandru Ardelean 3 participants 3 messages Apr 2, 2021 – Apr 6, 2021 IIO

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 iio: buffer: use sysfs_attr_init() on allocated attrs

When dynamically allocating sysfs attributes, it's a good idea to call sysfs_attr_init() on them to initialize lock_class_keys. This change does that.

The lock_class_keys are set when the CONFIG_DEBUG_LOCK_ALLOC symbol is enabled. Which is [likely] one reason why I did not see this during development.

I also am not able to see this even with CONFIG_DEBUG_LOCK_ALLOC enabled, so this may [likely] be reproduce-able on some system configurations.

This was reported via:
https://lore.kernel.org/linux-iio/CA+U=DsrsvGgXEF30-vXuXS_k=-mjSjiBwEEzwKb1hJVn1P98OA@mail.gmail.com/T/#u

Fixes 15097c7a1adc ("iio: buffer: wrap all buffer attributes into iio_dev_attr")

---

@Marek: could you maybe test this on your setup?

I haven't been able to reproduce this on mine.

Thanks
Alex

 drivers/iio/industrialio-buffer.c | 1 +
 1 file changed, 1 insertion(+)
drivers/iio/industrialio-buffer.c +1 -0
index ee5aab9d4a23..06b2ea087408 100644
@@ -1309,6 +1309,7 @@ static struct attribute *iio_buffer_wrap_attr(struct iio_buffer *buffer,
 	iio_attr->buffer = buffer;
 	memcpy(&iio_attr->dev_attr, dattr, sizeof(iio_attr->dev_attr));
 	iio_attr->dev_attr.attr.name = kstrdup_const(attr->name, GFP_KERNEL);
+	sysfs_attr_init(&iio_attr->dev_attr.attr);
 
 	list_add(&iio_attr->l, &buffer->buffer_attr_list);
 
Signature · 1 line
2.30.2
maintainer
#1 lore raw
Quoted 14 lines · On Fri, 2 Apr 2021 20:42:26 +0300 Alexandru Ardelean <[email protected]>…

When dynamically allocating sysfs attributes, it's a good idea to call sysfs_attr_init() on them to initialize lock_class_keys. This change does that.

The lock_class_keys are set when the CONFIG_DEBUG_LOCK_ALLOC symbol is enabled. Which is [likely] one reason why I did not see this during development.

I also am not able to see this even with CONFIG_DEBUG_LOCK_ALLOC enabled, so this may [likely] be reproduce-able on some system configurations.

This was reported via:
https://lore.kernel.org/linux-iio/CA+U=DsrsvGgXEF30-vXuXS_k=-mjSjiBwEEzwKb1hJVn1P98OA@mail.gmail.com/T/#u

Quoted 8 lines
Fixes 15097c7a1adc ("iio: buffer: wrap all buffer attributes into iio_dev_attr")

---

@Marek: could you maybe test this on your setup?

I haven't been able to reproduce this on mine.

I'm fairly sure this is the right fix, and 'should' resolve the issue Marek saw so I'm going to queue it up.

Applied to the togreg branch of iio.git and pushed out as testing for the autobuilders to poke at it and see if we missed anything.

Thanks,

Jonathan

Quoted 19 lines

Thanks
Alex

 drivers/iio/industrialio-buffer.c | 1 +
 1 file changed, 1 insertion(+)
drivers/iio/industrialio-buffer.c +1 -0
index ee5aab9d4a23..06b2ea087408 100644
@@ -1309,6 +1309,7 @@ static struct attribute *iio_buffer_wrap_attr(struct iio_buffer *buffer,
 	iio_attr->buffer = buffer;
 	memcpy(&iio_attr->dev_attr, dattr, sizeof(iio_attr->dev_attr));
 	iio_attr->dev_attr.attr.name = kstrdup_const(attr->name, GFP_KERNEL);
+	sysfs_attr_init(&iio_attr->dev_attr.attr);
 
 	list_add(&iio_attr->l, &buffer->buffer_attr_list);
 
Tested-by on v1 1/1
#2 lore raw
In reply to Alexandru Ardelean
Quoted 14 lines · Alexandru Ardelean

When dynamically allocating sysfs attributes, it's a good idea to call sysfs_attr_init() on them to initialize lock_class_keys. This change does that.

The lock_class_keys are set when the CONFIG_DEBUG_LOCK_ALLOC symbol is enabled. Which is [likely] one reason why I did not see this during development.

I also am not able to see this even with CONFIG_DEBUG_LOCK_ALLOC enabled, so this may [likely] be reproduce-able on some system configurations.

This was reported via:
https://lore.kernel.org/linux-iio/CA+U=DsrsvGgXEF30-vXuXS_k=-mjSjiBwEEzwKb1hJVn1P98OA@mail.gmail.com/T/#u

Quoted 8 lines
Fixes 15097c7a1adc ("iio: buffer: wrap all buffer attributes into iio_dev_attr")

---

@Marek: could you maybe test this on your setup?

I haven't been able to reproduce this on mine.

Works fine with this fix. Thanks!

Quoted 11 lines

Thanks
Alex

  drivers/iio/industrialio-buffer.c | 1 +
  1 file changed, 1 insertion(+)
drivers/iio/industrialio-buffer.c +0 -0
index ee5aab9d4a23..06b2ea087408 100644

drivers/iio/industrialio-buffer.c static struct attribute *iio_buffer_wrap_attr(struct iio_buffer *buffer, · line 1315

Quoted 7 lines
drivers/iio/industrialio-buffer.c +1 -0
@@ -1309,6 +1309,7 @@ static struct attribute *iio_buffer_wrap_attr(struct iio_buffer *buffer,
  	iio_attr->buffer = buffer;
  	memcpy(&iio_attr->dev_attr, dattr, sizeof(iio_attr->dev_attr));
  	iio_attr->dev_attr.attr.name = kstrdup_const(attr->name, GFP_KERNEL);
+	sysfs_attr_init(&iio_attr->dev_attr.attr);
 
  	list_add(&iio_attr->l, &buffer->buffer_attr_list);
 

Best regards

Signature · 2 lines
Marek Szyprowski, PhD
Samsung R&D Institute Poland