Skip to contentSkip to conversation

drm/amdgpu: fix null pointer reference to adev.

PATCH Superseded Lepton Wu 3 participants 5 messages Jul 7, 2020

Subsystems (2)
lore
Share & tools
lore

Lepton Wu

author
#0 lore raw

PATCH 1/1 drm/amdgpu: fix null pointer reference to adev.

I hit this when compiling amdgpu in kernel. amdgpu_driver_load_kms fail to load firmwares since GPU was initialized before rootfs is ready. Just gracefully fail in such cases.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 3 ++-
 drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 2 ++
 2 files changed, 4 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +2 -1
index 126e74758a34..f9d277f8ddd4 100644
@@ -1124,7 +1124,8 @@ static int amdgpu_pci_probe(struct pci_dev *pdev,
 		goto err_pci;
 
 	adev = dev->dev_private;
-	ret = amdgpu_debugfs_init(adev);
+	if (adev)
+		ret = amdgpu_debugfs_init(adev);
 	if (ret)
 		DRM_ERROR("Creating debugfs files failed (%d).\n", ret);
 
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +2 -0
index d7e17e34fee1..99a6ec49ead5 100644
@@ -978,6 +978,8 @@ int amdgpu_driver_open_kms(struct drm_device *dev, struct drm_file *file_priv)
 	struct amdgpu_fpriv *fpriv;
 	int r, pasid;
 
+	if (!adev)
+		return -ENODEV;
 	/* Ensure IB tests are run on ring */
 	flush_delayed_work(&adev->delayed_init_work);
 
Signature · 6 lines
2.27.0.212.ge8ba1cc988-goog

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
maintainer
#1 lore raw

Am 07.07.20 um 05:26 schrieb Lepton Wu:

Quoted 3 lines

I hit this when compiling amdgpu in kernel. amdgpu_driver_load_kms fail to load firmwares since GPU was initialized before rootfs is ready. Just gracefully fail in such cases.

Good catch, but the solution looks incorrect to me.

The underlying problem is that the return value of amdgpu_driver_load_kms() is not correctly checked.

Christian.

Quoted 26 lines
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 3 ++-
  drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 2 ++
  2 files changed, 4 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +2 -1
index 126e74758a34..f9d277f8ddd4 100644
@@ -1124,7 +1124,8 @@ static int amdgpu_pci_probe(struct pci_dev *pdev,
  		goto err_pci;
 
  	adev = dev->dev_private;
-	ret = amdgpu_debugfs_init(adev);
+	if (adev)
+		ret = amdgpu_debugfs_init(adev);
  	if (ret)
  		DRM_ERROR("Creating debugfs files failed (%d).\n", ret);
 
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +0 -0
index d7e17e34fee1..99a6ec49ead5 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c int amdgpu_driver_open_kms(struct drm_device *dev, struct drm_file *file_priv) · line 985

Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +2 -0
@@ -978,6 +978,8 @@ int amdgpu_driver_open_kms(struct drm_device *dev, struct drm_file *file_priv)
  	struct amdgpu_fpriv *fpriv;
  	int r, pasid;
 
+	if (!adev)
+		return -ENODEV;
  	/* Ensure IB tests are run on ring */
  	flush_delayed_work(&adev->delayed_init_work);
 

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

author
#2 lore raw

PATCH v2 1/1 drm/amdgpu: fix null pointer reference to adev.

I hit this when compiling amdgpu in kernel. amdgpu_driver_load_kms fail to load firmwares since GPU was initialized before rootfs is ready. Just gracefully fail in such cases.

v2: Check return code of amdgpu_driver_load_kms

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +3 -1
index 126e74758a34..75bcd1789185 100644
@@ -1111,7 +1111,9 @@ static int amdgpu_pci_probe(struct pci_dev *pdev,
 
 	pci_set_drvdata(pdev, dev);
 
-	amdgpu_driver_load_kms(dev, ent->driver_data);
+	ret = amdgpu_driver_load_kms(dev, ent->driver_data);
+	if (ret)
+		goto err_pci;
 
 retry_init:
 	ret = drm_dev_register(dev, ent->driver_data);
Signature · 6 lines
2.27.0.212.ge8ba1cc988-goog

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
#3 lore raw
Quoted 8 lines · Lepton Wu

I hit this when compiling amdgpu in kernel. amdgpu_driver_load_kms fail to load firmwares since GPU was initialized before rootfs is ready. Just gracefully fail in such cases.

v2: Check return code of amdgpu_driver_load_kms

Already fixed:
https://cgit.freedesktop.org/drm/drm/commit/?id=7504d3bbec7da70516a13e34415b92bf5203399a

Alex

Quoted 22 lines
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +3 -2
index 126e74758a34..75bcd1789185 100644
@@ -1111,7 +1111,9 @@ static int amdgpu_pci_probe(struct pci_dev *pdev,
 
        pci_set_drvdata(pdev, dev);
 
-       amdgpu_driver_load_kms(dev, ent->driver_data);
+       ret = amdgpu_driver_load_kms(dev, ent->driver_data);
+       if (ret)
+               goto err_pci;
 
 retry_init:
        ret = drm_dev_register(dev, ent->driver_data);
--

2.27.0.212.ge8ba1cc988-goog

Quoted 4 lines

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

author
#4 lore raw
Quoted 7 lines · Alex Deucher
Quoted 5 lines · Lepton Wu

I hit this when compiling amdgpu in kernel. amdgpu_driver_load_kms fail to load firmwares since GPU was initialized before rootfs is ready. Just gracefully fail in such cases.

Quoted 6 lines
Quoted 3 lines

v2: Check return code of amdgpu_driver_load_kms

Already fixed:
https://cgit.freedesktop.org/drm/drm/commit/?id=7504d3bbec7da70516a13e34415b92bf5203399a

Nice, next time I will check drm tree instead of Linus tree for drm related stuff.

Quoted 25 lines

Alex

Quoted 22 lines
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +3 -2
index 126e74758a34..75bcd1789185 100644
@@ -1111,7 +1111,9 @@ static int amdgpu_pci_probe(struct pci_dev *pdev,
 
        pci_set_drvdata(pdev, dev);
 
-       amdgpu_driver_load_kms(dev, ent->driver_data);
+       ret = amdgpu_driver_load_kms(dev, ent->driver_data);
+       if (ret)
+               goto err_pci;
 
 retry_init:
        ret = drm_dev_register(dev, ent->driver_data);
--

2.27.0.212.ge8ba1cc988-goog

Quoted 4 lines
Quoted 4 lines

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx