Skip to contentSkip to conversation

tty: serial: add missing pci_dev_put() before return

PATCH In review Qing Wang 3 participants 4 messages Feb 15, 2022 1 message not in the archive TTY layer and serial drivers

lore
Share & tools
lore

Qing Wang

author
#0 lore raw

PATCH 1/1 tty: serial: add missing pci_dev_put() before return

From: Wang Qing <[email protected]>

pci_get_slot() increases its reference count, the caller must decrement the reference count by calling pci_dev_put()

---
 drivers/tty/serial/pch_uart.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/tty/serial/pch_uart.c +5 -2
index f0351e6..da5a276
@@ -723,7 +723,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__);
-		return;
+		goto out;
 	}
 	priv->chan_tx = chan;
 
@@ -739,13 +739,16 @@ static void pch_request_dma(struct uart_port *port)
 			__func__);
 		dma_release_channel(priv->chan_tx);
 		priv->chan_tx = NULL;
-		return;
+		goto out;
 	}
 
 	/* Get Consistent memory for DMA */
 	priv->rx_buf_virt = dma_alloc_coherent(port->dev, port->fifosize,
 				    &priv->rx_buf_dma, GFP_KERNEL);
 	priv->chan_rx = chan;
+
+out:
+	pci_dev_put(dma_dev);
 }
 
 static void pch_dma_rx_complete(void *arg)
Signature · 1 line
2.7.4
maintainer
#1 lore raw
Quoted 28 lines · Qing Wang

From: Wang Qing <[email protected]>

pci_get_slot() increases its reference count, the caller must decrement the reference count by calling pci_dev_put()

---
  drivers/tty/serial/pch_uart.c | 7 +++++--
  1 file changed, 5 insertions(+), 2 deletions(-)
drivers/tty/serial/pch_uart.c +1 -2
index f0351e6..da5a276
@@ -723,7 +723,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__);
-		return;
+		goto out;
  	}
  	priv->chan_tx = chan;
 
@@ -739,13 +739,16 @@ static void pch_request_dma(struct uart_port *port)
  			__func__);
  		dma_release_channel(priv->chan_tx);
  		priv->chan_tx = NULL;
-		return;

drivers/tty/serial/pch_uart.c static void pch_request_dma(struct uart_port *port) · line 751

Quoted 10 lines
drivers/tty/serial/pch_uart.c +4 -0
+		goto out;
  	}
 
  	/* Get Consistent memory for DMA */
  	priv->rx_buf_virt = dma_alloc_coherent(port->dev, port->fifosize,
  				    &priv->rx_buf_dma, GFP_KERNEL);
  	priv->chan_rx = chan;
+
+out:
+	pci_dev_put(dma_dev);

Again, dma_dev is stored to an internal structure and shouldn't be freed now.

Quoted 3 lines
drivers/tty/serial/pch_uart.c +0 -0
  }
 
  static void pch_dma_rx_complete(void *arg)
Signature · 2 lines
js
suse labs
#2 lore raw
In reply to Qing Wang
Quoted 44 lines · Qing Wang

From: Wang Qing <[email protected]>

pci_get_slot() increases its reference count, the caller must decrement the reference count by calling pci_dev_put()

---
 drivers/tty/serial/pch_uart.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/tty/serial/pch_uart.c +5 -2
index f0351e6..da5a276
@@ -723,7 +723,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__);
-		return;
+		goto out;
 	}
 	priv->chan_tx = chan;
 
@@ -739,13 +739,16 @@ static void pch_request_dma(struct uart_port *port)
 			__func__);
 		dma_release_channel(priv->chan_tx);
 		priv->chan_tx = NULL;
-		return;
+		goto out;
 	}
 
 	/* Get Consistent memory for DMA */
 	priv->rx_buf_virt = dma_alloc_coherent(port->dev, port->fifosize,
 				    &priv->rx_buf_dma, GFP_KERNEL);
 	priv->chan_rx = chan;
+
+out:
+	pci_dev_put(dma_dev);
 }
 
 static void pch_dma_rx_complete(void *arg)
Signature · 1 line
2.7.4

What tool are you using to find these? As Jiri points out, it is not very correct at all, be careful to not cause bugs when you are attempting to fix them.

For stuff like this, please always test your changes to verify they work.

thanks,

greg k-h

A message that is not in the archive (sent off-list or not yet received): [email protected].@PFlndGFPMGFTTkxXMGRWRlpAa3JvYWguY29tPg==

author
#4 lore raw
Quoted 51 lines
Quoted 40 lines · Qing Wang

From: Wang Qing <[email protected]>

pci_get_slot() increases its reference count, the caller must decrement the reference count by calling pci_dev_put()

---
  drivers/tty/serial/pch_uart.c | 7 +++++--

  1 file changed, 5 insertions(+), 2 deletions(-)
drivers/tty/serial/pch_uart.c +1 -1
index f0351e6..da5a276
@@ -723,7 +723,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__);
-             return;
+             goto out;
         }
         priv->chan_tx = chan;

drivers/tty/serial/pch_uart.c +1 -1
@@ -739,13 +739,16 @@ static void pch_request_dma(struct uart_port *port)
                         __func__);
                 dma_release_channel(priv->chan_tx);
                 priv->chan_tx = NULL;
-             return;
+             goto out;
         }


        /* Get Consistent memory for DMA */
        priv->rx_buf_virt = dma_alloc_coherent(port->dev, port->fifosize, &priv->rx_buf_dma, GFP_KERNEL); priv->chan_rx = chan;

drivers/tty/serial/pch_uart.c +3 -0
+
+out:
+     pci_dev_put(dma_dev);
Quoted 6 lines

  }

  static void pch_dma_rx_complete(void *arg)

Signature · 1 line
2.7.4

What tool are you using to find these?  As Jiri points out, it is not very correct at all, be careful to not cause bugs when you are attempting to fix them.

Quoted 2 lines

For stuff like this, please always test your changes to verify they work.

Got it.

Some tools are taken from the cocci community, some are developed byself, I will improve the tool and add tests to avoid this situation.

Thanks,
Qing

Quoted 5 lines

thanks,

greg k-h