Skip to content

Commit a965315

Browse files
Adam Wallisgregkh
authored andcommitted
usb: xhci: force all memory allocations to node
The xhci driver forces DMA memory to be node aware, however, there are several ring-related memory allocations that are not memory node aware. This patch resolves those *alloc functions to be allocated on the proper memory node. Signed-off-by: Adam Wallis <[email protected]> Acked-by: Mathias Nyman <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 5ef12cb commit a965315

File tree

1 file changed

+38
-19
lines changed

1 file changed

+38
-19
lines changed

drivers/usb/host/xhci-mem.c

Lines changed: 38 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,9 @@ static struct xhci_segment *xhci_segment_alloc(struct xhci_hcd *xhci,
3333
struct xhci_segment *seg;
3434
dma_addr_t dma;
3535
int i;
36+
struct device *dev = xhci_to_hcd(xhci)->self.sysdev;
3637

37-
seg = kzalloc(sizeof *seg, flags);
38+
seg = kzalloc_node(sizeof(*seg), flags, dev_to_node(dev));
3839
if (!seg)
3940
return NULL;
4041

@@ -45,7 +46,8 @@ static struct xhci_segment *xhci_segment_alloc(struct xhci_hcd *xhci,
4546
}
4647

4748
if (max_packet) {
48-
seg->bounce_buf = kzalloc(max_packet, flags);
49+
seg->bounce_buf = kzalloc_node(max_packet, flags,
50+
dev_to_node(dev));
4951
if (!seg->bounce_buf) {
5052
dma_pool_free(xhci->segment_pool, seg->trbs, dma);
5153
kfree(seg);
@@ -363,8 +365,9 @@ struct xhci_ring *xhci_ring_alloc(struct xhci_hcd *xhci,
363365
{
364366
struct xhci_ring *ring;
365367
int ret;
368+
struct device *dev = xhci_to_hcd(xhci)->self.sysdev;
366369

367-
ring = kzalloc(sizeof *(ring), flags);
370+
ring = kzalloc_node(sizeof(*ring), flags, dev_to_node(dev));
368371
if (!ring)
369372
return NULL;
370373

@@ -458,11 +461,12 @@ struct xhci_container_ctx *xhci_alloc_container_ctx(struct xhci_hcd *xhci,
458461
int type, gfp_t flags)
459462
{
460463
struct xhci_container_ctx *ctx;
464+
struct device *dev = xhci_to_hcd(xhci)->self.sysdev;
461465

462466
if ((type != XHCI_CTX_TYPE_DEVICE) && (type != XHCI_CTX_TYPE_INPUT))
463467
return NULL;
464468

465-
ctx = kzalloc(sizeof(*ctx), flags);
469+
ctx = kzalloc_node(sizeof(*ctx), flags, dev_to_node(dev));
466470
if (!ctx)
467471
return NULL;
468472

@@ -615,6 +619,7 @@ struct xhci_stream_info *xhci_alloc_stream_info(struct xhci_hcd *xhci,
615619
struct xhci_ring *cur_ring;
616620
u64 addr;
617621
int ret;
622+
struct device *dev = xhci_to_hcd(xhci)->self.sysdev;
618623

619624
xhci_dbg(xhci, "Allocating %u streams and %u "
620625
"stream context array entries.\n",
@@ -625,17 +630,18 @@ struct xhci_stream_info *xhci_alloc_stream_info(struct xhci_hcd *xhci,
625630
}
626631
xhci->cmd_ring_reserved_trbs++;
627632

628-
stream_info = kzalloc(sizeof(struct xhci_stream_info), mem_flags);
633+
stream_info = kzalloc_node(sizeof(*stream_info), mem_flags,
634+
dev_to_node(dev));
629635
if (!stream_info)
630636
goto cleanup_trbs;
631637

632638
stream_info->num_streams = num_streams;
633639
stream_info->num_stream_ctxs = num_stream_ctxs;
634640

635641
/* Initialize the array of virtual pointers to stream rings. */
636-
stream_info->stream_rings = kzalloc(
637-
sizeof(struct xhci_ring *)*num_streams,
638-
mem_flags);
642+
stream_info->stream_rings = kcalloc_node(
643+
num_streams, sizeof(struct xhci_ring *), mem_flags,
644+
dev_to_node(dev));
639645
if (!stream_info->stream_rings)
640646
goto cleanup_info;
641647

@@ -831,6 +837,7 @@ int xhci_alloc_tt_info(struct xhci_hcd *xhci,
831837
struct xhci_tt_bw_info *tt_info;
832838
unsigned int num_ports;
833839
int i, j;
840+
struct device *dev = xhci_to_hcd(xhci)->self.sysdev;
834841

835842
if (!tt->multi)
836843
num_ports = 1;
@@ -840,7 +847,8 @@ int xhci_alloc_tt_info(struct xhci_hcd *xhci,
840847
for (i = 0; i < num_ports; i++, tt_info++) {
841848
struct xhci_interval_bw_table *bw_table;
842849

843-
tt_info = kzalloc(sizeof(*tt_info), mem_flags);
850+
tt_info = kzalloc_node(sizeof(*tt_info), mem_flags,
851+
dev_to_node(dev));
844852
if (!tt_info)
845853
goto free_tts;
846854
INIT_LIST_HEAD(&tt_info->tt_list);
@@ -1641,7 +1649,8 @@ static int scratchpad_alloc(struct xhci_hcd *xhci, gfp_t flags)
16411649
if (!num_sp)
16421650
return 0;
16431651

1644-
xhci->scratchpad = kzalloc(sizeof(*xhci->scratchpad), flags);
1652+
xhci->scratchpad = kzalloc_node(sizeof(*xhci->scratchpad), flags,
1653+
dev_to_node(dev));
16451654
if (!xhci->scratchpad)
16461655
goto fail_sp;
16471656

@@ -1651,7 +1660,8 @@ static int scratchpad_alloc(struct xhci_hcd *xhci, gfp_t flags)
16511660
if (!xhci->scratchpad->sp_array)
16521661
goto fail_sp2;
16531662

1654-
xhci->scratchpad->sp_buffers = kzalloc(sizeof(void *) * num_sp, flags);
1663+
xhci->scratchpad->sp_buffers = kcalloc_node(num_sp, sizeof(void *),
1664+
flags, dev_to_node(dev));
16551665
if (!xhci->scratchpad->sp_buffers)
16561666
goto fail_sp3;
16571667

@@ -1719,14 +1729,16 @@ struct xhci_command *xhci_alloc_command(struct xhci_hcd *xhci,
17191729
bool allocate_completion, gfp_t mem_flags)
17201730
{
17211731
struct xhci_command *command;
1732+
struct device *dev = xhci_to_hcd(xhci)->self.sysdev;
17221733

1723-
command = kzalloc(sizeof(*command), mem_flags);
1734+
command = kzalloc_node(sizeof(*command), mem_flags, dev_to_node(dev));
17241735
if (!command)
17251736
return NULL;
17261737

17271738
if (allocate_completion) {
17281739
command->completion =
1729-
kzalloc(sizeof(struct completion), mem_flags);
1740+
kzalloc_node(sizeof(struct completion), mem_flags,
1741+
dev_to_node(dev));
17301742
if (!command->completion) {
17311743
kfree(command);
17321744
return NULL;
@@ -2099,6 +2111,7 @@ static void xhci_add_in_port(struct xhci_hcd *xhci, unsigned int num_ports,
20992111
int i;
21002112
u8 major_revision, minor_revision;
21012113
struct xhci_hub *rhub;
2114+
struct device *dev = xhci_to_hcd(xhci)->self.sysdev;
21022115

21032116
temp = readl(addr);
21042117
major_revision = XHCI_EXT_PORT_MAJOR(temp);
@@ -2135,8 +2148,8 @@ static void xhci_add_in_port(struct xhci_hcd *xhci, unsigned int num_ports,
21352148

21362149
rhub->psi_count = XHCI_EXT_PORT_PSIC(temp);
21372150
if (rhub->psi_count) {
2138-
rhub->psi = kcalloc(rhub->psi_count, sizeof(*rhub->psi),
2139-
GFP_KERNEL);
2151+
rhub->psi = kcalloc_node(rhub->psi_count, sizeof(*rhub->psi),
2152+
GFP_KERNEL, dev_to_node(dev));
21402153
if (!rhub->psi)
21412154
rhub->psi_count = 0;
21422155

@@ -2214,10 +2227,12 @@ static void xhci_create_rhub_port_array(struct xhci_hcd *xhci,
22142227
{
22152228
int port_index = 0;
22162229
int i;
2230+
struct device *dev = xhci_to_hcd(xhci)->self.sysdev;
22172231

22182232
if (!rhub->num_ports)
22192233
return;
2220-
rhub->ports = kcalloc(rhub->num_ports, sizeof(rhub->ports), flags);
2234+
rhub->ports = kcalloc_node(rhub->num_ports, sizeof(rhub->ports), flags,
2235+
dev_to_node(dev));
22212236
for (i = 0; i < HCS_MAX_PORTS(xhci->hcs_params1); i++) {
22222237
if (xhci->hw_ports[i].rhub != rhub ||
22232238
xhci->hw_ports[i].hcd_portnum == DUPLICATE_ENTRY)
@@ -2245,9 +2260,11 @@ static int xhci_setup_port_arrays(struct xhci_hcd *xhci, gfp_t flags)
22452260
int i, j;
22462261
int cap_count = 0;
22472262
u32 cap_start;
2263+
struct device *dev = xhci_to_hcd(xhci)->self.sysdev;
22482264

22492265
num_ports = HCS_MAX_PORTS(xhci->hcs_params1);
2250-
xhci->hw_ports = kcalloc(num_ports, sizeof(*xhci->hw_ports), flags);
2266+
xhci->hw_ports = kcalloc_node(num_ports, sizeof(*xhci->hw_ports),
2267+
flags, dev_to_node(dev));
22512268
if (!xhci->hw_ports)
22522269
return -ENOMEM;
22532270

@@ -2257,7 +2274,8 @@ static int xhci_setup_port_arrays(struct xhci_hcd *xhci, gfp_t flags)
22572274
xhci->hw_ports[i].hw_portnum = i;
22582275
}
22592276

2260-
xhci->rh_bw = kzalloc(sizeof(*xhci->rh_bw)*num_ports, flags);
2277+
xhci->rh_bw = kzalloc_node(sizeof(*xhci->rh_bw)*num_ports, flags,
2278+
dev_to_node(dev));
22612279
if (!xhci->rh_bw)
22622280
return -ENOMEM;
22632281
for (i = 0; i < num_ports; i++) {
@@ -2284,7 +2302,8 @@ static int xhci_setup_port_arrays(struct xhci_hcd *xhci, gfp_t flags)
22842302
XHCI_EXT_CAPS_PROTOCOL);
22852303
}
22862304

2287-
xhci->ext_caps = kzalloc(sizeof(*xhci->ext_caps) * cap_count, flags);
2305+
xhci->ext_caps = kcalloc_node(cap_count, sizeof(*xhci->ext_caps),
2306+
flags, dev_to_node(dev));
22882307
if (!xhci->ext_caps)
22892308
return -ENOMEM;
22902309

0 commit comments

Comments
 (0)