pm: device_runtime: Fix possible underflow

The runtime API is referenced count and uses a uint32_t.
Avoid underflow when dealing with put requests.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
This commit is contained in:
Flavio Ceolin 2021-08-24 23:12:27 -07:00 committed by Anas Nashif
commit 4960a9aa7a

View file

@ -113,6 +113,11 @@ static int pm_device_request(const struct device *dev,
goto out_unlock;
}
} else {
/* Check if it is already 0 to avoid an underflow */
if (dev->pm->usage == 0) {
goto out_unlock;
}
dev->pm->usage--;
if (dev->pm->usage > 0) {
goto out_unlock;