aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/w1/slaves/w1_ds2408.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_ds2408.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_ds2408.c')
-rw-r--r--drivers/w1/slaves/w1_ds2408.c24
1 files changed, 12 insertions, 12 deletions
diff --git a/drivers/w1/slaves/w1_ds2408.c b/drivers/w1/slaves/w1_ds2408.c
index 8e813eed0f0..441ad3a3b58 100644
--- a/drivers/w1/slaves/w1_ds2408.c
+++ b/drivers/w1/slaves/w1_ds2408.c
@@ -52,11 +52,11 @@ static int _read_reg(struct w1_slave *sl, u8 address, unsigned char* buf)
52 if (!buf) 52 if (!buf)
53 return -EINVAL; 53 return -EINVAL;
54 54
55 mutex_lock(&sl->master->mutex); 55 mutex_lock(&sl->master->bus_mutex);
56 dev_dbg(&sl->dev, "mutex locked"); 56 dev_dbg(&sl->dev, "mutex locked");
57 57
58 if (w1_reset_select_slave(sl)) { 58 if (w1_reset_select_slave(sl)) {
59 mutex_unlock(&sl->master->mutex); 59 mutex_unlock(&sl->master->bus_mutex);
60 return -EIO; 60 return -EIO;
61 } 61 }
62 62
@@ -66,7 +66,7 @@ static int _read_reg(struct w1_slave *sl, u8 address, unsigned char* buf)
66 w1_write_block(sl->master, wrbuf, 3); 66 w1_write_block(sl->master, wrbuf, 3);
67 *buf = w1_read_8(sl->master); 67 *buf = w1_read_8(sl->master);
68 68
69 mutex_unlock(&sl->master->mutex); 69 mutex_unlock(&sl->master->bus_mutex);
70 dev_dbg(&sl->dev, "mutex unlocked"); 70 dev_dbg(&sl->dev, "mutex unlocked");
71 return 1; 71 return 1;
72} 72}
@@ -165,7 +165,7 @@ static ssize_t w1_f29_write_output(
165 return -EFAULT; 165 return -EFAULT;
166 166
167 dev_dbg(&sl->dev, "locking mutex for write_output"); 167 dev_dbg(&sl->dev, "locking mutex for write_output");
168 mutex_lock(&sl->master->mutex); 168 mutex_lock(&sl->master->bus_mutex);
169 dev_dbg(&sl->dev, "mutex locked"); 169 dev_dbg(&sl->dev, "mutex locked");
170 170
171 if (w1_reset_select_slave(sl)) 171 if (w1_reset_select_slave(sl))
@@ -200,14 +200,14 @@ static ssize_t w1_f29_write_output(
200 /* read the result of the READ_PIO_REGS command */ 200 /* read the result of the READ_PIO_REGS command */
201 if (w1_read_8(sl->master) == *buf) { 201 if (w1_read_8(sl->master) == *buf) {
202 /* success! */ 202 /* success! */
203 mutex_unlock(&sl->master->mutex); 203 mutex_unlock(&sl->master->bus_mutex);
204 dev_dbg(&sl->dev, 204 dev_dbg(&sl->dev,
205 "mutex unlocked, retries:%d", retries); 205 "mutex unlocked, retries:%d", retries);
206 return 1; 206 return 1;
207 } 207 }
208 } 208 }
209error: 209error:
210 mutex_unlock(&sl->master->mutex); 210 mutex_unlock(&sl->master->bus_mutex);
211 dev_dbg(&sl->dev, "mutex unlocked in error, retries:%d", retries); 211 dev_dbg(&sl->dev, "mutex unlocked in error, retries:%d", retries);
212 212
213 return -EIO; 213 return -EIO;
@@ -228,7 +228,7 @@ static ssize_t w1_f29_write_activity(
228 if (count != 1 || off != 0) 228 if (count != 1 || off != 0)
229 return -EFAULT; 229 return -EFAULT;
230 230
231 mutex_lock(&sl->master->mutex); 231 mutex_lock(&sl->master->bus_mutex);
232 232
233 if (w1_reset_select_slave(sl)) 233 if (w1_reset_select_slave(sl))
234 goto error; 234 goto error;
@@ -236,7 +236,7 @@ static ssize_t w1_f29_write_activity(
236 while (retries--) { 236 while (retries--) {
237 w1_write_8(sl->master, W1_F29_FUNC_RESET_ACTIVITY_LATCHES); 237 w1_write_8(sl->master, W1_F29_FUNC_RESET_ACTIVITY_LATCHES);
238 if (w1_read_8(sl->master) == W1_F29_SUCCESS_CONFIRM_BYTE) { 238 if (w1_read_8(sl->master) == W1_F29_SUCCESS_CONFIRM_BYTE) {
239 mutex_unlock(&sl->master->mutex); 239 mutex_unlock(&sl->master->bus_mutex);
240 return 1; 240 return 1;
241 } 241 }
242 if (w1_reset_resume_command(sl->master)) 242 if (w1_reset_resume_command(sl->master))
@@ -244,7 +244,7 @@ static ssize_t w1_f29_write_activity(
244 } 244 }
245 245
246error: 246error:
247 mutex_unlock(&sl->master->mutex); 247 mutex_unlock(&sl->master->bus_mutex);
248 return -EIO; 248 return -EIO;
249} 249}
250 250
@@ -263,7 +263,7 @@ static ssize_t w1_f29_write_status_control(
263 if (count != 1 || off != 0) 263 if (count != 1 || off != 0)
264 return -EFAULT; 264 return -EFAULT;
265 265
266 mutex_lock(&sl->master->mutex); 266 mutex_lock(&sl->master->bus_mutex);
267 267
268 if (w1_reset_select_slave(sl)) 268 if (w1_reset_select_slave(sl))
269 goto error; 269 goto error;
@@ -285,12 +285,12 @@ static ssize_t w1_f29_write_status_control(
285 w1_write_block(sl->master, w1_buf, 3); 285 w1_write_block(sl->master, w1_buf, 3);
286 if (w1_read_8(sl->master) == *buf) { 286 if (w1_read_8(sl->master) == *buf) {
287 /* success! */ 287 /* success! */
288 mutex_unlock(&sl->master->mutex); 288 mutex_unlock(&sl->master->bus_mutex);
289 return 1; 289 return 1;
290 } 290 }
291 } 291 }
292error: 292error:
293 mutex_unlock(&sl->master->mutex); 293 mutex_unlock(&sl->master->bus_mutex);
294 294
295 return -EIO; 295 return -EIO;
296} 296}