[PATCH 3/6] pps: use scoped_guard for pps_idr_lock

Michal Schmidt posted 6 patches 1 year, 2 months ago
[PATCH 3/6] pps: use scoped_guard for pps_idr_lock
Posted by Michal Schmidt 1 year, 2 months ago
Use the scoped_guard syntax to be more brief.

Signed-off-by: Michal Schmidt <mschmidt@redhat.com>
---
 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
Re: [PATCH 3/6] pps: use scoped_guard for pps_idr_lock
Posted by Uwe Kleine-König 1 year, 2 months ago
Hello,

On Mon, Dec 02, 2024 at 05:34:48PM +0100, Michal Schmidt wrote:
> Use the scoped_guard syntax to be more brief.
> 
> Signed-off-by: Michal Schmidt <mschmidt@redhat.com>

This patch undoes most of patch 2. I'd squash these together.

Best regards
Uwe