linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] tty: serial: add missing pci_dev_put() before return
@ 2022-02-15  2:01 Qing Wang
  2022-02-15  6:14 ` Jiri Slaby
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Qing Wang @ 2022-02-15  2:01 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Jiri Slaby, linux-serial, linux-kernel; +Cc: Wang Qing

From: Wang Qing <wangqing@vivo.com>

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

Signed-off-by: Wang Qing <wangqing@vivo.com>
---
 drivers/tty/serial/pch_uart.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/tty/serial/pch_uart.c b/drivers/tty/serial/pch_uart.c
index f0351e6..da5a276
--- a/drivers/tty/serial/pch_uart.c
+++ b/drivers/tty/serial/pch_uart.c
@@ -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)
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] tty: serial: add missing pci_dev_put() before return
  2022-02-15  2:01 [PATCH] tty: serial: add missing pci_dev_put() before return Qing Wang
@ 2022-02-15  6:14 ` Jiri Slaby
  2022-02-15  7:46 ` Greg Kroah-Hartman
       [not found] ` <AEkAWQDgE7ilYE2UlPdbG4pX.9.1644911172685.Hmail.wangqing@vivo.com.@PFlndGFPMGFTTkxXMGRWRlpAa3JvYWguY29tPg==>
  2 siblings, 0 replies; 4+ messages in thread
From: Jiri Slaby @ 2022-02-15  6:14 UTC (permalink / raw)
  To: Qing Wang, Greg Kroah-Hartman, linux-serial, linux-kernel

On 15. 02. 22, 3:01, Qing Wang wrote:
> From: Wang Qing <wangqing@vivo.com>
> 
> pci_get_slot() increases its reference count, the caller must
> decrement the reference count by calling pci_dev_put()
> 
> Signed-off-by: Wang Qing <wangqing@vivo.com>
> ---
>   drivers/tty/serial/pch_uart.c | 7 +++++--
>   1 file changed, 5 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/tty/serial/pch_uart.c b/drivers/tty/serial/pch_uart.c
> index f0351e6..da5a276
> --- a/drivers/tty/serial/pch_uart.c
> +++ b/drivers/tty/serial/pch_uart.c
> @@ -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);

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

>   }
>   
>   static void pch_dma_rx_complete(void *arg)


-- 
js
suse labs

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] tty: serial: add missing pci_dev_put() before return
  2022-02-15  2:01 [PATCH] tty: serial: add missing pci_dev_put() before return Qing Wang
  2022-02-15  6:14 ` Jiri Slaby
@ 2022-02-15  7:46 ` Greg Kroah-Hartman
       [not found] ` <AEkAWQDgE7ilYE2UlPdbG4pX.9.1644911172685.Hmail.wangqing@vivo.com.@PFlndGFPMGFTTkxXMGRWRlpAa3JvYWguY29tPg==>
  2 siblings, 0 replies; 4+ messages in thread
From: Greg Kroah-Hartman @ 2022-02-15  7:46 UTC (permalink / raw)
  To: Qing Wang; +Cc: Jiri Slaby, linux-serial, linux-kernel

On Mon, Feb 14, 2022 at 06:01:12PM -0800, Qing Wang wrote:
> From: Wang Qing <wangqing@vivo.com>
> 
> pci_get_slot() increases its reference count, the caller must
> decrement the reference count by calling pci_dev_put()
> 
> Signed-off-by: Wang Qing <wangqing@vivo.com>
> ---
>  drivers/tty/serial/pch_uart.c | 7 +++++--
>  1 file changed, 5 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/tty/serial/pch_uart.c b/drivers/tty/serial/pch_uart.c
> index f0351e6..da5a276
> --- a/drivers/tty/serial/pch_uart.c
> +++ b/drivers/tty/serial/pch_uart.c
> @@ -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)
> -- 
> 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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* RE: [PATCH] tty: serial: add missing pci_dev_put() before return
       [not found] ` <AEkAWQDgE7ilYE2UlPdbG4pX.9.1644911172685.Hmail.wangqing@vivo.com.@PFlndGFPMGFTTkxXMGRWRlpAa3JvYWguY29tPg==>
@ 2022-02-15  8:41   ` 王擎
  0 siblings, 0 replies; 4+ messages in thread
From: 王擎 @ 2022-02-15  8:41 UTC (permalink / raw)
  To: Greg Kroah-Hartman; +Cc: Jiri Slaby, linux-serial, linux-kernel


>>On Mon, Feb 14, 2022 at 06:01:12PM -0800, Qing Wang wrote:
>> From: Wang Qing <wangqing@vivo.com>
>> 
>> pci_get_slot() increases its reference count, the caller must
>> decrement the reference count by calling pci_dev_put()
>> 
>> Signed-off-by: Wang Qing <wangqing@vivo.com>
>> ---
>>  drivers/tty/serial/pch_uart.c | 7 +++++--
>>  1 file changed, 5 insertions(+), 2 deletions(-)
>> 
>> diff --git a/drivers/tty/serial/pch_uart.c b/drivers/tty/serial/pch_uart.c
>> index f0351e6..da5a276
>> --- a/drivers/tty/serial/pch_uart.c
>> +++ b/drivers/tty/serial/pch_uart.c
>> @@ -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)
>> -- 
>> 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.

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
>
>thanks,
>
>greg k-h
>

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-02-15  8:41 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-15  2:01 [PATCH] tty: serial: add missing pci_dev_put() before return Qing Wang
2022-02-15  6:14 ` Jiri Slaby
2022-02-15  7:46 ` Greg Kroah-Hartman
     [not found] ` <AEkAWQDgE7ilYE2UlPdbG4pX.9.1644911172685.Hmail.wangqing@vivo.com.@PFlndGFPMGFTTkxXMGRWRlpAa3JvYWguY29tPg==>
2022-02-15  8:41   ` 王擎

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).