From patchwork Sat Jun 10 07:04:10 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhengui li X-Patchwork-Id: 9779795 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id C5D4F6034B for ; Sat, 10 Jun 2017 12:22:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B5A652870E for ; Sat, 10 Jun 2017 12:22:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A86C328723; Sat, 10 Jun 2017 12:22:19 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 6AF9A2870E for ; Sat, 10 Jun 2017 12:22:17 +0000 (UTC) Received: from localhost ([::1]:58369 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dJfPE-0003zK-Ik for patchwork-qemu-devel@patchwork.kernel.org; Sat, 10 Jun 2017 08:22:16 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37360) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dJcHY-0004MN-QE for qemu-devel@nongnu.org; Sat, 10 Jun 2017 05:02:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dJcHY-0007yJ-6R for qemu-devel@nongnu.org; Sat, 10 Jun 2017 05:02:08 -0400 Received: from szxga02-in.huawei.com ([45.249.212.188]:3944) by eggs.gnu.org with esmtps (TLS1.0:RSA_ARCFOUR_SHA1:16) (Exim 4.71) (envelope-from ) id 1dJcHS-0007u4-7y; Sat, 10 Jun 2017 05:02:02 -0400 Received: from 172.30.72.56 (EHLO DGGEML404-HUB.china.huawei.com) ([172.30.72.56]) by dggrg02-dlp.huawei.com (MOS 4.4.6-GA FastPath queued) with ESMTP id APB53740; Sat, 10 Jun 2017 17:01:52 +0800 (CST) Received: from localhost.localdomain (10.175.104.153) by DGGEML404-HUB.china.huawei.com (10.3.17.39) with Microsoft SMTP Server id 14.3.301.0; Sat, 10 Jun 2017 17:01:43 +0800 From: Zhengui Li To: , , Date: Sat, 10 Jun 2017 15:04:10 +0800 Message-ID: <1497078250-19505-1-git-send-email-lizhengui@huawei.com> X-Mailer: git-send-email 1.8.3.1 MIME-Version: 1.0 X-Originating-IP: [10.175.104.153] X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A0B0205.593BB581.00DB, ss=1, re=0.000, recu=0.000, reip=0.000, cl=1, cld=1, fgs=0, ip=0.0.0.0, so=2014-11-16 11:51:01, dmn=2013-03-21 17:37:32 X-Mirapoint-Loop-Id: 36c4024bb0e796a9f1612b31d4a3bc2c X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] [fuzzy] X-Received-From: 45.249.212.188 X-Mailman-Approved-At: Sat, 10 Jun 2017 08:21:40 -0400 Subject: [Qemu-devel] [PATCH] bdrv_inc_in_flight and bdrv_dec_in_flight: X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: lizhengui@huawei.com, qemu-devel@nongnu.org, qemu-block@nongnu.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Avoid empty pointer access if the bs is NULL. Signed-off-by: Zhengui Li --- block/io.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/block/io.c b/block/io.c index ed31810..b12d7cf 100644 --- a/block/io.c +++ b/block/io.c @@ -492,7 +492,9 @@ static bool tracked_request_overlaps(BdrvTrackedRequest *req, void bdrv_inc_in_flight(BlockDriverState *bs) { - atomic_inc(&bs->in_flight); + if (bs) { + atomic_inc(&bs->in_flight); + } } static void dummy_bh_cb(void *opaque) @@ -508,8 +510,10 @@ void bdrv_wakeup(BlockDriverState *bs) void bdrv_dec_in_flight(BlockDriverState *bs) { - atomic_dec(&bs->in_flight); - bdrv_wakeup(bs); + if (bs) { + atomic_dec(&bs->in_flight); + bdrv_wakeup(bs); + } } static bool coroutine_fn wait_serialising_requests(BdrvTrackedRequest *self)