summaryrefslogtreecommitdiff
path: root/samples/kobject
diff options
context:
space:
mode:
authorNguyen Dinh Phi <phind.uet@gmail.com>2022-03-03 21:36:18 +0300
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2022-03-18 16:28:29 +0300
commit5a242d8547bdc5802d1e1200a85e69afc3c2d74e (patch)
treeeb14bd2ddfab55b9f3c2305477fc8c2b4e74417a /samples/kobject
parentb0f6807d35667faae6de5e23ceffa4546c209bc8 (diff)
downloadlinux-5a242d8547bdc5802d1e1200a85e69afc3c2d74e.tar.xz
samples/kobject: Use sysfs_emit instead of sprintf
sysfs_emit() is preferred over sprintf() when formatting the value to be returned to user space in show() functions, because it knows about sysfs buffer specifics and has sanity checks. Signed-off-by: Nguyen Dinh Phi <phind.uet@gmail.com> Link: https://lore.kernel.org/r/20220303183618.1342358-1-phind.uet@gmail.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'samples/kobject')
-rw-r--r--samples/kobject/kobject-example.c4
-rw-r--r--samples/kobject/kset-example.c4
2 files changed, 4 insertions, 4 deletions
diff --git a/samples/kobject/kobject-example.c b/samples/kobject/kobject-example.c
index 9e383fdbaa00..96678ed73216 100644
--- a/samples/kobject/kobject-example.c
+++ b/samples/kobject/kobject-example.c
@@ -28,7 +28,7 @@ static int bar;
static ssize_t foo_show(struct kobject *kobj, struct kobj_attribute *attr,
char *buf)
{
- return sprintf(buf, "%d\n", foo);
+ return sysfs_emit(buf, "%d\n", foo);
}
static ssize_t foo_store(struct kobject *kobj, struct kobj_attribute *attr,
@@ -60,7 +60,7 @@ static ssize_t b_show(struct kobject *kobj, struct kobj_attribute *attr,
var = baz;
else
var = bar;
- return sprintf(buf, "%d\n", var);
+ return sysfs_emit(buf, "%d\n", var);
}
static ssize_t b_store(struct kobject *kobj, struct kobj_attribute *attr,
diff --git a/samples/kobject/kset-example.c b/samples/kobject/kset-example.c
index c8010f126808..52f1acabd479 100644
--- a/samples/kobject/kset-example.c
+++ b/samples/kobject/kset-example.c
@@ -112,7 +112,7 @@ static void foo_release(struct kobject *kobj)
static ssize_t foo_show(struct foo_obj *foo_obj, struct foo_attribute *attr,
char *buf)
{
- return sprintf(buf, "%d\n", foo_obj->foo);
+ return sysfs_emit(buf, "%d\n", foo_obj->foo);
}
static ssize_t foo_store(struct foo_obj *foo_obj, struct foo_attribute *attr,
@@ -144,7 +144,7 @@ static ssize_t b_show(struct foo_obj *foo_obj, struct foo_attribute *attr,
var = foo_obj->baz;
else
var = foo_obj->bar;
- return sprintf(buf, "%d\n", var);
+ return sysfs_emit(buf, "%d\n", var);
}
static ssize_t b_store(struct foo_obj *foo_obj, struct foo_attribute *attr,