Received: by 10.223.164.202 with SMTP id h10csp709473wrb; Wed, 22 Nov 2017 14:10:19 -0800 (PST) X-Google-Smtp-Source: AGs4zMaVSXx6oB+0g5aVIUT4oFWoReE5qTgWQa/2Y1Bayu3P8zJYzg/s4vuwBdwq42WuOYc0xE6w X-Received: by 10.101.90.138 with SMTP id c10mr8435883pgt.441.1511388619426; Wed, 22 Nov 2017 14:10:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1511388619; cv=none; d=google.com; s=arc-20160816; b=BFVnkaFJrp8HjU5m4QYo86VodF7I9P3tdwut7xKRL6APZJwFhtd4AsUsHM8wmB5K8/ 0AkePXPAee204JTZSSx4ps+ooMMaqkclo7LYDfffFjvRgq8WdpDVTDFMD/boymeqEjU+ 1hAzVdTTCbMDeniMRaLS7msWocI/QsKwKsLn4Liqa2GJKg6IFi+78uxwEHeC3zsuTMLC 0HX6Cs7dEQLsV6scZBcKiGTCr5WrQzoBd5k5N6MqOjSQYrhUpE6BouIKUokjrjSD/kfi DTYENryUyoVNnStjOrYiBAI01ROMWrowmN0PnBbgYpu5T5ePDl8sW1tAOogcyHpG/g30 sGIA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=AtIs5eFJUf/uF1awTl4YftpeF32+t5uMNW27Y6a/r3A=; b=VVkrkWnHnq5fujkhLjEisgmEIOLsoEfEWuM82OYL2rtqH4VEFQUAm7ddQQyXhK3r4W Cp4nvVS1dp9FJ5vDTr5F0k2WGWuLm1/dt3vEloj7eQ/UenOg7vD0jcViQ2JoQ4G5lyOn 25nZInEvVh0cC3vEibh60XLqOjPbKF/Lc9MDLsxY5gc62f/rk3LJyicd9VOryuxH1Y5Z bl71LNwKFRwbI/rMJkauiN7FG9jNQmCcly6aTyob5EgxjHXlbzXsr49imaKk31BVkCib CTdtibJzWm6CD+UPQHIe6aDFqGmIEdhKTE+ssIn81whzizZDGtu7HHe0E1H59mqChxBA 6Kvw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=i9mzodS4; 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=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n3si3865449pld.564.2017.11.22.14.10.06; Wed, 22 Nov 2017 14:10: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=@gmail.com header.s=20161025 header.b=i9mzodS4; 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=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751710AbdKVWIy (ORCPT + 78 others); Wed, 22 Nov 2017 17:08:54 -0500 Received: from mail-io0-f194.google.com ([209.85.223.194]:40699 "EHLO mail-io0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751588AbdKVWIw (ORCPT ); Wed, 22 Nov 2017 17:08:52 -0500 Received: by mail-io0-f194.google.com with SMTP id d21so2542914ioe.7; Wed, 22 Nov 2017 14:08:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=AtIs5eFJUf/uF1awTl4YftpeF32+t5uMNW27Y6a/r3A=; b=i9mzodS4B+BHZ4dI4F0e2KBKZErkYASZm90ImQCr5LzxE/yT1B7gYl9SA0+jFvFBwD 5144kXLr7wzFqucSdGtmGmkCqxqLYSWMal7RTigG/KcB+psgOrLEg14OYveKEGdFyVFs f762/bdZlqNMaoKrZhtg9olhifL+mXZph4G7ScKdLU1EvM6u+PqBJpDTDyNp9jLAKT8F ls72cZZoVYoXfQqf9vCB4MVqzIRMDj6Mx711YtDYGRgOxSkp+0RyO0sk83dp4vVqinTv Q5C7W7jIbWjsGioATMMflFH1YVcMF12m8ceArEXiVXmaE8phP6gA8sQjBVdkZXq9PzZ/ k4LQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=AtIs5eFJUf/uF1awTl4YftpeF32+t5uMNW27Y6a/r3A=; b=i5cHBib5MyXQ10wNe2XijlpK/kbzBqLi+INiqzowHFbQHpSqFrqv7R/x5JIDP855Cl +TqKZSn317XwwT5UjGGgTPSIOR0omBh3s0gsffp5FOyo/QfgqPdSbu72q6ht7crgegOl 8lNOB0O7NbzAPekg0lYPxCBSoDvLdKQTA1Vx2lnJIgHyw0cWr8sB6CFcydHdN7kCOSVt PTkShMGun9jesGXjuC8cx9Jw3xaGiJpcw4ikSbPEWhcqjuvk5zT4TqatzzLZWXPIWtNY p3B2hnWFsLX4MeWI6UUk+kPxzzi8kKcgsrSJaWF5p+rRUAYwpKiQeSAlDFEBRxXzfFvR Aerw== X-Gm-Message-State: AJaThX5Bl1b8VlxZFpmi8w5+9nXxgUp2QdB78XCVQvJMp5ST0qLMSLDk UW/zAnCERxR/JzhwcysOGg8= X-Received: by 10.107.59.199 with SMTP id i190mr23953427ioa.97.1511388532199; Wed, 22 Nov 2017 14:08:52 -0800 (PST) Received: from rlippert.svl.corp.google.com ([100.123.242.116]) by smtp.gmail.com with ESMTPSA id x137sm2531010itb.37.2017.11.22.14.08.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 22 Nov 2017 14:08:51 -0800 (PST) From: Robert Lippert X-Google-Original-From: Robert Lippert To: linux@roeck-us.net Cc: linux-hwmon@vger.kernel.org, jdelvare@suse.com, linux-kernel@vger.kernel.org, xow@google.com, Robert Lippert Subject: [PATCH] hwmon: (pmbus) Use 64bit math for DIRECT format values Date: Wed, 22 Nov 2017 14:08:43 -0800 Message-Id: <20171122220843.18309-1-rlippert@google.com> X-Mailer: git-send-email 2.15.0.448.gf294e3d99a-goog Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Power values in the 100s of watt range can easily blow past 32bit math limits when processing everything in microwatts. Use 64bit math instead to avoid these issues on common 32bit ARM BMC platforms. Signed-off-by: Robert Lippert --- drivers/hwmon/pmbus/pmbus_core.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c index 52a58b8b6e1b..f4efea9f282e 100644 --- a/drivers/hwmon/pmbus/pmbus_core.c +++ b/drivers/hwmon/pmbus/pmbus_core.c @@ -499,8 +499,8 @@ static long pmbus_reg2data_linear(struct pmbus_data *data, static long pmbus_reg2data_direct(struct pmbus_data *data, struct pmbus_sensor *sensor) { - long val = (s16) sensor->data; - long m, b, R; + s64 val = (s16) sensor->data; + s64 m, b, R; m = data->info->m[sensor->class]; b = data->info->b[sensor->class]; @@ -528,11 +528,13 @@ static long pmbus_reg2data_direct(struct pmbus_data *data, R--; } while (R < 0) { - val = DIV_ROUND_CLOSEST(val, 10); + do_div(val, 10); R++; } - return (val - b) / m; + val = val - b; + do_div(val, m); + return val; } /* @@ -656,7 +658,8 @@ static u16 pmbus_data2reg_linear(struct pmbus_data *data, static u16 pmbus_data2reg_direct(struct pmbus_data *data, struct pmbus_sensor *sensor, long val) { - long m, b, R; + s64 m, b, R; + s64 val64 = val; m = data->info->m[sensor->class]; b = data->info->b[sensor->class]; @@ -673,18 +676,18 @@ static u16 pmbus_data2reg_direct(struct pmbus_data *data, R -= 3; /* Adjust R and b for data in milli-units */ b *= 1000; } - val = val * m + b; + val64 = val64 * m + b; while (R > 0) { - val *= 10; + val64 *= 10; R--; } while (R < 0) { - val = DIV_ROUND_CLOSEST(val, 10); + do_div(val64, 10); R++; } - return val; + return (u16) val64; } static u16 pmbus_data2reg_vid(struct pmbus_data *data, -- 2.15.0.448.gf294e3d99a-goog From 1584958667527577376@xxx Fri Nov 24 14:39:33 +0000 2017 X-GM-THRID: 1584958667527577376 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread