diff mbox

phy: fix kernel oops in phy_lookup()

Message ID 201404110259.43282.sergei.shtylyov@cogentembedded.com (mailing list archive)
State Accepted
Commit 743bb387a1edbf1ebbba6cf77c1af3e488886c39
Headers show

Commit Message

Sergei Shtylyov April 10, 2014, 10:59 p.m. UTC
The kernel oopses in phy_lookup() due to 'phy->init_data' being NULL if we
register PHYs from a device tree probing driver and then call phy_get() on a
device that has no representation in the device tree (e.g. a PCI device).
Checking the pointer before dereferening it and skipping an interation if
it's NULL prevents this kernel oops.

Signed-off-by: Sergei Shtylyov <sergei.shtylyov@cogentembedded.com>

---
The patch is against the 'fixes' branch of Kishon's 'linux-phy.git' repo.

 drivers/phy/phy-core.c |    3 +++
 1 file changed, 3 insertions(+)

--
To unsubscribe from this list: send the line "unsubscribe linux-sh" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

Index: linux-phy/drivers/phy/phy-core.c
===================================================================
--- linux-phy.orig/drivers/phy/phy-core.c
+++ linux-phy/drivers/phy/phy-core.c
@@ -64,6 +64,9 @@  static struct phy *phy_lookup(struct dev
 	class_dev_iter_init(&iter, phy_class, NULL, NULL);
 	while ((dev = class_dev_iter_next(&iter))) {
 		phy = to_phy(dev);
+
+		if (!phy->init_data)
+			continue;
 		count = phy->init_data->num_consumers;
 		consumers = phy->init_data->consumers;
 		while (count--) {