Oliver Neukum wrote:
>
> Am Sonntag, 10. November 2002 06:45 schrieb Randy.Dunlap:
> > David Brownell wrote:
> >
> >
> > ...
> >
> > > Your stack trace showed usblp_check_status() was what started this
> > > sequence of troubles, so I looked at it. There were some issues,
> > > it's got a lot of pretty early usb code:
> > >
> > > - it assumes it's OK to DMA onto the stack. kmalloc would likely
> > > be the best fix.
> >
> > Patch for this is attached. Please apply.
>
> If you do this, you should allocate the buffers seperately, because
> only then are you sure that there are no DMA issues.
Here's the patch that allocates <statusbuf> separately.
Please apply to 2.5.46.
~Randy
--- ./drivers/usb/class/usblp.c%hang Mon Nov 4 14:30:11 2002
+++ ./drivers/usb/class/usblp.c Sun Nov 10 15:49:56 2002
@@ -1,9 +1,9 @@
/*
- * usblp.c Version 0.12
+ * usblp.c Version 0.13
*
* Copyright (c) 1999 Michael Gee <[EMAIL PROTECTED]>
* Copyright (c) 1999 Pavel Machek <[EMAIL PROTECTED]>
- * Copyright (c) 2000 Randy Dunlap <[EMAIL PROTECTED]>
+ * Copyright (c) 2000 Randy Dunlap <[EMAIL PROTECTED]>
* Copyright (c) 2000 Vojtech Pavlik <[EMAIL PROTECTED]>
# Copyright (c) 2001 Pete Zaitcev <[EMAIL PROTECTED]>
# Copyright (c) 2001 David Paschal <[EMAIL PROTECTED]>
@@ -25,6 +25,7 @@
* v0.10- remove sleep_on, fix error on oom ([EMAIL PROTECTED])
* v0.11 - add proto_bias option (Pete Zaitcev)
* v0.12 - add hpoj.sourceforge.net ioctls (David Paschal)
+ * v0.13 - kmalloc() space for statusbuf (<status> not on stack);
*/
/*
@@ -59,7 +60,7 @@
/*
* Version Information
*/
-#define DRIVER_VERSION "v0.12"
+#define DRIVER_VERSION "v0.13"
#define DRIVER_AUTHOR "Michael Gee, Pavel Machek, Vojtech Pavlik, Randy Dunlap, Pete
Zaitcev, David Paschal"
#define DRIVER_DESC "USB Printer Device Class driver"
@@ -120,11 +121,18 @@
#define USBLP_LAST_PROTOCOL 3
#define USBLP_MAX_PROTOCOLS (USBLP_LAST_PROTOCOL+1)
+/*
+ * some arbitrary status buffer size;
+ * need a status buffer that is allocated via kmalloc(), not on stack
+ */
+#define STATUS_BUF_SIZE 8
+
struct usblp {
struct usb_device *dev; /* USB device */
devfs_handle_t devfs; /* devfs device */
struct semaphore sem; /* locks this struct,
especially "dev" */
char *buf; /* writeurb->transfer_buffer */
+ char *statusbuf; /* NOT on stack */
struct urb *readurb, *writeurb; /* The urbs */
wait_queue_head_t wait; /* Zzzzz ... */
int readcount; /* Counter for reads */
@@ -289,13 +297,14 @@
unsigned char status, newerr = 0;
int error;
- error = usblp_read_status (usblp, &status);
+ error = usblp_read_status (usblp, usblp->statusbuf);
if (error < 0) {
err("usblp%d: error %d reading printer status",
usblp->minor, error);
return 0;
}
+ status = *usblp->statusbuf;
if (~status & LP_PERRORP) {
newerr = 3;
if (status & LP_POUTPA) newerr = 1;
@@ -377,6 +386,7 @@
kfree (usblp->writeurb->transfer_buffer);
kfree (usblp->device_id_string);
+ kfree (usblp->statusbuf);
usb_free_urb(usblp->writeurb);
usb_free_urb(usblp->readurb);
kfree (usblp);
@@ -849,6 +859,13 @@
goto abort_minor;
}
+ /* Allocate buffer for printer status */
+ usblp->statusbuf = kmalloc(STATUS_BUF_SIZE, GFP_KERNEL);
+ if (!usblp->statusbuf) {
+ err("out of memory for statusbuf");
+ goto abort_minor;
+ }
+
/* Lookup quirks for this printer. */
usblp->quirks = usblp_quirks(
dev->descriptor.idVendor,
@@ -903,6 +920,7 @@
usb_free_urb(usblp->writeurb);
usb_free_urb(usblp->readurb);
if (usblp->buf) kfree(usblp->buf);
+ if (usblp->statusbuf) kfree(usblp->statusbuf);
if (usblp->device_id_string) kfree(usblp->device_id_string);
kfree(usblp);
}