Skip to content

Commit fbf740a

Browse files
Huai-Yuan Liugregkh
authored andcommitted
ppdev: Add an error check in register_device
In register_device, the return value of ida_simple_get is unchecked, in witch ida_simple_get will use an invalid index value. To address this issue, index should be checked after ida_simple_get. When the index value is abnormal, a warning message should be printed, the port should be dropped, and the value should be recorded. Fixes: 9a69645 ("ppdev: fix registering same device name") Signed-off-by: Huai-Yuan Liu <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent f866b65 commit fbf740a

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

drivers/char/ppdev.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -296,28 +296,35 @@ static int register_device(int minor, struct pp_struct *pp)
296296
if (!port) {
297297
pr_warn("%s: no associated port!\n", name);
298298
rc = -ENXIO;
299-
goto err;
299+
goto err_free_name;
300300
}
301301

302302
index = ida_alloc(&ida_index, GFP_KERNEL);
303+
if (index < 0) {
304+
pr_warn("%s: failed to get index!\n", name);
305+
rc = index;
306+
goto err_put_port;
307+
}
308+
303309
memset(&ppdev_cb, 0, sizeof(ppdev_cb));
304310
ppdev_cb.irq_func = pp_irq;
305311
ppdev_cb.flags = (pp->flags & PP_EXCL) ? PARPORT_FLAG_EXCL : 0;
306312
ppdev_cb.private = pp;
307313
pdev = parport_register_dev_model(port, name, &ppdev_cb, index);
308-
parport_put_port(port);
309314

310315
if (!pdev) {
311316
pr_warn("%s: failed to register device!\n", name);
312317
rc = -ENXIO;
313318
ida_free(&ida_index, index);
314-
goto err;
319+
goto err_put_port;
315320
}
316321

317322
pp->pdev = pdev;
318323
pp->index = index;
319324
dev_dbg(&pdev->dev, "registered pardevice\n");
320-
err:
325+
err_put_port:
326+
parport_put_port(port);
327+
err_free_name:
321328
kfree(name);
322329
return rc;
323330
}

0 commit comments

Comments
 (0)