Received: by 2002:a05:6358:5282:b0:b5:90e7:25cb with SMTP id g2csp3412621rwa; Tue, 23 Aug 2022 04:28:51 -0700 (PDT) X-Google-Smtp-Source: AA6agR5OS89jD6kKZ4seF9DD8YDKzlJHsftdPvgAMEEeXPi2NDlxqb2vqgq4wJY0n4pjvt6iNGK3 X-Received: by 2002:a17:902:7e45:b0:172:8c47:ff2e with SMTP id a5-20020a1709027e4500b001728c47ff2emr23567888pln.24.1661254130851; Tue, 23 Aug 2022 04:28:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661254130; cv=none; d=google.com; s=arc-20160816; b=MC9Ul2x1aUlup7IGOzpY+l7RhK3oqNAk0ojRL/swGUsF5tsFL5wisVUEHgQqHJYoAc uUGKlSPsIbaTlM+IVZJdpfzpqLdGHIxe/jD6bQ8ZrNU/HmlB1Qf5OcGEoQpjYMvmKEQk /Eg1ZC3+xSFBlZA6BkAAPErD10/FDfqnMED8ge+iW25Xe/63E97DRYOSysL/s2M/hR8d Ybv6XMnURDGeGwsFGchjFGg8MLQbezKkJ+/7EycY4FmdsfhXc2X3rodbJ08GLg8nGx8v 5weBGUziCNi8s7Uzp5lqSf5azIGwKe00JSnlLVjsxC47Git8M5f3L/abX02KpgLD8NQe zyAA== 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=63kythTNDcDvOTMd3gF6PgwHsO+Wfqz0rHmMjrNf5hQ=; b=zHdvfmaFF2bXKrQbwPPEIG60/9uB8tt2EnQXQrUXY5VpZDdJ2s5xt4hOxQ2Tj7Vrzn qilQdZeuuG6bPpqvAz5rvj/2KZz1FbOKKSgDVSVc64WY/oXzTd/6YiatXvoOl8Zo8/PM Hy7R7Sh1Y3rJTNJ8F/R13eK59qnqQ+ngRIfnE6qjNZcOz6BtMAgSTaxLeBKMblUTPIBN kG3pzQ0wwqfchlenRaFhtSSTQh8SOYGTZJLMV2Qb5CiALQyV+M5BEnBu1DiWUshyKC6a HExLpOisqxGWP5gqDwC7ogOJC7PCqRo/B+ldDT+zuuwItPrGJf5rQxUqLqAR189mnvig siDg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=rAwntlz7; 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 f10-20020a056a0022ca00b0052acaf4a3c0si1727528pfj.17.2022.08.23.04.28.39; Tue, 23 Aug 2022 04:28:50 -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=rAwntlz7; 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 S1356451AbiHWKr0 (ORCPT + 99 others); Tue, 23 Aug 2022 06:47:26 -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-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 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); 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); @@ -1832,13 +1837,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: if (dev->zoned) null_zone_exit(dev); -- 2.35.1