Re: [PATCH RESEND] tracing: Fix overflow in get_free_elt()

From: Steven Rostedt
Date: Wed Aug 07 2024 - 09:28:56 EST


On Wed, 7 Aug 2024 11:34:43 +0000
Tze-nan Wu (吳澤南) <Tze-nan.Wu@xxxxxxxxxxxx> wrote:

> > > -idx = atomic_inc_return(&map->next_elt);
> > > +idx = atomic_fetch_add_unless(&map->next_elt, 1, map->max_elts);
> >
> > I guess we need to add (with a comment):
> >
> > idx--;
> >
> Thanks for reviewing this!
>
> By reference to "/include/linux/atomic/atomic-instrumented.h",
> `atomic_fetch_add_unless` will return the original value before the
> adding happens on operands.

Ah, right. I haven't used that before and was thinking this was the same as
the inc_return().

-- Steve