All of lore.kernel.org
 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, kieran.bingham@ideasonboard.com
Subject: [PATCH v6 2/3] of: Make of_fwnode_handle() safer
Date: Wed, 24 May 2017 17:53:54 +0300	[thread overview]
Message-ID: <1495637635-26057-3-git-send-email-sakari.ailus@linux.intel.com> (raw)
In-Reply-To: <1495637635-26057-1-git-send-email-sakari.ailus@linux.intel.com>

On the expense of a little bit more complexity in the of_fwnode_handle()
macro, make the macro result in NULL in case its argument is NULL while
still referencing it only once.

Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Reviewed-by: Kieran Bingham <kieran.bingham+renesas@ideasonboard.com>
---
 include/linux/of.h | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/include/linux/of.h b/include/linux/of.h
index 50fcdb5..f05c87f 100644
--- a/include/linux/of.h
+++ b/include/linux/of.h
@@ -159,7 +159,13 @@ static inline struct device_node *to_of_node(struct fwnode_handle *fwnode)
 		container_of(fwnode, struct device_node, fwnode) : NULL;
 }
 
-#define of_fwnode_handle(node) (&(node)->fwnode)
+#define of_fwnode_handle(node)						\
+	({								\
+		typeof(node) __of_fwnode_handle_node = (node);		\
+									\
+		__of_fwnode_handle_node ?				\
+			&__of_fwnode_handle_node->fwnode : NULL;	\
+	})
 
 static inline bool of_have_populated_dt(void)
 {
-- 
2.7.4


  parent reply	other threads:[~2017-05-24 14:55 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-24 14:53 [PATCH v6 0/3] Preparation for further fwnode property cleanup Sakari Ailus
2017-05-24 14:53 ` [PATCH v6 1/3] of: Move OF property and graph API from base.c to property.c Sakari Ailus
2017-05-24 14:53 ` Sakari Ailus [this message]
2017-05-24 14:53 ` [PATCH v6 3/3] of: Support const and non-const use for to_of_node() Sakari Ailus
2017-05-31 12:28 ` [PATCH v6 0/3] Preparation for further fwnode property cleanup Sakari Ailus
2017-06-05 15:12   ` Rob Herring
2017-06-07 11:42     ` Sakari Ailus

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=1495637635-26057-3-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=kieran.bingham@ideasonboard.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 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.