w1: introduce a slave mutex for serializing IO
authorNeilBrown <neilb@suse.de>
Tue, 1 May 2012 18:49:24 +0000 (11:49 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 12 Jun 2012 22:27:32 +0000 (15:27 -0700)
w1 devices need a mutex to serial IO.  Most use master->mutex.
However that is used for other purposes and they can conflict.

In particular master->mutex is held while w1_attach_slave_device is
called.

For bq27000, this registers a 'powersupply' device which tries to read the
current status.  The attempt to read will cause a deadlock on
master->mutex.

So create a new per-slave mutex and use that for serializing IO for
bq27000.

Signed-off-by: NeilBrown <neilb@suse.de>
Cc: Evgeniy Polyakov <zbr@ioremap.net>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/w1/slaves/w1_bq27000.c
drivers/w1/w1.c
drivers/w1/w1.h

index 52ad812fa1e7e73c8bc07545b82e967c73ff6a50..87554788fa32f963be93ab2f22103dff3f162ca5 100644 (file)
@@ -31,10 +31,10 @@ static int w1_bq27000_read(struct device *dev, unsigned int reg)
        u8 val;
        struct w1_slave *sl = container_of(dev->parent, struct w1_slave, dev);
 
-       mutex_lock(&sl->master->mutex);
+       mutex_lock(&sl->mutex);
        w1_write_8(sl->master, HDQ_CMD_READ | reg);
        val = w1_read_8(sl->master);
-       mutex_unlock(&sl->master->mutex);
+       mutex_unlock(&sl->mutex);
 
        return val;
 }
index 2f2e894ea0c84e23392db10c0fb4e46b25b00ab3..69075c3dfc737289023a38973ff944671de2545a 100644 (file)
@@ -688,6 +688,7 @@ static int w1_attach_slave_device(struct w1_master *dev, struct w1_reg_num *rn)
        memcpy(&sl->reg_num, rn, sizeof(sl->reg_num));
        atomic_set(&sl->refcnt, 0);
        init_completion(&sl->released);
+       mutex_init(&sl->mutex);
 
        spin_lock(&w1_flock);
        f = w1_family_registered(rn->family);
index 4d012ca3f32c42a27c2ccd54b9b506907abd597e..8c8be380a98a3bda388a22284a401b7756aaa2f1 100644 (file)
@@ -75,6 +75,7 @@ struct w1_slave
        void                    *family_data;
        struct device           dev;
        struct completion       released;
+       struct mutex            mutex;
 };
 
 typedef void (*w1_slave_found_callback)(struct w1_master *, u64);