From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f42.google.com (mail-wr1-f42.google.com [209.85.221.42]) (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 E23AE31C57B for ; Tue, 25 Nov 2025 14:27:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.42 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764080830; cv=none; b=c57EaCwqdYKcf3cosIpjRvNcLReJ4pVLxlpksdb5rPIDgmWWInSMOh0wgU+QdA9Ki2zESCMJSCgr9Tx1s3E5STy5xB9q8cGY/GE0PtAt1jJPwMDBtVB8C3Rv8eHabarH+P9OGzd4ov6AVj+o/g/OaeNeULYnBvT5Gwgk22Odoio= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764080830; c=relaxed/simple; bh=1JMJfkBBhG+t8MUgIM9PXhaMbkiYOvUOMsqXgqotGsQ=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=S9G3Km1qiEo09+Vp9EKnBTwo+8B0vIRLWC7yFkXCOGSxF8DHRNNEXiQz3Pr9zME/csa2gRDkhvbHWlSc6PA8ScahLSYJjw6wTYShxgS0YN5TeCTIN2t0TZ6DaE7EnvsqamGE80wjdF12szyT185DsLNOQfUnndJeQKjfSpEJ23s= 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=k/MmHj3a; arc=none smtp.client-ip=209.85.221.42 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="k/MmHj3a" Received: by mail-wr1-f42.google.com with SMTP id ffacd0b85a97d-42b2a0c18caso3469671f8f.1 for ; Tue, 25 Nov 2025 06:27:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1764080827; x=1764685627; darn=vger.kernel.org; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:subject:cc:to:from:date:message-id:from:to :cc:subject:date:message-id:reply-to; bh=U5j4evZ1IL3IsXZZO8TZcDakLErkiExtx5jEOZlyoZM=; b=k/MmHj3auNXzDIHHtLDQwmpuJ9j1JMk5hZwt2R7p4Tq5ealPrFdBQjehD84jS0ihYq FaFYVt0fcXI6UZ4Sry1fyUmXN5Y23G34yeX5B9D8uvnaGT48kGYiTDM/cVERPiRWCGOR k1oTVAILxpngqAKb45e4LxHXdXGpN82AlEA4lzSeCffkKBtOoaW6QDODsNpSdYWBlz07 UQClmqnXwcuGB6DEaer9Ftuzwt92MbeY0wpKYEIeLG9sP9FgEZbaVn89AojyRQoSg9Qh ydTwBXejzTqey4emCv5YzfpLYJk5Y9R5ytDmqrJXuSn6/s5zaUxd25hSGVJdEfS5yX+j aR9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764080827; x=1764685627; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:subject:cc:to:from:date:message-id:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=U5j4evZ1IL3IsXZZO8TZcDakLErkiExtx5jEOZlyoZM=; b=hQtjYOy2ZlOI9xgkpywIM0mLIKf12kry0Z/ZJ59ijVOaNUrKTco1ixkvLOhKRTo7D3 LDEvULy5e+pw0xoO2nkcj/CkGWiFs1wk24KoyhwLu785KFYmn4u7CL4AI4hhmogw8KlG bTPfH0nGep4UP6CRQUUwJoZun986J1mqIiVD3cBGyLdLRtVtv0wMDpkOWnhBsUTk70Ci jwUzMMysFb5tUTswnNL3nHCZQEJKeACI2GaWv8YdTElNcLMIr5LKJOkSQ4XlcpEB7t7t 8wR1NPKZ3sYqLimUS4rGFhH1duZl141FcfN97msHm3xCAIxXxnQ6El9TsKEDyycTsMEj YtIA== X-Forwarded-Encrypted: i=1; AJvYcCXHrg9IWJRCSkAJHW8FfSCoAyLC7HVn6tvzELZI4YXbRVS13FkNALjv6VLdEMZMD44wYfQ0W2Q4a45bLiU=@vger.kernel.org X-Gm-Message-State: AOJu0YxT3Cn4RRclN8KrbtCGxdIKVwQZIC8zlSLDvtF1VCnFYD6oVUft fmTaSObhZGCIQGrnFWaqElZ+HiCwTYeDZuX69whnVsKx+R/R5GF+vmQ3 X-Gm-Gg: ASbGncu07uBUyOqdN1RjEzUHH3V3DkO8VLWnJTH0Xp7kXETQsRqTuDc7/JrITkQXclN n5SLhkPeWj2M5y3l9mRC9AR6bitzt8MVqrwMtDwoXR14pXMzaSKQBMPWOy04Sau/1QOlamH/V00 pZXj+V2jULv+rlVZg03ZJXrwwVpZyhS8t2u50aTxaXRA62F96jz/deMiP9dzkQX9a/nzPyCA0Uc N2Fc4ksHIgD7lorrVNsacLON9VBLIh9s5tsz4cSI5939qIPD5DPb0SAF8LFGWU0e0FqxjNMNaON o+KHUIaaSQirkALNPLP7pWvEr4UUczWCkhwFoL3aSLiIcfpaF8Q1O1Os9Aa+s1cWS2ZGwoR17Qm 1obaza/ATBLZPM9C43ey9E3CVMuL/6g9hZ+LRxrVSRapRHdCUQnsTO053IooBexKg9gW1MqNyR3 BeCkI1sTp4LRbA4turbuz+jARR X-Google-Smtp-Source: AGHT+IHvuQUfPvDdiGxUCavncDHFdm/57aDV7lAJuFupVjzIP2m2WqLeNn06EjGTaov/1bccbWvrAA== X-Received: by 2002:a5d:5888:0:b0:42b:3b55:8908 with SMTP id ffacd0b85a97d-42cc1d22c70mr15977277f8f.51.1764080826902; Tue, 25 Nov 2025 06:27:06 -0800 (PST) Received: from Ansuel-XPS. (93-34-90-37.ip49.fastwebnet.it. [93.34.90.37]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-42cb7fa7affsm34792088f8f.23.2025.11.25.06.27.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Nov 2025 06:27:06 -0800 (PST) Message-ID: <6925bcba.df0a0220.925a7.ca27@mx.google.com> X-Google-Original-Message-ID: Date: Tue, 25 Nov 2025 15:27:02 +0100 From: Christian Marangi To: david laight Cc: rafael@kernel.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: thermal/drivers/airoha: Fix low trip temperature setting References: <20251122220747.70c51d9d@pumpkin> 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=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20251122220747.70c51d9d@pumpkin> On Sat, Nov 22, 2025 at 10:07:47PM +0000, david laight wrote: > There is a 'cut&paste' error in the code that sets the 'low' limit. > The clamp() calls contains 'high' instead of 'low'. > > While FEILD_MAX() ought to be (and probably is) a compile-time constant. > it isn't constant enough for the range check I'm adding to clamp_t(). > Additionally (and probably accidentally) it has a 64bit unsigned type > which propagates through RAW_TO_TEMP() causing a 'signedness error'. > Hit it at the root cause with an (int) cast of FIELD_MAX(). > (Alternatively arrange for RAW_TO_TEMP() to always return a signed value.) > Sorry but I'm not very convinced by this section. clamp_t in theory cast everything to the requested type. FIELD_MAX will correctly result in the max value for the register and then RAW_TO_TEMP should convert the value to a temp and be an int. If it wasn't the case it should have been a BUILD_BUG error. Am I missing something? > Fixes: 42de37f40e1b ("thermal/drivers: Add support for Airoha EN7581 thermal sensor") > > Signed-off by: David Laight > > --- > This is a diff because I've not even contemplated committing the nearly 500 > files I changed. > > diff --git a/drivers/thermal/airoha_thermal.c b/drivers/thermal/airoha_thermal.c > index b9fd6bfc88e5..75afc94fea5f 100644 > --- a/drivers/thermal/airoha_thermal.c > +++ b/drivers/thermal/airoha_thermal.c > @@ -261,8 +261,8 @@ static int airoha_thermal_set_trips(struct thermal_zone_device *tz, int low, > > if (high != INT_MAX) { > /* Validate high and clamp it a supported value */ > - high = clamp_t(int, high, RAW_TO_TEMP(priv, 0), > - RAW_TO_TEMP(priv, FIELD_MAX(EN7581_DOUT_TADC_MASK))); > + high = clamp(high, RAW_TO_TEMP(priv, 0), > + RAW_TO_TEMP(priv, (int)FIELD_MAX(EN7581_DOUT_TADC_MASK))); > > /* We offset the high temp of 1°C to trigger correct event */ > writel(TEMP_TO_RAW(priv, high) >> 4, > @@ -273,8 +273,8 @@ static int airoha_thermal_set_trips(struct thermal_zone_device *tz, int low, > > if (low != -INT_MAX) { > /* Validate low and clamp it to a supported value */ > - low = clamp_t(int, high, RAW_TO_TEMP(priv, 0), > - RAW_TO_TEMP(priv, FIELD_MAX(EN7581_DOUT_TADC_MASK))); > + low = clamp(low, RAW_TO_TEMP(priv, 0), > + RAW_TO_TEMP(priv, (int)FIELD_MAX(EN7581_DOUT_TADC_MASK))); > > /* We offset the low temp of 1°C to trigger correct event */ > writel(TEMP_TO_RAW(priv, low) >> 4, > -- Ansuel