From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f177.google.com (mail-pf1-f177.google.com [209.85.210.177]) (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 556C62D2398 for ; Fri, 21 Nov 2025 15:50:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.177 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763740235; cv=none; b=SI54P41uhhOfFITr8Fwi1dS/CNuAT4WZW5YrlWHZFJ7iAfhGyabmOuUoiSrcALdyk7m5Sp70xMrYhm1KyJDNYTVG4zJPUfrZDkFqWnVhjsxpWGqO1+w3NsLZoBwnyciRR6u2vjML31zsy7agLyo+aW48z3kc4yYaUQkRzhKabk8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763740235; c=relaxed/simple; bh=4i3X/OCJXTmh+1M2IfDmIZ75Sl7aUvTCnxuEmAjeoG0=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=a3DMb/s1P6WQRJ0YWIja4fIgkpPlURmK5ar22gjM1FhKZnn/iZc6kcEq3A0ClYgAS9LexfL++AmnnIe+niH8hY3TuoThSxUlDSW8Zq2jkwOGFt0UpAhQqQP5VTRbqo1kicv5zSwQf5zGa1ubzQG46rXsnbpUPGQXVw9IluckjYA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=roeck-us.net; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=jkqbww40; arc=none smtp.client-ip=209.85.210.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=roeck-us.net 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="jkqbww40" Received: by mail-pf1-f177.google.com with SMTP id d2e1a72fcca58-7b852bb31d9so2655284b3a.0 for ; Fri, 21 Nov 2025 07:50:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1763740233; x=1764345033; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:sender:from:to:cc:subject:date:message-id :reply-to; bh=lW5lXIt/CZeUQ4dXVL5FmacDKUMrztihLOUWLxEXWaI=; b=jkqbww40aPw1tGsc2U3jR/IFpCxmWzJvIgQilZtmSidXPIqM7IQ7l7DCwh4G2Awvjr wLp4/NYYKqKorydB7lQ95+AdGTClKS1zBXJ7Ssr/Hu7ZfSIgAXNcrnzbVIlI3Kw/4mAR k1yZTlgO+Xl2YEwoMa7qlQ0rX2cbvSq09WdpW+2St2Grbsv4KVD5b06lsPEuIYrRxo5u avv8utY53bYSLH9Uhlsb9b16UXp4htecGw9w8L8IoGllnq6zleZBJar5647+lGo6gHC3 /WMRM4ZpcceJJI+I0XAmUd/TWSdh0ahAEPgZgB4h9WzXLiQ1eHKFH6muZS2DHkNURzHs Kt0A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763740233; x=1764345033; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:sender:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=lW5lXIt/CZeUQ4dXVL5FmacDKUMrztihLOUWLxEXWaI=; b=C21Kp1V8KtWGt+4KF5ODFKotufOYFD1Uh+2YnEaeXJb1l3UmLpwWcm6geffAfOiwxL 2L5KCLOD+PtYJsuk0IanZLgAtWa7EcOY6vbTFS6gTxYhyosxr3J6uESbXs/st4E1Tsv3 ba8rIYTLQqAUAGd1zkNysX7c1sUDbWlBNASDE7+LgeoLTW2ERH+ke0QN2aPZPi/YwhJO KYtocGatsLdTCHqELl2QB42xHUZ5YcGQNTbREeXZCJqiF2ylztgwnBTRCP1wpPno9kRK ijYatAN/G/eqWIolwXcezCDfrru1lBhBeKEVNhR5k6Z/89x+hsrpXsIwau78Qj10pgH4 7E1g== X-Forwarded-Encrypted: i=1; AJvYcCW4nAwpGM8vQ64HvkXn3tw8eKIN68EbHLJwN8dB/ocPxc72/YIeyXCoRlM713CXQ0eBArB9yzkFG9A6hFI=@vger.kernel.org X-Gm-Message-State: AOJu0YyHwHNNvqzoAvZETh8NKFLvi4lLbJ/iKdx1VVCDm8pMTda5tCSA EjwsY0MCEcTwrl/B+XWyyjHSgkiu8HFaoSwBdDinpiy1dj6iTamxhehM X-Gm-Gg: ASbGncvykOy2zYdjdFggOsk+Rb0l5dD93ExpK6cSrG3sBqx3otp+0d4KMe73FKg49Pz s08eWth56EY5Ya6aDCr8k+zT2SFeaYhm+x9jfbuECZk0iHkSaIWqLuJKPlOvQGKQBrQPwJjVul2 zjGemO63YPGyij++Q13kIG7/7uNhZNGtnZbPl3Xp2T7IhVvFxnxrG/e5OnJjstDPoK9a3J4niY4 AvsvPbqZoTEiDjwF37tubf5Tbx94ByhqMBL1JozfRzOS3r/qlhWoJ4WL0O55XtVDiAH73Apx5a5 rD2VBYYHMLiJBJzXMu1o2LvjSoWBT+tRpVsRBAHvnt08r4A06GhzKeDu/l01z/KN1/dWQntkHGH W7izHJsDZGPHbfmhqFMq0kf6ep5guGvTlDflt9o93rbJzd+lDZkkeEX1gVihWRnRxGIHlUNnfVC WI+ve/RLG8Tu8frVn3XHMJ6GE= X-Google-Smtp-Source: AGHT+IFGAVfMguY3irLBdPFgatYV5J/rG2XF23gXi7wkGig+85rnvjmjfKaMXO2h3mkQxAiIveeiGw== X-Received: by 2002:a05:7022:1182:b0:11a:3b88:f756 with SMTP id a92af1059eb24-11c9d7126b6mr514728c88.19.1763740233406; Fri, 21 Nov 2025 07:50:33 -0800 (PST) Received: from server.roeck-us.net ([2600:1700:e321:62f0:da43:aeff:fecc:bfd5]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-11c93cd457dsm26918913c88.0.2025.11.21.07.50.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Nov 2025 07:50:32 -0800 (PST) Sender: Guenter Roeck Date: Fri, 21 Nov 2025 07:50:31 -0800 From: Guenter Roeck To: Gui-Dong Han Cc: juergh@proton.me, linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org, baijiaju1990@gmail.com Subject: Re: [PATCH] hwmon: (vt1211) Convert macros to functions to avoid TOCTOU Message-ID: <9c9b5eb5-ed5f-4b94-a44d-eec829faf22f@roeck-us.net> References: <20251120041331.1917570-1-hanguidong02@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20251120041331.1917570-1-hanguidong02@gmail.com> On Thu, Nov 20, 2025 at 12:13:31PM +0800, Gui-Dong Han wrote: > The macros IN_FROM_REG, TEMP_FROM_REG, and RPM_FROM_REG evaluate their > arguments multiple times. These macros are used in lockless show functions > involving shared driver data, leading to Time-of-Check to Time-of-Use race > conditions. > > For example, RPM_FROM_REG checks if a value is 0 or 255, and then uses it > in a division. If the value is modified by another thread to 0 after the > check but before the division, it causes a divide-by-zero error. > > Convert these macros to static functions. This guarantees that arguments > are evaluated only once (pass-by-value), fixing the race conditions. > Adhere to the principle of minimal changes by only converting the specific > macros involved in these lockless contexts. > > Link: https://lore.kernel.org/all/CALbr=LYJ_ehtp53HXEVkSpYoub+XYSTU8Rg=o1xxMJ8=5z8B-g@mail.gmail.com/ > Signed-off-by: Gui-Dong Han > --- Applied. Thanks, Guenter