2017-08-02 11:19:23

by Arvind Yadav

[permalink] [raw]
Subject: [PATCH 0/3] constify char 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.

Arvind Yadav (3):
[PATCH 1/3] char: tlclk: constify attribute_group structures.
[PATCH 2/3] char: tpm: constify attribute_group structures.
[PATCH 3/3] char: virtio: constify attribute_group structures.

drivers/char/tlclk.c | 2 +-
drivers/char/tpm/tpm_ppi.c | 2 +-
drivers/char/virtio_console.c | 2 +-
3 files changed, 3 insertions(+), 3 deletions(-)

--
1.9.1


2017-08-02 11:19:27

by Arvind Yadav

[permalink] [raw]
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 <[email protected]>
---
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

2017-08-02 17:59:26

by Gross, Mark

[permalink] [raw]
Subject: RE: [PATCH 0/3] constify char attribute_group structures

Why stop at these 3 users of attribute_group?

--mark

-----Original Message-----
From: Arvind Yadav [mailto:[email protected]]
Sent: Wednesday, August 2, 2017 4:19 AM
To: [email protected]; [email protected]; Gross, Mark <[email protected]>
Cc: [email protected]
Subject: [PATCH 0/3] constify char 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.

Arvind Yadav (3):
[PATCH 1/3] char: tlclk: constify attribute_group structures.
[PATCH 2/3] char: tpm: constify attribute_group structures.
[PATCH 3/3] char: virtio: constify attribute_group structures.

drivers/char/tlclk.c | 2 +-
drivers/char/tpm/tpm_ppi.c | 2 +-
drivers/char/virtio_console.c | 2 +-
3 files changed, 3 insertions(+), 3 deletions(-)

--
1.9.1

2017-08-02 18:15:58

by Gross, Mark

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

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 <[email protected]>

--mark

> -----Original Message-----
> From: Arvind Yadav [mailto:[email protected]]
> Sent: Wednesday, August 2, 2017 4:19 AM
> To: [email protected]; [email protected]; Gross, Mark
> <[email protected]>
> Cc: [email protected]
> 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 <[email protected]>
> ---
> 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

2017-08-03 05:34:48

by Arvind Yadav

[permalink] [raw]
Subject: Re: [PATCH 0/3] constify char attribute_group structures

Hi Mark,


On Wednesday 02 August 2017 11:26 PM, Gross, Mark wrote:
> Why stop at these 3 users of attribute_group?
I am doing for all. This changes is only for char user. Few patch are
under review and few are merged. Rest all I will send.

~arvind
> --mark
>
> -----Original Message-----
> From: Arvind Yadav [mailto:[email protected]]
> Sent: Wednesday, August 2, 2017 4:19 AM
> To: [email protected]; [email protected]; Gross, Mark <[email protected]>
> Cc: [email protected]
> Subject: [PATCH 0/3] constify char 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.
>
> Arvind Yadav (3):
> [PATCH 1/3] char: tlclk: constify attribute_group structures.
> [PATCH 2/3] char: tpm: constify attribute_group structures.
> [PATCH 3/3] char: virtio: constify attribute_group structures.
>
> drivers/char/tlclk.c | 2 +-
> drivers/char/tpm/tpm_ppi.c | 2 +-
> drivers/char/virtio_console.c | 2 +-
> 3 files changed, 3 insertions(+), 3 deletions(-)
>
> --
> 1.9.1
>

2017-08-03 12:37:33

by Gross, Mark

[permalink] [raw]
Subject: RE: [PATCH 0/3] constify char attribute_group structures

Sounds good to me.
--mark

> -----Original Message-----
> From: Arvind Yadav [mailto:[email protected]]
> Sent: Wednesday, August 2, 2017 10:35 PM
> To: Gross, Mark <[email protected]>; [email protected];
> [email protected]
> Cc: [email protected]
> Subject: Re: [PATCH 0/3] constify char attribute_group structures
>
> Hi Mark,
>
>
> On Wednesday 02 August 2017 11:26 PM, Gross, Mark wrote:
> > Why stop at these 3 users of attribute_group?
> I am doing for all. This changes is only for char user. Few patch are under
> review and few are merged. Rest all I will send.
>
> ~arvind
> > --mark
> >
> > -----Original Message-----
> > From: Arvind Yadav [mailto:[email protected]]
> > Sent: Wednesday, August 2, 2017 4:19 AM
> > To: [email protected]; [email protected]; Gross, Mark
> > <[email protected]>
> > Cc: [email protected]
> > Subject: [PATCH 0/3] constify char 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.
> >
> > Arvind Yadav (3):
> > [PATCH 1/3] char: tlclk: constify attribute_group structures.
> > [PATCH 2/3] char: tpm: constify attribute_group structures.
> > [PATCH 3/3] char: virtio: constify attribute_group structures.
> >
> > drivers/char/tlclk.c | 2 +-
> > drivers/char/tpm/tpm_ppi.c | 2 +-
> > drivers/char/virtio_console.c | 2 +-
> > 3 files changed, 3 insertions(+), 3 deletions(-)
> >
> > --
> > 1.9.1
> >