diff mbox series

[11/59] drm/udl: Use devm_drm_dev_alloc

Message ID 20200415074034.175360-12-daniel.vetter@ffwll.ch (mailing list archive)
State New, archived
Headers show
Series devm_drm_dev_alloc, v2 | expand

Commit Message

Daniel Vetter April 15, 2020, 7:39 a.m. UTC
Also init the fbdev emulation before we register the device, that way
we can rely on the auto-cleanup and simplify the probe error code even
more.

v2: Rebase on top of Thomas' patches to remove the return value from
drm_fbdev_generic_setup()

Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
Cc: Noralf Trønnes <noralf@tronnes.org>
Cc: Dave Airlie <airlied@redhat.com>
Cc: Sean Paul <sean@poorly.run>
Cc: Thomas Zimmermann <tzimmermann@suse.de>
Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
Cc: Emil Velikov <emil.l.velikov@gmail.com>
Cc: Sam Ravnborg <sam@ravnborg.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
---
 drivers/gpu/drm/udl/udl_drv.c | 26 +++++++-------------------
 1 file changed, 7 insertions(+), 19 deletions(-)

Comments

Thomas Zimmermann April 15, 2020, 7:55 a.m. UTC | #1
Am 15.04.20 um 09:39 schrieb Daniel Vetter:
> Also init the fbdev emulation before we register the device, that way
> we can rely on the auto-cleanup and simplify the probe error code even
> more.
> 
> v2: Rebase on top of Thomas' patches to remove the return value from
> drm_fbdev_generic_setup()
> 
> Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
> Cc: Noralf Trønnes <noralf@tronnes.org>
> Cc: Dave Airlie <airlied@redhat.com>
> Cc: Sean Paul <sean@poorly.run>
> Cc: Thomas Zimmermann <tzimmermann@suse.de>
> Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
> Cc: Emil Velikov <emil.l.velikov@gmail.com>
> Cc: Sam Ravnborg <sam@ravnborg.org>
> Cc: Thomas Gleixner <tglx@linutronix.de>

Reviewed-by: Thomas Zimmermann <tzimmermann@suse.de>

