> > Done.  I also took 8 bytes off of the POST_BSIZE to account for the
> > extra int (assuming int's are 8 bytes on 64 bit CPUs).
>
> No, int is always 4 bytes.

OK, I only took 4 bytes off.

>
> The patch is good enough, but keep in mind some things.
>
> > --- drivers/usb/serial/usbserial.orig       2004-09-28 10:21:54.000000000 -0400
> > +++ drivers/usb/serial/usbserial.c  2004-09-28 16:40:31.000000000 -0400
>
> This is wrong. You ought to generate patches with:
>  diff -ur linux-base linux-work
> This way the patch can be applied with -p1

Done.

>
> > +                   BUG();
> > +           }
> >             up(&port->sem);
> > -
> > +
> >             spin_lock_irqsave(&post_lock, flags);
>
> A replacement of one empty line with another empty line is fishy.
> Either your diff is toast, or your editor adds trailing space
> and THEN your mailer strips it. It's a pure luck that your patch
> is still usable.

Fixed.

Thanks for the help Pete!  Here is the updated patch:


Signed-off-by: Sam King <[EMAIL PROTECTED]>

--- linux-2.4.27-base/drivers/usb/serial/usbserial.c    2004-08-07 19:26:05.000000000 
-0400
+++ linux-2.4.27-work/drivers/usb/serial/usbserial.c    2004-09-29 09:21:29.000000000 
-0400
@@ -350,10 +350,13 @@
 /*
  * The post kludge structures and variables.
  */
-#define POST_BSIZE     100     /* little below 128 in total */
+#define POST_JOB_WRITE    0
+#define POST_JOB_THROTTLE 1
+#define POST_BSIZE        96   /* little below 128 in total */
 struct usb_serial_post_job {
        struct list_head link;
        struct usb_serial_port *port;
+       int type;
        int len;
        char buff[POST_BSIZE];
 };
@@ -367,11 +370,12 @@
 static int __serial_write (struct usb_serial_port *port, int from_user, const 
unsigned char *buf, int count);
 static int  serial_write (struct tty_struct * tty, int from_user, const unsigned char 
*buf, int count);
 static int  serial_post_job(struct usb_serial_port *port, int from_user,
-    int gfp, const unsigned char *buf, int count);
+    int gfp, const unsigned char *buf, int count, int type);
 static int  serial_post_one(struct usb_serial_port *port, int from_user,
-    int gfp, const unsigned char *buf, int count);
+    int gfp, const unsigned char *buf, int count, int type);
 static int  serial_write_room (struct tty_struct *tty);
 static int  serial_chars_in_buffer (struct tty_struct *tty);
+static void __serial_throttle (struct tty_struct * tty);
 static void serial_throttle (struct tty_struct * tty);
 static void serial_unthrottle (struct tty_struct * tty);
 static int  serial_ioctl (struct tty_struct *tty, struct file * file, unsigned int 
cmd, unsigned long arg);
@@ -497,19 +501,28 @@
                port = job->port;
                /* get_usb_serial checks port->tty, so cannot be used */
                serial = port->serial;
-               if (port->write_busy) {
-                       dbg("%s - port %d busy", __FUNCTION__, port->number);
-                       pos = pos->next;
-                       continue;
+               if (job->type == POST_JOB_WRITE) {
+                       if (port->write_busy) {
+                               dbg("%s - port %d busy", __FUNCTION__, port->number);
+                               pos = pos->next;
+                               continue;
+                       }
                }
                list_del(&job->link);
                spin_unlock_irqrestore(&post_lock, flags);

                down(&port->sem);
-               dbg("%s - port %d len %d backlog %d", __FUNCTION__,
-                   port->number, job->len, port->write_backlog);
-               if (port->tty != NULL)
-                       __serial_write(port, 0, job->buff, job->len);
+               if (job->type == POST_JOB_WRITE) {
+                       dbg("%s - port %d len %d backlog %d", __FUNCTION__,
+                           port->number, job->len, port->write_backlog);
+                       if (port->tty != NULL)
+                               __serial_write(port, 0, job->buff, job->len);
+               } else if (job->type == POST_JOB_THROTTLE) {
+                       if (port->tty != NULL)
+                               __serial_throttle(port->tty);
+               } else {
+                       BUG();
+               }
                up(&port->sem);

                spin_lock_irqsave(&post_lock, flags);
@@ -722,7 +735,7 @@
                if (port->write_busy) {
                        up(&port->sem);
                        return serial_post_job(port, from_user, GFP_KERNEL,
-                           buf, count);
+                           buf, count, POST_JOB_WRITE);
                }

                rc = __serial_write(port, from_user, buf, count);
