diff mbox series

[2/3] drm/gud: use devm_add_action_or_reset() helper

Message ID FD5792B37EAB593D+20240907070010.1661756-1-helugang@uniontech.com (mailing list archive)
State New, archived
Headers show
Series [1/3] drm/xe: use devm_add_action_or_reset() helper | expand

Commit Message

He Lugang Sept. 7, 2024, 7 a.m. UTC
Use devm_add_action_or_reset() to release resources in case of failure,
because the cleanup function will be automatically called.

Signed-off-by: He Lugang <helugang@uniontech.com>
---
 drivers/gpu/drm/gud/gud_drv.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Noralf Trønnes Sept. 12, 2024, 7:57 p.m. UTC | #1
On 07.09.2024 09:00, He Lugang wrote:
> Use devm_add_action_or_reset() to release resources in case of failure,
> because the cleanup function will be automatically called.
> 
> Signed-off-by: He Lugang <helugang@uniontech.com>
> ---
>  drivers/gpu/drm/gud/gud_drv.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/gpu/drm/gud/gud_drv.c b/drivers/gpu/drm/gud/gud_drv.c
> index ac6bbf920c72..f121f6deb268 100644
> --- a/drivers/gpu/drm/gud/gud_drv.c
> +++ b/drivers/gpu/drm/gud/gud_drv.c
> @@ -473,7 +473,7 @@ static int gud_probe(struct usb_interface *intf, const struct usb_device_id *id)
>  	INIT_WORK(&gdrm->work, gud_flush_work);
>  	gud_clear_damage(gdrm);
>  
> -	ret = devm_add_action(dev, gud_free_buffers_and_mutex, gdrm);
> +	ret = devm_add_action_or_reset(dev, gud_free_buffers_and_mutex, gdrm);

I don't think this is necessary. If this call fails we're left with an
inititalized mutex but that doesn't matter since probing ends here and
the mutex can't be accidentally used anywhere. And the buffers are
allocated later.

A change that would be useful is switching to the managed mutex_init
versions, devm_mutex_init() for ctrl_lock and drmm_mutex_init() for
damage_lock (can be accessed after the device is gone) ;-)

Noralf.

>  	if (ret)
>  		return ret;
>
diff mbox series

Patch

diff --git a/drivers/gpu/drm/gud/gud_drv.c b/drivers/gpu/drm/gud/gud_drv.c
index ac6bbf920c72..f121f6deb268 100644
--- a/drivers/gpu/drm/gud/gud_drv.c
+++ b/drivers/gpu/drm/gud/gud_drv.c
@@ -473,7 +473,7 @@  static int gud_probe(struct usb_interface *intf, const struct usb_device_id *id)
 	INIT_WORK(&gdrm->work, gud_flush_work);
 	gud_clear_damage(gdrm);
 
-	ret = devm_add_action(dev, gud_free_buffers_and_mutex, gdrm);
+	ret = devm_add_action_or_reset(dev, gud_free_buffers_and_mutex, gdrm);
 	if (ret)
 		return ret;