Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 11 Feb 2009 14:25:09 +0000 (UTC)
From:      John Baldwin <jhb@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r188484 - head/sys/dev/ppbus
Message-ID:  <200902111425.n1BEP9Ov027831@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
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);
 }



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