@@ -740,11 +753,12 @@
                return -EINVAL;
        }

-       return serial_post_job(port, 0, GFP_ATOMIC, buf, count);
+       return serial_post_job(port, 0, GFP_ATOMIC, buf, count,
+                              POST_JOB_WRITE);
 }

 static int serial_post_job(struct usb_serial_port *port, int from_user,
-    int gfp, const unsigned char *buf, int count)
+    int gfp, const unsigned char *buf, int count, int type)
 {
        int done = 0, length;
        int rc;
@@ -767,27 +781,34 @@
                count = 512;
        }

-       while (done < count) {
-               length = count - done;
-               if (length > POST_BSIZE)
-                       length = POST_BSIZE;
-               if (length > port->bulk_out_size)
-                       length = port->bulk_out_size;
-
-               rc = serial_post_one(port, from_user, gfp, buf + done, length);
-               if (rc <= 0) {
-                       if (done != 0)
-                               return done;
-                       return rc;
+       if (type == POST_JOB_WRITE) {
+               while (done < count) {
+                       length = count - done;
+                       if (length > POST_BSIZE)
+                               length = POST_BSIZE;
+                       if (length > port->bulk_out_size)
+                               length = port->bulk_out_size;
+
+                       rc = serial_post_one(port, from_user, gfp, buf + done,
+                                            length, type);
+                       if (rc <= 0) {
+                               if (done != 0)
+                                       return done;
+                               return rc;
+                       }
+                       done += rc;
                }
-               done += rc;
+       } else if (type == POST_JOB_THROTTLE) {
+               serial_post_one(port, from_user, gfp, buf, count, type);
+       } else {
+               BUG();
        }
-
+
        return done;
 }

 static int serial_post_one(struct usb_serial_port *port, int from_user,
-    int gfp, const unsigned char *buf, int count)
+    int gfp, const unsigned char *buf, int count, int type)
 {
        struct usb_serial *serial = get_usb_serial (port, __FUNCTION__);
        struct usb_serial_post_job *job;
@@ -803,14 +824,17 @@
        if (count >= POST_BSIZE)
                count = POST_BSIZE;
        job->len = count;
+       job->type = type;

-       if (from_user) {
-               if (copy_from_user(job->buff, buf, count)) {
-                       kfree(job);
-                       return -EFAULT;
+       if (type == POST_JOB_WRITE) {
+               if (from_user) {
+                       if (copy_from_user(job->buff, buf, count)) {
+                               kfree(job);
+                               return -EFAULT;
+                       }
+               } else {
+                       memcpy(job->buff, buf, count);
                }
-       } else {
-               memcpy(job->buff, buf, count);
        }

        spin_lock_irqsave(&post_lock, flags);
@@ -895,21 +919,36 @@
        if (!serial)
                return;

-       down (&port->sem);
+       if (!in_interrupt()) {
+               post_helper(NULL);
+
+               down(&port->sem);
+               __serial_throttle(tty);
+               up (&port->sem);
+               return;
+       }
+
+       serial_post_job(port, 0, GFP_ATOMIC, NULL, 0, POST_JOB_THROTTLE);
+}
+
+static void __serial_throttle (struct tty_struct * tty)
+{
+       struct usb_serial_port *port = (struct usb_serial_port *) tty->driver_data;
+       struct usb_serial *serial = get_usb_serial (port, __FUNCTION__);
+
+       if (!serial)
+               return;

        dbg("%s - port %d", __FUNCTION__, port->number);

        if (!port->open_count) {
                dbg ("%s - port not open", __FUNCTION__);
-               goto exit;
+               return;
        }

        /* pass on to the driver specific version of this function */
        if (serial->type->throttle)
                serial->type->throttle(port);
-
-exit:
-       up (&port->sem);
 }

 static void serial_unthrottle (struct tty_struct * tty)


-------------------------------------------------------
This SF.net email is sponsored by: IT Product Guide on ITManagersJournal
Use IT products in your business? Tell us what you think of them. Give us
Your Opinions, Get Free ThinkGeek Gift Certificates! Click to find out more
http://productguide.itmanagersjournal.com/guidepromo.tmpl
_______________________________________________
[EMAIL PROTECTED]
To unsubscribe, use the last form field at:
https://lists.sourceforge.net/lists/listinfo/linux-usb-devel

Reply via email to