From patchwork Sat Oct 22 02:16:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yu Kuai X-Patchwork-Id: 7064 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4242:0:0:0:0:0 with SMTP id s2csp992385wrr; Fri, 21 Oct 2022 18:55:30 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7gzbjxiGv2wf3iKIgkfHCMRCEIN8NsoJi2C1NMaxWXlffsstYAl1XhP1k1M/NXOnQgfG9y X-Received: by 2002:aa7:de81:0:b0:461:2122:a807 with SMTP id j1-20020aa7de81000000b004612122a807mr8582056edv.382.1666403730429; Fri, 21 Oct 2022 18:55:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666403730; cv=none; d=google.com; s=arc-20160816; b=O4lRj58yjAhrSO/pWcwhM3rqiDuWTXB7VFDUAk+G1Nqjcozn9Pl4xczutjZFlHiWS5 /t/nztkGdp28jB9pGu/CUtG4gFFS1alWHUWMIqsRKctBVP4tSVt5nM4wHU7SW9/aYGvg l9TyuO5N60pNVBSlKvpphMOahGLSqHwCK3eej/1u5KmBYldUEH6QxmsxtGtEps7E9Fth Rasd0mENj96paINTFuVPAgHZ1fHNV0blwJoMW7DPhXtgSMKrAHL+2XP3yZ8KaMBwYgPm 2GaRb5aHavRaLnW9SUOOarHR2NkLx5PVF5JB6PfRARGUflHkIp7kMwGoi93+qKV4omko V/dQ== 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 :message-id:date:subject:cc:to:from; bh=CyzmrWkXR/LA6CZw3vXfn818pDJGqKi4IduDe00g9rk=; b=O7ik8vqIEr8/Jq1kp/70iPAnsEcJ2geQy8Y3u4uzfi4wXIVeNc/4gejnjPwGZH3+ox CZdFwOdJIx7MTLb9OvELnox81WpvhHep7StWiUNCNSzmwQMDBaa2n9ycHNbC6ELn5GyT L3QjthPdhQUb3t9oilggCLYKEsErJkUUDi2MwJ69QIF1XbRT6+rgzv9TeA9yzMZu8UJ5 NeFVRbxkVmvbVE9C0+ei1o/yYdka4rr5h3u+AAiRTwoFNyC7EViCpb6khtzHRQ25NYvp 5IAqQucQil/sniWG8VIZJtUD6C2C+YFnQKMGxES1bQNk3WWxBtDcVkg/rRwLEY5CdKCg jmBQ== ARC-Authentication-Results: i=1; mx.google.com; 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y15-20020a056402440f00b00459f6b0fa96si26706981eda.355.2022.10.21.18.55.06; Fri, 21 Oct 2022 18:55:30 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229808AbiJVByX (ORCPT + 99 others); Fri, 21 Oct 2022 21:54:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56040 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229975AbiJVByV (ORCPT ); Fri, 21 Oct 2022 21:54:21 -0400 Received: from dggsgout11.his.huawei.com (unknown [45.249.212.51]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 911692CDEB; Fri, 21 Oct 2022 18:54:18 -0700 (PDT) Received: from mail02.huawei.com (unknown [172.30.67.153]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4MvPTM4YpNzKFt3; Sat, 22 Oct 2022 09:51:51 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.127.227]) by APP4 (Coremail) with SMTP id gCh0CgBHWTBGTVNjcFznAA--.52S4; Sat, 22 Oct 2022 09:54:16 +0800 (CST) From: Yu Kuai To: axboe@kernel.dk, hch@lst.de, ming.lei@redhat.com Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, yukuai3@huawei.com, yukuai1@huaweicloud.com, yi.zhang@huawei.com Subject: [PATCH v2] block: fix memory leak for elevator on add_disk failure Date: Sat, 22 Oct 2022 10:16:15 +0800 Message-Id: <20221022021615.2756171-1-yukuai1@huaweicloud.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 X-CM-TRANSID: gCh0CgBHWTBGTVNjcFznAA--.52S4 X-Coremail-Antispam: 1UD129KBjvJXoW7ZF4kXFyUuFWxWw1ftFyDGFg_yoW8CF4fpr s8Z3s0grWDWr4UWF1jqa17JFy5Cw1kGr93WFW3Gr1a9wnakFsFva4UKa15Way5ArZ3Xan7 XFWxGFy0gF18Aw7anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUyG14x267AKxVW8JVW5JwAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2ocxC64kIII0Yj41l84x0c7CEw4AK67xGY2AK02 1l84ACjcxK6xIIjxv20xvE14v26w1j6s0DM28EF7xvwVC0I7IYx2IY6xkF7I0E14v26r4U JVWxJr1l84ACjcxK6I8E87Iv67AKxVW0oVCq3wA2z4x0Y4vEx4A2jsIEc7CjxVAFwI0_Gc CE3s1le2I262IYc4CY6c8Ij28IcVAaY2xG8wAqx4xG64xvF2IEw4CE5I8CrVC2j2WlYx0E 2Ix0cI8IcVAFwI0_Jr0_Jr4lYx0Ex4A2jsIE14v26r1j6r4UMcvjeVCFs4IE7xkEbVWUJV W8JwACjcxG0xvY0x0EwIxGrwACjI8F5VA0II8E6IAqYI8I648v4I1l42xK82IYc2Ij64vI r41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8Gjc xK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r1q6r43MIIYrxkI7VAKI48JMIIF0xvE2Ix0 cI8IcVAFwI0_Jr0_JF4lIxAIcVC0I7IYx2IY6xkF7I0E14v26r1j6r4UMIIF0xvE42xK8V AvwI8IcIk0rVWrZr1j6s0DMIIF0xvEx4A2jsIE14v26r1j6r4UMIIF0xvEx4A2jsIEc7Cj xVAFwI0_Jr0_GrUvcSsGvfC2KfnxnUUI43ZEXa7VUbXdbUUUUUU== X-CM-SenderInfo: 51xn3trlr6x35dzhxuhorxvhhfrp/ X-CFilter-Loop: Reflected X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747350958001753314?= X-GMAIL-MSGID: =?utf-8?q?1747350958001753314?= From: Yu Kuai The default elevator is allocated in the beginning of device_add_disk(), however, it's not freed in the following error path. Fixes: 50e34d78815e ("block: disable the elevator int del_gendisk") Signed-off-by: Yu Kuai Reviewed-by: Christoph Hellwig Reviewed-by: Jason Yan --- Changes in v2: - fix wrong fix tag - add review tag block/genhd.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/block/genhd.c b/block/genhd.c index b3d04e79e854..fea319c8f99e 100644 --- a/block/genhd.c +++ b/block/genhd.c @@ -437,9 +437,10 @@ int __must_check device_add_disk(struct device *parent, struct gendisk *disk, * Otherwise just allocate the device numbers for both the whole device * and all partitions from the extended dev_t space. */ + ret = -EINVAL; if (disk->major) { if (WARN_ON(!disk->minors)) - return -EINVAL; + goto out_exit_elevator; if (disk->minors > DISK_MAX_PARTS) { pr_err("block: can't allocate more than %d partitions\n", @@ -447,14 +448,14 @@ int __must_check device_add_disk(struct device *parent, struct gendisk *disk, disk->minors = DISK_MAX_PARTS; } if (disk->first_minor + disk->minors > MINORMASK + 1) - return -EINVAL; + goto out_exit_elevator; } else { if (WARN_ON(disk->minors)) - return -EINVAL; + goto out_exit_elevator; ret = blk_alloc_ext_minor(); if (ret < 0) - return ret; + goto out_exit_elevator; disk->major = BLOCK_EXT_MAJOR; disk->first_minor = ret; } @@ -571,6 +572,9 @@ int __must_check device_add_disk(struct device *parent, struct gendisk *disk, out_free_ext_minor: if (disk->major == BLOCK_EXT_MAJOR) blk_free_ext_minor(disk->first_minor); +out_exit_elevator: + if (disk->queue->elevator) + elevator_exit(disk->queue); return ret; } EXPORT_SYMBOL(device_add_disk);