[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20241202163451.1442566-3-mschmidt@redhat.com>
Date: Mon, 2 Dec 2024 17:34:47 +0100
From: Michal Schmidt <mschmidt@...hat.com>
To: Rodolfo Giometti <giometti@...eenne.com>
Cc: Uwe Kleine-König <u.kleine-koenig@...gutronix.de>,
Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
Christophe JAILLET <christophe.jaillet@...adoo.fr>,
"Dr. David Alan Gilbert" <linux@...blig.org>,
Ma Ke <make24@...as.ac.cn>,
Andrew Morton <akpm@...ux-foundation.org>,
George Spelvin <linux@...izon.com>,
linux-kernel@...r.kernel.org
Subject: [PATCH 2/6] pps: simplify pps_idr_lock locking
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@...hat.com>
---
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
Powered by blists - more mailing lists