aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/w1/slaves/w1_therm.c
diff options
context:
space:
mode:
authorNeilBrown <neilb@suse.de>2012-05-18 01:59:52 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2012-06-13 19:38:40 -0400
commitb02f8bede217a4b145ecc16d3940c78d83941147 (patch)
treecbd02191cc2698c460b9abedea44de13855510c6 /drivers/w1/slaves/w1_therm.c
parentb7e938d06d0de43bdbee8844a8736c81480c1031 (diff)
W1: split master mutex to avoid deadlocks.
The 'mutex' in struct w1_master is use for two very different purposes. Firstly it protects various data structures such as the list of all slaves. Secondly it protects the w1 buss against concurrent accesses. This can lead to deadlocks when the ->probe code called while adding a slave needs to talk on the bus, as is the case for power_supply devices. ds2780 and ds2781 drivers contain a work around to track which process hold the lock simply to avoid this deadlock. bq27000 doesn't have that work around and so deadlocks. There are other possible deadlocks involving sysfs. When removing a device the sysfs s_active lock is held, so the lock that protects the slave list must take precedence over s_active. However when access power_supply attributes via sysfs, the s_active lock must take precedence over the lock that protects accesses to the bus. So to avoid deadlocks between w1 slaves and sysfs, these must be two separate locks. Making them separate means that the work around in ds2780 and ds2781 can be removed. So this patch: - adds a new mutex: "bus_mutex" which serialises access to the bus. - takes in mutex in w1_search and ds1wm_search while they access the bus for searching. The mutex is dropped before calling the callback which adds the slave. - changes all slaves to use bus_mutex instead of mutex to protect access to the bus - removes w1_ds2790_io_nolock and w1_ds2781_io_nolock, and the related code from drivers/power/ds278[01]_battery.c which calls them. Signed-off-by: NeilBrown <neilb@suse.de> Acked-by: Evgeniy Polyakov <zbr@ioremap.net> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/w1/slaves/w1_therm.c')
-rw-r--r--drivers/w1/slaves/w1_therm.c10
1 files changed, 5 insertions, 5 deletions
diff --git a/drivers/w1/slaves/w1_therm.c b/drivers/w1/slaves/w1_therm.c
index ff29ae747ee8..d90062b211f8 100644
--- a/drivers/w1/slaves/w1_therm.c
+++ b/drivers/w1/slaves/w1_therm.c
@@ -179,7 +179,7 @@ static ssize_t w1_therm_read(struct device *device,
179 int i, max_trying = 10; 179 int i, max_trying = 10;
180 ssize_t c = PAGE_SIZE; 180 ssize_t c = PAGE_SIZE;
181 181
182 i = mutex_lock_interruptible(&dev->mutex); 182 i = mutex_lock_interruptible(&dev->bus_mutex);
183 if (i != 0) 183 if (i != 0)
184 return i; 184 return i;
185 185
@@ -207,19 +207,19 @@ static ssize_t w1_therm_read(struct device *device,
207 w1_write_8(dev, W1_CONVERT_TEMP); 207 w1_write_8(dev, W1_CONVERT_TEMP);
208 208
209 if (external_power) { 209 if (external_power) {
210 mutex_unlock(&dev->mutex); 210 mutex_unlock(&dev->bus_mutex);
211 211
212 sleep_rem = msleep_interruptible(tm); 212 sleep_rem = msleep_interruptible(tm);
213 if (sleep_rem != 0) 213 if (sleep_rem != 0)
214 return -EINTR; 214 return -EINTR;
215 215
216 i = mutex_lock_interruptible(&dev->mutex); 216 i = mutex_lock_interruptible(&dev->bus_mutex);
217 if (i != 0) 217 if (i != 0)
218 return i; 218 return i;
219 } else if (!w1_strong_pullup) { 219 } else if (!w1_strong_pullup) {
220 sleep_rem = msleep_interruptible(tm); 220 sleep_rem = msleep_interruptible(tm);
221 if (sleep_rem != 0) { 221 if (sleep_rem != 0) {
222 mutex_unlock(&dev->mutex); 222 mutex_unlock(&dev->bus_mutex);
223 return -EINTR; 223 return -EINTR;
224 } 224 }
225 } 225 }
@@ -258,7 +258,7 @@ static ssize_t w1_therm_read(struct device *device,
258 258
259 c -= snprintf(buf + PAGE_SIZE - c, c, "t=%d\n", 259 c -= snprintf(buf + PAGE_SIZE - c, c, "t=%d\n",
260 w1_convert_temp(rom, sl->family->fid)); 260 w1_convert_temp(rom, sl->family->fid));
261 mutex_unlock(&dev->mutex); 261 mutex_unlock(&dev->bus_mutex);
262 262
263 return PAGE_SIZE - c; 263 return PAGE_SIZE - c;
264} 264}