Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp9707904pxu; Tue, 29 Dec 2020 02:52:59 -0800 (PST) X-Google-Smtp-Source: ABdhPJwWvYmxcZ1jmBWOD9NNq0xJlspY/wwcwhDSv70HvAWGcipUi0e79dJ2w4gHxH6A8zEWSfgY X-Received: by 2002:a17:906:ae0c:: with SMTP id le12mr45391435ejb.283.1609239179271; Tue, 29 Dec 2020 02:52:59 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1609239179; cv=pass; d=google.com; s=arc-20160816; b=P0HTRwo15kjZ9hNk80HneRXPuDvxn1xxx/p8UqgGyF2/7N2oLvhO/qCaOOkomXvJIc 5cCDhQm9vOgO/L6oLXG1Y+ygBG0CMyfzvolomgNtCydJszIMCI/Woqer2jWWKDDbQ9yW tVEtNn+zHoDCuroaIZMu60tgFtE2e8S+8my443lWnvS5byisUGyWJ8on+I+/0qWbQrzx puc+01oJsxSY7jrc3PHblm+ME4tZzbMa2cLkag5fx8t4naP6CbtUGkg7rYDxmSSN1fR1 uSaK/SgwJ61RHnJP3i6xxGp5v4c6OWnl9xo2dYoLbjEnAyhGfPqd1Ibb/wjr1LFNoKOY QWLQ== 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=mjU5BmwXOze4RzKoNjECXt34IBYswkpNDNJCOrIzPGE=; b=uSP18RA/1VQ/6DcLP+uEl7I/MP9DFD5wgHxntBRlC2UoAaxXsQyGh37274VHSzUUmz gQvZcV7E4Meg/bmCiyoo1ls0m569zKd3qyfgOtaMRvyVVdAQDfZglkkbzhIUTZK9mUK4 TiTADhb66KeaBOi6CnP8EGxS/1n3CcWOrB5Guu/vKAxMO0fz6pkEVCqcT+xqIOKSAHIu 9qnRgTuxmaSK2p3W2vW/PKW+xA8IFi3nCbyhoxjmPdlbQB/B9zt6q7xQf/G9Tcggj59c 75wIGNztY7QAcRSh/+DICDS2z4uOkC7kCwFxcIWQRk/LTc2S04ORwWRwQvrwI3t8bMEH rTPQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@windriversystems.onmicrosoft.com header.s=selector2-windriversystems-onmicrosoft-com header.b=VlbDaH8q; 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 g12si20071110eje.114.2020.12.29.02.52.36; Tue, 29 Dec 2020 02:52:59 -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=VlbDaH8q; 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 S1726203AbgL2Kvu (ORCPT + 99 others); Tue, 29 Dec 2020 05:51:50 -0500 Received: from mail-eopbgr750040.outbound.protection.outlook.com ([40.107.75.40]:56385 "EHLO NAM02-BL2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725866AbgL2Kvt (ORCPT ); Tue, 29 Dec 2020 05:51:49 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=NFUnNm4eKDgTw4LZNESKqdtkoklm4dPygXSEiYtxU/H89k/RINkmwy18AapN8BpR7ZpBW0d1tWdDz10dSBy/QbmM6jf+Rau9owtz8S2vTbJMP0PVbLLPO5ukU3px0wywhHXMcikCnzLyxDwwDT2WAd3qNqhbPmJKHnY4qfWHCUuhniZJCPCrhCHZrlQeKv5sa9JrzdP6FyR78ZldskpCAb7jhU9qlHJ6nrN1u0FhoHmwUXqoahrzG1oy0jDmXvqWtz4ZZjDm8z/mYYMBut2hD4C/jYT6Urb7C/acSpRdK+cq4HPlt/r3nd/ePWJ7Yz4OLmk/QxLM/Y7bZvVEJdqSKg== 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=mjU5BmwXOze4RzKoNjECXt34IBYswkpNDNJCOrIzPGE=; b=H+8P848g5Z6uUNDqcGk3j5emMNzmK+nH+0AjukvFHEmCOp1NrpfLOAytd45tjvCHoRkg9K2+r2vXLnwJRCPYEe/idTczf4WuK6NyIKvnJnF/iS5qpohrC4uEweru6yiVoNqCg8J/ccUUtd159064YpvIGuAFn3CYnR4oLr1heh7JYM5NHEpYB4SLO2S9OtUeZUTekfSzCvPYWRRnHXC1dKJKg7URrUHBmjVuwVinNwvoDREmAOoaUI74UHJnmW2DMuq+3OyHfQKPCcpl0XOz6m/LwSIRf39agg/mcNTMbod19Pt4HSvI5o9IwkHYBlQck8zwbdoaHWU0UONxjkvh9A== 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=mjU5BmwXOze4RzKoNjECXt34IBYswkpNDNJCOrIzPGE=; b=VlbDaH8q7+NBRRymTuW4Hb/Dc0W5Hz3tRMxoeR9tQ4g7fMAs2IKjkYxBrisnpCE85/uCYINh8dBJNSbAIdI/PSBK0dWR6CgaW0v6uBkyoWpvaDU1bQ1U0IyxynKbxBnEZVIYVncrgcF07XtRBiWwYcPqtuZw6tysQRNuj/JfubY= 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 PH0PR11MB5191.namprd11.prod.outlook.com (2603:10b6:510:3e::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3700.29; Tue, 29 Dec 2020 10:51: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 10:51: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 v3] regmap: debugfs: Fix a memory leak when calling regmap_attach_dev Date: Tue, 29 Dec 2020 18:50:46 +0800 Message-Id: <20201229105046.41984-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: HK0PR03CA0115.apcprd03.prod.outlook.com (2603:1096:203:b0::31) 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 HK0PR03CA0115.apcprd03.prod.outlook.com (2603:1096:203:b0::31) 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 10:51:02 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: f16013c9-99ed-45f2-1698-08d8abe7a344 X-MS-TrafficTypeDiagnostic: PH0PR11MB5191: 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: 9RieKCx+UjzAwM8bfvg87HNkBeemMMg120HnP61ogCOCtbp6jPjyNdSo3ryc+SgQ15Nf/qRVfZ2QA1DYFYVBsln+SxIS9H2Yf1pT7296iGV2gfkDUSlFzJ7aaoNtyYL5dS0UFekX3/3nLxHrNO0+ysv+5tIzozCSRPxwuPkTvB5Z07lYWhVTWnxxWQ46J17y842o98B6iIVft7s8uG2P9JPyRSqRJkfXYFwhHMc5Yupm3x1iXTFjeeCmbJ5o3YoEzXfTnv/36alTzTuqgN55vPa31CRnlKjR39TKDOZ7EOP7WbB5kP9Tfl15/uDM/4sbNwPmJsEinVFNYxaPKmI437ez7uz4mO3yQBprdIJMSnxXaxKQToXMTvEbQWsAugY2L+S+70TA+ueXqJrDGc5YCA== 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)(39850400004)(396003)(376002)(346002)(366004)(136003)(6512007)(36756003)(186003)(316002)(66556008)(6506007)(2906002)(66946007)(86362001)(1076003)(66476007)(5660300002)(4326008)(6666004)(44832011)(83380400001)(6486002)(16526019)(956004)(6916009)(8936002)(8676002)(478600001)(2616005)(52116002)(26005);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?us-ascii?Q?ORJ4AsNxY0sCmDXMdE4gW7DKUfWw+oJ+tYrpMlGnEMko5cYA1+b0NXOvBnve?= =?us-ascii?Q?rpcfmaVvM84IEWzt7g87Zj538dXkoOO+Cemzx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ubuaTutEmwkvn13PjElpTi79/cyTXXNTIdrTKKoFW?= =?us-ascii?Q?AEFO?= 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 10:51:03.6405 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 8ddb2873-a1ad-4a18-ae4e-4644631433be X-MS-Exchange-CrossTenant-Network-Message-Id: f16013c9-99ed-45f2-1698-08d8abe7a344 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: BnSIGTg3Ka1ndbuflpFubM1ujS4UTmzMtDu2o5BYhfUANA1MTkdYkJk8J8ok2HZBhQ3TsLLEfjOSWUn7vpKnMGbB6rldtGnbHnXsg15HTuo= X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR11MB5191 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 Fixes: 9b947a13e7f6 ("regmap: use debugfs even when no device") 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