diff options
Diffstat (limited to 'scripts')
| -rw-r--r-- | scripts/Makefile.autofdo | 2 | ||||
| -rw-r--r-- | scripts/coccinelle/api/devm_kmalloc_objs.cocci | 136 | ||||
| -rw-r--r-- | scripts/coccinelle/api/kmalloc_objs.cocci | 114 | ||||
| -rw-r--r-- | scripts/coccinelle/free/cleanup-free.cocci | 112 | ||||
| -rw-r--r-- | scripts/coccinelle/misc/array_end.cocci | 73 | ||||
| -rwxr-xr-x | scripts/get_maintainer.pl | 43 |
6 files changed, 431 insertions, 49 deletions
diff --git a/scripts/Makefile.autofdo b/scripts/Makefile.autofdo index 57a3aba6ffc2..32c18df237f1 100644 --- a/scripts/Makefile.autofdo +++ b/scripts/Makefile.autofdo @@ -13,7 +13,7 @@ endif ifdef CLANG_AUTOFDO_PROFILE CFLAGS_AUTOFDO_CLANG += -fprofile-sample-use=$(CLANG_AUTOFDO_PROFILE) -ffunction-sections CFLAGS_AUTOFDO_CLANG += -fsplit-machine-functions - RUSTFLAGS_AUTOFDO_CLANG += -Zprofile-sample-use=$(CLANG_AUTOFDO_PROFILE) -Zfunction-sections=y + RUSTFLAGS_AUTOFDO_CLANG += $(if $(call rustc-min-version,110000),-Cprofile-sample-use,-Zprofile-sample-use)=$(CLANG_AUTOFDO_PROFILE) -Zfunction-sections=y RUSTFLAGS_AUTOFDO_CLANG += -Cllvm-args=-split-machine-functions endif diff --git a/scripts/coccinelle/api/devm_kmalloc_objs.cocci b/scripts/coccinelle/api/devm_kmalloc_objs.cocci new file mode 100644 index 000000000000..322f79a2d965 --- /dev/null +++ b/scripts/coccinelle/api/devm_kmalloc_objs.cocci @@ -0,0 +1,136 @@ +// SPDX-License-Identifier: GPL-2.0-only +/// Use devm_kmalloc_obj family of macros for allocations +/// +// Confidence: High +// Options: --include-headers-for-types --all-includes --include-headers --keep-comments + +virtual patch + +@initialize:python@ +@@ +import sys + +def alloc_array(name): + func = "FAILED_RENAME" + if name == "devm_kmalloc_array": + func = "devm_kmalloc_objs" + elif name == "devm_kvmalloc_array": + func = "devm_kvmalloc_objs" + elif name == "devm_kcalloc": + func = "devm_kzalloc_objs" + elif name == "devm_kvcalloc": + func = "devm_kvzalloc_objs" + else: + print(f"Unknown transform for {name}", file=sys.stderr) + return func + +// This excludes anything that is assigning to or from integral types or +// string literals. Everything else gets the sizeof() extracted for the +// kmalloc_obj() type/var argument. sizeof(void *) is also excluded because +// it will need case-by-case double-checking to make sure the right type is +// being assigned. +@direct depends on patch && !(file in "tools") && !(file in "samples")@ +typedef u8, u16, u32, u64; +typedef __u8, __u16, __u32, __u64; +typedef uint8_t, uint16_t, uint32_t, uint64_t; +typedef uchar, ushort, uint, ulong; +typedef __le16, __le32, __le64; +typedef __be16, __be32, __be64; +typedef wchar_t; +type INTEGRAL = {u8,__u8,uint8_t,char,unsigned char,uchar,wchar_t, + u16,__u16,uint16_t,unsigned short,ushort, + u32,__u32,uint32_t,unsigned int,uint, + u64,__u64,uint64_t,unsigned long,ulong, + __le16,__le32,__le64,__be16,__be32,__be64}; +char [] STRING; +INTEGRAL *BYTES; +INTEGRAL **BYTES_PTRS; +type TYPE; +expression VAR; +expression GFP; +expression COUNT; +expression FLEX; +expression E; +expression DEV; +identifier ALLOC =~ "^devm_kv?[mz]alloc$"; +fresh identifier ALLOC_OBJ = ALLOC ## "_obj"; +fresh identifier ALLOC_FLEX = ALLOC ## "_flex"; +identifier ALLOC_ARRAY = {devm_kmalloc_array,devm_kvmalloc_array,devm_kcalloc,devm_kvcalloc}; +fresh identifier ALLOC_OBJS = script:python(ALLOC_ARRAY) { alloc_array(ALLOC_ARRAY) }; +@@ + +( +- VAR = ALLOC(DEV,(sizeof(*VAR)), GFP) ++ VAR = ALLOC_OBJ(DEV,*VAR, GFP) +| + ALLOC(DEV,(\(sizeof(STRING)\|sizeof(INTEGRAL)\|sizeof(INTEGRAL *)\)), GFP) +| + BYTES = ALLOC(DEV,(sizeof(E)), GFP) +| + BYTES = ALLOC(DEV,(sizeof(TYPE)), GFP) +| + BYTES_PTRS = ALLOC(DEV,(sizeof(E)), GFP) +| + BYTES_PTRS = ALLOC(DEV,(sizeof(TYPE)), GFP) +| + ALLOC(DEV,(sizeof(void *)), GFP) +| +- ALLOC(DEV,(sizeof(E)), GFP) ++ ALLOC_OBJ(DEV, E, GFP) +| +- ALLOC(DEV,(sizeof(TYPE)), GFP) ++ ALLOC_OBJ(DEV,TYPE, GFP) +| + ALLOC_ARRAY(DEV,COUNT, (\(sizeof(STRING)\|sizeof(INTEGRAL)\|sizeof(INTEGRAL *)\)), GFP) +| + BYTES = ALLOC_ARRAY(DEV, COUNT, (sizeof(E)), GFP) +| + BYTES = ALLOC_ARRAY(DEV,COUNT, (sizeof(TYPE)), GFP) +| + BYTES_PTRS = ALLOC_ARRAY(DEV, COUNT, (sizeof(E)), GFP) +| + BYTES_PTRS = ALLOC_ARRAY(DEV, COUNT, (sizeof(TYPE)), GFP) +| + ALLOC_ARRAY(DEV, (\(sizeof(STRING)\|sizeof(INTEGRAL)\|sizeof(INTEGRAL *)\)), COUNT, GFP) +| + BYTES = ALLOC_ARRAY(DEV, (sizeof(E)), COUNT, GFP) +| + BYTES = ALLOC_ARRAY(DEV, (sizeof(TYPE)), COUNT, GFP) +| + BYTES_PTRS = ALLOC_ARRAY(DEV, (sizeof(E)), COUNT, GFP) +| + BYTES_PTRS = ALLOC_ARRAY(DEV, (sizeof(TYPE)), COUNT, GFP) +| + ALLOC_ARRAY(DEV, COUNT, (sizeof(void *)), GFP) +| + ALLOC_ARRAY(DEV, (sizeof(void *)), COUNT, GFP) +| +- ALLOC_ARRAY(DEV, COUNT, (sizeof(E)), GFP) ++ ALLOC_OBJS(DEV, E, COUNT, GFP) +| +- ALLOC_ARRAY(DEV, COUNT, (sizeof(TYPE)), GFP) ++ ALLOC_OBJS(DEV, TYPE, COUNT, GFP) +| +- ALLOC_ARRAY(DEV, (sizeof(E)), COUNT, GFP) ++ ALLOC_OBJS(DEV, E, COUNT, GFP) +| +- ALLOC_ARRAY(DEV, (sizeof(TYPE)), COUNT, GFP) ++ ALLOC_OBJS(DEV, TYPE, COUNT, GFP) +| +- ALLOC(DEV, struct_size(VAR, FLEX, COUNT), GFP) ++ ALLOC_FLEX(DEV, *VAR, FLEX, COUNT, GFP) +| +- ALLOC(DEV, struct_size_t(TYPE, FLEX, COUNT), GFP) ++ ALLOC_FLEX(DEV, TYPE, FLEX, COUNT, GFP) +) + +@drop_gfp_kernel depends on patch && !(file in "tools") && !(file in "samples")@ +identifier ALLOC = {devm_kmalloc_obj,devm_kmalloc_objs,devm_kmalloc_flex, + devm_kzalloc_obj,devm_kzalloc_objs,devm_kzalloc_flex, + devm_kvmalloc_obj,devm_kvmalloc_objs,devm_kvmalloc_flex, + devm_kvzalloc_obj,devm_kvzalloc_objs,devm_kvzalloc_flex}; +@@ + + ALLOC(... +- , GFP_KERNEL + ) diff --git a/scripts/coccinelle/api/kmalloc_objs.cocci b/scripts/coccinelle/api/kmalloc_objs.cocci index 0a98ddf03eca..e47604f7a1a6 100644 --- a/scripts/coccinelle/api/kmalloc_objs.cocci +++ b/scripts/coccinelle/api/kmalloc_objs.cocci @@ -20,6 +20,10 @@ def alloc_array(name): func = "kzalloc_objs" elif name == "kvcalloc": func = "kvzalloc_objs" + elif name == "devm_kmalloc_array": + func = "devm_kmalloc_objs" + elif name == "devm_kcalloc": + func = "devm_kzalloc_objs" else: print(f"Unknown transform for {name}", file=sys.stderr) return func @@ -42,6 +46,15 @@ def alloc_array(name): // Everything else gets the sizeof() extracted for the kmalloc_obj() // type/var argument. // +// The device-managed allocators differ from the plain ones only by taking +// the managing "struct device *" as a leading argument, so rather than +// repeating every pattern for them, the leading arguments are captured in +// an "expression list" metavariable and replayed on the replacement side. +// ARGS is empty for the plain allocators, in which case Coccinelle drops +// the separating comma as well. Note that there is no devm_kvmalloc +// family, and that the devm array helpers only exist as +// (dev, count, size, gfp). +// // The first matching alternative below wins, so the exclusions must come // before the more general conversions. @direct depends on patch && !(file in "tools") && !(file in "samples")@ @@ -81,150 +94,155 @@ expression GFP; expression COUNT; expression FLEX; expression E; -identifier ALLOC =~ "^kv?[mz]alloc$"; +expression list ARGS; +identifier ALLOC = {kmalloc,kzalloc,kvmalloc,kvzalloc, + devm_kmalloc,devm_kzalloc}; fresh identifier ALLOC_OBJ = ALLOC ## "_obj"; fresh identifier ALLOC_FLEX = ALLOC ## "_flex"; -identifier ALLOC_ARRAY = {kmalloc_array,kvmalloc_array,kcalloc,kvcalloc}; +identifier ALLOC_ARRAY = {kmalloc_array,kvmalloc_array,kcalloc,kvcalloc, + devm_kmalloc_array,devm_kcalloc}; fresh identifier ALLOC_OBJS = script:python(ALLOC_ARRAY) { alloc_array(ALLOC_ARRAY) }; @@ ( // Convert a single object sized by its target: p = kmalloc(sizeof(*p), gfp) -- VAR = ALLOC((sizeof(*VAR)), GFP) -+ VAR = ALLOC_OBJ(*VAR, GFP) +- VAR = ALLOC(ARGS, (sizeof(*VAR)), GFP) ++ VAR = ALLOC_OBJ(ARGS, *VAR, GFP) | // Exclude byte buffers and integral pointers: kmalloc(sizeof(u8), gfp), // kmalloc(sizeof("str"), gfp), kmalloc(sizeof(char *), gfp) - ALLOC((\(sizeof(STRING)\|sizeof(BYTE_TYPES)\| + ALLOC(ARGS, (\(sizeof(STRING)\|sizeof(BYTE_TYPES)\| sizeof(BYTE_TYPES *)\|sizeof(MULTIBYTE_TYPES *)\)), GFP) | // Exclude anything assigned to a byte pointer: // u8 *buf = kmalloc(sizeof(*hdr), gfp) - BYTES = ALLOC((\(sizeof(E)\|sizeof(TYPE)\)), GFP) + BYTES = ALLOC(ARGS, (\(sizeof(E)\|sizeof(TYPE)\)), GFP) | // Convert a multi-byte type to a pointer to it: // u32 *p = kmalloc(sizeof(u32), gfp) \(MULTIBYTES\|CONST_MULTIBYTES\) = -- ALLOC((sizeof(MULTIBYTE_TYPES)), GFP) -+ ALLOC_OBJ(MULTIBYTE_TYPES, GFP) +- ALLOC(ARGS, (sizeof(MULTIBYTE_TYPES)), GFP) ++ ALLOC_OBJ(ARGS, MULTIBYTE_TYPES, GFP) | // Same by expression: u32 *p = kmalloc(sizeof(p[0]), gfp) \(MULTIBYTES\|CONST_MULTIBYTES\) = -- ALLOC((sizeof(MULTIBYTE)), GFP) -+ ALLOC_OBJ(MULTIBYTE, GFP) +- ALLOC(ARGS, (sizeof(MULTIBYTE)), GFP) ++ ALLOC_OBJ(ARGS, MULTIBYTE, GFP) | // Exclude other multi-byte sizes, e.g. to pointers to arrays: s16 (*p)[2] = ... - ALLOC((\(sizeof(MULTIBYTE_TYPES)\|sizeof(MULTIBYTE)\)), GFP) + ALLOC(ARGS, (\(sizeof(MULTIBYTE_TYPES)\|sizeof(MULTIBYTE)\)), GFP) | // Exclude anything else assigned to a multi-byte pointer: // u32 *p = kmalloc(sizeof(*hdr), gfp) - \(MULTIBYTES\|CONST_MULTIBYTES\) = ALLOC((\(sizeof(E)\|sizeof(TYPE)\)), GFP) + \(MULTIBYTES\|CONST_MULTIBYTES\) = ALLOC(ARGS, (\(sizeof(E)\|sizeof(TYPE)\)), GFP) | // Exclude void pointers, to be checked by hand: kmalloc(sizeof(void *), gfp) - ALLOC((sizeof(void *)), GFP) + ALLOC(ARGS, (sizeof(void *)), GFP) | // Convert any other expression: p = kmalloc(sizeof(s->item), gfp) -- ALLOC((sizeof(E)), GFP) -+ ALLOC_OBJ(E, GFP) +- ALLOC(ARGS, (sizeof(E)), GFP) ++ ALLOC_OBJ(ARGS, E, GFP) | // Convert any other type: p = kmalloc(sizeof(struct item), gfp) -- ALLOC((sizeof(TYPE)), GFP) -+ ALLOC_OBJ(TYPE, GFP) +- ALLOC(ARGS, (sizeof(TYPE)), GFP) ++ ALLOC_OBJ(ARGS, TYPE, GFP) | // The same, for arrays allocated as (count, size): // Exclude byte buffers and integral pointers: kcalloc(n, sizeof(u8), gfp), // kcalloc(n, sizeof(char *), gfp) - ALLOC_ARRAY(COUNT, (\(sizeof(STRING)\|sizeof(BYTE_TYPES)\| + ALLOC_ARRAY(ARGS, COUNT, (\(sizeof(STRING)\|sizeof(BYTE_TYPES)\| sizeof(BYTE_TYPES *)\|sizeof(MULTIBYTE_TYPES *)\)), GFP) | // Exclude arrays assigned to a byte pointer: // u8 *buf = kcalloc(n, sizeof(*hdr), gfp) - BYTES = ALLOC_ARRAY(COUNT, (\(sizeof(E)\|sizeof(TYPE)\)), GFP) + BYTES = ALLOC_ARRAY(ARGS, COUNT, (\(sizeof(E)\|sizeof(TYPE)\)), GFP) | // Convert a multi-byte array to a pointer to it: // u32 *p = kcalloc(n, sizeof(u32), gfp) \(MULTIBYTES\|CONST_MULTIBYTES\) = -- ALLOC_ARRAY(COUNT, (sizeof(MULTIBYTE_TYPES)), GFP) -+ ALLOC_OBJS(MULTIBYTE_TYPES, COUNT, GFP) +- ALLOC_ARRAY(ARGS, COUNT, (sizeof(MULTIBYTE_TYPES)), GFP) ++ ALLOC_OBJS(ARGS, MULTIBYTE_TYPES, COUNT, GFP) | // Same by expression: u32 *p = kcalloc(n, sizeof(*p), gfp) \(MULTIBYTES\|CONST_MULTIBYTES\) = -- ALLOC_ARRAY(COUNT, (sizeof(MULTIBYTE)), GFP) -+ ALLOC_OBJS(MULTIBYTE, COUNT, GFP) +- ALLOC_ARRAY(ARGS, COUNT, (sizeof(MULTIBYTE)), GFP) ++ ALLOC_OBJS(ARGS, MULTIBYTE, COUNT, GFP) | // Exclude other multi-byte arrays: // s16 (*pairs)[2] = kcalloc(n, sizeof(s16), gfp) - ALLOC_ARRAY(COUNT, (\(sizeof(MULTIBYTE_TYPES)\|sizeof(MULTIBYTE)\)), GFP) + ALLOC_ARRAY(ARGS, COUNT, (\(sizeof(MULTIBYTE_TYPES)\|sizeof(MULTIBYTE)\)), GFP) | // Exclude other arrays assigned to a multi-byte pointer: // u32 *p = kcalloc(n, sizeof(*hdr), gfp) - \(MULTIBYTES\|CONST_MULTIBYTES\) = ALLOC_ARRAY(COUNT, (\(sizeof(E)\|sizeof(TYPE)\)), GFP) + \(MULTIBYTES\|CONST_MULTIBYTES\) = ALLOC_ARRAY(ARGS, COUNT, (\(sizeof(E)\|sizeof(TYPE)\)), GFP) | // Exclude arrays of void pointers: kcalloc(n, sizeof(void *), gfp) - ALLOC_ARRAY(COUNT, (sizeof(void *)), GFP) + ALLOC_ARRAY(ARGS, COUNT, (sizeof(void *)), GFP) | // Convert any other expression: p = kcalloc(n, sizeof(*p), gfp) -- ALLOC_ARRAY(COUNT, (sizeof(E)), GFP) -+ ALLOC_OBJS(E, COUNT, GFP) +- ALLOC_ARRAY(ARGS, COUNT, (sizeof(E)), GFP) ++ ALLOC_OBJS(ARGS, E, COUNT, GFP) | // Convert any other type: p = kcalloc(n, sizeof(struct item), gfp) -- ALLOC_ARRAY(COUNT, (sizeof(TYPE)), GFP) -+ ALLOC_OBJS(TYPE, COUNT, GFP) +- ALLOC_ARRAY(ARGS, COUNT, (sizeof(TYPE)), GFP) ++ ALLOC_OBJS(ARGS, TYPE, COUNT, GFP) | // The same, for arrays allocated as (size, count): // Exclude byte buffers and integral pointers: kcalloc(sizeof(u8), n, gfp), // kcalloc(sizeof(char *), n, gfp) - ALLOC_ARRAY((\(sizeof(STRING)\|sizeof(BYTE_TYPES)\| + ALLOC_ARRAY(ARGS, (\(sizeof(STRING)\|sizeof(BYTE_TYPES)\| sizeof(BYTE_TYPES *)\|sizeof(MULTIBYTE_TYPES *)\)), COUNT, GFP) | // Exclude arrays assigned to a byte pointer: // u8 *buf = kcalloc(sizeof(*hdr), n, gfp) - BYTES = ALLOC_ARRAY((\(sizeof(E)\|sizeof(TYPE)\)), COUNT, GFP) + BYTES = ALLOC_ARRAY(ARGS, (\(sizeof(E)\|sizeof(TYPE)\)), COUNT, GFP) | // Convert a multi-byte array to a pointer to it: // u32 *p = kcalloc(sizeof(u32), n, gfp) \(MULTIBYTES\|CONST_MULTIBYTES\) = -- ALLOC_ARRAY((sizeof(MULTIBYTE_TYPES)), COUNT, GFP) -+ ALLOC_OBJS(MULTIBYTE_TYPES, COUNT, GFP) +- ALLOC_ARRAY(ARGS, (sizeof(MULTIBYTE_TYPES)), COUNT, GFP) ++ ALLOC_OBJS(ARGS, MULTIBYTE_TYPES, COUNT, GFP) | // Same by expression: u32 *p = kcalloc(sizeof(*p), n, gfp) \(MULTIBYTES\|CONST_MULTIBYTES\) = -- ALLOC_ARRAY((sizeof(MULTIBYTE)), COUNT, GFP) -+ ALLOC_OBJS(MULTIBYTE, COUNT, GFP) +- ALLOC_ARRAY(ARGS, (sizeof(MULTIBYTE)), COUNT, GFP) ++ ALLOC_OBJS(ARGS, MULTIBYTE, COUNT, GFP) | // Exclude other multi-byte arrays: // s16 (*pairs)[2] = kcalloc(sizeof(s16), n, gfp) - ALLOC_ARRAY((\(sizeof(MULTIBYTE_TYPES)\|sizeof(MULTIBYTE)\)), COUNT, GFP) + ALLOC_ARRAY(ARGS, (\(sizeof(MULTIBYTE_TYPES)\|sizeof(MULTIBYTE)\)), COUNT, GFP) | // Exclude other arrays assigned to a multi-byte pointer: // u32 *p = kcalloc(sizeof(*hdr), n, gfp) - \(MULTIBYTES\|CONST_MULTIBYTES\) = ALLOC_ARRAY((\(sizeof(E)\|sizeof(TYPE)\)), COUNT, GFP) + \(MULTIBYTES\|CONST_MULTIBYTES\) = ALLOC_ARRAY(ARGS, (\(sizeof(E)\|sizeof(TYPE)\)), COUNT, GFP) | // Exclude arrays of void pointers: kcalloc(sizeof(void *), n, gfp) - ALLOC_ARRAY((sizeof(void *)), COUNT, GFP) + ALLOC_ARRAY(ARGS, (sizeof(void *)), COUNT, GFP) | // Convert any other expression: p = kcalloc(sizeof(*p), n, gfp) -- ALLOC_ARRAY((sizeof(E)), COUNT, GFP) -+ ALLOC_OBJS(E, COUNT, GFP) +- ALLOC_ARRAY(ARGS, (sizeof(E)), COUNT, GFP) ++ ALLOC_OBJS(ARGS, E, COUNT, GFP) | // Convert any other type: p = kcalloc(sizeof(struct item), n, gfp) -- ALLOC_ARRAY((sizeof(TYPE)), COUNT, GFP) -+ ALLOC_OBJS(TYPE, COUNT, GFP) +- ALLOC_ARRAY(ARGS, (sizeof(TYPE)), COUNT, GFP) ++ ALLOC_OBJS(ARGS, TYPE, COUNT, GFP) | // Convert flexible array structures: p = kmalloc(struct_size(p, data, n), gfp) -- ALLOC(struct_size(VAR, FLEX, COUNT), GFP) -+ ALLOC_FLEX(*VAR, FLEX, COUNT, GFP) +- ALLOC(ARGS, struct_size(VAR, FLEX, COUNT), GFP) ++ ALLOC_FLEX(ARGS, *VAR, FLEX, COUNT, GFP) | // Same by type: kmalloc(struct_size_t(struct item, data, n), gfp) -- ALLOC(struct_size_t(TYPE, FLEX, COUNT), GFP) -+ ALLOC_FLEX(TYPE, FLEX, COUNT, GFP) +- ALLOC(ARGS, struct_size_t(TYPE, FLEX, COUNT), GFP) ++ ALLOC_FLEX(ARGS, TYPE, FLEX, COUNT, GFP) ) @drop_gfp_kernel depends on patch && !(file in "tools") && !(file in "samples")@ identifier ALLOC = {kmalloc_obj,kmalloc_objs,kmalloc_flex, kzalloc_obj,kzalloc_objs,kzalloc_flex, kvmalloc_obj,kvmalloc_objs,kvmalloc_flex, - kvzalloc_obj,kvzalloc_objs,kvzalloc_flex}; + kvzalloc_obj,kvzalloc_objs,kvzalloc_flex, + devm_kmalloc_obj,devm_kmalloc_objs,devm_kmalloc_flex, + devm_kzalloc_obj,devm_kzalloc_objs,devm_kzalloc_flex}; @@ ALLOC(... diff --git a/scripts/coccinelle/free/cleanup-free.cocci b/scripts/coccinelle/free/cleanup-free.cocci new file mode 100644 index 000000000000..2aba766b5bbb --- /dev/null +++ b/scripts/coccinelle/free/cleanup-free.cocci @@ -0,0 +1,112 @@ +// SPDX-License-Identifier: GPL-2.0-only +/// +/// Find __cleanup(kfree) +/// Using __cleanup(kfree) will pass the stack address of the annotated +/// local variable to kfree, causing an invalid free. +/// I.e., `T v __cleanup(kfree);` --> `kfree(&v);` +/// Such usage is impossible to be correct. +/// +// Confidence: High +// Copyright: (C) 2026 Ella Ma +// Options: --no-includes --include-headers + +virtual report +virtual org + +// Suggesting using __free for the functions with a DEFINE_FREE definition. +// Update this list when new DEFINE_FREE definitions are added. +@free@ +attribute name __cleanup; +symbol kfree, kfree_sensitive, kvfree, kvfree_atomic, free_percpu; +type T; +identifier v, n; +position p; +@@ + +( + T v __cleanup@p( +( + n +& +( + kfree \| kfree_sensitive \| kvfree \| kvfree_atomic \| free_percpu +) +) + ); +| + T v __cleanup@p( +( + n +& +( + kfree \| kfree_sensitive \| kvfree \| kvfree_atomic \| free_percpu +) +) + ) = ...; +) + +@script:python depends on report@ +p << free.p; +n << free.n; +@@ + +msg = f"ERROR: __cleanup({n}) will cause an invalid free: the stack address of the annotated variable will be passed to {n}; declare the variable using __free({n}) to cause the pointee to be freed" +coccilib.report.print_report(p[0], msg) + +@script:python depends on org@ +p << free.p; +n << free.n; +@@ + +msg = f"ERROR: __cleanup({n}) will cause an invalid free: the stack address of the annotated variable will be passed to {n}; declare the variable using __free({n}) to cause the pointee to be freed" +coccilib.org.print_todo(p[0], msg) + + +// Reporting __cleanup usage for the functions without a DEFINE_FREE definition. +// The following list only contains frequently used functions. Supplement it if +// necessary. +@cleanup@ +attribute name __cleanup; +symbol vfree, vfree_atomic, kfree_const; +type T; +identifier v, n; +position p; +@@ + +( + T v __cleanup@p( +( + n +& +( + vfree \| vfree_atomic \| kfree_const +) +) + ); +| + T v __cleanup@p( +( + n +& +( + vfree \| vfree_atomic \| kfree_const +) +) + ) = ...; +) + +@script:python depends on report@ +p << cleanup.p; +n << cleanup.n; +@@ + +msg = f"ERROR: __cleanup({n}) will cause an invalid free: the stack address of the annotated variable will be passed to {n}" +coccilib.report.print_report(p[0], msg) + +@script:python depends on org@ +p << cleanup.p; +n << cleanup.n; +@@ + +msg = f"ERROR: __cleanup({n}) will cause an invalid free: the stack address of the annotated variable will be passed to {n}" +coccilib.org.print_todo(p[0], msg) diff --git a/scripts/coccinelle/misc/array_end.cocci b/scripts/coccinelle/misc/array_end.cocci new file mode 100644 index 000000000000..2f0bbc4ce17d --- /dev/null +++ b/scripts/coccinelle/misc/array_end.cocci @@ -0,0 +1,73 @@ +// SPDX-License-Identifier: GPL-2.0-only +/// Use ARRAY_END instead of an expression derived from ARRAY_SIZE +// +// Confidence: High +// Copyright: 2026, Alejandro Colomar <alx@kernel.org> +// Options: --no-includes --include-headers + +virtual patch +virtual context +virtual org +virtual report + +@depends on context disable zero_multiple_format@ +type T; +T[] a; +expression b; +@@ +( +* a + ARRAY_SIZE(a) +| +* &a[0] + ARRAY_SIZE(a) +| +* &a[ARRAY_SIZE(a)] +| +* &a[ARRAY_SIZE(a) - b] +) + +@depends on patch disable zero_multiple_format@ +type T; +T[] a; +expression b; +@@ +( +- (a + ARRAY_SIZE(a)) ++ ARRAY_END(a) +| +- (&a[0] + ARRAY_SIZE(a)) ++ ARRAY_END(a) +| +- (&a[ARRAY_SIZE(a)]) ++ ARRAY_END(a) +| +- (&a[ARRAY_SIZE(a) - b]) ++ ARRAY_END(a) - b +) + +@r depends on org || report disable zero_multiple_format@ +type T; +T[] a; +expression b; +position p; +@@ +( + a@p + ARRAY_SIZE(a) +| + &a[0]@p + ARRAY_SIZE(a) +| + &a[ARRAY_SIZE(a)]@p +| + &a[ARRAY_SIZE(a)@p - b] +) + +@script:python depends on org@ +p << r.p; +@@ + +coccilib.org.print_todo(p[0], "WARNING should use ARRAY_END") + +@script:python depends on report@ +p << r.p; +@@ + +coccilib.report.print_report(p[0], "WARNING: opportunity for ARRAY_END") diff --git a/scripts/get_maintainer.pl b/scripts/get_maintainer.pl index 16b80a700d4a..265245e568c6 100755 --- a/scripts/get_maintainer.pl +++ b/scripts/get_maintainer.pl @@ -959,6 +959,15 @@ sub get_maintainers { $tvi = $end + 1; } + # THE REST matches every file, so only fall back to it when no + # other matching section provides a mailing list for this file + # that we would actually output with the current options. + my ($the_rest) = grep { get_section_name($_) eq "THE REST" } keys %hash; + if (defined($the_rest) && + grep { $_ != $the_rest && section_has_list($_) } keys %hash) { + delete $hash{$the_rest}; + } + foreach my $line (sort {$hash{$b} <=> $hash{$a}} keys %hash) { add_categories($line, ""); if ($sections) { @@ -1295,6 +1304,40 @@ sub find_ending_index { return $index; } +sub get_section_name { + my ($index) = @_; + + return $typevalue[find_starting_index($index)]; +} + +sub section_has_list { + my ($index) = @_; + + my $start = find_starting_index($index); + my $end = find_ending_index($index); + for (my $i = $start; $i < $end; $i++) { + next if ($typevalue[$i] !~ m/^L:\s*(.*)/); + my $list_additional = ""; + if ($1 =~ m/[^\s]+\s+(.*)$/) { + $list_additional = $1; + } + return 1 if (list_is_selected($list_additional)); + } + return 0; +} + +# Must match the list selection in add_categories() +sub list_is_selected { + my ($list_additional) = @_; + + if ($list_additional =~ m/subscribers-only/) { + return $email_subscriber_list; + } elsif ($list_additional =~ m/moderated/) { + return $email_list && $email_moderated_list; + } + return $email_list; +} + sub get_subsystem_name { my ($index) = @_; |
