Skip to contentSkip to conversation

Input: bma150: fix ref count leak in bma150_open

PATCH In review Navid Emamdoost 2 participants 4 messages Jun 14, 2020 – Jun 15, 2020

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

PATCH 1/1 Input: bma150: fix ref count leak in bma150_open

in bma150_open, pm_runtime_get_sync is called which increments the counter even in case of failure, leading to incorrect ref count. In case of failure, decrement the ref count before returning.

---
 drivers/input/misc/bma150.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/input/misc/bma150.c +5 -2
index a9d984da95f3..e2f1b05fcb2a 100644
@@ -348,7 +348,7 @@ static int bma150_open(struct input_dev *input)
 
 	error = pm_runtime_get_sync(&bma150->client->dev);
 	if (error < 0 && error != -ENOSYS)
-		return error;
+		goto out;
 
 	/*
 	 * See if runtime PM woke up the device. If runtime PM
@@ -357,10 +357,13 @@ static int bma150_open(struct input_dev *input)
 	if (bma150->mode != BMA150_MODE_NORMAL) {
 		error = bma150_set_mode(bma150, BMA150_MODE_NORMAL);
 		if (error)
-			return error;
+			goto out;
 	}
 
 	return 0;
+out:
+	pm_runtime_put(&bma150->client->dev);
+	return error;
 }
 
 static void bma150_close(struct input_dev *input)
Signature · 1 line
2.17.1
#1 lore raw
Quoted 4 lines · Navid Emamdoost

in bma150_open, pm_runtime_get_sync is called which increments the counter even in case of failure, leading to incorrect ref count. In case of failure, decrement the ref count before returning.

...

Review

Quoted 4 lines
        error = pm_runtime_get_sync(&bma150->client->dev);
        if (error < 0 && error != -ENOSYS)
(quoted diff) +1 -1
-               return error;
+               goto out;

So, what will happen in case of -ENOSYS?

...

Quoted 1 line

+ pm_runtime_put(&bma150->client->dev);

Slightly better to use _put_noidle(). (More consistency with error path)

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#2 lore raw

PATCH v2 1/1 Input: bma150: fix ref count leak in bma150_open

in bma150_open, pm_runtime_get_sync is called which increments the counter even in case of failure, leading to incorrect ref count. In case of failure, decrement the ref count before returning.

---
Changes in v2:
-- repplace pm_runtime_put with pm_runtime_put_noidle

---
 drivers/input/misc/bma150.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/input/misc/bma150.c +5 -2
index a9d984da95f3..ec394b4faa14 100644
@@ -348,7 +348,7 @@ static int bma150_open(struct input_dev *input)
 
 	error = pm_runtime_get_sync(&bma150->client->dev);
 	if (error < 0 && error != -ENOSYS)
-		return error;
+		goto out;
 
 	/*
 	 * See if runtime PM woke up the device. If runtime PM
@@ -357,10 +357,13 @@ static int bma150_open(struct input_dev *input)
 	if (bma150->mode != BMA150_MODE_NORMAL) {
 		error = bma150_set_mode(bma150, BMA150_MODE_NORMAL);
 		if (error)
-			return error;
+			goto out;
 	}
 
 	return 0;
+out:
+	pm_runtime_put_noidle(&bma150->client->dev);
+	return error;
 }
 
 static void bma150_close(struct input_dev *input)
Signature · 1 line
2.17.1
#3 lore raw
In reply to Andy Shevchenko
Quoted 8 lines · Andy Shevchenko
Quoted 4 lines · Navid Emamdoost

in bma150_open, pm_runtime_get_sync is called which increments the counter even in case of failure, leading to incorrect ref count. In case of failure, decrement the ref count before returning.

Quoted 8 lines

...

Review

Quoted 4 lines
        error = pm_runtime_get_sync(&bma150->client->dev);
        if (error < 0 && error != -ENOSYS)
(quoted diff) +1 -1
-               return error;
+               goto out;

So, what will happen in case of -ENOSYS?

I'm not sure!

Quoted 6 lines

...

Quoted 1 line

+ pm_runtime_put(&bma150->client->dev);

Slightly better to use _put_noidle(). (More consistency with error path)

v2 is sent.

Quoted 4 lines

--
With Best Regards,
Andy Shevchenko

Signature · 1 line
Navid.