@@ -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}
@@ -437,7 +451,7 @@ static ssize_t platform_profile_store(struct kobject *kobj,
437451 return ret ;
438452 }
439453
440- sysfs_notify ( acpi_kobj , NULL , "platform_profile" );
454+ profile_notify_legacy ( );
441455
442456 return count ;
443457}
@@ -474,6 +488,22 @@ static const struct attribute_group platform_profile_group = {
474488 .is_visible = profile_class_is_visible ,
475489};
476490
491+ /**
492+ * profile_update_legacy - Update the legacy sysfs interface
493+ *
494+ * This wrapper takes care of only updating the legacy sysfs interface
495+ * if it was registered during module initialization.
496+ *
497+ * Return: 0 on success or error code on failure.
498+ */
499+ static int profile_update_legacy (void )
500+ {
501+ if (!acpi_kobj )
502+ return 0 ;
503+
504+ return sysfs_update_group (acpi_kobj , & platform_profile_group );
505+ }
506+
477507/**
478508 * platform_profile_notify - Notify class device and legacy sysfs interface
479509 * @dev: The class device
@@ -483,7 +513,7 @@ void platform_profile_notify(struct device *dev)
483513 scoped_cond_guard (mutex_intr , return , & profile_lock ) {
484514 _notify_class_profile (dev , NULL );
485515 }
486- sysfs_notify ( acpi_kobj , NULL , "platform_profile" );
516+ profile_notify_legacy ( );
487517}
488518EXPORT_SYMBOL_GPL (platform_profile_notify );
489519
@@ -532,7 +562,7 @@ int platform_profile_cycle(void)
532562 return err ;
533563 }
534564
535- sysfs_notify ( acpi_kobj , NULL , "platform_profile" );
565+ profile_notify_legacy ( );
536566
537567 return 0 ;
538568}
@@ -606,9 +636,9 @@ struct device *platform_profile_register(struct device *dev, const char *name,
606636 goto cleanup_ida ;
607637 }
608638
609- sysfs_notify ( acpi_kobj , NULL , "platform_profile" );
639+ profile_notify_legacy ( );
610640
611- err = sysfs_update_group ( acpi_kobj , & platform_profile_group );
641+ err = profile_update_legacy ( );
612642 if (err )
613643 goto cleanup_cur ;
614644
@@ -640,9 +670,8 @@ int platform_profile_remove(struct device *dev)
640670 device_unregister (& pprof -> dev );
641671 ida_free (& platform_profile_ida , id );
642672
643- sysfs_notify (acpi_kobj , NULL , "platform_profile" );
644-
645- sysfs_update_group (acpi_kobj , & platform_profile_group );
673+ profile_notify_legacy ();
674+ profile_update_legacy ();
646675
647676 return 0 ;
648677}
@@ -696,16 +725,28 @@ static int __init platform_profile_init(void)
696725 if (err )
697726 return err ;
698727
699- err = sysfs_create_group (acpi_kobj , & platform_profile_group );
700- if (err )
701- 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+ }
702741
703- return err ;
742+ return 0 ;
704743}
705744
706745static void __exit platform_profile_exit (void )
707746{
708- sysfs_remove_group (acpi_kobj , & platform_profile_group );
747+ if (acpi_kobj )
748+ sysfs_remove_group (acpi_kobj , & platform_profile_group );
749+
709750 class_unregister (& platform_profile_class );
710751}
711752module_init (platform_profile_init );
0 commit comments