kernel/ksysfs.c: use sysfs_emit for sysfs show handlers

sysfs_emit() is the recommended way to format strings for sysfs as per
Documentation/filesystems/sysfs.rst.

Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
Link: https://lore.kernel.org/r/20230324-ksysfs-sysfs_emit-v1-1-67c03cddc8a6@weissschuh.net
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
Thomas Weißschuh 2023-03-24 15:40:41 +00:00 committed by Greg Kroah-Hartman
parent 44650f33d3
commit 9f33a88c0a
1 changed files with 11 additions and 11 deletions

View File

@ -39,7 +39,7 @@ static struct kobj_attribute _name##_attr = __ATTR_RW(_name)
static ssize_t uevent_seqnum_show(struct kobject *kobj, static ssize_t uevent_seqnum_show(struct kobject *kobj,
struct kobj_attribute *attr, char *buf) struct kobj_attribute *attr, char *buf)
{ {
return sprintf(buf, "%llu\n", (unsigned long long)uevent_seqnum); return sysfs_emit(buf, "%llu\n", (unsigned long long)uevent_seqnum);
} }
KERNEL_ATTR_RO(uevent_seqnum); KERNEL_ATTR_RO(uevent_seqnum);
@ -64,7 +64,7 @@ KERNEL_ATTR_RO(address_bits);
static ssize_t uevent_helper_show(struct kobject *kobj, static ssize_t uevent_helper_show(struct kobject *kobj,
struct kobj_attribute *attr, char *buf) struct kobj_attribute *attr, char *buf)
{ {
return sprintf(buf, "%s\n", uevent_helper); return sysfs_emit(buf, "%s\n", uevent_helper);
} }
static ssize_t uevent_helper_store(struct kobject *kobj, static ssize_t uevent_helper_store(struct kobject *kobj,
struct kobj_attribute *attr, struct kobj_attribute *attr,
@ -85,7 +85,7 @@ KERNEL_ATTR_RW(uevent_helper);
static ssize_t profiling_show(struct kobject *kobj, static ssize_t profiling_show(struct kobject *kobj,
struct kobj_attribute *attr, char *buf) struct kobj_attribute *attr, char *buf)
{ {
return sprintf(buf, "%d\n", prof_on); return sysfs_emit(buf, "%d\n", prof_on);
} }
static ssize_t profiling_store(struct kobject *kobj, static ssize_t profiling_store(struct kobject *kobj,
struct kobj_attribute *attr, struct kobj_attribute *attr,
@ -116,14 +116,14 @@ KERNEL_ATTR_RW(profiling);
static ssize_t kexec_loaded_show(struct kobject *kobj, static ssize_t kexec_loaded_show(struct kobject *kobj,
struct kobj_attribute *attr, char *buf) struct kobj_attribute *attr, char *buf)
{ {
return sprintf(buf, "%d\n", !!kexec_image); return sysfs_emit(buf, "%d\n", !!kexec_image);
} }
KERNEL_ATTR_RO(kexec_loaded); KERNEL_ATTR_RO(kexec_loaded);
static ssize_t kexec_crash_loaded_show(struct kobject *kobj, static ssize_t kexec_crash_loaded_show(struct kobject *kobj,
struct kobj_attribute *attr, char *buf) struct kobj_attribute *attr, char *buf)
{ {
return sprintf(buf, "%d\n", kexec_crash_loaded()); return sysfs_emit(buf, "%d\n", kexec_crash_loaded());
} }
KERNEL_ATTR_RO(kexec_crash_loaded); KERNEL_ATTR_RO(kexec_crash_loaded);
@ -135,7 +135,7 @@ static ssize_t kexec_crash_size_show(struct kobject *kobj,
if (size < 0) if (size < 0)
return size; return size;
return sprintf(buf, "%zd\n", size); return sysfs_emit(buf, "%zd\n", size);
} }
static ssize_t kexec_crash_size_store(struct kobject *kobj, static ssize_t kexec_crash_size_store(struct kobject *kobj,
struct kobj_attribute *attr, struct kobj_attribute *attr,
@ -160,8 +160,8 @@ static ssize_t vmcoreinfo_show(struct kobject *kobj,
struct kobj_attribute *attr, char *buf) struct kobj_attribute *attr, char *buf)
{ {
phys_addr_t vmcore_base = paddr_vmcoreinfo_note(); phys_addr_t vmcore_base = paddr_vmcoreinfo_note();
return sprintf(buf, "%pa %x\n", &vmcore_base, return sysfs_emit(buf, "%pa %x\n", &vmcore_base,
(unsigned int)VMCOREINFO_NOTE_SIZE); (unsigned int)VMCOREINFO_NOTE_SIZE);
} }
KERNEL_ATTR_RO(vmcoreinfo); KERNEL_ATTR_RO(vmcoreinfo);
@ -171,7 +171,7 @@ KERNEL_ATTR_RO(vmcoreinfo);
static ssize_t fscaps_show(struct kobject *kobj, static ssize_t fscaps_show(struct kobject *kobj,
struct kobj_attribute *attr, char *buf) struct kobj_attribute *attr, char *buf)
{ {
return sprintf(buf, "%d\n", file_caps_enabled); return sysfs_emit(buf, "%d\n", file_caps_enabled);
} }
KERNEL_ATTR_RO(fscaps); KERNEL_ATTR_RO(fscaps);
@ -180,7 +180,7 @@ int rcu_expedited;
static ssize_t rcu_expedited_show(struct kobject *kobj, static ssize_t rcu_expedited_show(struct kobject *kobj,
struct kobj_attribute *attr, char *buf) struct kobj_attribute *attr, char *buf)
{ {
return sprintf(buf, "%d\n", READ_ONCE(rcu_expedited)); return sysfs_emit(buf, "%d\n", READ_ONCE(rcu_expedited));
} }
static ssize_t rcu_expedited_store(struct kobject *kobj, static ssize_t rcu_expedited_store(struct kobject *kobj,
struct kobj_attribute *attr, struct kobj_attribute *attr,
@ -197,7 +197,7 @@ int rcu_normal;
static ssize_t rcu_normal_show(struct kobject *kobj, static ssize_t rcu_normal_show(struct kobject *kobj,
struct kobj_attribute *attr, char *buf) struct kobj_attribute *attr, char *buf)
{ {
return sprintf(buf, "%d\n", READ_ONCE(rcu_normal)); return sysfs_emit(buf, "%d\n", READ_ONCE(rcu_normal));
} }
static ssize_t rcu_normal_store(struct kobject *kobj, static ssize_t rcu_normal_store(struct kobject *kobj,
struct kobj_attribute *attr, struct kobj_attribute *attr,