Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp2657791imj; Mon, 11 Feb 2019 06:35:16 -0800 (PST) X-Google-Smtp-Source: AHgI3Ibj39YTKZE5UzOMBqdQN2doOkzVfMvJVg6UoN8zFe0gAe98bOt1Nrv4faVLlPhjWrF9A/RF X-Received: by 2002:a65:6150:: with SMTP id o16mr31729963pgv.434.1549895716255; Mon, 11 Feb 2019 06:35:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549895716; cv=none; d=google.com; s=arc-20160816; b=dPKICUoucwn/vcClVKwv+3vE5xOHFDa/PbWPpDve3DMrbBt7K1nhZNis8C7elWSAK9 5570sP7SdR6eTriA+8bEhJKupIYUHvVLYA4wRBw5Q1jc/+OuASj871xGIoyblL4SdVeP wx+aGclpbGu3DaDkehzxFMEeVQoENqKAz9rBAO2Vdsxjn52MKsDHwpDkuFPwEVEJXfQQ HT5S+DhRTgEiBr1YO+6XFaKTBqmg0pfV6LCSzbrlZXE8oD1A9cCGOKpme4xYS9f8AffY pp39gN+Up/1AvOSb1u7hn5FjS9WnvlGpZbIBor94WBazBt5d/AjFBIw4ZVOqfYZ7cz0w yY7Q== 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=ehobpMdLH5Dw+djxHaMm1StNrfQT7ftlyapEN28caiA=; b=pRCK/bNPwva3PwBYucwhe3K2hJYg/hS74yIjP+QdiQZopqCz5+yRT5iI2qaUB8UAHj PbFu4EL6Y52/Ra68nNh+KYFCmcYGLNBP04xm1EJn60eJDaq649RkdkbcVNeIhl5mIH6n qiO72cmfCCgH2vhBtZwWB9bGz65FbB0bsqh9jpr3ArAithUc2vpdqytSVxcwqApLjf2g R4cCtkEGSfisuNUTgBBYEp6owZ4Dn7cCn9XIJUwpTcuu1cD8nlMk9iOOkxRXnFjghVL3 Wi0sWNYzcIYxkh+VIBwZg1yDojyqUHsPGoUqb3QtudjEa7HjnGK2d7k6S2+hV/ky3XwJ /OpQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=krI4DMv7; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 33si7892763plu.169.2019.02.11.06.34.58; Mon, 11 Feb 2019 06:35:16 -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=krI4DMv7; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730853AbfBKOe0 (ORCPT + 99 others); Mon, 11 Feb 2019 09:34:26 -0500 Received: from mail.kernel.org ([198.145.29.99]:42650 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730846AbfBKOeZ (ORCPT ); Mon, 11 Feb 2019 09:34:25 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (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 8C167204EC; Mon, 11 Feb 2019 14:34:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1549895665; bh=y0WSYXKRyR0LxqHl1Tu7PYsQ9VesolrHaRAcsONuLWc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=krI4DMv78pC+ENzLx6ZVMMmpgQO+O5GpQ0GpDU95PDc8cOJ0E9ZDV3KMfAqEJpcac +ijkarnLe+CU8hpelkr1y09yKaQUpWzB/zr4g9HejhYwHNilJ7MufIuWRLlcJneJfK WYTFiBtfzY1x4liHQp8JrLjlTWfG+7RrAn7UdLt0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Kangjie Lu , Guenter Roeck , Sasha Levin Subject: [PATCH 4.20 251/352] hwmon: (lm80) fix a missing check of the status of SMBus read Date: Mon, 11 Feb 2019 15:17:58 +0100 Message-Id: <20190211141903.071742683@linuxfoundation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190211141846.543045703@linuxfoundation.org> References: <20190211141846.543045703@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore 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 4.20-stable review patch. If anyone has any objections, please let me know. ------------------ [ 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