MLK-16285-1 staging: typec: tcpci: move request interrupt to the end of probe
authorPeter Chen <peter.chen@nxp.com>
Fri, 15 Sep 2017 02:05:21 +0000 (10:05 +0800)
committerNitin Garg <nitin.garg@nxp.com>
Mon, 19 Mar 2018 20:38:36 +0000 (15:38 -0500)
The tcpci_irq may visit tcpci->port if unexpected interrupt occurs
(eg, board design issue causes GPIO status is incorrect) and cause
NULL pointer dereference issue.

Besides, delete clear TCPC_ALERT and TCPC_ALERT_MASK code which are
already done at tcpci_init.

Signed-off-by: Peter Chen <peter.chen@nxp.com>
Acked-by: Li Jun <jun.li@nxp.com>
drivers/staging/typec/tcpci.c

index e0cdd37..3f1c505 100644 (file)
@@ -765,23 +765,25 @@ static int tcpci_probe(struct i2c_client *client,
        if (err < 0)
                return err;
 
-       /* Clear and disable chip interrupts */
-       tcpci_write16(tcpci, TCPC_ALERT, 0xffff);
-       tcpci_write16(tcpci, TCPC_ALERT_MASK, 0);
+       tcpci->port = tcpm_register_port(tcpci->dev, &tcpci->tcpc);
+       if (IS_ERR(tcpci->port))
+               return PTR_ERR(tcpci->port);
+
+       err = tcpci_ss_mux_control_init(tcpci);
+       if (err)
+               goto err1;
 
        err = devm_request_threaded_irq(tcpci->dev, client->irq, NULL,
                                        tcpci_irq,
                                        IRQF_ONESHOT | IRQF_TRIGGER_LOW,
                                        dev_name(tcpci->dev), tcpci);
        if (err < 0)
-               return err;
-
-       err = tcpci_ss_mux_control_init(tcpci);
-       if (err)
-               return err;
+               goto err1;
 
-       tcpci->port = tcpm_register_port(tcpci->dev, &tcpci->tcpc);
-       return PTR_ERR_OR_ZERO(tcpci->port);
+       return 0;
+err1:
+       tcpm_unregister_port(tcpci->port);
+       return err;
 }
 
 static int tcpci_remove(struct i2c_client *client)