Commit ee0a29ba authored by Colin Ian King's avatar Colin Ian King Committed by Greg Kroah-Hartman

serial-uartlite: fix null pointer dereference on pointer port

Pointer port is dereferenced on port->private_data when assigning pointer
pdata before port is null checked, leading to a potential null pointer
dereference.  Fix this by assigning pdata after the null pointer check on
port.

Detected by CoverityScan, CID#1475434 ("Dereference before null check")

Fixes: 3b209d25 ("serial-uartlite: Do not use static struct uart_driver out of probe()")
Signed-off-by: default avatarColin Ian King <colin.king@canonical.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent d491324f
......@@ -694,10 +694,11 @@ static int ulite_assign(struct device *dev, int id, u32 base, int irq,
static int ulite_release(struct device *dev)
{
struct uart_port *port = dev_get_drvdata(dev);
struct uartlite_data *pdata = port->private_data;
int rc = 0;
if (port) {
struct uartlite_data *pdata = port->private_data;
rc = uart_remove_one_port(pdata->ulite_uart_driver, port);
dev_set_drvdata(dev, NULL);
port->mapbase = 0;
......@@ -715,10 +716,12 @@ static int ulite_release(struct device *dev)
static int __maybe_unused ulite_suspend(struct device *dev)
{
struct uart_port *port = dev_get_drvdata(dev);
if (port) {
struct uartlite_data *pdata = port->private_data;
if (port)
uart_suspend_port(pdata->ulite_uart_driver, port);
}
return 0;
}
......@@ -732,10 +735,12 @@ static int __maybe_unused ulite_suspend(struct device *dev)
static int __maybe_unused ulite_resume(struct device *dev)
{
struct uart_port *port = dev_get_drvdata(dev);
if (port) {
struct uartlite_data *pdata = port->private_data;
if (port)
uart_resume_port(pdata->ulite_uart_driver, port);
}
return 0;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment