From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751590AbcGRPa5 (ORCPT ); Mon, 18 Jul 2016 11:30:57 -0400 Received: from smtprelay0186.hostedemail.com ([216.40.44.186]:49930 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751251AbcGRPaw (ORCPT ); Mon, 18 Jul 2016 11:30:52 -0400 X-Session-Marker: 6A6F6540706572636865732E636F6D X-Spam-Summary: 2,0,0,,d41d8cd98f00b204,joe@perches.com,:::::,RULES_HIT:41:355:379:541:599:973:982:988:989:1260:1277:1311:1313:1314:1345:1359:1373:1437:1515:1516:1518:1534:1541:1593:1594:1711:1730:1747:1777:1792:2393:2559:2562:2693:2736:2828:2898:3138:3139:3140:3141:3142:3353:3622:3865:3866:3867:3868:3870:3871:3872:3874:4184:4321:5007:6117:7903:10004:10400:10848:11026:11232:11658:11914:12517:12519:12740:13069:13071:13095:13161:13229:13311:13357:13439:13894:14180:14659:14721:21060:21080:21433:30012:30054: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:2,LUA_SUMMARY:none X-HE-Tag: sand13_7acd84a80372a X-Filterd-Recvd-Size: 2168 Message-ID: <1468855842.1900.14.camel@perches.com> Subject: Re: checkpatch: false positives for else after return From: Joe Perches To: Thierry Reding , Andy Whitcroft Cc: linux-kernel@vger.kernel.org Date: Mon, 18 Jul 2016 08:30:42 -0700 In-Reply-To: <20160718112622.GA18547@ulmo.ba.sec> References: <20160718112622.GA18547@ulmo.ba.sec> 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 Mon, 2016-07-18 at 13:26 +0200, Thierry Reding wrote: > Hi, > > I've run across what I think is a false positive for checkpatch's > UNNECESSARY_ELSE check. The code that triggers it is in the > tegra_sor_probe() function in drivers/gpu/drm/tegra/sor.c. For > reference, here's the code: > > if (sor->soc->supports_hdmi) { > sor->ops = &tegra_sor_hdmi_ops; > } else if (sor->soc->supports_lvds) { > dev_err(&pdev->dev, "LVDS not supported yet\n"); > return -ENODEV; > } else { > dev_err(&pdev->dev, "unknown (non-DP) support\n"); > return -ENODEV; > } > > For the first case (HDMI supported on SoC) the code should continue > normally, but otherwise we need to error out because we don't support > the configuration. > > I can't come up with an alternative way of writing the above, and at the > same time I can't see what's wrong with the above. It looks like a > legitimate use of an else to me. > > I made an attempt at fixing the check myself but failed miserably. Regex > isn't among my strong skills =\ > > Any ideas on how to deal with this? Hi Thierry. Ignore checkpatch when it's wrong. The message is: "else is not generally useful after a break or return" and that statement is true. checkpatch is not, and will not become, a code flow analysis tool.  It's a very brain-dead, stupid little script that looks at very simple patch table rules.