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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Jonathan Cameron <Jonathan.Cameron@xxxxxxxxxx>

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

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

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);
 }
 
-- 
2.43.1





[Index of Archives]     [Linux IBM ACPI]     [Linux Power Management]     [Linux Kernel]     [Linux Laptop]     [Kernel Newbies]     [Share Photos]     [Security]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Video 4 Linux]     [Device Mapper]     [Linux Resources]
  Powered by Linux