]> err.no Git - linux-2.6/blobdiff - drivers/w1/slaves/w1_therm.c
Merge branch 'dmapool' of git://git.kernel.org/pub/scm/linux/kernel/git/willy/misc
[linux-2.6] / drivers / w1 / slaves / w1_therm.c
index 536d16d78de75ce313fa7f4f2b394e2617f4033e..112f4ec59035424bc36b7251fcb6367c9bca7f77 100644 (file)
 #include <linux/kernel.h>
 #include <linux/module.h>
 #include <linux/moduleparam.h>
+#include <linux/sched.h>
 #include <linux/device.h>
 #include <linux/types.h>
 #include <linux/delay.h>
 
 #include "../w1.h"
-#include "../w1_io.h"
 #include "../w1_int.h"
 #include "../w1_family.h"
 
@@ -42,13 +42,13 @@ static u8 bad_roms[][9] = {
                                {}
                        };
 
-static ssize_t w1_therm_read_bin(struct kobject *, char *, loff_t, size_t);
+static ssize_t w1_therm_read_bin(struct kobject *, struct bin_attribute *,
+                                char *, loff_t, size_t);
 
 static struct bin_attribute w1_therm_bin_attr = {
        .attr = {
                .name = "w1_slave",
                .mode = S_IRUGO,
-               .owner = THIS_MODULE,
        },
        .size = W1_SLAVE_DATA_SIZE,
        .read = w1_therm_read_bin,
@@ -112,7 +112,7 @@ static struct w1_therm_family_converter w1_therm_families[] = {
 
 static inline int w1_DS18B20_convert_temp(u8 rom[9])
 {
-       int t = (rom[1] << 8) | rom[0];
+       s16 t = (rom[1] << 8) | rom[0];
        t /= 16;
        return t;
 }
@@ -141,7 +141,7 @@ static inline int w1_convert_temp(u8 rom[9], u8 fid)
 {
        int i;
 
-       for (i=0; i<sizeof(w1_therm_families)/sizeof(w1_therm_families[0]); ++i)
+       for (i = 0; i < ARRAY_SIZE(w1_therm_families); ++i)
                if (w1_therm_families[i].f->fid == fid)
                        return w1_therm_families[i].convert(rom);
 
@@ -159,19 +159,16 @@ static int w1_therm_check_rom(u8 rom[9])
        return 0;
 }
 
-static ssize_t w1_therm_read_bin(struct kobject *kobj, char *buf, loff_t off, size_t count)
+static ssize_t w1_therm_read_bin(struct kobject *kobj,
+                                struct bin_attribute *bin_attr,
+                                char *buf, loff_t off, size_t count)
 {
        struct w1_slave *sl = kobj_to_w1_slave(kobj);
        struct w1_master *dev = sl->master;
        u8 rom[9], crc, verdict;
        int i, max_trying = 10;
 
-       atomic_inc(&sl->refcnt);
-       smp_mb__after_atomic_inc();
-       if (down_interruptible(&sl->master->mutex)) {
-               count = 0;
-               goto out_dec;
-       }
+       mutex_lock(&sl->master->mutex);
 
        if (off > W1_SLAVE_DATA_SIZE) {
                count = 0;
@@ -196,11 +193,7 @@ static ssize_t w1_therm_read_bin(struct kobject *kobj, char *buf, loff_t off, si
 
                        w1_write_8(dev, W1_CONVERT_TEMP);
 
-                       while (tm) {
-                               tm = msleep_interruptible(tm);
-                               if (signal_pending(current))
-                                       flush_signals(current);
-                       }
+                       msleep(tm);
 
                        if (!w1_reset_select_slave(sl)) {
 
@@ -211,7 +204,7 @@ static ssize_t w1_therm_read_bin(struct kobject *kobj, char *buf, loff_t off, si
 
                                crc = w1_calc_crc8(rom, 8);
 
-                               if (rom[8] == crc && rom[0])
+                               if (rom[8] == crc)
                                        verdict = 1;
                        }
                }
@@ -234,10 +227,7 @@ 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:
-       up(&dev->mutex);
-out_dec:
-       smp_mb__before_atomic_inc();
-       atomic_dec(&sl->refcnt);
+       mutex_unlock(&dev->mutex);
 
        return count;
 }
@@ -246,7 +236,7 @@ static int __init w1_therm_init(void)
 {
        int err, i;
 
-       for (i=0; i<sizeof(w1_therm_families)/sizeof(w1_therm_families[0]); ++i) {
+       for (i = 0; i < ARRAY_SIZE(w1_therm_families); ++i) {
                err = w1_register_family(w1_therm_families[i].f);
                if (err)
                        w1_therm_families[i].broken = 1;
@@ -259,7 +249,7 @@ static void __exit w1_therm_fini(void)
 {
        int i;
 
-       for (i=0; i<sizeof(w1_therm_families)/sizeof(w1_therm_families[0]); ++i)
+       for (i = 0; i < ARRAY_SIZE(w1_therm_families); ++i)
                if (!w1_therm_families[i].broken)
                        w1_unregister_family(w1_therm_families[i].f);
 }