Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp4127436pxk; Tue, 8 Sep 2020 11:21:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx0c/9glN7xO7NP3fKUy+iaDbtGSweMTEeO4kfSzfUB61UXVBbN3iArDH4rEeKkS0X1LB9S X-Received: by 2002:a05:6402:615:: with SMTP id n21mr237693edv.59.1599589293835; Tue, 08 Sep 2020 11:21:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599589293; cv=none; d=google.com; s=arc-20160816; b=YG8LN1/QEEkDwvGUewUx5dfgZn5HQNEzGR14z1vos9QjudXaBIeIUz0xH7U9XmM6yF +phfjjjtKWdiIOvH0GVQsSHkA601A5Grb5AUD+0lcepm7v6BXN85XA9no95+0Up6fvx+ pYvbl//Lb7HSN/SqD8W2LJRHNEj5UvwccdZKfayiggQuXanGRRHfOufaSSfvIAM0x42i jqjCME4cVVUN7zQncmajvrWrT0cAEX2RupSTuuImiJ4+/HwFANui+g+A/CfHrR5JNRIW JJ7sXEHrSULRxIc0K6y7LV0tAgu3cc62nLOdbWKSV7HIfgOW3IsM7Xyt4dGdMMwFF2mf euig== 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=VB9/rTwlhLuKa5/F+gbnZP29ccFiFX/dVYovaapjK4c=; b=wEm2lGyokVJXFsh39PSpSNCOovRFjG/bOMJbPj84PT/FKHsxfIxHOl340GNflbM8/S FVlx5mkWhjTROtK8kJ3E+Hmub1vlv3a8VQyw8iysPN8J4M0UHD2FGoTPyuCGYxrdHbYV NDqd+VRm0YeIDIhrxjHyzksNtzoT1sMtNGOEdPVsJ5+ytL2VDGyEcY1SvSnnYJIBykmT ek6ixAIJBQ2mR8SPpjHk879J7jlIFlCbNrkU6Ugwr6OyIM/cVdhZdX4jjGrY6cE98c06 vsqVL3bH+mQuC5tVQQvmWqI/ID/JopQF0WeKpCELJdyQHmuGMlumVu7mGQalw4oDPL+I UvmQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=uc1YLGAi; 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 a26si12577242ejr.504.2020.09.08.11.21.10; Tue, 08 Sep 2020 11:21:33 -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=uc1YLGAi; 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 S1731794AbgIHSUe (ORCPT + 99 others); Tue, 8 Sep 2020 14:20:34 -0400 Received: from mail.kernel.org ([198.145.29.99]:56678 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731449AbgIHQLL (ORCPT ); Tue, 8 Sep 2020 12:11:11 -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 765CE2479A; Tue, 8 Sep 2020 15:42:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1599579733; bh=mpA3MbNqtFQ4NxGhPR6tP5hHJmfELPRJmAUNWdcPSq8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uc1YLGAiidJTAHy0dPiOPDJcVLAoyQD3M37YoyxNm4YI02AP3Dx37P0KmJa52PR23 uns6jxPt5dqOpbXbHIOQml2lZPfPRnHrHTyvg96uLb7853O3m/ggY4JoSieJYYk2W4 e4XjjZPV2c0TbBrD64X6XIoFe0dzzlqkBQBqnHUw= 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 5.4 005/129] hwmon: (applesmc) check status earlier. Date: Tue, 8 Sep 2020 17:24:06 +0200 Message-Id: <20200908152229.969754408@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200908152229.689878733@linuxfoundation.org> References: <20200908152229.689878733@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 183ff3d251299..006bc07bcd301 100644 --- a/drivers/hwmon/applesmc.c +++ b/drivers/hwmon/applesmc.c @@ -748,15 +748,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: @@ -805,12 +808,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, @@ -846,12 +848,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, @@ -867,10 +868,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 @@ -946,13 +948,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