From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-yw1-f178.google.com (mail-yw1-f178.google.com [209.85.128.178]) (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 83EF527456 for ; Tue, 28 Jul 2026 00:23:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.178 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785198187; cv=none; b=di8Rmej5Fnq7BJxvILQveK8bupoEioz4JeoZ05bQrwmqZqQDycArBHUISGRoN5KnIO4gidsr2FVYPZVWIp30f1o3/jX1KJx/hW1SoLlN8ixTBiTDyMicbLCpdBDWeTvx5O6hmF2Zx7F05UeEA3pNa7lIE7tSXCRQi0RpvlC7KQM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785198187; c=relaxed/simple; bh=I9oZIPUckVI2Bbf9EzAvTugPHOS6/E6ouPMxLjLZ8+8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=aTUEadJnGSgRJajPvm4PKz1E+ZraEdqysJyDHz4+P9fUBBJi7n5YUl13uSjxHrFEAA6dRmJ4JASro4hgmen9up5+C/nIaxHy0AY0c8UdKVoFUeYgQInyQDxXQjdIW/ZhzY9DW6J+nRVkZfWuK1WDn3wGVu3Hz/PWMRzQUSMruFI= 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=CMtHjwB/; arc=none smtp.client-ip=209.85.128.178 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="CMtHjwB/" Received: by mail-yw1-f178.google.com with SMTP id 00721157ae682-81f36179d72so41331377b3.2 for ; Mon, 27 Jul 2026 17:23:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1785198185; x=1785802985; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=8Kmr1YgrJ4oRQYtmiDZKltCYWP1t62Qg//SOlsWViac=; b=CMtHjwB/TlT7SZwb5yr/zviQqGvww+TL38NDpfcwAjskTZ1d4T9EzYsVpNeNNKviai cBcEKjtrVezhYmyvowsbQbSfqSy5rM67OR19QMDg4/MRrDFxPd3RMKr3gF1DI0RmeIkT aUSva9is7pGPKhSBchUa6GnEOzL2jDKu2B6RuBcFZk+3OrRZEeydi5UkRouRuK3i9DSp 1F7Jvve3M/EPbHd3fRN1jY0lRu4efFF7AVRFzqFEhs2BoFjntPMFc3HUbxXzIhZGv741 9y4LnMF0m7O6XjP/aZxWz2V7cNctJ4ts3C0OKz8q82mrgfoQ31U4h5zYngeTIQJq7k1q eCJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785198185; x=1785802985; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=8Kmr1YgrJ4oRQYtmiDZKltCYWP1t62Qg//SOlsWViac=; b=hu9YVXCNe/Gvzkdc076XomrcY1akBSiG15lPVoSjj8e0wMVv7hjttK2NVeBMsScEbC VmRrA0SHm7KAvGnklVXilMobjDcdIj6PXXSqoghUAqgDhhpJ40rNXdpET7Kma9gdp7uz RX3QzRphlFDoeuY0vLdXx63KVP8Z2xraqtNsjfuAQqBDDGEAyTOm21Tj/aogkfUdqt5o vVXe+RwxLXurZBHk4Flf412zhFgdTovWdmy3368YJdsD2VCHoZ24deq0L8IfVronzmGJ m2AjGUYMOQFKD02fCotifLPog0ApBJkK/Bd8sC97Awae7HMtXJnRSi6SncUhohK6PBcj Vocw== X-Forwarded-Encrypted: i=1; AHgh+RoSYEWnf6W6rdp6SEu2v6bcESrDKYhWzZLnM+dQfvznbPB7OABOR8yRxHvbXq33D46G40NaF6YBXxGOYOE=@vger.kernel.org X-Gm-Message-State: AOJu0Ywfs9h4+1iFL2hzc1IcEdEunyI38FyFzrl8rpCpMcHKe63UnhWN hdnXk94qjKiHEqo2GUqCS5ePZAas2I2JXgui++gD8dyQrMy6VmSttLwC X-Gm-Gg: AR+sD13uZoAjrkV5OdEX38Kg5nFXnITD2tZwxPARKkvyG7+BmggGebYq+Lozn890mf4 7yCzqX0x31nBqCgC71OxAVHyhEK9EZCpci+h539K+syDP/5IjfRYeEqlrPWgMhWSdSjsUo4uorq hbPP60d6Qrri+9hfBXcsBrRBmQwwttDuAeJ0tetrd5NqQr/4vYztPhhCssXVOXsGY+ieCaOcpn+ zPjMwSKFv0gZYZbGPhvdIRu8py5jVPZqK4mz0mZVXM71aUTQKIHcblYJUFAvGmkAF/8rOl6YU9X fz3KOqWu4BFFsYn7sGhcb8JjJNT7lciYpEcqBSwx43yN86mfK18JR/A+mKjbEznqnt0Z4CksrGR 79tAXwkhgmYjMTqauDdUxknbHxg7nxIOIt090vBbaif8E7f1Kcjp6wVhpHJDP1cuwVCs8+agttT gdlb8AxC242YelyO4hxA== X-Received: by 2002:a05:690c:498d:b0:81c:d5ae:739c with SMTP id 00721157ae682-81f99238c15mr522597b3.49.1785198185465; Mon, 27 Jul 2026 17:23:05 -0700 (PDT) Received: from tresc054937.tre-sc.gov.br ([187.65.210.13]) by smtp.gmail.com with ESMTPSA id 00721157ae682-81f655acc7csm39583707b3.0.2026.07.27.17.22.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jul 2026 17:23:02 -0700 (PDT) From: Luiz Angelo Daros de Luca Date: Mon, 27 Jul 2026 21:22:22 -0300 Subject: [hwmon PATCH v2 6/8] hwmon: (adt7470) Use cached PWM frequency value 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="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20260727-adt7470_fixes-v2-6-598e38a46ba6@gmail.com> References: <20260727-adt7470_fixes-v2-0-598e38a46ba6@gmail.com> In-Reply-To: <20260727-adt7470_fixes-v2-0-598e38a46ba6@gmail.com> To: Guenter Roeck , Chris Packham , Andrew Morton , "Darrick J. Wong" , "Mark M. Hoffman" Cc: linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org, Luiz Angelo Daros de Luca X-Mailer: b4 0.15.2 adt7470_pwm_read() currently ignores failures returned by pwm1_freq_get(). If the register read fails, the negative error code is returned through *val while the function itself reports success, potentially exposing a negative PWM frequency through sysfs. Fix this by using the cached PWM frequency maintained by the driver, eliminating the register access from the read path. Apart from the corrected error propagation and using the cached value, no functional change is intended. Fixes: ef67959c4253 ("hwmon: (adt7470) Convert to use regmap") Signed-off-by: Luiz Angelo Daros de Luca --- drivers/hwmon/adt7470.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/drivers/hwmon/adt7470.c b/drivers/hwmon/adt7470.c index c6fc7d38d698..1fbca4869b7b 100644 --- a/drivers/hwmon/adt7470.c +++ b/drivers/hwmon/adt7470.c @@ -182,6 +182,7 @@ struct adt7470_data { u8 pwm_min[ADT7470_PWM_COUNT]; s8 pwm_tmin[ADT7470_PWM_COUNT]; u8 pwm_auto_temp[ADT7470_PWM_COUNT]; + u32 pwm_freq; struct task_struct *auto_update; unsigned int auto_update_interval; @@ -756,7 +757,7 @@ static ssize_t force_pwm_max_store(struct device *dev, } /* These are the valid PWM frequencies to the nearest Hz */ -static const int adt7470_freq_map[] = { +static const u32 adt7470_freq_map[] = { 11, 15, 22, 29, 35, 44, 59, 88, 1400, 22500 }; @@ -796,7 +797,7 @@ static int adt7470_pwm_read(struct device *dev, u32 attr, int channel, long *val *val = 1 + data->pwm_automatic[channel]; break; case hwmon_pwm_freq: - *val = pwm1_freq_get(dev); + *val = data->pwm_freq; break; default: return -EOPNOTSUPP; @@ -809,12 +810,14 @@ static int pwm1_freq_set(struct device *dev, long freq) { struct adt7470_data *data = dev_get_drvdata(dev); unsigned int low_freq = ADT7470_CFG_LF; + u32 closest_freq; int index; int err; /* Round the user value given to the closest available frequency */ index = find_closest(freq, adt7470_freq_map, ARRAY_SIZE(adt7470_freq_map)); + closest_freq = adt7470_freq_map[index]; if (index >= 8) { index -= 8; @@ -832,6 +835,10 @@ static int pwm1_freq_set(struct device *dev, long freq) err = regmap_update_bits(data->regmap, ADT7470_REG_CFG_2, ADT7470_FREQ_MASK, index << ADT7470_FREQ_SHIFT); + if (err < 0) + goto out; + + data->pwm_freq = closest_freq; out: mutex_unlock(&data->lock); @@ -1285,6 +1292,7 @@ static int adt7470_probe(struct i2c_client *client) struct device *dev = &client->dev; struct adt7470_data *data; struct device *hwmon_dev; + int freq_val; int err; data = devm_kzalloc(dev, sizeof(struct adt7470_data), GFP_KERNEL); @@ -1309,6 +1317,14 @@ static int adt7470_probe(struct i2c_client *client) if (err < 0) return err; + freq_val = pwm1_freq_get(dev); + if (freq_val <= 0) { + err = freq_val < 0 ? freq_val : -EINVAL; + return err; + } + + data->pwm_freq = (u32)freq_val; + /* Register sysfs hooks */ hwmon_dev = devm_hwmon_device_register_with_info(dev, client->name, data, &adt7470_chip_info, -- 2.55.0