devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sakari Ailus <sakari.ailus@linux.intel.com>
To: devicetree@vger.kernel.org, robh@kernel.org, frowand.list@gmail.com
Cc: linux-acpi@vger.kernel.org, sudeep.holla@arm.com,
	lorenzo.pieralisi@arm.com, mika.westerberg@linux.intel.com,
	rafael@kernel.org, mark.rutland@arm.com, broonie@kernel.org,
	ahs3@redhat.com
Subject: [PATCH v5 3/3] of: Support const and non-const use for to_of_node()
Date: Mon, 22 May 2017 11:11:38 +0300	[thread overview]
Message-ID: <1495440698-22260-4-git-send-email-sakari.ailus@linux.intel.com> (raw)
In-Reply-To: <1495440698-22260-1-git-send-email-sakari.ailus@linux.intel.com>

Turn to_of_node() into a macro in order to support both const and
non-const use. Additionally make the fwnode argument to is_of_node() const
as well.

Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
---
 include/linux/of.h | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)

diff --git a/include/linux/of.h b/include/linux/of.h
index a7ccf34..52ffebc 100644
--- a/include/linux/of.h
+++ b/include/linux/of.h
@@ -148,16 +148,20 @@ extern raw_spinlock_t devtree_lock;
 #ifdef CONFIG_OF
 void of_core_init(void);
 
-static inline bool is_of_node(struct fwnode_handle *fwnode)
+static inline bool is_of_node(const struct fwnode_handle *fwnode)
 {
 	return !IS_ERR_OR_NULL(fwnode) && fwnode->type == FWNODE_OF;
 }
 
-static inline struct device_node *to_of_node(struct fwnode_handle *fwnode)
-{
-	return is_of_node(fwnode) ?
-		container_of(fwnode, struct device_node, fwnode) : NULL;
-}
+#define to_of_node(__fwnode)						\
+	({								\
+		typeof(__fwnode) __to_of_node_fwnode = __fwnode;	\
+									\
+		is_of_node(__to_of_node_fwnode) ?			\
+			container_of(__to_of_node_fwnode,		\
+				     struct device_node, fwnode) :	\
+			NULL;						\
+	})
 
 #define of_fwnode_handle(node)						\
 	({								\
@@ -539,12 +543,12 @@ static inline void of_core_init(void)
 {
 }
 
-static inline bool is_of_node(struct fwnode_handle *fwnode)
+static inline bool is_of_node(const struct fwnode_handle *fwnode)
 {
 	return false;
 }
 
-static inline struct device_node *to_of_node(struct fwnode_handle *fwnode)
+static inline const struct device_node *to_of_node(struct fwnode_handle *fwnode)
 {
 	return NULL;
 }
-- 
2.7.4


  parent reply	other threads:[~2017-05-22  8:11 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-22  8:11 [PATCH v5 0/3] Preparation for further fwnode property cleanup Sakari Ailus
2017-05-22  8:11 ` [PATCH v5 1/3] of: Move OF property and graph API from base.c to property.c Sakari Ailus
2017-05-22 14:22   ` Rob Herring
2017-05-22 14:33     ` Sakari Ailus
2017-05-22 14:38       ` Rob Herring
2017-05-22 14:42   ` [PATCH v5.1 " Sakari Ailus
2017-05-22  8:11 ` [PATCH v5 2/3] of: Make of_fwnode_handle() safer Sakari Ailus
2017-05-24 10:31   ` Kieran Bingham
2017-05-22  8:11 ` Sakari Ailus [this message]
2017-05-23  6:39   ` [PATCH v5.1 3/3] of: Support const and non-const use for to_of_node() Sakari Ailus
     [not found]     ` <1495521543-31570-1-git-send-email-sakari.ailus-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
2017-05-24 10:48       ` Kieran Bingham

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=1495440698-22260-4-git-send-email-sakari.ailus@linux.intel.com \
    --to=sakari.ailus@linux.intel.com \
    --cc=ahs3@redhat.com \
    --cc=broonie@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=frowand.list@gmail.com \
    --cc=linux-acpi@vger.kernel.org \
    --cc=lorenzo.pieralisi@arm.com \
    --cc=mark.rutland@arm.com \
    --cc=mika.westerberg@linux.intel.com \
    --cc=rafael@kernel.org \
    --cc=robh@kernel.org \
    --cc=sudeep.holla@arm.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).