[PATCH v2 6/6] powerpc: sysdev: use lock guard for mutex

Shrikanth Hegde posted 6 patches 9 months, 1 week ago
There is a newer version of this series
[PATCH v2 6/6] powerpc: sysdev: use lock guard for mutex
Posted by Shrikanth Hegde 9 months, 1 week ago
use guard(mutex) for scope based resource management of mutex
This would make the code simpler and easier to maintain.

More details on lock guards can be found at
https://lore.kernel.org/all/20230612093537.614161713@infradead.org/T/#u

Signed-off-by: Shrikanth Hegde <sshegde@linux.ibm.com>
---
 arch/powerpc/sysdev/fsl_mpic_timer_wakeup.c | 8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)

diff --git a/arch/powerpc/sysdev/fsl_mpic_timer_wakeup.c b/arch/powerpc/sysdev/fsl_mpic_timer_wakeup.c
index ce6c739c51e5..bbfc7c39b957 100644
--- a/arch/powerpc/sysdev/fsl_mpic_timer_wakeup.c
+++ b/arch/powerpc/sysdev/fsl_mpic_timer_wakeup.c
@@ -75,7 +75,7 @@ static ssize_t fsl_timer_wakeup_store(struct device *dev,
 	if (kstrtoll(buf, 0, &interval))
 		return -EINVAL;
 
-	mutex_lock(&sysfs_lock);
+	guard(mutex)(&sysfs_lock);
 
 	if (fsl_wakeup->timer) {
 		disable_irq_wake(fsl_wakeup->timer->irq);
@@ -84,14 +84,12 @@ static ssize_t fsl_timer_wakeup_store(struct device *dev,
 	}
 
 	if (!interval) {
-		mutex_unlock(&sysfs_lock);
 		return count;
 	}
 
 	fsl_wakeup->timer = mpic_request_timer(fsl_mpic_timer_irq,
 						fsl_wakeup, interval);
 	if (!fsl_wakeup->timer) {
-		mutex_unlock(&sysfs_lock);
 		return -EINVAL;
 	}
 
@@ -99,15 +97,11 @@ static ssize_t fsl_timer_wakeup_store(struct device *dev,
 	if (ret) {
 		mpic_free_timer(fsl_wakeup->timer);
 		fsl_wakeup->timer = NULL;
-		mutex_unlock(&sysfs_lock);
-
 		return ret;
 	}
 
 	mpic_start_timer(fsl_wakeup->timer);
 
-	mutex_unlock(&sysfs_lock);
-
 	return count;
 }
 
-- 
2.39.3
Re: [PATCH v2 6/6] powerpc: sysdev: use lock guard for mutex
Posted by Srikar Dronamraju 7 months, 3 weeks ago
* Shrikanth Hegde <sshegde@linux.ibm.com> [2025-03-14 17:15:02]:

> use guard(mutex) for scope based resource management of mutex
> This would make the code simpler and easier to maintain.
> 
> More details on lock guards can be found at
> https://lore.kernel.org/all/20230612093537.614161713@infradead.org/T/#u
> 
> Signed-off-by: Shrikanth Hegde <sshegde@linux.ibm.com>
> ---
>  arch/powerpc/sysdev/fsl_mpic_timer_wakeup.c | 8 +-------
>  1 file changed, 1 insertion(+), 7 deletions(-)
> 
> diff --git a/arch/powerpc/sysdev/fsl_mpic_timer_wakeup.c b/arch/powerpc/sysdev/fsl_mpic_timer_wakeup.c
> index ce6c739c51e5..bbfc7c39b957 100644
> --- a/arch/powerpc/sysdev/fsl_mpic_timer_wakeup.c
> +++ b/arch/powerpc/sysdev/fsl_mpic_timer_wakeup.c
> @@ -75,7 +75,7 @@ static ssize_t fsl_timer_wakeup_store(struct device *dev,
>  	if (kstrtoll(buf, 0, &interval))
>  		return -EINVAL;
>  
> -	mutex_lock(&sysfs_lock);
> +	guard(mutex)(&sysfs_lock);
>  
>  	if (fsl_wakeup->timer) {
>  		disable_irq_wake(fsl_wakeup->timer->irq);
> @@ -84,14 +84,12 @@ static ssize_t fsl_timer_wakeup_store(struct device *dev,
>  	}
>  
>  	if (!interval) {
> -		mutex_unlock(&sysfs_lock);
>  		return count;
>  	}

Nit: Here and the next change, due to the current change, there is no need
for curly braces.

Other than this nit looks good to me.

Reviewed-by: Srikar Dronamraju <srikar@linux.ibm.com>

-- 
Thanks and Regards
Srikar Dronamraju
Re: [PATCH v2 6/6] powerpc: sysdev: use lock guard for mutex
Posted by Shrikanth Hegde 7 months, 2 weeks ago






Hi





On 4/30/25 18:40, Srikar Dronamraju wrote:
> * Shrikanth Hegde <sshegde@linux.ibm.com> [2025-03-14 17:15:02]:
>

Hi Srikar.

>> use guard(mutex) for scope based resource management of mutex
>> This would make the code simpler and easier to maintain.
>>
>> More details on lock guards can be found at
>> https://lore.kernel.org/all/20230612093537.614161713@infradead.org/T/#u
>>
>> Signed-off-by: Shrikanth Hegde <sshegde@linux.ibm.com>
>> ---
>>   arch/powerpc/sysdev/fsl_mpic_timer_wakeup.c | 8 +-------
>>   1 file changed, 1 insertion(+), 7 deletions(-)
>>
>> diff --git a/arch/powerpc/sysdev/fsl_mpic_timer_wakeup.c b/arch/powerpc/sysdev/fsl_mpic_timer_wakeup.c
>> index ce6c739c51e5..bbfc7c39b957 100644
>> --- a/arch/powerpc/sysdev/fsl_mpic_timer_wakeup.c
>> +++ b/arch/powerpc/sysdev/fsl_mpic_timer_wakeup.c
>> @@ -75,7 +75,7 @@ static ssize_t fsl_timer_wakeup_store(struct device *dev,
>>   	if (kstrtoll(buf, 0, &interval))
>>   		return -EINVAL;
>>   
>> -	mutex_lock(&sysfs_lock);
>> +	guard(mutex)(&sysfs_lock);
>>   
>>   	if (fsl_wakeup->timer) {
>>   		disable_irq_wake(fsl_wakeup->timer->irq);
>> @@ -84,14 +84,12 @@ static ssize_t fsl_timer_wakeup_store(struct device *dev,
>>   	}
>>   
>>   	if (!interval) {
>> -		mutex_unlock(&sysfs_lock);
>>   		return count;
>>   	}
> 
> Nit: Here and the next change, due to the current change, there is no need
> for curly braces.

Ok. will fix it next version.

> 
> Other than this nit looks good to me.
> 
> Reviewed-by: Srikar Dronamraju <srikar@linux.ibm.com>

Thanks for the reviews.

>