Skip to contentSkip to conversation

usb: gadget: precedence bug in show_requests()

PATCH Superseded Dan Carpenter 2 participants 3 messages Jan 20, 2013

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 usb: gadget: precedence bug in show_requests()

The mod operation has higher precedence than the divide but the intent was to divide first. It's supposed to count through one time for RX and a second time for TX but instead of doing "0 1 2 0 1 2" it does "0 0 1 1 2 2".

---
Static checker stuff. Untested.

drivers/usb/chipidea/debug.c +1 -1
index 3bc244d..3cd223c 100644
@@ -709,7 +709,7 @@ static ssize_t show_requests(struct device *dev, struct device_attribute *attr,
 
 			n += scnprintf(buf + n, PAGE_SIZE - n,
 					"EP=%02i: TD=%08X %s\n",
-					i % ci->hw_ep_max/2, (u32)req->dma,
+					i % (ci->hw_ep_max / 2), (u32)req->dma,
 					((i < ci->hw_ep_max/2) ? "RX" : "TX"));
 
 			for (j = 0; j < qSize; j++)
#1 lore raw

Hello.

Quoted 1 line · Dan Carpenter

The mod operation has higher precedence than the divide

They are of the same priority AFAIR, but that doesn't matter since these
operations are executed left to right.

Quoted 14 lines

but the intent
was to divide first. It's supposed to count through one time for RX and a second time for TX but instead of doing "0 1 2 0 1 2" it does "0 0 1 1 2 2".

---
Static checker stuff. Untested.

drivers/usb/chipidea/debug.c +0 -0
index 3bc244d..3cd223c 100644

drivers/usb/chipidea/debug.c static ssize_t show_requests(struct device *dev, struct device_attribute *attr, · line 715

Quoted 8 lines
drivers/usb/chipidea/debug.c +1 -1
@@ -709,7 +709,7 @@ static ssize_t show_requests(struct device *dev, struct device_attribute *attr,
 
  			n += scnprintf(buf + n, PAGE_SIZE - n,
  					"EP=%02i: TD=%08X %s\n",
-					i % ci->hw_ep_max/2, (u32)req->dma,
+					i % (ci->hw_ep_max / 2), (u32)req->dma,
  					((i < ci->hw_ep_max/2) ? "RX" : "TX"));
 
  			for (j = 0; j < qSize; j++)

WBR, Sergei

#2 lore raw
In reply to Dan Carpenter
Quoted 9 lines · Sergei Shtylyov

Hello.

Quoted 1 line · Dan Carpenter

The mod operation has higher precedence than the divide

They are of the same priority AFAIR, but that doesn't matter since
these operations are executed left to right.

Oh yeah, you're right. I feel dumb now. Let me resend with a different changelog.

regards,
dan carpenter