Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3696504imu; Mon, 28 Jan 2019 09:12:27 -0800 (PST) X-Google-Smtp-Source: ALg8bN7EZhF30NLzjQd04IuhD0sPoDkhihoFMhRmjO7wZrMqix9nerSx97NKoj0DCcJ4g6RgKoEV X-Received: by 2002:a63:5346:: with SMTP id t6mr20856756pgl.40.1548695547158; Mon, 28 Jan 2019 09:12:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548695547; cv=none; d=google.com; s=arc-20160816; b=haIZU+t4XjCXvdcpIk/3+wj7O+89OySibzUU/9kK1umYQM9U87Il3XY11KtGsZRpdE GGSi8oa0GXjDosiOd38Vm/d/JTS755tJfPKLFioyEuUJACvaPzIVXiHrOigzZdjE3VTE 6ylevvulYmOlx62/zaGOxjfheIeU4R9+ApIsIHl4C13ovyqJRJb0AG8YXD6UVIF60Dnk oOKrf45d9R6mcr7X6uKaVb3swyxX4uR4y7uZgxIEZlQh0RnH1JdzRqChs7gtAAcr2dwL h6nqPGu42Eu8dcQqaphKLU8MBKMtWaP6V7fg+pOM33rXupDLWRodIPHim5HEYWza7I6b 0XlQ== 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=JRginnUdU6MMoKMEvDQZhH5/oRuMGntB7Rq4+HtN18s=; b=AV6uOUyWs4SVSyDMgCeey28nKZjh/Nd8b9jzN/S1II2/lEdOngShQsFsRtpe7NKPj1 tAVM+I7sAhbZHaRDB0tpm64swouLCZ447e/iURXoRnOlNYWGCf5H1ml4wSj10sHeBxTa Y6++INeLiDP9aDKuuKJKp63t3+u3GD5CLjY0YY/TJ/8+vjE1OwlwnszROtRh4gq7/ZnR ju8UTxuR9HnNtILPSZL+VpvgrEMY08pg2ZeIYHWtfZnT1stDkDioa0Vpl2LQLpQP3f14 nSGQFOOqObk994b0qBpQtnsBWwA84yjTVWx7xD5zuXTtQF1AXGZCr+5D1pDaRmDNL7JX 1FTA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="YyM1/E60"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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. [209.132.180.67]) by mx.google.com with ESMTP id h67si3606555pfb.146.2019.01.28.09.12.11; Mon, 28 Jan 2019 09:12:27 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="YyM1/E60"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 S1732050AbfA1QKC (ORCPT + 99 others); Mon, 28 Jan 2019 11:10:02 -0500 Received: from mail.kernel.org ([198.145.29.99]:35380 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731494AbfA1QJ7 (ORCPT ); Mon, 28 Jan 2019 11:09:59 -0500 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 A77A42171F; Mon, 28 Jan 2019 16:09:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1548691799; bh=rpGuL0U3h7Hq77TNLq8XnKd1cHGOMWFsyjr95sIHu6Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YyM1/E60um74XuEihNRwEAzVukqBwm5yMk4idIBKsPHaxw6PWOepdF3YDJPdkCzLp QSTzZW2PUNpfTrap3uQekjmeHXgU8lbbVbtA+FhfP4nBiVA1WBTBJeuC9P+Su2+v36 XfN1LN/nykgxQWYmdUtZVA9+hO/EUkd/4nnuFlmk= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Kangjie Lu , Guenter Roeck , Sasha Levin , linux-hwmon@vger.kernel.org Subject: [PATCH AUTOSEL 4.19 220/258] hwmon: (lm80) fix a missing check of the status of SMBus read Date: Mon, 28 Jan 2019 10:58:46 -0500 Message-Id: <20190128155924.51521-220-sashal@kernel.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190128155924.51521-1-sashal@kernel.org> References: <20190128155924.51521-1-sashal@kernel.org> MIME-Version: 1.0 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: Kangjie Lu [ Upstream commit c9c63915519b1def7043b184680f33c24cd49d7b ] If lm80_read_value() fails, it returns a negative number instead of the correct read data. Therefore, we should avoid using the data if it fails. The fix checks if lm80_read_value() fails, and if so, returns with the error number. Signed-off-by: Kangjie Lu [groeck: One variable for return values is enough] Signed-off-by: Guenter Roeck Signed-off-by: Sasha Levin --- drivers/hwmon/lm80.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/drivers/hwmon/lm80.c b/drivers/hwmon/lm80.c index 08e3945a6fbf..04f9df0d2341 100644 --- a/drivers/hwmon/lm80.c +++ b/drivers/hwmon/lm80.c @@ -360,9 +360,11 @@ static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr, struct i2c_client *client = data->client; unsigned long min, val; u8 reg; - int err = kstrtoul(buf, 10, &val); - if (err < 0) - return err; + int rv; + + rv = kstrtoul(buf, 10, &val); + if (rv < 0) + return rv; /* Save fan_min */ mutex_lock(&data->update_lock); @@ -390,8 +392,11 @@ static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr, return -EINVAL; } - reg = (lm80_read_value(client, LM80_REG_FANDIV) & - ~(3 << (2 * (nr + 1)))) | (data->fan_div[nr] << (2 * (nr + 1))); + rv = lm80_read_value(client, LM80_REG_FANDIV); + if (rv < 0) + return rv; + reg = (rv & ~(3 << (2 * (nr + 1)))) + | (data->fan_div[nr] << (2 * (nr + 1))); lm80_write_value(client, LM80_REG_FANDIV, reg); /* Restore fan_min */ -- 2.19.1