Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp4141506pxk; Tue, 8 Sep 2020 11:42:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwWrvgf9BX6MT4baL+JGDxVXqpXhzCwbdqMaHcdKf/Ro0FI3+Fa9llzBfHb+Pbepu4T1zME X-Received: by 2002:a50:d304:: with SMTP id g4mr357717edh.248.1599590549237; Tue, 08 Sep 2020 11:42:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599590549; cv=none; d=google.com; s=arc-20160816; b=jIHx/fzSSXP/XU5tcLE3/3eKbvaGafYv53WORq5jny59QWf1RnV9DtZqnD0fDAW3z8 08WDcePBWlDi5DXE9M6nXIjE3PiIAPYZDsGNheJlIs8RICSFdUbYMOx7xOBzO5sqKYBQ mv2cZXqa4yV9FEsyUlzGp0hgKTEPk3cWl1QViKbg9OB+tdxDVXbUYonxyFln89ljHR00 nZazWL6kBQ+c1L4oqg5c+l6Szx7HHv9bmEsi1vM7aO8vYA2Tez9FA8Bn6ls5ds949+Rb a5NRCxKoEtiwUMqfBORckBgCQEdaigFUWKFJZQ5mLY9B1t/0t0xxU0hR0PBvRdm2Lq48 21yw== 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=acrgyZ0LrGQ5Cs4K4/XtXfYJvmEv36bjQG9wAIjJscc=; b=UeTkvF9CBAazAQ3yNR3Mw6oAP/Dx+VNAFF+i02hrO+9XUH+Ow+orHVLS6mDqPFwh0U fecBTi+sF2OyK90IINlbaAKqPqoVB8vsgCmDVVu0PeIVs+SOOGw3ZZ2L3fwmEUy11QDS ArL54UryzPpb86En3yNHetrYFevhPmsQSqaheb+nv/e1ysLYhLaq6B4AK4sLymXkf8RA /uO8Rpwwkf4LJSUquw53pI9x/GE+tbGsguS4CWlT6zCVBgkDg1hsHbV1Yks7+peGhRza mZv+t0luPCw6l86fPJupbk92R9Ldw9iNScHNjccnrJ++4NLK7t2zsLJ44dTHrYKSj4kc vRsg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=w8CkuJDE; 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 a17si12556225ejc.540.2020.09.08.11.42.06; Tue, 08 Sep 2020 11:42:29 -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=w8CkuJDE; 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 S1731979AbgIHSle (ORCPT + 99 others); Tue, 8 Sep 2020 14:41:34 -0400 Received: from mail.kernel.org ([198.145.29.99]:52186 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731294AbgIHQIC (ORCPT ); Tue, 8 Sep 2020 12:08:02 -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 505B523ED2; Tue, 8 Sep 2020 15:47:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1599580064; bh=IQ4F+qoYkAzgMNeGwGj8KmuUX6Ix0afDmrRyS92ms8o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=w8CkuJDEGsME0rz5m1wqDrsfuuRtpzBfuUCPSpk6d433CmkUkdv3Ts97BvYdRdqpi 2IJQ3Jjt8uXC8DbzV9HJBHhd3uGCxjOlxvECxiQL+A3LuKcPyj317o2rL+bcx1TlQ6 7UZbNqXhhq3fW4z6xDy1nM5pamVxKt63BM9537Kg= 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.19 08/88] hwmon: (applesmc) check status earlier. Date: Tue, 8 Sep 2020 17:25:09 +0200 Message-Id: <20200908152221.509108578@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200908152221.082184905@linuxfoundation.org> References: <20200908152221.082184905@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 5c677ba440143..b201129a9beae 100644 --- a/drivers/hwmon/applesmc.c +++ b/drivers/hwmon/applesmc.c @@ -760,15 +760,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: @@ -817,12 +820,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, @@ -858,12 +860,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, @@ -879,10 +880,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 @@ -958,13 +960,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