Avoid crashing if we are forced to close() before teh open() completed
(can happen on disconnect, probably due do dubious logic in vdevgone()).
This commit is contained in:
parent
12a0758a42
commit
021319d9b3
|
@ -1,4 +1,4 @@
|
||||||
/* $NetBSD: ulpt.c,v 1.12 1999/06/30 06:44:23 augustss Exp $ */
|
/* $NetBSD: ulpt.c,v 1.13 1999/07/14 19:12:07 augustss Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 1998 The NetBSD Foundation, Inc.
|
* Copyright (c) 1998 The NetBSD Foundation, Inc.
|
||||||
|
@ -313,10 +313,10 @@ ulptopen(dev, flag, mode, p)
|
||||||
USB_GET_SC_OPEN(ulpt, ULPTUNIT(dev), sc);
|
USB_GET_SC_OPEN(ulpt, ULPTUNIT(dev), sc);
|
||||||
|
|
||||||
if (!sc || !sc->sc_iface || sc->sc_dying)
|
if (!sc || !sc->sc_iface || sc->sc_dying)
|
||||||
return ENXIO;
|
return (ENXIO);
|
||||||
|
|
||||||
if (sc->sc_state)
|
if (sc->sc_state)
|
||||||
return EBUSY;
|
return (EBUSY);
|
||||||
|
|
||||||
sc->sc_state = ULPT_INIT;
|
sc->sc_state = ULPT_INIT;
|
||||||
sc->sc_flags = flags;
|
sc->sc_flags = flags;
|
||||||
|
@ -328,14 +328,14 @@ ulptopen(dev, flag, mode, p)
|
||||||
for (spin = 0; (ulpt_status(sc) & LPS_SELECT) == 0; spin += STEP) {
|
for (spin = 0; (ulpt_status(sc) & LPS_SELECT) == 0; spin += STEP) {
|
||||||
if (spin >= TIMEOUT) {
|
if (spin >= TIMEOUT) {
|
||||||
sc->sc_state = 0;
|
sc->sc_state = 0;
|
||||||
return EBUSY;
|
return (EBUSY);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* wait 1/4 second, give up if we get a signal */
|
/* wait 1/4 second, give up if we get a signal */
|
||||||
error = tsleep((caddr_t)sc, LPTPRI | PCATCH, "ulptop", STEP);
|
error = tsleep((caddr_t)sc, LPTPRI | PCATCH, "ulptop", STEP);
|
||||||
if (error != EWOULDBLOCK) {
|
if (error != EWOULDBLOCK) {
|
||||||
sc->sc_state = 0;
|
sc->sc_state = 0;
|
||||||
return error;
|
return (error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -369,7 +369,7 @@ ulpt_statusmsg(status, sc)
|
||||||
else if (new & LPS_NERR)
|
else if (new & LPS_NERR)
|
||||||
log(LOG_NOTICE, "%s: output error\n", USBDEVNAME(sc->sc_dev));
|
log(LOG_NOTICE, "%s: output error\n", USBDEVNAME(sc->sc_dev));
|
||||||
|
|
||||||
return status;
|
return (status);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
@ -381,6 +381,10 @@ ulptclose(dev, flag, mode, p)
|
||||||
{
|
{
|
||||||
USB_GET_SC(ulpt, ULPTUNIT(dev), sc);
|
USB_GET_SC(ulpt, ULPTUNIT(dev), sc);
|
||||||
|
|
||||||
|
if (sc->sc_state != ULPT_OPEN)
|
||||||
|
/* We are being forced to close before the open completed. */
|
||||||
|
return (0);
|
||||||
|
|
||||||
usbd_close_pipe(sc->sc_bulkpipe);
|
usbd_close_pipe(sc->sc_bulkpipe);
|
||||||
sc->sc_bulkpipe = 0;
|
sc->sc_bulkpipe = 0;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue