Re: [PATCH] net/mlx4_core: Use refcount_t for refcount

From: Jason Gunthorpe
Date: Tue Aug 06 2019 - 14:36:09 EST


On Sat, Aug 03, 2019 at 10:42:31AM +0800, Chuhong Yuan wrote:
> Saeed Mahameed <saeedm@xxxxxxxxxxxx> ä2019å8æ3æåå äå2:38åéï
> >
> > On Sat, 2019-08-03 at 00:10 +0800, Chuhong Yuan wrote:
> > > Chuhong Yuan <hslester96@xxxxxxxxx> ä2019å8æ2æåä äå8:10åéï
> > > > refcount_t is better for reference counters since its
> > > > implementation can prevent overflows.
> > > > So convert atomic_t ref counters to refcount_t.
> > > >
> > > > Also convert refcount from 0-based to 1-based.
> > > >
> > >
> > > It seems that directly converting refcount from 0-based
> > > to 1-based is infeasible.
> > > I am sorry for this mistake.
> >
> > Just curious, why not keep it 0 based and use refcout_t ?
> >
> > refcount API should have the same semantics as atomic_t API .. no ?
>
> refcount API will warn when increase a 0 refcount.
> It regards this as a use-after-free.

If this causes failures then the code is not doing atomic as a
refcount properly anyhow..

There are some cases where the atomic refcount is just a imprecise
debugging aide.

Jason