From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-14.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D4619C433E0 for ; Tue, 16 Feb 2021 08:44:14 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 84AB564E2B for ; Tue, 16 Feb 2021 08:44:14 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 84AB564E2B Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Subject:To:From: Message-ID:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=/sMWYB845OD0+i2lIgzNuxdfQrNqC0PNudKW7bVgxhs=; b=SEKwXCIaYDu9RvcsWZckwsLkC r2hzpBNeunv25m812nwj01+YYwmBczPlBvCkr0My6Yg/7jKxGWwyk3eqiTSPJFRF8YwfqQ6/zctdT 20okaLrkLctQb53wV2K9K05/1WdCvYB5JyIB3sEMVu5zXOzetkN4UvLpATo+2kbf0WKnkFckURJWs HGFaBVFvY7uqqdtRkL1ipS1f+W1AVuNcZnmQ9zJcfVhHY1XQhzaeGo5Zwo1GLMwWLxVbWnMo3OlSi YIqtXTYTYmwn5rPtV18zNHlGbg7ldLn51gdxFZbQrF3pQJTUgpPbYWmBmXvDlpCGiwtiTH/F07rcP /jKcVQ+WQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1lBvw0-0005h7-Us; Tue, 16 Feb 2021 08:42:16 +0000 Received: from mail.kernel.org ([198.145.29.99]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1lBvvy-0005gb-Ao for linux-arm-kernel@lists.infradead.org; Tue, 16 Feb 2021 08:42:15 +0000 Received: from disco-boy.misterjones.org (disco-boy.misterjones.org [51.254.78.96]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 1610164E00; Tue, 16 Feb 2021 08:42:13 +0000 (UTC) Received: from 78.163-31-62.static.virginmediabusiness.co.uk ([62.31.163.78] helo=why.misterjones.org) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94) (envelope-from ) id 1lBvvu-00EOXz-Uy; Tue, 16 Feb 2021 08:42:11 +0000 Date: Tue, 16 Feb 2021 08:42:10 +0000 Message-ID: <87pn10pfod.wl-maz@kernel.org> From: Marc Zyngier To: Tomi Valkeinen Subject: Re: [PATCH] mfd: syscon: Don't free allocated name for regmap_config In-Reply-To: References: <20200903160237.932818-1-maz@kernel.org> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL-LB/10.8 EasyPG/1.0.0 Emacs/27.1 (x86_64-pc-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") X-SA-Exim-Connect-IP: 62.31.163.78 X-SA-Exim-Rcpt-To: tomi.valkeinen@ideasonboard.com, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kernel-team@android.com, lee.jones@linaro.org, arnd@arndb.de, s-anna@ti.com X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210216_034214_488113_5B79026C X-CRM114-Status: GOOD ( 26.62 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Arnd Bergmann , kernel-team@android.com, linux-kernel@vger.kernel.org, Suman Anna , Lee Jones , linux-arm-kernel@lists.infradead.org Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Hi Tomi, On Tue, 16 Feb 2021 06:34:50 +0000, Tomi Valkeinen wrote: > > Hi Marc, > > On 03/09/2020 19:02, Marc Zyngier wrote: > > The name allocated for the regmap_config structure is freed > > pretty early, right after the registration of the MMIO region. > > > > Unfortunately, that doesn't follow the life cycle that debugfs > > expects, as it can access the name field long after the free > > has occured. > > > > Move the free on the error path, and keep it forever otherwise. > > > > Fixes: e15d7f2b81d2 ("mfd: syscon: Use a unique name with regmap_config") > > Signed-off-by: Marc Zyngier > > --- > > drivers/mfd/syscon.c | 2 +- > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > diff --git a/drivers/mfd/syscon.c b/drivers/mfd/syscon.c > > index 75859e492984..7a660411c562 100644 > > --- a/drivers/mfd/syscon.c > > +++ b/drivers/mfd/syscon.c > > @@ -108,7 +108,6 @@ static struct syscon *of_syscon_register(struct device_node *np, bool check_clk) > > syscon_config.max_register = resource_size(&res) - reg_io_width; > > > > regmap = regmap_init_mmio(NULL, base, &syscon_config); > > - kfree(syscon_config.name); > > if (IS_ERR(regmap)) { > > pr_err("regmap init failed\n"); > > ret = PTR_ERR(regmap); > > @@ -145,6 +144,7 @@ static struct syscon *of_syscon_register(struct device_node *np, bool check_clk) > > regmap_exit(regmap); > > err_regmap: > > iounmap(base); > > + kfree(syscon_config.name); > > err_map: > > kfree(syscon); > > return ERR_PTR(ret); > > > > This patch causes lots of kmemleak reports, for example: It may trigger some kmemleak reports, but at the time it was written, this patch avoided some very nasty memory corruption with debugfs. The problem is that the memory management responsibilities between syscon, regmap and debugfs are rather obscure. If you can come up with an accurate description of the life cycle of syscon_config.name across these 3 subsystems, we may be able to fix it for good. Thanks, M. -- Without deviation from the norm, progress is not possible. _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel