diff options
author | Rastislav Barlik <barlik@zoho.com> | 2014-12-17 21:14:48 +0100 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2015-03-25 13:40:31 +0100 |
commit | 5fd637e7a75fb2a4c0b62683c08dae959160fedf (patch) | |
tree | 14939b0698c41cb523f7ed8d64d6ec0a66c21531 /samples/kobject/kset-example.c | |
parent | 1c34203a1496d1849ba978021b878b3447d433c8 (diff) | |
download | talos-op-linux-5fd637e7a75fb2a4c0b62683c08dae959160fedf.tar.gz talos-op-linux-5fd637e7a75fb2a4c0b62683c08dae959160fedf.zip |
samples/kobject: Use kstrtoint instead of sscanf
Use kstrtoint function instead of sscanf and check for return values.
Signed-off-by: Rastislav Barlik <barlik@zoho.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'samples/kobject/kset-example.c')
-rw-r--r-- | samples/kobject/kset-example.c | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/samples/kobject/kset-example.c b/samples/kobject/kset-example.c index ab5e447ec238..e80ced3a5203 100644 --- a/samples/kobject/kset-example.c +++ b/samples/kobject/kset-example.c @@ -120,7 +120,12 @@ static ssize_t foo_show(struct foo_obj *foo_obj, struct foo_attribute *attr, static ssize_t foo_store(struct foo_obj *foo_obj, struct foo_attribute *attr, const char *buf, size_t count) { - sscanf(buf, "%du", &foo_obj->foo); + int ret; + + ret = kstrtoint(buf, 10, &foo_obj->foo); + if (ret < 0) + return ret; + return count; } @@ -147,9 +152,12 @@ static ssize_t b_show(struct foo_obj *foo_obj, struct foo_attribute *attr, static ssize_t b_store(struct foo_obj *foo_obj, struct foo_attribute *attr, const char *buf, size_t count) { - int var; + int var, ret; + + ret = kstrtoint(buf, 10, &var); + if (ret < 0) + return ret; - sscanf(buf, "%du", &var); if (strcmp(attr->attr.name, "baz") == 0) foo_obj->baz = var; else |