[PATCH] PCI/pwrctrl: lock device when calling device_is_bound()

Bartosz Golaszewski posted 1 patch 6 days, 18 hours ago
drivers/pci/pwrctrl/core.c | 26 +++++++++++++++-----------
1 file changed, 15 insertions(+), 11 deletions(-)
[PATCH] PCI/pwrctrl: lock device when calling device_is_bound()
Posted by Bartosz Golaszewski 6 days, 18 hours ago
The kerneldoc for device_is_bound() states that it must be called with
the device lock taken. Synchronize the two calls in pwrctrl core.

Fixes: b35cf3b6aa1e ("PCI/pwrctrl: Add APIs to power on/off pwrctrl devices")
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
---
 drivers/pci/pwrctrl/core.c | 26 +++++++++++++++-----------
 1 file changed, 15 insertions(+), 11 deletions(-)

diff --git a/drivers/pci/pwrctrl/core.c b/drivers/pci/pwrctrl/core.c
index 97cff5b8ca88..cd08d590483b 100644
--- a/drivers/pci/pwrctrl/core.c
+++ b/drivers/pci/pwrctrl/core.c
@@ -161,10 +161,12 @@ static void pci_pwrctrl_power_off_device(struct device_node *np)
 	if (!pdev)
 		return;
 
