From: Ard Biesheuvel <ardb+git@google.com>
To: linux-efi@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, "Ard Biesheuvel" <ardb@kernel.org>,
"Thomas Weißschuh" <linux@weissschuh.net>
Subject: [PATCH v2 2/2] efi: Use sysfs_emit() not sprintf() to generate sysfs file contents
Date: Thu, 8 Oct 2026 10:13:20 +0200 [thread overview]
Message-ID: <20261008081317.2602565-6-ardb+git@google.com> (raw)
In-Reply-To: <20261008081317.2602565-4-ardb+git@google.com>
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
next prev parent reply other threads:[~2026-10-08 8:13 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
2026-10-08 13:04 ` [PATCH v2 0/2] EFI sysfs constification Thomas Weißschuh
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261008081317.2602565-6-ardb+git@google.com \
--to=ardb+git@google.com \
--cc=ardb@kernel.org \
--cc=linux-efi@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@weissschuh.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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®