From patchwork Thu Feb 28 17:34:36 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony PERARD X-Patchwork-Id: 1049636 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=citrix.com Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 449KTh2dBSz9s4V for ; Fri, 1 Mar 2019 04:36:08 +1100 (AEDT) Received: from localhost ([127.0.0.1]:43694 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gzPbK-0006Ay-4C for incoming@patchwork.ozlabs.org; Thu, 28 Feb 2019 12:36:06 -0500 Received: from eggs.gnu.org ([209.51.188.92]:36172) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gzPaV-000682-4l for qemu-devel@nongnu.org; Thu, 28 Feb 2019 12:35:17 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gzPaU-0003dN-BQ for qemu-devel@nongnu.org; Thu, 28 Feb 2019 12:35:15 -0500 Received: from smtp03.citrix.com ([162.221.156.55]:52020) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gzPaU-0003KN-1V for qemu-devel@nongnu.org; Thu, 28 Feb 2019 12:35:14 -0500 X-IronPort-AV: E=Sophos;i="5.58,423,1544486400"; d="scan'208";a="79361353" From: Anthony PERARD To: Date: Thu, 28 Feb 2019 17:34:36 +0000 Message-ID: <20190228173439.8013-2-anthony.perard@citrix.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190228173439.8013-1-anthony.perard@citrix.com> References: <20190228173439.8013-1-anthony.perard@citrix.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 162.221.156.55 Subject: [Qemu-devel] [PULL 1/4] dataplane/xen-block: remove dead code 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: xen-devel@lists.xenproject.org, Peter Maydell Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Paul Durrant The if() statement is clearly bogus (dead code which should have been cleaned up when grant mapping was removed). Spotted by Coverity: CID 1398635 While in the neighbourhood, add a missing 'fall through' annotation. Reported-by: Peter Maydell Signed-off-by: Paul Durrant Acked-by: Anthony PERARD Message-Id: <20190215162533.19475-2-paul.durrant@citrix.com> Signed-off-by: Anthony PERARD --- hw/block/dataplane/xen-block.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/hw/block/dataplane/xen-block.c b/hw/block/dataplane/xen-block.c index c6a15da024..f1523c5b45 100644 --- a/hw/block/dataplane/xen-block.c +++ b/hw/block/dataplane/xen-block.c @@ -281,10 +281,6 @@ static void xen_block_complete_aio(void *opaque, int ret) break; case BLKIF_OP_WRITE: case BLKIF_OP_FLUSH_DISKCACHE: - if (!request->req.nr_segments) { - break; - } - break; default: break; } @@ -298,6 +294,7 @@ static void xen_block_complete_aio(void *opaque, int ret) if (!request->req.nr_segments) { break; } + /* fall through */ case BLKIF_OP_READ: if (request->status == BLKIF_RSP_OKAY) { block_acct_done(blk_get_stats(dataplane->blk), &request->acct); From patchwork Thu Feb 28 17:34:37 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony PERARD X-Patchwork-Id: 1049639 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=citrix.com Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 449KWr3MdYz9s4V for ; Fri, 1 Mar 2019 04:38:00 +1100 (AEDT) Received: from localhost ([127.0.0.1]:43717 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gzPd8-0007Vz-9P for incoming@patchwork.ozlabs.org; Thu, 28 Feb 2019 12:37:58 -0500 Received: from eggs.gnu.org ([209.51.188.92]:36183) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gzPaV-000683-IH for qemu-devel@nongnu.org; Thu, 28 Feb 2019 12:35:17 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gzPaU-0003dt-RX for qemu-devel@nongnu.org; Thu, 28 Feb 2019 12:35:15 -0500 Received: from smtp03.citrix.com ([162.221.156.55]:52020) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gzPaU-0003KN-I6 for qemu-devel@nongnu.org; Thu, 28 Feb 2019 12:35:14 -0500 X-IronPort-AV: E=Sophos;i="5.58,423,1544486400"; d="scan'208";a="79361355" From: Anthony PERARD To: Date: Thu, 28 Feb 2019 17:34:37 +0000 Message-ID: <20190228173439.8013-3-anthony.perard@citrix.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190228173439.8013-1-anthony.perard@citrix.com> References: <20190228173439.8013-1-anthony.perard@citrix.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 162.221.156.55 Subject: [Qemu-devel] [PULL 2/4] xen-block: remove redundant assignment 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: xen-devel@lists.xenproject.org, Peter Maydell Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Paul Durrant The assignment to 'p' is unnecessary as the code will either goto 'invalid' or p will get overwritten. Spotted by Coverity: CID 1398638 Reported-by: Peter Maydell Signed-off-by: Paul Durrant Acked-by: Anthony PERARD Message-Id: <20190215162533.19475-3-paul.durrant@citrix.com> Signed-off-by: Anthony PERARD --- hw/block/xen-block.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/hw/block/xen-block.c b/hw/block/xen-block.c index 5012af9cb6..29afe2703a 100644 --- a/hw/block/xen-block.c +++ b/hw/block/xen-block.c @@ -413,8 +413,7 @@ static void xen_block_set_vdev(Object *obj, Visitor *v, const char *name, } if (*end == 'p') { - p = (char *) ++end; - if (*end == '\0') { + if (*(++end) == '\0') { goto invalid; } } From patchwork Thu Feb 28 17:34:38 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony PERARD X-Patchwork-Id: 1049638 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=citrix.com Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 449KVz4mKtz9s4V for ; Fri, 1 Mar 2019 04:37:15 +1100 (AEDT) Received: from localhost ([127.0.0.1]:43713 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gzPcP-0006x0-F4 for incoming@patchwork.ozlabs.org; Thu, 28 Feb 2019 12:37:13 -0500 Received: from eggs.gnu.org ([209.51.188.92]:36187) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gzPaV-000684-ML for qemu-devel@nongnu.org; Thu, 28 Feb 2019 12:35:17 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gzPaU-0003e6-SH for qemu-devel@nongnu.org; Thu, 28 Feb 2019 12:35:15 -0500 Received: from smtp03.citrix.com ([162.221.156.55]:52030) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gzPaU-0003Mt-Im for qemu-devel@nongnu.org; Thu, 28 Feb 2019 12:35:14 -0500 X-IronPort-AV: E=Sophos;i="5.58,423,1544486400"; d="scan'208";a="79361363" From: Anthony PERARD To: Date: Thu, 28 Feb 2019 17:34:38 +0000 Message-ID: <20190228173439.8013-4-anthony.perard@citrix.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190228173439.8013-1-anthony.perard@citrix.com> References: <20190228173439.8013-1-anthony.perard@citrix.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 162.221.156.55 Subject: [Qemu-devel] [PULL 3/4] xen-block: report error condition from vbd_name_to_disk() 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: xen-devel@lists.xenproject.org, Peter Maydell Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Paul Durrant The function needs to make sure it is passed a valid disk name. This is easily done by making sure that the parsing loop results in a non-zero value. Spotted by Coverity: CID 1398640 Reported-by: Peter Maydell Signed-off-by: Paul Durrant Acked-by: Anthony PERARD Message-Id: <20190215162533.19475-4-paul.durrant@citrix.com> Signed-off-by: Anthony PERARD --- hw/block/xen-block.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/hw/block/xen-block.c b/hw/block/xen-block.c index 29afe2703a..37a456c207 100644 --- a/hw/block/xen-block.c +++ b/hw/block/xen-block.c @@ -351,21 +351,28 @@ static void xen_block_get_vdev(Object *obj, Visitor *v, const char *name, g_free(str); } -static unsigned int vbd_name_to_disk(const char *name, const char **endp) +static int vbd_name_to_disk(const char *name, const char **endp, + unsigned long *disk) { - unsigned int disk = 0; + unsigned int n = 0; while (*name != '\0') { if (!g_ascii_isalpha(*name) || !g_ascii_islower(*name)) { break; } - disk *= 26; - disk += *name++ - 'a' + 1; + n *= 26; + n += *name++ - 'a' + 1; } *endp = name; - return disk - 1; + if (!n) { + return -1; + } + + *disk = n - 1; + + return 0; } static void xen_block_set_vdev(Object *obj, Visitor *v, const char *name, @@ -418,7 +425,9 @@ static void xen_block_set_vdev(Object *obj, Visitor *v, const char *name, } } } else { - vdev->disk = vbd_name_to_disk(p, &end); + if (vbd_name_to_disk(p, &end, &vdev->disk)) { + goto invalid; + } } if (*end != '\0') { From patchwork Thu Feb 28 17:34:39 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony PERARD X-Patchwork-Id: 1049641 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=citrix.com Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 449Kb83Kgjz9s9L for ; Fri, 1 Mar 2019 04:40:52 +1100 (AEDT) Received: from localhost ([127.0.0.1]:43775 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gzPfu-0001Fp-CQ for incoming@patchwork.ozlabs.org; Thu, 28 Feb 2019 12:40:50 -0500 Received: from eggs.gnu.org ([209.51.188.92]:36401) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gzPbT-0006nn-Rp for qemu-devel@nongnu.org; Thu, 28 Feb 2019 12:36:16 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gzPbR-0003xo-Ft for qemu-devel@nongnu.org; Thu, 28 Feb 2019 12:36:15 -0500 Received: from smtp03.citrix.com ([162.221.156.55]:52091) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gzPbP-0003qn-2m for qemu-devel@nongnu.org; Thu, 28 Feb 2019 12:36:13 -0500 X-IronPort-AV: E=Sophos;i="5.58,423,1544486400"; d="scan'208";a="79361418" From: Anthony PERARD To: Date: Thu, 28 Feb 2019 17:34:39 +0000 Message-ID: <20190228173439.8013-5-anthony.perard@citrix.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190228173439.8013-1-anthony.perard@citrix.com> References: <20190228173439.8013-1-anthony.perard@citrix.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 162.221.156.55 Subject: [Qemu-devel] [PULL 4/4] xen-block: stop leaking memory in xen_block_drive_create() 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: xen-devel@lists.xenproject.org, Peter Maydell Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Paul Durrant The locally allocated QDict-s need to be freed. ('file_layer' will be freed implicitly since it is added as an object to 'driver_layer'). Spotted by Coverity: CID 1398649 While in the neighbourhood free 'driver' and 'filename' as soon as they are added to the QDicts. Freeing after the 'done' label doesn't make that much sense as, if the error path jumps to that label, the values would be NULL anyway. This patch also makes that more obvious by taking the error path if 'params' is NULL and then asserting that both driver and filename are non-NULL in the normal path. Reported-by: Peter Maydell Signed-off-by: Paul Durrant Message-Id: <20190219163440.15702-1-paul.durrant@citrix.com> Acked-by: Anthony PERARD Signed-off-by: Anthony PERARD --- hw/block/xen-block.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/hw/block/xen-block.c b/hw/block/xen-block.c index 37a456c207..70fc2455e8 100644 --- a/hw/block/xen-block.c +++ b/hw/block/xen-block.c @@ -743,12 +743,12 @@ static XenBlockDrive *xen_block_drive_create(const char *id, } g_strfreev(v); - } - - if (!filename) { - error_setg(errp, "no filename"); + } else { + error_setg(errp, "no params"); goto done; } + + assert(filename); assert(driver); drive = g_new0(XenBlockDrive, 1); @@ -758,6 +758,7 @@ static XenBlockDrive *xen_block_drive_create(const char *id, qdict_put_str(file_layer, "driver", "file"); qdict_put_str(file_layer, "filename", filename); + g_free(filename); if (mode && *mode != 'w') { qdict_put_bool(file_layer, "read-only", true); @@ -793,16 +794,17 @@ static XenBlockDrive *xen_block_drive_create(const char *id, driver_layer = qdict_new(); qdict_put_str(driver_layer, "driver", driver); + g_free(driver); + qdict_put_obj(driver_layer, "file", QOBJECT(file_layer)); g_assert(!drive->node_name); drive->node_name = xen_block_blockdev_add(drive->id, driver_layer, &local_err); -done: - g_free(driver); - g_free(filename); + qobject_unref(driver_layer); +done: if (local_err) { error_propagate(errp, local_err); xen_block_drive_destroy(drive, NULL);