mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] platform/x86: lenovo: convert mutex_init() users to devm_mutex_init()
@ 2026-11-02 13:52 surirajat
  0 siblings, 0 replies; 4+ messages in thread
From: surirajat @ 2026-11-02 13:52 UTC (permalink / raw)
  To: hansg, ilpo.jarvinen
  Cc: platform-driver-x86, linux-kernel, ibm-acpi-devel, markpearson,
	hdegoede, rajat.suri

From: Rajat Suri <rajat.suri@dell.com>

Convert the mutex_init() calls in thinkpad_acpi to devm_mutex_init()
so that the mutex lifecycle is managed by devres.

This fixes thinkpad_acpi, which never destroyed the hotkey, brightness,
volume and fan mutexes on its teardown path.

Per feedback, the patch now covers only driver code for hardware validated so far.

Details per driver:

 - thinkpad_acpi: bind the hotkey, hotkey thread data, brightness, volume
   and fan mutexes to tpacpi_pdev, which is registered before any
   subdriver init runs, and propagate a possible failure from
   devm_mutex_init().

No functional change intended.

Signed-off-by: Rajat Suri <rajat.suri@dell.com>
---
 drivers/platform/x86/lenovo/thinkpad_acpi.c | 22 ++++++++++++++++-----
 1 file changed, 17 insertions(+), 5 deletions(-)

diff --git a/drivers/platform/x86/lenovo/thinkpad_acpi.c b/drivers/platform/x86/lenovo/thinkpad_acpi.c
index 4f81855ad721..0fc105fc28d0 100644
--- a/drivers/platform/x86/lenovo/thinkpad_acpi.c
+++ b/drivers/platform/x86/lenovo/thinkpad_acpi.c
@@ -3381,10 +3381,14 @@ static int __init hotkey_init(struct ibm_init_struct *iibm)
 	       tpacpi_inputdev->close != NULL);
 
 	TPACPI_ACPIHANDLE_INIT(hkey);
-	mutex_init(&hotkey_mutex);
+	res = devm_mutex_init(&tpacpi_pdev->dev, &hotkey_mutex);
+	if (res)
+		return res;
 
 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
-	mutex_init(&hotkey_thread_data_mutex);
+	res = devm_mutex_init(&tpacpi_pdev->dev, &hotkey_thread_data_mutex);
+	if (res)
+		return res;
 #endif
 
 	/* hotkey not supported on 570 */
