Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp9474602pxu; Mon, 28 Dec 2020 17:52:58 -0800 (PST) X-Google-Smtp-Source: ABdhPJznnP9dnM95tTMlyrxDwt6fTWbHfo93R07wTKGBOWVsAAU5ewmJyw5pfXHi4fE8nZ6jkyc9 X-Received: by 2002:a17:906:2695:: with SMTP id t21mr39246907ejc.287.1609206778770; Mon, 28 Dec 2020 17:52:58 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1609206778; cv=pass; d=google.com; s=arc-20160816; b=Q2/Lb9WrdFR3t0dGBOueLYxvQRknB/U087ihYPyHuEQNU+vZsNjUrFhf0RATQxbn4A /LsKakgxyCc67D0HJjAPSnLeo/KF2PpFoYBAXxniR97SBqaMq4SHIxyPLvkkrXAStV4N mi+mbCumrQ31IUJzgfvbn/aZFpwuNIJd078EXAGc8HUdr7FSHPHpaYPbjC4wYQIdfYfu u/a6jfeD9QJIAdCdlbOuVETI3ntvaZx6bCz1qeB0MqG5a4Z3vLNiOmAsAviA3sCnWAd2 wp7/ide8hk/BQnQcHia582ZpC2ManJEBrN/bQpt9PxWJrCZjtLruIFx4pFwMiohsyqSr 8Mgw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :message-id:date:subject:cc:to:from:dkim-signature; bh=TgpzCMUwwCOaK01z61+JK4feMYO3TBRVPY/9eEGoTTY=; b=c6aW66D3eIwtfWkzPqpF/SEH5C3JH9pksWAmdf+4qNCvS2BiQPaah5ANO5PHeHUptb JGqkcbruIuvJhF7sEYwWPMzUgRijC2U5HHH5AusXOMxSbL3PdwI8coZwX9gasAeTfRYd 8OszPt2rqh8YXBzAEDYAgp8wdndNR5IEoKO3zIBBZUAtwFKmQ7WrXYKCfWULlEdZkGI0 Hawb165e6RDR+cU+0l3IDTm0qT+cPwkIfaBt0OyUMYVuw6za7sDa9IVp34AulWXpDXFI 5SUj5nAKQ28yn8FvzL19pEQAl3soi9nkcO+G9ExgR+16/nxMk3NH4LdEj0hZ9g4AIsMh ICUg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@windriversystems.onmicrosoft.com header.s=selector2-windriversystems-onmicrosoft-com header.b=nLJF0qxp; arc=pass (i=1 spf=pass spfdomain=windriver.com dkim=pass dkdomain=windriver.com dmarc=pass fromdomain=windriver.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id hp25si19898736ejc.361.2020.12.28.17.52.36; Mon, 28 Dec 2020 17:52:58 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@windriversystems.onmicrosoft.com header.s=selector2-windriversystems-onmicrosoft-com header.b=nLJF0qxp; arc=pass (i=1 spf=pass spfdomain=windriver.com dkim=pass dkdomain=windriver.com dmarc=pass fromdomain=windriver.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727770AbgL2BRs (ORCPT + 99 others); Mon, 28 Dec 2020 20:17:48 -0500 Received: from mail-eopbgr750080.outbound.protection.outlook.com ([40.107.75.80]:17374 "EHLO NAM02-BL2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726738AbgL2BRr (ORCPT ); Mon, 28 Dec 2020 20:17:47 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=C0k86/akjpIGudCFC1kh6LxG51RpsfCEVvGRBDg2awErlaI81bQ0Wi2pmyLEJfCDQuzOVBz+O/MBaKa1rKYVNRaoVqt/eCSMadCL9i2pqK5Wx6PgrA1ZR65KHDzNhu9jz+UWwZ4n4WY17hWBeZKgb01WOhZjIKvO1h65qdY3Ut4vpX6rvvYUyzDeJS0HR6MaMvU2YaoVhbAhJpxLeHwmD3r22iy+aFT0X50lu+njDFfGhCff3JH+UqWH6RWSzJ6JuSCnzrrhmW8TOHz7Qmprt1FqPjQzLK4mVLTKDZLHgmcMC3FKKYjfcbde+N5Kyj/dCdbNscV7zgNb/qlsMLotmQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=TgpzCMUwwCOaK01z61+JK4feMYO3TBRVPY/9eEGoTTY=; b=OBwr8yLQTZUjtL8/XEOJpQTVyf918GQCw9Bi4xYozH5vtWpjritKKD/X/56hXTE0N6PVJQizS2Gepsn+gPHtZwBuVoCigr9qciZ1NaBEftsyuCApXnXuPm2iMzVMxs1c5Wca2YZQNRtLi1CrMLbWasu9nYP4O1/1mXRQoccVby/7QTL5BmzRUcLAVyfNBq5CqLLOresCTNnddhd1s57b3oLh+weDufUw81BFsBrnT94uRRhnkWdL5Ul2VHHT8hdzbznY3yLsZW1G1NXBOXd4/UMI3/SoGhcCSRgT7jom8q+ujvQQlDZ4YOoJaEOlwHDaMlHAB4qykSvqBWrMmgor9Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=windriver.com; dmarc=pass action=none header.from=windriver.com; dkim=pass header.d=windriver.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=windriversystems.onmicrosoft.com; s=selector2-windriversystems-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=TgpzCMUwwCOaK01z61+JK4feMYO3TBRVPY/9eEGoTTY=; b=nLJF0qxp74HpUkjQho0dWEfsYfbieMGPvZD3U3Dfm7Tct9MBX1IsCBw9dRlxA/a72jpYEvD2etOMQO5IR3YXXni4n0bBy71as1TLR5sWfz6Jaxi6Bk1qdk8I8b8zAxIbUswLa5zAh3cLtyjw54vWCKq/5wVc1+P+x/eP57dfHRk= Authentication-Results: kernel.org; dkim=none (message not signed) header.d=none;kernel.org; dmarc=none action=none header.from=windriver.com; Received: from PH0PR11MB5077.namprd11.prod.outlook.com (2603:10b6:510:3b::17) by PH0PR11MB5176.namprd11.prod.outlook.com (2603:10b6:510:3f::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3700.28; Tue, 29 Dec 2020 01:17:03 +0000 Received: from PH0PR11MB5077.namprd11.prod.outlook.com ([fe80::564:ae38:9aae:7896]) by PH0PR11MB5077.namprd11.prod.outlook.com ([fe80::564:ae38:9aae:7896%5]) with mapi id 15.20.3700.031; Tue, 29 Dec 2020 01:17:03 +0000 From: Xiaolei Wang To: broonie@kernel.org Cc: gregkh@linuxfoundation.org, rafael@kernel.org, david@lechnology.com, linux-kernel@vger.kernel.org Subject: [PATCH v2] regmap: debugfs: Fix a memory leak when calling regmap_attach_dev Date: Tue, 29 Dec 2020 09:16:17 +0800 Message-Id: <20201229011617.3795455-1-xiaolei.wang@windriver.com> X-Mailer: git-send-email 2.25.1 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [60.247.85.82] X-ClientProxiedBy: HK2PR04CA0064.apcprd04.prod.outlook.com (2603:1096:202:14::32) To PH0PR11MB5077.namprd11.prod.outlook.com (2603:10b6:510:3b::17) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from pek-lpggp7.wrs.com (60.247.85.82) by HK2PR04CA0064.apcprd04.prod.outlook.com (2603:1096:202:14::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3700.27 via Frontend Transport; Tue, 29 Dec 2020 01:17:01 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 0138e764-696b-4bb2-1a8a-08d8ab977306 X-MS-TrafficTypeDiagnostic: PH0PR11MB5176: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:302; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 4fUA1jaB+vfJGbEJhVENxqAxXgqSmgzBYg6IRxqKJ+IJeZs0fXCddoBG8GGDmkauPCi/P2IqBnXZbV7cO186Q27AQV8kK5XudUesmyciRlkHlKaMkyZ39q/VHfFPZ9F9lhlOUjGGCpW5koKmSdhf1RhZw4o3RMeGF8jovsTKTP4HK1HPMRHL5127sarMqbZmug9tdud4qs6hPkoLHn7aoS/zXJKYZ896SvuRMW9pIcngLielKY2xnvzs9nid9lFtdnkL1hFxRlafxl006wcAXJszzbkiIoSHXlOPj9d7bVUsp0x+DKDjcfop5g/7xYNGlFoKaq7ynC2KyH4WH9Lf0jlnkHJ6EBTJz/iuAvnDNOy8z/+iF1xen3AfJE+1pADr2+WtU50bow270NUaOCRiug== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PH0PR11MB5077.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(346002)(366004)(136003)(396003)(376002)(39850400004)(44832011)(6506007)(2616005)(16526019)(6486002)(956004)(36756003)(1076003)(26005)(8676002)(66556008)(66946007)(66476007)(2906002)(5660300002)(4326008)(6512007)(83380400001)(8936002)(6916009)(186003)(86362001)(52116002)(478600001)(316002)(6666004);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?us-ascii?Q?eLzlxh7knG7krlIzQjY7Iv88XGpyaiVIPepwkQ8LHgwboOhFZpcJdC+qmNxI?= =?us-ascii?Q?FgEKjS9ClfQJcBTiuptLe4EZH767+NueiX3T7KtJjWyH3BtA98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rVHdVrk7B9oQm0Yy62K0B9CwitxYBdMorIKBEzm7e0?= =?us-ascii?Q?Oplm?= X-OriginatorOrg: windriver.com X-MS-Exchange-CrossTenant-AuthSource: PH0PR11MB5077.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Dec 2020 01:17:03.0280 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 8ddb2873-a1ad-4a18-ae4e-4644631433be X-MS-Exchange-CrossTenant-Network-Message-Id: 0138e764-696b-4bb2-1a8a-08d8ab977306 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: fjoj8ZJsYJsTnMgMoT6BZ7wl2yN1YbXuwihdndaFthHiep/bKYQP75Ws8WWneTU8SbJxPdOu2nC077tf3o2TSglbQ/bf7YiaKbwSKvXsods= X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR11MB5176 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Fixes: 9b947a13e7f6 ("regmap: use debugfs even when no device") After initializing the regmap through syscon_regmap_lookup_by_compatible, then regmap_attach_dev to the device, because the debugfs_name has been allocated, there is no need to redistribute it again unreferenced object 0xd8399b80 (size 64): comm "swapper/0", pid 1, jiffies 4294937641 (age 278.590s) hex dump (first 32 bytes): 64 75 6d 6d 79 2d 69 6f 6d 75 78 63 2d 67 70 72 dummy-iomuxc-gpr 40 32 30 65 34 30 30 30 00 7f 52 5b d8 7e 42 69 @20e4000..R[.~Bi backtrace: [] kasprintf+0x2c/0x54 [<6ad3bbc2>] regmap_debugfs_init+0xdc/0x2fc [] __regmap_init+0xc38/0xd88 [<1f7e0609>] of_syscon_register+0x168/0x294 [<735e8766>] device_node_get_regmap+0x6c/0x98 [] imx6ul_init_machine+0x20/0x88 [<0456565b>] customize_machine+0x1c/0x30 [] do_one_initcall+0x80/0x3ac [<7e584867>] kernel_init_freeable+0x170/0x1f0 [<80074741>] kernel_init+0x8/0x120 [<285d6f28>] ret_from_fork+0x14/0x20 [<00000000>] 0x0 Signed-off-by: Xiaolei Wang --- drivers/base/regmap/regmap-debugfs.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/drivers/base/regmap/regmap-debugfs.c b/drivers/base/regmap/regmap-debugfs.c index 8dfac7f3ed7a..bf03cd343be2 100644 --- a/drivers/base/regmap/regmap-debugfs.c +++ b/drivers/base/regmap/regmap-debugfs.c @@ -582,18 +582,25 @@ void regmap_debugfs_init(struct regmap *map) devname = dev_name(map->dev); if (name) { - map->debugfs_name = kasprintf(GFP_KERNEL, "%s-%s", + if (!map->debugfs_name) { + map->debugfs_name = kasprintf(GFP_KERNEL, "%s-%s", devname, name); + if (!map->debugfs_name) + return; + } name = map->debugfs_name; } else { name = devname; } if (!strcmp(name, "dummy")) { - kfree(map->debugfs_name); + if (!map->debugfs_name) + kfree(map->debugfs_name); map->debugfs_name = kasprintf(GFP_KERNEL, "dummy%d", dummy_index); + if (!map->debugfs_name) + return; name = map->debugfs_name; dummy_index++; } -- 2.25.1