Browse Source

MIIPHYBB: Return 0xFFFF if the PHY is not asserting TA.

This patch sets the returned value to 0xFFFF if the PHY does not exist
and does not assert Transfer Acknowledge. A NULL check for the value
pointer is also added for buffer overflow protection.

Without this patch 'mii info' will  show 'phantom' devices because the
value will be not be initialized and return with some random value.

Signed-off-by: Richard Retanubun <RichardRetanubun@RuggedCom.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>
Richard Retanubun 16 years ago
parent
commit
3f6b18ffd9
1 changed files with 7 additions and 0 deletions
  1. 7 0
      drivers/net/phy/miiphybb.c

+ 7 - 0
drivers/net/phy/miiphybb.c

@@ -127,6 +127,11 @@ int bb_miiphy_read (char *devname, unsigned char addr,
 	volatile ioport_t *iop = ioport_addr ((immap_t *) CONFIG_SYS_IMMR, MDIO_PORT);
 	volatile ioport_t *iop = ioport_addr ((immap_t *) CONFIG_SYS_IMMR, MDIO_PORT);
 #endif
 #endif
 
 
+	if (value == NULL) {
+		puts("NULL value pointer\n");
+		return (-1);
+	}
+
 	miiphy_pre (1, addr, reg);
 	miiphy_pre (1, addr, reg);
 
 
 	/* tri-state our MDIO I/O pin so we can read */
 	/* tri-state our MDIO I/O pin so we can read */
@@ -145,6 +150,8 @@ int bb_miiphy_read (char *devname, unsigned char addr,
 			MDC (1);
 			MDC (1);
 			MIIDELAY;
 			MIIDELAY;
 		}
 		}
+		/* There is no PHY, set value to 0xFFFF and return */
+		*value = 0xFFFF;
 		return (-1);
 		return (-1);
 	}
 	}