diff options
| author | Josh Poimboeuf <jpoimboe@redhat.com> | 2017-02-13 20:42:38 -0500 |
|---|---|---|
| committer | Jiri Kosina <jkosina@suse.cz> | 2017-03-08 03:23:52 -0500 |
| commit | 68ae4b2b687c3da59ca1d762646ddece4ea1c438 (patch) | |
| tree | 6e0ebffd92c74bf41a8c0e587456cfd67db57347 /kernel/livepatch | |
| parent | c349cdcaba589fb49cf105093ebc695eb8b9ff08 (diff) | |
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 <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>
Diffstat (limited to 'kernel/livepatch')
| -rw-r--r-- | kernel/livepatch/core.c | 13 |
1 files changed, 5 insertions, 8 deletions
diff --git a/kernel/livepatch/core.c b/kernel/livepatch/core.c index 6a137e1f4490..83c4949862b4 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, | |||
| 408 | { | 408 | { |
| 409 | struct klp_patch *patch; | 409 | struct klp_patch *patch; |
| 410 | int ret; | 410 | int ret; |
| 411 | unsigned long val; | 411 | bool enabled; |
| 412 | 412 | ||
| 413 | ret = kstrtoul(buf, 10, &val); | 413 | ret = kstrtobool(buf, &enabled); |
| 414 | if (ret) | 414 | if (ret) |
| 415 | return -EINVAL; | 415 | return ret; |
| 416 | |||
| 417 | if (val > 1) | ||
| 418 | return -EINVAL; | ||
| 419 | 416 | ||
| 420 | patch = container_of(kobj, struct klp_patch, kobj); | 417 | patch = container_of(kobj, struct klp_patch, kobj); |
| 421 | 418 | ||
| 422 | mutex_lock(&klp_mutex); | 419 | mutex_lock(&klp_mutex); |
| 423 | 420 | ||
| 424 | if (patch->enabled == val) { | 421 | if (patch->enabled == enabled) { |
| 425 | /* already in requested state */ | 422 | /* already in requested state */ |
| 426 | ret = -EINVAL; | 423 | ret = -EINVAL; |
| 427 | goto err; | 424 | goto err; |
| 428 | } | 425 | } |
| 429 | 426 | ||
| 430 | if (val) { | 427 | if (enabled) { |
| 431 | ret = __klp_enable_patch(patch); | 428 | ret = __klp_enable_patch(patch); |
| 432 | if (ret) | 429 | if (ret) |
| 433 | goto err; | 430 | goto err; |
