lkml.org 
[lkml]   [2016]   [Nov]   [21]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [RFC][PATCH 7/7] kref: Implement using refcount_t
On Fri, Nov 18, 2016 at 12:37:18PM +0100, Peter Zijlstra wrote:
[snip]
> +
> +/*
> + * Similar to atomic_inc(), will saturate at UINT_MAX and WARN.
> + *
> + * Provides no memory ordering, it is assumed the caller already has a
> + * reference on the object, will WARN when this is not so.
> + */
> +static inline void refcount_inc(refcount_t *r)
> +{
> + unsigned int old, new, val = atomic_read(&r->refs);
> +
> + for (;;) {
> + WARN(!val, "refcount_t: increment on 0; use-after-free.\n");
> +

Do we want to put the address of @r into the WARN information? Which
could help us locate the problematic object quickly.

Regards,
Boqun

> + if (unlikely(val == UINT_MAX))
> + return;
> +
> + new = val + 1;
> + old = atomic_cmpxchg_relaxed(&r->refs, val, new);
> + if (old == val)
> + break;
> +
> + val = old;
> + }
> +
> + WARN(new == UINT_MAX, "refcount_t: saturated; leaking memory.\n");
> +}
[...]
[unhandled content-type:application/pgp-signature]
\
 
 \ /
  Last update: 2016-11-21 09:45    [W:0.162 / U:0.704 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site