Re: [Cocci] [PATCH] Coccinelle: zalloc_simple: Fix patch mode for dma_alloc_coherent()
On Fri, 3 Apr 2020, Alex Dewar wrote: > Commit dfd32cad146e ("dma-mapping: remove dma_zalloc_coherent()"), in > removing dma_zalloc_coherent() treewide, inadvertently removed the patch > rule for dma_alloc_coherent(), leaving Coccinelle unable to auto-generate > patches for this case. Fix this. > > Fixes: dfd32cad146e ("dma-mapping: remove dma_zalloc_coherent()") > CC: Luis Chamberlain > Signed-off-by: Alex Dewar > --- > scripts/coccinelle/api/alloc/zalloc-simple.cocci | 9 + > 1 file changed, 9 insertions(+) > > diff --git a/scripts/coccinelle/api/alloc/zalloc-simple.cocci > b/scripts/coccinelle/api/alloc/zalloc-simple.cocci > index 26cda3f48f01..c53aab7fe096 100644 > --- a/scripts/coccinelle/api/alloc/zalloc-simple.cocci > +++ b/scripts/coccinelle/api/alloc/zalloc-simple.cocci > @@ -70,6 +70,15 @@ statement S; > - x = (T)vmalloc(E1); > + x = (T)vzalloc(E1); > | > +- x = dma_alloc_coherent(E2,E1,E3,E4); > ++ x = dma_alloc_coherent(E2,E1,E3,E4); Hi, I don't understand the above case. The before and after code seem to be the same? julia > +| > +- x = (T *)dma_alloc_coherent(E2,E1,E3,E4); > ++ x = dma_alloc_coherent(E2,E1,E3,E4); > +| > +- x = (T)dma_alloc_coherent(E2,E1,E3,E4); > ++ x = (T)dma_alloc_coherent(E2,E1,E3,E4); > +| > - x = kmalloc_node(E1,E2,E3); > + x = kzalloc_node(E1,E2,E3); > | > -- > 2.26.0 > > ___ Cocci mailing list Cocci@systeme.lip6.fr https://systeme.lip6.fr/mailman/listinfo/cocci
Re: [Cocci] Function-like macro with the same name as a typedef
> * spatch seems to have trouble parsing > > ARMSSE *s = ARMSSE(opaque); > > where ARMSSE is a typedef, and ARMSSE() is a function-like macro. > Yes, I know that's in rather poor taste. I am curious for the safe handling of related software development challenges. > * Workaround #1: rename the typedef to ARMSSE_ Will adjustments become more interesting also around such name space issues? Regards, Markus ___ Cocci mailing list Cocci@systeme.lip6.fr https://systeme.lip6.fr/mailman/listinfo/cocci
[Cocci] Function-like macro with the same name as a typedef -> parse error
I noticed that Coccinelle skips over much of QEMU's hw/arm/armsse.c. I append a minimized test case. Observations: * spatch seems to have trouble parsing ARMSSE *s = ARMSSE(opaque); where ARMSSE is a typedef, and ARMSSE() is a function-like macro. Yes, I know that's in rather poor taste. * Workaround #1: rename the typedef to ARMSSE_ * Workaround #2: move the typedef and the macro from the .h to the .c. $ cat armsse.c #include "armsse.h" void nsccfg_handler(void *opaque, int n, int level) { ARMSSE *s = ARMSSE(opaque); s->nsccfg = level; } $ cat armsse.h #ifndef ARMSSE_H #define ARMSSE_H typedef struct { int nsccfg; } ARMSSE; #define ARMSSE(obj) ((ARMSSE *)(obj)) #endif $ spatch --parse-c armsse.c init_defs_builtins: /usr/lib64/coccinelle/standard.h PARSING: armsse.c including ./armsse.h ERROR-RECOV: found sync '}' at line 8 parsing pass2: try again ERROR-RECOV: found sync '}' at line 8 parsing pass3: try again ERROR-RECOV: found sync '}' at line 8 parse error = File "armsse.c", line 5, column 16, charpos = 91 around = 'ARMSSE', whole content = ARMSSE *s = ARMSSE(opaque); badcount: 7 bad: #include "armsse.h" bad: bad: void nsccfg_handler(void *opaque, int n, int level) bad: { BAD:! ARMSSE *s = ARMSSE(opaque); bad: bad: s->nsccfg = level; bad: } --- maybe 10 most problematic tokens --- ARMSSE: present in 2 parsing errors example: void nsccfg_handler(void *opaque, int n, int level) { ARMSSE *s = ARMSSE(opaque); opaque: present in 2 parsing errors example: void nsccfg_handler(void *opaque, int n, int level) { ARMSSE *s = ARMSSE(opaque); level: present in 1 parsing errors example: void nsccfg_handler(void *opaque, int n, int level) { ARMSSE *s = ARMSSE(opaque); n: present in 1 parsing errors example: void nsccfg_handler(void *opaque, int n, int level) { ARMSSE *s = ARMSSE(opaque); nsccfg_handler: present in 1 parsing errors example: void nsccfg_handler(void *opaque, int n, int level) { ARMSSE *s = ARMSSE(opaque); s: present in 1 parsing errors example: void nsccfg_handler(void *opaque, int n, int level) { ARMSSE *s = ARMSSE(opaque); --- NB total files = 1; perfect = 0; pbs = 1; timeout = 0; => 0% nb good = 0, nb passed = 0 => 0.00% passed nb good = 0, nb bad = 7 => 0.00% good or passed $ spatch --version spatch version 1.0.7 compiled with OCaml version 4.07.0 Flags passed to the configure script: --build=x86_64-redhat-linux-gnu --host=x86_64-redhat-linux-gnu --program-prefix= --disable-dependency-tracking --prefix=/usr --exec-prefix=/usr --bindir=/usr/bin --sbindir=/usr/sbin --sysconfdir=/etc --datadir=/usr/share --includedir=/usr/include --libdir=/usr/lib64 --libexecdir=/usr/libexec --localstatedir=/var --sharedstatedir=/var/lib --mandir=/usr/share/man --infodir=/usr/share/info --with-python=/usr/bin/python3 --with-menhir=/usr/bin/menhir OCaml scripting support: yes Python scripting support: yes Syntax of regular expresssions: PCRE ___ Cocci mailing list Cocci@systeme.lip6.fr https://systeme.lip6.fr/mailman/listinfo/cocci