Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Input: hil_ptr - check return value of input_register_device()

[dtor@mail.ru: also signal correct return value to callers]
Signed-off-by: Andres Salomon <dilinger@debian.org>
Signed-off-by: Dmitry Torokhov <dtor@mail.ru>

authored by

Andres Salomon and committed by
Dmitry Torokhov
2ff98147 e9542dff

+25 -10
+25 -10
drivers/input/mouse/hil_ptr.c
··· 247 247 248 248 static int hil_ptr_connect(struct serio *serio, struct serio_driver *driver) 249 249 { 250 - struct hil_ptr *ptr; 251 - const char *txt; 252 - unsigned int i, naxsets, btntype; 253 - uint8_t did, *idd; 250 + struct hil_ptr *ptr; 251 + const char *txt; 252 + unsigned int i, naxsets, btntype; 253 + uint8_t did, *idd; 254 + int error; 254 255 255 - if (!(ptr = kzalloc(sizeof(struct hil_ptr), GFP_KERNEL))) 256 + ptr = kzalloc(sizeof(struct hil_ptr), GFP_KERNEL); 257 + if (!ptr) 256 258 return -ENOMEM; 257 259 258 260 ptr->dev = input_allocate_device(); 259 - if (!ptr->dev) 261 + if (!ptr->dev) { 262 + error = -ENOMEM; 260 263 goto bail0; 264 + } 261 265 262 - if (serio_open(serio, driver)) 266 + error = serio_open(serio, driver); 267 + if (error) 263 268 goto bail1; 264 269 265 270 serio_set_drvdata(serio, ptr); ··· 302 297 did = ptr->idd[0]; 303 298 idd = ptr->idd + 1; 304 299 txt = "unknown"; 300 + 305 301 if ((did & HIL_IDD_DID_TYPE_MASK) == HIL_IDD_DID_TYPE_REL) { 306 302 ptr->dev->evbit[0] = BIT_MASK(EV_REL); 307 303 txt = "relative"; ··· 312 306 ptr->dev->evbit[0] = BIT_MASK(EV_ABS); 313 307 txt = "absolute"; 314 308 } 315 - if (!ptr->dev->evbit[0]) 309 + 310 + if (!ptr->dev->evbit[0]) { 311 + error = -ENODEV; 316 312 goto bail2; 313 + } 317 314 318 315 ptr->nbtn = HIL_IDD_NUM_BUTTONS(idd); 319 316 if (ptr->nbtn) ··· 389 380 ptr->dev->id.version = 0x0100; /* TODO: get from ptr->rsc */ 390 381 ptr->dev->dev.parent = &serio->dev; 391 382 392 - input_register_device(ptr->dev); 383 + error = input_register_device(ptr->dev); 384 + if (error) { 385 + printk(KERN_INFO PREFIX "Unable to register input device\n"); 386 + goto bail2; 387 + } 388 + 393 389 printk(KERN_INFO "input: %s (%s), ID: %d\n", 394 390 ptr->dev->name, 395 391 (btntype == BTN_MOUSE) ? "HIL mouse":"HIL tablet or touchpad", 396 392 did); 397 393 398 394 return 0; 395 + 399 396 bail2: 400 397 serio_close(serio); 401 398 bail1: ··· 409 394 bail0: 410 395 kfree(ptr); 411 396 serio_set_drvdata(serio, NULL); 412 - return -ENODEV; 397 + return error; 413 398 } 414 399 415 400 static struct serio_device_id hil_ptr_ids[] = {