diff mbox

kvm: Fix warning from static code analysis

Message ID 1346704840-9522-1-git-send-email-sw@weilnetz.de (mailing list archive)
State New, archived
Headers show

Commit Message

Stefan Weil Sept. 3, 2012, 8:40 p.m. UTC
Report from smatch:

kvm-all.c:1373 kvm_init(135) warn:
 variable dereferenced before check 's' (see line 1360)

's' cannot by NULL (it was alloced using g_malloc0), so there is no need
to check it here.

Signed-off-by: Stefan Weil <sw@weilnetz.de>
---
 kvm-all.c |   12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)

Comments

Peter Maydell Sept. 3, 2012, 9:10 p.m. UTC | #1
On 3 September 2012 21:40, Stefan Weil <sw@weilnetz.de> wrote:
> Report from smatch:
>
> kvm-all.c:1373 kvm_init(135) warn:
>  variable dereferenced before check 's' (see line 1360)
>
> 's' cannot by NULL (it was alloced using g_malloc0), so there is no need
> to check it here.
>
> Signed-off-by: Stefan Weil <sw@weilnetz.de>

Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

-- PMM
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Stefan Hajnoczi Sept. 5, 2012, 9:36 a.m. UTC | #2
On Mon, Sep 03, 2012 at 10:40:40PM +0200, Stefan Weil wrote:
> Report from smatch:
> 
> kvm-all.c:1373 kvm_init(135) warn:
>  variable dereferenced before check 's' (see line 1360)
> 
> 's' cannot by NULL (it was alloced using g_malloc0), so there is no need
> to check it here.
> 
> Signed-off-by: Stefan Weil <sw@weilnetz.de>
> ---
>  kvm-all.c |   12 +++++-------
>  1 file changed, 5 insertions(+), 7 deletions(-)

Thanks, applied to the trivial patches tree:
https://github.com/stefanha/qemu/commits/trivial-patches

Stefan
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/kvm-all.c b/kvm-all.c
index 34b02c1..20b980d 100644
--- a/kvm-all.c
+++ b/kvm-all.c
@@ -1370,13 +1370,11 @@  int kvm_init(void)
     return 0;
 
 err:
-    if (s) {
-        if (s->vmfd >= 0) {
-            close(s->vmfd);
-        }
-        if (s->fd != -1) {
-            close(s->fd);
-        }
+    if (s->vmfd >= 0) {
+        close(s->vmfd);
+    }
+    if (s->fd != -1) {
+        close(s->fd);
     }
     g_free(s);