Skip to contentSkip to conversation

Staging: iio: constify attribute_group structures

PATCH In review Bhumika Goyal 3 participants 7 messages Sep 26, 2016 – Sep 28, 2016 2 messages not in the archive

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

cover Staging: iio: constify attribute_group structures

Constify attribute_group structures.

Bhumika Goyal (2):
Staging: iio: adc: constify attribute_group structures
Staging: iio: light: constify attribute_group structures

 drivers/staging/iio/adc/ad7280a.c   | 2 +-
 drivers/staging/iio/light/tsl2583.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
Signature · 1 line
1.9.1
#1 lore raw

PATCH 1/2 Staging: iio: adc: constify attribute_group structures

Check for attribute_group structures that are only stored in the attrs filed of iio_info structure. As the attrs field of iio_info structures is constant, so these attribute_group structures can also be declared constant.
Done using coccinelle:

@r1 disable optional_qualifier @
identifier i;
position p;
@@
static struct attribute_group i@p = {...};

@ok1@
identifier r1.i;
position p;
struct iio_info x;
@@
x.attrs=&i@p;

@bad@
position p!={r1.p,ok1.p};
identifier r1.i;
@@
i@p

@depends on !bad disable optional_qualifier@
identifier r1.i;
@@
static
+const
struct attribute_group i={...};

@depends on !bad disable optional_qualifier@
identifier r1.i;
@@
+const
struct attribute_group i;

File size before: drivers/staging/iio/adc/ad7280a.o
text data bss dec hex filename
6487 584 776 7847 1ea7
drivers/staging/iio/adc/ad7280a.o

File size after: drivers/staging/iio/adc/ad7280a.o
text data bss dec hex filename
6551 544 776 7871 1ebf
drivers/staging/iio/adc/ad7280a.o

---
 drivers/staging/iio/adc/ad7280a.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/iio/adc/ad7280a.c +1 -1
