Skip to content

Commit

Permalink
ACPI / Battery: Resolve the race condition in the sysfs_remove_battery()
Browse files Browse the repository at this point in the history
Use battery->lock in sysfs_remove_battery() to make
checking, removing, and clearing bat.dev atomic.
This is necessary because sysfs_remove_battery() may
be invoked concurrently from different paths.

    https://bugzilla.kernel.org/show_bug.cgi?id=35642

Signed-off-by: Lan Tianyu <tianyu.lan@intel.com>
Signed-off-by: Len Brown <len.brown@intel.com>
  • Loading branch information
Lan Tianyu authored and Len Brown committed Jul 14, 2011
1 parent 6e17fb6 commit 9c921c2
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion drivers/acpi/battery.c
Original file line number Diff line number Diff line change
Expand Up @@ -573,11 +573,16 @@ static int sysfs_add_battery(struct acpi_battery *battery)

static void sysfs_remove_battery(struct acpi_battery *battery)
{
if (!battery->bat.dev)
mutex_lock(&battery->lock);
if (!battery->bat.dev) {
mutex_unlock(&battery->lock);
return;
}

device_remove_file(battery->bat.dev, &alarm_attr);
power_supply_unregister(&battery->bat);
battery->bat.dev = NULL;
mutex_unlock(&battery->lock);
}

/*
Expand Down

0 comments on commit 9c921c2

Please sign in to comment.