fw_cfg: use __ATTR_RO_MODE to define rev sysfs
PATCH 1/1 fw_cfg: use __ATTR_RO_MODE to define rev sysfs
Leverage __ATTR_RO_MODE to define rev sysfs instead of using open code to define the attribute.
--- drivers/firmware/qemu_fw_cfg.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-)
drivers/firmware/qemu_fw_cfg.c +4 -9
@@ -296,18 +296,13 @@ static int fw_cfg_do_platform_probe(struct platform_device *pdev)return 0 ; } -static ssize_t fw_cfg_showrev (struct kobject *k,struct attribute *a,char *buf) +static ssize_t fw_cfg_rev_show (struct kobject *k,struct kobj_attribute *a, +char *buf) {return sprintf (buf,"%u\n" , fw_cfg_rev); } - -static const struct { -struct attribute attr; -ssize_t (*show)(struct kobject *k,struct attribute *a,char *buf); -} fw_cfg_rev_attr = { - .attr = { .name ="rev" , .mode =S_IRUSR }, - .show = fw_cfg_showrev, -}; +static const struct kobj_attribute fw_cfg_rev_attr = +__ATTR_RO_MODE (fw_cfg_rev,0400 );/* fw_cfg_sysfs_entry type */ struct fw_cfg_sysfs_entry {
Signature · 1 line
2.19.1
Michael S. Tsirkin
maintainerQuoted 25 lines · Wei Yang
Leverage
__ATTR_RO_MODEto define rev sysfs instead of using open code to define the attribute.Signed-off-by Wei Yang <[email protected]>--- drivers/firmware/qemu_fw_cfg.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-)drivers/firmware/qemu_fw_cfg.c +2
-4@@ -296,18 +296,13 @@ static int fw_cfg_do_platform_probe(struct platform_device *pdev)return 0 ; } -static ssize_t fw_cfg_showrev (struct kobject *k,struct attribute *a,char *buf) +static ssize_t fw_cfg_rev_show (struct kobject *k,struct kobj_attribute *a, +char *buf) {return sprintf (buf,"%u\n" , fw_cfg_rev); } - -static const struct { - struct attribute attr;
drivers/firmware/qemu_fw_cfg.c static int fw_cfg_do_platform_probe(struct platform_device *pdev) · line 308
Quoted 10 lines
drivers/firmware/qemu_fw_cfg.c +2
-5-ssize_t (*show)(struct kobject *k,struct attribute *a,char *buf); -} fw_cfg_rev_attr = { - .attr = { .name = "rev", .mode = S_IRUSR }, - .show = fw_cfg_showrev, -}; +static const struct kobj_attribute fw_cfg_rev_attr = +__ATTR_RO_MODE (fw_cfg_rev,0400 );/* fw_cfg_sysfs_entry type */ struct fw_cfg_sysfs_entry {
Looks like this will change the name from "rev" to "fw_cfg_rev". That's a userspace visible change which we should not do lightly.
Quoted 2 lines
Signature · 1 line
2.19.1
Hi Wei,
Quoted 22 lines · Wei Yang
Leverage
__ATTR_RO_MODEto define rev sysfs instead of using open code to define the attribute.Signed-off-by Wei Yang <[email protected]>--- drivers/firmware/qemu_fw_cfg.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-)drivers/firmware/qemu_fw_cfg.c +2
-1@@ -296,18 +296,13 @@ static int fw_cfg_do_platform_probe(struct platform_device *pdev)return 0 ; } -static ssize_t fw_cfg_showrev (struct kobject *k,struct attribute *a,char *buf) +static ssize_t fw_cfg_rev_show (struct kobject *k,struct kobj_attribute *a, +char *buf) {return sprintf (buf,"%u\n" , fw_cfg_rev); }
drivers/firmware/qemu_fw_cfg.c static int fw_cfg_do_platform_probe(struct platform_device *pdev) · line 305
Quoted 10 lines
drivers/firmware/qemu_fw_cfg.c +2
-8- -static const struct { -struct attribute attr; -ssize_t (*show)(struct kobject *k,struct attribute *a,char *buf); -} fw_cfg_rev_attr = { - .attr = { .name ="rev" , .mode =S_IRUSR }, - .show = fw_cfg_showrev, -}; +static const struct kobj_attribute fw_cfg_rev_attr = +__ATTR_RO_MODE (fw_cfg_rev,0400 );
Why not keep S_IRUSR?
Quoted 4 lines
drivers/firmware/qemu_fw_cfg.c +0
-0/* fw_cfg_sysfs_entry type */ struct fw_cfg_sysfs_entry {
Quoted 34 lines · Michael S. Tsirkin
Quoted 33 lines · Wei Yang
Leverage
__ATTR_RO_MODEto define rev sysfs instead of using open code to define the attribute.Signed-off-by Wei Yang <[email protected]>--- drivers/firmware/qemu_fw_cfg.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-)drivers/firmware/qemu_fw_cfg.c +4
-9@@ -296,18 +296,13 @@ static int fw_cfg_do_platform_probe(struct platform_device *pdev)return 0 ; } -static ssize_t fw_cfg_showrev (struct kobject *k,struct attribute *a,char *buf) +static ssize_t fw_cfg_rev_show (struct kobject *k,struct kobj_attribute *a, +char *buf) {return sprintf (buf,"%u\n" , fw_cfg_rev); } - -static const struct { -struct attribute attr; -ssize_t (*show)(struct kobject *k,struct attribute *a,char *buf); -} fw_cfg_rev_attr = { - .attr = { .name ="rev" , .mode =S_IRUSR }, - .show = fw_cfg_showrev, -}; +static const struct kobj_attribute fw_cfg_rev_attr = +__ATTR_RO_MODE (fw_cfg_rev,0400 );
Quoted 6 lines
drivers/firmware/qemu_fw_cfg.c static int fw_cfg_do_platform_probe(struct platform_device *pdev) · line 308
Quoted 2 lines
drivers/firmware/qemu_fw_cfg.c +0
-0/* fw_cfg_sysfs_entry type */ struct fw_cfg_sysfs_entry {Looks like this will change the name from "rev" to "
fw_cfg_rev". That's a userspace visible change which we should not do lightly.
We could name the function rev_show but this stay fragile, we'd also need a comment "don't rename this".
Quoted 3 lines
Quoted 2 lines
Signature · 1 line
2.19.1
Michael S. Tsirkin
maintainerQuoted 42 lines · Philippe Mathieu-Daudé
Quoted 34 lines · Michael S. Tsirkin
Quoted 33 lines · Wei Yang
Leverage
__ATTR_RO_MODEto define rev sysfs instead of using open code to define the attribute.Signed-off-by Wei Yang <[email protected]>--- drivers/firmware/qemu_fw_cfg.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-)drivers/firmware/qemu_fw_cfg.c +4
-9@@ -296,18 +296,13 @@ static int fw_cfg_do_platform_probe(struct platform_device *pdev)return 0 ; } -static ssize_t fw_cfg_showrev (struct kobject *k,struct attribute *a,char *buf) +static ssize_t fw_cfg_rev_show (struct kobject *k,struct kobj_attribute *a, +char *buf) {return sprintf (buf,"%u\n" , fw_cfg_rev); } - -static const struct { -struct attribute attr; -ssize_t (*show)(struct kobject *k,struct attribute *a,char *buf); -} fw_cfg_rev_attr = { - .attr = { .name ="rev" , .mode =S_IRUSR }, - .show = fw_cfg_showrev, -}; +static const struct kobj_attribute fw_cfg_rev_attr = +__ATTR_RO_MODE (fw_cfg_rev,0400 );Quoted 6 lines
drivers/firmware/qemu_fw_cfg.c static int fw_cfg_do_platform_probe(struct platform_device *pdev) · line 308
Quoted 2 lines
drivers/firmware/qemu_fw_cfg.c +0
-0/* fw_cfg_sysfs_entry type */ struct fw_cfg_sysfs_entry {Looks like this will change the name from "rev" to "
fw_cfg_rev". That's a userspace visible change which we should not do lightly.
Quoted 2 lines
We could name the function
rev_showbut this stay fragile, we'd also need a comment "don't rename this".
It's a given that one must not rename attributes.
Quoted 3 lines
Quoted 3 lines
Quoted 2 lines
Signature · 1 line
2.19.1
Quoted 29 lines · Philippe Mathieu-Daudé
Hi Wei,
Quoted 26 lines · Wei Yang
Leverage
__ATTR_RO_MODEto define rev sysfs instead of using open code to define the attribute.Signed-off-by Wei Yang <[email protected]>--- drivers/firmware/qemu_fw_cfg.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-)drivers/firmware/qemu_fw_cfg.c +2
-5@@ -296,18 +296,13 @@ static int fw_cfg_do_platform_probe(struct platform_device *pdev)return 0 ; } -static ssize_t fw_cfg_showrev (struct kobject *k,struct attribute *a,char *buf) +static ssize_t fw_cfg_rev_show (struct kobject *k,struct kobj_attribute *a, +char *buf) {return sprintf (buf,"%u\n" , fw_cfg_rev); } - -static const struct { - struct attribute attr; - ssize_t (*show)(struct kobject *k, struct attribute *a, char *buf);
Quoted 9 lines
drivers/firmware/qemu_fw_cfg.c static int fw_cfg_do_platform_probe(struct platform_device *pdev) · line 305
Quoted 6 lines
drivers/firmware/qemu_fw_cfg.c +2
-4-} fw_cfg_rev_attr = { - .attr = { .name = "rev", .mode = S_IRUSR }, - .show = fw_cfg_showrev, -}; +static const struct kobj_attribute fw_cfg_rev_attr = +__ATTR_RO_MODE (fw_cfg_rev,0400 );Why not keep
S_IRUSR?
Because scripts/checkpatch.pl suggest not use S_IRUSR :-)
I am not sure about the particular reason.
Quoted 4 lines
Quoted 4 lines
drivers/firmware/qemu_fw_cfg.c +0
-0/* fw_cfg_sysfs_entry type */ struct fw_cfg_sysfs_entry {
Signature · 2 lines
Wei Yang Help you, Help me
Quoted 34 lines · Michael S. Tsirkin
Quoted 33 lines · Wei Yang
Leverage
__ATTR_RO_MODEto define rev sysfs instead of using open code to define the attribute.Signed-off-by Wei Yang <[email protected]>--- drivers/firmware/qemu_fw_cfg.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-)drivers/firmware/qemu_fw_cfg.c +4
-9@@ -296,18 +296,13 @@ static int fw_cfg_do_platform_probe(struct platform_device *pdev)return 0 ; } -static ssize_t fw_cfg_showrev (struct kobject *k,struct attribute *a,char *buf) +static ssize_t fw_cfg_rev_show (struct kobject *k,struct kobj_attribute *a, +char *buf) {return sprintf (buf,"%u\n" , fw_cfg_rev); } - -static const struct { -struct attribute attr; -ssize_t (*show)(struct kobject *k,struct attribute *a,char *buf); -} fw_cfg_rev_attr = { - .attr = { .name ="rev" , .mode =S_IRUSR }, - .show = fw_cfg_showrev, -}; +static const struct kobj_attribute fw_cfg_rev_attr = +__ATTR_RO_MODE (fw_cfg_rev,0400 );
Quoted 6 lines
drivers/firmware/qemu_fw_cfg.c static int fw_cfg_do_platform_probe(struct platform_device *pdev) · line 308
Quoted 2 lines
drivers/firmware/qemu_fw_cfg.c +0
-0/* fw_cfg_sysfs_entry type */ struct fw_cfg_sysfs_entry {Looks like this will change the name from "rev" to "
fw_cfg_rev". That's a userspace visible change which we should not do lightly.
You are right, I should keep the interface untouched.
To keep it user un-visible, we could change like below:
- __ATTR_RO(fw_cfg_rev);
+ __ATTR_RO(rev);
Is this better for you?
Quoted 2 lines
Quoted 2 lines
Signature · 1 line
2.19.1
Signature · 2 lines
Wei Yang Help you, Help me
Michael S. Tsirkin
maintainerQuoted 49 lines · Wei Yang
Quoted 34 lines · Michael S. Tsirkin
Quoted 33 lines · Wei Yang
Leverage
__ATTR_RO_MODEto define rev sysfs instead of using open code to define the attribute.Signed-off-by Wei Yang <[email protected]>--- drivers/firmware/qemu_fw_cfg.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-)drivers/firmware/qemu_fw_cfg.c +4
-9@@ -296,18 +296,13 @@ static int fw_cfg_do_platform_probe(struct platform_device *pdev)return 0 ; } -static ssize_t fw_cfg_showrev (struct kobject *k,struct attribute *a,char *buf) +static ssize_t fw_cfg_rev_show (struct kobject *k,struct kobj_attribute *a, +char *buf) {return sprintf (buf,"%u\n" , fw_cfg_rev); } - -static const struct { -struct attribute attr; -ssize_t (*show)(struct kobject *k,struct attribute *a,char *buf); -} fw_cfg_rev_attr = { - .attr = { .name ="rev" , .mode =S_IRUSR }, - .show = fw_cfg_showrev, -}; +static const struct kobj_attribute fw_cfg_rev_attr = +__ATTR_RO_MODE (fw_cfg_rev,0400 );Quoted 6 lines
drivers/firmware/qemu_fw_cfg.c static int fw_cfg_do_platform_probe(struct platform_device *pdev) · line 308
Quoted 2 lines
drivers/firmware/qemu_fw_cfg.c +0
-0/* fw_cfg_sysfs_entry type */ struct fw_cfg_sysfs_entry {Looks like this will change the name from "rev" to "
fw_cfg_rev". That's a userspace visible change which we should not do lightly.You are right, I should keep the interface untouched.
To keep it user un-visible, we could change like below:
(quoted diff) +1
-1- __ATTR_RO(fw_cfg_rev); + __ATTR_RO(rev);
Quoted 1 line
Is this better for you?
Also why use 0400 and not S_IRUSR?
Quoted 6 lines
Quoted 2 lines
Quoted 2 lines
Signature · 1 line
2.19.1Signature · 2 lines
Wei Yang Help you, Help me
Michael S. Tsirkin
maintainerQuoted 40 lines · Wei Yang
Quoted 29 lines · Philippe Mathieu-Daudé
Hi Wei,
Quoted 26 lines · Wei Yang
Leverage
__ATTR_RO_MODEto define rev sysfs instead of using open code to define the attribute.Signed-off-by Wei Yang <[email protected]>--- drivers/firmware/qemu_fw_cfg.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-)drivers/firmware/qemu_fw_cfg.c +2
-5@@ -296,18 +296,13 @@ static int fw_cfg_do_platform_probe(struct platform_device *pdev)return 0 ; } -static ssize_t fw_cfg_showrev (struct kobject *k,struct attribute *a,char *buf) +static ssize_t fw_cfg_rev_show (struct kobject *k,struct kobj_attribute *a, +char *buf) {return sprintf (buf,"%u\n" , fw_cfg_rev); } - -static const struct { - struct attribute attr; - ssize_t (*show)(struct kobject *k, struct attribute *a, char *buf);Quoted 9 lines
drivers/firmware/qemu_fw_cfg.c static int fw_cfg_do_platform_probe(struct platform_device *pdev) · line 305
Quoted 6 lines
drivers/firmware/qemu_fw_cfg.c +2
-4-} fw_cfg_rev_attr = { - .attr = { .name = "rev", .mode = S_IRUSR }, - .show = fw_cfg_showrev, -}; +static const struct kobj_attribute fw_cfg_rev_attr = +__ATTR_RO_MODE (fw_cfg_rev,0400 );Why not keep
S_IRUSR?
Quoted 3 lines
Because
scripts/checkpatch.plsuggest not useS_IRUSR:-)I am not sure about the particular reason.
Oh yea.
http://lkml.kernel.org/r/CA+55aFw5v23T-zvDZp-MmD_EYxF8WbafwwB59934FV7g21uMGQ@mail.gmail.com
maybe mention this in the commit log.
Quoted 8 lines
Quoted 4 lines
Quoted 4 lines
drivers/firmware/qemu_fw_cfg.c +0
-0/* fw_cfg_sysfs_entry type */ struct fw_cfg_sysfs_entry {Signature · 2 lines
Wei Yang Help you, Help me
Quoted 47 lines · Michael S. Tsirkin
Quoted 46 lines · Wei Yang
Quoted 34 lines · Michael S. Tsirkin
Quoted 33 lines · Wei Yang
Leverage
__ATTR_RO_MODEto define rev sysfs instead of using open code to define the attribute.Signed-off-by Wei Yang <[email protected]>--- drivers/firmware/qemu_fw_cfg.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-)drivers/firmware/qemu_fw_cfg.c +4
-9@@ -296,18 +296,13 @@ static int fw_cfg_do_platform_probe(struct platform_device *pdev)return 0 ; } -static ssize_t fw_cfg_showrev (struct kobject *k,struct attribute *a,char *buf) +static ssize_t fw_cfg_rev_show (struct kobject *k,struct kobj_attribute *a, +char *buf) {return sprintf (buf,"%u\n" , fw_cfg_rev); } - -static const struct { -struct attribute attr; -ssize_t (*show)(struct kobject *k,struct attribute *a,char *buf); -} fw_cfg_rev_attr = { - .attr = { .name ="rev" , .mode =S_IRUSR }, - .show = fw_cfg_showrev, -}; +static const struct kobj_attribute fw_cfg_rev_attr = +__ATTR_RO_MODE (fw_cfg_rev,0400 );Quoted 6 lines
drivers/firmware/qemu_fw_cfg.c static int fw_cfg_do_platform_probe(struct platform_device *pdev) · line 308
Quoted 2 lines
drivers/firmware/qemu_fw_cfg.c +0
-0/* fw_cfg_sysfs_entry type */ struct fw_cfg_sysfs_entry {Looks like this will change the name from "rev" to "
fw_cfg_rev". That's a userspace visible change which we should not do lightly.You are right, I should keep the interface untouched.
To keep it user un-visible, we could change like below:
Quoted 8 lines
Quoted 4 lines
(quoted diff) +1
-1- __ATTR_RO(fw_cfg_rev); + __ATTR_RO(rev);Is this better for you?
Also why use 0400 and not
S_IRUSR?
This is interesting. The scripts/checkpatch.pl suggest to use 0400.
I am not sure why the script give this suggestion. Maybe we need to fix the script?
Quoted 6 lines
Quoted 6 lines
Quoted 2 lines
Quoted 2 lines
Signature · 1 line
2.19.1Signature · 2 lines
Wei Yang Help you, Help me
Signature · 2 lines
Wei Yang Help you, Help me
Quoted 43 lines · Michael S. Tsirkin
Quoted 42 lines · Wei Yang
Quoted 29 lines · Philippe Mathieu-Daudé
Hi Wei,
Quoted 26 lines · Wei Yang
Leverage
__ATTR_RO_MODEto define rev sysfs instead of using open code to define the attribute.Signed-off-by Wei Yang <[email protected]>--- drivers/firmware/qemu_fw_cfg.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-)drivers/firmware/qemu_fw_cfg.c +2
-5@@ -296,18 +296,13 @@ static int fw_cfg_do_platform_probe(struct platform_device *pdev)return 0 ; } -static ssize_t fw_cfg_showrev (struct kobject *k,struct attribute *a,char *buf) +static ssize_t fw_cfg_rev_show (struct kobject *k,struct kobj_attribute *a, +char *buf) {return sprintf (buf,"%u\n" , fw_cfg_rev); } - -static const struct { - struct attribute attr; - ssize_t (*show)(struct kobject *k, struct attribute *a, char *buf);Quoted 9 lines
drivers/firmware/qemu_fw_cfg.c static int fw_cfg_do_platform_probe(struct platform_device *pdev) · line 305
Quoted 6 lines
drivers/firmware/qemu_fw_cfg.c +2
-4-} fw_cfg_rev_attr = { - .attr = { .name = "rev", .mode = S_IRUSR }, - .show = fw_cfg_showrev, -}; +static const struct kobj_attribute fw_cfg_rev_attr = +__ATTR_RO_MODE (fw_cfg_rev,0400 );Why not keep
S_IRUSR?Because
scripts/checkpatch.plsuggest not useS_IRUSR:-)
Quoted 8 lines
Quoted 1 line
I am not sure about the particular reason.
Oh yea.
http://lkml.kernel.org/r/CA+55aFw5v23T-zvDZp-MmD_EYxF8WbafwwB59934FV7g21uMGQ@mail.gmail.com
maybe mention this in the commit log.
Thanks :-)
Quoted 8 lines
Quoted 8 lines
Quoted 4 lines
Quoted 4 lines
drivers/firmware/qemu_fw_cfg.c +0
-0/* fw_cfg_sysfs_entry type */ struct fw_cfg_sysfs_entry {Signature · 2 lines
Wei Yang Help you, Help me
Signature · 2 lines
Wei Yang Help you, Help me
Quoted 47 lines · Michael S. Tsirkin
Quoted 46 lines · Wei Yang
Quoted 34 lines · Michael S. Tsirkin
Quoted 33 lines · Wei Yang
Leverage
__ATTR_RO_MODEto define rev sysfs instead of using open code to define the attribute.Signed-off-by Wei Yang <[email protected]>--- drivers/firmware/qemu_fw_cfg.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-)drivers/firmware/qemu_fw_cfg.c +4
-9@@ -296,18 +296,13 @@ static int fw_cfg_do_platform_probe(struct platform_device *pdev)return 0 ; } -static ssize_t fw_cfg_showrev (struct kobject *k,struct attribute *a,char *buf) +static ssize_t fw_cfg_rev_show (struct kobject *k,struct kobj_attribute *a, +char *buf) {return sprintf (buf,"%u\n" , fw_cfg_rev); } - -static const struct { -struct attribute attr; -ssize_t (*show)(struct kobject *k,struct attribute *a,char *buf); -} fw_cfg_rev_attr = { - .attr = { .name ="rev" , .mode =S_IRUSR }, - .show = fw_cfg_showrev, -}; +static const struct kobj_attribute fw_cfg_rev_attr = +__ATTR_RO_MODE (fw_cfg_rev,0400 );Quoted 6 lines
drivers/firmware/qemu_fw_cfg.c static int fw_cfg_do_platform_probe(struct platform_device *pdev) · line 308
Quoted 2 lines
drivers/firmware/qemu_fw_cfg.c +0
-0/* fw_cfg_sysfs_entry type */ struct fw_cfg_sysfs_entry {Looks like this will change the name from "rev" to "
fw_cfg_rev". That's a userspace visible change which we should not do lightly.You are right, I should keep the interface untouched.
To keep it user un-visible, we could change like below:
Quoted 8 lines
Quoted 4 lines
(quoted diff) +1
-1- __ATTR_RO(fw_cfg_rev); + __ATTR_RO(rev);Is this better for you?
Also why use 0400 and not
S_IRUSR?
In case this is the proper way to use 0400 and after keeping the name un-changed, would you mind I sending v2 for this?
Quoted 6 lines
Quoted 6 lines
Quoted 2 lines
Quoted 2 lines
Signature · 1 line
2.19.1Signature · 2 lines
Wei Yang Help you, Help me
Signature · 2 lines
Wei Yang Help you, Help me