From patchwork Mon Oct 31 16:48:20 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Juergen Gross X-Patchwork-Id: 9405997 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 E7F7F60588 for ; Mon, 31 Oct 2016 16:50:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D952D2935A for ; Mon, 31 Oct 2016 16:50:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CE6782935C; Mon, 31 Oct 2016 16:50:43 +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=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 9BEB82935A for ; Mon, 31 Oct 2016 16:50:42 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1c1FlR-0003lG-NP; Mon, 31 Oct 2016 16:48:49 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1c1FlP-0003kI-TK for xen-devel@lists.xen.org; Mon, 31 Oct 2016 16:48:48 +0000 Received: from [85.158.143.35] by server-10.bemta-6.messagelabs.com id CF/58-30618-FE577185; Mon, 31 Oct 2016 16:48:47 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrOLMWRWlGSWpSXmKPExsVyuP0Ov+67UvE Ig10bxC2WfFzM4sDocXT3b6YAxijWzLyk/IoE1oxT68+yFGwRrVj6oJ+9gfGnYBcjJ4eEgJHE 24n/mLoYuTiEBBYyStzp3cgEkmATUJXYcP0UK4gtImAl8XD/NVaQImaBLkaJrbO2sYAkhAV8J c4/O8gMYrMANXR0dIHZvAL2EjuOz2OB2CAncX3mdLChnAIOEq/XXAOrEQKqmbjsEPMERu4FjA yrGDWKU4vKUot0jUz1kooy0zNKchMzc3QNDcz0clOLixPTU3MSk4r1kvNzNzECPcwABDsYVy0 IPMQoycGkJMr7NUw8QogvKT+lMiOxOCO+qDQntfgQowwHh5IE75cSoJxgUWp6akVaZg4w1GDS Ehw8SiK8bMBwE+ItLkjMLc5Mh0idYlSUEuetB+kTAElklObBtcHC+xKjrJQwLyPQIUI8BalFu ZklqPKvGMU5GJWEeVlBxvNk5pXATX8FtJgJaHFaoQjI4pJEhJRUA+Pse46yBv2rs+vPcOjs2b FNXN/VdokU74T415lxv23zTyyp5393/bAuj+MxfyuugzNvbbb5ton7WFzA9Qu+jgVrLv9q0in 6bPSoIONirVcV1++AXfrCcqfKrizbm7NPKHLaNNsvgonPNW34ZWvTVDzF32hHy8/RYRW5qp60 J+/Jxff8P+Iu71ViKc5INNRiLipOBABmH9o6agIAAA== X-Env-Sender: jgross@suse.com X-Msg-Ref: server-5.tower-21.messagelabs.com!1477932526!32952526!1 X-Originating-IP: [195.135.220.15] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 9.0.13; banners=-,-,- X-VirusChecked: Checked Received: (qmail 38624 invoked from network); 31 Oct 2016 16:48:46 -0000 Received: from mx2.suse.de (HELO mx2.suse.de) (195.135.220.15) by server-5.tower-21.messagelabs.com with DHE-RSA-CAMELLIA256-SHA encrypted SMTP; 31 Oct 2016 16:48:46 -0000 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id BE1B9AD20; Mon, 31 Oct 2016 16:48:45 +0000 (UTC) From: Juergen Gross To: linux-kernel@vger.kernel.org, xen-devel@lists.xen.org Date: Mon, 31 Oct 2016 17:48:20 +0100 Message-Id: <1477932510-28594-3-git-send-email-jgross@suse.com> X-Mailer: git-send-email 2.6.6 In-Reply-To: <1477932510-28594-1-git-send-email-jgross@suse.com> References: <1477932510-28594-1-git-send-email-jgross@suse.com> Cc: Juergen Gross , boris.ostrovsky@oracle.com, roger.pau@citrix.com, david.vrabel@citrix.com Subject: [Xen-devel] [PATCH 02/12] xen: make use of xenbus_read_unsigned() in xen-blkback X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP Use xenbus_read_unsigned() instead of xenbus_scanf() when possible. This requires to change the type of one read from int to unsigned, but this case has been wrong before: negative values are not allowed for the modified case. Cc: konrad.wilk@oracle.com Cc: roger.pau@citrix.com Signed-off-by: Juergen Gross --- drivers/block/xen-blkback/xenbus.c | 36 ++++++++++++++---------------------- 1 file changed, 14 insertions(+), 22 deletions(-) diff --git a/drivers/block/xen-blkback/xenbus.c b/drivers/block/xen-blkback/xenbus.c index 3cc6d1d..415e79b 100644 --- a/drivers/block/xen-blkback/xenbus.c +++ b/drivers/block/xen-blkback/xenbus.c @@ -533,13 +533,11 @@ static void xen_blkbk_discard(struct xenbus_transaction xbt, struct backend_info struct xenbus_device *dev = be->dev; struct xen_blkif *blkif = be->blkif; int err; - int state = 0, discard_enable; + int state = 0; struct block_device *bdev = be->blkif->vbd.bdev; struct request_queue *q = bdev_get_queue(bdev); - err = xenbus_scanf(XBT_NIL, dev->nodename, "discard-enable", "%d", - &discard_enable); - if (err == 1 && !discard_enable) + if (!xenbus_read_unsigned(dev->nodename, "discard-enable", 1)) return; if (blk_queue_discard(q)) { @@ -1039,30 +1037,24 @@ static int connect_ring(struct backend_info *be) xenbus_dev_fatal(dev, err, "unknown fe protocol %s", protocol); return -ENOSYS; } - err = xenbus_scanf(XBT_NIL, dev->otherend, - "feature-persistent", "%u", &pers_grants); - if (err <= 0) - pers_grants = 0; - + pers_grants = xenbus_read_unsigned(dev->otherend, "feature-persistent", + 0); be->blkif->vbd.feature_gnt_persistent = pers_grants; be->blkif->vbd.overflow_max_grants = 0; /* * Read the number of hardware queues from frontend. */ - err = xenbus_scanf(XBT_NIL, dev->otherend, "multi-queue-num-queues", - "%u", &requested_num_queues); - if (err < 0) { - requested_num_queues = 1; - } else { - if (requested_num_queues > xenblk_max_queues - || requested_num_queues == 0) { - /* Buggy or malicious guest. */ - xenbus_dev_fatal(dev, err, - "guest requested %u queues, exceeding the maximum of %u.", - requested_num_queues, xenblk_max_queues); - return -ENOSYS; - } + requested_num_queues = xenbus_read_unsigned(dev->otherend, + "multi-queue-num-queues", + 1); + if (requested_num_queues > xenblk_max_queues + || requested_num_queues == 0) { + /* Buggy or malicious guest. */ + xenbus_dev_fatal(dev, err, + "guest requested %u queues, exceeding the maximum of %u.", + requested_num_queues, xenblk_max_queues); + return -ENOSYS; } be->blkif->nr_rings = requested_num_queues; if (xen_blkif_alloc_rings(be->blkif))