@@ -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
@@ -692,16 +722,28 @@ static int __init platform_profile_init(void)
692722 if (err )
693723 return err ;
694724
695- err = sysfs_create_group (acpi_kobj , & platform_profile_group );
696- if (err )
697- class_unregister (& platform_profile_class );
725+ /*
726+ * The ACPI kobject can be missing if ACPI was disabled during booting.
727+ * We thus skip the initialization of the legacy sysfs interface in such
728+ * cases to allow the platform profile class to work on ARM64 notebooks
729+ * without ACPI support.
730+ */
731+ if (acpi_kobj ) {
732+ err = sysfs_create_group (acpi_kobj , & platform_profile_group );
733+ if (err < 0 ) {
734+ class_unregister (& platform_profile_class );
735+ return err ;
736+ }
737+ }
698738
699- return err ;
739+ return 0 ;
700740}
701741
702742static void __exit platform_profile_exit (void )
703743{
704- sysfs_remove_group (acpi_kobj , & platform_profile_group );
744+ if (acpi_kobj )
745+ sysfs_remove_group (acpi_kobj , & platform_profile_group );
746+
705747 class_unregister (& platform_profile_class );
706748}
707749module_init (platform_profile_init );
0 commit comments