Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933168AbcLACwW (ORCPT ); Wed, 30 Nov 2016 21:52:22 -0500 Received: from m12-17.163.com ([220.181.12.17]:36209 "EHLO m12-17.163.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756701AbcLACwV (ORCPT ); Wed, 30 Nov 2016 21:52:21 -0500 From: Pan Bian To: Markus Pargmann , nbd-general@lists.sourceforge.net Cc: linux-kernel@vger.kernel.org, Pan Bian Subject: [PATCH 1/1] block: nbd: fix bugs in nbd_init Date: Thu, 1 Dec 2016 10:51:38 +0800 Message-Id: <1480560698-2260-1-git-send-email-bianpan2016@163.com> X-Mailer: git-send-email 1.9.1 X-CM-TRANSID: EcCowAAHwgxIkD9YItf2Dg--.881S3 X-Coremail-Antispam: 1Uf129KBjvJXoW7Kr4kZFWUtw1kuFWDXr17GFg_yoW8JFyrpF Z8Ga4UK34rCanrZFW8Jw4UZF15Aa12k34xGF12k3sI9r15uFZF9F1Iya42qF18GrZ5AF4f XF4DJF48tF18ArDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07bVDGOUUUUU= X-Originating-IP: [106.120.213.17] X-CM-SenderInfo: held01tdqsiiqw6rljoofrz/xtbBUQ8zclaDsSOUdAAAs4 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1285 Lines: 41 Fix bug https://bugzilla.kernel.org/show_bug.cgi?id=188441. Fix 3 bugs in function nbd_init: (1) set error code (-ENOMEM) when the call to alloc_disk() fails; (2) function blk_mq_init_queue() returns an ERR_PTR pointer rather than NULL on failures, so use IS_ERR to check the return value; (3) set error code on the branch that blk_mq_init_queue() returns an invalid pointer. Signed-off-by: Pan Bian --- drivers/block/nbd.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c index 7a10487..200e899 100644 --- a/drivers/block/nbd.c +++ b/drivers/block/nbd.c @@ -930,8 +930,10 @@ static int __init nbd_init(void) for (i = 0; i < nbds_max; i++) { struct gendisk *disk = alloc_disk(1 << part_shift); - if (!disk) + if (!disk) { + err = -ENOMEM; goto out; + } nbd_dev[i].disk = disk; nbd_dev[i].tag_set.ops = &nbd_mq_ops; @@ -955,7 +957,8 @@ static int __init nbd_init(void) * These structs are big so we dynamically allocate them. */ disk->queue = blk_mq_init_queue(&nbd_dev[i].tag_set); - if (!disk->queue) { + if (IS_ERR(disk->queue)) { + err = PTR_ERR(disk->queue); blk_mq_free_tag_set(&nbd_dev[i].tag_set); put_disk(disk); goto out; -- 1.9.1