Paulo,

First, your patch would not apply cleanly to 2.4.22 because all of the
tab characters in it had been replaced by spaces (IOW, general
whitespace manglement).

I rediffed it and made a corresponding patch (I hope) for 2.6.0-test5.
Does it look right to you?

In general, patches/updates should be made to 2.5/2.6 before being
pushed into 2.4.  Can you test this patch to 2.6.0-test5 and then
we can ask Greg to merge it into 2.6.x?

I made one change to your patch (as I see now that you mentioned).
I update writecount from transfer_buffer_length *before* calling
usb_submit_urb() instead of afterwards.  The HCD "owns" the urb
after usb_submit_urb() is called...
Or, as you also mention, a local <actualcount> could be used here.


Patches to 2.4.22 and 2.6.0-test5 are below.  (not as attachments
since that makes them harder for others to review)

~Randy



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

| 
| 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)



patch_name:     usblp24_noblock.patch
patch_version:  2003-09-16.11:14:03
author:         Paulo Marques <[EMAIL PROTECTED]>
description:    handle NONBLOCK writing on usblp;
product:        Linux
product_versions: 2.4.22
diffstat:       =
 drivers/usb/printer.c |   11 ++---------
 1 files changed, 2 insertions(+), 9 deletions(-)


diff -Naurp ./drivers/usb/printer.c~noblock ./drivers/usb/printer.c
--- ./drivers/usb/printer.c~noblock     2002-11-28 15:53:14.000000000 -0800
+++ ./drivers/usb/printer.c     2003-09-16 11:12:49.000000000 -0700
@@ -572,7 +572,7 @@ static ssize_t usblp_write(struct file *
                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 @@ static ssize_t usblp_write(struct file *
                        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;
 
@@ -624,6 +616,7 @@ static ssize_t usblp_write(struct file *
                        return writecount ? writecount : -EFAULT;
                }
 
+               writecount += usblp->writeurb.transfer_buffer_length;
                usblp->writeurb.dev = usblp->dev;
                usb_submit_urb(&usblp->writeurb);
                up (&usblp->sem);




patch_name:     usblp26_noblock.patch
patch_version:  2003-09-16.11:14:19
author:         Paulo Marques <[EMAIL PROTECTED]>
description:    handle NONBLOCK writing on usblp;
product:        Linux
product_versions: 2.6.0-test5
diffstat:       =
 drivers/usb/class/usblp.c |   11 ++---------
 1 files changed, 2 insertions(+), 9 deletions(-)


diff -Naurp ./drivers/usb/class/usblp.c~noblock ./drivers/usb/class/usblp.c
--- ./drivers/usb/class/usblp.c~noblock 2003-09-08 12:49:54.000000000 -0700
+++ ./drivers/usb/class/usblp.c 2003-09-16 11:09:50.000000000 -0700
@@ -607,7 +607,7 @@ static ssize_t usblp_write(struct file *
                if (!usblp->wcomplete) {
                        barrier();
                        if (file->f_flags & O_NONBLOCK)
-                               return -EAGAIN;
+                               return writecount ? writecount : -EAGAIN;
 
                        timeout = USBLP_WRITE_TIMEOUT;
                        add_wait_queue(&usblp->wait, &wait);
@@ -651,14 +651,6 @@ static ssize_t usblp_write(struct file *
                        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;
 
@@ -668,6 +660,7 @@ static ssize_t usblp_write(struct file *
                        return writecount ? writecount : -EFAULT;
                }
 
+               writecount += usblp->writeurb->transfer_buffer_length;
                usblp->writeurb->dev = usblp->dev;
                usblp->wcomplete = 0;
                if (usb_submit_urb(usblp->writeurb, GFP_KERNEL)) {


-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
_______________________________________________
[EMAIL PROTECTED]
To unsubscribe, use the last form field at:
https://lists.sourceforge.net/lists/listinfo/linux-usb-devel

Reply via email to