* + checkpatch-add-a-couple-new-alloc-functions-to-alloc-with-multiplies-check.patch added to mm-nonmm-unstable branch
@ 2023-09-13 21:22 Andrew Morton
2023-09-13 22:12 ` Gustavo A. R. Silva
0 siblings, 1 reply; 4+ messages in thread
From: Andrew Morton @ 2023-09-13 21:22 UTC (permalink / raw)
To: mm-commits, lukas.bulwahn, gustavoars, dwaipayanray1, apw, joe,
akpm
The patch titled
Subject: checkpatch: add a couple new alloc functions to alloc with multiplies check
has been added to the -mm mm-nonmm-unstable branch. Its filename is
checkpatch-add-a-couple-new-alloc-functions-to-alloc-with-multiplies-check.patch
This patch will shortly appear at
https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/checkpatch-add-a-couple-new-alloc-functions-to-alloc-with-multiplies-check.patch
This patch will later appear in the mm-nonmm-unstable branch at
git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
Before you just go and hit "reply", please:
a) Consider who else should be cc'ed
b) Prefer to cc a suitable mailing list as well
c) Ideally: find the original patch on the mailing list and do a
reply-to-all to that, adding suitable additional cc's
*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***
The -mm tree is included into linux-next via the mm-everything
branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
and is updated there every 2-3 working days
------------------------------------------------------
From: Joe Perches <joe@perches.com>
Subject: checkpatch: add a couple new alloc functions to alloc with multiplies check
Date: Wed, 13 Sep 2023 13:37:52 -0700
vmalloc() and vzalloc() functions have now 2-factor multiplication
argument forms vmalloc_array() and vcalloc(), correspondingly.
Add alloc-with-multiplies checks for these new functions.
Simplify the original codes repeated else to use a hash.
Link: https://github.com/KSPP/linux/issues/342
Link: https://lore.kernel.org/lkml/ZQCaO+tYycDxVLy7@work/
Link: https://lkml.kernel.org/r/edb667e19211652a32ef6069159bb85dbc3bcdfc.1694636817.git.joe@perches.com
Original-patch-by: Gustavo A. R. Silva <gustavoars@kernel.org>
Signed-off-by: Joe Perches <joe@perches.com>
Cc: Andy Whitcroft <apw@canonical.com>
Cc: Dwaipayan Ray <dwaipayanray1@gmail.com>
Cc: Lukas Bulwahn <lukas.bulwahn@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
---
scripts/checkpatch.pl | 21 ++++++++++++++-------
1 file changed, 14 insertions(+), 7 deletions(-)
--- a/scripts/checkpatch.pl~checkpatch-add-a-couple-new-alloc-functions-to-alloc-with-multiplies-check
+++ a/scripts/checkpatch.pl
@@ -834,6 +834,16 @@ our %deprecated_apis = (
#Create a search pattern for all these strings to speed up a loop below
our $deprecated_apis_search = '(?:' . join('|', keys %deprecated_apis) . ')';
+our %alloc_with_multiply_apis = (
+ "kmalloc" => "kmalloc_array",
+ "kvmalloc" => "kvmalloc_array",
+ "vmalloc" => "vmalloc_array",
+ "kvzalloc" => "kvcalloc",
+ "kzalloc" => "kcalloc",
+ "vzalloc" => "vcalloc",
+);
+our $alloc_with_multiply_search = '(?:' . join('|', keys %alloc_with_multiply_apis) . ')';
+
our $mode_perms_world_writable = qr{
S_IWUGO |
S_IWOTH |
@@ -7187,17 +7197,14 @@ sub process {
"Prefer $3(sizeof(*$1)...) over $3($4...)\n" . $herecurr);
}
-# check for (kv|k)[mz]alloc with multiplies that could be kmalloc_array/kvmalloc_array/kvcalloc/kcalloc
+# check for various allocs with multiplies that should use safer functions
if ($perl_version_ok &&
defined $stat &&
- $stat =~ /^\+\s*($Lval)\s*\=\s*(?:$balanced_parens)?\s*((?:kv|k)[mz]alloc)\s*\(\s*($FuncArg)\s*\*\s*($FuncArg)\s*,/) {
+ $stat =~ /^\+\s*($Lval)\s*\=\s*(?:$balanced_parens)?\s*($alloc_with_multiply_search)\s*\(\s*($FuncArg)\s*\*\s*($FuncArg)\s*,/) {
my $oldfunc = $3;
+ my $newfunc = $alloc_with_multiply_apis{$oldfunc};
my $a1 = $4;
my $a2 = $10;
- my $newfunc = "kmalloc_array";
- $newfunc = "kvmalloc_array" if ($oldfunc eq "kvmalloc");
- $newfunc = "kvcalloc" if ($oldfunc eq "kvzalloc");
- $newfunc = "kcalloc" if ($oldfunc eq "kzalloc");
my $r1 = $a1;
my $r2 = $a2;
if ($a1 =~ /^sizeof\s*\S/) {
@@ -7213,7 +7220,7 @@ sub process {
"Prefer $newfunc over $oldfunc with multiply\n" . $herectx) &&
$cnt == 1 &&
$fix) {
- $fixed[$fixlinenr] =~ s/\b($Lval)\s*\=\s*(?:$balanced_parens)?\s*((?:kv|k)[mz]alloc)\s*\(\s*($FuncArg)\s*\*\s*($FuncArg)/$1 . ' = ' . "$newfunc(" . trim($r1) . ', ' . trim($r2)/e;
+ $fixed[$fixlinenr] =~ s/\b($Lval)\s*\=\s*(?:$balanced_parens)?\s*($oldfunc)\s*\(\s*($FuncArg)\s*\*\s*($FuncArg)/$1 . ' = ' . "$newfunc(" . trim($r1) . ', ' . trim($r2)/e;
}
}
}
_
Patches currently in -mm which might be from joe@perches.com are
checkpatch-simplify-creating-search-strings.patch
checkpatch-add-a-couple-new-alloc-functions-to-alloc-with-multiplies-check.patch
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: + checkpatch-add-a-couple-new-alloc-functions-to-alloc-with-multiplies-check.patch added to mm-nonmm-unstable branch
2023-09-13 21:22 Andrew Morton
@ 2023-09-13 22:12 ` Gustavo A. R. Silva
2023-09-13 22:17 ` Andrew Morton
0 siblings, 1 reply; 4+ messages in thread
From: Gustavo A. R. Silva @ 2023-09-13 22:12 UTC (permalink / raw)
To: Andrew Morton, mm-commits, lukas.bulwahn, gustavoars,
dwaipayanray1, apw, joe
On 9/13/23 15:22, Andrew Morton wrote:
> The patch titled
> Subject: checkpatch: add a couple new alloc functions to alloc with multiplies check
> has been added to the -mm mm-nonmm-unstable branch. Its filename is
> checkpatch-add-a-couple-new-alloc-functions-to-alloc-with-multiplies-check.patch
>
> This patch will shortly appear at
> https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/checkpatch-add-a-couple-new-alloc-functions-to-alloc-with-multiplies-check.patch
>
> This patch will later appear in the mm-nonmm-unstable branch at
> git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
>
> Before you just go and hit "reply", please:
> a) Consider who else should be cc'ed
> b) Prefer to cc a suitable mailing list as well
> c) Ideally: find the original patch on the mailing list and do a
> reply-to-all to that, adding suitable additional cc's
>
> *** Remember to use Documentation/process/submit-checklist.rst when testing your code ***
>
> The -mm tree is included into linux-next via the mm-everything
> branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
> and is updated there every 2-3 working days
>
> ------------------------------------------------------
> From: Joe Perches <joe@perches.com>
> Subject: checkpatch: add a couple new alloc functions to alloc with multiplies check
> Date: Wed, 13 Sep 2023 13:37:52 -0700
>
> vmalloc() and vzalloc() functions have now 2-factor multiplication
> argument forms vmalloc_array() and vcalloc(), correspondingly.
>
> Add alloc-with-multiplies checks for these new functions.
>
> Simplify the original codes repeated else to use a hash.
>
> Link: https://github.com/KSPP/linux/issues/342
>
> Link: https://lore.kernel.org/lkml/ZQCaO+tYycDxVLy7@work/
> Link: https://lkml.kernel.org/r/edb667e19211652a32ef6069159bb85dbc3bcdfc.1694636817.git.joe@perches.com
> Original-patch-by: Gustavo A. R. Silva <gustavoars@kernel.org>
This patch should include the following tags:
Co-developed-by: Gustavo A. R. Silva <gustavoars@kernel.org>
Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
Thanks
--
Gustavo
> Signed-off-by: Joe Perches <joe@perches.com>
> Cc: Andy Whitcroft <apw@canonical.com>
> Cc: Dwaipayan Ray <dwaipayanray1@gmail.com>
> Cc: Lukas Bulwahn <lukas.bulwahn@gmail.com>
> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
> ---
>
> scripts/checkpatch.pl | 21 ++++++++++++++-------
> 1 file changed, 14 insertions(+), 7 deletions(-)
>
> --- a/scripts/checkpatch.pl~checkpatch-add-a-couple-new-alloc-functions-to-alloc-with-multiplies-check
> +++ a/scripts/checkpatch.pl
> @@ -834,6 +834,16 @@ our %deprecated_apis = (
> #Create a search pattern for all these strings to speed up a loop below
> our $deprecated_apis_search = '(?:' . join('|', keys %deprecated_apis) . ')';
>
> +our %alloc_with_multiply_apis = (
> + "kmalloc" => "kmalloc_array",
> + "kvmalloc" => "kvmalloc_array",
> + "vmalloc" => "vmalloc_array",
> + "kvzalloc" => "kvcalloc",
> + "kzalloc" => "kcalloc",
> + "vzalloc" => "vcalloc",
> +);
> +our $alloc_with_multiply_search = '(?:' . join('|', keys %alloc_with_multiply_apis) . ')';
> +
> our $mode_perms_world_writable = qr{
> S_IWUGO |
> S_IWOTH |
> @@ -7187,17 +7197,14 @@ sub process {
> "Prefer $3(sizeof(*$1)...) over $3($4...)\n" . $herecurr);
> }
>
> -# check for (kv|k)[mz]alloc with multiplies that could be kmalloc_array/kvmalloc_array/kvcalloc/kcalloc
> +# check for various allocs with multiplies that should use safer functions
> if ($perl_version_ok &&
> defined $stat &&
> - $stat =~ /^\+\s*($Lval)\s*\=\s*(?:$balanced_parens)?\s*((?:kv|k)[mz]alloc)\s*\(\s*($FuncArg)\s*\*\s*($FuncArg)\s*,/) {
> + $stat =~ /^\+\s*($Lval)\s*\=\s*(?:$balanced_parens)?\s*($alloc_with_multiply_search)\s*\(\s*($FuncArg)\s*\*\s*($FuncArg)\s*,/) {
> my $oldfunc = $3;
> + my $newfunc = $alloc_with_multiply_apis{$oldfunc};
> my $a1 = $4;
> my $a2 = $10;
> - my $newfunc = "kmalloc_array";
> - $newfunc = "kvmalloc_array" if ($oldfunc eq "kvmalloc");
> - $newfunc = "kvcalloc" if ($oldfunc eq "kvzalloc");
> - $newfunc = "kcalloc" if ($oldfunc eq "kzalloc");
> my $r1 = $a1;
> my $r2 = $a2;
> if ($a1 =~ /^sizeof\s*\S/) {
> @@ -7213,7 +7220,7 @@ sub process {
> "Prefer $newfunc over $oldfunc with multiply\n" . $herectx) &&
> $cnt == 1 &&
> $fix) {
> - $fixed[$fixlinenr] =~ s/\b($Lval)\s*\=\s*(?:$balanced_parens)?\s*((?:kv|k)[mz]alloc)\s*\(\s*($FuncArg)\s*\*\s*($FuncArg)/$1 . ' = ' . "$newfunc(" . trim($r1) . ', ' . trim($r2)/e;
> + $fixed[$fixlinenr] =~ s/\b($Lval)\s*\=\s*(?:$balanced_parens)?\s*($oldfunc)\s*\(\s*($FuncArg)\s*\*\s*($FuncArg)/$1 . ' = ' . "$newfunc(" . trim($r1) . ', ' . trim($r2)/e;
> }
> }
> }
> _
>
> Patches currently in -mm which might be from joe@perches.com are
>
> checkpatch-simplify-creating-search-strings.patch
> checkpatch-add-a-couple-new-alloc-functions-to-alloc-with-multiplies-check.patch
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: + checkpatch-add-a-couple-new-alloc-functions-to-alloc-with-multiplies-check.patch added to mm-nonmm-unstable branch
2023-09-13 22:12 ` Gustavo A. R. Silva
@ 2023-09-13 22:17 ` Andrew Morton
0 siblings, 0 replies; 4+ messages in thread
From: Andrew Morton @ 2023-09-13 22:17 UTC (permalink / raw)
To: Gustavo A. R. Silva
Cc: mm-commits, lukas.bulwahn, gustavoars, dwaipayanray1, apw, joe
On Wed, 13 Sep 2023 16:12:52 -0600 "Gustavo A. R. Silva" <gustavo@embeddedor.com> wrote:
> > Link: https://lore.kernel.org/lkml/ZQCaO+tYycDxVLy7@work/
> > Link: https://lkml.kernel.org/r/edb667e19211652a32ef6069159bb85dbc3bcdfc.1694636817.git.joe@perches.com
> > Original-patch-by: Gustavo A. R. Silva <gustavoars@kernel.org>
>
> This patch should include the following tags:
>
> Co-developed-by: Gustavo A. R. Silva <gustavoars@kernel.org>
> Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
added, thanks.
^ permalink raw reply [flat|nested] 4+ messages in thread
* + checkpatch-add-a-couple-new-alloc-functions-to-alloc-with-multiplies-check.patch added to mm-nonmm-unstable branch
@ 2023-09-14 19:08 Andrew Morton
0 siblings, 0 replies; 4+ messages in thread
From: Andrew Morton @ 2023-09-14 19:08 UTC (permalink / raw)
To: mm-commits, gustavoars, joe, akpm
The patch titled
Subject: checkpatch: add a couple new alloc functions to alloc with multiplies check
has been added to the -mm mm-nonmm-unstable branch. Its filename is
checkpatch-add-a-couple-new-alloc-functions-to-alloc-with-multiplies-check.patch
This patch will shortly appear at
https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/checkpatch-add-a-couple-new-alloc-functions-to-alloc-with-multiplies-check.patch
This patch will later appear in the mm-nonmm-unstable branch at
git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
Before you just go and hit "reply", please:
a) Consider who else should be cc'ed
b) Prefer to cc a suitable mailing list as well
c) Ideally: find the original patch on the mailing list and do a
reply-to-all to that, adding suitable additional cc's
*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***
The -mm tree is included into linux-next via the mm-everything
branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
and is updated there every 2-3 working days
------------------------------------------------------
From: Joe Perches <joe@perches.com>
Subject: checkpatch: add a couple new alloc functions to alloc with multiplies check
Date: Wed, 13 Sep 2023 18:41:47 -0700
vmalloc() and vzalloc() functions have now 2-factor multiplication
argument forms vmalloc_array() and vcalloc(), correspondingly.
Add alloc-with-multiplies checks for these new functions.
Simplify the original codes repeated else to use a hash.
Link: https://github.com/KSPP/linux/issues/342
Link: https://lkml.kernel.org/r/edb667e19211652a32ef6069159bb85dbc3bcdff.1694636817.git.joe@perches.com
Original-patch-by: Gustavo A. R. Silva <gustavoars@kernel.org>
Co-developed-by: Gustavo A. R. Silva <gustavoars@kernel.org>
Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
Link: https://lore.kernel.org/lkml/ZQCaO+tYycDxVLy7@work/
Signed-off-by: Joe Perches <joe@perches.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
---
scripts/checkpatch.pl | 21 ++++++++++++++-------
1 file changed, 14 insertions(+), 7 deletions(-)
--- a/scripts/checkpatch.pl~checkpatch-add-a-couple-new-alloc-functions-to-alloc-with-multiplies-check
+++ a/scripts/checkpatch.pl
@@ -834,6 +834,16 @@ our %deprecated_apis = (
#Create a search pattern for all these strings to speed up a loop below
our $deprecated_apis_search = '(?:' . join('|', keys %deprecated_apis) . ')';
+our %alloc_with_multiply_apis = (
+ "kmalloc" => "kmalloc_array",
+ "kvmalloc" => "kvmalloc_array",
+ "vmalloc" => "vmalloc_array",
+ "kvzalloc" => "kvcalloc",
+ "kzalloc" => "kcalloc",
+ "vzalloc" => "vcalloc",
+);
+our $alloc_with_multiply_search = '(?:' . join('|', keys %alloc_with_multiply_apis) . ')';
+
our $mode_perms_world_writable = qr{
S_IWUGO |
S_IWOTH |
@@ -7187,17 +7197,14 @@ sub process {
"Prefer $3(sizeof(*$1)...) over $3($4...)\n" . $herecurr);
}
-# check for (kv|k)[mz]alloc with multiplies that could be kmalloc_array/kvmalloc_array/kvcalloc/kcalloc
+# check for various allocs with multiplies that should use safer functions
if ($perl_version_ok &&
defined $stat &&
- $stat =~ /^\+\s*($Lval)\s*\=\s*(?:$balanced_parens)?\s*((?:kv|k)[mz]alloc)\s*\(\s*($FuncArg)\s*\*\s*($FuncArg)\s*,/) {
+ $stat =~ /^\+\s*($Lval)\s*\=\s*(?:$balanced_parens)?\s*($alloc_with_multiply_search)\s*\(\s*($FuncArg)\s*\*\s*($FuncArg)/) {
my $oldfunc = $3;
+ my $newfunc = $alloc_with_multiply_apis{$oldfunc};
my $a1 = $4;
my $a2 = $10;
- my $newfunc = "kmalloc_array";
- $newfunc = "kvmalloc_array" if ($oldfunc eq "kvmalloc");
- $newfunc = "kvcalloc" if ($oldfunc eq "kvzalloc");
- $newfunc = "kcalloc" if ($oldfunc eq "kzalloc");
my $r1 = $a1;
my $r2 = $a2;
if ($a1 =~ /^sizeof\s*\S/) {
@@ -7213,7 +7220,7 @@ sub process {
"Prefer $newfunc over $oldfunc with multiply\n" . $herectx) &&
$cnt == 1 &&
$fix) {
- $fixed[$fixlinenr] =~ s/\b($Lval)\s*\=\s*(?:$balanced_parens)?\s*((?:kv|k)[mz]alloc)\s*\(\s*($FuncArg)\s*\*\s*($FuncArg)/$1 . ' = ' . "$newfunc(" . trim($r1) . ', ' . trim($r2)/e;
+ $fixed[$fixlinenr] =~ s/\b($Lval)\s*\=\s*(?:$balanced_parens)?\s*($oldfunc)\s*\(\s*($FuncArg)\s*\*\s*($FuncArg)/$1 . ' = ' . "$newfunc(" . trim($r1) . ', ' . trim($r2)/e;
}
}
}
_
Patches currently in -mm which might be from joe@perches.com are
checkpatch-simplify-creating-search-strings.patch
checkpatch-add-a-couple-new-alloc-functions-to-alloc-with-multiplies-check.patch
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2023-09-14 19:08 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-09-14 19:08 + checkpatch-add-a-couple-new-alloc-functions-to-alloc-with-multiplies-check.patch added to mm-nonmm-unstable branch Andrew Morton
-- strict thread matches above, loose matches on Subject: below --
2023-09-13 21:22 Andrew Morton
2023-09-13 22:12 ` Gustavo A. R. Silva
2023-09-13 22:17 ` Andrew Morton
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.