From patchwork Wed Jun 29 08:25:12 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "lan,Tianyu" X-Patchwork-Id: 927612 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.4) with ESMTP id p5T8NtFh010922 for ; Wed, 29 Jun 2011 08:28:10 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753750Ab1F2IYy (ORCPT ); Wed, 29 Jun 2011 04:24:54 -0400 Received: from mga11.intel.com ([192.55.52.93]:49553 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753713Ab1F2IYy (ORCPT ); Wed, 29 Jun 2011 04:24:54 -0400 Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga102.fm.intel.com with ESMTP; 29 Jun 2011 01:24:54 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="4.65,442,1304319600"; d="scan'208";a="24178724" Received: from lantianyu-ws.sh.intel.com (HELO localhost) ([10.239.35.77]) by fmsmga001.fm.intel.com with ESMTP; 29 Jun 2011 01:24:53 -0700 From: Lan Tianyu To: lenb@kernel.org Cc: linux-acpi@vger.kernel.org, tianyu.lan@intel.com, rui.zhang@intel.com, stable@kernel.org Subject: [PATCH 6/6] ACPI / Battery: Resolve the race condition in the sysfs_remove_battery() Date: Wed, 29 Jun 2011 16:25:12 +0800 Message-Id: <1309335912-26625-1-git-send-email-tianyu.lan@intel.com> X-Mailer: git-send-email 1.7.6.rc2.8.g28eb Sender: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter1.kernel.org [140.211.167.41]); Wed, 29 Jun 2011 08:28:14 +0000 (UTC) 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 --- drivers/acpi/battery.c | 7 ++++++- 1 files changed, 6 insertions(+), 1 deletions(-) diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c index cb4a554..123adee 100644 --- a/drivers/acpi/battery.c +++ b/drivers/acpi/battery.c @@ -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); } /*