From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754145AbcKATSE (ORCPT ); Tue, 1 Nov 2016 15:18:04 -0400 Received: from smtp08.smtpout.orange.fr ([80.12.242.130]:53107 "EHLO smtp.smtpout.orange.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752674AbcKATSC (ORCPT ); Tue, 1 Nov 2016 15:18:02 -0400 X-ME-Helo: [127.0.0.1] X-ME-Date: Tue, 01 Nov 2016 20:18:00 +0100 X-ME-IP: 92.140.167.9 Subject: Re: [PATCH] UBIFS: Remove some dead code To: Richard Weinberger , dedekind1@gmail.com, adrian.hunter@intel.com, julia.lawall@lip6.fr References: <20161101064525.11813-1-christophe.jaillet@wanadoo.fr> Cc: linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org Newsgroups: gmane.linux.kernel.janitors,gmane.linux.drivers.mtd,gmane.linux.kernel From: Christophe JAILLET Message-ID: <1dc01a45-1eb4-20bd-c5c8-c8f37ba60e06@wanadoo.fr> Date: Tue, 1 Nov 2016 20:17:52 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.4.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 8bit X-Antivirus: avast! (VPS 161101-0, 01/11/2016), Outbound message X-Antivirus-Status: Clean Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Le 01/11/2016 à 12:42, Richard Weinberger a écrit : > On 01.11.2016 07:45, Christophe JAILLET wrote: >> 'ubifs_fast_find_freeable()' can not return an error pointer, so this test >> can be removed. >> >> Signed-off-by: Christophe JAILLET >> --- >> fs/ubifs/gc.c | 4 ---- >> 1 file changed, 4 deletions(-) >> >> diff --git a/fs/ubifs/gc.c b/fs/ubifs/gc.c >> index e845c64b6ce1..7b35e3d6cde7 100644 >> --- a/fs/ubifs/gc.c >> +++ b/fs/ubifs/gc.c >> @@ -846,10 +846,6 @@ int ubifs_gc_start_commit(struct ubifs_info *c) >> */ >> while (1) { >> lp = ubifs_fast_find_freeable(c); >> - if (IS_ERR(lp)) { >> - err = PTR_ERR(lp); >> - goto out; >> - } > Good catch, how did you find this? > If you have a tool/script I'd like to use it too. > > Thanks, > //richard > -- Hi, well, it is a bit tricky. AFAIK, coccinelle is only able to match things in a given file. Finding issues between 2 files can be tricky. So first, I have built a list a functions which are likely to return NULL, either because they explicitly return NULL or if its return value is tested against NULL or not. See coccinelle script n°1 below. Then I have built a list of functions followed by a test with IS_ERR. See coccinelle script n°2 below. These 2 scripts generate 2 lists of functions. If a function is present in the 2 files, it is likely that something is spurious. Either the IS_ERR is not needed (this is the case in the patch above), either the return value is incorrectly checked. Could also be that NULL is returned but an error pointer would be a better option. I also did more or less the same for functions that return PTR_ERR and functions that are not followed by a test with IS_ERR. I can post these other scripts if wanted. Any ideas to improve or speed-up the coccinelle scripts are welcome. Julia ? Best regards, CJ Coccinelle script n°1: ===================== @find@ identifier f; @@ f(...) { ... return NULL; } @script:python@ f << find.f; @@ print "%s" %(f) @find2@ identifier f; expression x; statement S; @@ x = f(...); ( if (x) S | if (!x) S ) @script:python@ f << find2.f; @@ print "%s" %(f) Coccinelle script n°2: ===================== @find@ statement S; type t; t *x; identifier f; @@ x = f(...); ( if (IS_ERR(x)) S | if (!IS_ERR(x)) S ) @script:python@ f << find.f; @@ print "%s" %(f)