summaryrefslogtreecommitdiffstats
path: root/sys/dev/mii
diff options
context:
space:
mode:
authorimp <imp@FreeBSD.org>2008-08-23 15:50:18 +0000
committerimp <imp@FreeBSD.org>2008-08-23 15:50:18 +0000
commit9120f9e68b4c05d81448de40ec29aa81a7f05149 (patch)
tree2e4f57dbf19c688f9e029df12f4f4faea17d48dd /sys/dev/mii
parentccd3e368a5fcf2b83317b5301bba9c18c8c8f7e9 (diff)
downloadFreeBSD-src-9120f9e68b4c05d81448de40ec29aa81a7f05149.zip
FreeBSD-src-9120f9e68b4c05d81448de40ec29aa81a7f05149.tar.gz
Move the code that looks for the companion phy to a subroutine to make
sure we get the error handling right in both places. This also simplifies the code somewhat.
Diffstat (limited to 'sys/dev/mii')
-rw-r--r--sys/dev/mii/mlphy.c45
1 files changed, 22 insertions, 23 deletions
diff --git a/sys/dev/mii/mlphy.c b/sys/dev/mii/mlphy.c
index d44d36f..a99d242 100644
--- a/sys/dev/mii/mlphy.c
+++ b/sys/dev/mii/mlphy.c
@@ -177,6 +177,25 @@ mlphy_attach(dev)
return (0);
}
+static struct mii_softc *
+mlphy_find_other(device_t mii)
+{
+ device_t *devlist;
+ struct mii_softc *retval;
+ int i, devs;
+
+ retval = NULL;
+ if (device_get_children(mii, &devlist, &devs))
+ return (NULL);
+ for (i = 0; i < devs; i++)
+ if (strcmp(device_get_name(devlist[i]), "mlphy")) {
+ retval = device_get_softc(devlist[i]);
+ break;
+ }
+ free(devlist, M_TEMP);
+ return (retval);
+}
+
static int
mlphy_service(xsc, mii, cmd)
struct mii_softc *xsc;
@@ -187,22 +206,13 @@ mlphy_service(xsc, mii, cmd)
struct mii_softc *other = NULL;
struct mlphy_softc *msc = (struct mlphy_softc *)xsc;
struct mii_softc *sc = (struct mii_softc *)&msc->ml_mii;
- device_t *devlist;
- int devs, i, other_inst, reg;
+ int other_inst, reg;
/*
* See if there's another PHY on this bus with us.
* If so, we may need it for 10Mbps modes.
*/
- if (device_get_children(msc->ml_mii.mii_dev, &devlist, &devs) == 0) {
- for (i = 0; i < devs; i++) {
- if (strcmp(device_get_name(devlist[i]), "mlphy")) {
- other = device_get_softc(devlist[i]);
- break;
- }
- }
- free(devlist, M_TEMP);
- }
+ other = mlphy_find_other(msc->ml_mii.mii_dev);
switch (cmd) {
case MII_POLLSTAT:
@@ -397,20 +407,9 @@ mlphy_status(sc)
struct mlphy_softc *msc = (struct mlphy_softc *)sc;
struct mii_data *mii = msc->ml_mii.mii_pdata;
struct mii_softc *other = NULL;
- device_t *devlist;
- int devs, i;
/* See if there's another PHY on the bus with us. */
- devs = 0;
- device_get_children(msc->ml_mii.mii_dev, &devlist, &devs);
- for (i = 0; i < devs; i++) {
- if (strcmp(device_get_name(devlist[i]), "mlphy")) {
- other = device_get_softc(devlist[i]);
- break;
- }
- }
- free(devlist, M_TEMP);
-
+ other = mlphy_find_other(msc->ml_mii.mii_dev);
if (other == NULL)
return;
OpenPOWER on IntegriCloud