[PATCH v9 3/3] fixes! [max9286]: Fix dev->of_node refcnting

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

 



With a little help from an of_ref_read():

+static int of_ref_read(struct device_node *node)
+{
+       if (node)
+               return kref_read(&node->kobj.kref);
+
+       return 0;
+}

I've validated the refcount of the node now stays consitent.
Particularly between entry (A) and exit (B) of the parse_dt function:

[    2.305784] max9286 4-004c: A: node refcnt is 6
[    2.310401] max9286 4-004c: node refcnt is 6
[    2.314729] max9286 4-004c: 1335: node refcnt is 6
[    2.319587] max9286 4-004c: 1356: node refcnt is 6
[    2.324432] max9286 4-004c: 1364: (in for_each) node refcnt is 6
[    2.330503] max9286 4-004c: 1364: (in for_each) node refcnt is 6
[    2.336575] max9286 4-004c: 1364: (in for_each) node refcnt is 6
[    2.342656] max9286 4-004c: 1364: (in for_each) node refcnt is 6
[    2.348724] max9286 4-004c: 1364: (in for_each) node refcnt is 6
[    2.354808] max9286 4-004c: 1437: node refcnt is 6
[    2.359644] max9286 4-004c: B: node refcnt is 6

I've added a comment to explain the extra of_node_get() but the exercise
identified that the driver was incorrectly calling of_node_put() on the
same node. Those have been removed.

Signed-off-by: Kieran Bingham <kieran.bingham+renesas@xxxxxxxxxxxxxxxx>
---
 drivers/media/i2c/max9286.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/drivers/media/i2c/max9286.c b/drivers/media/i2c/max9286.c
index 66201dc4b7f7..590f384161a5 100644
--- a/drivers/media/i2c/max9286.c
+++ b/drivers/media/i2c/max9286.c
@@ -1108,11 +1108,11 @@ static int max9286_parse_dt(struct max9286_priv *priv)
 	struct device_node *node = NULL;
 	unsigned int i2c_mux_mask = 0;
 
+	/* Balance the of_node_put() performed by of_find_node_by_name(). */
 	of_node_get(dev->of_node);
 	i2c_mux = of_find_node_by_name(dev->of_node, "i2c-mux");
 	if (!i2c_mux) {
 		dev_err(dev, "Failed to find i2c-mux node\n");
-		of_node_put(dev->of_node);
 		return -EINVAL;
 	}
 
@@ -1160,7 +1160,6 @@ static int max9286_parse_dt(struct max9286_priv *priv)
 					of_fwnode_handle(node), &vep);
 			if (ret) {
 				of_node_put(node);
-				of_node_put(dev->of_node);
 				return ret;
 			}
 
@@ -1170,7 +1169,6 @@ static int max9286_parse_dt(struct max9286_priv *priv)
 					vep.bus_type);
 				v4l2_fwnode_endpoint_free(&vep);
 				of_node_put(node);
-				of_node_put(dev->of_node);
 				return -EINVAL;
 			}
 
@@ -1208,7 +1206,6 @@ static int max9286_parse_dt(struct max9286_priv *priv)
 		priv->nsources++;
 	}
 	of_node_put(node);
-	of_node_put(dev->of_node);
 
 	priv->route_mask = priv->source_mask;
 
-- 
2.25.1




[Index of Archives]     [Linux Samsung SOC]     [Linux Wireless]     [Linux Kernel]     [ATH6KL]     [Linux Bluetooth]     [Linux Netdev]     [Kernel Newbies]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Samba]     [Device Mapper]

  Powered by Linux