Revert to Fedora kernel-2.6.17-1.2187_FC5 patched with vs2.0.2.1; there are too many...
[linux-2.6.git] / drivers / w1 / slaves / w1_therm.c
index 5372cfc..536d16d 100644 (file)
@@ -29,6 +29,7 @@
 #include <linux/delay.h>
 
 #include "../w1.h"
+#include "../w1_io.h"
 #include "../w1_int.h"
 #include "../w1_family.h"
 
@@ -165,7 +166,12 @@ static ssize_t w1_therm_read_bin(struct kobject *kobj, char *buf, loff_t off, si
        u8 rom[9], crc, verdict;
        int i, max_trying = 10;
 
-       mutex_lock(&sl->master->mutex);
+       atomic_inc(&sl->refcnt);
+       smp_mb__after_atomic_inc();
+       if (down_interruptible(&sl->master->mutex)) {
+               count = 0;
+               goto out_dec;
+       }
 
        if (off > W1_SLAVE_DATA_SIZE) {
                count = 0;
@@ -228,7 +234,10 @@ static ssize_t w1_therm_read_bin(struct kobject *kobj, char *buf, loff_t off, si
 
        count += sprintf(buf + count, "t=%d\n", w1_convert_temp(rom, sl->family->fid));
 out:
-       mutex_unlock(&dev->mutex);
+       up(&dev->mutex);
+out_dec:
+       smp_mb__before_atomic_inc();
+       atomic_dec(&sl->refcnt);
 
        return count;
 }