Skip to contentSkip to conversation

platform/chrome: wilco_ec: Fix device reference leak on open failure

PATCH In review Yige Jiang 2 participants 2 messages Nov 5 – Nov 6

Subsystems (2)
lore
Share & tools
lore

Yige Jiang

author
#0 lore raw

PATCH v2 1/1 platform/chrome: wilco_ec: Fix device reference leak on open failure

telem_open() takes a reference to dev_data->dev before allocating the session. If that allocation fails, it returns -ENOMEM without dropping the reference. Since release is not called after a failed open, the device data remains pinned after removal.

Take the device reference only after the session allocation succeeds, so that a failed open does not leave an unbalanced reference. The successful open path remains balanced by telem_release().

Fixes 1210d1e6bad1 ("platform/chrome: wilco_ec: Add telemetry char device interface")

---
Changes in v2:
- Move get_device() after successful session allocation instead of adding put_device() to the allocation failure path, as suggested by Tzung-Bi Shih.
- Drop the obsolete Assisted-by trailer and retain the AI disclosure below.

v1 Message-ID: <[email protected]> Based on linux-next next-20261102 (2637bdec0535).
Compile-tested: baseline and v2 arm64 target objects, GCC 14.2.0, W=1. CONFIG_COMPILE_TEST=y, CONFIG_OF_DYNAMIC=y, CONFIG_WILCO_EC_TELEMETRY=m. No full kernel/module-link, hardware or runtime test was performed. AI assistance: Codex (LLM) helped make the patch.

 drivers/platform/chrome/wilco_ec/telemetry.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/platform/chrome/wilco_ec/telemetry.c +2 -2
index 45be318b05f6..b91cb62c4192 100644
@@ -245,13 +245,13 @@
 	if (atomic_cmpxchg(&dev_data->available, 1, 0) == 0)
 		return -EBUSY;
 
-	get_device(&dev_data->dev);
-
 	sess_data = kzalloc_obj(*sess_data);
 	if (!sess_data) {
 		atomic_set(&dev_data->available, 1);
 		return -ENOMEM;
 	}
+
+	get_device(&dev_data->dev);
 	sess_data->dev_data = dev_data;
 	sess_data->has_msg = false;
 

base-commit: 2637bdec0535a2044cd830eba9a79363651d9043

maintainer
#1 lore raw
Quoted 10 lines · Yige Jiang

telem_open() takes a reference to dev_data->dev before allocating the session. If that allocation fails, it returns -ENOMEM without dropping the reference. Since release is not called after a failed open, the device data remains pinned after removal.

Take the device reference only after the session allocation succeeds, so that a failed open does not leave an unbalanced reference. The successful open path remains balanced by telem_release().

[...]

Applied to

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

[1/1] platform/chrome: wilco_ec: Fix device reference leak on open failure

      commit: 80436896141ecca950125dec3f320b7aacc5038a

Thanks!