aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorSarah Sharp <sarah.a.sharp@linux.intel.com>2009-05-14 14:44:14 -0400
committerGreg Kroah-Hartman <gregkh@suse.de>2009-06-16 00:44:51 -0400
commit6071d8363b7b284038069f1795a98372fbc1a48e (patch)
treee5b56ace01d240c49b1acbdc02f17cf6a2102fdc /drivers
parent7dd19e69d131ea34f74397559b422511e54d2911 (diff)
usb; xhci: Fix TRB offset calculations.
Greg KH introduced a bug into xhci_trb_virt_to_dma() when he changed the type of offset to dma_addr_t from unsigned int and dropped the casts to unsigned int around the virtual address pointer subtraction. trb and seg->trbs are both valid pointers to virtual addresses, so the compiler will mod the subtraction by the size of union trb (16 bytes). segment_offset is an unsigned long, which is guaranteed to be at least as big as a void *. Drop the void * casts in the first if statement because trb and seg->trbs are both pointers of the same type (pointers to union trb). Signed-off-by: Sarah Sharp <sarah.a.sharp@linux.intel.com> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/usb/host/xhci-ring.c13
1 files changed, 6 insertions, 7 deletions
diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c
index d42a738cdaa7..02d81985c454 100644
--- a/drivers/usb/host/xhci-ring.c
+++ b/drivers/usb/host/xhci-ring.c
@@ -74,16 +74,15 @@
74dma_addr_t xhci_trb_virt_to_dma(struct xhci_segment *seg, 74dma_addr_t xhci_trb_virt_to_dma(struct xhci_segment *seg,
75 union xhci_trb *trb) 75 union xhci_trb *trb)
76{ 76{
77 dma_addr_t offset; 77 unsigned long segment_offset;
78 78
79 if (!seg || !trb || (void *) trb < (void *) seg->trbs) 79 if (!seg || !trb || trb < seg->trbs)
80 return 0; 80 return 0;
81 /* offset in bytes, since these are byte-addressable */ 81 /* offset in TRBs */
82 offset = trb - seg->trbs; 82 segment_offset = trb - seg->trbs;
83 /* SEGMENT_SIZE in bytes, trbs are 16-byte aligned */ 83 if (segment_offset > TRBS_PER_SEGMENT)
84 if (offset > SEGMENT_SIZE || (offset % sizeof(*trb)) != 0)
85 return 0; 84 return 0;
86 return seg->dma + offset; 85 return seg->dma + (segment_offset * sizeof(*trb));
87} 86}
88 87
89/* Does this link TRB point to the first segment in a ring, 88/* Does this link TRB point to the first segment in a ring,