2006-12-05 23:33:00

by Lu, Yinghai

[permalink] [raw]
Subject: RE: [LinuxBIOS] [linux-usb-devel] [RFC][PATCH 0/2] x86_64 Early usb debug port support.



-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of
[email protected]
Sent: Tuesday, December 05, 2006 3:01 AM

>+static int ehci_wait_for_port(int port)
>+{
>+ unsigned status;
>+ int ret, reps;
>+ for (reps = 0; reps >= 0; reps++) {
>+ status = readl(&ehci_regs->status);
>+ if (status & STS_PCD) {
>+ ret = ehci_reset_port(port);
>+ if (ret == 0)
>+ return 0;
>+ }
>+ }
>+ return -ENOTCONN;
>+}
>+

What do you mean by
+ for (reps = 0; reps >= 0; reps++) {
?

YH




2006-12-05 23:50:43

by Eric W. Biederman

[permalink] [raw]
Subject: Re: [LinuxBIOS] [linux-usb-devel] [RFC][PATCH 0/2] x86_64 Early usb debug port support.

"Lu, Yinghai" <[email protected]> writes:

> -----Original Message-----
> From: [email protected]
> [mailto:[email protected]] On Behalf Of
> [email protected]
> Sent: Tuesday, December 05, 2006 3:01 AM
>
>>+static int ehci_wait_for_port(int port)
>>+{
>>+ unsigned status;
>>+ int ret, reps;
>>+ for (reps = 0; reps >= 0; reps++) {
>>+ status = readl(&ehci_regs->status);
>>+ if (status & STS_PCD) {
>>+ ret = ehci_reset_port(port);
>>+ if (ret == 0)
>>+ return 0;
>>+ }
>>+ }
>>+ return -ENOTCONN;
>>+}
>>+
>
> What do you mean by
> + for (reps = 0; reps >= 0; reps++) {
> ?

If you will not reps is negative. Roughly it is a loop
that will timeout eventually if a usb debug cable is not present.
Putting some deliberate delays in there so I could be certain
of timing out after a second or two would probably be better, but
I don't have anything that resembles a good timer at that point.

The problem is you have to wait until the ehci notices your usb
debug cable before you reset it and get it going and that can be a
non-trivial amount of time. So the loop is 100% necessary.

So since I didn't know how many loop iterations made sense I allowed
it to loop for 2^31 times or until reps goes negative.

Eric

2006-12-06 15:31:44

by Segher Boessenkool

[permalink] [raw]
Subject: Re: [LinuxBIOS] [linux-usb-devel] [RFC][PATCH 0/2] x86_64 Early usb debug port support.

>> What do you mean by
>> + for (reps = 0; reps >= 0; reps++) {
>> ?
>
> If you will not reps is negative. Roughly it is a loop
> that will timeout eventually if a usb debug cable is not present.

> So since I didn't know how many loop iterations made sense I allowed
> it to loop for 2^31 times or until reps goes negative.

This doesn't work however. Signed overflow in C is undefined,
and GCC actually optimises accordingly (unless -fwrapv is used).


Segher