Re: [PATCH] USB: cdc-acm: fix racy TIOCMIWAIT implementation

From: Johan Hovold

Date: Mon Sep 07 2026 - 06:09:30 EST


On Mon, Sep 07, 2026 at 11:50:41AM +0200, Oliver Neukum wrote:
> On 07.09.26 10:47, Johan Hovold wrote:
> > On Mon, Sep 07, 2026 at 10:17:38AM +0200, Oliver Neukum wrote:
> >> On 07.09.26 08:55, Johan Hovold wrote:
> >>> The wakeup condition needs to be checked after adding the task to the
> >>> waitqueue and updating the task state to avoid missing a racing modem
> >>> status update or disconnect.
> >>
> >> I am sorry, but in this case I have to ask:
> >> Isn't TIOCMIWAIT inherently racy against the hardware?
> >
> > What do you mean?
>
> The interface does not state from or to which state it changed.
> Now you could say that it is implicitly the last time TIOCMGET
> was called, but that is
>
> 1. not clearly stated
> 2. not enforceable

Right. The original implementation (and serial core) have always stored
the counters on entry and compared to that. So that is the defacto
semantics.

> > Looking at the implementation again now, it seems further changes are
> > needed to fix the implementation, though. The completion handler should
> > not be updating old_count. That's for each TIOCMIWAIT to do.
>
> I am sorry to be obnoxious about that, but I am afraid that would
> break TIOCGICOUNT

Why do you think so? TIOCGICOUNT just returns the current counters.

Johan