Skip to contentSkip to conversation

rtc: ab8500: replace sprintf() with sysfs_emit()

PATCH RESEND Applied Maxwell Doose 2 participants 2 messages May 3 – May 4

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

PATCH RESEND 1/1 rtc: ab8500: replace sprintf() with sysfs_emit()

This patch replaces sprintf() with sysfs_emit() to ensure proper bounds checking. It also simplifies the return logic by directly returning the error after logging, instead of logging, calling sprintf(), then returning.

---
note 1: original patch can be found here:
https://lore.kernel.org/linux-rtc/CAD++jLkQD_ZSFPGrx4uL+ezrR1Ai2ddUF9_PpesDG+AEwiDrag@mail.gmail.com/T/#t

note 2: I rebased this on to v7.1-rc1 to make sure there wouldn't be any merge conflicts.

 drivers/rtc/rtc-ab8500.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/rtc/rtc-ab8500.c +1 -2
index ed2b6b8bb3bf..c6147837f957 100644
@@ -284,11 +284,10 @@ static ssize_t ab8500_sysfs_show_rtc_calibration(struct device *dev,
 	retval = ab8500_rtc_get_calibration(dev, &calibration);
 	if (retval < 0) {
 		dev_err(dev, "Failed to read RTC calibration attribute\n");
-		sprintf(buf, "0\n");
 		return retval;
 	}
 
-	return sprintf(buf, "%d\n", calibration);
+	return sysfs_emit(buf, "%d\n", calibration);
 }
 
 static DEVICE_ATTR(rtc_calibration, S_IRUGO | S_IWUSR,

base-commit: 254f49634ee16a731174d2ae34bc50bd5f45e731

Signature · 1 line
2.54.0
maintainer Applied
#1 lore raw
Quoted 4 lines · Maxwell Doose

This patch replaces sprintf() with sysfs_emit() to ensure proper bounds checking. It also simplifies the return logic by directly returning the error after logging, instead of logging, calling sprintf(), then returning.

Applied, thanks!

[1/1] rtc: ab8500: replace sprintf() with sysfs_emit()

      https://git.kernel.org/abelloni/c/b72386864481

Best regards,

Signature · 3 lines
Alexandre Belloni, co-owner and COO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com