Skip to contentSkip to conversation

arch/mips: remove duplicate structure field initialization

PATCH In review Julia Lawall 3 participants 6 messages Sep 21, 2009 – Sep 23, 2009

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 arch/mips: remove duplicate structure field initialization

From: Julia Lawall <[email protected]>

The definition of the irq_ipi structure has two initializations of the flags field. This combines them.

The semantic match that finds this problem is as follows:
(http://coccinelle.lip6.fr/)

// <smpl>
@r@
identifier I, s, fld;
position p0,p;
expression E;
@@

struct I s =@p0 { ... .fld@p = E, ...};

@s@
identifier I, s, r.fld;
position r.p0,p;
expression E;
@@

struct I s =@p0 { ... .fld@p = E, ...};

@script:python@
p0 << r.p0;
fld << r.fld;
ps << s.p;
pr << r.p;
@@

if int(ps[0].line)!=int(pr[0].line) or int(ps[0].column)!=int(pr[0].column):
cocci.print_main(fld,p0)
// </smpl>

---
 arch/mips/kernel/smtc.c             |    5 ++---
 1 files changed, 2 insertions(+), 3 deletions(-)
arch/mips/kernel/smtc.c +2 -3
index 67153a0..4d181df 100644
@@ -1098,9 +1098,8 @@ static void ipi_irq_dispatch(void)
 
 static struct irqaction irq_ipi = {
 	.handler	= ipi_interrupt,
-	.flags		= IRQF_DISABLED,
-	.name		= "SMTC_IPI",
-	.flags		= IRQF_PERCPU
+	.flags		= IRQF_DISABLED | IRQF_PERCPU,
+	.name		= "SMTC_IPI"
 };
 
 static void setup_cross_vpe_interrupts(unsigned int nvpe)
#1 lore raw

On Mon, Sep 21, 2009 at 05:08:55PM +0200, Julia Lawall wrote:

Adding Kevin "SMTC Kissel to cc.

Quoted 48 lines

From: Julia Lawall <[email protected]>

The definition of the irq_ipi structure has two initializations of the flags field. This combines them.

The semantic match that finds this problem is as follows:
(http://coccinelle.lip6.fr/)

// <smpl>
@r@
identifier I, s, fld;
position p0,p;
expression E;
@@

struct I s =@p0 { ... .fld@p = E, ...};

@s@
identifier I, s, r.fld;
position r.p0,p;
expression E;
@@

struct I s =@p0 { ... .fld@p = E, ...};

@script:python@
p0 << r.p0;
fld << r.fld;
ps << s.p;
pr << r.p;
@@

if int(ps[0].line)!=int(pr[0].line) or int(ps[0].column)!=int(pr[0].column):
cocci.print_main(fld,p0)
// </smpl>

---
 arch/mips/kernel/smtc.c             |    5 ++---
 1 files changed, 2 insertions(+), 3 deletions(-)
arch/mips/kernel/smtc.c +0 -0
index 67153a0..4d181df 100644
@@ -1098,9 +1098,8 @@ static void ipi_irq_dispatch(void)
 

arch/mips/kernel/smtc.c static void ipi_irq_dispatch(void) · line 1105

Quoted 10 lines
arch/mips/kernel/smtc.c +2 -3
 static struct irqaction irq_ipi = {
 	.handler	= ipi_interrupt,
-	.flags		= IRQF_DISABLED,
-	.name		= "SMTC_IPI",
-	.flags		= IRQF_PERCPU
+	.flags		= IRQF_DISABLED | IRQF_PERCPU,
+	.name		= "SMTC_IPI"
 };
 
 static void setup_cross_vpe_interrupts(unsigned int nvpe)

The actual semantic of this code as implemented by gcc is that all but the last initializer are ignored so until somebody actually tests your code I'll just remove the first of the two initializers and put a comment there.

Ralf

#2 lore raw

I'm still on the mailing list, and had seen this going by. I'm not sure where that second .flags declaration got added. Way, way back when I was pretty much the only maintainer of the file, irq_ipi.flags was explicitly initialized to IRQF_DISABLED by an actual assignment statement in setp_cross_vpe_interrupts(), and the per-CPUness was handled by an "irq_desc[cpu_ipi_irq].status |= IRQ_PER_CPU". My guess is that first someone (maybe me) migrated the IRQF_DISABLED assignment into the declaration of the struct, and that later someone found the IRQ_PER_CPU thing bogus or deprecated and converted it into a second .flags line in the struct declaration, missing the fact that there was already one there.

In any case, I'm willing to sign off on Julia's patch. It's certainly more important that the IRQ be PER_CPU than initially DISABLED, but during the time when SMTC was seeing its heaviest testing at MIPS, both attributes were true.

Regards,

Kevin K.

Quoted 71 lines · Ralf Baechle

On Mon, Sep 21, 2009 at 05:08:55PM +0200, Julia Lawall wrote:

Adding Kevin "SMTC Kissel to cc.

Quoted 49 lines

From: Julia Lawall <[email protected]>

The definition of the irq_ipi structure has two initializations of the flags field. This combines them.

The semantic match that finds this problem is as follows:
(http://coccinelle.lip6.fr/)

// <smpl>
@r@
identifier I, s, fld;
position p0,p;
expression E;
@@

struct I s =@p0 { ... .fld@p = E, ...};

@s@
identifier I, s, r.fld;
position r.p0,p;
expression E;
@@

struct I s =@p0 { ... .fld@p = E, ...};

@script:python@
p0 << r.p0;
fld << r.fld;
ps << s.p;
pr << r.p;
@@

if int(ps[0].line)!=int(pr[0].line) or int(ps[0].column)!=int(pr[0].column):
cocci.print_main(fld,p0)
// </smpl>

---
 arch/mips/kernel/smtc.c             |    5 ++---
 1 files changed, 2 insertions(+), 3 deletions(-)
arch/mips/kernel/smtc.c +0 -0
index 67153a0..4d181df 100644
@@ -1098,9 +1098,8 @@ static void ipi_irq_dispatch(void)
 

arch/mips/kernel/smtc.c static void ipi_irq_dispatch(void) · line 1105

Quoted 10 lines
arch/mips/kernel/smtc.c +2 -3
 static struct irqaction irq_ipi = {
 	.handler	= ipi_interrupt,
-	.flags		= IRQF_DISABLED,
-	.name		= "SMTC_IPI",
-	.flags		= IRQF_PERCPU
+	.flags		= IRQF_DISABLED | IRQF_PERCPU,
+	.name		= "SMTC_IPI"
 };
 
 static void setup_cross_vpe_interrupts(unsigned int nvpe)

The actual semantic of this code as implemented by gcc is that all but the last initializer are ignored so until somebody actually tests your code I'll just remove the first of the two initializers and put a comment there.

Ralf

#3 lore raw

Ha! Found the breakage. It wasn't a two-phase commit. It was just an overworked mantainer in a hurry, in July 2007. See commit 033890b084adfa367c544864451d7730552ce8bf

Regards,

Kevin K.

Quoted 98 lines · Kevin D. Kissell

I'm still on the mailing list, and had seen this going by. I'm not sure where that second .flags declaration got added. Way, way back when I was pretty much the only maintainer of the file, irq_ipi.flags was explicitly initialized to IRQF_DISABLED by an actual assignment statement in setp_cross_vpe_interrupts(), and the per-CPUness was handled by an "irq_desc[cpu_ipi_irq].status |= IRQ_PER_CPU". My guess is that first someone (maybe me) migrated the IRQF_DISABLED assignment into the declaration of the struct, and that later someone found the IRQ_PER_CPU thing bogus or deprecated and converted it into a second .flags line in the struct declaration, missing the fact that there was already one there.

In any case, I'm willing to sign off on Julia's patch. It's certainly more important that the IRQ be PER_CPU than initially DISABLED, but during the time when SMTC was seeing its heaviest testing at MIPS, both attributes were true.

Regards,

Kevin K.

Quoted 74 lines · Ralf Baechle

On Mon, Sep 21, 2009 at 05:08:55PM +0200, Julia Lawall wrote:

Adding Kevin "SMTC Kissel to cc.

Quoted 50 lines

From: Julia Lawall <[email protected]>

The definition of the irq_ipi structure has two initializations of the flags field. This combines them.

The semantic match that finds this problem is as follows:
(http://coccinelle.lip6.fr/)

// <smpl>
@r@
identifier I, s, fld;
position p0,p;
expression E;
@@

struct I s =@p0 { ... .fld@p = E, ...};

@s@
identifier I, s, r.fld;
position r.p0,p;
expression E;
@@

struct I s =@p0 { ... .fld@p = E, ...};

@script:python@
p0 << r.p0;
fld << r.fld;
ps << s.p;
pr << r.p;
@@

if int(ps[0].line)!=int(pr[0].line) or
int(ps[0].column)!=int(pr[0].column):
cocci.print_main(fld,p0)
// </smpl>

---
 arch/mips/kernel/smtc.c             |    5 ++---
 1 files changed, 2 insertions(+), 3 deletions(-)
arch/mips/kernel/smtc.c +0 -0
index 67153a0..4d181df 100644
@@ -1098,9 +1098,8 @@ static void ipi_irq_dispatch(void)
 

arch/mips/kernel/smtc.c static void ipi_irq_dispatch(void) · line 1105

Quoted 10 lines
arch/mips/kernel/smtc.c +2 -3
 static struct irqaction irq_ipi = {
     .handler    = ipi_interrupt,
-    .flags        = IRQF_DISABLED,
-    .name        = "SMTC_IPI",
-    .flags        = IRQF_PERCPU
+    .flags        = IRQF_DISABLED | IRQF_PERCPU,
+    .name        = "SMTC_IPI"
 };
 
 static void setup_cross_vpe_interrupts(unsigned int nvpe)

The actual semantic of this code as implemented by gcc is that all but the
last initializer are ignored so until somebody actually tests your code I'll just remove the first of the two initializers and put a comment there.

Ralf

#4 lore raw
Quoted 3 lines · Kevin D. Kissell

Ha! Found the breakage. It wasn't a two-phase commit. It was just an overworked mantainer in a hurry, in July 2007. See commit 033890b084adfa367c544864451d7730552ce8bf

An overworked maintainer in cooperation with a broken compiler. Worse - it's not the first time this type of bug strikes but probably this was never brought to the gcc maintainers' attention.

Ralf

#5 lore raw
In reply to Kevin D. Kissell
Quoted 12 lines · Kevin D. Kissell

I'm still on the mailing list, and had seen this going by. I'm not sure where that second .flags declaration got added. Way, way back when I was pretty much the only maintainer of the file, irq_ipi.flags was explicitly initialized to IRQF_DISABLED by an actual assignment statement in setp_cross_vpe_interrupts(), and the per-CPUness was handled by an "irq_desc[cpu_ipi_irq].status |= IRQ_PER_CPU". My guess is that first someone (maybe me) migrated the IRQF_DISABLED assignment into the declaration of the struct, and that later someone found the IRQ_PER_CPU thing bogus or deprecated and converted it into a second .flags line in the struct declaration, missing the fact that there was already one there.

Quoted 4 lines

In any case, I'm willing to sign off on Julia's patch. It's certainly more important that the IRQ be PER_CPU than initially DISABLED, but during the time when SMTC was seeing its heaviest testing at MIPS, both attributes were true.

I've reverted my patch and merged Julia's original patch with an extra comment added.

Thanks Julia,

Ralf