Re: [PATCH v4 2/2] tty: serial: dz: convert atomic_* to refcount_* APIs for irq_guard
From: Greg Kroah-Hartman
Date: Wed Jan 04 2023 - 03:29:27 EST
On Tue, Jan 03, 2023 at 03:39:17PM +0530, Deepak R Varma wrote:
> On Tue, Jan 03, 2023 at 10:00:48AM +0100, Jiri Slaby wrote:
> > On 26. 12. 22, 7:21, Deepak R Varma wrote:
> > > The refcount_* APIs are designed to address known issues with the
> > > atomic_t APIs for reference counting. They provide following distinct
> > > advantages:
> > > - protect the reference counters from overflow/underflow
> > > - avoid use-after-free errors
> > > - provide improved memory ordering guarantee schemes
> > > - neater and safer.
> > > Hence, replace the atomic_* APIs by their equivalent refcount_t
> > > API functions.
> > >
> > > This patch proposal address the following warnings generated by
> > > the atomic_as_refcounter.cocci coccinelle script
> > > atomic_add_return(-1, ...)
> > ...
> > > --- a/drivers/tty/serial/dz.c
> > > +++ b/drivers/tty/serial/dz.c
> > ...
> > > @@ -400,18 +399,16 @@ static int dz_startup(struct uart_port *uport)
> > > struct dz_port *dport = to_dport(uport);
> > > struct dz_mux *mux = dport->mux;
> > > unsigned long flags;
> > > - int irq_guard;
> > > int ret;
> > > u16 tmp;
> > >
> > > - irq_guard = atomic_add_return(1, &mux->irq_guard);
> > > - if (irq_guard != 1)
> > > + refcount_inc(&mux->irq_guard);
> > > + if (refcount_read(&mux->irq_guard) != 1)
> > > return 0;
> > >
> > > - ret = request_irq(dport->port.irq, dz_interrupt,
> > > - IRQF_SHARED, "dz", mux);
> > > + ret = request_irq(dport->port.irq, dz_interrupt, IRQF_SHARED, "dz", mux);
> >
> > How is this related to the above described change?
>
> No, it is not. My apologies. I must have joined the lines for improved readability
> and forgot to revert. I will restore this in next revision based on the feedback
> on the other patch of this series. OR I can include this change in the current
> change log as a "while at it..." statement. Would you advise me?
NEVER have a "while at it..." change as part of a commit unless it is
relevant to the main change being made. You know better...
thanks,
greg k-h