Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp1205686pxk; Mon, 31 Aug 2020 12:43:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxyJRq3OPLezyUzDtVl9VWdQ8hwjwYLf4I7Rz0N4vxxtl4NLwwxLJZydyrUXWaRxzDkaFJb X-Received: by 2002:aa7:d458:: with SMTP id q24mr2638127edr.23.1598903036795; Mon, 31 Aug 2020 12:43:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598903036; cv=none; d=google.com; s=arc-20160816; b=dndHH/Rjc2n1tSCMvbfXR577HiMybKw8DMJAiHXJQDs6csxcZDSLxYeQxYoyn4cN6Q OVb86juqOmiquLOOwud+fcBYUKk9ELdIQZcMgAGVTkxrKffiMvxRpbzgLcT5E40V31Fe MZ5W7jJVt6njyp1ef3lnWcPAWm0GrqMdBGZB2crzHPjWfMMb2p35IA/ZsHMYaD1FPbCj DLzNn/7T2qOa3ToHOa8nYHTZZH56Wzr/YZZNRMd784J7JOrLUA6ffcRDzx8+vMiZ+iTT cUS1FAMtp2j082Tea69TM6yaLwhn+m7KyBwpKDhS51tUDXaYJAmHt3qnHacMjxecctY3 otlA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=q8Mb7hlDiQlExIWbgrqvTLZBE2oTpk3pIDo6UbV4zug=; b=WlWcPtHBTJZipN9P4vV6pEAgVos6rLhakREzvcdVMqK/+biGc/I9pxWDrca2o9MWJ0 UpUY6ubVI+GZiCKrVkpPUo2CXiZG/bLgXOBB+VmTH2kpRbn7mpgRCYVSYq7ueNLwDyp3 PXw/UrZGFJOSUiLGHkJC/9HO/EDMF4qGo6dbZ4HzyaYW9v9c1QOqZjuyUHb5SYlL7jyv 8z7LXavZhge1pxS2rbpfXWmmHJDB42cJvDm3+tQfT8i96J0CAtGv9Oni3LFnDwIwjCzv E2Q+8XwOkt/tDvtjg/hob0pFK6XnYKpigEph3dBqtAqqXV8jGDfue3DxccWPId0/PZ4d P5fw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="asB7YS/N"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n6si5958960ejg.175.2020.08.31.12.43.34; Mon, 31 Aug 2020 12:43:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="asB7YS/N"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729436AbgHaPkk (ORCPT + 99 others); Mon, 31 Aug 2020 11:40:40 -0400 Received: from mail.kernel.org ([198.145.29.99]:38732 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728458AbgHaP3w (ORCPT ); Mon, 31 Aug 2020 11:29:52 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id A79BD2083E; Mon, 31 Aug 2020 15:29:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1598887791; bh=p/VXYwFUJB/kg5jcz4g7W6vjlMbDu0lvknVGLt7O638=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=asB7YS/NcUF1o0uF3XRYy1mKRbLNez5wYOna2R7j1rvB6HV2YgwZ7l6NT97YxiBJY APSJwz813oLjgWL4NyiCTYGLIe3IXkoq7Gu/LRlNYiwXnl6I3LIXo1QYqfwANuHN/C lFtInZCDqxeuZ82XbVAJIa4v9L0GTBKKi89KGZh8= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Tom Rix , Henrik Rydberg , Guenter Roeck , Sasha Levin , linux-hwmon@vger.kernel.org, clang-built-linux@googlegroups.com Subject: [PATCH AUTOSEL 5.8 10/42] hwmon: (applesmc) check status earlier. Date: Mon, 31 Aug 2020 11:29:02 -0400 Message-Id: <20200831152934.1023912-10-sashal@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200831152934.1023912-1-sashal@kernel.org> References: <20200831152934.1023912-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Tom Rix [ Upstream commit cecf7560f00a8419396a2ed0f6e5d245ccb4feac ] clang static analysis reports this representative problem applesmc.c:758:10: warning: 1st function call argument is an uninitialized value left = be16_to_cpu(*(__be16 *)(buffer + 6)) >> 2; ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ buffer is filled by the earlier call ret = applesmc_read_key(LIGHT_SENSOR_LEFT_KEY, ... This problem is reported because a goto skips the status check. Other similar problems use data from applesmc_read_key before checking the status. So move the checks to before the use. Signed-off-by: Tom Rix Reviewed-by: Henrik Rydberg Link: https://lore.kernel.org/r/20200820131932.10590-1-trix@redhat.com Signed-off-by: Guenter Roeck Signed-off-by: Sasha Levin --- drivers/hwmon/applesmc.c | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/drivers/hwmon/applesmc.c b/drivers/hwmon/applesmc.c index 3166184093157..a18887990f4a2 100644 --- a/drivers/hwmon/applesmc.c +++ b/drivers/hwmon/applesmc.c @@ -753,15 +753,18 @@ static ssize_t applesmc_light_show(struct device *dev, } ret = applesmc_read_key(LIGHT_SENSOR_LEFT_KEY, buffer, data_length); + if (ret) + goto out; /* newer macbooks report a single 10-bit bigendian value */ if (data_length == 10) { left = be16_to_cpu(*(__be16 *)(buffer + 6)) >> 2; goto out; } left = buffer[2]; + + ret = applesmc_read_key(LIGHT_SENSOR_RIGHT_KEY, buffer, data_length); if (ret) goto out; - ret = applesmc_read_key(LIGHT_SENSOR_RIGHT_KEY, buffer, data_length); right = buffer[2]; out: @@ -810,12 +813,11 @@ static ssize_t applesmc_show_fan_speed(struct device *dev, to_index(attr)); ret = applesmc_read_key(newkey, buffer, 2); - speed = ((buffer[0] << 8 | buffer[1]) >> 2); - if (ret) return ret; - else - return snprintf(sysfsbuf, PAGE_SIZE, "%u\n", speed); + + speed = ((buffer[0] << 8 | buffer[1]) >> 2); + return snprintf(sysfsbuf, PAGE_SIZE, "%u\n", speed); } static ssize_t applesmc_store_fan_speed(struct device *dev, @@ -851,12 +853,11 @@ static ssize_t applesmc_show_fan_manual(struct device *dev, u8 buffer[2]; ret = applesmc_read_key(FANS_MANUAL, buffer, 2); - manual = ((buffer[0] << 8 | buffer[1]) >> to_index(attr)) & 0x01; - if (ret) return ret; - else - return snprintf(sysfsbuf, PAGE_SIZE, "%d\n", manual); + + manual = ((buffer[0] << 8 | buffer[1]) >> to_index(attr)) & 0x01; + return snprintf(sysfsbuf, PAGE_SIZE, "%d\n", manual); } static ssize_t applesmc_store_fan_manual(struct device *dev, @@ -872,10 +873,11 @@ static ssize_t applesmc_store_fan_manual(struct device *dev, return -EINVAL; ret = applesmc_read_key(FANS_MANUAL, buffer, 2); - val = (buffer[0] << 8 | buffer[1]); if (ret) goto out; + val = (buffer[0] << 8 | buffer[1]); + if (input) val = val | (0x01 << to_index(attr)); else @@ -951,13 +953,12 @@ static ssize_t applesmc_key_count_show(struct device *dev, u32 count; ret = applesmc_read_key(KEY_COUNT_KEY, buffer, 4); - count = ((u32)buffer[0]<<24) + ((u32)buffer[1]<<16) + - ((u32)buffer[2]<<8) + buffer[3]; - if (ret) return ret; - else - return snprintf(sysfsbuf, PAGE_SIZE, "%d\n", count); + + count = ((u32)buffer[0]<<24) + ((u32)buffer[1]<<16) + + ((u32)buffer[2]<<8) + buffer[3]; + return snprintf(sysfsbuf, PAGE_SIZE, "%d\n", count); } static ssize_t applesmc_key_at_index_read_show(struct device *dev, -- 2.25.1