Skip to content

Commit 960d710

Browse files
committed
drm/xe/oa: Handle errors in xe_oa_register()
Let xe_oa_unregister() be handled by devm infra since it's only putting the kobject. Also, since kobject_create_and_add may fail, handle the error accordingly. Reviewed-by: Ashutosh Dixit <ashutosh.dixit@intel.com> Link: https://patchwork.freedesktop.org/patch/msgid/20250213192909.996148-11-lucas.demarchi@intel.com Signed-off-by: Lucas De Marchi <lucas.demarchi@intel.com>
1 parent 00f6a86 commit 960d710

File tree

3 files changed

+24
-23
lines changed

3 files changed

+24
-23
lines changed

drivers/gpu/drm/xe/xe_device.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -877,15 +877,17 @@ int xe_device_probe(struct xe_device *xe)
877877

878878
err = xe_pxp_init(xe);
879879
if (err)
880-
goto err_fini_display;
880+
goto err_remove_display;
881881

882882
err = drm_dev_register(&xe->drm, 0);
883883
if (err)
884-
goto err_fini_display;
884+
goto err_remove_display;
885885

886886
xe_display_register(xe);
887887

888-
xe_oa_register(xe);
888+
err = xe_oa_register(xe);
889+
if (err)
890+
goto err_unregister_display;
889891

890892
xe_pmu_register(&xe->pmu);
891893

@@ -902,7 +904,9 @@ int xe_device_probe(struct xe_device *xe)
902904

903905
return devm_add_action_or_reset(xe->drm.dev, xe_device_sanitize, xe);
904906

905-
err_fini_display:
907+
err_unregister_display:
908+
xe_display_unregister(xe);
909+
err_remove_display:
906910
xe_display_driver_remove(xe);
907911

908912
return err;
@@ -971,8 +975,6 @@ void xe_device_remove(struct xe_device *xe)
971975

972976
xe_display_driver_remove(xe);
973977

974-
xe_oa_unregister(xe);
975-
976978
xe_heci_gsc_fini(xe);
977979

978980
xe_device_call_remove_actions(xe);

drivers/gpu/drm/xe/xe_oa.c

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2423,36 +2423,36 @@ int xe_oa_remove_config_ioctl(struct drm_device *dev, u64 data, struct drm_file
24232423
return ret;
24242424
}
24252425

2426+
static void xe_oa_unregister(void *arg)
2427+
{
2428+
struct xe_oa *oa = arg;
2429+
2430+
if (!oa->metrics_kobj)
2431+
return;
2432+
2433+
kobject_put(oa->metrics_kobj);
2434+
oa->metrics_kobj = NULL;
2435+
}
2436+
24262437
/**
24272438
* xe_oa_register - Xe OA registration
24282439
* @xe: @xe_device
24292440
*
24302441
* Exposes the metrics sysfs directory upon completion of module initialization
24312442
*/
2432-
void xe_oa_register(struct xe_device *xe)
2443+
int xe_oa_register(struct xe_device *xe)
24332444
{
24342445
struct xe_oa *oa = &xe->oa;
24352446

24362447
if (!oa->xe)
2437-
return;
2448+
return 0;
24382449

24392450
oa->metrics_kobj = kobject_create_and_add("metrics",
24402451
&xe->drm.primary->kdev->kobj);
2441-
}
2442-
2443-
/**
2444-
* xe_oa_unregister - Xe OA de-registration
2445-
* @xe: @xe_device
2446-
*/
2447-
void xe_oa_unregister(struct xe_device *xe)
2448-
{
2449-
struct xe_oa *oa = &xe->oa;
2450-
24512452
if (!oa->metrics_kobj)
2452-
return;
2453+
return -ENOMEM;
24532454

2454-
kobject_put(oa->metrics_kobj);
2455-
oa->metrics_kobj = NULL;
2455+
return devm_add_action_or_reset(xe->drm.dev, xe_oa_unregister, oa);
24562456
}
24572457

24582458
static u32 num_oa_units_per_gt(struct xe_gt *gt)

drivers/gpu/drm/xe/xe_oa.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ struct xe_gt;
1515
struct xe_hw_engine;
1616

1717
int xe_oa_init(struct xe_device *xe);
18-
void xe_oa_register(struct xe_device *xe);
19-
void xe_oa_unregister(struct xe_device *xe);
18+
int xe_oa_register(struct xe_device *xe);
2019
int xe_oa_stream_open_ioctl(struct drm_device *dev, u64 data, struct drm_file *file);
2120
int xe_oa_add_config_ioctl(struct drm_device *dev, u64 data, struct drm_file *file);
2221
int xe_oa_remove_config_ioctl(struct drm_device *dev, u64 data, struct drm_file *file);

0 commit comments

Comments
 (0)