This patch updates the shuttle-usbat driver to be scatter-gather safe.

Greg, please apply.

Matt

----- Forwarded message from Alan Stern <[EMAIL PROTECTED]> -----

Date: Mon, 24 Nov 2003 16:31:35 -0500 (EST)
From: Alan Stern <[EMAIL PROTECTED]>
Subject: PATCH: (as147)  Update scatter-gather handling in the shuttle-usbat
 driver
To: Matthew Dharm <[EMAIL PROTECTED]>
cc: USB Storage List <[EMAIL PROTECTED]>
X-Spam-Status: No, hits=-4.0 required=5.0 tests=UNIFIED_PATCH,RCVD_IN_ORBZ version=2.11

Matt:

This patch updates the shuttle_usbat driver to use the new scatter-gather 
transfer routines.  The small set of changes needed speaks well for the 
original organization of the code.

This has not been tested.

Alan Stern


===== shuttle_usbat.c 1.24 vs edited =====
--- 1.24/drivers/usb/storage/shuttle_usbat.c    Mon Aug  4 13:47:08 2003
+++ edited/drivers/usb/storage/shuttle_usbat.c  Mon Nov 24 16:19:30 2003
@@ -40,7 +40,6 @@
  */
 
 #include "transport.h"
-#include "raw_bulk.h"
 #include "protocol.h"
 #include "usb.h"
 #include "debug.h"
@@ -529,9 +528,8 @@
        unsigned char *buffer;
        unsigned int len;
        unsigned int sector;
-       struct scatterlist *sg = NULL;
-       int sg_segment = 0;
-       int sg_offset = 0;
+       unsigned int sg_segment = 0;
+       unsigned int sg_offset = 0;
 
        US_DEBUGP("handle_read10: transfersize %d\n",
                srb->transfersize);
@@ -572,19 +570,20 @@
 
        len = (65535/srb->transfersize) * srb->transfersize;
        US_DEBUGP("Max read is %d bytes\n", len);
-       buffer = kmalloc(len, GFP_NOIO);
-       if (buffer == NULL) // bloody hell!
-               return USB_STOR_TRANSPORT_FAILED;
+       len = min(len, srb->request_bufflen);
+       if (srb->use_sg) {
+               buffer = kmalloc(len, GFP_NOIO);
+               if (buffer == NULL) // bloody hell!
+                       return USB_STOR_TRANSPORT_FAILED;
+       } else
+               buffer = srb->request_buffer;
        sector = short_pack(data[7+3], data[7+2]);
        sector <<= 16;
        sector |= short_pack(data[7+5], data[7+4]);
        transferred = 0;
 
-       if (srb->use_sg) {
-               sg = (struct scatterlist *)srb->request_buffer;
-               sg_segment = 0; // for keeping track of where we are in
-               sg_offset = 0;  // the scatter/gather list
-       }
+       sg_segment = 0; // for keeping track of where we are in
+       sg_offset = 0;  // the scatter/gather list
 
        while (transferred != srb->request_bufflen) {
 
@@ -618,10 +617,10 @@
                // Transfer the received data into the srb buffer
 
                if (srb->use_sg)
-                       us_copy_to_sgbuf(buffer, len, sg,
-                                        &sg_segment, &sg_offset, srb->use_sg);
+                       usb_stor_access_xfer_buf(buffer, len, srb,
+                                        &sg_segment, &sg_offset, TO_XFER_BUF);
                else
-                       memcpy(srb->request_buffer+transferred, buffer, len);
+                       buffer += len;
 
                // Update the amount transferred and the sector number
 
@@ -630,7 +629,8 @@
 
        } // while transferred != srb->request_bufflen
 
-       kfree(buffer);
+       if (srb->use_sg)
+               kfree(buffer);
        return result;
 }
 

----- End forwarded message -----

-- 
Matthew Dharm                              Home: [EMAIL PROTECTED] 
Maintainer, Linux USB Mass Storage Driver

S:  Another stupid question?
G:  There's no such thing as a stupid question, only stupid people.
                                        -- Stef and Greg
User Friendly, 7/15/1998

Attachment: pgp00000.pgp
Description: PGP signature

Reply via email to