qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH 0/2] dataplane: fix bogus coverity warnings
@ 2014-03-14 15:14 Stefan Hajnoczi
  2014-03-14 15:14 ` [Qemu-devel] [PATCH 1/2] iothread: fix bogus coverity warning Stefan Hajnoczi
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Stefan Hajnoczi @ 2014-03-14 15:14 UTC (permalink / raw)
  To: qemu-devel
  Cc: Kevin Wolf, Markus Armbruster, Stefan Hajnoczi,
	Dr. David Alan Gilbert

Coverity detects when variable are accessed under a mutex most of the time.  It
warns when they are not accessed under the mutex.  I initialized variables
before the mutex and threads that access them even exist - Coverity doesn't
like that.  Fix the code.

Stefan Hajnoczi (2):
  iothread: fix bogus coverity warning
  rfifolock: fix bogus coverity warning

 iothread.c       | 5 ++++-
 util/rfifolock.c | 4 +++-
 2 files changed, 7 insertions(+), 2 deletions(-)

-- 
1.8.5.3

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

* [Qemu-devel] [PATCH 1/2] iothread: fix bogus coverity warning
  2014-03-14 15:14 [Qemu-devel] [PATCH 0/2] dataplane: fix bogus coverity warnings Stefan Hajnoczi
@ 2014-03-14 15:14 ` Stefan Hajnoczi
  2014-03-14 15:14 ` [Qemu-devel] [PATCH 2/2] rfifolock: " Stefan Hajnoczi
  2014-03-14 17:25 ` [Qemu-devel] [PATCH 0/2] dataplane: fix bogus coverity warnings Paolo Bonzini
  2 siblings, 0 replies; 5+ messages in thread
From: Stefan Hajnoczi @ 2014-03-14 15:14 UTC (permalink / raw)
  To: qemu-devel
  Cc: Kevin Wolf, Markus Armbruster, Stefan Hajnoczi,
	Dr. David Alan Gilbert

Coverity warns about initializing variables that will later be accessed
under a mutex.  There is no problem with the code itself but let's avoid
accumulating Coverity warnings.

Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
---
 iothread.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/iothread.c b/iothread.c
index cb5986b..9e25af9 100644
--- a/iothread.c
+++ b/iothread.c
@@ -75,11 +75,14 @@ static void iothread_complete(UserCreatable *obj, Error **errp)
 
     iothread->stopping = false;
     iothread->ctx = aio_context_new();
-    iothread->thread_id = -1;
 
     qemu_mutex_init(&iothread->init_done_lock);
     qemu_cond_init(&iothread->init_done_cond);
 
+    qemu_mutex_lock(&iothread->init_done_lock);
+    iothread->thread_id = -1;
+    qemu_mutex_unlock(&iothread->init_done_lock);
+
     /* This assumes we are called from a thread with useful CPU affinity for us
      * to inherit.
      */
-- 
1.8.5.3

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

