aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/input
diff options
context:
space:
mode:
authorRandy Dunlap <rdunlap@xenotime.net>2006-07-19 01:14:55 -0400
committerDmitry Torokhov <dtor@insightbb.com>2006-07-19 01:14:55 -0400
commit73b59a3b1c09e4bfc678400b77b96134dcfbf112 (patch)
tree3dc175cd7606fb651a914cbb837268ee7438c838 /drivers/input
parent2c1dd69d28cba5a51e838897e0335f82a292f366 (diff)
Input: serio/gameport - check whether driver core calls succeeded
Signed-off-by: Randy Dunlap <rdunlap@xenotime.net> Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
Diffstat (limited to 'drivers/input')
-rw-r--r--drivers/input/gameport/gameport.c66
-rw-r--r--drivers/input/serio/serio.c65
2 files changed, 100 insertions, 31 deletions
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
54static struct bus_type gameport_bus; 54static struct bus_type gameport_bus;
55 55
56static void gameport_add_driver(struct gameport_driver *drv);
56static void gameport_add_port(struct gameport *gameport); 57static void gameport_add_port(struct gameport *gameport);
57static void gameport_destroy_port(struct gameport *gameport); 58static void gameport_destroy_port(struct gameport *gameport);
58static void gameport_reconnect_port(struct gameport *gameport); 59static void gameport_reconnect_port(struct gameport *gameport);
@@ -211,8 +212,14 @@ static void gameport_release_driver(struct gameport *gameport)
211 212
212static void gameport_find_driver(struct gameport *gameport) 213static 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
320static struct gameport_event *gameport_get_event(void) 326static 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)
342static void gameport_handle_event(void) 348static 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 */
545static void gameport_add_port(struct gameport *gameport) 550static 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
706static struct bus_type gameport_bus = { 719static 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
725static 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
712void __gameport_register_driver(struct gameport_driver *drv, struct module *owner) 736void __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
779static int __init gameport_init(void) 803static 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}
diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
index 6521034bc933..3e76ad71c9a0 100644
--- a/drivers/input/serio/serio.c
+++ b/drivers/input/serio/serio.c
@@ -62,6 +62,7 @@ static LIST_HEAD(serio_list);
62 62
63static struct bus_type serio_bus; 63static struct bus_type serio_bus;
64 64
65static void serio_add_driver(struct serio_driver *drv);
65static void serio_add_port(struct serio *serio); 66static void serio_add_port(struct serio *serio);
66static void serio_destroy_port(struct serio *serio); 67static void serio_destroy_port(struct serio *serio);
67static void serio_reconnect_port(struct serio *serio); 68static void serio_reconnect_port(struct serio *serio);
@@ -140,8 +141,14 @@ static void serio_release_driver(struct serio *serio)
140 141
141static void serio_find_driver(struct serio *serio) 142static void serio_find_driver(struct serio *serio)
142{ 143{
144 int error;
145
143 down_write(&serio_bus.subsys.rwsem); 146 down_write(&serio_bus.subsys.rwsem);
144 device_attach(&serio->dev); 147 error = device_attach(&serio->dev);
148 if (error < 0)
149 printk(KERN_WARNING
150 "serio: device_attach() failed for %s (%s), error: %d\n",
151 serio->phys, serio->name, error);
145 up_write(&serio_bus.subsys.rwsem); 152 up_write(&serio_bus.subsys.rwsem);
146} 153}
147 154
@@ -272,7 +279,6 @@ static struct serio_event *serio_get_event(void)
272static void serio_handle_event(void) 279static void serio_handle_event(void)
273{ 280{
274 struct serio_event *event; 281 struct serio_event *event;
275 struct serio_driver *serio_drv;
276 282
277 mutex_lock(&serio_mutex); 283 mutex_lock(&serio_mutex);
278 284
@@ -304,8 +310,7 @@ static void serio_handle_event(void)
304 break; 310 break;
305 311
306 case SERIO_REGISTER_DRIVER: 312 case SERIO_REGISTER_DRIVER:
307 serio_drv = event->object; 313 serio_add_driver(event->object);
308 driver_register(&serio_drv->driver);
309 break; 314 break;
310 315
311 default: 316 default:
@@ -525,6 +530,7 @@ static void serio_init_port(struct serio *serio)
525 530
526 __module_get(THIS_MODULE); 531 __module_get(THIS_MODULE);
527 532
533 INIT_LIST_HEAD(&serio->node);
528 spin_lock_init(&serio->lock); 534 spin_lock_init(&serio->lock);
529 mutex_init(&serio->drv_mutex); 535 mutex_init(&serio->drv_mutex);
530 device_initialize(&serio->dev); 536 device_initialize(&serio->dev);
@@ -542,6 +548,8 @@ static void serio_init_port(struct serio *serio)
542 */ 548 */
543static void serio_add_port(struct serio *serio) 549static void serio_add_port(struct serio *serio)
544{ 550{
551 int error;
552
545 if (serio->parent) { 553 if (serio->parent) {
546 serio_pause_rx(serio->parent); 554 serio_pause_rx(serio->parent);
547 serio->parent->child = serio; 555 serio->parent->child = serio;
@@ -551,9 +559,19 @@ static void serio_add_port(struct serio *serio)
551 list_add_tail(&serio->node, &serio_list); 559 list_add_tail(&serio->node, &serio_list);
552 if (serio->start) 560 if (serio->start)
553 serio->start(serio); 561 serio->start(serio);
554 device_add(&serio->dev); 562 error = device_add(&serio->dev);
555 sysfs_create_group(&serio->dev.kobj, &serio_id_attr_group); 563 if (error)
556 serio->registered = 1; 564 printk(KERN_ERR
565 "serio: device_add() failed for %s (%s), error: %d\n",
566 serio->phys, serio->name, error);
567 else {
568 serio->registered = 1;
569 error = sysfs_create_group(&serio->dev.kobj, &serio_id_attr_group);
570 if (error)
571 printk(KERN_ERR
572 "serio: sysfs_create_group() failed for %s (%s), error: %d\n",
573 serio->phys, serio->name, error);
574 }
557} 575}
558 576
559/* 577/*
@@ -583,10 +601,10 @@ static void serio_destroy_port(struct serio *serio)
583 if (serio->registered) { 601 if (serio->registered) {
584 sysfs_remove_group(&serio->dev.kobj, &serio_id_attr_group); 602 sysfs_remove_group(&serio->dev.kobj, &serio_id_attr_group);
585 device_del(&serio->dev); 603 device_del(&serio->dev);
586 list_del_init(&serio->node);
587 serio->registered = 0; 604 serio->registered = 0;
588 } 605 }
589 606
607 list_del_init(&serio->node);
590 serio_remove_pending_events(serio); 608 serio_remove_pending_events(serio);
591 put_device(&serio->dev); 609 put_device(&serio->dev);
592} 610}
@@ -756,6 +774,17 @@ static struct bus_type serio_bus = {
756 .remove = serio_driver_remove, 774 .remove = serio_driver_remove,
757}; 775};
758 776
777static void serio_add_driver(struct serio_driver *drv)
778{
779 int error;
780
781 error = driver_register(&drv->driver);
782 if (error)
783 printk(KERN_ERR
784 "serio: driver_register() failed for %s, error: %d\n",
785 drv->driver.name, error);
786}
787
759void __serio_register_driver(struct serio_driver *drv, struct module *owner) 788void __serio_register_driver(struct serio_driver *drv, struct module *owner)
760{ 789{
761 drv->driver.bus = &serio_bus; 790 drv->driver.bus = &serio_bus;
@@ -903,18 +932,26 @@ irqreturn_t serio_interrupt(struct serio *serio,
903 932
904static int __init serio_init(void) 933static int __init serio_init(void)
905{ 934{
906 serio_task = kthread_run(serio_thread, NULL, "kseriod"); 935 int error;
907 if (IS_ERR(serio_task)) {
908 printk(KERN_ERR "serio: Failed to start kseriod\n");
909 return PTR_ERR(serio_task);
910 }
911 936
912 serio_bus.dev_attrs = serio_device_attrs; 937 serio_bus.dev_attrs = serio_device_attrs;
913 serio_bus.drv_attrs = serio_driver_attrs; 938 serio_bus.drv_attrs = serio_driver_attrs;
914 serio_bus.match = serio_bus_match; 939 serio_bus.match = serio_bus_match;
915 serio_bus.uevent = serio_uevent; 940 serio_bus.uevent = serio_uevent;
916 serio_bus.resume = serio_resume; 941 serio_bus.resume = serio_resume;
917 bus_register(&serio_bus); 942 error = bus_register(&serio_bus);
943 if (error) {
944 printk(KERN_ERR "serio: failed to register serio bus, error: %d\n", error);
945 return error;
946 }
947
948 serio_task = kthread_run(serio_thread, NULL, "kseriod");
949 if (IS_ERR(serio_task)) {
950 bus_unregister(&serio_bus);
951 error = PTR_ERR(serio_task);
952 printk(KERN_ERR "serio: Failed to start kseriod, error: %d\n", error);
953 return error;
954 }
918 955
919 return 0; 956 return 0;
920} 957}