From 96cb2ba1c909ee947c626ff31f15895a9aae7f80 Mon Sep 17 00:00:00 2001 Message-Id: <96cb2ba1c909ee947c626ff31f15895a9aae7f80.1418787305.git.jen@redhat.com> In-Reply-To: References: From: Jeffrey Cody Date: Wed, 3 Dec 2014 20:00:39 -0600 Subject: [CHANGE 02/12] block: allow bdrv_unref() to be passed NULL pointers To: rhvirt-patches@redhat.com, jen@redhat.com RH-Author: Jeffrey Cody Message-id: <0f4723184e867553426aeb7a7af4be87babab0da.1417620879.git.jcody@redhat.com> Patchwork-id: 62661 O-Subject: [PATCH qemu-kvm-rhev RHEV7.1 v2 1/7] block: allow bdrv_unref() to be passed NULL pointers Bugzilla: 1136381 RH-Acked-by: Markus Armbruster RH-Acked-by: Max Reitz RH-Acked-by: Fam Zheng RH-Acked-by: John Snow 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 Signed-off-by: Jeff Cody Signed-off-by: Kevin Wolf (cherry picked from commit 9a4d5ca60772e09d0cbac01f1b4778aa68e00eaa) Signed-off-by: Jeff E. Nelson --- block.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/block.c b/block.c index cdbdb6b..cef9bda 100644 --- a/block.c +++ b/block.c @@ -5425,6 +5425,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); -- 2.1.0