* [PATCH] serial: 8250_lpss: Fix missing check for return value of pci_get_slot()
@ 2023-06-14 15:32 Chenyuan Mi
2023-06-14 16:08 ` Andy Shevchenko
2023-06-14 16:28 ` Greg KH
0 siblings, 2 replies; 3+ messages in thread
From: Chenyuan Mi @ 2023-06-14 15:32 UTC (permalink / raw)
To: ilpo.jarvinen
Cc: andriy.shevchenko, gregkh, jirislaby, linux-serial, linux-kernel,
Chenyuan Mi
The pci_get_slot() function may return NULL, which may
cause null pointer deference, and most other callsites of
pci_get_slot() do Null check. Add Null check for return
value of pci_get_slot().
Found by our static analysis tool.
Signed-off-by: Chenyuan Mi <cymi20@fudan.edu.cn>
---
drivers/tty/serial/8250/8250_lpss.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/tty/serial/8250/8250_lpss.c b/drivers/tty/serial/8250/8250_lpss.c
index 0e43bdfb7459..05af5865ee1b 100644
--- a/drivers/tty/serial/8250/8250_lpss.c
+++ b/drivers/tty/serial/8250/8250_lpss.c
@@ -137,6 +137,8 @@ static int byt_serial_setup(struct lpss8250 *lpss, struct uart_port *port)
}
dma_dev = pci_get_slot(pdev->bus, PCI_DEVFN(PCI_SLOT(pdev->devfn), 0));
+ if (!dma_dev)
+ return -ENODEV;
param->dma_dev = &dma_dev->dev;
param->m_master = 0;
--
2.17.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] serial: 8250_lpss: Fix missing check for return value of pci_get_slot()
2023-06-14 15:32 [PATCH] serial: 8250_lpss: Fix missing check for return value of pci_get_slot() Chenyuan Mi
@ 2023-06-14 16:08 ` Andy Shevchenko
2023-06-14 16:28 ` Greg KH
1 sibling, 0 replies; 3+ messages in thread
From: Andy Shevchenko @ 2023-06-14 16:08 UTC (permalink / raw)
To: Chenyuan Mi; +Cc: ilpo.jarvinen, gregkh, jirislaby, linux-serial, linux-kernel
On Wed, Jun 14, 2023 at 08:32:26AM -0700, Chenyuan Mi wrote:
> The pci_get_slot() function may return NULL, which may
> cause null pointer deference, and most other callsites of
> pci_get_slot() do Null check. Add Null check for return
> value of pci_get_slot().
>
> Found by our static analysis tool.
...
> dma_dev = pci_get_slot(pdev->bus, PCI_DEVFN(PCI_SLOT(pdev->devfn), 0));
> + if (!dma_dev)
> + return -ENODEV;
This adds (almost) a dead code. The function 0 must be present in accordance
with the PCI specification (even earliest version of it state that).
If pci_get_slot() returns a NULL, in this case it means that something, much
bigger issue, happens and this check won't help us to do anything anyway.
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] serial: 8250_lpss: Fix missing check for return value of pci_get_slot()
2023-06-14 15:32 [PATCH] serial: 8250_lpss: Fix missing check for return value of pci_get_slot() Chenyuan Mi
2023-06-14 16:08 ` Andy Shevchenko
@ 2023-06-14 16:28 ` Greg KH
1 sibling, 0 replies; 3+ messages in thread
From: Greg KH @ 2023-06-14 16:28 UTC (permalink / raw)
To: Chenyuan Mi
Cc: ilpo.jarvinen, andriy.shevchenko, jirislaby, linux-serial,
linux-kernel
On Wed, Jun 14, 2023 at 08:32:26AM -0700, Chenyuan Mi wrote:
> The pci_get_slot() function may return NULL, which may
> cause null pointer deference, and most other callsites of
> pci_get_slot() do Null check. Add Null check for return
> value of pci_get_slot().
>
> Found by our static analysis tool.
Please read Documentation/process/researcher-guidelines.rst for how to
do this properly. Until then, we obviously can not take these types of
patches.
greg k-h
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-06-14 16:29 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-06-14 15:32 [PATCH] serial: 8250_lpss: Fix missing check for return value of pci_get_slot() Chenyuan Mi
2023-06-14 16:08 ` Andy Shevchenko
2023-06-14 16:28 ` Greg KH
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).