From patchwork Fri Oct 11 16:04:11 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Vladimir Sementsov-Ogievskiy X-Patchwork-Id: 11186629 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 472F71709 for ; Sat, 12 Oct 2019 04:55:56 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 21D4D20659 for ; Sat, 12 Oct 2019 04:55:55 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 21D4D20659 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=virtuozzo.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iJ9Pq-0003L2-6N; Sat, 12 Oct 2019 04:54:06 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iIxSw-0001Tg-V9 for xen-devel@lists.xenproject.org; Fri, 11 Oct 2019 16:08:30 +0000 X-Inumbo-ID: 5cc167fc-ec41-11e9-8aca-bc764e2007e4 Received: from relay.sw.ru (unknown [185.231.240.75]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 5cc167fc-ec41-11e9-8aca-bc764e2007e4; Fri, 11 Oct 2019 16:08:29 +0000 (UTC) Received: from [10.94.3.0] (helo=kvm.qa.sw.ru) by relay.sw.ru with esmtp (Exim 4.92.2) (envelope-from ) id 1iIxQb-0003XG-IB; Fri, 11 Oct 2019 19:06:05 +0300 From: Vladimir Sementsov-Ogievskiy To: qemu-devel@nongnu.org Date: Fri, 11 Oct 2019 19:04:11 +0300 Message-Id: <20191011160552.22907-26-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20191011160552.22907-1-vsementsov@virtuozzo.com> References: <20191011160552.22907-1-vsementsov@virtuozzo.com> MIME-Version: 1.0 X-Mailman-Approved-At: Sat, 12 Oct 2019 04:54:04 +0000 Subject: [Xen-devel] [RFC v5 025/126] scripts: add coccinelle script to use auto propagated errp X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Ronnie Sahlberg , Jeff Cody , Jan Kiszka , Eric Blake , Alberto Garcia , Hailiang Zhang , qemu-block@nongnu.org, Aleksandar Rikalo , Halil Pasic , =?utf-8?q?Herv=C3=A9_Poussineau?= , Anthony Perard , Samuel Thibault , =?utf-8?q?Philippe_Mathieu-?= =?utf-8?q?Daud=C3=A9?= , Anthony Green , Laurent Vivier , Eduardo Habkost , Xie Changlong , Peter Lieven , "Dr. David Alan Gilbert" , Beniamino Galvani , Eric Auger , Alex Williamson , Stefan Hajnoczi , John Snow , Richard Henderson , Kevin Wolf , vsementsov@virtuozzo.com, Andrew Jeffery , Chris Wulff , Subbaraya Sundeep , Michael Walle , qemu-ppc@nongnu.org, Bastian Koppelmann , Igor Mammedov , Fam Zheng , Peter Maydell , sheepdog@lists.wpkg.org, Matthew Rosato , David Hildenbrand , Palmer Dabbelt , Thomas Huth , Max Filippov , "Denis V. Lunev" , Hannes Reinecke , Stefano Stabellini , "Gonglei \(Arei\)" , Marcel Apfelbaum , Liu Yuan , Artyom Tarasenko , Eric Farman , Amit Shah , Stefan Weil , Greg Kurz , Yuval Shaia , qemu-s390x@nongnu.org, qemu-arm@nongnu.org, Peter Chubb , =?utf-8?q?C?= =?utf-8?q?=C3=A9dric_Le_Goater?= , Stafford Horne , qemu-riscv@nongnu.org, Cornelia Huck , Aleksandar Markovic , Aurelien Jarno , Paul Burton , Sagar Karandikar , Paul Durrant , Jason Wang , Gerd Hoffmann , "Edgar E. Iglesias" , Guan Xuetao , Ari Sundholm , Juan Quintela , Michael Roth , Christian Borntraeger , Joel Stanley , Jason Dillaman , Antony Pavlov , xen-devel@lists.xenproject.org, integration@gluster.org, Laszlo Ersek , "Richard W.M. Jones" , Andrew Baumann , Max Reitz , "Michael S. Tsirkin" , Mark Cave-Ayland , Vincenzo Maffione , Marek Vasut , armbru@redhat.com, =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , Alistair Francis , Pavel Dovgalyuk , Giuseppe Lettieri , Luigi Rizzo , David Gibson , Tony Krowiak , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , Xiao Guangrong , Pierre Morel , Wen Congyang , Jean-Christophe Dubois , Paolo Bonzini , Stefan Berger Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Signed-off-by: Vladimir Sementsov-Ogievskiy --- CC: Gerd Hoffmann CC: "Gonglei (Arei)" CC: Eduardo Habkost CC: Igor Mammedov CC: Laurent Vivier CC: Amit Shah CC: Kevin Wolf CC: Max Reitz CC: John Snow CC: Ari Sundholm CC: Pavel Dovgalyuk CC: Paolo Bonzini CC: Stefan Hajnoczi CC: Fam Zheng CC: Stefan Weil CC: Ronnie Sahlberg CC: Peter Lieven CC: Eric Blake CC: "Denis V. Lunev" CC: Markus Armbruster CC: Alberto Garcia CC: Jason Dillaman CC: Wen Congyang CC: Xie Changlong CC: Liu Yuan CC: "Richard W.M. Jones" CC: Jeff Cody CC: "Marc-André Lureau" CC: "Daniel P. Berrangé" CC: Richard Henderson CC: Greg Kurz CC: "Michael S. Tsirkin" CC: Marcel Apfelbaum CC: Beniamino Galvani CC: Peter Maydell CC: "Cédric Le Goater" CC: Andrew Jeffery CC: Joel Stanley CC: Andrew Baumann CC: "Philippe Mathieu-Daudé" CC: Antony Pavlov CC: Jean-Christophe Dubois CC: Peter Chubb CC: Subbaraya Sundeep CC: Eric Auger CC: Alistair Francis CC: "Edgar E. Iglesias" CC: Stefano Stabellini CC: Anthony Perard CC: Paul Durrant CC: Paul Burton CC: Aleksandar Rikalo CC: Chris Wulff CC: Marek Vasut CC: David Gibson CC: Cornelia Huck CC: Halil Pasic CC: Christian Borntraeger CC: "Hervé Poussineau" CC: Xiao Guangrong CC: Aurelien Jarno CC: Aleksandar Markovic CC: Mark Cave-Ayland CC: Jason Wang CC: Laszlo Ersek CC: Yuval Shaia CC: Palmer Dabbelt CC: Sagar Karandikar CC: Bastian Koppelmann CC: David Hildenbrand CC: Thomas Huth CC: Eric Farman CC: Matthew Rosato CC: Hannes Reinecke CC: Michael Walle CC: Artyom Tarasenko CC: Stefan Berger CC: Samuel Thibault CC: Alex Williamson CC: Tony Krowiak CC: Pierre Morel CC: Michael Roth CC: Hailiang Zhang CC: Juan Quintela CC: "Dr. David Alan Gilbert" CC: Luigi Rizzo CC: Giuseppe Lettieri CC: Vincenzo Maffione CC: Jan Kiszka CC: Anthony Green CC: Stafford Horne CC: Guan Xuetao CC: Max Filippov CC: qemu-block@nongnu.org CC: integration@gluster.org CC: sheepdog@lists.wpkg.org CC: qemu-arm@nongnu.org CC: xen-devel@lists.xenproject.org CC: qemu-ppc@nongnu.org CC: qemu-s390x@nongnu.org CC: qemu-riscv@nongnu.org scripts/coccinelle/auto-propagated-errp.cocci | 118 ++++++++++++++++++ 1 file changed, 118 insertions(+) create mode 100644 scripts/coccinelle/auto-propagated-errp.cocci diff --git a/scripts/coccinelle/auto-propagated-errp.cocci b/scripts/coccinelle/auto-propagated-errp.cocci new file mode 100644 index 0000000000..d9731620aa --- /dev/null +++ b/scripts/coccinelle/auto-propagated-errp.cocci @@ -0,0 +1,118 @@ +@rule0@ +// Add invocation to errp-functions where necessary +identifier fn, local_err; +symbol errp; +@@ + + fn(..., Error **errp, ...) + { ++ ERRP_AUTO_PROPAGATE(); + <+... +( + error_append_hint(errp, ...); +| + error_prepend(errp, ...); +| + Error *local_err = NULL; +) + ...+> + } + +@@ +// Drop doubled invocation +identifier rule0.fn; +@@ + + fn(...) +{ +- ERRP_AUTO_PROPAGATE(); + ERRP_AUTO_PROPAGATE(); + ... +} + +@rule1@ +// Drop local_err +identifier fn, local_err; +symbol errp; +@@ + + fn(..., Error **errp, ...) + { + <... +- Error *local_err = NULL; + ...> + } + +@@ +// Handle pattern with goto, otherwise we'll finish up +// with labels at function end which will not compile. +identifier rule1.fn; +identifier rule1.local_err; +identifier OUT; +@@ + + fn(...) + { + <... +- goto OUT; ++ return; + ...> +- OUT: +- error_propagate(errp, local_err); + } + +@@ +identifier rule1.fn; +identifier rule1.local_err; +@@ + + fn(...) + { + <... +( +- error_free(local_err); +- local_err = NULL; ++ error_free_errp(errp); +| +- error_free(local_err); ++ error_free_errp(errp); +| +- error_report_err(local_err); ++ error_report_errp(errp); +| +- warn_report_err(local_err); ++ warn_report_errp(errp); +| +- error_propagate_prepend(errp, local_err, ++ error_prepend(errp, + ...); +| +- error_propagate(errp, local_err); +) + ...> + } + +@@ +identifier rule1.fn; +identifier rule1.local_err; +@@ + + fn(...) + { + <... +( +- &local_err ++ errp +| +- local_err ++ *errp +) + ...> + } + +@@ +symbol errp; +@@ + +- *errp != NULL ++ *errp