@@ -115,7 +115,7 @@ int pm_async_enabled = 1;
115
115
static ssize_t pm_async_show (struct kobject * kobj , struct kobj_attribute * attr ,
116
116
char * buf )
117
117
{
118
- return sprintf (buf , "%d\n" , pm_async_enabled );
118
+ return sysfs_emit (buf , "%d\n" , pm_async_enabled );
119
119
}
120
120
121
121
static ssize_t pm_async_store (struct kobject * kobj , struct kobj_attribute * attr ,
@@ -139,7 +139,7 @@ power_attr(pm_async);
139
139
static ssize_t mem_sleep_show (struct kobject * kobj , struct kobj_attribute * attr ,
140
140
char * buf )
141
141
{
142
- char * s = buf ;
142
+ ssize_t count = 0 ;
143
143
suspend_state_t i ;
144
144
145
145
for (i = PM_SUSPEND_MIN ; i < PM_SUSPEND_MAX ; i ++ ) {
@@ -149,17 +149,17 @@ static ssize_t mem_sleep_show(struct kobject *kobj, struct kobj_attribute *attr,
149
149
const char * label = mem_sleep_states [i ];
150
150
151
151
if (mem_sleep_current == i )
152
- s += sprintf ( s , "[%s] " , label );
152
+ count += sysfs_emit_at ( buf , count , "[%s] " , label );
153
153
else
154
- s += sprintf ( s , "%s " , label );
154
+ count += sysfs_emit_at ( buf , count , "%s " , label );
155
155
}
156
156
}
157
157
158
158
/* Convert the last space to a newline if needed. */
159
- if (s != buf )
160
- * ( s - 1 ) = '\n' ;
159
+ if (count > 0 )
160
+ buf [ count - 1 ] = '\n' ;
161
161
162
- return ( s - buf ) ;
162
+ return count ;
163
163
}
164
164
165
165
static suspend_state_t decode_suspend_state (const char * buf , size_t n )
@@ -220,7 +220,7 @@ bool sync_on_suspend_enabled = !IS_ENABLED(CONFIG_SUSPEND_SKIP_SYNC);
220
220
static ssize_t sync_on_suspend_show (struct kobject * kobj ,
221
221
struct kobj_attribute * attr , char * buf )
222
222
{
223
- return sprintf (buf , "%d\n" , sync_on_suspend_enabled );
223
+ return sysfs_emit (buf , "%d\n" , sync_on_suspend_enabled );
224
224
}
225
225
226
226
static ssize_t sync_on_suspend_store (struct kobject * kobj ,
@@ -257,22 +257,22 @@ static const char * const pm_tests[__TEST_AFTER_LAST] = {
257
257
static ssize_t pm_test_show (struct kobject * kobj , struct kobj_attribute * attr ,
258
258
char * buf )
259
259
{
260
- char * s = buf ;
260
+ ssize_t count = 0 ;
261
261
int level ;
262
262
263
263
for (level = TEST_FIRST ; level <= TEST_MAX ; level ++ )
264
264
if (pm_tests [level ]) {
265
265
if (level == pm_test_level )
266
- s += sprintf ( s , "[%s] " , pm_tests [level ]);
266
+ count += sysfs_emit_at ( buf , count , "[%s] " , pm_tests [level ]);
267
267
else
268
- s += sprintf ( s , "%s " , pm_tests [level ]);
268
+ count += sysfs_emit_at ( buf , count , "%s " , pm_tests [level ]);
269
269
}
270
270
271
- if ( s != buf )
272
- /* convert the last space to a newline */
273
- * ( s - 1 ) = '\n' ;
271
+ /* Convert the last space to a newline if needed. */
272
+ if ( count > 0 )
273
+ buf [ count - 1 ] = '\n' ;
274
274
275
- return ( s - buf ) ;
275
+ return count ;
276
276
}
277
277
278
278
static ssize_t pm_test_store (struct kobject * kobj , struct kobj_attribute * attr ,
@@ -390,7 +390,7 @@ static const char * const suspend_step_names[] = {
390
390
static ssize_t _name##_show(struct kobject *kobj, \
391
391
struct kobj_attribute *attr, char *buf) \
392
392
{ \
393
- return sprintf (buf, format_str, suspend_stats._name); \
393
+ return sysfs_emit (buf, format_str, suspend_stats._name);\
394
394
} \
395
395
static struct kobj_attribute _name = __ATTR_RO(_name)
396
396
@@ -404,7 +404,7 @@ suspend_attr(max_hw_sleep, "%llu\n");
404
404
static ssize_t _name##_show(struct kobject *kobj, \
405
405
struct kobj_attribute *attr, char *buf) \
406
406
{ \
407
- return sprintf (buf, "%u\n", \
407
+ return sysfs_emit (buf, "%u\n", \
408
408
suspend_stats.step_failures[step-1]); \
409
409
} \
410
410
static struct kobj_attribute _name = __ATTR_RO(_name)
@@ -428,7 +428,7 @@ static ssize_t last_failed_dev_show(struct kobject *kobj,
428
428
index %= REC_FAILED_NUM ;
429
429
last_failed_dev = suspend_stats .failed_devs [index ];
430
430
431
- return sprintf (buf , "%s\n" , last_failed_dev );
431
+ return sysfs_emit (buf , "%s\n" , last_failed_dev );
432
432
}
433
433
static struct kobj_attribute last_failed_dev = __ATTR_RO (last_failed_dev );
434
434
@@ -442,7 +442,7 @@ static ssize_t last_failed_errno_show(struct kobject *kobj,
442
442
index %= REC_FAILED_NUM ;
443
443
last_failed_errno = suspend_stats .errno [index ];
444
444
445
- return sprintf (buf , "%d\n" , last_failed_errno );
445
+ return sysfs_emit (buf , "%d\n" , last_failed_errno );
446
446
}
447
447
static struct kobj_attribute last_failed_errno = __ATTR_RO (last_failed_errno );
448
448
@@ -456,7 +456,7 @@ static ssize_t last_failed_step_show(struct kobject *kobj,
456
456
index %= REC_FAILED_NUM ;
457
457
step = suspend_stats .failed_steps [index ];
458
458
459
- return sprintf (buf , "%s\n" , suspend_step_names [step ]);
459
+ return sysfs_emit (buf , "%s\n" , suspend_step_names [step ]);
460
460
}
461
461
static struct kobj_attribute last_failed_step = __ATTR_RO (last_failed_step );
462
462
@@ -571,7 +571,7 @@ bool pm_print_times_enabled;
571
571
static ssize_t pm_print_times_show (struct kobject * kobj ,
572
572
struct kobj_attribute * attr , char * buf )
573
573
{
574
- return sprintf (buf , "%d\n" , pm_print_times_enabled );
574
+ return sysfs_emit (buf , "%d\n" , pm_print_times_enabled );
575
575
}
576
576
577
577
static ssize_t pm_print_times_store (struct kobject * kobj ,
@@ -604,7 +604,7 @@ static ssize_t pm_wakeup_irq_show(struct kobject *kobj,
604
604
if (!pm_wakeup_irq ())
605
605
return - ENODATA ;
606
606
607
- return sprintf (buf , "%u\n" , pm_wakeup_irq ());
607
+ return sysfs_emit (buf , "%u\n" , pm_wakeup_irq ());
608
608
}
609
609
610
610
power_attr_ro (pm_wakeup_irq );
@@ -620,7 +620,7 @@ EXPORT_SYMBOL_GPL(pm_debug_messages_should_print);
620
620
static ssize_t pm_debug_messages_show (struct kobject * kobj ,
621
621
struct kobj_attribute * attr , char * buf )
622
622
{
623
- return sprintf (buf , "%d\n" , pm_debug_messages_on );
623
+ return sysfs_emit (buf , "%d\n" , pm_debug_messages_on );
624
624
}
625
625
626
626
static ssize_t pm_debug_messages_store (struct kobject * kobj ,
@@ -668,21 +668,23 @@ struct kobject *power_kobj;
668
668
static ssize_t state_show (struct kobject * kobj , struct kobj_attribute * attr ,
669
669
char * buf )
670
670
{
671
- char * s = buf ;
671
+ ssize_t count = 0 ;
672
672
#ifdef CONFIG_SUSPEND
673
673
suspend_state_t i ;
674
674
675
675
for (i = PM_SUSPEND_MIN ; i < PM_SUSPEND_MAX ; i ++ )
676
676
if (pm_states [i ])
677
- s += sprintf ( s , "%s " , pm_states [i ]);
677
+ count += sysfs_emit_at ( buf , count , "%s " , pm_states [i ]);
678
678
679
679
#endif
680
680
if (hibernation_available ())
681
- s += sprintf (s , "disk " );
682
- if (s != buf )
683
- /* convert the last space to a newline */
684
- * (s - 1 ) = '\n' ;
685
- return (s - buf );
681
+ count += sysfs_emit_at (buf , count , "disk " );
682
+
683
+ /* Convert the last space to a newline if needed. */
684
+ if (count > 0 )
685
+ buf [count - 1 ] = '\n' ;
686
+
687
+ return count ;
686
688
}
687
689
688
690
static suspend_state_t decode_state (const char * buf , size_t n )
@@ -782,7 +784,7 @@ static ssize_t wakeup_count_show(struct kobject *kobj,
782
784
unsigned int val ;
783
785
784
786
return pm_get_wakeup_count (& val , true) ?
785
- sprintf (buf , "%u\n" , val ) : - EINTR ;
787
+ sysfs_emit (buf , "%u\n" , val ) : - EINTR ;
786
788
}
787
789
788
790
static ssize_t wakeup_count_store (struct kobject * kobj ,
@@ -824,17 +826,17 @@ static ssize_t autosleep_show(struct kobject *kobj,
824
826
suspend_state_t state = pm_autosleep_state ();
825
827
826
828
if (state == PM_SUSPEND_ON )
827
- return sprintf (buf , "off\n" );
829
+ return sysfs_emit (buf , "off\n" );
828
830
829
831
#ifdef CONFIG_SUSPEND
830
832
if (state < PM_SUSPEND_MAX )
831
- return sprintf (buf , "%s\n" , pm_states [state ] ?
833
+ return sysfs_emit (buf , "%s\n" , pm_states [state ] ?
832
834
pm_states [state ] : "error" );
833
835
#endif
834
836
#ifdef CONFIG_HIBERNATION
835
- return sprintf (buf , "disk\n" );
837
+ return sysfs_emit (buf , "disk\n" );
836
838
#else
837
- return sprintf (buf , "error" );
839
+ return sysfs_emit (buf , "error\n " );
838
840
#endif
839
841
}
840
842
@@ -903,7 +905,7 @@ int pm_trace_enabled;
903
905
static ssize_t pm_trace_show (struct kobject * kobj , struct kobj_attribute * attr ,
904
906
char * buf )
905
907
{
906
- return sprintf (buf , "%d\n" , pm_trace_enabled );
908
+ return sysfs_emit (buf , "%d\n" , pm_trace_enabled );
907
909
}
908
910
909
911
static ssize_t
@@ -940,7 +942,7 @@ power_attr_ro(pm_trace_dev_match);
940
942
static ssize_t pm_freeze_timeout_show (struct kobject * kobj ,
941
943
struct kobj_attribute * attr , char * buf )
942
944
{
943
- return sprintf (buf , "%u\n" , freeze_timeout_msecs );
945
+ return sysfs_emit (buf , "%u\n" , freeze_timeout_msecs );
944
946
}
945
947
946
948
static ssize_t pm_freeze_timeout_store (struct kobject * kobj ,
0 commit comments