All of lore.kernel.org
 help / color / mirror / Atom feed
* [lm-sensors] [PATCH] hwmon/adt7411: improve locking
@ 2010-02-18 17:14 Wolfram Sang
  2010-02-21  9:56 ` Jean Delvare
  2010-02-21 10:10 ` Wolfram Sang
  0 siblings, 2 replies; 3+ messages in thread
From: Wolfram Sang @ 2010-02-18 17:14 UTC (permalink / raw)
  To: lm-sensors

Add proper locking for the cached variables. Also get rid of ref_is_vdd, which
became obsolete.

Signed-off-by: Wolfram Sang <w.sang@pengutronix.de>
Cc: Jean Delvare <khali@linux-fr.org>
---
 drivers/hwmon/adt7411.c |   21 ++++++++++++++-------
 1 files changed, 14 insertions(+), 7 deletions(-)

diff --git a/drivers/hwmon/adt7411.c b/drivers/hwmon/adt7411.c
index 2a86314..05b34b1 100644
--- a/drivers/hwmon/adt7411.c
+++ b/drivers/hwmon/adt7411.c
@@ -48,9 +48,9 @@ static const unsigned short normal_i2c[] = { 0x48, 0x4a, 0x4b, I2C_CLIENT_END };
 
 struct adt7411_data {
 	struct mutex device_lock;	/* for "atomic" device accesses */
+	struct mutex update_lock;
 	unsigned long next_update;
 	int vref_cached;
-	bool ref_is_vdd;
 	struct device *hwmon_dev;
 };
 
