serial: pch: Fix PCI device refcount leak in pch_request_dma()
authorXiongfeng Wang <wangxiongfeng2@huawei.com>
Tue, 22 Nov 2022 11:45:59 +0000 (19:45 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 22 Nov 2022 16:58:51 +0000 (17:58 +0100)
As comment of pci_get_slot() says, it returns a pci_device with its
refcount increased. The caller must decrement the reference count by
calling pci_dev_put().

Since 'dma_dev' is only used to filter the channel in filter(), we can
call pci_dev_put() before exiting from pch_request_dma(). Add the
missing pci_dev_put() for the normal and error path.

Fixes: 3c6a483275f4 ("Serial: EG20T: add PCH_UART driver")
Signed-off-by: Xiongfeng Wang <wangxiongfeng2@huawei.com>
Link: https://lore.kernel.org/r/20221122114559.27692-1-wangxiongfeng2@huawei.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/tty/serial/pch_uart.c

index c76719c0f453a0f7fb0c0d26720ab9fb9f6a3955..3d54a43768cd2497180920ce1103f34d1ad3cd14 100644 (file)
@@ -694,6 +694,7 @@ static void pch_request_dma(struct uart_port *port)
        if (!chan) {
                dev_err(priv->port.dev, "%s:dma_request_channel FAILS(Tx)\n",
                        __func__);
+               pci_dev_put(dma_dev);
                return;
        }
        priv->chan_tx = chan;
@@ -710,6 +711,7 @@ static void pch_request_dma(struct uart_port *port)
                        __func__);
                dma_release_channel(priv->chan_tx);
                priv->chan_tx = NULL;
+               pci_dev_put(dma_dev);
                return;
        }
 
@@ -717,6 +719,8 @@ static void pch_request_dma(struct uart_port *port)
        priv->rx_buf_virt = dma_alloc_coherent(port->dev, port->fifosize,
                                    &priv->rx_buf_dma, GFP_KERNEL);
        priv->chan_rx = chan;
+
+       pci_dev_put(dma_dev);
 }
 
 static void pch_dma_rx_complete(void *arg)