samples/kobject: Use kstrtoint instead of sscanf
[sfrench/cifs-2.6.git] / samples / kobject / kset-example.c
index ab5e447ec23871b66b46049129dfaafc6f3f287d..e80ced3a5203f2ce77c3003724c7a208b8f6de4d 100644 (file)
@@ -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