From nobody Wed Dec 17 09:16:22 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 6175FC49EC3 for ; Tue, 23 Aug 2022 10:47:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1356457AbiHWKr1 (ORCPT ); Tue, 23 Aug 2022 06:47:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46370 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1356099AbiHWKl1 (ORCPT ); Tue, 23 Aug 2022 06:41:27 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E0442A8309; Tue, 23 Aug 2022 02:08:59 -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 ams.source.kernel.org (Postfix) with ESMTPS id EF19AB81C63; Tue, 23 Aug 2022 09:08:58 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 38487C433C1; Tue, 23 Aug 2022 09:08:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1661245737; bh=gqAEIG8WfbBhqZK393AADTyvKVoO0A2WXRDn+KKYA08=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rAwntlz7F7O7gFLp09RvajNkx/jlcXESbN7Phtkr1v3klCQlgyedJUSFZqrI3yye+ VWOCZ+aSDVCgwn8bilq3C/biAs0rVlvEnEhJ95wUOEx7h81UpJbrCb9vHbjmxenHqT BgbIv8grHL9EpUkWimoPVuupU6vA6Ek7hQYc90bs= 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 4.19 143/287] null_blk: fix ida error handling in null_add_dev() Date: Tue, 23 Aug 2022 10:25:12 +0200 Message-Id: <20220823080105.341063792@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220823080100.268827165@linuxfoundation.org> References: <20220823080100.268827165@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 4fef1fb918ec..5553df736c72 100644 --- a/drivers/block/null_blk_main.c +++ b/drivers/block/null_blk_main.c @@ -1819,8 +1819,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); @@ -1832,13 +1837,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