Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 27 May 2005 11:44:26 +0200
From:      Jan-Espen Pettersen <sigsegv@radiotube.org>
To:        iedowse@freebsd.org
Cc:        freebsd-usb@freebsd.org
Subject:   ulpt_tick after close
Message-ID:  <4296EBFA.1070902@radiotube.org>

next in thread | raw e-mail | index | archive | help
This is an OpenPGP/MIME signed message (RFC 2440 and 3156)
--------------enigACD021B26671C91D09F39611
Content-Type: multipart/mixed; boundary="------------080206050905070602070505"

This is a multi-part message in MIME format.
--------------080206050905070602070505
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit

I've for a few weeks suspected that there was more problems with the USB
printer implementation than those that have been resolved through
usb/78208 (http://www.freebsd.org/cgi/query-pr.cgi?pr=78208). I found
that ulpt_read_cb reschedules the ulpt_tick callout, but fails to check
if sc->sc_has_callout is set. ulpt_close destroys the read xfer and
unsets sc->sc_has_callout. Running ulpt_tick with the read xfer
destroyed causes a page fault. Therefore I suggest checking
sc->sc_has_callout in ulpt_read_cb before rescheduling the ulpt_tick
callout.

I have attached the diff I used to test this case. This patch is not
ment as a fix, but rather to prove that this problem exists.

Running with this patch I recently got this from the kernel (dmesg):
ULPT: Warning - Avoided ulpt_tick after ulptclose (ulpt_read_cb)

This means that ulpt_read_cb was called with sc->sc_has_callout == 0. I
suspect that this happened after ulpt_close had finished.

Jan-Espen Pettersen


--------------080206050905070602070505
Content-Type: text/x-patch;
 name="ulpt.c.pft.diff"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="ulpt.c.pft.diff"

Index: sys/dev/usb/ulpt.c
===================================================================
RCS file: /usr/ncvs/src/sys/dev/usb/ulpt.c,v
retrieving revision 1.65.2.1
diff -u -r1.65.2.1 ulpt.c
--- sys/dev/usb/ulpt.c	30 Jan 2005 01:00:10 -0000	1.65.2.1
+++ sys/dev/usb/ulpt.c	25 Apr 2005 05:47:52 -0000
@@ -816,9 +816,13 @@
 	if (!err && n > 0)
 		DPRINTF(("ulpt_tick: discarding %d bytes\n", n));
 #endif
-	if (!err || err == USBD_TIMEOUT)
-		usb_callout(sc->sc_read_callout, hz / ULPT_READS_PER_SEC,
-			    ulpt_tick, sc);
+	if (!err || err == USBD_TIMEOUT) {
+		if (sc->sc_has_callout)
+			usb_callout(sc->sc_read_callout, hz / ULPT_READS_PER_SEC,
+				    ulpt_tick, sc);
+		else
+			printf("ULPT: Warning - Avoided ulpt_tick after ulptclose (ulpt_read_cb)\n");
+	}
 }
 
 void

--------------080206050905070602070505--

--------------enigACD021B26671C91D09F39611
Content-Type: application/pgp-signature; name="signature.asc"
Content-Description: OpenPGP digital signature
Content-Disposition: attachment; filename="signature.asc"

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFCluwEH90qNYni6VoRAvkuAJ4z73L6QcjdqTPMJ2Qr3D3XQD8ssgCgwVHN
Qt4rdkOiIMkhrbNr7ljVJ50=
=ypp5
-----END PGP SIGNATURE-----

--------------enigACD021B26671C91D09F39611--



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