]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
powerpc: sysdev: use lock guard for mutex
authorShrikanth Hegde <sshegde@linux.ibm.com>
Mon, 5 May 2025 07:53:33 +0000 (13:23 +0530)
committerMadhavan Srinivasan <maddy@linux.ibm.com>
Mon, 23 Jun 2025 04:27:11 +0000 (09:57 +0530)
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

Reviewed-by: Srikar Dronamraju <srikar@linux.ibm.com>
Signed-off-by: Shrikanth Hegde <sshegde@linux.ibm.com>
Tested-by: Venkat Rao Bagalkote <venkat88@linux.ibm.com>
Signed-off-by: Madhavan Srinivasan <maddy@linux.ibm.com>
Link: https://patch.msgid.link/20250505075333.184463-7-sshegde@linux.ibm.com
arch/powerpc/sysdev/fsl_mpic_timer_wakeup.c

index ce6c739c51e5109fbe315e1f82e741992d994481..06d9101a5d494d2fa0193c8263649290027ed18f 100644 (file)
@@ -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);
@@ -83,31 +83,23 @@ static ssize_t fsl_timer_wakeup_store(struct device *dev,
                fsl_wakeup->timer = NULL;
        }
 
-       if (!interval) {
-               mutex_unlock(&sysfs_lock);
+       if (!interval)
                return count;
-       }
 
        fsl_wakeup->timer = mpic_request_timer(fsl_mpic_timer_irq,
                                                fsl_wakeup, interval);
-       if (!fsl_wakeup->timer) {
-               mutex_unlock(&sysfs_lock);
+       if (!fsl_wakeup->timer)
                return -EINVAL;
-       }
 
        ret = enable_irq_wake(fsl_wakeup->timer->irq);
        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;
 }