linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] Input: edt-ft5x06 - use U16_MAX instead of -1
@ 2020-10-26 17:41 Andy Shevchenko
  2020-12-09 20:52 ` Andy Shevchenko
  2020-12-09 23:15 ` Dmitry Torokhov
  0 siblings, 2 replies; 3+ messages in thread
From: Andy Shevchenko @ 2020-10-26 17:41 UTC (permalink / raw)
  To: Dmitry Torokhov, linux-input; +Cc: Andy Shevchenko

Explicitly show what the value we supply for the touchscreen resolution
when it can't be detected. -1 is hard to compare with when unsigned short
type is in use. The change will help to avoid signed vs. unsigned error
prone comparisons.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
v2: rebased on top of v5.10-rc1
 drivers/input/touchscreen/edt-ft5x06.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/input/touchscreen/edt-ft5x06.c b/drivers/input/touchscreen/edt-ft5x06.c
index 6ff81d48da86..34e9cb9c0691 100644
--- a/drivers/input/touchscreen/edt-ft5x06.c
+++ b/drivers/input/touchscreen/edt-ft5x06.c
@@ -23,6 +23,7 @@
 #include <linux/input/touchscreen.h>
 #include <linux/irq.h>
 #include <linux/kernel.h>
+#include <linux/limits.h>
 #include <linux/module.h>
 #include <linux/ratelimit.h>
 #include <linux/regulator/consumer.h>
@@ -1005,8 +1006,8 @@ edt_ft5x06_ts_get_parameters(struct edt_ft5x06_ts_data *tsdata)
 		tsdata->num_y = edt_ft5x06_register_read(tsdata,
 							 reg_addr->reg_num_y);
 	} else {
-		tsdata->num_x = -1;
-		tsdata->num_y = -1;
+		tsdata->num_x = U16_MAX;
+		tsdata->num_y = U16_MAX;
 	}
 }
 
-- 
2.28.0


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

* Re: [PATCH v2] Input: edt-ft5x06 - use U16_MAX instead of -1
  2020-10-26 17:41 [PATCH v2] Input: edt-ft5x06 - use U16_MAX instead of -1 Andy Shevchenko
@ 2020-12-09 20:52 ` Andy Shevchenko
  2020-12-09 23:15 ` Dmitry Torokhov
  1 sibling, 0 replies; 3+ messages in thread
From: Andy Shevchenko @ 2020-12-09 20:52 UTC (permalink / raw)
  To: Dmitry Torokhov, linux-input

On Mon, Oct 26, 2020 at 07:41:26PM +0200, Andy Shevchenko wrote:
> Explicitly show what the value we supply for the touchscreen resolution
> when it can't be detected. -1 is hard to compare with when unsigned short
> type is in use. The change will help to avoid signed vs. unsigned error
> prone comparisons.

Any comments on this?


-- 
With Best Regards,
Andy Shevchenko



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

* Re: [PATCH v2] Input: edt-ft5x06 - use U16_MAX instead of -1
  2020-10-26 17:41 [PATCH v2] Input: edt-ft5x06 - use U16_MAX instead of -1 Andy Shevchenko
  2020-12-09 20:52 ` Andy Shevchenko
@ 2020-12-09 23:15 ` Dmitry Torokhov
  1 sibling, 0 replies; 3+ messages in thread
From: Dmitry Torokhov @ 2020-12-09 23:15 UTC (permalink / raw)
  To: Andy Shevchenko; +Cc: linux-input

Hi Andy,

On Mon, Oct 26, 2020 at 07:41:26PM +0200, Andy Shevchenko wrote:
> Explicitly show what the value we supply for the touchscreen resolution
> when it can't be detected. -1 is hard to compare with when unsigned short
> type is in use. The change will help to avoid signed vs. unsigned error
> prone comparisons.
> 
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> ---
> v2: rebased on top of v5.10-rc1
>  drivers/input/touchscreen/edt-ft5x06.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/input/touchscreen/edt-ft5x06.c b/drivers/input/touchscreen/edt-ft5x06.c
> index 6ff81d48da86..34e9cb9c0691 100644
> --- a/drivers/input/touchscreen/edt-ft5x06.c
> +++ b/drivers/input/touchscreen/edt-ft5x06.c
> @@ -23,6 +23,7 @@
>  #include <linux/input/touchscreen.h>
>  #include <linux/irq.h>
>  #include <linux/kernel.h>
> +#include <linux/limits.h>
>  #include <linux/module.h>
>  #include <linux/ratelimit.h>
>  #include <linux/regulator/consumer.h>
> @@ -1005,8 +1006,8 @@ edt_ft5x06_ts_get_parameters(struct edt_ft5x06_ts_data *tsdata)
>  		tsdata->num_y = edt_ft5x06_register_read(tsdata,
>  							 reg_addr->reg_num_y);
>  	} else {
> -		tsdata->num_x = -1;
> -		tsdata->num_y = -1;
> +		tsdata->num_x = U16_MAX;
> +		tsdata->num_y = U16_MAX;

Here we do not really do any comparisons, and using -1 to set to
maximum unsigned number is a common pattern...

However I just CCed you on a patch that removes special handling for
number of electrodes on select firmwares, so this patch will no longer
be relevant.

Thanks.

-- 
Dmitry

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

end of thread, other threads:[~2020-12-09 23:16 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-26 17:41 [PATCH v2] Input: edt-ft5x06 - use U16_MAX instead of -1 Andy Shevchenko
2020-12-09 20:52 ` Andy Shevchenko
2020-12-09 23:15 ` Dmitry Torokhov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).