From nobody Sun Feb 8 08:03:30 2026 Received: from mail-pl1-f181.google.com (mail-pl1-f181.google.com [209.85.214.181]) (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 DE8C22D7DFE for ; Tue, 2 Dec 2025 17:56:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764698171; cv=none; b=K38rGbmqakXpi1ZuoCQsAeSuexTJC651FByBx+N2/K6QTK1O0detUgYCx5VPIjTCljXYpz/XlGweOW33PZRelgQubFq7lCSrH2Tib3PfJELBD8nVKqFcO93olDQGbw2JpYerIBupv6pdoz/VisPA1MpaZqITVN7cTLBCF8Nkg9I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764698171; c=relaxed/simple; bh=Sm1TJsLugjHHVTBU9eOX+J0ZzXKdlMhbFNRgtkZfXK4=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=Hu02E7dvaOnrlSJ+E1sBi+AkvaVjHX398mocsnoHvP0HagTKbLh+ZcvCtIEc4nfGGqof1twJ1cQFZSG4GSfvka26XqRpffVpj2BJ+mF/mILxyjv7qbuHWlggN1Jgxp/brXFvILnAk48+KgODFkg7e2RVOmOjrM1b/GMSMQYxKUM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=HplFKdsN; arc=none smtp.client-ip=209.85.214.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="HplFKdsN" Received: by mail-pl1-f181.google.com with SMTP id d9443c01a7336-297e982506fso74094735ad.2 for ; Tue, 02 Dec 2025 09:56:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1764698169; x=1765302969; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=qsBL4a1ShlWZYhLRPfFIvAo1My/w18YNcBjeFswWfCo=; b=HplFKdsN2uMxTbX/6vvtljMLf8ytTszkH2h1N67vGJWwsdkjjq3OdiEss8eBTyOtNF 5uk9oYcIRPoyEqZLBdYEMHuB0s8pC8hwiRYAPhvarR7WwBa8R+uDDhnlpmBZOl5HQMPi PqJkoKT4EmWp7BknI8+rMWy5IOD8pWzvoyBaMmxC/TVNFN82EUr4ylOTSUxVuQsshDCD HGF0ijN11akFpY4AewLn3756PAqxuiNnKyQNLZqZhBhpLtmPvbayNZ1VaqTzIFgqQ3s4 XU3CB+fy9RcshZQS376fV/ZZbWBOvd5IpP72zGkCg/Zk3YKFrODG+cMo6fqByKhd3qCM c/sw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764698169; x=1765302969; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=qsBL4a1ShlWZYhLRPfFIvAo1My/w18YNcBjeFswWfCo=; b=k/O6Loeo2ZRxtS84fgPYo+QU1ZEYqEeykNZcxqYfNyv/KhVUtXdHGxLVHbVah6kVWT 24q4KfSUeuscV14+kwltxpoN4K5hiPla79qoOuwuYTQXKtAQRqdg9+Cd7vB9NEodLmy8 rV2TjeZHzSNWocRtO9ewFsNl8thqokH1qf6zJp8gzyI9Fz/YuFE3sj0beymAHYNR9m1v bOBQFLSrqY5nNTEGCkL8J6afAL7jwZxzC2TONt1IIoyacQiT75qoC7ShBsJVNSHuMAn4 zCpWMUp5/i26jHsJhMKwORugCcIiGVQMAD7E1+qW1Lahc4T+A+kCpmPr4I2IsfJIud+0 6EzA== X-Forwarded-Encrypted: i=1; AJvYcCU1B0qr+wawFm6i6L0PuXYpPVRp7bRSAB61PPxUTvN+MsERHJghAW99iDR0a6tQil8OJ19W6XgkBfmqSL4=@vger.kernel.org X-Gm-Message-State: AOJu0YwWBMEoaLXc7QiCytZFJSSRzupcEyL9RrgQOfxSfvTrSZ0warWb Gn2v+P2ZNgSoL7jQ7V/ItZ1J6/Eu77AIL+6rHRnV9qBd4TZa55zVRk53 X-Gm-Gg: ASbGncsCDlk+PeutXaNsRb8uzz8TiIRs2zBlG9BausAX7nzDlsnOjpnJ4UdSq80qqzl FU/aULMjBOxdMhbNXb8UhP2Hjo7NYB9NP69hz7IHh2ywge+nagjR/4A9ZFKgHrfTKMY9/AUF1+J 2535eX2v6GZ1MRPdmxvHOPCEsnvMd5uFvGtE5HeCuuNJpfnLqpgOSvbkMSby5vggx70UksIp++m q0IFkwDfXsbSpssc91/FnSuFFJf4XkFGQdj0vQoeVk0UXRCJ1xtuKbtRYvyAUmc8q8d+UJRwZ0C fGM+HoxAcORwkpvkWejd0dpMeYxxF9m3m0TsTlTy2p4ll6jLIV1ZGoLujv3wEHOJ56JpAHEhd8+ +g0PaoAI2dWTsTyunzF3wQFMZLJyffLz+AjMoYUIBf9oVbboB6x8xmsbsQyfs+uKjXOA2JKPN1M NM1tJ6iUWcrf2E7Bb9yFKqhGBn9x/9fsSVRl1ev9BQuP1mHI7dPeURqxGeXwbl3R633WRi5IVrN 09BUtD8emhbYW2KQNbjwEZfvlDMJVsiq5/O192cO/mvWi2p2iCS3DyC9Fn1 X-Google-Smtp-Source: AGHT+IFwDDfVSopHbo6xulB0WM1KDJud7F9TNEtVOs+678Ns8drjaPWu6pYY6Ju3zwj7SzEVh91fXA== X-Received: by 2002:a17:903:1aaf:b0:296:4d61:6cdb with SMTP id d9443c01a7336-29b6bee38f7mr520296995ad.27.1764698169114; Tue, 02 Dec 2025 09:56:09 -0800 (PST) Received: from 2045D.localdomain (191.sub-75-229-198.myvzw.com. [75.229.198.191]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-29bce40ab42sm159623585ad.5.2025.12.02.09.56.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Dec 2025 09:56:08 -0800 (PST) From: Gui-Dong Han To: linux@roeck-us.net Cc: linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org, baijiaju1990@gmail.com, Gui-Dong Han Subject: [PATCH] hwmon: submitting-patches: Explain race conditions caused by calculations in macros Date: Wed, 3 Dec 2025 01:55:36 +0800 Message-ID: <20251202175536.12774-1-hanguidong02@gmail.com> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The current documentation advises against calculations in macros primarily to avoid code obfuscation. It misses the risk of concurrency issues. Add a note explaining that macros evaluating arguments multiple times can lead to race conditions when accessing shared data. Link: https://lore.kernel.org/all/CALbr=3DLYJ_ehtp53HXEVkSpYoub+XYSTU8Rg=3D= o1xxMJ8=3D5z8B-g@mail.gmail.com/ Signed-off-by: Gui-Dong Han --- Documentation/hwmon/submitting-patches.rst | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Documentation/hwmon/submitting-patches.rst b/Documentation/hwm= on/submitting-patches.rst index 6482c4f137dc..7f7095951750 100644 --- a/Documentation/hwmon/submitting-patches.rst +++ b/Documentation/hwmon/submitting-patches.rst @@ -82,7 +82,10 @@ increase the chances of your change being accepted. * Avoid calculations in macros and macro-generated functions. While such m= acros may save a line or so in the source, it obfuscates the code and makes co= de review more difficult. It may also result in code which is more complica= ted - than necessary. Use inline functions or just regular functions instead. + than necessary. Such macros may also evaluate their arguments multiple t= imes. + This leads to Time-of-Check to Time-of-Use (TOCTOU) race conditions when + accessing shared data without locking, for example when calculating valu= es in + sysfs show functions. Use inline functions or just regular functions ins= tead. =20 * Limit the number of kernel log messages. In general, your driver should = not generate an error message just because a runtime operation failed. Report --=20 2.43.0