From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from shelob.surriel.com (shelob.surriel.com [96.67.55.147]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 181B9CD1284 for ; Sun, 31 Mar 2024 05:55:05 +0000 (UTC) Received: from localhost ([::1] helo=shelob.surriel.com) by shelob.surriel.com with esmtp (Exim 4.97.1) (envelope-from ) id 1rqo8H-000000007HB-3uiL; Sun, 31 Mar 2024 01:53:29 -0400 Received: from mail-qv1-xf34.google.com ([2607:f8b0:4864:20::f34]) by shelob.surriel.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.97.1) (envelope-from ) id 1rqo8C-000000007GH-1CHp for kernelnewbies@kernelnewbies.org; Sun, 31 Mar 2024 01:53:27 -0400 Received: by mail-qv1-xf34.google.com with SMTP id 6a1803df08f44-696609f5cf2so20054646d6.3 for ; Sat, 30 Mar 2024 22:53:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vt-edu.20230601.gappssmtp.com; s=20230601; t=1711864377; x=1712469177; darn=kernelnewbies.org; h=message-id:date:content-transfer-encoding:mime-version:references :in-reply-to:subject:cc:to:from:sender:from:to:cc:subject:date :message-id:reply-to; bh=NW3u3tm6x9eNCMOAPAzUuB2Yct8dtJMrASwYdHhPYIo=; b=yXLwz2RUNc+CPkiP7Zt/96eSfOEhRt0nGaJKaYCUYW5HTtjmNR8lHkZVXO5oKEaaRY ouaFKMMmAyCvDTA7eCAi9r1klxSHUrG1sgEp5Le4TeRxtYXFVYVY4fC79llGWm5Y6DDt 0iG5iLEU2I1UHXwf867XwoHOzAfS5o11IB29GXQK6P7/+NmJWwmpUd4OZ6RCtIYxzkHf rzR84kiTXqGmxdjyxLZQ1AgAG9jX0bfzMPBxAVMPMo/v86LYlqjiFkC1XSTVIRPy4+JH tVfz7xJhtMSk3/39CxwxNyJk4HdHXIfRspjNm6KqUvbkeWhllipCFS1AvKbsJ8N3TbJD gBsw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711864377; x=1712469177; h=message-id:date:content-transfer-encoding:mime-version:references :in-reply-to:subject:cc:to:from:sender:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=NW3u3tm6x9eNCMOAPAzUuB2Yct8dtJMrASwYdHhPYIo=; b=uwdR7cly29ky9PdrAg92MIucR7qR8ShXcYRXHY/A75FojvXCRb1YhGqYVFt36ZoYWd Vn7bwETu9QhjNaip1Z7Ig6W5UkiUbD1nYykUy/M2F3uJ3Jl1wyLFrZS25K81S++Jfkna SSi0ppxZYh1sMpphLL7gyFPV08Ol3y8aTdM2iXjN8/1i/A0Ahs8Z00iQx4Xh6laFnsGK oyj7J1XfG0wINEsDACrl2GXXgcRHlSxaqianEr7z0+4SJXJBH8RZnPXHdTG9ckmNgwD5 JrGAZqiQy90Yvdoie7RkkJuQ4gtQQXZDidbm0hikqjA/oWx8SFd6ve8TJquoJ4PKcNZv zr9A== X-Gm-Message-State: AOJu0YyfoAFeyIX4bKnouv4Wh2eCKG/FrOWy4zArqCVIgpWjlh8+/f7I 8cMQOlhbJyLkt2Z64f6WAViIIr9C76MT3vpqwYjkzzoIDEQXTXN3JhrBSk/J1uQ= X-Google-Smtp-Source: AGHT+IHO/YptOTe8wXkcNQlZ91deSFPDlVqPruXvxovIUC56cnVj9JpKgidxKzZz4amz3RR+SlwGww== X-Received: by 2002:ad4:590b:0:b0:698:fd7b:3868 with SMTP id ez11-20020ad4590b000000b00698fd7b3868mr2674503qvb.52.1711864376763; Sat, 30 Mar 2024 22:52:56 -0700 (PDT) Received: from turing-police (c-73-31-28-59.hsd1.va.comcast.net. [73.31.28.59]) by smtp.gmail.com with ESMTPSA id qq2-20020a0562142c0200b0069687cdaba3sm3285209qvb.36.2024.03.30.22.52.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 Mar 2024 22:52:55 -0700 (PDT) From: "Valdis Kl=?utf-8?Q?=c4=93?=tnieks" X-Google-Original-From: "Valdis Kl=?utf-8?Q?=c4=93?=tnieks" X-Mailer: exmh version 2.10.0-pre 07/05/2021 with nmh-1.8+dev To: Camila Alvarez Inostroza Subject: Re: Coding style when using atomic_dec_and_test In-Reply-To: <6b587fa4-4069-419f-bae7-b53aeb86a955@macbook-pro-de-camila.local> References: <6b587fa4-4069-419f-bae7-b53aeb86a955@macbook-pro-de-camila.local> Mime-Version: 1.0 Date: Sun, 31 Mar 2024 01:52:54 -0400 Message-ID: <33205.1711864374@turing-police> Cc: kernelnewbies@kernelnewbies.org X-BeenThere: kernelnewbies@kernelnewbies.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Learn about the Linux kernel List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: multipart/mixed; boundary="===============2473269045932505114==" Errors-To: kernelnewbies-bounces@kernelnewbies.org --===============2473269045932505114== Content-Type: multipart/signed; boundary="==_Exmh_1711864374_2500P"; micalg=pgp-sha256; protocol="application/pgp-signature" Content-Transfer-Encoding: 7bit --==_Exmh_1711864374_2500P Content-Type: text/plain; charset=us-ascii On Sat, 30 Mar 2024 21:52:29 -0300, Camila Alvarez Inostroza said: > I've seen two ways of handling the resulting operation, below are a couple > of examples: > (1) if (!atomic_dec_and_test(&rd->refcount)) > return; > call_rcu(&rd->rcu, free_rootdomain); > > (2) if (atomic64_dec_and_test(&map->refcnt)) { > /* bpf_map_free_id() must be called first */ > ... > } > > Is it prefered to use one option over the other? Or is it just personal > preference? Yes. :) Basically, it will depend on what the code logic structure is like. If the logical way to do it is "if it fails, return now", then you do (1). If the logical structure is "if it succeeds, do this before continuing", you do (2). In other cases, you may want to do the "structured goto" the kernel uses to unwind allocations and locks that happened before the failure. The above is not an exhaustive list. --==_Exmh_1711864374_2500P Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Comment: Exmh version 2.9.0 11/07/2018 iQEcBAEBCAAGBQJmCPo2AAoJEI0DS38y7CIclwAIAI56+V+ygMv7bo5utvjNEfUK IrX/+HVZ9rMw+vyrfx+woAOi6UQa36P5/aahOasAkDyrCcvvQs+tQ+VBPmEiHwvY sIQzPcTT10cbNHsw65k0Z+JaBveKWcSG3cbl7yGOanqHtXIZr9xin9MPaTLxEMnd rOQP4XYMOBKMA3Z8AyOSVPXzl2XHsoDroOjB8aDlwFDV8ir2AZt3aIfKbdUdqolH LWHueMLroBouaNvbpvKCE12nSK1L0Z7z0Jr2giETgL+7VqkOzjkYLRog2mGu5AVD oq8To/+Q34E26fCRoFGUUGhFfiE55RnLHm5dqFG9ZTMp+xsmpzFnJmg9k1lgC98= =Brig -----END PGP SIGNATURE----- --==_Exmh_1711864374_2500P-- --===============2473269045932505114== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies --===============2473269045932505114==--