From 5704d4557f279962a1fa9ee9c5b562eb27376103 Mon Sep 17 00:00:00 2001 From: Paolo Pisati Date: Mon, 27 Nov 2017 12:07:34 +0100 Subject: scripts/package: snap-pkg target Following in footsteps of other targets like 'deb-pkg, 'rpm-pkg' and 'tar-pkg', this patch adds a 'snap-pkg' target for the creation of a Linux kernel snap package using the kbuild infrastructure. A snap, in its general form, is a self contained, sandboxed, universal package and it is intended to work across multiple distributions and/or devices. A snap package is distributed as a single compressed squashfs filesystem. A kernel snap is a snap package carrying the Linux kernel, kernel modules, accessory files (DTBs, System.map, etc) and a manifesto file. The purpose of a kernel snap is to carry the Linux kernel during the creation of a system image, eg. Ubuntu Core, and its subsequent upgrades. For more information on snap packages: https://snapcraft.io/docs/ Signed-off-by: Paolo Pisati Signed-off-by: Masahiro Yamada --- scripts/package/Makefile | 16 ++++++++++++++++ scripts/package/snapcraft.template | 14 ++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 scripts/package/snapcraft.template (limited to 'scripts') diff --git a/scripts/package/Makefile b/scripts/package/Makefile index c23534925b38..61e29da374cc 100644 --- a/scripts/package/Makefile +++ b/scripts/package/Makefile @@ -94,6 +94,21 @@ bindeb-pkg: FORCE clean-dirs += $(objtree)/debian/ +# snap-pkg +# --------------------------------------------------------------------------- +snap-pkg: FORCE + rm -rf $(objtree)/snap + mkdir $(objtree)/snap + $(MAKE) clean + $(call cmd,src_tar,$(KERNELPATH)) + sed "s@KERNELRELEASE@$(KERNELRELEASE)@; \ + s@SRCTREE@$(shell realpath $(KERNELPATH).tar.gz)@" \ + $(srctree)/scripts/package/snapcraft.template > \ + $(objtree)/snap/snapcraft.yaml + cd $(objtree)/snap && \ + snapcraft --target-arch=$(UTS_MACHINE) + +clean-dirs += $(objtree)/snap/ # tarball targets # --------------------------------------------------------------------------- @@ -138,6 +153,7 @@ help: FORCE @echo ' binrpm-pkg - Build only the binary kernel RPM package' @echo ' deb-pkg - Build both source and binary deb kernel packages' @echo ' bindeb-pkg - Build only the binary kernel deb package' + @echo ' snap-pkg - Build only the binary kernel snap package (will connect to external hosts)' @echo ' tar-pkg - Build the kernel as an uncompressed tarball' @echo ' targz-pkg - Build the kernel as a gzip compressed tarball' @echo ' tarbz2-pkg - Build the kernel as a bzip2 compressed tarball' diff --git a/scripts/package/snapcraft.template b/scripts/package/snapcraft.template new file mode 100644 index 000000000000..626d278e4a5a --- /dev/null +++ b/scripts/package/snapcraft.template @@ -0,0 +1,14 @@ +name: kernel +version: KERNELRELEASE +summary: Linux kernel +description: The upstream Linux kernel +grade: stable +confinement: strict +type: kernel + +parts: + kernel: + plugin: kernel + source: SRCTREE + source-type: tar + kernel-with-firmware: false -- cgit v1.2.3 From 262dad68e152fda06e5c5666b3186c23dfd6ae2f Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Wed, 6 Dec 2017 19:32:57 +0900 Subject: kbuild: pkg: make out-of-tree rpm/deb-pkg build immediately fail We do not support out-of-tree building of rpm-pkg / deb-pkg. If O= is given, the build should be terminated, but the "false" command is not effective since it is not the last command in the cmd_src_tar. Then, rpm-pkg / deb-pkg tries to continue building, and fails for a different reason. Set -e option so that the "false" terminates the building immediately. I also put the error messages to stderr, and made it stand out more. For example, "make O=foo rpm-pkg" will fail as follows: /bin/bash ../scripts/package/mkspec >./kernel.spec TAR kernel-4.15.0_rc2+.tar.gz ERROR: Building source tarball is not possible outside the kernel source tree. Don't set KBUILD_OUTPUT, or use the binrpm-pkg or bindeb-pkg target instead. ../scripts/package/Makefile:53: recipe for target 'rpm-pkg' failed Signed-off-by: Masahiro Yamada Tested-by: Jim Davis --- scripts/package/Makefile | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'scripts') diff --git a/scripts/package/Makefile b/scripts/package/Makefile index 61e29da374cc..9fbcf5ed0ca7 100644 --- a/scripts/package/Makefile +++ b/scripts/package/Makefile @@ -32,10 +32,14 @@ MKSPEC := $(srctree)/scripts/package/mkspec quiet_cmd_src_tar = TAR $(2).tar.gz cmd_src_tar = \ +set -e; \ if test "$(objtree)" != "$(srctree)"; then \ - echo "Building source tarball is not possible outside the"; \ - echo "kernel source tree. Don't set KBUILD_OUTPUT, or use the"; \ - echo "binrpm-pkg or bindeb-pkg target instead."; \ + echo >&2; \ + echo >&2 " ERROR:"; \ + echo >&2 " Building source tarball is not possible outside the"; \ + echo >&2 " kernel source tree. Don't set KBUILD_OUTPUT, or use the"; \ + echo >&2 " binrpm-pkg or bindeb-pkg target instead."; \ + echo >&2; \ false; \ fi ; \ $(srctree)/scripts/setlocalversion --save-scmversion; \ -- cgit v1.2.3 From 5e2d9da5b9ba350a4f13bd3b255be046bcf86465 Mon Sep 17 00:00:00 2001 From: Himanshu Jha Date: Wed, 27 Dec 2017 03:10:10 +0530 Subject: Coccinelle: kzalloc-simple: Add all zero allocating functions There are many instances where memory is allocated using regular allocator functions immediately followed by setting the allocated memory to 0 value using memset. We already have zero memory allocator functions to set the memory to 0 value instead of manually setting it using memset. Therefore, use zero memory allocating functions instead of regular memory allocators followed by memset 0 to remove redundant memset and make the code more cleaner and also reduce the code size. Signed-off-by: Himanshu Jha Acked-by: Julia Lawall Signed-off-by: Masahiro Yamada --- scripts/coccinelle/api/alloc/kzalloc-simple.cocci | 372 +++++++++++++++++++++- 1 file changed, 367 insertions(+), 5 deletions(-) (limited to 'scripts') diff --git a/scripts/coccinelle/api/alloc/kzalloc-simple.cocci b/scripts/coccinelle/api/alloc/kzalloc-simple.cocci index 52c55e4fa67d..92b20913055f 100644 --- a/scripts/coccinelle/api/alloc/kzalloc-simple.cocci +++ b/scripts/coccinelle/api/alloc/kzalloc-simple.cocci @@ -1,5 +1,5 @@ /// -/// Use kzalloc rather than kmalloc followed by memset with 0 +/// Use zeroing allocator rather than allocator followed by memset with 0 /// /// This considers some simple cases that are common and easy to validate /// Note in particular that there are no ...s in the rule, so all of the @@ -8,6 +8,7 @@ // Confidence: High // Copyright: (C) 2009-2010 Julia Lawall, Nicolas Palix, DIKU. GPLv2. // Copyright: (C) 2009-2010 Gilles Muller, INRIA/LiP6. GPLv2. +// Copyright: (C) 2017 Himanshu Jha GPLv2. // URL: http://coccinelle.lip6.fr/rules/kzalloc.html // Options: --no-includes --include-headers // @@ -28,11 +29,14 @@ virtual report @depends on context@ type T, T2; expression x; -expression E1,E2; +expression E1; statement S; @@ -* x = (T)kmalloc(E1,E2); +* x = (T)\(kmalloc(E1, ...)\|vmalloc(E1)\|dma_alloc_coherent(...,E1,...)\| + kmalloc_node(E1, ...)\|kmem_cache_alloc(...)\|kmem_alloc(E1, ...)\| + devm_kmalloc(...,E1,...)\|kvmalloc(E1, ...)\|pci_alloc_consistent(...,E1,...)\| + kvmalloc_node(E1,...)\); if ((x==NULL) || ...) S * memset((T2)x,0,E1); @@ -43,12 +47,101 @@ statement S; @depends on patch@ type T, T2; expression x; -expression E1,E2; +expression E1,E2,E3,E4; statement S; @@ -- x = (T)kmalloc(E1,E2); +( +- x = kmalloc(E1,E2); ++ x = kzalloc(E1,E2); +| +- x = (T *)kmalloc(E1,E2); + x = kzalloc(E1,E2); +| +- x = (T)kmalloc(E1,E2); ++ x = (T)kzalloc(E1,E2); +| +- x = vmalloc(E1); ++ x = vzalloc(E1); +| +- x = (T *)vmalloc(E1); ++ x = vzalloc(E1); +| +- x = (T)vmalloc(E1); ++ x = (T)vzalloc(E1); +| +- x = dma_alloc_coherent(E2,E1,E3,E4); ++ x = dma_zalloc_coherent(E2,E1,E3,E4); +| +- x = (T *)dma_alloc_coherent(E2,E1,E3,E4); ++ x = dma_zalloc_coherent(E2,E1,E3,E4); +| +- x = (T)dma_alloc_coherent(E2,E1,E3,E4); ++ x = (T)dma_zalloc_coherent(E2,E1,E3,E4); +| +- x = kmalloc_node(E1,E2,E3); ++ x = kzalloc_node(E1,E2,E3); +| +- x = (T *)kmalloc_node(E1,E2,E3); ++ x = kzalloc_node(E1,E2,E3); +| +- x = (T)kmalloc_node(E1,E2,E3); ++ x = (T)kzalloc_node(E1,E2,E3); +| +- x = kmem_cache_alloc(E3,E4); ++ x = kmem_cache_zalloc(E3,E4); +| +- x = (T *)kmem_cache_alloc(E3,E4); ++ x = kmem_cache_zalloc(E3,E4); +| +- x = (T)kmem_cache_alloc(E3,E4); ++ x = (T)kmem_cache_zalloc(E3,E4); +| +- x = kmem_alloc(E1,E2); ++ x = kmem_zalloc(E1,E2); +| +- x = (T *)kmem_alloc(E1,E2); ++ x = kmem_zalloc(E1,E2); +| +- x = (T)kmem_alloc(E1,E2); ++ x = (T)kmem_zalloc(E1,E2); +| +- x = devm_kmalloc(E2,E1,E3); ++ x = devm_kzalloc(E2,E1,E3); +| +- x = (T *)devm_kmalloc(E2,E1,E3); ++ x = devm_kzalloc(E2,E1,E3); +| +- x = (T)devm_kmalloc(E2,E1,E3); ++ x = (T)devm_kzalloc(E2,E1,E3); +| +- x = kvmalloc(E1,E2); ++ x = kvzalloc(E1,E2); +| +- x = (T *)kvmalloc(E1,E2); ++ x = kvzalloc(E1,E2); +| +- x = (T)kvmalloc(E1,E2); ++ x = (T)kvzalloc(E1,E2); +| +- x = pci_alloc_consistent(E2,E1,E3); ++ x = pci_zalloc_consistent(E2,E1,E3); +| +- x = (T *)pci_alloc_consistent(E2,E1,E3); ++ x = pci_zalloc_consistent(E2,E1,E3); +| +- x = (T)pci_alloc_consistent(E2,E1,E3); ++ x = (T)pci_zalloc_consistent(E2,E1,E3); +| +- x = kvmalloc_node(E1,E2,E3); ++ x = kvzalloc_node(E1,E2,E3); +| +- x = (T *)kvmalloc_node(E1,E2,E3); ++ x = kvzalloc_node(E1,E2,E3); +| +- x = (T)kvmalloc_node(E1,E2,E3); ++ x = (T)kvzalloc_node(E1,E2,E3); +) if ((x==NULL) || ...) S - memset((T2)x,0,E1); @@ -84,3 +177,272 @@ x << r.x; msg="WARNING: kzalloc should be used for %s, instead of kmalloc/memset" % (x) coccilib.report.print_report(p[0], msg) + +//----------------------------------------------------------------- +@r1 depends on org || report@ +type T, T2; +expression x; +expression E1; +statement S; +position p; +@@ + + x = (T)vmalloc@p(E1); + if ((x==NULL) || ...) S + memset((T2)x,0,E1); + +@script:python depends on org@ +p << r1.p; +x << r1.x; +@@ + +msg="%s" % (x) +msg_safe=msg.replace("[","@(").replace("]",")") +coccilib.org.print_todo(p[0], msg_safe) + +@script:python depends on report@ +p << r1.p; +x << r1.x; +@@ + +msg="WARNING: vzalloc should be used for %s, instead of vmalloc/memset" % (x) +coccilib.report.print_report(p[0], msg) + +//----------------------------------------------------------------- +@r2 depends on org || report@ +type T, T2; +expression x; +expression E1,E2,E3,E4; +statement S; +position p; +@@ + + x = (T)dma_alloc_coherent@p(E2,E1,E3,E4); + if ((x==NULL) || ...) S + memset((T2)x,0,E1); + +@script:python depends on org@ +p << r2.p; +x << r2.x; +@@ + +msg="%s" % (x) +msg_safe=msg.replace("[","@(").replace("]",")") +coccilib.org.print_todo(p[0], msg_safe) + +@script:python depends on report@ +p << r2.p; +x << r2.x; +@@ + +msg="WARNING: dma_zalloc_coherent should be used for %s, instead of dma_alloc_coherent/memset" % (x) +coccilib.report.print_report(p[0], msg) + +//----------------------------------------------------------------- +@r3 depends on org || report@ +type T, T2; +expression x; +expression E1,E2,E3; +statement S; +position p; +@@ + + x = (T)kmalloc_node@p(E1,E2,E3); + if ((x==NULL) || ...) S + memset((T2)x,0,E1); + +@script:python depends on org@ +p << r3.p; +x << r3.x; +@@ + +msg="%s" % (x) +msg_safe=msg.replace("[","@(").replace("]",")") +coccilib.org.print_todo(p[0], msg_safe) + +@script:python depends on report@ +p << r3.p; +x << r3.x; +@@ + +msg="WARNING: kzalloc_node should be used for %s, instead of kmalloc_node/memset" % (x) +coccilib.report.print_report(p[0], msg) + +//----------------------------------------------------------------- +@r4 depends on org || report@ +type T, T2; +expression x; +expression E1,E2,E3; +statement S; +position p; +@@ + + x = (T)kmem_cache_alloc@p(E2,E3); + if ((x==NULL) || ...) S + memset((T2)x,0,E1); + +@script:python depends on org@ +p << r4.p; +x << r4.x; +@@ + +msg="%s" % (x) +msg_safe=msg.replace("[","@(").replace("]",")") +coccilib.org.print_todo(p[0], msg_safe) + +@script:python depends on report@ +p << r4.p; +x << r4.x; +@@ + +msg="WARNING: kmem_cache_zalloc should be used for %s, instead of kmem_cache_alloc/memset" % (x) +coccilib.report.print_report(p[0], msg) + +//----------------------------------------------------------------- +@r5 depends on org || report@ +type T, T2; +expression x; +expression E1,E2; +statement S; +position p; +@@ + + x = (T)kmem_alloc@p(E1,E2); + if ((x==NULL) || ...) S + memset((T2)x,0,E1); + +@script:python depends on org@ +p << r5.p; +x << r5.x; +@@ + +msg="%s" % (x) +msg_safe=msg.replace("[","@(").replace("]",")") +coccilib.org.print_todo(p[0], msg_safe) + +@script:python depends on report@ +p << r5.p; +x << r5.x; +@@ + +msg="WARNING: kmem_zalloc should be used for %s, instead of kmem_alloc/memset" % (x) +coccilib.report.print_report(p[0], msg) + +//----------------------------------------------------------------- +@r6 depends on org || report@ +type T, T2; +expression x; +expression E1,E2,E3; +statement S; +position p; +@@ + + x = (T)devm_kmalloc@p(E2,E1,E3); + if ((x==NULL) || ...) S + memset((T2)x,0,E1); + +@script:python depends on org@ +p << r6.p; +x << r6.x; +@@ + +msg="%s" % (x) +msg_safe=msg.replace("[","@(").replace("]",")") +coccilib.org.print_todo(p[0], msg_safe) + +@script:python depends on report@ +p << r6.p; +x << r6.x; +@@ + +msg="WARNING: devm_kzalloc should be used for %s, instead of devm_kmalloc/memset" % (x) +coccilib.report.print_report(p[0], msg) + +//----------------------------------------------------------------- +@r7 depends on org || report@ +type T, T2; +expression x; +expression E1,E2; +statement S; +position p; +@@ + + x = (T)kvmalloc@p(E1,E2); + if ((x==NULL) || ...) S + memset((T2)x,0,E1); + +@script:python depends on org@ +p << r7.p; +x << r7.x; +@@ + +msg="%s" % (x) +msg_safe=msg.replace("[","@(").replace("]",")") +coccilib.org.print_todo(p[0], msg_safe) + +@script:python depends on report@ +p << r7.p; +x << r7.x; +@@ + +msg="WARNING: kvzalloc should be used for %s, instead of kvmalloc/memset" % (x) +coccilib.report.print_report(p[0], msg) + +//----------------------------------------------------------------- +@r8 depends on org || report@ +type T, T2; +expression x; +expression E1,E2,E3; +statement S; +position p; +@@ + + x = (T)pci_alloc_consistent@p(E2,E1,E3); + if ((x==NULL) || ...) S + memset((T2)x,0,E1); + +@script:python depends on org@ +p << r8.p; +x << r8.x; +@@ + +msg="%s" % (x) +msg_safe=msg.replace("[","@(").replace("]",")") +coccilib.org.print_todo(p[0], msg_safe) + +@script:python depends on report@ +p << r8.p; +x << r8.x; +@@ + +msg="WARNING: pci_zalloc_consistent should be used for %s, instead of pci_alloc_consistent/memset" % (x) +coccilib.report.print_report(p[0], msg) +//----------------------------------------------------------------- +@r9 depends on org || report@ +type T, T2; +expression x; +expression E1,E2,E3; +statement S; +position p; +@@ + + x = (T)kvmalloc_node@p(E1,E2,E3); + if ((x==NULL) || ...) S + memset((T2)x,0,E1); + +@script:python depends on org@ +p << r9.p; +x << r9.x; +@@ + +msg="%s" % (x) +msg_safe=msg.replace("[","@(").replace("]",")") +coccilib.org.print_todo(p[0], msg_safe) + +@script:python depends on report@ +p << r9.p; +x << r9.x; +@@ + +msg="WARNING: kvzalloc_node should be used for %s, instead of kvmalloc_node/memset" % (x) +coccilib.report.print_report(p[0], msg) -- cgit v1.2.3 From cb00a4f3dbd622acea1059c9da40131b8733d24e Mon Sep 17 00:00:00 2001 From: Jérémy Lefaure Date: Fri, 29 Dec 2017 19:14:23 +0100 Subject: Coccinelle: array_size: report even if include is missing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Rule r does not depend on rule i (which is the include of linux/kernel.h) so the output should not depend on i in org and report mode. Signed-off-by: Jérémy Lefaure Acked-by: Julia Lawall Signed-off-by: Masahiro Yamada --- scripts/coccinelle/misc/array_size.cocci | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'scripts') diff --git a/scripts/coccinelle/misc/array_size.cocci b/scripts/coccinelle/misc/array_size.cocci index 6ec05710b017..09520f0941f0 100644 --- a/scripts/coccinelle/misc/array_size.cocci +++ b/scripts/coccinelle/misc/array_size.cocci @@ -72,13 +72,13 @@ position p; (sizeof(E)@p /sizeof(T)) ) -@script:python depends on i&&org@ +@script:python depends on org@ p << r.p; @@ coccilib.org.print_todo(p[0], "WARNING should use ARRAY_SIZE") -@script:python depends on i&&report@ +@script:python depends on report@ p << r.p; @@ -- cgit v1.2.3 From d8e7eb51b03d83910d2dec48c5df4ec419a6bcff Mon Sep 17 00:00:00 2001 From: Himanshu Jha Date: Sat, 13 Jan 2018 21:26:30 +0530 Subject: Coccinelle: alloc_cast: Add more memory allocating functions to the list Add more memory allocating functions that are frequently used in the kernel code to the existing list and remove the useless casts where it is unnecessary. But preserve those casts having __attribute__ such as __force, __iomem, etc. which are used by Sparse in the static analysis of the code. Also remove two blank lines at EOF. Signed-off-by: Himanshu Jha Acked-by: Julia Lawall Signed-off-by: Masahiro Yamada --- scripts/coccinelle/api/alloc/alloc_cast.cocci | 92 +++++++++++++++++++++------ 1 file changed, 71 insertions(+), 21 deletions(-) (limited to 'scripts') diff --git a/scripts/coccinelle/api/alloc/alloc_cast.cocci b/scripts/coccinelle/api/alloc/alloc_cast.cocci index 6c308ee19b32..408ee3879f9b 100644 --- a/scripts/coccinelle/api/alloc/alloc_cast.cocci +++ b/scripts/coccinelle/api/alloc/alloc_cast.cocci @@ -5,10 +5,11 @@ //# kmalloc, kzalloc, kcalloc, kmem_cache_alloc, kmem_cache_zalloc, //# kmem_cache_alloc_node, kmalloc_node and kzalloc_node and removes //# the casting as it is not required. The result in the patch case may -//#need some reformatting. +//# need some reformatting. // // Confidence: High -// Copyright: 2014, Himangi Saraogi GPLv2. +// Copyright: (C) 2014 Himangi Saraogi GPLv2. +// Copyright: (C) 2017 Himanshu Jha GPLv2. // Comments: // Options: --no-includes --include-headers // @@ -18,55 +19,104 @@ virtual patch virtual org virtual report +@initialize:python@ +@@ +import re +pattern = '__' +m = re.compile(pattern) + +@r1 depends on context || patch@ +type T; +@@ + + (T *) + \(kmalloc\|kzalloc\|kcalloc\|kmem_cache_alloc\|kmem_cache_zalloc\| + kmem_cache_alloc_node\|kmalloc_node\|kzalloc_node\|vmalloc\|vzalloc\| + dma_alloc_coherent\|dma_zalloc_coherent\|devm_kmalloc\|devm_kzalloc\| + kvmalloc\|kvzalloc\|kvmalloc_node\|kvzalloc_node\|pci_alloc_consistent\| + pci_zalloc_consistent\|kmem_alloc\|kmem_zalloc\|kmem_zone_alloc\| + kmem_zone_zalloc\|vmalloc_node\|vzalloc_node\)(...) + //---------------------------------------------------------- // For context mode //---------------------------------------------------------- -@depends on context@ -type T; +@script:python depends on context@ +t << r1.T; +@@ + +if m.search(t) != None: + cocci.include_match(False) + +@depends on context && r1@ +type r1.T; @@ * (T *) \(kmalloc\|kzalloc\|kcalloc\|kmem_cache_alloc\|kmem_cache_zalloc\| - kmem_cache_alloc_node\|kmalloc_node\|kzalloc_node\)(...) + kmem_cache_alloc_node\|kmalloc_node\|kzalloc_node\|vmalloc\|vzalloc\| + dma_alloc_coherent\|dma_zalloc_coherent\|devm_kmalloc\|devm_kzalloc\| + kvmalloc\|kvzalloc\|kvmalloc_node\|kvzalloc_node\|pci_alloc_consistent\| + pci_zalloc_consistent\|kmem_alloc\|kmem_zalloc\|kmem_zone_alloc\| + kmem_zone_zalloc\|vmalloc_node\|vzalloc_node\)(...) //---------------------------------------------------------- // For patch mode //---------------------------------------------------------- -@depends on patch@ -type T; +@script:python depends on patch@ +t << r1.T; +@@ + +if m.search(t) != None: + cocci.include_match(False) + +@depends on patch && r1@ +type r1.T; @@ - (T *) - (\(kmalloc\|kzalloc\|kcalloc\|kmem_cache_alloc\|kmem_cache_zalloc\| - kmem_cache_alloc_node\|kmalloc_node\|kzalloc_node\)(...)) + \(kmalloc\|kzalloc\|kcalloc\|kmem_cache_alloc\|kmem_cache_zalloc\| + kmem_cache_alloc_node\|kmalloc_node\|kzalloc_node\|vmalloc\|vzalloc\| + dma_alloc_coherent\|dma_zalloc_coherent\|devm_kmalloc\|devm_kzalloc\| + kvmalloc\|kvzalloc\|kvmalloc_node\|kvzalloc_node\|pci_alloc_consistent\| + pci_zalloc_consistent\|kmem_alloc\|kmem_zalloc\|kmem_zone_alloc\| + kmem_zone_zalloc\|vmalloc_node\|vzalloc_node\)(...) //---------------------------------------------------------- // For org and report mode //---------------------------------------------------------- -@r depends on org || report@ +@r2 depends on org || report@ type T; position p; @@ - (T@p *)\(kmalloc\|kzalloc\|kcalloc\|kmem_cache_alloc\|kmem_cache_zalloc\| - kmem_cache_alloc_node\|kmalloc_node\|kzalloc_node\)(...) + (T@p *) + \(kmalloc\|kzalloc\|kcalloc\|kmem_cache_alloc\|kmem_cache_zalloc\| + kmem_cache_alloc_node\|kmalloc_node\|kzalloc_node\|vmalloc\|vzalloc\| + dma_alloc_coherent\|dma_zalloc_coherent\|devm_kmalloc\|devm_kzalloc\| + kvmalloc\|kvzalloc\|kvmalloc_node\|kvzalloc_node\|pci_alloc_consistent\| + pci_zalloc_consistent\|kmem_alloc\|kmem_zalloc\|kmem_zone_alloc\| + kmem_zone_zalloc\|vmalloc_node\|vzalloc_node\)(...) @script:python depends on org@ -p << r.p; -t << r.T; +p << r2.p; +t << r2.T; @@ -coccilib.org.print_safe_todo(p[0], t) +if m.search(t) != None: + cocci.include_match(False) +else: + coccilib.org.print_safe_todo(p[0], t) @script:python depends on report@ -p << r.p; -t << r.T; +p << r2.p; +t << r2.T; @@ -msg="WARNING: casting value returned by memory allocation function to (%s *) is useless." % (t) -coccilib.report.print_report(p[0], msg) - - +if m.search(t) != None: + cocci.include_match(False) +else: + msg="WARNING: casting value returned by memory allocation function to (%s *) is useless." % (t) + coccilib.report.print_report(p[0], msg) -- cgit v1.2.3 From 3e47599fd61d6ba650b09e023f97bc9b9e7e390f Mon Sep 17 00:00:00 2001 From: Himanshu Jha Date: Sat, 13 Jan 2018 21:28:15 +0530 Subject: Coccinelle: ifnullfree: Trim the warning reported in report mode Remove the unncessary part of the warning reported, in the report mode, so that a single warning produced does not exceed more than line and hence improve readability of the warnings produced in the subsequent reports to a file. Signed-off-by: Himanshu Jha Acked-by: Julia Lawall Signed-off-by: Masahiro Yamada --- scripts/coccinelle/free/ifnullfree.cocci | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'scripts') diff --git a/scripts/coccinelle/free/ifnullfree.cocci b/scripts/coccinelle/free/ifnullfree.cocci index 14a4cd98e83b..a70e123cb12b 100644 --- a/scripts/coccinelle/free/ifnullfree.cocci +++ b/scripts/coccinelle/free/ifnullfree.cocci @@ -55,5 +55,5 @@ cocci.print_main("NULL check before that freeing function is not needed", p) p << r.p; @@ -msg = "WARNING: NULL check before freeing functions like kfree, debugfs_remove, debugfs_remove_recursive or usb_free_urb is not needed. Maybe consider reorganizing relevant code to avoid passing NULL values." +msg = "WARNING: NULL check before some freeing functions is not needed." coccilib.report.print_report(p[0], msg) -- cgit v1.2.3 From 1936f8f30066cd608d1cee5807a2adf380dda718 Mon Sep 17 00:00:00 2001 From: Himanshu Jha Date: Sun, 14 Jan 2018 01:56:58 +0530 Subject: Coccinelle: kzalloc-simple: Rename kzalloc-simple to zalloc-simple Rename kzalloc-simple to zalloc-simple since now the rule is not specific to kzalloc function only, but also to many other zero memory allocating functions specified in the rule. Suggested-by: SF Markus Elfring Signed-off-by: Himanshu Jha Acked-by: Julia Lawall Signed-off-by: Masahiro Yamada --- scripts/coccinelle/api/alloc/kzalloc-simple.cocci | 448 ---------------------- scripts/coccinelle/api/alloc/zalloc-simple.cocci | 448 ++++++++++++++++++++++ 2 files changed, 448 insertions(+), 448 deletions(-) delete mode 100644 scripts/coccinelle/api/alloc/kzalloc-simple.cocci create mode 100644 scripts/coccinelle/api/alloc/zalloc-simple.cocci (limited to 'scripts') diff --git a/scripts/coccinelle/api/alloc/kzalloc-simple.cocci b/scripts/coccinelle/api/alloc/kzalloc-simple.cocci deleted file mode 100644 index 92b20913055f..000000000000 --- a/scripts/coccinelle/api/alloc/kzalloc-simple.cocci +++ /dev/null @@ -1,448 +0,0 @@ -/// -/// Use zeroing allocator rather than allocator followed by memset with 0 -/// -/// This considers some simple cases that are common and easy to validate -/// Note in particular that there are no ...s in the rule, so all of the -/// matched code has to be contiguous -/// -// Confidence: High -// Copyright: (C) 2009-2010 Julia Lawall, Nicolas Palix, DIKU. GPLv2. -// Copyright: (C) 2009-2010 Gilles Muller, INRIA/LiP6. GPLv2. -// Copyright: (C) 2017 Himanshu Jha GPLv2. -// URL: http://coccinelle.lip6.fr/rules/kzalloc.html -// Options: --no-includes --include-headers -// -// Keywords: kmalloc, kzalloc -// Version min: < 2.6.12 kmalloc -// Version min: 2.6.14 kzalloc -// - -virtual context -virtual patch -virtual org -virtual report - -//---------------------------------------------------------- -// For context mode -//---------------------------------------------------------- - -@depends on context@ -type T, T2; -expression x; -expression E1; -statement S; -@@ - -* x = (T)\(kmalloc(E1, ...)\|vmalloc(E1)\|dma_alloc_coherent(...,E1,...)\| - kmalloc_node(E1, ...)\|kmem_cache_alloc(...)\|kmem_alloc(E1, ...)\| - devm_kmalloc(...,E1,...)\|kvmalloc(E1, ...)\|pci_alloc_consistent(...,E1,...)\| - kvmalloc_node(E1,...)\); - if ((x==NULL) || ...) S -* memset((T2)x,0,E1); - -//---------------------------------------------------------- -// For patch mode -//---------------------------------------------------------- - -@depends on patch@ -type T, T2; -expression x; -expression E1,E2,E3,E4; -statement S; -@@ - -( -- x = kmalloc(E1,E2); -+ x = kzalloc(E1,E2); -| -- x = (T *)kmalloc(E1,E2); -+ x = kzalloc(E1,E2); -| -- x = (T)kmalloc(E1,E2); -+ x = (T)kzalloc(E1,E2); -| -- x = vmalloc(E1); -+ x = vzalloc(E1); -| -- x = (T *)vmalloc(E1); -+ x = vzalloc(E1); -| -- x = (T)vmalloc(E1); -+ x = (T)vzalloc(E1); -| -- x = dma_alloc_coherent(E2,E1,E3,E4); -+ x = dma_zalloc_coherent(E2,E1,E3,E4); -| -- x = (T *)dma_alloc_coherent(E2,E1,E3,E4); -+ x = dma_zalloc_coherent(E2,E1,E3,E4); -| -- x = (T)dma_alloc_coherent(E2,E1,E3,E4); -+ x = (T)dma_zalloc_coherent(E2,E1,E3,E4); -| -- x = kmalloc_node(E1,E2,E3); -+ x = kzalloc_node(E1,E2,E3); -| -- x = (T *)kmalloc_node(E1,E2,E3); -+ x = kzalloc_node(E1,E2,E3); -| -- x = (T)kmalloc_node(E1,E2,E3); -+ x = (T)kzalloc_node(E1,E2,E3); -| -- x = kmem_cache_alloc(E3,E4); -+ x = kmem_cache_zalloc(E3,E4); -| -- x = (T *)kmem_cache_alloc(E3,E4); -+ x = kmem_cache_zalloc(E3,E4); -| -- x = (T)kmem_cache_alloc(E3,E4); -+ x = (T)kmem_cache_zalloc(E3,E4); -| -- x = kmem_alloc(E1,E2); -+ x = kmem_zalloc(E1,E2); -| -- x = (T *)kmem_alloc(E1,E2); -+ x = kmem_zalloc(E1,E2); -| -- x = (T)kmem_alloc(E1,E2); -+ x = (T)kmem_zalloc(E1,E2); -| -- x = devm_kmalloc(E2,E1,E3); -+ x = devm_kzalloc(E2,E1,E3); -| -- x = (T *)devm_kmalloc(E2,E1,E3); -+ x = devm_kzalloc(E2,E1,E3); -| -- x = (T)devm_kmalloc(E2,E1,E3); -+ x = (T)devm_kzalloc(E2,E1,E3); -| -- x = kvmalloc(E1,E2); -+ x = kvzalloc(E1,E2); -| -- x = (T *)kvmalloc(E1,E2); -+ x = kvzalloc(E1,E2); -| -- x = (T)kvmalloc(E1,E2); -+ x = (T)kvzalloc(E1,E2); -| -- x = pci_alloc_consistent(E2,E1,E3); -+ x = pci_zalloc_consistent(E2,E1,E3); -| -- x = (T *)pci_alloc_consistent(E2,E1,E3); -+ x = pci_zalloc_consistent(E2,E1,E3); -| -- x = (T)pci_alloc_consistent(E2,E1,E3); -+ x = (T)pci_zalloc_consistent(E2,E1,E3); -| -- x = kvmalloc_node(E1,E2,E3); -+ x = kvzalloc_node(E1,E2,E3); -| -- x = (T *)kvmalloc_node(E1,E2,E3); -+ x = kvzalloc_node(E1,E2,E3); -| -- x = (T)kvmalloc_node(E1,E2,E3); -+ x = (T)kvzalloc_node(E1,E2,E3); -) - if ((x==NULL) || ...) S -- memset((T2)x,0,E1); - -//---------------------------------------------------------- -// For org mode -//---------------------------------------------------------- - -@r depends on org || report@ -type T, T2; -expression x; -expression E1,E2; -statement S; -position p; -@@ - - x = (T)kmalloc@p(E1,E2); - if ((x==NULL) || ...) S - memset((T2)x,0,E1); - -@script:python depends on org@ -p << r.p; -x << r.x; -@@ - -msg="%s" % (x) -msg_safe=msg.replace("[","@(").replace("]",")") -coccilib.org.print_todo(p[0], msg_safe) - -@script:python depends on report@ -p << r.p; -x << r.x; -@@ - -msg="WARNING: kzalloc should be used for %s, instead of kmalloc/memset" % (x) -coccilib.report.print_report(p[0], msg) - -//----------------------------------------------------------------- -@r1 depends on org || report@ -type T, T2; -expression x; -expression E1; -statement S; -position p; -@@ - - x = (T)vmalloc@p(E1); - if ((x==NULL) || ...) S - memset((T2)x,0,E1); - -@script:python depends on org@ -p << r1.p; -x << r1.x; -@@ - -msg="%s" % (x) -msg_safe=msg.replace("[","@(").replace("]",")") -coccilib.org.print_todo(p[0], msg_safe) - -@script:python depends on report@ -p << r1.p; -x << r1.x; -@@ - -msg="WARNING: vzalloc should be used for %s, instead of vmalloc/memset" % (x) -coccilib.report.print_report(p[0], msg) - -//----------------------------------------------------------------- -@r2 depends on org || report@ -type T, T2; -expression x; -expression E1,E2,E3,E4; -statement S; -position p; -@@ - - x = (T)dma_alloc_coherent@p(E2,E1,E3,E4); - if ((x==NULL) || ...) S - memset((T2)x,0,E1); - -@script:python depends on org@ -p << r2.p; -x << r2.x; -@@ - -msg="%s" % (x) -msg_safe=msg.replace("[","@(").replace("]",")") -coccilib.org.print_todo(p[0], msg_safe) - -@script:python depends on report@ -p << r2.p; -x << r2.x; -@@ - -msg="WARNING: dma_zalloc_coherent should be used for %s, instead of dma_alloc_coherent/memset" % (x) -coccilib.report.print_report(p[0], msg) - -//----------------------------------------------------------------- -@r3 depends on org || report@ -type T, T2; -expression x; -expression E1,E2,E3; -statement S; -position p; -@@ - - x = (T)kmalloc_node@p(E1,E2,E3); - if ((x==NULL) || ...) S - memset((T2)x,0,E1); - -@script:python depends on org@ -p << r3.p; -x << r3.x; -@@ - -msg="%s" % (x) -msg_safe=msg.replace("[","@(").replace("]",")") -coccilib.org.print_todo(p[0], msg_safe) - -@script:python depends on report@ -p << r3.p; -x << r3.x; -@@ - -msg="WARNING: kzalloc_node should be used for %s, instead of kmalloc_node/memset" % (x) -coccilib.report.print_report(p[0], msg) - -//----------------------------------------------------------------- -@r4 depends on org || report@ -type T, T2; -expression x; -expression E1,E2,E3; -statement S; -position p; -@@ - - x = (T)kmem_cache_alloc@p(E2,E3); - if ((x==NULL) || ...) S - memset((T2)x,0,E1); - -@script:python depends on org@ -p << r4.p; -x << r4.x; -@@ - -msg="%s" % (x) -msg_safe=msg.replace("[","@(").replace("]",")") -coccilib.org.print_todo(p[0], msg_safe) - -@script:python depends on report@ -p << r4.p; -x << r4.x; -@@ - -msg="WARNING: kmem_cache_zalloc should be used for %s, instead of kmem_cache_alloc/memset" % (x) -coccilib.report.print_report(p[0], msg) - -//----------------------------------------------------------------- -@r5 depends on org || report@ -type T, T2; -expression x; -expression E1,E2; -statement S; -position p; -@@ - - x = (T)kmem_alloc@p(E1,E2); - if ((x==NULL) || ...) S - memset((T2)x,0,E1); - -@script:python depends on org@ -p << r5.p; -x << r5.x; -@@ - -msg="%s" % (x) -msg_safe=msg.replace("[","@(").replace("]",")") -coccilib.org.print_todo(p[0], msg_safe) - -@script:python depends on report@ -p << r5.p; -x << r5.x; -@@ - -msg="WARNING: kmem_zalloc should be used for %s, instead of kmem_alloc/memset" % (x) -coccilib.report.print_report(p[0], msg) - -//----------------------------------------------------------------- -@r6 depends on org || report@ -type T, T2; -expression x; -expression E1,E2,E3; -statement S; -position p; -@@ - - x = (T)devm_kmalloc@p(E2,E1,E3); - if ((x==NULL) || ...) S - memset((T2)x,0,E1); - -@script:python depends on org@ -p << r6.p; -x << r6.x; -@@ - -msg="%s" % (x) -msg_safe=msg.replace("[","@(").replace("]",")") -coccilib.org.print_todo(p[0], msg_safe) - -@script:python depends on report@ -p << r6.p; -x << r6.x; -@@ - -msg="WARNING: devm_kzalloc should be used for %s, instead of devm_kmalloc/memset" % (x) -coccilib.report.print_report(p[0], msg) - -//----------------------------------------------------------------- -@r7 depends on org || report@ -type T, T2; -expression x; -expression E1,E2; -statement S; -position p; -@@ - - x = (T)kvmalloc@p(E1,E2); - if ((x==NULL) || ...) S - memset((T2)x,0,E1); - -@script:python depends on org@ -p << r7.p; -x << r7.x; -@@ - -msg="%s" % (x) -msg_safe=msg.replace("[","@(").replace("]",")") -coccilib.org.print_todo(p[0], msg_safe) - -@script:python depends on report@ -p << r7.p; -x << r7.x; -@@ - -msg="WARNING: kvzalloc should be used for %s, instead of kvmalloc/memset" % (x) -coccilib.report.print_report(p[0], msg) - -//----------------------------------------------------------------- -@r8 depends on org || report@ -type T, T2; -expression x; -expression E1,E2,E3; -statement S; -position p; -@@ - - x = (T)pci_alloc_consistent@p(E2,E1,E3); - if ((x==NULL) || ...) S - memset((T2)x,0,E1); - -@script:python depends on org@ -p << r8.p; -x << r8.x; -@@ - -msg="%s" % (x) -msg_safe=msg.replace("[","@(").replace("]",")") -coccilib.org.print_todo(p[0], msg_safe) - -@script:python depends on report@ -p << r8.p; -x << r8.x; -@@ - -msg="WARNING: pci_zalloc_consistent should be used for %s, instead of pci_alloc_consistent/memset" % (x) -coccilib.report.print_report(p[0], msg) -//----------------------------------------------------------------- -@r9 depends on org || report@ -type T, T2; -expression x; -expression E1,E2,E3; -statement S; -position p; -@@ - - x = (T)kvmalloc_node@p(E1,E2,E3); - if ((x==NULL) || ...) S - memset((T2)x,0,E1); - -@script:python depends on org@ -p << r9.p; -x << r9.x; -@@ - -msg="%s" % (x) -msg_safe=msg.replace("[","@(").replace("]",")") -coccilib.org.print_todo(p[0], msg_safe) - -@script:python depends on report@ -p << r9.p; -x << r9.x; -@@ - -msg="WARNING: kvzalloc_node should be used for %s, instead of kvmalloc_node/memset" % (x) -coccilib.report.print_report(p[0], msg) diff --git a/scripts/coccinelle/api/alloc/zalloc-simple.cocci b/scripts/coccinelle/api/alloc/zalloc-simple.cocci new file mode 100644 index 000000000000..92b20913055f --- /dev/null +++ b/scripts/coccinelle/api/alloc/zalloc-simple.cocci @@ -0,0 +1,448 @@ +/// +/// Use zeroing allocator rather than allocator followed by memset with 0 +/// +/// This considers some simple cases that are common and easy to validate +/// Note in particular that there are no ...s in the rule, so all of the +/// matched code has to be contiguous +/// +// Confidence: High +// Copyright: (C) 2009-2010 Julia Lawall, Nicolas Palix, DIKU. GPLv2. +// Copyright: (C) 2009-2010 Gilles Muller, INRIA/LiP6. GPLv2. +// Copyright: (C) 2017 Himanshu Jha GPLv2. +// URL: http://coccinelle.lip6.fr/rules/kzalloc.html +// Options: --no-includes --include-headers +// +// Keywords: kmalloc, kzalloc +// Version min: < 2.6.12 kmalloc +// Version min: 2.6.14 kzalloc +// + +virtual context +virtual patch +virtual org +virtual report + +//---------------------------------------------------------- +// For context mode +//---------------------------------------------------------- + +@depends on context@ +type T, T2; +expression x; +expression E1; +statement S; +@@ + +* x = (T)\(kmalloc(E1, ...)\|vmalloc(E1)\|dma_alloc_coherent(...,E1,...)\| + kmalloc_node(E1, ...)\|kmem_cache_alloc(...)\|kmem_alloc(E1, ...)\| + devm_kmalloc(...,E1,...)\|kvmalloc(E1, ...)\|pci_alloc_consistent(...,E1,...)\| + kvmalloc_node(E1,...)\); + if ((x==NULL) || ...) S +* memset((T2)x,0,E1); + +//---------------------------------------------------------- +// For patch mode +//---------------------------------------------------------- + +@depends on patch@ +type T, T2; +expression x; +expression E1,E2,E3,E4; +statement S; +@@ + +( +- x = kmalloc(E1,E2); ++ x = kzalloc(E1,E2); +| +- x = (T *)kmalloc(E1,E2); ++ x = kzalloc(E1,E2); +| +- x = (T)kmalloc(E1,E2); ++ x = (T)kzalloc(E1,E2); +| +- x = vmalloc(E1); ++ x = vzalloc(E1); +| +- x = (T *)vmalloc(E1); ++ x = vzalloc(E1); +| +- x = (T)vmalloc(E1); ++ x = (T)vzalloc(E1); +| +- x = dma_alloc_coherent(E2,E1,E3,E4); ++ x = dma_zalloc_coherent(E2,E1,E3,E4); +| +- x = (T *)dma_alloc_coherent(E2,E1,E3,E4); ++ x = dma_zalloc_coherent(E2,E1,E3,E4); +| +- x = (T)dma_alloc_coherent(E2,E1,E3,E4); ++ x = (T)dma_zalloc_coherent(E2,E1,E3,E4); +| +- x = kmalloc_node(E1,E2,E3); ++ x = kzalloc_node(E1,E2,E3); +| +- x = (T *)kmalloc_node(E1,E2,E3); ++ x = kzalloc_node(E1,E2,E3); +| +- x = (T)kmalloc_node(E1,E2,E3); ++ x = (T)kzalloc_node(E1,E2,E3); +| +- x = kmem_cache_alloc(E3,E4); ++ x = kmem_cache_zalloc(E3,E4); +| +- x = (T *)kmem_cache_alloc(E3,E4); ++ x = kmem_cache_zalloc(E3,E4); +| +- x = (T)kmem_cache_alloc(E3,E4); ++ x = (T)kmem_cache_zalloc(E3,E4); +| +- x = kmem_alloc(E1,E2); ++ x = kmem_zalloc(E1,E2); +| +- x = (T *)kmem_alloc(E1,E2); ++ x = kmem_zalloc(E1,E2); +| +- x = (T)kmem_alloc(E1,E2); ++ x = (T)kmem_zalloc(E1,E2); +| +- x = devm_kmalloc(E2,E1,E3); ++ x = devm_kzalloc(E2,E1,E3); +| +- x = (T *)devm_kmalloc(E2,E1,E3); ++ x = devm_kzalloc(E2,E1,E3); +| +- x = (T)devm_kmalloc(E2,E1,E3); ++ x = (T)devm_kzalloc(E2,E1,E3); +| +- x = kvmalloc(E1,E2); ++ x = kvzalloc(E1,E2); +| +- x = (T *)kvmalloc(E1,E2); ++ x = kvzalloc(E1,E2); +| +- x = (T)kvmalloc(E1,E2); ++ x = (T)kvzalloc(E1,E2); +| +- x = pci_alloc_consistent(E2,E1,E3); ++ x = pci_zalloc_consistent(E2,E1,E3); +| +- x = (T *)pci_alloc_consistent(E2,E1,E3); ++ x = pci_zalloc_consistent(E2,E1,E3); +| +- x = (T)pci_alloc_consistent(E2,E1,E3); ++ x = (T)pci_zalloc_consistent(E2,E1,E3); +| +- x = kvmalloc_node(E1,E2,E3); ++ x = kvzalloc_node(E1,E2,E3); +| +- x = (T *)kvmalloc_node(E1,E2,E3); ++ x = kvzalloc_node(E1,E2,E3); +| +- x = (T)kvmalloc_node(E1,E2,E3); ++ x = (T)kvzalloc_node(E1,E2,E3); +) + if ((x==NULL) || ...) S +- memset((T2)x,0,E1); + +//---------------------------------------------------------- +// For org mode +//---------------------------------------------------------- + +@r depends on org || report@ +type T, T2; +expression x; +expression E1,E2; +statement S; +position p; +@@ + + x = (T)kmalloc@p(E1,E2); + if ((x==NULL) || ...) S + memset((T2)x,0,E1); + +@script:python depends on org@ +p << r.p; +x << r.x; +@@ + +msg="%s" % (x) +msg_safe=msg.replace("[","@(").replace("]",")") +coccilib.org.print_todo(p[0], msg_safe) + +@script:python depends on report@ +p << r.p; +x << r.x; +@@ + +msg="WARNING: kzalloc should be used for %s, instead of kmalloc/memset" % (x) +coccilib.report.print_report(p[0], msg) + +//----------------------------------------------------------------- +@r1 depends on org || report@ +type T, T2; +expression x; +expression E1; +statement S; +position p; +@@ + + x = (T)vmalloc@p(E1); + if ((x==NULL) || ...) S + memset((T2)x,0,E1); + +@script:python depends on org@ +p << r1.p; +x << r1.x; +@@ + +msg="%s" % (x) +msg_safe=msg.replace("[","@(").replace("]",")") +coccilib.org.print_todo(p[0], msg_safe) + +@script:python depends on report@ +p << r1.p; +x << r1.x; +@@ + +msg="WARNING: vzalloc should be used for %s, instead of vmalloc/memset" % (x) +coccilib.report.print_report(p[0], msg) + +//----------------------------------------------------------------- +@r2 depends on org || report@ +type T, T2; +expression x; +expression E1,E2,E3,E4; +statement S; +position p; +@@ + + x = (T)dma_alloc_coherent@p(E2,E1,E3,E4); + if ((x==NULL) || ...) S + memset((T2)x,0,E1); + +@script:python depends on org@ +p << r2.p; +x << r2.x; +@@ + +msg="%s" % (x) +msg_safe=msg.replace("[","@(").replace("]",")") +coccilib.org.print_todo(p[0], msg_safe) + +@script:python depends on report@ +p << r2.p; +x << r2.x; +@@ + +msg="WARNING: dma_zalloc_coherent should be used for %s, instead of dma_alloc_coherent/memset" % (x) +coccilib.report.print_report(p[0], msg) + +//----------------------------------------------------------------- +@r3 depends on org || report@ +type T, T2; +expression x; +expression E1,E2,E3; +statement S; +position p; +@@ + + x = (T)kmalloc_node@p(E1,E2,E3); + if ((x==NULL) || ...) S + memset((T2)x,0,E1); + +@script:python depends on org@ +p << r3.p; +x << r3.x; +@@ + +msg="%s" % (x) +msg_safe=msg.replace("[","@(").replace("]",")") +coccilib.org.print_todo(p[0], msg_safe) + +@script:python depends on report@ +p << r3.p; +x << r3.x; +@@ + +msg="WARNING: kzalloc_node should be used for %s, instead of kmalloc_node/memset" % (x) +coccilib.report.print_report(p[0], msg) + +//----------------------------------------------------------------- +@r4 depends on org || report@ +type T, T2; +expression x; +expression E1,E2,E3; +statement S; +position p; +@@ + + x = (T)kmem_cache_alloc@p(E2,E3); + if ((x==NULL) || ...) S + memset((T2)x,0,E1); + +@script:python depends on org@ +p << r4.p; +x << r4.x; +@@ + +msg="%s" % (x) +msg_safe=msg.replace("[","@(").replace("]",")") +coccilib.org.print_todo(p[0], msg_safe) + +@script:python depends on report@ +p << r4.p; +x << r4.x; +@@ + +msg="WARNING: kmem_cache_zalloc should be used for %s, instead of kmem_cache_alloc/memset" % (x) +coccilib.report.print_report(p[0], msg) + +//----------------------------------------------------------------- +@r5 depends on org || report@ +type T, T2; +expression x; +expression E1,E2; +statement S; +position p; +@@ + + x = (T)kmem_alloc@p(E1,E2); + if ((x==NULL) || ...) S + memset((T2)x,0,E1); + +@script:python depends on org@ +p << r5.p; +x << r5.x; +@@ + +msg="%s" % (x) +msg_safe=msg.replace("[","@(").replace("]",")") +coccilib.org.print_todo(p[0], msg_safe) + +@script:python depends on report@ +p << r5.p; +x << r5.x; +@@ + +msg="WARNING: kmem_zalloc should be used for %s, instead of kmem_alloc/memset" % (x) +coccilib.report.print_report(p[0], msg) + +//----------------------------------------------------------------- +@r6 depends on org || report@ +type T, T2; +expression x; +expression E1,E2,E3; +statement S; +position p; +@@ + + x = (T)devm_kmalloc@p(E2,E1,E3); + if ((x==NULL) || ...) S + memset((T2)x,0,E1); + +@script:python depends on org@ +p << r6.p; +x << r6.x; +@@ + +msg="%s" % (x) +msg_safe=msg.replace("[","@(").replace("]",")") +coccilib.org.print_todo(p[0], msg_safe) + +@script:python depends on report@ +p << r6.p; +x << r6.x; +@@ + +msg="WARNING: devm_kzalloc should be used for %s, instead of devm_kmalloc/memset" % (x) +coccilib.report.print_report(p[0], msg) + +//----------------------------------------------------------------- +@r7 depends on org || report@ +type T, T2; +expression x; +expression E1,E2; +statement S; +position p; +@@ + + x = (T)kvmalloc@p(E1,E2); + if ((x==NULL) || ...) S + memset((T2)x,0,E1); + +@script:python depends on org@ +p << r7.p; +x << r7.x; +@@ + +msg="%s" % (x) +msg_safe=msg.replace("[","@(").replace("]",")") +coccilib.org.print_todo(p[0], msg_safe) + +@script:python depends on report@ +p << r7.p; +x << r7.x; +@@ + +msg="WARNING: kvzalloc should be used for %s, instead of kvmalloc/memset" % (x) +coccilib.report.print_report(p[0], msg) + +//----------------------------------------------------------------- +@r8 depends on org || report@ +type T, T2; +expression x; +expression E1,E2,E3; +statement S; +position p; +@@ + + x = (T)pci_alloc_consistent@p(E2,E1,E3); + if ((x==NULL) || ...) S + memset((T2)x,0,E1); + +@script:python depends on org@ +p << r8.p; +x << r8.x; +@@ + +msg="%s" % (x) +msg_safe=msg.replace("[","@(").replace("]",")") +coccilib.org.print_todo(p[0], msg_safe) + +@script:python depends on report@ +p << r8.p; +x << r8.x; +@@ + +msg="WARNING: pci_zalloc_consistent should be used for %s, instead of pci_alloc_consistent/memset" % (x) +coccilib.report.print_report(p[0], msg) +//----------------------------------------------------------------- +@r9 depends on org || report@ +type T, T2; +expression x; +expression E1,E2,E3; +statement S; +position p; +@@ + + x = (T)kvmalloc_node@p(E1,E2,E3); + if ((x==NULL) || ...) S + memset((T2)x,0,E1); + +@script:python depends on org@ +p << r9.p; +x << r9.x; +@@ + +msg="%s" % (x) +msg_safe=msg.replace("[","@(").replace("]",")") +coccilib.org.print_todo(p[0], msg_safe) + +@script:python depends on report@ +p << r9.p; +x << r9.x; +@@ + +msg="WARNING: kvzalloc_node should be used for %s, instead of kvmalloc_node/memset" % (x) +coccilib.report.print_report(p[0], msg) -- cgit v1.2.3 From 25899e02819944ffe7cbbf9b3350cb33beb90865 Mon Sep 17 00:00:00 2001 From: Julia Lawall Date: Sat, 27 Jan 2018 19:23:36 +0100 Subject: Coccinelle: memdup: drop spurious line The kmemdup line in the non-patch case was left over from the added kmemdup line in the patch case. Signed-off-by: Julia Lawall Signed-off-by: Masahiro Yamada --- scripts/coccinelle/api/memdup.cocci | 1 - 1 file changed, 1 deletion(-) (limited to 'scripts') diff --git a/scripts/coccinelle/api/memdup.cocci b/scripts/coccinelle/api/memdup.cocci index 3d1aa71b7579..1249b727644b 100644 --- a/scripts/coccinelle/api/memdup.cocci +++ b/scripts/coccinelle/api/memdup.cocci @@ -49,7 +49,6 @@ statement S; @@ * to = \(kmalloc@p\|kzalloc@p\)(size,flag); - to = kmemdup(from,size,flag); if (to==NULL || ...) S * memcpy(to, from, size); -- cgit v1.2.3 From 1640eea35e8dcf0cb437f03c56868a97d0666df3 Mon Sep 17 00:00:00 2001 From: Julia Lawall Date: Thu, 1 Feb 2018 10:20:55 +0100 Subject: Coccinelle: coccicheck: fix typo Correct spelling of "coccinelle". Signed-off-by: Julia Lawall Signed-off-by: Masahiro Yamada --- scripts/coccicheck | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'scripts') diff --git a/scripts/coccicheck b/scripts/coccicheck index ecfac64b39fe..9fedca611b7f 100755 --- a/scripts/coccicheck +++ b/scripts/coccicheck @@ -177,7 +177,7 @@ coccinelle () { REQ_NUM=$(echo $REQ | ${DIR}/scripts/ld-version.sh) if [ "$REQ_NUM" != "0" ] ; then if [ "$SPATCH_VERSION_NUM" -lt "$REQ_NUM" ] ; then - echo "Skipping coccinele SmPL patch: $COCCI" + echo "Skipping coccinelle SmPL patch: $COCCI" echo "You have coccinelle: $SPATCH_VERSION" echo "This SmPL patch requires: $REQ" return -- cgit v1.2.3