Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

+32 -31
+8 -6
drivers/gpu/drm/xe/xe_device.c
··· 877 877 878 878 err = xe_pxp_init(xe); 879 879 if (err) 880 - goto err_fini_display; 880 + goto err_remove_display; 881 881 882 882 err = drm_dev_register(&xe->drm, 0); 883 883 if (err) 884 - goto err_fini_display; 884 + goto err_remove_display; 885 885 886 886 xe_display_register(xe); 887 887 888 - xe_oa_register(xe); 888 + err = xe_oa_register(xe); 889 + if (err) 890 + goto err_unregister_display; 889 891 890 892 xe_pmu_register(&xe->pmu); 891 893 ··· 904 902 905 903 return devm_add_action_or_reset(xe->drm.dev, xe_device_sanitize, xe); 906 904 907 - err_fini_display: 905 + err_unregister_display: 906 + xe_display_unregister(xe); 907 + err_remove_display: 908 908 xe_display_driver_remove(xe); 909 909 910 910 return err; ··· 974 970 drm_dev_unplug(&xe->drm); 975 971 976 972 xe_display_driver_remove(xe); 977 - 978 - xe_oa_unregister(xe); 979 973 980 974 xe_heci_gsc_fini(xe); 981 975
+23 -23
drivers/gpu/drm/xe/xe_oa.c
··· 2423 2423 return ret; 2424 2424 } 2425 2425 2426 - /** 2427 - * xe_oa_register - Xe OA registration 2428 - * @xe: @xe_device 2429 - * 2430 - * Exposes the metrics sysfs directory upon completion of module initialization 2431 - */ 2432 - void xe_oa_register(struct xe_device *xe) 2426 + static void xe_oa_unregister(void *arg) 2433 2427 { 2434 - struct xe_oa *oa = &xe->oa; 2435 - 2436 - if (!oa->xe) 2437 - return; 2438 - 2439 - oa->metrics_kobj = kobject_create_and_add("metrics", 2440 - &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; 2428 + struct xe_oa *oa = arg; 2450 2429 2451 2430 if (!oa->metrics_kobj) 2452 2431 return; 2453 2432 2454 2433 kobject_put(oa->metrics_kobj); 2455 2434 oa->metrics_kobj = NULL; 2435 + } 2436 + 2437 + /** 2438 + * xe_oa_register - Xe OA registration 2439 + * @xe: @xe_device 2440 + * 2441 + * Exposes the metrics sysfs directory upon completion of module initialization 2442 + */ 2443 + int xe_oa_register(struct xe_device *xe) 2444 + { 2445 + struct xe_oa *oa = &xe->oa; 2446 + 2447 + if (!oa->xe) 2448 + return 0; 2449 + 2450 + oa->metrics_kobj = kobject_create_and_add("metrics", 2451 + &xe->drm.primary->kdev->kobj); 2452 + if (!oa->metrics_kobj) 2453 + return -ENOMEM; 2454 + 2455 + return devm_add_action_or_reset(xe->drm.dev, xe_oa_unregister, oa); 2456 2456 } 2457 2457 2458 2458 static u32 num_oa_units_per_gt(struct xe_gt *gt)
+1 -2
drivers/gpu/drm/xe/xe_oa.h
··· 15 15 struct xe_hw_engine; 16 16 17 17 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); 20 19 int xe_oa_stream_open_ioctl(struct drm_device *dev, u64 data, struct drm_file *file); 21 20 int xe_oa_add_config_ioctl(struct drm_device *dev, u64 data, struct drm_file *file); 22 21 int xe_oa_remove_config_ioctl(struct drm_device *dev, u64 data, struct drm_file *file);