@@ -142,18 +142,18 @@ static ssize_t adt7411_show_input(struct device *dev,
 	int val;
 	u8 lsb_reg, lsb_shift;
 
+	mutex_lock(&data->update_lock);
 	if (time_after_eq(jiffies, data->next_update)) {
 		val = i2c_smbus_read_byte_data(client, ADT7411_REG_CFG3);
 		if (val < 0)
-			return val;
-		data->ref_is_vdd = val & ADT7411_CFG3_REF_VDD;
+			goto exit_unlock;
 
-		if (data->ref_is_vdd) {
+		if (val & ADT7411_CFG3_REF_VDD) {
 			val = adt7411_read_10_bit(client,
 					ADT7411_REG_INT_TEMP_VDD_LSB,
 					ADT7411_REG_VDD_MSB, 2);
 			if (val < 0)
-				return val;
+				goto exit_unlock;
 
 			data->vref_cached = val * 7000 / 1024;
 		} else {
@@ -167,9 +167,13 @@ static ssize_t adt7411_show_input(struct device *dev,
 	lsb_shift = 2 * (nr & 0x03);
 	val = adt7411_read_10_bit(client, lsb_reg,
 			ADT7411_REG_EXT_TEMP_AIN1_MSB + nr, lsb_shift);
+	if (val < 0)
+		goto exit_unlock;
 
-	return val < 0 ? val :
-			sprintf(buf, "%u\n", val * data->vref_cached / 1024);
+	val = sprintf(buf, "%u\n", val * data->vref_cached / 1024);
+ exit_unlock:
+	mutex_unlock(&data->update_lock);
+	return val;
 }
 
 static ssize_t adt7411_show_bit(struct device *dev,
@@ -198,7 +202,9 @@ static ssize_t adt7411_set_bit(struct device *dev, struct device_attribute *attr
 	ret = adt7411_modify_bit(client, s_attr2->index, s_attr2->nr, flag);
 
 	/* force update */
+	mutex_lock(&data->update_lock);
 	data->next_update = jiffies;
+	mutex_unlock(&data->update_lock);
 
 	return ret < 0 ? ret : count;
 }
@@ -280,6 +286,7 @@ static int __devinit adt7411_probe(struct i2c_client *client,
 
 	i2c_set_clientdata(client, data);
 	mutex_init(&data->device_lock);
+	mutex_init(&data->update_lock);
 
 	ret = adt7411_modify_bit(client, ADT7411_REG_CFG1,
 				 ADT7411_CFG1_START_MONITOR, 1);
-- 
1.6.5


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

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [lm-sensors] [PATCH] hwmon/adt7411: improve locking
  2010-02-18 17:14 [lm-sensors] [PATCH] hwmon/adt7411: improve locking Wolfram Sang
@ 2010-02-21  9:56 ` Jean Delvare
  2010-02-21 10:10 ` Wolfram Sang
  1 sibling, 0 replies; 3+ messages in thread
From: Jean Delvare @ 2010-02-21  9:56 UTC (permalink / raw)
  To: lm-sensors

On Thu, 18 Feb 2010 18:14:38 +0100, Wolfram Sang wrote:
> Add proper locking for the cached variables. Also get rid of ref_is_vdd, which
> became obsolete.
> 
> Signed-off-by: Wolfram Sang <w.sang@pengutronix.de>
> Cc: Jean Delvare <khali@linux-fr.org>

Yes, exactly what I had in mind. Patch applied, thanks.

> ---
>  drivers/hwmon/adt7411.c |   21 ++++++++++++++-------
>  1 files changed, 14 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/hwmon/adt7411.c b/drivers/hwmon/adt7411.c
> index 2a86314..05b34b1 100644
> --- a/drivers/hwmon/adt7411.c
> +++ b/drivers/hwmon/adt7411.c
> @@ -48,9 +48,9 @@ static const unsigned short normal_i2c[] = { 0x48, 0x4a, 0x4b, I2C_CLIENT_END };
>  
>  struct adt7411_data {
>  	struct mutex device_lock;	/* for "atomic" device accesses */
> +	struct mutex update_lock;
>  	unsigned long next_update;
>  	int vref_cached;
> -	bool ref_is_vdd;
>  	struct device *hwmon_dev;
>  };
>  
> @@ -142,18 +142,18 @@ static ssize_t adt7411_show_input(struct device *dev,
>  	int val;
>  	u8 lsb_reg, lsb_shift;
>  
> +	mutex_lock(&data->update_lock);
>  	if (time_after_eq(jiffies, data->next_update)) {
>  		val = i2c_smbus_read_byte_data(client, ADT7411_REG_CFG3);
>  		if (val < 0)
> -			return val;
> -		data->ref_is_vdd = val & ADT7411_CFG3_REF_VDD;
> +			goto exit_unlock;
>  
> -		if (data->ref_is_vdd) {
> +		if (val & ADT7411_CFG3_REF_VDD) {
>  			val = adt7411_read_10_bit(client,
>  					ADT7411_REG_INT_TEMP_VDD_LSB,
>  					ADT7411_REG_VDD_MSB, 2);
>  			if (val < 0)
> -				return val;
> +				goto exit_unlock;
>  
>  			data->vref_cached = val * 7000 / 1024;
>  		} else {
> @@ -167,9 +167,13 @@ static ssize_t adt7411_show_input(struct device *dev,
>  	lsb_shift = 2 * (nr & 0x03);
>  	val = adt7411_read_10_bit(client, lsb_reg,
>  			ADT7411_REG_EXT_TEMP_AIN1_MSB + nr, lsb_shift);
> +	if (val < 0)
> +		goto exit_unlock;
>  
> -	return val < 0 ? val :
> -			sprintf(buf, "%u\n", val * data->vref_cached / 1024);
> +	val = sprintf(buf, "%u\n", val * data->vref_cached / 1024);
> + exit_unlock:
> +	mutex_unlock(&data->update_lock);
> +	return val;
>  }
>  
>  static ssize_t adt7411_show_bit(struct device *dev,
> @@ -198,7 +202,9 @@ static ssize_t adt7411_set_bit(struct device *dev, struct device_attribute *attr
>  	ret = adt7411_modify_bit(client, s_attr2->index, s_attr2->nr, flag);
>  
>  	/* force update */
> +	mutex_lock(&data->update_lock);
>  	data->next_update = jiffies;
> +	mutex_unlock(&data->update_lock);
>  
>  	return ret < 0 ? ret : count;
>  }
> @@ -280,6 +286,7 @@ static int __devinit adt7411_probe(struct i2c_client *client,
>  
>  	i2c_set_clientdata(client, data);
>  	mutex_init(&data->device_lock);
> +	mutex_init(&data->update_lock);
>  
>  	ret = adt7411_modify_bit(client, ADT7411_REG_CFG1,
>  				 ADT7411_CFG1_START_MONITOR, 1);


-- 
Jean Delvare

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [lm-sensors] [PATCH] hwmon/adt7411: improve locking
  2010-02-18 17:14 [lm-sensors] [PATCH] hwmon/adt7411: improve locking Wolfram Sang
  2010-02-21  9:56 ` Jean Delvare
@ 2010-02-21 10:10 ` Wolfram Sang
  1 sibling, 0 replies; 3+ messages in thread
From: Wolfram Sang @ 2010-02-21 10:10 UTC (permalink / raw)
  To: lm-sensors


[-- Attachment #1.1: Type: text/plain, Size: 259 bytes --]

> Yes, exactly what I had in mind. Patch applied, thanks.

\o/ Finally! Now, to the next task...

-- 
Pengutronix e.K.                           | Wolfram Sang                |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |

[-- Attachment #1.2: Digital signature --]
[-- Type: application/pgp-signature, Size: 197 bytes --]

[-- Attachment #2: Type: text/plain, Size: 153 bytes --]

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2010-02-21 10:10 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-02-18 17:14 [lm-sensors] [PATCH] hwmon/adt7411: improve locking Wolfram Sang
2010-02-21  9:56 ` Jean Delvare
2010-02-21 10:10 ` Wolfram Sang

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.