* [Qemu-devel] [PATCH 2/2] rfifolock: fix bogus coverity warning
  2014-03-14 15:14 [Qemu-devel] [PATCH 0/2] dataplane: fix bogus coverity warnings Stefan Hajnoczi
  2014-03-14 15:14 ` [Qemu-devel] [PATCH 1/2] iothread: fix bogus coverity warning Stefan Hajnoczi
@ 2014-03-14 15:14 ` Stefan Hajnoczi
  2014-03-14 17:25 ` [Qemu-devel] [PATCH 0/2] dataplane: fix bogus coverity warnings Paolo Bonzini
  2 siblings, 0 replies; 5+ messages in thread
From: Stefan Hajnoczi @ 2014-03-14 15:14 UTC (permalink / raw)
  To: qemu-devel
  Cc: Kevin Wolf, Markus Armbruster, Stefan Hajnoczi,
	Dr. David Alan Gilbert

Coverity warns about initializing variables that will later be accessed
under a mutex.  There is no problem with the code itself but let's avoid
accumulating Coverity warnings.

Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
---
 util/rfifolock.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/util/rfifolock.c b/util/rfifolock.c
index afbf748..f42214d 100644
--- a/util/rfifolock.c
+++ b/util/rfifolock.c
@@ -17,12 +17,14 @@
 void rfifolock_init(RFifoLock *r, void (*cb)(void *), void *opaque)
 {
     qemu_mutex_init(&r->lock);
+    qemu_cond_init(&r->cond);
+    qemu_mutex_lock(&r->lock);
     r->head = 0;
     r->tail = 0;
-    qemu_cond_init(&r->cond);
     r->nesting = 0;
     r->cb = cb;
     r->cb_opaque = opaque;
+    qemu_mutex_unlock(&r->lock);
 }
 
 void rfifolock_destroy(RFifoLock *r)
-- 
1.8.5.3

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

* Re: [Qemu-devel] [PATCH 0/2] dataplane: fix bogus coverity warnings
  2014-03-14 15:14 [Qemu-devel] [PATCH 0/2] dataplane: fix bogus coverity warnings Stefan Hajnoczi
  2014-03-14 15:14 ` [Qemu-devel] [PATCH 1/2] iothread: fix bogus coverity warning Stefan Hajnoczi
  2014-03-14 15:14 ` [Qemu-devel] [PATCH 2/2] rfifolock: " Stefan Hajnoczi
@ 2014-03-14 17:25 ` Paolo Bonzini
  2014-03-17 14:56   ` Stefan Hajnoczi
  2 siblings, 1 reply; 5+ messages in thread
From: Paolo Bonzini @ 2014-03-14 17:25 UTC (permalink / raw)
  To: Stefan Hajnoczi, qemu-devel
  Cc: Kevin Wolf, Markus Armbruster, Dr. David Alan Gilbert

Il 14/03/2014 16:14, Stefan Hajnoczi ha scritto:
> Coverity detects when variable are accessed under a mutex most of the time.  It
> warns when they are not accessed under the mutex.  I initialized variables
> before the mutex and threads that access them even exist - Coverity doesn't
> like that.  Fix the code.
>
> Stefan Hajnoczi (2):
>   iothread: fix bogus coverity warning
>   rfifolock: fix bogus coverity warning
>
>  iothread.c       | 5 ++++-
>  util/rfifolock.c | 4 +++-
>  2 files changed, 7 insertions(+), 2 deletions(-)
>

Nah, I think Coverity is wrong.  It should detect initialization of the 
mutex, and treat surrounding code as single-threaded.  I silenced the 
defects in the report, like others before.

Paolo

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

* Re: [Qemu-devel] [PATCH 0/2] dataplane: fix bogus coverity warnings
  2014-03-14 17:25 ` [Qemu-devel] [PATCH 0/2] dataplane: fix bogus coverity warnings Paolo Bonzini
@ 2014-03-17 14:56   ` Stefan Hajnoczi
  0 siblings, 0 replies; 5+ messages in thread
From: Stefan Hajnoczi @ 2014-03-17 14:56 UTC (permalink / raw)
  To: Paolo Bonzini
  Cc: Kevin Wolf, qemu-devel, Dr. David Alan Gilbert, Markus Armbruster

On Fri, Mar 14, 2014 at 06:25:34PM +0100, Paolo Bonzini wrote:
> Il 14/03/2014 16:14, Stefan Hajnoczi ha scritto:
> >Coverity detects when variable are accessed under a mutex most of the time.  It
> >warns when they are not accessed under the mutex.  I initialized variables
> >before the mutex and threads that access them even exist - Coverity doesn't
> >like that.  Fix the code.
> >
> >Stefan Hajnoczi (2):
> >  iothread: fix bogus coverity warning
> >  rfifolock: fix bogus coverity warning
> >
> > iothread.c       | 5 ++++-
> > util/rfifolock.c | 4 +++-
> > 2 files changed, 7 insertions(+), 2 deletions(-)
> >
> 
> Nah, I think Coverity is wrong.  It should detect initialization of
> the mutex, and treat surrounding code as single-threaded.  I
> silenced the defects in the report, like others before.

Okay, let's drop these patches.

Stefan

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

end of thread, other threads:[~2014-03-17 14:56 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-03-14 15:14 [Qemu-devel] [PATCH 0/2] dataplane: fix bogus coverity warnings Stefan Hajnoczi
2014-03-14 15:14 ` [Qemu-devel] [PATCH 1/2] iothread: fix bogus coverity warning Stefan Hajnoczi
2014-03-14 15:14 ` [Qemu-devel] [PATCH 2/2] rfifolock: " Stefan Hajnoczi
2014-03-14 17:25 ` [Qemu-devel] [PATCH 0/2] dataplane: fix bogus coverity warnings Paolo Bonzini
2014-03-17 14:56   ` Stefan Hajnoczi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).