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

Noralf Trønnes noralf at tronnes.org
Thu Sep 12 19:57:26 UTC 2024



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 at 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;
>  


More information about the dri-devel mailing list