[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <1312521008.2096.173.camel@lantianyu-ws>
Date: Fri, 05 Aug 2011 13:10:08 +0800
From: "lan,Tianyu" <tianyu.lan@...el.com>
To: Sergey Senozhatsky <sergey.senozhatsky@...il.com>
Cc: Len Brown <lenb@...nel.org>,
"linux-acpi@...r.kernel.org" <linux-acpi@...r.kernel.org>,
"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH] Battery: sysfs_remove_battery(): possible circular
locking
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@...il.com>
>
> ---
>
> 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@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists