From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1422688AbcFCUmP (ORCPT ); Fri, 3 Jun 2016 16:42:15 -0400 Received: from smtprelay0120.hostedemail.com ([216.40.44.120]:38896 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752272AbcFCUmO (ORCPT ); Fri, 3 Jun 2016 16:42:14 -0400 X-Session-Marker: 6A6F6540706572636865732E636F6D X-Spam-Summary: 50,0,0,,d41d8cd98f00b204,joe@perches.com,:::::::::,RULES_HIT:41:355:379:541:560:599:800:960:967:973:982:988:989:1260:1277:1311:1313:1314:1345:1359:1373:1437:1515:1516:1518:1534:1542:1593:1594:1711:1730:1747:1777:1792:1981:2194:2199:2393:2525:2560:2563:2682:2685:2828:2859:2895:2933:2937:2939:2942:2945:2947:2951:2954:3022:3138:3139:3140:3141:3142:3354:3608:3622:3865:3866:3867:3868:3870:3871:3872:3874:3934:3936:3938:3941:3944:3947:3950:3953:3956:3959:4250:4321:5007:7875:7903:7974:9025:10004:10400:10848:11232:11658:11783:11914:12043:12517:12519:12555:12663:12740:13095:13132:13231:13439:13894:14181:14659:14721:21080:21433:30012:30034:30054:30064:30069:30070:30091,0,RBL:none,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fn,MSBL:0,DNSBL:none,Custom_rules:0:0:0,LFtime:4,LUA_SUMMARY:none X-HE-Tag: light00_4d4ce37eb5716 X-Filterd-Recvd-Size: 3310 Message-ID: <1464986529.11800.24.camel@perches.com> Subject: Re: [PATCH V2] checkpatch: Flag code that returns a negative number less than 1 From: Joe Perches To: Nishanth Menon , Andy Whitcroft Cc: linux-kernel@vger.kernel.org, afd@ti.com, Andrew Morton Date: Fri, 03 Jun 2016 13:42:09 -0700 In-Reply-To: <1464984122-16381-1-git-send-email-nm@ti.com> References: <1464967533-14634-1-git-send-email-nm@ti.com> <1464984122-16381-1-git-send-email-nm@ti.com> Content-Type: text/plain; charset="ISO-8859-1" X-Mailer: Evolution 3.18.5.2-0ubuntu3 Mime-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 2016-06-03 at 15:02 -0500, Nishanth Menon wrote: > In some functions, returning a -ve decimal value is actually a valid > return condition when the function is returning a value, however, it > can also be misused for returning an error value that should ideally > be a valid error code defined in include/uapi/asm-generic/errno-base.h > or include/uapi/asm-generic/errno.h. The notable exception is "-1" > which has quiet a history of usage as pointed out by Joe Perches. > > Considering typical error of doing the following: > int fn(void) > { > /* ... error condition ... */ > return -2; > } > > void fn1(void) > { > /* some code */ > if (fn() < 0) { > pr_err("Error occurred\n"); > return; > } > /* other cases... */ > } > > Flag this as a check case for developer verification. > > The check is done for negative values less than 1 and tools > directory is exempt from this requirement based on Joe Perches' > suggestion. > > Suggested-by: Joe Perches No, I didn't suggest this. I'm not at all sure it's even a good idea. > Signed-off-by: Nishanth Menon > --- > Changes in V2: > - change in regex for check for check for less than 1 > - Update in commit message to the effect > - Added Suggested-by for Joe's recommendation on regex. > > V1: https://patchwork.kernel.org/patch/9153345/ > >  scripts/checkpatch.pl | 6 ++++++ >  1 file changed, 6 insertions(+) > > diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl > index 4904ced676d4..a2e677b5fd78 100755 > --- a/scripts/checkpatch.pl > +++ b/scripts/checkpatch.pl > @@ -4351,6 +4351,12 @@ sub process { >   } >   } >   > +# return with a value is not usually a good sign, unless the function is supposed to return a value > + if ($realfile !~ /^tools/ && defined($stat) && $stat =~ /^.\s*return\s*-\s*(?!1\b)\d+\s*;/s) { I think if ($realfile != /^tools/ && $line =~ /\breturn\s*-\s*(?!1\b)\d+\s*;/ would be better as it would catch return -2 in a macro or a multi-line statement like if () return -2; > + CHK("RETURN_NUMBER", > +     "Suspect error return with a value, If this is error value, refer to include/uapi/asm-generic/errno-base.h  and include/uapi/asm-generic/errno.h\n" . $herecurr); That's an awfully long message. Maybe something like: "Perhaps better to use standard ERRNO system error symbols"