summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLogan Gunthorpe <logang@deltatee.com>2021-06-10 18:06:05 +0200
committerBjorn Helgaas <bhelgaas@google.com>2021-06-11 01:01:41 +0200
commite4ece59abd70d8f54e2163274dc996bb442832a6 (patch)
tree9b8c0159fbd6f5a66a2ac779752ea052344d36e5
parentPCI/P2PDMA: Rename upstream_bridge_distance() and rework doc (diff)
downloadlinux-e4ece59abd70d8f54e2163274dc996bb442832a6.tar.xz
linux-e4ece59abd70d8f54e2163274dc996bb442832a6.zip
PCI/P2PDMA: Collect acs list in stack buffer to avoid sleeping
In order to call the calc_map_type_and_dist_warn() function from a dma_map operation, the function must not sleep. The only reason it sleeps is to allocate memory for the seq_buf to print a verbose warning telling the user how to disable ACS for that path. Instead of allocating the memory with kmalloc(), allocate a smaller buffer on the stack. A 128 byte buffer is enough to print 10 PCI device names. A system with 10 bridge ports between two devices that have ACS enabled would be unusually large, so this should still be a reasonable limit. This also cleans up the awkward (and broken) return with -ENOMEM which contradicts the return type and the caller was not prepared for. Link: https://lore.kernel.org/r/20210610160609.28447-3-logang@deltatee.com Signed-off-by: Logan Gunthorpe <logang@deltatee.com> Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
-rw-r--r--drivers/pci/p2pdma.c7
1 files changed, 2 insertions, 5 deletions
diff --git a/drivers/pci/p2pdma.c b/drivers/pci/p2pdma.c
index a860137fac89..109bd7321962 100644
--- a/drivers/pci/p2pdma.c
+++ b/drivers/pci/p2pdma.c
@@ -502,11 +502,10 @@ calc_map_type_and_dist_warn(struct pci_dev *provider, struct pci_dev *client,
{
struct seq_buf acs_list;
bool acs_redirects;
+ char buf[128];
int ret;
- seq_buf_init(&acs_list, kmalloc(PAGE_SIZE, GFP_KERNEL), PAGE_SIZE);
- if (!acs_list.buffer)
- return -ENOMEM;
+ seq_buf_init(&acs_list, buf, sizeof(buf));
ret = calc_map_type_and_dist(provider, client, dist, &acs_redirects,
&acs_list);
@@ -524,8 +523,6 @@ calc_map_type_and_dist_warn(struct pci_dev *provider, struct pci_dev *client,
pci_name(provider));
}
- kfree(acs_list.buffer);
-
return ret;
}