mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v2 0/2] EFI sysfs constification
@ 2026-10-08  8:13 Ard Biesheuvel
  2026-10-08  8:13 ` [PATCH v2 1/2] efi: Constify sysfs attributes Ard Biesheuvel
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Ard Biesheuvel @ 2026-10-08  8:13 UTC (permalink / raw)
  To: linux-efi; +Cc: linux-kernel, Ard Biesheuvel, Thomas Weißschuh

From: Ard Biesheuvel <ardb@kernel.org>

Constify static sysfs node accessors in the EFI core code. While at it,
switch to sysfs_emit() where appropriate.

Changes since v1:
- constify efi_runtime_show() prototype and use __KOBJ_ATTR
- add sysfs_emit() patch

Cc: Thomas Weißschuh <linux@weissschuh.net>

Ard Biesheuvel (2):
  efi: Constify sysfs attributes
  efi: Use sysfs_emit() not sprintf() to generate sysfs file contents

 arch/x86/platform/efi/efi.c | 13 ++---
 drivers/firmware/efi/efi.c  | 52 +++++++++++---------
 include/linux/efi.h         |  3 +-
 3 files changed, 37 insertions(+), 31 deletions(-)

-- 
2.56.0.360.g66cac248cb-goog


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH v2 1/2] efi: Constify sysfs attributes
  2026-10-08  8:13 [PATCH v2 0/2] EFI sysfs constification Ard Biesheuvel
@ 2026-10-08  8:13 ` Ard Biesheuvel
  2026-10-08  8:13 ` [PATCH v2 2/2] efi: Use sysfs_emit() not sprintf() to generate sysfs file contents Ard Biesheuvel
  2026-10-08 13:04 ` [PATCH v2 0/2] EFI sysfs constification Thomas Weißschuh
  2 siblings, 0 replies; 4+ messages in thread
From: Ard Biesheuvel @ 2026-10-08  8:13 UTC (permalink / raw)
  To: linux-efi; +Cc: linux-kernel, Ard Biesheuvel, Thomas Weißschuh

From: Ard Biesheuvel <ardb@kernel.org>

Implement Thomas's suggestions to constify sysfs kobject attributes.

Cc: Thomas Weißschuh <linux@weissschuh.net>
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
---
 arch/x86/platform/efi/efi.c | 11 +++---
 drivers/firmware/efi/efi.c  | 36 +++++++++++---------
 include/linux/efi.h         |  3 +-
 3 files changed, 28 insertions(+), 22 deletions(-)

diff --git a/arch/x86/platform/efi/efi.c b/arch/x86/platform/efi/efi.c
index 0c39adb96b91..d8fe93770c2a 100644
--- a/arch/x86/platform/efi/efi.c
+++ b/arch/x86/platform/efi/efi.c
@@ -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) ||
diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c
index e08ce813a3d4..8026264d4990 100644
--- a/drivers/firmware/efi/efi.c
+++ b/drivers/firmware/efi/efi.c
@@ -131,7 +131,7 @@ struct kobject *efi_kobj;
  * one value per file rule!
  */
 static ssize_t systab_show(struct kobject *kobj,
-			   struct kobj_attribute *attr, char *buf)
+			   const struct kobj_attribute *attr, char *buf)
 {
 	char *str = buf;
 
@@ -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 = __KOBJ_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 *at
 	return 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)
 {
diff --git a/include/linux/efi.h b/include/linux/efi.h
index ecb34be37a87..fda81d7c4850 100644
--- a/include/linux/efi.h
+++ b/include/linux/efi.h
@@ -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);
 
