Skip to contentSkip to conversation

Input: edt-ft5x06 - use U16_MAX instead of -1

PATCH In review Andy Shevchenko 2 participants 3 messages Oct 26, 2020 – Dec 9, 2020

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 Input: edt-ft5x06 - use U16_MAX instead of -1

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.

---
v2: rebased on top of v5.10-rc1

 drivers/input/touchscreen/edt-ft5x06.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/input/touchscreen/edt-ft5x06.c +3 -2
index 6ff81d48da86..34e9cb9c0691 100644
@@ -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;
 	}
 }
 
Signature · 1 line
2.28.0
#1 lore raw
Quoted 4 lines · 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.

Any comments on this?

Signature · 2 lines
With Best Regards,
Andy Shevchenko
maintainer
#2 lore raw
In reply to Andy Shevchenko

Hi Andy,

Quoted 24 lines · 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.

---
v2: rebased on top of v5.10-rc1

 drivers/input/touchscreen/edt-ft5x06.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/input/touchscreen/edt-ft5x06.c +1 -0
index 6ff81d48da86..34e9cb9c0691 100644
@@ -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>

drivers/input/touchscreen/edt-ft5x06.c edt_ft5x06_ts_get_parameters(struct edt_ft5x06_ts_data *tsdata) · line 1010

Quoted 7 lines
drivers/input/touchscreen/edt-ft5x06.c +2 -2
@@ -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.

Signature · 1 line
Dmitry