[PATCH v2] drm/xe/oa: Remove sysfs entry on idr_alloc failure in xe_oa_add_config_ioctl()

yaolu@kylinos.cn posted 1 patch 3 weeks, 5 days ago
drivers/gpu/drm/xe/xe_oa.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
[PATCH v2] drm/xe/oa: Remove sysfs entry on idr_alloc failure in xe_oa_add_config_ioctl()
Posted by yaolu@kylinos.cn 3 weeks, 5 days ago
From: Lu Yao <yaolu@kylinos.cn>

If idr_alloc() fails after create_dynamic_oa_sysfs_entry() has
succeeded, the error path frees the OA config without removing the
metrics sysfs group.

Remove the sysfs group before releasing the config, and fix up the
misleading error message copied from the sysfs creation failure path.

Fixes: cdf02fe1a94a ("drm/xe/oa/uapi: Add/remove OA config perf ops")
Signed-off-by: Lu Yao <yaolu@kylinos.cn>
---
 drivers/gpu/drm/xe/xe_oa.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

---
v1->v2: using a new goto suggested by Rodrigo
  Link: https://lore.kernel.org/all/apGuQY7vZRIUZghZ@intel.com

diff --git a/drivers/gpu/drm/xe/xe_oa.c b/drivers/gpu/drm/xe/xe_oa.c
index 9c5384b95c63..ab09dcff5860 100644
--- a/drivers/gpu/drm/xe/xe_oa.c
+++ b/drivers/gpu/drm/xe/xe_oa.c
@@ -2435,9 +2435,9 @@ int xe_oa_add_config_ioctl(struct drm_device *dev, u64 data, struct drm_file *fi
 
 	oa_config->id = idr_alloc(&oa->metrics_idr, oa_config, 1, 0, GFP_KERNEL);
 	if (oa_config->id < 0) {
-		drm_dbg(&oa->xe->drm, "Failed to create sysfs entry for OA config\n");
+		drm_dbg(&oa->xe->drm, "Failed to allocate id for OA config\n");
 		err = oa_config->id;
-		goto sysfs_err;
+		goto id_alloc_err;
 	}
 
 	id = oa_config->id;
@@ -2448,6 +2448,8 @@ int xe_oa_add_config_ioctl(struct drm_device *dev, u64 data, struct drm_file *fi
 
 	return id;
 
+id_alloc_err:
+	sysfs_remove_group(oa->metrics_kobj, &oa_config->sysfs_metric);
 sysfs_err:
 	mutex_unlock(&oa->metrics_lock);
 reg_err:
-- 
2.25.1
Re: [PATCH v2] drm/xe/oa: Remove sysfs entry on idr_alloc failure in xe_oa_add_config_ioctl()
Posted by Rodrigo Vivi 3 weeks, 4 days ago
On Mon, Aug 31, 2026 at 09:42:18AM +0800, yaolu@kylinos.cn wrote:
> From: Lu Yao <yaolu@kylinos.cn>
> 
> If idr_alloc() fails after create_dynamic_oa_sysfs_entry() has
> succeeded, the error path frees the OA config without removing the
> metrics sysfs group.
> 
> Remove the sysfs group before releasing the config, and fix up the
> misleading error message copied from the sysfs creation failure path.
> 
> Fixes: cdf02fe1a94a ("drm/xe/oa/uapi: Add/remove OA config perf ops")
> Signed-off-by: Lu Yao <yaolu@kylinos.cn>
> ---
>  drivers/gpu/drm/xe/xe_oa.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> ---
> v1->v2: using a new goto suggested by Rodrigo

Thank you

Reviewed-by: Rodrigo Vivi <rodrigo.vivi@intel.com>

and pushed

>   Link: https://lore.kernel.org/all/apGuQY7vZRIUZghZ@intel.com
> 
> diff --git a/drivers/gpu/drm/xe/xe_oa.c b/drivers/gpu/drm/xe/xe_oa.c
> index 9c5384b95c63..ab09dcff5860 100644
> --- a/drivers/gpu/drm/xe/xe_oa.c
> +++ b/drivers/gpu/drm/xe/xe_oa.c
> @@ -2435,9 +2435,9 @@ int xe_oa_add_config_ioctl(struct drm_device *dev, u64 data, struct drm_file *fi
>  
>  	oa_config->id = idr_alloc(&oa->metrics_idr, oa_config, 1, 0, GFP_KERNEL);
>  	if (oa_config->id < 0) {
> -		drm_dbg(&oa->xe->drm, "Failed to create sysfs entry for OA config\n");
> +		drm_dbg(&oa->xe->drm, "Failed to allocate id for OA config\n");
>  		err = oa_config->id;
> -		goto sysfs_err;
> +		goto id_alloc_err;
>  	}
>  
>  	id = oa_config->id;
> @@ -2448,6 +2448,8 @@ int xe_oa_add_config_ioctl(struct drm_device *dev, u64 data, struct drm_file *fi
>  
>  	return id;
>  
> +id_alloc_err:
> +	sysfs_remove_group(oa->metrics_kobj, &oa_config->sysfs_metric);
>  sysfs_err:
>  	mutex_unlock(&oa->metrics_lock);
>  reg_err:
> -- 
> 2.25.1
>