]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
tty: nozomi: Fix the error handling path of 'nozomi_card_init()'
authorChristophe JAILLET <christophe.jaillet@wanadoo.fr>
Tue, 25 May 2021 18:51:57 +0000 (20:51 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 27 May 2021 13:20:02 +0000 (15:20 +0200)
The error handling path is broken and we may un-register things that have
never been registered.

Update the loops index accordingly.

Fixes: 9842c38e9176 ("kfifo: fix warn_unused_result")
Suggested-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Link: https://lore.kernel.org/r/e28c2e92c7475da25b03d022ea2d6dcf1ba807a2.1621968629.git.christophe.jaillet@wanadoo.fr
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/tty/nozomi.c

index b85d4beabc1fb3ac7d694d0181089e333aa1cf79..0c80f25c8c3d8fd5ede4bedef3d61e6b4e0323a0 100644 (file)
@@ -1378,7 +1378,7 @@ static int nozomi_card_init(struct pci_dev *pdev,
                        NOZOMI_NAME, dc);
        if (unlikely(ret)) {
                dev_err(&pdev->dev, "can't request irq %d\n", pdev->irq);
-               goto err_free_kfifo;
+               goto err_free_all_kfifo;
        }
 
        DBG1("base_addr: %p", dc->base_addr);
@@ -1416,13 +1416,15 @@ static int nozomi_card_init(struct pci_dev *pdev,
        return 0;
 
 err_free_tty:
-       for (i = 0; i < MAX_PORT; ++i) {
+       for (i--; i >= 0; i--) {
                tty_unregister_device(ntty_driver, dc->index_start + i);
                tty_port_destroy(&dc->port[i].port);
        }
        free_irq(pdev->irq, dc);
+err_free_all_kfifo:
+       i = MAX_PORT;
 err_free_kfifo:
-       for (i = 0; i < MAX_PORT; i++)
+       for (i--; i >= PORT_MDM; i--)
                kfifo_free(&dc->port[i].fifo_ul);
 err_free_sbuf:
        kfree(dc->send_buf);