All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] HID: wacom: Remove comparison of u8 mode with zero and simplify.
@ 2017-07-02 21:54 Christos Gkekas
  2017-07-02 22:04 ` Joe Perches
  0 siblings, 1 reply; 4+ messages in thread
From: Christos Gkekas @ 2017-07-02 21:54 UTC (permalink / raw)
  To: Jiri Kosina, Benjamin Tissoires, linux-input, linux-kernel
  Cc: Christos Gkekas

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

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] HID: wacom: Remove comparison of u8 mode with zero and simplify.
  2017-07-02 21:54 [PATCH] HID: wacom: Remove comparison of u8 mode with zero and simplify Christos Gkekas
@ 2017-07-02 22:04 ` Joe Perches
  2017-07-02 22:32   ` Christos Gkekas
  0 siblings, 1 reply; 4+ messages in thread
From: Joe Perches @ 2017-07-02 22:04 UTC (permalink / raw)
  To: Christos Gkekas, Jiri Kosina, Benjamin Tissoires, linux-input,
	linux-kernel

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.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] HID: wacom: Remove comparison of u8 mode with zero and simplify.
  2017-07-02 22:04 ` Joe Perches
@ 2017-07-02 22:32   ` Christos Gkekas
  0 siblings, 0 replies; 4+ messages in thread
From: Christos Gkekas @ 2017-07-02 22:32 UTC (permalink / raw)
  To: Joe Perches; +Cc: Jiri Kosina, Benjamin Tissoires, linux-input, linux-kernel

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.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH] HID: wacom: Remove comparison of u8 mode with zero and simplify.
@ 2017-07-02 22:46 Christos Gkekas
  0 siblings, 0 replies; 4+ messages in thread
From: Christos Gkekas @ 2017-07-02 22:46 UTC (permalink / raw)
  To: Joe Perches, Jiri Kosina, Benjamin Tissoires, linux-input, linux-kernel
  Cc: Christos Gkekas

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..ae2408d 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 sprintf(buf, "%d\n", mode < 3 ? mode : -1);
 }
 
 #define DEVICE_EKR_ATTR_GROUP(SET_ID)					\
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2017-07-02 22:46 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-07-02 21:54 [PATCH] HID: wacom: Remove comparison of u8 mode with zero and simplify Christos Gkekas
2017-07-02 22:04 ` Joe Perches
2017-07-02 22:32   ` Christos Gkekas
2017-07-02 22:46 Christos Gkekas

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.