lkml.org 
[lkml]   [2009]   [Apr]   [30]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH] Detect and warn on atomic_inc/atomic_dec wrapping around

* Nikanth Karthikesan <knikanth@novell.com> wrote:

> Add a debug option to detect and warn when the 32-bit atomic_t
> wraps around during atomic_inc and atomic_dec.
>
> Signed-off-by: Nikanth Karthikesan <knikanth@suse.de>

hm, what's the motivation?

As a generic debug helper this is not appropriate i think - counts
can easily have a meaning when going negative as well. (we have no
signed-atomic primitives)

> static inline void atomic_inc(atomic_t *v)
> {
> +#if defined(CONFIG_ENABLE_WARN_ATOMIC_INC_WRAP)
> + WARN_ON(atomic_add_unless(v, 1, INT_MAX) == 0);
> +#else
> asm volatile(LOCK_PREFIX "incl %0"
> : "+m" (v->counter));
> +#endif
> }

also looks a bit ugly - this ugly #ifdef would spread into every
architecture.

If we want to restrict atomic_t value ranges like that then the
clean solution would be to add generic wrappers doing the debug
(once, in generic code), and renaming the arch primitives to
raw_atomic_inc() (etc), doing the lowlevel bits cleanly.

Do we really want this?

Ingo


\
 
 \ /
  Last update: 2009-04-30 10:27    [W:0.080 / U:0.248 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site