From: Guenter Roeck <linux@roeck-us.net>
To: Martin Blumenstingl <martin.blumenstingl@googlemail.com>
Cc: linux-hwmon@vger.kernel.org, jdelvare@suse.com,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v3 1/2] hwmon: (jc42) Convert register access and caching to regmap/regcache
Date: Fri, 21 Oct 2022 10:11:27 -0700 [thread overview]
Message-ID: <20221021171127.GB1888515@roeck-us.net> (raw)
In-Reply-To: <20221021165000.1865615-2-martin.blumenstingl@googlemail.com>
On Fri, Oct 21, 2022 at 06:49:59PM +0200, Martin Blumenstingl wrote:
> Switch the jc42 driver to use an I2C regmap to access the registers.
> Also move over to regmap's built-in caching instead of adding a
> custom caching implementation. This works for JC42_REG_TEMP_UPPER,
> JC42_REG_TEMP_LOWER and JC42_REG_TEMP_CRITICAL as these values never
> change except when explicitly written. The cache For JC42_REG_TEMP is
> dropped (regmap can't cache it because it's volatile, meaning it can
> change at any time) as well for simplicity and consistency with other
> drivers.
>
> Signed-off-by: Martin Blumenstingl <martin.blumenstingl@googlemail.com>
> ---
...
> case hwmon_temp_crit_hyst:
> + ret = regmap_read(data->regmap, JC42_REG_TEMP_CRITICAL,
> + ®val);
> + if (ret)
> + return ret;
> +
> /*
> * JC42.4 compliant chips only support four hysteresis values.
> * Pick best choice and go from there.
> @@ -356,7 +349,7 @@ static int jc42_write(struct device *dev, enum hwmon_sensor_types type,
> val = clamp_val(val, (data->extended ? JC42_TEMP_MIN_EXTENDED
> : JC42_TEMP_MIN) - 6000,
> JC42_TEMP_MAX);
> - diff = jc42_temp_from_reg(data->temp[t_crit]) - val;
> + diff = jc42_temp_from_reg(regval) - val;
> hyst = 0;
> if (diff > 0) {
> if (diff < 2250)
> @@ -368,17 +361,14 @@ static int jc42_write(struct device *dev, enum hwmon_sensor_types type,
> }
> data->config = (data->config & ~JC42_CFG_HYST_MASK) |
> (hyst << JC42_CFG_HYST_SHIFT);
> - ret = i2c_smbus_write_word_swapped(data->client,
> - JC42_REG_CONFIG,
> - data->config);
> + ret = regmap_write(data->regmap, JC42_REG_CONFIG,
> + data->config);
> break;
This code sequence still requires a mutex since another thread could modify
the upper limit (and/or the hysteresis) while the hysteresis is in the process
of being written. Worst case there could be a mismatch between the value in
data->config and the value actually written into the chip. Granted, that is
unlikely to happen, but the race still exists.
Thanks,
Guenter
next prev parent reply other threads:[~2022-10-21 17:11 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-21 16:49 [PATCH v3 0/2] hwmon: (jc42) regmap conversion and resume fix Martin Blumenstingl
2022-10-21 16:49 ` [PATCH v3 1/2] hwmon: (jc42) Convert register access and caching to regmap/regcache Martin Blumenstingl
2022-10-21 17:11 ` Guenter Roeck [this message]
2022-10-21 17:51 ` Martin Blumenstingl
2022-10-22 4:04 ` Guenter Roeck
2022-10-21 16:50 ` [PATCH v3 2/2] hwmon: (jc42) Restore the min/max/critical temperatures on resume Martin Blumenstingl
2022-10-21 17:25 ` Guenter Roeck
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20221021171127.GB1888515@roeck-us.net \
--to=linux@roeck-us.net \
--cc=jdelvare@suse.com \
--cc=linux-hwmon@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=martin.blumenstingl@googlemail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®