fsl_qman_probe() allocates the FQ table. If workqueue allocation
fails, the probe returns without freeing the table, resulting in
a memory leak.

Introduce qman_free_fq_table() and call it on the workqueue
allocation failure path.

Fixes: c535e923bb97 ("soc/fsl: Introduce DPAA 1.x QMan device driver")
Signed-off-by: Haoxiang Li <[email protected]>
---
 drivers/soc/fsl/qbman/qman.c      | 7 +++++++
 drivers/soc/fsl/qbman/qman_ccsr.c | 4 +++-
 drivers/soc/fsl/qbman/qman_priv.h | 1 +
 3 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/drivers/soc/fsl/qbman/qman.c b/drivers/soc/fsl/qbman/qman.c
index 9ddafcb18f1c..10c9fd9f98c1 100644
--- a/drivers/soc/fsl/qbman/qman.c
+++ b/drivers/soc/fsl/qbman/qman.c
@@ -1116,6 +1116,13 @@ int qman_alloc_fq_table(u32 _num_fqids)
        return 0;
 }
 
+void qman_free_fq_table(void)
+{
+       vfree(fq_table);
+       fq_table = NULL;
+       num_fqids = 0;
+}
+
 static struct qman_fq *idx_to_fq(u32 idx)
 {
        struct qman_fq *fq;
diff --git a/drivers/soc/fsl/qbman/qman_ccsr.c 
b/drivers/soc/fsl/qbman/qman_ccsr.c
index aa5348f4902f..f9f333c63c8c 100644
--- a/drivers/soc/fsl/qbman/qman_ccsr.c
+++ b/drivers/soc/fsl/qbman/qman_ccsr.c
@@ -861,8 +861,10 @@ static int fsl_qman_probe(struct platform_device *pdev)
                return ret;
 
        ret = qman_wq_alloc();
-       if (ret)
+       if (ret) {
+               qman_free_fq_table();
                return ret;
+       }
 
        __qman_probed = 1;
 
diff --git a/drivers/soc/fsl/qbman/qman_priv.h 
b/drivers/soc/fsl/qbman/qman_priv.h
index fd1cf543fb81..a3283bcef1ac 100644
--- a/drivers/soc/fsl/qbman/qman_priv.h
+++ b/drivers/soc/fsl/qbman/qman_priv.h
@@ -216,6 +216,7 @@ const struct qm_portal_config 
*qman_destroy_affine_portal(void);
 int qman_query_fq(struct qman_fq *fq, struct qm_fqd *fqd);
 
 int qman_alloc_fq_table(u32 num_fqids);
+void qman_free_fq_table(void);
 
 /*   QMan s/w corenet portal, low-level i/face  */
 
-- 
2.25.1


Reply via email to