Re: [linux-usb-devel] Re: [BUG] usblp_write spins forever after an error
From: Paulo Marques
Date: Mon Feb 16 2004 - 10:17:28 EST
Greg KH wrote:
On Sun, Feb 15, 2004 at 01:55:32PM -0800, Andy Lutomirski wrote:
I recently cancelled a print job with the printer's cancel function, and
the CUPS backend got stuck in usblp_write (using 100% CPU and not
responding to signals).
I wrote a patch some time ago to correct a bug exactly at usblp_write. It is
still not in the main kernel, but you can give it a try and see if it helps. It
applies cleanly against 2.6.2-rc2, but I guess it should apply to 2.6.2-rc3.
This patch corrected a problem for me, that happened when a printer presents an
out-of-paper status while printing a document. The driver would send endless
garbage to the printer.
I hope this helps,
--
Paulo Marques - www.grupopie.com
"In a world without walls and fences who needs windows and gates?"
--- drivers/usb/class/usblp.c.orig 2004-02-09 14:46:27.000000000 +0000
+++ drivers/usb/class/usblp.c 2004-02-09 15:03:32.281551096 +0000
@@ -603,7 +603,7 @@ static ssize_t usblp_write(struct file *
{
DECLARE_WAITQUEUE(wait, current);
struct usblp *usblp = file->private_data;
- int timeout, err = 0;
+ int timeout, err = 0, transfer_length;
size_t writecount = 0;
while (writecount < count) {
@@ -654,19 +654,13 @@ static ssize_t usblp_write(struct file *
continue;
}
- writecount += usblp->writeurb->transfer_buffer_length;
- usblp->writeurb->transfer_buffer_length = 0;
+ transfer_length=(count - writecount);
+ if (transfer_length > USBLP_BUF_SIZE)
+ transfer_length = USBLP_BUF_SIZE;
- if (writecount == count) {
- up (&usblp->sem);
- break;
- }
+ usblp->writeurb->transfer_buffer_length = transfer_length;
- usblp->writeurb->transfer_buffer_length = (count - writecount) < USBLP_BUF_SIZE ?
- (count - writecount) : USBLP_BUF_SIZE;
-
- if (copy_from_user(usblp->writeurb->transfer_buffer, buffer + writecount,
- usblp->writeurb->transfer_buffer_length)) {
+ if (copy_from_user(usblp->writeurb->transfer_buffer, buffer + writecount, transfer_length)) {
up(&usblp->sem);
return writecount ? writecount : -EFAULT;
}
@@ -683,6 +677,8 @@ static ssize_t usblp_write(struct file *
break;
}
up (&usblp->sem);
+
+ writecount += transfer_length;
}
return count;