[PATCH 3/6] pps: use scoped_guard for pps_idr_lock
From: Michal Schmidt
Date: Mon Dec 02 2024 - 14:37:51 EST
Use the scoped_guard syntax to be more brief.
Signed-off-by: Michal Schmidt <mschmidt@xxxxxxxxxx>
---
drivers/pps/pps.c | 15 ++++++---------
1 file changed, 6 insertions(+), 9 deletions(-)
diff --git a/drivers/pps/pps.c b/drivers/pps/pps.c
index 9a631f6d3a1e..92be7815a621 100644
--- a/drivers/pps/pps.c
+++ b/drivers/pps/pps.c
@@ -323,9 +323,8 @@ static void pps_device_destruct(struct device *dev)
/* Now we can release the ID for re-use */
pr_debug("deallocating pps%d\n", pps->id);
- mutex_lock(&pps_idr_lock);
- idr_remove(&pps_idr, pps->id);
- mutex_unlock(&pps_idr_lock);
+ scoped_guard(mutex, &pps_idr_lock)
+ idr_remove(&pps_idr, pps->id);
kfree(dev);
kfree(pps);
@@ -340,9 +339,8 @@ int pps_register_cdev(struct pps_device *pps)
* Get new ID for the new PPS source. After idr_alloc() calling
* the new source will be freely available into the kernel.
*/
- mutex_lock(&pps_idr_lock);
- err = idr_alloc(&pps_idr, pps, 0, PPS_MAX_SOURCES, GFP_KERNEL);
- mutex_unlock(&pps_idr_lock);
+ scoped_guard(mutex, &pps_idr_lock)
+ err = idr_alloc(&pps_idr, pps, 0, PPS_MAX_SOURCES, GFP_KERNEL);
if (err < 0) {
if (err == -ENOSPC) {
pr_err("%s: too many PPS sources in the system\n",
@@ -387,9 +385,8 @@ int pps_register_cdev(struct pps_device *pps)
cdev_del(&pps->cdev);
free_idr:
- mutex_lock(&pps_idr_lock);
- idr_remove(&pps_idr, pps->id);
- mutex_unlock(&pps_idr_lock);
+ scoped_guard(mutex, &pps_idr_lock)
+ idr_remove(&pps_idr, pps->id);
return err;
}
--
2.47.0