Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp4116253pxk; Tue, 8 Sep 2020 11:06:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwq3IeX3Xm7TDGlDonQNqH6czp/0Sh6nG9VB2l0kePq89dAfcgCC/QoHpwz353pIw24MFEj X-Received: by 2002:aa7:dcd9:: with SMTP id w25mr177653edu.280.1599588383597; Tue, 08 Sep 2020 11:06:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599588383; cv=none; d=google.com; s=arc-20160816; b=g9ul1q9yVHSR/n8u63+7aZ0sAM7O0l6EVQZWzxY5iVvrCTnaRZbzgqT2D7vMIdZRg8 gE/h0Ca9BwMoI69Cz5qfOtPfSAIzTA6gACICMg6puwshtFpNeCazdqPJHLg4uEMKUQRW mK/61FdBCcHepJIdWXULlCv/X8HOhYB2Byjygtt2PFYhmFLkV6j4TcdK/mvmJxcUTl2K +v5mycY0E8XOVnMuCjlD55v8+zg7F+50WwcOS/DVZ/YX+ONS3DDlS+/yJ+kv7tzTl3J0 3xQli3MbGBpZj4WfXNg9vJp7wvRjx+S7x3Ex5cpMvxe+TsepFigxPPmgn9va5XV6Xwvy PlHg== 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=slDSWQ2X/kjn6zN70N5IznY/dgkca2yQRQYTOulmN1FhKzLerYK8OwAa8TlKoVq+P7 XPYtVq3ECCCev9POFnudipEfG66Kpdbeu3BUAIokEmmXmVUtwZz1FnJ6EHIVAdfpPBl8 m7P+Ewql0Ug56GbqZoH0oGvv19MWvCus7BBt8RCdw32OlgfRf6BPe1SXXAAVZB0V2T2c DC4N4TdK/O7Jm4xMqkh9YxTTJVbiVP30QsQYGPCXbw8Ie1hz9t9C1FuYyqBI63rj/xVx LEtBvMzwHwt+vhaueAdJk3mnXIHK9H1EuV0iU1v+UpvQaKrFfmonTOLtArg0+cUmsaDe w3bw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=p07mdHik; 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 z2si12442106ejj.455.2020.09.08.11.06.00; Tue, 08 Sep 2020 11:06:23 -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=p07mdHik; 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 S1731740AbgIHSEi (ORCPT + 99 others); Tue, 8 Sep 2020 14:04:38 -0400 Received: from mail.kernel.org ([198.145.29.99]:56676 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731529AbgIHQMK (ORCPT ); Tue, 8 Sep 2020 12:12:10 -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 776B4247BC; Tue, 8 Sep 2020 15:51:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1599580289; bh=IQ4F+qoYkAzgMNeGwGj8KmuUX6Ix0afDmrRyS92ms8o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=p07mdHikxk+vvaos4tpeGRqj3QN5uhwayBDdi4ZbbPaErWe22zjEqX2t2PexMSviV o+p/kPfeTC+IGmp4mbGsNr626RQy4LEQQSlCrWVVLaleByezryRFRhrVjvsjz+He1k lc8PI88ZS+AyNYoT/A6ChrVWJGNNKFgod2an74ro= 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.14 05/65] hwmon: (applesmc) check status earlier. Date: Tue, 8 Sep 2020 17:25:50 +0200 Message-Id: <20200908152217.303990371@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200908152217.022816723@linuxfoundation.org> References: <20200908152217.022816723@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