Skip to contentSkip to conversation

Input: atmel_mxt_ts - Remove unnecessary byte_offset check

PATCH In review Christos Gkekas 3 participants 4 messages Oct 8, 2017 – Oct 9, 2017

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

PATCH 1/1 Input: atmel_mxt_ts - Remove unnecessary byte_offset check

Variable byte_offset is unsigned so checking whether it is greater or equal to zero is redundant.

---
 drivers/input/touchscreen/atmel_mxt_ts.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/input/touchscreen/atmel_mxt_ts.c +1 -1
index 7659bc4..baafaed 100644
@@ -1356,7 +1356,7 @@ static int mxt_prepare_cfg_mem(struct mxt_data *data,
 
 			byte_offset = reg + i - cfg_start_ofs;
 
-			if (byte_offset >= 0 && byte_offset < config_mem_size) {
+			if (byte_offset < config_mem_size) {
 				*(config_mem + byte_offset) = val;
 			} else {
 				dev_err(dev, "Bad object: reg:%d, T%d, ofs=%d\n",
Signature · 1 line
2.7.4
maintainer
#1 lore raw
Quoted 4 lines · Christos Gkekas

Variable byte_offset is unsigned so checking whether it is greater or equal to zero is redundant.

Yep - looks sensible to me.

Quoted 20 lines
---
 drivers/input/touchscreen/atmel_mxt_ts.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/input/touchscreen/atmel_mxt_ts.c +1 -1
index 7659bc4..baafaed 100644
@@ -1356,7 +1356,7 @@ static int mxt_prepare_cfg_mem(struct mxt_data *data,
 
 			byte_offset = reg + i - cfg_start_ofs;
 
-			if (byte_offset >= 0 && byte_offset < config_mem_size) {
+			if (byte_offset < config_mem_size) {
 				*(config_mem + byte_offset) = val;
 			} else {
 				dev_err(dev, "Bad object: reg:%d, T%d, ofs=%d\n",
Signature · 1 line
2.7.4
maintainer
#2 lore raw
Quoted 9 lines · Nick Dyer
Quoted 4 lines · Christos Gkekas

Variable byte_offset is unsigned so checking whether it is greater or equal to zero is redundant.

Yep - looks sensible to me.

I believe this has been discussed before and Linus told us to keep the such checks as is: they neatly document the ranges of values, safe in case we ever change the type of the variables, and do not cost us anything at execution time.

Quoted 13 lines
Quoted 13 lines
---
 drivers/input/touchscreen/atmel_mxt_ts.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/input/touchscreen/atmel_mxt_ts.c +0 -0
index 7659bc4..baafaed 100644
@@ -1356,7 +1356,7 @@ static int mxt_prepare_cfg_mem(struct mxt_data *data,
 
 			byte_offset = reg + i - cfg_start_ofs;
 
Quoted 8 lines
Quoted 8 lines
drivers/input/touchscreen/atmel_mxt_ts.c +1 -1
-			if (byte_offset >= 0 && byte_offset < config_mem_size) {
+			if (byte_offset < config_mem_size) {
 				*(config_mem + byte_offset) = val;
 			} else {
 				dev_err(dev, "Bad object: reg:%d, T%d, ofs=%d\n",
Signature · 1 line
2.7.4

Thanks.

Signature · 1 line
Dmitry
#3 lore raw
Quoted 7 lines · Dmitry Torokhov
Quoted 6 lines · Nick Dyer
Quoted 4 lines · Christos Gkekas

Variable byte_offset is unsigned so checking whether it is greater or equal to zero is redundant.

Quoted 9 lines
Quoted 3 lines

Yep - looks sensible to me.

I believe this has been discussed before and Linus told us to keep the such checks as is: they neatly document the ranges of values, safe in case we ever change the type of the variables, and do not cost us anything at execution time.

Fair enough, thanks for your feedback.

I believe you are referring to this:
https://lkml.org/lkml/2006/11/28/206

Regards,
Christos

Quoted 27 lines
Quoted 14 lines
Quoted 14 lines

---
 drivers/input/touchscreen/atmel_mxt_ts.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/input/touchscreen/atmel_mxt_ts.c +0 -0
index 7659bc4..baafaed 100644
@@ -1356,7 +1356,7 @@ static int mxt_prepare_cfg_mem(struct mxt_data *data,
 
 			byte_offset = reg + i - cfg_start_ofs;
 
Quoted 8 lines
Quoted 8 lines
drivers/input/touchscreen/atmel_mxt_ts.c +1 -1
-			if (byte_offset >= 0 && byte_offset < config_mem_size) {
+			if (byte_offset < config_mem_size) {
 				*(config_mem + byte_offset) = val;
 			} else {
 				dev_err(dev, "Bad object: reg:%d, T%d, ofs=%d\n",
Signature · 1 line
2.7.4

Thanks.

Signature · 1 line
Dmitry