2424static ssize_t
2525name_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}
3030static 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}
4444static 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}
5858static 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}
7672static DEVICE_ATTR_RO (since_epoch );
7773
7874static ssize_t
7975max_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
8480static 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}
125121static DEVICE_ATTR_RO (hctosys );
126122
127123static ssize_t
128124wakealarm_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
151147static 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
231227static ssize_t
@@ -246,8 +242,8 @@ static DEVICE_ATTR_RW(offset);
246242static ssize_t
247243range_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}
252248static DEVICE_ATTR_RO (range );
253249
0 commit comments