From patchwork Mon Sep 14 07:50:08 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Jenkins X-Patchwork-Id: 47235 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 n8E7oDuR014755 for ; Mon, 14 Sep 2009 07:50:13 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750749AbZINHuI (ORCPT ); Mon, 14 Sep 2009 03:50:08 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1751192AbZINHuI (ORCPT ); Mon, 14 Sep 2009 03:50:08 -0400 Received: from mail-fx0-f217.google.com ([209.85.220.217]:54873 "EHLO mail-fx0-f217.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750749AbZINHuH (ORCPT ); Mon, 14 Sep 2009 03:50:07 -0400 Received: by fxm17 with SMTP id 17so647099fxm.37 for ; Mon, 14 Sep 2009 00:50:10 -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=tHRrDr7jhE3xhy5HZ6U8jNKp0yg8oytS3NnT2p5cRDI=; b=IVTlixcl13FiKJ7lmOiH0anWCn1e44b4x9/iANVMA2vDLHeww8StmbwVLIBldL+Prg RYUmM4S7hjl9jdtlyMVHhpiGgdgzInNJguYxMqpVigmC5CSXkm1/azmD3d0NtbbsdDv6 WR7WHVozyt6cV8YjMyueoLaprXoccsNyEMwlo= 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=O/QXMvsl1RZjQDc3g5irB/dkQAWnc5adQ7oacWTpbm/8CkRpgFTy1F1GOWGXN82OUQ OcX/srIsLOsnz5T1YwOheKTqjZIKY4FUKGtZM5tCK9IfnoTuNS2p6nfZy3DkxPfEYZPh XgaLoGcQUnLt9hsl3MatXHeOWC8P7+CWNuv3E= Received: by 10.204.34.70 with SMTP id k6mr4858667bkd.178.1252914609993; Mon, 14 Sep 2009 00:50:09 -0700 (PDT) Received: from ?192.168.0.5? ([86.53.68.233]) by mx.google.com with ESMTPS id 22sm996783fkq.52.2009.09.14.00.50.08 (version=SSLv3 cipher=RC4-MD5); Mon, 14 Sep 2009 00:50:09 -0700 (PDT) Message-ID: <4AADF5B0.1040400@tuffmail.co.uk> Date: Mon, 14 Sep 2009 08:50:08 +0100 From: Alan Jenkins User-Agent: Thunderbird 2.0.0.21 (X11/20090318) MIME-Version: 1.0 To: Zhao Yakui CC: Zhang Rui , linux acpi Subject: [PATCHv2] ACPI fan: fix memleak on acpi_fan_add_fs() failure Sender: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org Signed-off-by: Alan Jenkins --- v2: Only remove sysfs links when the function fails. drivers/acpi/fan.c | 20 ++++++++++++-------- 1 files changed, 12 insertions(+), 8 deletions(-) diff --git a/drivers/acpi/fan.c b/drivers/acpi/fan.c index 947556e..6b110c7 100644 --- a/drivers/acpi/fan.c +++ b/drivers/acpi/fan.c @@ -249,8 +249,8 @@ static int acpi_fan_add(struct acpi_device *device) result = acpi_bus_get_power(device->handle, &state); if (result) { - printk(KERN_ERR PREFIX "Reading power state\n"); - goto end; + printk(KERN_ERR PREFIX "Error reading power state\n"); + return result; } device->flags.force_power_state = 1; @@ -259,10 +259,8 @@ static int acpi_fan_add(struct acpi_device *device) cdev = thermal_cooling_device_register("Fan", device, &fan_cooling_ops); - if (IS_ERR(cdev)) { - result = PTR_ERR(cdev); - goto end; - } + if (IS_ERR(cdev)) + return PTR_ERR(cdev); dev_info(&device->dev, "registered as cooling_device%d\n", cdev->id); @@ -283,13 +281,19 @@ static int acpi_fan_add(struct acpi_device *device) result = acpi_fan_add_fs(device); if (result) - goto end; + goto err_unregister; printk(KERN_INFO PREFIX "%s [%s] (%s)\n", acpi_device_name(device), acpi_device_bid(device), !device->power.state ? "on" : "off"); - end: + return 0; + +err_unregister: + sysfs_remove_link(&device->dev.kobj, "thermal_cooling"); + sysfs_remove_link(&cdev->device.kobj, "device"); + thermal_cooling_device_unregister(cdev); + return result; }