Skip to contentSkip to conversation

net, phy: fix NULL pointer deference

PATCH New Heiko Schocher 1 participant 1 message Sep 5, 2013

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 2/3 net, phy: fix NULL pointer deference

if phydev is a NULL pointer, code crash, so add check if phydev != NULL

Cc Andy Fleming <[email protected]>
Cc Kumar Gala <[email protected]>
Cc Joe Hershberger <[email protected]>
Cc Tom Rini <[email protected]>

---
Found on the dxr2 board with no phy connected to the board, U-Boot crashes with:

U-Boot# tftp 0x80200000 /tftpboot/dxr2/u-boot.bin data abort

MAYBE you should read doc/README.arm-unaligned-accesses

pc : [<87f80ffc>]          lr : [<87f7fbdc>]

sp : 86f5ace0 ip : ffffff00 fp : 87f9a2c2
r10: 00000000 r9 : 87f9a2c7 r8 : 86f5af30
r7 : 00000000 r6 : 86f5f750 r5 : 86f5f7f0 r4 : 86f5f750
r3 : 86f5f804 r2 : 86f5f7f0 r1 : 00000014 r0 : 00000000
Flags: Nzcv IRQs off FIQs on Mode SVC_32 Resetting CPU ...

resetting ...

---
 drivers/net/phy/phy.c | 30 ++++++++++++++++++++++++++++++

1 Datei ge?ndert, 30 Zeilen hinzugef?gt(+)

drivers/net/phy/phy.c +30 -0
index 62925bb..4885100 100644
@@ -36,6 +36,9 @@ static int genphy_config_advert(struct phy_device *phydev)
 	int oldadv, adv;
 	int err, changed = 0;
 
+	if (!phydev)
+		return -1;
+
 	/* Only allow advertising what
 	 * this PHY supports */
 	phydev->advertising &= phydev->supported;
@@ -114,6 +117,9 @@ static int genphy_setup_forced(struct phy_device *phydev)
 	int err;
 	int ctl = 0;
 
+	if (!phydev)
+		return -1;
+
 	phydev->pause = phydev->asym_pause = 0;
 
 	if (SPEED_1000 == phydev->speed)
@@ -166,6 +172,9 @@ int genphy_config_aneg(struct phy_device *phydev)
 {
 	int result;
 
+	if (!phydev)
+		return -1;
+
 	if (AUTONEG_ENABLE != phydev->autoneg)
 		return genphy_setup_forced(phydev);
 
@@ -206,6 +215,9 @@ int genphy_update_link(struct phy_device *phydev)
 {
 	unsigned int mii_reg;
 
+	if (!phydev)
+		return -1;
+
 	/*
 	 * Wait if the link is up, and autonegotiation is in progress
 	 * (ie - we're capable and it's not done)
@@ -274,6 +286,9 @@ int genphy_parse_link(struct phy_device *phydev)
 {
 	int mii_reg = phy_read(phydev, MDIO_DEVAD_NONE, MII_BMSR);
 
+	if (!phydev)
+		return -1;
+
 	/* We're using autonegotiation */
 	if (mii_reg & BMSR_ANEGCAPABLE) {
 		u32 lpa = 0;
@@ -365,6 +380,9 @@ int genphy_config(struct phy_device *phydev)
 	int val;
 	u32 features;
 
+	if (!phydev)
+		return -1;
+
 	/* For now, I'll claim that the generic driver supports
 	 * all possible port types */
 	features = (SUPPORTED_TP | SUPPORTED_MII
@@ -495,6 +513,9 @@ static int phy_probe(struct phy_device *phydev)
 {
 	int err = 0;
 
+	if (!phydev)
+		return -1;
+
 	phydev->advertising = phydev->supported = phydev->drv->features;
 	phydev->mmds = phydev->drv->mmds;
 
@@ -782,6 +803,9 @@ struct phy_device *phy_connect(struct mii_dev *bus, int addr,
  */
 int phy_startup(struct phy_device *phydev)
 {
+	if (!phydev)
+		return -1;
+
 	if (phydev->drv->startup)
 		return phydev->drv->startup(phydev);
 
@@ -790,6 +814,9 @@ int phy_startup(struct phy_device *phydev)
 
 static int __board_phy_config(struct phy_device *phydev)
 {
+	if (!phydev)
+		return -1;
+
 	if (phydev->drv->config)
 		return phydev->drv->config(phydev);
 	return 0;
@@ -808,6 +835,9 @@ int phy_config(struct phy_device *phydev)
 
 int phy_shutdown(struct phy_device *phydev)
 {
+	if (!phydev)
+		return -1;
+
 	if (phydev->drv->shutdown)
 		phydev->drv->shutdown(phydev);
 
Signature · 1 line
1.7.11.7