From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754956AbcC1QSr (ORCPT ); Mon, 28 Mar 2016 12:18:47 -0400 Received: from youngberry.canonical.com ([91.189.89.112]:51053 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754002AbcC1QSo (ORCPT ); Mon, 28 Mar 2016 12:18:44 -0400 From: Colin King To: Sujith Thomas , Darren Hart , platform-driver-x86@vger.kernel.org Cc: linux-kernel@vger.kernel.org Subject: [PATCH] intel_menlow: set cdev after null device check to avoid null pointer dereference Date: Mon, 28 Mar 2016 17:18:39 +0100 Message-Id: <1459181919-13825-1-git-send-email-colin.king@canonical.com> X-Mailer: git-send-email 2.7.4 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Colin Ian King intel_menlow_memory_remove sanity checks to see if device is null, however, this check is performed after we have already passed device into a call to acpi_driver_data. If device is null, then acpi_driver_data will produce a null pointer dereference on device. The correct action is to sanity check device, then assign cdev, then check if cdev is null. Signed-off-by: Colin Ian King --- drivers/platform/x86/intel_menlow.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/drivers/platform/x86/intel_menlow.c b/drivers/platform/x86/intel_menlow.c index 0a919d8..185a1bd 100644 --- a/drivers/platform/x86/intel_menlow.c +++ b/drivers/platform/x86/intel_menlow.c @@ -196,9 +196,13 @@ static int intel_menlow_memory_add(struct acpi_device *device) static int intel_menlow_memory_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"); -- 2.7.4