From nobody Wed Oct 8 02:04:51 2025 Received: from mail-ej1-f44.google.com (mail-ej1-f44.google.com [209.85.218.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D66192E3B0A for ; Thu, 3 Jul 2025 11:27:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751542071; cv=none; b=Kz1EeDc8ubA9K/yLDiKpw1J3Hh0R2DFIhe+1dFVyTXs3XNJTSYz9JX5gpKiGCYptj3FxFkCgh004zRxMbiZSvrNwVwGMrbgim9Bm5aHN728gVHRgjCo4H/xlP43pfgRvX0wRABxPlL6cIXFeeC5aHpo7TXe32OIorLu6H6gNKeA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751542071; c=relaxed/simple; bh=VFHVp92oUtdD8O/al59Afa61BRyaZZLLREdoqIPcQBM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=RSVGt8jeiw/vqNeTCFxK78ibId4XOuviBvl3zzkLspqUtdTdgUqjaS2/9vpGcH3g7qlQOnZdvVKcBwwCD3AecJwTx4fPycNu/fMD/cVIb0Qm6DnCIdRIwSHxfg4yUMWADcFr5+PRdoaLe7RPvUmR/lxZtcVe0JiVEzCjbgCjQho= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=tuxon.dev; spf=pass smtp.mailfrom=tuxon.dev; dkim=pass (2048-bit key) header.d=tuxon.dev header.i=@tuxon.dev header.b=ce9zA/zE; arc=none smtp.client-ip=209.85.218.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=tuxon.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=tuxon.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=tuxon.dev header.i=@tuxon.dev header.b="ce9zA/zE" Received: by mail-ej1-f44.google.com with SMTP id a640c23a62f3a-ae0ccfd5ca5so783432666b.3 for ; Thu, 03 Jul 2025 04:27:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tuxon.dev; s=google; t=1751542067; x=1752146867; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=00v7jImDBQ2eMu0i8J3EDPnWwIf7Eay4sawX2tdcIjU=; b=ce9zA/zEvvLqxk6gQN2n3Y1W4udkQvyd342x9EDUA/DKO4eeV4d+878b9lbaVA6P3V GPqS+Nr3UGfqjvK20PED5zHJjbnopkb/qAmi+Lq1ppJcsqlPQ8+p99FZHpgI21JUBxZX yUETSH2XYRlIBx/nMBZGMbnceR0jwjDGC158FKNSQmPvBeUTfq+lvw1s9v8Pc8R+97oC d6Y3HWPjpzeghPM/Ha+EncWl9K7tjDpLQrto5XP2JcItmnkA2jM0KzU74/ALQ3nrXo/2 Dgu48ckltY1MjfnQ4Kl9t0dkofDf1YDvo06SZx39+8LsrQihhuLO0f8/JodmAGBbFMsp HLoA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751542067; x=1752146867; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=00v7jImDBQ2eMu0i8J3EDPnWwIf7Eay4sawX2tdcIjU=; b=qxEEQhOcUNtgjDAQWHPOsD8rkoNfCf7DpXxqAD9uOzF7Hb0x3ohQZJvjoaY8JiC/ij 8gkqRzkP5hatsQ7YUg/jhdoGw1omXqNhhfF3NZZ+Txo2lrLsrUZ0gpQiSegcof5rpVzj ViEl6LpcSaZFXO3IqIo6iPvQAzb9c8XwUBqpTUJtCwNpWPJvFqBc2iXlJ4ruLyRR+IMn ZqPpF95OZUzubOWvDnueaMixxHC6AgsT+xovYEHMS23gG5oMojZ4YSJ3laDQeJp4M2Ac hw2XPr5ymB++199qGoGpcqZv+82fnpjtpH1zOiYMaS7juFs3NPtjOzQkPRyrYj8m4VQK XIgg== X-Forwarded-Encrypted: i=1; AJvYcCX3ppbninC0mtBpyvvgUCnMNSrZKFrtvJ7tcjZ7QjkI0OS8jGwkFQxKOxDJnicwRSLYJ6D2gVkuV57JzoY=@vger.kernel.org X-Gm-Message-State: AOJu0YynRUpQzVXbWagCIIzeYCs4pnvlvvMHG73krmQCxZh4gvyC2yZt uPa7tWuf0pthtiG5o0P+bJXXW3fDZSkRIyv9H8YwnTeovBk36a9T7HNFF2KUcjehOjg= X-Gm-Gg: ASbGncvLRvhMKEZECyYcIxyKKKbeotqcH7m0Ak3tdO9Uh2m2lHlrI6qCIYiy3jcuXDY TzDSsj/ItowVtNCOxDwsRmgCkMto+R31r743unxWhJaG325al+neBJ7HL9VtJBZ9e4yv5RdZSAk xIuvDP0salBnJQTYSRcSs8tKxysqsctext8S7TUgH+d/J1SUDivW+Ci25nsvp6tJVwnHuVF7PtW Z1lYMVYAzeR6iSn6zBRnoED77Tw4gXEmC3sUGDvI4H5mpzjAKqsbC5EEeYuIebTpLr95GRNJsR5 SqFDDo5PJQEA8cH3744/tgjs4gYXRkSBulE4LLSpIaJhHJd7dxJrmSnv3e7en/Fw59XzwtrqgqP zUEK1PDKZu4KpEdc= X-Google-Smtp-Source: AGHT+IEGjD3eSI1D9oPtbbf+Qd+7ik/ERcGzIN30TUY3t1ZpkWKdf4ycZcaIs03RCZW44chHMZB55g== X-Received: by 2002:a17:907:d8a:b0:ade:4121:8d3d with SMTP id a640c23a62f3a-ae3c2b3bf4amr586271766b.12.1751542066863; Thu, 03 Jul 2025 04:27:46 -0700 (PDT) Received: from claudiu-X670E-Pro-RS.. ([82.78.167.83]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ae35365a75fsm1247016966b.67.2025.07.03.04.27.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Jul 2025 04:27:46 -0700 (PDT) From: Claudiu X-Google-Original-From: Claudiu To: linux@armlinux.org.uk, gregkh@linuxfoundation.org, david.m.ertman@intel.com, ira.weiny@intel.com, leon@kernel.org, rafael@kernel.org, dakr@kernel.org, len.brown@intel.com, pavel@kernel.org, andersson@kernel.org, mturquette@baylibre.com, sboyd@kernel.org, maarten.lankhorst@linux.intel.com, mripard@kernel.org, tzimmermann@suse.de, airlied@gmail.com, simona@ffwll.ch, wsa+renesas@sang-engineering.com, ulf.hansson@linaro.org, mathieu.poirier@linaro.org, vkoul@kernel.org, yung-chuan.liao@linux.intel.com, pierre-louis.bossart@linux.dev, broonie@kernel.org, robh@kernel.org, jirislaby@kernel.org, saravanak@google.com, jic23@kernel.org, dmitry.torokhov@gmail.com Cc: claudiu.beznea@tuxon.dev, linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-clk@vger.kernel.org, linux-i2c@vger.kernel.org, linux-mmc@vger.kernel.org, linux-remoteproc@vger.kernel.org, linux-sound@vger.kernel.org, linux-spi@vger.kernel.org, linux-serial@vger.kernel.org, bhelgaas@google.com, geert@linux-m68k.org, linux-iio@vger.kernel.org, linux-renesas-soc@vger.kernel.org, fabrizio.castro.jz@renesas.com, Claudiu Beznea Subject: [PATCH v5 1/3] PM: domains: Add flags to specify power on attach/detach Date: Thu, 3 Jul 2025 14:27:06 +0300 Message-ID: <20250703112708.1621607-2-claudiu.beznea.uj@bp.renesas.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250703112708.1621607-1-claudiu.beznea.uj@bp.renesas.com> References: <20250703112708.1621607-1-claudiu.beznea.uj@bp.renesas.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Claudiu Beznea Calling dev_pm_domain_attach()/dev_pm_domain_detach() in bus driver probe/remove functions can affect system behavior when the drivers attached to the bus use devres-managed resources. Since devres actions may need to access device registers, calling dev_pm_domain_detach() too early, i.e., before these actions complete, can cause failures on some systems. One such example is Renesas RZ/G3S SoC-based platforms. If the device clocks are managed via PM domains, invoking dev_pm_domain_detach() in the bus driver's remove function removes the device's clocks from the PM domain, preventing any subsequent pm_runtime_resume*() calls from enabling those clocks. The second argument of dev_pm_domain_attach() specifies whether the PM domain should be powered on during attachment. Likewise, the second argument of dev_pm_domain_detach() indicates whether the domain should be powered off during detachment. Upcoming commits address the issue described above (initially for the platform bus only) by deferring the call to dev_pm_domain_detach() until after devres_release_all() in device_unbind_cleanup(). The detach_power_off field in struct dev_pm_info stores the detach power off info from the second argument of dev_pm_domain_attach(). Because there are cases where the device's PM domain power-on/off behavior must be conditional (e.g., in i2c_device_probe()), the patch introduces PD_FLAG_ATTACH_POWER_ON and PD_FLAG_DETACH_POWER_OFF flags to be passed to dev_pm_domain_attach(). Finally, dev_pm_domain_attach() and its users are updated to use the newly introduced PD_FLAG_ATTACH_POWER_ON and PD_FLAG_DETACH_POWER_OFF macros. This is a preparatory commit. Signed-off-by: Claudiu Beznea Acked-by: Wolfram Sang Reviewed-by: Mathieu Poirier Reviewed-by: Ulf Hansson --- Changes in v5: - none; this patch is new drivers/amba/bus.c | 4 ++-- drivers/base/auxiliary.c | 2 +- drivers/base/platform.c | 2 +- drivers/base/power/common.c | 6 +++--- drivers/clk/qcom/apcs-sdx55.c | 2 +- drivers/gpu/drm/display/drm_dp_aux_bus.c | 2 +- drivers/i2c/i2c-core-base.c | 2 +- drivers/mmc/core/sdio_bus.c | 2 +- drivers/rpmsg/rpmsg_core.c | 2 +- drivers/soundwire/bus_type.c | 2 +- drivers/spi/spi.c | 2 +- drivers/tty/serdev/core.c | 2 +- include/linux/pm_domain.h | 10 ++++++++-- 13 files changed, 23 insertions(+), 17 deletions(-) diff --git a/drivers/amba/bus.c b/drivers/amba/bus.c index 71482d639a6d..74e34a07ef72 100644 --- a/drivers/amba/bus.c +++ b/drivers/amba/bus.c @@ -138,7 +138,7 @@ static int amba_read_periphid(struct amba_device *dev) void __iomem *tmp; int i, ret; =20 - ret =3D dev_pm_domain_attach(&dev->dev, true); + ret =3D dev_pm_domain_attach(&dev->dev, PD_FLAG_ATTACH_POWER_ON); if (ret) { dev_dbg(&dev->dev, "can't get PM domain: %d\n", ret); goto err_out; @@ -291,7 +291,7 @@ static int amba_probe(struct device *dev) if (ret < 0) break; =20 - ret =3D dev_pm_domain_attach(dev, true); + ret =3D dev_pm_domain_attach(dev, PD_FLAG_ATTACH_POWER_ON); if (ret) break; =20 diff --git a/drivers/base/auxiliary.c b/drivers/base/auxiliary.c index dba7c8e13a53..44cd3f85b659 100644 --- a/drivers/base/auxiliary.c +++ b/drivers/base/auxiliary.c @@ -217,7 +217,7 @@ static int auxiliary_bus_probe(struct device *dev) struct auxiliary_device *auxdev =3D to_auxiliary_dev(dev); int ret; =20 - ret =3D dev_pm_domain_attach(dev, true); + ret =3D dev_pm_domain_attach(dev, PD_FLAG_ATTACH_POWER_ON); if (ret) { dev_warn(dev, "Failed to attach to PM Domain : %d\n", ret); return ret; diff --git a/drivers/base/platform.c b/drivers/base/platform.c index 075ec1d1b73a..df1ec34fdf56 100644 --- a/drivers/base/platform.c +++ b/drivers/base/platform.c @@ -1396,7 +1396,7 @@ static int platform_probe(struct device *_dev) if (ret < 0) return ret; =20 - ret =3D dev_pm_domain_attach(_dev, true); + ret =3D dev_pm_domain_attach(_dev, PD_FLAG_ATTACH_POWER_ON); if (ret) goto out; =20 diff --git a/drivers/base/power/common.c b/drivers/base/power/common.c index 781968a128ff..fecb85fa85ac 100644 --- a/drivers/base/power/common.c +++ b/drivers/base/power/common.c @@ -83,7 +83,7 @@ EXPORT_SYMBOL_GPL(dev_pm_put_subsys_data); /** * dev_pm_domain_attach - Attach a device to its PM domain. * @dev: Device to attach. - * @power_on: Used to indicate whether we should power on the device. + * @flags: indicate whether we should power on/off the device on attach/de= tach * * The @dev may only be attached to a single PM domain. By iterating throu= gh * the available alternatives we try to find a valid PM domain for the dev= ice. @@ -100,14 +100,14 @@ EXPORT_SYMBOL_GPL(dev_pm_put_subsys_data); * Returns 0 on successfully attached PM domain, or when it is found that = the * device doesn't need a PM domain, else a negative error code. */ -int dev_pm_domain_attach(struct device *dev, bool power_on) +int dev_pm_domain_attach(struct device *dev, u32 flags) { int ret; =20 if (dev->pm_domain) return 0; =20 - ret =3D acpi_dev_pm_attach(dev, power_on); + ret =3D acpi_dev_pm_attach(dev, !!(flags & PD_FLAG_ATTACH_POWER_ON)); if (!ret) ret =3D genpd_dev_pm_attach(dev); =20 diff --git a/drivers/clk/qcom/apcs-sdx55.c b/drivers/clk/qcom/apcs-sdx55.c index 3ba01622d8f0..90dd1f1855c2 100644 --- a/drivers/clk/qcom/apcs-sdx55.c +++ b/drivers/clk/qcom/apcs-sdx55.c @@ -111,7 +111,7 @@ static int qcom_apcs_sdx55_clk_probe(struct platform_de= vice *pdev) * driver, there seems to be no better place to do this. So do it here! */ cpu_dev =3D get_cpu_device(0); - ret =3D dev_pm_domain_attach(cpu_dev, true); + ret =3D dev_pm_domain_attach(cpu_dev, PD_FLAG_ATTACH_POWER_ON); if (ret) { dev_err_probe(dev, ret, "can't get PM domain: %d\n", ret); goto err; diff --git a/drivers/gpu/drm/display/drm_dp_aux_bus.c b/drivers/gpu/drm/dis= play/drm_dp_aux_bus.c index 7b9afcf48836..2d279e82922f 100644 --- a/drivers/gpu/drm/display/drm_dp_aux_bus.c +++ b/drivers/gpu/drm/display/drm_dp_aux_bus.c @@ -58,7 +58,7 @@ static int dp_aux_ep_probe(struct device *dev) container_of(aux_ep, struct dp_aux_ep_device_with_data, aux_ep); int ret; =20 - ret =3D dev_pm_domain_attach(dev, true); + ret =3D dev_pm_domain_attach(dev, PD_FLAG_ATTACH_POWER_ON); if (ret) return dev_err_probe(dev, ret, "Failed to attach to PM Domain\n"); =20 diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c index 2ad2b1838f0f..38eabf1173da 100644 --- a/drivers/i2c/i2c-core-base.c +++ b/drivers/i2c/i2c-core-base.c @@ -573,7 +573,7 @@ static int i2c_device_probe(struct device *dev) goto err_clear_wakeup_irq; =20 do_power_on =3D !i2c_acpi_waive_d0_probe(dev); - status =3D dev_pm_domain_attach(&client->dev, do_power_on); + status =3D dev_pm_domain_attach(&client->dev, do_power_on ? PD_FLAG_ATTAC= H_POWER_ON : 0); if (status) goto err_clear_wakeup_irq; =20 diff --git a/drivers/mmc/core/sdio_bus.c b/drivers/mmc/core/sdio_bus.c index b66b637e2d57..656601754966 100644 --- a/drivers/mmc/core/sdio_bus.c +++ b/drivers/mmc/core/sdio_bus.c @@ -161,7 +161,7 @@ static int sdio_bus_probe(struct device *dev) if (!id) return -ENODEV; =20 - ret =3D dev_pm_domain_attach(dev, false); + ret =3D dev_pm_domain_attach(dev, 0); if (ret) return ret; =20 diff --git a/drivers/rpmsg/rpmsg_core.c b/drivers/rpmsg/rpmsg_core.c index 6ee36adcbdba..bece5e635ee9 100644 --- a/drivers/rpmsg/rpmsg_core.c +++ b/drivers/rpmsg/rpmsg_core.c @@ -479,7 +479,7 @@ static int rpmsg_dev_probe(struct device *dev) struct rpmsg_endpoint *ept =3D NULL; int err; =20 - err =3D dev_pm_domain_attach(dev, true); + err =3D dev_pm_domain_attach(dev, PD_FLAG_ATTACH_POWER_ON); if (err) goto out; =20 diff --git a/drivers/soundwire/bus_type.c b/drivers/soundwire/bus_type.c index 75d6f16efced..bc1e653080d9 100644 --- a/drivers/soundwire/bus_type.c +++ b/drivers/soundwire/bus_type.c @@ -101,7 +101,7 @@ static int sdw_drv_probe(struct device *dev) /* * attach to power domain but don't turn on (last arg) */ - ret =3D dev_pm_domain_attach(dev, false); + ret =3D dev_pm_domain_attach(dev, 0); if (ret) return ret; =20 diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c index 1bc0fdbb1bd7..8200b47b2295 100644 --- a/drivers/spi/spi.c +++ b/drivers/spi/spi.c @@ -427,7 +427,7 @@ static int spi_probe(struct device *dev) if (spi->irq < 0) spi->irq =3D 0; =20 - ret =3D dev_pm_domain_attach(dev, true); + ret =3D dev_pm_domain_attach(dev, PD_FLAG_ATTACH_POWER_ON); if (ret) return ret; =20 diff --git a/drivers/tty/serdev/core.c b/drivers/tty/serdev/core.c index 0213381fa358..d16c207a1a9b 100644 --- a/drivers/tty/serdev/core.c +++ b/drivers/tty/serdev/core.c @@ -399,7 +399,7 @@ static int serdev_drv_probe(struct device *dev) const struct serdev_device_driver *sdrv =3D to_serdev_device_driver(dev->= driver); int ret; =20 - ret =3D dev_pm_domain_attach(dev, true); + ret =3D dev_pm_domain_attach(dev, PD_FLAG_ATTACH_POWER_ON); if (ret) return ret; =20 diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h index 0b18160901a2..62a35a78ce9b 100644 --- a/include/linux/pm_domain.h +++ b/include/linux/pm_domain.h @@ -36,10 +36,16 @@ * isn't specified, the index just follows the * index for the attached PM domain. * + * PD_FLAG_ATTACH_POWER_ON: Power on the domain during attach. + * + * PD_FLAG_DETACH_POWER_OFF: Power off the domain during detach. + * */ #define PD_FLAG_NO_DEV_LINK BIT(0) #define PD_FLAG_DEV_LINK_ON BIT(1) #define PD_FLAG_REQUIRED_OPP BIT(2) +#define PD_FLAG_ATTACH_POWER_ON BIT(3) +#define PD_FLAG_DETACH_POWER_OFF BIT(4) =20 struct dev_pm_domain_attach_data { const char * const *pd_names; @@ -501,7 +507,7 @@ struct generic_pm_domain *of_genpd_remove_last(struct d= evice_node *np) #endif /* CONFIG_PM_GENERIC_DOMAINS_OF */ =20 #ifdef CONFIG_PM -int dev_pm_domain_attach(struct device *dev, bool power_on); +int dev_pm_domain_attach(struct device *dev, u32 flags); struct device *dev_pm_domain_attach_by_id(struct device *dev, unsigned int index); struct device *dev_pm_domain_attach_by_name(struct device *dev, @@ -518,7 +524,7 @@ int dev_pm_domain_start(struct device *dev); void dev_pm_domain_set(struct device *dev, struct dev_pm_domain *pd); int dev_pm_domain_set_performance_state(struct device *dev, unsigned int s= tate); #else -static inline int dev_pm_domain_attach(struct device *dev, bool power_on) +static inline int dev_pm_domain_attach(struct device *dev, u32 flags) { return 0; } --=20 2.43.0 From nobody Wed Oct 8 02:04:51 2025 Received: from mail-ej1-f45.google.com (mail-ej1-f45.google.com [209.85.218.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 907022E49B1 for ; Thu, 3 Jul 2025 11:27:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751542074; cv=none; b=Ipxjix8Jw33ORa195eV8Y+KRs1FL66p/VRTrfu39jQJq/vsv6ez6+114qG0QInhGectymb+NEE6xxoLyQV6zZfGM9hKXkHCfxtI0CXZV8KB8QNJSIpxFwrSs7egIPA9svA16KUUQjtGem+SgnJHhR3M1v33PtCOQmhh3FjklF8U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751542074; c=relaxed/simple; bh=X1Oyr9vFTxLX3A2BuvfxXazNPEQYM31gD4YJTucU+Z4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QLa1EVPzPzIDlfZ6YE5nzrkO85/Llykwz79hfXIhmhFFgXfBxAHlSn4HV7kEOV1vv8IhtDBQpag6i2ue/NXI6JdsUWCffXREghDYZWq6Q77KYXm2BRgi5UDXUWzEVlb17GXCe6pmaI29BWyYrAAUgGrJ8/8Hgu0fsHnowpeKVu8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=tuxon.dev; spf=pass smtp.mailfrom=tuxon.dev; dkim=pass (2048-bit key) header.d=tuxon.dev header.i=@tuxon.dev header.b=NWaPrfeM; arc=none smtp.client-ip=209.85.218.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=tuxon.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=tuxon.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=tuxon.dev header.i=@tuxon.dev header.b="NWaPrfeM" Received: by mail-ej1-f45.google.com with SMTP id a640c23a62f3a-ae3c5f666bfso272674766b.3 for ; Thu, 03 Jul 2025 04:27:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tuxon.dev; s=google; t=1751542070; x=1752146870; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=cTGALKZoVheypQ1QT5i2+A3Y7/0VfJ5YTQvSLmEPSq0=; b=NWaPrfeMNu6lzcL6odLfZsNPLmYpVaPVg30El2x0eGSaccOcXkGqo1EdMEBm1zC5GI UWaqm6d88selempizMTQdl90luJ/o+HoxhIRBcnWkeaVoOAWZ5OPgM2yecuG97Pr3HJk qS96Ys4Ra3HzmYQX/1A68bF3kcz0O6hpK2bGHsmMkmPhgrbC18rNVDAvvopGIFVsu/1D LZHIOwrOvbHodHlqKABBqMCqB/qUr4Ndf25U9wWhGVeY6W8qK6Zb1JmladgI6A9GLm8M hHIviZwE4iTBFIbTFTNuii2SNcEwqd8Jb01yMnVWxLifPGewD6MrP5QTZ1wX5YqjBED6 GrlA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751542070; x=1752146870; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=cTGALKZoVheypQ1QT5i2+A3Y7/0VfJ5YTQvSLmEPSq0=; b=DV15SdLivaYiLB/zJpcgxkTL8+lsYTp/l3J6qZbs8dHQv9xtZG+rodW26V4WGVCIVd Sl4og8Rs0wGzsS2yMLoafr3K1fqMMLo7ehVmy8Y/zSQftkUwdS/6+VtM0twFcevXxWb4 uoVSjh/g0Bt2LRs+2QJIgfhiopflTfyIh4CvD5WhDSIS6HyziiWQGyxFmP0oaM7UcTkc xmugMDL4h1oRwbbsrlyxKHHicsADKuYdFugv+5lL74ru9rFucg5zhNjyjCEkDfy+v1T7 Ud4rz1nQkJeFx3G1nY1onMX2dDm5GVaTv7J5UqRX2dM+xQlA/9YDuqz2HOHqcQeEsgr4 HeHA== X-Forwarded-Encrypted: i=1; AJvYcCVFFTYWyM7OcypzKpv1zeTqonFmSs+sKnou4XbQUXudOgea6SgojTOKUGHZUPhVM5s6a80cvbTokwUJlM8=@vger.kernel.org X-Gm-Message-State: AOJu0YwjWrro9A29sOWtRA4BW02y5fT7R3s+CXcdNF4wgs/nR/ESMpBV 5lPQvpr6IJ3LoIs8PaUaHp+dC+cqvOMaQujsY24KTj6LRn/b1MqMeHaFQGJkexynDQg= X-Gm-Gg: ASbGnctn0x7r5A54p3ka2v8MxVrnAx7kWwJQSlGrFefPtf8ah1OwVv88mwIDmHeo6t8 9xE5d9ku1ReF4pEBSdYtIQzpBDKWvsHUDhX56+gMUcyxhuvJHTGBnLtGIkHrRrBEpdoA8yjRQZF 4RDpSyUwlN7wFdoEsW2kgBgU0H3dU+/Mgi8sL6Z5JgUarr9HLLZUAs6koCclIuXfzYO8awDoaIA +zQGBksJuBCO7I2xpL6Bl0Cfu5iODjAP3cAKJRpKNQBEMv0fzJLaSIp0nllK3KqlAAYZEZB6K/P 4qHYZ27XiE2rD78Rpc5nb+cD6L13jsVTqS66vjR6E2IvFpv4+fFYlnqZr/4yIRjRWYZc1OuQax7 sm6Aaf2aNkMAIMlw= X-Google-Smtp-Source: AGHT+IFkYQwbGErnKmAXbXp56IWazGm9DvxurIRdNCD1GAvBXxqd+zW8SE1e2XD1WudHDmEIZdYoAw== X-Received: by 2002:a17:907:1ca7:b0:ae3:6b52:f7dd with SMTP id a640c23a62f3a-ae3c2d69de4mr612468566b.46.1751542069470; Thu, 03 Jul 2025 04:27:49 -0700 (PDT) Received: from claudiu-X670E-Pro-RS.. ([82.78.167.83]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ae35365a75fsm1247016966b.67.2025.07.03.04.27.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Jul 2025 04:27:49 -0700 (PDT) From: Claudiu X-Google-Original-From: Claudiu To: linux@armlinux.org.uk, gregkh@linuxfoundation.org, david.m.ertman@intel.com, ira.weiny@intel.com, leon@kernel.org, rafael@kernel.org, dakr@kernel.org, len.brown@intel.com, pavel@kernel.org, andersson@kernel.org, mturquette@baylibre.com, sboyd@kernel.org, maarten.lankhorst@linux.intel.com, mripard@kernel.org, tzimmermann@suse.de, airlied@gmail.com, simona@ffwll.ch, wsa+renesas@sang-engineering.com, ulf.hansson@linaro.org, mathieu.poirier@linaro.org, vkoul@kernel.org, yung-chuan.liao@linux.intel.com, pierre-louis.bossart@linux.dev, broonie@kernel.org, robh@kernel.org, jirislaby@kernel.org, saravanak@google.com, jic23@kernel.org, dmitry.torokhov@gmail.com Cc: claudiu.beznea@tuxon.dev, linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-clk@vger.kernel.org, linux-i2c@vger.kernel.org, linux-mmc@vger.kernel.org, linux-remoteproc@vger.kernel.org, linux-sound@vger.kernel.org, linux-spi@vger.kernel.org, linux-serial@vger.kernel.org, bhelgaas@google.com, geert@linux-m68k.org, linux-iio@vger.kernel.org, linux-renesas-soc@vger.kernel.org, fabrizio.castro.jz@renesas.com, Claudiu Beznea Subject: [PATCH v5 2/3] PM: domains: Detach on device_unbind_cleanup() Date: Thu, 3 Jul 2025 14:27:07 +0300 Message-ID: <20250703112708.1621607-3-claudiu.beznea.uj@bp.renesas.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250703112708.1621607-1-claudiu.beznea.uj@bp.renesas.com> References: <20250703112708.1621607-1-claudiu.beznea.uj@bp.renesas.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Claudiu Beznea The dev_pm_domain_attach() function is typically used in bus code alongside dev_pm_domain_detach(), often following patterns like: static int bus_probe(struct device *_dev) { struct bus_driver *drv =3D to_bus_driver(dev->driver); struct bus_device *dev =3D to_bus_device(_dev); int ret; // ... ret =3D dev_pm_domain_attach(_dev, true); if (ret) return ret; if (drv->probe) ret =3D drv->probe(dev); // ... } static void bus_remove(struct device *_dev) { struct bus_driver *drv =3D to_bus_driver(dev->driver); struct bus_device *dev =3D to_bus_device(_dev); if (drv->remove) drv->remove(dev); dev_pm_domain_detach(_dev); } When the driver's probe function uses devres-managed resources that depend on the power domain state, those resources are released later during device_unbind_cleanup(). Releasing devres-managed resources that depend on the power domain state after detaching the device from its PM domain can cause failures. For example, if the driver uses devm_pm_runtime_enable() in its probe function, and the device's clocks are managed by the PM domain, then during removal the runtime PM is disabled in device_unbind_cleanup() after the clocks have been removed from the PM domain. It may happen that the devm_pm_runtime_enable() action causes the device to be runtime-resumed. If the driver specific runtime PM APIs access registers directly, this will lead to accessing device registers without clocks being enabled. Similar issues may occur with other devres actions that access device registers. Add detach_power_off member to struct dev_pm_info, to be used later in device_unbind_cleanup() as the power_off argument for dev_pm_domain_detach(). This is a preparatory step toward removing dev_pm_domain_detach() calls from bus remove functions. Since the current PM domain detach functions (genpd_dev_pm_detach() and acpi_dev_pm_detach()) already set dev->pm_domain =3D NULL, there should be no issues with bus drivers that still call dev_pm_domain_detach() in their remove functions. Signed-off-by: Claudiu Beznea Acked-by: Wolfram Sang Reviewed-by: Ulf Hansson --- Changes in v5: - added flags argument to dev_pm_domain_attach_attach() - added description for struct dev_pm_info::detach_power_off; @Rafael: I kept the detach_power_off flag outside of CONFIG_PM as it is used unconditionally in device_unbind_cleanup() Changes in v4: - save dev->power.detach_power_off in dev_pm_domain_attach() and use it in device_unbind_cleanup() when detaching - adjusted patch description Changes in v3: - dropped devm_pm_domain_detach_off(), devm_pm_domain_detach_on() and use a single function devm_pm_domain_detach() Changes in v2: - none; this patch is new drivers/base/dd.c | 2 ++ drivers/base/power/common.c | 3 +++ include/linux/pm.h | 1 + 3 files changed, 6 insertions(+) diff --git a/drivers/base/dd.c b/drivers/base/dd.c index b526e0e0f52d..13ab98e033ea 100644 --- a/drivers/base/dd.c +++ b/drivers/base/dd.c @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -552,6 +553,7 @@ static void device_unbind_cleanup(struct device *dev) dev->dma_range_map =3D NULL; device_set_driver(dev, NULL); dev_set_drvdata(dev, NULL); + dev_pm_domain_detach(dev, dev->power.detach_power_off); if (dev->pm_domain && dev->pm_domain->dismiss) dev->pm_domain->dismiss(dev); pm_runtime_reinit(dev); diff --git a/drivers/base/power/common.c b/drivers/base/power/common.c index fecb85fa85ac..6ecf9ce4a4e6 100644 --- a/drivers/base/power/common.c +++ b/drivers/base/power/common.c @@ -111,6 +111,9 @@ int dev_pm_domain_attach(struct device *dev, u32 flags) if (!ret) ret =3D genpd_dev_pm_attach(dev); =20 + if (dev->pm_domain) + dev->power.detach_power_off =3D !!(flags & PD_FLAG_DETACH_POWER_OFF); + return ret < 0 ? ret : 0; } EXPORT_SYMBOL_GPL(dev_pm_domain_attach); diff --git a/include/linux/pm.h b/include/linux/pm.h index f0bd8fbae4f2..be824dfc8577 100644 --- a/include/linux/pm.h +++ b/include/linux/pm.h @@ -720,6 +720,7 @@ struct dev_pm_info { struct pm_subsys_data *subsys_data; /* Owned by the subsystem. */ void (*set_latency_tolerance)(struct device *, s32); struct dev_pm_qos *qos; + bool detach_power_off:1; /* Owned by the driver core */ }; =20 extern int dev_pm_get_subsys_data(struct device *dev); --=20 2.43.0 From nobody Wed Oct 8 02:04:51 2025 Received: from mail-ej1-f44.google.com (mail-ej1-f44.google.com [209.85.218.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3111A2E6115 for ; Thu, 3 Jul 2025 11:27:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751542076; cv=none; b=oqr7heCx1YU25emDOBFoJfv8GXs3CbfaVTRXJuhvwyJ/20OU3upaLoB0b+CyX2NZyzxbG116EkBGByRwbvOyRcb2OmGAUTvGK8JP1sUJHgxnbH0x7DnPTz+6IDMxttdrTTMvTh1G7fEFtIrUCJtP/IoxPWpNLH6tE9VGq1J5omg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751542076; c=relaxed/simple; bh=dKp9sNBVKhCMWq2ozbMkBemUSa+iPERmFu+4dZggoQ0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qnoqtqOpzwcraTeiQ3/ER12EiV5XwljlY9jrdp8MvtMo9HQ+hSuXguEJRsVsO3ACAagWZE1fivWr2U/w1xKC/3qYMu3XKPhkHRLeP3sd1ksreeLVUTC9badKt9DJuqkqIBGQohoPYL6lRBfdgTx213K1u0QTLtpKnI3c7QbnuKc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=tuxon.dev; spf=pass smtp.mailfrom=tuxon.dev; dkim=pass (2048-bit key) header.d=tuxon.dev header.i=@tuxon.dev header.b=cxqeRkAm; arc=none smtp.client-ip=209.85.218.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=tuxon.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=tuxon.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=tuxon.dev header.i=@tuxon.dev header.b="cxqeRkAm" Received: by mail-ej1-f44.google.com with SMTP id a640c23a62f3a-ae0bde4d5c9so1444871566b.3 for ; Thu, 03 Jul 2025 04:27:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tuxon.dev; s=google; t=1751542072; x=1752146872; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=amy1aSEWJFLjdFKle4TRafGT1dI6FK2dRgoWrJhpEoE=; b=cxqeRkAmo+uhAkoMMQwvBP/akaaA+fW/9V9vZNVm2+J3NsvGJPkfzEQDkhNz6BvmOh 3sy7SDwTPiykFPgHxFKqPDV70lgxb9VitxB2zID8UhJEFqbjSr6/beF1A+paHxzJLbV2 fCsPFX0X2dXVHFISOIdTo8bHJzzw2i/2PWJU1fYLb+tV1f0mIKR8nnHFEOgX2m69aacR NgtAX6hIBrFtiKatkSlnHgVieJORSNq7h/WbY5fRfJUzCPYMt6OG0G9qmrBkr2OuIoFH BjAsSdZRFHbIo+yxKwu60qLSEiRdqqKoSmqYbWC/MXA7Fwv6q3tItqmJmsLAJS2Nzb1K iL3w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751542072; x=1752146872; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=amy1aSEWJFLjdFKle4TRafGT1dI6FK2dRgoWrJhpEoE=; b=AgCLWEErd6oRf+NPejpyBa7x42zpbi5AhwcyP5kCGu3jLs73gHRyRs3HpwhFFFos6E GqneWtC8WB63Eo59i5pdqvmAnqzuRR8CWOaBCXKahRNjSshgNamcfv9cFqrtl5ZY4NLE KNMZdukaSeotOPlc5qlqRxjhlaWSbCW8zAKXiEZiLkzMaNzWB63U3Ccc/dwM3F7ZpReA 90ICoP6QYqbjoNzAMjexWj+HOMqR8dQZYSB3P2znWIPwEHR9ioO394AF6tJZqXCCVAJX aNDBldn6r3SJ8v0pK3/WBVkhqH2B+iahvsKnC8QAnfjgqH7/A7rbcwrBZAJ5dJTEy5AI rYnw== X-Forwarded-Encrypted: i=1; AJvYcCXIcpkfMqSiOv9eEq95pNmkJC0SltSXCksT1OAuUsfZvGAh/fMgZxFWJa7RAX/Jd7PUXvNieudTNEDjaUI=@vger.kernel.org X-Gm-Message-State: AOJu0YxwuG4eXpV+G57O+0bOB6z+Fl3HZabHEvd1rH3AbjRm7DbXtij1 FXtlPh+MrZ18TIJSLhMa4ZjlYHiK7eSZ5RioDTMmOeRjTpcBLifN8VRB3hqVFnpqkPs= X-Gm-Gg: ASbGncupUGptYNKyuezO/ld8/KzZYPDD9ugunM/4dnP9dG3/eylzL7WQJHbjAw/arFK OYnlk4jINnn2MipMMi3fGSd+RMEpwnUkEt4lECvFLqdfpKT1Kx0uSWwSKng/mA6SMa7vMYHWF3R NSH8RDizf50P3PqxuKoPRfrU4ArEtwe02BlEjGoqyShyrU0pCDPtgwh+VIZUvXL9X0oXZyTozq3 TZq49aIZTQKGEohHa1M0PmLl6kBQUAyG6R+CdRPZkoQoBru07vS826JvEO1SEA/wd+DA1FnWn4p 3UoGFKivbcPcoR6o87hX6aPoKyFZhxxlHGDR8dNXZvuwPUzxuCeN/q0T9B1dOB2eUjK1BpSlfKH oYSqztolQVBCf8cU= X-Google-Smtp-Source: AGHT+IGtvsJyDMQsLfUDl9utWzUCxFT2n50ILIV0XhgAq1dND93ylmRMS+yE9TxwtIdCeTyEpsNdFg== X-Received: by 2002:a17:907:d644:b0:ae3:cd73:efde with SMTP id a640c23a62f3a-ae3d8b1b1d4mr273821366b.44.1751542072208; Thu, 03 Jul 2025 04:27:52 -0700 (PDT) Received: from claudiu-X670E-Pro-RS.. ([82.78.167.83]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ae35365a75fsm1247016966b.67.2025.07.03.04.27.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Jul 2025 04:27:51 -0700 (PDT) From: Claudiu X-Google-Original-From: Claudiu To: linux@armlinux.org.uk, gregkh@linuxfoundation.org, david.m.ertman@intel.com, ira.weiny@intel.com, leon@kernel.org, rafael@kernel.org, dakr@kernel.org, len.brown@intel.com, pavel@kernel.org, andersson@kernel.org, mturquette@baylibre.com, sboyd@kernel.org, maarten.lankhorst@linux.intel.com, mripard@kernel.org, tzimmermann@suse.de, airlied@gmail.com, simona@ffwll.ch, wsa+renesas@sang-engineering.com, ulf.hansson@linaro.org, mathieu.poirier@linaro.org, vkoul@kernel.org, yung-chuan.liao@linux.intel.com, pierre-louis.bossart@linux.dev, broonie@kernel.org, robh@kernel.org, jirislaby@kernel.org, saravanak@google.com, jic23@kernel.org, dmitry.torokhov@gmail.com Cc: claudiu.beznea@tuxon.dev, linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-clk@vger.kernel.org, linux-i2c@vger.kernel.org, linux-mmc@vger.kernel.org, linux-remoteproc@vger.kernel.org, linux-sound@vger.kernel.org, linux-spi@vger.kernel.org, linux-serial@vger.kernel.org, bhelgaas@google.com, geert@linux-m68k.org, linux-iio@vger.kernel.org, linux-renesas-soc@vger.kernel.org, fabrizio.castro.jz@renesas.com, Claudiu Beznea Subject: [PATCH v5 3/3] driver core: platform: Drop dev_pm_domain_detach() call Date: Thu, 3 Jul 2025 14:27:08 +0300 Message-ID: <20250703112708.1621607-4-claudiu.beznea.uj@bp.renesas.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250703112708.1621607-1-claudiu.beznea.uj@bp.renesas.com> References: <20250703112708.1621607-1-claudiu.beznea.uj@bp.renesas.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Claudiu Beznea On the Renesas RZ/G3S (and other Renesas SoCs, e.g., RZ/G2{L, LC, UL}), clocks are managed through PM domains. These PM domains, registered on behalf of the clock controller driver, are configured with GENPD_FLAG_PM_CLK. In most of the Renesas drivers used by RZ SoCs, the clocks are enabled/disabled using runtime PM APIs. The power domains may also have power_on/power_off support implemented. After the device PM domain is powered off any CPU accesses to these domains leads to system aborts. During probe, devices are attached to the PM domain controlling their clocks and power. Similarly, during removal, devices are detached from the PM domain. The detachment call stack is as follows: device_driver_detach() -> device_release_driver_internal() -> __device_release_driver() -> device_remove() -> platform_remove() -> dev_pm_domain_detach() During driver unbind, after the device is detached from its PM domain, the device_unbind_cleanup() function is called, which subsequently invokes devres_release_all(). This function handles devres resource cleanup. If runtime PM is enabled in driver probe via devm_pm_runtime_enable(), the cleanup process triggers the action or reset function for disabling runtime PM. This function is pm_runtime_disable_action(), which leads to the following call stack of interest when called: pm_runtime_disable_action() -> pm_runtime_dont_use_autosuspend() -> __pm_runtime_use_autosuspend() -> update_autosuspend() -> rpm_idle() The rpm_idle() function attempts to resume the device at runtime. However, at the point it is called, the device is no longer part of a PM domain (which manages clocks and power states). If the driver implements its own runtime PM APIs for specific functionalities - such as the rzg2l_adc driver - while also relying on the power domain subsystem for power management, rpm_idle() will invoke the driver's runtime PM API. However, since the device is no longer part of a PM domain at this point, the PM domain's runtime PM APIs will not be called. This leads to system aborts on Renesas SoCs. Another identified case is when a subsystem performs various cleanups using device_unbind_cleanup(), calling driver-specific APIs in the process. A known example is the thermal subsystem, which may call driver-specific APIs to disable the thermal device. The relevant call stack in this case is: device_driver_detach() -> device_release_driver_internal() -> device_unbind_cleanup() -> devres_release_all() -> devm_thermal_of_zone_release() -> thermal_zone_device_disable() -> thermal_zone_device_set_mode() -> struct thermal_zone_device_ops::change_mode() At the moment the driver-specific change_mode() API is called, the device is no longer part of its PM domain. Accessing its registers without proper power management leads to system aborts. Drop the call to dev_pm_domain_detach() from the platform bus remove function and rely on the newly introduced call in device_unbind_cleanup(). This ensures the same effect, but the call now occurs after all driver-specific devres resources have been freed. Signed-off-by: Claudiu Beznea Acked-by: Wolfram Sang Reviewed-by: Ulf Hansson --- Changes in v5: - dropped tab in the call traces from patch description - used PD_FLAG_ATTACH_POWER_ON, PD_FLAG_DETACH_POWER_OFF Changes in v4: - dropped devm_pm_domain_attach() approach - adjusted patch description to reflect this Changes in v3: - adjusted the call to devm_pm_domain_attach() as it now gets 2 parameters Changes in v2: - dropped the devres group open/close approach and use devm_pm_domain_attach() - adjusted patch description to reflect the new approach drivers/base/platform.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/drivers/base/platform.c b/drivers/base/platform.c index df1ec34fdf56..09450349cf32 100644 --- a/drivers/base/platform.c +++ b/drivers/base/platform.c @@ -1396,15 +1396,13 @@ static int platform_probe(struct device *_dev) if (ret < 0) return ret; =20 - ret =3D dev_pm_domain_attach(_dev, PD_FLAG_ATTACH_POWER_ON); + ret =3D dev_pm_domain_attach(_dev, PD_FLAG_ATTACH_POWER_ON | + PD_FLAG_DETACH_POWER_OFF); if (ret) goto out; =20 - if (drv->probe) { + if (drv->probe) ret =3D drv->probe(dev); - if (ret) - dev_pm_domain_detach(_dev, true); - } =20 out: if (drv->prevent_deferred_probe && ret =3D=3D -EPROBE_DEFER) { @@ -1422,7 +1420,6 @@ static void platform_remove(struct device *_dev) =20 if (drv->remove) drv->remove(dev); - dev_pm_domain_detach(_dev, true); } =20 static void platform_shutdown(struct device *_dev) --=20 2.43.0