Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

rtc: sysfs: Use sysfs_emit() to instead of s*printf()

Follow the advice of the Documentation/filesystems/sysfs.rst that show()
should only use sysfs_emit() or sysfs_emit_at() when formatting the value
to be returned to user space.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Link: https://lore.kernel.org/r/20250702061534.2670729-1-andriy.shevchenko@linux.intel.com
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>

authored by

Andy Shevchenko and committed by
Alexandre Belloni
4dda8df7 e92eda97

+21 -25
+21 -25
drivers/rtc/sysfs.c
··· 24 24 static ssize_t 25 25 name_show(struct device *dev, struct device_attribute *attr, char *buf) 26 26 { 27 - return sprintf(buf, "%s %s\n", dev_driver_string(dev->parent), 28 - dev_name(dev->parent)); 27 + return sysfs_emit(buf, "%s %s\n", dev_driver_string(dev->parent), 28 + dev_name(dev->parent)); 29 29 } 30 30 static DEVICE_ATTR_RO(name); 31 31 ··· 39 39 if (retval) 40 40 return retval; 41 41 42 - return sprintf(buf, "%ptRd\n", &tm); 42 + return sysfs_emit(buf, "%ptRd\n", &tm); 43 43 } 44 44 static DEVICE_ATTR_RO(date); 45 45 ··· 53 53 if (retval) 54 54 return retval; 55 55 56 - return sprintf(buf, "%ptRt\n", &tm); 56 + return sysfs_emit(buf, "%ptRt\n", &tm); 57 57 } 58 58 static DEVICE_ATTR_RO(time); 59 59 ··· 64 64 struct rtc_time tm; 65 65 66 66 retval = rtc_read_time(to_rtc_device(dev), &tm); 67 - if (retval == 0) { 68 - time64_t time; 67 + if (retval) 68 + return retval; 69 69 70 - time = rtc_tm_to_time64(&tm); 71 - retval = sprintf(buf, "%lld\n", time); 72 - } 73 - 74 - return retval; 70 + return sysfs_emit(buf, "%lld\n", rtc_tm_to_time64(&tm)); 75 71 } 76 72 static DEVICE_ATTR_RO(since_epoch); 77 73 78 74 static ssize_t 79 75 max_user_freq_show(struct device *dev, struct device_attribute *attr, char *buf) 80 76 { 81 - return sprintf(buf, "%d\n", to_rtc_device(dev)->max_user_freq); 77 + return sysfs_emit(buf, "%d\n", to_rtc_device(dev)->max_user_freq); 82 78 } 83 79 84 80 static ssize_t ··· 114 118 if (rtc_hctosys_ret == 0 && 115 119 strcmp(dev_name(&to_rtc_device(dev)->dev), 116 120 CONFIG_RTC_HCTOSYS_DEVICE) == 0) 117 - return sprintf(buf, "1\n"); 121 + return sysfs_emit(buf, "1\n"); 118 122 #endif 119 - return sprintf(buf, "0\n"); 123 + return sysfs_emit(buf, "0\n"); 120 124 } 121 125 static DEVICE_ATTR_RO(hctosys); 122 126 ··· 124 128 wakealarm_show(struct device *dev, struct device_attribute *attr, char *buf) 125 129 { 126 130 ssize_t retval; 127 - time64_t alarm; 128 131 struct rtc_wkalrm alm; 129 132 130 133 /* Don't show disabled alarms. For uniformity, RTC alarms are ··· 135 140 * alarms after they trigger, to ensure one-shot semantics. 136 141 */ 137 142 retval = rtc_read_alarm(to_rtc_device(dev), &alm); 138 - if (retval == 0 && alm.enabled) { 139 - alarm = rtc_tm_to_time64(&alm.time); 140 - retval = sprintf(buf, "%lld\n", alarm); 141 - } 143 + if (retval) 144 + return retval; 142 145 143 - return retval; 146 + if (alm.enabled) 147 + return sysfs_emit(buf, "%lld\n", rtc_tm_to_time64(&alm.time)); 148 + 149 + return 0; 144 150 } 145 151 146 152 static ssize_t ··· 218 222 long offset; 219 223 220 224 retval = rtc_read_offset(to_rtc_device(dev), &offset); 221 - if (retval == 0) 222 - retval = sprintf(buf, "%ld\n", offset); 225 + if (retval) 226 + return retval; 223 227 224 - return retval; 228 + return sysfs_emit(buf, "%ld\n", offset); 225 229 } 226 230 227 231 static ssize_t ··· 242 246 static ssize_t 243 247 range_show(struct device *dev, struct device_attribute *attr, char *buf) 244 248 { 245 - return sprintf(buf, "[%lld,%llu]\n", to_rtc_device(dev)->range_min, 246 - to_rtc_device(dev)->range_max); 249 + return sysfs_emit(buf, "[%lld,%llu]\n", to_rtc_device(dev)->range_min, 250 + to_rtc_device(dev)->range_max); 247 251 } 248 252 static DEVICE_ATTR_RO(range); 249 253