Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp2251015pxb; Mon, 18 Jan 2021 12:20:45 -0800 (PST) X-Google-Smtp-Source: ABdhPJwbrQDKr4ujol46KJ1L7Kz3GFE/CLRGXk2qj8W0rwwCMheXDlyaOWHhp/j96NBwG4eh6hPD X-Received: by 2002:a50:e84d:: with SMTP id k13mr877290edn.154.1611001245122; Mon, 18 Jan 2021 12:20:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611001245; cv=none; d=google.com; s=arc-20160816; b=ZwjXZ6jxp5Nek6cI2It4+nl0zn5IMWb88AXSa4FgYkExXii/0SqzD8oSVDRM989ONX PfFbsX2731LnVKdJ80yLtXTlzepg2KZ3fiIoh4l1O/a2ADLBZWysK1F3yQjUrDcnNOVL BG8rrQp8+lDj5IHfmsEy6KXGEvFjGLt2abO1rF6Ynzvzr0BXFdyu+3GOnAegrQS8FKI4 r3t4mFiH/ot0plYSesXDvArbn36AzA8HsMNcRAzEnyw3YLRWmZuds1A9DY+jEWbXCq6O l0iAO6Lngtqd7wIHrkrNz1CF/WKGYzkZeycm3gZcYNUXDrsVg7vM0IsvO5rLSWzkAAbu NuoQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:reply-to; bh=J8uu0HUiN8SN6II5HsKiE6kftRNhKowXcEILufp9i/8=; b=YNkKEcEtrap3cCb5f5Qg63MYJJWd4/n7l4ARA7UTyA8Gm5eoGFIbZ3r4wuTEtANFyC 3CWFB+LjCyl7cF5MPcnr9ZSxK7n7+f4cS4w+e9REz4dskF9SGWuOYSvisQHgOFA2gz9L em/6/Rx4gGGTS0mXUQYJhK/4+b25JMU9IB/S05n/GEQo16+d/N1Rt45J6rkzFpTXC5pp aOfY1WSUSp04SEmczqjEgzwcRr3GTN5E6+3z102hPVuOzTfJvRsQoGbXssPC0EqAa2CW c1CaKIRInd7776kzrol3clVVqDO5MZzvlAK45EOLl5cr+CxVG2PH1xjEuS1e5lpob3s1 uRrg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id j27si8110519edj.268.2021.01.18.12.20.21; Mon, 18 Jan 2021 12:20:45 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2394205AbhARURm (ORCPT + 99 others); Mon, 18 Jan 2021 15:17:42 -0500 Received: from mail-1.ca.inter.net ([208.85.220.69]:45435 "EHLO mail-1.ca.inter.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2437994AbhARURa (ORCPT ); Mon, 18 Jan 2021 15:17:30 -0500 Received: from localhost (offload-3.ca.inter.net [208.85.220.70]) by mail-1.ca.inter.net (Postfix) with ESMTP id 7680F2EA30D; Mon, 18 Jan 2021 15:16:43 -0500 (EST) Received: from mail-1.ca.inter.net ([208.85.220.69]) by localhost (offload-3.ca.inter.net [208.85.220.70]) (amavisd-new, port 10024) with ESMTP id Ip4T-viMDDji; Mon, 18 Jan 2021 15:03:07 -0500 (EST) Received: from [192.168.48.23] (host-104-157-204-209.dyn.295.ca [104.157.204.209]) (using TLSv1 with cipher DHE-RSA-AES128-SHA (128/128 bits)) (No client certificate requested) (Authenticated sender: dgilbert@interlog.com) by mail-1.ca.inter.net (Postfix) with ESMTPSA id DA1402EA307; Mon, 18 Jan 2021 15:16:42 -0500 (EST) Reply-To: dgilbert@interlog.com Subject: Re: [PATCH] checkpatch: Improve TYPECAST_INT_CONSTANT test message To: Joe Perches , Andrew Morton Cc: LKML References: <63178794d14d12f28ccf87707f420ba97b90f6fd.camel@perches.com> From: Douglas Gilbert Message-ID: <1afecb44-cc40-c943-8d6e-eb3f50eaa9f9@interlog.com> Date: Mon, 18 Jan 2021 15:16:42 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-CA Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2021-01-18 12:19 p.m., Joe Perches wrote: > Improve the TYPECAST_INT_CONSTANT test by showing the suggested > conversion for various type of uses like (unsigned int)1 to 1U. The questionable code snippet was: unsigned int nent, nalloc; .... if (check_add_overflow(nent, (unsigned int)1, &nalloc)) where the check_add_overflow() macro [include/linux/overflow.h] uses typeid to check its first and second arguments have the same type. So it is likely others could meet this issue. Doug Gilbert > Signed-off-by: Joe Perches > --- > > Douglas Gilbert sent me a private email (and in that email said he > 'loves to hate checkpatch' ;) complaining that checkpatch warned on the > use of the cast of '(unsigned int)1' so make it more obvious why the > message is emitted by always showing the suggested conversion. > > scripts/checkpatch.pl | 20 ++++++++++---------- > 1 file changed, 10 insertions(+), 10 deletions(-) > > diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl > index 016115a62a9f..4f8494527139 100755 > --- a/scripts/checkpatch.pl > +++ b/scripts/checkpatch.pl > @@ -6527,18 +6527,18 @@ sub process { > if ($line =~ /(\(\s*$C90_int_types\s*\)\s*)($Constant)\b/) { > my $cast = $1; > my $const = $2; > + my $suffix = ""; > + my $newconst = $const; > + $newconst =~ s/${Int_type}$//; > + $suffix .= 'U' if ($cast =~ /\bunsigned\b/); > + if ($cast =~ /\blong\s+long\b/) { > + $suffix .= 'LL'; > + } elsif ($cast =~ /\blong\b/) { > + $suffix .= 'L'; > + } > if (WARN("TYPECAST_INT_CONSTANT", > - "Unnecessary typecast of c90 int constant\n" . $herecurr) && > + "Unnecessary typecast of c90 int constant - '$cast$const' could be '$const$suffix'\n" . $herecurr) && > $fix) { > - my $suffix = ""; > - my $newconst = $const; > - $newconst =~ s/${Int_type}$//; > - $suffix .= 'U' if ($cast =~ /\bunsigned\b/); > - if ($cast =~ /\blong\s+long\b/) { > - $suffix .= 'LL'; > - } elsif ($cast =~ /\blong\b/) { > - $suffix .= 'L'; > - } > $fixed[$fixlinenr] =~ s/\Q$cast\E$const\b/$newconst$suffix/; > } > } > >