svn commit: r188484 - head/sys/dev/ppbus

John Baldwin jhb at FreeBSD.org
Wed Feb 11 06:25:10 PST 2009


Author: jhb
Date: Wed Feb 11 14:25:09 2009
New Revision: 188484
URL: http://svn.freebsd.org/changeset/base/188484

Log:
  Fix lptopen() and lptclose() to not trash the state of the HAVEBUS flag
  in 'sc_state'.  This allows the lpt_release_ppbus() calls in those two
  routines to actually release the ppbus and thus fixes the hangs noticed
  with the lpt(4) driver since the recent ppbus changes.  The old lpt(4)
  driver didn't actually check the HAVEBUS flag in lpt_release_ppbus() which
  is why these bugs weren't noticed before.

Modified:
  head/sys/dev/ppbus/lpt.c

Modified: head/sys/dev/ppbus/lpt.c
==============================================================================
--- head/sys/dev/ppbus/lpt.c	Wed Feb 11 13:44:27 2009	(r188483)
+++ head/sys/dev/ppbus/lpt.c	Wed Feb 11 14:25:09 2009	(r188484)
@@ -544,10 +544,10 @@ lptopen(struct cdev *dev, int flags, int
 	do {
 		/* ran out of waiting for the printer */
 		if (trys++ >= LPINITRDY*4) {
-			sc->sc_state = 0;
 			lprintf(("status %x\n", ppb_rstr(ppbus)));
 
 			lpt_release_ppbus(lptdev);
+			sc->sc_state = 0;
 			ppb_unlock(ppbus);
 			return (EBUSY);
 		}
@@ -555,9 +555,8 @@ lptopen(struct cdev *dev, int flags, int
 		/* wait 1/4 second, give up if we get a signal */
 		if (ppb_sleep(ppbus, lptdev, LPPRI | PCATCH, "lptinit",
 		    hz / 4) != EWOULDBLOCK) {
-			sc->sc_state = 0;
-
 			lpt_release_ppbus(lptdev);
+			sc->sc_state = 0;
 			ppb_unlock(ppbus);
 			return (EBUSY);
 		}
@@ -577,7 +576,8 @@ lptopen(struct cdev *dev, int flags, int
 
 	ppb_wctr(ppbus, sc->sc_control);
 
-	sc->sc_state = OPEN;
+	sc->sc_state &= ~LPTINIT;
+	sc->sc_state |= OPEN;
 	sc->sc_xfercnt = 0;
 
 	/* only use timeout if using interrupt */
@@ -611,11 +611,8 @@ lptclose(struct cdev *dev, int flags, in
 	int err;
 
 	ppb_lock(ppbus);
-	if (sc->sc_flags & LP_BYPASS) {
-		sc->sc_state = 0;
-		ppb_unlock(ppbus);
+	if (sc->sc_flags & LP_BYPASS)
 		goto end_close;
-	}
 
 	if ((err = lpt_request_ppbus(lptdev, PPB_WAIT|PPB_INTR)) != 0) {
 		ppb_unlock(ppbus);
@@ -635,16 +632,16 @@ lptclose(struct cdev *dev, int flags, in
 	sc->sc_state &= ~OPEN;
 	callout_stop(&sc->sc_timer);
 	ppb_wctr(ppbus, LPC_NINIT);
-	sc->sc_state = 0;
-	sc->sc_xfercnt = 0;
 
 	/*
 	 * unregistration of interrupt forced by release
 	 */
 	lpt_release_ppbus(lptdev);
-	ppb_unlock(ppbus);
 
 end_close:
+	sc->sc_state = 0;
+	sc->sc_xfercnt = 0;
+	ppb_unlock(ppbus);
 	lprintf(("closed.\n"));
 	return(0);
 }


More information about the svn-src-head mailing list