]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
misc: bh1770glc: use pm_runtime_resume_and_get() in power_state_store
authorVivek BalachandharTN <vivek.balachandhar@gmail.com>
Thu, 30 Oct 2025 12:00:22 +0000 (12:00 +0000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 26 Nov 2025 14:09:37 +0000 (15:09 +0100)
pm_runtime_get_sync() may increment the runtime PM usage count even if the
resume fails, which requires an explicit pm_runtime_put_noidle() to balance
it. This driver ignored the return value, risking a usage-count leak on
resume failure.

Replace it with pm_runtime_resume_and_get(), which returns 0 on success and
a negative errno on failure, and only increments the usage count on success.
This simplifies the error path and avoids possible leaks. Also check for
errors explicitly with `if (ret < 0)`.

Signed-off-by: Vivek BalachandharTN <vivek.balachandhar@gmail.com>
Link: https://patch.msgid.link/20251030120022.239951-1-vivek.balachandhar@gmail.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/misc/bh1770glc.c

index 0c052b05ab6a9494e6f7a7cf84b34479145da6c6..45f8fc69a71138d5c534be1ca4718753d4bcdc3a 100644 (file)
@@ -640,7 +640,9 @@ static ssize_t bh1770_power_state_store(struct device *dev,
 
        mutex_lock(&chip->mutex);
        if (value) {
-               pm_runtime_get_sync(dev);
+               ret = pm_runtime_resume_and_get(dev);
+               if (ret < 0)
+                       goto leave;
 
                ret = bh1770_lux_rate(chip, chip->lux_rate_index);
                if (ret < 0) {