public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] USB: core: of: Check device_node before parsing in usb_of_get_child_node()
@ 2016-08-15 18:31 Vaibhav Hiremath
  2016-08-15 18:41 ` Greg KH
  2016-08-16  1:33 ` Peter Chen
  0 siblings, 2 replies; 6+ messages in thread
From: Vaibhav Hiremath @ 2016-08-15 18:31 UTC (permalink / raw)
  To: linux-usb
  Cc: gregkh, robh, p.zabel, stern, arnd, peter.chen, linux-kernel,
	Vaibhav Hiremath

In case of HUB devices connected to USB ports, we may not have DT
node representing it inside USB, and when devices connected to hub
gets enumerated, call to usb_of_get_child_node() leads to NULL pointer
dereference.

In the usecase we have, where EHCI port is connected to USB HUB
device, and downward ports of HUB are connected to further USB
devices. When those devices gets enumerated, in order,
 1. USB HUB ->
	-> Call to usb_of_get_child_node() is OK, as
	parent->dev.of_node is pointing to host node.
 2. Devices connected to downward port of USB HUB
 	-> Call to usb_of_get_child_node() leads to NULL
	pointer dereference as parent->dev.of_node = NULL,
	as USB HUB DTS node may be empty.

Fix this NULL pointer dereference by adding check for pointer
device_node inside usb_of_get_child_node() fn.

Signed-off-by: Vaibhav Hiremath <vaibhav.hiremath@linaro.org>
---
Testing: I have build tested it against mainline.

 drivers/usb/core/of.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/usb/core/of.c b/drivers/usb/core/of.c
index 2289700..dc667a3 100644
--- a/drivers/usb/core/of.c
+++ b/drivers/usb/core/of.c
@@ -34,6 +34,9 @@ struct device_node *usb_of_get_child_node(struct device_node *parent,
 	struct device_node *node;
 	u32 port;
 
+	if (!parent)
+		return NULL;
+
 	for_each_child_of_node(parent, node) {
 		if (!of_property_read_u32(node, "reg", &port)) {
 			if (port == portnum)
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2016-08-16 21:21 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-08-15 18:31 [PATCH] USB: core: of: Check device_node before parsing in usb_of_get_child_node() Vaibhav Hiremath
2016-08-15 18:41 ` Greg KH
2016-08-15 19:18   ` Vaibhav Hiremath
2016-08-15 19:34   ` Alan Stern
2016-08-16  1:33 ` Peter Chen
2016-08-16 21:14   ` Vaibhav Hiremath

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox