linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v6] tty: 8250: fix a missing check for pci_ioremap_bar
@ 2019-03-25 22:21 Aditya Pakki
  2019-03-26 10:17 ` Andy Shevchenko
  0 siblings, 1 reply; 3+ messages in thread
From: Aditya Pakki @ 2019-03-25 22:21 UTC (permalink / raw)
  To: pakki001
  Cc: kjlu, Greg Kroah-Hartman, Jiri Slaby, Vinod Koul,
	Andy Shevchenko, linux-serial, linux-kernel

pci_ioremap_bar could fail. The patch returns in case of failure to
acquire IOMEM. It also releases the acquired resource in the exit path.

Signed-off-by: Aditya Pakki <pakki001@umn.edu>

---
v5: change pci_iounmap to iounmap to pass kbuild errors in other arch
v4: Missed resource release in dma_probe failure.
v3: Change the order of pci_iounmap and dw_dma_remove
v2: Failed to release resource in exit path and incorrect code in non
DMA case, suggested by Andy Shevchenko
v1: Missed return by default in CONFIG_SERIAL_8250_DMA, suggested by
Jiri Slaby
---
 drivers/tty/serial/8250/8250_lpss.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/drivers/tty/serial/8250/8250_lpss.c b/drivers/tty/serial/8250/8250_lpss.c
index 53ca9ba6ab4b..c7c7bf5d7e5e 100644
--- a/drivers/tty/serial/8250/8250_lpss.c
+++ b/drivers/tty/serial/8250/8250_lpss.c
@@ -170,14 +170,18 @@ static void qrk_serial_setup_dma(struct lpss8250 *lpss, struct uart_port *port)
 	int ret;
 
 	chip->dev = &pdev->dev;
+	chip->pdata = &qrk_serial_dma_pdata;
 	chip->irq = pci_irq_vector(pdev, 0);
 	chip->regs = pci_ioremap_bar(pdev, 1);
-	chip->pdata = &qrk_serial_dma_pdata;
+	if (!chip->regs)
+		return;
 
 	/* Falling back to PIO mode if DMA probing fails */
 	ret = dw_dma_probe(chip);
-	if (ret)
+	if (ret) {
+		iounmap(chip->regs);
 		return;
+	}
 
 	pci_try_set_mwi(pdev);
 
@@ -199,7 +203,10 @@ static void qrk_serial_exit_dma(struct lpss8250 *lpss)
 
 	if (!param->dma_dev)
 		return;
+
 	dw_dma_remove(&lpss->dma_chip);
+
+	iounmap(&lpss->dma_chip->regs);
 }
 #else	/* CONFIG_SERIAL_8250_DMA */
 static void qrk_serial_setup_dma(struct lpss8250 *lpss, struct uart_port *port) {}
-- 
2.17.1


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

* Re: [PATCH v6] tty: 8250: fix a missing check for pci_ioremap_bar
  2019-03-25 22:21 [PATCH v6] tty: 8250: fix a missing check for pci_ioremap_bar Aditya Pakki
@ 2019-03-26 10:17 ` Andy Shevchenko
  2019-03-26 10:28   ` Jiri Slaby
  0 siblings, 1 reply; 3+ messages in thread
From: Andy Shevchenko @ 2019-03-26 10:17 UTC (permalink / raw)
  To: Aditya Pakki
  Cc: kjlu, Greg Kroah-Hartman, Jiri Slaby, Vinod Koul, linux-serial,
	linux-kernel

On Mon, Mar 25, 2019 at 05:21:46PM -0500, Aditya Pakki wrote:
> pci_ioremap_bar could fail. The patch returns in case of failure to
> acquire IOMEM. It also releases the acquired resource in the exit path.

Thanks for an update.
One comment below.

After addressing it, take mine
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

> 
> Signed-off-by: Aditya Pakki <pakki001@umn.edu>
> 
> ---
> v5: change pci_iounmap to iounmap to pass kbuild errors in other arch
> v4: Missed resource release in dma_probe failure.
> v3: Change the order of pci_iounmap and dw_dma_remove
> v2: Failed to release resource in exit path and incorrect code in non
> DMA case, suggested by Andy Shevchenko
> v1: Missed return by default in CONFIG_SERIAL_8250_DMA, suggested by
> Jiri Slaby
> ---
>  drivers/tty/serial/8250/8250_lpss.c | 11 +++++++++--
>  1 file changed, 9 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/tty/serial/8250/8250_lpss.c b/drivers/tty/serial/8250/8250_lpss.c
> index 53ca9ba6ab4b..c7c7bf5d7e5e 100644
> --- a/drivers/tty/serial/8250/8250_lpss.c
> +++ b/drivers/tty/serial/8250/8250_lpss.c
> @@ -170,14 +170,18 @@ static void qrk_serial_setup_dma(struct lpss8250 *lpss, struct uart_port *port)
>  	int ret;
>  
>  	chip->dev = &pdev->dev;
> +	chip->pdata = &qrk_serial_dma_pdata;
>  	chip->irq = pci_irq_vector(pdev, 0);
>  	chip->regs = pci_ioremap_bar(pdev, 1);
> -	chip->pdata = &qrk_serial_dma_pdata;
> +	if (!chip->regs)
> +		return;
>  
>  	/* Falling back to PIO mode if DMA probing fails */
>  	ret = dw_dma_probe(chip);
> -	if (ret)
> +	if (ret) {
> +		iounmap(chip->regs);
>  		return;
> +	}
>  
>  	pci_try_set_mwi(pdev);
>  
> @@ -199,7 +203,10 @@ static void qrk_serial_exit_dma(struct lpss8250 *lpss)
>  
>  	if (!param->dma_dev)
>  		return;
> +
>  	dw_dma_remove(&lpss->dma_chip);
> +
> +	iounmap(&lpss->dma_chip->regs);

This is a bit fragile form of writing. Perhaps

        struct dw_dma_chip *chip = &lpss->dma_chip;

	...
	dw_dma_remove(chip);

	iounmap(chip->regs);

>  }
>  #else	/* CONFIG_SERIAL_8250_DMA */
>  static void qrk_serial_setup_dma(struct lpss8250 *lpss, struct uart_port *port) {}
> -- 
> 2.17.1
> 

-- 
With Best Regards,
Andy Shevchenko



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

* Re: [PATCH v6] tty: 8250: fix a missing check for pci_ioremap_bar
  2019-03-26 10:17 ` Andy Shevchenko
@ 2019-03-26 10:28   ` Jiri Slaby
  0 siblings, 0 replies; 3+ messages in thread
From: Jiri Slaby @ 2019-03-26 10:28 UTC (permalink / raw)
  To: Andy Shevchenko, Aditya Pakki
  Cc: Vinod Koul, Greg Kroah-Hartman, kjlu, linux-kernel, linux-serial

On 26. 03. 19, 11:17, Andy Shevchenko wrote:
>> @@ -199,7 +203,10 @@ static void qrk_serial_exit_dma(struct lpss8250 *lpss)
>>  
>>  	if (!param->dma_dev)
>>  		return;
>> +
>>  	dw_dma_remove(&lpss->dma_chip);
>> +
>> +	iounmap(&lpss->dma_chip->regs);
> 
> This is a bit fragile form of writing. Perhaps

It actually won't even compile, will it (it must have been
"(&lpss->dma_chip)->regs")? Do you at least compile-test your patches
before sending?

thanks,
-- 
js
suse labs

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

end of thread, other threads:[~2019-03-26 10:28 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-03-25 22:21 [PATCH v6] tty: 8250: fix a missing check for pci_ioremap_bar Aditya Pakki
2019-03-26 10:17 ` Andy Shevchenko
2019-03-26 10:28   ` Jiri Slaby

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).