diff options
author | Evgeniy Polyakov <johnpol@2ka.mipt.ru> | 2005-05-20 14:33:25 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@suse.de> | 2005-06-22 00:43:09 -0400 |
commit | 7785925dd8e0d2f389d4a9168f1683c6b249a552 (patch) | |
tree | 5772979184dc9e2b811503fab6ed1119f5c9f93a /drivers/w1/w1.c | |
parent | 85e941cc9f10316080a16b121d24d329e5c2a65d (diff) |
[PATCH] w1: cleanups.
- white space changes.
- list_for_each_entry/list_for_each_entry_safe and reverse changes.
- small coding style changes.
- removed redundant NULL checks.
- use attribute group and macros instead of direct device attributes.
Patch is havily based on work from Adrian Bunk and Dmitry Torokhov,
thanks guys.
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 | 273 |
1 files changed, 96 insertions, 177 deletions
diff --git a/drivers/w1/w1.c b/drivers/w1/w1.c index 24a192e3b8b4..5b49c9a937f0 100644 --- a/drivers/w1/w1.c +++ b/drivers/w1/w1.c | |||
@@ -1,8 +1,8 @@ | |||
1 | /* | 1 | /* |
2 | * w1.c | 2 | * w1.c |
3 | * | 3 | * |
4 | * Copyright (c) 2004 Evgeniy Polyakov <johnpol@2ka.mipt.ru> | 4 | * Copyright (c) 2004 Evgeniy Polyakov <johnpol@2ka.mipt.ru> |
5 | * | 5 | * |
6 | * | 6 | * |
7 | * This program is free software; you can redistribute it and/or modify | 7 | * This program is free software; you can redistribute it and/or modify |
8 | * it under the terms of the GNU General Public License as published by | 8 | * it under the terms of the GNU General Public License as published by |
@@ -99,6 +99,23 @@ static ssize_t w1_default_read_bin(struct kobject *kobj, char *buf, loff_t off, | |||
99 | return sprintf(buf, "No family registered.\n"); | 99 | return sprintf(buf, "No family registered.\n"); |
100 | } | 100 | } |
101 | 101 | ||
102 | static struct device_attribute w1_slave_attribute = | ||
103 | __ATTR(name, S_IRUGO, w1_default_read_name, NULL); | ||
104 | |||
105 | static struct device_attribute w1_slave_attribute_val = | ||
106 | __ATTR(value, S_IRUGO, w1_default_read_name, NULL); | ||
107 | |||
108 | static struct bin_attribute w1_slave_bin_attribute = { | ||
109 | .attr = { | ||
110 | .name = "w1_slave", | ||
111 | .mode = S_IRUGO, | ||
112 | .owner = THIS_MODULE, | ||
113 | }, | ||
114 | .size = W1_SLAVE_DATA_SIZE, | ||
115 | .read = &w1_default_read_bin, | ||
116 | }; | ||
117 | |||
118 | |||
102 | static struct bus_type w1_bus_type = { | 119 | static struct bus_type w1_bus_type = { |
103 | .name = "w1", | 120 | .name = "w1", |
104 | .match = w1_master_match, | 121 | .match = w1_master_match, |
@@ -119,34 +136,16 @@ struct device w1_device = { | |||
119 | .release = &w1_master_release | 136 | .release = &w1_master_release |
120 | }; | 137 | }; |
121 | 138 | ||
122 | static struct device_attribute w1_slave_attribute = { | ||
123 | .attr = { | ||
124 | .name = "name", | ||
125 | .mode = S_IRUGO, | ||
126 | .owner = THIS_MODULE | ||
127 | }, | ||
128 | .show = &w1_default_read_name, | ||
129 | }; | ||
130 | |||
131 | static struct device_attribute w1_slave_attribute_val = { | ||
132 | .attr = { | ||
133 | .name = "value", | ||
134 | .mode = S_IRUGO, | ||
135 | .owner = THIS_MODULE | ||
136 | }, | ||
137 | .show = &w1_default_read_name, | ||
138 | }; | ||
139 | |||
140 | static ssize_t w1_master_attribute_show_name(struct device *dev, struct device_attribute *attr, char *buf) | 139 | static ssize_t w1_master_attribute_show_name(struct device *dev, struct device_attribute *attr, char *buf) |
141 | { | 140 | { |
142 | struct w1_master *md = container_of (dev, struct w1_master, dev); | 141 | struct w1_master *md = container_of (dev, struct w1_master, dev); |
143 | ssize_t count; | 142 | ssize_t count; |
144 | 143 | ||
145 | if (down_interruptible (&md->mutex)) | 144 | if (down_interruptible (&md->mutex)) |
146 | return -EBUSY; | 145 | return -EBUSY; |
147 | 146 | ||
148 | count = sprintf(buf, "%s\n", md->name); | 147 | count = sprintf(buf, "%s\n", md->name); |
149 | 148 | ||
150 | up(&md->mutex); | 149 | up(&md->mutex); |
151 | 150 | ||
152 | return count; | 151 | return count; |
@@ -156,12 +155,12 @@ static ssize_t w1_master_attribute_show_pointer(struct device *dev, struct devic | |||
156 | { | 155 | { |
157 | struct w1_master *md = container_of(dev, struct w1_master, dev); | 156 | struct w1_master *md = container_of(dev, struct w1_master, dev); |
158 | ssize_t count; | 157 | ssize_t count; |
159 | 158 | ||
160 | if (down_interruptible(&md->mutex)) | 159 | if (down_interruptible(&md->mutex)) |
161 | return -EBUSY; | 160 | return -EBUSY; |
162 | 161 | ||
163 | count = sprintf(buf, "0x%p\n", md->bus_master); | 162 | count = sprintf(buf, "0x%p\n", md->bus_master); |
164 | 163 | ||
165 | up(&md->mutex); | 164 | up(&md->mutex); |
166 | return count; | 165 | return count; |
167 | } | 166 | } |
@@ -177,12 +176,12 @@ static ssize_t w1_master_attribute_show_max_slave_count(struct device *dev, stru | |||
177 | { | 176 | { |
178 | struct w1_master *md = container_of(dev, struct w1_master, dev); | 177 | struct w1_master *md = container_of(dev, struct w1_master, dev); |
179 | ssize_t count; | 178 | ssize_t count; |
180 | 179 | ||
181 | if (down_interruptible(&md->mutex)) | 180 | if (down_interruptible(&md->mutex)) |
182 | return -EBUSY; | 181 | return -EBUSY; |
183 | 182 | ||
184 | count = sprintf(buf, "%d\n", md->max_slave_count); | 183 | count = sprintf(buf, "%d\n", md->max_slave_count); |
185 | 184 | ||
186 | up(&md->mutex); | 185 | up(&md->mutex); |
187 | return count; | 186 | return count; |
188 | } | 187 | } |
@@ -191,12 +190,12 @@ static ssize_t w1_master_attribute_show_attempts(struct device *dev, struct devi | |||
191 | { | 190 | { |
192 | struct w1_master *md = container_of(dev, struct w1_master, dev); | 191 | struct w1_master *md = container_of(dev, struct w1_master, dev); |
193 | ssize_t count; | 192 | ssize_t count; |
194 | 193 | ||
195 | if (down_interruptible(&md->mutex)) | 194 | if (down_interruptible(&md->mutex)) |
196 | return -EBUSY; | 195 | return -EBUSY; |
197 | 196 | ||
198 | count = sprintf(buf, "%lu\n", md->attempts); | 197 | count = sprintf(buf, "%lu\n", md->attempts); |
199 | 198 | ||
200 | up(&md->mutex); | 199 | up(&md->mutex); |
201 | return count; | 200 | return count; |
202 | } | 201 | } |
@@ -205,12 +204,12 @@ static ssize_t w1_master_attribute_show_slave_count(struct device *dev, struct d | |||
205 | { | 204 | { |
206 | struct w1_master *md = container_of(dev, struct w1_master, dev); | 205 | struct w1_master *md = container_of(dev, struct w1_master, dev); |
207 | ssize_t count; | 206 | ssize_t count; |
208 | 207 | ||
209 | if (down_interruptible(&md->mutex)) | 208 | if (down_interruptible(&md->mutex)) |
210 | return -EBUSY; | 209 | return -EBUSY; |
211 | 210 | ||
212 | count = sprintf(buf, "%d\n", md->slave_count); | 211 | count = sprintf(buf, "%d\n", md->slave_count); |
213 | 212 | ||
214 | up(&md->mutex); | 213 | up(&md->mutex); |
215 | return count; | 214 | return count; |
216 | } | 215 | } |
@@ -233,7 +232,7 @@ static ssize_t w1_master_attribute_show_slaves(struct device *dev, struct device | |||
233 | list_for_each_safe(ent, n, &md->slist) { | 232 | list_for_each_safe(ent, n, &md->slist) { |
234 | sl = list_entry(ent, struct w1_slave, w1_slave_entry); | 233 | sl = list_entry(ent, struct w1_slave, w1_slave_entry); |
235 | 234 | ||
236 | c -= snprintf(buf + PAGE_SIZE - c, c, "%s\n", sl->name); | 235 | c -= snprintf(buf + PAGE_SIZE - c, c, "%s\n", sl->name); |
237 | } | 236 | } |
238 | } | 237 | } |
239 | 238 | ||
@@ -242,73 +241,44 @@ static ssize_t w1_master_attribute_show_slaves(struct device *dev, struct device | |||
242 | return PAGE_SIZE - c; | 241 | return PAGE_SIZE - c; |
243 | } | 242 | } |
244 | 243 | ||
245 | static struct device_attribute w1_master_attribute_slaves = { | 244 | #define W1_MASTER_ATTR_RO(_name, _mode) \ |
246 | .attr = { | 245 | struct device_attribute w1_master_attribute_##_name = \ |
247 | .name = "w1_master_slaves", | 246 | __ATTR(w1_master_##_name, _mode, \ |
248 | .mode = S_IRUGO, | 247 | w1_master_attribute_show_##_name, NULL) |
249 | .owner = THIS_MODULE, | 248 | |
250 | }, | 249 | static W1_MASTER_ATTR_RO(name, S_IRUGO); |
251 | .show = &w1_master_attribute_show_slaves, | 250 | static W1_MASTER_ATTR_RO(slaves, S_IRUGO); |
252 | }; | 251 | static W1_MASTER_ATTR_RO(slave_count, S_IRUGO); |
253 | static struct device_attribute w1_master_attribute_slave_count = { | 252 | static W1_MASTER_ATTR_RO(max_slave_count, S_IRUGO); |
254 | .attr = { | 253 | static W1_MASTER_ATTR_RO(attempts, S_IRUGO); |
255 | .name = "w1_master_slave_count", | 254 | static W1_MASTER_ATTR_RO(timeout, S_IRUGO); |
256 | .mode = S_IRUGO, | 255 | static W1_MASTER_ATTR_RO(pointer, S_IRUGO); |
257 | .owner = THIS_MODULE | 256 | |
258 | }, | 257 | static struct attribute *w1_master_default_attrs[] = { |
259 | .show = &w1_master_attribute_show_slave_count, | 258 | &w1_master_attribute_name.attr, |
260 | }; | 259 | &w1_master_attribute_slaves.attr, |
261 | static struct device_attribute w1_master_attribute_attempts = { | 260 | &w1_master_attribute_slave_count.attr, |
262 | .attr = { | 261 | &w1_master_attribute_max_slave_count.attr, |
263 | .name = "w1_master_attempts", | 262 | &w1_master_attribute_attempts.attr, |
264 | .mode = S_IRUGO, | 263 | &w1_master_attribute_timeout.attr, |
265 | .owner = THIS_MODULE | 264 | &w1_master_attribute_pointer.attr, |
266 | }, | 265 | NULL |
267 | .show = &w1_master_attribute_show_attempts, | ||
268 | }; | ||
269 | static struct device_attribute w1_master_attribute_max_slave_count = { | ||
270 | .attr = { | ||
271 | .name = "w1_master_max_slave_count", | ||
272 | .mode = S_IRUGO, | ||
273 | .owner = THIS_MODULE | ||
274 | }, | ||
275 | .show = &w1_master_attribute_show_max_slave_count, | ||
276 | }; | ||
277 | static struct device_attribute w1_master_attribute_timeout = { | ||
278 | .attr = { | ||
279 | .name = "w1_master_timeout", | ||
280 | .mode = S_IRUGO, | ||
281 | .owner = THIS_MODULE | ||
282 | }, | ||
283 | .show = &w1_master_attribute_show_timeout, | ||
284 | }; | ||
285 | static struct device_attribute w1_master_attribute_pointer = { | ||
286 | .attr = { | ||
287 | .name = "w1_master_pointer", | ||
288 | .mode = S_IRUGO, | ||
289 | .owner = THIS_MODULE | ||
290 | }, | ||
291 | .show = &w1_master_attribute_show_pointer, | ||
292 | }; | ||
293 | static struct device_attribute w1_master_attribute_name = { | ||
294 | .attr = { | ||
295 | .name = "w1_master_name", | ||
296 | .mode = S_IRUGO, | ||
297 | .owner = THIS_MODULE | ||
298 | }, | ||
299 | .show = &w1_master_attribute_show_name, | ||
300 | }; | 266 | }; |
301 | 267 | ||
302 | static struct bin_attribute w1_slave_bin_attribute = { | 268 | static struct attribute_group w1_master_defattr_group = { |
303 | .attr = { | 269 | .attrs = w1_master_default_attrs, |
304 | .name = "w1_slave", | ||
305 | .mode = S_IRUGO, | ||
306 | .owner = THIS_MODULE, | ||
307 | }, | ||
308 | .size = W1_SLAVE_DATA_SIZE, | ||
309 | .read = &w1_default_read_bin, | ||
310 | }; | 270 | }; |
311 | 271 | ||
272 | int w1_create_master_attributes(struct w1_master *master) | ||
273 | { | ||
274 | return sysfs_create_group(&master->dev.kobj, &w1_master_defattr_group); | ||
275 | } | ||
276 | |||
277 | void w1_destroy_master_attributes(struct w1_master *master) | ||
278 | { | ||
279 | sysfs_remove_group(&master->dev.kobj, &w1_master_defattr_group); | ||
280 | } | ||
281 | |||
312 | static int __w1_attach_slave_device(struct w1_slave *sl) | 282 | static int __w1_attach_slave_device(struct w1_slave *sl) |
313 | { | 283 | { |
314 | int err; | 284 | int err; |
@@ -341,7 +311,7 @@ static int __w1_attach_slave_device(struct w1_slave *sl) | |||
341 | memcpy(&sl->attr_bin, &w1_slave_bin_attribute, sizeof(sl->attr_bin)); | 311 | memcpy(&sl->attr_bin, &w1_slave_bin_attribute, sizeof(sl->attr_bin)); |
342 | memcpy(&sl->attr_name, &w1_slave_attribute, sizeof(sl->attr_name)); | 312 | memcpy(&sl->attr_name, &w1_slave_attribute, sizeof(sl->attr_name)); |
343 | memcpy(&sl->attr_val, &w1_slave_attribute_val, sizeof(sl->attr_val)); | 313 | memcpy(&sl->attr_val, &w1_slave_attribute_val, sizeof(sl->attr_val)); |
344 | 314 | ||
345 | sl->attr_bin.read = sl->family->fops->rbin; | 315 | sl->attr_bin.read = sl->family->fops->rbin; |
346 | sl->attr_name.show = sl->family->fops->rname; | 316 | sl->attr_name.show = sl->family->fops->rname; |
347 | sl->attr_val.show = sl->family->fops->rval; | 317 | sl->attr_val.show = sl->family->fops->rval; |
@@ -445,7 +415,7 @@ static int w1_attach_slave_device(struct w1_master *dev, struct w1_reg_num *rn) | |||
445 | static void w1_slave_detach(struct w1_slave *sl) | 415 | static void w1_slave_detach(struct w1_slave *sl) |
446 | { | 416 | { |
447 | struct w1_netlink_msg msg; | 417 | struct w1_netlink_msg msg; |
448 | 418 | ||
449 | dev_info(&sl->dev, "%s: detaching %s.\n", __func__, sl->name); | 419 | dev_info(&sl->dev, "%s: detaching %s.\n", __func__, sl->name); |
450 | 420 | ||
451 | while (atomic_read(&sl->refcnt)) { | 421 | while (atomic_read(&sl->refcnt)) { |
@@ -471,8 +441,8 @@ static struct w1_master *w1_search_master(unsigned long data) | |||
471 | { | 441 | { |
472 | struct w1_master *dev; | 442 | struct w1_master *dev; |
473 | int found = 0; | 443 | int found = 0; |
474 | 444 | ||
475 | spin_lock_irq(&w1_mlock); | 445 | spin_lock_bh(&w1_mlock); |
476 | list_for_each_entry(dev, &w1_masters, w1_master_entry) { | 446 | list_for_each_entry(dev, &w1_masters, w1_master_entry) { |
477 | if (dev->bus_master->data == data) { | 447 | if (dev->bus_master->data == data) { |
478 | found = 1; | 448 | found = 1; |
@@ -480,12 +450,12 @@ static struct w1_master *w1_search_master(unsigned long data) | |||
480 | break; | 450 | break; |
481 | } | 451 | } |
482 | } | 452 | } |
483 | spin_unlock_irq(&w1_mlock); | 453 | spin_unlock_bh(&w1_mlock); |
484 | 454 | ||
485 | return (found)?dev:NULL; | 455 | return (found)?dev:NULL; |
486 | } | 456 | } |
487 | 457 | ||
488 | void w1_slave_found(unsigned long data, u64 rn) | 458 | static void w1_slave_found(unsigned long data, u64 rn) |
489 | { | 459 | { |
490 | int slave_count; | 460 | int slave_count; |
491 | struct w1_slave *sl; | 461 | struct w1_slave *sl; |
@@ -500,7 +470,7 @@ void w1_slave_found(unsigned long data, u64 rn) | |||
500 | data); | 470 | data); |
501 | return; | 471 | return; |
502 | } | 472 | } |
503 | 473 | ||
504 | tmp = (struct w1_reg_num *) &rn; | 474 | tmp = (struct w1_reg_num *) &rn; |
505 | 475 | ||
506 | slave_count = 0; | 476 | slave_count = 0; |
@@ -513,8 +483,7 @@ void w1_slave_found(unsigned long data, u64 rn) | |||
513 | sl->reg_num.crc == tmp->crc) { | 483 | sl->reg_num.crc == tmp->crc) { |
514 | set_bit(W1_SLAVE_ACTIVE, (long *)&sl->flags); | 484 | set_bit(W1_SLAVE_ACTIVE, (long *)&sl->flags); |
515 | break; | 485 | break; |
516 | } | 486 | } else if (sl->reg_num.family == tmp->family) { |
517 | else if (sl->reg_num.family == tmp->family) { | ||
518 | family_found = 1; | 487 | family_found = 1; |
519 | break; | 488 | break; |
520 | } | 489 | } |
@@ -528,7 +497,7 @@ void w1_slave_found(unsigned long data, u64 rn) | |||
528 | rn && ((le64_to_cpu(rn) >> 56) & 0xff) == w1_calc_crc8((u8 *)&rn, 7)) { | 497 | rn && ((le64_to_cpu(rn) >> 56) & 0xff) == w1_calc_crc8((u8 *)&rn, 7)) { |
529 | w1_attach_slave_device(dev, tmp); | 498 | w1_attach_slave_device(dev, tmp); |
530 | } | 499 | } |
531 | 500 | ||
532 | atomic_dec(&dev->refcnt); | 501 | atomic_dec(&dev->refcnt); |
533 | } | 502 | } |
534 | 503 | ||
@@ -545,8 +514,8 @@ void w1_search(struct w1_master *dev) | |||
545 | 514 | ||
546 | desc_bit = 64; | 515 | desc_bit = 64; |
547 | 516 | ||
548 | while (!(id_bit && comp_bit) && !last_device | 517 | while (!(id_bit && comp_bit) && !last_device && |
549 | && count++ < dev->max_slave_count) { | 518 | count++ < dev->max_slave_count) { |
550 | last = rn; | 519 | last = rn; |
551 | rn = 0; | 520 | rn = 0; |
552 | 521 | ||
@@ -591,8 +560,7 @@ void w1_search(struct w1_master *dev) | |||
591 | last_family_desc = last_zero; | 560 | last_family_desc = last_zero; |
592 | } | 561 | } |
593 | 562 | ||
594 | } | 563 | } else |
595 | else | ||
596 | search_bit = id_bit; | 564 | search_bit = id_bit; |
597 | 565 | ||
598 | tmp = search_bit; | 566 | tmp = search_bit; |
@@ -615,42 +583,15 @@ void w1_search(struct w1_master *dev) | |||
615 | last_device = 1; | 583 | last_device = 1; |
616 | 584 | ||
617 | desc_bit = last_zero; | 585 | desc_bit = last_zero; |
618 | 586 | ||
619 | w1_slave_found(dev->bus_master->data, rn); | 587 | w1_slave_found(dev->bus_master->data, rn); |
620 | } | 588 | } |
621 | } | 589 | } |
622 | 590 | ||
623 | int w1_create_master_attributes(struct w1_master *dev) | 591 | static int w1_control(void *data) |
624 | { | ||
625 | if ( device_create_file(&dev->dev, &w1_master_attribute_slaves) < 0 || | ||
626 | device_create_file(&dev->dev, &w1_master_attribute_slave_count) < 0 || | ||
627 | device_create_file(&dev->dev, &w1_master_attribute_attempts) < 0 || | ||
628 | device_create_file(&dev->dev, &w1_master_attribute_max_slave_count) < 0 || | ||
629 | device_create_file(&dev->dev, &w1_master_attribute_timeout) < 0|| | ||
630 | device_create_file(&dev->dev, &w1_master_attribute_pointer) < 0|| | ||
631 | device_create_file(&dev->dev, &w1_master_attribute_name) < 0) | ||
632 | return -EINVAL; | ||
633 | |||
634 | return 0; | ||
635 | } | ||
636 | |||
637 | void w1_destroy_master_attributes(struct w1_master *dev) | ||
638 | { | ||
639 | device_remove_file(&dev->dev, &w1_master_attribute_slaves); | ||
640 | device_remove_file(&dev->dev, &w1_master_attribute_slave_count); | ||
641 | device_remove_file(&dev->dev, &w1_master_attribute_attempts); | ||
642 | device_remove_file(&dev->dev, &w1_master_attribute_max_slave_count); | ||
643 | device_remove_file(&dev->dev, &w1_master_attribute_timeout); | ||
644 | device_remove_file(&dev->dev, &w1_master_attribute_pointer); | ||
645 | device_remove_file(&dev->dev, &w1_master_attribute_name); | ||
646 | } | ||
647 | |||
648 | |||
649 | int w1_control(void *data) | ||
650 | { | 592 | { |
651 | struct w1_slave *sl; | 593 | struct w1_slave *sl, *sln; |
652 | struct w1_master *dev; | 594 | struct w1_master *dev, *n; |
653 | struct list_head *ent, *ment, *n, *mn; | ||
654 | int err, have_to_wait = 0; | 595 | int err, have_to_wait = 0; |
655 | 596 | ||
656 | daemonize("w1_control"); | 597 | daemonize("w1_control"); |
@@ -665,9 +606,7 @@ int w1_control(void *data) | |||
665 | if (signal_pending(current)) | 606 | if (signal_pending(current)) |
666 | flush_signals(current); | 607 | flush_signals(current); |
667 | 608 | ||
668 | list_for_each_safe(ment, mn, &w1_masters) { | 609 | list_for_each_entry_safe(dev, n, &w1_masters, w1_master_entry) { |
669 | dev = list_entry(ment, struct w1_master, w1_master_entry); | ||
670 | |||
671 | if (!control_needs_exit && !dev->need_exit) | 610 | if (!control_needs_exit && !dev->need_exit) |
672 | continue; | 611 | continue; |
673 | /* | 612 | /* |
@@ -679,9 +618,9 @@ int w1_control(void *data) | |||
679 | continue; | 618 | continue; |
680 | } | 619 | } |
681 | 620 | ||
682 | spin_lock(&w1_mlock); | 621 | spin_lock_bh(&w1_mlock); |
683 | list_del(&dev->w1_master_entry); | 622 | list_del(&dev->w1_master_entry); |
684 | spin_unlock(&w1_mlock); | 623 | spin_unlock_bh(&w1_mlock); |
685 | 624 | ||
686 | if (control_needs_exit) { | 625 | if (control_needs_exit) { |
687 | dev->need_exit = 1; | 626 | dev->need_exit = 1; |
@@ -695,19 +634,11 @@ int w1_control(void *data) | |||
695 | 634 | ||
696 | wait_for_completion(&dev->dev_exited); | 635 | wait_for_completion(&dev->dev_exited); |
697 | 636 | ||
698 | list_for_each_safe(ent, n, &dev->slist) { | 637 | list_for_each_entry_safe(sl, sln, &dev->slist, w1_slave_entry) { |
699 | sl = list_entry(ent, struct w1_slave, w1_slave_entry); | 638 | list_del(&sl->w1_slave_entry); |
700 | |||
701 | if (!sl) | ||
702 | dev_warn(&dev->dev, | ||
703 | "%s: slave entry is NULL.\n", | ||
704 | __func__); | ||
705 | else { | ||
706 | list_del(&sl->w1_slave_entry); | ||
707 | 639 | ||
708 | w1_slave_detach(sl); | 640 | w1_slave_detach(sl); |
709 | kfree(sl); | 641 | kfree(sl); |
710 | } | ||
711 | } | 642 | } |
712 | w1_destroy_master_attributes(dev); | 643 | w1_destroy_master_attributes(dev); |
713 | atomic_dec(&dev->refcnt); | 644 | atomic_dec(&dev->refcnt); |
@@ -720,8 +651,7 @@ int w1_control(void *data) | |||
720 | int w1_process(void *data) | 651 | int w1_process(void *data) |
721 | { | 652 | { |
722 | struct w1_master *dev = (struct w1_master *) data; | 653 | struct w1_master *dev = (struct w1_master *) data; |
723 | struct list_head *ent, *n; | 654 | struct w1_slave *sl, *sln; |
724 | struct w1_slave *sl; | ||
725 | 655 | ||
726 | daemonize("%s", dev->name); | 656 | daemonize("%s", dev->name); |
727 | allow_signal(SIGTERM); | 657 | allow_signal(SIGTERM); |
@@ -742,27 +672,20 @@ int w1_process(void *data) | |||
742 | if (down_interruptible(&dev->mutex)) | 672 | if (down_interruptible(&dev->mutex)) |
743 | continue; | 673 | continue; |
744 | 674 | ||
745 | list_for_each_safe(ent, n, &dev->slist) { | 675 | list_for_each_entry(sl, &dev->slist, w1_slave_entry) |
746 | sl = list_entry(ent, struct w1_slave, w1_slave_entry); | ||
747 | |||
748 | if (sl) | ||
749 | clear_bit(W1_SLAVE_ACTIVE, (long *)&sl->flags); | 676 | clear_bit(W1_SLAVE_ACTIVE, (long *)&sl->flags); |
750 | } | ||
751 | |||
752 | w1_search_devices(dev, w1_slave_found); | ||
753 | 677 | ||
754 | list_for_each_safe(ent, n, &dev->slist) { | 678 | w1_search_devices(dev, w1_slave_found); |
755 | sl = list_entry(ent, struct w1_slave, w1_slave_entry); | ||
756 | 679 | ||
757 | if (sl && !test_bit(W1_SLAVE_ACTIVE, (unsigned long *)&sl->flags) && !--sl->ttl) { | 680 | list_for_each_entry_safe(sl, sln, &dev->slist, w1_slave_entry) { |
681 | if (!test_bit(W1_SLAVE_ACTIVE, (unsigned long *)&sl->flags) && !--sl->ttl) { | ||
758 | list_del (&sl->w1_slave_entry); | 682 | list_del (&sl->w1_slave_entry); |
759 | 683 | ||
760 | w1_slave_detach (sl); | 684 | w1_slave_detach (sl); |
761 | kfree (sl); | 685 | kfree (sl); |
762 | 686 | ||
763 | dev->slave_count--; | 687 | dev->slave_count--; |
764 | } | 688 | } else if (test_bit(W1_SLAVE_ACTIVE, (unsigned long *)&sl->flags)) |
765 | else if (test_bit(W1_SLAVE_ACTIVE, (unsigned long *)&sl->flags)) | ||
766 | sl->ttl = dev->slave_ttl; | 689 | sl->ttl = dev->slave_ttl; |
767 | } | 690 | } |
768 | up(&dev->mutex); | 691 | up(&dev->mutex); |
@@ -774,7 +697,7 @@ int w1_process(void *data) | |||
774 | return 0; | 697 | return 0; |
775 | } | 698 | } |
776 | 699 | ||
777 | int w1_init(void) | 700 | static int w1_init(void) |
778 | { | 701 | { |
779 | int retval; | 702 | int retval; |
780 | 703 | ||
@@ -814,18 +737,14 @@ err_out_exit_init: | |||
814 | return retval; | 737 | return retval; |
815 | } | 738 | } |
816 | 739 | ||
817 | void w1_fini(void) | 740 | static void w1_fini(void) |
818 | { | 741 | { |
819 | struct w1_master *dev; | 742 | struct w1_master *dev; |
820 | struct list_head *ent, *n; | ||
821 | 743 | ||
822 | list_for_each_safe(ent, n, &w1_masters) { | 744 | list_for_each_entry(dev, &w1_masters, w1_master_entry) |
823 | dev = list_entry(ent, struct w1_master, w1_master_entry); | ||
824 | __w1_remove_master_device(dev); | 745 | __w1_remove_master_device(dev); |
825 | } | ||
826 | 746 | ||
827 | control_needs_exit = 1; | 747 | control_needs_exit = 1; |
828 | |||
829 | wait_for_completion(&w1_control_complete); | 748 | wait_for_completion(&w1_control_complete); |
830 | 749 | ||
831 | driver_unregister(&w1_driver); | 750 | driver_unregister(&w1_driver); |