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


Groups > linux.kernel > #1679570 > unrolled thread

[PATCH] HID: wacom: Remove comparison of u8 mode with zero and simplify.

Started byChristos Gkekas <chris.gekas@gmail.com>
First post2017-07-03 00:00 +0200
Last post2017-07-03 00:40 +0200
Articles 3 — 2 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH] HID: wacom: Remove comparison of u8 mode with zero and simplify. Christos Gkekas <chris.gekas@gmail.com> - 2017-07-03 00:00 +0200
    Re: [PATCH] HID: wacom: Remove comparison of u8 mode with zero and  simplify. Joe Perches <joe@perches.com> - 2017-07-03 00:10 +0200
      Re: [PATCH] HID: wacom: Remove comparison of u8 mode with zero and  simplify. Christos Gkekas <chris.gekas@gmail.com> - 2017-07-03 00:40 +0200

#1679570 — [PATCH] HID: wacom: Remove comparison of u8 mode with zero and simplify.

FromChristos Gkekas <chris.gekas@gmail.com>
Date2017-07-03 00:00 +0200
Subject[PATCH] HID: wacom: Remove comparison of u8 mode with zero and simplify.
Message-ID<tYV4l-88R-13@gated-at.bofh.it>
Variable mode in method wacom_show_remote_mode() is defined as u8, thus
statement (mode >= 0) is always true and should be removed, simplifying
the logic.

Signed-off-by: Christos Gkekas <chris.gekas@gmail.com>
---
 drivers/hid/wacom_sys.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/drivers/hid/wacom_sys.c b/drivers/hid/wacom_sys.c
index 838c1eb..79c3d7f 100644
--- a/drivers/hid/wacom_sys.c
+++ b/drivers/hid/wacom_sys.c
@@ -1671,10 +1671,7 @@ static ssize_t wacom_show_remote_mode(struct kobject *kobj,
 	u8 mode;
 
 	mode = wacom->led.groups[index].select;
-	if (mode >= 0 && mode < 3)
-		return snprintf(buf, PAGE_SIZE, "%d\n", mode);
-	else
-		return snprintf(buf, PAGE_SIZE, "%d\n", -1);
+	return snprintf(buf, PAGE_SIZE, "%d\n", mode < 3 ? mode : -1);
 }
 
 #define DEVICE_EKR_ATTR_GROUP(SET_ID)					\
-- 
2.7.4

[toc] | [next] | [standalone]


#1679572 — Re: [PATCH] HID: wacom: Remove comparison of u8 mode with zero and simplify.

FromJoe Perches <joe@perches.com>
Date2017-07-03 00:10 +0200
SubjectRe: [PATCH] HID: wacom: Remove comparison of u8 mode with zero and simplify.
Message-ID<tYVe2-8rT-9@gated-at.bofh.it>
In reply to#1679570
On Sun, 2017-07-02 at 22:54 +0100, Christos Gkekas wrote:
> Variable mode in method wacom_show_remote_mode() is defined as u8, thus
> statement (mode >= 0) is always true and should be removed, simplifying
> the logic.
[]
> diff --git a/drivers/hid/wacom_sys.c b/drivers/hid/wacom_sys.c
[]
> @@ -1671,10 +1671,7 @@ static ssize_t wacom_show_remote_mode(struct kobject *kobj,
>  	u8 mode;
>  
>  	mode = wacom->led.groups[index].select;
> -	if (mode >= 0 && mode < 3)
> -		return snprintf(buf, PAGE_SIZE, "%d\n", mode);
> -	else
> -		return snprintf(buf, PAGE_SIZE, "%d\n", -1);
> +	return snprintf(buf, PAGE_SIZE, "%d\n", mode < 3 ? mode : -1);

It's also hard to imagine that PAGE_SIZE could be less than 4 bytes so
	return sprintf(buf, "%d\n", mode < 3 ? mode : -1);
could work too.

[toc] | [prev] | [next] | [standalone]


#1679575 — Re: [PATCH] HID: wacom: Remove comparison of u8 mode with zero and simplify.

FromChristos Gkekas <chris.gekas@gmail.com>
Date2017-07-03 00:40 +0200
SubjectRe: [PATCH] HID: wacom: Remove comparison of u8 mode with zero and simplify.
Message-ID<tYVH3-be-3@gated-at.bofh.it>
In reply to#1679572
On 02/07/17 15:04:28 -0700, Joe Perches wrote:
> On Sun, 2017-07-02 at 22:54 +0100, Christos Gkekas wrote:
> > Variable mode in method wacom_show_remote_mode() is defined as u8, thus
> > statement (mode >= 0) is always true and should be removed, simplifying
> > the logic.
> []
> > diff --git a/drivers/hid/wacom_sys.c b/drivers/hid/wacom_sys.c
> []
> > @@ -1671,10 +1671,7 @@ static ssize_t wacom_show_remote_mode(struct kobject *kobj,
> >  	u8 mode;
> >  
> >  	mode = wacom->led.groups[index].select;
> > -	if (mode >= 0 && mode < 3)
> > -		return snprintf(buf, PAGE_SIZE, "%d\n", mode);
> > -	else
> > -		return snprintf(buf, PAGE_SIZE, "%d\n", -1);
> > +	return snprintf(buf, PAGE_SIZE, "%d\n", mode < 3 ? mode : -1);
> 
> It's also hard to imagine that PAGE_SIZE could be less than 4 bytes so
> 	return sprintf(buf, "%d\n", mode < 3 ? mode : -1);
> could work too.
>
Thanks for the suggestion, makes sense. I will resend the patch.

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web