Skip to contentSkip to conversation

PM: sleep: Fix error handling in dpm_prepare()

PATCH In review Rafael J. Wysocki 4 participants 4 messages Dec 16, 2021 – Dec 17, 2021

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 PM: sleep: Fix error handling in dpm_prepare()

From: Rafael J. Wysocki <[email protected]>

Commit 2aa36604e824 ("PM: sleep: Avoid calling put_device() under dpm_list_mtx") forgot to update the while () loop termination condition to also break the loop if error is nonzero, which causes the loop to become infinite if device_prepare() returns an error for one device.

Add the missing !error check.

Fixes 2aa36604e824 ("PM: sleep: Avoid calling put_device() under dpm_list_mtx")

Thomas Hellström <[email protected]>

---
 drivers/base/power/main.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/base/power/main.c +1 -1
Index: linux-pm/drivers/base/power/main.c
===================================================================
@@ -1902,7 +1902,7 @@ int dpm_prepare(pm_message_t state)
 	device_block_probing();
 
 	mutex_lock(&dpm_list_mtx);
-	while (!list_empty(&dpm_list)) {
+	while (!list_empty(&dpm_list) && !error) {
 		struct device *dev = to_device(dpm_list.next);
 
 		get_device(dev);
Reviewed-by on v1 1/1
#1 lore raw
Quoted 8 lines · Rafael J. Wysocki

From: Rafael J. Wysocki <[email protected]>

Commit 2aa36604e824 ("PM: sleep: Avoid calling put_device() under dpm_list_mtx") forgot to update the while () loop termination condition to also break the loop if error is nonzero, which causes the loop to become infinite if device_prepare() returns an error for one device.

Quoted 6 lines

Add the missing !error check.

Fixes 2aa36604e824 ("PM: sleep: Avoid calling put_device() under

dpm_list_mtx")

Thomas Hellström <[email protected]>

Was this meant to be a Reported-by:?
Also Cc stable? IIRC 2aa36604e824 was.

In any case,

Thanks,
Thomas

Quoted 20 lines

---
 drivers/base/power/main.c |    2 +-

 1 file changed, 1 insertion(+), 1 deletion(-)

Index: linux-pm/drivers/base/power/main.c
===================================================================

drivers/base/power/main.c +0 -0
@@ -1902,7 +1902,7 @@ int dpm_prepare(pm_message_t state)
         device_block_probing();


        mutex_lock(&dpm_list_mtx);
-       while (!list_empty(&dpm_list)) {
+       while (!list_empty(&dpm_list) && !error) { struct device *dev = to_device(dpm_list.next);
                get_device(dev);

#2 lore raw
Quoted 10 lines · Thomas Hellström
Quoted 8 lines · Rafael J. Wysocki

From: Rafael J. Wysocki <[email protected]>

Commit 2aa36604e824 ("PM: sleep: Avoid calling put_device() under dpm_list_mtx") forgot to update the while () loop termination condition to also break the loop if error is nonzero, which causes the loop to become infinite if device_prepare() returns an error for one device.

Quoted 8 lines
Quoted 6 lines

Add the missing !error check.

Fixes 2aa36604e824 ("PM: sleep: Avoid calling put_device() under

dpm_list_mtx")

Thomas Hellström <[email protected]>

Was this meant to be a Reported-by:?

Yes, it was, sorry.

Quoted 1 line

Also Cc stable? IIRC 2aa36604e824 was.

That gets added later and -stable can figure it out.

Quoted 2 lines

In any case,

Thanks!

Quoted 22 lines
Quoted 20 lines
---
 drivers/base/power/main.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Index: linux-pm/drivers/base/power/main.c
===================================================================

drivers/base/power/main.c +1 -1
@@ -1902,7 +1902,7 @@ int dpm_prepare(pm_message_t state)
        device_block_probing();
 
        mutex_lock(&dpm_list_mtx);
-       while (!list_empty(&dpm_list)) {
+       while (!list_empty(&dpm_list) && !error) {
                struct device *dev = to_device(dpm_list.next);
 
                get_device(dev);
Reviewed-by on v1 1/1
#3 lore raw
In reply to Rafael J. Wysocki
Quoted 9 lines · Rafael J. Wysocki

From: Rafael J. Wysocki <[email protected]>

Commit 2aa36604e824 ("PM: sleep: Avoid calling put_device() under dpm_list_mtx") forgot to update the while () loop termination condition to also break the loop if error is nonzero, which causes the loop to become infinite if device_prepare() returns an error for one device.

Quoted 5 lines

Add the missing !error check.

Fixes 2aa36604e824 ("PM: sleep: Avoid calling put_device() under dpm_list_mtx")

Thomas Hellström <[email protected]>

Kind regards
Uffe

Quoted 20 lines
---
 drivers/base/power/main.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Index: linux-pm/drivers/base/power/main.c
===================================================================

drivers/base/power/main.c +1 -1
@@ -1902,7 +1902,7 @@ int dpm_prepare(pm_message_t state)
        device_block_probing();
 
        mutex_lock(&dpm_list_mtx);
-       while (!list_empty(&dpm_list)) {
+       while (!list_empty(&dpm_list) && !error) {
                struct device *dev = to_device(dpm_list.next);
 
                get_device(dev);