diff mbox series

[v2] drm/xe: use devm_add_action_or_reset() helper

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

Commit Message

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

Reviewed-by: Rodrigo Vivi <rodrigo.vivi@intel.com>
Signed-off-by: He Lugang <helugang@uniontech.com>
---
v2:move devm_add_action_or_reset after sysfs_create_files to avoid removing
the sysfs files that hadn't been created.
---
 drivers/gpu/drm/xe/xe_gt_freq.c  | 4 ++--
 drivers/gpu/drm/xe/xe_gt_sysfs.c | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

Comments

Rodrigo Vivi Sept. 16, 2024, 4:38 p.m. UTC | #1
On Wed, Sep 11, 2024 at 06:22:15PM +0800, He Lugang wrote:
> Use devm_add_action_or_reset() to release resources in case of failure,
> because the cleanup function will be automatically called.
> 
> Reviewed-by: Rodrigo Vivi <rodrigo.vivi@intel.com>
> Signed-off-by: He Lugang <helugang@uniontech.com>
> ---
> v2:move devm_add_action_or_reset after sysfs_create_files to avoid removing
> the sysfs files that hadn't been created.
> ---

pushed to drm-xe-next, thanks for the patch

>  drivers/gpu/drm/xe/xe_gt_freq.c  | 4 ++--
>  drivers/gpu/drm/xe/xe_gt_sysfs.c | 2 +-
>  2 files changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/gpu/drm/xe/xe_gt_freq.c b/drivers/gpu/drm/xe/xe_gt_freq.c
> index 68a5778b4319..ab76973f3e1e 100644
> --- a/drivers/gpu/drm/xe/xe_gt_freq.c
> +++ b/drivers/gpu/drm/xe/xe_gt_freq.c
> @@ -237,11 +237,11 @@ int xe_gt_freq_init(struct xe_gt *gt)
>  	if (!gt->freq)
>  		return -ENOMEM;
>  
> -	err = devm_add_action(xe->drm.dev, freq_fini, gt->freq);
> +	err = sysfs_create_files(gt->freq, freq_attrs);
>  	if (err)
>  		return err;
>  
> -	err = sysfs_create_files(gt->freq, freq_attrs);
> +	err = devm_add_action_or_reset(xe->drm.dev, freq_fini, gt->freq);
>  	if (err)
>  		return err;
>  
> diff --git a/drivers/gpu/drm/xe/xe_gt_sysfs.c b/drivers/gpu/drm/xe/xe_gt_sysfs.c
> index a05c3699e8b9..ec2b8246204b 100644
> --- a/drivers/gpu/drm/xe/xe_gt_sysfs.c
> +++ b/drivers/gpu/drm/xe/xe_gt_sysfs.c
> @@ -51,5 +51,5 @@ int xe_gt_sysfs_init(struct xe_gt *gt)
>  
>  	gt->sysfs = &kg->base;
>  
> -	return devm_add_action(xe->drm.dev, gt_sysfs_fini, gt);
> +	return devm_add_action_or_reset(xe->drm.dev, gt_sysfs_fini, gt);
>  }
> -- 
> 2.45.2
>
diff mbox series

Patch

diff --git a/drivers/gpu/drm/xe/xe_gt_freq.c b/drivers/gpu/drm/xe/xe_gt_freq.c
index 68a5778b4319..ab76973f3e1e 100644
--- a/drivers/gpu/drm/xe/xe_gt_freq.c
+++ b/drivers/gpu/drm/xe/xe_gt_freq.c
@@ -237,11 +237,11 @@  int xe_gt_freq_init(struct xe_gt *gt)
 	if (!gt->freq)
 		return -ENOMEM;
 
-	err = devm_add_action(xe->drm.dev, freq_fini, gt->freq);
+	err = sysfs_create_files(gt->freq, freq_attrs);
 	if (err)
 		return err;
 
-	err = sysfs_create_files(gt->freq, freq_attrs);
+	err = devm_add_action_or_reset(xe->drm.dev, freq_fini, gt->freq);
 	if (err)
 		return err;
 
diff --git a/drivers/gpu/drm/xe/xe_gt_sysfs.c b/drivers/gpu/drm/xe/xe_gt_sysfs.c
index a05c3699e8b9..ec2b8246204b 100644
--- a/drivers/gpu/drm/xe/xe_gt_sysfs.c
+++ b/drivers/gpu/drm/xe/xe_gt_sysfs.c
@@ -51,5 +51,5 @@  int xe_gt_sysfs_init(struct xe_gt *gt)
 
 	gt->sysfs = &kg->base;
 
-	return devm_add_action(xe->drm.dev, gt_sysfs_fini, gt);
+	return devm_add_action_or_reset(xe->drm.dev, gt_sysfs_fini, gt);
 }