All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] tty: 8250: fix a missing check for pci_ioremap_bar
@ 2019-03-23 22:53 Aditya Pakki
  2019-03-24 12:05 ` Andy Shevchenko
  0 siblings, 1 reply; 4+ messages in thread
From: Aditya Pakki @ 2019-03-23 22:53 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 fix captures the failure and
pass an error code upstream. This can avoid potential NULL
pointer dereferences in the future.

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

---
v1: Missed return by default in CONFIG_SERIAL_8250_DMA, suggested by
Jiri Slaby
---
 drivers/tty/serial/8250/8250_lpss.c | 16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)

diff --git a/drivers/tty/serial/8250/8250_lpss.c b/drivers/tty/serial/8250/8250_lpss.c
index 53ca9ba6ab4b..1dc67897dcf8 100644
--- a/drivers/tty/serial/8250/8250_lpss.c
+++ b/drivers/tty/serial/8250/8250_lpss.c
@@ -161,7 +161,7 @@ static const struct dw_dma_platform_data qrk_serial_dma_pdata = {
 	.multi_block = {0},
 };
 
-static void qrk_serial_setup_dma(struct lpss8250 *lpss, struct uart_port *port)
+static int qrk_serial_setup_dma(struct lpss8250 *lpss, struct uart_port *port)
 {
 	struct uart_8250_dma *dma = &lpss->dma;
 	struct dw_dma_chip *chip = &lpss->dma_chip;
@@ -172,12 +172,14 @@ static void qrk_serial_setup_dma(struct lpss8250 *lpss, struct uart_port *port)
 	chip->dev = &pdev->dev;
 	chip->irq = pci_irq_vector(pdev, 0);
 	chip->regs = pci_ioremap_bar(pdev, 1);
+	if (!chip->regs)
+		return -EIO;
 	chip->pdata = &qrk_serial_dma_pdata;
 
 	/* Falling back to PIO mode if DMA probing fails */
 	ret = dw_dma_probe(chip);
 	if (ret)
-		return;
+		return ret;
 
 	pci_try_set_mwi(pdev);
 
@@ -191,6 +193,7 @@ static void qrk_serial_setup_dma(struct lpss8250 *lpss, struct uart_port *port)
 	param->hs_polarity = true;
 
 	lpss->dma_maxburst = 8;
+	return 0;
 }
 
 static void qrk_serial_exit_dma(struct lpss8250 *lpss)
@@ -202,7 +205,11 @@ static void qrk_serial_exit_dma(struct lpss8250 *lpss)
 	dw_dma_remove(&lpss->dma_chip);
 }
 #else	/* CONFIG_SERIAL_8250_DMA */
-static void qrk_serial_setup_dma(struct lpss8250 *lpss, struct uart_port *port) {}
+static int qrk_serial_setup_dma(struct lpss8250 *lpss, struct uart_port *port)
+{
+	return 0;
+}
+
 static void qrk_serial_exit_dma(struct lpss8250 *lpss) {}
 #endif	/* !CONFIG_SERIAL_8250_DMA */
 
@@ -219,8 +226,7 @@ static int qrk_serial_setup(struct lpss8250 *lpss, struct uart_port *port)
 
 	port->irq = pci_irq_vector(pdev, 0);
 
-	qrk_serial_setup_dma(lpss, port);
-	return 0;
+	return qrk_serial_setup_dma(lpss, port);
 }
 
 static void qrk_serial_exit(struct lpss8250 *lpss)
-- 
2.17.1


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

* Re: [PATCH v2] tty: 8250: fix a missing check for pci_ioremap_bar
  2019-03-23 22:53 [PATCH v2] tty: 8250: fix a missing check for pci_ioremap_bar Aditya Pakki
@ 2019-03-24 12:05 ` Andy Shevchenko
  2019-03-24 12:26   ` Andy Shevchenko
  0 siblings, 1 reply; 4+ messages in thread
From: Andy Shevchenko @ 2019-03-24 12:05 UTC (permalink / raw)
  To: Aditya Pakki
  Cc: Kangjie Lu, Greg Kroah-Hartman, Jiri Slaby, Vinod Koul,
	Andy Shevchenko, open list:SERIAL DRIVERS,
	Linux Kernel Mailing List

On Sun, Mar 24, 2019 at 12:55 AM Aditya Pakki <pakki001@umn.edu> wrote:
>
> pci_ioremap_bar could fail. The fix captures the failure and
> pass an error code upstream. This can avoid potential NULL
> pointer dereferences in the future.
>

NAK.
This will break non-DMA case.

> Signed-off-by: Aditya Pakki <pakki001@umn.edu>
>
> ---
> v1: Missed return by default in CONFIG_SERIAL_8250_DMA, suggested by
> Jiri Slaby
> ---
>  drivers/tty/serial/8250/8250_lpss.c | 16 +++++++++++-----
>  1 file changed, 11 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/tty/serial/8250/8250_lpss.c b/drivers/tty/serial/8250/8250_lpss.c
> index 53ca9ba6ab4b..1dc67897dcf8 100644
> --- a/drivers/tty/serial/8250/8250_lpss.c
> +++ b/drivers/tty/serial/8250/8250_lpss.c
> @@ -161,7 +161,7 @@ static const struct dw_dma_platform_data qrk_serial_dma_pdata = {
>         .multi_block = {0},
>  };
>
> -static void qrk_serial_setup_dma(struct lpss8250 *lpss, struct uart_port *port)
> +static int qrk_serial_setup_dma(struct lpss8250 *lpss, struct uart_port *port)
>  {
>         struct uart_8250_dma *dma = &lpss->dma;
>         struct dw_dma_chip *chip = &lpss->dma_chip;
> @@ -172,12 +172,14 @@ static void qrk_serial_setup_dma(struct lpss8250 *lpss, struct uart_port *port)
>         chip->dev = &pdev->dev;
>         chip->irq = pci_irq_vector(pdev, 0);
>         chip->regs = pci_ioremap_bar(pdev, 1);
> +       if (!chip->regs)
> +               return -EIO;
>         chip->pdata = &qrk_serial_dma_pdata;
>
>         /* Falling back to PIO mode if DMA probing fails */
>         ret = dw_dma_probe(chip);
>         if (ret)
> -               return;
> +               return ret;
>
>         pci_try_set_mwi(pdev);
>
> @@ -191,6 +193,7 @@ static void qrk_serial_setup_dma(struct lpss8250 *lpss, struct uart_port *port)
>         param->hs_polarity = true;
>
>         lpss->dma_maxburst = 8;
> +       return 0;
>  }
>
>  static void qrk_serial_exit_dma(struct lpss8250 *lpss)
> @@ -202,7 +205,11 @@ static void qrk_serial_exit_dma(struct lpss8250 *lpss)
>         dw_dma_remove(&lpss->dma_chip);
>  }
>  #else  /* CONFIG_SERIAL_8250_DMA */
> -static void qrk_serial_setup_dma(struct lpss8250 *lpss, struct uart_port *port) {}
> +static int qrk_serial_setup_dma(struct lpss8250 *lpss, struct uart_port *port)
> +{
> +       return 0;
> +}
> +
>  static void qrk_serial_exit_dma(struct lpss8250 *lpss) {}
>  #endif /* !CONFIG_SERIAL_8250_DMA */
>
> @@ -219,8 +226,7 @@ static int qrk_serial_setup(struct lpss8250 *lpss, struct uart_port *port)
>
>         port->irq = pci_irq_vector(pdev, 0);
>
> -       qrk_serial_setup_dma(lpss, port);
> -       return 0;
> +       return qrk_serial_setup_dma(lpss, port);
>  }
>
>  static void qrk_serial_exit(struct lpss8250 *lpss)
> --
> 2.17.1
>


-- 
With Best Regards,
Andy Shevchenko

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

* Re: [PATCH v2] tty: 8250: fix a missing check for pci_ioremap_bar
  2019-03-24 12:05 ` Andy Shevchenko
@ 2019-03-24 12:26   ` Andy Shevchenko
  2019-03-24 12:31     ` Andy Shevchenko
  0 siblings, 1 reply; 4+ messages in thread
From: Andy Shevchenko @ 2019-03-24 12:26 UTC (permalink / raw)
  To: Aditya Pakki
  Cc: Kangjie Lu, Greg Kroah-Hartman, Jiri Slaby, Vinod Koul,
	Andy Shevchenko, open list:SERIAL DRIVERS,
	Linux Kernel Mailing List

On Sun, Mar 24, 2019 at 2:05 PM Andy Shevchenko
<andy.shevchenko@gmail.com> wrote:
> On Sun, Mar 24, 2019 at 12:55 AM Aditya Pakki <pakki001@umn.edu> wrote:
> >
> > pci_ioremap_bar could fail. The fix captures the failure and
> > pass an error code upstream. This can avoid potential NULL
> > pointer dereferences in the future.
> >
>
> NAK.
> This will break non-DMA case.

> > @@ -172,12 +172,14 @@ static void qrk_serial_setup_dma(struct lpss8250 *lpss, struct uart_port *port)

Just to clarify, what you need is simple

void __iomem *regs;

chip->pdata = ... //move it here for better looking code
chip->irq = ...
chip->regs = pci_ioremap_bar(...);
if (!chip->regs)
  return;

and thank you for pointing to this.

-- 
With Best Regards,
Andy Shevchenko

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

* Re: [PATCH v2] tty: 8250: fix a missing check for pci_ioremap_bar
  2019-03-24 12:26   ` Andy Shevchenko
@ 2019-03-24 12:31     ` Andy Shevchenko
  0 siblings, 0 replies; 4+ messages in thread
From: Andy Shevchenko @ 2019-03-24 12:31 UTC (permalink / raw)
  To: Aditya Pakki
  Cc: Kangjie Lu, Greg Kroah-Hartman, Jiri Slaby, Vinod Koul,
	Andy Shevchenko, open list:SERIAL DRIVERS,
	Linux Kernel Mailing List

On Sun, Mar 24, 2019 at 2:26 PM Andy Shevchenko
<andy.shevchenko@gmail.com> wrote:
> On Sun, Mar 24, 2019 at 2:05 PM Andy Shevchenko
> <andy.shevchenko@gmail.com> wrote:
> > On Sun, Mar 24, 2019 at 12:55 AM Aditya Pakki <pakki001@umn.edu> wrote:
> > >
> > > pci_ioremap_bar could fail. The fix captures the failure and
> > > pass an error code upstream. This can avoid potential NULL
> > > pointer dereferences in the future.
> > >
> >
> > NAK.
> > This will break non-DMA case.
>
> > > @@ -172,12 +172,14 @@ static void qrk_serial_setup_dma(struct lpss8250 *lpss, struct uart_port *port)
>
> Just to clarify, what you need is simple
>

> void __iomem *regs;

Sorry for leftover.

> chip->pdata = ... //move it here for better looking code
> chip->irq = ...

> chip->regs = pci_ioremap_bar(...);

And looking into the code it needs pci_iounmap() on exit one.

> if (!chip->regs)
>   return;
>
> and thank you for pointing to this.

-- 
With Best Regards,
Andy Shevchenko

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

end of thread, other threads:[~2019-03-24 12:31 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-03-23 22:53 [PATCH v2] tty: 8250: fix a missing check for pci_ioremap_bar Aditya Pakki
2019-03-24 12:05 ` Andy Shevchenko
2019-03-24 12:26   ` Andy Shevchenko
2019-03-24 12:31     ` Andy Shevchenko

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.