> ---
>  drivers/gpu/drm/udl/udl_drv.c | 26 +++++++-------------------
>  1 file changed, 7 insertions(+), 19 deletions(-)
> 
> diff --git a/drivers/gpu/drm/udl/udl_drv.c b/drivers/gpu/drm/udl/udl_drv.c
> index 9cc6d075cb40..523f60e02a85 100644
> --- a/drivers/gpu/drm/udl/udl_drv.c
> +++ b/drivers/gpu/drm/udl/udl_drv.c
> @@ -57,27 +57,20 @@ static struct udl_device *udl_driver_create(struct usb_interface *interface)
>  	struct udl_device *udl;
>  	int r;
>  
> -	udl = kzalloc(sizeof(*udl), GFP_KERNEL);
> -	if (!udl)
> -		return ERR_PTR(-ENOMEM);
> -
> -	r = drm_dev_init(&udl->drm, &driver, &interface->dev);
> -	if (r) {
> -		kfree(udl);
> -		return ERR_PTR(r);
> -	}
> +	udl = devm_drm_dev_alloc(&interface->dev, &driver,
> +				 struct udl_device, drm);
> +	if (IS_ERR(udl))
> +		return udl;
>  
>  	udl->udev = udev;
>  	udl->drm.dev_private = udl;
> -	drmm_add_final_kfree(&udl->drm, udl);
>  
>  	r = udl_init(udl);
> -	if (r) {
> -		drm_dev_put(&udl->drm);
> +	if (r)
>  		return ERR_PTR(r);
> -	}
>  
>  	usb_set_intfdata(interface, udl);
> +
>  	return udl;
>  }
>  
> @@ -93,17 +86,13 @@ static int udl_usb_probe(struct usb_interface *interface,
>  
>  	r = drm_dev_register(&udl->drm, 0);
>  	if (r)
> -		goto err_free;
> +		return r;
>  
>  	DRM_INFO("Initialized udl on minor %d\n", udl->drm.primary->index);
>  
>  	drm_fbdev_generic_setup(&udl->drm, 0);
>  
>  	return 0;
> -
> -err_free:
> -	drm_dev_put(&udl->drm);
> -	return r;
>  }
>  
>  static void udl_usb_disconnect(struct usb_interface *interface)
> @@ -113,7 +102,6 @@ static void udl_usb_disconnect(struct usb_interface *interface)
>  	drm_kms_helper_poll_fini(dev);
>  	udl_drop_usb(dev);
>  	drm_dev_unplug(dev);
> -	drm_dev_put(dev);
>  }
>  
>  /*
>
Sam Ravnborg April 24, 2020, 2:55 p.m. UTC | #2
Hi Daniel.

On Wed, Apr 15, 2020 at 09:39:46AM +0200, Daniel Vetter wrote:
> Also init the fbdev emulation before we register the device, that way
> we can rely on the auto-cleanup and simplify the probe error code even
> more.
> 
> v2: Rebase on top of Thomas' patches to remove the return value from
> drm_fbdev_generic_setup()

with the rebase the changelog in confusing as this patch does nothing of
what is described in the changelog.
Only the title (that is in convinently not available when replying to
email) describes what this patch does.

With the changelog properly adjusted:
Acked-by: Sam Ravnborg <sam@ravnborg.org>

> 
> Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
> Cc: Noralf Trønnes <noralf@tronnes.org>
> Cc: Dave Airlie <airlied@redhat.com>
> Cc: Sean Paul <sean@poorly.run>
> Cc: Thomas Zimmermann <tzimmermann@suse.de>
> Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
> Cc: Emil Velikov <emil.l.velikov@gmail.com>
> Cc: Sam Ravnborg <sam@ravnborg.org>
> Cc: Thomas Gleixner <tglx@linutronix.de>
> ---
>  drivers/gpu/drm/udl/udl_drv.c | 26 +++++++-------------------
>  1 file changed, 7 insertions(+), 19 deletions(-)
> 
> diff --git a/drivers/gpu/drm/udl/udl_drv.c b/drivers/gpu/drm/udl/udl_drv.c
> index 9cc6d075cb40..523f60e02a85 100644
> --- a/drivers/gpu/drm/udl/udl_drv.c
> +++ b/drivers/gpu/drm/udl/udl_drv.c
> @@ -57,27 +57,20 @@ static struct udl_device *udl_driver_create(struct usb_interface *interface)
>  	struct udl_device *udl;
>  	int r;
>  
> -	udl = kzalloc(sizeof(*udl), GFP_KERNEL);
> -	if (!udl)
> -		return ERR_PTR(-ENOMEM);
> -
> -	r = drm_dev_init(&udl->drm, &driver, &interface->dev);
> -	if (r) {
> -		kfree(udl);
> -		return ERR_PTR(r);
> -	}
> +	udl = devm_drm_dev_alloc(&interface->dev, &driver,
> +				 struct udl_device, drm);
> +	if (IS_ERR(udl))
> +		return udl;
>  
>  	udl->udev = udev;
>  	udl->drm.dev_private = udl;
> -	drmm_add_final_kfree(&udl->drm, udl);
>  
>  	r = udl_init(udl);
> -	if (r) {
> -		drm_dev_put(&udl->drm);
> +	if (r)
>  		return ERR_PTR(r);
> -	}
>  
>  	usb_set_intfdata(interface, udl);
> +
>  	return udl;
>  }
>  
> @@ -93,17 +86,13 @@ static int udl_usb_probe(struct usb_interface *interface,
>  
>  	r = drm_dev_register(&udl->drm, 0);
>  	if (r)
> -		goto err_free;
> +		return r;
>  
>  	DRM_INFO("Initialized udl on minor %d\n", udl->drm.primary->index);
>  
>  	drm_fbdev_generic_setup(&udl->drm, 0);
>  
>  	return 0;
> -
> -err_free:
> -	drm_dev_put(&udl->drm);
> -	return r;
>  }
>  
>  static void udl_usb_disconnect(struct usb_interface *interface)
> @@ -113,7 +102,6 @@ static void udl_usb_disconnect(struct usb_interface *interface)
>  	drm_kms_helper_poll_fini(dev);
>  	udl_drop_usb(dev);
>  	drm_dev_unplug(dev);
> -	drm_dev_put(dev);
>  }
>  
>  /*
> -- 
> 2.25.1
> 
> _______________________________________________
> dri-devel mailing list
> dri-devel@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/dri-devel
Daniel Vetter April 28, 2020, 1:18 p.m. UTC | #3
On Fri, Apr 24, 2020 at 04:55:56PM +0200, Sam Ravnborg wrote:
> Hi Daniel.
> 
> On Wed, Apr 15, 2020 at 09:39:46AM +0200, Daniel Vetter wrote:
> > Also init the fbdev emulation before we register the device, that way
> > we can rely on the auto-cleanup and simplify the probe error code even
> > more.
> > 
> > v2: Rebase on top of Thomas' patches to remove the return value from
> > drm_fbdev_generic_setup()
> 
> with the rebase the changelog in confusing as this patch does nothing of
> what is described in the changelog.
> Only the title (that is in convinently not available when replying to
> email) describes what this patch does.

Good point, I fixed that up while applying, thanks for taking a look.
-Daniel

> 
> With the changelog properly adjusted:
> Acked-by: Sam Ravnborg <sam@ravnborg.org>
> 
> > 
> > Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
> > Cc: Noralf Trønnes <noralf@tronnes.org>
> > Cc: Dave Airlie <airlied@redhat.com>
> > Cc: Sean Paul <sean@poorly.run>
> > Cc: Thomas Zimmermann <tzimmermann@suse.de>
> > Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
> > Cc: Emil Velikov <emil.l.velikov@gmail.com>
> > Cc: Sam Ravnborg <sam@ravnborg.org>
> > Cc: Thomas Gleixner <tglx@linutronix.de>
> > ---
> >  drivers/gpu/drm/udl/udl_drv.c | 26 +++++++-------------------
> >  1 file changed, 7 insertions(+), 19 deletions(-)
> > 
> > diff --git a/drivers/gpu/drm/udl/udl_drv.c b/drivers/gpu/drm/udl/udl_drv.c
> > index 9cc6d075cb40..523f60e02a85 100644
> > --- a/drivers/gpu/drm/udl/udl_drv.c
> > +++ b/drivers/gpu/drm/udl/udl_drv.c
> > @@ -57,27 +57,20 @@ static struct udl_device *udl_driver_create(struct usb_interface *interface)
> >  	struct udl_device *udl;
> >  	int r;
> >  
> > -	udl = kzalloc(sizeof(*udl), GFP_KERNEL);
> > -	if (!udl)
> > -		return ERR_PTR(-ENOMEM);
> > -
> > -	r = drm_dev_init(&udl->drm, &driver, &interface->dev);
> > -	if (r) {
> > -		kfree(udl);
> > -		return ERR_PTR(r);
> > -	}
> > +	udl = devm_drm_dev_alloc(&interface->dev, &driver,
> > +				 struct udl_device, drm);
> > +	if (IS_ERR(udl))
> > +		return udl;
> >  
> >  	udl->udev = udev;
> >  	udl->drm.dev_private = udl;
> > -	drmm_add_final_kfree(&udl->drm, udl);
> >  
> >  	r = udl_init(udl);
> > -	if (r) {
> > -		drm_dev_put(&udl->drm);
> > +	if (r)
> >  		return ERR_PTR(r);
> > -	}
> >  
> >  	usb_set_intfdata(interface, udl);
> > +
> >  	return udl;
> >  }
> >  
> > @@ -93,17 +86,13 @@ static int udl_usb_probe(struct usb_interface *interface,
> >  
> >  	r = drm_dev_register(&udl->drm, 0);
> >  	if (r)
> > -		goto err_free;
> > +		return r;
> >  
> >  	DRM_INFO("Initialized udl on minor %d\n", udl->drm.primary->index);
> >  
> >  	drm_fbdev_generic_setup(&udl->drm, 0);
> >  
> >  	return 0;
> > -
> > -err_free:
> > -	drm_dev_put(&udl->drm);
> > -	return r;
> >  }
> >  
> >  static void udl_usb_disconnect(struct usb_interface *interface)
> > @@ -113,7 +102,6 @@ static void udl_usb_disconnect(struct usb_interface *interface)
> >  	drm_kms_helper_poll_fini(dev);
> >  	udl_drop_usb(dev);
> >  	drm_dev_unplug(dev);
> > -	drm_dev_put(dev);
> >  }
> >  
> >  /*
> > -- 
> > 2.25.1
> > 
> > _______________________________________________
> > dri-devel mailing list
> > dri-devel@lists.freedesktop.org
> > https://lists.freedesktop.org/mailman/listinfo/dri-devel
diff mbox series

Patch

diff --git a/drivers/gpu/drm/udl/udl_drv.c b/drivers/gpu/drm/udl/udl_drv.c
index 9cc6d075cb40..523f60e02a85 100644
--- a/drivers/gpu/drm/udl/udl_drv.c
+++ b/drivers/gpu/drm/udl/udl_drv.c
@@ -57,27 +57,20 @@  static struct udl_device *udl_driver_create(struct usb_interface *interface)
 	struct udl_device *udl;
 	int r;
 
-	udl = kzalloc(sizeof(*udl), GFP_KERNEL);
-	if (!udl)
-		return ERR_PTR(-ENOMEM);
-
-	r = drm_dev_init(&udl->drm, &driver, &interface->dev);
-	if (r) {
-		kfree(udl);
-		return ERR_PTR(r);
-	}
+	udl = devm_drm_dev_alloc(&interface->dev, &driver,
+				 struct udl_device, drm);
+	if (IS_ERR(udl))
+		return udl;
 
 	udl->udev = udev;
 	udl->drm.dev_private = udl;
-	drmm_add_final_kfree(&udl->drm, udl);
 
 	r = udl_init(udl);
-	if (r) {
-		drm_dev_put(&udl->drm);
+	if (r)
 		return ERR_PTR(r);
-	}
 
 	usb_set_intfdata(interface, udl);
+
 	return udl;
 }
 
@@ -93,17 +86,13 @@  static int udl_usb_probe(struct usb_interface *interface,
 
 	r = drm_dev_register(&udl->drm, 0);
 	if (r)
-		goto err_free;
+		return r;
 
 	DRM_INFO("Initialized udl on minor %d\n", udl->drm.primary->index);
 
 	drm_fbdev_generic_setup(&udl->drm, 0);
 
 	return 0;
-
-err_free:
-	drm_dev_put(&udl->drm);
-	return r;
 }
 
 static void udl_usb_disconnect(struct usb_interface *interface)
@@ -113,7 +102,6 @@  static void udl_usb_disconnect(struct usb_interface *interface)
 	drm_kms_helper_poll_fini(dev);
 	udl_drop_usb(dev);
 	drm_dev_unplug(dev);
-	drm_dev_put(dev);
 }
 
 /*