Skip to contentSkip to conversation

drm/hisilicon: Use pcim_enable_device()

PATCH In review Tian Tao 3 participants 5 messages Dec 21, 2020 – Dec 22, 2020

Subsystems (3)
lore
Share & tools
lore

Tian Tao

author maintainer
#0 lore raw

PATCH 1/1 drm/hisilicon: Use pcim_enable_device()

Using the managed function simplifies the error handling. After unloading the driver, the PCI device should now get disabled as well.

---
 drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c +2 -4
index 02f3bd1..7159018 100644
@@ -329,7 +329,7 @@ static int hibmc_pci_probe(struct pci_dev *pdev,
 	dev->pdev = pdev;
 	pci_set_drvdata(pdev, dev);
 
-	ret = pci_enable_device(pdev);
+	ret = pcim_enable_device(pdev);
 	if (ret) {
 		drm_err(dev, "failed to enable pci device: %d\n", ret);
 		goto err_free;
@@ -338,7 +338,7 @@ static int hibmc_pci_probe(struct pci_dev *pdev,
 	ret = hibmc_load(dev);
 	if (ret) {
 		drm_err(dev, "failed to load hibmc: %d\n", ret);
-		goto err_disable;
+		goto err_free;
 	}
 
 	ret = drm_dev_register(dev, 0);
@@ -354,8 +354,6 @@ static int hibmc_pci_probe(struct pci_dev *pdev,
 
 err_unload:
 	hibmc_unload(dev);
-err_disable:
-	pci_disable_device(pdev);
 err_free:
 	drm_dev_put(dev);
 
Signature · 6 lines
2.7.4

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#1 lore raw
Quoted 32 lines · Tian Tao

Using the managed function simplifies the error handling. After unloading the driver, the PCI device should now get disabled as well.

---
 drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c +2 -2
index 02f3bd1..7159018 100644
@@ -329,7 +329,7 @@ static int hibmc_pci_probe(struct pci_dev *pdev,
 	dev->pdev = pdev;
 	pci_set_drvdata(pdev, dev);
 
-	ret = pci_enable_device(pdev);
+	ret = pcim_enable_device(pdev);
 	if (ret) {
 		drm_err(dev, "failed to enable pci device: %d\n", ret);
 		goto err_free;
@@ -338,7 +338,7 @@ static int hibmc_pci_probe(struct pci_dev *pdev,
 	ret = hibmc_load(dev);
 	if (ret) {
 		drm_err(dev, "failed to load hibmc: %d\n", ret);
-		goto err_disable;
+		goto err_free;
 	}
 
 	ret = drm_dev_register(dev, 0);

drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c static int hibmc_pci_probe(struct pci_dev *pdev, · line 358

Quoted 7 lines
drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c +0 -2
@@ -354,8 +354,6 @@ static int hibmc_pci_probe(struct pci_dev *pdev,
 
 err_unload:
 	hibmc_unload(dev);
-err_disable:
-	pci_disable_device(pdev);
 err_free:
 	drm_dev_put(dev);

The drm_dev_put here and in hibmc_pci_remove is wrong, devm_drm_dev_alloc takes care of that already. I'm kinda suprised you don't have a refcount underrun already - do you test module unload with KASAN enabled?

The pcim patch looks ok, so Reviewed-by: Daniel Vetter <[email protected]>

Cheers, Daniel

Quoted 4 lines
Signature · 2 lines
-- 
2.7.4
Signature · 7 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#2 lore raw
Quoted 34 lines · Daniel Vetter
Quoted 33 lines · Tian Tao

Using the managed function simplifies the error handling. After unloading the driver, the PCI device should now get disabled as well.

---
  drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c | 6 ++----
  1 file changed, 2 insertions(+), 4 deletions(-)
drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c +2 -2
index 02f3bd1..7159018 100644
@@ -329,7 +329,7 @@ static int hibmc_pci_probe(struct pci_dev *pdev,
  	dev->pdev = pdev;
  	pci_set_drvdata(pdev, dev);
 
-	ret = pci_enable_device(pdev);
+	ret = pcim_enable_device(pdev);
  	if (ret) {
  		drm_err(dev, "failed to enable pci device: %d\n", ret);
  		goto err_free;
@@ -338,7 +338,7 @@ static int hibmc_pci_probe(struct pci_dev *pdev,
  	ret = hibmc_load(dev);
  	if (ret) {
  		drm_err(dev, "failed to load hibmc: %d\n", ret);
-		goto err_disable;
+		goto err_free;
  	}
 
  	ret = drm_dev_register(dev, 0);
@@ -354,8 +354,6 @@ static int hibmc_pci_probe(struct pci_dev *pdev,
 
Quoted 9 lines

drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c static int hibmc_pci_probe(struct pci_dev *pdev, · line 358

Quoted 6 lines
drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c +0 -2
  err_unload:
  	hibmc_unload(dev);
-err_disable:
-	pci_disable_device(pdev);
  err_free:
  	drm_dev_put(dev);

The drm_dev_put here and in hibmc_pci_remove is wrong, devm_drm_dev_alloc takes care of that already. I'm kinda suprised you don't have a refcount underrun already - do you test module unload with KASAN enabled?

Thanks for helping to review the code,and kindly giving me advice。

this problem have been fixed。

c855af2f9c5c60760fd1bed7889a81bc37d2591d drm/hisilicon: Fix use-after-free

Quoted 8 lines

The pcim patch looks ok, so Reviewed-by: Daniel Vetter <[email protected]>

Cheers, Daniel

Quoted 4 lines
Signature · 2 lines
-- 
2.7.4

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

#3 lore raw
Quoted 47 lines · tiantao (H)
Quoted 34 lines · Daniel Vetter
Quoted 33 lines · Tian Tao

Using the managed function simplifies the error handling. After unloading the driver, the PCI device should now get disabled as well.

---
  drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c | 6 ++----
  1 file changed, 2 insertions(+), 4 deletions(-)
drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c +2 -2
index 02f3bd1..7159018 100644
@@ -329,7 +329,7 @@ static int hibmc_pci_probe(struct pci_dev *pdev,
     dev->pdev = pdev;
     pci_set_drvdata(pdev, dev);
 
-    ret = pci_enable_device(pdev);
+    ret = pcim_enable_device(pdev);
     if (ret) {
             drm_err(dev, "failed to enable pci device: %d\n", ret);
             goto err_free;
@@ -338,7 +338,7 @@ static int hibmc_pci_probe(struct pci_dev *pdev,
     ret = hibmc_load(dev);
     if (ret) {
             drm_err(dev, "failed to load hibmc: %d\n", ret);
-            goto err_disable;
+            goto err_free;
     }
 
     ret = drm_dev_register(dev, 0);
@@ -354,8 +354,6 @@ static int hibmc_pci_probe(struct pci_dev *pdev,
 
Quoted 9 lines

drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c static int hibmc_pci_probe(struct pci_dev *pdev, · line 358

Quoted 6 lines
drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c +0 -2
  err_unload:
     hibmc_unload(dev);
-err_disable:
-    pci_disable_device(pdev);
  err_free:
     drm_dev_put(dev);

The drm_dev_put here and in hibmc_pci_remove is wrong, devm_drm_dev_alloc takes care of that already. I'm kinda suprised you don't have a refcount underrun already - do you test module unload with KASAN enabled?

Quoted 5 lines

Thanks for helping to review the code,and kindly giving me advice。

this problem have been fixed。

c855af2f9c5c60760fd1bed7889a81bc37d2591d drm/hisilicon: Fix use-after-free

Sorry, I was on an older tree. Note that this fix is incomplete, the drm_dev_put in the error path of hibmc_pci_probe still exists. -Daniel

Quoted 10 lines
Quoted 9 lines

The pcim patch looks ok, so Reviewed-by: Daniel Vetter <[email protected]>

Cheers, Daniel

Quoted 4 lines
drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c +0 -1
--

2.7.4

Signature · 7 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#4 lore raw
Quoted 46 lines · Daniel Vetter
Quoted 45 lines · tiantao (H)
Quoted 43 lines · Daniel Vetter
Quoted 32 lines · Tian Tao

Using the managed function simplifies the error handling. After unloading the driver, the PCI device should now get disabled as well.

---
   drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c | 6 ++----
   1 file changed, 2 insertions(+), 4 deletions(-)
drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c +2 -2
index 02f3bd1..7159018 100644
@@ -329,7 +329,7 @@ static int hibmc_pci_probe(struct pci_dev *pdev,
      dev->pdev = pdev;
      pci_set_drvdata(pdev, dev);
 
-    ret = pci_enable_device(pdev);
+    ret = pcim_enable_device(pdev);
      if (ret) {
              drm_err(dev, "failed to enable pci device: %d\n", ret);
              goto err_free;
@@ -338,7 +338,7 @@ static int hibmc_pci_probe(struct pci_dev *pdev,
      ret = hibmc_load(dev);
      if (ret) {
              drm_err(dev, "failed to load hibmc: %d\n", ret);
-            goto err_disable;
+            goto err_free;
      }
 
      ret = drm_dev_register(dev, 0);

drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c static int hibmc_pci_probe(struct pci_dev *pdev, · line 358

Quoted 7 lines
drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c +0 -2
@@ -354,8 +354,6 @@ static int hibmc_pci_probe(struct pci_dev *pdev,
 
   err_unload:
      hibmc_unload(dev);
-err_disable:
-    pci_disable_device(pdev);
   err_free:
      drm_dev_put(dev);

The drm_dev_put here and in hibmc_pci_remove is wrong, devm_drm_dev_alloc takes care of that already. I'm kinda suprised you don't have a refcount underrun already - do you test module unload with KASAN enabled?

Quoted 8 lines
Quoted 5 lines

Thanks for helping to review the code,and kindly giving me advice。

this problem have been fixed。

c855af2f9c5c60760fd1bed7889a81bc37d2591d drm/hisilicon: Fix use-after-free

Sorry, I was on an older tree. Note that this fix is incomplete, the drm_dev_put in the error path of hibmc_pci_probe still exists. -Daniel

I also found the problem, has raised the patch in the internal review and testing, to confirm that there is no problem, it will be sent out. Thanks for the reminder.

Quoted 8 lines
Quoted 7 lines
Quoted 7 lines

The pcim patch looks ok, so Reviewed-by: Daniel Vetter <[email protected]>

Cheers, Daniel

Quoted 3 lines
drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c +0 -1
--

2.7.4

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