Skip to content

Commit 2ff9814

Browse files
dilingerdtor
authored andcommitted
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>
1 parent e9542df commit 2ff9814

1 file changed

Lines changed: 26 additions & 11 deletions

File tree

‎drivers/input/mouse/hil_ptr.c‎

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -247,19 +247,24 @@ static void hil_ptr_disconnect(struct serio *serio)
247247

248248
static int hil_ptr_connect(struct serio *serio, struct serio_driver *driver)
249249
{
250-
struct hil_ptr *ptr;
251-
const char *txt;
252-
unsigned int i, naxsets, btntype;
253-
uint8_t did, *idd;
254-
255-
if (!(ptr = kzalloc(sizeof(struct hil_ptr), GFP_KERNEL)))
250+
struct hil_ptr *ptr;
251+
const char *txt;
252+
unsigned int i, naxsets, btntype;
253+
uint8_t did, *idd;
254+
int error;
255+
256+
ptr = kzalloc(sizeof(struct hil_ptr), GFP_KERNEL);
257+
if (!ptr)
256258
return -ENOMEM;
257259

258260
ptr->dev = input_allocate_device();
259-
if (!ptr->dev)
261+
if (!ptr->dev) {
262+
error = -ENOMEM;
260263
goto bail0;
264+
}
261265

262-
if (serio_open(serio, driver))
266+
error = serio_open(serio, driver);
267+
if (error)
263268
goto bail1;
264269

265270
serio_set_drvdata(serio, ptr);
@@ -297,6 +302,7 @@ static int hil_ptr_connect(struct serio *serio, struct serio_driver *driver)
297302
did = ptr->idd[0];
298303
idd = ptr->idd + 1;
299304
txt = "unknown";
305+
300306
if ((did & HIL_IDD_DID_TYPE_MASK) == HIL_IDD_DID_TYPE_REL) {
301307
ptr->dev->evbit[0] = BIT_MASK(EV_REL);
302308
txt = "relative";
@@ -306,8 +312,11 @@ static int hil_ptr_connect(struct serio *serio, struct serio_driver *driver)
306312
ptr->dev->evbit[0] = BIT_MASK(EV_ABS);
307313
txt = "absolute";
308314
}
309-
if (!ptr->dev->evbit[0])
315+
316+
if (!ptr->dev->evbit[0]) {
317+
error = -ENODEV;
310318
goto bail2;
319+
}
311320

312321
ptr->nbtn = HIL_IDD_NUM_BUTTONS(idd);
313322
if (ptr->nbtn)
@@ -380,21 +389,27 @@ static int hil_ptr_connect(struct serio *serio, struct serio_driver *driver)
380389
ptr->dev->id.version = 0x0100; /* TODO: get from ptr->rsc */
381390
ptr->dev->dev.parent = &serio->dev;
382391

383-
input_register_device(ptr->dev);
392+
error = input_register_device(ptr->dev);
393+
if (error) {
394+
printk(KERN_INFO PREFIX "Unable to register input device\n");
395+
goto bail2;
396+
}
397+
384398
printk(KERN_INFO "input: %s (%s), ID: %d\n",
385399
ptr->dev->name,
386400
(btntype == BTN_MOUSE) ? "HIL mouse":"HIL tablet or touchpad",
387401
did);
388402

389403
return 0;
404+
390405
bail2:
391406
serio_close(serio);
392407
bail1:
393408
input_free_device(ptr->dev);
394409
bail0:
395410
kfree(ptr);
396411
serio_set_drvdata(serio, NULL);
397-
return -ENODEV;
412+
return error;
398413
}
399414

400415
static struct serio_device_id hil_ptr_ids[] = {

0 commit comments

Comments
 (0)