All of lore.kernel.org
 help / color / mirror / Atom feed
From: Kieran Bingham <kieran.bingham+renesas@ideasonboard.com>
To: linux-renesas-soc@vger.kernel.org
Cc: "Kieran Bingham" <kieran.bingham@ideasonboard.com>,
	"Laurent Pinchart" <laurent.pinchart@ideasonboard.com>,
	"Jacopo Mondi" <jacopo@jmondi.org>,
	"Niklas Söderlund" <niklas.soderlund@ragnatech.se>,
	"Hyun Kwon" <hyunk@xilinx.com>,
	"Manivannan Sadhasivam" <manivannan.sadhasivam@linaro.org>,
	"Kieran Bingham" <kieran.bingham+renesas@ideasonboard.com>
Subject: [PATCH v9 3/3] fixes! [max9286]: Fix dev->of_node refcnting
Date: Thu, 14 May 2020 15:00:16 +0100	[thread overview]
Message-ID: <20200514140016.1445489-4-kieran.bingham+renesas@ideasonboard.com> (raw)
In-Reply-To: <20200514140016.1445489-1-kieran.bingham+renesas@ideasonboard.com>

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@ideasonboard.com>
---
 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


  parent reply	other threads:[~2020-05-14 14:00 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-14 14:00 [PATCH v9.1 0/3] MAX9286 fixups Kieran Bingham
2020-05-14 14:00 ` [PATCH v9.1 1/3] fixes! [max9286]: Use the same default mbus_fmt everywhere Kieran Bingham
2020-05-14 14:00 ` [PATCH v9 2/3] fixes! [max9286]: Don't provide GPIO names Kieran Bingham
2020-05-14 14:00 ` Kieran Bingham [this message]
2020-05-16 14:25 ` [PATCH v9.1 0/3] MAX9286 fixups Jacopo Mondi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200514140016.1445489-4-kieran.bingham+renesas@ideasonboard.com \
    --to=kieran.bingham+renesas@ideasonboard.com \
    --cc=hyunk@xilinx.com \
    --cc=jacopo@jmondi.org \
    --cc=kieran.bingham@ideasonboard.com \
    --cc=laurent.pinchart@ideasonboard.com \
    --cc=linux-renesas-soc@vger.kernel.org \
    --cc=manivannan.sadhasivam@linaro.org \
    --cc=niklas.soderlund@ragnatech.se \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.