Skip to contentSkip to conversation

PM / devfreq: unlock mutex and free devfreq struct in error path

PATCH Superseded Lukasz Luba 2 participants 3 messages Mar 12, 2021 – Mar 15, 2021 Device frequency (devfreq)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 PM / devfreq: unlock mutex and free devfreq struct in error path

The devfreq->lock is held for time of setup. Release the lock in the error path, before jumping to the end of the function.

Change the goto destination which frees the allocated memory.

---
 drivers/devfreq/devfreq.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/devfreq/devfreq.c +2 -1
index b6d3e7db0b09..99b2eeedc238 100644
@@ -822,7 +822,8 @@ struct devfreq *devfreq_add_device(struct device *dev,
 
 	if (devfreq->profile->timer < 0
 		|| devfreq->profile->timer >= DEVFREQ_TIMER_NUM) {
-		goto err_out;
+		mutex_unlock(&devfreq->lock);
+		goto err_dev;
 	}
 
 	if (!devfreq->profile->max_state && !devfreq->profile->freq_table) {
Signature · 1 line
2.17.1
maintainer
#1 lore raw

Hi Lukasz,

Quoted 16 lines · Lukasz Luba

The devfreq->lock is held for time of setup. Release the lock in the error path, before jumping to the end of the function.

Change the goto destination which frees the allocated memory.

---
 drivers/devfreq/devfreq.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/devfreq/devfreq.c +0 -0
index b6d3e7db0b09..99b2eeedc238 100644

drivers/devfreq/devfreq.c struct devfreq *devfreq_add_device(struct device *dev, · line 829

Quoted 9 lines
drivers/devfreq/devfreq.c +2 -1
@@ -822,7 +822,8 @@ struct devfreq *devfreq_add_device(struct device *dev,
 
 	if (devfreq->profile->timer < 0
 		|| devfreq->profile->timer >= DEVFREQ_TIMER_NUM) {
-		goto err_out;
+		mutex_unlock(&devfreq->lock);
+		goto err_dev;
 	}
 
 	if (!devfreq->profile->max_state && !devfreq->profile->freq_table) {

Looks good to me. But, need to add the following information
and please use capital letter of the first character of patch title. Thanks.

Fixes 4dc3bab8687f ("PM / devfreq: Add support delayed timer for polling mode")

Also, need to send it to stable lkml.

Signature · 3 lines
Best Regards,
Chanwoo Choi
Samsung Electronics
#2 lore raw

Hi Chanwoo,

Quoted 26 lines · Chanwoo Choi

Hi Lukasz,

Quoted 23 lines · Lukasz Luba

The devfreq->lock is held for time of setup. Release the lock in the error path, before jumping to the end of the function.

Change the goto destination which frees the allocated memory.

---
  drivers/devfreq/devfreq.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
drivers/devfreq/devfreq.c +2 -1
index b6d3e7db0b09..99b2eeedc238 100644
@@ -822,7 +822,8 @@ struct devfreq *devfreq_add_device(struct device *dev,
 
  	if (devfreq->profile->timer < 0
  		|| devfreq->profile->timer >= DEVFREQ_TIMER_NUM) {
-		goto err_out;
+		mutex_unlock(&devfreq->lock);
+		goto err_dev;
  	}
 
Quoted 5 lines

drivers/devfreq/devfreq.c struct devfreq *devfreq_add_device(struct device *dev, · line 829

Quoted 2 lines
drivers/devfreq/devfreq.c +0 -0
  	if (!devfreq->profile->max_state && !devfreq->profile->freq_table) {

Looks good to me. But, need to add the following information
and please use capital letter of the first character of patch title. Thanks.

thanks for looking at this, sure, I'll use the capital letter.

Quoted 5 lines
Fixes 4dc3bab8687f ("PM / devfreq: Add support delayed timer for polling mode")

Also, need to send it to stable lkml.

I'll add the 'Fixes' tag and send v2 also into stable v5.8+:

Cc v5.8+ <[email protected]> # v5.8+

Regards,
Lukasz