diff mbox series

[8/8] iio: adc: adi-axi-adc: Use __free(device_node) and guard(mutex)

Message ID 20240211174237.182947-9-jic23@kernel.org
State New
Headers show
Series of: automate of_node_put() - new approach to loops. | expand

Commit Message

Jonathan Cameron Feb. 11, 2024, 5:42 p.m. UTC
From: Jonathan Cameron <Jonathan.Cameron@huawei.com>

Avoid need to manually handle of_node_put() or the unlocking of the
mutex.

Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
---
 drivers/iio/adc/adi-axi-adc.c | 16 ++++------------
 1 file changed, 4 insertions(+), 12 deletions(-)
diff mbox series

Patch

diff --git a/drivers/iio/adc/adi-axi-adc.c b/drivers/iio/adc/adi-axi-adc.c
index c247ff1541d2..3c85e8a6467b 100644
--- a/drivers/iio/adc/adi-axi-adc.c
+++ b/drivers/iio/adc/adi-axi-adc.c
@@ -248,19 +248,19 @@  static struct adi_axi_adc_client *adi_axi_adc_attach_client(struct device *dev)
 {
 	const struct adi_axi_adc_core_info *info;
 	struct adi_axi_adc_client *cl;
-	struct device_node *cln;
 
 	info = of_device_get_match_data(dev);
 	if (!info)
 		return ERR_PTR(-ENODEV);
 
-	cln = of_parse_phandle(dev->of_node, "adi,adc-dev", 0);
+	struct device_node *cln __free(device_node) =
+		of_parse_phandle(dev->of_node, "adi,adc-dev", 0);
 	if (!cln) {
 		dev_err(dev, "No 'adi,adc-dev' node defined\n");
 		return ERR_PTR(-ENODEV);
 	}
 
-	mutex_lock(&registered_clients_lock);
+	guard(mutex)(&registered_clients_lock);
 
 	list_for_each_entry(cl, &registered_clients, entry) {
 		if (!cl->dev)
@@ -269,22 +269,14 @@  static struct adi_axi_adc_client *adi_axi_adc_attach_client(struct device *dev)
 		if (cl->dev->of_node != cln)
 			continue;
 
-		if (!try_module_get(cl->dev->driver->owner)) {
-			mutex_unlock(&registered_clients_lock);
-			of_node_put(cln);
+		if (!try_module_get(cl->dev->driver->owner))
 			return ERR_PTR(-ENODEV);
-		}
 
 		get_device(cl->dev);
 		cl->info = info;
-		mutex_unlock(&registered_clients_lock);
-		of_node_put(cln);
 		return cl;
 	}
 
-	mutex_unlock(&registered_clients_lock);
-	of_node_put(cln);
-
 	return ERR_PTR(-EPROBE_DEFER);
 }