Randy.Dunlap wrote:


On Mon, 15 Sep 2003 16:09:08 +0100 Paulo Marques <[EMAIL PROTECTED]> wrote:

| | Hi all,
| | I sent an email to the current "USB PRINTER DRIVER" maintainer in 04 Aug and 11 | Sep, to warn about a bug found in the printer.c driver in kernel version 2.4.22. | I even corrected the bug and sent a patch.
| | As listed in MAINTAINERS, the current maintainer is Vojtech Pavlik | ([EMAIL PROTECTED]). However i got no reply from both e-mails, and the current 2.4 | kernel version still has the same bug.
| | Is this e-mail wrong? Who should i send patches to?


That's Vojtech's email address AFAIK.
Please copy this mailing list on such problems/patches.


Ok, here goes the patch, then. :)


The test case that produced the bug was like this:

- open the device
- call fcntl to make the file non-blocking
- with the printer out of paper, write to the file
- put paper in the printer
- now the printer prints endless characters from the process user-space data area, until the process closes the device.


This test was made using a usb<->paralel adapter connected to a receipt printer.

The problem is in the "usblp_write" function.

The patch makes 2 corrections:

First the return value when (usblp->writeurb.status == -EINPROGRESS) and the file is non-blocking should account for the bytes already sent.

Second, the "writecount += usblp->writeurb.transfer_buffer_length;" was adding a length that was not being initialized inside this function which could lead to unexpected bugs.

Anyway, i tested the code in the same situation that systematically produced the bug, and it was gone :)

Please check that there is no logical (read idiotical :) flaw in my reasoning, before using the patch. I'm not that knowledgeable about the USB core, so i'm might be doing something bad by using the "writeurb.transfer_buffer_length" after submitting the urb, or something. (if this is the case, a local variable that stored the length could solve this)

--
Paulo Marques
Software Development Department - Restinfor, Lda.
Phone: +351 252 290600, Fax: +351 252 290601
Web: www.grupopie.com

"In a world without walls and fences who needs windows and gates?"
--- drivers/usb/printer.ori     Mon Aug  4 19:26:22 2003
+++ drivers/usb/printer.c    Mon Aug  4 19:29:08 2003
@@ -572,7 +572,7 @@
         if (usblp->writeurb.status == -EINPROGRESS) {

          if (file->f_flags & O_NONBLOCK)
-             return -EAGAIN;
+             return writecount ? writecount : -EAGAIN;

          timeout = USBLP_WRITE_TIMEOUT;
          while (timeout && usblp->writeurb.status == -EINPROGRESS) {
@@ -607,14 +607,6 @@
          continue;
         }

-     writecount += usblp->writeurb.transfer_buffer_length;
-     usblp->writeurb.transfer_buffer_length = 0;
-
-     if (writecount == count) {
-         up (&usblp->sem);
-         break;
-     }
-
         usblp->writeurb.transfer_buffer_length = (count - writecount) < 
USBLP_BUF_SIZE ?
                           (count - writecount) : USBLP_BUF_SIZE;

@@ -627,6 +619,8 @@
         usblp->writeurb.dev = usblp->dev;
         usb_submit_urb(&usblp->writeurb);
         up (&usblp->sem);
+
+     writecount += usblp->writeurb.transfer_buffer_length;
     }

     return count; 

Reply via email to