[PATCH 2/6] pps: simplify pps_idr_lock locking

From: Michal Schmidt
Date: Mon Dec 02 2024 - 11:50:02 EST


It is sufficient to hold pps_idr_lock only around the idr
(de)allocations. There is no reason for the assignment to pps->id or for
the error printing to be under the lock.

Simplify the pps_idr_lock locking and the error path.

Signed-off-by: Michal Schmidt <mschmidt@xxxxxxxxxx>
---
drivers/pps/pps.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/drivers/pps/pps.c b/drivers/pps/pps.c
index 4f497353daa2..9a631f6d3a1e 100644
--- a/drivers/pps/pps.c
+++ b/drivers/pps/pps.c
@@ -336,22 +336,22 @@ int pps_register_cdev(struct pps_device *pps)
int err;
dev_t devt;

- mutex_lock(&pps_idr_lock);
/*
* 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);
if (err < 0) {
if (err == -ENOSPC) {
pr_err("%s: too many PPS sources in the system\n",
pps->info.name);
err = -EBUSY;
}
- goto out_unlock;
+ return err;
}
pps->id = err;
- mutex_unlock(&pps_idr_lock);

devt = MKDEV(MAJOR(pps_devt), pps->id);

@@ -389,7 +389,6 @@ int pps_register_cdev(struct pps_device *pps)
free_idr:
mutex_lock(&pps_idr_lock);
idr_remove(&pps_idr, pps->id);
-out_unlock:
mutex_unlock(&pps_idr_lock);
return err;
}
--
2.47.0