From patchwork Mon Apr 6 17:47:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 1267020 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=amsat.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=mNgL36Vb; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 48wzVp0hxpz9sRR for ; Tue, 7 Apr 2020 04:25:37 +1000 (AEST) Received: from localhost ([::1]:36672 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jLWRC-0006fz-TO for incoming@patchwork.ozlabs.org; Mon, 06 Apr 2020 14:25:34 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36904) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jLVrm-00035e-FR for qemu-devel@nongnu.org; Mon, 06 Apr 2020 13:48:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jLVrl-0003cC-8r for qemu-devel@nongnu.org; Mon, 06 Apr 2020 13:48:58 -0400 Received: from mail-wm1-x32e.google.com ([2a00:1450:4864:20::32e]:38918) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jLVrl-0003bo-2f for qemu-devel@nongnu.org; Mon, 06 Apr 2020 13:48:57 -0400 Received: by mail-wm1-x32e.google.com with SMTP id y20so309000wma.4 for ; Mon, 06 Apr 2020 10:48:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=+cshPsuV+p8IWnAz7VC2hUR8PIasPI419EzyAajDQQE=; b=mNgL36Vb89yMQ5n8Ku7zfqfPAxnaWgJRgbgA0rF+/hj6UudBNa+dz0UuOcxcJlM4F+ fZwhsg6c1KnDO4hlVVdrWRQv5xUc2jV+co7WWAS/I+OnIMYITjtEsQr98nnSuwZoReCK wXoybjOyOeLAiQOcNCSvWWyoZCoUf9lkJI3OGE1im+YMB9yLxeeptse1sAIRH++BrvCm 7oIWQHeimeXrmXLe7rAWg1Bv7zKMmvdyzkfKw8lKtNG2AHyArKxEN5YIvFQ4KgEe9wqA O7nF86CTESy6KrZK3rUdMnS/qdMvLZKrJImhs1Q/GtwL2CvygNWMAwPjh9AzVYvHOwoa AvIA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=+cshPsuV+p8IWnAz7VC2hUR8PIasPI419EzyAajDQQE=; b=mknuzEXaqvwJfzWFY7BJBDNJllcBcfBoCILOBnC4ePpH+/7ie6q+aFvTuxUJp/Yqq/ Ot6+0R+dHLAIxgiDqZJLUJcTQATGHxWZx3cABnoe+YR45eIcUM7Ez4V58o2dKlcCI/kw GvciFX8NF1eL4KYEeQFrTu7LRNt1isPziCkXT86m6etCJcdTBmstxGZ6GyR3wpNw+hWe EjCQUtKuLZIyujEvcOO+Hh0AojWWfwR9yuGQLKIJG/ZP1vek8ewFvkzYumbq2/7yWLjt kUM/uNMehNMM5JiwG3p6WKKjNcwR5jCbPVb+0vtJviYrdXBAttkn0Wb6q+18mNMuap6n J1yA== X-Gm-Message-State: AGi0PuZk4PJ3jsxQu99bNHE+hBoTM9xWhHnUcAZX26bRXPMrWoNGAWxo xRF5COZIHAJ2sEhtujQkPFBlv3gAP58= X-Google-Smtp-Source: APiQypKUaK6m68AfwdJGTHp2tkQjoZ+Jd58PLCxSSes/kO6DaxxU1osQdDWF8je6BdRnKZV7I656gw== X-Received: by 2002:a1c:1f8e:: with SMTP id f136mr175199wmf.166.1586195335715; Mon, 06 Apr 2020 10:48:55 -0700 (PDT) Received: from x1w.redhat.com (116.red-83-42-57.dynamicip.rima-tde.net. [83.42.57.116]) by smtp.gmail.com with ESMTPSA id a67sm364880wmc.30.2020.04.06.10.48.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Apr 2020 10:48:55 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org, Markus Armbruster Subject: [PATCH-for-5.1 v2 48/54] scripts/coccinelle: Use &error_abort in TypeInfo::instance_init() Date: Mon, 6 Apr 2020 19:47:37 +0200 Message-Id: <20200406174743.16956-49-f4bug@amsat.org> X-Mailer: git-send-email 2.21.1 In-Reply-To: <20200406174743.16956-1-f4bug@amsat.org> References: <20200406174743.16956-1-f4bug@amsat.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::32e X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Vladimir Sementsov-Ogievskiy , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" The instance_init() calls are not suppose to fail. Add a Coccinelle script to use &error_abort instead of ignoring errors by using a NULL Error*. Signed-off-by: Philippe Mathieu-Daudé --- .../use-error_abort-in-instance_init.cocci | 52 +++++++++++++++++++ MAINTAINERS | 1 + 2 files changed, 53 insertions(+) create mode 100644 scripts/coccinelle/use-error_abort-in-instance_init.cocci diff --git a/scripts/coccinelle/use-error_abort-in-instance_init.cocci b/scripts/coccinelle/use-error_abort-in-instance_init.cocci new file mode 100644 index 0000000000..8302d74a0c --- /dev/null +++ b/scripts/coccinelle/use-error_abort-in-instance_init.cocci @@ -0,0 +1,52 @@ +// Use &error_abort in TypeInfo::instance_init() +// +// Copyright: (C) 2020 Philippe Mathieu-Daudé +// This work is licensed under the terms of the GNU GPLv2 or later. +// +// spatch \ +// --macro-file scripts/cocci-macro-file.h --include-headers \ +// --sp-file scripts/coccinelle/use-error_abort-in-instance_init.cocci \ +// --keep-comments --in-place +// +// Inspired by https://www.mail-archive.com/qemu-devel@nongnu.org/msg692500.html +// and https://www.mail-archive.com/qemu-devel@nongnu.org/msg693637.html + + +@ has_qapi_error @ +@@ + #include "qapi/error.h" + + +@ match_instance_init @ +TypeInfo info; +identifier instance_initfn; +@@ + info.instance_init = instance_initfn; + + +@ use_error_abort @ +identifier match_instance_init.instance_initfn; +identifier func_with_error; +expression parentobj, propname, childobj, size, type, errp; +position pos; +@@ +void instance_initfn(...) +{ + <+... +( + object_initialize_child(parentobj, propname, + childobj, size, type, + errp, NULL); +| + func_with_error@pos(..., +- NULL); ++ &error_abort); +) + ...+> +} + + +@script:python depends on use_error_abort && !has_qapi_error@ +p << use_error_abort.pos; +@@ +print('[[manual edit required, %s misses #include "qapi/error.h"]]' % p[0].file) diff --git a/MAINTAINERS b/MAINTAINERS index 14de2a31dc..ae71a0a4b0 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -2059,6 +2059,7 @@ F: scripts/coccinelle/error-use-after-free.cocci F: scripts/coccinelle/error_propagate_null.cocci F: scripts/coccinelle/remove_local_err.cocci F: scripts/coccinelle/simplify-init-realize-error_propagate.cocci +F: scripts/coccinelle/use-error_abort-in-instance_init.cocci F: scripts/coccinelle/use-error_fatal.cocci F: scripts/coccinelle/use-error_propagate-in-realize.cocci