Received: by 10.223.176.46 with SMTP id f43csp251082wra; Tue, 23 Jan 2018 20:18:05 -0800 (PST) X-Google-Smtp-Source: AH8x226WuXSBvrL58PkFIKKPVd7LndYy6A4v6dYi1LRM2k0VtN6zrHVVJmV25yloVZjd8LnLcG3H X-Received: by 10.99.181.13 with SMTP id y13mr5380403pge.196.1516767485429; Tue, 23 Jan 2018 20:18:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516767485; cv=none; d=google.com; s=arc-20160816; b=I71knBYh8zUo+yHOyXWAyzYFPBvcHwfA0IavM7cW564e3HXnlBiuR76zfvqpylNp/3 /RxjFZnPV7ML/atnWwoUHnJeSqKZO5LSYxfMbIG8ZgbgfP12mN/dR+qfkTGtWVrVT6IO NVkUoSgzSEufktpIda9aKLamitJvzIu1HvU/u9xIUK6AJvED+oYnenlRdWgSvcqDeaAy Zdh+GQYEBku/efP1ECxkpeONzaTwPApQnyPQv8R7vSE7CSTt9yHEkmOMR/wegfchDSY6 dy/yKAg4PVda7CGVvWBAr/VNll510mW9pVnGb/2syxjP+wxeehlkbsDsO8govl4Ahv/s 84IQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :spamdiagnosticmetadata:spamdiagnosticoutput:content-language :accept-language:in-reply-to:references:message-id:date:thread-index :thread-topic:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=6T7rPFQqlZrP/h29sYf8JnPpZ1zSjrqDMZBSuDBALfA=; b=y3ROWSEsUwhhLw0eruDbDj81k9V1gdaosoIVxGAaqmcqhmRNUtiGHE3RPlVRdQOMDW Ok1Btyx/nsCuzRsQJ62BeEI+rv0p730Xt2mXR1fI5ZGvtdTE1dErpY9Gx7//HWXTLs6a 89OKAZXApvbq9qKGmXR2KegE1G1+kOuhzDXN5iKsAp1iiG6BuytK3K7VZAtjOEJYVTPG kOh4VIS61e82GUXH9H0pS/mlKI4D0kiEJkV00k5UJIMPGDnatRwKCixbhKZjtYNUcyPV Dn+M353OA9OLd9+rdJb6cQNjt7MbO5vCiXzoMfhYA09NXD2NlzmEPsiPOMVWJO60orCA AxBA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=RFycOO2i; 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=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k29si2238617pfj.228.2018.01.23.20.17.51; Tue, 23 Jan 2018 20:18:05 -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=@microsoft.com header.s=selector1 header.b=RFycOO2i; 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=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932457AbeAXEQC (ORCPT + 99 others); Tue, 23 Jan 2018 23:16:02 -0500 Received: from mail-sn1nam01on0105.outbound.protection.outlook.com ([104.47.32.105]:55328 "EHLO NAM01-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S932427AbeAXEP5 (ORCPT ); Tue, 23 Jan 2018 23:15:57 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=6T7rPFQqlZrP/h29sYf8JnPpZ1zSjrqDMZBSuDBALfA=; b=RFycOO2iBPgYRfRW+0pJpHDuBnBkFDDuI8CL3L8eESd4UASH93AHLZqod7BRROUdrLhXpO9b82A7YxW/tSTvqd3OQSWs9Bqprsx+5/xwuZdAls4DCf/BzYvGMY/AGzBquGteQtKzxabPbmqeyZsrSE1Mv0F55qKX+FzBGVEH85M= Received: from DM5PR2101MB1032.namprd21.prod.outlook.com (52.132.128.13) by DM5PR2101MB1015.namprd21.prod.outlook.com (52.132.133.37) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.464.0; Wed, 24 Jan 2018 04:15:53 +0000 Received: from DM5PR2101MB1032.namprd21.prod.outlook.com ([fe80::6485:b98:d15e:9da7]) by DM5PR2101MB1032.namprd21.prod.outlook.com ([fe80::6485:b98:d15e:9da7%2]) with mapi id 15.20.0464.000; Wed, 24 Jan 2018 04:15:53 +0000 From: Sasha Levin To: "linux-kernel@vger.kernel.org" , "stable@vger.kernel.org" CC: Robert Lippert , Robert Lippert , Guenter Roeck , Sasha Levin Subject: [PATCH AUTOSEL for 4.14 063/100] hwmon: (pmbus) Use 64bit math for DIRECT format values Thread-Topic: [PATCH AUTOSEL for 4.14 063/100] hwmon: (pmbus) Use 64bit math for DIRECT format values Thread-Index: AQHTlMnklYa0pT5+Xk+OTPLa1gVXbA== Date: Wed, 24 Jan 2018 04:14:56 +0000 Message-ID: <20180124041414.32065-63-alexander.levin@microsoft.com> References: <20180124041414.32065-1-alexander.levin@microsoft.com> In-Reply-To: <20180124041414.32065-1-alexander.levin@microsoft.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [52.168.54.252] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1;DM5PR2101MB1015;7:lvQh6weMrKsJkG9Yy/YYGDDgzkNUrNXcpBXMTX0vexRAyoDxlOpW/SjcY4iBMRgchIyZ92JuDTBd+dzgp/f2puPBGyRiIN+/jKd63GGdYW4hP/q/sYqW/ghDMtjSHmD5IyfyyJCIxM/mN9gs34P+vfokh74xJ4vEZi4CxPOgdGNAXgOmsGBq6f8Ie/wrC9HVATmS/9hlB8IacYFh5tcywpdMR17WQt6x6/i+ZxnAxiVVCqhTC+UBCIJhSvnDaRGm x-ms-office365-filtering-correlation-id: 58afd693-e65f-437c-b28d-08d562e12908 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(5600026)(4604075)(3008032)(4534165)(4627221)(201703031133081)(201702281549075)(48565401081)(2017052603307)(7193020);SRVR:DM5PR2101MB1015; x-ms-traffictypediagnostic: DM5PR2101MB1015: x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(28532068793085)(89211679590171)(85827821059158)(211936372134217)(153496737603132); x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(61425038)(6040501)(2401047)(5005006)(8121501046)(3002001)(10201501046)(3231046)(2400081)(944501161)(93006095)(93001095)(6055026)(61426038)(61427038)(6041288)(20161123558120)(20161123562045)(20161123564045)(20161123560045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(6072148)(201708071742011);SRVR:DM5PR2101MB1015;BCL:0;PCL:0;RULEID:;SRVR:DM5PR2101MB1015; x-forefront-prvs: 056297E276 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(396003)(39380400002)(376002)(366004)(39860400002)(346002)(199004)(189003)(478600001)(106356001)(6512007)(53936002)(2900100001)(36756003)(102836004)(2950100002)(2501003)(10290500003)(97736004)(14454004)(81166006)(72206003)(8936002)(39060400002)(6486002)(1076002)(10090500001)(6346003)(26005)(54906003)(4326008)(76176011)(99286004)(86362001)(3660700001)(105586002)(6116002)(8676002)(68736007)(22452003)(66066001)(25786009)(6506007)(5660300001)(305945005)(7736002)(3280700002)(5250100002)(2906002)(107886003)(86612001)(6436002)(316002)(81156014)(3846002)(110136005)(22906009)(217873001);DIR:OUT;SFP:1102;SCL:1;SRVR:DM5PR2101MB1015;H:DM5PR2101MB1032.namprd21.prod.outlook.com;FPR:;SPF:None;PTR:InfoNoRecords;A:1;MX:1;LANG:en; received-spf: None (protection.outlook.com: microsoft.com does not designate permitted sender hosts) authentication-results: spf=none (sender IP is ) smtp.mailfrom=Alexander.Levin@microsoft.com; x-microsoft-antispam-message-info: dxuWST+NqZ9X2qCHMNPPje2wvgufwzaCCRd6I6RLUFddx53JuudNfOFwtoIVwPCRgTxlcjoXxeT7dx2jcVPA8A== spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: 58afd693-e65f-437c-b28d-08d562e12908 X-MS-Exchange-CrossTenant-originalarrivaltime: 24 Jan 2018 04:14:56.9809 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR2101MB1015 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Robert Lippert [ Upstream commit bd467e4eababe4c04272c1e646f066db02734c79 ] 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. Fixes: 442aba78728e ("hwmon: PMBus device driver") Signed-off-by: Robert Lippert Signed-off-by: Guenter Roeck Signed-off-by: Sasha Levin --- 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_c= ore.c index 52a58b8b6e1b..a139940cd991 100644 --- a/drivers/hwmon/pmbus/pmbus_core.c +++ b/drivers/hwmon/pmbus/pmbus_core.c @@ -21,6 +21,7 @@ =20 #include #include +#include #include #include #include @@ -499,8 +500,8 @@ static long pmbus_reg2data_linear(struct pmbus_data *da= ta, static long pmbus_reg2data_direct(struct pmbus_data *data, struct pmbus_sensor *sensor) { - long val =3D (s16) sensor->data; - long m, b, R; + s64 b, val =3D (s16)sensor->data; + s32 m, R; =20 m =3D data->info->m[sensor->class]; b =3D data->info->b[sensor->class]; @@ -528,11 +529,12 @@ static long pmbus_reg2data_direct(struct pmbus_data *= data, R--; } while (R < 0) { - val =3D DIV_ROUND_CLOSEST(val, 10); + val =3D div_s64(val + 5LL, 10L); /* round closest */ R++; } =20 - return (val - b) / m; + val =3D div_s64(val - b, m); + return clamp_val(val, LONG_MIN, LONG_MAX); } =20 /* @@ -656,7 +658,8 @@ static u16 pmbus_data2reg_linear(struct pmbus_data *dat= a, static u16 pmbus_data2reg_direct(struct pmbus_data *data, struct pmbus_sensor *sensor, long val) { - long m, b, R; + s64 b, val64 =3D val; + s32 m, R; =20 m =3D data->info->m[sensor->class]; b =3D data->info->b[sensor->class]; @@ -673,18 +676,18 @@ static u16 pmbus_data2reg_direct(struct pmbus_data *d= ata, R -=3D 3; /* Adjust R and b for data in milli-units */ b *=3D 1000; } - val =3D val * m + b; + val64 =3D val64 * m + b; =20 while (R > 0) { - val *=3D 10; + val64 *=3D 10; R--; } while (R < 0) { - val =3D DIV_ROUND_CLOSEST(val, 10); + val64 =3D div_s64(val64 + 5LL, 10L); /* round closest */ R++; } =20 - return val; + return (u16)clamp_val(val64, S16_MIN, S16_MAX); } =20 static u16 pmbus_data2reg_vid(struct pmbus_data *data, --=20 2.11.0