Commit 73b59a3b authored by Randy Dunlap's avatar Randy Dunlap Committed by Dmitry Torokhov

Input: serio/gameport - check whether driver core calls succeeded

Signed-off-by: default avatarRandy Dunlap <rdunlap@xenotime.net>
Signed-off-by: default avatarDmitry Torokhov <dtor@mail.ru>
parent 2c1dd69d
...@@ -53,6 +53,7 @@ static LIST_HEAD(gameport_list); ...@@ -53,6 +53,7 @@ static LIST_HEAD(gameport_list);
static struct bus_type gameport_bus; static struct bus_type gameport_bus;
static void gameport_add_driver(struct gameport_driver *drv);
static void gameport_add_port(struct gameport *gameport); static void gameport_add_port(struct gameport *gameport);
static void gameport_destroy_port(struct gameport *gameport); static void gameport_destroy_port(struct gameport *gameport);
static void gameport_reconnect_port(struct gameport *gameport); static void gameport_reconnect_port(struct gameport *gameport);
...@@ -211,8 +212,14 @@ static void gameport_release_driver(struct gameport *gameport) ...@@ -211,8 +212,14 @@ static void gameport_release_driver(struct gameport *gameport)
static void gameport_find_driver(struct gameport *gameport) static void gameport_find_driver(struct gameport *gameport)
{ {
int error;
down_write(&gameport_bus.subsys.rwsem); down_write(&gameport_bus.subsys.rwsem);
device_attach(&gameport->dev); error = device_attach(&gameport->dev);
if (error < 0)
printk(KERN_WARNING
"gameport: device_attach() failed for %s (%s), error: %d\n",
gameport->phys, gameport->name, error);
up_write(&gameport_bus.subsys.rwsem); up_write(&gameport_bus.subsys.rwsem);
} }
...@@ -316,7 +323,6 @@ static void gameport_remove_duplicate_events(struct gameport_event *event) ...@@ -316,7 +323,6 @@ static void gameport_remove_duplicate_events(struct gameport_event *event)
spin_unlock_irqrestore(&gameport_event_lock, flags); spin_unlock_irqrestore(&gameport_event_lock, flags);
} }
static struct gameport_event *gameport_get_event(void) static struct gameport_event *gameport_get_event(void)
{ {
struct gameport_event *event; struct gameport_event *event;
...@@ -342,7 +348,6 @@ static struct gameport_event *gameport_get_event(void) ...@@ -342,7 +348,6 @@ static struct gameport_event *gameport_get_event(void)
static void gameport_handle_event(void) static void gameport_handle_event(void)
{ {
struct gameport_event *event; struct gameport_event *event;
struct gameport_driver *gameport_drv;
mutex_lock(&gameport_mutex); mutex_lock(&gameport_mutex);
...@@ -369,8 +374,7 @@ static void gameport_handle_event(void) ...@@ -369,8 +374,7 @@ static void gameport_handle_event(void)
break; break;
case GAMEPORT_REGISTER_DRIVER: case GAMEPORT_REGISTER_DRIVER:
gameport_drv = event->object; gameport_add_driver(event->object);
driver_register(&gameport_drv->driver);
break; break;
default: default:
...@@ -532,6 +536,7 @@ static void gameport_init_port(struct gameport *gameport) ...@@ -532,6 +536,7 @@ static void gameport_init_port(struct gameport *gameport)
if (gameport->parent) if (gameport->parent)
gameport->dev.parent = &gameport->parent->dev; gameport->dev.parent = &gameport->parent->dev;
INIT_LIST_HEAD(&gameport->node);
spin_lock_init(&gameport->timer_lock); spin_lock_init(&gameport->timer_lock);
init_timer(&gameport->poll_timer); init_timer(&gameport->poll_timer);
gameport->poll_timer.function = gameport_run_poll_handler; gameport->poll_timer.function = gameport_run_poll_handler;
...@@ -544,6 +549,8 @@ static void gameport_init_port(struct gameport *gameport) ...@@ -544,6 +549,8 @@ static void gameport_init_port(struct gameport *gameport)
*/ */
static void gameport_add_port(struct gameport *gameport) static void gameport_add_port(struct gameport *gameport)
{ {
int error;
if (gameport->parent) if (gameport->parent)
gameport->parent->child = gameport; gameport->parent->child = gameport;
...@@ -558,8 +565,13 @@ static void gameport_add_port(struct gameport *gameport) ...@@ -558,8 +565,13 @@ static void gameport_add_port(struct gameport *gameport)
printk(KERN_INFO "gameport: %s is %s, speed %dkHz\n", printk(KERN_INFO "gameport: %s is %s, speed %dkHz\n",
gameport->name, gameport->phys, gameport->speed); gameport->name, gameport->phys, gameport->speed);
device_add(&gameport->dev); error = device_add(&gameport->dev);
gameport->registered = 1; if (error)
printk(KERN_ERR
"gameport: device_add() failed for %s (%s), error: %d\n",
gameport->phys, gameport->name, error);
else
gameport->registered = 1;
} }
/* /*
...@@ -583,10 +595,11 @@ static void gameport_destroy_port(struct gameport *gameport) ...@@ -583,10 +595,11 @@ static void gameport_destroy_port(struct gameport *gameport)
if (gameport->registered) { if (gameport->registered) {
device_del(&gameport->dev); device_del(&gameport->dev);
list_del_init(&gameport->node);
gameport->registered = 0; gameport->registered = 0;
} }
list_del_init(&gameport->node);
gameport_remove_pending_events(gameport); gameport_remove_pending_events(gameport);
put_device(&gameport->dev); put_device(&gameport->dev);
} }
...@@ -704,11 +717,22 @@ static int gameport_driver_remove(struct device *dev) ...@@ -704,11 +717,22 @@ static int gameport_driver_remove(struct device *dev)
} }
static struct bus_type gameport_bus = { static struct bus_type gameport_bus = {
.name = "gameport", .name = "gameport",
.probe = gameport_driver_probe, .probe = gameport_driver_probe,
.remove = gameport_driver_remove, .remove = gameport_driver_remove,
}; };
static void gameport_add_driver(struct gameport_driver *drv)
{
int error;
error = driver_register(&drv->driver);
if (error)
printk(KERN_ERR
"gameport: driver_register() failed for %s, error: %d\n",
drv->driver.name, error);
}
void __gameport_register_driver(struct gameport_driver *drv, struct module *owner) void __gameport_register_driver(struct gameport_driver *drv, struct module *owner)
{ {
drv->driver.bus = &gameport_bus; drv->driver.bus = &gameport_bus;
...@@ -778,16 +802,24 @@ void gameport_close(struct gameport *gameport) ...@@ -778,16 +802,24 @@ void gameport_close(struct gameport *gameport)
static int __init gameport_init(void) static int __init gameport_init(void)
{ {
gameport_task = kthread_run(gameport_thread, NULL, "kgameportd"); int error;
if (IS_ERR(gameport_task)) {
printk(KERN_ERR "gameport: Failed to start kgameportd\n");
return PTR_ERR(gameport_task);
}
gameport_bus.dev_attrs = gameport_device_attrs; gameport_bus.dev_attrs = gameport_device_attrs;
gameport_bus.drv_attrs = gameport_driver_attrs; gameport_bus.drv_attrs = gameport_driver_attrs;
gameport_bus.match = gameport_bus_match; gameport_bus.match = gameport_bus_match;
bus_register(&gameport_bus); error = bus_register(&gameport_bus);
if (error) {
printk(KERN_ERR "gameport: failed to register gameport bus, error: %d\n", error);
return error;
}
gameport_task = kthread_run(gameport_thread, NULL, "kgameportd");
if (IS_ERR(gameport_task)) {
bus_unregister(&gameport_bus);
error = PTR_ERR(gameport_task);
printk(KERN_ERR "gameport: Failed to start kgameportd, error: %d\n", error);
return error;
}
return 0; return 0;
} }
......
...@@ -62,6 +62,7 @@ static LIST_HEAD(serio_list); ...@@ -62,6 +62,7 @@ static LIST_HEAD(serio_list);
static struct bus_type serio_bus; static struct bus_type serio_bus;
static void serio_add_driver(struct serio_driver *drv);
static void serio_add_port(struct serio *serio); static void serio_add_port(struct serio *serio);
static void serio_destroy_port(struct serio *serio); static void serio_destroy_port(struct serio *serio);
static void serio_reconnect_port(struct serio *serio); static void serio_reconnect_port(struct serio *serio);
...@@ -140,8 +141,14 @@ static void serio_release_driver(struct serio *serio) ...@@ -140,8 +141,14 @@ static void serio_release_driver(struct serio *serio)
static void serio_find_driver(struct serio *serio) static void serio_find_driver(struct serio *serio)
{ {
int error;
down_write(&serio_bus.subsys.rwsem); down_write(&serio_bus.subsys.rwsem);
device_attach(&serio->dev); error = device_attach(&serio->dev);
if (error < 0)
printk(KERN_WARNING
"serio: device_attach() failed for %s (%s), error: %d\n",
serio->phys, serio->name, error);
up_write(&serio_bus.subsys.rwsem); up_write(&serio_bus.subsys.rwsem);
} }
...@@ -272,7 +279,6 @@ static struct serio_event *serio_get_event(void) ...@@ -272,7 +279,6 @@ static struct serio_event *serio_get_event(void)
static void serio_handle_event(void) static void serio_handle_event(void)
{ {
struct serio_event *event; struct serio_event *event;
struct serio_driver *serio_drv;
mutex_lock(&serio_mutex); mutex_lock(&serio_mutex);
...@@ -304,8 +310,7 @@ static void serio_handle_event(void) ...@@ -304,8 +310,7 @@ static void serio_handle_event(void)
break; break;
case SERIO_REGISTER_DRIVER: case SERIO_REGISTER_DRIVER:
serio_drv = event->object; serio_add_driver(event->object);
driver_register(&serio_drv->driver);
break; break;
default: default:
...@@ -525,6 +530,7 @@ static void serio_init_port(struct serio *serio) ...@@ -525,6 +530,7 @@ static void serio_init_port(struct serio *serio)
__module_get(THIS_MODULE); __module_get(THIS_MODULE);
INIT_LIST_HEAD(&serio->node);
spin_lock_init(&serio->lock); spin_lock_init(&serio->lock);
mutex_init(&serio->drv_mutex); mutex_init(&serio->drv_mutex);
device_initialize(&serio->dev); device_initialize(&serio->dev);
...@@ -542,6 +548,8 @@ static void serio_init_port(struct serio *serio) ...@@ -542,6 +548,8 @@ static void serio_init_port(struct serio *serio)
*/ */
static void serio_add_port(struct serio *serio) static void serio_add_port(struct serio *serio)
{ {
int error;
if (serio->parent) { if (serio->parent) {
serio_pause_rx(serio->parent); serio_pause_rx(serio->parent);
serio->parent->child = serio; serio->parent->child = serio;
...@@ -551,9 +559,19 @@ static void serio_add_port(struct serio *serio) ...@@ -551,9 +559,19 @@ static void serio_add_port(struct serio *serio)
list_add_tail(&serio->node, &serio_list); list_add_tail(&serio->node, &serio_list);
if (serio->start) if (serio->start)
serio->start(serio); serio->start(serio);
device_add(&serio->dev); error = device_add(&serio->dev);
sysfs_create_group(&serio->dev.kobj, &serio_id_attr_group); if (error)
serio->registered = 1; printk(KERN_ERR
"serio: device_add() failed for %s (%s), error: %d\n",
serio->phys, serio->name, error);
else {
serio->registered = 1;
error = sysfs_create_group(&serio->dev.kobj, &serio_id_attr_group);
if (error)
printk(KERN_ERR
"serio: sysfs_create_group() failed for %s (%s), error: %d\n",
serio->phys, serio->name, error);
}
} }
/* /*
...@@ -583,10 +601,10 @@ static void serio_destroy_port(struct serio *serio) ...@@ -583,10 +601,10 @@ static void serio_destroy_port(struct serio *serio)
if (serio->registered) { if (serio->registered) {
sysfs_remove_group(&serio->dev.kobj, &serio_id_attr_group); sysfs_remove_group(&serio->dev.kobj, &serio_id_attr_group);
device_del(&serio->dev); device_del(&serio->dev);
list_del_init(&serio->node);
serio->registered = 0; serio->registered = 0;
} }
list_del_init(&serio->node);
serio_remove_pending_events(serio); serio_remove_pending_events(serio);
put_device(&serio->dev); put_device(&serio->dev);
} }
...@@ -756,6 +774,17 @@ static struct bus_type serio_bus = { ...@@ -756,6 +774,17 @@ static struct bus_type serio_bus = {
.remove = serio_driver_remove, .remove = serio_driver_remove,
}; };
static void serio_add_driver(struct serio_driver *drv)
{
int error;
error = driver_register(&drv->driver);
if (error)
printk(KERN_ERR
"serio: driver_register() failed for %s, error: %d\n",
drv->driver.name, error);
}
void __serio_register_driver(struct serio_driver *drv, struct module *owner) void __serio_register_driver(struct serio_driver *drv, struct module *owner)
{ {
drv->driver.bus = &serio_bus; drv->driver.bus = &serio_bus;
...@@ -903,18 +932,26 @@ irqreturn_t serio_interrupt(struct serio *serio, ...@@ -903,18 +932,26 @@ irqreturn_t serio_interrupt(struct serio *serio,
static int __init serio_init(void) static int __init serio_init(void)
{ {
serio_task = kthread_run(serio_thread, NULL, "kseriod"); int error;
if (IS_ERR(serio_task)) {
printk(KERN_ERR "serio: Failed to start kseriod\n");
return PTR_ERR(serio_task);
}
serio_bus.dev_attrs = serio_device_attrs; serio_bus.dev_attrs = serio_device_attrs;
serio_bus.drv_attrs = serio_driver_attrs; serio_bus.drv_attrs = serio_driver_attrs;
serio_bus.match = serio_bus_match; serio_bus.match = serio_bus_match;
serio_bus.uevent = serio_uevent; serio_bus.uevent = serio_uevent;
serio_bus.resume = serio_resume; serio_bus.resume = serio_resume;
bus_register(&serio_bus); error = bus_register(&serio_bus);
if (error) {
printk(KERN_ERR "serio: failed to register serio bus, error: %d\n", error);
return error;
}
serio_task = kthread_run(serio_thread, NULL, "kseriod");
if (IS_ERR(serio_task)) {
bus_unregister(&serio_bus);
error = PTR_ERR(serio_task);
printk(KERN_ERR "serio: Failed to start kseriod, error: %d\n", error);
return error;
}
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment