Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp557513ybl; Wed, 28 Aug 2019 01:54:44 -0700 (PDT) X-Google-Smtp-Source: APXvYqzEfJQea49rzBz69B9JS49ZTHzBaRlUnmyu4Jhj9DoIhsAK8t9dnqCQQ5aPOgnu2IcYaMuK X-Received: by 2002:a62:63c1:: with SMTP id x184mr3466426pfb.11.1566982484066; Wed, 28 Aug 2019 01:54:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566982484; cv=none; d=google.com; s=arc-20160816; b=h0Mgi7GEMuPa4un4kWYpZg+mZE0Dj/ZhzNiGykwM0toKWJ6qEJXSTK7GsJ0A4DEvgW by+rzLs/7acIvI6LGw0JUzCJlj9EYBfPz9s/bUkKonEgrHi9ZSUKGfGmi9NYGigeOaH0 8l3NQNtM3TzKpNZL17TwkE9+RrXEggBpKjxZCMlLzv9dy8DHOMbDhMRSxeWsxxRD92Qk at77llvkL1deL3PEJgkk3fn2WfxF6FNTYntW2wqRBSIRkN60u3+xpx+Od8i9LPcLYECp aQ3zJsKzNO1zSFZhSEsdYNXbXEgrG1gnsKcjocZurxxcLLu08UmL1aWC4IWLGH6eQ3Qc 5CVQ== 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 :references:in-reply-to:date:cc:to:from:subject:message-id; bh=s5cgXyjG1tJkW8ICzmceM+Fhyx5SXvHbqUwyvd8+ipA=; b=HckyD/8aDVCK3EqS1ssEDKLQmj6vQJXQ4dCQOMuetfMJ3anNi+hP1YBd2jsqViQ3oT 7dgb3AJrJ0g/iPDBt1JMJzglJlJIBJtLUzq4f+Y/chXMwnC3n6sEu6lTThkGGi1S8peu RyQ0pUqWligsCCiFvg8APmK4o0eiZ3lRm8xvtfIOuRb+c3QnpKj26OP5aUoyGcnMfTKx hmWJT67xCIPDoO6A/pZO/e6tk2Fur5lO0eSfleCjywSA3O2PgzMe+HR/E1TG5e5YXKW/ JgSIeP7oJoYuIH0ZfjdqtQfRSSpiCeNERekbTbtmvzpZrq9UOzCaxWmXOVBDxecHQOIf qjJQ== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 139si1900663pfc.3.2019.08.28.01.54.27; Wed, 28 Aug 2019 01:54:44 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726618AbfH1IwQ (ORCPT + 99 others); Wed, 28 Aug 2019 04:52:16 -0400 Received: from mga11.intel.com ([192.55.52.93]:20965 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726566AbfH1IwP (ORCPT ); Wed, 28 Aug 2019 04:52:15 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 28 Aug 2019 01:52:15 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,440,1559545200"; d="scan'208";a="183060632" Received: from deyangko-mobl.ccr.corp.intel.com ([10.249.168.35]) by orsmga003.jf.intel.com with ESMTP; 28 Aug 2019 01:52:12 -0700 Message-ID: <82458318837ed1154a183be0b96337fc7809c645.camel@intel.com> Subject: Re: [PATCH] thermal: rcar_gen3_thermal: Fix Wshift-negative-value From: Zhang Rui To: Daniel Lezcano , Nathan Huckleberry , edubezval@gmail.com Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, clang-built-linux@googlegroups.com, Yoshihiro Kaneko , wsa+renesas@sang-engineering.com Date: Wed, 28 Aug 2019 16:52:20 +0800 In-Reply-To: References: <20190613211228.34092-1-nhuck@google.com> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.28.5-0ubuntu0.18.04.1 Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. 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 */ > > -#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)); > > > >