All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] genirq: Make - vs ?: precedence explicit
@ 2017-11-22 20:56 Kees Cook
  2017-11-23 19:13 ` [tip:irq/urgent] genirq/matrix: Make - vs ?: Precedence explicit tip-bot for Kees Cook
  2017-11-28 12:19 ` [PATCH] genirq: Make - vs ?: precedence explicit Rasmus Villemoes
  0 siblings, 2 replies; 4+ messages in thread
From: Kees Cook @ 2017-11-22 20:56 UTC (permalink / raw)
  To: Thomas Gleixner; +Cc: linux-kernel

Noticed with a Clang build. This improves the readability of the ?:
expression, as it has lower precedence than the - expression. Show
explicitly that - is evaluated first.

Cc: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Kees Cook <keescook@chromium.org>
---
 kernel/irq/matrix.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/irq/matrix.c b/kernel/irq/matrix.c
index a3cbbc8191c5..7df2480005f8 100644
--- a/kernel/irq/matrix.c
+++ b/kernel/irq/matrix.c
@@ -384,7 +384,7 @@ unsigned int irq_matrix_available(struct irq_matrix *m, bool cpudown)
 {
 	struct cpumap *cm = this_cpu_ptr(m->maps);
 
-	return m->global_available - cpudown ? cm->available : 0;
+	return (m->global_available - cpudown) ? cm->available : 0;
 }
 
 /**
-- 
2.7.4


-- 
Kees Cook
Pixel Security

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

* [tip:irq/urgent] genirq/matrix: Make - vs ?: Precedence explicit
  2017-11-22 20:56 [PATCH] genirq: Make - vs ?: precedence explicit Kees Cook
@ 2017-11-23 19:13 ` tip-bot for Kees Cook
  2017-11-28 12:19 ` [PATCH] genirq: Make - vs ?: precedence explicit Rasmus Villemoes
  1 sibling, 0 replies; 4+ messages in thread
From: tip-bot for Kees Cook @ 2017-11-23 19:13 UTC (permalink / raw)
  To: linux-tip-commits; +Cc: keescook, mingo, hpa, tglx, linux-kernel

Commit-ID:  75f1133873d6a1276d3c19918b7c94975840f990
Gitweb:     https://git.kernel.org/tip/75f1133873d6a1276d3c19918b7c94975840f990
Author:     Kees Cook <keescook@chromium.org>
AuthorDate: Wed, 22 Nov 2017 12:56:45 -0800
Committer:  Thomas Gleixner <tglx@linutronix.de>
CommitDate: Thu, 23 Nov 2017 20:09:31 +0100

genirq/matrix: Make - vs ?: Precedence explicit

Noticed with a Clang build. This improves the readability of the ?:
expression, as it has lower precedence than the - expression. Show
explicitly that - is evaluated first.

Signed-off-by: Kees Cook <keescook@chromium.org>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Link: https://lkml.kernel.org/r/20171122205645.GA27125@beast
---
 kernel/irq/matrix.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/irq/matrix.c b/kernel/irq/matrix.c
index a3cbbc8..7df2480 100644
--- a/kernel/irq/matrix.c
+++ b/kernel/irq/matrix.c
@@ -384,7 +384,7 @@ unsigned int irq_matrix_available(struct irq_matrix *m, bool cpudown)
 {
 	struct cpumap *cm = this_cpu_ptr(m->maps);
 
-	return m->global_available - cpudown ? cm->available : 0;
+	return (m->global_available - cpudown) ? cm->available : 0;
 }
 
 /**

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

* Re: [PATCH] genirq: Make - vs ?: precedence explicit
  2017-11-22 20:56 [PATCH] genirq: Make - vs ?: precedence explicit Kees Cook
  2017-11-23 19:13 ` [tip:irq/urgent] genirq/matrix: Make - vs ?: Precedence explicit tip-bot for Kees Cook
@ 2017-11-28 12:19 ` Rasmus Villemoes
  2017-11-28 13:43   ` Thomas Gleixner
  1 sibling, 1 reply; 4+ messages in thread
From: Rasmus Villemoes @ 2017-11-28 12:19 UTC (permalink / raw)
  To: Kees Cook, Thomas Gleixner; +Cc: linux-kernel

On 2017-11-22 21:56, Kees Cook wrote:
> Noticed with a Clang build. This improves the readability of the ?:
> expression, as it has lower precedence than the - expression. Show
> explicitly that - is evaluated first.
> 
> Cc: Thomas Gleixner <tglx@linutronix.de>
> Signed-off-by: Kees Cook <keescook@chromium.org>
> ---
>  kernel/irq/matrix.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/kernel/irq/matrix.c b/kernel/irq/matrix.c
> index a3cbbc8191c5..7df2480005f8 100644
> --- a/kernel/irq/matrix.c
> +++ b/kernel/irq/matrix.c
> @@ -384,7 +384,7 @@ unsigned int irq_matrix_available(struct irq_matrix *m, bool cpudown)
>  {
>  	struct cpumap *cm = this_cpu_ptr(m->maps);
>  
> -	return m->global_available - cpudown ? cm->available : 0;
> +	return (m->global_available - cpudown) ? cm->available : 0;
>  }

I see that this got applied, and that doesn't change the semantics of
the code. But surely the code is and was buggy, right? From the kernel
doc, I'm pretty sure the idea is to subtract cm->available if cpudown is
true, otherwise subtract 0, i.e.

  return m->global_available - (cpudown ? cm->available : 0);

Rasmus

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

* Re: [PATCH] genirq: Make - vs ?: precedence explicit
  2017-11-28 12:19 ` [PATCH] genirq: Make - vs ?: precedence explicit Rasmus Villemoes
@ 2017-11-28 13:43   ` Thomas Gleixner
  0 siblings, 0 replies; 4+ messages in thread
From: Thomas Gleixner @ 2017-11-28 13:43 UTC (permalink / raw)
  To: Rasmus Villemoes; +Cc: Kees Cook, linux-kernel

On Tue, 28 Nov 2017, Rasmus Villemoes wrote:
> On 2017-11-22 21:56, Kees Cook wrote:
> > Noticed with a Clang build. This improves the readability of the ?:
> > expression, as it has lower precedence than the - expression. Show
> > explicitly that - is evaluated first.
> > 
> > Cc: Thomas Gleixner <tglx@linutronix.de>
> > Signed-off-by: Kees Cook <keescook@chromium.org>
> > ---
> >  kernel/irq/matrix.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/kernel/irq/matrix.c b/kernel/irq/matrix.c
> > index a3cbbc8191c5..7df2480005f8 100644
> > --- a/kernel/irq/matrix.c
> > +++ b/kernel/irq/matrix.c
> > @@ -384,7 +384,7 @@ unsigned int irq_matrix_available(struct irq_matrix *m, bool cpudown)
> >  {
> >  	struct cpumap *cm = this_cpu_ptr(m->maps);
> >  
> > -	return m->global_available - cpudown ? cm->available : 0;
> > +	return (m->global_available - cpudown) ? cm->available : 0;
> >  }
> 
> I see that this got applied, and that doesn't change the semantics of
> the code. But surely the code is and was buggy, right? From the kernel
> doc, I'm pretty sure the idea is to subtract cm->available if cpudown is
> true, otherwise subtract 0, i.e.
> 
>   return m->global_available - (cpudown ? cm->available : 0);

Yes, you are right. I completely misread it when I merged that patch. Good
catch!

Thanks,

	tglx

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

end of thread, other threads:[~2017-11-28 13:43 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-11-22 20:56 [PATCH] genirq: Make - vs ?: precedence explicit Kees Cook
2017-11-23 19:13 ` [tip:irq/urgent] genirq/matrix: Make - vs ?: Precedence explicit tip-bot for Kees Cook
2017-11-28 12:19 ` [PATCH] genirq: Make - vs ?: precedence explicit Rasmus Villemoes
2017-11-28 13:43   ` Thomas Gleixner

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.