linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: linux-kernel@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	stable@vger.kernel.org, Johan Hovold <johan@kernel.org>,
	Rob Herring <robh@kernel.org>, Sasha Levin <sashal@kernel.org>
Subject: [PATCH 4.4 25/86] of: add helper to lookup compatible child node
Date: Thu, 29 Nov 2018 15:11:50 +0100	[thread overview]
Message-ID: <20181129140111.907831844@linuxfoundation.org> (raw)
In-Reply-To: <20181129140109.832117862@linuxfoundation.org>

4.4-stable review patch.  If anyone has any objections, please let me know.

------------------

[ Upstream commit 36156f9241cb0f9e37d998052873ca7501ad4b36 ]

Add of_get_compatible_child() helper that can be used to lookup
compatible child nodes.

Several drivers currently use of_find_compatible_node() to lookup child
nodes while failing to notice that the of_find_ functions search the
entire tree depth-first (from a given start node) and therefore can
match unrelated nodes. The fact that these functions also drop a
reference to the node they start searching from (e.g. the parent node)
is typically also overlooked, something which can lead to use-after-free
bugs.

Signed-off-by: Johan Hovold <johan@kernel.org>
Signed-off-by: Rob Herring <robh@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 drivers/of/base.c  | 25 +++++++++++++++++++++++++
 include/linux/of.h |  8 ++++++++
 2 files changed, 33 insertions(+)

diff --git a/drivers/of/base.c b/drivers/of/base.c
index 31341290cd91..c6e019208d17 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -712,6 +712,31 @@ struct device_node *of_get_next_available_child(const struct device_node *node,
 }
 EXPORT_SYMBOL(of_get_next_available_child);
 
