Skip to contentSkip to conversation

Input: bma150 - Fix runtime PM usage count leak in open

PATCH Applied Arina Kharlamova 2 participants 2 messages Nov 30 – Dec 1

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 Input: bma150 - Fix runtime PM usage count leak in open

pm_runtime_get_sync() keeps the usage count raised even when it fails, and bma150_open() returns on that error without dropping it. The same happens when bma150_set_mode() fails. The input core does not call close() after a failed open(), so every failed open leaks one count.

Use pm_runtime_resume_and_get(), which drops the count when it fails, and put the reference when setting the mode fails.

Fixes c17ca3f5a2c9 ("Input: add driver for Bosch Sensortec's BMA150 accelerometer")

---
Found by checks derived from the spec2patch kernel API specifications, with the help of an AI coding assistant (Claude); I reviewed the analysis and the fix.
---
Changes in v2:
- Use pm_runtime_resume_and_get() and a plain pm_runtime_put() (Dmitry).
- Link to v1: https://patch.msgid.link/[email protected]

---
 drivers/input/misc/bma150.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
drivers/input/misc/bma150.c +5 -3
index 16aecc9b5ef4..c14ce8862697 100644
@@ -346,8 +346,8 @@ static int bma150_open(struct input_dev *input)
 	struct bma150_data *bma150 = input_get_drvdata(input);
 	int error;
 
-	error = pm_runtime_get_sync(&bma150->client->dev);
-	if (error < 0 && error != -ENOSYS)
+	error = pm_runtime_resume_and_get(&bma150->client->dev);
+	if (error)
 		return error;
 
 	/*
@@ -356,8 +356,10 @@ static int bma150_open(struct input_dev *input)
 	 */
 	if (bma150->mode != BMA150_MODE_NORMAL) {
 		error = bma150_set_mode(bma150, BMA150_MODE_NORMAL);
-		if (error)
+		if (error) {
+			pm_runtime_put(&bma150->client->dev);
 			return error;
+		}
 	}
 
 	return 0;

---
base-commit: 25faec9ce61c01fb45abf812a222c5b43c3cd5c5
change-id: 20261129-s2p-c10-1ffdd363d4ed

Best regards,

Signature · 1 line
Arina Kharlamova <[email protected]>
maintainer Applied
#1 lore raw
Quoted 7 lines · On Tue, Dec 01, 2026 at 02:29:00AM +0400, Arina Kharlamova via B4 Relay wrote:

From: Arina Kharlamova <[email protected]>

pm_runtime_get_sync() keeps the usage count raised even when it fails, and bma150_open() returns on that error without dropping it. The same happens when bma150_set_mode() fails. The input core does not call close() after a failed open(), so every failed open leaks one count.

Quoted 5 lines

Use pm_runtime_resume_and_get(), which drops the count when it fails, and put the reference when setting the mode fails.

Fixes c17ca3f5a2c9 ("Input: add driver for Bosch Sensortec's BMA150 accelerometer")

Applied, thank you.

Signature · 1 line
Dmitry