From patchwork Mon Jan 26 19:27:28 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Reitz X-Patchwork-Id: 432995 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id C00C314007D for ; Tue, 27 Jan 2015 06:28:49 +1100 (AEDT) Received: from localhost ([::1]:43643 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YFpL5-0007py-UF for incoming@patchwork.ozlabs.org; Mon, 26 Jan 2015 14:28:47 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47308) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YFpKK-0006Yx-LW for qemu-devel@nongnu.org; Mon, 26 Jan 2015 14:28:01 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YFpKD-0001hr-QE for qemu-devel@nongnu.org; Mon, 26 Jan 2015 14:28:00 -0500 Received: from mx1.redhat.com ([209.132.183.28]:56523) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YFpKD-0001hU-HL for qemu-devel@nongnu.org; Mon, 26 Jan 2015 14:27:53 -0500 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id t0QJRpHh012770 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Mon, 26 Jan 2015 14:27:52 -0500 Received: from localhost ([10.18.17.71]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t0QJRo3n020503 (version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=NO); Mon, 26 Jan 2015 14:27:51 -0500 From: Max Reitz To: qemu-devel@nongnu.org Date: Mon, 26 Jan 2015 14:27:28 -0500 Message-Id: <1422300468-16216-2-git-send-email-mreitz@redhat.com> In-Reply-To: <1422300468-16216-1-git-send-email-mreitz@redhat.com> References: <1422300468-16216-1-git-send-email-mreitz@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Kevin Wolf , Markus Armbruster , Stefan Hajnoczi , Max Reitz Subject: [Qemu-devel] [PATCH 01/21] block: Guard remaining unsafe blk_bs() callers X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org There are cases where it is probably (!) not necessary to check whether the return value of blk_bs() is non-NULL, and those are places after blk_new_open(). In every other place, though, there has to be some check to make sure that the return value of blk_bs() is non-NULL before it is used. This patch adds that check to hopefully all of the remaining places. Signed-off-by: Max Reitz Reviewed-by: Eric Blake --- blockdev.c | 18 ++++++++++-------- hw/block/xen_disk.c | 4 +++- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/blockdev.c b/blockdev.c index 8ed2fec..9c5b6ac 100644 --- a/blockdev.c +++ b/blockdev.c @@ -121,14 +121,16 @@ void blockdev_mark_auto_del(BlockBackend *blk) return; } - aio_context = bdrv_get_aio_context(bs); - aio_context_acquire(aio_context); + if (bs) { + aio_context = bdrv_get_aio_context(bs); + aio_context_acquire(aio_context); - if (bs->job) { - block_job_cancel(bs->job); - } + if (bs->job) { + block_job_cancel(bs->job); + } - aio_context_release(aio_context); + aio_context_release(aio_context); + } dinfo->auto_del = 1; } @@ -228,8 +230,8 @@ bool drive_check_orphaned(void) dinfo->type != IF_NONE) { fprintf(stderr, "Warning: Orphaned drive without device: " "id=%s,file=%s,if=%s,bus=%d,unit=%d\n", - blk_name(blk), blk_bs(blk)->filename, if_name[dinfo->type], - dinfo->bus, dinfo->unit); + blk_name(blk), blk_bs(blk) ? blk_bs(blk)->filename : "", + if_name[dinfo->type], dinfo->bus, dinfo->unit); rs = true; } } diff --git a/hw/block/xen_disk.c b/hw/block/xen_disk.c index 1b0257c..665e706 100644 --- a/hw/block/xen_disk.c +++ b/hw/block/xen_disk.c @@ -933,9 +933,11 @@ static int blk_connect(struct XenDevice *xendev) blk_attach_dev_nofail(blkdev->blk, blkdev); blkdev->file_size = blk_getlength(blkdev->blk); if (blkdev->file_size < 0) { + BlockDriverState *bs = blk_bs(blkdev->blk); + const char *drv_name = bs ? bdrv_get_format_name(bs) : NULL; xen_be_printf(&blkdev->xendev, 1, "blk_getlength: %d (%s) | drv %s\n", (int)blkdev->file_size, strerror(-blkdev->file_size), - bdrv_get_format_name(blk_bs(blkdev->blk)) ?: "-"); + drv_name ?: "-"); blkdev->file_size = 0; }