From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-yw1-f177.google.com (mail-yw1-f177.google.com [209.85.128.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 33F391A9FA8 for ; Tue, 28 Jul 2026 00:22:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.177 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785198165; cv=none; b=F6zPEyD/l7rrakSRNfdAlIYxq1hpJV3dNIW/Tgnmav93jCb/6rGzgEELSOsA7nvR49EkTxemM2RKnkfjdIwxSFVSLEXVwNjnIAs8lC8VTKL28c2smLIkrDYZToEm4F5sx92R08/RNB1ae+9Zm3YTxw9L83SQUyovJ8VSU8rKgDk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785198165; c=relaxed/simple; bh=otyfV37K5jCT+kjDuv33Jof243V9rWG53jfTfDM1hko=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=HY7xnd7NHgxC82oWQCuDwCKTjfOa96kFnqIizNo+7J6ASVvM4cbnJvUmjTXcIdcPZopzsk95FcnyWQ0xyz7pRjV2CF2LZ7Ibflhrf0gh3GkaRVel8UYYK1et9i1FXXmGKlLr0l7me7lGUx2MlTePJvPi5gSNE17ayhr810nVRHE= 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=lBKnEu++; arc=none smtp.client-ip=209.85.128.177 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="lBKnEu++" Received: by mail-yw1-f177.google.com with SMTP id 00721157ae682-7dbcb505578so30280567b3.3 for ; Mon, 27 Jul 2026 17:22:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1785198163; x=1785802963; 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=fe5LqOn1qfiOnUxC1maEycp7XWWBtguH8PckX6DUpu0=; b=lBKnEu++d/33U2OAvlMYDogA2dRAImED5BfiFivFghDZrPONlOZRa6nUNQ7xIpW5No 7ksTLlb/xQwbbNbPTTOPkKigp9z3zMY9/elXM8ZGBungH8r1zX+BYISVhB/JAZFi/Wq+ CYtN8jlk2L6O05NiCp4gsqwID5n0jb790lJWBizTS2E9EOjDLmYsxnz1WyIHJ32BS0mQ pZV3AEqx5lYimQI4Zk8Bb3kwlFJk3wN4qcwNNTfPU4u9EUoDeqMVc7wFQneSg3G3SpLX PgrzjQU9yOhPzpP8Az2DOIHXIp6h89QgF8r8o3fUVvrdoste9Yximj2mhfa2oOfTfzec dr8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785198163; x=1785802963; 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=fe5LqOn1qfiOnUxC1maEycp7XWWBtguH8PckX6DUpu0=; b=haS7H7FO3yVfEjmBDmgXmFpTGy4f6UmxPkZgldLlBlzFtsAu70v+fVYWTMeGUcrVTA 8azIQQGEyPb+VGG8FzTLnLYyPrlwZF8zBy8cSQxR3B1EfoHbn7AsTYIH5DU4J32EdXiM F072gdRcyl+izKGIWtHjeVHp7ot2tY1XqHLL3EmNNvBYhKeBeHBQBOugdWHw6khVsNnv dX26jBSXT6sQ68q1U3w5gGSCnAjwXcwJ7crFbNnig1Q+cSTWrZp9h4Uznyvo0Bau6u+X qc49DLWJr5cSXxa3Xroo/22buCKTU43mNhcfgdotI92qvOvixnWQaLe1lnBYfFN/PqvP 9rog== X-Forwarded-Encrypted: i=1; AHgh+RodwZ0HD3VpXIAHwNL7T1jN6vcQjmtLfiKPFGJlWRv1VUApL2PAkCmesS/KNG70J6zgYDxGX5GHG/1onqY=@vger.kernel.org X-Gm-Message-State: AOJu0YwRpVNxtBiCcyqPwZyFGGNJCRe+erOb6WDaXCu7lp4+au+nGumk QW/ck9T3L9fPXIeG1v/s4HbzrQANoPsDviwFJ6HBApOpcdMhzaQpObDR X-Gm-Gg: AR+sD11ysYgIYow6JslFSMoVsSKEADyvM38oyw/gWQMhifClkrG5MihUc6nIVY6D8gy rFrQPYzWjDmQKxvonuUOXdypOV0yw7GfDNxfVElZgqnSiG/ceZE+X0ucdyq0sqC44rTWGzYPfi5 HcObH/2CbMjt9JP5sMZACfGoEa6snBK5CtIDUd9J4BK6uD83hdjYgUc7RwPj1IgdYEy/DAj8E0u YY/6NdQD0NtyP3kytvDeSPfMTZTZ8RqFHGlVnhOD5nSY9itsaxZhCuaCm4Akv12zSZj7Q+tDbP7 60gl6MnGh2NMZIO4srZp1VcQZ/H0Dd5vn9W43YUClvtKFhcWOt2g/OHxSdigfk9/nUUjhMmjYsw kbPcqZURokATKaaeXmq4rsIvIKKavx8PNbR+gMGDfD2wgzQspvhra6UmcRurKYpLn6t28qsP6/o A9hVaJyAvRwA8HnD1U1w== X-Received: by 2002:a05:690c:e3ef:b0:81e:bee4:2c1c with SMTP id 00721157ae682-81f9927660fmr308827b3.63.1785198162957; Mon, 27 Jul 2026 17:22:42 -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.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jul 2026 17:22:38 -0700 (PDT) From: Luiz Angelo Daros de Luca Date: Mon, 27 Jul 2026 21:22:18 -0300 Subject: [hwmon PATCH v2 2/8] hwmon: (adt7470) Fix cache updated before hardware write on I2C error 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-2-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_temp_write() and adt7470_pwm_write() update the driver's cached values (temp_min, temp_max, pwm_input, pwm_enable) before issuing the corresponding regmap_write(), and never check whether the write succeeded before committing that update. If the I2C transaction fails, the function correctly propagates the error to the caller, but the cache silently keeps the new value, which was never actually applied to the hardware. Subsequent reads then report a value that does not match the device state. Reorder both write paths to update the cache only after a successful regmap_write(), so the cache always reflects what was actually written to the hardware. Fixes: ef67959c4253 ("hwmon: (adt7470) Convert to use regmap") Signed-off-by: Luiz Angelo Daros de Luca --- drivers/hwmon/adt7470.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/drivers/hwmon/adt7470.c b/drivers/hwmon/adt7470.c index 481d51617f4b..62ec68ea0a40 100644 --- a/drivers/hwmon/adt7470.c +++ b/drivers/hwmon/adt7470.c @@ -589,14 +589,16 @@ static int adt7470_temp_write(struct device *dev, u32 attr, int channel, long va switch (attr) { case hwmon_temp_min: mutex_lock(&data->lock); - data->temp_min[channel] = val; err = regmap_write(data->regmap, ADT7470_TEMP_MIN_REG(channel), val); + if (!err) + data->temp_min[channel] = val; mutex_unlock(&data->lock); break; case hwmon_temp_max: mutex_lock(&data->lock); - data->temp_max[channel] = val; err = regmap_write(data->regmap, ADT7470_TEMP_MAX_REG(channel), val); + if (!err) + data->temp_max[channel] = val; mutex_unlock(&data->lock); break; default: @@ -831,9 +833,10 @@ static int adt7470_pwm_write(struct device *dev, u32 attr, int channel, long val case hwmon_pwm_input: val = clamp_val(val, 0, 255); mutex_lock(&data->lock); - data->pwm[channel] = val; err = regmap_write(data->regmap, ADT7470_REG_PWM(channel), - data->pwm[channel]); + val); + if (!err) + data->pwm[channel] = val; mutex_unlock(&data->lock); break; case hwmon_pwm_enable: @@ -847,10 +850,11 @@ static int adt7470_pwm_write(struct device *dev, u32 attr, int channel, long val val--; mutex_lock(&data->lock); - data->pwm_automatic[channel] = val; err = regmap_update_bits(data->regmap, ADT7470_REG_PWM_CFG(channel), pwm_auto_reg_mask, val ? pwm_auto_reg_mask : 0); + if (!err) + data->pwm_automatic[channel] = val; mutex_unlock(&data->lock); break; case hwmon_pwm_freq: -- 2.55.0