[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-Id: <20250212194857.192057-2-trintaeoitogc@gmail.com>
Date: Wed, 12 Feb 2025 16:48:57 -0300
From: Guilherme Giacomo Simoes <trintaeoitogc@...il.com>
To: a.hindborg@...nel.org,
alex.gaynor@...il.com,
aliceryhl@...gle.com,
apw@...onical.com,
arnd@...db.de,
aswinunni01@...il.com,
axboe@...nel.dk,
benno.lossin@...ton.me,
bhelgaas@...gle.com,
bjorn3_gh@...tonmail.com,
boqun.feng@...il.com,
dakr@...nel.org,
dwaipayanray1@...il.com,
ethan.twardy@...il.com,
fujita.tomonori@...il.com,
gary@...yguo.net,
gregkh@...uxfoundation.org,
joe@...ches.com,
lukas.bulwahn@...il.com,
ojeda@...nel.org,
pbonzini@...hat.com,
tmgross@...ch.edu,
walmeida@...rosoft.com
Cc: trintaeoitogc@...il.com,
rust-for-linux@...r.kernel.org,
linux-kernel@...r.kernel.org
Subject: [PATCH 3/3] checkpatch: throw error in malformed arrays
In module! macro, some fields have a string array type, and we need a
check for guarantee a good formatation.
Check if the current line contains one of these keys that must be a
string array and if so, make a regex for check if contains more than one
value in array, if yes, the array should be in vertical. If array have
only one value, so the array can be in the same line.
Signed-off-by: Guilherme Giacomo Simoes <trintaeoitogc@...il.com>
---
scripts/checkpatch.pl | 68 +++++++++++++++++++++++++++++++++++++++++++
1 file changed, 68 insertions(+)
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 7b28ad331742..d45536c2c63a 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -2775,6 +2775,9 @@ sub process {
$realcnt = 0;
$linenr = 0;
$fixlinenr = -1;
+
+ my %parse_module_arr;
+
foreach my $line (@lines) {
$linenr++;
$fixlinenr++;
@@ -3567,6 +3570,71 @@ sub process {
# ignore non-hunk lines and lines being removed
next if (!$hunk_line || $line =~ /^-/);
+# check if arrays has more than one value in the same line
+ my $inline = 0;
+ if ($line =~ /^\+\s*.*\b(author|alias|firmware)\s*:\s*\[/) {
+ $inline = 1;
+
+ if ($line =~ /author/) {
+ $parse_module_arr{'author'} = 1;
+ }
+
+ if ($line =~ /alias/) {
+ $parse_module_arr{'alias'} = 1;
+ }
+
+ if ($line =~ /firmware/) {
+ $parse_module_arr{'firmware'} = 1;
+ }
+ }
+
+ if (keys %parse_module_arr) {
+ my @keys = keys %parse_module_arr;
+ my $key = $keys[0];
+
+ my $more_than_one_vl = qr/".+",\s*".+"/;
+
+ if ($line =~ $more_than_one_vl) {
+ ERROR("ERR_ARRAY_MODULE_MACRO",
+ "the key $key have more than one values in same line\n$here\n". cat_vet($rawline));
+ }
+ elsif ($inline && $line !~ /\]/ && $line =~ /\["/) {
+ ERROR("ERR_ARRAY_MODULE_MACRO",
+ qq~the key $key need a new line after declare the key\n$here\n~ . cat_vet($rawline) . qq~\nFor example:
+
+FROM
+'example': ['value',
+ 'value'
+
+TO
+'example': [
+ 'value',
+ 'value
+
+ ~);
+ }
+ elsif (!$inline && $line =~ /"\]/) {
+ ERROR("ERR_ARRAY_MODULE_MACRO",
+ qq~the key $key need a new line after last value and before ]\n$here\n~ . cat_vet($rawline) . qq~\nFor example:
+
+FROM
+'last_value']
+
+TO
+'last_value'
+]
+ ~);
+ }
+
+ #END OF ANALYZE FIELD
+ if ((!$inline || $line !~ $more_than_one_vl) && $line =~ /\]/) {
+ delete $parse_module_arr{author};
+ delete $parse_module_arr{alias};
+ delete $parse_module_arr{firmware};
+ }
+ }
+
+
#trailing whitespace
if ($line =~ /^\+.*\015/) {
my $herevet = "$here\n" . cat_vet($rawline) . "\n";
--
2.34.1
Powered by blists - more mailing lists