serial: 8250_exar: Avoid NULL pointer dereference at ->exit()

It's possible that during ->exit() the private_data is NULL,
for instance when there was no GPIO device instantiated.
Due to this we may not dereference it. Add a respective check.

Note, for now ->exit() only makes sense when GPIO device
was instantiated, that's why we may use the check for entire
function.

Fixes: 81171e7d31a6 ("serial: 8250_exar: Constify the software nodes")
Reported-by: Maxim Levitsky <mlevitsk@redhat.com>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Tested-by: Maxim Levitsky <mlevitsk@redhat.com>
Link: https://lore.kernel.org/r/20210608144239.12697-1-andriy.shevchenko@linux.intel.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by Andy Shevchenko and committed by Greg Kroah-Hartman 7c3e8d9d 8124c8a6

+5 -1
+5 -1
drivers/tty/serial/8250/8250_exar.c
··· 553 553 { 554 554 struct exar8250 *priv = pci_get_drvdata(pcidev); 555 555 struct uart_8250_port *port = serial8250_get_port(priv->line[0]); 556 - struct platform_device *pdev = port->port.private_data; 556 + struct platform_device *pdev; 557 + 558 + pdev = port->port.private_data; 559 + if (!pdev) 560 + return; 557 561 558 562 device_remove_software_node(&pdev->dev); 559 563 platform_device_unregister(pdev);