Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp2925360rwb; Mon, 15 Aug 2022 14:10:21 -0700 (PDT) X-Google-Smtp-Source: AA6agR7JWv19wtQsQNDcWGdyRiYzvBPztOhWYbfYuXl83QgghYCETp8kYw/mXZp2dFS2eHfwH6nn X-Received: by 2002:a63:2048:0:b0:41c:daad:450d with SMTP id r8-20020a632048000000b0041cdaad450dmr15026951pgm.240.1660597821295; Mon, 15 Aug 2022 14:10:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660597821; cv=none; d=google.com; s=arc-20160816; b=jgwXUNfkjTz3jCPGceDxl8JMk4A6qK1E7ZW+RrvuQVjELQmVui2iiFUnK5lkvTgQos NOA8Lvt5XSMKa1wRyCn9SLG4+T2n3Fm9XuQW5yxREAq96lHML3ZIZGEd31YTjyrwbHi7 5ED+0+2JQ5F2g3TDsZqUtH5MbeBqtQUtpj59Dpr2RqRINzhJtuMCefO8+a3gh6bTsk79 xnubplV9n7uPWWlde58eOcmiNDWZjQ6RZwGRmpdDZRehUfQNv1T+nCaP/NkLxZPfgoTD yfmx6QgFJd9RPqHIQbzSsvDDqG1Q5+3OPirvEBKvmNOXzI9b/1uq/Ra7jokDsU42ZweR +cJw== 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=R6dqlSIUbbNxO6KDe6DY6hZnWdNeK8eEGr9Bar0ZQY0=; b=jlK8PuBEiPf4oiSv/M7k2Veg8oBnVGDL8zyhHMxStdFiBpeN1YQrhbwaxzYDo0Xmy/ 8SML+e+TCYrHh2BwvetMUgEbGUGjobA5bc5hbNHxQntQ+8QqMWoZ/Pr+lYvMKjbI/K0e ZLyXl7tNaXFMNyjz+Adq0uk3pYFKSD30av48aArzTx9TxVgvBJfmVkjHPM0IV6WWNMCc 7FEGxAuB+q2lk9w8//aDIVMcYN9TsA70BkHlNrlGK92knA0scvF650fkEpAnc33xILM1 XoEktqugq0zu8ZEtlmHvJFyr7O/JfwaSuHMm9iGmkWFtwCvgJIoUE+4Um7Z+SbbdXbMx 0TJg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=cMs0JttF; 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 q93-20020a17090a1b6600b001f315e50d85si11189182pjq.175.2022.08.15.14.10.10; Mon, 15 Aug 2022 14:10:21 -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=cMs0JttF; 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 S241634AbiHOT3u (ORCPT + 99 others); Mon, 15 Aug 2022 15:29:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57456 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343535AbiHOT0K (ORCPT ); Mon, 15 Aug 2022 15:26:10 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D78402ED60; Mon, 15 Aug 2022 11:41:35 -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 7481060FB8; Mon, 15 Aug 2022 18:41:35 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 619AAC433D6; Mon, 15 Aug 2022 18:41:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660588894; bh=3mOKCliFe7i9AhglC7ww2MiPXJeDXcOx3MuanO0bK3A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cMs0JttFRZGZdJ+vArm6h5i0eAsQDg2nApbsXDoi+E0k73jJtV14HrOSyHyrilFpv fuUKhN7O7fnJodn+iU0sHl/iRW5fPs8bcchS1iA1ZRF9fYbloGhPGynRp7uXxL9TdR HCI6pKWAggwSDXw+heqN1dT/H7xbnCSNVwvz19/o= 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.15 548/779] null_blk: fix ida error handling in null_add_dev() Date: Mon, 15 Aug 2022 20:03:12 +0200 Message-Id: <20220815180400.746303156@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220815180337.130757997@linuxfoundation.org> References: <20220815180337.130757997@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 187d779c8ca0..4c8b4101516c 100644 --- a/drivers/block/null_blk/main.c +++ b/drivers/block/null_blk/main.c @@ -1884,8 +1884,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); @@ -1905,13 +1910,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