Adding new checks to checkpatch.pl
cover Adding new checks to checkpatch.pl
This is a proposal to add two new checks to checkpatch.pl. There are two wrapper functions for memset that can be used under certain conditions. The details are described thoroughly in the patch itself. The wrapper functions are:
eth_zero_addr()eth_broadcast_addr()
I'm sending the patch to the outreachy mailing list first for the following reasons:
Second eye review,
the patch was inspired by one of coccinelle's challenge problems for outreachy round 10.
I understand that eventually the patch should be sent to the maintainers of checkpatch.pl
Aya Mahfouz (1):
scripts: checkpatch.pl: add 2 new checks on memset calls
scripts/checkpatch.pl | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+)
Signature · 1 line
1.9.3
PATCH 1/1 scripts: checkpatch.pl: add 2 new checks on memset calls
This patch adds 2 new checks on memset calls in the file checkpatch.pl as follows:
replace memset by eth_zero_addr if the second argument is an address of zeros (0x00). eth_zero_addr is a wrapper function for memset that takes an address array to set as zero. The size address has to be ETH_ALEN.
replace memset by eth_broadcast_addr if the second argument is the broadcast address (0xff). eth_broadcast_addr is a wrapper function for memset that sets the passed array the broadcast address. The size of the address has to be ETH_ALEN.
--- scripts/checkpatch.pl | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+)
scripts/checkpatch.pl +19 -0
@@ -4918,6 +4918,25 @@ sub process { } } +# Check for memset(foo, 0x00|0xff, ETH_ALEN) that could be eth_zero_addr(foo)|eth_broadcast_addr(foo) + if ($^V && $^V ge 5.10.0 && + $line =~ /^\+(?:.*?)\bmemset\s*\(\s*$FuncArg\s*,\s*$FuncArg\s*\,\s*ETH_ALEN\s*\)/s) { + my $num = $7; + if ($num =~ "0x00" && WARN("PREFER_ETH_ZERO_ADDR", + "Prefer eth_zero_addr() over memset() if the second address is 0x00\n" . $herecurr) && + $fix) { + + $fixed[$fixlinenr] =~ s/\bmemset\s*\(\s*$FuncArg\s*,\s*$FuncArg\s*\,\s*ETH_ALEN\s*\)/eth_zero_addr($2)/; + } + elsif ($num =~ "0xff" && WARN("PREFER_ETH_BROADCAST_ADDR", + "Prefer eth_broadcast_addr() over memset() if the second address is 0xff\n" . $herecurr) && + $fix) { + + $fixed[$fixlinenr] =~ s/\bmemset\s*\(\s*$FuncArg\s*,\s*$FuncArg\s*\,\s*ETH_ALEN\s*\)/eth_broadcast_addr($2)/; + } + } + + # typecasts on min/max could be min_t/max_t if ($^V && $^V ge 5.10.0 && defined $stat &&
Signature · 1 line
1.9.3
Re: [Outreachy kernel] [PATCH 1/1] scripts: checkpatch.pl: add 2 new checks on memset calls
Quoted 8 lines · Aya Mahfouz
This patch adds 2 new checks on memset calls in the file checkpatch.pl as follows:
replace memset by
eth_zero_addrif the second argument is an address of zeros (0x00).eth_zero_addris a wrapper function for memset that takes an address array to set as zero. The size address has to beETH_ALEN.
Quoted 4 lines
replace memset by
eth_broadcast_addrif the second argument is the broadcast address (0xff).eth_broadcast_addris a wrapper function for memset that sets the passed array the broadcast address. The size of the address has to beETH_ALEN.
It's a nice idea, but Greg doesn't accept patches on checkpatch.
julia
Quoted 45 lines
Signed-off-by Aya Mahfouz <[email protected]>--- scripts/checkpatch.pl | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+)scripts/checkpatch.pl +19
-0@@ -4918,6 +4918,25 @@ sub process { } } +# Check for memset(foo, 0x00|0xff, ETH_ALEN) that could be eth_zero_addr(foo)|eth_broadcast_addr(foo) + if ($^V && $^V ge 5.10.0 && + $line =~ /^\+(?:.*?)\bmemset\s*\(\s*$FuncArg\s*,\s*$FuncArg\s*\,\s*ETH_ALEN\s*\)/s) { + my $num = $7; + if ($num =~ "0x00" && WARN("PREFER_ETH_ZERO_ADDR", + "Prefer eth_zero_addr() over memset() if the second address is 0x00\n" . $herecurr) && + $fix) { + + $fixed[$fixlinenr] =~ s/\bmemset\s*\(\s*$FuncArg\s*,\s*$FuncArg\s*\,\s*ETH_ALEN\s*\)/eth_zero_addr($2)/; + } + elsif ($num =~ "0xff" && WARN("PREFER_ETH_BROADCAST_ADDR", + "Prefer eth_broadcast_addr() over memset() if the second address is 0xff\n" . $herecurr) && + $fix) { + + $fixed[$fixlinenr] =~ s/\bmemset\s*\(\s*$FuncArg\s*,\s*$FuncArg\s*\,\s*ETH_ALEN\s*\)/eth_broadcast_addr($2)/; + } + } + + # typecasts on min/max could be min_t/max_t if ($^V && $^V ge 5.10.0 && defined $stat &&Signature · 8 lines
1.9.3 -- You received this message because you are subscribed to the Google Groups "outreachy-kernel" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/052f177392bde0338901921fcbb0ef70f1d85882.1424580894.git.mahfouz.saif.elyazal%40gmail.com. For more options, visit https://groups.google.com/d/optout.