Skip to contentSkip to conversation

fs: dlm: lockspace: constify kset_uevent_ops structures

PATCH In review Bhumika Goyal 2 participants 2 messages Oct 27, 2016 Distributed lock manager (DLM)

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fs: dlm: lockspace: constify kset_uevent_ops structures

Declare kset_uevent_ops structure as const as it is only passed as the second argument to the function kset_create_and_add. This argument is of type const struct kset_uevent_ops *, so kset_uevent_ops structures having this property can be declared const.
Done using Coccinelle:

@r1 disable optional_qualifier @
identifier i;
position p;
@@
static struct kset_uevent_ops i at p = {...};

@ok1@
identifier r1.i;
position p;
expression e1,e2;
@@
kset_create_and_add(e1,&i at p,e2)

@bad@
position p!={r1.p,ok1.p};
identifier r1.i;
@@
i at p

@depends on !bad disable optional_qualifier@
identifier r1.i;
@@
static
+const
struct kset_uevent_ops i={...};

@depends on !bad disable optional_qualifier@
identifier r1.i;
@@
+const
struct kset_uevent_ops i;

File size before:
text data bss dec hex filename
8034 528 484 9046 2356 fs/dlm/lockspace.o

File size after:
text data bss dec hex filename
8050 496 484 9030 2346 fs/dlm/lockspace.o

---
 fs/dlm/lockspace.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/dlm/lockspace.c +1 -1
index f3e7278..2ea1b77 100644
@@ -233,7 +233,7 @@ static int dlm_uevent(struct kset *kset, struct kobject *kobj,
 	return 0;
 }
 
-static struct kset_uevent_ops dlm_uevent_ops = {
+static const struct kset_uevent_ops dlm_uevent_ops = {
 	.uevent = dlm_uevent,
 };
 
Signature · 1 line
1.9.1
Acked-by on v1 1/1
#1 lore raw
Quoted 42 lines · Bhumika Goyal

Declare kset_uevent_ops structure as const as it is only passed as the second argument to the function kset_create_and_add. This argument is of type const struct kset_uevent_ops *, so kset_uevent_ops structures having this property can be declared const.
Done using Coccinelle:

@r1 disable optional_qualifier @
identifier i;
position p;
@@
static struct kset_uevent_ops i at p = {...};

@ok1@
identifier r1.i;
position p;
expression e1,e2;
@@
kset_create_and_add(e1,&i at p,e2)

@bad@
position p!={r1.p,ok1.p};
identifier r1.i;
@@
i at p

@depends on !bad disable optional_qualifier@
identifier r1.i;
@@
static
+const
struct kset_uevent_ops i={...};

@depends on !bad disable optional_qualifier@
identifier r1.i;
@@
+const
struct kset_uevent_ops i;

File size before:
text data bss dec hex filename
8034 528 484 9046 2356 fs/dlm/lockspace.o

Quoted 5 lines

File size after:
text data bss dec hex filename
8050 496 484 9030 2346 fs/dlm/lockspace.o

Quoted 21 lines
---
 fs/dlm/lockspace.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/dlm/lockspace.c +1 -2
index f3e7278..2ea1b77 100644
@@ -233,7 +233,7 @@ static int dlm_uevent(struct kset *kset, struct kobject *kobj,
 	return 0;
 }
 
-static struct kset_uevent_ops dlm_uevent_ops = {
+static const struct kset_uevent_ops dlm_uevent_ops = {
 	.uevent = dlm_uevent,
 };
 
--

1.9.1