efi: Constify sysfs attributes
PATCH 1/1 efi: Constify sysfs attributes
From: Ard Biesheuvel <[email protected]>
Implement Thomas's suggestions to constify sysfs kobject attributes.
Cc Thomas Weißschuh <[email protected]>
Signed-off-by Ard Biesheuvel <[email protected]>
--- arch/x86/platform/efi/efi.c | 11 ++++--- drivers/firmware/efi/efi.c | 34 +++++++++++--------- include/linux/efi.h | 3 +- 3 files changed, 27 insertions(+), 21 deletions(-)
arch/x86/platform/efi/efi.c +6 -5
@@ -891,7 +891,7 @@ bool efi_is_table_address(unsigned long phys_addr)#define EFI_ATTR_SHOW (name) \ static ssize_t name##_show(struct kobject *kobj, \ - struct kobj_attribute *attr, char *buf) \ + const struct kobj_attribute *attr, char *buf) \ { \ return sprintf(buf, "0x%lx\n", EFI_FIELD(name)); \ }
@@ -900,11 +900,12 @@ EFI_ATTR_SHOW(fw_vendor);EFI_ATTR_SHOW (runtime);EFI_ATTR_SHOW (config_table); -struct kobj_attribute efi_attr_fw_vendor =__ATTR_RO (fw_vendor); -struct kobj_attribute efi_attr_runtime =__ATTR_RO (runtime); -struct kobj_attribute efi_attr_config_table =__ATTR_RO (config_table); +const struct kobj_attribute efi_attr_fw_vendor =__KOBJ_ATTR_RO (fw_vendor); +const struct kobj_attribute efi_attr_runtime =__KOBJ_ATTR_RO (runtime); +const struct kobj_attribute efi_attr_config_table =__KOBJ_ATTR_RO (config_table); -umode_t efi_attr_is_visible (struct kobject *kobj,struct attribute *attr,int n) +umode_t efi_attr_is_visible (struct kobject *kobj,const struct attribute *attr, +int n) {if (attr == &efi_attr_fw_vendor.attr) { if (efi_enabled(EFI_PARAVIRT) ||
drivers/firmware/efi/efi.c +19 -15
@@ -155,21 +155,21 @@ static ssize_t systab_show(struct kobject *kobj,return str - buf; } -static struct kobj_attribute efi_attr_systab =__ATTR_RO_MODE (systab,0400 ); +static const struct kobj_attribute efi_attr_systab =__ATTR_RO_MODE (systab,0400 );static ssize_t fw_platform_size_show (struct kobject *kobj, -struct kobj_attribute *attr,char *buf) +const struct kobj_attribute *attr,char *buf) {return sprintf (buf,"%d\n" ,efi_enabled (EFI_64BIT ) ?64 :32 ); } -extern __weak struct kobj_attribute efi_attr_fw_vendor; -extern __weak struct kobj_attribute efi_attr_runtime; -extern __weak struct kobj_attribute efi_attr_config_table; -static struct kobj_attribute efi_attr_fw_platform_size = -__ATTR_RO (fw_platform_size); +extern __weak const struct kobj_attribute efi_attr_fw_vendor; +extern __weak const struct kobj_attribute efi_attr_runtime; +extern __weak const struct kobj_attribute efi_attr_config_table; +static const struct kobj_attribute efi_attr_fw_platform_size = +__KOBJ_ATTR_RO (fw_platform_size); -static struct attribute *efi_subsys_attrs[] = { +static const struct attribute *const efi_subsys_attrs[] = { &efi_attr_systab.attr, &efi_attr_fw_platform_size.attr, &efi_attr_fw_vendor.attr,
@@ -178,15 +178,16 @@ static struct attribute *efi_subsys_attrs[] = { NULL, }; -umode_t __weak efi_attr_is_visible (struct kobject *kobj,struct attribute *attr, +umode_t __weak efi_attr_is_visible (struct kobject *kobj, +const struct attribute *attr,int n) {return attr->mode; }static const struct attribute_group efi_subsys_attr_group = { - .attrs = efi_subsys_attrs, - .is_visible = efi_attr_is_visible, + .attrs_const = efi_subsys_attrs, + .is_visible_const = efi_attr_is_visible, };struct blocking_notifier_head efivar_ops_nh;
@@ -401,12 +402,15 @@ static void __init efi_debugfs_init(void)static inline void efi_debugfs_init (void ) {}#endif -static ssize_t efi_runtime_show (struct kobject *kobj,struct kobj_attribute *attr,char *buf) +static ssize_t efi_runtime_show (struct kobject *kobj, +const struct kobj_attribute *attr, +char *buf) {return sprintf (buf,"%d\n" ,efi_enabled (EFI_RUNTIME_SERVICES )); } -static ssize_t efi_runtime_store (struct kobject *kobj,struct kobj_attribute *attr, +static ssize_t efi_runtime_store (struct kobject *kobj, +const struct kobj_attribute *attr,const char *buf,size_t count) {int ret;
@@ -424,8 +428,8 @@ static ssize_t efi_runtime_store(struct kobject *kobj, struct kobj_attribute *atreturn count; } -static struct kobj_attribute efi_runtime_attr = -__ATTR (runtime_enable,0644 , efi_runtime_show, efi_runtime_store); +static const struct kobj_attribute efi_runtime_attr = +__KOBJ_ATTR (runtime_enable,0644 , efi_runtime_show, efi_runtime_store);static int __init efipostcore_init (void ) {
include/linux/efi.h +2 -1
@@ -1353,7 +1353,8 @@ bool efi_config_table_is_usable(const efi_guid_t *guid, unsigned long table)return xen_efi_config_table_is_usable (guid, table); } -umode_t efi_attr_is_visible (struct kobject *kobj,struct attribute *attr,int n); +umode_t efi_attr_is_visible (struct kobject *kobj,const struct attribute *attr, +int n);int ovmf_log_probe (unsigned long ovmf_debug_log_table);
Signature · 1 line
2.56.0.360.g66cac248cb-goog
Quoted 6 lines · Ard Biesheuvel
From: Ard Biesheuvel <[email protected]>
Implement Thomas's suggestions to constify sysfs kobject attributes.
Cc Thomas Weißschuh <[email protected]>Signed-off-by Ard Biesheuvel <[email protected]>
Thanks! But some remarks.
Quoted 23 lines
--- arch/x86/platform/efi/efi.c | 11 ++++--- drivers/firmware/efi/efi.c | 34 +++++++++++--------- include/linux/efi.h | 3 +- 3 files changed, 27 insertions(+), 21 deletions(-)arch/x86/platform/efi/efi.c +1
-1@@ -891,7 +891,7 @@ bool efi_is_table_address(unsigned long phys_addr)#define EFI_ATTR_SHOW (name) \ static ssize_t name##_show(struct kobject *kobj, \ - struct kobj_attribute *attr, char *buf) \ + const struct kobj_attribute *attr, char *buf) \ { \ return sprintf(buf, "0x%lx\n", EFI_FIELD(name)); \ }@@ -900,11 +900,12 @@ EFI_ATTR_SHOW(fw_vendor);EFI_ATTR_SHOW (runtime);EFI_ATTR_SHOW (config_table);
arch/x86/platform/efi/efi.c EFI_ATTR_SHOW(fw_vendor); · line 908
Quoted 10 lines
arch/x86/platform/efi/efi.c +5
-4-struct kobj_attribute efi_attr_fw_vendor =__ATTR_RO (fw_vendor); -struct kobj_attribute efi_attr_runtime =__ATTR_RO (runtime); -struct kobj_attribute efi_attr_config_table =__ATTR_RO (config_table); +const struct kobj_attribute efi_attr_fw_vendor =__KOBJ_ATTR_RO (fw_vendor); +const struct kobj_attribute efi_attr_runtime =__KOBJ_ATTR_RO (runtime); +const struct kobj_attribute efi_attr_config_table =__KOBJ_ATTR_RO (config_table); -umode_t efi_attr_is_visible (struct kobject *kobj,struct attribute *attr,int n) +umode_t efi_attr_is_visible (struct kobject *kobj,const struct attribute *attr, +int n)
The break looks unnecessary.
drivers/firmware/efi/efi.c static ssize_t systab_show(struct kobject *kobj, · line 158
Quoted 13 lines
arch/x86/platform/efi/efi.c +0
-0{if (attr == &efi_attr_fw_vendor.attr) { if (efi_enabled(EFI_PARAVIRT) ||drivers/firmware/efi/efi.c +1
-1@@ -155,21 +155,21 @@ static ssize_t systab_show(struct kobject *kobj,return str - buf; } -static struct kobj_attribute efi_attr_systab =__ATTR_RO_MODE (systab,0400 ); +static const struct kobj_attribute efi_attr_systab =__ATTR_RO_MODE (systab,0400 );
__KOBJ_ATTR_RO_MODE()
(and the callback prototype)
drivers/firmware/efi/efi.c static ssize_t systab_show(struct kobject *kobj, · line 163
Quoted 5 lines
drivers/firmware/efi/efi.c +1
-1static ssize_t fw_platform_size_show (struct kobject *kobj, -struct kobj_attribute *attr,char *buf) +const struct kobj_attribute *attr,char *buf) {return sprintf (buf,"%d\n" ,efi_enabled (EFI_64BIT ) ?64 :32 );
This should switch to sysfs_emit() at some point.
Quoted 1 line
drivers/firmware/efi/efi.c +0
-0}
(...)