Skip to contentSkip to conversation

platform/x86: Constify static attribute_group structs

PATCH In review Rikard Falkeborn 4 participants 8 messages Jun 5, 2021 – Jun 9, 2021

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

cover platform/x86: Constify static attribute_group structs

Constify a couple of static attribute_group structs which are never modified to allow the compiler to put them in read-only memory.

Rikard Falkeborn (4):
platform/x86: hdaps: Constify static attribute_group struct platform/x86: intel_pmt_crashlog: Constify static attribute_group
struct
platform/x86: tc1100-wmi: Constify static attribute_group struct x86/platform/uv: Constify static attribute_group struct

 drivers/platform/x86/hdaps.c              | 2 +-
 drivers/platform/x86/intel_pmt_crashlog.c | 2 +-
 drivers/platform/x86/tc1100-wmi.c         | 2 +-
 drivers/platform/x86/uv_sysfs.c           | 4 ++--
 4 files changed, 5 insertions(+), 5 deletions(-)
Signature · 1 line
2.31.1
#1 lore raw

PATCH 1/4 platform/x86: hdaps: Constify static attribute_group struct

The only use of hdaps_attribute_group is to pass its address to sysfs_create_group() and sysfs_remove_group(), both which takes pointers to const attribute_group structs. Make it const to allow the compiler to put it in read-only memory.

---
 drivers/platform/x86/hdaps.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/platform/x86/hdaps.c +1 -1
index a72270932ec3..9996485f5295 100644
@@ -462,7 +462,7 @@ static struct attribute *hdaps_attributes[] = {
 	NULL,
 };
 
-static struct attribute_group hdaps_attribute_group = {
+static const struct attribute_group hdaps_attribute_group = {
 	.attrs = hdaps_attributes,
 };
 
Signature · 1 line
2.31.1
maintainer Reviewed-by on v1 1/4
#2 lore raw

Re: [PATCH 1/4] platform/x86: hdaps: Constify static attribute_group struct

Quoted 6 lines

The only use of hdaps_attribute_group is to pass its address to sysfs_create_group() and sysfs_remove_group(), both which takes pointers to const attribute_group structs. Make it const to allow the compiler to put it in read-only memory.

Thanks for the patch and keeping me informed.

Quoted 18 lines
---
  drivers/platform/x86/hdaps.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/platform/x86/hdaps.c +1 -1
index a72270932ec3..9996485f5295 100644
@@ -462,7 +462,7 @@ static struct attribute *hdaps_attributes[] = {
  	NULL,
  };
 
-static struct attribute_group hdaps_attribute_group = {
+static const struct attribute_group hdaps_attribute_group = {
  	.attrs = hdaps_attributes,
  };
 
#3 lore raw

PATCH 2/4 platform/x86: intel_pmt_crashlog: Constify static attribute_group struct

In reply to Rikard Falkeborn

The only use of pmt_crashlog_group is to assign its address to the attr_grp field in the intel_pmt_namespace struct, which is a pointer to const attribute_group. Make it const to allow the compiler to put it in read-only memory.

---
 drivers/platform/x86/intel_pmt_crashlog.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/platform/x86/intel_pmt_crashlog.c +1 -1
index 92d315a16cfd..56963ceb6345 100644
@@ -218,7 +218,7 @@ static struct attribute *pmt_crashlog_attrs[] = {
 	NULL
 };
 
-static struct attribute_group pmt_crashlog_group = {
+static const struct attribute_group pmt_crashlog_group = {
 	.attrs	= pmt_crashlog_attrs,
 };
 
Signature · 1 line
2.31.1
#4 lore raw

PATCH 3/4 platform/x86: tc1100-wmi: Constify static attribute_group struct

In reply to Rikard Falkeborn

The only use of tc1100_attribute_group is to pass its address to sysfs_create_group() and sysfs_remove_group(), both which takes pointer to const attribute_group structs. Make it const to allow the compiler to put it in read-only memory.

---
 drivers/platform/x86/tc1100-wmi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/platform/x86/tc1100-wmi.c +1 -1
index 803920b6f01d..9072eb302618 100644
@@ -156,7 +156,7 @@ static struct attribute *tc1100_attributes[] = {
 	NULL
 };
 
-static struct attribute_group tc1100_attribute_group = {
+static const struct attribute_group tc1100_attribute_group = {
 	.attrs	= tc1100_attributes,
 };
 
Signature · 1 line
2.31.1
#5 lore raw

PATCH 4/4 x86/platform/uv: Constify static attribute_group struct

In reply to Rikard Falkeborn

The only use of base_attr_group and hubless_base_attr_group is to pass their addresses to sysfs_create_group() and sysfs_remove_group(), both which takes pointers to const attribute_group structs. Make them const to allow the compiler to put them in read-only memory.

---
 drivers/platform/x86/uv_sysfs.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/platform/x86/uv_sysfs.c +2 -2
index 7badcfa3f384..956a354b57c1 100644
@@ -778,7 +778,7 @@ static struct attribute *base_attrs[] = {
 	NULL,
 };
 
-static struct attribute_group base_attr_group = {
+static const struct attribute_group base_attr_group = {
 	.attrs = base_attrs
 };
 
@@ -823,7 +823,7 @@ static struct attribute *hubless_base_attrs[] = {
 	NULL,
 };
 
-static struct attribute_group hubless_base_attr_group = {
+static const struct attribute_group hubless_base_attr_group = {
 	.attrs = hubless_base_attrs
 };
 
Signature · 1 line
2.31.1
maintainer Reviewed-by on v1 4/4
#6 lore raw

RE: [PATCH 4/4] x86/platform/uv: Constify static attribute_group struct

Quoted 6 lines

The only use of base_attr_group and hubless_base_attr_group is to pass their addresses to sysfs_create_group() and sysfs_remove_group(), both which takes pointers to const attribute_group structs. Make them const to allow the compiler to put them in read-only memory.

Thank you for the patch.

Quoted 28 lines
---
 drivers/platform/x86/uv_sysfs.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/platform/x86/uv_sysfs.c +2 -3
index 7badcfa3f384..956a354b57c1 100644
@@ -778,7 +778,7 @@ static struct attribute *base_attrs[] = {
 	NULL,
 };
 
-static struct attribute_group base_attr_group = {
+static const struct attribute_group base_attr_group = {
 	.attrs = base_attrs
 };
 
@@ -823,7 +823,7 @@ static struct attribute *hubless_base_attrs[] = {
 	NULL,
 };
 
-static struct attribute_group hubless_base_attr_group = {
+static const struct attribute_group hubless_base_attr_group = {
 	.attrs = hubless_base_attrs
 };
 
--

2.31.1

#7 lore raw
In reply to Rikard Falkeborn

Hi,

Quoted 9 lines · Rikard Falkeborn

Constify a couple of static attribute_group structs which are never modified to allow the compiler to put them in read-only memory.

Rikard Falkeborn (4):
platform/x86: hdaps: Constify static attribute_group struct platform/x86: intel_pmt_crashlog: Constify static attribute_group
struct
platform/x86: tc1100-wmi: Constify static attribute_group struct x86/platform/uv: Constify static attribute_group struct

Thank you for your patch-series, I've applied the series to my review-hans branch:
https://git.kernel.org/pub/scm/linux/kernel/git/pdx86/platform-drivers-x86.git/log/?h=review-hans

Note it will show up in my review-hans branch once I've pushed my local branch there, which might take a while.

Once I've run some tests on this branch the patches there will be added to the platform-drivers-x86/for-next branch and eventually will be included in the pdx86 pull-request to Linus for the next merge-window.

Regards,

Hans