@@ -6830,11 +6834,14 @@ static int __init brightness_init(struct ibm_init_struct *iibm)
 {
 	struct backlight_properties props;
 	int b;
+	int ret;
 	unsigned long quirks;
 
 	vdbg_printk(TPACPI_DBG_INIT, "initializing brightness subdriver\n");
 
-	mutex_init(&brightness_mutex);
+	ret = devm_mutex_init(&tpacpi_pdev->dev, &brightness_mutex);
+	if (ret)
+		return ret;
 
 	quirks = tpacpi_check_quirks(brightness_quirk_table,
 				ARRAY_SIZE(brightness_quirk_table));
@@ -7575,7 +7582,9 @@ static int __init volume_init(struct ibm_init_struct *iibm)
 
 	vdbg_printk(TPACPI_DBG_INIT, "initializing volume subdriver\n");
 
-	mutex_init(&volume_mutex);
+	rc = devm_mutex_init(&tpacpi_pdev->dev, &volume_mutex);
+	if (rc)
+		return rc;
 
 	/*
 	 * Check for module parameter bogosity, note that we
@@ -8913,11 +8922,14 @@ static const struct tpacpi_quirk fan_quirk_table[] __initconst = {
 static int __init fan_init(struct ibm_init_struct *iibm)
 {
 	unsigned long quirks;
+	int ret;
 
 	vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_FAN,
 			"initializing fan subdriver\n");
 
-	mutex_init(&fan_mutex);
+	ret = devm_mutex_init(&tpacpi_pdev->dev, &fan_mutex);
+	if (ret)
+		return ret;
 	fan_status_access_mode = TPACPI_FAN_NONE;
 	fan_control_access_mode = TPACPI_FAN_WR_NONE;
 	fan_control_commands = 0;
-- 
2.43.0


^ permalink raw reply	[flat|nested] 4+ messages in thread
* [PATCH] platform/x86: lenovo: convert mutex_init() users to devm_mutex_init()
@ 2026-10-30 13:54 surirajat
  2026-10-30 14:03 ` Ilpo Järvinen
  0 siblings, 1 reply; 4+ messages in thread
From: surirajat @ 2026-10-30 13:54 UTC (permalink / raw)
  To: hansg, ilpo.jarvinen
  Cc: platform-driver-x86, linux-kernel, ibm-acpi-devel, markpearson,
	hdegoede, rajat.suri

From: Rajat Suri <rajat.suri@dell.com>

Convert the mutex_init() calls under drivers/platform/x86/lenovo/
to devm_mutex_init() so that the mutex lifecycle is managed by devres.

This removes the need for manual mutex_destroy() calls in wmi-camera and
ideapad-laptop, and fixes thinkpad_acpi, which never destroyed the
hotkey, brightness, volume and fan mutexes on its teardown path.

Details per driver:

 - wmi-camera: bind notify_lock to the WMI device and drop the
   mutex_destroy() from remove().

 - ideapad-laptop: allocate the DYTC private data with devm_kzalloc() and
   bind its mutex to the platform device. Calling mutex_destroy() on a
   manually freed object is not possible with devres, so the kfree() and
   ideapad_dytc_profile_exit() helper are removed as well. The memory now
   outlives the platform profile registration, which is also devm managed
   and therefore released in reverse order.

 - thinkpad_acpi: bind the hotkey, hotkey thread data, brightness, volume
   and fan mutexes to tpacpi_pdev, which is registered before any
   subdriver init runs, and propagate a possible failure from
   devm_mutex_init().

No functional change intended.

Signed-off-by: Rajat Suri <rajat.suri@dell.com>
---
 drivers/platform/x86/lenovo/ideapad-laptop.c | 23 ++++----------------
 drivers/platform/x86/lenovo/thinkpad_acpi.c  | 21 +++++++++++++-----
 drivers/platform/x86/lenovo/wmi-camera.c     |  6 +----
 3 files changed, 21 insertions(+), 29 deletions(-)

diff --git a/drivers/platform/x86/lenovo/ideapad-laptop.c b/drivers/platform/x86/lenovo/ideapad-laptop.c
index fcb5ed7035f5..ee8e00bdaf6b 100644
--- a/drivers/platform/x86/lenovo/ideapad-laptop.c
+++ b/drivers/platform/x86/lenovo/ideapad-laptop.c
@@ -1172,11 +1172,13 @@ static int ideapad_dytc_profile_init(struct ideapad_private *priv)
 		return -ENODEV;
 	}
 
-	priv->dytc = kzalloc_obj(*priv->dytc);
+	priv->dytc = devm_kzalloc(&priv->platform_device->dev, sizeof(*priv->dytc), GFP_KERNEL);
 	if (!priv->dytc)
 		return -ENOMEM;
 
-	mutex_init(&priv->dytc->mutex);
+	err = devm_mutex_init(&priv->platform_device->dev, &priv->dytc->mutex);
+	if (err)
+		goto pp_reg_failed;
 
 	priv->dytc->priv = priv;
 
@@ -1195,24 +1197,11 @@ static int ideapad_dytc_profile_init(struct ideapad_private *priv)
 	return 0;
 
 pp_reg_failed:
-	mutex_destroy(&priv->dytc->mutex);
-	kfree(priv->dytc);
 	priv->dytc = NULL;
 
 	return err;
 }
 
-static void ideapad_dytc_profile_exit(struct ideapad_private *priv)
-{
-	if (!priv->dytc)
-		return;
-
-	mutex_destroy(&priv->dytc->mutex);
-	kfree(priv->dytc);
-
-	priv->dytc = NULL;
-}
-
 /*
  * Rfkill
  */
@@ -2487,8 +2476,6 @@ static int ideapad_acpi_add(struct platform_device *pdev)
 	ideapad_backlight_exit(priv);
 
 backlight_failed:
-	ideapad_dytc_profile_exit(priv);
-
 	for (i = 0; i < IDEAPAD_RFKILL_DEV_NUM; i++)
 		ideapad_unregister_rfkill(priv, i);
 
@@ -2516,8 +2503,6 @@ static void ideapad_acpi_remove(struct platform_device *pdev)
 				   ideapad_acpi_notify);
 
 	ideapad_backlight_exit(priv);
-	ideapad_dytc_profile_exit(priv);
-
 	for (i = 0; i < IDEAPAD_RFKILL_DEV_NUM; i++)
 		ideapad_unregister_rfkill(priv, i);
 
