Skip to contentSkip to conversation

platform/x86: intel/pmt: Replace sprintf() with sysfs_emit()

PATCH In review Kaushlendra Kumar 2 participants 2 messages Dec 18, 2025 – Dec 23, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 platform/x86: intel/pmt: Replace sprintf() with sysfs_emit()

Replace sprintf() calls with sysfs_emit() in guid_show(), size_show(), and offset_show() sysfs attribute handlers. The sysfs_emit() function provides automatic buffer bounds checking and is the preferred method for formatting sysfs output per Documentation/filesystems/sysfs.rst.

This improves safety by preventing potential buffer overflows and aligns with current kernel coding standards for sysfs attribute implementation.

---
 drivers/platform/x86/intel/pmt/class.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/platform/x86/intel/pmt/class.c +3 -3
index 7c3023d5d91d..be3c8d9e4fff 100644
@@ -140,7 +140,7 @@ guid_show(struct device *dev, struct device_attribute *attr, char *buf)
 {
 	struct intel_pmt_entry *entry = dev_get_drvdata(dev);
 
-	return sprintf(buf, "0x%x\n", entry->guid);
+	return sysfs_emit(buf, "0x%x\n", entry->guid);
 }
 static DEVICE_ATTR_RO(guid);
 
@@ -149,7 +149,7 @@ static ssize_t size_show(struct device *dev, struct device_attribute *attr,
 {
 	struct intel_pmt_entry *entry = dev_get_drvdata(dev);
 
-	return sprintf(buf, "%zu\n", entry->size);
+	return sysfs_emit(buf, "%zu\n", entry->size);
 }
 static DEVICE_ATTR_RO(size);
 
@@ -158,7 +158,7 @@ offset_show(struct device *dev, struct device_attribute *attr, char *buf)
 {
 	struct intel_pmt_entry *entry = dev_get_drvdata(dev);
 
-	return sprintf(buf, "%lu\n", offset_in_page(entry->base_addr));
+	return sysfs_emit(buf, "%lu\n", offset_in_page(entry->base_addr));
 }
 static DEVICE_ATTR_RO(offset);
 
Signature · 1 line
2.34.1
maintainer
#1 lore raw
Quoted 9 lines · Kaushlendra Kumar

Replace sprintf() calls with sysfs_emit() in guid_show(), size_show(), and offset_show() sysfs attribute handlers. The sysfs_emit() function provides automatic buffer bounds checking and is the preferred method for formatting sysfs output per Documentation/filesystems/sysfs.rst.

This improves safety by preventing potential buffer overflows and aligns with current kernel coding standards for sysfs attribute implementation.

[...]

Thank you for your contribution, it has been applied to my local review-ilpo-next branch. Note it will show up in the public platform-drivers-x86/review-ilpo-next branch only once I've pushed my local branch there, which might take a while.

The list of commits applied:
[1/1] platform/x86: intel/pmt: Replace sprintf() with sysfs_emit()

      commit: dd0a2d47cfc4c5ffb3e866c94a80c03ff5ecdd70

--
i.