Re: [PATCH] Battery: sysfs_remove_battery(): possible circularlocking
From: lan,Tianyu
Date: Fri Aug 05 2011 - 01:11:58 EST
I think changing 'the marker' to 'battery->bat.name' will introduce
problem.
In the sysfs_add_battery(), when the 'battery->bat.name' is assigned,
the power_supply_register() and device_create_file() have not been
invoked. In this time, maybe sysfs_remove_battery() will be invoked and
cause device_remove_file() and power_supply_unregister() invoked without
device file created and power supply registered.
sysfs_remove_battery() will be invoked in the battery_notify(),
acpi_battery_refresh() and sysfs_remove_battery() which causes the
situation. This is also the cause of bug 35642.
> I've changed `the marker' from `battery->bat.dev' to `battery->bat.name', so
> the basic idea should remain the same, now we just can release battery->lock
> more quicker, before device_remove_file() call.
>
> Signed-off-by: Sergey Senozhatsky <sergey.senozhatsky@xxxxxxxxx>
>
> ---
>
> drivers/acpi/battery.c | 6 ++++--
> 1 files changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c
> index 87c0a8d..398cbfb 100644
> --- a/drivers/acpi/battery.c
> +++ b/drivers/acpi/battery.c
> @@ -574,15 +574,17 @@ static int sysfs_add_battery(struct acpi_battery *battery)
> static void sysfs_remove_battery(struct acpi_battery *battery)
> {
> mutex_lock(&battery->lock);
> - if (!battery->bat.dev) {
> + if (!battery->bat.name) {
> mutex_unlock(&battery->lock);
> return;
> }
>
> + battery->bat.name = NULL;
> + mutex_unlock(&battery->lock);
> +
> device_remove_file(battery->bat.dev, &alarm_attr);
> power_supply_unregister(&battery->bat);
> battery->bat.dev = NULL;
> - mutex_unlock(&battery->lock);
> }
>
> /*
>
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/