diff mbox

[v3,11/15] livepatch: use kstrtobool() in enabled_store()

Message ID 50c4817cbccd6e6cfd0c85c96bf127f84ee79cc8.1481220077.git.jpoimboe@redhat.com (mailing list archive)
State Superseded
Headers show

Commit Message

Josh Poimboeuf Dec. 8, 2016, 6:08 p.m. UTC
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>
---
 kernel/livepatch/core.c | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)

Comments

Petr Mladek Dec. 16, 2016, 4:55 p.m. UTC | #1
On Thu 2016-12-08 12:08:36, Josh Poimboeuf wrote:
> 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>
> ---
>  kernel/livepatch/core.c | 11 ++++-------
>  1 file changed, 4 insertions(+), 7 deletions(-)
> 
> diff --git a/kernel/livepatch/core.c b/kernel/livepatch/core.c
> index 6a137e1..8ca8a0e 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;

I would return "ret" here. It is -EINVAL as well but... ;-)

Anyway, feel free to use:

Reviewed-by: Petr Mladek <pmladek@suse.com>

Best Regards,
Petr
Josh Poimboeuf Dec. 16, 2016, 10:19 p.m. UTC | #2
On Fri, Dec 16, 2016 at 05:55:55PM +0100, Petr Mladek wrote:
> On Thu 2016-12-08 12:08:36, Josh Poimboeuf wrote:
> > 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>
> > ---
> >  kernel/livepatch/core.c | 11 ++++-------
> >  1 file changed, 4 insertions(+), 7 deletions(-)
> > 
> > diff --git a/kernel/livepatch/core.c b/kernel/livepatch/core.c
> > index 6a137e1..8ca8a0e 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;
> 
> I would return "ret" here. It is -EINVAL as well but... ;-)

That was a preexisting issue with the kstrtoul() return code, but I'll
sneak your suggested change into this patch if nobody objects.

> Anyway, feel free to use:
> 
> Reviewed-by: Petr Mladek <pmladek@suse.com>
> 
> Best Regards,
> Petr
Miroslav Benes Dec. 23, 2016, 1:13 p.m. UTC | #3
On Fri, 16 Dec 2016, Josh Poimboeuf wrote:

> On Fri, Dec 16, 2016 at 05:55:55PM +0100, Petr Mladek wrote:
> > On Thu 2016-12-08 12:08:36, Josh Poimboeuf wrote:
> > > 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>
> > > ---
> > >  kernel/livepatch/core.c | 11 ++++-------
> > >  1 file changed, 4 insertions(+), 7 deletions(-)
> > > 
> > > diff --git a/kernel/livepatch/core.c b/kernel/livepatch/core.c
> > > index 6a137e1..8ca8a0e 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;
> > 
> > I would return "ret" here. It is -EINVAL as well but... ;-)
> 
> That was a preexisting issue with the kstrtoul() return code, but I'll
> sneak your suggested change into this patch if nobody objects.

Fine with me.

Acked-by: Miroslav Benes <mbenes@suse.cz>

Miroslav
diff mbox

Patch

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