From: Rosen Penev <rosenp@gmail.com>
To: dmaengine@vger.kernel.org
Cc: Vinod Koul <vkoul@kernel.org>, Frank Li <Frank.Li@kernel.org>,
Harninder Rai <harninder.rai@freescale.com>,
Xuelin Shi <xuelin.shi@freescale.com>,
linux-kernel@vger.kernel.org (open list)
Subject: [PATCHv7] dmaengine: fsl_raid: check fsl_re_chan_probe() return value
Date: Fri, 18 Sep 2026 17:43:49 -0700 [thread overview]
Message-ID: <20260919004349.736044-1-rosenp@gmail.com> (raw)
fsl_re_probe() ignores the return value of fsl_re_chan_probe() and
unconditionally increments total_chans. When a channel fails to probe
(for example, an IRQ mapping failure) its re_jrs[] slot is left NULL, yet
total_chans still advances, so fsl_re_remove_chan() later dereferences the
NULL pointer during device removal.
Check return value and guard fsl_re_remove() against NULL entries.
Fixes: ad80da658bbc ("dmaengine: Driver support for FSL RaidEngine device.")
Assisted-by: LLM
Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
v7: handle differently based on sashiko review
v6: increment ridx before continue;
v5: put some stuff on one line for easier readability.
v4: use break;
v3: fix sashiko review
v2: fix description
drivers/dma/fsl_raid.c | 31 +++++++++++++++++++++----------
1 file changed, 21 insertions(+), 10 deletions(-)
diff --git a/drivers/dma/fsl_raid.c b/drivers/dma/fsl_raid.c
index 9cc289f7129e..f269fe9df795 100644
--- a/drivers/dma/fsl_raid.c
+++ b/drivers/dma/fsl_raid.c
@@ -687,7 +687,6 @@ static int fsl_re_chan_probe(struct platform_device *ofdev,
goto err_free;
}
- re_priv->re_jrs[q] = chan;
chan->chan.device = dma_dev;
chan->chan.private = chan;
chan->dev = chandev;
@@ -741,6 +740,11 @@ static int fsl_re_chan_probe(struct platform_device *ofdev,
/* Enable RE/CHAN */
out_be32(&chan->jrregs->jr_command, FSL_RE_ENABLE);
+ /* Only record the channel once it is fully initialized, so the
+ * cleanup paths never touch a partially-probed ring.
+ */
+ re_priv->re_jrs[q] = chan;
+
return 0;
err_free_1:
@@ -836,18 +840,24 @@ static int fsl_re_probe(struct platform_device *ofdev)
}
/* Find out the Job Rings present under each JQ */
for_each_child_of_node(np, child) {
- rc = of_device_is_compatible(child,
- "fsl,raideng-v1.0-job-ring");
- if (rc) {
- fsl_re_chan_probe(ofdev, child, ridx++, off);
- re_priv->total_chans++;
+ if (!of_device_is_compatible(child, "fsl,raideng-v1.0-job-ring"))
+ continue;
+
+ if (ridx >= FSL_RE_MAX_CHANS) {
+ dev_warn(dev, "too many job rings, max %d\n", FSL_RE_MAX_CHANS);
+ of_node_put(child);
+ break;
}
+
+ rc = fsl_re_chan_probe(ofdev, child, ridx, off);
+ if (rc)
+ dev_err(dev, "job ring %d probe failed: %d\n", ridx, rc);
+ re_priv->total_chans++;
+ ridx++;
}
}
- dma_async_device_register(dma_dev);
-
- return 0;
+ return dma_async_device_register(dma_dev);
}
static void fsl_re_remove_chan(struct fsl_re_chan *chan)
@@ -872,7 +882,8 @@ static void fsl_re_remove(struct platform_device *ofdev)
/* Cleanup chan related memory areas */
for (i = 0; i < re_priv->total_chans; i++)
- fsl_re_remove_chan(re_priv->re_jrs[i]);
+ if (re_priv->re_jrs[i])
+ fsl_re_remove_chan(re_priv->re_jrs[i]);
/* Unregister the driver */
dma_async_device_unregister(&re_priv->dma_dev);
--
2.55.0
reply other threads:[~2026-09-19 0:43 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260919004349.736044-1-rosenp@gmail.com \
--to=rosenp@gmail.com \
--cc=Frank.Li@kernel.org \
--cc=dmaengine@vger.kernel.org \
--cc=harninder.rai@freescale.com \
--cc=linux-kernel@vger.kernel.org \
--cc=vkoul@kernel.org \
--cc=xuelin.shi@freescale.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®