diff options
author | Rastislav Barlik <barlik@zoho.com> | 2014-12-17 15:14:48 -0500 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2015-03-25 08:40:31 -0400 |
commit | 5fd637e7a75fb2a4c0b62683c08dae959160fedf (patch) | |
tree | 14939b0698c41cb523f7ed8d64d6ec0a66c21531 /samples | |
parent | 1c34203a1496d1849ba978021b878b3447d433c8 (diff) |
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')
-rw-r--r-- | samples/kobject/kobject-example.c | 14 | ||||
-rw-r--r-- | samples/kobject/kset-example.c | 14 |
2 files changed, 22 insertions, 6 deletions
diff --git a/samples/kobject/kobject-example.c b/samples/kobject/kobject-example.c index 01562e0d4992..063aaece0bcd 100644 --- a/samples/kobject/kobject-example.c +++ b/samples/kobject/kobject-example.c | |||
@@ -36,7 +36,12 @@ static ssize_t foo_show(struct kobject *kobj, struct kobj_attribute *attr, | |||
36 | static ssize_t foo_store(struct kobject *kobj, struct kobj_attribute *attr, | 36 | static ssize_t foo_store(struct kobject *kobj, struct kobj_attribute *attr, |
37 | const char *buf, size_t count) | 37 | const char *buf, size_t count) |
38 | { | 38 | { |
39 | sscanf(buf, "%du", &foo); | 39 | int ret; |
40 | |||
41 | ret = kstrtoint(buf, 10, &foo); | ||
42 | if (ret < 0) | ||
43 | return ret; | ||
44 | |||
40 | return count; | 45 | return count; |
41 | } | 46 | } |
42 | 47 | ||
@@ -63,9 +68,12 @@ static ssize_t b_show(struct kobject *kobj, struct kobj_attribute *attr, | |||
63 | static ssize_t b_store(struct kobject *kobj, struct kobj_attribute *attr, | 68 | static ssize_t b_store(struct kobject *kobj, struct kobj_attribute *attr, |
64 | const char *buf, size_t count) | 69 | const char *buf, size_t count) |
65 | { | 70 | { |
66 | int var; | 71 | int var, ret; |
72 | |||
73 | ret = kstrtoint(buf, 10, &var); | ||
74 | if (ret < 0) | ||
75 | return ret; | ||
67 | 76 | ||
68 | sscanf(buf, "%du", &var); | ||
69 | if (strcmp(attr->attr.name, "baz") == 0) | 77 | if (strcmp(attr->attr.name, "baz") == 0) |
70 | baz = var; | 78 | baz = var; |
71 | else | 79 | else |
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, | |||
120 | static ssize_t foo_store(struct foo_obj *foo_obj, struct foo_attribute *attr, | 120 | static ssize_t foo_store(struct foo_obj *foo_obj, struct foo_attribute *attr, |
121 | const char *buf, size_t count) | 121 | const char *buf, size_t count) |
122 | { | 122 | { |
123 | sscanf(buf, "%du", &foo_obj->foo); | 123 | int ret; |
124 | |||
125 | ret = kstrtoint(buf, 10, &foo_obj->foo); | ||
126 | if (ret < 0) | ||
127 | return ret; | ||
128 | |||
124 | return count; | 129 | return count; |
125 | } | 130 | } |
126 | 131 | ||
@@ -147,9 +152,12 @@ static ssize_t b_show(struct foo_obj *foo_obj, struct foo_attribute *attr, | |||
147 | static ssize_t b_store(struct foo_obj *foo_obj, struct foo_attribute *attr, | 152 | static ssize_t b_store(struct foo_obj *foo_obj, struct foo_attribute *attr, |
148 | const char *buf, size_t count) | 153 | const char *buf, size_t count) |
149 | { | 154 | { |
150 | int var; | 155 | int var, ret; |
156 | |||
157 | ret = kstrtoint(buf, 10, &var); | ||
158 | if (ret < 0) | ||
159 | return ret; | ||
151 | 160 | ||
152 | sscanf(buf, "%du", &var); | ||
153 | if (strcmp(attr->attr.name, "baz") == 0) | 161 | if (strcmp(attr->attr.name, "baz") == 0) |
154 | foo_obj->baz = var; | 162 | foo_obj->baz = var; |
155 | else | 163 | else |