linux-pm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] thermal: rcar_gen3_thermal: Fix Wshift-negative-value
@ 2019-06-13 21:12 Nathan Huckleberry
  2019-06-14 10:52 ` Daniel Lezcano
  0 siblings, 1 reply; 6+ messages in thread
From: Nathan Huckleberry @ 2019-06-13 21:12 UTC (permalink / raw)
  To: rui.zhang, edubezval, daniel.lezcano
  Cc: linux-pm, linux-kernel, Nathan Huckleberry, clang-built-linux

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.

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 <nhuck@google.com>
---
 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));
-- 
2.22.0.rc2.383.gf4fbbf30c2-goog


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] thermal: rcar_gen3_thermal: Fix Wshift-negative-value
  2019-06-13 21:12 [PATCH] thermal: rcar_gen3_thermal: Fix Wshift-negative-value Nathan Huckleberry
@ 2019-06-14 10:52 ` Daniel Lezcano
  2019-08-13 20:12   ` Nathan Huckleberry
  2019-08-28  8:52   ` Zhang Rui
  0 siblings, 2 replies; 6+ messages in thread
From: Daniel Lezcano @ 2019-06-14 10:52 UTC (permalink / raw)
  To: Nathan Huckleberry, rui.zhang, edubezval
  Cc: linux-pm, linux-kernel, clang-built-linux, Yoshihiro Kaneko


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.


> 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 <nhuck@google.com>
> ---
>  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));
> 


-- 
 <http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs

Follow Linaro:  <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] thermal: rcar_gen3_thermal: Fix Wshift-negative-value
  2019-06-14 10:52 ` Daniel Lezcano
@ 2019-08-13 20:12   ` Nathan Huckleberry
  2019-08-28  8:52   ` Zhang Rui
  1 sibling, 0 replies; 6+ messages in thread
From: Nathan Huckleberry @ 2019-08-13 20:12 UTC (permalink / raw)
  To: Daniel Lezcano
  Cc: rui.zhang, edubezval, linux-pm, linux-kernel, clang-built-linux,
	Yoshihiro Kaneko

I'm not familiar enough with the code to rewrite these parts of the
driver. Silencing the warnings while maintaining the same
functionality was the goal of this patch.

On Fri, Jun 14, 2019 at 3:52 AM Daniel Lezcano
<daniel.lezcano@linaro.org> 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.
>
>
> > 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 <nhuck@google.com>
> > ---
> >  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));
> >
>
>
> --
>  <http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs
>
> Follow Linaro:  <http://www.facebook.com/pages/Linaro> Facebook |
> <http://twitter.com/#!/linaroorg> Twitter |
> <http://www.linaro.org/linaro-blog/> Blog
>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] thermal: rcar_gen3_thermal: Fix Wshift-negative-value
  2019-06-14 10:52 ` Daniel Lezcano
  2019-08-13 20:12   ` Nathan Huckleberry
@ 2019-08-28  8:52   ` Zhang Rui
  2019-08-29 13:11     ` Wolfram Sang
  1 sibling, 1 reply; 6+ messages in thread
From: Zhang Rui @ 2019-08-28  8:52 UTC (permalink / raw)
  To: Daniel Lezcano, Nathan Huckleberry, edubezval
  Cc: linux-pm, linux-kernel, clang-built-linux, Yoshihiro Kaneko, wsa+renesas

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 <nhuck@google.com>
> > ---
> >  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));
> > 
> 
> 


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] thermal: rcar_gen3_thermal: Fix Wshift-negative-value
  2019-08-28  8:52   ` Zhang Rui
@ 2019-08-29 13:11     ` Wolfram Sang
  2019-08-31  7:40       ` Simon Horman
  0 siblings, 1 reply; 6+ messages in thread
From: Wolfram Sang @ 2019-08-29 13:11 UTC (permalink / raw)
  To: Zhang Rui, Simon Horman
  Cc: Daniel Lezcano, Nathan Huckleberry, edubezval, linux-pm,
	linux-kernel, clang-built-linux, Yoshihiro Kaneko, wsa+renesas

[-- Attachment #1: Type: text/plain, Size: 4129 bytes --]

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.

> 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 <nhuck@google.com>
> > > ---
> > >  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));
> > > 
> > 
> > 
> 

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] thermal: rcar_gen3_thermal: Fix Wshift-negative-value
  2019-08-29 13:11     ` Wolfram Sang
@ 2019-08-31  7:40       ` Simon Horman
  0 siblings, 0 replies; 6+ messages in thread
From: Simon Horman @ 2019-08-31  7:40 UTC (permalink / raw)
  To: Wolfram Sang
  Cc: Zhang Rui, Daniel Lezcano, Nathan Huckleberry, edubezval,
	linux-pm, linux-kernel, clang-built-linux, Yoshihiro Kaneko,
	wsa+renesas

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 <nhuck@google.com>
> > > > ---
> > > >  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));
> > > > 
> > > 
> > > 
> > 



^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2019-08-31  7:40 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-13 21:12 [PATCH] thermal: rcar_gen3_thermal: Fix Wshift-negative-value Nathan Huckleberry
2019-06-14 10:52 ` Daniel Lezcano
2019-08-13 20:12   ` Nathan Huckleberry
2019-08-28  8:52   ` Zhang Rui
2019-08-29 13:11     ` Wolfram Sang
2019-08-31  7:40       ` Simon Horman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).