From patchwork Mon Mar 25 10:50:05 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Colin King X-Patchwork-Id: 2330411 Return-Path: X-Original-To: patchwork-linux-acpi@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork1.kernel.org (Postfix) with ESMTP id 6B0A93FC54 for ; Mon, 25 Mar 2013 10:50:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756226Ab3CYKuO (ORCPT ); Mon, 25 Mar 2013 06:50:14 -0400 Received: from youngberry.canonical.com ([91.189.89.112]:45572 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755484Ab3CYKuN (ORCPT ); Mon, 25 Mar 2013 06:50:13 -0400 Received: from cpc3-craw6-2-0-cust180.croy.cable.virginmedia.com ([77.100.248.181] helo=localhost) by youngberry.canonical.com with esmtpsa (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1UK4yd-00044U-Kb; Mon, 25 Mar 2013 10:50:07 +0000 From: Colin King To: Zhang Rui , Len Brown , "Rafael J. Wysocki" , linux-acpi@vger.kernel.org Subject: [PATCH 1/2] ACPI / fan: avoid null pointer deference error Date: Mon, 25 Mar 2013 10:50:05 +0000 Message-Id: <1364208606-8446-2-git-send-email-colin.king@canonical.com> X-Mailer: git-send-email 1.8.1.2 In-Reply-To: <1364208606-8446-1-git-send-email-colin.king@canonical.com> References: <1364208606-8446-1-git-send-email-colin.king@canonical.com> Sender: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org From: Colin Ian King Fix a null pointer deference by acpi_driver_data() if device is null. We should only set cdev and check this is OK after we are sure device is not null. Smatch analysis: drivers/acpi/fan.c:179 acpi_fan_remove() warn: variable dereferenced before check 'device' (see line 177) Signed-off-by: Colin Ian King --- drivers/acpi/fan.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/drivers/acpi/fan.c b/drivers/acpi/fan.c index f815da8..8d1c010 100644 --- a/drivers/acpi/fan.c +++ b/drivers/acpi/fan.c @@ -174,9 +174,13 @@ static int acpi_fan_add(struct acpi_device *device) static int acpi_fan_remove(struct acpi_device *device) { - struct thermal_cooling_device *cdev = acpi_driver_data(device); + struct thermal_cooling_device *cdev; + + if (!device) + return -EINVAL; - if (!device || !cdev) + cdev = acpi_driver_data(device); + if (!cdev) return -EINVAL; sysfs_remove_link(&device->dev.kobj, "thermal_cooling");