From patchwork Sat Oct 29 07:13:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chen Zhongjin X-Patchwork-Id: 12657 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp1228771wru; Sat, 29 Oct 2022 00:25:39 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5tLakiJeIoYYJ+H7LnVEuFaDiocmRvC+r5+rdzh/+Vrtjdi22rd2QTIPi16tlbD+uR107S X-Received: by 2002:a17:902:e882:b0:186:a3ba:8780 with SMTP id w2-20020a170902e88200b00186a3ba8780mr3174144plg.114.1667028339362; Sat, 29 Oct 2022 00:25:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667028339; cv=none; d=google.com; s=arc-20160816; b=YhAApdm0YNgQXbvmL2T4Fmt4WRVct0kaN5jE79gmzRu1cBRlhnTK4xUmzMr2+5bw6t 3F7ullHnEnCKsxFMDdhh4JyIjwb06idD7uRv2FLsKEoGpKlUYC1/JADWbLUkPc87jrOg Ev8VVYjZIP+oShY6/74xtphwhbMOQ9DtX2S26cldpEu8iSot+iHWPVLAzuBTSPy7GW1m 4YDoC9oxSNyq2I627KNNi1wIdATHbqVbpTHzz9qQcOKOf3UoOwFa+QRHgTew++T4L+n3 2uDeJg9EWWJT0HeH9knWa8gzZ5n3nuc4NMXZvHfwsro4+keyq5Tu8cg4EMLJPCU4pn64 unuA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:subject:cc:to:from; bh=uNS1p+CHt4B5WomrJliNTGO+KK7wKMzsql4s7jFcamc=; b=N/abGsLC5Xvk/vMDORcUKDxXzSwmtnIKVwzQVqXsuJh9bS6I1aObu+n1s0aV49hw6i Igt7EnF+2rTmuJAR7OcFyi373mBDLraHJM9watzhqlW/vQL0BQrpQrX6w003bgA5I/GR H00M9vdFJsG6WZa6tAKQT1/ddhynF9+5YuYZp/xp1G2Hi0DWxOcWgzR0N32oppsQqw0/ BHlLPLj5nz8pK3v4TkOSnjCEgASF1ICR1ojzSGsAF/QTK7DgYYWVCknrp8icjbX8ef/a LDARobnUb8rILxdEX0jrFyOkqjqlcYRhVS9N2kTz9mmDXZWNlmcn1qdV34yF5MareT/h waZg== 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; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z184-20020a6265c1000000b00554245aac47si945461pfb.283.2022.10.29.00.25.25; Sat, 29 Oct 2022 00:25:39 -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; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229571AbiJ2HRS (ORCPT + 99 others); Sat, 29 Oct 2022 03:17:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59834 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229457AbiJ2HRR (ORCPT ); Sat, 29 Oct 2022 03:17:17 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 49C9717FD53; Sat, 29 Oct 2022 00:17:16 -0700 (PDT) Received: from dggpemm500020.china.huawei.com (unknown [172.30.72.54]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4MzrFz06WJzVjK5; Sat, 29 Oct 2022 15:12:23 +0800 (CST) Received: from dggpemm500013.china.huawei.com (7.185.36.172) by dggpemm500020.china.huawei.com (7.185.36.49) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Sat, 29 Oct 2022 15:17:14 +0800 Received: from ubuntu1804.huawei.com (10.67.175.36) by dggpemm500013.china.huawei.com (7.185.36.172) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Sat, 29 Oct 2022 15:17:14 +0800 From: Chen Zhongjin To: , CC: , , , Subject: [PATCH] block: Fix possible memory leak for rq_wb on add_disk failure Date: Sat, 29 Oct 2022 15:13:55 +0800 Message-ID: <20221029071355.35462-1-chenzhongjin@huawei.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 X-Originating-IP: [10.67.175.36] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To dggpemm500013.china.huawei.com (7.185.36.172) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, 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?1748005908060730209?= X-GMAIL-MSGID: =?utf-8?q?1748005908060730209?= kmemleak reported memory leaks in device_add_disk(): kmemleak: 3 new suspected memory leaks unreferenced object 0xffff88800f420800 (size 512): comm "modprobe", pid 4275, jiffies 4295639067 (age 223.512s) hex dump (first 32 bytes): 04 00 00 00 08 00 00 00 01 00 00 00 00 00 00 00 ................ 00 e1 f5 05 00 00 00 00 00 00 00 00 00 00 00 00 ................ backtrace: [<00000000d3662699>] kmalloc_trace+0x26/0x60 [<00000000edc7aadc>] wbt_init+0x50/0x6f0 [<0000000069601d16>] wbt_enable_default+0x157/0x1c0 [<0000000028fc393f>] blk_register_queue+0x2a4/0x420 [<000000007345a042>] device_add_disk+0x6fd/0xe40 [<0000000060e6aab0>] nbd_dev_add+0x828/0xbf0 [nbd] ... It is because the memory allocated in wbt_enable_default() is not released in device_add_disk() error path. Normally, these memory are freed in: del_gendisk() rq_qos_exit() rqos->ops->exit(rqos); wbt_exit() So rq_qos_exit() is called to free the rq_wb memory for wbt_init(). However in the error path of device_add_disk(), only blk_unregister_queue() is called and make rq_wb memory leaked. Add rq_qos_exit() to the error path to fix it. Fixes: 83cbce957446 ("block: add error handling for device_add_disk / add_disk") Signed-off-by: Chen Zhongjin Reviewed-by: Christoph Hellwig --- block/genhd.c | 1 + 1 file changed, 1 insertion(+) diff --git a/block/genhd.c b/block/genhd.c index fee90eb98b4a..0f9769db2de8 100644 --- a/block/genhd.c +++ b/block/genhd.c @@ -527,6 +527,7 @@ int __must_check device_add_disk(struct device *parent, struct gendisk *disk, bdi_unregister(disk->bdi); out_unregister_queue: blk_unregister_queue(disk); + rq_qos_exit(disk->queue); out_put_slave_dir: kobject_put(disk->slave_dir); out_put_holder_dir: