Skip to content

Commit 68ae4b2

Browse files
jpoimboeJiri Kosina
authored andcommitted
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>
1 parent c349cdc commit 68ae4b2

1 file changed

Lines changed: 5 additions & 8 deletions

File tree

‎kernel/livepatch/core.c‎

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -408,26 +408,23 @@ static ssize_t enabled_store(struct kobject *kobj, struct kobj_attribute *attr,
408408
{
409409
struct klp_patch *patch;
410410
int ret;
411-
unsigned long val;
411+
bool enabled;
412412

413-
ret = kstrtoul(buf, 10, &val);
413+
ret = kstrtobool(buf, &enabled);
414414
if (ret)
415-
return -EINVAL;
416-
417-
if (val > 1)
418-
return -EINVAL;
415+
return ret;
419416

420417
patch = container_of(kobj, struct klp_patch, kobj);
421418

422419
mutex_lock(&klp_mutex);
423420

424-
if (patch->enabled == val) {
421+
if (patch->enabled == enabled) {
425422
/* already in requested state */
426423
ret = -EINVAL;
427424
goto err;
428425
}
429426

430-
if (val) {
427+
if (enabled) {
431428
ret = __klp_enable_patch(patch);
432429
if (ret)
433430
goto err;

0 commit comments

Comments
 (0)