Re: [PATCH] USB: cdc-acm: fix racy TIOCMIWAIT implementation
From: Oliver Neukum
Date: Tue Sep 08 2026 - 05:52:56 EST
On 08.09.26 09:12, Johan Hovold wrote:
On Tue, Sep 08, 2026 at 08:54:36AM +0200, Oliver Neukum wrote:
Very well. Ample reasons. Do you have a patch or do you want me to fix it?
I sent a v2 yesterday that should take care of it all:
https://lore.kernel.org/all/20260907095130.130636-1-johan@xxxxxxxxxx/
Thank you. I misinterpreted your intent. Sorry.
I am afraid that patch has a few weaknesses.
1. It mixes changes to measuring the old count and to how the sleeping works
2. If you want to change the logic at all, then we have a first check for changes
that is almost sure to fail.
It seems to me that if you are going to touch the logic there at all, the
sensible order of actions in the loop would be
A - check for signals
B - schedule
C - check for changes
That way we
i - avoid calling into the scheduler if signals are pending
ii - avoid returning -ERESTARTSYS if we have a result we can report
iii - avoid rechecking for changes after only a few dozen cycles
We have an inherent race against the hardware. The chance that we don't
have to sleep is essentially zero.
Regards
Oliver