# Re: \[PATCH RESEND\] tracing: Fix overflow in get\_free\_elt()

- From: Steven Rostedt \<rostedt@goodmis.org\>
- Date: 2024-08-07 13:28:47 
- List: linux-trace-kernel
- Page: https://ratatoskr.run/linux-trace-kernel/2024/08/2699410
- Thread: https://ratatoskr.run/linux-trace-kernel/2024/08/2695881/t.md

```text
On Wed, 7 Aug 2024 11:34:43 +0000
Tze-nan Wu (吳澤南) [ref] 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
```
