From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pg1-f171.google.com (mail-pg1-f171.google.com [209.85.215.171]) (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 2D11B265632 for ; Fri, 28 Nov 2025 16:34:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.171 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764347692; cv=none; b=sFFPCnO6chOWES6MIC8rmReEsFhhgYQ/eH5kZxgFIkG0l/yMSzHCMz/hmihuKmb+cENztE7uohdJqaDwcrFZnIamhJxa0tFFvSvIoZrQnivgFgF9PzMc99RefhKA31I8PMLWoa+ymeCq8HXQcyCuUxcUexIjm9EXgrRWnmgW/eI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764347692; c=relaxed/simple; bh=GXH1cWPdGus4O8oVWZv/sxdK/JlLC1p3HxJzlpZFPDs=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=FIPtG/HnjYvwr6kvd1eVIEsL22R/PnSbZ6Wy8ge8+5BWUqQ7zxt/zPiQx8Pyeh/eUifiYmxbwenqpNxL5wnWIjK/uaueZDS7IQlqkYwIYvUO2Nu0VeW/nIj+cpC841zOG6f3AwUXLKMKS4mL4DQHzUfZMn7JEjwB1kTIJaJRe3s= 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=TLluKbad; arc=none smtp.client-ip=209.85.215.171 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="TLluKbad" Received: by mail-pg1-f171.google.com with SMTP id 41be03b00d2f7-bc4b952cc9dso1902230a12.3 for ; Fri, 28 Nov 2025 08:34:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1764347690; x=1764952490; 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=PFmk9hlrvzIMQ9F/XPguCU52S/7ZrA0XyoOyhl4nsuw=; b=TLluKbadMCGr88g/x2llq+qT5GyW6r6J8v/tBctvbh1gobzLq1j6QQdyjwJE2BsoNs S6d11YJdxowsdOrmkajG3n4B55JVOIi8cTC1zAQiMa3rPNkDOdvnZ+Fpgz9Gm7KN8giY Q940ozf2f9eIZCuF2mpBS94TNUQLbYihI5dugIPjT7gz/3z8u32bVZZBin5afeTHQs/t 9n9dXZzgilE5gFH3Bh07n6xaI9vvK+e58ROjK4vZBRwSP6cRiL2yMMOPF3IgBaqWSY+F iwTMRHpZT4kID7Y3FkVU8HSlZCau4rZDtiwep0ROpNbCtxU1eEO5G5fQ7Y6HXWCnt68o vUgg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764347690; x=1764952490; 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=PFmk9hlrvzIMQ9F/XPguCU52S/7ZrA0XyoOyhl4nsuw=; b=kM3V5YVS/ha2scfgqgzBwbFPGkn7/0ijjAqVos/Sc1V26RkcLzXtCkJbhUYEFuhC9V KtOvaY+GBVFelnKrmqK5ylK9GzPBq2BmSRTCPb5IxIXz6S8oUbxnKTD7X7H2OorpXnM8 VitIkWLneckc3TC0Gm9vsvPCUt0dADkEnQXRcnOovIsiGqNAoGLcPlNkDINKBL2WIAep VdnqjwNZ+6rGPGQpAPBswGjnYRC24H1vPx3g1dmtPcbzoFvut9k4nCfPIpmQKHgS+eL+ 0T7qEanrge8ejyPYJ8Qctf2a3yDt5VGtH/GrrpB3ZSFJXqWt9angwlalUrilfXn1yBUL sY5g== X-Forwarded-Encrypted: i=1; AJvYcCXtxcxwQXH/XrvMzf7nqCBi1WlsvU1j36HxZqQSWM/gpY99Po5uFd46Jzh2gxOCcT5YwImuiAxFOAh9V04=@vger.kernel.org X-Gm-Message-State: AOJu0YzH+l10FJXy9XBob4bx8svaRjkoGJEpVJReuRPkC7ee8D1zcE9f vupGweS2BpTRbydZINTXaZxk3y72YzsytD3sRl6/ctnWCItv5eP56THd X-Gm-Gg: ASbGncs0SZG96eY52qP8IFUOT77FyHgRXgV1oMmzZq8eGY7aubVwnTpm4oN2BcU3+X8 xM3Mcexy40o/WjiNLS0Gi0TPQfeEEl/u2AL2jMC+lcbYL69NJ6i0sr1o+/CehHAxKJkHdaob/dc uLkQCI1Yu/XIft6JRkw4hgrFsUlzXurl/eLmIF2ezOwTxwcqsHTjR/pGX+FSiWi0thQkNsOMfG7 99lG1tNfGbQ6ejtUKpLhJgKVWU0E0wXErouelYnWjX2gozokh/1Htf2WbMjhnSnGLwUeU4gDe6Z 9Dx6mXH9eeXKjR36F8x5ifLs0F7OJRwBy0CR3cKuUkTQBAunhd+Pd8nAqRkkv92wAmj4yXltEzX prny5Qa90FIzJXi5LhzIyRmV0z8sqawXap/0y8KiX7eqEdo6aQLm09YSyztyyhKy7pPh+lMG+Bg qXre4bxar3c0TGiWal+AF1sPU= X-Google-Smtp-Source: AGHT+IHSE4V0DVDx+1WJxYLX/1UcOOn/zoR6YvJ99VgXvbLfW9lqG/mD60tGkXaEnTc9gRyYW/IiAA== X-Received: by 2002:a05:7300:2716:b0:2a4:3594:d545 with SMTP id 5a478bee46e88-2a719d5a9d5mr13034270eec.18.1764347690279; Fri, 28 Nov 2025 08:34:50 -0800 (PST) Received: from server.roeck-us.net ([2600:1700:e321:62f0:da43:aeff:fecc:bfd5]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-2a9653ca11esm16442454eec.0.2025.11.28.08.34.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 28 Nov 2025 08:34:49 -0800 (PST) Sender: Guenter Roeck Date: Fri, 28 Nov 2025 08:34:48 -0800 From: Guenter Roeck To: Gui-Dong Han Cc: linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: Re: [PATCH] hwmon: (max6620) Add locking to avoid TOCTOU Message-ID: References: <20251128124351.3778-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: <20251128124351.3778-1-hanguidong02@gmail.com> On Fri, Nov 28, 2025 at 08:43:51PM +0800, Gui-Dong Han wrote: > The function max6620_read checks shared data (tach and target) for zero > before passing it to max6620_fan_tach_to_rpm, which uses it as a divisor. > These accesses are currently lockless. If the data changes to zero > between the check and the division, it causes a divide-by-zero error. > > Explicitly acquire the update lock around these checks and calculations > to ensure the data remains stable, preventing Time-of-Check to > Time-of-Use (TOCTOU) race conditions. > > This change also aligns the locking behavior with the hwmon_fan_alarm > case, which already uses the update lock. > > Link: https://lore.kernel.org/all/CALbr=LYJ_ehtp53HXEVkSpYoub+XYSTU8Rg=o1xxMJ8=5z8B-g@mail.gmail.com/ > Fixes: e8ac01e5db32 ("hwmon: Add Maxim MAX6620 hardware monitoring driver") > Cc: stable@vger.kernel.org > Signed-off-by: Gui-Dong Han > --- > Based on the discussion in the link, I will submit a series of patches to > address TOCTOU issues in the hwmon subsystem by converting macros to > functions or adjusting locking where appropriate. This patch is not necessary. The driver registers with the hwmon subsystem using devm_hwmon_device_register_with_info(). That means the hwmon subsystem handles the necessary locking. On top of that, removing the existing driver internal locking code is queued for v6.19. Thanks, Guenter