Coccicheck: Remove memcpy to struct assignment test
Subsystems (2)
PATCH 1/1 Coccicheck: Remove memcpy to struct assignment test
The Coccinelle script scripts/coccinelle/misc/memcpy-assign.cocci look for opportunities to replace a call to memcpy by a struct assignment. This patch removes memcpy-assign.cocci as it is not clear that this convention has an impact on the generated code.
--- scripts/coccinelle/misc/memcpy-assign.cocci | 103 ---------------------------- 1 file changed, 103 deletions(-) delete mode 100644 scripts/coccinelle/misc/memcpy-assign.cocci
scripts/coccinelle/misc/memcpy-assign.cocci deleted +0 -103
@@ -1,103 +0,0 @@ -// -// Replace memcpy with struct assignment. -// -// Confidence: High -// Copyright: (C) 2012 Peter Senna Tschudin, INRIA/LIP6. GPLv2. -// URL: http://coccinelle.lip6.fr/ -// Comments: -// Options: --no-includes --include-headers - -virtual patch -virtual report -virtual context -virtual org - - at r1 depends on !patch@ -identifier struct_name; -struct struct_name to; -struct struct_name from; -struct struct_name *top; -struct struct_name *fromp; -position p; -@@ -memcpy at p(\(&(to)\|top\), \(&(from)\|fromp\), \(sizeof(to)\|sizeof(from)\|sizeof(struct struct_name)\|sizeof(*top)\|sizeof(*fromp)\)) - - at script:python depends on report@ -p << r1.p; -@@ -coccilib.report.print_report(p[0],"Replace memcpy with struct assignment") - - at depends on context@ -position r1.p; -@@ -*memcpy at p(...); - - at script:python depends on org@ -p << r1.p; -@@ -cocci.print_main("Replace memcpy with struct assignment",p) - - at depends on patch@ -identifier struct_name; -struct struct_name to; -struct struct_name from; -@@ -( --memcpy(&(to), &(from), sizeof(to)); -+to = from; -| --memcpy(&(to), &(from), sizeof(from)); -+to = from; -| --memcpy(&(to), &(from), sizeof(struct struct_name)); -+to = from; -) - - at depends on patch@ -identifier struct_name; -struct struct_name to; -struct struct_name *from; -@@ -( --memcpy(&(to), from, sizeof(to)); -+to = *from; -| --memcpy(&(to), from, sizeof(*from)); -+to = *from; -| --memcpy(&(to), from, sizeof(struct struct_name)); -+to = *from; -) - - at depends on patch@ -identifier struct_name; -struct struct_name *to; -struct struct_name from; -@@ -( --memcpy(to, &(from), sizeof(*to)); -+ *to = from; -| --memcpy(to, &(from), sizeof(from)); -+ *to = from; -| --memcpy(to, &(from), sizeof(struct struct_name)); -+ *to = from; -) - -@depends on patch@ -identifier struct_name; -struct struct_name *to; -struct struct_name *from; -@@ -( --memcpy(to, from, sizeof(*to)); -+ *to = *from; -| --memcpy(to, from, sizeof(*from)); -+ *to = *from; -| --memcpy(to, from, sizeof(struct struct_name)); -+ *to = *from; -) -
Signature · 1 line
1.8.3.1
Quoted 4 lines · Peter Senna Tschudin
The Coccinelle script
scripts/coccinelle/misc/memcpy-assign.coccilook for opportunities to replace a call to memcpy by a struct assignment. This patch removesmemcpy-assign.coccias it is not clear that this convention has an impact on the generated code.
Using struct assignment keeps the type check and is just for this reason always preferable over memcpy().
Kind regards,
Bernd
Signature · 2 lines
Bernd Petrovitsch Email : bernd at petrovitsch.priv.at
LUGA : http://www.luga.atQuoted 8 lines · Bernd Petrovitsch
Quoted 4 lines · Peter Senna Tschudin
The Coccinelle script
scripts/coccinelle/misc/memcpy-assign.coccilook for opportunities to replace a call to memcpy by a struct assignment. This patch removesmemcpy-assign.coccias it is not clear that this convention has an impact on the generated code.Using struct assignment keeps the type check and is just for this reason always preferable over
memcpy().
What about the assignment hiding that a potentially large memcpy is happening instead of just a pointer assignment?
Quoted 7 lines
Kind regards,
Bernd
--
Bernd Petrovitsch Email : bernd at petrovitsch.priv.at
LUGA : http://www.luga.at
Signature · 1 line
Peter
Hi!
Quoted 8 lines · Peter Senna Tschudin
Quoted 6 lines · Bernd Petrovitsch
Quoted 4 lines · Peter Senna Tschudin
The Coccinelle script
scripts/coccinelle/misc/memcpy-assign.coccilook for opportunities to replace a call to memcpy by a struct assignment. This patch removesmemcpy-assign.coccias it is not clear that this convention has an impact on the generated code.
Quoted 4 lines
Quoted 2 lines
Using struct assignment keeps the type check and is just for this reason always preferable over
memcpy().What about the assignment hiding that a potentially large memcpy is happening instead of just a pointer assignment?
It makes no difference if you copy 2KB with a struct assignment or with a memcpy(). IMHO most probably each and every C compiler produces the same code for both cases.
And - more important - I assume that people which actually read the code (to understand the code) also know if the variables there are pointers/ints or a (somewhat large) struct (if only one see an field access in the struct, it should be pretty clear).
I don't think it makes actually much sense trying to read source without that ....
Bernd
Signature · 2 lines
Bernd Petrovitsch Email : bernd at petrovitsch.priv.at
LUGA : http://www.luga.atQuoted 11 lines · Bernd Petrovitsch
Hi!
Quoted 8 lines · Peter Senna Tschudin
Quoted 6 lines · Bernd Petrovitsch
Quoted 4 lines · Peter Senna Tschudin
The Coccinelle script
scripts/coccinelle/misc/memcpy-assign.coccilook for opportunities to replace a call to memcpy by a struct assignment. This patch removesmemcpy-assign.coccias it is not clear that this convention has an impact on the generated code.
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines
Using struct assignment keeps the type check and is just for this reason always preferable over
memcpy().What about the assignment hiding that a potentially large memcpy is happening instead of just a pointer assignment?
It makes no difference if you copy 2KB with a struct assignment or with a
memcpy(). IMHO most probably each and every C compiler produces the same code for both cases.
Really? We have a much different memcpy() function than gcc provides for some arches.
Quoted 6 lines
And - more important - I assume that people which actually read the code (to understand the code) also know if the variables there are pointers/ints or a (somewhat large) struct (if only one see an field access in the struct, it should be pretty clear).
I don't think it makes actually much sense trying to read source without that ....
You want to make it painfully obvious exactly what the code is doing so that I can fix your bugs. And you can fix mine. If I see two variables being assigned to each other I'll initially assume that they are just pointers and not care about them. But if it's doing a 64Kb memcpy, maybe that's not a good thing to be doing at that point in the code.
That's why I don't like these "implicit" memcpy() calls, it hides what is going on for no good reason.
Can someone please just remove the check from the kernel as I'm getting tired of rejecting patches that do this...
thanks,
greg k-h
Dne 19.3.2014 17:48, Greg Kroah-Hartman napsal(a):
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines · Peter Senna Tschudin
Quoted 4 lines
The Coccinelle script
scripts/coccinelle/misc/memcpy-assign.coccilook for opportunities to replace a call to memcpy by a struct assignment. This patch removesmemcpy-assign.coccias it is not clear that this convention has an impact on the generated code.
[...]
Quoted 2 lines
Can someone please just remove the check from the kernel as I'm getting tired of rejecting patches that do this...
I just applied Peter's revert to kbuild.git#misc.
Michal