Linux-PCI Archive on lore.kernel.org
 help / color / Atom feed
From: Ard Biesheuvel <ardb@kernel.org>
To: linux-pci@vger.kernel.org
Cc: christian.koenig@amd.com, bhelgaas@google.com, jon@solid-run.com,
	wasim.khan@nxp.com, Ard Biesheuvel <ardb@kernel.org>
Subject: [PATCH] PCI: allow pci_resize_resource() to be used on devices on the root bus
Date: Tue, 21 Apr 2020 18:22:56 +0200
Message-ID: <20200421162256.26887-1-ardb@kernel.org> (raw)

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


             reply index

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-21 16:22 Ard Biesheuvel [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200421162256.26887-1-ardb@kernel.org \
    --to=ardb@kernel.org \
    --cc=bhelgaas@google.com \
    --cc=christian.koenig@amd.com \
    --cc=jon@solid-run.com \
    --cc=linux-pci@vger.kernel.org \
    --cc=wasim.khan@nxp.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Linux-PCI Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-pci/0 linux-pci/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-pci linux-pci/ https://lore.kernel.org/linux-pci \
		linux-pci@vger.kernel.org
	public-inbox-index linux-pci

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-pci


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git