lkml.org 
[lkml]   [2019]   [Aug]   [2]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH 5/6] lib/refcount: Improve performance of generic REFCOUNT_FULL code
On Fri, Aug 02, 2019 at 11:09:59AM +0100, Will Deacon wrote:
> static inline void refcount_add(int i, refcount_t *r)
> {
> + int old = atomic_fetch_add_relaxed(i, &r->refs);
> +
> + WARN_ONCE(!old, "refcount_t: addition on 0; use-after-free.\n");
> + if (unlikely(old <= 0 || old + i <= 0)) {
> + refcount_set(r, REFCOUNT_SATURATED);
> + WARN_ONCE(1, "refcount_t: saturated; leaking memory.\n");
> + }
> }

That will trigger both WARNs when !old.

\
 
 \ /
  Last update: 2019-08-02 20:55    [W:0.075 / U:1.388 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site