From c131633ba9761d3214ea51716bff0d28702d0701 Mon Sep 17 00:00:00 2001 From: tangbinzy Date: Mon, 4 Sep 2023 08:02:24 +0000 Subject: [PATCH] checkpatch: fix g_malloc check mainline inclusion commit dfdb4f3c28737879685398c4a610a220e1ecf9c2 category: bugfix --------------------------------------------------------------- Use the string equality operator "eq", and ensure that $1 is defined by using "(try|)" instead of "(try)?". The alternative "((?:try)?)" is longer and less readable. Signed-off-by: Paolo Bonzini Signed-off-by: tangbinzy --- scripts/checkpatch.pl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index cb8eff233e..3aadccd49d 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -2832,8 +2832,8 @@ sub process { } # check for pointless casting of g_malloc return - if ($line =~ /\*\s*\)\s*g_(try)?(m|re)alloc(0?)(_n)?\b/) { - if ($2 == 'm') { + if ($line =~ /\*\s*\)\s*g_(try|)(m|re)alloc(0?)(_n)?\b/) { + if ($2 eq 'm') { ERROR("unnecessary cast may hide bugs, use g_$1new$3 instead\n" . $herecurr); } else { ERROR("unnecessary cast may hide bugs, use g_$1renew$3 instead\n" . $herecurr); -- Gitee