Skip to content

Commit

Permalink
livepatch: use kstrtobool() in enabled_store()
Browse files Browse the repository at this point in the history
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 <pmladek@suse.com>
Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
Acked-by: Miroslav Benes <mbenes@suse.cz>
Reviewed-by: Petr Mladek <pmladek@suse.com>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
  • Loading branch information
Josh Poimboeuf authored and Jiri Kosina committed Mar 8, 2017
1 parent c349cdc commit 68ae4b2
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions kernel/livepatch/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 68ae4b2

Please sign in to comment.