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(-)
From: Emese Revfy <[email protected]>
Signed-off-by: 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(-)
diff --git a/drivers/base/bus.c b/drivers/base/bus.c
index 63c143e..c47cd56 100644
--- a/drivers/base/bus.c
+++ b/drivers/base/bus.c
@@ -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,
};
diff --git a/drivers/base/core.c b/drivers/base/core.c
index f1290cb..37e079b 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -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,
diff --git a/drivers/base/memory.c b/drivers/base/memory.c
index 989429c..2272b00 100644
--- a/drivers/base/memory.c
+++ b/drivers/base/memory.c
@@ -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,
};
diff --git a/include/linux/kobject.h b/include/linux/kobject.h
index 58ae8e0..57a1eaa 100644
--- a/include/linux/kobject.h
+++ b/include/linux/kobject.h
@@ -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)
diff --git a/lib/kobject.c b/lib/kobject.c
index b512b74..cecf5a0 100644
--- a/lib/kobject.c
+++ b/lib/kobject.c
@@ -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;
diff --git a/lib/kobject_uevent.c b/lib/kobject_uevent.c
index 920a3ca..c9d3a3e 100644
--- a/lib/kobject_uevent.c
+++ b/lib/kobject_uevent.c
@@ -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;
--
1.6.5.3
From: Emese Revfy <[email protected]>
Signed-off-by: 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(-)
diff --git a/drivers/misc/kgdbts.c b/drivers/misc/kgdbts.c
index fcb6ec1..42f5558 100644
--- a/drivers/misc/kgdbts.c
+++ b/drivers/misc/kgdbts.c
@@ -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,
diff --git a/drivers/serial/kgdboc.c b/drivers/serial/kgdboc.c
index eadc1ab..2d81457 100644
--- a/drivers/serial/kgdboc.c
+++ b/drivers/serial/kgdboc.c
@@ -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,
diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
index 6adcc29..ba61222 100644
--- a/include/linux/kgdb.h
+++ b/include/linux/kgdb.h
@@ -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);
diff --git a/kernel/kgdb.c b/kernel/kgdb.c
index 2eb517e..a66317a 100644
--- a/kernel/kgdb.c
+++ b/kernel/kgdb.c
@@ -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);
--
1.6.5.3
From: Emese Revfy <[email protected]>
Signed-off-by: Emese Revfy <[email protected]>
---
fs/gfs2/sys.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/fs/gfs2/sys.c b/fs/gfs2/sys.c
index c5dad1e..2d9b7ed 100644
--- a/fs/gfs2/sys.c
+++ b/fs/gfs2/sys.c
@@ -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,
};
--
1.6.5.3
From: Emese Revfy <[email protected]>
Signed-off-by: Emese Revfy <[email protected]>
---
mm/slub.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/mm/slub.c b/mm/slub.c
index 4996fc7..fb63aca 100644
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -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,
};
--
1.6.5.3
From: Emese Revfy <[email protected]>
Signed-off-by: Emese Revfy <[email protected]>
---
kernel/params.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/kernel/params.c b/kernel/params.c
index d656c27..e9d197e 100644
--- a/kernel/params.c
+++ b/kernel/params.c
@@ -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,
};
--
1.6.5.3
On Mon, 2009-12-14 at 01:00 +0100, [email protected] wrote:
> From: Emese Revfy <[email protected]>
>
>
> Signed-off-by: Emese Revfy <[email protected]>
Acked-by: Steven Whitehouse <[email protected]>
Steve.
> ---
> fs/gfs2/sys.c | 2 +-
> 1 files changed, 1 insertions(+), 1 deletions(-)
>
> diff --git a/fs/gfs2/sys.c b/fs/gfs2/sys.c
> index c5dad1e..2d9b7ed 100644
> --- a/fs/gfs2/sys.c
> +++ b/fs/gfs2/sys.c
> @@ -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,
> };
>
On Mon, Dec 14, 2009 at 2:00 AM, <[email protected]> wrote:
> From: Emese Revfy <[email protected]>
>
>
> Signed-off-by: Emese Revfy <[email protected]>
> ---
> ?mm/slub.c | ? ?2 +-
> ?1 files changed, 1 insertions(+), 1 deletions(-)
>
> diff --git a/mm/slub.c b/mm/slub.c
> index 4996fc7..fb63aca 100644
> --- a/mm/slub.c
> +++ b/mm/slub.c
> @@ -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?
Pekka Enberg wrote:
> On Mon, Dec 14, 2009 at 2:00 AM, <[email protected]> wrote:
>> From: Emese Revfy <[email protected]>
>>
>>
>> Signed-off-by: Emese Revfy <[email protected]>
>> ---
>> mm/slub.c | 2 +-
>> 1 files changed, 1 insertions(+), 1 deletions(-)
>>
>> diff --git a/mm/slub.c b/mm/slub.c
>> index 4996fc7..fb63aca 100644
>> --- a/mm/slub.c
>> +++ b/mm/slub.c
>> @@ -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?
>
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
On Sat, 26 Dec 2009, Emese Revfy wrote:
> >> diff --git a/mm/slub.c b/mm/slub.c
> >> index 4996fc7..fb63aca 100644
> >> --- a/mm/slub.c
> >> +++ b/mm/slub.c
> >> @@ -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?
> >
>
> 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.
Emese Revfy kirjoitti:
> Pekka Enberg wrote:
>> On Mon, Dec 14, 2009 at 2:00 AM, <[email protected]> wrote:
>>> From: Emese Revfy <[email protected]>
>>>
>>>
>>> Signed-off-by: Emese Revfy <[email protected]>
>>> ---
>>> mm/slub.c | 2 +-
>>> 1 files changed, 1 insertions(+), 1 deletions(-)
>>>
>>> diff --git a/mm/slub.c b/mm/slub.c
>>> index 4996fc7..fb63aca 100644
>>> --- a/mm/slub.c
>>> +++ b/mm/slub.c
>>> @@ -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?
>>
>
> 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.
David Rientjes wrote:
> On Sat, 26 Dec 2009, Emese Revfy wrote:
>
>>>> diff --git a/mm/slub.c b/mm/slub.c
>>>> index 4996fc7..fb63aca 100644
>>>> --- a/mm/slub.c
>>>> +++ b/mm/slub.c
>>>> @@ -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?
>>>
>> 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.
I see what you mean, this was part of [PATCH 1/4] that I forgot to CC to you.
Emese
Hi Emese,
On Tue, Dec 29, 2009 at 10:50 PM, Emese Revfy <[email protected]> wrote:
> David Rientjes wrote:
>> On Sat, 26 Dec 2009, Emese Revfy wrote:
>>
>>>>> diff --git a/mm/slub.c b/mm/slub.c
>>>>> index 4996fc7..fb63aca 100644
>>>>> --- a/mm/slub.c
>>>>> +++ b/mm/slub.c
>>>>> @@ -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?
>>>>
>>> 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.
>
> 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
>> 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.
Signed-off-by: Emese Revfy <[email protected]>
---
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(-)
diff --git a/drivers/base/bus.c b/drivers/base/bus.c
index c0c5a43..2afe599 100644
--- a/drivers/base/bus.c
+++ b/drivers/base/bus.c
@@ -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,
};
diff --git a/drivers/base/core.c b/drivers/base/core.c
index 2820257..82bd3ff 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -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,
diff --git a/drivers/base/memory.c b/drivers/base/memory.c
index d7d77d4..0bcf8c2 100644
--- a/drivers/base/memory.c
+++ b/drivers/base/memory.c
@@ -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,
};
diff --git a/fs/gfs2/sys.c b/fs/gfs2/sys.c
index 0dc3462..9be733e 100644
--- a/fs/gfs2/sys.c
+++ b/fs/gfs2/sys.c
@@ -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,
};
diff --git a/include/linux/kobject.h b/include/linux/kobject.h
index 58ae8e0..57a1eaa 100644
--- a/include/linux/kobject.h
+++ b/include/linux/kobject.h
@@ -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)
diff --git a/kernel/params.c b/kernel/params.c
index cf1b691..ac5de7d 100644
--- a/kernel/params.c
+++ b/kernel/params.c
@@ -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,
};
diff --git a/lib/kobject.c b/lib/kobject.c
index b512b74..cecf5a0 100644
--- a/lib/kobject.c
+++ b/lib/kobject.c
@@ -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;
diff --git a/lib/kobject_uevent.c b/lib/kobject_uevent.c
index 920a3ca..c9d3a3e 100644
--- a/lib/kobject_uevent.c
+++ b/lib/kobject_uevent.c
@@ -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;
diff --git a/mm/slub.c b/mm/slub.c
index 8d71aaf..02b5a83 100644
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -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,
};
On Tue, Dec 29, 2009 at 09:58:11PM +0100, Emese Revfy wrote:
> >> 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.
Why is this needed? What does it accomplish?
thanks,
greg k-h
Greg KH wrote:
> On Tue, Dec 29, 2009 at 09:58:11PM +0100, Emese Revfy wrote:
>>>> 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.
>
> 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
On Thu, Dec 31, 2009 at 01:16:58AM +0100, Emese Revfy wrote:
> Greg KH wrote:
> > On Tue, Dec 29, 2009 at 09:58:11PM +0100, Emese Revfy wrote:
> >>>> 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.
> >
> > 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
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
Signed-off-by: Emese Revfy <[email protected]>
---
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(-)
diff --git a/drivers/base/bus.c b/drivers/base/bus.c
index c0c5a43..2afe599 100644
--- a/drivers/base/bus.c
+++ b/drivers/base/bus.c
@@ -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,
};
diff --git a/drivers/base/core.c b/drivers/base/core.c
index 2820257..82bd3ff 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -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,
diff --git a/drivers/base/memory.c b/drivers/base/memory.c
index d7d77d4..0bcf8c2 100644
--- a/drivers/base/memory.c
+++ b/drivers/base/memory.c
@@ -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,
};
diff --git a/fs/gfs2/sys.c b/fs/gfs2/sys.c
index 0dc3462..9be733e 100644
--- a/fs/gfs2/sys.c
+++ b/fs/gfs2/sys.c
@@ -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,
};
diff --git a/include/linux/kobject.h b/include/linux/kobject.h
index 58ae8e0..57a1eaa 100644
--- a/include/linux/kobject.h
+++ b/include/linux/kobject.h
@@ -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)
diff --git a/kernel/params.c b/kernel/params.c
index cf1b691..ac5de7d 100644
--- a/kernel/params.c
+++ b/kernel/params.c
@@ -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,
};
diff --git a/lib/kobject.c b/lib/kobject.c
index b512b74..cecf5a0 100644
--- a/lib/kobject.c
+++ b/lib/kobject.c
@@ -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;
diff --git a/lib/kobject_uevent.c b/lib/kobject_uevent.c
index 920a3ca..c9d3a3e 100644
--- a/lib/kobject_uevent.c
+++ b/lib/kobject_uevent.c
@@ -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;
diff --git a/mm/slub.c b/mm/slub.c
index 8d71aaf..02b5a83 100644
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -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,
};