All of lore.kernel.org
 help / color / mirror / Atom feed
From: Tim Deegan <tim@xen.org>
To: xen-devel@lists.xen.org
Subject: [PATCH] RFC xen: suppress Coverity warnings about atomic_read and atomic_set.
Date: Thu, 12 Sep 2013 14:47:23 +0100	[thread overview]
Message-ID: <1378993643-13345-1-git-send-email-tim@xen.org> (raw)

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

             reply	other threads:[~2013-09-12 13:47 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-09-12 13:47 Tim Deegan [this message]
2013-09-12 14:06 ` [PATCH] RFC xen: suppress Coverity warnings about atomic_read and atomic_set 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1378993643-13345-1-git-send-email-tim@xen.org \
    --to=tim@xen.org \
    --cc=xen-devel@lists.xen.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.