From: Josh Poimboeuf Date: Tue, 14 Feb 2017 01:42:38 +0000 (-0600) Subject: livepatch: use kstrtobool() in enabled_store() X-Git-Tag: v4.12-rc1~125^2^2~6 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=68ae4b2b687c3da59ca1d762646ddece4ea1c438;p=thirdparty%2Flinux.git livepatch: use kstrtobool() in enabled_store() The sysfs enabled value is a boolean, so kstrtobool() is a better fit for parsing the input string since it does the range checking for us. Suggested-by: Petr Mladek Signed-off-by: Josh Poimboeuf Acked-by: Miroslav Benes Reviewed-by: Petr Mladek Signed-off-by: Jiri Kosina --- diff --git a/kernel/livepatch/core.c b/kernel/livepatch/core.c index 6a137e1f4490a..83c4949862b42 100644 --- a/kernel/livepatch/core.c +++ b/kernel/livepatch/core.c @@ -408,26 +408,23 @@ static ssize_t enabled_store(struct kobject *kobj, struct kobj_attribute *attr, { struct klp_patch *patch; int ret; - unsigned long val; + bool enabled; - ret = kstrtoul(buf, 10, &val); + ret = kstrtobool(buf, &enabled); if (ret) - return -EINVAL; - - if (val > 1) - return -EINVAL; + return ret; patch = container_of(kobj, struct klp_patch, kobj); mutex_lock(&klp_mutex); - if (patch->enabled == val) { + if (patch->enabled == enabled) { /* already in requested state */ ret = -EINVAL; goto err; } - if (val) { + if (enabled) { ret = __klp_enable_patch(patch); if (ret) goto err;