From: Dmitry Torokhov <dtor_core@ameritech.net>
To: Linus Torvalds <torvalds@osdl.org>
Cc: Vojtech Pavlik <vojtech@suse.cz>, Andrew Morton <akpm@osdl.org>,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: [git pull 11/14] Handle failures in input_register_device()
Date: Sun, 20 Nov 2005 01:36:22 -0500 [thread overview]
Message-ID: <20051120064420.617555000.dtor_core@ameritech.net> (raw)
In-Reply-To: 20051120063611.269343000.dtor_core@ameritech.net
[-- Attachment #1: input-device-registration-cleanup.patch --]
[-- Type: text/plain, Size: 3636 bytes --]
Input: handle failures in input_register_device()
Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
---
drivers/input/input.c | 63 ++++++++++++++++++++++++++++----------------------
1 files changed, 36 insertions(+), 27 deletions(-)
Index: work/drivers/input/input.c
===================================================================
--- work.orig/drivers/input/input.c
+++ work/drivers/input/input.c
@@ -536,7 +536,7 @@ static struct attribute *input_dev_attrs
NULL
};
-static struct attribute_group input_dev_group = {
+static struct attribute_group input_dev_attr_group = {
.attrs = input_dev_attrs,
};
@@ -717,35 +717,14 @@ struct input_dev *input_allocate_device(
return dev;
}
-static void input_register_classdevice(struct input_dev *dev)
-{
- static atomic_t input_no = ATOMIC_INIT(0);
- const char *path;
-
- __module_get(THIS_MODULE);
-
- dev->dev = dev->cdev.dev;
-
- snprintf(dev->cdev.class_id, sizeof(dev->cdev.class_id),
- "input%ld", (unsigned long) atomic_inc_return(&input_no) - 1);
-
- path = kobject_get_path(&dev->cdev.class->subsys.kset.kobj, GFP_KERNEL);
- printk(KERN_INFO "input: %s as %s/%s\n",
- dev->name ? dev->name : "Unspecified device",
- path ? path : "", dev->cdev.class_id);
- kfree(path);
-
- class_device_add(&dev->cdev);
- sysfs_create_group(&dev->cdev.kobj, &input_dev_group);
- sysfs_create_group(&dev->cdev.kobj, &input_dev_id_attr_group);
- sysfs_create_group(&dev->cdev.kobj, &input_dev_caps_attr_group);
-}
-
int input_register_device(struct input_dev *dev)
{
+ static atomic_t input_no = ATOMIC_INIT(0);
struct input_handle *handle;
struct input_handler *handler;
struct input_device_id *id;
+ const char *path;
+ int error;
if (!dev->dynalloc) {
printk(KERN_WARNING "input: device %s is statically allocated, will not register\n"
@@ -773,7 +752,32 @@ int input_register_device(struct input_d
INIT_LIST_HEAD(&dev->h_list);
list_add_tail(&dev->node, &input_dev_list);
- input_register_classdevice(dev);
+ dev->cdev.class = &input_class;
+ snprintf(dev->cdev.class_id, sizeof(dev->cdev.class_id),
+ "input%ld", (unsigned long) atomic_inc_return(&input_no) - 1);
+
+ error = class_device_add(&dev->cdev);
+ if (error)
+ return error;
+
+ error = sysfs_create_group(&dev->cdev.kobj, &input_dev_attr_group);
+ if (error)
+ goto fail1;
+
+ error = sysfs_create_group(&dev->cdev.kobj, &input_dev_id_attr_group);
+ if (error)
+ goto fail2;
+
+ error = sysfs_create_group(&dev->cdev.kobj, &input_dev_caps_attr_group);
+ if (error)
+ goto fail3;
+
+ __module_get(THIS_MODULE);
+
+ path = kobject_get_path(&dev->cdev.kobj, GFP_KERNEL);
+ printk(KERN_INFO "input: %s as %s\n",
+ dev->name ? dev->name : "Unspecified device", path ? path : "N/A");
+ kfree(path);
list_for_each_entry(handler, &input_handler_list, node)
if (!handler->blacklist || !input_match_device(handler->blacklist, dev))
@@ -784,6 +788,11 @@ int input_register_device(struct input_d
input_wakeup_procfs_readers();
return 0;
+
+ fail3: sysfs_remove_group(&dev->cdev.kobj, &input_dev_id_attr_group);
+ fail2: sysfs_remove_group(&dev->cdev.kobj, &input_dev_attr_group);
+ fail1: class_device_del(&dev->cdev);
+ return error;
}
void input_unregister_device(struct input_dev *dev)
@@ -805,7 +814,7 @@ void input_unregister_device(struct inpu
sysfs_remove_group(&dev->cdev.kobj, &input_dev_caps_attr_group);
sysfs_remove_group(&dev->cdev.kobj, &input_dev_id_attr_group);
- sysfs_remove_group(&dev->cdev.kobj, &input_dev_group);
+ sysfs_remove_group(&dev->cdev.kobj, &input_dev_attr_group);
class_device_unregister(&dev->cdev);
input_wakeup_procfs_readers();
next prev parent reply other threads:[~2005-11-20 6:49 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-11-20 6:36 [git pull 00/14] Input updates for 2.6.15 Dmitry Torokhov
2005-11-20 6:36 ` [git pull 01/14] atkbd - speed up setting leds/repeat state Dmitry Torokhov
2005-11-20 6:36 ` [git pull 02/14] Add Wistron driver Dmitry Torokhov
2005-11-20 6:36 ` [git pull 03/14] Wistron - disable for x86_64 Dmitry Torokhov
2005-11-20 9:52 ` Geert Uytterhoeven
2005-11-22 3:42 ` Dmitry Torokhov
2005-11-20 6:36 ` [git pull 04/14] Wistron - add support for Acer Aspire notebooks Dmitry Torokhov
2005-11-20 6:36 ` [git pull 05/14] Wistron - convert to dynamic input_dev allocation Dmitry Torokhov
2005-11-20 6:36 ` [git pull 06/14] Wistron - add PM support Dmitry Torokhov
2005-11-20 6:36 ` [git pull 07/14] wistron - disable wifi/bluetooth on suspend Dmitry Torokhov
2005-11-20 6:36 ` [git pull 08/14] Uinput: convert to dynalloc allocation Dmitry Torokhov
2005-11-20 6:36 ` [git pull 09/14] Uinput: add UI_SET_SWBIT ioctl Dmitry Torokhov
2005-11-23 22:53 ` Benjamin Herrenschmidt
2005-11-23 23:06 ` Benjamin Herrenschmidt
2005-11-23 23:13 ` Dmitry Torokhov
2005-11-23 23:01 ` Benjamin Herrenschmidt
2005-11-23 23:12 ` Dmitry Torokhov
2005-11-23 23:28 ` Benjamin Herrenschmidt
2005-11-20 6:36 ` [git pull 10/14] Uinput: dont use "interruptible" in FF code Dmitry Torokhov
2005-11-20 6:36 ` Dmitry Torokhov [this message]
2005-11-20 6:36 ` [git pull 12/14] Input - help swsusp Dmitry Torokhov
2005-11-20 6:36 ` [git pull 13/14] Input updates for 2.6.15 Dmitry Torokhov
2005-11-20 6:36 ` [git pull 14/14] Fix missing initialization in ir-kbd-gpio.c Dmitry Torokhov
2005-11-20 8:37 ` [git pull 00/14] Input updates for 2.6.15 Vojtech Pavlik
2005-11-20 17:04 ` Dmitry Torokhov
2005-11-20 17:19 ` Linus Torvalds
2005-11-20 17:42 ` Dmitry Torokhov
2005-11-20 18:17 ` Linus Torvalds
2005-11-22 3:40 ` Dmitry Torokhov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20051120064420.617555000.dtor_core@ameritech.net \
--to=dtor_core@ameritech.net \
--cc=akpm@osdl.org \
--cc=linux-kernel@vger.kernel.org \
--cc=torvalds@osdl.org \
--cc=vojtech@suse.cz \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox