phy: fix kernel oops in phy_lookup()
authorSergei Shtylyov <sergei.shtylyov@cogentembedded.com>
Sat, 19 Apr 2014 03:21:43 +0000 (08:51 +0530)
committerSimon Horman <horms+renesas@verge.net.au>
Fri, 5 Dec 2014 04:13:21 +0000 (13:13 +0900)
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>
Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
(cherry picked from commit 743bb387a1edbf1ebbba6cf77c1af3e488886c39)
Signed-off-by: Simon Horman <horms+renesas@verge.net.au>
drivers/phy/phy-core.c

index 59879bf..59ce9cd 100644 (file)
@@ -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--) {