[v3,05/30] dma/dpaa2: add sanity check for SG entry

Message ID 20240722163930.2171568-6-g.singh@nxp.com (mailing list archive)
State Superseded
Delegated to: Thomas Monjalon
Headers
Series NXP DMA driver fixes and Enhancements |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Gagandeep Singh July 22, 2024, 4:39 p.m. UTC
From: Jun Yang <jun.yang@nxp.com>

Make sure the SG entry number doesn't overflow.

Signed-off-by: Jun Yang <jun.yang@nxp.com>
---
 drivers/dma/dpaa2/dpaa2_qdma.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
  

Comments

Stephen Hemminger July 22, 2024, 8:21 p.m. UTC | #1
On Mon, 22 Jul 2024 22:09:05 +0530
Gagandeep Singh <g.singh@nxp.com> wrote:

> From: Jun Yang <jun.yang@nxp.com>
> 
> Make sure the SG entry number doesn't overflow.
> 
> Signed-off-by: Jun Yang <jun.yang@nxp.com>
> ---

Please do not use the term 'sanity check'.
It is on the Inclusive Naming word list as a Tier 2: strongly consider replacing.
https://inclusivenaming.org/word-lists/tier-2/sanity-check/
  

Patch

diff --git a/drivers/dma/dpaa2/dpaa2_qdma.c b/drivers/dma/dpaa2/dpaa2_qdma.c
index 44b82c139e..7f6ebcb46b 100644
--- a/drivers/dma/dpaa2/dpaa2_qdma.c
+++ b/drivers/dma/dpaa2/dpaa2_qdma.c
@@ -615,8 +615,17 @@  dpaa2_qdma_copy_sg(void *dev_private,
 	struct qbman_fle *fle;
 	struct qdma_sdd *sdd;
 
-	if (unlikely(nb_src != nb_dst))
+	if (unlikely(nb_src != nb_dst)) {
+		DPAA2_QDMA_ERR("SG entry src num(%d) != dst num(%d)",
+			nb_src, nb_dst);
 		return -ENOTSUP;
+	}
+
+	if (unlikely(nb_src > RTE_DPAA2_QDMA_JOB_SUBMIT_MAX)) {
+		DPAA2_QDMA_ERR("SG entry number(%d) > MAX(%d)",
+			nb_src, RTE_DPAA2_QDMA_JOB_SUBMIT_MAX);
+		return -EINVAL;
+	}
 
 	memset(fd, 0, sizeof(struct qbman_fd));