-- 
2.56.0.360.g66cac248cb-goog


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH v2 2/2] efi: Use sysfs_emit() not sprintf() to generate sysfs file contents
  2026-10-08  8:13 [PATCH v2 0/2] EFI sysfs constification Ard Biesheuvel
  2026-10-08  8:13 ` [PATCH v2 1/2] efi: Constify sysfs attributes Ard Biesheuvel
@ 2026-10-08  8:13 ` Ard Biesheuvel
  2026-10-08 13:04 ` [PATCH v2 0/2] EFI sysfs constification Thomas Weißschuh
  2 siblings, 0 replies; 4+ messages in thread
From: Ard Biesheuvel @ 2026-10-08  8:13 UTC (permalink / raw)
  To: linux-efi; +Cc: linux-kernel, Ard Biesheuvel, Thomas Weißschuh

From: Ard Biesheuvel <ardb@kernel.org>

Use sysfs_emit() where appropriate to generate the contents of EFI
related sysfs nodes. This is a more robust wrapper around sprintf()
designed for this purpose.

Reported-by: Thomas Weißschuh <linux@weissschuh.net>
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
---
 arch/x86/platform/efi/efi.c |  2 +-
 drivers/firmware/efi/efi.c  | 16 ++++++++--------
 2 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/arch/x86/platform/efi/efi.c b/arch/x86/platform/efi/efi.c
index d8fe93770c2a..5eb96c17883e 100644
--- a/arch/x86/platform/efi/efi.c
+++ b/arch/x86/platform/efi/efi.c
@@ -893,7 +893,7 @@ bool efi_is_table_address(unsigned long phys_addr)
 static ssize_t name##_show(struct kobject *kobj, \
 			   const struct kobj_attribute *attr, char *buf) \
 { \
-	return sprintf(buf, "0x%lx\n", EFI_FIELD(name)); \
+	return sysfs_emit(buf, "0x%lx\n", EFI_FIELD(name)); \
 }
 
 EFI_ATTR_SHOW(fw_vendor);
diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c
index 8026264d4990..b4504542cb2c 100644
--- a/drivers/firmware/efi/efi.c
+++ b/drivers/firmware/efi/efi.c
@@ -133,26 +133,26 @@ struct kobject *efi_kobj;
 static ssize_t systab_show(struct kobject *kobj,
 			   const struct kobj_attribute *attr, char *buf)
 {
-	char *str = buf;
+	int offset = 0;
 
 	if (!kobj || !buf)
 		return -EINVAL;
 
 	if (efi.acpi20 != EFI_INVALID_TABLE_ADDR)
-		str += sprintf(str, "ACPI20=0x%lx\n", efi.acpi20);
+		offset = sysfs_emit(buf, "ACPI20=0x%lx\n", efi.acpi20);
 	if (efi.acpi != EFI_INVALID_TABLE_ADDR)
-		str += sprintf(str, "ACPI=0x%lx\n", efi.acpi);
+		offset += sysfs_emit_at(buf, offset, "ACPI=0x%lx\n", efi.acpi);
 	/*
 	 * If both SMBIOS and SMBIOS3 entry points are implemented, the
 	 * SMBIOS3 entry point shall be preferred, so we list it first to
 	 * let applications stop parsing after the first match.
 	 */
 	if (efi.smbios3 != EFI_INVALID_TABLE_ADDR)
-		str += sprintf(str, "SMBIOS3=0x%lx\n", efi.smbios3);
+		offset += sysfs_emit_at(buf, offset, "SMBIOS3=0x%lx\n", efi.smbios3);
 	if (efi.smbios != EFI_INVALID_TABLE_ADDR)
-		str += sprintf(str, "SMBIOS=0x%lx\n", efi.smbios);
+		offset += sysfs_emit_at(buf, offset, "SMBIOS=0x%lx\n", efi.smbios);
 
-	return str - buf;
+	return offset;
 }
 
 static const struct kobj_attribute efi_attr_systab = __KOBJ_ATTR_RO_MODE(systab, 0400);
@@ -160,7 +160,7 @@ static const struct kobj_attribute efi_attr_systab = __KOBJ_ATTR_RO_MODE(systab,
 static ssize_t fw_platform_size_show(struct kobject *kobj,
 				     const struct kobj_attribute *attr, char *buf)
 {
-	return sprintf(buf, "%d\n", efi_enabled(EFI_64BIT) ? 64 : 32);
+	return sysfs_emit(buf, "%d\n", efi_enabled(EFI_64BIT) ? 64 : 32);
 }
 
 extern __weak const struct kobj_attribute efi_attr_fw_vendor;
@@ -406,7 +406,7 @@ 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));
+	return sysfs_emit(buf, "%d\n", efi_enabled(EFI_RUNTIME_SERVICES));
 }
 
 static ssize_t efi_runtime_store(struct kobject *kobj,
-- 
2.56.0.360.g66cac248cb-goog


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2 0/2] EFI sysfs constification
  2026-10-08  8:13 [PATCH v2 0/2] EFI sysfs constification Ard Biesheuvel
  2026-10-08  8:13 ` [PATCH v2 1/2] efi: Constify sysfs attributes Ard Biesheuvel
  2026-10-08  8:13 ` [PATCH v2 2/2] efi: Use sysfs_emit() not sprintf() to generate sysfs file contents Ard Biesheuvel
@ 2026-10-08 13:04 ` Thomas Weißschuh
  2 siblings, 0 replies; 4+ messages in thread
From: Thomas Weißschuh @ 2026-10-08 13:04 UTC (permalink / raw)
  To: Ard Biesheuvel; +Cc: linux-efi, linux-kernel, Ard Biesheuvel

Oct 8, 2026 10:13:25 Ard Biesheuvel <ardb+git@google.com>:

> From: Ard Biesheuvel <ardb@kernel.org>
>
> Constify static sysfs node accessors in the EFI core code. While at it,
> switch to sysfs_emit() where appropriate.
>
> Changes since v1:
> - constify efi_runtime_show() prototype and use __KOBJ_ATTR
> - add sysfs_emit() patch

Reviewed-by: Thomas Weißschuh <linux@weissschuh.net>

> Ard Biesheuvel (2):
>   efi: Constify sysfs attributes
>   efi: Use sysfs_emit() not sprintf() to generate sysfs file contents
>
> arch/x86/platform/efi/efi.c | 13 ++---
> drivers/firmware/efi/efi.c  | 52 +++++++++++---------
> include/linux/efi.h         |  3 +-
> 3 files changed, 37 insertions(+), 31 deletions(-)
>
> --
> 2.56.0.360.g66cac248cb-goog


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-10-08 13:04 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-08  8:13 [PATCH v2 0/2] EFI sysfs constification Ard Biesheuvel
2026-10-08  8:13 ` [PATCH v2 1/2] efi: Constify sysfs attributes Ard Biesheuvel
2026-10-08  8:13 ` [PATCH v2 2/2] efi: Use sysfs_emit() not sprintf() to generate sysfs file contents Ard Biesheuvel
2026-10-08 13:04 ` [PATCH v2 0/2] EFI sysfs constification Thomas Weißschuh

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®