Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1984452imu; Fri, 14 Dec 2018 04:05:19 -0800 (PST) X-Google-Smtp-Source: AFSGD/WqDDQQhkngL3s3Xh6rHcZo7H4tL+TGbA0VdTkASImQSCzAVDnXVoIqAnjLrj8NM7P+IqtU X-Received: by 2002:a62:6303:: with SMTP id x3mr2669941pfb.110.1544789119543; Fri, 14 Dec 2018 04:05:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544789119; cv=none; d=google.com; s=arc-20160816; b=CESpRfshNTmkhuhxGBitRkGL8tAticQbX2+3qgjQvo35APblZkYNhilDvewgrQLE3C 5CqjY+I2C7qbY60f1qQ2YGunhUa6YL2gCOLgXJpabioUX5AGFaWbMx667LGeXjOEPq7n RX6oRjvlkAF6OnheVd9CRcrTKNBBnIsp7xO0V4VdVeuHBJs5eizfoOhQF5i5RVpm2/KD veyJUYV+ANvxjbXYJncEe9Sl7+3kW9kBafh9szUjHdsnTZbYMhUilxwRwWbLtiWxN+qG 1+EPi1+BOpGQFPaiy6C5gxPqCEJBLZlEbhEjq3doP18dWHVpG3k7SYk7R5FFcygQmknf Y/Qg== 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=YVh4RdN2cqDi+E9a0+aSVJIwRzN/jl7OHtv8Zz6Zwmw=; b=SY78IHHbCLhNZn67dk3pU8+/FK4m4/40LM6vpCNxmvFajqXnubBvDmxTUrR0bohW02 otO9Xr+ddBfFaJtW7pPeOzehEDocf/WYIgPgimDOwfxbJO+eLugJAsespUI6qJyJtWvj xBeoDFRc/bY6GiYoanmyRxuxGR2mhGwDgxPiyYmU4fZpUGrom4f9X9kC7+WhNlj3O6au eRGgSxtnNb5wwLN3CJTYkyC0tOrfWtPEnDV39y6ce0Zv2MrnxDjV7at+RQ+3J8gzq/zh J+7LNmnVV5BU4xnae/2Q6dFkEB03o+I1lMgE2o6OaMt4U2kOq4Js2rQ3gVmYIz69JdD5 pG/Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=difDro2N; 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 z12si3783537plk.90.2018.12.14.04.05.04; Fri, 14 Dec 2018 04:05:19 -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=difDro2N; 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 S1730292AbeLNMDV (ORCPT + 99 others); Fri, 14 Dec 2018 07:03:21 -0500 Received: from mail.kernel.org ([198.145.29.99]:46634 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730258AbeLNMDO (ORCPT ); Fri, 14 Dec 2018 07:03:14 -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 6D3242145D; Fri, 14 Dec 2018 12:03:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1544788993; bh=pcYjMC+3aw1WumIMa5Z7Ni4fB6N/+wgRIGQxsIQXHj0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=difDro2NM9MHDYQOFaAoOyfhftZVT2J7UcsOFvOQ3qK/5FkmO/k1GdcUw+5hM15ON h5i9wPIT/qH93I97Xst6lJln7HTegcEk1iie3cd6yAqcd2DRp3N1TWjmvn+1mpSSNT lDCov8vq9xOUDWYwVMpYHB3lj8KveXOSuKSMmQ04= 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.19 053/142] hwmon: (ina2xx) Fix current value calculation Date: Fri, 14 Dec 2018 12:58:58 +0100 Message-Id: <20181214115749.184546248@linuxfoundation.org> X-Mailer: git-send-email 2.20.0 In-Reply-To: <20181214115747.053633987@linuxfoundation.org> References: <20181214115747.053633987@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.19-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