Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Staging: dgnc: constify attribute_group structures

Check for attribute_group structures that are only passed as a second
argument to the functions sysfs_remove_group and sysfs_create_group. As
these arguments are constant so, attribute_group structures having this
property can also be made constant.
Done using coccinelle:

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

@ok1@
identifier r1.i;
position p;
expression e1;
@@
(
sysfs_remove_group(e1,&i@p)
|
sysfs_create_group(e1,&i@p)
)

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

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

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

File size before:
text data bss dec hex filename
6248 1024 0 7272 1c68
drivers/staging/dgnc/dgnc_sysfs.o

File size after:
text data bss dec hex filename
6288 960 0 7248 1c50
drivers/staging/dgnc/dgnc_sysfs.o

Signed-off-by: Bhumika Goyal <bhumirks@gmail.com>
Acked-by: Julia Lawall <julia.lawall@lip6.fr>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Bhumika Goyal and committed by
Greg Kroah-Hartman
7b346dac d983c597

+1 -1
+1 -1
drivers/staging/dgnc/dgnc_sysfs.c
··· 677 677 NULL 678 678 }; 679 679 680 - static struct attribute_group dgnc_tty_attribute_group = { 680 + static const struct attribute_group dgnc_tty_attribute_group = { 681 681 .name = NULL, 682 682 .attrs = dgnc_sysfs_tty_entries, 683 683 };