Skip to content

Commit 6306653

Browse files
Xueqin Luorafaeljw
authored andcommitted
PM: hibernate: Use sysfs_emit() and sysfs_emit_at() in "show" functions
As Documentation/filesystems/sysfs.rst suggested, show() should only use sysfs_emit() or sysfs_emit_at() when formatting the value to be returned to user space. No functional change intended. Signed-off-by: Xueqin Luo <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Rafael J. Wysocki <[email protected]>
1 parent 8400291 commit 6306653

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

kernel/power/hibernate.c

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1123,11 +1123,11 @@ static const char * const hibernation_modes[] = {
11231123
static ssize_t disk_show(struct kobject *kobj, struct kobj_attribute *attr,
11241124
char *buf)
11251125
{
1126+
ssize_t count = 0;
11261127
int i;
1127-
char *start = buf;
11281128

11291129
if (!hibernation_available())
1130-
return sprintf(buf, "[disabled]\n");
1130+
return sysfs_emit(buf, "[disabled]\n");
11311131

11321132
for (i = HIBERNATION_FIRST; i <= HIBERNATION_MAX; i++) {
11331133
if (!hibernation_modes[i])
@@ -1147,12 +1147,16 @@ static ssize_t disk_show(struct kobject *kobj, struct kobj_attribute *attr,
11471147
continue;
11481148
}
11491149
if (i == hibernation_mode)
1150-
buf += sprintf(buf, "[%s] ", hibernation_modes[i]);
1150+
count += sysfs_emit_at(buf, count, "[%s] ", hibernation_modes[i]);
11511151
else
1152-
buf += sprintf(buf, "%s ", hibernation_modes[i]);
1152+
count += sysfs_emit_at(buf, count, "%s ", hibernation_modes[i]);
11531153
}
1154-
buf += sprintf(buf, "\n");
1155-
return buf-start;
1154+
1155+
/* Convert the last space to a newline if needed. */
1156+
if (count > 0)
1157+
buf[count - 1] = '\n';
1158+
1159+
return count;
11561160
}
11571161

11581162
static ssize_t disk_store(struct kobject *kobj, struct kobj_attribute *attr,
@@ -1210,8 +1214,8 @@ power_attr(disk);
12101214
static ssize_t resume_show(struct kobject *kobj, struct kobj_attribute *attr,
12111215
char *buf)
12121216
{
1213-
return sprintf(buf, "%d:%d\n", MAJOR(swsusp_resume_device),
1214-
MINOR(swsusp_resume_device));
1217+
return sysfs_emit(buf, "%d:%d\n", MAJOR(swsusp_resume_device),
1218+
MINOR(swsusp_resume_device));
12151219
}
12161220

12171221
static ssize_t resume_store(struct kobject *kobj, struct kobj_attribute *attr,
@@ -1270,7 +1274,7 @@ power_attr(resume);
12701274
static ssize_t resume_offset_show(struct kobject *kobj,
12711275
struct kobj_attribute *attr, char *buf)
12721276
{
1273-
return sprintf(buf, "%llu\n", (unsigned long long)swsusp_resume_block);
1277+
return sysfs_emit(buf, "%llu\n", (unsigned long long)swsusp_resume_block);
12741278
}
12751279

12761280
static ssize_t resume_offset_store(struct kobject *kobj,
@@ -1293,7 +1297,7 @@ power_attr(resume_offset);
12931297
static ssize_t image_size_show(struct kobject *kobj, struct kobj_attribute *attr,
12941298
char *buf)
12951299
{
1296-
return sprintf(buf, "%lu\n", image_size);
1300+
return sysfs_emit(buf, "%lu\n", image_size);
12971301
}
12981302

12991303
static ssize_t image_size_store(struct kobject *kobj, struct kobj_attribute *attr,
@@ -1314,7 +1318,7 @@ power_attr(image_size);
13141318
static ssize_t reserved_size_show(struct kobject *kobj,
13151319
struct kobj_attribute *attr, char *buf)
13161320
{
1317-
return sprintf(buf, "%lu\n", reserved_size);
1321+
return sysfs_emit(buf, "%lu\n", reserved_size);
13181322
}
13191323

13201324
static ssize_t reserved_size_store(struct kobject *kobj,

0 commit comments

Comments
 (0)