From patchwork Sat Mar 26 18:18:26 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mariusz Kozlowski X-Patchwork-Id: 665921 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id p2QIJ23v001038 for ; Sat, 26 Mar 2011 18:19:03 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752208Ab1CZSSk (ORCPT ); Sat, 26 Mar 2011 14:18:40 -0400 Received: from unix.wroclaw.pl ([94.23.28.62]:41529 "EHLO unix.wroclaw.pl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751840Ab1CZSSj (ORCPT ); Sat, 26 Mar 2011 14:18:39 -0400 Received: from dynamic-78-8-223-146.ssp.dialog.net.pl ([78.8.223.146]:36686 helo=localhost.localdomain) by unix.wroclaw.pl with esmtpsa (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.69) (envelope-from ) id 1Q3Y4G-0007JM-Su; Sat, 26 Mar 2011 19:18:33 +0100 From: Mariusz Kozlowski To: Len Brown Cc: Kyle McMartin , linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, Mariusz Kozlowski Subject: [PATCH] ACPI battery: fix possible use after free in acpi_battery_add() Date: Sat, 26 Mar 2011 19:18:26 +0100 Message-Id: <1301163506-7236-1-git-send-email-mk@lab.zgora.pl> X-Mailer: git-send-email 1.7.0.4 X-SA-Report: SpamAssassin 3.2.5 (2008-06-10) on unix.wroclaw.pl Spam=No score=-1.4 bayes=0.5 autolearn=disabled Spam Tests: * -1.4 ALL_TRUSTED Passed through trusted hosts only via SMTP 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]); Sat, 26 Mar 2011 18:19:03 +0000 (UTC) diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c index fcc13ac..27375e7 100644 --- a/drivers/acpi/battery.c +++ b/drivers/acpi/battery.c @@ -978,18 +978,15 @@ static int acpi_battery_add(struct acpi_device *device) acpi_battery_update(battery); #ifdef CONFIG_ACPI_PROCFS_POWER result = acpi_battery_add_fs(device); -#endif - if (!result) { - printk(KERN_INFO PREFIX "%s Slot [%s] (battery %s)\n", - ACPI_BATTERY_DEVICE_NAME, acpi_device_bid(device), - device->status.battery_present ? "present" : "absent"); - } else { -#ifdef CONFIG_ACPI_PROCFS_POWER + if (result) { acpi_battery_remove_fs(device); -#endif kfree(battery); + return result; } - +#endif + printk(KERN_INFO PREFIX "%s Slot [%s] (battery %s)\n", + ACPI_BATTERY_DEVICE_NAME, acpi_device_bid(device), + device->status.battery_present ? "present" : "absent"); battery->pm_nb.notifier_call = battery_notify; register_pm_notifier(&battery->pm_nb);