Skip to contentSkip to conversation

staging: media: tegra-video: fix syncpoint leak in tegra20 channel init

PATCH In review Cong Nguyen 4 participants 4 messages Jul 26 – Jul 27

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

PATCH 1/1 staging: media: tegra-video: fix syncpoint leak in tegra20 channel init

tegra20_channel_host1x_syncpt_init() requests two host1x syncpoints. It stored the first one (mw ack) into chan->mw_ack_sp[0] and only then requested the second one (frame start). If the second request failed the function returned without releasing the first syncpoint, leaking it: the caller tegra_channel_init() bails out with a bare "return ret" on a syncpt init failure and does not run its free_syncpts error path (that path only covers failures after syncpoint init has fully succeeded), and the channel is subsequently torn down via the kfree()-only path, so nothing ever releases the orphaned syncpoint.

Release the already-acquired syncpoint on the error path, and only publish the syncpoints into the channel once both have been successfully requested, so chan->mw_ack_sp[0] never holds a released handle. This matches the handling in tegra210_channel_host1x_syncpt_init().

Fixes 0e2c4117c351 ("staging: media: tegra-video: add CSI support for Tegra20 and Tegra30")
---
 drivers/staging/media/tegra-video/tegra20.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/staging/media/tegra-video/tegra20.c +4 -3
index e513e6ccb776..f8acb6834a0b 100644
@@ -429,12 +429,13 @@ static int tegra20_channel_host1x_syncpt_init(struct tegra_vi_channel *chan)
 	if (!out_sp)
 		return dev_err_probe(vi->dev, -EBUSY, "failed to request mw ack syncpoint\n");
 
-	chan->mw_ack_sp[0] = out_sp;
-
 	fs_sp = host1x_syncpt_request(&vi->client, HOST1X_SYNCPT_CLIENT_MANAGED);
-	if (!fs_sp)
+	if (!fs_sp) {
+		host1x_syncpt_put(out_sp);
 		return dev_err_probe(vi->dev, -EBUSY, "failed to request frame start syncpoint\n");
+	}
 
+	chan->mw_ack_sp[0] = out_sp;
 	chan->frame_start_sp[0] = fs_sp;
 
 	return 0;
Signature · 1 line
2.25.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 46 lines · Cong Nguyen

tegra20_channel_host1x_syncpt_init() requests two host1x syncpoints. It stored the first one (mw ack) into chan->mw_ack_sp[0] and only then requested the second one (frame start). If the second request failed the function returned without releasing the first syncpoint, leaking it: the caller tegra_channel_init() bails out with a bare "return ret" on a syncpt init failure and does not run its free_syncpts error path (that path only covers failures after syncpoint init has fully succeeded), and the channel is subsequently torn down via the kfree()-only path, so nothing ever releases the orphaned syncpoint.

Release the already-acquired syncpoint on the error path, and only publish the syncpoints into the channel once both have been successfully requested, so chan->mw_ack_sp[0] never holds a released handle. This matches the handling in tegra210_channel_host1x_syncpt_init().

Fixes 0e2c4117c351 ("staging: media: tegra-video: add CSI support for Tegra20 and Tegra30")
---
 drivers/staging/media/tegra-video/tegra20.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/staging/media/tegra-video/tegra20.c +4 -3
index e513e6ccb776..f8acb6834a0b 100644
@@ -429,12 +429,13 @@ static int tegra20_channel_host1x_syncpt_init(struct tegra_vi_channel *chan)
 	if (!out_sp)
 		return dev_err_probe(vi->dev, -EBUSY, "failed to request mw ack syncpoint\n");
 
-	chan->mw_ack_sp[0] = out_sp;
-
 	fs_sp = host1x_syncpt_request(&vi->client, HOST1X_SYNCPT_CLIENT_MANAGED);
-	if (!fs_sp)
+	if (!fs_sp) {
+		host1x_syncpt_put(out_sp);
 		return dev_err_probe(vi->dev, -EBUSY, "failed to request frame start syncpoint\n");
+	}
 
+	chan->mw_ack_sp[0] = out_sp;
 	chan->frame_start_sp[0] = fs_sp;
 
 	return 0;
Signature · 1 line
2.25.1

Thanks!

Reviewed-by on v1 1/1
#2 lore raw
In reply to Cong Nguyen

нд, 26 лип. 2026 р. о 13:04 Cong Nguyen <[email protected]> пише:

Quoted 16 lines

tegra20_channel_host1x_syncpt_init() requests two host1x syncpoints. It stored the first one (mw ack) into chan->mw_ack_sp[0] and only then requested the second one (frame start). If the second request failed the function returned without releasing the first syncpoint, leaking it: the caller tegra_channel_init() bails out with a bare "return ret" on a syncpt init failure and does not run its free_syncpts error path (that path only covers failures after syncpoint init has fully succeeded), and the channel is subsequently torn down via the kfree()-only path, so nothing ever releases the orphaned syncpoint.

Release the already-acquired syncpoint on the error path, and only publish the syncpoints into the channel once both have been successfully requested, so chan->mw_ack_sp[0] never holds a released handle. This matches the handling in tegra210_channel_host1x_syncpt_init().

Quoted 6 lines
Fixes 0e2c4117c351 ("staging: media: tegra-video: add CSI support for Tegra20 and Tegra30")
---
 drivers/staging/media/tegra-video/tegra20.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

Very nice, thank you!

maintainer Reviewed-by on v1 1/1
#3 lore raw
In reply to Cong Nguyen
Quoted 10 lines · Cong Nguyen

tegra20_channel_host1x_syncpt_init() requests two host1x syncpoints. It stored the first one (mw ack) into chan->mw_ack_sp[0] and only then requested the second one (frame start). If the second request failed the function returned without releasing the first syncpoint, leaking it: the caller tegra_channel_init() bails out with a bare "return ret" on a syncpt init failure and does not run its free_syncpts error path (that path only covers failures after syncpoint init has fully succeeded), and the channel is subsequently torn down via the kfree()-only path, so nothing ever releases the orphaned syncpoint.

Quoted 7 lines

Release the already-acquired syncpoint on the error path, and only publish the syncpoints into the channel once both have been successfully requested, so chan->mw_ack_sp[0] never holds a released handle. This matches the handling in tegra210_channel_host1x_syncpt_init().

Fixes 0e2c4117c351 ("staging: media: tegra-video: add CSI support for Tegra20 and Tegra30")

--
Luca Ceresoli, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com