Skip to contentSkip to conversation

Constify struct kset_uevent_ops for 2.6.32-git-053fe57ac v2

PATCH In review [email protected] 5 participants 18 messages Dec 13, 2009 – Dec 31, 2009

Subsystems (8)
lore
Share & tools
lore
#17 lore raw

PATCH 4/4 Constify struct kset_uevent_ops for 2.6.32-git-053fe57ac v2

In reply to [email protected]

From: Emese Revfy <[email protected]>

---
 kernel/params.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
kernel/params.c +1 -1
index d656c27..e9d197e 100644
@@ -739,7 +739,7 @@ static int uevent_filter(struct kset *kset, struct kobject *kobj)
 	return 0;
 }
 
-static struct kset_uevent_ops module_uevent_ops = {
+static const struct kset_uevent_ops module_uevent_ops = {
 	.filter = uevent_filter,
 };
 
Signature · 1 line
1.6.5.3
#2 lore raw

PATCH 1/1 Constify struct kgdb_io for 2.6.32-git-053fe57ac v2

In reply to [email protected]

From: Emese Revfy <[email protected]>

---
 drivers/misc/kgdbts.c   |    4 ++--
 drivers/serial/kgdboc.c |    4 ++--
 include/linux/kgdb.h    |   18 +++++++++---------
 kernel/kgdb.c           |    6 +++---
 4 files changed, 16 insertions(+), 16 deletions(-)
drivers/misc/kgdbts.c +2 -2
index fcb6ec1..42f5558 100644
@@ -118,7 +118,7 @@
 	} while (0)
 #define MAX_CONFIG_LEN		40
 
-static struct kgdb_io kgdbts_io_ops;
+static const struct kgdb_io kgdbts_io_ops;
 static char get_buf[BUFMAX];
 static int get_buf_cnt;
 static char put_buf[BUFMAX];
@@ -1108,7 +1108,7 @@ static void kgdbts_post_exp_handler(void)
 		module_put(THIS_MODULE);
 }
 
