diff options
author | Evgeniy Polyakov <johnpol@2ka.mipt.ru> | 2006-04-03 04:04:27 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@suse.de> | 2006-06-22 14:22:50 -0400 |
commit | abd52a13206e02537ca1dc08fc5438c7d27bdbf1 (patch) | |
tree | efe0ff89898aad10600d392ac727dcea9e7af322 /drivers/w1/w1.c | |
parent | 46e07f6e5eb0e465e086b8f485f4238bd453e3e9 (diff) |
[PATCH] w1: Use mutexes instead of semaphores.
Use mutexes instead of semaphores.
Patch tested on x86_64 and i386 with test bus master driver.
Signed-off-by: Evgeniy Polyakov <johnpol@2ka.mipt.ru>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/w1/w1.c')
-rw-r--r-- | drivers/w1/w1.c | 114 |
1 files changed, 39 insertions, 75 deletions
diff --git a/drivers/w1/w1.c b/drivers/w1/w1.c index 32d8de881f11..420be14c2f8e 100644 --- a/drivers/w1/w1.c +++ b/drivers/w1/w1.c | |||
@@ -54,7 +54,7 @@ module_param_named(control_timeout, w1_control_timeout, int, 0); | |||
54 | module_param_named(max_slave_count, w1_max_slave_count, int, 0); | 54 | module_param_named(max_slave_count, w1_max_slave_count, int, 0); |
55 | module_param_named(slave_ttl, w1_max_slave_ttl, int, 0); | 55 | module_param_named(slave_ttl, w1_max_slave_ttl, int, 0); |
56 | 56 | ||
57 | DECLARE_MUTEX(w1_mlock); | 57 | DEFINE_MUTEX(w1_mlock); |
58 | LIST_HEAD(w1_masters); | 58 | LIST_HEAD(w1_masters); |
59 | 59 | ||
60 | static struct task_struct *w1_control_thread; | 60 | static struct task_struct *w1_control_thread; |
@@ -139,11 +139,7 @@ static ssize_t w1_default_write(struct kobject *kobj, char *buf, loff_t off, siz | |||
139 | { | 139 | { |
140 | struct w1_slave *sl = kobj_to_w1_slave(kobj); | 140 | struct w1_slave *sl = kobj_to_w1_slave(kobj); |
141 | 141 | ||
142 | if (down_interruptible(&sl->master->mutex)) { | 142 | mutex_lock(&sl->master->mutex); |
143 | count = 0; | ||
144 | goto out; | ||
145 | } | ||
146 | |||
147 | if (w1_reset_select_slave(sl)) { | 143 | if (w1_reset_select_slave(sl)) { |
148 | count = 0; | 144 | count = 0; |
149 | goto out_up; | 145 | goto out_up; |
@@ -152,8 +148,7 @@ static ssize_t w1_default_write(struct kobject *kobj, char *buf, loff_t off, siz | |||
152 | w1_write_block(sl->master, buf, count); | 148 | w1_write_block(sl->master, buf, count); |
153 | 149 | ||
154 | out_up: | 150 | out_up: |
155 | up(&sl->master->mutex); | 151 | mutex_unlock(&sl->master->mutex); |
156 | out: | ||
157 | return count; | 152 | return count; |
158 | } | 153 | } |
159 | 154 | ||
@@ -161,15 +156,9 @@ static ssize_t w1_default_read(struct kobject *kobj, char *buf, loff_t off, size | |||
161 | { | 156 | { |
162 | struct w1_slave *sl = kobj_to_w1_slave(kobj); | 157 | struct w1_slave *sl = kobj_to_w1_slave(kobj); |
163 | 158 | ||
164 | if (down_interruptible(&sl->master->mutex)) { | 159 | mutex_lock(&sl->master->mutex); |
165 | count = 0; | ||
166 | goto out; | ||
167 | } | ||
168 | |||
169 | w1_read_block(sl->master, buf, count); | 160 | w1_read_block(sl->master, buf, count); |
170 | 161 | mutex_unlock(&sl->master->mutex); | |
171 | up(&sl->master->mutex); | ||
172 | out: | ||
173 | return count; | 162 | return count; |
174 | } | 163 | } |
175 | 164 | ||
@@ -243,12 +232,9 @@ static ssize_t w1_master_attribute_show_name(struct device *dev, struct device_a | |||
243 | struct w1_master *md = dev_to_w1_master(dev); | 232 | struct w1_master *md = dev_to_w1_master(dev); |
244 | ssize_t count; | 233 | ssize_t count; |
245 | 234 | ||
246 | if (down_interruptible (&md->mutex)) | 235 | mutex_lock(&md->mutex); |
247 | return -EBUSY; | ||
248 | |||
249 | count = sprintf(buf, "%s\n", md->name); | 236 | count = sprintf(buf, "%s\n", md->name); |
250 | 237 | mutex_unlock(&md->mutex); | |
251 | up(&md->mutex); | ||
252 | 238 | ||
253 | return count; | 239 | return count; |
254 | } | 240 | } |
@@ -259,12 +245,9 @@ static ssize_t w1_master_attribute_store_search(struct device * dev, | |||
259 | { | 245 | { |
260 | struct w1_master *md = dev_to_w1_master(dev); | 246 | struct w1_master *md = dev_to_w1_master(dev); |
261 | 247 | ||
262 | if (down_interruptible (&md->mutex)) | 248 | mutex_lock(&md->mutex); |
263 | return -EBUSY; | ||
264 | |||
265 | md->search_count = simple_strtol(buf, NULL, 0); | 249 | md->search_count = simple_strtol(buf, NULL, 0); |
266 | 250 | mutex_unlock(&md->mutex); | |
267 | up(&md->mutex); | ||
268 | 251 | ||
269 | return count; | 252 | return count; |
270 | } | 253 | } |
@@ -276,12 +259,9 @@ static ssize_t w1_master_attribute_show_search(struct device *dev, | |||
276 | struct w1_master *md = dev_to_w1_master(dev); | 259 | struct w1_master *md = dev_to_w1_master(dev); |
277 | ssize_t count; | 260 | ssize_t count; |
278 | 261 | ||
279 | if (down_interruptible (&md->mutex)) | 262 | mutex_lock(&md->mutex); |
280 | return -EBUSY; | ||
281 | |||
282 | count = sprintf(buf, "%d\n", md->search_count); | 263 | count = sprintf(buf, "%d\n", md->search_count); |
283 | 264 | mutex_unlock(&md->mutex); | |
284 | up(&md->mutex); | ||
285 | 265 | ||
286 | return count; | 266 | return count; |
287 | } | 267 | } |
@@ -291,12 +271,9 @@ static ssize_t w1_master_attribute_show_pointer(struct device *dev, struct devic | |||
291 | struct w1_master *md = dev_to_w1_master(dev); | 271 | struct w1_master *md = dev_to_w1_master(dev); |
292 | ssize_t count; | 272 | ssize_t count; |
293 | 273 | ||
294 | if (down_interruptible(&md->mutex)) | 274 | mutex_lock(&md->mutex); |
295 | return -EBUSY; | ||
296 | |||
297 | count = sprintf(buf, "0x%p\n", md->bus_master); | 275 | count = sprintf(buf, "0x%p\n", md->bus_master); |
298 | 276 | mutex_unlock(&md->mutex); | |
299 | up(&md->mutex); | ||
300 | return count; | 277 | return count; |
301 | } | 278 | } |
302 | 279 | ||
@@ -312,12 +289,9 @@ static ssize_t w1_master_attribute_show_max_slave_count(struct device *dev, stru | |||
312 | struct w1_master *md = dev_to_w1_master(dev); | 289 | struct w1_master *md = dev_to_w1_master(dev); |
313 | ssize_t count; | 290 | ssize_t count; |
314 | 291 | ||
315 | if (down_interruptible(&md->mutex)) | 292 | mutex_lock(&md->mutex); |
316 | return -EBUSY; | ||
317 | |||
318 | count = sprintf(buf, "%d\n", md->max_slave_count); | 293 | count = sprintf(buf, "%d\n", md->max_slave_count); |
319 | 294 | mutex_unlock(&md->mutex); | |
320 | up(&md->mutex); | ||
321 | return count; | 295 | return count; |
322 | } | 296 | } |
323 | 297 | ||
@@ -326,12 +300,9 @@ static ssize_t w1_master_attribute_show_attempts(struct device *dev, struct devi | |||
326 | struct w1_master *md = dev_to_w1_master(dev); | 300 | struct w1_master *md = dev_to_w1_master(dev); |
327 | ssize_t count; | 301 | ssize_t count; |
328 | 302 | ||
329 | if (down_interruptible(&md->mutex)) | 303 | mutex_lock(&md->mutex); |
330 | return -EBUSY; | ||
331 | |||
332 | count = sprintf(buf, "%lu\n", md->attempts); | 304 | count = sprintf(buf, "%lu\n", md->attempts); |
333 | 305 | mutex_unlock(&md->mutex); | |
334 | up(&md->mutex); | ||
335 | return count; | 306 | return count; |
336 | } | 307 | } |
337 | 308 | ||
@@ -340,12 +311,9 @@ static ssize_t w1_master_attribute_show_slave_count(struct device *dev, struct d | |||
340 | struct w1_master *md = dev_to_w1_master(dev); | 311 | struct w1_master *md = dev_to_w1_master(dev); |
341 | ssize_t count; | 312 | ssize_t count; |
342 | 313 | ||
343 | if (down_interruptible(&md->mutex)) | 314 | mutex_lock(&md->mutex); |
344 | return -EBUSY; | ||
345 | |||
346 | count = sprintf(buf, "%d\n", md->slave_count); | 315 | count = sprintf(buf, "%d\n", md->slave_count); |
347 | 316 | mutex_unlock(&md->mutex); | |
348 | up(&md->mutex); | ||
349 | return count; | 317 | return count; |
350 | } | 318 | } |
351 | 319 | ||
@@ -354,8 +322,7 @@ static ssize_t w1_master_attribute_show_slaves(struct device *dev, struct device | |||
354 | struct w1_master *md = dev_to_w1_master(dev); | 322 | struct w1_master *md = dev_to_w1_master(dev); |
355 | int c = PAGE_SIZE; | 323 | int c = PAGE_SIZE; |
356 | 324 | ||
357 | if (down_interruptible(&md->mutex)) | 325 | mutex_lock(&md->mutex); |
358 | return -EBUSY; | ||
359 | 326 | ||
360 | if (md->slave_count == 0) | 327 | if (md->slave_count == 0) |
361 | c -= snprintf(buf + PAGE_SIZE - c, c, "not found.\n"); | 328 | c -= snprintf(buf + PAGE_SIZE - c, c, "not found.\n"); |
@@ -370,7 +337,7 @@ static ssize_t w1_master_attribute_show_slaves(struct device *dev, struct device | |||
370 | } | 337 | } |
371 | } | 338 | } |
372 | 339 | ||
373 | up(&md->mutex); | 340 | mutex_unlock(&md->mutex); |
374 | 341 | ||
375 | return PAGE_SIZE - c; | 342 | return PAGE_SIZE - c; |
376 | } | 343 | } |
@@ -620,7 +587,7 @@ static struct w1_master *w1_search_master(void *data) | |||
620 | struct w1_master *dev; | 587 | struct w1_master *dev; |
621 | int found = 0; | 588 | int found = 0; |
622 | 589 | ||
623 | down(&w1_mlock); | 590 | mutex_lock(&w1_mlock); |
624 | list_for_each_entry(dev, &w1_masters, w1_master_entry) { | 591 | list_for_each_entry(dev, &w1_masters, w1_master_entry) { |
625 | if (dev->bus_master->data == data) { | 592 | if (dev->bus_master->data == data) { |
626 | found = 1; | 593 | found = 1; |
@@ -628,7 +595,7 @@ static struct w1_master *w1_search_master(void *data) | |||
628 | break; | 595 | break; |
629 | } | 596 | } |
630 | } | 597 | } |
631 | up(&w1_mlock); | 598 | mutex_unlock(&w1_mlock); |
632 | 599 | ||
633 | return (found)?dev:NULL; | 600 | return (found)?dev:NULL; |
634 | } | 601 | } |
@@ -638,7 +605,7 @@ struct w1_master *w1_search_master_id(u32 id) | |||
638 | struct w1_master *dev; | 605 | struct w1_master *dev; |
639 | int found = 0; | 606 | int found = 0; |
640 | 607 | ||
641 | down(&w1_mlock); | 608 | mutex_lock(&w1_mlock); |
642 | list_for_each_entry(dev, &w1_masters, w1_master_entry) { | 609 | list_for_each_entry(dev, &w1_masters, w1_master_entry) { |
643 | if (dev->id == id) { | 610 | if (dev->id == id) { |
644 | found = 1; | 611 | found = 1; |
@@ -646,7 +613,7 @@ struct w1_master *w1_search_master_id(u32 id) | |||
646 | break; | 613 | break; |
647 | } | 614 | } |
648 | } | 615 | } |
649 | up(&w1_mlock); | 616 | mutex_unlock(&w1_mlock); |
650 | 617 | ||
651 | return (found)?dev:NULL; | 618 | return (found)?dev:NULL; |
652 | } | 619 | } |
@@ -657,9 +624,9 @@ struct w1_slave *w1_search_slave(struct w1_reg_num *id) | |||
657 | struct w1_slave *sl = NULL; | 624 | struct w1_slave *sl = NULL; |
658 | int found = 0; | 625 | int found = 0; |
659 | 626 | ||
660 | down(&w1_mlock); | 627 | mutex_lock(&w1_mlock); |
661 | list_for_each_entry(dev, &w1_masters, w1_master_entry) { | 628 | list_for_each_entry(dev, &w1_masters, w1_master_entry) { |
662 | down(&dev->mutex); | 629 | mutex_lock(&dev->mutex); |
663 | list_for_each_entry(sl, &dev->slist, w1_slave_entry) { | 630 | list_for_each_entry(sl, &dev->slist, w1_slave_entry) { |
664 | if (sl->reg_num.family == id->family && | 631 | if (sl->reg_num.family == id->family && |
665 | sl->reg_num.id == id->id && | 632 | sl->reg_num.id == id->id && |
@@ -670,12 +637,12 @@ struct w1_slave *w1_search_slave(struct w1_reg_num *id) | |||
670 | break; | 637 | break; |
671 | } | 638 | } |
672 | } | 639 | } |
673 | up(&dev->mutex); | 640 | mutex_unlock(&dev->mutex); |
674 | 641 | ||
675 | if (found) | 642 | if (found) |
676 | break; | 643 | break; |
677 | } | 644 | } |
678 | up(&w1_mlock); | 645 | mutex_unlock(&w1_mlock); |
679 | 646 | ||
680 | return (found)?sl:NULL; | 647 | return (found)?sl:NULL; |
681 | } | 648 | } |
@@ -684,13 +651,13 @@ void w1_reconnect_slaves(struct w1_family *f) | |||
684 | { | 651 | { |
685 | struct w1_master *dev; | 652 | struct w1_master *dev; |
686 | 653 | ||
687 | down(&w1_mlock); | 654 | mutex_lock(&w1_mlock); |
688 | list_for_each_entry(dev, &w1_masters, w1_master_entry) { | 655 | list_for_each_entry(dev, &w1_masters, w1_master_entry) { |
689 | dev_dbg(&dev->dev, "Reconnecting slaves in %s into new family %02x.\n", | 656 | dev_dbg(&dev->dev, "Reconnecting slaves in %s into new family %02x.\n", |
690 | dev->name, f->fid); | 657 | dev->name, f->fid); |
691 | set_bit(W1_MASTER_NEED_RECONNECT, &dev->flags); | 658 | set_bit(W1_MASTER_NEED_RECONNECT, &dev->flags); |
692 | } | 659 | } |
693 | up(&w1_mlock); | 660 | mutex_unlock(&w1_mlock); |
694 | } | 661 | } |
695 | 662 | ||
696 | static void w1_slave_found(void *data, u64 rn) | 663 | static void w1_slave_found(void *data, u64 rn) |
@@ -845,23 +812,23 @@ static int w1_control(void *data) | |||
845 | if (kthread_should_stop() || test_bit(W1_MASTER_NEED_EXIT, &dev->flags)) { | 812 | if (kthread_should_stop() || test_bit(W1_MASTER_NEED_EXIT, &dev->flags)) { |
846 | set_bit(W1_MASTER_NEED_EXIT, &dev->flags); | 813 | set_bit(W1_MASTER_NEED_EXIT, &dev->flags); |
847 | 814 | ||
848 | down(&w1_mlock); | 815 | mutex_lock(&w1_mlock); |
849 | list_del(&dev->w1_master_entry); | 816 | list_del(&dev->w1_master_entry); |
850 | up(&w1_mlock); | 817 | mutex_unlock(&w1_mlock); |
851 | 818 | ||
852 | down(&dev->mutex); | 819 | mutex_lock(&dev->mutex); |
853 | list_for_each_entry_safe(sl, sln, &dev->slist, w1_slave_entry) { | 820 | list_for_each_entry_safe(sl, sln, &dev->slist, w1_slave_entry) { |
854 | w1_slave_detach(sl); | 821 | w1_slave_detach(sl); |
855 | } | 822 | } |
856 | w1_destroy_master_attributes(dev); | 823 | w1_destroy_master_attributes(dev); |
857 | up(&dev->mutex); | 824 | mutex_unlock(&dev->mutex); |
858 | atomic_dec(&dev->refcnt); | 825 | atomic_dec(&dev->refcnt); |
859 | continue; | 826 | continue; |
860 | } | 827 | } |
861 | 828 | ||
862 | if (test_bit(W1_MASTER_NEED_RECONNECT, &dev->flags)) { | 829 | if (test_bit(W1_MASTER_NEED_RECONNECT, &dev->flags)) { |
863 | dev_dbg(&dev->dev, "Reconnecting slaves in device %s.\n", dev->name); | 830 | dev_dbg(&dev->dev, "Reconnecting slaves in device %s.\n", dev->name); |
864 | down(&dev->mutex); | 831 | mutex_lock(&dev->mutex); |
865 | list_for_each_entry_safe(sl, sln, &dev->slist, w1_slave_entry) { | 832 | list_for_each_entry_safe(sl, sln, &dev->slist, w1_slave_entry) { |
866 | if (sl->family->fid == W1_FAMILY_DEFAULT) { | 833 | if (sl->family->fid == W1_FAMILY_DEFAULT) { |
867 | struct w1_reg_num rn; | 834 | struct w1_reg_num rn; |
@@ -874,7 +841,7 @@ static int w1_control(void *data) | |||
874 | } | 841 | } |
875 | dev_dbg(&dev->dev, "Reconnecting slaves in device %s has been finished.\n", dev->name); | 842 | dev_dbg(&dev->dev, "Reconnecting slaves in device %s has been finished.\n", dev->name); |
876 | clear_bit(W1_MASTER_NEED_RECONNECT, &dev->flags); | 843 | clear_bit(W1_MASTER_NEED_RECONNECT, &dev->flags); |
877 | up(&dev->mutex); | 844 | mutex_unlock(&dev->mutex); |
878 | } | 845 | } |
879 | } | 846 | } |
880 | } | 847 | } |
@@ -921,12 +888,9 @@ int w1_process(void *data) | |||
921 | if (dev->search_count == 0) | 888 | if (dev->search_count == 0) |
922 | continue; | 889 | continue; |
923 | 890 | ||
924 | if (down_interruptible(&dev->mutex)) | 891 | mutex_lock(&dev->mutex); |
925 | continue; | ||
926 | |||
927 | w1_search_process(dev, W1_SEARCH); | 892 | w1_search_process(dev, W1_SEARCH); |
928 | 893 | mutex_unlock(&dev->mutex); | |
929 | up(&dev->mutex); | ||
930 | } | 894 | } |
931 | 895 | ||
932 | atomic_dec(&dev->refcnt); | 896 | atomic_dec(&dev->refcnt); |