Commit 53e66bd3 authored by Greg Kroah-Hartman's avatar Greg Kroah-Hartman

[PATCH] Fix USB printer transfers

From Barry K. Nathan

This fixes the ulblp transfer length code, which would otherwise skip
the final iteration and lead to incomplete printer output (and us
waiting forever for the transfer to complete)
parent ab1b2b63
...@@ -603,7 +603,7 @@ static ssize_t usblp_write(struct file *file, const char __user *buffer, size_t ...@@ -603,7 +603,7 @@ static ssize_t usblp_write(struct file *file, const char __user *buffer, size_t
{ {
DECLARE_WAITQUEUE(wait, current); DECLARE_WAITQUEUE(wait, current);
struct usblp *usblp = file->private_data; struct usblp *usblp = file->private_data;
int timeout, err = 0, transfer_length; int timeout, err = 0, transfer_length = 0;
size_t writecount = 0; size_t writecount = 0;
while (writecount < count) { while (writecount < count) {
...@@ -654,6 +654,16 @@ static ssize_t usblp_write(struct file *file, const char __user *buffer, size_t ...@@ -654,6 +654,16 @@ static ssize_t usblp_write(struct file *file, const char __user *buffer, size_t
continue; continue;
} }
/* We must increment writecount here, and not at the
* end of the loop. Otherwise, the final loop iteration may
* be skipped, leading to incomplete printer output.
*/
writecount += transfer_length;
if (writecount == count) {
up(&usblp->sem);
break;
}
transfer_length=(count - writecount); transfer_length=(count - writecount);
if (transfer_length > USBLP_BUF_SIZE) if (transfer_length > USBLP_BUF_SIZE)
transfer_length = USBLP_BUF_SIZE; transfer_length = USBLP_BUF_SIZE;
...@@ -677,8 +687,6 @@ static ssize_t usblp_write(struct file *file, const char __user *buffer, size_t ...@@ -677,8 +687,6 @@ static ssize_t usblp_write(struct file *file, const char __user *buffer, size_t
break; break;
} }
up (&usblp->sem); up (&usblp->sem);
writecount += transfer_length;
} }
return count; return count;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment