diff options
-rw-r--r-- | drivers/base/bus.c | 77 |
1 files changed, 40 insertions, 37 deletions
diff --git a/drivers/base/bus.c b/drivers/base/bus.c index d7c5ea246a0b..7d8a7ce73fb3 100644 --- a/drivers/base/bus.c +++ b/drivers/base/bus.c | |||
@@ -518,34 +518,36 @@ int bus_add_driver(struct device_driver *drv) | |||
518 | struct bus_type * bus = get_bus(drv->bus); | 518 | struct bus_type * bus = get_bus(drv->bus); |
519 | int error = 0; | 519 | int error = 0; |
520 | 520 | ||
521 | if (bus) { | 521 | if (!bus) |
522 | pr_debug("bus %s: add driver %s\n", bus->name, drv->name); | 522 | return 0; |
523 | error = kobject_set_name(&drv->kobj, "%s", drv->name); | 523 | |
524 | if (error) | 524 | pr_debug("bus %s: add driver %s\n", bus->name, drv->name); |
525 | goto out_put_bus; | 525 | error = kobject_set_name(&drv->kobj, "%s", drv->name); |
526 | drv->kobj.kset = &bus->drivers; | 526 | if (error) |
527 | if ((error = kobject_register(&drv->kobj))) | 527 | goto out_put_bus; |
528 | goto out_put_bus; | 528 | drv->kobj.kset = &bus->drivers; |
529 | 529 | if ((error = kobject_register(&drv->kobj))) | |
530 | error = driver_attach(drv); | 530 | goto out_put_bus; |
531 | if (error) | 531 | |
532 | goto out_unregister; | 532 | error = driver_attach(drv); |
533 | klist_add_tail(&drv->knode_bus, &bus->klist_drivers); | 533 | if (error) |
534 | module_add_driver(drv->owner, drv); | 534 | goto out_unregister; |
535 | 535 | klist_add_tail(&drv->knode_bus, &bus->klist_drivers); | |
536 | error = driver_add_attrs(bus, drv); | 536 | module_add_driver(drv->owner, drv); |
537 | if (error) { | 537 | |
538 | /* How the hell do we get out of this pickle? Give up */ | 538 | error = driver_add_attrs(bus, drv); |
539 | printk(KERN_ERR "%s: driver_add_attrs(%s) failed\n", | 539 | if (error) { |
540 | __FUNCTION__, drv->name); | 540 | /* How the hell do we get out of this pickle? Give up */ |
541 | } | 541 | printk(KERN_ERR "%s: driver_add_attrs(%s) failed\n", |
542 | error = add_bind_files(drv); | 542 | __FUNCTION__, drv->name); |
543 | if (error) { | 543 | } |
544 | /* Ditto */ | 544 | error = add_bind_files(drv); |
545 | printk(KERN_ERR "%s: add_bind_files(%s) failed\n", | 545 | if (error) { |
546 | __FUNCTION__, drv->name); | 546 | /* Ditto */ |
547 | } | 547 | printk(KERN_ERR "%s: add_bind_files(%s) failed\n", |
548 | __FUNCTION__, drv->name); | ||
548 | } | 549 | } |
550 | |||
549 | return error; | 551 | return error; |
550 | out_unregister: | 552 | out_unregister: |
551 | kobject_unregister(&drv->kobj); | 553 | kobject_unregister(&drv->kobj); |
@@ -565,16 +567,17 @@ out_put_bus: | |||
565 | 567 | ||
566 | void bus_remove_driver(struct device_driver * drv) | 568 | void bus_remove_driver(struct device_driver * drv) |
567 | { | 569 | { |
568 | if (drv->bus) { | 570 | if (!drv->bus) |
569 | remove_bind_files(drv); | 571 | return; |
570 | driver_remove_attrs(drv->bus, drv); | 572 | |
571 | klist_remove(&drv->knode_bus); | 573 | remove_bind_files(drv); |
572 | pr_debug("bus %s: remove driver %s\n", drv->bus->name, drv->name); | 574 | driver_remove_attrs(drv->bus, drv); |
573 | driver_detach(drv); | 575 | klist_remove(&drv->knode_bus); |
574 | module_remove_driver(drv); | 576 | pr_debug("bus %s: remove driver %s\n", drv->bus->name, drv->name); |
575 | kobject_unregister(&drv->kobj); | 577 | driver_detach(drv); |
576 | put_bus(drv->bus); | 578 | module_remove_driver(drv); |
577 | } | 579 | kobject_unregister(&drv->kobj); |
580 | put_bus(drv->bus); | ||
578 | } | 581 | } |
579 | 582 | ||
580 | 583 | ||