From mboxrd@z Thu Jan 1 00:00:00 1970 From: Tim Deegan Subject: [PATCH] RFC xen: suppress Coverity warnings about atomic_read and atomic_set. Date: Thu, 12 Sep 2013 14:47:23 +0100 Message-ID: <1378993643-13345-1-git-send-email-tim@xen.org> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: xen-devel@lists.xen.org List-Id: xen-devel@lists.xenproject.org Coverity generates false positives when read_atomic() and write_atomic() are called with pointers to objects smaller than 64 bits (because it can't see that the 64-bit access in the switych statement is dead code). I don't want to automatically suppress all ofthose, because read_atomic() and write_atomic() could still be called with mis-cast pointers, but for atomic_t accessors it's pretty clealry always safe. RFC because I'm not sure what people think about scattering coverity annotations in the code. Signed-off-by: Tim Deegan --- xen/include/asm-x86/atomic.h | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/xen/include/asm-x86/atomic.h b/xen/include/asm-x86/atomic.h index e476ab5..cfa3f66 100644 --- a/xen/include/asm-x86/atomic.h +++ b/xen/include/asm-x86/atomic.h @@ -70,7 +70,11 @@ typedef struct { int counter; } atomic_t; * Atomically reads the value of @v. */ #define _atomic_read(v) ((v).counter) -#define atomic_read(v) read_atomic(&((v)->counter)) +static inline int atomic_read(atomic_t *v) +{ + /* coverity[incompatible_cast : FALSE] */ + return read_atomic(&v->counter); +} /** * atomic_set - set atomic variable @@ -80,7 +84,11 @@ typedef struct { int counter; } atomic_t; * Atomically sets the value of @v to @i. */ #define _atomic_set(v,i) (((v).counter) = (i)) -#define atomic_set(v,i) write_atomic(&((v)->counter), (i)) +static inline void atomic_set(atomic_t *v, int i) +{ + /* coverity[incompatible_cast : FALSE] */ + write_atomic(&v->counter, i); +} /** * atomic_add - add integer to atomic variable -- 1.7.10.4