From patchwork Tue Oct 9 05:54:06 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Len Brown X-Patchwork-Id: 1568521 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 423AC3FE80 for ; Tue, 9 Oct 2012 06:08:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753668Ab2JIGId (ORCPT ); Tue, 9 Oct 2012 02:08:33 -0400 Received: from mail-qc0-f174.google.com ([209.85.216.174]:38957 "EHLO mail-qc0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752252Ab2JIGDL (ORCPT ); Tue, 9 Oct 2012 02:03:11 -0400 Received: by mail-qc0-f174.google.com with SMTP id d3so3587711qch.19 for ; Mon, 08 Oct 2012 23:03:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references:in-reply-to:references:reply-to:organization; bh=xMlZ99UmmsYQEjEnRjG547YBYlO80XVvqzEhfAeMC9A=; b=XzOD5iAETw6XV414Zr7ctw/zRyC/NBZzWhUqta08ykZM5s8C0mLpWnzwzzKzpXt60p K5Z33AQ1rpR7b4IzRitSu1fcnCJJB+nNQgMAUL0KAImrdxPfVVlfH5GHZ4j/hhaM0OW+ CZcMItArvMdNPvJuPlyg/dMQeWsmTrz5NA2tqwgbjl6u2CMQpFNALKiwIfi+dMooMUCQ OmIcPgqNIKEqzNPI354KCEiMgB/i3kqxGxTjLOY197jfJhlobHh4tuPvP1qMkmas/YIl F83FheMPWgR9MpMCQjMrPFGMYPSZ8T6WjuRXlciS1Pw19+cNyjloCtKJS2i9tFHQLNbb MaCA== Received: by 10.229.105.212 with SMTP id u20mr2882001qco.67.1349762591440; Mon, 08 Oct 2012 23:03:11 -0700 (PDT) Received: from x980.localdomain6 (pool-74-104-146-186.bstnma.fios.verizon.net. [74.104.146.186]) by mx.google.com with ESMTPS id ck11sm20206037qab.17.2012.10.08.23.03.09 (version=SSLv3 cipher=OTHER); Mon, 08 Oct 2012 23:03:10 -0700 (PDT) From: Len Brown To: linux-acpi@vger.kernel.org, linux-pm@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Guenter Roeck , Zhang Rui Subject: [PATCH 16/30] thermal: Fix potential NULL pointer accesses Date: Tue, 9 Oct 2012 01:54:06 -0400 Message-Id: <204dd1d39c32f39a95bf7a7248f63b372fd137a6.1349761836.git.len.brown@intel.com> X-Mailer: git-send-email 1.8.0.rc1 In-Reply-To: <1349762060-25334-1-git-send-email-lenb@kernel.org> References: <1349762060-25334-1-git-send-email-lenb@kernel.org> In-Reply-To: References: Reply-To: Len Brown Organization: Intel Open Source Technology Center Sender: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org From: Guenter Roeck The type parameter in thermal_zone_device_register and thermal_cooling_device_register can be NULL, indicating that no sysfs attribute for the type should be created. Only call strlen() and strcpy() on type if it is not NULL. This patch addresses Coverity #102180 and #102182: Dereference before null check Signed-off-by: Guenter Roeck Signed-off-by: Zhang Rui --- drivers/thermal/thermal_sys.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/thermal/thermal_sys.c b/drivers/thermal/thermal_sys.c index 36e6f4d..47498b8 100644 --- a/drivers/thermal/thermal_sys.c +++ b/drivers/thermal/thermal_sys.c @@ -901,7 +901,7 @@ thermal_cooling_device_register(char *type, void *devdata, struct thermal_zone_device *pos; int result; - if (strlen(type) >= THERMAL_NAME_LENGTH) + if (type && strlen(type) >= THERMAL_NAME_LENGTH) return ERR_PTR(-EINVAL); if (!ops || !ops->get_max_state || !ops->get_cur_state || @@ -918,7 +918,7 @@ thermal_cooling_device_register(char *type, void *devdata, return ERR_PTR(result); } - strcpy(cdev->type, type); + strcpy(cdev->type, type ? : ""); mutex_init(&cdev->lock); INIT_LIST_HEAD(&cdev->thermal_instances); cdev->ops = ops; @@ -1344,7 +1344,7 @@ struct thermal_zone_device *thermal_zone_device_register(const char *type, int count; int passive = 0; - if (strlen(type) >= THERMAL_NAME_LENGTH) + if (type && strlen(type) >= THERMAL_NAME_LENGTH) return ERR_PTR(-EINVAL); if (trips > THERMAL_MAX_TRIPS || trips < 0 || mask >> trips) @@ -1366,7 +1366,7 @@ struct thermal_zone_device *thermal_zone_device_register(const char *type, return ERR_PTR(result); } - strcpy(tz->type, type); + strcpy(tz->type, type ? : ""); tz->ops = ops; tz->device.class = &thermal_class; tz->devdata = devdata;