diff mbox series

platform/chrome: cros_ec_typec: add remove driver hook

Message ID 20240726181235.920335-1-cascardo@igalia.com (mailing list archive)
State Accepted
Commit a1927fbbf74f9f61eb5c6d1414037c97a8d942ab
Headers show
Series platform/chrome: cros_ec_typec: add remove driver hook | expand

Commit Message

Thadeu Lima de Souza Cascardo July 26, 2024, 6:12 p.m. UTC
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>
---
 drivers/platform/chrome/cros_ec_typec.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

Comments

Tzung-Bi Shih Aug. 9, 2024, 12:58 p.m. UTC | #1
On Fri, Jul 26, 2024 at 03:12:35PM -0300, Thadeu Lima de Souza Cascardo wrote:
> 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.
> 
> [...]

Applied to

    https://git.kernel.org/pub/scm/linux/kernel/git/chrome-platform/linux.git for-next

Thanks!

[1/1] platform/chrome: cros_ec_typec: add remove driver hook
      commit: a1927fbbf74f9f61eb5c6d1414037c97a8d942ab
diff mbox series

Patch

diff --git a/drivers/platform/chrome/cros_ec_typec.c b/drivers/platform/chrome/cros_ec_typec.c
index 4d305876ec08..c7781aea0b88 100644
--- a/drivers/platform/chrome/cros_ec_typec.c
+++ b/drivers/platform/chrome/cros_ec_typec.c
@@ -1285,6 +1285,15 @@  static int cros_typec_probe(struct platform_device *pdev)
 	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);