Linux Hardware Monitor development
 help / color / mirror / Atom feed
From: Tzung-Bi Shih <tzungbi@kernel.org>
To: Guenter Roeck <linux@roeck-us.net>
Cc: Hardware Monitoring <linux-hwmon@vger.kernel.org>
Subject: Re: [PATCH 4/6] hwmon: (tmp464) Use multi-byte regmap operations
Date: Thu, 18 Jul 2024 09:29:02 +0800	[thread overview]
Message-ID: <Zphv3kGeqX7LUgY0@tzungbi-laptop> (raw)
In-Reply-To: <4b195103-5f8a-4251-8612-7ec51f07bd2d@roeck-us.net>

On Wed, Jul 17, 2024 at 07:37:10AM -0700, Guenter Roeck wrote:
> On 7/17/24 06:35, Tzung-Bi Shih wrote:
> > On Tue, Jul 16, 2024 at 04:00:48PM -0700, Guenter Roeck wrote:
> > > @@ -147,11 +147,11 @@ static int tmp464_temp_read(struct device *dev, u32 attr, int channel, long *val
> > >   {
> > [...]
> > > -	mutex_lock(&data->update_lock);
> > > -
> > >   	switch (attr) {
> > >   	case hwmon_temp_max_alarm:
> > >   		err = regmap_read(regmap, TMP464_THERM_STATUS_REG, &regval);
> > > @@ -172,26 +172,27 @@ static int tmp464_temp_read(struct device *dev, u32 attr, int channel, long *val
> > >   		 * complete. That means we have to cache the value internally
> > >   		 * for one measurement cycle and report the cached value.
> > >   		 */
> > > +		mutex_lock(&data->update_lock);
> > >   		if (!data->valid || time_after(jiffies, data->last_updated +
> > >   					       msecs_to_jiffies(data->update_interval))) {
> > >   			err = regmap_read(regmap, TMP464_REMOTE_OPEN_REG, &regval);
> > >   			if (err < 0)
> > > -				break;
> > > +				goto unlock;
> > >   			data->open_reg = regval;
> > >   			data->last_updated = jiffies;
> > >   			data->valid = true;
> > >   		}
> > >   		*val = !!(data->open_reg & BIT(channel + 7));
> > > +unlock:
> > > +		mutex_unlock(&data->update_lock);
> > >   		break;
> > 
> > I think the function can entirely drop the mutex.  Only [1] needs it.
> > 
> 
> It is needed to protect updating open_reg. Otherwise a second process
> could enter the code and read the register again, which would then return
> different (cleared) values. As result open_reg might contain the temporarily
> "cleared" values.
> 
> Process 1			Process 2
> err = regmap_read();
> data->open_reg = regval;
> 				err = regmap_read();
> 				data->open_reg = regval;
> data->last_updated = jiffies;
> ...

Ack.

Reviewed-by: Tzung-Bi Shih <tzungbi@kernel.org>

  reply	other threads:[~2024-07-18  1:29 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-16 23:00 [PATCH 0/6] hwmon: Use multi-byte regmap operations Guenter Roeck
2024-07-16 23:00 ` [PATCH 1/6] hwmon: (lm95245) " Guenter Roeck
2024-07-17 13:33   ` Tzung-Bi Shih
2024-07-16 23:00 ` [PATCH 2/6] hwmon: (nct7802) " Guenter Roeck
2024-07-17 13:35   ` Tzung-Bi Shih
2024-07-16 23:00 ` [PATCH 3/6] hwmon: (adt7x10) " Guenter Roeck
2024-07-17 13:35   ` Tzung-Bi Shih
2024-07-16 23:00 ` [PATCH 4/6] hwmon: (tmp464) " Guenter Roeck
2024-07-17 13:35   ` Tzung-Bi Shih
2024-07-17 14:37     ` Guenter Roeck
2024-07-18  1:29       ` Tzung-Bi Shih [this message]
2024-07-16 23:00 ` [PATCH 5/6] hwmon: (max6639) " Guenter Roeck
2024-07-17 13:36   ` Tzung-Bi Shih
2024-07-17 17:14     ` Guenter Roeck
2024-07-18  1:28       ` Tzung-Bi Shih
2024-07-18  2:27         ` Guenter Roeck
2024-07-16 23:00 ` [PATCH 6/6] hwmon: (amc6821) " Guenter Roeck
2024-07-17 13:36   ` Tzung-Bi Shih

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=Zphv3kGeqX7LUgY0@tzungbi-laptop \
    --to=tzungbi@kernel.org \
    --cc=linux-hwmon@vger.kernel.org \
    --cc=linux@roeck-us.net \
    /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