Received: by 2002:a05:6a10:2785:0:0:0:0 with SMTP id ia5csp19315pxb; Fri, 15 Jan 2021 04:51:25 -0800 (PST) X-Google-Smtp-Source: ABdhPJyfKT4yrxXzVMTe9JB2Op4sDziJgXcBAouMxtBSeVpNrOgAo188phuKgO0guyIRmmVuT+Tn X-Received: by 2002:a05:6402:100c:: with SMTP id c12mr9868803edu.356.1610715084966; Fri, 15 Jan 2021 04:51:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610715084; cv=none; d=google.com; s=arc-20160816; b=EQA2JYRK+CjDuRtXj2R3ugHJTUaF6YNf0imIagMF6xOvap3EunWlaZivCehmKh5qIK Owme0s9uPdph7dVa5p+PWr0tfSvwaGLDqsYy1FJrksXIUrNKv34Twv5UydHi5x/h1J8O UFlweO5Hx5pSk9sk1JSntwtLC/AznREZASpEmuaJCies9E7thliSrYHOytqr8EgVY/11 aWKmh0FJZJfmVxE1+c5bjIMfTahkcHVnyKHcOLu3MBIWWkc6advLnMMoS+r9G1k1UaMl uvnpdmpV2Eivwc+8mm5Aa5Y7kX9nX/wdCwZCcJ0shI7cwAcZQl1Of31otyJaa9vcwWDq TkGA== 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=a5BEbxfYoZvBEDROKnwTtPfSsJORg7qqRu3ZsvIZ7o0=; b=jXzFY1njOd9FcRM9pQdUwc6v5HUTM31hHSm6ZAAX0RHv9PE34E8MGCXsK7bKiWL/I9 z6tnHuZmgM5bgMKw5QELKRbcDOnv9Ffn4pQxWIRWh/li3QGzw4tjouXHETduRq0d2mJm zNOOzxdkm/Ku9egEAgtRDzuhmx/tK4g/uDtXDNXWWFoA5NyXGT4DklBRrwq8+91gK6s2 /jf0Vo/puUxu/taKVnSaChxqzd5U8ljg5i1ZCnrWxKnNI5YPJNA+qhEa2QuGGNQoaoS1 xD+K0A95ByDelz9+maOFNZrSUHNc6WPcHkzVBeLscbEzBdvtGp4nNFTr/WMJCzhaKq/4 7A4g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="2Wc/nOvM"; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q26si3505531eju.216.2021.01.15.04.51.00; Fri, 15 Jan 2021 04:51:24 -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=@linuxfoundation.org header.s=korg header.b="2Wc/nOvM"; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387849AbhAOMgL (ORCPT + 99 others); Fri, 15 Jan 2021 07:36:11 -0500 Received: from mail.kernel.org ([198.145.29.99]:43058 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387788AbhAOMf7 (ORCPT ); Fri, 15 Jan 2021 07:35:59 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 293102399C; Fri, 15 Jan 2021 12:35:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1610714118; bh=JnrR4vsSbpqjqdW8b9BavNLaK+WKxDy4qbB7pMGWGPw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=2Wc/nOvMBYVNxDegG3yaKsmmNqH+m+P6UsKyZ/MYXDfRW0Yk2Gt/WDgebqX4iNCSV wvve6/YMN1GAX6H2XYfePTyKBhw1jdaKgD8A0mbXt+ckGmgUtAyuqv6TEk6gHo+1Na 0fWqWct/oD9j4/0nUzjH/Jk7ezjyzp2RQWXvcwcw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Xiaolei Wang , Mark Brown Subject: [PATCH 5.4 55/62] regmap: debugfs: Fix a memory leak when calling regmap_attach_dev Date: Fri, 15 Jan 2021 13:28:17 +0100 Message-Id: <20210115122001.049398706@linuxfoundation.org> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210115121958.391610178@linuxfoundation.org> References: <20210115121958.391610178@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Xiaolei Wang commit cffa4b2122f5f3e53cf3d529bbc74651f95856d5 upstream. 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 Link: https://lore.kernel.org/r/20201229105046.41984-1-xiaolei.wang@windriver.com Signed-off-by: Mark Brown Signed-off-by: Greg Kroah-Hartman --- drivers/base/regmap/regmap-debugfs.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) --- a/drivers/base/regmap/regmap-debugfs.c +++ b/drivers/base/regmap/regmap-debugfs.c @@ -583,18 +583,25 @@ void regmap_debugfs_init(struct regmap * 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++; }