Skip to contentSkip to conversation

atm: Cleanup redundant tests on unsigned

PATCH Applied Roel Kluin 3 participants 4 messages Oct 23, 2009 – Oct 29, 2009

Subsystems (3)
lore
Share & tools
lore

Roel Kluin

author
#0 lore raw

PATCH 1/1 atm: Cleanup redundant tests on unsigned

The variables are unsigned so the `< 0' test always fails, the other part of the test catches wrapped values.

---
 drivers/atm/fore200e.c |    4 ++--
 drivers/atm/he.c       |    2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)
drivers/atm/fore200e.c +2 -2
index f766cc4..bc53fed 100644
@@ -2906,8 +2906,8 @@ fore200e_proc_read(struct atm_dev *dev, loff_t* pos, char* page)
 	u32 media_index    = FORE200E_MEDIA_INDEX(fore200e->bus->read(&fore200e->cp_queues->media_type));
 	u32 oc3_index;
 
-	if ((media_index < 0) || (media_index > 4))
-	    media_index = 5;
+	if (media_index > 4)
+		media_index = 5;
 	
 	switch (fore200e->loop_mode) {
 	    case ATM_LM_NONE:    oc3_index = 0;
drivers/atm/he.c +1 -1
index 7066703..e906658 100644
@@ -2739,7 +2739,7 @@ he_ioctl(struct atm_dev *atm_dev, unsigned int cmd, void __user *arg)
 			spin_lock_irqsave(&he_dev->global_lock, flags);
 			switch (reg.type) {
 				case HE_REGTYPE_PCI:
-					if (reg.addr < 0 || reg.addr >= HE_REGMAP_SIZE) {
+					if (reg.addr >= HE_REGMAP_SIZE) {
 						err = -EINVAL;
 						break;
 					}
#1 lore raw
Quoted 5 lines · Roel Kluin

The variables are unsigned so the `< 0' test always fails, the other part of the test catches wrapped values.

---

I believe such patches were posted in the past.

General consensus is that compiler is able to do this optimization for us, and reader doesnt have to ask to himself : "Is the test safe enough ?"

maintainer
#2 lore raw

From: Eric Dumazet <[email protected]>
Date: Fri, 23 Oct 2009 18:08:30 +0200

Quoted 11 lines
Quoted 5 lines · Roel Kluin

The variables are unsigned so the `< 0' test always fails, the other part of the test catches wrapped values.

---

I believe such patches were posted in the past.

General consensus is that compiler is able to do this optimization for us, and reader doesnt have to ask to himself : "Is the test safe enough ?"

Conversely, the reader can say "Wow this can be negative? There's tests missing elsewhere! ... oh, nevermind it's unsigned"

That really wastes people's time too.

I suspect I'll apply these patches. :-)