All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] RFC xen: suppress Coverity warnings about atomic_read and atomic_set.
@ 2013-09-12 13:47 Tim Deegan
  2013-09-12 14:06 ` Jan Beulich
  2013-09-12 14:32 ` Matthew Daley
  0 siblings, 2 replies; 7+ messages in thread
From: Tim Deegan @ 2013-09-12 13:47 UTC (permalink / raw)
  To: xen-devel

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 <tim@xen.org>
---
 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

^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2013-09-13  7:28 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-09-12 13:47 [PATCH] RFC xen: suppress Coverity warnings about atomic_read and atomic_set Tim Deegan
2013-09-12 14:06 ` Jan Beulich
2013-09-12 14:14   ` Ian Campbell
2013-09-12 14:17     ` Andrew Cooper
2013-09-12 14:23     ` Tim Deegan
2013-09-13  7:27       ` Tim Deegan
2013-09-12 14:32 ` Matthew Daley

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.