-static struct kgdb_io kgdbts_io_ops = {
+static const struct kgdb_io kgdbts_io_ops = {
 	.name			= "kgdbts",
 	.read_char		= kgdbts_get_char,
 	.write_char		= kgdbts_put_char,
drivers/serial/kgdboc.c +2 -2
index eadc1ab..2d81457 100644
@@ -18,7 +18,7 @@
 
 #define MAX_CONFIG_LEN		40
 
-static struct kgdb_io		kgdboc_io_ops;
+static const struct kgdb_io	kgdboc_io_ops;
 
 /* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
 static int configured		= -1;
@@ -154,7 +154,7 @@ static void kgdboc_post_exp_handler(void)
 		module_put(THIS_MODULE);
 }
 
-static struct kgdb_io kgdboc_io_ops = {
+static const struct kgdb_io kgdboc_io_ops = {
 	.name			= "kgdboc",
 	.read_char		= kgdboc_get_char,
 	.write_char		= kgdboc_put_char,
include/linux/kgdb.h +9 -9
index 6adcc29..ba61222 100644
@@ -251,20 +251,20 @@ struct kgdb_arch {
  */
 struct kgdb_io {
 	const char		*name;
-	int			(*read_char) (void);
-	void			(*write_char) (u8);
-	void			(*flush) (void);
-	int			(*init) (void);
-	void			(*pre_exception) (void);
-	void			(*post_exception) (void);
+	int			(* const read_char) (void);
+	void			(* const write_char) (u8);
+	void			(* const flush) (void);
+	int			(* const init) (void);
+	void			(* const pre_exception) (void);
+	void			(* const post_exception) (void);
 };
 
-extern struct kgdb_arch		arch_kgdb_ops;
+extern struct kgdb_arch	arch_kgdb_ops;
 
 extern unsigned long __weak kgdb_arch_pc(int exception, struct pt_regs *regs);
 
-extern int kgdb_register_io_module(struct kgdb_io *local_kgdb_io_ops);
-extern void kgdb_unregister_io_module(struct kgdb_io *local_kgdb_io_ops);
+extern int kgdb_register_io_module(const struct kgdb_io *local_kgdb_io_ops);
+extern void kgdb_unregister_io_module(const struct kgdb_io *local_kgdb_io_ops);
 
 extern int kgdb_hex2long(char **ptr, unsigned long *long_val);
 extern int kgdb_mem2hex(char *mem, char *buf, int count);
kernel/kgdb.c +3 -3
index 2eb517e..a66317a 100644
@@ -86,7 +86,7 @@ static int			kgdb_io_module_registered;
 /* Guard for recursive entry */
 static int			exception_level;
 
-static struct kgdb_io		*kgdb_io_ops;
+static const struct kgdb_io	*kgdb_io_ops;
 static DEFINE_SPINLOCK(kgdb_registration_lock);
 
 /* kgdb console driver is loaded */
@@ -1661,7 +1661,7 @@ static void kgdb_initial_breakpoint(void)
  *
  *	Register it with the KGDB core.
  */
-int kgdb_register_io_module(struct kgdb_io *new_kgdb_io_ops)
+int kgdb_register_io_module(const struct kgdb_io *new_kgdb_io_ops)
 {
 	int err;
 
@@ -1706,7 +1706,7 @@ EXPORT_SYMBOL_GPL(kgdb_register_io_module);
  *
  *	Unregister it with the KGDB core.
  */
-void kgdb_unregister_io_module(struct kgdb_io *old_kgdb_io_ops)
+void kgdb_unregister_io_module(const struct kgdb_io *old_kgdb_io_ops)
 {
 	BUG_ON(kgdb_connected);
 
Signature · 1 line
1.6.5.3
#5 lore raw

PATCH 3/4 Constify struct kset_uevent_ops for 2.6.32-git-053fe57ac v2

In reply to [email protected]

From: Emese Revfy <[email protected]>

---
 mm/slub.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
mm/slub.c +1 -1
index 4996fc7..fb63aca 100644
@@ -4522,7 +4522,7 @@ static int uevent_filter(struct kset *kset, struct kobject *kobj)
 	return 0;
 }
 
-static struct kset_uevent_ops slab_uevent_ops = {
+static const struct kset_uevent_ops slab_uevent_ops = {
 	.filter = uevent_filter,
 };
 
Signature · 1 line
1.6.5.3
#0 lore raw

cover Constify struct kset_uevent_ops for 2.6.32-git-053fe57ac v2

From: Emese Revfy <[email protected]>

Hello everyone!

The following patch series attempts to constify several structures that hold function pointers. This is only the initial batch, there are about over 150 candidate structures, some of which can be constified as well, I plan to submit them in the future.

The list of constified structures in this series (* marks this thread):
acpi_dock_ops
address_space_operations
backlight_ops
block_device_operations
dma_map_ops
extent_io_ops
file_lock_operations
file_operations
hv_ops
intel_dvo_dev_ops
item_operations
iwl_ops
kgdb_arch
kgdb_io
* kset_uevent_ops
lock_manager_operations
microcode_ops
mtrr_ops
neigh_ops
nlmsvc_binding
pci_raw_ops
platform_hibernation_ops
platform_suspend_ops
snd_ac97_build_ops
sysfs_ops
usb_mon_operations
wd_ops

There are certain exceptions where a given instance of the structure cannot be const, they are marked with a comment in the patch.

The patches compile fine with an allyesconfig kernel on i386 and x86_64.

Please let me know if any of these structures should not be constified and any other issues you see with them.

Changelog:
----------
v1 -> v2
- updated to linus-git-053fe57
- extended comments with a reference to code that prevents constification
- split up patches by subsystem as suggested by Greg KH, Jiri Slaby
- added all Acked-by's received so far
- removed patch for super_operations for now
- removed patch for ptmx_fops

Thanks,
Emese

 drivers/base/bus.c      |    2 +-
 drivers/base/core.c     |    2 +-
 drivers/base/memory.c   |    2 +-
 fs/gfs2/sys.c           |    2 +-
 include/linux/kobject.h |   10 +++++-----
 kernel/params.c         |    2 +-
 lib/kobject.c           |    4 ++--
 lib/kobject_uevent.c    |    2 +-
 mm/slub.c               |    2 +-
 9 files changed, 14 insertions(+), 14 deletions(-)
#3 lore raw

PATCH 2/4 Constify struct kset_uevent_ops for 2.6.32-git-053fe57ac v2

From: Emese Revfy <[email protected]>

---
 fs/gfs2/sys.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
fs/gfs2/sys.c +1 -1
index c5dad1e..2d9b7ed 100644
@@ -586,7 +586,7 @@ static int gfs2_uevent(struct kset *kset, struct kobject *kobj,
 	return 0;
 }
 
-static struct kset_uevent_ops gfs2_uevent_ops = {
+static const struct kset_uevent_ops gfs2_uevent_ops = {
 	.uevent = gfs2_uevent,
 };
 
Signature · 1 line
1.6.5.3
#1 lore raw

PATCH 1/4 Constify struct kset_uevent_ops for 2.6.32-git-053fe57ac v2

In reply to [email protected]

From: Emese Revfy <[email protected]>

---
 drivers/base/bus.c      |    2 +-
 drivers/base/core.c     |    2 +-
 drivers/base/memory.c   |    2 +-
 include/linux/kobject.h |   10 +++++-----
 lib/kobject.c           |    4 ++--
 lib/kobject_uevent.c    |    2 +-
 6 files changed, 11 insertions(+), 11 deletions(-)
drivers/base/bus.c +1 -1
index 63c143e..c47cd56 100644
@@ -154,7 +154,7 @@ static int bus_uevent_filter(struct kset *kset, struct kobject *kobj)
 	return 0;
 }
 
-static struct kset_uevent_ops bus_uevent_ops = {
+static const struct kset_uevent_ops bus_uevent_ops = {
 	.filter = bus_uevent_filter,
 };
 
drivers/base/core.c +1 -1
index f1290cb..37e079b 100644
@@ -252,7 +252,7 @@ static int dev_uevent(struct kset *kset, struct kobject *kobj,
 	return retval;
 }
 
-static struct kset_uevent_ops device_uevent_ops = {
+static const struct kset_uevent_ops device_uevent_ops = {
 	.filter =	dev_uevent_filter,
 	.name =		dev_uevent_name,
 	.uevent =	dev_uevent,
drivers/base/memory.c +1 -1
index 989429c..2272b00 100644
@@ -44,7 +44,7 @@ static int memory_uevent(struct kset *kset, struct kobject *obj, struct kobj_uev
 	return retval;
 }
 
-static struct kset_uevent_ops memory_uevent_ops = {
+static const struct kset_uevent_ops memory_uevent_ops = {
 	.name		= memory_uevent_name,
 	.uevent		= memory_uevent,
 };
include/linux/kobject.h +5 -5
index 58ae8e0..57a1eaa 100644
@@ -118,9 +118,9 @@ struct kobj_uevent_env {
 };
 
 struct kset_uevent_ops {
-	int (*filter)(struct kset *kset, struct kobject *kobj);
-	const char *(*name)(struct kset *kset, struct kobject *kobj);
-	int (*uevent)(struct kset *kset, struct kobject *kobj,
+	int (* const filter)(struct kset *kset, struct kobject *kobj);
+	const char *(* const name)(struct kset *kset, struct kobject *kobj);
+	int (* const uevent)(struct kset *kset, struct kobject *kobj,
 		      struct kobj_uevent_env *env);
 };
 
@@ -155,14 +155,14 @@ struct kset {
 	struct list_head list;
 	spinlock_t list_lock;
 	struct kobject kobj;
-	struct kset_uevent_ops *uevent_ops;
+	const struct kset_uevent_ops *uevent_ops;
 };
 
 extern void kset_init(struct kset *kset);
 extern int __must_check kset_register(struct kset *kset);
 extern void kset_unregister(struct kset *kset);
 extern struct kset * __must_check kset_create_and_add(const char *name,
-						struct kset_uevent_ops *u,
+						const struct kset_uevent_ops *u,
 						struct kobject *parent_kobj);
 
 static inline struct kset *to_kset(struct kobject *kobj)
lib/kobject.c +2 -2
index b512b74..cecf5a0 100644
@@ -789,7 +789,7 @@ static struct kobj_type kset_ktype = {
  * If the kset was not able to be created, NULL will be returned.
  */
 static struct kset *kset_create(const char *name,
-				struct kset_uevent_ops *uevent_ops,
+				const struct kset_uevent_ops *uevent_ops,
 				struct kobject *parent_kobj)
 {
 	struct kset *kset;
@@ -832,7 +832,7 @@ static struct kset *kset_create(const char *name,
  * If the kset was not able to be created, NULL will be returned.
  */
 struct kset *kset_create_and_add(const char *name,
-				 struct kset_uevent_ops *uevent_ops,
+				 const struct kset_uevent_ops *uevent_ops,
 				 struct kobject *parent_kobj)
 {
 	struct kset *kset;
lib/kobject_uevent.c +1 -1
index 920a3ca..c9d3a3e 100644
@@ -95,7 +95,7 @@ int kobject_uevent_env(struct kobject *kobj, enum kobject_action action,
 	const char *subsystem;
 	struct kobject *top_kobj;
 	struct kset *kset;
-	struct kset_uevent_ops *uevent_ops;
+	const struct kset_uevent_ops *uevent_ops;
 	u64 seq;
 	int i = 0;
 	int retval = 0;
Signature · 1 line
1.6.5.3
Acked-by on v1 2/4
#4 lore raw
In reply to [email protected]
Quoted 4 lines · On Mon, 2009-12-14 at 01:00 +0100, [email protected] wrote:

From: Emese Revfy <[email protected]>

Steve.

Quoted 17 lines
---
 fs/gfs2/sys.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
fs/gfs2/sys.c +1 -1
index c5dad1e..2d9b7ed 100644
@@ -586,7 +586,7 @@ static int gfs2_uevent(struct kset *kset, struct kobject *kobj,
 	return 0;
 }
 
-static struct kset_uevent_ops gfs2_uevent_ops = {
+static const struct kset_uevent_ops gfs2_uevent_ops = {
 	.uevent = gfs2_uevent,
 };
 
#6 lore raw
In reply to [email protected]
Quoted 13 lines · On Mon, Dec 14, 2009 at 2:00 AM, <[email protected]> wrote:

From: Emese Revfy <[email protected]>

---
 mm/slub.c |    2 +-

 1 files changed, 1 insertions(+), 1 deletions(-)
mm/slub.c +0 -0
index 4996fc7..fb63aca 100644

mm/slub.c static int uevent_filter(struct kset *kset, struct kobject *kobj) · line 4527

Quoted 7 lines
mm/slub.c +1 -1
@@ -4522,7 +4522,7 @@ static int uevent_filter(struct kset *kset, struct kobject *kobj)
        return 0;
  }
 
-static struct kset_uevent_ops slab_uevent_ops = {
+static const struct kset_uevent_ops slab_uevent_ops = {
        .filter = uevent_filter,
  };

CC mm/slub.o
mm/slub.c: In function 'slab_sysfs_init':
mm/slub.c:4679: warning: passing argument 2 of 'kset_create_and_add' discards qualifiers from pointer target type include/linux/kobject.h:164: note: expected 'struct kset_uevent_ops *' but argument is of type 'const struct kset_uevent_ops *'

Hmm?

#7 lore raw
Quoted 29 lines · Pekka Enberg
Quoted 13 lines · On Mon, Dec 14, 2009 at 2:00 AM, <[email protected]> wrote:

From: Emese Revfy <[email protected]>

---
 mm/slub.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
mm/slub.c +0 -0
index 4996fc7..fb63aca 100644

mm/slub.c static int uevent_filter(struct kset *kset, struct kobject *kobj) · line 4527

Quoted 7 lines
mm/slub.c +1 -1
@@ -4522,7 +4522,7 @@ static int uevent_filter(struct kset *kset, struct kobject *kobj)
       return 0;
 }
 
-static struct kset_uevent_ops slab_uevent_ops = {
+static const struct kset_uevent_ops slab_uevent_ops = {
       .filter = uevent_filter,
 };

CC mm/slub.o
mm/slub.c: In function 'slab_sysfs_init':
mm/slub.c:4679: warning: passing argument 2 of 'kset_create_and_add' discards qualifiers from pointer target type include/linux/kobject.h:164: note: expected 'struct kset_uevent_ops *' but argument is of type 'const struct kset_uevent_ops *'

Quoted 2 lines

Hmm?

I double checked both the declaration and definitions of the affected function/structure and they are consistently const here.
Can you tell me what patch/tree combination you encountered this warning with? Thanks, Emese

#8 lore raw
Quoted 20 lines · Emese Revfy
Quoted 20 lines

mm/slub.c static int uevent_filter(struct kset *kset, struct kobject *kobj) · line 4527

Quoted 12 lines
mm/slub.c +1 -1
index 4996fc7..fb63aca 100644
@@ -4522,7 +4522,7 @@ static int uevent_filter(struct kset *kset, struct kobject *kobj)
       return 0;
 }
 
-static struct kset_uevent_ops slab_uevent_ops = {
+static const struct kset_uevent_ops slab_uevent_ops = {
       .filter = uevent_filter,
 };

CC mm/slub.o
mm/slub.c: In function 'slab_sysfs_init':
mm/slub.c:4679: warning: passing argument 2 of 'kset_create_and_add' discards qualifiers from pointer target type include/linux/kobject.h:164: note: expected 'struct kset_uevent_ops *' but argument is of type 'const struct kset_uevent_ops *'

Quoted 8 lines
Quoted 2 lines

Hmm?

I double checked both the declaration and definitions of the affected function/structure and they are consistently const here.
Can you tell me what patch/tree combination you encountered this warning with? Thanks, Emese

The warning emitted by gcc is pretty explicit; the second formal of kset_create_and_add() takes a 'struct kset_uevent_ops *' type while you're now passing 'const struct kset_uevent_ops *' as the result of your change. That said, kset_create() could probably be modified with the const qualifier, but that's outside the scope of your patchset and would have to be proposed seperately.

#11 lore raw
In reply to Emese Revfy

Emese Revfy kirjoitti:

Quoted 29 lines
Quoted 28 lines · Pekka Enberg
Quoted 13 lines · On Mon, Dec 14, 2009 at 2:00 AM, <[email protected]> wrote:

From: Emese Revfy <[email protected]>

---
 mm/slub.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
mm/slub.c +0 -0
index 4996fc7..fb63aca 100644

mm/slub.c static int uevent_filter(struct kset *kset, struct kobject *kobj) · line 4527

Quoted 7 lines
mm/slub.c +1 -1
@@ -4522,7 +4522,7 @@ static int uevent_filter(struct kset *kset, struct kobject *kobj)
       return 0;
 }
 
-static struct kset_uevent_ops slab_uevent_ops = {
+static const struct kset_uevent_ops slab_uevent_ops = {
       .filter = uevent_filter,
 };

CC mm/slub.o
mm/slub.c: In function 'slab_sysfs_init':
mm/slub.c:4679: warning: passing argument 2 of 'kset_create_and_add' discards qualifiers from pointer target type include/linux/kobject.h:164: note: expected 'struct kset_uevent_ops *' but argument is of type 'const struct kset_uevent_ops *'

Quoted 6 lines
Quoted 2 lines

Hmm?

I double checked both the declaration and definitions of the affected function/structure and they are consistently const here.
Can you tell me what patch/tree combination you encountered this warning with?

2.6.33-rc2 with your patch.

#9 lore raw
In reply to David Rientjes
Quoted 29 lines · David Rientjes
Quoted 19 lines · Emese Revfy
Quoted 19 lines

mm/slub.c static int uevent_filter(struct kset *kset, struct kobject *kobj) · line 4527

Quoted 12 lines
mm/slub.c +1 -1
index 4996fc7..fb63aca 100644
@@ -4522,7 +4522,7 @@ static int uevent_filter(struct kset *kset, struct kobject *kobj)
       return 0;
 }
 
-static struct kset_uevent_ops slab_uevent_ops = {
+static const struct kset_uevent_ops slab_uevent_ops = {
       .filter = uevent_filter,
 };

CC mm/slub.o
mm/slub.c: In function 'slab_sysfs_init':
mm/slub.c:4679: warning: passing argument 2 of 'kset_create_and_add' discards qualifiers from pointer target type include/linux/kobject.h:164: note: expected 'struct kset_uevent_ops *' but argument is of type 'const struct kset_uevent_ops *'

Quoted 7 lines
Quoted 2 lines

Hmm?

I double checked both the declaration and definitions of the affected function/structure and they are consistently const here.
Can you tell me what patch/tree combination you encountered this warning with? Thanks, Emese

Quoted 6 lines

The warning emitted by gcc is pretty explicit; the second formal of kset_create_and_add() takes a 'struct kset_uevent_ops *' type while you're now passing 'const struct kset_uevent_ops *' as the result of your change. That said, kset_create() could probably be modified with the const qualifier, but that's outside the scope of your patchset and would have to be proposed seperately.

I see what you mean, this was part of [PATCH 1/4] that I forgot to CC to you. Emese

#10 lore raw

Hi Emese,

Quoted 30 lines · Emese Revfy
Quoted 29 lines · David Rientjes
Quoted 26 lines · Emese Revfy
Quoted 19 lines

mm/slub.c static int uevent_filter(struct kset *kset, struct kobject *kobj) · line 4527

Quoted 12 lines
mm/slub.c +1 -1
index 4996fc7..fb63aca 100644
@@ -4522,7 +4522,7 @@ static int uevent_filter(struct kset *kset, struct kobject *kobj)
        return 0;
  }
 
-static struct kset_uevent_ops slab_uevent_ops = {
+static const struct kset_uevent_ops slab_uevent_ops = {
        .filter = uevent_filter,
  };

  CC      mm/slub.o
mm/slub.c: In function 'slab_sysfs_init':
mm/slub.c:4679: warning: passing argument 2 of 'kset_create_and_add' discards qualifiers from pointer target type include/linux/kobject.h:164: note: expected 'struct kset_uevent_ops *' but argument is of type 'const struct kset_uevent_ops *'

Quoted 2 lines

Hmm?

I double checked both the declaration and definitions of the affected function/structure and they are consistently const here.
Can you tell me what patch/tree combination you encountered this warning with? Thanks, Emese

Quoted 8 lines
Quoted 6 lines

The warning emitted by gcc is pretty explicit; the second formal of kset_create_and_add() takes a 'struct kset_uevent_ops *' type while you're now passing 'const struct kset_uevent_ops *' as the result of your change. That said, kset_create() could probably be modified with the const qualifier, but that's outside the scope of your patchset and would have to be proposed seperately.

I see what you mean, this was part of [PATCH 1/4] that I forgot to CC to you.

Then you might as well fold everything in one patch and send it to Andrew. I can't apply both in my tree and I don't want to apply something that doesn't compile cleanly.

Pekka

#12 lore raw

Re: [PATCH 1/1] Constify struct kset_uevent_ops for 2.6.33-rc2

In reply to Pekka Enberg
Quoted 6 lines
Quoted 4 lines

I double checked both the declaration and definitions of the affected function/structure and they are consistently const here. Can you tell me what patch/tree combination you encountered this warning with?

2.6.33-rc2 with your patch.

Here is the updated patch for 2.6.33-rc2 in one piece. Emese

From: Emese Revfy <[email protected]>

Constify struct kset_uevent_ops.

---

 drivers/base/bus.c      |    2 +-
 drivers/base/core.c     |    2 +-
 drivers/base/memory.c   |    2 +-
 fs/gfs2/sys.c           |    2 +-
 include/linux/kobject.h |   10 +++++-----
 kernel/params.c         |    2 +-
 lib/kobject.c           |    4 ++--
 lib/kobject_uevent.c    |    2 +-
 mm/slub.c               |    2 +-
 9 files changed, 14 insertions(+), 14 deletions(-)
drivers/base/bus.c +1 -1
index c0c5a43..2afe599 100644
@@ -154,7 +154,7 @@ static int bus_uevent_filter(struct kset *kset, struct kobject *kobj)
 	return 0;
 }
 
-static struct kset_uevent_ops bus_uevent_ops = {
+static const struct kset_uevent_ops bus_uevent_ops = {
 	.filter = bus_uevent_filter,
 };
 
drivers/base/core.c +1 -1
index 2820257..82bd3ff 100644
@@ -252,7 +252,7 @@ static int dev_uevent(struct kset *kset, struct kobject *kobj,
 	return retval;
 }
 
-static struct kset_uevent_ops device_uevent_ops = {
+static const struct kset_uevent_ops device_uevent_ops = {
 	.filter =	dev_uevent_filter,
 	.name =		dev_uevent_name,
 	.uevent =	dev_uevent,
drivers/base/memory.c +1 -1
index d7d77d4..0bcf8c2 100644
@@ -44,7 +44,7 @@ static int memory_uevent(struct kset *kset, struct kobject *obj, struct kobj_uev
 	return retval;
 }
 
-static struct kset_uevent_ops memory_uevent_ops = {
+static const struct kset_uevent_ops memory_uevent_ops = {
 	.name		= memory_uevent_name,
 	.uevent		= memory_uevent,
 };
fs/gfs2/sys.c +1 -1
index 0dc3462..9be733e 100644
@@ -576,7 +576,7 @@ static int gfs2_uevent(struct kset *kset, struct kobject *kobj,
 	return 0;
 }
 
-static struct kset_uevent_ops gfs2_uevent_ops = {
+static const struct kset_uevent_ops gfs2_uevent_ops = {
 	.uevent = gfs2_uevent,
 };
 
include/linux/kobject.h +5 -5
index 58ae8e0..57a1eaa 100644
@@ -118,9 +118,9 @@ struct kobj_uevent_env {
 };
 
 struct kset_uevent_ops {
-	int (*filter)(struct kset *kset, struct kobject *kobj);
-	const char *(*name)(struct kset *kset, struct kobject *kobj);
-	int (*uevent)(struct kset *kset, struct kobject *kobj,
+	int (* const filter)(struct kset *kset, struct kobject *kobj);
+	const char *(* const name)(struct kset *kset, struct kobject *kobj);
+	int (* const uevent)(struct kset *kset, struct kobject *kobj,
 		      struct kobj_uevent_env *env);
 };
 
@@ -155,14 +155,14 @@ struct kset {
 	struct list_head list;
 	spinlock_t list_lock;
 	struct kobject kobj;
-	struct kset_uevent_ops *uevent_ops;
+	const struct kset_uevent_ops *uevent_ops;
 };
 
 extern void kset_init(struct kset *kset);
 extern int __must_check kset_register(struct kset *kset);
 extern void kset_unregister(struct kset *kset);
 extern struct kset * __must_check kset_create_and_add(const char *name,
-						struct kset_uevent_ops *u,
+						const struct kset_uevent_ops *u,
 						struct kobject *parent_kobj);
 
 static inline struct kset *to_kset(struct kobject *kobj)
kernel/params.c +1 -1
index cf1b691..ac5de7d 100644
@@ -737,7 +737,7 @@ static int uevent_filter(struct kset *kset, struct kobject *kobj)
 	return 0;
 }
 
-static struct kset_uevent_ops module_uevent_ops = {
+static const struct kset_uevent_ops module_uevent_ops = {
 	.filter = uevent_filter,
 };
 
lib/kobject.c +2 -2
index b512b74..cecf5a0 100644
@@ -789,7 +789,7 @@ static struct kobj_type kset_ktype = {
  * If the kset was not able to be created, NULL will be returned.
  */
 static struct kset *kset_create(const char *name,
-				struct kset_uevent_ops *uevent_ops,
+				const struct kset_uevent_ops *uevent_ops,
 				struct kobject *parent_kobj)
 {
 	struct kset *kset;
@@ -832,7 +832,7 @@ static struct kset *kset_create(const char *name,
  * If the kset was not able to be created, NULL will be returned.
  */
 struct kset *kset_create_and_add(const char *name,
-				 struct kset_uevent_ops *uevent_ops,
+				 const struct kset_uevent_ops *uevent_ops,
 				 struct kobject *parent_kobj)
 {
 	struct kset *kset;
lib/kobject_uevent.c +1 -1
index 920a3ca..c9d3a3e 100644
@@ -95,7 +95,7 @@ int kobject_uevent_env(struct kobject *kobj, enum kobject_action action,
 	const char *subsystem;
 	struct kobject *top_kobj;
 	struct kset *kset;
-	struct kset_uevent_ops *uevent_ops;
+	const struct kset_uevent_ops *uevent_ops;
 	u64 seq;
 	int i = 0;
 	int retval = 0;
mm/slub.c +1 -1
index 8d71aaf..02b5a83 100644
@@ -4538,7 +4538,7 @@ static int uevent_filter(struct kset *kset, struct kobject *kobj)
 	return 0;
 }
 
-static struct kset_uevent_ops slab_uevent_ops = {
+static const struct kset_uevent_ops slab_uevent_ops = {
 	.filter = uevent_filter,
 };
 
#13 lore raw

Re: [PATCH 1/1] Constify struct kset_uevent_ops for 2.6.33-rc2

Quoted 7 lines · Emese Revfy
Quoted 6 lines
Quoted 4 lines

I double checked both the declaration and definitions of the affected function/structure and they are consistently const here. Can you tell me what patch/tree combination you encountered this warning with?

2.6.33-rc2 with your patch.

Quoted 7 lines

Here is the updated patch for 2.6.33-rc2 in one piece. Emese

From: Emese Revfy <[email protected]>

Constify struct kset_uevent_ops.

Why is this needed? What does it accomplish?

thanks,

greg k-h

#14 lore raw

Re: [PATCH 1/1] Constify struct kset_uevent_ops for 2.6.33-rc2

Quoted 10 lines · Greg KH
Quoted 9 lines · Emese Revfy
Quoted 5 lines
Quoted 4 lines

I double checked both the declaration and definitions of the affected function/structure and they are consistently const here. Can you tell me what patch/tree combination you encountered this warning with?

2.6.33-rc2 with your patch.

Here is the updated patch for 2.6.33-rc2 in one piece. Emese

Quoted 5 lines
Quoted 3 lines

From: Emese Revfy <[email protected]>

Constify struct kset_uevent_ops.

Why is this needed? What does it accomplish?

This is my contribution to the ops structure constification effort that some developers started a few years ago (Arjan, Al Viro, etc.) and that has been worked on somewhat sporadically ever since. For a summary of why this is useful please see Arjan's email:
http://lkml.org/lkml/2009/12/14/216
--
Emese

#15 lore raw

Re: [PATCH 1/1] Constify struct kset_uevent_ops for 2.6.33-rc2

Quoted 15 lines · Emese Revfy
Quoted 14 lines · Greg KH
Quoted 12 lines · Emese Revfy
Quoted 5 lines
Quoted 4 lines

I double checked both the declaration and definitions of the affected function/structure and they are consistently const here. Can you tell me what patch/tree combination you encountered this warning with?

2.6.33-rc2 with your patch.

Here is the updated patch for 2.6.33-rc2 in one piece. Emese

From: Emese Revfy <[email protected]>

Constify struct kset_uevent_ops.

Quoted 7 lines
Quoted 1 line

Why is this needed? What does it accomplish?

This is my contribution to the ops structure constification effort that some developers started a few years ago (Arjan, Al Viro, etc.) and that has been worked on somewhat sporadically ever since. For a summary of why this is useful please see Arjan's email:
http://lkml.org/lkml/2009/12/14/216

Then please insert this kind of information in the patch itself, otherwise it is totally unknown.

Care to resend with the proper information in it?

thanks,

greg k-h

#16 lore raw

Re: [PATCH 1/1] Constify struct kset_uevent_ops for 2.6.33-rc2

From: Emese Revfy <[email protected]>

Constify struct kset_uevent_ops.

This is part of the ops structure constification
effort started by Arjan van de Ven et al.

Benefits of this constification:

* prevents modification of data that is shared
(referenced) by many other structure instances
at runtime

* detects/prevents accidental (but not intentional) modification attempts on archs that enforce read-only kernel data at runtime

* potentially better optimized code as the compiler can assume that the const data cannot be changed

* the compiler/linker move const data into .rodata and therefore exclude them from false sharing

---

 drivers/base/bus.c      |    2 +-
 drivers/base/core.c     |    2 +-
 drivers/base/memory.c   |    2 +-
 fs/gfs2/sys.c           |    2 +-
 include/linux/kobject.h |   10 +++++-----
 kernel/params.c         |    2 +-
 lib/kobject.c           |    4 ++--
 lib/kobject_uevent.c    |    2 +-
 mm/slub.c               |    2 +-
 9 files changed, 14 insertions(+), 14 deletions(-)
drivers/base/bus.c +1 -1
index c0c5a43..2afe599 100644
@@ -154,7 +154,7 @@ static int bus_uevent_filter(struct kset *kset, struct kobject *kobj)
 	return 0;
 }
 
-static struct kset_uevent_ops bus_uevent_ops = {
+static const struct kset_uevent_ops bus_uevent_ops = {
 	.filter = bus_uevent_filter,
 };
 
drivers/base/core.c +1 -1
index 2820257..82bd3ff 100644
@@ -252,7 +252,7 @@ static int dev_uevent(struct kset *kset, struct kobject *kobj,
 	return retval;
 }
 
-static struct kset_uevent_ops device_uevent_ops = {
+static const struct kset_uevent_ops device_uevent_ops = {
 	.filter =	dev_uevent_filter,
 	.name =		dev_uevent_name,
 	.uevent =	dev_uevent,
drivers/base/memory.c +1 -1
index d7d77d4..0bcf8c2 100644
@@ -44,7 +44,7 @@ static int memory_uevent(struct kset *kset, struct kobject *obj, struct kobj_uev
 	return retval;
 }
 
-static struct kset_uevent_ops memory_uevent_ops = {
+static const struct kset_uevent_ops memory_uevent_ops = {
 	.name		= memory_uevent_name,
 	.uevent		= memory_uevent,
 };
fs/gfs2/sys.c +1 -1
index 0dc3462..9be733e 100644
@@ -576,7 +576,7 @@ static int gfs2_uevent(struct kset *kset, struct kobject *kobj,
 	return 0;
 }
 
-static struct kset_uevent_ops gfs2_uevent_ops = {
+static const struct kset_uevent_ops gfs2_uevent_ops = {
 	.uevent = gfs2_uevent,
 };
 
include/linux/kobject.h +5 -5
index 58ae8e0..57a1eaa 100644
@@ -118,9 +118,9 @@ struct kobj_uevent_env {
 };
 
 struct kset_uevent_ops {
-	int (*filter)(struct kset *kset, struct kobject *kobj);
-	const char *(*name)(struct kset *kset, struct kobject *kobj);
-	int (*uevent)(struct kset *kset, struct kobject *kobj,
+	int (* const filter)(struct kset *kset, struct kobject *kobj);
+	const char *(* const name)(struct kset *kset, struct kobject *kobj);
+	int (* const uevent)(struct kset *kset, struct kobject *kobj,
 		      struct kobj_uevent_env *env);
 };
 
@@ -155,14 +155,14 @@ struct kset {
 	struct list_head list;
 	spinlock_t list_lock;
 	struct kobject kobj;
-	struct kset_uevent_ops *uevent_ops;
+	const struct kset_uevent_ops *uevent_ops;
 };
 
 extern void kset_init(struct kset *kset);
 extern int __must_check kset_register(struct kset *kset);
 extern void kset_unregister(struct kset *kset);
 extern struct kset * __must_check kset_create_and_add(const char *name,
-						struct kset_uevent_ops *u,
+						const struct kset_uevent_ops *u,
 						struct kobject *parent_kobj);
 
 static inline struct kset *to_kset(struct kobject *kobj)
kernel/params.c +1 -1
index cf1b691..ac5de7d 100644
@@ -737,7 +737,7 @@ static int uevent_filter(struct kset *kset, struct kobject *kobj)
 	return 0;
 }
 
-static struct kset_uevent_ops module_uevent_ops = {
+static const struct kset_uevent_ops module_uevent_ops = {
 	.filter = uevent_filter,
 };
 
lib/kobject.c +2 -2
index b512b74..cecf5a0 100644
@@ -789,7 +789,7 @@ static struct kobj_type kset_ktype = {
  * If the kset was not able to be created, NULL will be returned.
  */
 static struct kset *kset_create(const char *name,
-				struct kset_uevent_ops *uevent_ops,
+				const struct kset_uevent_ops *uevent_ops,
 				struct kobject *parent_kobj)
 {
 	struct kset *kset;
@@ -832,7 +832,7 @@ static struct kset *kset_create(const char *name,
  * If the kset was not able to be created, NULL will be returned.
  */
 struct kset *kset_create_and_add(const char *name,
-				 struct kset_uevent_ops *uevent_ops,
+				 const struct kset_uevent_ops *uevent_ops,
 				 struct kobject *parent_kobj)
 {
 	struct kset *kset;
lib/kobject_uevent.c +1 -1
index 920a3ca..c9d3a3e 100644
@@ -95,7 +95,7 @@ int kobject_uevent_env(struct kobject *kobj, enum kobject_action action,
 	const char *subsystem;
 	struct kobject *top_kobj;
 	struct kset *kset;
-	struct kset_uevent_ops *uevent_ops;
+	const struct kset_uevent_ops *uevent_ops;
 	u64 seq;
 	int i = 0;
 	int retval = 0;
mm/slub.c +1 -1
index 8d71aaf..02b5a83 100644
@@ -4538,7 +4538,7 @@ static int uevent_filter(struct kset *kset, struct kobject *kobj)
 	return 0;
 }
 
-static struct kset_uevent_ops slab_uevent_ops = {
+static const struct kset_uevent_ops slab_uevent_ops = {
 	.filter = uevent_filter,
 };