Commit bbafa4668f37f5093a3ae2a8b0cbe327e24e12da
Committed by
Greg Kroah-Hartman
1 parent
b876aef7f8
Exists in
master
and in
7 other branches
[PATCH] PATCH: usb-storage: allocate separate sense buffer
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>
Showing 3 changed files with 13 additions and 2 deletions Side-by-side Diff
drivers/usb/storage/transport.c
... | ... | @@ -636,11 +636,11 @@ |
636 | 636 | |
637 | 637 | /* use the new buffer we have */ |
638 | 638 | old_request_buffer = srb->request_buffer; |
639 | - srb->request_buffer = srb->sense_buffer; | |
639 | + srb->request_buffer = us->sensebuf; | |
640 | 640 | |
641 | 641 | /* set the buffer length for transfer */ |
642 | 642 | old_request_bufflen = srb->request_bufflen; |
643 | - srb->request_bufflen = 18; | |
643 | + srb->request_bufflen = US_SENSE_SIZE; | |
644 | 644 | |
645 | 645 | /* set up for no scatter-gather use */ |
646 | 646 | old_sg = srb->use_sg; |
... | ... | @@ -652,6 +652,7 @@ |
652 | 652 | temp_result = us->transport(us->srb, us); |
653 | 653 | |
654 | 654 | /* let's clean up right away */ |
655 | + memcpy(srb->sense_buffer, us->sensebuf, US_SENSE_SIZE); | |
655 | 656 | srb->resid = old_resid; |
656 | 657 | srb->request_buffer = old_request_buffer; |
657 | 658 | srb->request_bufflen = old_request_bufflen; |
drivers/usb/storage/usb.c
... | ... | @@ -467,6 +467,12 @@ |
467 | 467 | US_DEBUGP("I/O buffer allocation failed\n"); |
468 | 468 | return -ENOMEM; |
469 | 469 | } |
470 | + | |
471 | + us->sensebuf = kmalloc(US_SENSE_SIZE, GFP_KERNEL); | |
472 | + if (!us->sensebuf) { | |
473 | + US_DEBUGP("Sense buffer allocation failed\n"); | |
474 | + return -ENOMEM; | |
475 | + } | |
470 | 476 | return 0; |
471 | 477 | } |
472 | 478 | |
... | ... | @@ -799,6 +805,8 @@ |
799 | 805 | static void dissociate_dev(struct us_data *us) |
800 | 806 | { |
801 | 807 | US_DEBUGP("-- %s\n", __FUNCTION__); |
808 | + | |
809 | + kfree(us->sensebuf); | |
802 | 810 | |
803 | 811 | /* Free the device-related DMA-mapped buffers */ |
804 | 812 | if (us->cr) |
drivers/usb/storage/usb.h
... | ... | @@ -117,6 +117,7 @@ |
117 | 117 | */ |
118 | 118 | |
119 | 119 | #define US_IOBUF_SIZE 64 /* Size of the DMA-mapped I/O buffer */ |
120 | +#define US_SENSE_SIZE 18 /* Size of the autosense data buffer */ | |
120 | 121 | |
121 | 122 | typedef int (*trans_cmnd)(struct scsi_cmnd *, struct us_data*); |
122 | 123 | typedef int (*trans_reset)(struct us_data*); |
... | ... | @@ -168,6 +169,7 @@ |
168 | 169 | struct usb_ctrlrequest *cr; /* control requests */ |
169 | 170 | struct usb_sg_request current_sg; /* scatter-gather req. */ |
170 | 171 | unsigned char *iobuf; /* I/O buffer */ |
172 | + unsigned char *sensebuf; /* sense data buffer */ | |
171 | 173 | dma_addr_t cr_dma; /* buffer DMA addresses */ |
172 | 174 | dma_addr_t iobuf_dma; |
173 | 175 |