Staging: iio: constify attribute_group structures
Subsystems (4)
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
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 1ea7drivers/staging/iio/adc/ad7280a.o
File size after: drivers/staging/iio/adc/ad7280a.o
text data bss dec hex filename
6551 544 776 7871 1ebfdrivers/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
@@ -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
PATCH 2/2 Staging: iio: light: constify attribute_group structures
In reply to Bhumika GoyalCheck 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 1d9ddrivers/staging/iio/light/tsl2583.o
File size after: drivers/staging/iio/light/tsl2583.o
text data bss dec hex filename
6593 988 0 7581 1d9ddrivers/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
@@ -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
Re: [PATCH 1/2] Staging: iio: adc: constify attribute_group structures
In reply to a message not in the archiveQuoted 49 lines · Lars-Peter Clausen
Quoted 48 lines · Bhumika Goyal
Check for
attribute_groupstructures that are only stored in the attrs filed ofiio_infostructure. As the attrs field ofiio_infostructures is constant, so theseattribute_groupstructures can also be declared constant.
Done using coccinelle:@r1 disable
optional_qualifier@
identifier i;
position p;
@@
static structattribute_groupi@p = {...};@ok1@
identifier r1.i;
position p;
structiio_infox;
@@
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
structattribute_groupi={...};@depends on !bad disable optional_qualifier@
identifier r1.i;
@@
+const
structattribute_groupi;File size before:
drivers/staging/iio/adc/ad7280a.o
text data bss dec hex filename
6487 584 776 7847 1ea7drivers/staging/iio/adc/ad7280a.oFile size after:
drivers/staging/iio/adc/ad7280a.o
text data bss dec hex filename
6551 544 776 7871 1ebfdrivers/staging/iio/adc/ad7280a.o
Quoted 7 lines
Quoted 1 line
Signed-off-by Bhumika Goyal <[email protected]>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_attrsfield in theiio_infostruct is not a const structattribute_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 moreattribute_groupstructs 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@@ -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, };
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_attrsfield in theiio_infostruct is not a const structattribute_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 moreattribute_groupstructs in the drivers that can be made const.
Quoted 5 lines
Well, I thought of constifying the
attribute_groupsstructures for event attributes but then as you said theevent_attrsfiled ofiio_infois not constant so left it. But I would definitely like to work on this further. So, firstly I need to find why theevent_attrsfield can be made constant in theiio_infostructure 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
Re: [PATCH 1/2] Staging: iio: adc: constify attribute_group structures
In reply to a message not in the archiveQuoted 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.
Greg KH
maintainerRe: [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 :)