From patchwork Sun May 10 17:57:46 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Jenkins X-Patchwork-Id: 22808 Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id n4AHwD9P016889 for ; Sun, 10 May 2009 17:58:13 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752315AbZEJR6K (ORCPT ); Sun, 10 May 2009 13:58:10 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1753780AbZEJR6K (ORCPT ); Sun, 10 May 2009 13:58:10 -0400 Received: from mail-ew0-f176.google.com ([209.85.219.176]:42640 "EHLO mail-ew0-f176.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752333AbZEJR6J (ORCPT ); Sun, 10 May 2009 13:58:09 -0400 Received: by ewy24 with SMTP id 24so2978619ewy.37 for ; Sun, 10 May 2009 10:58:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=gamma; h=domainkey-signature:received:received:sender:message-id:date:from :user-agent:mime-version:to:cc:subject:content-type :content-transfer-encoding; bh=RfYYJ+92LTThWh1Sh6EjvdpxUD7oaCucBx1YT1OLhSU=; b=RJsHH9rJA+UzapBcTJXsxiVcJDienVr5yTOiPHc6++6Rp3kMLzxXMzPrW3zBgXWhef XJDrtAOayOce6cghlM+/hGu6Yc4rGwQUbWj1dkU/nZjJkJsVpKAq3rpIkiPr/BK8kbU4 ZAf18+F+ndDnN3mJ/Ur8DxvSxOxDVynaef+tQ= DomainKey-Signature: a=rsa-sha1; c=nofws; d=googlemail.com; s=gamma; h=sender:message-id:date:from:user-agent:mime-version:to:cc:subject :content-type:content-transfer-encoding; b=ZZSNozovVwS0khwkUxEtYzRHlFAo4DTkrH9mZ8CloM4kcXk6xy3y54/Yv9CQZanfkf UhPHWtNsiZaOleXOJ08fWCVHVHYIInlaeh7St0qIC4hbxbRB7UVSApfjXiMVFkOQ18/X ZSidYmmm6rbVrVA/ke8DZNGO9TA8mzfUyupDY= Received: by 10.216.25.209 with SMTP id z59mr2894773wez.204.1241978288894; Sun, 10 May 2009 10:58:08 -0700 (PDT) Received: from ?192.168.0.2? ([86.53.68.233]) by mx.google.com with ESMTPS id 10sm6118212eyd.12.2009.05.10.10.58.07 (version=SSLv3 cipher=RC4-MD5); Sun, 10 May 2009 10:58:08 -0700 (PDT) Message-ID: <4A07159A.9010006@tuffmail.co.uk> Date: Sun, 10 May 2009 18:57:46 +0100 From: Alan Jenkins User-Agent: Thunderbird 2.0.0.21 (X11/20090409) MIME-Version: 1.0 To: Alexey Starikovskiy CC: linux acpi Subject: [RFC] ACPI battery driver: odd usage of generic power supply class on battery removal Sender: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org Hi, The ACPI battery driver does something strange with the generic power supply class, when the battery is removed from my laptop. Instead of clearing the "present" attribute of the class device, it removes the entire class device. Can this be corrected, or is there a specific reason for it? Patch follows for illustration purposes. If this can be changed, I'd also try to cleanup acpi_battery_update(). I don't think it's right that CONFIG_ACPI_SYSFS_POWER affects the control flow. When it's disabled, acpi_battery_present() is not tested before calling acpi_battery_get_state(). It might not cause any problems, but it is evil. --- To unsubscribe from this list: send the line "unsubscribe linux-acpi" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c index 69cbc57..050444a 100644 --- a/drivers/acpi/battery.c +++ b/drivers/acpi/battery.c @@ -482,6 +482,11 @@ static int sysfs_add_battery(struct acpi_battery *battery) return device_create_file(battery->bat.dev, &alarm_attr); } +static void sysfs_update_battery(struct acpi_battery *battery) +{ + power_supply_changed(&battery->bat); +} + static void sysfs_remove_battery(struct acpi_battery *battery) { if (!battery->bat.dev) @@ -500,7 +505,7 @@ static int acpi_battery_update(struct acpi_battery *battery) return result; #ifdef CONFIG_ACPI_SYSFS_POWER if (!acpi_battery_present(battery)) { - sysfs_remove_battery(battery); + sysfs_update_battery(battery); battery->update_time = 0; return 0; } @@ -513,8 +518,7 @@ static int acpi_battery_update(struct acpi_battery *battery) acpi_battery_init_alarm(battery); } #ifdef CONFIG_ACPI_SYSFS_POWER - if (!battery->bat.dev) - sysfs_add_battery(battery); + sysfs_update_battery(battery); #endif return acpi_battery_get_state(battery); }