aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/input
diff options
context:
space:
mode:
authorDmitry Torokhov <dtor@insightbb.com>2006-11-05 22:40:19 -0500
committerDmitry Torokhov <dtor@insightbb.com>2006-11-05 22:40:19 -0500
commit721556150e397f606a3f029736d77a27503f94e2 (patch)
tree1bdce32c4d1421f0dfbd9871986fcb7eaa6aba56 /drivers/input
parent127278ce2254c61f1346500374d61e33f74a8729 (diff)
Input: mice - handle errors when registering input devices
Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
Diffstat (limited to 'drivers/input')
-rw-r--r--drivers/input/mouse/amimouse.c11
-rw-r--r--drivers/input/mouse/inport.c23
-rw-r--r--drivers/input/mouse/logibm.c24
-rw-r--r--drivers/input/mouse/pc110pad.c26
-rw-r--r--drivers/input/mouse/psmouse-base.c84
-rw-r--r--drivers/input/mouse/rpcmouse.c20
-rw-r--r--drivers/input/mouse/sermouse.c13
-rw-r--r--drivers/input/mouse/vsxxxaa.c13
8 files changed, 154 insertions, 60 deletions
diff --git a/drivers/input/mouse/amimouse.c b/drivers/input/mouse/amimouse.c
index 599a7b2dc519..239a0e16d91a 100644
--- a/drivers/input/mouse/amimouse.c
+++ b/drivers/input/mouse/amimouse.c
@@ -95,10 +95,13 @@ static void amimouse_close(struct input_dev *dev)
95 95
96static int __init amimouse_init(void) 96static int __init amimouse_init(void)
97{ 97{
98 int err;
99
98 if (!MACH_IS_AMIGA || !AMIGAHW_PRESENT(AMI_MOUSE)) 100 if (!MACH_IS_AMIGA || !AMIGAHW_PRESENT(AMI_MOUSE))
99 return -ENODEV; 101 return -ENODEV;
100 102
101 if (!(amimouse_dev = input_allocate_device())) 103 amimouse_dev = input_allocate_device();
104 if (!amimouse_dev)
102 return -ENOMEM; 105 return -ENOMEM;
103 106
104 amimouse_dev->name = "Amiga mouse"; 107 amimouse_dev->name = "Amiga mouse";
@@ -114,7 +117,11 @@ static int __init amimouse_init(void)
114 amimouse_dev->open = amimouse_open; 117 amimouse_dev->open = amimouse_open;
115 amimouse_dev->close = amimouse_close; 118 amimouse_dev->close = amimouse_close;
116 119
117 input_register_device(amimouse_dev); 120 err = input_register_device(amimouse_dev);
121 if (err) {
122 input_free_device(amimouse_dev);
123 return err;
124 }
118 125
119 return 0; 126 return 0;
120} 127}
diff --git a/drivers/input/mouse/inport.c b/drivers/input/mouse/inport.c
index e1252fa9a107..13dd96785e39 100644
--- a/drivers/input/mouse/inport.c
+++ b/drivers/input/mouse/inport.c
@@ -135,6 +135,7 @@ static void inport_close(struct input_dev *dev)
135static int __init inport_init(void) 135static int __init inport_init(void)
136{ 136{
137 unsigned char a, b, c; 137 unsigned char a, b, c;
138 int err;
138 139
139 if (!request_region(INPORT_BASE, INPORT_EXTENT, "inport")) { 140 if (!request_region(INPORT_BASE, INPORT_EXTENT, "inport")) {
140 printk(KERN_ERR "inport.c: Can't allocate ports at %#x\n", INPORT_BASE); 141 printk(KERN_ERR "inport.c: Can't allocate ports at %#x\n", INPORT_BASE);
@@ -145,15 +146,16 @@ static int __init inport_init(void)
145 b = inb(INPORT_SIGNATURE_PORT); 146 b = inb(INPORT_SIGNATURE_PORT);
146 c = inb(INPORT_SIGNATURE_PORT); 147 c = inb(INPORT_SIGNATURE_PORT);
147 if (a == b || a != c) { 148 if (a == b || a != c) {
148 release_region(INPORT_BASE, INPORT_EXTENT);
149 printk(KERN_ERR "inport.c: Didn't find InPort mouse at %#x\n", INPORT_BASE); 149 printk(KERN_ERR "inport.c: Didn't find InPort mouse at %#x\n", INPORT_BASE);
150 return -ENODEV; 150 err = -ENODEV;
151 goto err_release_region;
151 } 152 }
152 153
153 if (!(inport_dev = input_allocate_device())) { 154 inport_dev = input_allocate_device();
155 if (!inport_dev) {
154 printk(KERN_ERR "inport.c: Not enough memory for input device\n"); 156 printk(KERN_ERR "inport.c: Not enough memory for input device\n");
155 release_region(INPORT_BASE, INPORT_EXTENT); 157 err = -ENOMEM;
156 return -ENOMEM; 158 goto err_release_region;
157 } 159 }
158 160
159 inport_dev->name = INPORT_NAME; 161 inport_dev->name = INPORT_NAME;
@@ -174,9 +176,18 @@ static int __init inport_init(void)
174 outb(INPORT_REG_MODE, INPORT_CONTROL_PORT); 176 outb(INPORT_REG_MODE, INPORT_CONTROL_PORT);
175 outb(INPORT_MODE_BASE, INPORT_DATA_PORT); 177 outb(INPORT_MODE_BASE, INPORT_DATA_PORT);
176 178
177 input_register_device(inport_dev); 179 err = input_register_device(inport_dev);
180 if (err)
181 goto err_free_dev;
178 182
179 return 0; 183 return 0;
184
185 err_free_dev:
186 input_free_device(inport_dev);
187 err_release_region:
188 release_region(INPORT_BASE, INPORT_EXTENT);
189
190 return err;
180} 191}
181 192
182static void __exit inport_exit(void) 193static void __exit inport_exit(void)
diff --git a/drivers/input/mouse/logibm.c b/drivers/input/mouse/logibm.c
index 8e9c2f3d69a8..db205995bffd 100644
--- a/drivers/input/mouse/logibm.c
+++ b/drivers/input/mouse/logibm.c
@@ -124,6 +124,8 @@ static void logibm_close(struct input_dev *dev)
124 124
125static int __init logibm_init(void) 125static int __init logibm_init(void)
126{ 126{
127 int err;
128
127 if (!request_region(LOGIBM_BASE, LOGIBM_EXTENT, "logibm")) { 129 if (!request_region(LOGIBM_BASE, LOGIBM_EXTENT, "logibm")) {
128 printk(KERN_ERR "logibm.c: Can't allocate ports at %#x\n", LOGIBM_BASE); 130 printk(KERN_ERR "logibm.c: Can't allocate ports at %#x\n", LOGIBM_BASE);
129 return -EBUSY; 131 return -EBUSY;
@@ -134,18 +136,19 @@ static int __init logibm_init(void)
134 udelay(100); 136 udelay(100);
135 137
136 if (inb(LOGIBM_SIGNATURE_PORT) != LOGIBM_SIGNATURE_BYTE) { 138 if (inb(LOGIBM_SIGNATURE_PORT) != LOGIBM_SIGNATURE_BYTE) {
137 release_region(LOGIBM_BASE, LOGIBM_EXTENT);
138 printk(KERN_ERR "logibm.c: Didn't find Logitech busmouse at %#x\n", LOGIBM_BASE); 139 printk(KERN_ERR "logibm.c: Didn't find Logitech busmouse at %#x\n", LOGIBM_BASE);
139 return -ENODEV; 140 err = -ENODEV;
141 goto err_release_region;
140 } 142 }
141 143
142 outb(LOGIBM_DEFAULT_MODE, LOGIBM_CONFIG_PORT); 144 outb(LOGIBM_DEFAULT_MODE, LOGIBM_CONFIG_PORT);
143 outb(LOGIBM_DISABLE_IRQ, LOGIBM_CONTROL_PORT); 145 outb(LOGIBM_DISABLE_IRQ, LOGIBM_CONTROL_PORT);
144 146
145 if (!(logibm_dev = input_allocate_device())) { 147 logibm_dev = input_allocate_device();
148 if (!logibm_dev) {
146 printk(KERN_ERR "logibm.c: Not enough memory for input device\n"); 149 printk(KERN_ERR "logibm.c: Not enough memory for input device\n");
147 release_region(LOGIBM_BASE, LOGIBM_EXTENT); 150 err = -ENOMEM;
148 return -ENOMEM; 151 goto err_release_region;
149 } 152 }
150 153
151 logibm_dev->name = "Logitech bus mouse"; 154 logibm_dev->name = "Logitech bus mouse";
@@ -162,9 +165,18 @@ static int __init logibm_init(void)
162 logibm_dev->open = logibm_open; 165 logibm_dev->open = logibm_open;
163 logibm_dev->close = logibm_close; 166 logibm_dev->close = logibm_close;
164 167
165 input_register_device(logibm_dev); 168 err = input_register_device(logibm_dev);
169 if (err)
170 goto err_free_dev;
166 171
167 return 0; 172 return 0;
173
174 err_free_dev:
175 input_free_device(logibm_dev);
176 err_release_region:
177 release_region(LOGIBM_BASE, LOGIBM_EXTENT);
178
179 return err;
168} 180}
169 181
170static void __exit logibm_exit(void) 182static void __exit logibm_exit(void)
diff --git a/drivers/input/mouse/pc110pad.c b/drivers/input/mouse/pc110pad.c
index 8c075aa7223b..f155c1fea04e 100644
--- a/drivers/input/mouse/pc110pad.c
+++ b/drivers/input/mouse/pc110pad.c
@@ -108,6 +108,7 @@ static int pc110pad_open(struct input_dev *dev)
108static int __init pc110pad_init(void) 108static int __init pc110pad_init(void)
109{ 109{
110 struct pci_dev *dev; 110 struct pci_dev *dev;
111 int err;
111 112
112 dev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, NULL); 113 dev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, NULL);
113 if (dev) { 114 if (dev) {
@@ -124,16 +125,16 @@ static int __init pc110pad_init(void)
124 outb(PC110PAD_OFF, pc110pad_io + 2); 125 outb(PC110PAD_OFF, pc110pad_io + 2);
125 126
126 if (request_irq(pc110pad_irq, pc110pad_interrupt, 0, "pc110pad", NULL)) { 127 if (request_irq(pc110pad_irq, pc110pad_interrupt, 0, "pc110pad", NULL)) {
127 release_region(pc110pad_io, 4);
128 printk(KERN_ERR "pc110pad: Unable to get irq %d.\n", pc110pad_irq); 128 printk(KERN_ERR "pc110pad: Unable to get irq %d.\n", pc110pad_irq);
129 return -EBUSY; 129 err = -EBUSY;
130 goto err_release_region;
130 } 131 }
131 132
132 if (!(pc110pad_dev = input_allocate_device())) { 133 pc110pad_dev = input_allocate_device();
133 free_irq(pc110pad_irq, NULL); 134 if (!pc110pad_dev) {
134 release_region(pc110pad_io, 4);
135 printk(KERN_ERR "pc110pad: Not enough memory.\n"); 135 printk(KERN_ERR "pc110pad: Not enough memory.\n");
136 return -ENOMEM; 136 err = -ENOMEM;
137 goto err_free_irq;
137 } 138 }
138 139
139 pc110pad_dev->name = "IBM PC110 TouchPad"; 140 pc110pad_dev->name = "IBM PC110 TouchPad";
@@ -153,9 +154,20 @@ static int __init pc110pad_init(void)
153 pc110pad_dev->open = pc110pad_open; 154 pc110pad_dev->open = pc110pad_open;
154 pc110pad_dev->close = pc110pad_close; 155 pc110pad_dev->close = pc110pad_close;
155 156
156 input_register_device(pc110pad_dev); 157 err = input_register_device(pc110pad_dev);
158 if (err)
159 goto err_free_dev;
157 160
158 return 0; 161 return 0;
162
163 err_free_dev:
164 input_free_device(pc110pad_dev);
165 err_free_irq:
166 free_irq(pc110pad_irq, NULL);
167 err_release_region:
168 release_region(pc110pad_io, 4);
169
170 return err;
159} 171}
160 172
161static void __exit pc110pad_exit(void) 173static void __exit pc110pad_exit(void)
diff --git a/drivers/input/mouse/psmouse-base.c b/drivers/input/mouse/psmouse-base.c
index 6f9b2c7cc9c2..9144df65e703 100644
--- a/drivers/input/mouse/psmouse-base.c
+++ b/drivers/input/mouse/psmouse-base.c
@@ -1102,7 +1102,7 @@ static int psmouse_connect(struct serio *serio, struct serio_driver *drv)
1102{ 1102{
1103 struct psmouse *psmouse, *parent = NULL; 1103 struct psmouse *psmouse, *parent = NULL;
1104 struct input_dev *input_dev; 1104 struct input_dev *input_dev;
1105 int retval = -ENOMEM; 1105 int retval = 0, error = -ENOMEM;
1106 1106
1107 mutex_lock(&psmouse_mutex); 1107 mutex_lock(&psmouse_mutex);
1108 1108
@@ -1118,7 +1118,7 @@ static int psmouse_connect(struct serio *serio, struct serio_driver *drv)
1118 psmouse = kzalloc(sizeof(struct psmouse), GFP_KERNEL); 1118 psmouse = kzalloc(sizeof(struct psmouse), GFP_KERNEL);
1119 input_dev = input_allocate_device(); 1119 input_dev = input_allocate_device();
1120 if (!psmouse || !input_dev) 1120 if (!psmouse || !input_dev)
1121 goto out; 1121 goto err_free;
1122 1122
1123 ps2_init(&psmouse->ps2dev, serio); 1123 ps2_init(&psmouse->ps2dev, serio);
1124 INIT_WORK(&psmouse->resync_work, psmouse_resync, psmouse); 1124 INIT_WORK(&psmouse->resync_work, psmouse_resync, psmouse);
@@ -1129,14 +1129,13 @@ static int psmouse_connect(struct serio *serio, struct serio_driver *drv)
1129 1129
1130 serio_set_drvdata(serio, psmouse); 1130 serio_set_drvdata(serio, psmouse);
1131 1131
1132 retval = serio_open(serio, drv); 1132 error = serio_open(serio, drv);
1133 if (retval) 1133 if (error)
1134 goto out; 1134 goto err_clear_drvdata;
1135 1135
1136 if (psmouse_probe(psmouse) < 0) { 1136 if (psmouse_probe(psmouse) < 0) {
1137 serio_close(serio); 1137 error = -ENODEV;
1138 retval = -ENODEV; 1138 goto err_close_serio;
1139 goto out;
1140 } 1139 }
1141 1140
1142 psmouse->rate = psmouse_rate; 1141 psmouse->rate = psmouse_rate;
@@ -1150,30 +1149,44 @@ static int psmouse_connect(struct serio *serio, struct serio_driver *drv)
1150 psmouse_set_state(psmouse, PSMOUSE_CMD_MODE); 1149 psmouse_set_state(psmouse, PSMOUSE_CMD_MODE);
1151 psmouse_initialize(psmouse); 1150 psmouse_initialize(psmouse);
1152 1151
1153 input_register_device(psmouse->dev); 1152 error = input_register_device(psmouse->dev);
1153 if (error)
1154 goto err_protocol_disconnect;
1154 1155
1155 if (parent && parent->pt_activate) 1156 if (parent && parent->pt_activate)
1156 parent->pt_activate(parent); 1157 parent->pt_activate(parent);
1157 1158
1158 sysfs_create_group(&serio->dev.kobj, &psmouse_attribute_group); 1159 error = sysfs_create_group(&serio->dev.kobj, &psmouse_attribute_group);
1160 if (error)
1161 goto err_pt_deactivate;
1159 1162
1160 psmouse_activate(psmouse); 1163 psmouse_activate(psmouse);
1161 1164
1162 retval = 0; 1165 out:
1163
1164out:
1165 if (retval) {
1166 serio_set_drvdata(serio, NULL);
1167 input_free_device(input_dev);
1168 kfree(psmouse);
1169 }
1170
1171 /* If this is a pass-through port the parent needs to be re-activated */ 1166 /* If this is a pass-through port the parent needs to be re-activated */
1172 if (parent) 1167 if (parent)
1173 psmouse_activate(parent); 1168 psmouse_activate(parent);
1174 1169
1175 mutex_unlock(&psmouse_mutex); 1170 mutex_unlock(&psmouse_mutex);
1176 return retval; 1171 return retval;
1172
1173 err_pt_deactivate:
1174 if (parent && parent->pt_deactivate)
1175 parent->pt_deactivate(parent);
1176 err_protocol_disconnect:
1177 if (psmouse->disconnect)
1178 psmouse->disconnect(psmouse);
1179 psmouse_set_state(psmouse, PSMOUSE_IGNORE);
1180 err_close_serio:
1181 serio_close(serio);
1182 err_clear_drvdata:
1183 serio_set_drvdata(serio, NULL);
1184 err_free:
1185 input_free_device(input_dev);
1186 kfree(psmouse);
1187
1188 retval = error;
1189 goto out;
1177} 1190}
1178 1191
1179 1192
@@ -1365,17 +1378,20 @@ static ssize_t psmouse_attr_set_protocol(struct psmouse *psmouse, void *data, co
1365{ 1378{
1366 struct serio *serio = psmouse->ps2dev.serio; 1379 struct serio *serio = psmouse->ps2dev.serio;
1367 struct psmouse *parent = NULL; 1380 struct psmouse *parent = NULL;
1368 struct input_dev *new_dev; 1381 struct input_dev *old_dev, *new_dev;
1369 const struct psmouse_protocol *proto; 1382 const struct psmouse_protocol *proto, *old_proto;
1383 int error;
1370 int retry = 0; 1384 int retry = 0;
1371 1385
1372 if (!(proto = psmouse_protocol_by_name(buf, count))) 1386 proto = psmouse_protocol_by_name(buf, count);
1387 if (!proto)
1373 return -EINVAL; 1388 return -EINVAL;
1374 1389
1375 if (psmouse->type == proto->type) 1390 if (psmouse->type == proto->type)
1376 return count; 1391 return count;
1377 1392
1378 if (!(new_dev = input_allocate_device())) 1393 new_dev = input_allocate_device();
1394 if (!new_dev)
1379 return -ENOMEM; 1395 return -ENOMEM;
1380 1396
1381 while (serio->child) { 1397 while (serio->child) {
@@ -1408,11 +1424,13 @@ static ssize_t psmouse_attr_set_protocol(struct psmouse *psmouse, void *data, co
1408 parent->pt_deactivate(parent); 1424 parent->pt_deactivate(parent);
1409 } 1425 }
1410 1426
1427 old_dev = psmouse->dev;
1428 old_proto = psmouse_protocol_by_type(psmouse->type);
1429
1411 if (psmouse->disconnect) 1430 if (psmouse->disconnect)
1412 psmouse->disconnect(psmouse); 1431 psmouse->disconnect(psmouse);
1413 1432
1414 psmouse_set_state(psmouse, PSMOUSE_IGNORE); 1433 psmouse_set_state(psmouse, PSMOUSE_IGNORE);
1415 input_unregister_device(psmouse->dev);
1416 1434
1417 psmouse->dev = new_dev; 1435 psmouse->dev = new_dev;
1418 psmouse_set_state(psmouse, PSMOUSE_INITIALIZING); 1436 psmouse_set_state(psmouse, PSMOUSE_INITIALIZING);
@@ -1426,7 +1444,23 @@ static ssize_t psmouse_attr_set_protocol(struct psmouse *psmouse, void *data, co
1426 psmouse_initialize(psmouse); 1444 psmouse_initialize(psmouse);
1427 psmouse_set_state(psmouse, PSMOUSE_CMD_MODE); 1445 psmouse_set_state(psmouse, PSMOUSE_CMD_MODE);
1428 1446
1429 input_register_device(psmouse->dev); 1447 error = input_register_device(psmouse->dev);
1448 if (error) {
1449 if (psmouse->disconnect)
1450 psmouse->disconnect(psmouse);
1451
1452 psmouse_set_state(psmouse, PSMOUSE_IGNORE);
1453 input_free_device(new_dev);
1454 psmouse->dev = old_dev;
1455 psmouse_set_state(psmouse, PSMOUSE_INITIALIZING);
1456 psmouse_switch_protocol(psmouse, old_proto);
1457 psmouse_initialize(psmouse);
1458 psmouse_set_state(psmouse, PSMOUSE_CMD_MODE);
1459
1460 return error;
1461 }
1462
1463 input_unregister_device(old_dev);
1430 1464
1431 if (parent && parent->pt_activate) 1465 if (parent && parent->pt_activate)
1432 parent->pt_activate(parent); 1466 parent->pt_activate(parent);
diff --git a/drivers/input/mouse/rpcmouse.c b/drivers/input/mouse/rpcmouse.c
index ea0468569610..fbdcfd8eb4e9 100644
--- a/drivers/input/mouse/rpcmouse.c
+++ b/drivers/input/mouse/rpcmouse.c
@@ -66,7 +66,10 @@ static irqreturn_t rpcmouse_irq(int irq, void *dev_id)
66 66
67static int __init rpcmouse_init(void) 67static int __init rpcmouse_init(void)
68{ 68{
69 if (!(rpcmouse_dev = input_allocate_device())) 69 int err;
70
71 rpcmouse_dev = input_allocate_device();
72 if (!rpcmouse_dev)
70 return -ENOMEM; 73 return -ENOMEM;
71 74
72 rpcmouse_dev->name = "Acorn RiscPC Mouse"; 75 rpcmouse_dev->name = "Acorn RiscPC Mouse";
@@ -85,13 +88,22 @@ static int __init rpcmouse_init(void)
85 88
86 if (request_irq(IRQ_VSYNCPULSE, rpcmouse_irq, IRQF_SHARED, "rpcmouse", rpcmouse_dev)) { 89 if (request_irq(IRQ_VSYNCPULSE, rpcmouse_irq, IRQF_SHARED, "rpcmouse", rpcmouse_dev)) {
87 printk(KERN_ERR "rpcmouse: unable to allocate VSYNC interrupt\n"); 90 printk(KERN_ERR "rpcmouse: unable to allocate VSYNC interrupt\n");
88 input_free_device(rpcmouse_dev); 91 err = -EBUSY;
89 return -EBUSY; 92 goto err_free_dev;
90 } 93 }
91 94
92 input_register_device(rpcmouse_dev); 95 err = input_register_device(rpcmouse_dev);
96 if (err)
97 goto err_free_irq;
93 98
94 return 0; 99 return 0;
100
101 err_free_irq:
102 free_irq(IRQ_VSYNCPULSE, rpcmouse_dev);
103 err_free_dev:
104 input_free_device(rpcmouse_dev);
105
106 return err;
95} 107}
96 108
97static void __exit rpcmouse_exit(void) 109static void __exit rpcmouse_exit(void)
diff --git a/drivers/input/mouse/sermouse.c b/drivers/input/mouse/sermouse.c
index 2a272c5daf08..10b51e7f01f6 100644
--- a/drivers/input/mouse/sermouse.c
+++ b/drivers/input/mouse/sermouse.c
@@ -246,7 +246,7 @@ static int sermouse_connect(struct serio *serio, struct serio_driver *drv)
246 sermouse = kzalloc(sizeof(struct sermouse), GFP_KERNEL); 246 sermouse = kzalloc(sizeof(struct sermouse), GFP_KERNEL);
247 input_dev = input_allocate_device(); 247 input_dev = input_allocate_device();
248 if (!sermouse || !input_dev) 248 if (!sermouse || !input_dev)
249 goto fail; 249 goto fail1;
250 250
251 sermouse->dev = input_dev; 251 sermouse->dev = input_dev;
252 snprintf(sermouse->phys, sizeof(sermouse->phys), "%s/input0", serio->phys); 252 snprintf(sermouse->phys, sizeof(sermouse->phys), "%s/input0", serio->phys);
@@ -275,14 +275,17 @@ static int sermouse_connect(struct serio *serio, struct serio_driver *drv)
275 275
276 err = serio_open(serio, drv); 276 err = serio_open(serio, drv);
277 if (err) 277 if (err)
278 goto fail; 278 goto fail2;
279 279
280 input_register_device(sermouse->dev); 280 err = input_register_device(sermouse->dev);
281 if (err)
282 goto fail3;
281 283
282 return 0; 284 return 0;
283 285
284 fail: serio_set_drvdata(serio, NULL); 286 fail3: serio_close(serio);
285 input_free_device(input_dev); 287 fail2: serio_set_drvdata(serio, NULL);
288 fail1: input_free_device(input_dev);
286 kfree(sermouse); 289 kfree(sermouse);
287 return err; 290 return err;
288} 291}
diff --git a/drivers/input/mouse/vsxxxaa.c b/drivers/input/mouse/vsxxxaa.c
index ffdb50eee93d..ffd0d6624a8c 100644
--- a/drivers/input/mouse/vsxxxaa.c
+++ b/drivers/input/mouse/vsxxxaa.c
@@ -497,7 +497,7 @@ vsxxxaa_connect (struct serio *serio, struct serio_driver *drv)
497 mouse = kzalloc (sizeof (struct vsxxxaa), GFP_KERNEL); 497 mouse = kzalloc (sizeof (struct vsxxxaa), GFP_KERNEL);
498 input_dev = input_allocate_device (); 498 input_dev = input_allocate_device ();
499 if (!mouse || !input_dev) 499 if (!mouse || !input_dev)
500 goto fail; 500 goto fail1;
501 501
502 mouse->dev = input_dev; 502 mouse->dev = input_dev;
503 mouse->serio = serio; 503 mouse->serio = serio;
@@ -527,7 +527,7 @@ vsxxxaa_connect (struct serio *serio, struct serio_driver *drv)
527 527
528 err = serio_open (serio, drv); 528 err = serio_open (serio, drv);
529 if (err) 529 if (err)
530 goto fail; 530 goto fail2;
531 531
532 /* 532 /*
533 * Request selftest. Standard packet format and differential 533 * Request selftest. Standard packet format and differential
@@ -535,12 +535,15 @@ vsxxxaa_connect (struct serio *serio, struct serio_driver *drv)
535 */ 535 */
536 serio->write (serio, 'T'); /* Test */ 536 serio->write (serio, 'T'); /* Test */
537 537
538 input_register_device (input_dev); 538 err = input_register_device (input_dev);
539 if (err)
540 goto fail3;
539 541
540 return 0; 542 return 0;
541 543
542 fail: serio_set_drvdata (serio, NULL); 544 fail3: serio_close (serio);
543 input_free_device (input_dev); 545 fail2: serio_set_drvdata (serio, NULL);
546 fail1: input_free_device (input_dev);
544 kfree (mouse); 547 kfree (mouse);
545 return err; 548 return err;
546} 549}