From: Heiko Schocher Date: Thu, 5 Sep 2013 11:50:41 +0200 Subject: [U-Boot] =?utf-8?q?=5BPATCH_v3=5D_net=2C_phy=2C_cpsw=3A_fix_NULL_?= =?utf-8?q?pointer_deference?= In-Reply-To: <1378361122-6019-1-git-send-email-hs@denx.de> References: <1378361122-6019-1-git-send-email-hs@denx.de> Message-ID: <1378374641-17281-1-git-send-email-hs@denx.de> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de if phy_connect() did not find a phy, phydev is NULL and following code in cpsw_phy_init() crashes. Fix this. Signed-off-by: Heiko Schocher Cc: Joe Hershberger Cc: Mugunthan V N Cc: Tom Rini --- - changes for v2: - change commit message as it is a NULL pointer deference error not a unaligned access problem, as Tom Rini mentioned - fix more places in the driver with NULL pointer problem - changes for v3: - add comment from Mugunthan V N: - priv NULL pointer checks not needed Found on the dxr2 board with no phy connected to the board, U-Boot crashes with: U-Boot 2013.07-12701-gea98378-dirty (Sep 04 2013 - 06:58:16) I2C: ready DRAM: 128 MiB Enable d-cache FactorySet is not right in eeprom. NAND: 256 MiB MMC: OMAP SD/MMC: 0, OMAP SD/MMC: 1 8-bit BCH HW ECC selected Net: Could not get PHY for cpsw: addr 0 data abort MAYBE you should read doc/README.arm-unaligned-accesses pc : [<87f80574>] lr : [<87f80fcc>] sp : 86f5aee0 ip : 00000034 fp : 80100020 r10: 00000014 r9 : 07e5d000 r8 : 86f5af30 r7 : 86f5f750 r6 : 86f5f804 r5 : 86f5f708 r4 : 86f5f750 r3 : 00000000 r2 : 00000000 r1 : 87fa4d08 r0 : 00000000 Flags: nZCv IRQs off FIQs on Mode SVC_32 Resetting CPU ... --- drivers/net/cpsw.c | 10 +++++++++- 1 Datei ge?ndert, 9 Zeilen hinzugef?gt(+), 1 Zeile entfernt(-) diff --git a/drivers/net/cpsw.c b/drivers/net/cpsw.c index 9bab71a..39240d9 100644 --- a/drivers/net/cpsw.c +++ b/drivers/net/cpsw.c @@ -568,9 +568,14 @@ static void cpsw_set_slave_mac(struct cpsw_slave *slave, static void cpsw_slave_update_link(struct cpsw_slave *slave, struct cpsw_priv *priv, int *link) { - struct phy_device *phy = priv->phydev; + struct phy_device *phy; u32 mac_control = 0; + phy = priv->phydev; + + if (!phy) + return; + phy_startup(phy); *link = phy->link; @@ -947,6 +952,9 @@ static int cpsw_phy_init(struct eth_device *dev, struct cpsw_slave *slave) dev, slave->data->phy_if); + if (!phydev) + return -1; + phydev->supported &= supported; phydev->advertising = phydev->supported; -- 1.7.11.7