Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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: 3b209d253e7f ("serial-uartlite: Do not use static struct uart_driver out of probe()")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Colin Ian King and committed by
Greg Kroah-Hartman
ee0a29ba d491324f

+10 -5
+10 -5
drivers/tty/serial/uartlite.c
··· 694 694 static int ulite_release(struct device *dev) 695 695 { 696 696 struct uart_port *port = dev_get_drvdata(dev); 697 - struct uartlite_data *pdata = port->private_data; 698 697 int rc = 0; 699 698 700 699 if (port) { 700 + struct uartlite_data *pdata = port->private_data; 701 + 701 702 rc = uart_remove_one_port(pdata->ulite_uart_driver, port); 702 703 dev_set_drvdata(dev, NULL); 703 704 port->mapbase = 0; ··· 716 715 static int __maybe_unused ulite_suspend(struct device *dev) 717 716 { 718 717 struct uart_port *port = dev_get_drvdata(dev); 719 - struct uartlite_data *pdata = port->private_data; 720 718 721 - if (port) 719 + if (port) { 720 + struct uartlite_data *pdata = port->private_data; 721 + 722 722 uart_suspend_port(pdata->ulite_uart_driver, port); 723 + } 723 724 724 725 return 0; 725 726 } ··· 735 732 static int __maybe_unused ulite_resume(struct device *dev) 736 733 { 737 734 struct uart_port *port = dev_get_drvdata(dev); 738 - struct uartlite_data *pdata = port->private_data; 739 735 740 - if (port) 736 + if (port) { 737 + struct uartlite_data *pdata = port->private_data; 738 + 741 739 uart_resume_port(pdata->ulite_uart_driver, port); 740 + } 742 741 743 742 return 0; 744 743 }