Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp1498478imw; Tue, 5 Jul 2022 10:29:54 -0700 (PDT) X-Google-Smtp-Source: AGRyM1s9jJKqee52AUNKCJIQb7nvaHLelpXKynyjK6GXV2BlNPzTcu/O5woH8XThiGF4fyZ2Q1rq X-Received: by 2002:a05:6402:4244:b0:437:726c:e1a with SMTP id g4-20020a056402424400b00437726c0e1amr49171603edb.107.1657042194119; Tue, 05 Jul 2022 10:29:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657042194; cv=none; d=google.com; s=arc-20160816; b=HELQR+Shu5pjS3pQkX6OCZTRrV3DZzMDcUSomznf+QGUBPsFvLom1F6+g1IkkIflzZ Vtpj6usj0CyI6CDIA1U1sTzB8mjUgwDwmFumZrRI++AVqQSkdjwc+xOjNwzB6ecRxWhC VU+G0iErXPkKZW4cr5rduC3xdcKLlndY/VNAvLQIgz1RFeLgWbgyW0OFPKWl44z6kjRB uszo0KXwKyUsjKUjYhWN6fcFvh59lg/7XMIQcYrmKFq1gX+P4/daGZtZ4TiJ2LNRmwiP Qkao3STPLrxkqRf19VLK2W51uS5/7swPN6NsMdEGO+eQOGhfXMTZh67WqINAg2HUzTSn qAXg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=DibX9iQEUFrXxkIm9PYaQ+YczA5+PDT4pu/k9a93CZ4=; b=XoHz4Icuju8ultnwPatsrmWsi5enYfRrcOTmScBq/hTXeeQdcT6FLtavv8KrjVyfsm nruHYLNfWaQSfjO/nx+2IbiQmR1XihR3LzBHRIhNimGMMSEtPUD7pifXH9wspYJXp5PB ohcektfFQ+alNhQ1oCweFh3JV+hGlRE9WBdIe72ScLbzfINg76s+L3yUBq2jMOBTZES9 M6c8Y4Fnw5AEf8IGJo8NGEDuSMECCQIlmlwxZziMD+qE/7ggj+7YHgjFy3X7q0fZOyZS 38oozV8cQD2HSnwrtbuPaGhvZreTd99SG4oTJVWMY21Q2RiAXShBtsljVNVtIoyGz5KK JJnA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=nK5H+j5Z; 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=chromium.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i8-20020a05640242c800b0042d91401df0si20347703edc.133.2022.07.05.10.29.28; Tue, 05 Jul 2022 10:29:54 -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=@chromium.org header.s=google header.b=nK5H+j5Z; 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=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231414AbiGERR6 (ORCPT + 99 others); Tue, 5 Jul 2022 13:17:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39708 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229905AbiGERR5 (ORCPT ); Tue, 5 Jul 2022 13:17:57 -0400 Received: from mail-vk1-xa33.google.com (mail-vk1-xa33.google.com [IPv6:2607:f8b0:4864:20::a33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7458E1CFD0 for ; Tue, 5 Jul 2022 10:17:56 -0700 (PDT) Received: by mail-vk1-xa33.google.com with SMTP id j15so125260vkn.7 for ; Tue, 05 Jul 2022 10:17:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=DibX9iQEUFrXxkIm9PYaQ+YczA5+PDT4pu/k9a93CZ4=; b=nK5H+j5ZR39sYeXQoPrCBk/xTcXYb0lrGz/hZhHBtPek2kaE+xuCcYjTmZZBb5J4IZ VFXFAj0a3LAS8jtJhbS4PtkPhPg1CjfV00iuEL+oI3k5WQYaDFov2C6t9uju9W509TwD /5RBMO3qIpkp6DxPnVoIw5VeFwEi5JWiEJotw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=DibX9iQEUFrXxkIm9PYaQ+YczA5+PDT4pu/k9a93CZ4=; b=4/xnd39k26sbwxLDG/09tUQh1OWLf2lf7vDeCogfu5uOW8BXp1ISNsGFEjBExj5LSC RVwiuo8cSfdKVkcGt8CmSXx82MtRAZkuob9Q/4NoR1KMe3JgdEvqG/arSzNBzAvJPgtW OXnd44+sPTZPr1WJM8S1KAH+qErxXKvW04fU2BAY5N0efxX8NFHg9dndCtBOMbcXiNTp Nj6Ayb9mwuNHYK8usFL41ujeWez5Su9F0KcxXUxeIQIUUhB6g+W2j3VEj24swtFRtDcQ 11QjeEUw5/WOu8rE9yD/RZZOFfhLLR31/AzQ0iQ9/iRiPcIyo/QN4atRgkTtWUiC2FSl l/yQ== X-Gm-Message-State: AJIora9yRyaK/PWZG3q6PTIBW4mh5uuPtfIJ7IkV/K5eSFcYY2LBAAp8 e+B/rAD3af6FqnDCZuew7soW1FhYKOu1yaPp3usKJw== X-Received: by 2002:a05:6122:152b:b0:36c:2e3f:599b with SMTP id g11-20020a056122152b00b0036c2e3f599bmr21318514vkq.5.1657041475532; Tue, 05 Jul 2022 10:17:55 -0700 (PDT) MIME-Version: 1.0 References: <20220705094946.827697-1-hsinyi@chromium.org> In-Reply-To: From: Hsin-Yi Wang Date: Wed, 6 Jul 2022 01:27:07 +0800 Message-ID: Subject: Re: [PATCH] PM: domains: Ensure genpd_debugfs_dir exists before remove To: Greg Kroah-Hartman 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 Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, 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 Wed, Jul 6, 2022 at 12:26 AM Greg Kroah-Hartman wrote: > > 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. > Done. Added in v2. Thanks for the review. > thanks, > > greg k-h