Skip to content

Commit

Permalink
kobject: Constify struct kset_uevent_ops
Browse files Browse the repository at this point in the history
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]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
  • Loading branch information
ephox-gcc-plugins authored and gregkh committed Mar 8, 2010
1 parent 985fc17 commit 9cd4361
Show file tree
Hide file tree
Showing 9 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion drivers/base/bus.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};

Expand Down
2 changes: 1 addition & 1 deletion drivers/base/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion drivers/base/memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down
2 changes: 1 addition & 1 deletion fs/gfs2/sys.c
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,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,
};

Expand Down
10 changes: 5 additions & 5 deletions include/linux/kobject.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};

Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion kernel/params.c
Original file line number Diff line number Diff line change
Expand Up @@ -736,7 +736,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,
};

Expand Down
4 changes: 2 additions & 2 deletions lib/kobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion lib/kobject_uevent.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion mm/slub.c
Original file line number Diff line number Diff line change
Expand Up @@ -4409,7 +4409,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,
};

Expand Down

0 comments on commit 9cd4361

Please sign in to comment.