yeahuh / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone
Blob Blame History Raw
From 9a9800bbe9e2a38adaccc98314fff2354a52037e Mon Sep 17 00:00:00 2001
From: Jeffrey Cody <jcody@redhat.com>
Date: Tue, 16 Sep 2014 20:11:50 +0200
Subject: [PATCH 12/20] block: allow bdrv_unref() to be passed NULL pointers

Message-id: <aadda07926a2fbf063041cd73b68b8846ff677ed.1410897407.git.jcody@redhat.com>
Patchwork-id: 61216
O-Subject: [PATCH qemu-kvm-rhel RHEL7.1 11/15] block: allow bdrv_unref() to be passed NULL pointers
Bugzilla: 1098086
RH-Acked-by: Fam Zheng <famz@redhat.com>
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
RH-Acked-by: Max Reitz <mreitz@redhat.com>

If bdrv_unref() is passed a NULL BDS pointer, it is safe to
exit with no operation.  This will allow cleanup code to blindly
call bdrv_unref() on a BDS that has been initialized to NULL.

Reviewed-by: Max Reitz <mreitz@redhat.com>
Signed-off-by: Jeff Cody <jcody@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
(cherry picked from commit 9a4d5ca60772e09d0cbac01f1b4778aa68e00eaa)

Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
---
 block.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/block.c b/block.c
index a2e95f6..af162fe 100644
--- a/block.c
+++ b/block.c
@@ -5083,6 +5083,9 @@ void bdrv_ref(BlockDriverState *bs)
  * deleted. */
 void bdrv_unref(BlockDriverState *bs)
 {
+    if (!bs) {
+        return;
+    }
     assert(bs->refcnt > 0);
     if (--bs->refcnt == 0) {
         bdrv_delete(bs);
-- 
1.7.1