All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] drm/radeon:avoid null pointer dereference when dev is not bound
@ 2020-12-27  8:24 ` Defang Bo
  0 siblings, 0 replies; 8+ messages in thread
From: Defang Bo @ 2020-12-27  8:24 UTC (permalink / raw)
  To: airlied, daniel
  Cc: alexander.deucher, amd-gfx, dri-devel, linux-kernel, Defang Bo

[Why]
Similar to commit<0fa375e6>. If the set_state/can_switch code access the drm_device when dev is not bound,
a null pointer dereference can happen.

[How]
Add sanity checks to prevent it.

Signed-off-by: Defang Bo <bodefang@126.com>
---
 drivers/gpu/drm/radeon/radeon_device.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
index 266e3cb..50a1a60 100644
--- a/drivers/gpu/drm/radeon/radeon_device.c
+++ b/drivers/gpu/drm/radeon/radeon_device.c
@@ -1224,6 +1224,9 @@ static void radeon_switcheroo_set_state(struct pci_dev *pdev, enum vga_switchero
 {
 	struct drm_device *dev = pci_get_drvdata(pdev);
 
+	if (!dev)
+		return;
+
 	if (radeon_is_px(dev) && state == VGA_SWITCHEROO_OFF)
 		return;
 
@@ -1257,6 +1260,9 @@ static void radeon_switcheroo_set_state(struct pci_dev *pdev, enum vga_switchero
 static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
 {
 	struct drm_device *dev = pci_get_drvdata(pdev);
+
+	if (!dev)
+		return false;
 
 	/*
 	 * FIXME: open_count is protected by drm_global_mutex but that would lead to
-- 
2.7.4


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

end of thread, other threads:[~2021-01-05  8:23 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-27  8:24 [PATCH] drm/radeon:avoid null pointer dereference when dev is not bound Defang Bo
2020-12-27  8:24 ` Defang Bo
2020-12-27  8:24 ` Defang Bo
2021-01-04 17:00 ` Alex Deucher
2021-01-04 17:00   ` Alex Deucher
2021-01-04 17:00   ` Alex Deucher
2021-01-05  2:43   ` bodefang
2021-01-05  2:43     ` bodefang

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.