]> www.infradead.org Git - linux.git/commitdiff
platform/chrome: cros_ec_typec: add remove driver hook
authorThadeu Lima de Souza Cascardo <cascardo@igalia.com>
Fri, 26 Jul 2024 18:12:35 +0000 (15:12 -0300)
committerTzung-Bi Shih <tzungbi@kernel.org>
Fri, 9 Aug 2024 12:55:09 +0000 (20:55 +0800)
This allows the driver to be unbound and bound again. Otherwise, when
unbinding the driver, there will be leftover sysfs entries.

When rebinding the driver, it also ends up touching freed memory when
adding to the notifier chain as the old one was not removed and ends up
being traversed.

Add a remove_new driver hook, which removes the notifier from the chain and
unregisters the typec ports.

Signed-off-by: Thadeu Lima de Souza Cascardo <cascardo@igalia.com>
Link: https://lore.kernel.org/r/20240726181235.920335-1-cascardo@igalia.com
Signed-off-by: Tzung-Bi Shih <tzungbi@kernel.org>
drivers/platform/chrome/cros_ec_typec.c

index 4d305876ec08f6d87e7f2d6c3bb5478d26e1db36..c7781aea0b88b2066c07107f2a5d2dcf16b999a0 100644 (file)
@@ -1285,6 +1285,15 @@ unregister_ports:
        return ret;
 }
 
+static void cros_typec_remove(struct platform_device *pdev)
+{
+       struct cros_typec_data *typec = platform_get_drvdata(pdev);
+
+       cros_usbpd_unregister_notify(&typec->nb);
+       cancel_work_sync(&typec->port_work);
+       cros_unregister_ports(typec);
+}
+
 static int __maybe_unused cros_typec_suspend(struct device *dev)
 {
        struct cros_typec_data *typec = dev_get_drvdata(dev);
@@ -1316,6 +1325,7 @@ static struct platform_driver cros_typec_driver = {
                .pm = &cros_typec_pm_ops,
        },
        .probe = cros_typec_probe,
+       .remove_new = cros_typec_remove,
 };
 
 module_platform_driver(cros_typec_driver);