Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp2147304pxb; Mon, 18 Jan 2021 09:22:17 -0800 (PST) X-Google-Smtp-Source: ABdhPJwmdIawOlyF4QnpyfzeZOc66B8jqUKVttuTxygYe/ccUEwHmPx0xW/Rwz+oiCFVc89GBCRG X-Received: by 2002:a50:ef04:: with SMTP id m4mr367692eds.283.1610990537495; Mon, 18 Jan 2021 09:22:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610990537; cv=none; d=google.com; s=arc-20160816; b=YFbaO7gB6oE5tvknpkpNzNSGKZpgAuItr1QJsyvMhJ+dEhbYvqim2+oC3D9ujIoy7v 3mHt30s+cAUfQRDRQ9QNv+n0jLd+IVdPVNPIzJezWKk1erqoKgVGa+fCEKkKCErA8hHu uF6JmYuFu7+PcnCxuXuqnkGgQt0zzagwOByLPY9uTylyvATQ/YyBrTDtDGbx3uoA0lQH kxA7UfAIUZlzK6syrOLHLrv8KCkQIdCSDvLQGyxzYnokNSG+Zw2ipi0Vzl7yKaW7R+Js UHv474XKCb0algponSvIrv+/INGttVdNa0wN3wdE4pVVemxzDVa1e2h1pPuZ4Mrs1GLe vy1A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:date:cc:to:from:subject :message-id; bh=POaKK+hnRKHUW3gCLegKR2cijkVLV7ORWv2Op/GBLjc=; b=qk0lj9rK0aIMkZdZfw75RhuLhgAJMIyJApWe+1V+q8GjjJD1VLplC7DGA3UAyXeR3Y FIGMvxK/ZB7HLRtneJjyldiTt6s7ixNU1rYXK33/CHNLIERhI7X18GbzfCQSzrFiHB+e w83GZtchDHH043WgaFSHpRDtgwLh6w8xua3J/2csCAIRFoz2k3k8Jftx+N4U1nVacwFs gYzw5DZSt8iHJgoevpbnQYe3A+TeJyZWMSjCPFXra1ODuVYl1VMJiwQRRNNNeRQ4Kvew M+z6xJzQnA7OJKsL+a/fQNpA4rk3IlF709Mm8rsCbj1zMVWKL89aC65hn0vfQZJ8tVXc MsDQ== 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 f13si3776355edx.272.2021.01.18.09.21.53; Mon, 18 Jan 2021 09:22:17 -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 S2406876AbhARRUE (ORCPT + 99 others); Mon, 18 Jan 2021 12:20:04 -0500 Received: from smtprelay0109.hostedemail.com ([216.40.44.109]:49252 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2406531AbhARRUC (ORCPT ); Mon, 18 Jan 2021 12:20:02 -0500 Received: from filter.hostedemail.com (clb03-v110.bra.tucows.net [216.40.38.60]) by smtprelay03.hostedemail.com (Postfix) with ESMTP id AE7458384366; Mon, 18 Jan 2021 17:19:20 +0000 (UTC) X-Session-Marker: 6A6F6540706572636865732E636F6D X-Spam-Summary: 2,0,0,,d41d8cd98f00b204,joe@perches.com,,RULES_HIT:41:69:355:379:800:960:973:982:988:989:1260:1261:1277:1311:1313:1314:1345:1359:1437:1515:1516:1518:1534:1541:1593:1594:1711:1730:1747:1777:1792:2197:2199:2393:2559:2562:2828:3138:3139:3140:3141:3142:3353:3653:3865:3866:3867:3868:3870:3871:3872:3874:4321:5007:6119:7652:7903:8531:8907:10004:10400:10848:11026:11232:11473:11658:11914:12043:12114:12297:12438:12555:12663:12760:12986:13069:13095:13181:13229:13311:13357:13439:14181:14394:14659:14721:14777:21080:21212:21221:21433:21627:21660:21819:30022:30054,0,RBL:none,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:,MSBL:0,DNSBL:none,Custom_rules:0:0:0,LFtime:2,LUA_SUMMARY:none X-HE-Tag: pet14_23036e32754b X-Filterd-Recvd-Size: 2639 Received: from [192.168.1.159] (unknown [47.151.137.21]) (Authenticated sender: joe@perches.com) by omf01.hostedemail.com (Postfix) with ESMTPA; Mon, 18 Jan 2021 17:19:19 +0000 (UTC) Message-ID: Subject: [PATCH] checkpatch: Improve TYPECAST_INT_CONSTANT test message From: Joe Perches To: Andrew Morton Cc: dgilbert@interlog.com, LKML Date: Mon, 18 Jan 2021 09:19:18 -0800 In-Reply-To: References: <63178794d14d12f28ccf87707f420ba97b90f6fd.camel@perches.com> Content-Type: text/plain; charset="ISO-8859-1" User-Agent: Evolution 3.38.1-1 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Improve the TYPECAST_INT_CONSTANT test by showing the suggested conversion for various type of uses like (unsigned int)1 to 1U. 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/; } }