Re: [PATCH] Coccinelle: Script to replace allocate and memcpy with zalloc functions
Dne 23.7.2016 v 23:00 Amitoj Kaur Chawla napsal(a): > This script finds instances of allocate and memcpy which can be > replaced with a direct call to zalloc equivalent of a function. > > Signed-off-by: Amitoj Kaur Chawla > --- > scripts/coccinelle/api/zalloc.cocci | 556 > > 1 file changed, 556 insertions(+) > create mode 100644 scripts/coccinelle/api/zalloc.cocci > > diff --git a/scripts/coccinelle/api/zalloc.cocci > b/scripts/coccinelle/api/zalloc.cocci > new file mode 100644 > index 000..4f94e43 > --- /dev/null > +++ b/scripts/coccinelle/api/zalloc.cocci > @@ -0,0 +1,556 @@ > +/// Prefer zalloc functions instead of using allocate and memcpy. s/memcpy/memset/ ? The actual spatch names the correct function. Michal
Re: [PATCH] Coccinelle: Script to replace allocate and memcpy with zalloc functions
On Sun, 24 Jul 2016, Amitoj Kaur Chawla wrote: > This script finds instances of allocate and memcpy which can be > replaced with a direct call to zalloc equivalent of a function. > > Signed-off-by: Amitoj Kaur Chawla Acked-by: Julia Lawall > --- > scripts/coccinelle/api/zalloc.cocci | 556 > > 1 file changed, 556 insertions(+) > create mode 100644 scripts/coccinelle/api/zalloc.cocci > > diff --git a/scripts/coccinelle/api/zalloc.cocci > b/scripts/coccinelle/api/zalloc.cocci > new file mode 100644 > index 000..4f94e43 > --- /dev/null > +++ b/scripts/coccinelle/api/zalloc.cocci > @@ -0,0 +1,556 @@ > +/// Prefer zalloc functions instead of using allocate and memcpy. > +/// > +// Confidence: High > +// Copyright: (C) 2016 Amitoj Kaur Chawla > + > +virtual patch > +virtual context > +virtual org > +virtual report > + > +@dma1 depends on patch && !context && !org && !report@ > +type T; > +T *d; > +statement S; > +@@ > + > +d = > +-dma_pool_alloc > ++dma_pool_zalloc > + (...); > +if (!d) S > +- memset(d, 0, sizeof(T)); > + > +@dma2 depends on patch && !context && !org && !report@ > +expression d; > +statement S; > +@@ > + > +d = > +-dma_pool_alloc > ++dma_pool_zalloc > + (...); > +if (!d) S > +- memset(d, 0, sizeof(*d)); > +@vz1 depends on patch && !context && !org && !report@ > +type T; > +T *d; > +statement S; > +@@ > + > +d = > +-vmalloc > ++vzalloc > + (...); > +if (!d) S > +- memset(d, 0, sizeof(T)); > + > +@vz2 depends on patch && !context && !org && !report@ > +expression d; > +statement S; > +@@ > + > +d = > +-vmalloc > ++vzalloc > + (...); > +if (!d) S > +- memset(d, 0, sizeof(*d)); > +@vzn1 depends on patch && !context && !org && !report@ > +type T; > +T *d; > +statement S; > +@@ > + > +d = > +-vmalloc_node > ++vzalloc_node > + (...); > +if (!d) S > +- memset(d, 0, sizeof(T)); > + > +@vzn2 depends on patch && !context && !org && !report@ > +expression d; > +statement S; > +@@ > + > +d = > +-vmalloc_node > ++vzalloc_node > + (...); > +if (!d) S > +- memset(d, 0, sizeof(*d)); > +@pci1 depends on patch && !context && !org && !report@ > +type T; > +T *d; > +statement S; > +@@ > + > +d = > +-pci_alloc_consistent > ++pci_zalloc_consistent > + (...); > +if (!d) S > +- memset(d, 0, sizeof(T)); > + > +@pci2 depends on patch && !context && !org && !report@ > +expression d; > +statement S; > +@@ > + > +d = > +-pci_alloc_consistent > ++pci_zalloc_consistent > + (...); > +if (!d) S > +- memset(d, 0, sizeof(*d)); > +@kmem1 depends on patch && !context && !org && !report@ > +type T; > +T *d; > +statement S; > +@@ > + > +d = > +-kmem_cache_alloc > ++kmem_cache_zalloc > + (...); > +if (!d) S > +- memset(d, 0, sizeof(T)); > + > +@kmem2 depends on patch && !context && !org && !report@ > +expression d; > +statement S; > +@@ > + > +d = > +-kmem_cache_alloc > ++kmem_cache_zalloc > + (...); > +if (!d) S > +- memset(d, 0, sizeof(*d)); > +@dma3 depends on patch && !context && !org && !report@ > +type T; > +T *d; > +statement S; > +@@ > + > +d = > +-dma_alloc_coherent > ++dma_zalloc_coherent > + (...); > +if (!d) S > +- memset(d, 0, sizeof(T)); > + > +@dma4 depends on patch && !context && !org && !report@ > +expression d; > +statement S; > +@@ > + > +d = > +-dma_alloc_coherent > ++dma_zalloc_coherent > + (...); > +if (!d) S > +- memset(d, 0, sizeof(*d)); > +@acpi1 depends on patch && !context && !org && !report@ > +type T; > +T *d; > +statement S; > +@@ > + > +d = > +-acpi_os_allocate > ++acpi_os_allocate_zeroed > + (...); > +if (!d) S > +- memset(d, 0, sizeof(T)); > + > +@acpi2 depends on patch && !context && !org && !report@ > +expression d; > +statement S; > +@@ > + > +d = > +-acpi_os_allocate > ++acpi_os_allocate_zeroed > + (...); > +if (!d) S > +- memset(d, 0, sizeof(*d)); > + > +// > > + > +@dma1_context depends on !patch && (context || org || report)@ > +type T; > +statement S; > +T *d; > +position j0; > +@@ > + > +d@j0 = > +* dma_pool_alloc > + (...); > +if (!d) S > +*memset(d, 0, sizeof(T)); > + > +@dma2_context depends on !patch && (context || org ||
[PATCH] Coccinelle: Script to replace allocate and memcpy with zalloc functions
This script finds instances of allocate and memcpy which can be replaced with a direct call to zalloc equivalent of a function. Signed-off-by: Amitoj Kaur Chawla --- scripts/coccinelle/api/zalloc.cocci | 556 1 file changed, 556 insertions(+) create mode 100644 scripts/coccinelle/api/zalloc.cocci diff --git a/scripts/coccinelle/api/zalloc.cocci b/scripts/coccinelle/api/zalloc.cocci new file mode 100644 index 000..4f94e43 --- /dev/null +++ b/scripts/coccinelle/api/zalloc.cocci @@ -0,0 +1,556 @@ +/// Prefer zalloc functions instead of using allocate and memcpy. +/// +// Confidence: High +// Copyright: (C) 2016 Amitoj Kaur Chawla + +virtual patch +virtual context +virtual org +virtual report + +@dma1 depends on patch && !context && !org && !report@ +type T; +T *d; +statement S; +@@ + +d = +-dma_pool_alloc ++dma_pool_zalloc + (...); +if (!d) S +- memset(d, 0, sizeof(T)); + +@dma2 depends on patch && !context && !org && !report@ +expression d; +statement S; +@@ + +d = +-dma_pool_alloc ++dma_pool_zalloc + (...); +if (!d) S +- memset(d, 0, sizeof(*d)); +@vz1 depends on patch && !context && !org && !report@ +type T; +T *d; +statement S; +@@ + +d = +-vmalloc ++vzalloc + (...); +if (!d) S +- memset(d, 0, sizeof(T)); + +@vz2 depends on patch && !context && !org && !report@ +expression d; +statement S; +@@ + +d = +-vmalloc ++vzalloc + (...); +if (!d) S +- memset(d, 0, sizeof(*d)); +@vzn1 depends on patch && !context && !org && !report@ +type T; +T *d; +statement S; +@@ + +d = +-vmalloc_node ++vzalloc_node + (...); +if (!d) S +- memset(d, 0, sizeof(T)); + +@vzn2 depends on patch && !context && !org && !report@ +expression d; +statement S; +@@ + +d = +-vmalloc_node ++vzalloc_node + (...); +if (!d) S +- memset(d, 0, sizeof(*d)); +@pci1 depends on patch && !context && !org && !report@ +type T; +T *d; +statement S; +@@ + +d = +-pci_alloc_consistent ++pci_zalloc_consistent + (...); +if (!d) S +- memset(d, 0, sizeof(T)); + +@pci2 depends on patch && !context && !org && !report@ +expression d; +statement S; +@@ + +d = +-pci_alloc_consistent ++pci_zalloc_consistent + (...); +if (!d) S +- memset(d, 0, sizeof(*d)); +@kmem1 depends on patch && !context && !org && !report@ +type T; +T *d; +statement S; +@@ + +d = +-kmem_cache_alloc ++kmem_cache_zalloc + (...); +if (!d) S +- memset(d, 0, sizeof(T)); + +@kmem2 depends on patch && !context && !org && !report@ +expression d; +statement S; +@@ + +d = +-kmem_cache_alloc ++kmem_cache_zalloc + (...); +if (!d) S +- memset(d, 0, sizeof(*d)); +@dma3 depends on patch && !context && !org && !report@ +type T; +T *d; +statement S; +@@ + +d = +-dma_alloc_coherent ++dma_zalloc_coherent + (...); +if (!d) S +- memset(d, 0, sizeof(T)); + +@dma4 depends on patch && !context && !org && !report@ +expression d; +statement S; +@@ + +d = +-dma_alloc_coherent ++dma_zalloc_coherent + (...); +if (!d) S +- memset(d, 0, sizeof(*d)); +@acpi1 depends on patch && !context && !org && !report@ +type T; +T *d; +statement S; +@@ + +d = +-acpi_os_allocate ++acpi_os_allocate_zeroed + (...); +if (!d) S +- memset(d, 0, sizeof(T)); + +@acpi2 depends on patch && !context && !org && !report@ +expression d; +statement S; +@@ + +d = +-acpi_os_allocate ++acpi_os_allocate_zeroed + (...); +if (!d) S +- memset(d, 0, sizeof(*d)); + +// + +@dma1_context depends on !patch && (context || org || report)@ +type T; +statement S; +T *d; +position j0; +@@ + +d@j0 = +* dma_pool_alloc + (...); +if (!d) S +*memset(d, 0, sizeof(T)); + +@dma2_context depends on !patch && (context || org || report)@ +statement S; +expression d; +position j0; +@@ + +d@j0 = +* dma_pool_alloc + (...); +if (!d) S +*memset(d, 0, sizeof(*d)); + +@vz1_context depends on !patch && (context || org || report)@ +type T; +statement S; +T *d; +position j0; +@@ + +d@j0 = +* vmalloc + (...); +if (!d) S +*memset(d, 0, sizeof(T)); + +@vz2_context depends on !patch && (context || org || report)@ +statement S; +expression