Re: [GIT PULL] HID regression fix

From: Linus Torvalds
Date: Tue Jun 06 2023 - 08:20:20 EST


On Mon, Jun 5, 2023 at 2:39 PM Jiri Kosina <jikos@xxxxxxxxxx> wrote:
>
> - Final, confirmed fix for regression causing some devices connected via
> Logitech HID++ Unifying receiver take too long to initialize (Benjamin
> Tissoires)

Thanks.

The 'don't use goto' looks good, but can we simplify things further?

In particular, this kind of loop is why "do { } while ()" exists.

But also, testing "ret" in that end condition is all kinds of strange.
It smells of Pascal loops, because Pascal didn't have any sane control
flow (little known fact: in a rare show of self-reflection, "Pascal"
was named to sound like the Finnish word "paska", meaning "shit").

The *sane* thing to do is not to test "ret" in the loop condition, but
just add the obvious control flow - so the code that wants to retry
should just do 'continue' in that loop.

Then the loop itself ends up being just

do {
...
} while (--max_retries);

and we don't need any fake initialization of 'ret'.

Anyway, just a thought.

It would also simplify things a lot if that function was split up so
that you'd have that whole loop in a helper function. That way it
could just use "return ret" or whatever, with the mutex_lock/unlock in
the caller.

Btw, it does look like the code is mixing two different kinds of
return types in 'ret': regular Linux error numbers as negative
numbers, but then possibly positive "HIDPP status" values that it gets
from the report (ie

ret = response->rap.params[1];

ends up being returned as a value, mixed with

ret = -ETIMEDOUT;

so which is it? A negative error, or a positive HID report byte value? Or both?

Linus