Input: rework handle creation code
- consolidate code for binding handlers to a device
- return error codes from handlers connect() methods back to input
core and log failures
Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
diff --git a/drivers/input/evdev.c b/drivers/input/evdev.c
index 64b47de..840fa19 100644
--- a/drivers/input/evdev.c
+++ b/drivers/input/evdev.c
@@ -605,21 +605,24 @@
.flush = evdev_flush
};
-static struct input_handle *evdev_connect(struct input_handler *handler, struct input_dev *dev,
- const struct input_device_id *id)
+static int evdev_connect(struct input_handler *handler, struct input_dev *dev,
+ const struct input_device_id *id)
{
struct evdev *evdev;
struct class_device *cdev;
+ dev_t devt;
int minor;
+ int error;
for (minor = 0; minor < EVDEV_MINORS && evdev_table[minor]; minor++);
if (minor == EVDEV_MINORS) {
printk(KERN_ERR "evdev: no more free evdev devices\n");
- return NULL;
+ return -ENFILE;
}
- if (!(evdev = kzalloc(sizeof(struct evdev), GFP_KERNEL)))
- return NULL;
+ evdev = kzalloc(sizeof(struct evdev), GFP_KERNEL);
+ if (!evdev)
+ return -ENOMEM;
INIT_LIST_HEAD(&evdev->list);
init_waitqueue_head(&evdev->wait);
@@ -634,15 +637,35 @@
evdev_table[minor] = evdev;
- cdev = class_device_create(&input_class, &dev->cdev,
- MKDEV(INPUT_MAJOR, EVDEV_MINOR_BASE + minor),
- dev->cdev.dev, evdev->name);
+ devt = MKDEV(INPUT_MAJOR, EVDEV_MINOR_BASE + minor),
+
+ cdev = class_device_create(&input_class, &dev->cdev, devt,
+ dev->cdev.dev, evdev->name);
+ if (IS_ERR(cdev)) {
+ error = PTR_ERR(cdev);
+ goto err_free_evdev;
+ }
/* temporary symlink to keep userspace happy */
- sysfs_create_link(&input_class.subsys.kset.kobj, &cdev->kobj,
- evdev->name);
+ error = sysfs_create_link(&input_class.subsys.kset.kobj,
+ &cdev->kobj, evdev->name);
+ if (error)
+ goto err_cdev_destroy;
- return &evdev->handle;
+ error = input_register_handle(&evdev->handle);
+ if (error)
+ goto err_remove_link;
+
+ return 0;
+
+ err_remove_link:
+ sysfs_remove_link(&input_class.subsys.kset.kobj, evdev->name);
+ err_cdev_destroy:
+ class_device_destroy(&input_class, devt);
+ err_free_evdev:
+ kfree(evdev);
+ evdev_table[minor] = NULL;
+ return error;
}
static void evdev_disconnect(struct input_handle *handle)
@@ -650,6 +673,8 @@
struct evdev *evdev = handle->private;
struct evdev_list *list;
+ input_unregister_handle(handle);
+
sysfs_remove_link(&input_class.subsys.kset.kobj, evdev->name);
class_device_destroy(&input_class,
MKDEV(INPUT_MAJOR, EVDEV_MINOR_BASE + evdev->minor));