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 21:04:14 -0700 [thread overview]
Message-ID: <7de80d4f-7c25-6b6b-ebb0-e9e1254dac53@roeck-us.net> (raw)
In-Reply-To: <CAFBinCDRA-Xw_Y9PkL2vmCqW3A1vCWeRB2EDEJQgQ+qKMn9dYw@mail.gmail.com>
On 10/21/22 10:51, Martin Blumenstingl wrote:
> Hi Guenter,
>
> On Fri, Oct 21, 2022 at 7:11 PM Guenter Roeck <linux@roeck-us.net> wrote:
> [...]
>>> @@ -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 for spotting this - this is indeed a potential issue.
> Do you also want me to add locking for the data->config access (read)
> in jc42_read()? Without a lock there in theory jc42_write() may have
> already updated data->config with a new value while hardware still has
> the old value. So in the end the read output may show a hysteresis
> which was not programmed to the registers at that time.
>
Thanks for noticing. I had missed that one. Yes, please.
Thanks,
Guenter
next prev parent reply other threads:[~2022-10-22 4:04 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
2022-10-21 17:51 ` Martin Blumenstingl
2022-10-22 4:04 ` Guenter Roeck [this message]
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=7de80d4f-7c25-6b6b-ebb0-e9e1254dac53@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®