diff options
Diffstat (limited to 'drivers/input/gameport')
-rw-r--r-- | drivers/input/gameport/fm801-gp.c | 4 | ||||
-rw-r--r-- | drivers/input/gameport/gameport.c | 66 |
2 files changed, 51 insertions, 19 deletions
diff --git a/drivers/input/gameport/fm801-gp.c b/drivers/input/gameport/fm801-gp.c index 47e93daa0fa7..90de5afe03c2 100644 --- a/drivers/input/gameport/fm801-gp.c +++ b/drivers/input/gameport/fm801-gp.c | |||
@@ -106,10 +106,10 @@ static int __devinit fm801_gp_probe(struct pci_dev *pci, const struct pci_device | |||
106 | gp->gameport = port; | 106 | gp->gameport = port; |
107 | gp->res_port = request_region(port->io, 0x10, "FM801 GP"); | 107 | gp->res_port = request_region(port->io, 0x10, "FM801 GP"); |
108 | if (!gp->res_port) { | 108 | if (!gp->res_port) { |
109 | kfree(gp); | ||
110 | gameport_free_port(port); | ||
111 | printk(KERN_DEBUG "fm801-gp: unable to grab region 0x%x-0x%x\n", | 109 | printk(KERN_DEBUG "fm801-gp: unable to grab region 0x%x-0x%x\n", |
112 | port->io, port->io + 0x0f); | 110 | port->io, port->io + 0x0f); |
111 | gameport_free_port(port); | ||
112 | kfree(gp); | ||
113 | return -EBUSY; | 113 | return -EBUSY; |
114 | } | 114 | } |
115 | 115 | ||
diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c index 36644bff379d..3f47ae55c6f3 100644 --- a/drivers/input/gameport/gameport.c +++ b/drivers/input/gameport/gameport.c | |||
@@ -53,6 +53,7 @@ static LIST_HEAD(gameport_list); | |||
53 | 53 | ||
54 | static struct bus_type gameport_bus; | 54 | static struct bus_type gameport_bus; |
55 | 55 | ||
56 | static void gameport_add_driver(struct gameport_driver *drv); | ||
56 | static void gameport_add_port(struct gameport *gameport); | 57 | static void gameport_add_port(struct gameport *gameport); |
57 | static void gameport_destroy_port(struct gameport *gameport); | 58 | static void gameport_destroy_port(struct gameport *gameport); |
58 | static void gameport_reconnect_port(struct gameport *gameport); | 59 | static void gameport_reconnect_port(struct gameport *gameport); |
@@ -211,8 +212,14 @@ static void gameport_release_driver(struct gameport *gameport) | |||
211 | 212 | ||
212 | static void gameport_find_driver(struct gameport *gameport) | 213 | static void gameport_find_driver(struct gameport *gameport) |
213 | { | 214 | { |
215 | int error; | ||
216 | |||
214 | down_write(&gameport_bus.subsys.rwsem); | 217 | down_write(&gameport_bus.subsys.rwsem); |
215 | device_attach(&gameport->dev); | 218 | error = device_attach(&gameport->dev); |
219 | if (error < 0) | ||
220 | printk(KERN_WARNING | ||
221 | "gameport: device_attach() failed for %s (%s), error: %d\n", | ||
222 | gameport->phys, gameport->name, error); | ||
216 | up_write(&gameport_bus.subsys.rwsem); | 223 | up_write(&gameport_bus.subsys.rwsem); |
217 | } | 224 | } |
218 | 225 | ||
@@ -316,7 +323,6 @@ static void gameport_remove_duplicate_events(struct gameport_event *event) | |||
316 | spin_unlock_irqrestore(&gameport_event_lock, flags); | 323 | spin_unlock_irqrestore(&gameport_event_lock, flags); |
317 | } | 324 | } |
318 | 325 | ||
319 | |||
320 | static struct gameport_event *gameport_get_event(void) | 326 | static struct gameport_event *gameport_get_event(void) |
321 | { | 327 | { |
322 | struct gameport_event *event; | 328 | struct gameport_event *event; |
@@ -342,7 +348,6 @@ static struct gameport_event *gameport_get_event(void) | |||
342 | static void gameport_handle_event(void) | 348 | static void gameport_handle_event(void) |
343 | { | 349 | { |
344 | struct gameport_event *event; | 350 | struct gameport_event *event; |
345 | struct gameport_driver *gameport_drv; | ||
346 | 351 | ||
347 | mutex_lock(&gameport_mutex); | 352 | mutex_lock(&gameport_mutex); |
348 | 353 | ||
@@ -369,8 +374,7 @@ static void gameport_handle_event(void) | |||
369 | break; | 374 | break; |
370 | 375 | ||
371 | case GAMEPORT_REGISTER_DRIVER: | 376 | case GAMEPORT_REGISTER_DRIVER: |
372 | gameport_drv = event->object; | 377 | gameport_add_driver(event->object); |
373 | driver_register(&gameport_drv->driver); | ||
374 | break; | 378 | break; |
375 | 379 | ||
376 | default: | 380 | default: |
@@ -532,6 +536,7 @@ static void gameport_init_port(struct gameport *gameport) | |||
532 | if (gameport->parent) | 536 | if (gameport->parent) |
533 | gameport->dev.parent = &gameport->parent->dev; | 537 | gameport->dev.parent = &gameport->parent->dev; |
534 | 538 | ||
539 | INIT_LIST_HEAD(&gameport->node); | ||
535 | spin_lock_init(&gameport->timer_lock); | 540 | spin_lock_init(&gameport->timer_lock); |
536 | init_timer(&gameport->poll_timer); | 541 | init_timer(&gameport->poll_timer); |
537 | gameport->poll_timer.function = gameport_run_poll_handler; | 542 | gameport->poll_timer.function = gameport_run_poll_handler; |
@@ -544,6 +549,8 @@ static void gameport_init_port(struct gameport *gameport) | |||
544 | */ | 549 | */ |
545 | static void gameport_add_port(struct gameport *gameport) | 550 | static void gameport_add_port(struct gameport *gameport) |
546 | { | 551 | { |
552 | int error; | ||
553 | |||
547 | if (gameport->parent) | 554 | if (gameport->parent) |
548 | gameport->parent->child = gameport; | 555 | gameport->parent->child = gameport; |
549 | 556 | ||
@@ -558,8 +565,13 @@ static void gameport_add_port(struct gameport *gameport) | |||
558 | printk(KERN_INFO "gameport: %s is %s, speed %dkHz\n", | 565 | printk(KERN_INFO "gameport: %s is %s, speed %dkHz\n", |
559 | gameport->name, gameport->phys, gameport->speed); | 566 | gameport->name, gameport->phys, gameport->speed); |
560 | 567 | ||
561 | device_add(&gameport->dev); | 568 | error = device_add(&gameport->dev); |
562 | gameport->registered = 1; | 569 | if (error) |
570 | printk(KERN_ERR | ||
571 | "gameport: device_add() failed for %s (%s), error: %d\n", | ||
572 | gameport->phys, gameport->name, error); | ||
573 | else | ||
574 | gameport->registered = 1; | ||
563 | } | 575 | } |
564 | 576 | ||
565 | /* | 577 | /* |
@@ -583,10 +595,11 @@ static void gameport_destroy_port(struct gameport *gameport) | |||
583 | 595 | ||
584 | if (gameport->registered) { | 596 | if (gameport->registered) { |
585 | device_del(&gameport->dev); | 597 | device_del(&gameport->dev); |
586 | list_del_init(&gameport->node); | ||
587 | gameport->registered = 0; | 598 | gameport->registered = 0; |
588 | } | 599 | } |
589 | 600 | ||
601 | list_del_init(&gameport->node); | ||
602 | |||
590 | gameport_remove_pending_events(gameport); | 603 | gameport_remove_pending_events(gameport); |
591 | put_device(&gameport->dev); | 604 | put_device(&gameport->dev); |
592 | } | 605 | } |
@@ -704,11 +717,22 @@ static int gameport_driver_remove(struct device *dev) | |||
704 | } | 717 | } |
705 | 718 | ||
706 | static struct bus_type gameport_bus = { | 719 | static struct bus_type gameport_bus = { |
707 | .name = "gameport", | 720 | .name = "gameport", |
708 | .probe = gameport_driver_probe, | 721 | .probe = gameport_driver_probe, |
709 | .remove = gameport_driver_remove, | 722 | .remove = gameport_driver_remove, |
710 | }; | 723 | }; |
711 | 724 | ||
725 | static void gameport_add_driver(struct gameport_driver *drv) | ||
726 | { | ||
727 | int error; | ||
728 | |||
729 | error = driver_register(&drv->driver); | ||
730 | if (error) | ||
731 | printk(KERN_ERR | ||
732 | "gameport: driver_register() failed for %s, error: %d\n", | ||
733 | drv->driver.name, error); | ||
734 | } | ||
735 | |||
712 | void __gameport_register_driver(struct gameport_driver *drv, struct module *owner) | 736 | void __gameport_register_driver(struct gameport_driver *drv, struct module *owner) |
713 | { | 737 | { |
714 | drv->driver.bus = &gameport_bus; | 738 | drv->driver.bus = &gameport_bus; |
@@ -778,16 +802,24 @@ void gameport_close(struct gameport *gameport) | |||
778 | 802 | ||
779 | static int __init gameport_init(void) | 803 | static int __init gameport_init(void) |
780 | { | 804 | { |
781 | gameport_task = kthread_run(gameport_thread, NULL, "kgameportd"); | 805 | int error; |
782 | if (IS_ERR(gameport_task)) { | ||
783 | printk(KERN_ERR "gameport: Failed to start kgameportd\n"); | ||
784 | return PTR_ERR(gameport_task); | ||
785 | } | ||
786 | 806 | ||
787 | gameport_bus.dev_attrs = gameport_device_attrs; | 807 | gameport_bus.dev_attrs = gameport_device_attrs; |
788 | gameport_bus.drv_attrs = gameport_driver_attrs; | 808 | gameport_bus.drv_attrs = gameport_driver_attrs; |
789 | gameport_bus.match = gameport_bus_match; | 809 | gameport_bus.match = gameport_bus_match; |
790 | bus_register(&gameport_bus); | 810 | error = bus_register(&gameport_bus); |
811 | if (error) { | ||
812 | printk(KERN_ERR "gameport: failed to register gameport bus, error: %d\n", error); | ||
813 | return error; | ||
814 | } | ||
815 | |||
816 | gameport_task = kthread_run(gameport_thread, NULL, "kgameportd"); | ||
817 | if (IS_ERR(gameport_task)) { | ||
818 | bus_unregister(&gameport_bus); | ||
819 | error = PTR_ERR(gameport_task); | ||
820 | printk(KERN_ERR "gameport: Failed to start kgameportd, error: %d\n", error); | ||
821 | return error; | ||
822 | } | ||
791 | 823 | ||
792 | return 0; | 824 | return 0; |
793 | } | 825 | } |