Skip to content

Commit 4dda8df

Browse files
andy-shevalexandrebelloni
authored andcommitted
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>
1 parent e92eda9 commit 4dda8df

1 file changed

Lines changed: 21 additions & 25 deletions

File tree

drivers/rtc/sysfs.c

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
static ssize_t
2525
name_show(struct device *dev, struct device_attribute *attr, char *buf)
2626
{
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));
2929
}
3030
static DEVICE_ATTR_RO(name);
3131

@@ -39,7 +39,7 @@ date_show(struct device *dev, struct device_attribute *attr, char *buf)
3939
if (retval)
4040
return retval;
4141

42-
return sprintf(buf, "%ptRd\n", &tm);
42+
return sysfs_emit(buf, "%ptRd\n", &tm);
4343
}
4444
static DEVICE_ATTR_RO(date);
4545

@@ -53,7 +53,7 @@ time_show(struct device *dev, struct device_attribute *attr, char *buf)
5353
if (retval)
5454
return retval;
5555

56-
return sprintf(buf, "%ptRt\n", &tm);
56+
return sysfs_emit(buf, "%ptRt\n", &tm);
5757
}
5858
static DEVICE_ATTR_RO(time);
5959

@@ -64,21 +64,17 @@ since_epoch_show(struct device *dev, struct device_attribute *attr, char *buf)
6464
struct rtc_time tm;
6565

6666
retval = rtc_read_time(to_rtc_device(dev), &tm);
67-
if (retval == 0) {
68-
time64_t time;
69-
70-
time = rtc_tm_to_time64(&tm);
71-
retval = sprintf(buf, "%lld\n", time);
72-
}
67+
if (retval)
68+
return retval;
7369

74-
return retval;
70+
return sysfs_emit(buf, "%lld\n", rtc_tm_to_time64(&tm));
7571
}
7672
static DEVICE_ATTR_RO(since_epoch);
7773

7874
static ssize_t
7975
max_user_freq_show(struct device *dev, struct device_attribute *attr, char *buf)
8076
{
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);
8278
}
8379

8480
static ssize_t
@@ -118,17 +114,16 @@ hctosys_show(struct device *dev, struct device_attribute *attr, char *buf)
118114
if (rtc_hctosys_ret == 0 &&
119115
strcmp(dev_name(&to_rtc_device(dev)->dev),
120116
CONFIG_RTC_HCTOSYS_DEVICE) == 0)
121-
return sprintf(buf, "1\n");
117+
return sysfs_emit(buf, "1\n");
122118
#endif
123-
return sprintf(buf, "0\n");
119+
return sysfs_emit(buf, "0\n");
124120
}
125121
static DEVICE_ATTR_RO(hctosys);
126122

127123
static ssize_t
128124
wakealarm_show(struct device *dev, struct device_attribute *attr, char *buf)
129125
{
130126
ssize_t retval;
131-
time64_t alarm;
132127
struct rtc_wkalrm alm;
133128

134129
/* Don't show disabled alarms. For uniformity, RTC alarms are
@@ -140,12 +135,13 @@ wakealarm_show(struct device *dev, struct device_attribute *attr, char *buf)
140135
* alarms after they trigger, to ensure one-shot semantics.
141136
*/
142137
retval = rtc_read_alarm(to_rtc_device(dev), &alm);
143-
if (retval == 0 && alm.enabled) {
144-
alarm = rtc_tm_to_time64(&alm.time);
145-
retval = sprintf(buf, "%lld\n", alarm);
146-
}
138+
if (retval)
139+
return retval;
140+
141+
if (alm.enabled)
142+
return sysfs_emit(buf, "%lld\n", rtc_tm_to_time64(&alm.time));
147143

148-
return retval;
144+
return 0;
149145
}
150146

151147
static ssize_t
@@ -222,10 +218,10 @@ offset_show(struct device *dev, struct device_attribute *attr, char *buf)
222218
long offset;
223219

224220
retval = rtc_read_offset(to_rtc_device(dev), &offset);
225-
if (retval == 0)
226-
retval = sprintf(buf, "%ld\n", offset);
221+
if (retval)
222+
return retval;
227223

228-
return retval;
224+
return sysfs_emit(buf, "%ld\n", offset);
229225
}
230226

231227
static ssize_t
@@ -246,8 +242,8 @@ static DEVICE_ATTR_RW(offset);
246242
static ssize_t
247243
range_show(struct device *dev, struct device_attribute *attr, char *buf)
248244
{
249-
return sprintf(buf, "[%lld,%llu]\n", to_rtc_device(dev)->range_min,
250-
to_rtc_device(dev)->range_max);
245+
return sysfs_emit(buf, "[%lld,%llu]\n", to_rtc_device(dev)->range_min,
246+
to_rtc_device(dev)->range_max);
251247
}
252248
static DEVICE_ATTR_RO(range);
253249

0 commit comments

Comments
 (0)