diff options
author | James Bottomley <jejb@mulgrave.il.steeleye.com> | 2006-11-22 13:06:44 -0500 |
---|---|---|
committer | James Bottomley <jejb@mulgrave.il.steeleye.com> | 2006-11-22 13:06:44 -0500 |
commit | 0bd2af46839ad6262d25714a6ec0365db9d6b98f (patch) | |
tree | dcced72d230d69fd0c5816ac6dd03ab84799a93e /drivers/base/bus.c | |
parent | e138a5d2356729b8752e88520cc1525fae9794ac (diff) | |
parent | f26b90440cd74c78fe10c9bd5160809704a9627c (diff) |
Merge ../scsi-rc-fixes-2.6
Diffstat (limited to 'drivers/base/bus.c')
-rw-r--r-- | drivers/base/bus.c | 108 |
1 files changed, 64 insertions, 44 deletions
diff --git a/drivers/base/bus.c b/drivers/base/bus.c index 12173d16bea7..7d8a7ce73fb3 100644 --- a/drivers/base/bus.c +++ b/drivers/base/bus.c | |||
@@ -372,19 +372,30 @@ int bus_add_device(struct device * dev) | |||
372 | pr_debug("bus %s: add device %s\n", bus->name, dev->bus_id); | 372 | pr_debug("bus %s: add device %s\n", bus->name, dev->bus_id); |
373 | error = device_add_attrs(bus, dev); | 373 | error = device_add_attrs(bus, dev); |
374 | if (error) | 374 | if (error) |
375 | goto out; | 375 | goto out_put; |
376 | error = sysfs_create_link(&bus->devices.kobj, | 376 | error = sysfs_create_link(&bus->devices.kobj, |
377 | &dev->kobj, dev->bus_id); | 377 | &dev->kobj, dev->bus_id); |
378 | if (error) | 378 | if (error) |
379 | goto out; | 379 | goto out_id; |
380 | error = sysfs_create_link(&dev->kobj, | 380 | error = sysfs_create_link(&dev->kobj, |
381 | &dev->bus->subsys.kset.kobj, "subsystem"); | 381 | &dev->bus->subsys.kset.kobj, "subsystem"); |
382 | if (error) | 382 | if (error) |
383 | goto out; | 383 | goto out_subsys; |
384 | error = sysfs_create_link(&dev->kobj, | 384 | error = sysfs_create_link(&dev->kobj, |
385 | &dev->bus->subsys.kset.kobj, "bus"); | 385 | &dev->bus->subsys.kset.kobj, "bus"); |
386 | if (error) | ||
387 | goto out_deprecated; | ||
386 | } | 388 | } |
387 | out: | 389 | return 0; |
390 | |||
391 | out_deprecated: | ||
392 | sysfs_remove_link(&dev->kobj, "subsystem"); | ||
393 | out_subsys: | ||
394 | sysfs_remove_link(&bus->devices.kobj, dev->bus_id); | ||
395 | out_id: | ||
396 | device_remove_attrs(bus, dev); | ||
397 | out_put: | ||
398 | put_bus(dev->bus); | ||
388 | return error; | 399 | return error; |
389 | } | 400 | } |
390 | 401 | ||
@@ -428,8 +439,10 @@ void bus_remove_device(struct device * dev) | |||
428 | sysfs_remove_link(&dev->kobj, "bus"); | 439 | sysfs_remove_link(&dev->kobj, "bus"); |
429 | sysfs_remove_link(&dev->bus->devices.kobj, dev->bus_id); | 440 | sysfs_remove_link(&dev->bus->devices.kobj, dev->bus_id); |
430 | device_remove_attrs(dev->bus, dev); | 441 | device_remove_attrs(dev->bus, dev); |
431 | dev->is_registered = 0; | 442 | if (dev->is_registered) { |
432 | klist_del(&dev->knode_bus); | 443 | dev->is_registered = 0; |
444 | klist_del(&dev->knode_bus); | ||
445 | } | ||
433 | pr_debug("bus %s: remove device %s\n", dev->bus->name, dev->bus_id); | 446 | pr_debug("bus %s: remove device %s\n", dev->bus->name, dev->bus_id); |
434 | device_release_driver(dev); | 447 | device_release_driver(dev); |
435 | put_bus(dev->bus); | 448 | put_bus(dev->bus); |
@@ -505,34 +518,36 @@ int bus_add_driver(struct device_driver *drv) | |||
505 | struct bus_type * bus = get_bus(drv->bus); | 518 | struct bus_type * bus = get_bus(drv->bus); |
506 | int error = 0; | 519 | int error = 0; |
507 | 520 | ||
508 | if (bus) { | 521 | if (!bus) |
509 | pr_debug("bus %s: add driver %s\n", bus->name, drv->name); | 522 | return 0; |
510 | error = kobject_set_name(&drv->kobj, "%s", drv->name); | 523 | |
511 | if (error) | 524 | pr_debug("bus %s: add driver %s\n", bus->name, drv->name); |
512 | goto out_put_bus; | 525 | error = kobject_set_name(&drv->kobj, "%s", drv->name); |
513 | drv->kobj.kset = &bus->drivers; | 526 | if (error) |
514 | if ((error = kobject_register(&drv->kobj))) | 527 | goto out_put_bus; |
515 | goto out_put_bus; | 528 | drv->kobj.kset = &bus->drivers; |
516 | 529 | if ((error = kobject_register(&drv->kobj))) | |
517 | error = driver_attach(drv); | 530 | goto out_put_bus; |
518 | if (error) | 531 | |
519 | goto out_unregister; | 532 | error = driver_attach(drv); |
520 | klist_add_tail(&drv->knode_bus, &bus->klist_drivers); | 533 | if (error) |
521 | module_add_driver(drv->owner, drv); | 534 | goto out_unregister; |
522 | 535 | klist_add_tail(&drv->knode_bus, &bus->klist_drivers); | |
523 | error = driver_add_attrs(bus, drv); | 536 | module_add_driver(drv->owner, drv); |
524 | if (error) { | 537 | |
525 | /* How the hell do we get out of this pickle? Give up */ | 538 | error = driver_add_attrs(bus, drv); |
526 | printk(KERN_ERR "%s: driver_add_attrs(%s) failed\n", | 539 | if (error) { |
527 | __FUNCTION__, drv->name); | 540 | /* How the hell do we get out of this pickle? Give up */ |
528 | } | 541 | printk(KERN_ERR "%s: driver_add_attrs(%s) failed\n", |
529 | error = add_bind_files(drv); | 542 | __FUNCTION__, drv->name); |
530 | if (error) { | ||
531 | /* Ditto */ | ||
532 | printk(KERN_ERR "%s: add_bind_files(%s) failed\n", | ||
533 | __FUNCTION__, drv->name); | ||
534 | } | ||
535 | } | 543 | } |
544 | error = add_bind_files(drv); | ||
545 | if (error) { | ||
546 | /* Ditto */ | ||
547 | printk(KERN_ERR "%s: add_bind_files(%s) failed\n", | ||
548 | __FUNCTION__, drv->name); | ||
549 | } | ||
550 | |||
536 | return error; | 551 | return error; |
537 | out_unregister: | 552 | out_unregister: |
538 | kobject_unregister(&drv->kobj); | 553 | kobject_unregister(&drv->kobj); |
@@ -552,16 +567,17 @@ out_put_bus: | |||
552 | 567 | ||
553 | void bus_remove_driver(struct device_driver * drv) | 568 | void bus_remove_driver(struct device_driver * drv) |
554 | { | 569 | { |
555 | if (drv->bus) { | 570 | if (!drv->bus) |
556 | remove_bind_files(drv); | 571 | return; |
557 | driver_remove_attrs(drv->bus, drv); | 572 | |
558 | klist_remove(&drv->knode_bus); | 573 | remove_bind_files(drv); |
559 | pr_debug("bus %s: remove driver %s\n", drv->bus->name, drv->name); | 574 | driver_remove_attrs(drv->bus, drv); |
560 | driver_detach(drv); | 575 | klist_remove(&drv->knode_bus); |
561 | module_remove_driver(drv); | 576 | pr_debug("bus %s: remove driver %s\n", drv->bus->name, drv->name); |
562 | kobject_unregister(&drv->kobj); | 577 | driver_detach(drv); |
563 | put_bus(drv->bus); | 578 | module_remove_driver(drv); |
564 | } | 579 | kobject_unregister(&drv->kobj); |
580 | put_bus(drv->bus); | ||
565 | } | 581 | } |
566 | 582 | ||
567 | 583 | ||
@@ -732,11 +748,15 @@ int bus_register(struct bus_type * bus) | |||
732 | 748 | ||
733 | klist_init(&bus->klist_devices, klist_devices_get, klist_devices_put); | 749 | klist_init(&bus->klist_devices, klist_devices_get, klist_devices_put); |
734 | klist_init(&bus->klist_drivers, NULL, NULL); | 750 | klist_init(&bus->klist_drivers, NULL, NULL); |
735 | bus_add_attrs(bus); | 751 | retval = bus_add_attrs(bus); |
752 | if (retval) | ||
753 | goto bus_attrs_fail; | ||
736 | 754 | ||
737 | pr_debug("bus type '%s' registered\n", bus->name); | 755 | pr_debug("bus type '%s' registered\n", bus->name); |
738 | return 0; | 756 | return 0; |
739 | 757 | ||
758 | bus_attrs_fail: | ||
759 | kset_unregister(&bus->drivers); | ||
740 | bus_drivers_fail: | 760 | bus_drivers_fail: |
741 | kset_unregister(&bus->devices); | 761 | kset_unregister(&bus->devices); |
742 | bus_devices_fail: | 762 | bus_devices_fail: |