Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 14 Dec 2013 18:50:00 +0000 (UTC)
From:      Gavin Atkinson <gavin@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r259393 - head/sys/dev/an
Message-ID:  <201312141850.rBEIo06F003098@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: gavin
Date: Sat Dec 14 18:49:59 2013
New Revision: 259393
URL: http://svnweb.freebsd.org/changeset/base/259393

Log:
  Fix several panics when initialization of an ISA or PC-CARD device fails:
  
  o  Assign sc->an_dev in an_probe() (which isn't really a probe function in
     the standard newbus sense) as we may need it for printing errors.
  o  Use device_printf() rather than if_printf() in an_reset() - this is
     called from an_probe() long before the ifp structure is initialised
     in an_attach().
  o  Initialize the ifp structure early in an_attach() as we use if_printf()
     in cases where allocation of descriptors etc fails.
  
  MFC after:	3 days

Modified:
  head/sys/dev/an/if_an.c
  head/sys/dev/an/if_an_pccard.c

Modified: head/sys/dev/an/if_an.c
==============================================================================
--- head/sys/dev/an/if_an.c	Sat Dec 14 17:46:58 2013	(r259392)
+++ head/sys/dev/an/if_an.c	Sat Dec 14 18:49:59 2013	(r259393)
@@ -358,6 +358,7 @@ an_probe(device_t dev)
 	CSR_WRITE_2(sc, AN_INT_EN(sc->mpi350), 0);
 	CSR_WRITE_2(sc, AN_EVENT_ACK(sc->mpi350), 0xFFFF);
 
+	sc->an_dev = dev;
 	mtx_init(&sc->an_mtx, device_get_nameunit(dev), MTX_NETWORK_LOCK,
 	    MTX_DEF);
 	AN_LOCK(sc);
@@ -686,6 +687,9 @@ an_attach(struct an_softc *sc, int flags
 		device_printf(sc->an_dev, "can not if_alloc()\n");
 		goto fail;
 	}
+	ifp->if_softc = sc;
+	if_initname(ifp, device_get_name(sc->an_dev),
+	    device_get_unit(sc->an_dev));
 
 	sc->an_gone = 0;
 	sc->an_associated = 0;
@@ -759,9 +763,6 @@ an_attach(struct an_softc *sc, int flags
 #endif
 	AN_UNLOCK(sc);
 
-	ifp->if_softc = sc;
-	if_initname(ifp, device_get_name(sc->an_dev),
-	    device_get_unit(sc->an_dev));
 	ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
 	ifp->if_ioctl = an_ioctl;
 	ifp->if_start = an_start;
@@ -1388,7 +1389,7 @@ an_reset(struct an_softc *sc)
 	an_cmd(sc, AN_CMD_NOOP2, 0);
 
 	if (an_cmd(sc, AN_CMD_FORCE_SYNCLOSS, 0) == ETIMEDOUT)
-		if_printf(sc->an_ifp, "reset failed\n");
+		device_printf(sc->an_dev, "reset failed\n");
 
 	an_cmd(sc, AN_CMD_DISABLE, 0);
 

Modified: head/sys/dev/an/if_an_pccard.c
==============================================================================
--- head/sys/dev/an/if_an_pccard.c	Sat Dec 14 17:46:58 2013	(r259392)
+++ head/sys/dev/an/if_an_pccard.c	Sat Dec 14 18:49:59 2013	(r259393)
@@ -141,8 +141,6 @@ an_pccard_attach(device_t dev)
 
 	an_alloc_irq(dev, sc->irq_rid, 0);
 
-	sc->an_dev = dev;
-
 	error = an_attach(sc, flags);
 	if (error)
 		goto fail;



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201312141850.rBEIo06F003098>