Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp1857847rwb; Fri, 19 Aug 2022 10:32:31 -0700 (PDT) X-Google-Smtp-Source: AA6agR6hF33XEnunW9UdSXEhPl8sEYQMri64L4PjKN2+owwVT06FUPwWAhS95jE258BQg7zAukF1 X-Received: by 2002:a05:6a00:4306:b0:52e:3bdc:2635 with SMTP id cb6-20020a056a00430600b0052e3bdc2635mr8821684pfb.79.1660930351294; Fri, 19 Aug 2022 10:32:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660930351; cv=none; d=google.com; s=arc-20160816; b=Avi7xb3uWOOqYkDQoTDerkNXFKn9I6/JYbmzer/Hp5+Zxj07hRl6NZ35SMSXAVZqI7 HVKAec7Eg8JQD8i3GJbofS3Au5TokVR0T9BQ8RKqOrI4r9XYp9kisQOUoGc5v8vLjXA3 vFfNipNpv74STkYVPYH/9afC9muqk+iDT6LqhGIaGvOa+8+cIkLHZ3BmTmMPktii4Ix2 /YeGIPGie1zE2oqP8NfXI9jSsTUPC8mvu6Ci/tO41Qu9OKo8t6LHCL9VzSXNV+Ifve42 n1YOV0DoLIvcbBBFw/JnGjK8yZpWIRn0D/6BKty22RPUqDzQcCxPlZ9QcP6I0pK3VF53 cI8w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=EWS3bYAWvUXYgHG3VQgmi363mFuo0DhYeYpvAyxBPPU=; b=tjs7R7SpSPopKBdG9MAUvJQf4/44NXcoYro/59UYntAg5GTTT9h3THAV69ZpD+L4PZ 5quttVyi2dO+PGU2Z80RJCkxjdbRGjvWlxczDmKfqJ7kcBrSxAY1bqJl1B8SqLUChIOu vCEzQm5WiqO6Z4fXJEOviOd8+xgsRKXg6Egn84vv1yINZHMDi7W0xkpXhkl6dlx9N94F TCzsMR5KilawLft1N1/+puvh2PvB/SywfFkeOUTwbgnUFOBXJW7xslcqD8n1el5sFKR7 fNJH4VuOTcYxC4cerZzlYB4hhxlIAT/um0oef6H2RmVjg4gLRPLvTAvpP4xHewxPLspa 5Wrw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=QcJWZxei; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id oo17-20020a17090b1c9100b001ef69a94be2si8344487pjb.134.2022.08.19.10.32.19; Fri, 19 Aug 2022 10:32:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=QcJWZxei; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1352638AbiHSQ2s (ORCPT + 99 others); Fri, 19 Aug 2022 12:28:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44482 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352972AbiHSQZ5 (ORCPT ); Fri, 19 Aug 2022 12:25:57 -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 D1F9AB6026; Fri, 19 Aug 2022 09:03:38 -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 724A4617A5; Fri, 19 Aug 2022 16:03:37 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8184BC433C1; Fri, 19 Aug 2022 16:03:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660925016; bh=LLTeC4buUX1RpkGN4KskQVmxDsOfq3Ye4iclIgdlGK0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QcJWZxeiXIZIR7ob+wHgmYE2XJELRX6B0rphmfbD//lp2+na4B2NwwubwghevxiUX Y34F/EvuSRxefvSoqRpYtXCbW57ni8MySa8rc5Tieq/zrI2XHseEyin7qc4Lr+lcV5 Pi7xCQhGAQHnpBFeZGFDZS2zl8cPABGVM/epTODY= 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.10 357/545] null_blk: fix ida error handling in null_add_dev() Date: Fri, 19 Aug 2022 17:42:07 +0200 Message-Id: <20220819153845.358195814@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220819153829.135562864@linuxfoundation.org> References: <20220819153829.135562864@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 bb3686c3869d..c6ba8f9f3f31 100644 --- a/drivers/block/null_blk_main.c +++ b/drivers/block/null_blk_main.c @@ -1876,8 +1876,13 @@ static int null_add_dev(struct nullb_device *dev) blk_queue_flag_clear(QUEUE_FLAG_ADD_RANDOM, nullb->q); mutex_lock(&lock); - nullb->index = ida_simple_get(&nullb_indexes, 0, 0, GFP_KERNEL); - dev->index = nullb->index; + rv = ida_simple_get(&nullb_indexes, 0, 0, GFP_KERNEL); + if (rv < 0) { + mutex_unlock(&lock); + goto out_cleanup_zone; + } + nullb->index = rv; + dev->index = rv; mutex_unlock(&lock); blk_queue_logical_block_size(nullb->q, dev->blocksize); @@ -1889,13 +1894,16 @@ static int null_add_dev(struct nullb_device *dev) rv = null_gendisk_register(nullb); if (rv) - goto out_cleanup_zone; + goto out_ida_free; mutex_lock(&lock); list_add_tail(&nullb->list, &nullb_list); mutex_unlock(&lock); return 0; + +out_ida_free: + ida_free(&nullb_indexes, nullb->index); out_cleanup_zone: null_free_zoned_dev(dev); out_cleanup_blk_queue: -- 2.35.1