mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Haotian Zhang <vulab@iscas.ac.cn>
To: Antonino Daplas <adaplas@gmail.com>, Helge Deller <deller@gmx.de>
Cc: linux-fbdev@vger.kernel.org, dri-devel@lists.freedesktop.org,
	linux-kernel@vger.kernel.org, Haotian Zhang <vulab@iscas.ac.cn>
Subject: [PATCH] fbdev/riva: Add NULL checks for pci_get_domain_bus_and_slot()
Date: Fri, 14 Nov 2025 16:06:34 +0800	[thread overview]
Message-ID: <20251114080634.2342-1-vulab@iscas.ac.cn> (raw)

The pci_get_domain_bus_and_slot() function can return NULL
if the requested PCI device is not found. The
nForceUpdateArbitrationSettings() and nv10GetConfig()
do not check for this, which can lead to a NULL pointer dereference
when the returned pointer is used in pci_read_config_dword().

Add NULL checks immediately after the calls to
pci_get_domain_bus_and_slot() in both functions.

Fixes: e22810808354 ("video: fbdev: riva: deprecate pci_get_bus_and_slot()")
Signed-off-by: Haotian Zhang <vulab@iscas.ac.cn>
---
 drivers/video/fbdev/riva/riva_hw.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/drivers/video/fbdev/riva/riva_hw.c b/drivers/video/fbdev/riva/riva_hw.c
index 8b829b720064..5b2f2d57c101 100644
--- a/drivers/video/fbdev/riva/riva_hw.c
+++ b/drivers/video/fbdev/riva/riva_hw.c
@@ -1100,6 +1100,10 @@ static void nForceUpdateArbitrationSettings
 	int domain = pci_domain_nr(pdev->bus);

 	dev = pci_get_domain_bus_and_slot(domain, 0, 3);
+	if (!dev) {
+		WARN_ON(1);
+		return;
+	}
 	pci_read_config_dword(dev, 0x6C, &uMClkPostDiv);
 	pci_dev_put(dev);
 	uMClkPostDiv = (uMClkPostDiv >> 8) & 0xf;
@@ -1115,6 +1119,10 @@ static void nForceUpdateArbitrationSettings
 	sim_data.enable_mp      = 0;

 	dev = pci_get_domain_bus_and_slot(domain, 0, 1);
+	if (!dev) {
+		WARN_ON(1);
+		return;
+	}
 	pci_read_config_dword(dev, 0x7C, &sim_data.memory_type);
 	pci_dev_put(dev);
 	sim_data.memory_type    = (sim_data.memory_type >> 12) & 1;
@@ -2085,11 +2093,19 @@ static void nv10GetConfig
 	 */
 	if(chipset == NV_CHIP_IGEFORCE2) {
 		dev = pci_get_domain_bus_and_slot(domain, 0, 1);
+		if (!dev) {
+			WARN_ON(1);
+			return;
+		}
 		pci_read_config_dword(dev, 0x7C, &amt);
 		pci_dev_put(dev);
 		chip->RamAmountKBytes = (((amt >> 6) & 31) + 1) * 1024;
 	} else if(chipset == NV_CHIP_0x01F0) {
 		dev = pci_get_domain_bus_and_slot(domain, 0, 1);
+		if (!dev) {
+			WARN_ON(1);
+			return;
+		}
 		pci_read_config_dword(dev, 0x84, &amt);
 		pci_dev_put(dev);
 		chip->RamAmountKBytes = (((amt >> 4) & 127) + 1) * 1024;
-- 
2.50.1.windows.1


             reply	other threads:[~2025-11-14  8:07 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-14  8:06 Haotian Zhang [this message]
2025-11-14 19:15 ` Helge Deller

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=20251114080634.2342-1-vulab@iscas.ac.cn \
    --to=vulab@iscas.ac.cn \
    --cc=adaplas@gmail.com \
    --cc=deller@gmx.de \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=linux-fbdev@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®