diff mbox series

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

Message ID 20210312184534.6423-1-lukasz.luba@arm.com
State Superseded
Headers show
Series PM / devfreq: unlock mutex and free devfreq struct in error path | expand

Commit Message

Lukasz Luba March 12, 2021, 6:45 p.m. UTC
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.

Signed-off-by: Lukasz Luba <lukasz.luba@arm.com>
---
 drivers/devfreq/devfreq.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Comments

Chanwoo Choi March 15, 2021, 7:20 a.m. UTC | #1
Hi Lukasz,

On 3/13/21 3:45 AM, Lukasz Luba wrote:
> 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.

> 

> Signed-off-by: Lukasz Luba <lukasz.luba@arm.com>

> ---

>  drivers/devfreq/devfreq.c | 3 ++-

>  1 file changed, 2 insertions(+), 1 deletion(-)

> 

> diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c

> index b6d3e7db0b09..99b2eeedc238 100644

> --- a/drivers/devfreq/devfreq.c

> +++ b/drivers/devfreq/devfreq.c

> @@ -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.

-- 
Best Regards,
Chanwoo Choi
Samsung Electronics
Lukasz Luba March 15, 2021, 9:22 a.m. UTC | #2
Hi Chanwoo,

On 3/15/21 7:20 AM, Chanwoo Choi wrote:
> Hi Lukasz,

> 

> On 3/13/21 3:45 AM, Lukasz Luba wrote:

>> 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.

>>

>> Signed-off-by: Lukasz Luba <lukasz.luba@arm.com>

>> ---

>>   drivers/devfreq/devfreq.c | 3 ++-

>>   1 file changed, 2 insertions(+), 1 deletion(-)

>>

>> diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c

>> index b6d3e7db0b09..99b2eeedc238 100644

>> --- a/drivers/devfreq/devfreq.c

>> +++ b/drivers/devfreq/devfreq.c

>> @@ -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.


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

> 

> 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+ <stable@vger.kernel.org> # v5.8+

Regards,
Lukasz
diff mbox series

Patch

diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
index b6d3e7db0b09..99b2eeedc238 100644
--- a/drivers/devfreq/devfreq.c
+++ b/drivers/devfreq/devfreq.c
@@ -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) {