Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp1470017imw; Tue, 5 Jul 2022 10:02:46 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vXHNVj5lXYX5LtaAN+LgA2Lj4ckqK2U/rVmOMbj5G68PaW96UprRbG6c0iRjZxV8W3prdS X-Received: by 2002:a17:907:a04b:b0:72a:ee53:7d2e with SMTP id gz11-20020a170907a04b00b0072aee537d2emr2035847ejc.764.1657040566309; Tue, 05 Jul 2022 10:02:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657040566; cv=none; d=google.com; s=arc-20160816; b=nGW1yoR0IE9PsAd1sYNif6F/0H91jjE+KJf5a1TKO7ylrGv+tlFYy6aj7hL4FaU/ZJ Cwd5O8C3twPURRhp+XnNUsVrbViI22Ua0TAnfZqbosN5sD28UURUm+jWH9hoZwAKSFQW tTAfkuCNwOBiLK7j9zPmXtgbWMk47qGntTC3k8B0bhOnI9g1okRcuOT8Znq2VkLan+Tw nE797Khe5SrjnL3B4bX5P83u1mu7ru3mYMPviMsBVnfUOkiaUF7d14FT/UBJE2luyjMW R/fm8dx1I4kVUuHmuCzeYZJeaM1aKKvtTwC8hy2xaFOT8aNui3mhoWymQYfPW9gak0Ps LsUg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=/iuLMYSL6t+1a50V/fN7TLQ4oR+AtopgJxRCTfxK0n8=; b=zGoO+FPkh8CzdXnGE9Y3LiBCoIupz4WFEzgWEfuEANWYXQw3Az2UJD+f8LmCZrDN5r 3ZJZgMJVJA8dIz9RCUq+oJM5r8j/SdAiT97GoW4GS2tX59KtDmAwCl6jAUojnckxw0ag UMLNGQYQ8VIuIRjnOjEH2uJ5k30PrnRa7jXcX06wskC1OOjlKsRpojqcfiGxEIXmx/oZ p4vLfxbBADy8crgF54rDtb1LGFnliec++XEoTH31TTl8lnImR/ocPnWrSKbtQMQcHwFP PVPBTxqWeZmI8sxocs461xN8OV6tlZBb9CK79tcGQkBJhsHYOSTz8Onw5okE7Ol8xcce f0UQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=kWxNROmp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ne23-20020a1709077b9700b006feb04902a8si31972737ejc.824.2022.07.05.10.02.21; Tue, 05 Jul 2022 10:02:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=kWxNROmp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S231560AbiGEQ0r (ORCPT + 99 others); Tue, 5 Jul 2022 12:26:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52064 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229554AbiGEQ0q (ORCPT ); Tue, 5 Jul 2022 12:26:46 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 31AA715717; Tue, 5 Jul 2022 09:26:45 -0700 (PDT) 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 BEB2D61BF4; Tue, 5 Jul 2022 16:26:44 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A223FC341C7; Tue, 5 Jul 2022 16:26:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1657038404; bh=xdkJ7dDI1TMRfLqibzYhOTOYetxZoqPZfydt+biEvLU=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=kWxNROmp9R1w+sHCDwq34HpsR/P/bYP1YyJTlrBFRbzTTg1TGK4+UACqqGtEX8q4G g8mdzVIhDrzuFPp3Qv9PHUaBpduIKfMkmybADyOSNU0uVrYi633TcgBVpf0wElooP8 G5gtLo7aYlN9if14nJafisUEhLkGNABol3TP8Kcs= Date: Tue, 5 Jul 2022 18:26:41 +0200 From: Greg Kroah-Hartman To: Hsin-Yi Wang Cc: "Rafael J . Wysocki" , Kevin Hilman , Ulf Hansson , Len Brown , Pavel Machek , Thierry Strudel , linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, AngeloGioacchino Del Regno , Pin-yen Lin Subject: Re: [PATCH] PM: domains: Ensure genpd_debugfs_dir exists before remove Message-ID: References: <20220705094946.827697-1-hsinyi@chromium.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-7.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jul 05, 2022 at 11:58:52PM +0800, Hsin-Yi Wang wrote: > On Tue, Jul 5, 2022 at 7:51 PM Greg Kroah-Hartman > wrote: > > > > On Tue, Jul 05, 2022 at 07:06:41PM +0800, Hsin-Yi Wang wrote: > > > On Tue, Jul 5, 2022 at 6:38 PM Greg Kroah-Hartman > > > wrote: > > > > > > > > On Tue, Jul 05, 2022 at 05:49:47PM +0800, Hsin-Yi Wang wrote: > > > > > genpd_debug_remove() may be indirectly called from others while > > > > > genpd_debugfs_dir is not yet set. Make sure genpd_debugfs_dir exists > > > > > before remove the sub components, otherwise components under > > > > > /sys/kernel/debug may be accidentally removed. > > > > > > > > > > Fixes: 718072ceb211 ("PM: domains: create debugfs nodes when adding power domains") > > > > > Signed-off-by: Hsin-Yi Wang > > > > > --- > > > > > An example: > > > > > scpsys_probe() in drivers/soc/mediatek/mtk-pm-domains.c indirectly calls > > > > > genpd_debug_remove() on probe fail, causing /sys/kernel/debug/usb to be > > > > > removed. > > > > > --- > > > > > drivers/base/power/domain.c | 3 +++ > > > > > 1 file changed, 3 insertions(+) > > > > > > > > > > diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c > > > > > index 3e86772d5fac5..5a2e0232862e0 100644 > > > > > --- a/drivers/base/power/domain.c > > > > > +++ b/drivers/base/power/domain.c > > > > > @@ -222,6 +222,9 @@ static void genpd_debug_remove(struct generic_pm_domain *genpd) > > > > > { > > > > > struct dentry *d; > > > > > > > > > > + if (!genpd_debugfs_dir) > > > > > + return; > > > > > + > > > > > d = debugfs_lookup(genpd->name, genpd_debugfs_dir); > > > > > debugfs_remove(d); > > > > > > > > Why not just change this to be: > > > > debugfs_remove(debugfs_lookup(genpd->name, debugfs_lookup("pm_genpd", NULL))); > > > If pm_genpd hasn't been created yet, debugfs_lookup("pm_genpd", NULL) > > > will return null. > > > > And how is this codepath being called if pm_genpd is not created yet? > > Surely you are not relying on the presence of a debugfs file to > > determine that? > > > > Caller didn't directly call genpd_debug_remove(). The flow is as follows: > > Normally, scpsys will create pm domain by: > scpsys_probe() > --> scpsys_add_one_domain() > --> pm_genpd_init() > --> genpd_debug_add() > > > If something fails, it will do the cleanup: > scpsys_probe() > --> scpsys_domain_cleanup() > --> scpsys_remove_one_domain() > --> pm_genpd_remove() > --> genpd_remove() > --> genpd_debug_remove() > > genpd_debug_add() checks if genpd_debugfs_dir is init by a > late_initcall genpd_debug_init(). If it's NULL, it will return > directly without creating anything. Later when genpd_debug_init() is > called, it will call genpd_debug_add() again. > > pm_genpd_remove() still needs to be called on the cleanup path to free > other stuff, but if genpd_debug_init() hasn't happened, > genpd_debug_remove() should be a no-op, or genpd_remove() shouldn't > call it. (We can move the check there, but adding in > genpd_debug_remove() is more similar to what genpd_debug_add() > currently is.) Thanks for the details. You might want to include this in the changelog text. I'm ok with the change now if that information is in there, I missed that there are paths to create devices before debugfs is initialized. thanks, greg k-h