Re: [PATCH v2 2/2] serial: core: do not touch the port after dropping the last reference
From: Johan Hovold
Date: Mon Nov 16 2026 - 02:53:18 EST
On Mon, Nov 16, 2026 at 09:49:45AM +0200, Tapio Reijonen wrote:
> On Thu, Nov 12, 2026 at 03:32:34PM +0100, Johan Hovold wrote:
> > On Thu, Nov 12, 2026 at 04:37:28AM +0000, Tapio Reijonen wrote:
> > > static inline void uart_port_deref(struct uart_port *uport)
> > > {
> > > - if (atomic_dec_and_test(&uport->state->refcount))
> > > - wake_up(&uport->state->remove_wait);
> > > + struct uart_state *state = uport->state;
> >
> > Hmm. Don't we also need a READ_ONCE() here to prevent the compiler
> > from doing something silly?
>
> Yes. Nothing writes uport->state once the port has been added, so I
> wrote it as a plain load. But the point of the patch is that the load
> must not happen after the decrement, and only READ_ONCE() rules out a
> reload there. I'll send a v3 with
>
> struct uart_state *state = READ_ONCE(uport->state);
>
> and keep your Reviewed-by unless you object.
Sounds good.
Johan