Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp3024768rwb; Mon, 15 Aug 2022 16:22:46 -0700 (PDT) X-Google-Smtp-Source: AA6agR6GUqSfVjuW8U0txC4I6PryIXgYAeP7H77p/LEFPjzSCZcDO/FzO3AdFRnjMReGIYHy3alK X-Received: by 2002:a62:1c04:0:b0:52e:d2b4:c029 with SMTP id c4-20020a621c04000000b0052ed2b4c029mr18737095pfc.60.1660605766521; Mon, 15 Aug 2022 16:22:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660605766; cv=none; d=google.com; s=arc-20160816; b=YgI14YWHo70tWd6iRE/TlGUFoG+6Y9ylMKsONGvhdIprFhTyk0De6UPvY2EasNa1YL NTFUhn4/A3HiMg93PgXpJgTwU5AGkSP69GgOHw7AdSHfmrVh8PuWTS8uLCVjf/5HjDvC pxApyUrMMf+75Pd482HN0pXg/OY7jiRsNg5IM736mgwuWb+7KT3LsA8pGTxof2IfiWt6 1bOld/4BrPnpxjCNruSsyo3Ka+1zZi/x6S6NRYpq5mvgi764Nu8bh1rbcq/yGuI0U1Of PRuVHyeF3ty1hlpVQFbtnVo7msxqFcDBqg9/BhLWsFwh7FmHWqnYaC4PS8fMCW3F4ucd CFMQ== 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=1uWUxFTfKfYpCbaSoHe7y5ODcPJ5QTL20zVG+ZP1z1Q=; b=zMNY9XL/Q24kNLojK5FshhjfLaNH93OYjjwCO3mzQKvhuqgPvw3soWwAOtcxaDJFRm LpdDyvLJH2wDK54kfMEvOklGzbqz/LwMa5C0gtKdvs/BO4/v68Itu92oDHjYPdZJLLsD ipj6PR8WudkrQ0FK6l869mk/7mcvqy6difLYFKXNW2QO2PHo/d0tv7039KVEZ5vJyzZU iDEFIWZXZm+G57VpuhHkS7eiF1JjvNBq/jqypIONxDYy09GHgUbt2j4dRDwWPpZXFEwT KLeIY4K+pXa0ddpUwT0d+jXnWLBVCZsjb9ilzWPLdQsyRqk62eLpPnUnUAKiXwqrkQ8v 4jEQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=q3JiemW1; 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 w22-20020a656956000000b004299cef0a3esi1122596pgq.375.2022.08.15.16.22.35; Mon, 15 Aug 2022 16:22:46 -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=q3JiemW1; 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 S1351023AbiHOW11 (ORCPT + 99 others); Mon, 15 Aug 2022 18:27:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60612 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348968AbiHOWVZ (ORCPT ); Mon, 15 Aug 2022 18:21:25 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7D62112423E; Mon, 15 Aug 2022 12:43:37 -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 AF058B80EAD; Mon, 15 Aug 2022 19:43:35 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 007B8C433D7; Mon, 15 Aug 2022 19:43:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660592614; bh=JKAQcE12YD+b1/CsredG6Cd/AlhWJ+dCWAGWHpNHILE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=q3JiemW1PFJdKZnLd9Xf1Pd3A4/l/PJM2x0+CHpKfOz0lkRR82fs1w7lRSqGiiYx1 Z9ArmOIl/xQsDc+P3Sf6XnufoHL4K8yI3mRV3HulK6EVSO4KFs42PK/2ZuWwPaH82b m22gGfohBjbWh5v+KRKXMt9mwAW1smpsswp/73Ds= 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.18 0816/1095] null_blk: fix ida error handling in null_add_dev() Date: Mon, 15 Aug 2022 20:03:35 +0200 Message-Id: <20220815180503.035442897@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220815180429.240518113@linuxfoundation.org> References: <20220815180429.240518113@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 c441a4972064..3e59e824ed1f 100644 --- a/drivers/block/null_blk/main.c +++ b/drivers/block/null_blk/main.c @@ -2044,8 +2044,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); @@ -2065,13 +2070,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_disk: -- 2.35.1