Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp5542053pxb; Tue, 16 Feb 2021 00:48:20 -0800 (PST) X-Google-Smtp-Source: ABdhPJw0dRf4YX8grCVScPsYzxEkq3sCIfqmFhljeokMvN228DhjAmSI1SO9Sc+LUF077cjfec3x X-Received: by 2002:a17:906:1118:: with SMTP id h24mr19552365eja.145.1613465300609; Tue, 16 Feb 2021 00:48:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613465300; cv=none; d=google.com; s=arc-20160816; b=hyhVkE34q0q0p6nCFoKeXO+XP+RuXV+tEENKL4iEWqZgwxfWD+shmetYfiMzjlS1/F vpIayZ6kloBfSD6gsj5Y/euB+s3RUcT0vgxOIbWVuv8TLR77FLkuQomzAJkihnXugelQ DPG0brmtx/pz/Qyx2mqU+rVsBp5FWoWI1ekam6nn6qXYBPzFqX5qLnF+ZGITxWsITc4I lutYCEyKwltEm3MReduoehfyuui6JEP4HmYmqp54x/QddvXWWRDONfqnI0oyM5FijAgJ Zydb0kxMFMNckdAqFc4kZWV8BhwWIThgJ9KQhw/ZCvNGSISG+XLG3NqA2xNB8pR2H6Nv oa4g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent:references:in-reply-to :subject:cc:to:from:message-id:date; bh=oZKWHaFWt5NRaW6+w5Ts4tSK3XoqZDXd7bvYXSWykLA=; b=GfwsKbkN7pHT135DcS0bpuvxuQWZ8yKC0fYvMFiF+6YAw7ATrE9M4outmDUgRytQih KwBbqLRNcH4T+WF35PEtCJDhgwz+kEEKFW2bmlU4HZzGCm/Evdol/RQQ4uacuewvqcfi jb+TkUWhPvfH/9QwoDJ4FEbyOFJXg4WL2wPRH1Lwgz1UFY/4hZU9G7DSKLkani6Mn0I6 NPHLFzey4aHCN/XQzekYHroElxwrNJIVkN9HmRrQxFiXYVdvF1I78OVZdVekMb0LP+kE l3PATQFwg544o+21rg8k9NMF0K2eN1WetzfvseVAqjJatCzVH4hZT9KgtPZhinWIbgwb +dhw== ARC-Authentication-Results: i=1; mx.google.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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c11si18569964edj.397.2021.02.16.00.47.57; Tue, 16 Feb 2021 00:48:20 -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; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230028AbhBPIqU (ORCPT + 99 others); Tue, 16 Feb 2021 03:46:20 -0500 Received: from mail.kernel.org ([198.145.29.99]:44624 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229994AbhBPImx (ORCPT ); Tue, 16 Feb 2021 03:42:53 -0500 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 Cc: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kernel-team@android.com, Lee Jones , Arnd Bergmann , Suman Anna 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") Content-Type: text/plain; charset=US-ASCII 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 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.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.