mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] platform/x86: x86-android-tablets: fix codec teardown if poweroff handler setup fails
@ 2026-11-03 10:55 Wentao Liang
  2026-11-03 11:10 ` Krzysztof Kozlowski
  2026-11-03 16:28 ` Hans de Goede
  0 siblings, 2 replies; 3+ messages in thread
From: Wentao Liang @ 2026-11-03 10:55 UTC (permalink / raw)
  To: Hans de Goede, Ilpo Järvinen
  Cc: platform-driver-x86, linux-kernel, Wentao Liang, stable

lenovo_yoga_tab2_830_1050_init_codec() stores the codec device reference,
the pinctrl handle and the pin mappings in globals on success; they are
only released by lenovo_yoga_tab2_830_1050_exit(). If the
register_sys_off_handler() call which follows it fails, the init callback
returns an error before the exit callback has been registered with the
framework, so the codec device reference and the other resources are
never released.

Factor the codec teardown out into a helper and call it from the error
path of both init callbacks.

Fixes: 4ce8f4c2027d ("platform/x86: x86-android-tablets: Fix Lenovo Yoga Tablet 2 830/1050 poweroff again")
Cc: stable@vger.kernel.org
Assisted-by: DeepSeek-V4.1-Flash and OpenAI Codex
Signed-off-by: Wentao Liang <vulab@iscas.ac.cn>
---
 .../platform/x86/x86-android-tablets/lenovo.c | 27 +++++++++++++------
 1 file changed, 19 insertions(+), 8 deletions(-)

diff --git a/drivers/platform/x86/x86-android-tablets/lenovo.c b/drivers/platform/x86/x86-android-tablets/lenovo.c
index 52d96ae89078..294986f84ce8 100644
--- a/drivers/platform/x86/x86-android-tablets/lenovo.c
+++ b/drivers/platform/x86/x86-android-tablets/lenovo.c
@@ -548,6 +548,14 @@ static int __init lenovo_yoga_tab2_830_1050_init_codec(void)
 	return ret;
 }
 
+static void lenovo_yoga_tab2_830_1050_exit_codec(void)
+{
+	device_remove_software_node(lenovo_yoga_tab2_830_1050_codec_dev);
+	pinctrl_put(lenovo_yoga_tab2_830_1050_codec_pinctrl);
+	pinctrl_unregister_mappings(&lenovo_yoga_tab2_830_1050_codec_pinctrl_map);
+	put_device(lenovo_yoga_tab2_830_1050_codec_dev);
+}
+
 /*
  * These tablet's DSDT does not set acpi_gbl_reduced_hardware, so acpi_power_off()
  * gets used as pm_power_off handler. This causes "poweroff" on these tablets
@@ -578,8 +586,11 @@ static int __init lenovo_yoga_tab2_830_1050_init(struct device *dev)
 	lenovo_yoga_tab2_830_1050_sys_off_handler =
 		register_sys_off_handler(SYS_OFF_MODE_POWER_OFF, SYS_OFF_PRIO_FIRMWARE + 1,
 					 lenovo_yoga_tab2_830_1050_power_off, NULL);
-	if (IS_ERR(lenovo_yoga_tab2_830_1050_sys_off_handler))
-		return PTR_ERR(lenovo_yoga_tab2_830_1050_sys_off_handler);
+	if (IS_ERR(lenovo_yoga_tab2_830_1050_sys_off_handler)) {
+		ret = PTR_ERR(lenovo_yoga_tab2_830_1050_sys_off_handler);
+		lenovo_yoga_tab2_830_1050_exit_codec();
+		return ret;
+	}
 
 	return 0;
 }
@@ -588,10 +599,7 @@ static void lenovo_yoga_tab2_830_1050_exit(void)
 {
 	unregister_sys_off_handler(lenovo_yoga_tab2_830_1050_sys_off_handler);
 
-	device_remove_software_node(lenovo_yoga_tab2_830_1050_codec_dev);
-	pinctrl_put(lenovo_yoga_tab2_830_1050_codec_pinctrl);
-	pinctrl_unregister_mappings(&lenovo_yoga_tab2_830_1050_codec_pinctrl_map);
-	put_device(lenovo_yoga_tab2_830_1050_codec_dev);
+	lenovo_yoga_tab2_830_1050_exit_codec();
 }
 
 /*
@@ -776,8 +784,11 @@ static int __init lenovo_yoga_tab2_1380_init(struct device *dev)
 	lenovo_yoga_tab2_830_1050_sys_off_handler =
 		register_sys_off_handler(SYS_OFF_MODE_POWER_OFF, SYS_OFF_PRIO_FIRMWARE + 1,
 					 lenovo_yoga_tab2_830_1050_power_off, NULL);
-	if (IS_ERR(lenovo_yoga_tab2_830_1050_sys_off_handler))
-		return PTR_ERR(lenovo_yoga_tab2_830_1050_sys_off_handler);
+	if (IS_ERR(lenovo_yoga_tab2_830_1050_sys_off_handler)) {
+		ret = PTR_ERR(lenovo_yoga_tab2_830_1050_sys_off_handler);
+		lenovo_yoga_tab2_830_1050_exit_codec();
+		return ret;
+	}
 
 	return 0;
 }
-- 
2.34.1


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-11-03 16:28 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-03 10:55 [PATCH] platform/x86: x86-android-tablets: fix codec teardown if poweroff handler setup fails Wentao Liang
2026-11-03 11:10 ` Krzysztof Kozlowski
2026-11-03 16:28 ` Hans de Goede

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®