Skip to contentSkip to conversation

arch/um: remove duplicate structure field initialization

PATCH Applied Julia Lawall 3 participants 4 messages Sep 19, 2009 – Sep 22, 2009

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

PATCH 5/5 arch/um: remove duplicate structure field initialization

From: Julia Lawall <[email protected]>

The definition of uml_netdev_ops has initializations of a local function and eth_mac_addr for its ndo_set_mac_address field. This change uses only the local function.

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/um/drivers/net_kern.c          |    1 -
 1 files changed, 0 insertions(+), 1 deletions(-)
arch/um/drivers/net_kern.c +0 -1
index a74245a..d17a623 100644
@@ -379,7 +379,6 @@ static const struct net_device_ops uml_netdev_ops = {
 	.ndo_tx_timeout 	= uml_net_tx_timeout,
 	.ndo_set_mac_address	= uml_net_set_mac,
 	.ndo_change_mtu 	= uml_net_change_mtu,
-	.ndo_set_mac_address 	= eth_mac_addr,
 	.ndo_validate_addr	= eth_validate_addr,
 };
 
Acked-by on v1 5/5
#1 lore raw
Quoted 33 lines · Julia Lawall

From: Julia Lawall <[email protected]>

The definition of uml_netdev_ops has initializations of a local function and eth_mac_addr for its ndo_set_mac_address field. This change uses only the local function.

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;
@@

Quoted 3 lines

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

Hmm, C99 said:
"
The initialization shall occur in initializer list order, each initializer provided for a particular subobject overriding any previously listed initializer for the same subobject [...] "

I am wondering why gcc doesn't (can't?) complain about this?

Quoted 3 lines
Quoted 20 lines

---
arch/um/drivers/net_kern.c | 1 -

1 files changed, 0 insertions(+), 1 deletions(-)
arch/um/drivers/net_kern.c +0 -2
index a74245a..d17a623 100644
@@ -379,7 +379,6 @@ static const struct net_device_ops uml_netdev_ops = {
 	.ndo_tx_timeout 	= uml_net_tx_timeout,
 	.ndo_set_mac_address	= uml_net_set_mac,
 	.ndo_change_mtu 	= uml_net_change_mtu,
-	.ndo_set_mac_address 	= eth_mac_addr,
 	.ndo_validate_addr	= eth_validate_addr,
 };
 
--

To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

Signature · 1 line
Live like a child, think like the god.
#2 lore raw
Quoted 7 lines

"
The initialization shall occur in initializer list order, each initializer provided for a particular subobject overriding any previously listed initializer for the same subobject [...] "

I am wondering why gcc doesn't (can't?) complain about this?

Does -Woverride-init (included in -Wextra / -W) not work? If so, please file a bug report.

Thanks,

Segher

#3 lore raw
Quoted 10 lines · Segher Boessenkool
Quoted 7 lines

"
The initialization shall occur in initializer list order, each initializer provided for a particular subobject overriding any previously listed initializer for the same subobject [...] "

I am wondering why gcc doesn't (can't?) complain about this?

Does -Woverride-init (included in -Wextra / -W) not work?  If so, please file a bug report.

Hmm, right, it works, but it seems that Linux kernel doesn't use it. Maybe we should add it? :-/
--
To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html