All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] drm/amd:avoid null pointer dereference when dev is not bound
@ 2020-12-27 11:46 Defang Bo
  0 siblings, 0 replies; only message in thread
From: Defang Bo @ 2020-12-27 11:46 UTC (permalink / raw)
  To: airlied, daniel, sumit.semwal
  Cc: alexander.deucher, christian.koenig, linux-kernel, linux-media,
	linaro-mm-sig, Defang Bo

[Why]
Similar to commit<0fa375e6>. If amdgpu_switcheroo_can_switch 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/amd/amdgpu/amdgpu_device.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
index 37da353..f70e528 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
@@ -1439,6 +1439,9 @@ static void amdgpu_switcheroo_set_state(struct pci_dev *pdev,
 static bool amdgpu_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] only message in thread

only message in thread, other threads:[~2020-12-27 12:23 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-27 11:46 [PATCH] drm/amd:avoid null pointer dereference when dev is not bound Defang Bo

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.