Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp1714384ybl; Sat, 31 Aug 2019 00:42:43 -0700 (PDT) X-Google-Smtp-Source: APXvYqysK0n3aNSIwyv29qWO3QRH70kpVGZ/wVrCRWtBoI0kRtVxyv9yy3rdBtguMZV/fZF9iCOr X-Received: by 2002:a17:90a:17e2:: with SMTP id q89mr2697217pja.8.1567237363049; Sat, 31 Aug 2019 00:42:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567237363; cv=none; d=google.com; s=arc-20160816; b=ps+57DL4qSlAlq13u9GPQKczK3dg3n8kEzxyif5SpZBb+oGoPy8TR3QOI8YTbh/Cyj JU0Q0MypHLsGCTg+nmEIV92j8DANpDDz19u4fT6UMH3+EA4zjEjBa5etYITvrDCW8sTG pMt90z8FYs0z7m8FpkF9NIphY/NDvLVBROuQnq6+40TJTy9L107YtRwm5JRAJhqbgdo0 1Bt5JsLFQMrDVQIHdZrnxPjrJzhU/OCoZxeXj4HaY5zz7U5pd5AAPaHorRU9qGn4pblM rX+9KnkffaTALc6+Wl/KJZRdhYB6la1IgT0ptRytdrxizu3EVEW1WLE5xU9TWagoXFWb BvLg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:organisation:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=hAk5ol4WXtTN920PXhXsqdoVb7GeAVVRFgUDXAJ/PaI=; b=BXMcO9QjdzXZB/cnkromeM+wT1sUvaoyGlgGLc8P00m1vFIIRO7/HDVZM8qHHewAyl 7ypEJD/bWWdqwcEzLQjRNjhnM1hhf70+G4KsKPUh7xxAvig5QQfAfVGYjrPkMYubxxxE 6dFFx8mfpL91yth16eZe2ro2n+a/8glR0Gtrkg243aHAzWu4vOf9QJhYFq7HciRuAJS2 Hm9ocluCLZGpONuHc1g+hJYrjqXMqQ6YKgEN3PKv1dxquTjokf4Tq8DVRgPVAobNpGQp HLEXcHFQzrhp8Ilpk1/daZMNVJzbFy0cgZeCJhLOViBvNmiKaXKztz1BH6PUQE+6T9sX 0vpw== 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 j6si8066538pfh.289.2019.08.31.00.42.27; Sat, 31 Aug 2019 00:42:43 -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 S1726683AbfHaHkV (ORCPT + 99 others); Sat, 31 Aug 2019 03:40:21 -0400 Received: from kirsty.vergenet.net ([202.4.237.240]:47636 "EHLO kirsty.vergenet.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726135AbfHaHkV (ORCPT ); Sat, 31 Aug 2019 03:40:21 -0400 Received: from penelope.horms.nl (ip4dab7138.direct-adsl.nl [77.171.113.56]) by kirsty.vergenet.net (Postfix) with ESMTPA id B3F8F25AE77; Sat, 31 Aug 2019 17:40:18 +1000 (AEST) Received: by penelope.horms.nl (Postfix, from userid 7100) id 92FBBE218F0; Sat, 31 Aug 2019 09:40:16 +0200 (CEST) Date: Sat, 31 Aug 2019 09:40:16 +0200 From: Simon Horman To: Wolfram Sang Cc: Zhang Rui , 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: <20190831074016.nqjtvqf3lesyz77z@verge.net.au> References: <20190613211228.34092-1-nhuck@google.com> <82458318837ed1154a183be0b96337fc7809c645.camel@intel.com> <20190829131124.GA2437@kunai> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190829131124.GA2437@kunai> Organisation: Horms Solutions BV User-Agent: NeoMutt/20170113 (1.7.2) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Aug 29, 2019 at 03:11:24PM +0200, Wolfram Sang wrote: > 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, > > > > > > On 13/06/2019 23:12, Nathan Huckleberry wrote: > > > > Clang produces the following warning > > > > > > > > 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)); ~~~~~~~~~~~~^~~~~~~~~~~~~~~~ > > > > > > > > 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. > > > > > > All the code seems broken regarding the negative value shifting as > > > the > > > macros pass an integer: > > > > > > eg. > > > tsc->coef.a2 = FIXPT_DIV(FIXPT_INT(thcode[1] - thcode[0]), > > > tsc->tj_t - FIXPT_INT(ths_tj_1)); > > > > > > thcode[1] is always < than thcode[0], > > > > > > thcode[1] - thcode[0] < 0 > > > > > > FIXPT_INT(thcode[1] - thcode[0]) is undefined > > > > > > > > > Is it done on purpose FIXPT_DIV(FIXPT_INT(thcode[1] - thcode[0]) ? > > > > > > Try developing the macro with the coef.a2 computation ... > > > > > > The code quality of this driver could be better, it deserves a rework > > > IMHO ... > > > > > > I suggest to revert: > > > > > > 4eb39f79ef443fa566d36bd43f1f578d5c140305 > > > bdc4480a669d476814061b4da6bb006f7048c8e5 > > > 6a310f8f97bb8bc2e2bb9db6f49a1b8678c8d144 > > > > > > Rework the coefficient computation and re-introduce what was reverted > > > in > > > a nicer way. > > > > Sounds reasonable to me. > > > > Yoshihiro, > > can you please clarify on this? Or else I will revert the above commits > > first? > > > > Also CC Wolfram Sang, the driver author. > > CCing Simon Horman who worked with Kaneko-san on these changes. Hi, I think that what has happened here is that these patches and moreover the driver has been through quite a few hands and I agree that zooming out and cleaning things up would make a lot of sense. Personally I would take the approach of incrementally cleaning things up. But I don't feel strongly about this. As for the specific question about a negative constant, I don't know of a specific reason that approach was taken and I don't recall investigating it at the time. Kind regards, Simon > > > thanks, > > rui > > > > > > > > > > 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(-) > > > > > > > > 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 */ > > > > > > > > /* no idea where these constants come from */ Regarding the line above, I believe the constant comes from the documentation. > > > > -#define TJ_3 -41 > > > > +#define TJ_3 41 > > > > > > > > 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 = (FIXPT_INT((ptat[1] - ptat[2]) * 157) > > > > - / (ptat[0] - ptat[2])) + FIXPT_INT(TJ_3); > > > > + / (ptat[0] - ptat[2])) - FIXPT_INT(TJ_3); > > > > > > > > tsc->coef.a1 = FIXPT_DIV(FIXPT_INT(thcode[1] - thcode[2]), > > > > - tsc->tj_t - FIXPT_INT(TJ_3)); > > > > - tsc->coef.b1 = FIXPT_INT(thcode[2]) - tsc->coef.a1 * TJ_3; > > > > + tsc->tj_t + FIXPT_INT(TJ_3)); > > > > + tsc->coef.b1 = FIXPT_INT(thcode[2]) + tsc->coef.a1 * TJ_3; > > > > > > > > tsc->coef.a2 = FIXPT_DIV(FIXPT_INT(thcode[1] - thcode[0]), > > > > tsc->tj_t - FIXPT_INT(ths_tj_1)); > > > > > > > > > > > >