From patchwork Thu Apr 20 15:57:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 675641 Delivered-To: patch@linaro.org Received: by 2002:a5d:4a41:0:0:0:0:0 with SMTP id v1csp395069wrs; Thu, 20 Apr 2023 08:59:32 -0700 (PDT) X-Google-Smtp-Source: AKy350bBrxoLcenli+NJsqtGyGMLTjHyZC64XyqWTMsX9b+4/LGm7RNlLVaIrgRz7nbTzOK+akec X-Received: by 2002:ad4:5d49:0:b0:5e9:2d8c:99e0 with SMTP id jk9-20020ad45d49000000b005e92d8c99e0mr2635594qvb.22.1682006372111; Thu, 20 Apr 2023 08:59:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682006372; cv=none; d=google.com; s=arc-20160816; b=jUWyeyWIM5Crtmh98WQhzTG8QwwOV1X+PSjsmLGN6AEzx32DzqeLH3DVHxOBj8ZA3Y bejq+PNjFaZHmlXbSa1iMzlHw+gbwEGQIo08SwXMJgupG0xDvxexBii6oaMwyeMoUjFI d/hKEeBM5PUYsHm9OI+Fh67yXiT84tfQf/LvAjv6kNsFT9B703Elh8Xo9Qy8bJ60WMVK 0ngiHiQZxkvIYOW58Z+LCicvIRpJtuBlf05EA/GmlN4/nZiwT+wWGyZadNWkGwDr3XTI BhUhkLSZlS5FKx1iQ0XzVpmaaKewz0+1V3z/puUHXHvOrUFPNGe0y0HQlXzz6IqOaUHr PHMQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=iXPQOZPEUZEREA0kEgOAFX8HZGCmldGugGG6ngHb1YM=; b=S4D09P0P1CsOjJNLqK130L8zcZopAAdo5KkuG4RoS5kfqlUiEukd8Av9UHG+F1LwKP BgAeZ4iLf7TfReT8dQQdAJFGBTqSm6MiBWpfliu25jmuOVV7Q0YdrYDS6/CGZQ6jpp6a orSc0WvNiodnTollRabQS1HFaeSPyHxFoPpwaKVUo4FdWOMJD9lfIzWhCate6NQ5FvJn bem0h9soYlWkePe4ksSyUlVZpfiZGFqHQ/i3sltVEdIKEaWbdSEjVBnFvHFxuTDWdQ6A ADVCwkORYS59SPmhQ+jKJp7xlOC2BGnszupYnCcZnYf0dBEY83isYqTV259ofyCukyml 0ggA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=H2Rmtedt; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id s9-20020a05622a178900b003ef30f52155si1599689qtk.312.2023.04.20.08.59.31 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 20 Apr 2023 08:59:32 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=H2Rmtedt; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ppWfA-0000E5-BF; Thu, 20 Apr 2023 11:57:36 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ppWf6-0000Bw-Sq for qemu-devel@nongnu.org; Thu, 20 Apr 2023 11:57:32 -0400 Received: from mail-wr1-x434.google.com ([2a00:1450:4864:20::434]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ppWf4-0007vG-Kg for qemu-devel@nongnu.org; Thu, 20 Apr 2023 11:57:32 -0400 Received: by mail-wr1-x434.google.com with SMTP id ffacd0b85a97d-3023a56048bso375204f8f.3 for ; Thu, 20 Apr 2023 08:57:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1682006249; x=1684598249; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=iXPQOZPEUZEREA0kEgOAFX8HZGCmldGugGG6ngHb1YM=; b=H2RmtedtHKryhRg+/vuUtN4soB/0wIE2YXEtxi24tXAJLBEScZikGhtSLQUFkwumEW svf3n1/uX7b9+Kh97ldiPoURwzWV6xMRW6JiqzEkGUTr0SokN9bbQN5r1rkwPhnUGyPY kwA8mqj5apCsmmoNOlZcNh7si62J4O+i2i7yNl5JM4/qJ3aMS9ToU2f1XvyLVhU1gtnF b2oGHoZDAWs9WsSypgcsUfnRzhgZk67t7RYViNTK+2CZ5Ruq1+PfYX7qA38Kda9j0lWl SUWY1LI9O3mPgt9MO4SB0vz+V/vVQCuGVmMaNQJiwfrX2EQScTTT7+UNGHe0Qj4K7rqE SrlQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682006249; x=1684598249; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=iXPQOZPEUZEREA0kEgOAFX8HZGCmldGugGG6ngHb1YM=; b=dHyjLnRedM4SNfDQCApMkVjBA8gZPRsjj+BdaEodXg2qRzX7g1n2hgD43B8SIlpeIZ yv3YftrhVtJge4/p2SBThWBzCkdJ70u2lz9cOK76wxBv9zcrsloRNbYzZOvO+Yu/f03j vd1wW4Yv7vjtmx5W6dVp86tnIuXR4ZdBKLxRwx63w+o3qDqo0iWw+VkTyt2xATSZe4y0 QFDvvuVXdTATVL5RhtdQ4CnBjt3HAy1Mx1PtVLK7MeN4Vf5NGSePXqU0lDUIvTLvhQpb K999M2AICRZp/TKpNPsx7h9aTwu9uDu/GqecIPMHX4WdmNo7fvI8EZr323oHp6UzH6WR ROqQ== X-Gm-Message-State: AAQBX9d+AfBOg7KFvK5xakE5M0+06BdL78CCuXYgdoqIBAP1ztdmYjH/ UQHhc/5GwRoBJU6aiwZs2UYZDQ== X-Received: by 2002:a5d:5304:0:b0:2f8:67ee:5ca9 with SMTP id e4-20020a5d5304000000b002f867ee5ca9mr1770490wrv.65.1682006248873; Thu, 20 Apr 2023 08:57:28 -0700 (PDT) Received: from zen.linaroharston ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id m7-20020a5d4a07000000b002c55521903bsm2276042wrq.51.2023.04.20.08.57.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Apr 2023 08:57:27 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 6D2E11FFC1; Thu, 20 Apr 2023 16:57:24 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Elena Ufimtseva , =?utf-8?q?Alex_Benn=C3=A9e?= , =?utf-8?q?Daniel_P?= =?utf-8?q?=2E_Berrang=C3=A9?= , peter.maydell@linaro.org, =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Paolo Bonzini , Thomas Huth , Markus Armbruster , Alexandre Iooss , John G Johnson , Jagannathan Raman , Juan Quintela , Eduardo Habkost , Richard Henderson , Mahmoud Mandour Subject: [PATCH 9/9] docs/style: call out the use of GUARD macros Date: Thu, 20 Apr 2023 16:57:23 +0100 Message-Id: <20230420155723.1711048-10-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230420155723.1711048-1-alex.bennee@linaro.org> References: <20230420155723.1711048-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::434; envelope-from=alex.bennee@linaro.org; helo=mail-wr1-x434.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org There use makes our code safer so we should mention them. Signed-off-by: Alex Bennée Reviewed-by: Juan Quintela Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Vladimir Sementsov-Ogievskiy --- docs/devel/style.rst | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/docs/devel/style.rst b/docs/devel/style.rst index 0bd01f3fca..b50a981a86 100644 --- a/docs/devel/style.rst +++ b/docs/devel/style.rst @@ -657,6 +657,42 @@ that declaration and the new code. See :ref:`qom` for more details. +QEMU GUARD macros +================= + +QEMU provides a number of ``_GUARD`` macros intended to make the +handling of multiple exit paths easier. For example using +``QEMU_LOCK_GUARD`` to take a lock will ensure the lock is released on +exit from the function. + +.. code-block:: c + + static int my_critical_function(SomeState *s, void *data) + { + QEMU_LOCK_GUARD(&s->lock); + do_thing1(data); + if (check_state2(data)) { + return -1; + } + do_thing3(data); + return 0; + } + +will ensure s->lock is released however the function is exited. There +are often ``WITH_`` forms of macros which more easily wrap around a +block inside a function. + +.. code-block:: c + + WITH_RCU_READ_LOCK_GUARD() { + QTAILQ_FOREACH_RCU(kid, &bus->children, sibling) { + err = do_the_thing(kid->child); + if (err < 0) { + return err; + } + } + } + Error handling and reporting ============================