Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp5480442imm; Tue, 26 Jun 2018 12:00:52 -0700 (PDT) X-Google-Smtp-Source: ADUXVKKem9CNSUV+jmgewx5sv91HQJtWDg4eIhWtQDOk0X3tz6fw2A9ZTf1xKWnXrzb4edARjVr5 X-Received: by 2002:a63:ac57:: with SMTP id z23-v6mr2389617pgn.74.1530039652113; Tue, 26 Jun 2018 12:00:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530039652; cv=none; d=google.com; s=arc-20160816; b=DNgzh63Rdy+ukdBH9ZPhXKH8ASqXcO+TPs5Y2A2PAWgcqGiHcl1NYND8XSu3raatqE iR7nFqMF7AMNfqke70SU/wPOeZvwT/GEnfEUNBJ8YPCvnP2w8d3g4xGC0Lu+4XkACkDw +uQS+3FKegkMXkNDK4PizVVJdVjkbpR4SRNQnEcibBitmCBxb7rgLE10G/Bdhymp0/c2 Lx4yrflM+H0KUBRGtTyyQia2Swg4oIpW5er7QYuMh5EdGUXHCNAtcuukmgTOhfZ91/cf ixDYCJ1B/K2ObwD/GLPldniFiGyQwykFs2b79D6cxZjXOUoObCJpA1cFdaDo51iiXADD 0fqg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :arc-authentication-results; bh=yIq5HZQc7AaskJ+syvebQF2cUe82gu1rZeIzFy3Pww8=; b=j6QFfdTJvbzXgJ74N6OELRfsPi82PnhqUIXe7EhXDwi4SUH5qVaamFUFtSa++gM8tL 1YhBpwOX24m30+S7U7HBidapgXjEzNKve2M4CQNl0J7zNtKscHZby6mKX7Tfj6hTKjt+ BCAZKVqFEUg27ROT2Gq/7LZVUQt65XckGhd/mmM3if+MA88ueIJKo4LlPGaB/JKk9Hvs M7C36i9p4D+qoyDFdehgs0wadZZbX9CrYkbWD21byBqh50PbaEW/5Toil/3jGC9fb7cl J4INKh6TxbaXsIaYWL6e3uu6P8PZUYj32W4iE2k0VdNQQ3wifFtASIYzbODMQs4l9E7T qByw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u134-v6si2057272pfc.244.2018.06.26.12.00.37; Tue, 26 Jun 2018 12:00:52 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754698AbeFZRvQ (ORCPT + 99 others); Tue, 26 Jun 2018 13:51:16 -0400 Received: from da1vs04.rockwellcollins.com ([205.175.227.52]:7965 "EHLO da1vs04.rockwellcollins.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752591AbeFZRvO (ORCPT ); Tue, 26 Jun 2018 13:51:14 -0400 Received: from ofwda1n02.rockwellcollins.com (HELO ciulimr02.rockwellcollins.com) ([205.175.227.14]) by da1vs04.rockwellcollins.com with ESMTP; 26 Jun 2018 12:51:13 -0500 X-Received: from righttwix.rockwellcollins.com (righttwix.rockwellcollins.com [192.168.141.218]) by ciulimr02.rockwellcollins.com (Postfix) with ESMTP id 4069C2007C; Tue, 26 Jun 2018 12:51:13 -0500 (CDT) From: Brandon Maier To: netdev@vger.kernel.org Cc: andrew@lunn.ch, f.fainelli@gmail.com, davem@davemloft.net, michal.simek@xilinx.com, clayton.shotwell@rockwellcollins.com, kristopher.cory@rockwellcollins.com, linux-kernel@vger.kernel.org, Brandon Maier Subject: [PATCH net-next v2 1/3] net: phy: xgmiitorgmii: Check phy_driver ready before accessing Date: Tue, 26 Jun 2018 12:50:48 -0500 Message-Id: <20180626175050.71165-1-brandon.maier@rockwellcollins.com> X-Mailer: git-send-email 2.17.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Since a phy_device is added to the global mdio_bus list during phy_device_register(), but a phy_device's phy_driver doesn't get attached until phy_probe(). It's possible of_phy_find_device() in xgmiitorgmii will return a valid phy with a NULL phy_driver. Leading to a NULL pointer access during the memcpy(). Fixes this Oops: Unable to handle kernel NULL pointer dereference at virtual address 00000000 pgd = c0004000 [00000000] *pgd=00000000 Internal error: Oops: 5 [#1] PREEMPT SMP ARM Modules linked in: CPU: 0 PID: 1 Comm: swapper/0 Not tainted 4.14.40 #1 Hardware name: Xilinx Zynq Platform task: ce4c8d00 task.stack: ce4ca000 PC is at memcpy+0x48/0x330 LR is at xgmiitorgmii_probe+0x90/0xe8 pc : [] lr : [] psr: 20000013 sp : ce4cbb54 ip : 00000000 fp : ce4cbb8c r10: 00000000 r9 : 00000000 r8 : c0c49178 r7 : 00000000 r6 : cdc14718 r5 : ce762800 r4 : cdc14710 r3 : 00000000 r2 : 00000054 r1 : 00000000 r0 : cdc14718 Flags: nzCv IRQs on FIQs on Mode SVC_32 ISA ARM Segment none Control: 18c5387d Table: 0000404a DAC: 00000051 Process swapper/0 (pid: 1, stack limit = 0xce4ca210) ... [] (memcpy) from [] (xgmiitorgmii_probe+0x90/0xe8) [] (xgmiitorgmii_probe) from [] (mdio_probe+0x28/0x34) [] (mdio_probe) from [] (driver_probe_device+0x254/0x414) [] (driver_probe_device) from [] (__device_attach_driver+0xac/0x10c) [] (__device_attach_driver) from [] (bus_for_each_drv+0x84/0xc8) [] (bus_for_each_drv) from [] (__device_attach+0xd0/0x134) [] (__device_attach) from [] (device_initial_probe+0x1c/0x20) [] (device_initial_probe) from [] (bus_probe_device+0x98/0xa0) [] (bus_probe_device) from [] (device_add+0x43c/0x5d0) [] (device_add) from [] (mdio_device_register+0x34/0x80) [] (mdio_device_register) from [] (of_mdiobus_register+0x170/0x30c) [] (of_mdiobus_register) from [] (macb_probe+0x710/0xc00) [] (macb_probe) from [] (platform_drv_probe+0x44/0x80) [] (platform_drv_probe) from [] (driver_probe_device+0x254/0x414) [] (driver_probe_device) from [] (__driver_attach+0x10c/0x118) [] (__driver_attach) from [] (bus_for_each_dev+0x8c/0xd0) [] (bus_for_each_dev) from [] (driver_attach+0x2c/0x30) [] (driver_attach) from [] (bus_add_driver+0x50/0x260) [] (bus_add_driver) from [] (driver_register+0x88/0x108) [] (driver_register) from [] (__platform_driver_register+0x50/0x58) [] (__platform_driver_register) from [] (macb_driver_init+0x24/0x28) [] (macb_driver_init) from [] (do_one_initcall+0x60/0x1a4) [] (do_one_initcall) from [] (kernel_init_freeable+0x15c/0x1f8) [] (kernel_init_freeable) from [] (kernel_init+0x18/0x124) [] (kernel_init) from [] (ret_from_fork+0x14/0x20) Code: ba000002 f5d1f03c f5d1f05c f5d1f07c (e8b151f8) ---[ end trace 3e4ec21905820a1f ]--- Signed-off-by: Brandon Maier --- v2: - Add Oops to commit message v1: https://marc.info/?l=linux-netdev&m=152838762210538&w=2 drivers/net/phy/xilinx_gmii2rgmii.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/net/phy/xilinx_gmii2rgmii.c b/drivers/net/phy/xilinx_gmii2rgmii.c index 2e5150b0b8d5..04c8bec1c4c1 100644 --- a/drivers/net/phy/xilinx_gmii2rgmii.c +++ b/drivers/net/phy/xilinx_gmii2rgmii.c @@ -81,6 +81,11 @@ static int xgmiitorgmii_probe(struct mdio_device *mdiodev) return -EPROBE_DEFER; } + if (!priv->phy_dev->drv) { + dev_info(dev, "Attached phy not ready\n"); + return -EPROBE_DEFER; + } + priv->addr = mdiodev->addr; priv->phy_drv = priv->phy_dev->drv; memcpy(&priv->conv_phy_drv, priv->phy_dev->drv, -- 2.17.1