From patchwork Sat Dec 26 20:58:58 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julia Lawall X-Patchwork-Id: 561116 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id D3678140C88 for ; Sun, 27 Dec 2015 07:59:04 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751674AbbLZU7C (ORCPT ); Sat, 26 Dec 2015 15:59:02 -0500 Received: from mail2-relais-roc.national.inria.fr ([192.134.164.83]:42888 "EHLO mail2-relais-roc.national.inria.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751601AbbLZU7B (ORCPT ); Sat, 26 Dec 2015 15:59:01 -0500 X-IronPort-AV: E=Sophos;i="5.20,483,1444687200"; d="scan'208";a="194461854" Received: from 198.67.28.109.rev.sfr.net (HELO hadrien) ([109.28.67.198]) by mail2-relais-roc.national.inria.fr with ESMTP/TLS/DHE-RSA-AES256-SHA; 26 Dec 2015 21:58:59 +0100 Date: Sat, 26 Dec 2015 21:58:58 +0100 (CET) From: Julia Lawall X-X-Sender: jll@localhost6.localdomain6 To: Gilles Muller , Nicolas Palix , Michal Marek , cocci@systeme.lip6.fr, linux-kernel@vger.kernel.org, Sergei Shtylyov , linux-media@vger.kernel.org, netdev@vger.kernel.org, linux-i2c@vger.kernel.org, linux-spi@vger.kernel.org, dri-devel@lists.freedesktop.org cc: kernel-janitors@vger.kernel.org Subject: [PATCH v2] coccinelle: api: check for propagation of error from platform_get_irq In-Reply-To: <567EF895.6080702@cogentembedded.com> Message-ID: References: <1451157891-24881-1-git-send-email-Julia.Lawall@lip6.fr> <567EF188.7020203@cogentembedded.com> <567EF895.6080702@cogentembedded.com> User-Agent: Alpine 2.02 (DEB 1266 2009-07-14) MIME-Version: 1.0 Sender: linux-i2c-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org The error return value of platform_get_irq seems to often get dropped. Signed-off-by: Julia Lawall --- v2: Check for the direct return case also. Added some mailing lists of common offenders. -- To unsubscribe from this list: send the line "unsubscribe linux-i2c" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/scripts/coccinelle/api/platform_get_irq_return.cocci b/scripts/coccinelle/api/platform_get_irq_return.cocci new file mode 100644 index 0000000..44680d0 --- /dev/null +++ b/scripts/coccinelle/api/platform_get_irq_return.cocci @@ -0,0 +1,58 @@ +/// Propagate the return value of platform_get_irq. +//# Sometimes the return value of platform_get_irq is tested using <= 0, but 0 +//# might not be an appropriate return value in an error case. +/// +// Confidence: Moderate +// Copyright: (C) 2015 Julia Lawall, Inria. GPLv2. +// URL: http://coccinelle.lip6.fr/ +// Options: --no-includes --include-headers + +virtual context +virtual org +virtual report + +// ---------------------------------------------------------------------------- + +@r depends on context || org || report@ +constant C; +statement S; +expression e, ret; +position j0, j1; +@@ + +* e@j0 = platform_get_irq(...); +( +if@j1 (...) { + ... + return -C; +} else S +| +if@j1 (...) { + ... + ret = -C; + ... + return ret; +} else S +) + +// ---------------------------------------------------------------------------- + +@script:python r_org depends on org@ +j0 << r.j0; +j1 << r.j1; +@@ + +msg = "Propagate return value of platform_get_irq." +coccilib.org.print_todo(j0[0], msg) +coccilib.org.print_link(j1[0], "") + +// ---------------------------------------------------------------------------- + +@script:python r_report depends on report@ +j0 << r.j0; +j1 << r.j1; +@@ + +msg = "Propagate return value of platform_get_irq around line %s." % (j1[0].line) +coccilib.report.print_report(j0[0], msg) +