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.
Showing the changes to kernel/livepatch (1 of 1 file). Show all
Unified · Split
| @@ -408,26 +408,23 @@ static ssize_t enabled_store(struct kobject *kobj, struct kobj_attribute *attr, · 407 unmodified lines | ||
| 408 | 408 | { |
| 409 | 409 | struct klp_patch *patch; |
| 410 | 410 | int ret; |
| 411 | − unsigned long val; | |
| 411 | + bool enabled; | |
| 412 | 412 | |
| 413 | − ret = kstrtoul(buf, 10, &val); | |
| 413 | + ret = kstrtobool(buf, &enabled); | |
| 414 | 414 | if (ret) |
| 415 | − return -EINVAL; | |
| 416 | − | |
| 417 | − if (val > 1) | |
| 418 | − return -EINVAL; | |
| 415 | + return ret; | |
| 419 | 416 | |
| 420 | 417 | patch = container_of(kobj, struct klp_patch, kobj); |
| 421 | 418 | |
| 422 | 419 | mutex_lock(&klp_mutex); |
| 423 | 420 | |
| 424 | − if (patch->enabled == val) { | |
| 421 | + if (patch->enabled == enabled) { | |
| 425 | 422 | /* already in requested state */ |
| 426 | 423 | ret = -EINVAL; |
| 427 | 424 | goto err; |
| 428 | 425 | } |
| 429 | 426 | |
| 430 | − if (val) { | |
| 427 | + if (enabled) { | |
| 431 | 428 | ret = __klp_enable_patch(patch); |
| 432 | 429 | if (ret) |
| 433 | 430 | goto err; |