From 0d694e35d40b86af5a314f3d0b6b2a1e8b00c152 Mon Sep 17 00:00:00 2001 From: Frank Wang Date: Wed, 11 Jan 2023 17:10:21 +0800 Subject: [PATCH] phy: rockchip: inno-usb2: add devm action for otg wake lock The otg wakelock should be destroyed when the device probe failed or removed, else may cause the following kernel errors. list_add corruption. next->prev should be prev (ffffffc01209d3c8), but was 0000000000000000. (next=ffffff800350faf8). ------------[ cut here ]------------ kernel BUG at lib/list_debug.c:25! Internal error: Oops - BUG: 0 [#1] PREEMPT SMP Modules linked in: CPU: 1 PID: 1 Comm: swapper/0 Not tainted 5.10.110 #83 Hardware name: Rockchip RK3562 EVB1 LP4X V10 Board (DT) pstate: 60400085 (nZCv daIf +PAN -UAO -TCO BTYPE=--) pc : __list_add_valid+0x6c/0x88 lr : __list_add_valid+0x6c/0x88 [...] Call trace: __list_add_valid+0x7c/0x98 wakeup_source_register+0x120/0x160 wakeup_source_register+0x120/0x160 device_init_wakeup+0x60/0xf4 [...] So add devm action to fix it. Signed-off-by: Frank Wang Change-Id: If54a299a694414ad759002e4f6c4187448ccdb15 --- drivers/phy/rockchip/phy-rockchip-inno-usb2.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/drivers/phy/rockchip/phy-rockchip-inno-usb2.c b/drivers/phy/rockchip/phy-rockchip-inno-usb2.c index 9d56c5506045..cb485829dfaa 100644 --- a/drivers/phy/rockchip/phy-rockchip-inno-usb2.c +++ b/drivers/phy/rockchip/phy-rockchip-inno-usb2.c @@ -2077,6 +2077,11 @@ static int rockchip_otg_event(struct notifier_block *nb, return NOTIFY_DONE; } +static void rockchip_otg_wake_lock_destroy(void *data) +{ + wake_lock_destroy((struct wake_lock *)(data)); +} + static int rockchip_usb2phy_otg_port_init(struct rockchip_usb2phy *rphy, struct rockchip_usb2phy_port *rport, struct device_node *child_np) @@ -2195,6 +2200,11 @@ static int rockchip_usb2phy_otg_port_init(struct rockchip_usb2phy *rphy, goto out; wake_lock_init(&rport->wakelock, WAKE_LOCK_SUSPEND, "rockchip_otg"); + ret = devm_add_action_or_reset(rphy->dev, rockchip_otg_wake_lock_destroy, + &rport->wakelock); + if (ret) + return ret; + INIT_DELAYED_WORK(&rport->bypass_uart_work, rockchip_usb_bypass_uart_work); INIT_DELAYED_WORK(&rport->chg_work, rockchip_chg_detect_work); @@ -2207,7 +2217,7 @@ static int rockchip_usb2phy_otg_port_init(struct rockchip_usb2phy *rphy, EXTCON_USB_HOST, &rport->event_nb); if (ret) { dev_err(rphy->dev, "register USB HOST notifier failed\n"); - goto err; + return ret; } } @@ -2223,10 +2233,6 @@ out: rport->suspended = true; return 0; - -err: - wake_lock_destroy(&rport->wakelock); - return ret; } static int rockchip_usb2phy_probe(struct platform_device *pdev)