Skip to contentSkip to conversation

fpga: dfl: fme: Constify static attribute_group structs

PATCH Applied Rikard Falkeborn 3 participants 5 messages Jan 8, 2021 – Jan 10, 2021

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

PATCH 1/1 fpga: dfl: fme: Constify static attribute_group structs

The only usage of these is to put their addresses in arrays of pointers to const attribute_groups. Make them const to allow the compiler to put them in read-only memory.

---
 drivers/fpga/dfl-fme-perf.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/fpga/dfl-fme-perf.c +3 -3
index 531266287eee..4299145ef347 100644
@@ -192,7 +192,7 @@ static struct attribute *fme_perf_cpumask_attrs[] = {
 	NULL,
 };
 
-static struct attribute_group fme_perf_cpumask_group = {
+static const struct attribute_group fme_perf_cpumask_group = {
 	.attrs = fme_perf_cpumask_attrs,
 };
 
@@ -225,7 +225,7 @@ static struct attribute *fme_perf_format_attrs[] = {
 	NULL,
 };
 
-static struct attribute_group fme_perf_format_group = {
+static const struct attribute_group fme_perf_format_group = {
 	.name = "format",
 	.attrs = fme_perf_format_attrs,
 };
@@ -239,7 +239,7 @@ static struct attribute *fme_perf_events_attrs_empty[] = {
 	NULL,
 };
 
-static struct attribute_group fme_perf_events_group = {
+static const struct attribute_group fme_perf_events_group = {
 	.name = "events",
 	.attrs = fme_perf_events_attrs_empty,
 };
Signature · 1 line
2.30.0
reviewer
#1 lore raw
Quoted 7 lines · Rikard Falkeborn

The only usage of these is to put their addresses in arrays of pointers to const attribute_groups. Make them const to allow the compiler to put them in read-only memory.

---
 drivers/fpga/dfl-fme-perf.c | 6 +++---

This looks ok.

There are other 'static struct's in drivers/fpga.

Why is the change limited to this file ?

Tom

Quoted 33 lines
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/fpga/dfl-fme-perf.c +3 -3
index 531266287eee..4299145ef347 100644
@@ -192,7 +192,7 @@ static struct attribute *fme_perf_cpumask_attrs[] = {
 	NULL,
 };
 
-static struct attribute_group fme_perf_cpumask_group = {
+static const struct attribute_group fme_perf_cpumask_group = {
 	.attrs = fme_perf_cpumask_attrs,
 };
 
@@ -225,7 +225,7 @@ static struct attribute *fme_perf_format_attrs[] = {
 	NULL,
 };
 
-static struct attribute_group fme_perf_format_group = {
+static const struct attribute_group fme_perf_format_group = {
 	.name = "format",
 	.attrs = fme_perf_format_attrs,
 };
@@ -239,7 +239,7 @@ static struct attribute *fme_perf_events_attrs_empty[] = {
 	NULL,
 };
 
-static struct attribute_group fme_perf_events_group = {
+static const struct attribute_group fme_perf_events_group = {
 	.name = "events",
 	.attrs = fme_perf_events_attrs_empty,
 };
#2 lore raw
Quoted 10 lines · Tom Rix
Quoted 7 lines · Rikard Falkeborn

The only usage of these is to put their addresses in arrays of pointers to const attribute_groups. Make them const to allow the compiler to put them in read-only memory.

---
 drivers/fpga/dfl-fme-perf.c | 6 +++---
Quoted 8 lines

This looks ok.

There are other 'static struct's in drivers/fpga.

Why is the change limited to this file ?

Tom

I have a WIP coccinelle script to constify static struct attribute_group and this is the only file in drivers/fpga which has non-const struct attribute_group, that's why it's limited to this file. I could have mentioned that in the commit message.

Rikard

Quoted 34 lines
Quoted 33 lines
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/fpga/dfl-fme-perf.c +3 -3
index 531266287eee..4299145ef347 100644
@@ -192,7 +192,7 @@ static struct attribute *fme_perf_cpumask_attrs[] = {
 	NULL,
 };
 
-static struct attribute_group fme_perf_cpumask_group = {
+static const struct attribute_group fme_perf_cpumask_group = {
 	.attrs = fme_perf_cpumask_attrs,
 };
 
@@ -225,7 +225,7 @@ static struct attribute *fme_perf_format_attrs[] = {
 	NULL,
 };
 
-static struct attribute_group fme_perf_format_group = {
+static const struct attribute_group fme_perf_format_group = {
 	.name = "format",
 	.attrs = fme_perf_format_attrs,
 };
@@ -239,7 +239,7 @@ static struct attribute *fme_perf_events_attrs_empty[] = {
 	NULL,
 };
 
-static struct attribute_group fme_perf_events_group = {
+static const struct attribute_group fme_perf_events_group = {
 	.name = "events",
 	.attrs = fme_perf_events_attrs_empty,
 };
reviewer Reviewed-by
#3 lore raw
Quoted 13 lines · Rikard Falkeborn
Quoted 12 lines · Tom Rix
Quoted 7 lines · Rikard Falkeborn

The only usage of these is to put their addresses in arrays of pointers to const attribute_groups. Make them const to allow the compiler to put them in read-only memory.

---
 drivers/fpga/dfl-fme-perf.c | 6 +++---

This looks ok.

There are other 'static struct's in drivers/fpga.

Quoted 8 lines
Quoted 4 lines

Why is the change limited to this file ?

Tom

I have a WIP coccinelle script to constify static struct attribute_group and this is the only file in drivers/fpga which has non-const struct attribute_group, that's why it's limited to this file. I could have mentioned that in the commit message.

No worries, thanks for the change!

Quoted 36 lines

Rikard

Quoted 33 lines
Quoted 33 lines
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/fpga/dfl-fme-perf.c +3 -3
index 531266287eee..4299145ef347 100644
@@ -192,7 +192,7 @@ static struct attribute *fme_perf_cpumask_attrs[] = {
 	NULL,
 };
 
-static struct attribute_group fme_perf_cpumask_group = {
+static const struct attribute_group fme_perf_cpumask_group = {
 	.attrs = fme_perf_cpumask_attrs,
 };
 
@@ -225,7 +225,7 @@ static struct attribute *fme_perf_format_attrs[] = {
 	NULL,
 };
 
-static struct attribute_group fme_perf_format_group = {
+static const struct attribute_group fme_perf_format_group = {
 	.name = "format",
 	.attrs = fme_perf_format_attrs,
 };
@@ -239,7 +239,7 @@ static struct attribute *fme_perf_events_attrs_empty[] = {
 	NULL,
 };
 
-static struct attribute_group fme_perf_events_group = {
+static const struct attribute_group fme_perf_events_group = {
 	.name = "events",
 	.attrs = fme_perf_events_attrs_empty,
 };
maintainer Applied
#4 lore raw
Quoted 59 lines · Tom Rix
Quoted 13 lines · Rikard Falkeborn
Quoted 12 lines · Tom Rix
Quoted 7 lines · Rikard Falkeborn

The only usage of these is to put their addresses in arrays of pointers to const attribute_groups. Make them const to allow the compiler to put them in read-only memory.

---
 drivers/fpga/dfl-fme-perf.c | 6 +++---

This looks ok.

There are other 'static struct's in drivers/fpga.

Quoted 8 lines
Quoted 4 lines

Why is the change limited to this file ?

Tom

I have a WIP coccinelle script to constify static struct attribute_group and this is the only file in drivers/fpga which has non-const struct attribute_group, that's why it's limited to this file. I could have mentioned that in the commit message.

No worries, thanks for the change!

Quoted 31 lines

Rikard

Quoted 28 lines
Quoted 28 lines
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/fpga/dfl-fme-perf.c +2 -2
index 531266287eee..4299145ef347 100644
@@ -192,7 +192,7 @@ static struct attribute *fme_perf_cpumask_attrs[] = {
 	NULL,
 };
 
-static struct attribute_group fme_perf_cpumask_group = {
+static const struct attribute_group fme_perf_cpumask_group = {
 	.attrs = fme_perf_cpumask_attrs,
 };
 
@@ -225,7 +225,7 @@ static struct attribute *fme_perf_format_attrs[] = {
 	NULL,
 };
 
-static struct attribute_group fme_perf_format_group = {
+static const struct attribute_group fme_perf_format_group = {
 	.name = "format",
 	.attrs = fme_perf_format_attrs,
 };
@@ -239,7 +239,7 @@ static struct attribute *fme_perf_events_attrs_empty[] = {
 	NULL,
 };
 
Quoted 6 lines
Quoted 5 lines
Quoted 5 lines

drivers/fpga/dfl-fme-perf.c static struct attribute *fme_perf_events_attrs_empty[] = { · line 245

Quoted 5 lines
drivers/fpga/dfl-fme-perf.c +1 -1
-static struct attribute_group fme_perf_events_group = {
+static const struct attribute_group fme_perf_events_group = {
 	.name = "events",
 	.attrs = fme_perf_events_attrs_empty,
 };

Applied,

Thanks