Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3702178pxb; Mon, 24 Jan 2022 15:48:06 -0800 (PST) X-Google-Smtp-Source: ABdhPJw6OehrbWoYyKqWGN9aIGAg6nI6Y9XtoGBY7M+jE5dVX7U02AMwrE7Fp7BrlbapqlHk09WG X-Received: by 2002:a17:903:22c4:b0:14b:4035:e166 with SMTP id y4-20020a17090322c400b0014b4035e166mr9455785plg.144.1643068086017; Mon, 24 Jan 2022 15:48:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643068086; cv=none; d=google.com; s=arc-20160816; b=cIPCvmIazAvjOvLZ1Fi1MkpjQCE92H01gclgj6ajysLefepWmt42pqjXoBL+ZeO9tc 0LzsZNnSyTqXrMXUkMSm2IbqeXh5qotPqIEKzkz7a7+NvOZRop1UmPPcmpbIy2dNB7MW e3UkBJTOQLX9mMWS8lkZYFQCkJB1TqQ88IUhbVLZHXTRstWkI2wriH7CWgvGvNySmJCO jDsp36fu+UNcbhGbiMrQHayH0Kj63+p2e/B5seY+JRWreWM5SMfuugobD6n7flg8HmvG wW/Hzvo6+spWl0dyib2W81hmFQYg8IYBiMb+0k+mo5QntBcsAflTim4C0jU7+KoQXl+I ZjPA== 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=DcazNjtVeJmwpO68+eEW27IeAsgFF8cuuM7h0wmKbms=; b=YohQVEjQbKsIAtpoxKASFUKMhuE4EbC6SIbwCxqF96uoVwSA0S5nM7AeYO2vFUt7/C FlV/zvTnym3W62vVrvfZhiQcuWzxPEWN+Js382uzIKwwEFkEDRmdjx649RS7ebdQnXBS OX+hvDwJX7XC0m+rw0rura+eLWkcUrN6SPj435+DfD+V5SNB0Vaa8fKSJt6hloZoO6mH h/RmYtoxMlEZb7tFuhSCn5OvZYenhEvonfQRfLP7ezaFk9niMh9e4my2ieisWSrGlz6A qRtEES3YT7DLRN/EDbF5/d1YVoBGo4Rk+ov+esoAeA98g5I5xg+dHsMzVat/INw5as+B SKgw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=qxpMUVYL; 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 n4si687181pjo.27.2022.01.24.15.47.54; Mon, 24 Jan 2022 15:48:06 -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=qxpMUVYL; 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 S2361964AbiAXXlS (ORCPT + 99 others); Mon, 24 Jan 2022 18:41:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47298 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1842620AbiAXXCS (ORCPT ); Mon, 24 Jan 2022 18:02:18 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D8229C06C588; Mon, 24 Jan 2022 13:14:26 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 74EAD614D0; Mon, 24 Jan 2022 21:14:26 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 51F84C340E5; Mon, 24 Jan 2022 21:14:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643058865; bh=GG2VcJaBszp1adCiwTCfU7WT3BqNfJaDko/ghevEf3Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qxpMUVYL/hN56iz0uwkZutEZ8xvzg5x3tnBDRSxWPsKUDDTuxMFzdgDYSClmezHCs k5c+2QNlfywmGmGsOia97syrJ5mqomCf6zn7CxzsjpPrgZMWVMK2HQrhSaQveGukZc rAdBHF4EbRpYsS/i1s3Y7tbmjk07xfFZEF3k+sf4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Mark Brown , Fabio Estevam , Sasha Levin Subject: [PATCH 5.16 0427/1039] regmap: Call regmap_debugfs_exit() prior to _init() Date: Mon, 24 Jan 2022 19:36:56 +0100 Message-Id: <20220124184139.652270158@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124184125.121143506@linuxfoundation.org> References: <20220124184125.121143506@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: Fabio Estevam [ Upstream commit 530792efa6cb86f5612ff093333fec735793b582 ] Since commit cffa4b2122f5 ("regmap: debugfs: Fix a memory leak when calling regmap_attach_dev"), the following debugfs error is seen on i.MX boards: debugfs: Directory 'dummy-iomuxc-gpr@20e0000' with parent 'regmap' already present! In the attempt to fix the memory leak, the above commit added a NULL check for map->debugfs_name. For the first debufs entry, map->debugfs_name is NULL and then the new name is allocated via kasprintf(). For the second debugfs entry, map->debugfs_name() is no longer NULL, so it will keep using the old entry name and the duplicate name error is seen. Quoting Mark Brown: "That means that if the device gets freed we'll end up with the old debugfs file hanging around pointing at nothing. ... To be more explicit this means we need a call to regmap_debugfs_exit() which will clean up all the existing debugfs stuff before we loose references to it." Call regmap_debugfs_exit() prior to regmap_debugfs_init() to fix the problem. Tested on i.MX6Q and i.MX6SX boards. Fixes: cffa4b2122f5 ("regmap: debugfs: Fix a memory leak when calling regmap_attach_dev") Suggested-by: Mark Brown Signed-off-by: Fabio Estevam Link: https://lore.kernel.org/r/20220107163307.335404-1-festevam@gmail.com Signed-off-by: Mark Brown Signed-off-by: Sasha Levin --- drivers/base/regmap/regmap.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/base/regmap/regmap.c b/drivers/base/regmap/regmap.c index 21a0c2562ec06..f7811641ed5ae 100644 --- a/drivers/base/regmap/regmap.c +++ b/drivers/base/regmap/regmap.c @@ -647,6 +647,7 @@ int regmap_attach_dev(struct device *dev, struct regmap *map, if (ret) return ret; + regmap_debugfs_exit(map); regmap_debugfs_init(map); /* Add a devres resource for dev_get_regmap() */ -- 2.34.1