* [PATCH] Coccicheck: Remove memcpy to struct assignment test
@ 2014-03-18 21:11 Peter Senna Tschudin
2014-03-19 12:02 ` Bernd Petrovitsch
0 siblings, 1 reply; 6+ messages in thread
From: Peter Senna Tschudin @ 2014-03-18 21:11 UTC (permalink / raw)
To: cocci
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.
Signed-off-by: Peter Senna Tschudin <peter.senna@gmail.com>
---
scripts/coccinelle/misc/memcpy-assign.cocci | 103 ----------------------------
1 file changed, 103 deletions(-)
delete mode 100644 scripts/coccinelle/misc/memcpy-assign.cocci
diff --git a/scripts/coccinelle/misc/memcpy-assign.cocci b/scripts/coccinelle/misc/memcpy-assign.cocci
deleted file mode 100644
index afd058b..0000000
--- a/scripts/coccinelle/misc/memcpy-assign.cocci
+++ /dev/null
@@ -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
-
-@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@p(\(&(to)\|top\), \(&(from)\|fromp\), \(sizeof(to)\|sizeof(from)\|sizeof(struct struct_name)\|sizeof(*top)\|sizeof(*fromp)\))
-
-@script:python depends on report@
-p << r1.p;
-@@
-coccilib.report.print_report(p[0],"Replace memcpy with struct assignment")
-
-@depends on context@
-position r1.p;
-@@
-*memcpy@p(...);
-
-@script:python depends on org@
-p << r1.p;
-@@
-cocci.print_main("Replace memcpy with struct assignment",p)
-
-@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;
-)
-
-@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;
-)
-
--
1.8.3.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH] Coccicheck: Remove memcpy to struct assignment test
2014-03-18 21:11 [PATCH] Coccicheck: Remove memcpy to struct assignment test Peter Senna Tschudin
@ 2014-03-19 12:02 ` Bernd Petrovitsch
2014-03-19 13:39 ` Peter Senna Tschudin
0 siblings, 1 reply; 6+ messages in thread
From: Bernd Petrovitsch @ 2014-03-19 12:02 UTC (permalink / raw)
To: cocci
On Die, 2014-03-18 at 22:11 +0100, Peter Senna Tschudin wrote:
> 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.
Using struct assignment keeps the type check and is just for this reason
always preferable over memcpy().
Kind regards,
Bernd
--
Bernd Petrovitsch Email : bernd@petrovitsch.priv.at
LUGA : http://www.luga.at
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] Coccicheck: Remove memcpy to struct assignment test
2014-03-19 12:02 ` Bernd Petrovitsch
@ 2014-03-19 13:39 ` Peter Senna Tschudin
2014-03-19 14:05 ` Bernd Petrovitsch
0 siblings, 1 reply; 6+ messages in thread
From: Peter Senna Tschudin @ 2014-03-19 13:39 UTC (permalink / raw)
To: cocci
On Wed, Mar 19, 2014 at 1:02 PM, Bernd Petrovitsch
<bernd@petrovitsch.priv.at> wrote:
> On Die, 2014-03-18 at 22:11 +0100, Peter Senna Tschudin wrote:
>> 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.
>
> 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?
>
> Kind regards,
> Bernd
> --
> Bernd Petrovitsch Email : bernd@petrovitsch.priv.at
> LUGA : http://www.luga.at
>
--
Peter
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] Coccicheck: Remove memcpy to struct assignment test
2014-03-19 13:39 ` Peter Senna Tschudin
@ 2014-03-19 14:05 ` Bernd Petrovitsch
2014-03-19 16:48 ` Greg Kroah-Hartman
0 siblings, 1 reply; 6+ messages in thread
From: Bernd Petrovitsch @ 2014-03-19 14:05 UTC (permalink / raw)
To: cocci
Hi!
On Mit, 2014-03-19 at 14:39 +0100, Peter Senna Tschudin wrote:
> On Wed, Mar 19, 2014 at 1:02 PM, Bernd Petrovitsch
> <bernd@petrovitsch.priv.at> wrote:
> > On Die, 2014-03-18 at 22:11 +0100, Peter Senna Tschudin wrote:
> >> 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.
> >
> > 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
--
Bernd Petrovitsch Email : bernd@petrovitsch.priv.at
LUGA : http://www.luga.at
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] Coccicheck: Remove memcpy to struct assignment test
2014-03-19 14:05 ` Bernd Petrovitsch
@ 2014-03-19 16:48 ` Greg Kroah-Hartman
2014-03-29 20:37 ` Michal Marek
0 siblings, 1 reply; 6+ messages in thread
From: Greg Kroah-Hartman @ 2014-03-19 16:48 UTC (permalink / raw)
To: cocci
On Wed, Mar 19, 2014 at 03:05:27PM +0100, Bernd Petrovitsch wrote:
> Hi!
>
> On Mit, 2014-03-19 at 14:39 +0100, Peter Senna Tschudin wrote:
> > On Wed, Mar 19, 2014 at 1:02 PM, Bernd Petrovitsch
> > <bernd@petrovitsch.priv.at> wrote:
> > > On Die, 2014-03-18 at 22:11 +0100, Peter Senna Tschudin wrote:
> > >> 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.
> > >
> > > 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.
> 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
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] Coccicheck: Remove memcpy to struct assignment test
2014-03-19 16:48 ` Greg Kroah-Hartman
@ 2014-03-29 20:37 ` Michal Marek
0 siblings, 0 replies; 6+ messages in thread
From: Michal Marek @ 2014-03-29 20:37 UTC (permalink / raw)
To: cocci
Dne 19.3.2014 17:48, Greg Kroah-Hartman napsal(a):
>>>> On Die, 2014-03-18 at 22:11 +0100, Peter Senna Tschudin wrote:
>>>>> 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.
[...]
> 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
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2014-03-29 20:37 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-03-18 21:11 [PATCH] Coccicheck: Remove memcpy to struct assignment test Peter Senna Tschudin
2014-03-19 12:02 ` Bernd Petrovitsch
2014-03-19 13:39 ` Peter Senna Tschudin
2014-03-19 14:05 ` Bernd Petrovitsch
2014-03-19 16:48 ` Greg Kroah-Hartman
2014-03-29 20:37 ` Michal Marek
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).