Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3696834imu; Mon, 28 Jan 2019 09:12:44 -0800 (PST) X-Google-Smtp-Source: ALg8bN61Cz+HyuBikFNPlz7sfwBFQLg4pVaoQo4QiycZVxnyBAqq3n2j+lR8LfvSwN6KBX72+q71 X-Received: by 2002:a62:d448:: with SMTP id u8mr22567483pfl.105.1548695564664; Mon, 28 Jan 2019 09:12:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548695564; cv=none; d=google.com; s=arc-20160816; b=RdDbf4ytGiCroV6fBOMmftkYGViaXjEOCMXjLmooLRVEOK63BVCH6dp9vSb1YJriLe i4YIry+Re203rsclUIx7CELuHPmvh/3TvCqqqS3yYZYZtIdHLlM+WOiR5gGEpg52ttfM pmfhxGIjaTNcZw5PBXX07QplhaJg6WzF39n57tnW1Wjs5aSNqFM/1xadWRWOhJbKxDF9 IJQO9dCs4iy+hBgO4Zbo5hDb5zLFUjuN/M96gjjIkjc1nQkYKl0D0ptzIbTp/9+tRHsQ e4hdvfb2cIscCJvzGTwmc9ssroiha6UMIIGw8w2u2B1ZMJsirG2hFALESUjPLXT7m89s JizQ== 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=xFAwtnVJHuVTcgFcq96wv6DIvqMfv252o2uOEZQHq7U=; b=jyWnCAJ7nVOFEgJYQDeX7r0OM0L9hNUVhAT0vC9xExjVX4BC3Cq0e72q5uNEHHfOH4 nuyvq8iG9hbGfcpCP2JC3UrH+79Qlv/LebXvqf0OXkRD7R8Kti9TkqR2WYZ6n84xGt8n GHplHs3pepXDH6FRbJiUZVpIuzCJXTy5GZ7HSP07RvBnOddFhqX2F9j3ehtQBpk6RWef k60BdssAt3uUTnLoGE9YK+QtM8rr2sP1GEwdyAalSYEtMBhOmJb8iarbTQQ3NTQemEUw HXpC31kY3mm7ByF/iYOYyRm7zkGBsbsBW1gTHOTBM9bhS5L51bDf2vhbOYENw218Nxya zz8w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=SdP95uBu; 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 q3si11760096plb.209.2019.01.28.09.12.28; Mon, 28 Jan 2019 09:12:44 -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=SdP95uBu; 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 S1727537AbfA1RLC (ORCPT + 99 others); Mon, 28 Jan 2019 12:11:02 -0500 Received: from mail.kernel.org ([198.145.29.99]:35456 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731301AbfA1QKB (ORCPT ); Mon, 28 Jan 2019 11:10:01 -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 960402084A; Mon, 28 Jan 2019 16:09:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1548691800; bh=HyMAqaFJwl6HiEL4HU+bZrxP9e1YDEIkXQIbeN9mQAE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SdP95uBu6wEt+49bKC8MhrIIxJqguIQyUsPavQ7qrjXcwE9Yhz87kY035jPx7216L TzxDuPrDQMkfYaGyT08Q5baVP2CIukCRe2dIQNwpYAic7HYrXO7+kNuQCj6Fclhn5H FUuUcMYD7GR3MNTGqNH8bCb9LP/uavOwpzsz3VQc= 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 221/258] hwmon: (lm80) fix a missing check of bus read in lm80 probe Date: Mon, 28 Jan 2019 10:58:47 -0500 Message-Id: <20190128155924.51521-221-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 9aa3aa15f4c2f74f47afd6c5db4b420fadf3f315 ] In lm80_probe(), if lm80_read_value() fails, it returns a negative error number which is stored to data->fan[f_min] and will be further used. We should avoid using the data if the read fails. The fix checks if lm80_read_value() fails, and if so, returns with the error number. Signed-off-by: Kangjie Lu Signed-off-by: Guenter Roeck Signed-off-by: Sasha Levin --- drivers/hwmon/lm80.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/drivers/hwmon/lm80.c b/drivers/hwmon/lm80.c index 04f9df0d2341..0e30fa00204c 100644 --- a/drivers/hwmon/lm80.c +++ b/drivers/hwmon/lm80.c @@ -628,6 +628,7 @@ static int lm80_probe(struct i2c_client *client, struct device *dev = &client->dev; struct device *hwmon_dev; struct lm80_data *data; + int rv; data = devm_kzalloc(dev, sizeof(struct lm80_data), GFP_KERNEL); if (!data) @@ -640,8 +641,14 @@ static int lm80_probe(struct i2c_client *client, lm80_init_client(client); /* A few vars need to be filled upon startup */ - data->fan[f_min][0] = lm80_read_value(client, LM80_REG_FAN_MIN(1)); - data->fan[f_min][1] = lm80_read_value(client, LM80_REG_FAN_MIN(2)); + rv = lm80_read_value(client, LM80_REG_FAN_MIN(1)); + if (rv < 0) + return rv; + data->fan[f_min][0] = rv; + rv = lm80_read_value(client, LM80_REG_FAN_MIN(2)); + if (rv < 0) + return rv; + data->fan[f_min][1] = rv; hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name, data, lm80_groups); -- 2.19.1