From aa71f1ca4aa061f91d871a803e1e3719d97a656c Mon Sep 17 00:00:00 2001 From: Sergei Shtylyov Date: Sat, 19 Apr 2014 08:51:43 +0530 Subject: [PATCH] phy: fix kernel oops in phy_lookup() 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 Signed-off-by: Kishon Vijay Abraham I Signed-off-by: Greg Kroah-Hartman (cherry picked from commit 743bb387a1edbf1ebbba6cf77c1af3e488886c39) Signed-off-by: Simon Horman --- drivers/phy/phy-core.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/phy/phy-core.c b/drivers/phy/phy-core.c index 59879bf..59ce9cd 100644 --- a/drivers/phy/phy-core.c +++ b/drivers/phy/phy-core.c @@ -64,6 +64,9 @@ static struct phy *phy_lookup(struct device *device, const char *port) 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--) { -- 2.7.4