+/**
+ * of_get_compatible_child - Find compatible child node
+ * @parent:	parent node
+ * @compatible:	compatible string
+ *
+ * Lookup child node whose compatible property contains the given compatible
+ * string.
+ *
+ * Returns a node pointer with refcount incremented, use of_node_put() on it
+ * when done; or NULL if not found.
+ */
+struct device_node *of_get_compatible_child(const struct device_node *parent,
+				const char *compatible)
+{
+	struct device_node *child;
+
+	for_each_child_of_node(parent, child) {
+		if (of_device_is_compatible(child, compatible))
+			break;
+	}
+
+	return child;
+}
+EXPORT_SYMBOL(of_get_compatible_child);
+
 /**
  *	of_get_child_by_name - Find the child node by name for a given parent
  *	@node:	parent node
diff --git a/include/linux/of.h b/include/linux/of.h
index dd10626a615f..d9371c9cd88a 100644
--- a/include/linux/of.h
+++ b/include/linux/of.h
@@ -265,6 +265,8 @@ extern struct device_node *of_get_next_child(const struct device_node *node,
 extern struct device_node *of_get_next_available_child(
 	const struct device_node *node, struct device_node *prev);
 
+extern struct device_node *of_get_compatible_child(const struct device_node *parent,
+					const char *compatible);
 extern struct device_node *of_get_child_by_name(const struct device_node *node,
 					const char *name);
 
@@ -462,6 +464,12 @@ static inline bool of_have_populated_dt(void)
 	return false;
 }
 
+static inline struct device_node *of_get_compatible_child(const struct device_node *parent,
+					const char *compatible)
+{
+	return NULL;
+}
+
 static inline struct device_node *of_get_child_by_name(
 					const struct device_node *node,
 					const char *name)
-- 
2.17.1




  parent reply	other threads:[~2018-11-29 14:17 UTC|newest]

Thread overview: 92+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-29 14:11 [PATCH 4.4 00/86] 4.4.166-stable review Greg Kroah-Hartman
2018-11-29 14:11 ` [PATCH 4.4 01/86] usb: core: Fix hub port connection events lost Greg Kroah-Hartman
2018-11-29 14:11 ` [PATCH 4.4 02/86] usb: xhci: fix timeout for transition from RExit to U0 Greg Kroah-Hartman
2018-11-29 14:11 ` [PATCH 4.4 03/86] MAINTAINERS: Add Sasha as a stable branch maintainer Greg Kroah-Hartman
2018-11-29 14:11 ` [PATCH 4.4 04/86] iwlwifi: mvm: support sta_statistics() even on older firmware Greg Kroah-Hartman
2018-11-29 14:11 ` [PATCH 4.4 05/86] v9fs_dir_readdir: fix double-free on p9stat_read error Greg Kroah-Hartman
2018-11-29 14:11 ` [PATCH 4.4 06/86] bfs: add sanity check at bfs_fill_super() Greg Kroah-Hartman
2018-11-29 14:11 ` [PATCH 4.4 07/86] sctp: clear the transport of some out_chunk_list chunks in sctp_assoc_rm_peer Greg Kroah-Hartman
2018-11-29 14:11 ` [PATCH 4.4 08/86] gfs2: Dont leave s_fs_info pointing to freed memory in init_sbd Greg Kroah-Hartman
2018-11-29 14:11 ` [PATCH 4.4 09/86] llc: do not use sk_eat_skb() Greg Kroah-Hartman
2018-11-29 14:11 ` [PATCH 4.4 10/86] drm/ast: change resolution may cause screen blurred Greg Kroah-Hartman
2018-11-29 14:11 ` [PATCH 4.4 11/86] drm/ast: fixed cursor may disappear sometimes Greg Kroah-Hartman
2018-11-29 14:11 ` [PATCH 4.4 12/86] can: dev: can_get_echo_skb(): factor out non sending code to __can_get_echo_skb() Greg Kroah-Hartman
2018-11-29 14:11 ` [PATCH 4.4 13/86] can: dev: __can_get_echo_skb(): replace struct can_frame by canfd_frame to access frame length Greg Kroah-Hartman
2018-11-29 14:11 ` [PATCH 4.4 14/86] can: dev: __can_get_echo_skb(): Dont crash the kernel if can_priv::echo_skb is accessed out of bounds Greg Kroah-Hartman
2018-11-29 14:11 ` [PATCH 4.4 15/86] can: dev: __can_get_echo_skb(): print error message, if trying to echo non existing skb Greg Kroah-Hartman
2018-11-29 14:11 ` [PATCH 4.4 16/86] ACPICA: AML interpreter: add region addresses in global list during initialization Greg Kroah-Hartman
2018-11-29 14:11 ` [PATCH 4.4 17/86] usb: xhci: Prevent bus suspend if a port connect change or polling state is detected Greg Kroah-Hartman
2018-11-29 14:11 ` [PATCH 4.4 18/86] KVM: PPC: Move and undef TRACE_INCLUDE_PATH/FILE Greg Kroah-Hartman
2018-11-29 14:11 ` [PATCH 4.4 19/86] cpufreq: imx6q: add return value check for voltage scale Greg Kroah-Hartman
2018-11-29 14:11 ` [PATCH 4.4 20/86] ARM: make lookup_processor_type() non-__init Greg Kroah-Hartman
2018-11-29 14:11 ` [PATCH 4.4 21/86] SUNRPC: Fix a bogus get/put in generic_key_to_expire() Greg Kroah-Hartman
2018-11-29 14:11 ` [PATCH 4.4 22/86] kdb: Use strscpy with destination buffer size Greg Kroah-Hartman
2018-11-29 14:11 ` [PATCH 4.4 23/86] powerpc/numa: Suppress "VPHN is not supported" messages Greg Kroah-Hartman
2018-11-29 14:11 ` [PATCH 4.4 24/86] tmpfs: make lseek(SEEK_DATA/SEK_HOLE) return ENXIO with a negative offset Greg Kroah-Hartman
2018-11-29 14:11 ` Greg Kroah-Hartman [this message]
2018-11-29 14:11 ` [PATCH 4.4 26/86] NFC: nfcmrvl_uart: fix OF child-node lookup Greg Kroah-Hartman
2018-11-29 14:11 ` [PATCH 4.4 27/86] net: bcmgenet: " Greg Kroah-Hartman
2018-11-29 14:11 ` [PATCH 4.4 28/86] x86/entry: spell EBX register correctly in documentation Greg Kroah-Hartman
2018-11-29 14:11 ` [PATCH 4.4 29/86] x86/entry/64: Remove %ebx handling from error_entry/exit Greg Kroah-Hartman
2018-11-29 14:11 ` [PATCH 4.4 30/86] arm64: remove no-op -p linker flag Greg Kroah-Hartman
2018-11-29 14:11 ` [PATCH 4.4 31/86] ath10k: fix kernel panic due to race in accessing arvif list Greg Kroah-Hartman
2018-11-29 14:11 ` [PATCH 4.4 32/86] Input: xpad - remove spurious events of wireless xpad 360 controller Greg Kroah-Hartman
2018-11-29 14:11 ` [PATCH 4.4 33/86] Input: xpad - handle "present" and "gone" correctly Greg Kroah-Hartman
2018-11-29 14:11 ` [PATCH 4.4 34/86] Input: xpad - update Xbox One Force Feedback Support Greg Kroah-Hartman
2018-11-29 14:12 ` [PATCH 4.4 35/86] Input: xpad - workaround dead irq_out after suspend/ resume Greg Kroah-Hartman
2018-11-29 14:12 ` [PATCH 4.4 36/86] Input: xpad - use LED API when identifying wireless controllers Greg Kroah-Hartman
2018-11-29 14:12 ` [PATCH 4.4 37/86] Input: xpad - correct xbox one pad device name Greg Kroah-Hartman
2018-11-29 14:12 ` [PATCH 4.4 38/86] Input: xpad - remove unused function Greg Kroah-Hartman
2018-11-29 14:12 ` [PATCH 4.4 39/86] Input: xpad - add Mad Catz FightStick TE 2 VID/PID Greg Kroah-Hartman
2018-11-29 14:12 ` [PATCH 4.4 40/86] Input: xpad - prevent spurious input from wired Xbox 360 controllers Greg Kroah-Hartman
2018-11-29 14:12 ` [PATCH 4.4 41/86] Input: xpad - add more third-party controllers Greg Kroah-Hartman
2018-11-29 14:12 ` [PATCH 4.4 42/86] Input: xpad - xbox one elite controller support Greg Kroah-Hartman
2018-11-29 14:12 ` [PATCH 4.4 43/86] Input: xpad - fix rumble on Xbox One controllers with 2015 firmware Greg Kroah-Hartman
2018-11-29 14:12 ` [PATCH 4.4 44/86] Input: xpad - power off wireless 360 controllers on suspend Greg Kroah-Hartman
2018-11-29 14:12 ` [PATCH 4.4 45/86] Input: xpad - add product ID for Xbox One S pad Greg Kroah-Hartman
2018-11-29 14:12 ` [PATCH 4.4 46/86] Input: xpad - fix Xbox One rumble stopping after 2.5 secs Greg Kroah-Hartman
2018-11-29 14:12 ` [PATCH 4.4 47/86] Input: xpad - correctly sort vendor ids Greg Kroah-Hartman
2018-11-29 14:12 ` [PATCH 4.4 48/86] Input: xpad - move reporting xbox one home button to common function Greg Kroah-Hartman
2018-11-29 14:12 ` [PATCH 4.4 49/86] Input: xpad - simplify error condition in init_output Greg Kroah-Hartman
2018-11-29 14:12 ` [PATCH 4.4 50/86] Input: xpad - dont depend on endpoint order Greg Kroah-Hartman
2018-11-29 14:12 ` [PATCH 4.4 51/86] Input: xpad - fix stuck mode button on Xbox One S pad Greg Kroah-Hartman
2018-11-29 14:12 ` [PATCH 4.4 52/86] Input: xpad - restore LED state after device resume Greg Kroah-Hartman
2018-11-29 14:12 ` [PATCH 4.4 53/86] Input: xpad - support some quirky Xbox One pads Greg Kroah-Hartman
2018-11-29 14:12 ` [PATCH 4.4 54/86] Input: xpad - sort supported devices by USB ID Greg Kroah-Hartman
2018-11-29 14:12 ` [PATCH 4.4 55/86] Input: xpad - sync supported devices with xboxdrv Greg Kroah-Hartman
2018-11-29 14:12 ` [PATCH 4.4 56/86] Input: xpad - add USB IDs for Mad Catz Brawlstick and Razer Sabertooth Greg Kroah-Hartman
2018-11-29 14:12 ` [PATCH 4.4 57/86] Input: xpad - sync supported devices with 360Controller Greg Kroah-Hartman
2018-11-29 14:12 ` [PATCH 4.4 58/86] Input: xpad - sync supported devices with XBCD Greg Kroah-Hartman
2018-11-29 14:12 ` [PATCH 4.4 59/86] Input: xpad - constify usb_device_id Greg Kroah-Hartman
2018-11-29 14:12 ` [PATCH 4.4 60/86] Input: xpad - fix PowerA init quirk for some gamepad models Greg Kroah-Hartman
2018-11-29 14:12 ` [PATCH 4.4 61/86] Input: xpad - validate USB endpoint type during probe Greg Kroah-Hartman
2018-11-29 14:12 ` [PATCH 4.4 62/86] Input: xpad - add support for PDP Xbox One controllers Greg Kroah-Hartman
2018-11-29 14:12 ` [PATCH 4.4 63/86] Input: xpad - add PDP device id 0x02a4 Greg Kroah-Hartman
2018-11-29 14:12 ` [PATCH 4.4 64/86] Input: xpad - fix some coding style issues Greg Kroah-Hartman
2018-11-29 14:12 ` [PATCH 4.4 65/86] Input: xpad - avoid using __set_bit() for capabilities Greg Kroah-Hartman
2018-11-29 14:12 ` [PATCH 4.4 66/86] Input: xpad - add GPD Win 2 Controller USB IDs Greg Kroah-Hartman
2018-11-29 14:12 ` [PATCH 4.4 67/86] Input: xpad - fix GPD Win 2 controller name Greg Kroah-Hartman
2018-11-29 14:12 ` [PATCH 4.4 68/86] Input: xpad - add support for Xbox1 PDP Camo series gamepad Greg Kroah-Hartman
2018-11-29 14:12 ` [PATCH 4.4 69/86] cw1200: Dont leak memory if krealloc failes Greg Kroah-Hartman
2018-11-29 14:12 ` [PATCH 4.4 70/86] mwifiex: Fix NULL pointer dereference in skb_dequeue() Greg Kroah-Hartman
2018-11-29 14:12 ` [PATCH 4.4 71/86] mwifiex: fix p2p device doesnt find in scan problem Greg Kroah-Hartman
2018-11-29 14:12 ` [PATCH 4.4 72/86] netfilter: nf_tables: fix oops when inserting an element into a verdict map Greg Kroah-Hartman
2018-11-29 14:12 ` [PATCH 4.4 73/86] scsi: ufs: fix bugs related to null pointer access and array size Greg Kroah-Hartman
2018-11-29 14:12 ` [PATCH 4.4 74/86] scsi: ufshcd: Fix race between clk scaling and ungate work Greg Kroah-Hartman
2018-11-29 14:12 ` [PATCH 4.4 75/86] scsi: ufs: fix race between clock gating and devfreq scaling work Greg Kroah-Hartman
2018-11-29 14:12 ` [PATCH 4.4 76/86] scsi: ufshcd: release resources if probe fails Greg Kroah-Hartman
2018-11-29 14:12 ` [PATCH 4.4 77/86] scsi: qla2xxx: do not queue commands when unloading Greg Kroah-Hartman
2018-11-29 14:12 ` [PATCH 4.4 78/86] iwlwifi: mvm: fix regulatory domain update when the firmware starts Greg Kroah-Hartman
2018-11-29 14:12 ` [PATCH 4.4 79/86] tty: wipe buffer Greg Kroah-Hartman
2018-11-29 14:12 ` [PATCH 4.4 80/86] tty: wipe buffer if not echoing data Greg Kroah-Hartman
2018-11-29 14:12 ` [PATCH 4.4 81/86] usb: xhci: fix uninitialized completion when USB3 port got wrong status Greg Kroah-Hartman
2018-11-29 14:12 ` [PATCH 4.4 82/86] btrfs: Ensure btrfs_trim_fs can trim the whole filesystem Greg Kroah-Hartman
2018-11-29 14:12 ` [PATCH 4.4 83/86] sched/core: Allow __sched_setscheduler() in interrupts when PI is not used Greg Kroah-Hartman
2018-11-29 14:12 ` [PATCH 4.4 84/86] namei: allow restricted O_CREAT of FIFOs and regular files Greg Kroah-Hartman
2018-11-29 14:12 ` [PATCH 4.4 85/86] s390/mm: Check for valid vma before zapping in gmap_discard Greg Kroah-Hartman
2018-11-29 14:12 ` [PATCH 4.4 86/86] drm/ast: Remove existing framebuffers before loading driver Greg Kroah-Hartman
2018-11-29 19:51 ` [PATCH 4.4 00/86] 4.4.166-stable review kernelci.org bot
2018-11-29 20:26 ` shuah
2018-11-29 21:49 ` Harsh Shandilya
2018-11-30  9:00 ` Naresh Kamboju
2018-11-30 22:27 ` Guenter Roeck

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=20181129140111.907831844@linuxfoundation.org \
    --to=gregkh@linuxfoundation.org \
    --cc=johan@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=robh@kernel.org \
    --cc=sashal@kernel.org \
    --cc=stable@vger.kernel.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 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).