Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757765AbbEEKVP (ORCPT ); Tue, 5 May 2015 06:21:15 -0400 Received: from www.osadl.org ([62.245.132.105]:45946 "EHLO www.osadl.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752532AbbEEKVI (ORCPT ); Tue, 5 May 2015 06:21:08 -0400 From: Nicholas Mc Guire To: Julia Lawall Cc: Gilles Muller , Nicolas Palix , Michal Marek , cocci@systeme.lip6.fr, linux-kernel@vger.kernel.org, Nicholas Mc Guire Subject: [PATCH RFC] Coccinelle: Check for return not matching function signature Date: Tue, 5 May 2015 12:12:41 +0200 Message-Id: <1430820761-28122-1-git-send-email-hofrat@osadl.org> X-Mailer: git-send-email 1.7.10.4 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2074 Lines: 71 Check if the signature of a function and the return value type match. This is currently not the case in more than 2300 functions. In many cases this mismatch will have no side-effects but in some cases it may lead to hard to locate problems - and for readability and code understanding it is also helpful when types match. Signed-off-by: Nicholas Mc Guire --- Did not see any false positives in a scan of 4.0-rc2 (but did not check all results either). Not sure if scripts/coccinelle/tests/ is the right place for this It did not seem to trigger any false positives but in some cases (notably void pointers) the warning might be unnecessary. The output is a bit lengthy - not sure if that is too much but it seemed useful to me to see the non-matching types explicitly in the warning message. Patch is against 4.1-rc2 (localversion-next is -next-20150505) .../coccinelle/tests/signature_matches_ret.cocci | 31 ++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 scripts/coccinelle/tests/signature_matches_ret.cocci diff --git a/scripts/coccinelle/tests/signature_matches_ret.cocci b/scripts/coccinelle/tests/signature_matches_ret.cocci new file mode 100644 index 0000000..2dd1086 --- /dev/null +++ b/scripts/coccinelle/tests/signature_matches_ret.cocci @@ -0,0 +1,31 @@ +// Find functions where return type and signature do not match +// Comments: +// Options: --no-includes --include-headers + +virtual context +virtual org +virtual report + +@match@ +identifier f,ret; +position p; +type T1,T2; +@@ + +T1 f(...) { + T2 ret; +<+... +* return@p ret +; +...+> +} + +@script:python@ +p << match.p; +fn << match.f; +T1 << match.T1; +T2 << match.T2; +@@ + +if T1 != T2: + print "%s:%s,%s WARNING: return of wrong type (%s != %s)" % (p[0].file,fn,p[0].line,T1,T2) -- 1.7.10.4 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/