Skip to contentSkip to conversation

usb: phy: am335x-control: check return value of bus_find_device

PATCH In review David Dueck 2 participants 2 messages Feb 8, 2015 USB

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 usb: phy: am335x-control: check return value of bus_find_device

This fixes a potential null pointer dereference.

---
 drivers/usb/phy/phy-am335x-control.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/usb/phy/phy-am335x-control.c +3 -0
index 403fab7..7b3035f 100644
@@ -126,6 +126,9 @@ struct phy_control *am335x_get_phy_control(struct device *dev)
 		return NULL;
 
 	dev = bus_find_device(&platform_bus_type, NULL, node, match);
+	if (!dev)
+		return NULL;
+
 	ctrl_usb = dev_get_drvdata(dev);
 	if (!ctrl_usb)
 		return NULL;
Signature · 1 line
2.2.2
Acked-by on v1 1/1
#1 lore raw
Quoted 3 lines · David Dueck

This fixes a potential null pointer dereference.

Fixes d4332013919a ("driver core: dev_get_drvdata: Don't check for NULL

dev")

Greg, this is a regression since d43320139 ("driver core:
dev_get_drvdata: Don't check for NULL dev"). I didn't check for NULL after bus_find_device() because I knew that dev_get_drvdata() will do it.

Quoted 10 lines
---
 drivers/usb/phy/phy-am335x-control.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/usb/phy/phy-am335x-control.c +0 -0
index 403fab7..7b3035f 100644

drivers/usb/phy/phy-am335x-control.c struct phy_control *am335x_get_phy_control(struct device *dev) · line 134

Quoted 9 lines
drivers/usb/phy/phy-am335x-control.c +3 -0
@@ -126,6 +126,9 @@ struct phy_control *am335x_get_phy_control(struct device *dev)
 		return NULL;
 
 	dev = bus_find_device(&platform_bus_type, NULL, node, match);
+	if (!dev)
+		return NULL;
+
 	ctrl_usb = dev_get_drvdata(dev)
 	if (!ctrl_usb)
 		return NULL;

Sebastian