[03/59] drm/vboxvideo: Use devm_drm_dev_alloc
diff mbox series

Message ID 20200415074034.175360-4-daniel.vetter@ffwll.ch
State New
Headers show
Series
  • devm_drm_dev_alloc, v2
Related show

Commit Message

Daniel Vetter April 15, 2020, 7:39 a.m. UTC
Straightforward conversion.

Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
Cc: Hans de Goede <hdegoede@redhat.com>
---
 drivers/gpu/drm/vboxvideo/vbox_drv.c | 19 +++++--------------
 1 file changed, 5 insertions(+), 14 deletions(-)

Comments

Hans de Goede April 15, 2020, 3:02 p.m. UTC | #1
Hi,

On 4/15/20 9:39 AM, Daniel Vetter wrote:
> Straightforward conversion.
> 
> Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
> Cc: Hans de Goede <hdegoede@redhat.com>

LGTM:

Reviewed-by: Hans de Goede <hdegoede@redhat.com>

Regards,

Hans



> ---
>   drivers/gpu/drm/vboxvideo/vbox_drv.c | 19 +++++--------------
>   1 file changed, 5 insertions(+), 14 deletions(-)
> 
> diff --git a/drivers/gpu/drm/vboxvideo/vbox_drv.c b/drivers/gpu/drm/vboxvideo/vbox_drv.c
> index 282348e071fe..7dd25c7a3768 100644
> --- a/drivers/gpu/drm/vboxvideo/vbox_drv.c
> +++ b/drivers/gpu/drm/vboxvideo/vbox_drv.c
> @@ -46,25 +46,19 @@ static int vbox_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
>   	if (ret)
>   		return ret;
>   
> -	vbox = kzalloc(sizeof(*vbox), GFP_KERNEL);
> -	if (!vbox)
> -		return -ENOMEM;
> -
> -	ret = drm_dev_init(&vbox->ddev, &driver, &pdev->dev);
> -	if (ret) {
> -		kfree(vbox);
> -		return ret;
> -	}
> +	vbox = devm_drm_dev_alloc(&pdev->dev, &driver,
> +				  struct vbox_private, ddev);
> +	if (IS_ERR(vbox))
> +		return PTR_ERR(vbox);
>   
>   	vbox->ddev.pdev = pdev;
>   	vbox->ddev.dev_private = vbox;
>   	pci_set_drvdata(pdev, vbox);
> -	drmm_add_final_kfree(&vbox->ddev, vbox);
>   	mutex_init(&vbox->hw_mutex);
>   
>   	ret = pci_enable_device(pdev);
>   	if (ret)
> -		goto err_dev_put;
> +		return ret;
>   
>   	ret = vbox_hw_init(vbox);
>   	if (ret)
> @@ -100,8 +94,6 @@ static int vbox_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
>   	vbox_hw_fini(vbox);
>   err_pci_disable:
>   	pci_disable_device(pdev);
> -err_dev_put:
> -	drm_dev_put(&vbox->ddev);
>   	return ret;
>   }
>   
> @@ -114,7 +106,6 @@ static void vbox_pci_remove(struct pci_dev *pdev)
>   	vbox_mode_fini(vbox);
>   	vbox_mm_fini(vbox);
>   	vbox_hw_fini(vbox);
> -	drm_dev_put(&vbox->ddev);
>   }
>   
>   #ifdef CONFIG_PM_SLEEP
>
Sam Ravnborg April 24, 2020, 4:33 p.m. UTC | #2
On Wed, Apr 15, 2020 at 09:39:38AM +0200, Daniel Vetter wrote:
> Straightforward conversion.
> 
> Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
> Cc: Hans de Goede <hdegoede@redhat.com>
Acked-by: Sam Ravnborg <sam@ravnborg.org>
> ---
>  drivers/gpu/drm/vboxvideo/vbox_drv.c | 19 +++++--------------
>  1 file changed, 5 insertions(+), 14 deletions(-)
> 
> diff --git a/drivers/gpu/drm/vboxvideo/vbox_drv.c b/drivers/gpu/drm/vboxvideo/vbox_drv.c
> index 282348e071fe..7dd25c7a3768 100644
> --- a/drivers/gpu/drm/vboxvideo/vbox_drv.c
> +++ b/drivers/gpu/drm/vboxvideo/vbox_drv.c
> @@ -46,25 +46,19 @@ static int vbox_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
>  	if (ret)
>  		return ret;
>  
> -	vbox = kzalloc(sizeof(*vbox), GFP_KERNEL);
> -	if (!vbox)
> -		return -ENOMEM;
> -
> -	ret = drm_dev_init(&vbox->ddev, &driver, &pdev->dev);
> -	if (ret) {
> -		kfree(vbox);
> -		return ret;
> -	}
> +	vbox = devm_drm_dev_alloc(&pdev->dev, &driver,
> +				  struct vbox_private, ddev);
> +	if (IS_ERR(vbox))
> +		return PTR_ERR(vbox);
>  
>  	vbox->ddev.pdev = pdev;
>  	vbox->ddev.dev_private = vbox;
>  	pci_set_drvdata(pdev, vbox);
> -	drmm_add_final_kfree(&vbox->ddev, vbox);
>  	mutex_init(&vbox->hw_mutex);
>  
>  	ret = pci_enable_device(pdev);
>  	if (ret)
> -		goto err_dev_put;
> +		return ret;
>  
>  	ret = vbox_hw_init(vbox);
>  	if (ret)
> @@ -100,8 +94,6 @@ static int vbox_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
>  	vbox_hw_fini(vbox);
>  err_pci_disable:
>  	pci_disable_device(pdev);
> -err_dev_put:
> -	drm_dev_put(&vbox->ddev);
>  	return ret;
>  }
>  
> @@ -114,7 +106,6 @@ static void vbox_pci_remove(struct pci_dev *pdev)
>  	vbox_mode_fini(vbox);
>  	vbox_mm_fini(vbox);
>  	vbox_hw_fini(vbox);
> -	drm_dev_put(&vbox->ddev);
>  }
>  
>  #ifdef CONFIG_PM_SLEEP
> -- 
> 2.25.1
> 
> _______________________________________________
> dri-devel mailing list
> dri-devel@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/dri-devel

