aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/w1/w1.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/w1/w1.c')
-rw-r--r--drivers/w1/w1.c302
1 files changed, 192 insertions, 110 deletions
diff --git a/drivers/w1/w1.c b/drivers/w1/w1.c
index 0bbf029b1ef1..1b6b74c116a9 100644
--- a/drivers/w1/w1.c
+++ b/drivers/w1/w1.c
@@ -45,10 +45,12 @@ MODULE_AUTHOR("Evgeniy Polyakov <johnpol@2ka.mipt.ru>");
45MODULE_DESCRIPTION("Driver for 1-wire Dallas network protocol."); 45MODULE_DESCRIPTION("Driver for 1-wire Dallas network protocol.");
46 46
47static int w1_timeout = 10; 47static int w1_timeout = 10;
48static int w1_control_timeout = 1;
48int w1_max_slave_count = 10; 49int w1_max_slave_count = 10;
49int w1_max_slave_ttl = 10; 50int w1_max_slave_ttl = 10;
50 51
51module_param_named(timeout, w1_timeout, int, 0); 52module_param_named(timeout, w1_timeout, int, 0);
53module_param_named(control_timeout, w1_control_timeout, int, 0);
52module_param_named(max_slave_count, w1_max_slave_count, int, 0); 54module_param_named(max_slave_count, w1_max_slave_count, int, 0);
53module_param_named(slave_ttl, w1_max_slave_ttl, int, 0); 55module_param_named(slave_ttl, w1_max_slave_ttl, int, 0);
54 56
@@ -59,19 +61,6 @@ static pid_t control_thread;
59static int control_needs_exit; 61static int control_needs_exit;
60static DECLARE_COMPLETION(w1_control_complete); 62static DECLARE_COMPLETION(w1_control_complete);
61 63
62/* stuff for the default family */
63static ssize_t w1_famdefault_read_name(struct device *dev, struct device_attribute *attr, char *buf)
64{
65 struct w1_slave *sl = container_of(dev, struct w1_slave, dev);
66 return(sprintf(buf, "%s\n", sl->name));
67}
68static struct w1_family_ops w1_default_fops = {
69 .rname = &w1_famdefault_read_name,
70};
71static struct w1_family w1_default_family = {
72 .fops = &w1_default_fops,
73};
74
75static int w1_master_match(struct device *dev, struct device_driver *drv) 64static int w1_master_match(struct device *dev, struct device_driver *drv)
76{ 65{
77 return 1; 66 return 1;
@@ -82,73 +71,116 @@ static int w1_master_probe(struct device *dev)
82 return -ENODEV; 71 return -ENODEV;
83} 72}
84 73
85static int w1_master_remove(struct device *dev)
86{
87 return 0;
88}
89
90static void w1_master_release(struct device *dev) 74static void w1_master_release(struct device *dev)
91{ 75{
92 struct w1_master *md = container_of(dev, struct w1_master, dev); 76 struct w1_master *md = dev_to_w1_master(dev);
93 77
94 complete(&md->dev_released); 78 dev_dbg(dev, "%s: Releasing %s.\n", __func__, md->name);
79
80 if (md->nls && md->nls->sk_socket)
81 sock_release(md->nls->sk_socket);
82 memset(md, 0, sizeof(struct w1_master) + sizeof(struct w1_bus_master));
83 kfree(md);
95} 84}
96 85
97static void w1_slave_release(struct device *dev) 86static void w1_slave_release(struct device *dev)
98{ 87{
99 struct w1_slave *sl = container_of(dev, struct w1_slave, dev); 88 struct w1_slave *sl = dev_to_w1_slave(dev);
89
90 dev_dbg(dev, "%s: Releasing %s.\n", __func__, sl->name);
91
92 while (atomic_read(&sl->refcnt)) {
93 dev_dbg(dev, "Waiting for %s to become free: refcnt=%d.\n",
94 sl->name, atomic_read(&sl->refcnt));
95 if (msleep_interruptible(1000))
96 flush_signals(current);
97 }
98
99 w1_family_put(sl->family);
100 sl->master->slave_count--;
100 101
101 complete(&sl->dev_released); 102 complete(&sl->released);
102} 103}
103 104
104static ssize_t w1_default_read_name(struct device *dev, struct device_attribute *attr, char *buf) 105static ssize_t w1_slave_read_name(struct device *dev, struct device_attribute *attr, char *buf)
105{ 106{
106 return sprintf(buf, "No family registered.\n"); 107 struct w1_slave *sl = dev_to_w1_slave(dev);
108
109 return sprintf(buf, "%s\n", sl->name);
107} 110}
108 111
109static ssize_t w1_default_read_bin(struct kobject *kobj, char *buf, loff_t off, 112static ssize_t w1_slave_read_id(struct kobject *kobj, char *buf, loff_t off, size_t count)
110 size_t count)
111{ 113{
112 return sprintf(buf, "No family registered.\n"); 114 struct w1_slave *sl = kobj_to_w1_slave(kobj);
115
116 atomic_inc(&sl->refcnt);
117 if (off > 8) {
118 count = 0;
119 } else {
120 if (off + count > 8)
121 count = 8 - off;
122
123 memcpy(buf, (u8 *)&sl->reg_num, count);
124 }
125 atomic_dec(&sl->refcnt);
126
127 return count;
113} 128}
114 129
115static struct device_attribute w1_slave_attribute = 130static struct device_attribute w1_slave_attr_name =
116 __ATTR(name, S_IRUGO, w1_default_read_name, NULL); 131 __ATTR(name, S_IRUGO, w1_slave_read_name, NULL);
117 132
118static struct bin_attribute w1_slave_bin_attribute = { 133static struct bin_attribute w1_slave_attr_bin_id = {
119 .attr = { 134 .attr = {
120 .name = "w1_slave", 135 .name = "id",
121 .mode = S_IRUGO, 136 .mode = S_IRUGO,
122 .owner = THIS_MODULE, 137 .owner = THIS_MODULE,
123 }, 138 },
124 .size = W1_SLAVE_DATA_SIZE, 139 .size = 8,
125 .read = &w1_default_read_bin, 140 .read = w1_slave_read_id,
126}; 141};
127 142
143/* Default family */
144static struct w1_family w1_default_family;
145
146static int w1_hotplug(struct device *dev, char **envp, int num_envp, char *buffer, int buffer_size);
128 147
129static struct bus_type w1_bus_type = { 148static struct bus_type w1_bus_type = {
130 .name = "w1", 149 .name = "w1",
131 .match = w1_master_match, 150 .match = w1_master_match,
151 .hotplug = w1_hotplug,
132}; 152};
133 153
134struct device_driver w1_driver = { 154struct device_driver w1_master_driver = {
135 .name = "w1_driver", 155 .name = "w1_master_driver",
136 .bus = &w1_bus_type, 156 .bus = &w1_bus_type,
137 .probe = w1_master_probe, 157 .probe = w1_master_probe,
138 .remove = w1_master_remove,
139}; 158};
140 159
141struct device w1_device = { 160struct device w1_master_device = {
142 .parent = NULL, 161 .parent = NULL,
143 .bus = &w1_bus_type, 162 .bus = &w1_bus_type,
144 .bus_id = "w1 bus master", 163 .bus_id = "w1 bus master",
145 .driver = &w1_driver, 164 .driver = &w1_master_driver,
146 .release = &w1_master_release 165 .release = &w1_master_release
147}; 166};
148 167
168struct device_driver w1_slave_driver = {
169 .name = "w1_slave_driver",
170 .bus = &w1_bus_type,
171};
172
173struct device w1_slave_device = {
174 .parent = NULL,
175 .bus = &w1_bus_type,
176 .bus_id = "w1 bus slave",
177 .driver = &w1_slave_driver,
178 .release = &w1_slave_release
179};
180
149static ssize_t w1_master_attribute_show_name(struct device *dev, struct device_attribute *attr, char *buf) 181static ssize_t w1_master_attribute_show_name(struct device *dev, struct device_attribute *attr, char *buf)
150{ 182{
151 struct w1_master *md = container_of(dev, struct w1_master, dev); 183 struct w1_master *md = dev_to_w1_master(dev);
152 ssize_t count; 184 ssize_t count;
153 185
154 if (down_interruptible (&md->mutex)) 186 if (down_interruptible (&md->mutex))
@@ -165,7 +197,7 @@ static ssize_t w1_master_attribute_store_search(struct device * dev,
165 struct device_attribute *attr, 197 struct device_attribute *attr,
166 const char * buf, size_t count) 198 const char * buf, size_t count)
167{ 199{
168 struct w1_master *md = container_of(dev, struct w1_master, dev); 200 struct w1_master *md = dev_to_w1_master(dev);
169 201
170 if (down_interruptible (&md->mutex)) 202 if (down_interruptible (&md->mutex))
171 return -EBUSY; 203 return -EBUSY;
@@ -181,7 +213,7 @@ static ssize_t w1_master_attribute_show_search(struct device *dev,
181 struct device_attribute *attr, 213 struct device_attribute *attr,
182 char *buf) 214 char *buf)
183{ 215{
184 struct w1_master *md = container_of(dev, struct w1_master, dev); 216 struct w1_master *md = dev_to_w1_master(dev);
185 ssize_t count; 217 ssize_t count;
186 218
187 if (down_interruptible (&md->mutex)) 219 if (down_interruptible (&md->mutex))
@@ -196,7 +228,7 @@ static ssize_t w1_master_attribute_show_search(struct device *dev,
196 228
197static ssize_t w1_master_attribute_show_pointer(struct device *dev, struct device_attribute *attr, char *buf) 229static ssize_t w1_master_attribute_show_pointer(struct device *dev, struct device_attribute *attr, char *buf)
198{ 230{
199 struct w1_master *md = container_of(dev, struct w1_master, dev); 231 struct w1_master *md = dev_to_w1_master(dev);
200 ssize_t count; 232 ssize_t count;
201 233
202 if (down_interruptible(&md->mutex)) 234 if (down_interruptible(&md->mutex))
@@ -217,7 +249,7 @@ static ssize_t w1_master_attribute_show_timeout(struct device *dev, struct devic
217 249
218static ssize_t w1_master_attribute_show_max_slave_count(struct device *dev, struct device_attribute *attr, char *buf) 250static ssize_t w1_master_attribute_show_max_slave_count(struct device *dev, struct device_attribute *attr, char *buf)
219{ 251{
220 struct w1_master *md = container_of(dev, struct w1_master, dev); 252 struct w1_master *md = dev_to_w1_master(dev);
221 ssize_t count; 253 ssize_t count;
222 254
223 if (down_interruptible(&md->mutex)) 255 if (down_interruptible(&md->mutex))
@@ -231,7 +263,7 @@ static ssize_t w1_master_attribute_show_max_slave_count(struct device *dev, stru
231 263
232static ssize_t w1_master_attribute_show_attempts(struct device *dev, struct device_attribute *attr, char *buf) 264static ssize_t w1_master_attribute_show_attempts(struct device *dev, struct device_attribute *attr, char *buf)
233{ 265{
234 struct w1_master *md = container_of(dev, struct w1_master, dev); 266 struct w1_master *md = dev_to_w1_master(dev);
235 ssize_t count; 267 ssize_t count;
236 268
237 if (down_interruptible(&md->mutex)) 269 if (down_interruptible(&md->mutex))
@@ -245,7 +277,7 @@ static ssize_t w1_master_attribute_show_attempts(struct device *dev, struct devi
245 277
246static ssize_t w1_master_attribute_show_slave_count(struct device *dev, struct device_attribute *attr, char *buf) 278static ssize_t w1_master_attribute_show_slave_count(struct device *dev, struct device_attribute *attr, char *buf)
247{ 279{
248 struct w1_master *md = container_of(dev, struct w1_master, dev); 280 struct w1_master *md = dev_to_w1_master(dev);
249 ssize_t count; 281 ssize_t count;
250 282
251 if (down_interruptible(&md->mutex)) 283 if (down_interruptible(&md->mutex))
@@ -259,7 +291,7 @@ static ssize_t w1_master_attribute_show_slave_count(struct device *dev, struct d
259 291
260static ssize_t w1_master_attribute_show_slaves(struct device *dev, struct device_attribute *attr, char *buf) 292static ssize_t w1_master_attribute_show_slaves(struct device *dev, struct device_attribute *attr, char *buf)
261{ 293{
262 struct w1_master *md = container_of(dev, struct w1_master, dev); 294 struct w1_master *md = dev_to_w1_master(dev);
263 int c = PAGE_SIZE; 295 int c = PAGE_SIZE;
264 296
265 if (down_interruptible(&md->mutex)) 297 if (down_interruptible(&md->mutex))
@@ -329,12 +361,55 @@ void w1_destroy_master_attributes(struct w1_master *master)
329 sysfs_remove_group(&master->dev.kobj, &w1_master_defattr_group); 361 sysfs_remove_group(&master->dev.kobj, &w1_master_defattr_group);
330} 362}
331 363
364#ifdef CONFIG_HOTPLUG
365static int w1_hotplug(struct device *dev, char **envp, int num_envp, char *buffer, int buffer_size)
366{
367 struct w1_master *md = NULL;
368 struct w1_slave *sl = NULL;
369 char *event_owner, *name;
370 int err, cur_index=0, cur_len=0;
371
372 if (dev->driver == &w1_master_driver) {
373 md = container_of(dev, struct w1_master, dev);
374 event_owner = "master";
375 name = md->name;
376 } else if (dev->driver == &w1_slave_driver) {
377 sl = container_of(dev, struct w1_slave, dev);
378 event_owner = "slave";
379 name = sl->name;
380 } else {
381 dev_dbg(dev, "Unknown hotplug event.\n");
382 return -EINVAL;
383 }
384
385 dev_dbg(dev, "Hotplug event for %s %s, bus_id=%s.\n", event_owner, name, dev->bus_id);
386
387 if (dev->driver != &w1_slave_driver || !sl)
388 return 0;
389
390 err = add_hotplug_env_var(envp, num_envp, &cur_index, buffer, buffer_size, &cur_len, "W1_FID=%02X", sl->reg_num.family);
391 if (err)
392 return err;
393
394 err = add_hotplug_env_var(envp, num_envp, &cur_index, buffer, buffer_size, &cur_len, "W1_SLAVE_ID=%024LX", (u64)sl->reg_num.id);
395 if (err)
396 return err;
397
398 return 0;
399};
400#else
401static int w1_hotplug(struct device *dev, char **envp, int num_envp, char *buffer, int buffer_size)
402{
403 return 0;
404}
405#endif
406
332static int __w1_attach_slave_device(struct w1_slave *sl) 407static int __w1_attach_slave_device(struct w1_slave *sl)
333{ 408{
334 int err; 409 int err;
335 410
336 sl->dev.parent = &sl->master->dev; 411 sl->dev.parent = &sl->master->dev;
337 sl->dev.driver = sl->master->driver; 412 sl->dev.driver = &w1_slave_driver;
338 sl->dev.bus = &w1_bus_type; 413 sl->dev.bus = &w1_bus_type;
339 sl->dev.release = &w1_slave_release; 414 sl->dev.release = &w1_slave_release;
340 415
@@ -347,8 +422,7 @@ static int __w1_attach_slave_device(struct w1_slave *sl)
347 (unsigned int) sl->reg_num.family, 422 (unsigned int) sl->reg_num.family,
348 (unsigned long long) sl->reg_num.id); 423 (unsigned long long) sl->reg_num.id);
349 424
350 dev_dbg(&sl->dev, "%s: registering %s.\n", __func__, 425 dev_dbg(&sl->dev, "%s: registering %s as %p.\n", __func__, &sl->dev.bus_id[0]);
351 &sl->dev.bus_id[0]);
352 426
353 err = device_register(&sl->dev); 427 err = device_register(&sl->dev);
354 if (err < 0) { 428 if (err < 0) {
@@ -358,36 +432,44 @@ static int __w1_attach_slave_device(struct w1_slave *sl)
358 return err; 432 return err;
359 } 433 }
360 434
361 memcpy(&sl->attr_bin, &w1_slave_bin_attribute, sizeof(sl->attr_bin)); 435 /* Create "name" entry */
362 memcpy(&sl->attr_name, &w1_slave_attribute, sizeof(sl->attr_name)); 436 err = device_create_file(&sl->dev, &w1_slave_attr_name);
363 437 if (err < 0) {
364 sl->attr_bin.read = sl->family->fops->rbin; 438 dev_err(&sl->dev,
365 sl->attr_name.show = sl->family->fops->rname; 439 "sysfs file creation for [%s] failed. err=%d\n",
440 sl->dev.bus_id, err);
441 goto out_unreg;
442 }
366 443
367 err = device_create_file(&sl->dev, &sl->attr_name); 444 /* Create "id" entry */
445 err = sysfs_create_bin_file(&sl->dev.kobj, &w1_slave_attr_bin_id);
368 if (err < 0) { 446 if (err < 0) {
369 dev_err(&sl->dev, 447 dev_err(&sl->dev,
370 "sysfs file creation for [%s] failed. err=%d\n", 448 "sysfs file creation for [%s] failed. err=%d\n",
371 sl->dev.bus_id, err); 449 sl->dev.bus_id, err);
372 device_unregister(&sl->dev); 450 goto out_rem1;
373 return err;
374 } 451 }
375 452
376 if ( sl->attr_bin.read ) { 453 /* if the family driver needs to initialize something... */
377 err = sysfs_create_bin_file(&sl->dev.kobj, &sl->attr_bin); 454 if (sl->family->fops && sl->family->fops->add_slave &&
378 if (err < 0) { 455 ((err = sl->family->fops->add_slave(sl)) < 0)) {
379 dev_err(&sl->dev, 456 dev_err(&sl->dev,
380 "sysfs file creation for [%s] failed. err=%d\n", 457 "sysfs file creation for [%s] failed. err=%d\n",
381 sl->dev.bus_id, err); 458 sl->dev.bus_id, err);
382 device_remove_file(&sl->dev, &sl->attr_name); 459 goto out_rem2;
383 device_unregister(&sl->dev);
384 return err;
385 }
386 } 460 }
387 461
388 list_add_tail(&sl->w1_slave_entry, &sl->master->slist); 462 list_add_tail(&sl->w1_slave_entry, &sl->master->slist);
389 463
390 return 0; 464 return 0;
465
466out_rem2:
467 sysfs_remove_bin_file(&sl->dev.kobj, &w1_slave_attr_bin_id);
468out_rem1:
469 device_remove_file(&sl->dev, &w1_slave_attr_name);
470out_unreg:
471 device_unregister(&sl->dev);
472 return err;
391} 473}
392 474
393static int w1_attach_slave_device(struct w1_master *dev, struct w1_reg_num *rn) 475static int w1_attach_slave_device(struct w1_master *dev, struct w1_reg_num *rn)
@@ -413,7 +495,7 @@ static int w1_attach_slave_device(struct w1_master *dev, struct w1_reg_num *rn)
413 495
414 memcpy(&sl->reg_num, rn, sizeof(sl->reg_num)); 496 memcpy(&sl->reg_num, rn, sizeof(sl->reg_num));
415 atomic_set(&sl->refcnt, 0); 497 atomic_set(&sl->refcnt, 0);
416 init_completion(&sl->dev_released); 498 init_completion(&sl->released);
417 499
418 spin_lock(&w1_flock); 500 spin_lock(&w1_flock);
419 f = w1_family_registered(rn->family); 501 f = w1_family_registered(rn->family);
@@ -452,28 +534,23 @@ static void w1_slave_detach(struct w1_slave *sl)
452{ 534{
453 struct w1_netlink_msg msg; 535 struct w1_netlink_msg msg;
454 536
455 dev_info(&sl->dev, "%s: detaching %s.\n", __func__, sl->name); 537 dev_dbg(&sl->dev, "%s: detaching %s [%p].\n", __func__, sl->name, sl);
456
457 while (atomic_read(&sl->refcnt)) {
458 printk(KERN_INFO "Waiting for %s to become free: refcnt=%d.\n",
459 sl->name, atomic_read(&sl->refcnt));
460 538
461 if (msleep_interruptible(1000)) 539 list_del(&sl->w1_slave_entry);
462 flush_signals(current);
463 }
464
465 if ( sl->attr_bin.read ) {
466 sysfs_remove_bin_file (&sl->dev.kobj, &sl->attr_bin);
467 }
468 device_remove_file(&sl->dev, &sl->attr_name);
469 device_unregister(&sl->dev);
470 w1_family_put(sl->family);
471 540
472 sl->master->slave_count--; 541 if (sl->family->fops && sl->family->fops->remove_slave)
542 sl->family->fops->remove_slave(sl);
473 543
474 memcpy(&msg.id.id, &sl->reg_num, sizeof(msg.id.id)); 544 memcpy(&msg.id.id, &sl->reg_num, sizeof(msg.id.id));
475 msg.type = W1_SLAVE_REMOVE; 545 msg.type = W1_SLAVE_REMOVE;
476 w1_netlink_send(sl->master, &msg); 546 w1_netlink_send(sl->master, &msg);
547
548 sysfs_remove_bin_file(&sl->dev.kobj, &w1_slave_attr_bin_id);
549 device_remove_file(&sl->dev, &w1_slave_attr_name);
550 device_unregister(&sl->dev);
551
552 wait_for_completion(&sl->released);
553 kfree(sl);
477} 554}
478 555
479static struct w1_master *w1_search_master(unsigned long data) 556static struct w1_master *w1_search_master(unsigned long data)
@@ -500,14 +577,13 @@ void w1_reconnect_slaves(struct w1_family *f)
500 577
501 spin_lock_bh(&w1_mlock); 578 spin_lock_bh(&w1_mlock);
502 list_for_each_entry(dev, &w1_masters, w1_master_entry) { 579 list_for_each_entry(dev, &w1_masters, w1_master_entry) {
503 dev_info(&dev->dev, "Reconnecting slaves in %s into new family %02x.\n", 580 dev_dbg(&dev->dev, "Reconnecting slaves in %s into new family %02x.\n",
504 dev->name, f->fid); 581 dev->name, f->fid);
505 set_bit(W1_MASTER_NEED_RECONNECT, &dev->flags); 582 set_bit(W1_MASTER_NEED_RECONNECT, &dev->flags);
506 } 583 }
507 spin_unlock_bh(&w1_mlock); 584 spin_unlock_bh(&w1_mlock);
508} 585}
509 586
510
511static void w1_slave_found(unsigned long data, u64 rn) 587static void w1_slave_found(unsigned long data, u64 rn)
512{ 588{
513 int slave_count; 589 int slave_count;
@@ -646,7 +722,7 @@ static int w1_control(void *data)
646 have_to_wait = 0; 722 have_to_wait = 0;
647 723
648 try_to_freeze(); 724 try_to_freeze();
649 msleep_interruptible(w1_timeout * 1000); 725 msleep_interruptible(w1_control_timeout * 1000);
650 726
651 if (signal_pending(current)) 727 if (signal_pending(current))
652 flush_signals(current); 728 flush_signals(current);
@@ -679,33 +755,30 @@ static int w1_control(void *data)
679 list_del(&dev->w1_master_entry); 755 list_del(&dev->w1_master_entry);
680 spin_unlock_bh(&w1_mlock); 756 spin_unlock_bh(&w1_mlock);
681 757
758 down(&dev->mutex);
682 list_for_each_entry_safe(sl, sln, &dev->slist, w1_slave_entry) { 759 list_for_each_entry_safe(sl, sln, &dev->slist, w1_slave_entry) {
683 list_del(&sl->w1_slave_entry);
684
685 w1_slave_detach(sl); 760 w1_slave_detach(sl);
686 kfree(sl);
687 } 761 }
688 w1_destroy_master_attributes(dev); 762 w1_destroy_master_attributes(dev);
763 up(&dev->mutex);
689 atomic_dec(&dev->refcnt); 764 atomic_dec(&dev->refcnt);
690 continue; 765 continue;
691 } 766 }
692 767
693 if (test_bit(W1_MASTER_NEED_RECONNECT, &dev->flags)) { 768 if (test_bit(W1_MASTER_NEED_RECONNECT, &dev->flags)) {
694 dev_info(&dev->dev, "Reconnecting slaves in device %s.\n", dev->name); 769 dev_dbg(&dev->dev, "Reconnecting slaves in device %s.\n", dev->name);
695 down(&dev->mutex); 770 down(&dev->mutex);
696 list_for_each_entry(sl, &dev->slist, w1_slave_entry) { 771 list_for_each_entry_safe(sl, sln, &dev->slist, w1_slave_entry) {
697 if (sl->family->fid == W1_FAMILY_DEFAULT) { 772 if (sl->family->fid == W1_FAMILY_DEFAULT) {
698 struct w1_reg_num rn; 773 struct w1_reg_num rn;
699 list_del(&sl->w1_slave_entry);
700 w1_slave_detach(sl);
701 774
702 memcpy(&rn, &sl->reg_num, sizeof(rn)); 775 memcpy(&rn, &sl->reg_num, sizeof(rn));
703 776 w1_slave_detach(sl);
704 kfree(sl);
705 777
706 w1_attach_slave_device(dev, &rn); 778 w1_attach_slave_device(dev, &rn);
707 } 779 }
708 } 780 }
781 dev_dbg(&dev->dev, "Reconnecting slaves in device %s has been finished.\n", dev->name);
709 clear_bit(W1_MASTER_NEED_RECONNECT, &dev->flags); 782 clear_bit(W1_MASTER_NEED_RECONNECT, &dev->flags);
710 up(&dev->mutex); 783 up(&dev->mutex);
711 } 784 }
@@ -749,10 +822,7 @@ int w1_process(void *data)
749 822
750 list_for_each_entry_safe(sl, sln, &dev->slist, w1_slave_entry) { 823 list_for_each_entry_safe(sl, sln, &dev->slist, w1_slave_entry) {
751 if (!test_bit(W1_SLAVE_ACTIVE, (unsigned long *)&sl->flags) && !--sl->ttl) { 824 if (!test_bit(W1_SLAVE_ACTIVE, (unsigned long *)&sl->flags) && !--sl->ttl) {
752 list_del (&sl->w1_slave_entry); 825 w1_slave_detach(sl);
753
754 w1_slave_detach (sl);
755 kfree (sl);
756 826
757 dev->slave_count--; 827 dev->slave_count--;
758 } else if (test_bit(W1_SLAVE_ACTIVE, (unsigned long *)&sl->flags)) 828 } else if (test_bit(W1_SLAVE_ACTIVE, (unsigned long *)&sl->flags))
@@ -783,7 +853,7 @@ static int w1_init(void)
783 goto err_out_exit_init; 853 goto err_out_exit_init;
784 } 854 }
785 855
786 retval = driver_register(&w1_driver); 856 retval = driver_register(&w1_master_driver);
787 if (retval) { 857 if (retval) {
788 printk(KERN_ERR 858 printk(KERN_ERR
789 "Failed to register master driver. err=%d.\n", 859 "Failed to register master driver. err=%d.\n",
@@ -791,18 +861,29 @@ static int w1_init(void)
791 goto err_out_bus_unregister; 861 goto err_out_bus_unregister;
792 } 862 }
793 863
864 retval = driver_register(&w1_slave_driver);
865 if (retval) {
866 printk(KERN_ERR
867 "Failed to register master driver. err=%d.\n",
868 retval);
869 goto err_out_master_unregister;
870 }
871
794 control_thread = kernel_thread(&w1_control, NULL, 0); 872 control_thread = kernel_thread(&w1_control, NULL, 0);
795 if (control_thread < 0) { 873 if (control_thread < 0) {
796 printk(KERN_ERR "Failed to create control thread. err=%d\n", 874 printk(KERN_ERR "Failed to create control thread. err=%d\n",
797 control_thread); 875 control_thread);
798 retval = control_thread; 876 retval = control_thread;
799 goto err_out_driver_unregister; 877 goto err_out_slave_unregister;
800 } 878 }
801 879
802 return 0; 880 return 0;
803 881
804err_out_driver_unregister: 882err_out_slave_unregister:
805 driver_unregister(&w1_driver); 883 driver_unregister(&w1_slave_driver);
884
885err_out_master_unregister:
886 driver_unregister(&w1_master_driver);
806 887
807err_out_bus_unregister: 888err_out_bus_unregister:
808 bus_unregister(&w1_bus_type); 889 bus_unregister(&w1_bus_type);
@@ -821,7 +902,8 @@ static void w1_fini(void)
821 control_needs_exit = 1; 902 control_needs_exit = 1;
822 wait_for_completion(&w1_control_complete); 903 wait_for_completion(&w1_control_complete);
823 904
824 driver_unregister(&w1_driver); 905 driver_unregister(&w1_slave_driver);
906 driver_unregister(&w1_master_driver);
825 bus_unregister(&w1_bus_type); 907 bus_unregister(&w1_bus_type);
826} 908}
827 909