[PATCH] firmware: tegra: bpmp: Free SRAM on channel initialization failure
From: Haoxiang Li
Date: Wed Nov 18 2026 - 08:53:26 EST
If TX or RX channel initialization fails after SRAM allocation
succeeds, tegra186_bpmp_setup_channels() returns without freeing
the two SRAM buffers.
Route all channel initialization failures through the existing
teardown path. Check the bpmp field before cleaning up the TX
and RX channels so that teardown skips channels that were not
successfully initialized.
Fixes: 2abd484ca48f ("firmware: tegra: bpmp: Add support for DRAM MRQ GSCs")
Signed-off-by: Haoxiang Li <haoxiang_li2024@xxxxxxx>
---
drivers/firmware/tegra/bpmp-tegra186.c | 22 ++++++++++++----------
1 file changed, 12 insertions(+), 10 deletions(-)
diff --git a/drivers/firmware/tegra/bpmp-tegra186.c b/drivers/firmware/tegra/bpmp-tegra186.c
index 5a97496600ac..d0a865ad604c 100644
--- a/drivers/firmware/tegra/bpmp-tegra186.c
+++ b/drivers/firmware/tegra/bpmp-tegra186.c
@@ -179,8 +179,10 @@ static void tegra186_bpmp_teardown_channels(struct tegra_bpmp *bpmp)
tegra186_bpmp_channel_cleanup(&bpmp->threaded_channels[i]);
}
- tegra186_bpmp_channel_cleanup(bpmp->rx_channel);
- tegra186_bpmp_channel_cleanup(bpmp->tx_channel);
+ if (bpmp->rx_channel->bpmp)
+ tegra186_bpmp_channel_cleanup(bpmp->rx_channel);
+ if (bpmp->tx_channel->bpmp)
+ tegra186_bpmp_channel_cleanup(bpmp->tx_channel);
if (priv->tx.pool) {
gen_pool_free(priv->tx.pool, (unsigned long)priv->tx.sram, 4096);
@@ -283,14 +285,12 @@ static int tegra186_bpmp_setup_channels(struct tegra_bpmp *bpmp)
err = tegra186_bpmp_channel_init(bpmp->tx_channel, bpmp,
bpmp->soc->channels.cpu_tx.offset);
if (err < 0)
- return err;
+ goto err_teardown;
err = tegra186_bpmp_channel_init(bpmp->rx_channel, bpmp,
bpmp->soc->channels.cpu_rx.offset);
- if (err < 0) {
- tegra186_bpmp_channel_cleanup(bpmp->tx_channel);
- return err;
- }
+ if (err < 0)
+ goto err_teardown;
for (i = 0; i < bpmp->threaded.count; i++) {
unsigned int index = bpmp->soc->channels.thread.offset + i;
@@ -298,11 +298,13 @@ static int tegra186_bpmp_setup_channels(struct tegra_bpmp *bpmp)
err = tegra186_bpmp_channel_init(&bpmp->threaded_channels[i],
bpmp, index);
if (err < 0)
- break;
+ goto err_teardown;
}
- if (err < 0)
- tegra186_bpmp_teardown_channels(bpmp);
+ return 0;
+
+err_teardown:
+ tegra186_bpmp_teardown_channels(bpmp);
return err;
}
--
2.25.1