Skip to contentSkip to conversation

remoteproc: omap: Fix cleanup after timer start failure

PATCH Applied Suyuan Wang 3 participants 3 messages Nov 18 – Nov 30 Remote processor (remoteproc)

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 remoteproc: omap: Fix cleanup after timer start failure

From: Suyuan Wang <[email protected]>

When omap_rproc_start_timer() fails in omap_rproc_enable_timers(), the error handling has three problems.

First, the stop loop also stops the timer that failed to start:

	while (i >= 0) {
		omap_rproc_stop_timer(&timers[i]);
		i--;
	}

omap_dm_timer_start() drops its runtime PM reference when pm_runtime_resume_and_get() fails, so stopping that timer calls pm_runtime_put_sync() once more than it should.

Second, the loop leaves i at -1 and then jumps to put_node, which falls through to free_timers:

	while (i--) {
		...
		omap_rproc_release_timer(&timers[i]);

With i == -1 the condition is true and the first iteration uses timers[-2]. The loop then keeps going through negative indexes.

Third, when configure is true, put_node puts np again. The parse loop already put every node it got, and np still points at the last one, so that reference is dropped twice.

Only stop the timers that were started. On resume (configure == false) return the error and keep the timers: they still belong to the driver and are released later by omap_rproc_disable_timers(rproc, true). On the first start (configure == true) release all the timers that were set up and skip put_node, since no node reference is held at this point.

Found with a static analysis tool and checked by hand.

Fixes e28edc571925 ("remoteproc/omap: Request a timer(s) for remoteproc usage")

---
Compile tested on arm with clang (W=1, no new warnings). I don't have the hardware, so the failure path hasn't been run.

---
 drivers/remoteproc/omap_remoteproc.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
drivers/remoteproc/omap_remoteproc.c +7 -4
index f52a531877ae..d50f2e993c4e 100644
@@ -418,11 +418,14 @@ static int omap_rproc_enable_timers(struct rproc *rproc, bool configure)
 		}
 	}
 	if (ret) {
-		while (i >= 0) {
+		while (i--)
 			omap_rproc_stop_timer(&timers[i]);
-			i--;
-		}
-		goto put_node;
+
+		if (!configure)
+			return ret;
+
+		i = num_timers;
+		goto free_timers;
 	}
 	return 0;
 
Reviewed-by on v1 1/1
#1 lore raw
Quoted 63 lines · On Wed, Nov 18, 2026 at 03:38:25PM +0000, Suyuan Wang via B4 Relay wrote:

From: Suyuan Wang <[email protected]>

When omap_rproc_start_timer() fails in omap_rproc_enable_timers(), the error handling has three problems.

First, the stop loop also stops the timer that failed to start:

	while (i >= 0) {
		omap_rproc_stop_timer(&timers[i]);
		i--;
	}

omap_dm_timer_start() drops its runtime PM reference when pm_runtime_resume_and_get() fails, so stopping that timer calls pm_runtime_put_sync() once more than it should.

Second, the loop leaves i at -1 and then jumps to put_node, which falls through to free_timers:

	while (i--) {
		...
		omap_rproc_release_timer(&timers[i]);

With i == -1 the condition is true and the first iteration uses timers[-2]. The loop then keeps going through negative indexes.

Third, when configure is true, put_node puts np again. The parse loop already put every node it got, and np still points at the last one, so that reference is dropped twice.

Only stop the timers that were started. On resume (configure == false) return the error and keep the timers: they still belong to the driver and are released later by omap_rproc_disable_timers(rproc, true). On the first start (configure == true) release all the timers that were set up and skip put_node, since no node reference is held at this point.

Found with a static analysis tool and checked by hand.

Fixes e28edc571925 ("remoteproc/omap: Request a timer(s) for remoteproc usage")

---
Compile tested on arm with clang (W=1, no new warnings). I don't have the hardware, so the failure path hasn't been run.

---
 drivers/remoteproc/omap_remoteproc.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
drivers/remoteproc/omap_remoteproc.c +1 -3
index f52a531877ae..d50f2e993c4e 100644
@@ -418,11 +418,14 @@ static int omap_rproc_enable_timers(struct rproc *rproc, bool configure)
 		}
 	}
 	if (ret) {
-		while (i >= 0) {
+		while (i--)
 			omap_rproc_stop_timer(&timers[i]);
-			i--;
-		}

drivers/remoteproc/omap_remoteproc.c static int omap_rproc_enable_timers(struct rproc *rproc, bool configure) · line 431

Quoted 10 lines
drivers/remoteproc/omap_remoteproc.c +6 -1
-		goto put_node;
+
+		if (!configure)
+			return ret;
+
+		i = num_timers;
+		goto free_timers;
 	}
 	return 0;
 

Regards,
Francesco

maintainer Applied
#2 lore raw
In reply to Suyuan Wang
Quoted 43 lines · On Wed, Nov 18, 2026 at 03:38:25PM +0000, Suyuan Wang via B4 Relay wrote:

From: Suyuan Wang <[email protected]>

When omap_rproc_start_timer() fails in omap_rproc_enable_timers(), the error handling has three problems.

First, the stop loop also stops the timer that failed to start:

	while (i >= 0) {
		omap_rproc_stop_timer(&timers[i]);
		i--;
	}

omap_dm_timer_start() drops its runtime PM reference when pm_runtime_resume_and_get() fails, so stopping that timer calls pm_runtime_put_sync() once more than it should.

Second, the loop leaves i at -1 and then jumps to put_node, which falls through to free_timers:

	while (i--) {
		...
		omap_rproc_release_timer(&timers[i]);

With i == -1 the condition is true and the first iteration uses timers[-2]. The loop then keeps going through negative indexes.

Third, when configure is true, put_node puts np again. The parse loop already put every node it got, and np still points at the last one, so that reference is dropped twice.

Only stop the timers that were started. On resume (configure == false) return the error and keep the timers: they still belong to the driver and are released later by omap_rproc_disable_timers(rproc, true). On the first start (configure == true) release all the timers that were set up and skip put_node, since no node reference is held at this point.

Found with a static analysis tool and checked by hand.

Fixes e28edc571925 ("remoteproc/omap: Request a timer(s) for remoteproc usage")
Quoted 7 lines

---
Compile tested on arm with clang (W=1, no new warnings). I don't have the hardware, so the failure path hasn't been run.

---
 drivers/remoteproc/omap_remoteproc.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

Applied.

Thanks,
Mathieu

Quoted 27 lines
drivers/remoteproc/omap_remoteproc.c +7 -4
index f52a531877ae..d50f2e993c4e 100644
@@ -418,11 +418,14 @@ static int omap_rproc_enable_timers(struct rproc *rproc, bool configure)
 		}
 	}
 	if (ret) {
-		while (i >= 0) {
+		while (i--)
 			omap_rproc_stop_timer(&timers[i]);
-			i--;
-		}
-		goto put_node;
+
+		if (!configure)
+			return ret;
+
+		i = num_timers;
+		goto free_timers;
 	}
 	return 0;