]> www.infradead.org Git - linux.git/commitdiff
pps: add an error check in parport_attach
authorMa Ke <make24@iscas.ac.cn>
Wed, 28 Aug 2024 13:18:14 +0000 (21:18 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 3 Sep 2024 10:33:09 +0000 (12:33 +0200)
In parport_attach, the return value of ida_alloc is unchecked, witch leads
to the use of an invalid index value.

To address this issue, index should be checked. When the index value is
abnormal, the device should be freed.

Found by code review, compile tested only.

Cc: stable@vger.kernel.org
Fixes: fb56d97df70e ("pps: client: use new parport device model")
Signed-off-by: Ma Ke <make24@iscas.ac.cn>
Acked-by: Rodolfo Giometti <giometti@enneenne.com>
Link: https://lore.kernel.org/r/20240828131814.3034338-1-make24@iscas.ac.cn
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/pps/clients/pps_parport.c

index 63d03a0df5cce9540c1da0a3162952c79c48999e..abaffb4e1c1ce9f27f5a3fd05e3814ecfe121911 100644 (file)
@@ -149,6 +149,9 @@ static void parport_attach(struct parport *port)
        }
 
        index = ida_alloc(&pps_client_index, GFP_KERNEL);
+       if (index < 0)
+               goto err_free_device;
+
        memset(&pps_client_cb, 0, sizeof(pps_client_cb));
        pps_client_cb.private = device;
        pps_client_cb.irq_func = parport_irq;
@@ -159,7 +162,7 @@ static void parport_attach(struct parport *port)
                                                    index);
        if (!device->pardev) {
                pr_err("couldn't register with %s\n", port->name);
-               goto err_free;
+               goto err_free_ida;
        }
 
        if (parport_claim_or_block(device->pardev) < 0) {
@@ -187,8 +190,9 @@ err_release_dev:
        parport_release(device->pardev);
 err_unregister_dev:
        parport_unregister_device(device->pardev);
-err_free:
+err_free_ida:
        ida_free(&pps_client_index, index);
+err_free_device:
        kfree(device);
 }