All of lore.kernel.org
 help / color / mirror / Atom feed
From: Hans de Goede <j.w.r.degoede@hhs.nl>
To: lm-sensors@vger.kernel.org
Subject: Re: [lm-sensors] [PATCH] hwmon: fix common race conditions, batch 2
Date: Mon, 07 Apr 2008 05:49:06 +0000	[thread overview]
Message-ID: <47F9B5D2.1070503@hhs.nl> (raw)
In-Reply-To: <20080406180721.GN27659@mars.solarsys.private>

Mark M. Hoffman wrote:
> Hi:
> 
>  atxp1.c    |    2 ++
>  coretemp.c |    2 ++
>  dme1737.c  |    6 ++++++
>  f71882fg.c |   14 ++++++++++----
>  gl518sm.c  |   18 ++++++++++++++----
>  gl520sm.c  |   16 ++++++++++++----
>  it87.c     |   26 ++++++++++++++++----------
>  7 files changed, 62 insertions(+), 22 deletions(-)
> 

<snip>

> diff --git a/drivers/hwmon/f71882fg.c b/drivers/hwmon/f71882fg.c
> index cbeb498..a97ebde 100644
> --- a/drivers/hwmon/f71882fg.c
> +++ b/drivers/hwmon/f71882fg.c
> @@ -593,9 +593,12 @@ static ssize_t show_temp_max_hyst(struct device *dev, struct device_attribute
>  {
>  	struct f71882fg_data *data = f71882fg_update_device(dev);
>  	int nr = to_sensor_dev_attr(devattr)->index;
> +	int res;
>  
> -	return sprintf(buf, "%d\n",
> -		(data->temp_high[nr] - data->temp_hyst[nr]) * 1000);
> +	mutex_lock(&data->update_lock);
> +	res = (data->temp_high[nr] - data->temp_hyst[nr]) * 1000;
> +	mutex_unlock(&data->update_lock);
> +	return sprintf(buf, "%d\n", res);
>  }
>  
>  static ssize_t store_temp_max_hyst(struct device *dev, struct device_attribute
> @@ -670,9 +673,12 @@ static ssize_t show_temp_crit_hyst(struct device *dev, struct device_attribute
>  {
>  	struct f71882fg_data *data = f71882fg_update_device(dev);
>  	int nr = to_sensor_dev_attr(devattr)->index;
> +	int res;
>  
> -	return sprintf(buf, "%d\n",
> -		(data->temp_ovt[nr] - data->temp_hyst[nr]) * 1000);
> +	mutex_lock(&data->update_lock);
> +	res = (data->temp_ovt[nr] - data->temp_hyst[nr]) * 1000;
> +	mutex_unlock(&data->update_lock);
> +	return sprintf(buf, "%d\n", res);
>  }
>  
>  static ssize_t show_temp_type(struct device *dev, struct device_attribute

I don't believe this is necessary, as data->temp_ovt / data->temp_high can be 
changed independend of data->temp_hyst. SO if a reader and a writer are racing 
with the locks the reader will either get the value from before or after the 
read, and without the lock, the same.

There are no parts of the code which change both data->temp_ovt/data->temp_high 
and data->temp_hyst at _the same time_. With the one exception being the code 
reading the values back from the IC in update_device(), so unless something is 
mucking with the hardware underneath us, in which case we have much bigger 
problems! , there us no race here.

The non locking in these functions was done by design.

With that said, I have no objections against this patch if it gives people a 
nice safe warm fuzzy feeling to have this patch present.

---

Talking about something else touching the hardware, maybe we should change the 
code which reads non changing registers periodically to actually check for 
unexpected changes, and yell if these are found, because AFAIK thats the only 
reason why we read these registers periodically even though they should 
theoretically never change.

Regards,

Hans

_______________________________________________
lm-sensors mailing list
lm-sensors@lm-sensors.org
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

  reply	other threads:[~2008-04-07  5:49 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-04-06 18:07 [lm-sensors] [PATCH] hwmon: fix common race conditions, batch 2 Mark M. Hoffman
2008-04-07  5:49 ` Hans de Goede [this message]
2008-04-07 13:35 ` Jean Delvare
2008-04-07 15:13 ` Jean Delvare
2008-04-07 20:04 ` Hans de Goede
2008-04-09  9:42 ` Jean Delvare
2008-04-11  7:18 ` Hans de Goede
2008-04-11  9:29 ` [lm-sensors] [PATCH] hwmon: fix common race conditions, Jean Delvare
2008-04-14 14:29 ` Hans de Goede

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=47F9B5D2.1070503@hhs.nl \
    --to=j.w.r.degoede@hhs.nl \
    --cc=lm-sensors@vger.kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.