@@ -190,6 +190,20 @@ static ssize_t profile_show(struct device *dev,
190190 return sysfs_emit (buf , "%s\n" , profile_names [profile ]);
191191}
192192
193+ /**
194+ * profile_notify_legacy - Notify the legacy sysfs interface
195+ *
196+ * This wrapper takes care of only notifying the legacy sysfs interface
197+ * if it was registered during module initialization.
198+ */
199+ static void profile_notify_legacy (void )
200+ {
201+ if (!acpi_kobj )
202+ return ;
203+
204+ sysfs_notify (acpi_kobj , NULL , "platform_profile" );
205+ }
206+
193207/**
194208 * profile_store - Set the profile for a class device
195209 * @dev: The device
@@ -215,7 +229,7 @@ static ssize_t profile_store(struct device *dev,
215229 return ret ;
216230 }
217231
218- sysfs_notify ( acpi_kobj , NULL , "platform_profile" );
232+ profile_notify_legacy ( );
219233
220234 return count ;
221235}
@@ -435,7 +449,7 @@ static ssize_t platform_profile_store(struct kobject *kobj,
435449 return ret ;
436450 }
437451
438- sysfs_notify ( acpi_kobj , NULL , "platform_profile" );
452+ profile_notify_legacy ( );
439453
440454 return count ;
441455}
@@ -472,6 +486,22 @@ static const struct attribute_group platform_profile_group = {
472486 .is_visible = profile_class_is_visible ,
473487};
474488
489+ /**
490+ * profile_update_legacy - Update the legacy sysfs interface
491+ *
492+ * This wrapper takes care of only updating the legacy sysfs interface
493+ * if it was registered during module initialization.
494+ *
495+ * Return: 0 on success or error code on failure.
496+ */
497+ static int profile_update_legacy (void )
498+ {
499+ if (!acpi_kobj )
500+ return 0 ;
501+
502+ return sysfs_update_group (acpi_kobj , & platform_profile_group );
503+ }
504+
475505/**
476506 * platform_profile_notify - Notify class device and legacy sysfs interface
477507 * @dev: The class device
@@ -481,7 +511,7 @@ void platform_profile_notify(struct device *dev)
481511 scoped_cond_guard (mutex_intr , return , & profile_lock ) {
482512 _notify_class_profile (dev , NULL );
483513 }
484- sysfs_notify ( acpi_kobj , NULL , "platform_profile" );
514+ profile_notify_legacy ( );
485515}
486516EXPORT_SYMBOL_GPL (platform_profile_notify );
487517
@@ -529,7 +559,7 @@ int platform_profile_cycle(void)
529559 return err ;
530560 }
531561
532- sysfs_notify ( acpi_kobj , NULL , "platform_profile" );
562+ profile_notify_legacy ( );
533563
534564 return 0 ;
535565}
@@ -603,9 +633,9 @@ struct device *platform_profile_register(struct device *dev, const char *name,
603633 goto cleanup_ida ;
604634 }
605635
606- sysfs_notify ( acpi_kobj , NULL , "platform_profile" );
636+ profile_notify_legacy ( );
607637
608- err = sysfs_update_group ( acpi_kobj , & platform_profile_group );
638+ err = profile_update_legacy ( );
609639 if (err )
610640 goto cleanup_cur ;
611641
@@ -639,8 +669,8 @@ void platform_profile_remove(struct device *dev)
639669 ida_free (& platform_profile_ida , pprof -> minor );
640670 device_unregister (& pprof -> dev );
641671
642- sysfs_notify ( acpi_kobj , NULL , "platform_profile" );
643- sysfs_update_group ( acpi_kobj , & platform_profile_group );
672+ profile_notify_legacy ( );
673+ profile_update_legacy ( );
644674}
645675EXPORT_SYMBOL_GPL (platform_profile_remove );
646676
@@ -695,16 +725,28 @@ static int __init platform_profile_init(void)
695725 if (err )
696726 return err ;
697727
698- err = sysfs_create_group (acpi_kobj , & platform_profile_group );
699- if (err )
700- class_unregister (& platform_profile_class );
728+ /*
729+ * The ACPI kobject can be missing if ACPI was disabled during booting.
730+ * We thus skip the initialization of the legacy sysfs interface in such
731+ * cases to allow the platform profile class to work on ARM64 notebooks
732+ * without ACPI support.
733+ */
734+ if (acpi_kobj ) {
735+ err = sysfs_create_group (acpi_kobj , & platform_profile_group );
736+ if (err < 0 ) {
737+ class_unregister (& platform_profile_class );
738+ return err ;
739+ }
740+ }
701741
702- return err ;
742+ return 0 ;
703743}
704744
705745static void __exit platform_profile_exit (void )
706746{
707- sysfs_remove_group (acpi_kobj , & platform_profile_group );
747+ if (acpi_kobj )
748+ sysfs_remove_group (acpi_kobj , & platform_profile_group );
749+
708750 class_unregister (& platform_profile_class );
709751}
710752module_init (platform_profile_init );
0 commit comments