diff --git a/drivers/platform/x86/lenovo/thinkpad_acpi.c b/drivers/platform/x86/lenovo/thinkpad_acpi.c
index 4f81855ad721..8c7d6f281ae3 100644
--- a/drivers/platform/x86/lenovo/thinkpad_acpi.c
+++ b/drivers/platform/x86/lenovo/thinkpad_acpi.c
@@ -3381,10 +3381,14 @@ static int __init hotkey_init(struct ibm_init_struct *iibm)
 	       tpacpi_inputdev->close != NULL);
 
 	TPACPI_ACPIHANDLE_INIT(hkey);
-	mutex_init(&hotkey_mutex);
+	res = devm_mutex_init(&tpacpi_pdev->dev, &hotkey_mutex);
+	if (res)
+		return res;
 
 #ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
-	mutex_init(&hotkey_thread_data_mutex);
+	res = devm_mutex_init(&tpacpi_pdev->dev, &hotkey_thread_data_mutex);
+	if (res)
+		return res;
 #endif
 
 	/* hotkey not supported on 570 */
@@ -6834,7 +6838,9 @@ static int __init brightness_init(struct ibm_init_struct *iibm)
 
 	vdbg_printk(TPACPI_DBG_INIT, "initializing brightness subdriver\n");
 
-	mutex_init(&brightness_mutex);
+	b = devm_mutex_init(&tpacpi_pdev->dev, &brightness_mutex);
+	if (b)
+		return b;
 
 	quirks = tpacpi_check_quirks(brightness_quirk_table,
 				ARRAY_SIZE(brightness_quirk_table));
@@ -7575,7 +7581,9 @@ static int __init volume_init(struct ibm_init_struct *iibm)
 
 	vdbg_printk(TPACPI_DBG_INIT, "initializing volume subdriver\n");
 
-	mutex_init(&volume_mutex);
+	rc = devm_mutex_init(&tpacpi_pdev->dev, &volume_mutex);
+	if (rc)
+		return rc;
 
 	/*
 	 * Check for module parameter bogosity, note that we
@@ -8913,11 +8921,14 @@ static const struct tpacpi_quirk fan_quirk_table[] __initconst = {
 static int __init fan_init(struct ibm_init_struct *iibm)
 {
 	unsigned long quirks;
+	int rc;
 
 	vdbg_printk(TPACPI_DBG_INIT | TPACPI_DBG_FAN,
 			"initializing fan subdriver\n");
 
-	mutex_init(&fan_mutex);
+	rc = devm_mutex_init(&tpacpi_pdev->dev, &fan_mutex);
+	if (rc)
+		return rc;
 	fan_status_access_mode = TPACPI_FAN_NONE;
 	fan_control_access_mode = TPACPI_FAN_WR_NONE;
 	fan_control_commands = 0;
diff --git a/drivers/platform/x86/lenovo/wmi-camera.c b/drivers/platform/x86/lenovo/wmi-camera.c
index 89ecbce60bf4..de4596686d2a 100644
--- a/drivers/platform/x86/lenovo/wmi-camera.c
+++ b/drivers/platform/x86/lenovo/wmi-camera.c
@@ -107,9 +107,7 @@ static int lenovo_wmi_probe(struct wmi_device *wdev, const void *context)
 
 	dev_set_drvdata(&wdev->dev, priv);
 
-	mutex_init(&priv->notify_lock);
-
-	return 0;
+	return devm_mutex_init(&wdev->dev, &priv->notify_lock);
 }
 
 static void lenovo_wmi_remove(struct wmi_device *wdev)
@@ -118,8 +116,6 @@ static void lenovo_wmi_remove(struct wmi_device *wdev)
 
 	if (priv->idev)
 		input_unregister_device(priv->idev);
-
-	mutex_destroy(&priv->notify_lock);
 }
 
 static const struct wmi_device_id lenovo_wmi_id_table[] = {
-- 
2.43.0


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

end of thread, other threads:[~2026-11-02 13:52 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-02 13:52 [PATCH] platform/x86: lenovo: convert mutex_init() users to devm_mutex_init() surirajat
  -- strict thread matches above, loose matches on Subject: below --
2026-10-30 13:54 surirajat
2026-10-30 14:03 ` Ilpo Järvinen
2026-10-31  1:04   ` Mark Pearson

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®