Skip to contentSkip to conversation

drm/amd:avoid null pointer dereference when dev is not bound

PATCH New Defang Bo 1 participant 1 message Dec 27, 2020

Subsystems (3)
lore
Share & tools
lore

Defang Bo

author
#0 lore raw

PATCH 1/1 drm/amd:avoid null pointer dereference when dev is not bound

[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.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +3 -0
index 37da353..f70e528 100644
@@ -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
Signature · 1 line
2.7.4