]> err.no Git - linux-2.6/commitdiff
[PATCH] PATCH: usb-storage: allocate separate sense buffer
authorAlan Stern <stern@rowland.harvard.edu>
Mon, 24 Oct 2005 02:40:22 +0000 (19:40 -0700)
committerGreg Kroah-Hartman <gregkh@suse.de>
Fri, 28 Oct 2005 23:47:50 +0000 (16:47 -0700)
This patch is from Alan Stern (as560).  It has been rediffed against a
current tree.

This patch allocates a separate buffer for usb-storage to use when
auto-sensing.  Up to now we have been using the sense buffer embedded in a
scsi_cmnd struct, which is dangerous on hosts that (a) don't do
cache-coherent DMA or (b) have DMA alignment restrictions.

Signed-off-by: Alan Stern <stern@rowland.harvard.edu>
Signed-off-by: Matthew Dharm <mdharm-usb@one-eyed-alien.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
drivers/usb/storage/transport.c
drivers/usb/storage/usb.c
drivers/usb/storage/usb.h

index e89e945fc4a756a50e229790094222af570f2237..7ca896a342e3ed1c9711475921f854d464b954ff 100644 (file)
@@ -636,11 +636,11 @@ void usb_stor_invoke_transport(struct scsi_cmnd *srb, struct us_data *us)
 
                /* use the new buffer we have */
                old_request_buffer = srb->request_buffer;
-               srb->request_buffer = srb->sense_buffer;
+               srb->request_buffer = us->sensebuf;
 
                /* set the buffer length for transfer */
                old_request_bufflen = srb->request_bufflen;
-               srb->request_bufflen = 18;
+               srb->request_bufflen = US_SENSE_SIZE;
 
                /* set up for no scatter-gather use */
                old_sg = srb->use_sg;
@@ -652,6 +652,7 @@ void usb_stor_invoke_transport(struct scsi_cmnd *srb, struct us_data *us)
                temp_result = us->transport(us->srb, us);
 
                /* let's clean up right away */
+               memcpy(srb->sense_buffer, us->sensebuf, US_SENSE_SIZE);
                srb->resid = old_resid;
                srb->request_buffer = old_request_buffer;
                srb->request_bufflen = old_request_bufflen;
index 92ee079d9172ecc367aab61ff0130c880b5cc706..eb901817b7d20626e1b1545bb51ec739a1602b55 100644 (file)
@@ -467,6 +467,12 @@ static int associate_dev(struct us_data *us, struct usb_interface *intf)
                US_DEBUGP("I/O buffer allocation failed\n");
                return -ENOMEM;
        }
+
+       us->sensebuf = kmalloc(US_SENSE_SIZE, GFP_KERNEL);
+       if (!us->sensebuf) {
+               US_DEBUGP("Sense buffer allocation failed\n");
+               return -ENOMEM;
+       }
        return 0;
 }
 
@@ -800,6 +806,8 @@ static void dissociate_dev(struct us_data *us)
 {
        US_DEBUGP("-- %s\n", __FUNCTION__);
 
+       kfree(us->sensebuf);
+
        /* Free the device-related DMA-mapped buffers */
        if (us->cr)
                usb_buffer_free(us->pusb_dev, sizeof(*us->cr), us->cr,
index a195adae57b6ebc26d9100446c490c03f2f77256..dfa4dc71dd3e04c967f2bf9d316be548820a962f 100644 (file)
@@ -117,6 +117,7 @@ enum { US_DO_ALL_FLAGS };
  */
 
 #define US_IOBUF_SIZE          64      /* Size of the DMA-mapped I/O buffer */
+#define US_SENSE_SIZE          18      /* Size of the autosense data buffer */
 
 typedef int (*trans_cmnd)(struct scsi_cmnd *, struct us_data*);
 typedef int (*trans_reset)(struct us_data*);
@@ -168,6 +169,7 @@ struct us_data {
        struct usb_ctrlrequest  *cr;             /* control requests     */
        struct usb_sg_request   current_sg;      /* scatter-gather req.  */
        unsigned char           *iobuf;          /* I/O buffer           */
+       unsigned char           *sensebuf;       /* sense data buffer    */
        dma_addr_t              cr_dma;          /* buffer DMA addresses */
        dma_addr_t              iobuf_dma;