Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp325185pxk; Fri, 11 Sep 2020 07:59:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJygv7D9syJhogcmpseoYqpDXKwij3A0KZHb0Gh6IyW7p2BZ/kCe4pUkNe1PS2rLetnjoeYd X-Received: by 2002:a17:906:24d2:: with SMTP id f18mr2401043ejb.510.1599836345578; Fri, 11 Sep 2020 07:59:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599836345; cv=none; d=google.com; s=arc-20160816; b=JRi5SYlPl6PyGVycsi1caSNQlrSBmYMYmJuMmXNf2rzZyFqGtNtXt9b68psmngsMIq l0oN6sBx9CJW0UdE7XwYmaVu+2fhOL9EWO7dNF8VT7E0KR5RbQDlEmreB3VHtfucZgqv wopjh/2Ky5Wr91HhRyYUwFQZDyJaa29SxZnO5TNaFWW0qAIL0mhnMIZ3g47mlKywHszs P8IfeROI/fXMAZzNATglBkIKGCIqN0g3oQxpt3nMtMkJJgoaK/01InVXHbhbbSfPVvLj s/G+Rg904aB4Fd4laoq6wR3TVPp6DfJNYIF5gTiD0Ne9sA47PRZvf9X9rO2mkNNmPZ8z lykw== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=zVml8lZ4CzV0G/mt1jeV/ATjmDpFiQiraE1CDHCO004=; b=qBjYEmNwGj6MWdO+o4ydqX9bclXJIoopmlDYQ+aNDYWc8vnhH8Fy0kVvwck13TM4jk V4HKHAr+fs+lCKWFZKdwMJupZ5ySJCPlcYvZsrQ1Ou/fbe7n3ARVCbyD3WvlY0bm3uLL FG8m5hqV7ZzJYY1BW7G/UpiA18o+uXc3L2xl1jVk51X/RaSQQ+cGKA3BsTh98OUQWrzK eHbjsRD87OYuKb6tiD0fSWyRtUvBWXFgaVdEVbr3ruuuc4O6aDJ1vIYoAOyKIquKaxus QbjWZkOYkC4o0e0qcgCKmKkPVZPM7juT8h77z9bwQs2IU1aobr+ofyd+fUproHZUtn39 Eoww== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=VEo5NBZO; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l60si1435692ede.535.2020.09.11.07.58.42; Fri, 11 Sep 2020 07:59:05 -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=VEo5NBZO; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726085AbgIKO51 (ORCPT + 99 others); Fri, 11 Sep 2020 10:57:27 -0400 Received: from mail.kernel.org ([198.145.29.99]:52786 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726165AbgIKNCU (ORCPT ); Fri, 11 Sep 2020 09:02:20 -0400 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id EC2B622276; Fri, 11 Sep 2020 12:56:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1599829012; bh=T6IXcbTZtskK1L7YVm0OiBCn2pW7sfMMpBbYy0pK7wk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VEo5NBZOL6crJ4Y/k4Nq8MwUqwGLDETBBaj/KhfxtAdUEhiGVTsoE8rHjNDtif5aL 4c9aRyKN8+YD4sUZNCqmiAHgzWMrWw8hic1kkWnfKY9KbENJO484bO+SvTLdRs3iy+ iepwO6yNGPm0I2Qc0WoLXehcqjaLFlCNIBoG0OfU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Tom Rix , Henrik Rydberg , Guenter Roeck , Sasha Levin Subject: [PATCH 4.9 04/71] hwmon: (applesmc) check status earlier. Date: Fri, 11 Sep 2020 14:45:48 +0200 Message-Id: <20200911122505.158628111@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200911122504.928931589@linuxfoundation.org> References: <20200911122504.928931589@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 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 0af7fd311979d..587fc5c686b3c 100644 --- a/drivers/hwmon/applesmc.c +++ b/drivers/hwmon/applesmc.c @@ -758,15 +758,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: @@ -814,12 +817,11 @@ static ssize_t applesmc_show_fan_speed(struct device *dev, sprintf(newkey, fan_speed_fmt[to_option(attr)], 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, @@ -854,12 +856,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, @@ -875,10 +876,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 @@ -954,13 +956,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