Received: by 2002:a05:6a10:2785:0:0:0:0 with SMTP id ia5csp13836pxb; Fri, 15 Jan 2021 04:42:02 -0800 (PST) X-Google-Smtp-Source: ABdhPJx7YSvM61kzWjD2DzS/UfsHxSfYHqVG9ulKQky8Sf6h6tQWNr+T0ZaIhrlMoAmg+/jA/wu9 X-Received: by 2002:a05:6402:40c4:: with SMTP id z4mr9244989edb.233.1610714522109; Fri, 15 Jan 2021 04:42:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610714522; cv=none; d=google.com; s=arc-20160816; b=cTj9YXzQai7b5n+dlSLSc0NZ4J1UZT2Ht7z/4dSOrQKdHgKnizb66tH42ZGFtG1W8L Wf45wh3EGvvY/98aqtp0J6J3fvB6A2f17B3cR5EbtqTneqkvsrYbFCOGfFSVcQnn+QZk bUZCdItA+tfTlsyi5tz503TvlTJki0mfcycAIaYjlh+J50cCaX+2zXUX9gBJjijThnPQ hZNDVBZNKBpBQ4K75OB20Nhj2wkgeakYnBZvb+lNwcc0SkaZ2Aq28RR3FbRLj387TUBt ETIFOO++6q1oOIPO3bOIzDKGH9m8XdF5NmdaiZfqZvKnOjH2dXZl7XUAdzBhpi6estwJ /xgQ== 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=bFda146F9y37LMmeiSMh1z8W1nmMkfmge7+9gXUq68Q=; b=weJNuTCIhgsGs1Y0lyOiCmOTBEYqi8fFYzgVd/x14wJ5gZEEC8c8fwkz2iclDynAqB vztEDyAO94+ZAnD7QgfjFU2YxFQB9hhv6zcpviS+JalK2LOuNSB1/tTnVo8YfsjlrtqI YEaKVf/tv1b6hf20P9MubPY92DR7LekhzYELW6r8Q986QlaAKidHn3HTgK5PacHUcfqy wSf2tpOPOHze0rdN7Kwx0pXiEQRq7I0Y/wVlELrM7ZuIb+KgZ2x/75ug1GSeHld88v4N svUVpPzO9qgtrb8YMcPpUfgzpBEjXpNd7yuKtO9t6m+djaQ0C4GcJiTada1PgyEp7kNt WW/A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=1WUlNNus; 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 ss12si3617061ejb.55.2021.01.15.04.41.38; Fri, 15 Jan 2021 04:42:02 -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=1WUlNNus; 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 S2388264AbhAOMjI (ORCPT + 99 others); Fri, 15 Jan 2021 07:39:08 -0500 Received: from mail.kernel.org ([198.145.29.99]:46210 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387713AbhAOMjE (ORCPT ); Fri, 15 Jan 2021 07:39:04 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id DE091235F8; Fri, 15 Jan 2021 12:38:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1610714328; bh=TveOYa+LMTSthBO63qsOiK/LZioXtOenl+OY9Ieh5ko=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=1WUlNNusOMRDeQKa060w7eMYUYQXUlYAr5igSzPReQwRxPWN/1ZwlG8VLkMn/kizt UQuWS/jSp/rqoMtcC8F8/KWlrAP7VzCxJB+sOD8unIdApxOnoB4+mZtQQzO2ni9Y9+ y0BQT5OQ6NFkpQaskoTmBSOed5jdN7eSr2y8FOKs= 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.10 086/103] regmap: debugfs: Fix a memory leak when calling regmap_attach_dev Date: Fri, 15 Jan 2021 13:28:19 +0100 Message-Id: <20210115122010.175920983@linuxfoundation.org> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210115122006.047132306@linuxfoundation.org> References: <20210115122006.047132306@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 @@ -582,18 +582,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++; }