From a458d892e62ccbb6d084fe07cde796377b07fd62 Mon Sep 17 00:00:00 2001 From: Flavio Ceolin Date: Mon, 22 Apr 2024 15:40:40 -0700 Subject: [PATCH] pm: device_runtime: Check busy status in runtime_enable We can't enable device runtime power management in a device that is set busy since it may suspend this device. Signed-off-by: Flavio Ceolin --- include/zephyr/pm/device_runtime.h | 1 + subsys/pm/device_runtime.c | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/include/zephyr/pm/device_runtime.h b/include/zephyr/pm/device_runtime.h index 3510a910f3..25fea556e4 100644 --- a/include/zephyr/pm/device_runtime.h +++ b/include/zephyr/pm/device_runtime.h @@ -49,6 +49,7 @@ int pm_device_runtime_auto_enable(const struct device *dev); * * @retval 0 If the device runtime PM is enabled successfully. * @retval -EPERM If device has power state locked. + * @retval -EBUSY If device is busy. * @retval -ENOTSUP If the device does not support PM. * @retval -errno Other negative errno, result of suspending the device. * diff --git a/subsys/pm/device_runtime.c b/subsys/pm/device_runtime.c index 533caddd50..b06b72242d 100644 --- a/subsys/pm/device_runtime.c +++ b/subsys/pm/device_runtime.c @@ -422,6 +422,11 @@ int pm_device_runtime_enable(const struct device *dev) goto end; } + if (pm_device_is_busy(dev)) { + ret = -EBUSY; + goto end; + } + if (atomic_test_bit(&dev->pm_base->flags, PM_DEVICE_FLAG_ISR_SAFE)) { ret = runtime_enable_sync(dev); goto end;