From: "lan,Tianyu" <tianyu.lan@intel.com>
To: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
Cc: Len Brown <lenb@kernel.org>,
"linux-acpi@vger.kernel.org" <linux-acpi@vger.kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] Battery: sysfs_remove_battery(): possible circular locking
Date: Fri, 05 Aug 2011 13:10:08 +0800 [thread overview]
Message-ID: <1312521008.2096.173.camel@lantianyu-ws> (raw)
In-Reply-To: <20110805003322.GA8311@swordfish>
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@gmail.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);
> }
>
> /*
>
next prev parent reply other threads:[~2011-08-05 5:11 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-08-05 0:33 Sergey Senozhatsky
2011-08-05 5:10 ` lan,Tianyu [this message]
2011-08-05 7:20 ` Sergey Senozhatsky
2011-08-05 16:39 ` Sergey Senozhatsky
2011-08-05 17:07 ` Lan, Tianyu
2011-08-05 22:34 ` Sergey Senozhatsky
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1312521008.2096.173.camel@lantianyu-ws \
--to=tianyu.lan@intel.com \
--cc=lenb@kernel.org \
--cc=linux-acpi@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=sergey.senozhatsky@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®