Skip to content

Commit 041142d

Browse files
jwrdegoederafaeljw
authored andcommitted
ACPI: platform-profile: Fix possible deadlock in platform_profile_remove()
After a rmmod thinkpad_acpi, lockdep pointed out this possible deadlock: Our _show and _store sysfs attr functions get called with the kn->active lock held for the sysfs attr and then take the profile_lock. sysfs_remove_group() also takes the kn->active lock for the sysfs attr, so if we call it with the profile_lock held, then we get an ABBA deadlock. platform_profile_remove() must only be called by drivers which have first *successfully* called platform_profile_register(). Anything else is a driver bug. So the check for cur_profile being set before calling sysfs_remove_group() is not necessary and it can be dropped. It is safe to call sysfs_remove_group() without holding the profile_lock since the attr-group group cannot be re-added until after we clear cur_profile. Change platform_profile_remove() to only hold the profile_lock while clearing the cur_profile, fixing the deadlock. Signed-off-by: Hans de Goede <hdegoede@redhat.com> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
1 parent 84f9017 commit 041142d

File tree

1 file changed

+2
-6
lines changed

1 file changed

+2
-6
lines changed

drivers/acpi/platform_profile.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -164,13 +164,9 @@ EXPORT_SYMBOL_GPL(platform_profile_register);
164164

165165
int platform_profile_remove(void)
166166
{
167-
mutex_lock(&profile_lock);
168-
if (!cur_profile) {
169-
mutex_unlock(&profile_lock);
170-
return -ENODEV;
171-
}
172-
173167
sysfs_remove_group(acpi_kobj, &platform_profile_group);
168+
169+
mutex_lock(&profile_lock);
174170
cur_profile = NULL;
175171
mutex_unlock(&profile_lock);
176172
return 0;

0 commit comments

Comments
 (0)