All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Frkuska, Joshua" <joshua_frkuska-nmGgyN9QBj3QT0dZR+AlfA@public.gmane.org>
To: linux-i2c-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Cc: Wolfram Sang <wsa-z923LK4zBo2bacvFa/9K2g@public.gmane.org>
Subject: [RFC PATCH 1/1] i2c: core: add of_get_i2c_adapter_by_node
Date: Mon, 29 Jun 2015 15:36:19 +0900	[thread overview]
Message-ID: <5590E763.3090703@mentor.com> (raw)

This adds of_get_i2c_adapter_by_node which both finds and properly
increments the adapter reference count.

This is different from of_find_i2c_device_by_node which does not
increment the adapter reference counter.

Signed-off-by: Vladimir Zapolskiy <vladimir_zapolskiy-nmGgyN9QBj3QT0dZR+AlfA@public.gmane.org>
Signed-off-by: Joshua Frkuska <joshua_frkuska-nmGgyN9QBj3QT0dZR+AlfA@public.gmane.org>
---
  drivers/i2c/i2c-core.c | 20 ++++++++++++++++++++
  1 file changed, 20 insertions(+)

diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
index 987c124..97caec6 100644
--- a/drivers/i2c/i2c-core.c
+++ b/drivers/i2c/i2c-core.c
@@ -1347,6 +1347,26 @@ struct i2c_adapter 
*of_find_i2c_adapter_by_node(struct device_node *node)
      return i2c_verify_adapter(dev);
  }
  EXPORT_SYMBOL(of_find_i2c_adapter_by_node);
+
+/* must call put_device() when done with returned i2c_adapter device */
+struct i2c_adapter *of_get_i2c_adapter_by_node(struct device_node *node)
+{
+    struct device *dev;
+    struct i2c_adapter *adapter;
+
+    dev = bus_find_device(&i2c_bus_type, NULL, node,
+                of_dev_node_match);
+    if (!dev)
+        return NULL;
+
+    adapter = i2c_verify_adapter(dev);
+
+    if (adapter && !try_module_get(adapter->owner))
+        adapter = NULL;
+
+    return adapter;
+}
+EXPORT_SYMBOL(of_get_i2c_adapter_by_node);
  #else
  static void of_i2c_register_devices(struct i2c_adapter *adap) { }
  #endif /* CONFIG_OF */

-- 
Joshua Frkuska | Embedded Software Engineer
Mentor Embedded Software Division
Mentor Graphics Japan Co., ltd.

             reply	other threads:[~2015-06-29  6:36 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-29  6:36 Frkuska, Joshua [this message]
     [not found] ` <5590E763.3090703-nmGgyN9QBj3QT0dZR+AlfA@public.gmane.org>
2015-06-29  8:17   ` [RFC PATCH 1/1] i2c: core: add of_get_i2c_adapter_by_node Wolfram Sang
2015-06-29 14:14     ` Vladimir Zapolskiy

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=5590E763.3090703@mentor.com \
    --to=joshua_frkuska-nmggyn9qbj3qt0dzr+alfa@public.gmane.org \
    --cc=linux-i2c-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=wsa-z923LK4zBo2bacvFa/9K2g@public.gmane.org \
    /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.