Received: by 2002:ab2:7a09:0:b0:1f8:46dc:890e with SMTP id k9csp198420lqo; Wed, 15 May 2024 11:33:18 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCX3kQMfwjU4I+DN1Z5vPYsuITFuRSNbtqU9JjXokqzghhv4YzruQL+Tx9vhqY/747rlO5uvwKbBsBSOBX+nBY37O6t889gtH/L02hFuIw== X-Google-Smtp-Source: AGHT+IGVcPkReIxVr8/v2AkchQtoYQHgy+q/C2ZWIakkqo7MiXDXjyV0VpqIA6DKQv0GaKdrCouu X-Received: by 2002:a17:906:db0a:b0:a5a:50e4:5738 with SMTP id a640c23a62f3a-a5a50e4586fmr1059160266b.73.1715797998594; Wed, 15 May 2024 11:33:18 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715797998; cv=pass; d=google.com; s=arc-20160816; b=hgeKjuJ78fOhzQapZ6daIqTX04RR5Wdnm/AJP/KVqAU/Ulc/nuBn2uGsM8xgSkr4Hn USlqWnm65RFzrdFSoRbPQFt7N1rwDDnIsTfipqEkihbJTHAvcXdM4cw09ZHoLs//F1pa ua0W28YTttJnUa2EQ7/dMF+3qLsxljPpFJnDMFBchNpnfqLR+1EuymYjh9aFPehItofY 5vUvjEthlD+U7DlfiYJKVgwup81xEM8HGctrBJBvX66OABgOBtJ/e4AfFkSHbODOG4xT hkMNbJ0PQKKH51zRpekWDauTJdLWmuxM1LzWTLqJY9cp+bwUpweNV9KdyHRr/ccFVANx QX1g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=KKkDnLN7qusp5ZEvAbHRefNjI/EUrE6vZKOBSo4hBmc=; fh=uyQbL+Lkd1IYBAnYg5CRH3XFJ6xa9dtiwTk9NHun5Lo=; b=cTcz68a1KkBip6qRzth2po+2cOKn6dW6uwFgnzZomXcA8V1KlRuhbyEETo4YNwmPWN z3mU7GJeg7PTtTHgilm6pyWUEl1SHodh96gmRB0s9r42Dfj+s3ClOkR5MY2eamSFqhDG bnXghk/TcnP7zrJkW53c5gJEUCvBfPrPL6kxhp1N2ba7IjNBZKUejNKHu9mx0py1FElw si3JIlRpgxsKKJnaN/MuOwLdodWqmTNbKO+P9LuT0fw3sJ7mPigwNrCqPGNe+BsEGwKb B+DmmNW9jFQpq9LitnNyGbka4I9PLMLOrqisZv/n46wVmzj/Ue+8HPGBeqgIeVq7ojXa hAjA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=HWVyaIS0; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-180265-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-180265-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id a640c23a62f3a-a5a17c2b6f9si798132766b.910.2024.05.15.11.33.18 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 May 2024 11:33:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-180265-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=HWVyaIS0; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-180265-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-180265-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 4D9691F22EDB for ; Wed, 15 May 2024 18:33:18 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id AC1F2158DD0; Wed, 15 May 2024 18:33:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="HWVyaIS0" Received: from mail-ed1-f46.google.com (mail-ed1-f46.google.com [209.85.208.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4D42E3C466 for ; Wed, 15 May 2024 18:33:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.46 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715797991; cv=none; b=Uyy1geTDx7iCmyDEW/XFqJEBvsFNiTTUHgAVqRS+uKFqNAXJIMe+OT4ZHZ18g60Q+oPwC14RQ3IXmwUGhzYNwscl2at4LyINCYWQEDnc4apS+fLz5qit5fC2vUAZINDUYFDLgOCwSOOm5ZJR+Mk5cB3xkTOm/fAyOoqKW2VJ1ZU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715797991; c=relaxed/simple; bh=yw+ipdvPqTKvzHRePFMCEGB32d2gTHY4yIizWZv9K1I=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=CFP377RMy8OR9XQkAFiMI/JLMZKtE8Z/3QY0KlSOCVBveHiidJdyBZgXKt2t+Wms19/EbySHrEvZoSeDT9meHLYYo6/7VPhwydlVkVKb+O2L2o3DSnZs8K5goRBTjKsxA//ZxYDigVZIRUmSjMbvFMjEdtKoQ8sZsGcU9WVuMik= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=HWVyaIS0; arc=none smtp.client-ip=209.85.208.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=google.com Received: by mail-ed1-f46.google.com with SMTP id 4fb4d7f45d1cf-572aad902baso36361a12.0 for ; Wed, 15 May 2024 11:33:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1715797988; x=1716402788; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=KKkDnLN7qusp5ZEvAbHRefNjI/EUrE6vZKOBSo4hBmc=; b=HWVyaIS0npQb1JpKRAJZztkST62euTKgxU7HH4B6I6s6UY/JYNOS2+GnzcMboRQuVg Fxe0U5VxQAL0Ls3kn4GeWlqSHkrhcbxxrWdlpCEa0vZMqL3b1dI2pIQ6g2n0sz3sgNPE JwcBZdn1f1bOMgbU+PaS3KTeYNOQD8os0uq/t+xk/OoCKm7pkDtBetoRpM46sq3dyR6q bNpCf1RiuFA/Ilr8CBHZ11X8ClH5V6GLBY1V8GlsgcOUfyj8ABab5tXExe6IH6X3M6/U twwvmxwnswpF3uucX+dFrHAMNi+3HPoHsJxTkuGT3E9juJneaEWM0SR4txt686dpHO2Z 1hHw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715797988; x=1716402788; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=KKkDnLN7qusp5ZEvAbHRefNjI/EUrE6vZKOBSo4hBmc=; b=Mbh65NCZoKEe2UiEme1UDRBUdG5SCed6WX6WihNKf93oxzI+ATeoTo7AzZ+P9GEU8X ZJpZ641pxSvBOiI+WKmZzGL0sdsP7wtBYYzp/YY8wk7v7p5qpR1+GdM9mAiGl6PouDH0 5GlUoR30y6cNuA/BhOY0DmhzJdcnaLRaQrs3fEh7JLOL4q8SRt+sx8m2z+K1iByC/rHS M4zhtMqI2OpDauCbmn3phRMuovBwy0vT7plICosVdKSsaJZ3pqL/1EnYVQjoOo7kMMFz +RtbWySahxV6BGKaz3ww4/jger7zZ0c2l7R2SHMx+b363yul26xTJ52LOreFqQ+opUpt v/8g== X-Forwarded-Encrypted: i=1; AJvYcCUqn3xkvLx7Ku4oyoWwL8BhkcQSozbMCQN2MZETGOG7iFWLxl4giIoeN7uzQ2+W0AvzOYFUjb2U5T0q1bZiEXL+HN+aGaW9fkztkU/j X-Gm-Message-State: AOJu0YzeMP+P0c0qfuyZdf5T7wN1kG8Ffv74RWCCb+NZeTj8me4HmcOc 2gS8cuarHFzm5Yj+3rSo1rBN20P4a6j737CZvNvcpoPTfhXW5y6mDgmHkA+HuNccA5DnnG14iAI P7TmeortDiqjnZtBsRtyUnp5cG4HRxPJW7/Q= X-Received: by 2002:a50:85c6:0:b0:573:438c:7789 with SMTP id 4fb4d7f45d1cf-574ae418342mr914673a12.1.1715797987465; Wed, 15 May 2024 11:33:07 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240515010805.605511-1-xandfury@gmail.com> <20240515010805.605511-4-xandfury@gmail.com> In-Reply-To: <20240515010805.605511-4-xandfury@gmail.com> From: Bill Wendling Date: Wed, 15 May 2024 11:32:48 -0700 Message-ID: Subject: Re: [RFC PATCH 3/4] selftests/binderfs: Macro argument 'fd' may be better as '(fd)' to avoid precedence issues To: Abhinav Saxena Cc: linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, llvm@lists.linux.dev, Shuah Khan , Nathan Chancellor , Nick Desaulniers , Justin Stitt Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Tue, May 14, 2024 at 6:08=E2=80=AFPM Abhinav Saxena = wrote: > > Change the macro argument 'fd' to '(fd)' to avoid potential precedence > issues. Without parentheses, the macro expansion could lead to > unexpected behavior when used with an expression having different > precedence levels. > > Example Code: > > #define CALC_SQR_BAD(x) (x*x) > #define CALC_SQR_GOOD(x) ((x)*(x)) > > CALC_SQR_BAD(2+3) expands to 2+(3*3)+2, giving 11 as the incorrect > answer. Enclosing with parathesis CALC_SQR_GOOD(2+3) sets the correct s/parathesis/parentheses/ > order of precedence and expands to (2+3)*(2+3), giving 25 as the > correct answer. > > Signed-off-by: Abhinav Saxena > --- > .../testing/selftests/filesystems/binderfs/binderfs_test.c | 6 +++--- > 1 file changed, 3 insertions(+), 3 deletions(-) > > diff --git a/tools/testing/selftests/filesystems/binderfs/binderfs_test.c= b/tools/testing/selftests/filesystems/binderfs/binderfs_test.c > index 4a149e3d4ba4..d5dba6c1e07f 100644 > --- a/tools/testing/selftests/filesystems/binderfs/binderfs_test.c > +++ b/tools/testing/selftests/filesystems/binderfs/binderfs_test.c > @@ -30,11 +30,11 @@ > > #define close_prot_errno_disarm(fd) \ > do { \ > - if (fd >=3D 0) { \ > + if ((fd) >=3D 0) { \ > int _e_ =3D errno; \ > - close(fd); \ > + close((fd)); \ > errno =3D _e_; \ > - fd =3D -EBADF; \ > + (fd) =3D -EBADF; \ While I agree that it's generally good to add parentheses in macros, this line ensures that 'fd' must be an lvalue and not an arithmetic expression. -bw > } \ > } while (false) > > -- > 2.34.1 >