usb: typec: qcom-pmic: fix use-after-free on late probe errors
authorJohan Hovold <johan+linaro@kernel.org>
Thu, 18 Apr 2024 14:57:29 +0000 (16:57 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 23 Apr 2024 23:28:19 +0000 (16:28 -0700)
Make sure to stop and deregister the port in case of late probe errors
to avoid use-after-free issues when the underlying memory is released by
devres.

Fixes: a4422ff22142 ("usb: typec: qcom: Add Qualcomm PMIC Type-C driver")
Cc: stable@vger.kernel.org # 6.5
Cc: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
Signed-off-by: Johan Hovold <johan+linaro@kernel.org>
Reviewed-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
Reviewed-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Link: https://lore.kernel.org/r/20240418145730.4605-2-johan+linaro@kernel.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/usb/typec/tcpm/qcom/qcom_pmic_typec.c

index e48412cdcb0fb5b5562afb2ce65af38a1d31840c..d3958c061a972ccbde85c07595132793e80afc94 100644 (file)
@@ -104,14 +104,18 @@ static int qcom_pmic_typec_probe(struct platform_device *pdev)
 
        ret = tcpm->port_start(tcpm, tcpm->tcpm_port);
        if (ret)
-               goto fwnode_remove;
+               goto port_unregister;
 
        ret = tcpm->pdphy_start(tcpm, tcpm->tcpm_port);
        if (ret)
-               goto fwnode_remove;
+               goto port_stop;
 
        return 0;
 
+port_stop:
+       tcpm->port_stop(tcpm);
+port_unregister:
+       tcpm_unregister_port(tcpm->tcpm_port);
 fwnode_remove:
        fwnode_remove_software_node(tcpm->tcpc.fwnode);