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 2/3] of: Make of_fwnode_handle() safer
Date: Mon, 22 May 2017 11:11:37 +0300 [thread overview]
Message-ID: <1495440698-22260-3-git-send-email-sakari.ailus@linux.intel.com> (raw)
In-Reply-To: <1495440698-22260-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>
---
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..a7ccf34 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
next prev 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 ` Sakari Ailus [this message]
2017-05-24 10:31 ` [PATCH v5 2/3] of: Make of_fwnode_handle() safer Kieran Bingham
2017-05-22 8:11 ` [PATCH v5 3/3] of: Support const and non-const use for to_of_node() Sakari Ailus
2017-05-23 6:39 ` [PATCH v5.1 " 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-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=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).