index 253a7f1..977241e 100644
@@ -478,7 +478,7 @@ static ssize_t ad7280_store_balance_timer(struct device *dev,
 static struct attribute *ad7280_attributes[AD7280A_MAX_CHAIN *
 					   AD7280A_CELLS_PER_DEV * 2 + 1];
 
-static struct attribute_group ad7280_attrs_group = {
+static const struct attribute_group ad7280_attrs_group = {
 	.attrs = ad7280_attributes,
 };
 
Signature · 1 line
1.9.1
#8 lore raw

PATCH 2/2 Staging: iio: light: constify attribute_group structures

In reply to Bhumika Goyal

Check for attribute_group structures that are only stored in the attrs filed of iio_info structure. As the attrs field of iio_info structures is constant, so these attribute_group structures can also be declared constant.
Done using coccinelle

@r1 disable optional_qualifier @
identifier i;
position p;
@@
static struct attribute_group i@p = {...};

@ok1@
identifier r1.i;
position p;
struct iio_info x;
@@
x.attrs=&i@p;

@bad@
position p!={r1.p,ok1.p};
identifier r1.i;
@@
i@p

@depends on !bad disable optional_qualifier@
identifier r1.i;
@@
static
+const
struct attribute_group i={...};

@depends on !bad disable optional_qualifier@
identifier r1.i;
@@
+const
struct attribute_group i;

File size before: drivers/staging/iio/light/tsl2583.o
text data bss dec hex filename
6529 1052 0 7581 1d9d
drivers/staging/iio/light/tsl2583.o

File size after: drivers/staging/iio/light/tsl2583.o
text data bss dec hex filename
6593 988 0 7581 1d9d
drivers/staging/iio/light/tsl2583.o

---
 drivers/staging/iio/light/tsl2583.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/iio/light/tsl2583.c +1 -1
index 05b4ad4..08f1583 100644
@@ -803,7 +803,7 @@ static struct attribute *sysfs_attrs_ctrl[] = {
 	NULL
 };
 
-static struct attribute_group tsl2583_attribute_group = {
+static const struct attribute_group tsl2583_attribute_group = {
 	.attrs = sysfs_attrs_ctrl,
 };
 
Signature · 1 line
1.9.1
#3 lore raw

Re: [PATCH 1/2] Staging: iio: adc: constify attribute_group structures

In reply to a message not in the archive
Quoted 49 lines · Lars-Peter Clausen
Quoted 48 lines · Bhumika Goyal

Check for attribute_group structures that are only stored in the attrs filed of iio_info structure. As the attrs field of iio_info structures is constant, so these attribute_group structures can also be declared constant.
Done using coccinelle:

@r1 disable optional_qualifier @
identifier i;
position p;
@@
static struct attribute_group i@p = {...};

@ok1@
identifier r1.i;
position p;
struct iio_info x;
@@
x.attrs=&i@p;

@bad@
position p!={r1.p,ok1.p};
identifier r1.i;
@@
i@p

@depends on !bad disable optional_qualifier@
identifier r1.i;
@@
static
+const
struct attribute_group i={...};

@depends on !bad disable optional_qualifier@
identifier r1.i;
@@
+const
struct attribute_group i;

File size before: drivers/staging/iio/adc/ad7280a.o
text data bss dec hex filename
6487 584 776 7847 1ea7
drivers/staging/iio/adc/ad7280a.o

File size after: drivers/staging/iio/adc/ad7280a.o
text data bss dec hex filename
6551 544 776 7871 1ebf
drivers/staging/iio/adc/ad7280a.o

Quoted 7 lines
Quoted 1 line

Looks good, thanks. Just as something to remember for future patches, if you send a patch for a single driver it is best to mention the driver in the subject. Usually you can also leave out the sub-subsystem. So in this case something like "staging:iio:ad7280a: ..."

OK, i will keep this is mind.

Quoted 7 lines

This patch also raises another issue. In this driver we have two attribute_groups, one for the device attributes, one for the event attributes. The device attribute group has now been made const, but the event struct has not.

Quoted 5 lines

For some reason the event_attrs field in the iio_info struct is not a const struct attribute_group. Even though there is no reason why it shouldn't be. Let me know if this is something you want to fix, once that is done there are a few more attribute_group structs in the drivers that can be made const.

Well, I thought of constifying the attribute_groups structures for event attributes but then as you said the event_attrs filed of iio_info is not constant so left it. But I would definitely like to work on this further. So, firstly I need to find why the event_attrs field can be made constant in the iio_info structure definition?

Thanks,
Bhumika

Quoted 19 lines
Quoted 18 lines
---
 drivers/staging/iio/adc/ad7280a.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/iio/adc/ad7280a.c +1 -1
index 253a7f1..977241e 100644
@@ -478,7 +478,7 @@ static ssize_t ad7280_store_balance_timer(struct device *dev,
 static struct attribute *ad7280_attributes[AD7280A_MAX_CHAIN *
                                         AD7280A_CELLS_PER_DEV * 2 + 1];
 
-static struct attribute_group ad7280_attrs_group = {
+static const struct attribute_group ad7280_attrs_group = {
      .attrs = ad7280_attributes,
 };
 
#4 lore raw

Re: [PATCH 1/2] Staging: iio: adc: constify attribute_group structures

Quoted 10 lines · Bhumika Goyal
Quoted 10 lines

This patch also raises another issue. In this driver we have two

Quoted 9 lines

attribute_groups, one for the device attributes, one for the event attributes. The device attribute group has now been made const, but the event struct has not.

For some reason the event_attrs field in the iio_info struct is not a const struct attribute_group. Even though there is no reason why it shouldn't be. Let me know if this is something you want to fix, once that is done there are a few more attribute_group structs in the drivers that can be made const.

Quoted 5 lines

Well, I thought of constifying the attribute_groups structures for event attributes but then as you said the event_attrs filed of iio_info is not constant so left it. But I would definitely like to work on this further. So, firstly I need to find why the event_attrs field can be made constant in the iio_info structure definition?

As far as I can tell this is simply an oversight, there is no reason why it should not be const, the IIO core is not going to modify the field, it is handled in the same way as the device attributes. The best way to handle this is send one patch to mark the field const in the iio_info struct (with an explanation in the commit message why that can and should be done) and then send the cleanups as follow up patches.

- Lars

#6 lore raw

Re: [PATCH 1/2] Staging: iio: adc: constify attribute_group structures

In reply to a message not in the archive
Quoted 8 lines · Jonathan Cameron
Quoted 7 lines

Looks good, thanks. Just as something to remember for future patches, if you send a patch for a single driver it is best to mention the driver in the subject. Usually you can also leave out the sub-subsystem. So in this case something like "staging:iio:ad7280a: ..."

Applied to the togreg branch of iio.git and pushed out as testing.

Greg fast-tracked this one, it's already in staging-testing.

maintainer
#7 lore raw

Re: [Outreachy kernel] Re: [PATCH 1/2] Staging: iio: adc: constify attribute_group structures

Quoted 11 lines · Lars-Peter Clausen
Quoted 8 lines · Jonathan Cameron
Quoted 7 lines

Looks good, thanks. Just as something to remember for future patches, if you send a patch for a single driver it is best to mention the driver in the subject. Usually you can also leave out the sub-subsystem. So in this case something like "staging:iio:ad7280a: ..."

Applied to the togreg branch of iio.git and pushed out as testing.

Greg fast-tracked this one, it's already in staging-testing.

That's fine, git handles merges wonderfully :)