From nobody Fri Sep 5 20:19:50 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id EBEE2C32772 for ; Tue, 23 Aug 2022 11:39:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1357592AbiHWLjr (ORCPT ); Tue, 23 Aug 2022 07:39:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49384 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1357859AbiHWLc2 (ORCPT ); Tue, 23 Aug 2022 07:32:28 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2BF0DC6B68; Tue, 23 Aug 2022 02:26:55 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id DA4C061328; Tue, 23 Aug 2022 09:26:54 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E5176C433D6; Tue, 23 Aug 2022 09:26:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1661246814; bh=x2NuveE8ONFScI78iZ8cTXF/d02hhkTjxBWlxNHqsnY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SBvXkbtM2cXH+ifrMPinw/YcA7Jg+ioPXM8kcpgv5cxnOm4w9X0PVpQ31uyDidb+9 6RPTSgvV30yLmFEnRWgASZhZNb/oJRAP2Jg4RKUKR75yQwWl8Phz5f3I84+ClM/Xr8 /UgGpDMsuqxRgL3tdE+c3FZbkznO1rLaild35QQ0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dan Carpenter , Jens Axboe , Sasha Levin Subject: [PATCH 5.4 198/389] null_blk: fix ida error handling in null_add_dev() Date: Tue, 23 Aug 2022 10:24:36 +0200 Message-Id: <20220823080123.911913944@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220823080115.331990024@linuxfoundation.org> References: <20220823080115.331990024@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Dan Carpenter [ Upstream commit ee452a8d984f94fa8e894f003a52e776e4572881 ] There needs to be some error checking if ida_simple_get() fails. Also call ida_free() if there are errors later. Fixes: 94bc02e30fb8 ("nullb: use ida to manage index") Signed-off-by: Dan Carpenter Link: https://lore.kernel.org/r/YtEhXsr6vJeoiYhd@kili Signed-off-by: Jens Axboe Signed-off-by: Sasha Levin --- drivers/block/null_blk_main.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/drivers/block/null_blk_main.c b/drivers/block/null_blk_main.c index 13eae973eaea..6cbdd8a691d2 100644 --- a/drivers/block/null_blk_main.c +++ b/drivers/block/null_blk_main.c @@ -1711,8 +1711,13 @@ static int null_add_dev(struct nullb_device *dev) blk_queue_flag_clear(QUEUE_FLAG_ADD_RANDOM, nullb->q); =20 mutex_lock(&lock); - nullb->index =3D ida_simple_get(&nullb_indexes, 0, 0, GFP_KERNEL); - dev->index =3D nullb->index; + rv =3D ida_simple_get(&nullb_indexes, 0, 0, GFP_KERNEL); + if (rv < 0) { + mutex_unlock(&lock); + goto out_cleanup_zone; + } + nullb->index =3D rv; + dev->index =3D rv; mutex_unlock(&lock); =20 blk_queue_logical_block_size(nullb->q, dev->blocksize); @@ -1724,13 +1729,16 @@ static int null_add_dev(struct nullb_device *dev) =20 rv =3D null_gendisk_register(nullb); if (rv) - goto out_cleanup_zone; + goto out_ida_free; =20 mutex_lock(&lock); list_add_tail(&nullb->list, &nullb_list); mutex_unlock(&lock); =20 return 0; + +out_ida_free: + ida_free(&nullb_indexes, nullb->index); out_cleanup_zone: if (dev->zoned) null_zone_exit(dev); --=20 2.35.1