Patch
diff mbox series

diff --git a/drivers/gpu/drm/vboxvideo/vbox_drv.c b/drivers/gpu/drm/vboxvideo/vbox_drv.c
index 282348e071fe..7dd25c7a3768 100644
--- a/drivers/gpu/drm/vboxvideo/vbox_drv.c
+++ b/drivers/gpu/drm/vboxvideo/vbox_drv.c
@@ -46,25 +46,19 @@  static int vbox_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
 	if (ret)
 		return ret;
 
-	vbox = kzalloc(sizeof(*vbox), GFP_KERNEL);
-	if (!vbox)
-		return -ENOMEM;
-
-	ret = drm_dev_init(&vbox->ddev, &driver, &pdev->dev);
-	if (ret) {
-		kfree(vbox);
-		return ret;
-	}
+	vbox = devm_drm_dev_alloc(&pdev->dev, &driver,
+				  struct vbox_private, ddev);
+	if (IS_ERR(vbox))
+		return PTR_ERR(vbox);
 
 	vbox->ddev.pdev = pdev;
 	vbox->ddev.dev_private = vbox;
 	pci_set_drvdata(pdev, vbox);
-	drmm_add_final_kfree(&vbox->ddev, vbox);
 	mutex_init(&vbox->hw_mutex);
 
 	ret = pci_enable_device(pdev);
 	if (ret)
-		goto err_dev_put;
+		return ret;
 
 	ret = vbox_hw_init(vbox);
 	if (ret)
@@ -100,8 +94,6 @@  static int vbox_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
 	vbox_hw_fini(vbox);
 err_pci_disable:
 	pci_disable_device(pdev);
-err_dev_put:
-	drm_dev_put(&vbox->ddev);
 	return ret;
 }
 
@@ -114,7 +106,6 @@  static void vbox_pci_remove(struct pci_dev *pdev)
 	vbox_mode_fini(vbox);
 	vbox_mm_fini(vbox);
 	vbox_hw_fini(vbox);
-	drm_dev_put(&vbox->ddev);
 }
 
 #ifdef CONFIG_PM_SLEEP