Skip to contentSkip to conversation

MISC: add const to bin_attribute structures

PATCH In review Bhumika Goyal 2 participants 2 messages Aug 2, 2017 – Aug 3, 2017 Char and misc drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 MISC: add const to bin_attribute structures

Add const to bin_attribute structures as they are only passed to the functions sysfs_{remove/create}_bin_file. The arguments passed are of type const, so declare the structures to be const.

Done using Coccinelle.

@m disable optional_qualifier@
identifier s;
position p;
@@
static struct bin_attribute s@p={...};

@okay1@
position p;
identifier m.s;
@@
(
sysfs_create_bin_file(...,&s@p,...)
|
sysfs_remove_bin_file(...,&s@p,...)
)

@bad@
position p!={m.p,okay1.p};
identifier m.s;
@@
s@p

@change depends on !bad disable optional_qualifier@ identifier m.s;
@@
static
+const
struct bin_attribute s={...};

---
 drivers/misc/ds1682.c         | 2 +-
 drivers/misc/eeprom/eeprom.c  | 2 +-
 drivers/misc/eeprom/max6875.c | 2 +-
 drivers/misc/pch_phub.c       | 2 +-
 4 files changed, 4 insertions(+), 4 deletions(-)
drivers/misc/ds1682.c +1 -1
index 28bb495..7231260 100644
@@ -173,7 +173,7 @@ static ssize_t ds1682_eeprom_write(struct file *filp, struct kobject *kobj,
 	return count;
 }
 
-static struct bin_attribute ds1682_eeprom_attr = {
+static const struct bin_attribute ds1682_eeprom_attr = {
 	.attr = {
 		.name = "eeprom",
 		.mode = S_IRUGO | S_IWUSR,
drivers/misc/eeprom/eeprom.c +1 -1
index 2fad790..60e3d91 100644
@@ -114,7 +114,7 @@ static ssize_t eeprom_read(struct file *filp, struct kobject *kobj,
 	return count;
 }
 
-static struct bin_attribute eeprom_attr = {
+static const struct bin_attribute eeprom_attr = {
 	.attr = {
 		.name = "eeprom",
 		.mode = S_IRUGO,
drivers/misc/eeprom/max6875.c +1 -1
index e4dd93b..0e32709 100644
@@ -124,7 +124,7 @@ static ssize_t max6875_read(struct file *filp, struct kobject *kobj,
 	return count;
 }
 
-static struct bin_attribute user_eeprom_attr = {
+static const struct bin_attribute user_eeprom_attr = {
 	.attr = {
 		.name = "eeprom",
 		.mode = S_IRUGO,
drivers/misc/pch_phub.c +1 -1
index e42bdc9..7410a07 100644
@@ -659,7 +659,7 @@ static ssize_t store_pch_mac(struct device *dev, struct device_attribute *attr,
 
 static DEVICE_ATTR(pch_mac, S_IRUGO | S_IWUSR, show_pch_mac, store_pch_mac);
 
-static struct bin_attribute pch_bin_attr = {
+static const struct bin_attribute pch_bin_attr = {
 	.attr = {
 		.name = "pch_firmware",
 		.mode = S_IRUGO | S_IWUSR,
Signature · 1 line
1.9.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 35 lines · Bhumika Goyal

Add const to bin_attribute structures as they are only passed to the functions sysfs_{remove/create}_bin_file. The arguments passed are of type const, so declare the structures to be const.

Done using Coccinelle.

@m disable optional_qualifier@
identifier s;
position p;
@@
static struct bin_attribute s@p={...};

@okay1@
position p;
identifier m.s;
@@
(
sysfs_create_bin_file(...,&s@p,...)
|
sysfs_remove_bin_file(...,&s@p,...)
)

@bad@
position p!={m.p,okay1.p};
identifier m.s;
@@
s@p

@change depends on !bad disable optional_qualifier@ identifier m.s;
@@
static
+const
struct bin_attribute s={...};

Quoted 8 lines
---
 drivers/misc/ds1682.c         | 2 +-
 drivers/misc/eeprom/eeprom.c  | 2 +-
 drivers/misc/eeprom/max6875.c | 2 +-
 drivers/misc/pch_phub.c       | 2 +-
 4 files changed, 4 insertions(+), 4 deletions(-)

(...)

Thanks,

Signature · 2 lines
Jean Delvare
SUSE L3 Support