summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArd Biesheuvel <ardb@kernel.org>2026-10-08 10:13:20 +0200
committerArd Biesheuvel <ardb@kernel.org>2026-10-15 13:53:08 +0200
commit64217cbfc7c2a1646bb7d63c2130c6ab85ca55ea (patch)
treea8b7ab12f115238f2f06a7f3bfc8d2650f9086d8
parent80779c1dca838b347a4b7e5e67f45e2adaee1c38 (diff)
downloadlinux-next-64217cbfc7c2a1646bb7d63c2130c6ab85ca55ea.tar.gz
linux-next-64217cbfc7c2a1646bb7d63c2130c6ab85ca55ea.zip
efi: Use sysfs_emit() not sprintf() to generate sysfs file contents
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> Reviewed-by: Thomas Weißschuh <linux@weissschuh.net> Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
-rw-r--r--arch/x86/platform/efi/efi.c2
-rw-r--r--drivers/firmware/efi/efi.c16
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,