-	if (device_is_bound(&pdev->dev)) {
-		ret = __pci_pwrctrl_power_off_device(&pdev->dev);
-		if (ret)
-			dev_err(&pdev->dev, "Failed to power off device: %d", ret);
+	scoped_guard(device, &pdev->dev) {
+		if (device_is_bound(&pdev->dev)) {
+			ret = __pci_pwrctrl_power_off_device(&pdev->dev);
+			if (ret)
+				dev_err(&pdev->dev, "Failed to power off device: %d", ret);
+		}
 	}
 
 	platform_device_put(pdev);
@@ -205,7 +207,7 @@ static int __pci_pwrctrl_power_on_device(struct device *dev)
 static int pci_pwrctrl_power_on_device(struct device_node *np)
 {
 	struct platform_device *pdev;
-	int ret;
+	int ret = 0;
 
 	for_each_available_child_of_node_scoped(np, child) {
 		ret = pci_pwrctrl_power_on_device(child);
@@ -217,12 +219,14 @@ static int pci_pwrctrl_power_on_device(struct device_node *np)
 	if (!pdev)
 		return 0;
 
-	if (device_is_bound(&pdev->dev)) {
-		ret = __pci_pwrctrl_power_on_device(&pdev->dev);
-	} else {
-		/* FIXME: Use blocking wait instead of probe deferral */
-		dev_dbg(&pdev->dev, "driver is not bound\n");
-		ret = -EPROBE_DEFER;
+	scoped_guard(device, &pdev->dev) {
+		if (device_is_bound(&pdev->dev)) {
+			ret = __pci_pwrctrl_power_on_device(&pdev->dev);
+		} else {
+			/* FIXME: Use blocking wait instead of probe deferral */
+			dev_dbg(&pdev->dev, "driver is not bound\n");
+			ret = -EPROBE_DEFER;
+		}
 	}
 
 	platform_device_put(pdev);
-- 
2.47.3
Re: [PATCH] PCI/pwrctrl: lock device when calling device_is_bound()
Posted by Bjorn Helgaas 6 days, 6 hours ago
On Mon, May 18, 2026 at 12:07:00PM +0200, Bartosz Golaszewski wrote:
> The kerneldoc for device_is_bound() states that it must be called with
> the device lock taken. Synchronize the two calls in pwrctrl core.
> 
> Fixes: b35cf3b6aa1e ("PCI/pwrctrl: Add APIs to power on/off pwrctrl devices")
> Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>

Applied to pci/pwrctrl for v7.2, thanks!

> ---
>  drivers/pci/pwrctrl/core.c | 26 +++++++++++++++-----------
>  1 file changed, 15 insertions(+), 11 deletions(-)
> 
> diff --git a/drivers/pci/pwrctrl/core.c b/drivers/pci/pwrctrl/core.c
> index 97cff5b8ca88..cd08d590483b 100644
> --- a/drivers/pci/pwrctrl/core.c
> +++ b/drivers/pci/pwrctrl/core.c
> @@ -161,10 +161,12 @@ static void pci_pwrctrl_power_off_device(struct device_node *np)
>  	if (!pdev)
>  		return;
>  
> -	if (device_is_bound(&pdev->dev)) {
> -		ret = __pci_pwrctrl_power_off_device(&pdev->dev);
> -		if (ret)
> -			dev_err(&pdev->dev, "Failed to power off device: %d", ret);
> +	scoped_guard(device, &pdev->dev) {
> +		if (device_is_bound(&pdev->dev)) {
> +			ret = __pci_pwrctrl_power_off_device(&pdev->dev);
> +			if (ret)
> +				dev_err(&pdev->dev, "Failed to power off device: %d", ret);
> +		}
>  	}
>  
>  	platform_device_put(pdev);
> @@ -205,7 +207,7 @@ static int __pci_pwrctrl_power_on_device(struct device *dev)
>  static int pci_pwrctrl_power_on_device(struct device_node *np)
>  {
>  	struct platform_device *pdev;
> -	int ret;
> +	int ret = 0;
>  
>  	for_each_available_child_of_node_scoped(np, child) {
>  		ret = pci_pwrctrl_power_on_device(child);
> @@ -217,12 +219,14 @@ static int pci_pwrctrl_power_on_device(struct device_node *np)
>  	if (!pdev)
>  		return 0;
>  
> -	if (device_is_bound(&pdev->dev)) {
> -		ret = __pci_pwrctrl_power_on_device(&pdev->dev);
> -	} else {
> -		/* FIXME: Use blocking wait instead of probe deferral */
> -		dev_dbg(&pdev->dev, "driver is not bound\n");
> -		ret = -EPROBE_DEFER;
> +	scoped_guard(device, &pdev->dev) {
> +		if (device_is_bound(&pdev->dev)) {
> +			ret = __pci_pwrctrl_power_on_device(&pdev->dev);
> +		} else {
> +			/* FIXME: Use blocking wait instead of probe deferral */
> +			dev_dbg(&pdev->dev, "driver is not bound\n");
> +			ret = -EPROBE_DEFER;
> +		}
>  	}
>  
>  	platform_device_put(pdev);
> -- 
> 2.47.3
>
Re: [PATCH] PCI/pwrctrl: lock device when calling device_is_bound()
Posted by Manivannan Sadhasivam 6 days, 18 hours ago
On Mon, May 18, 2026 at 12:07:00PM +0200, Bartosz Golaszewski wrote:
> The kerneldoc for device_is_bound() states that it must be called with
> the device lock taken. Synchronize the two calls in pwrctrl core.
> 
> Fixes: b35cf3b6aa1e ("PCI/pwrctrl: Add APIs to power on/off pwrctrl devices")
> Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>

Reviewed-by: Manivannan Sadhasivam <mani@kernel.org>

- Mani

> ---
>  drivers/pci/pwrctrl/core.c | 26 +++++++++++++++-----------
>  1 file changed, 15 insertions(+), 11 deletions(-)
> 
> diff --git a/drivers/pci/pwrctrl/core.c b/drivers/pci/pwrctrl/core.c
> index 97cff5b8ca88..cd08d590483b 100644
> --- a/drivers/pci/pwrctrl/core.c
> +++ b/drivers/pci/pwrctrl/core.c
> @@ -161,10 +161,12 @@ static void pci_pwrctrl_power_off_device(struct device_node *np)
>  	if (!pdev)
>  		return;
>  
> -	if (device_is_bound(&pdev->dev)) {
> -		ret = __pci_pwrctrl_power_off_device(&pdev->dev);
> -		if (ret)
> -			dev_err(&pdev->dev, "Failed to power off device: %d", ret);
> +	scoped_guard(device, &pdev->dev) {
> +		if (device_is_bound(&pdev->dev)) {
> +			ret = __pci_pwrctrl_power_off_device(&pdev->dev);
> +			if (ret)
> +				dev_err(&pdev->dev, "Failed to power off device: %d", ret);
> +		}
>  	}
>  
>  	platform_device_put(pdev);
> @@ -205,7 +207,7 @@ static int __pci_pwrctrl_power_on_device(struct device *dev)
>  static int pci_pwrctrl_power_on_device(struct device_node *np)
>  {
>  	struct platform_device *pdev;
> -	int ret;
> +	int ret = 0;
>  
>  	for_each_available_child_of_node_scoped(np, child) {
>  		ret = pci_pwrctrl_power_on_device(child);
> @@ -217,12 +219,14 @@ static int pci_pwrctrl_power_on_device(struct device_node *np)
>  	if (!pdev)
>  		return 0;
>  
> -	if (device_is_bound(&pdev->dev)) {
> -		ret = __pci_pwrctrl_power_on_device(&pdev->dev);
> -	} else {
> -		/* FIXME: Use blocking wait instead of probe deferral */
> -		dev_dbg(&pdev->dev, "driver is not bound\n");
> -		ret = -EPROBE_DEFER;
> +	scoped_guard(device, &pdev->dev) {
> +		if (device_is_bound(&pdev->dev)) {
> +			ret = __pci_pwrctrl_power_on_device(&pdev->dev);
> +		} else {
> +			/* FIXME: Use blocking wait instead of probe deferral */
> +			dev_dbg(&pdev->dev, "driver is not bound\n");
> +			ret = -EPROBE_DEFER;
> +		}
>  	}
>  
>  	platform_device_put(pdev);
> -- 
> 2.47.3
> 

-- 
மணிவண்ணன் சதாசிவம்