@@ -387,6 +387,7 @@ EXPORT_SYMBOL(acpi_bus_power_manageable);
387387
388388#ifdef CONFIG_PM
389389static DEFINE_MUTEX (acpi_pm_notifier_lock );
390+ static DEFINE_MUTEX (acpi_pm_notifier_install_lock );
390391
391392void acpi_pm_wakeup_event (struct device * dev )
392393{
@@ -443,24 +444,25 @@ acpi_status acpi_add_pm_notifier(struct acpi_device *adev, struct device *dev,
443444 if (!dev && !func )
444445 return AE_BAD_PARAMETER ;
445446
446- mutex_lock (& acpi_pm_notifier_lock );
447+ mutex_lock (& acpi_pm_notifier_install_lock );
447448
448449 if (adev -> wakeup .flags .notifier_present )
449450 goto out ;
450451
451- adev -> wakeup .ws = wakeup_source_register (dev_name (& adev -> dev ));
452- adev -> wakeup .context .dev = dev ;
453- adev -> wakeup .context .func = func ;
454-
455452 status = acpi_install_notify_handler (adev -> handle , ACPI_SYSTEM_NOTIFY ,
456453 acpi_pm_notify_handler , NULL );
457454 if (ACPI_FAILURE (status ))
458455 goto out ;
459456
457+ mutex_lock (& acpi_pm_notifier_lock );
458+ adev -> wakeup .ws = wakeup_source_register (dev_name (& adev -> dev ));
459+ adev -> wakeup .context .dev = dev ;
460+ adev -> wakeup .context .func = func ;
460461 adev -> wakeup .flags .notifier_present = true;
462+ mutex_unlock (& acpi_pm_notifier_lock );
461463
462464 out :
463- mutex_unlock (& acpi_pm_notifier_lock );
465+ mutex_unlock (& acpi_pm_notifier_install_lock );
464466 return status ;
465467}
466468
@@ -472,7 +474,7 @@ acpi_status acpi_remove_pm_notifier(struct acpi_device *adev)
472474{
473475 acpi_status status = AE_BAD_PARAMETER ;
474476
475- mutex_lock (& acpi_pm_notifier_lock );
477+ mutex_lock (& acpi_pm_notifier_install_lock );
476478
477479 if (!adev -> wakeup .flags .notifier_present )
478480 goto out ;
@@ -483,14 +485,15 @@ acpi_status acpi_remove_pm_notifier(struct acpi_device *adev)
483485 if (ACPI_FAILURE (status ))
484486 goto out ;
485487
488+ mutex_lock (& acpi_pm_notifier_lock );
486489 adev -> wakeup .context .func = NULL ;
487490 adev -> wakeup .context .dev = NULL ;
488491 wakeup_source_unregister (adev -> wakeup .ws );
489-
490492 adev -> wakeup .flags .notifier_present = false;
493+ mutex_unlock (& acpi_pm_notifier_lock );
491494
492495 out :
493- mutex_unlock (& acpi_pm_notifier_lock );
496+ mutex_unlock (& acpi_pm_notifier_install_lock );
494497 return status ;
495498}
496499
0 commit comments