Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp2280894ybl; Thu, 29 Aug 2019 06:14:14 -0700 (PDT) X-Google-Smtp-Source: APXvYqxTi38xVaAebvZMNXAuIq6R2f20E4Jm93GHiTiDqPwVIYWlc27rAec8W8KGC/mHYVht7HGH X-Received: by 2002:a17:90b:8ca:: with SMTP id ds10mr9533033pjb.139.1567084454737; Thu, 29 Aug 2019 06:14:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567084454; cv=none; d=google.com; s=arc-20160816; b=Hh4xV6d/MRbTK7JYcY26ZAF4ErgDrjwdQj+eWzvwNTl1BNYzXdbB1ghPuk1RqsR1OB dUxaZ8TjfFDGQOpAugdTrz2Hd2u+GB+4Hyn29hdKUOWZuo01WsNuu0kfZQLzdoSr3QOx clALx/mOyIGtxcCV7hX7rLShfs/YPnYc3EINEw+cYNnpmvVPJlzygf7pbMDRRbbZXpra uj8MYCIMrBmhuQHslfFrfNGrMN7x0wzXV0Ysy3TkPypl8dXus7DK4gsi3keeFVjZjrnD bki7t2o3bIfYNXSOjVqvfaUCNi6QNC4lKSpoW8+Q43sjWSfi7+iYx30m+TDImkAOLPJ/ 6OAA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=dJBlSmrfDTRv7cxuleB8tV+kWPMcqS42afzr9LQBfLI=; b=z8PFrK3tahZ/zpe/WCH6FjOMhkYobNzp9z1z6Tyh99AGvA/U+7fN77Da7GLHEmFs01 wogO5l5RcJjeC5MI7FtINctcH22wt12vbNGBQmGJhpx4Lrv7blCBbodMLRxm9e+GbYsS vgNvGfLZet2H0/xrPHjMuhbGP07kyaRIy9QImMM97b3QTfGZbxsummCFJqe9xJMIHVE9 icBYNvQHGGNWgfMXnaO6iSEB6e1+DlAg66JBj/jGBm8AWjqBu/pEltw+7kWapD9ufzqc O8m9b7LKEz7gTN4deahsJ6ORuR+uG5TlxGGCHuWPZuUvKLMsCV6UHFXx/5TKp/vPGV3d Lvkw== ARC-Authentication-Results: i=1; mx.google.com; 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 134si1682639pfa.245.2019.08.29.06.13.58; Thu, 29 Aug 2019 06:14:14 -0700 (PDT) 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; 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 S1727426AbfH2NL2 (ORCPT + 99 others); Thu, 29 Aug 2019 09:11:28 -0400 Received: from sauhun.de ([88.99.104.3]:38986 "EHLO pokefinder.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727182AbfH2NL2 (ORCPT ); Thu, 29 Aug 2019 09:11:28 -0400 Received: from localhost (p54B33070.dip0.t-ipconnect.de [84.179.48.112]) by pokefinder.org (Postfix) with ESMTPSA id C78242C001C; Thu, 29 Aug 2019 15:11:24 +0200 (CEST) Date: Thu, 29 Aug 2019 15:11:24 +0200 From: Wolfram Sang To: Zhang Rui , Simon Horman Cc: Daniel Lezcano , Nathan Huckleberry , edubezval@gmail.com, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, clang-built-linux@googlegroups.com, Yoshihiro Kaneko , wsa+renesas@sang-engineering.com Subject: Re: [PATCH] thermal: rcar_gen3_thermal: Fix Wshift-negative-value Message-ID: <20190829131124.GA2437@kunai> References: <20190613211228.34092-1-nhuck@google.com> <82458318837ed1154a183be0b96337fc7809c645.camel@intel.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="zhXaljGHf11kAtnf" Content-Disposition: inline In-Reply-To: <82458318837ed1154a183be0b96337fc7809c645.camel@intel.com> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --zhXaljGHf11kAtnf Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Wed, Aug 28, 2019 at 04:52:20PM +0800, Zhang Rui wrote: > On Fri, 2019-06-14 at 12:52 +0200, Daniel Lezcano wrote: > > Hi Nathan, > >=20 > > On 13/06/2019 23:12, Nathan Huckleberry wrote: > > > Clang produces the following warning > > >=20 > > > vers/thermal/rcar_gen3_thermal.c:147:33: warning: shifting a > > > negative > > > signed value is undefined [-Wshift-negative-value] / (ptat[0] - > > > ptat[2])) + > > > FIXPT_INT(TJ_3); ^~~~~~~~~~~~~~~ > > > drivers/thermal/rcar_gen3_thermal.c:126:29 > > > note: expanded from macro 'FIXPT_INT' #define FIXPT_INT(_x) ((_x) > > > << > > > FIXPT_SHIFT) ~~~~ ^ drivers/thermal/rcar_gen3_thermal.c:150:18: > > > warning: > > > shifting a negative signed value is undefined [-Wshift-negative- > > > value] > > > tsc->tj_t - FIXPT_INT(TJ_3)); ~~~~~~~~~~~~^~~~~~~~~~~~~~~~ > > >=20 > > > Upon further investigating it looks like there is no real reason > > > for > > > TJ_3 to be -41. Usages subtract -41, code would be cleaner to just > > > add. > >=20 > > All the code seems broken regarding the negative value shifting as > > the > > macros pass an integer: > >=20 > > eg. > > tsc->coef.a2 =3D FIXPT_DIV(FIXPT_INT(thcode[1] - thcode[0]), > > tsc->tj_t - FIXPT_INT(ths_tj_1)); > >=20 > > thcode[1] is always < than thcode[0], > >=20 > > thcode[1] - thcode[0] < 0 > >=20 > > FIXPT_INT(thcode[1] - thcode[0]) is undefined > >=20 > >=20 > > Is it done on purpose FIXPT_DIV(FIXPT_INT(thcode[1] - thcode[0]) ? > >=20 > > Try developing the macro with the coef.a2 computation ... > >=20 > > The code quality of this driver could be better, it deserves a rework > > IMHO ... > >=20 > > I suggest to revert: > >=20 > > 4eb39f79ef443fa566d36bd43f1f578d5c140305 > > bdc4480a669d476814061b4da6bb006f7048c8e5 > > 6a310f8f97bb8bc2e2bb9db6f49a1b8678c8d144 > >=20 > > Rework the coefficient computation and re-introduce what was reverted > > in > > a nicer way. >=20 > Sounds reasonable to me. >=20 > Yoshihiro, > can you please clarify on this? Or else I will revert the above commits > first? >=20 > Also CC Wolfram Sang, the driver author. CCing Simon Horman who worked with Kaneko-san on these changes. > thanks, > rui > >=20 > >=20 > > > Fixes: 4eb39f79ef44 ("thermal: rcar_gen3_thermal: Update value of > > > Tj_1") > > > Cc: clang-built-linux@googlegroups.com > > > Link: https://github.com/ClangBuiltLinux/linux/issues/531 > > > Signed-off-by: Nathan Huckleberry > > > --- > > > drivers/thermal/rcar_gen3_thermal.c | 8 ++++---- > > > 1 file changed, 4 insertions(+), 4 deletions(-) > > >=20 > > > diff --git a/drivers/thermal/rcar_gen3_thermal.c > > > b/drivers/thermal/rcar_gen3_thermal.c > > > index a56463308694..f4b4558c08e9 100644 > > > --- a/drivers/thermal/rcar_gen3_thermal.c > > > +++ b/drivers/thermal/rcar_gen3_thermal.c > > > @@ -131,7 +131,7 @@ static inline void > > > rcar_gen3_thermal_write(struct rcar_gen3_thermal_tsc *tsc, > > > #define RCAR3_THERMAL_GRAN 500 /* mili Celsius */ > > > =20 > > > /* no idea where these constants come from */ > > > -#define TJ_3 -41 > > > +#define TJ_3 41 > > > =20 > > > static void rcar_gen3_thermal_calc_coefs(struct > > > rcar_gen3_thermal_tsc *tsc, > > > int *ptat, const int *thcode, > > > @@ -144,11 +144,11 @@ static void > > > rcar_gen3_thermal_calc_coefs(struct rcar_gen3_thermal_tsc *tsc, > > > * the dividend (4095 * 4095 << 14 > INT_MAX) so keep it > > > unscaled > > > */ > > > tsc->tj_t =3D (FIXPT_INT((ptat[1] - ptat[2]) * 157) > > > - / (ptat[0] - ptat[2])) + FIXPT_INT(TJ_3); > > > + / (ptat[0] - ptat[2])) - FIXPT_INT(TJ_3); > > > =20 > > > tsc->coef.a1 =3D FIXPT_DIV(FIXPT_INT(thcode[1] - thcode[2]), > > > - tsc->tj_t - FIXPT_INT(TJ_3)); > > > - tsc->coef.b1 =3D FIXPT_INT(thcode[2]) - tsc->coef.a1 * TJ_3; > > > + tsc->tj_t + FIXPT_INT(TJ_3)); > > > + tsc->coef.b1 =3D FIXPT_INT(thcode[2]) + tsc->coef.a1 * TJ_3; > > > =20 > > > tsc->coef.a2 =3D FIXPT_DIV(FIXPT_INT(thcode[1] - thcode[0]), > > > tsc->tj_t - FIXPT_INT(ths_tj_1)); > > >=20 > >=20 > >=20 >=20 --zhXaljGHf11kAtnf Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEOZGx6rniZ1Gk92RdFA3kzBSgKbYFAl1nzvgACgkQFA3kzBSg KbYx+g//f5G/Zdl+qgCmmyNNWXxl8l6bbTgwmYs9qlm05wSREnJW80SFptJOOmVX 105JuRkTrXtoUnAmCxF/Z55HYly0hG4s0HByxuALCLpb3j+rcU+G0hdXrSdNICRk tN9HkHzYmKGszT5yaZY2EF730nUnpv71Pc4Z3wTY/H+5wz8uDv/6mW4IpcYM3Tnr 9ueuEBNYWwGiR/29dGwgaVnh0f/nIZllMEQbuYKeCxRuY58gqQFA9Ng5bEDfNFHV qR5n9jKoQetVx3zacipFHYjwv9d1rnAfHonBmvp5FjkZ/5/U0EBhkeouPxFTIRuW u1e2DzblJ1hGPHyVlwrl5294e9bujd6iVEMetJZnEU21n6aGb3lenQnYy6ER6cUB J6Pg9fnwoGFYH9WUkQwQ8V1tLO1zRf2SvJexYZmQK40n/D1M5oUUqfbTBd7wwofv WvXAkuVfACXvWiLVhOtlGGIX+C+IRlvdbl1L/12eAT2PW28k+aUzV7HHxHykfGjW CgLj4Kli7gsQO2NF4hQcG79FZDTnx/FPYGGT0U1SUaLfBBnYMOZ6HJbko4TJmnII FrcgDCPNHS/yGT/PcOM1XfqXwMlODu1aeneScG8bxbZT46iWRFDS7PL0zH8qrDr0 aCtkS4xv3uPyh6A9+o8Qpg/XEmoPpmZO1Z2bNR6B8wcYIuv3YDc= =a7UP -----END PGP SIGNATURE----- --zhXaljGHf11kAtnf--