Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

xhci: simplify how we store TDs in urb private data

Instead of storing a zero length array of td pointers, and then
allocate memory both for the td pointer array and the td's, just
use a zero length array of actual td's in urb private data.

old:

struct urb_priv {
struct xhci_td *td[0]
}

new:

struct urb_priv {
struct xhci_td td[0]
}

Signed-off-by: Mathias Nyman <mathias.nyman@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Mathias Nyman and committed by
Greg Kroah-Hartman
7e64b037 9ef7fbbb

+18 -33
+1 -4
drivers/usb/host/xhci-mem.c
··· 1817 1817 1818 1818 void xhci_urb_free_priv(struct urb_priv *urb_priv) 1819 1819 { 1820 - if (urb_priv) { 1821 - kfree(urb_priv->td[0]); 1822 - kfree(urb_priv); 1823 - } 1820 + kfree(urb_priv); 1824 1821 } 1825 1822 1826 1823 void xhci_free_command(struct xhci_hcd *xhci,
+10 -10
drivers/usb/host/xhci-ring.c
··· 2838 2838 return ret; 2839 2839 2840 2840 urb_priv = urb->hcpriv; 2841 - td = urb_priv->td[td_index]; 2841 + td = &urb_priv->td[td_index]; 2842 2842 2843 2843 INIT_LIST_HEAD(&td->td_list); 2844 2844 INIT_LIST_HEAD(&td->cancelled_td_list); ··· 3134 3134 if (urb->transfer_flags & URB_ZERO_PACKET && urb_priv->num_tds > 1) 3135 3135 need_zero_pkt = true; 3136 3136 3137 - td = urb_priv->td[0]; 3137 + td = &urb_priv->td[0]; 3138 3138 3139 3139 /* 3140 3140 * Don't give the first TRB to the hardware (by toggling the cycle bit) ··· 3227 3227 ret = prepare_transfer(xhci, xhci->devs[slot_id], 3228 3228 ep_index, urb->stream_id, 3229 3229 1, urb, 1, mem_flags); 3230 - urb_priv->td[1]->last_trb = ring->enqueue; 3230 + urb_priv->td[1].last_trb = ring->enqueue; 3231 3231 field = TRB_TYPE(TRB_NORMAL) | ring->cycle_state | TRB_IOC; 3232 3232 queue_trb(xhci, ring, 0, 0, 0, TRB_INTR_TARGET(0), field); 3233 3233 } ··· 3279 3279 return ret; 3280 3280 3281 3281 urb_priv = urb->hcpriv; 3282 - td = urb_priv->td[0]; 3282 + td = &urb_priv->td[0]; 3283 3283 3284 3284 /* 3285 3285 * Don't give the first TRB to the hardware (by toggling the cycle bit) ··· 3567 3567 return ret; 3568 3568 goto cleanup; 3569 3569 } 3570 - td = urb_priv->td[i]; 3570 + td = &urb_priv->td[i]; 3571 3571 3572 3572 /* use SIA as default, if frame id is used overwrite it */ 3573 3573 sia_frame_id = TRB_SIA; ··· 3674 3674 /* Clean up a partially enqueued isoc transfer. */ 3675 3675 3676 3676 for (i--; i >= 0; i--) 3677 - list_del_init(&urb_priv->td[i]->td_list); 3677 + list_del_init(&urb_priv->td[i].td_list); 3678 3678 3679 3679 /* Use the first TD as a temporary variable to turn the TDs we've queued 3680 3680 * into No-ops with a software-owned cycle bit. That way the hardware 3681 3681 * won't accidentally start executing bogus TDs when we partially 3682 3682 * overwrite them. td->first_trb and td->start_seg are already set. 3683 3683 */ 3684 - urb_priv->td[0]->last_trb = ep_ring->enqueue; 3684 + urb_priv->td[0].last_trb = ep_ring->enqueue; 3685 3685 /* Every TRB except the first & last will have its cycle bit flipped. */ 3686 - td_to_noop(xhci, ep_ring, urb_priv->td[0], true); 3686 + td_to_noop(xhci, ep_ring, &urb_priv->td[0], true); 3687 3687 3688 3688 /* Reset the ring enqueue back to the first TRB and its cycle bit. */ 3689 - ep_ring->enqueue = urb_priv->td[0]->first_trb; 3690 - ep_ring->enq_seg = urb_priv->td[0]->start_seg; 3689 + ep_ring->enqueue = urb_priv->td[0].first_trb; 3690 + ep_ring->enq_seg = urb_priv->td[0].start_seg; 3691 3691 ep_ring->cycle_state = start_cycle; 3692 3692 ep_ring->num_trbs_free = ep_ring->num_trbs_free_temp; 3693 3693 usb_hcd_unlink_urb_from_ep(bus_to_hcd(urb->dev->bus), urb);
+6 -18
drivers/usb/host/xhci.c
··· 1332 1332 int xhci_urb_enqueue(struct usb_hcd *hcd, struct urb *urb, gfp_t mem_flags) 1333 1333 { 1334 1334 struct xhci_hcd *xhci = hcd_to_xhci(hcd); 1335 - struct xhci_td *buffer; 1336 1335 unsigned long flags; 1337 1336 int ret = 0; 1338 1337 unsigned int slot_id, ep_index; 1339 1338 struct urb_priv *urb_priv; 1340 - int num_tds, i; 1339 + int num_tds; 1341 1340 1342 1341 if (!urb || xhci_check_args(hcd, urb->dev, urb->ep, 1343 1342 true, true, __func__) <= 0) ··· 1363 1364 num_tds = 1; 1364 1365 1365 1366 urb_priv = kzalloc(sizeof(struct urb_priv) + 1366 - num_tds * sizeof(struct xhci_td *), mem_flags); 1367 + num_tds * sizeof(struct xhci_td), mem_flags); 1367 1368 if (!urb_priv) 1368 1369 return -ENOMEM; 1369 - 1370 - buffer = kzalloc(num_tds * sizeof(struct xhci_td), mem_flags); 1371 - if (!buffer) { 1372 - kfree(urb_priv); 1373 - return -ENOMEM; 1374 - } 1375 - 1376 - for (i = 0; i < num_tds; i++) { 1377 - urb_priv->td[i] = buffer; 1378 - buffer++; 1379 - } 1380 1370 1381 1371 urb_priv->num_tds = num_tds; 1382 1372 urb_priv->num_tds_done = 0; ··· 1514 1526 for (i = urb_priv->num_tds_done; 1515 1527 i < urb_priv->num_tds && xhci->devs[urb->dev->slot_id]; 1516 1528 i++) { 1517 - td = urb_priv->td[i]; 1529 + td = &urb_priv->td[i]; 1518 1530 if (!list_empty(&td->td_list)) 1519 1531 list_del_init(&td->td_list); 1520 1532 if (!list_empty(&td->cancelled_td_list)) ··· 1545 1557 urb, urb->dev->devpath, 1546 1558 urb->ep->desc.bEndpointAddress, 1547 1559 (unsigned long long) xhci_trb_virt_to_dma( 1548 - urb_priv->td[i]->start_seg, 1549 - urb_priv->td[i]->first_trb)); 1560 + urb_priv->td[i].start_seg, 1561 + urb_priv->td[i].first_trb)); 1550 1562 1551 1563 for (; i < urb_priv->num_tds; i++) { 1552 - td = urb_priv->td[i]; 1564 + td = &urb_priv->td[i]; 1553 1565 list_add_tail(&td->cancelled_td_list, &ep->cancelled_td_list); 1554 1566 } 1555 1567
+1 -1
drivers/usb/host/xhci.h
··· 1610 1610 struct urb_priv { 1611 1611 int num_tds; 1612 1612 int num_tds_done; 1613 - struct xhci_td *td[0]; 1613 + struct xhci_td td[0]; 1614 1614 }; 1615 1615 1616 1616 /*