Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1990476imu; Fri, 14 Dec 2018 04:09:58 -0800 (PST) X-Google-Smtp-Source: AFSGD/VXKYH5mKUNx2o/ZA2c/eZkaeVDQe1SSvTYhjupBJo7qbuWRq8uy4iXH0w6aDLbYdi3WP2u X-Received: by 2002:a65:514c:: with SMTP id g12mr2446832pgq.169.1544789398618; Fri, 14 Dec 2018 04:09:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544789398; cv=none; d=google.com; s=arc-20160816; b=GTWkqSzaPOEBgHkS3unHs9Zgksd3QGgVLQXaAh7oGZG8WudNtDLh1wuqK2qZ7qNSal NV6NCJ2u3NHc45ZjLgreIt7k0gHdC7Z/El6BW0XsCIUDDTle8mDaLMZWW1/IJXYT7vy9 8TjiAiE1rqB6FfAxe72nWITAvlHDdjktKyF4ap5NaDa1S7EUGTXU/v0bGxKSQ4qeI763 X8EnvapbEJfWTFJBLGVixwbziBI0R+gVy4BLdLplnrZ/TYvR655Pl0xjKB37URjPWOQf jkwq8DFlZFtkJ/0jz0e8VZ9FTFpLIqiGNOv95qEVJCla5/o9o8ISP/XqvFhXWTqjZsbV LWsQ== 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=33gx2H9g01coiN+BMaUsRwgRlOxi69BuXS7Ig21yOBg=; b=Hr+GygQFpvqL0QtGwx6VKtHJXvdeC1G3CCfADDol4HKCbQ/rF6mhx3eC3yLqiqwbnM inaz6MyPw6anyFQWq1lZW523/45R4FgP6Leme7PA6N4Rt4PbMQz1r/WeaoxY+DwjDu3b TaHZRttih/osWoiqCLNujPdXC03hwYLVtJauHNSS/qeK0nfa2uAkx2r3W+j3e7YzVuxI GdPZTGBleTWa5F0uXK9yVCoXJO06OCnUTUPl8nzxfwry7IvN26iSoDQ+efJFtafXEpdu xqh3fBvsM1WxLChHhMpeFDiYNucBuCXMuOLnKKttZFLEbzeV2qAZ1Furh+UdOFYdxwxV aq0w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=miQ+a3tX; 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 v16si3777735pgc.519.2018.12.14.04.09.40; Fri, 14 Dec 2018 04:09:58 -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=miQ+a3tX; 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 S1730419AbeLNMIS (ORCPT + 99 others); Fri, 14 Dec 2018 07:08:18 -0500 Received: from mail.kernel.org ([198.145.29.99]:53690 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731232AbeLNMIP (ORCPT ); Fri, 14 Dec 2018 07:08:15 -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 EDF7C2147D; Fri, 14 Dec 2018 12:08:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1544789294; bh=mJUou9hl3hti0MEH1Klx8Ri9QDA6mxjDGZD2lDDEErY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=miQ+a3tX5UyBBVas98nPi6vJJDplePaDjHe4C2tcC6ZyQAxUUihmdLRnvOlFfgJzM ewkj7J0dT7IcXABxN374ZvtjCxS8fQRwb4lGRHzOp27BGn8aUpbNp02IG72z0fFFf5 sGa9060pUovXmIn9USNQpI+eg4HPJ/1hFYj7SvvI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Nicolin Chen , Guenter Roeck , Sasha Levin Subject: [PATCH 4.14 27/89] hwmon: (ina2xx) Fix current value calculation Date: Fri, 14 Dec 2018 12:59:40 +0100 Message-Id: <20181214115731.036940084@linuxfoundation.org> X-Mailer: git-send-email 2.20.0 In-Reply-To: <20181214115729.658859279@linuxfoundation.org> References: <20181214115729.658859279@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.14-stable review patch. If anyone has any objections, please let me know. ------------------ [ Upstream commit 38cd989ee38c16388cde89db5b734f9d55b905f9 ] The current register (04h) has a sign bit at MSB. The comments for this calculation also mention that it's a signed register. However, the regval is unsigned type so result of calculation turns out to be an incorrect value when current is negative. This patch simply fixes this by adding a casting to s16. Fixes: 5d389b125186c ("hwmon: (ina2xx) Make calibration register value fixed") Signed-off-by: Nicolin Chen Signed-off-by: Guenter Roeck Signed-off-by: Sasha Levin --- drivers/hwmon/ina2xx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/hwmon/ina2xx.c b/drivers/hwmon/ina2xx.c index c2252cf452f5..07ee19573b3f 100644 --- a/drivers/hwmon/ina2xx.c +++ b/drivers/hwmon/ina2xx.c @@ -274,7 +274,7 @@ static int ina2xx_get_value(struct ina2xx_data *data, u8 reg, break; case INA2XX_CURRENT: /* signed register, result in mA */ - val = regval * data->current_lsb_uA; + val = (s16)regval * data->current_lsb_uA; val = DIV_ROUND_CLOSEST(val, 1000); break; case INA2XX_CALIBRATION: -- 2.19.1