--- zzzz-none-000/linux-3.10.107/samples/kobject/kobject-example.c 2017-06-27 09:49:32.000000000 +0000 +++ scorpion-7490-727/linux-3.10.107/samples/kobject/kobject-example.c 2021-02-04 17:41:59.000000000 +0000 @@ -36,12 +36,18 @@ static ssize_t foo_store(struct kobject *kobj, struct kobj_attribute *attr, const char *buf, size_t count) { - sscanf(buf, "%du", &foo); + int ret; + + ret = kstrtoint(buf, 10, &foo); + if (ret < 0) + return ret; + return count; } +/* Sysfs attributes cannot be world-writable. */ static struct kobj_attribute foo_attribute = - __ATTR(foo, 0666, foo_show, foo_store); + __ATTR(foo, 0664, foo_show, foo_store); /* * More complex function where we determine which variable is being accessed by @@ -62,9 +68,12 @@ static ssize_t b_store(struct kobject *kobj, struct kobj_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) baz = var; else @@ -73,9 +82,9 @@ } static struct kobj_attribute baz_attribute = - __ATTR(baz, 0666, b_show, b_store); + __ATTR(baz, 0664, b_show, b_store); static struct kobj_attribute bar_attribute = - __ATTR(bar, 0666, b_show, b_store); + __ATTR(bar, 0664, b_show, b_store); /* @@ -133,5 +142,5 @@ module_init(example_init); module_exit(example_exit); -MODULE_LICENSE("GPL"); +MODULE_LICENSE("GPL v2"); MODULE_AUTHOR("Greg Kroah-Hartman ");