NFC: nfcmrvl_uart: add missing tty-device sanity check
authorJohan Hovold <johan@kernel.org>
Thu, 30 Mar 2017 10:15:36 +0000 (12:15 +0200)
committerSamuel Ortiz <sameo@linux.intel.com>
Sun, 18 Jun 2017 21:57:59 +0000 (23:57 +0200)
Make sure to check the tty-device pointer before trying to access the
parent device to avoid dereferencing a NULL-pointer when the tty is one
end of a Unix98 pty.

Fixes: e097dc624f78 ("NFC: nfcmrvl: add UART driver")
Cc: stable <stable@vger.kernel.org> # 4.2
Cc: Vincent Cuissard <cuissard@marvell.com>
Signed-off-by: Johan Hovold <johan@kernel.org>
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
drivers/nfc/nfcmrvl/uart.c

index 83a99e38e7bd316d949e44d1bc530865ac22befe..6c0c301611c482407513429f99f42a9b7a57db72 100644 (file)
@@ -109,6 +109,7 @@ static int nfcmrvl_nci_uart_open(struct nci_uart *nu)
        struct nfcmrvl_private *priv;
        struct nfcmrvl_platform_data *pdata = NULL;
        struct nfcmrvl_platform_data config;
+       struct device *dev = nu->tty->dev;
 
        /*
         * Platform data cannot be used here since usually it is already used
@@ -116,9 +117,8 @@ static int nfcmrvl_nci_uart_open(struct nci_uart *nu)
         * and check if DT entries were added.
         */
 
-       if (nu->tty->dev->parent && nu->tty->dev->parent->of_node)
-               if (nfcmrvl_uart_parse_dt(nu->tty->dev->parent->of_node,
-                                         &config) == 0)
+       if (dev && dev->parent && dev->parent->of_node)
+               if (nfcmrvl_uart_parse_dt(dev->parent->of_node, &config) == 0)
                        pdata = &config;
 
        if (!pdata) {
@@ -131,7 +131,7 @@ static int nfcmrvl_nci_uart_open(struct nci_uart *nu)
        }
 
        priv = nfcmrvl_nci_register_dev(NFCMRVL_PHY_UART, nu, &uart_ops,
-                                       nu->tty->dev, pdata);
+                                       dev, pdata);
        if (IS_ERR(priv))
                return PTR_ERR(priv);