Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1562856

[PATCH v4 11/15] livepatch: use kstrtobool() in enabled_store()

From Josh Poimboeuf <jpoimboe@redhat.com>
Newsgroups linux.kernel
Subject [PATCH v4 11/15] livepatch: use kstrtobool() in enabled_store()
Date 2017-01-19 17:00 +0100
Message-ID <t1ni2-3q2-15@gated-at.bofh.it> (permalink)
References <t1n8l-3mv-7@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


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>
---
 kernel/livepatch/core.c | 13 +++++--------
 1 file changed, 5 insertions(+), 8 deletions(-)

diff --git a/kernel/livepatch/core.c b/kernel/livepatch/core.c
index 6a137e1..83c4949 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;
-- 
2.7.4

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH v4 00/15] livepatch: hybrid consistency model Josh Poimboeuf <jpoimboe@redhat.com> - 2017-01-19 16:50 +0100
  [PATCH v4 02/15] x86/entry: define _TIF_ALLWORK_MASK flags explicitly Josh Poimboeuf <jpoimboe@redhat.com> - 2017-01-19 16:50 +0100
  [PATCH v4 15/15] livepatch: allow removal of a disabled patch Josh Poimboeuf <jpoimboe@redhat.com> - 2017-01-19 16:50 +0100
  [PATCH v4 04/15] livepatch/x86: add TIF_PATCH_PENDING thread flag Josh Poimboeuf <jpoimboe@redhat.com> - 2017-01-19 17:00 +0100
  [PATCH v4 12/15] livepatch: store function sizes Josh Poimboeuf <jpoimboe@redhat.com> - 2017-01-19 17:00 +0100
  [PATCH v4 06/15] livepatch/s390: reorganize TIF thread flag bits Josh Poimboeuf <jpoimboe@redhat.com> - 2017-01-19 17:00 +0100
  [PATCH v4 11/15] livepatch: use kstrtobool() in enabled_store() Josh Poimboeuf <jpoimboe@redhat.com> - 2017-01-19 17:00 +0100
  [PATCH v4 03/15] livepatch: create temporary klp_update_patch_state() stub Josh Poimboeuf <jpoimboe@redhat.com> - 2017-01-19 17:00 +0100
    Re: [PATCH v4 03/15] livepatch: create temporary klp_update_patch_state()  stub Miroslav Benes <mbenes@suse.cz> - 2017-01-27 10:00 +0100
  [PATCH v4 10/15] livepatch: move patching functions into patch.c Josh Poimboeuf <jpoimboe@redhat.com> - 2017-01-19 17:00 +0100

csiph-web