RE: [PATCH 1/3] char: tlclk: constify attribute_group structures.

From: Gross, Mark
Date: Wed Aug 02 2017 - 14:16:02 EST


The driver doesn't seem to touch the name field after its defined it looks ok functionally.

Note: I am not a fan of const declarations in the C language. It's too complicated when we get into casting and pointers to structures.

I'm not sure there is a lot of value in being pedantic on a few users of attribute_group structures. I'm thinking this change should be all or nothing and change core function prototypes to create warnings if they are not used with properly defined const 's. Otherwise this is just a cosmetic change of minimal value to a subset of drivers.

FWIW there does seem to be a good number (cscope finds 1700+) of attribute_group users across the kernel and a good number of them are not using const. If you go down this pedantic path I don't think you should at just 3 drivers.

Reviewed-by: mark gross <mark.gross@xxxxxxxxx>

--mark

> -----Original Message-----
> From: Arvind Yadav [mailto:arvind.yadav.cs@xxxxxxxxx]
> Sent: Wednesday, August 2, 2017 4:19 AM
> To: arnd@xxxxxxxx; gregkh@xxxxxxxxxxxxxxxxxxx; Gross, Mark
> <mark.gross@xxxxxxxxx>
> Cc: linux-kernel@xxxxxxxxxxxxxxx
> Subject: [PATCH 1/3] char: tlclk: constify attribute_group structures.
>
> attribute_group are not supposed to change at runtime. All functions working
> with attribute_group provided by <linux/sysfs.h> work with const
> attribute_group. So mark the non-const structs as const.
>
> Signed-off-by: Arvind Yadav <arvind.yadav.cs@xxxxxxxxx>
> ---
> drivers/char/tlclk.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/char/tlclk.c b/drivers/char/tlclk.c index 572a517..6210bff
> 100644
> --- a/drivers/char/tlclk.c
> +++ b/drivers/char/tlclk.c
> @@ -766,7 +766,7 @@ static ssize_t store_reset (struct device *d,
> NULL
> };
>
> -static struct attribute_group tlclk_attribute_group = {
> +static const struct attribute_group tlclk_attribute_group = {
> .name = NULL, /* put in device directory */
> .attrs = tlclk_sysfs_entries,
> };
> --
> 1.9.1