Skip to contentSkip to conversation

x86/resctrl: Constify kernfs_ops

PATCH Applied Rikard Falkeborn 3 participants 3 messages Nov 10, 2020 – Nov 19, 2020

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

PATCH 1/1 x86/resctrl: Constify kernfs_ops

The only usage of the kf_ops field in the rftype struct is to pass it as argument to __kernfs_create_file(), which accepts a pointer to const. Make it a pointer to const. This makes it possible to make rdtgroup_kf_single_ops and kf_mondata_ops const, which allows the compiler to put them in read-only memory.

---
 arch/x86/kernel/cpu/resctrl/internal.h | 2 +-
 arch/x86/kernel/cpu/resctrl/rdtgroup.c | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)
arch/x86/kernel/cpu/resctrl/internal.h +1 -1
index 6cb068fcf501..5540b025880c 100644
@@ -264,7 +264,7 @@ void __exit rdtgroup_exit(void);
 struct rftype {
 	char			*name;
 	umode_t			mode;
-	struct kernfs_ops	*kf_ops;
+	const struct kernfs_ops	*kf_ops;
 	unsigned long		flags;
 	unsigned long		fflags;
 
arch/x86/kernel/cpu/resctrl/rdtgroup.c +2 -2
index af323e2e3100..78dcbb8e0172 100644
@@ -240,13 +240,13 @@ static ssize_t rdtgroup_file_write(struct kernfs_open_file *of, char *buf,
 	return -EINVAL;
 }
 
-static struct kernfs_ops rdtgroup_kf_single_ops = {
+static const struct kernfs_ops rdtgroup_kf_single_ops = {
 	.atomic_write_len	= PAGE_SIZE,
 	.write			= rdtgroup_file_write,
 	.seq_show		= rdtgroup_seqfile_show,
 };
 
-static struct kernfs_ops kf_mondata_ops = {
+static const struct kernfs_ops kf_mondata_ops = {
 	.atomic_write_len	= PAGE_SIZE,
 	.seq_show		= rdtgroup_mondata_show,
 };
Signature · 1 line
2.29.2
maintainer Acked-by on v1 1/1
#1 lore raw
Quoted 7 lines · Rikard Falkeborn

The only usage of the kf_ops field in the rftype struct is to pass it as argument to __kernfs_create_file(), which accepts a pointer to const. Make it a pointer to const. This makes it possible to make rdtgroup_kf_single_ops and kf_mondata_ops const, which allows the compiler to put them in read-only memory.

Thank you very much Rikard.

Reinette

#2 lore raw
In reply to Rikard Falkeborn
The following commit has been merged into the x86/cache branch of tip:

The following commit has been merged into the x86/cache branch of tip:

Commit-ID:     2002d2951398317d0f46e64ae6d8dd58ed541c6d
Gitweb:        https://git.kernel.org/tip/2002d2951398317d0f46e64ae6d8dd58ed541c6d
Author:        Rikard Falkeborn <[email protected]>
AuthorDate:    Wed, 11 Nov 2020 00:02:28 +01:00
Committer:     Borislav Petkov <[email protected]>
CommitterDate: Thu, 19 Nov 2020 18:23:45 +01:00

x86/resctrl: Constify kernfs_ops

The only usage of the kf_ops field in the rftype struct is to pass it as argument to __kernfs_create_file(), which accepts a pointer to const. Make it a pointer to const. This makes it possible to make rdtgroup_kf_single_ops and kf_mondata_ops const, which allows the compiler to put them in read-only memory.

---
 arch/x86/kernel/cpu/resctrl/internal.h | 2 +-
 arch/x86/kernel/cpu/resctrl/rdtgroup.c | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)
arch/x86/kernel/cpu/resctrl/internal.h +1 -1
index 6cb068f..5540b02 100644
@@ -264,7 +264,7 @@ void __exit rdtgroup_exit(void);
 struct rftype {
 	char			*name;
 	umode_t			mode;
-	struct kernfs_ops	*kf_ops;
+	const struct kernfs_ops	*kf_ops;
 	unsigned long		flags;
 	unsigned long		fflags;
 
arch/x86/kernel/cpu/resctrl/rdtgroup.c +2 -2
index af323e2..78dcbb8 100644
@@ -240,13 +240,13 @@ static ssize_t rdtgroup_file_write(struct kernfs_open_file *of, char *buf,
 	return -EINVAL;
 }
 
-static struct kernfs_ops rdtgroup_kf_single_ops = {
+static const struct kernfs_ops rdtgroup_kf_single_ops = {
 	.atomic_write_len	= PAGE_SIZE,
 	.write			= rdtgroup_file_write,
 	.seq_show		= rdtgroup_seqfile_show,
 };
 
-static struct kernfs_ops kf_mondata_ops = {
+static const struct kernfs_ops kf_mondata_ops = {
 	.atomic_write_len	= PAGE_SIZE,
 	.seq_show		= rdtgroup_mondata_show,
 };