OSDN Git Service

checkpatch: fix g_malloc check
authorPaolo Bonzini <pbonzini@redhat.com>
Wed, 6 Apr 2022 12:27:52 +0000 (14:27 +0200)
committerPaolo Bonzini <pbonzini@redhat.com>
Thu, 12 May 2022 10:07:05 +0000 (12:07 +0200)
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 <pbonzini@redhat.com>
scripts/checkpatch.pl

index 4763d02..d900d18 100755 (executable)
@@ -2831,8 +2831,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);