linux-pci.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] PCI: allow pci_resize_resource() to be used on devices on the root bus
@ 2020-04-21 16:22 Ard Biesheuvel
  2020-04-21 16:43 ` Christian König
  2020-05-01 17:30 ` Bjorn Helgaas
  0 siblings, 2 replies; 16+ messages in thread
From: Ard Biesheuvel @ 2020-04-21 16:22 UTC (permalink / raw)
  To: linux-pci; +Cc: christian.koenig, bhelgaas, jon, wasim.khan, Ard Biesheuvel

When resizing a BAR, pci_reassign_bridge_resources() is invoked to
bring the bridge windows of parent bridges in line with the new BAR
assignment.

This assumes that the device whose BAR is being resized lives on a
subordinate bus, but this is not necessarily the case. A device may
live on the root bus, in which case dev->bus->self is NULL, and
passing a NULL pci_dev pointer to pci_reassign_bridge_resources()
will cause it to crash.

So let's make the call to pci_reassign_bridge_resources() conditional
on whether dev->bus->self is non-NULL in the first place.

Fixes: 8bb705e3e79d84e7 ("PCI: Add pci_resize_resource() for resizing BARs")
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
---
 drivers/pci/setup-res.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/drivers/pci/setup-res.c b/drivers/pci/setup-res.c
index d8ca40a97693..d21fa04fa44d 100644
--- a/drivers/pci/setup-res.c
+++ b/drivers/pci/setup-res.c
@@ -439,10 +439,11 @@ int pci_resize_resource(struct pci_dev *dev, int resno, int size)
 	res->end = res->start + pci_rebar_size_to_bytes(size) - 1;
 
 	/* Check if the new config works by trying to assign everything. */
-	ret = pci_reassign_bridge_resources(dev->bus->self, res->flags);
-	if (ret)
-		goto error_resize;
-
+	if (dev->bus->self) {
+		ret = pci_reassign_bridge_resources(dev->bus->self, res->flags);
+		if (ret)
+			goto error_resize;
+	}
 	return 0;
 
 error_resize:
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2020-05-01 17:30 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-21 16:22 [PATCH] PCI: allow pci_resize_resource() to be used on devices on the root bus Ard Biesheuvel
2020-04-21 16:43 ` Christian König
2020-04-21 17:07   ` Ard Biesheuvel
2020-04-25 17:32     ` Ard Biesheuvel
2020-04-26  9:08       ` Christian König
2020-04-26  9:58         ` Ard Biesheuvel
2020-04-26 10:46           ` Ard Biesheuvel
2020-04-26 10:53             ` Christian König
2020-04-26 10:59               ` Ard Biesheuvel
2020-04-26 11:27                 ` Christian König
2020-04-26 12:08                   ` Ard Biesheuvel
2020-04-26 12:55                     ` Christian König
2020-04-26 13:04                       ` Ard Biesheuvel
2020-04-26 13:16                         ` Christian König
2020-04-26 10:49           ` Christian König
2020-05-01 17:30 ` Bjorn Helgaas

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).