Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757873AbcLACM6 (ORCPT ); Wed, 30 Nov 2016 21:12:58 -0500 Received: from m12-14.163.com ([220.181.12.14]:59375 "EHLO m12-14.163.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756084AbcLACM5 (ORCPT ); Wed, 30 Nov 2016 21:12:57 -0500 From: Pan Bian To: Jens Axboe , Asai Thambi SP , Selvan Mani , Rajesh Kumar Sambandam , Vignesh Gunasekaran , Baoyou Xie , Keith Busch , Mike Christie , Al Viro Cc: linux-kernel@vger.kernel.org, Pan Bian Subject: [PATCH 1/1] block: mtip32xx: set error code on failure Date: Thu, 1 Dec 2016 10:10:46 +0800 Message-Id: <1480558246-19015-1-git-send-email-bianpan2016@163.com> X-Mailer: git-send-email 1.9.1 X-CM-TRANSID: DsCowACnVLawhj9Y9EN8Dg--.55114S3 X-Coremail-Antispam: 1Uf129KBjvJXoWrKw4rAF15trWfGw13XrW7twb_yoW8JrWxpa n5WFyFyryjgay7X3WUAa4Fvw1xCa1kCryagr1F9anrury5AFs29F4DKrySgr4jkrWIvF4q qF4DWryUXF1UZ3JanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07b3FxUUUUUU= X-Originating-IP: [106.120.213.17] X-CM-SenderInfo: held01tdqsiiqw6rljoofrz/xtbBURYzclaDsSMW7AAAs7 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1212 Lines: 33 Fix bug https://bugzilla.kernel.org/show_bug.cgi?id=188531. In function mtip_block_initialize(), variable rv takes the return value, and its value should be negative on errors. rv is initialized as 0 and is not reset when the call to ida_pre_get() fails. So 0 may be returned. The return value 0 indicates that there is no error, which may be inconsistent with the execution status. This patch fixes the bug by explicitly assigning -ENOMEM to rv on the branch that ida_pre_get() fails. Signed-off-by: Pan Bian --- drivers/block/mtip32xx/mtip32xx.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/block/mtip32xx/mtip32xx.c b/drivers/block/mtip32xx/mtip32xx.c index 3cfd879..36e70cb 100644 --- a/drivers/block/mtip32xx/mtip32xx.c +++ b/drivers/block/mtip32xx/mtip32xx.c @@ -3937,8 +3937,10 @@ static int mtip_block_initialize(struct driver_data *dd) /* Generate the disk name, implemented same as in sd.c */ do { - if (!ida_pre_get(&rssd_index_ida, GFP_KERNEL)) + if (!ida_pre_get(&rssd_index_ida, GFP_KERNEL)) { + rv = -ENOMEM; goto ida_get_error; + } spin_lock(&rssd_index_lock); rv = ida_get_new(&rssd_index_ida, &index); -- 1.9.1