From: Chenghai Huang <huangchenghai2@huawei.com>
To: <herbert@gondor.apana.org.au>, <davem@davemloft.net>
Cc: <linux-kernel@vger.kernel.org>, <linux-crypto@vger.kernel.org>,
<liulongfang@huawei.com>, <qianweili@huawei.com>,
<wangzhou1@hisilicon.com>, <linwenkai6@hisilicon.com>
Subject: [PATCH 3/4] crypto: hisilicon/qm - fix memory leak in hisi_qm_sort_devices
Date: Fri, 11 Sep 2026 18:29:41 +0800 [thread overview]
Message-ID: <20260911102942.387778-4-huangchenghai2@huawei.com> (raw)
In-Reply-To: <20260911102942.387778-1-huangchenghai2@huawei.com>
From: Wenkai Lin <linwenkai6@hisilicon.com>
hisi_qm_sort_devices() allocates a struct hisi_qm_resource for each
QM device and inserts it into one of two local lists (non_full_list
or full_list). If kzalloc() fails mid-loop, the function returns
-ENOMEM immediately without freeing the resources already inserted
into the local lists.
Because the splice into the caller's @head list happens only after
the loop completes, the caller's free_list(&head) cannot reclaim
them, so the already-allocated res entries are lost.
Fix by freeing both local lists before returning -ENOMEM.
Fixes: 2a75decec119 ("crypto: hisilicon/qm - optimize device selection priority based on queue ref count and NUMA distance")
Signed-off-by: Wenkai Lin <linwenkai6@hisilicon.com>
Signed-off-by: Chenghai Huang <huangchenghai2@huawei.com>
---
drivers/crypto/hisilicon/qm.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/drivers/crypto/hisilicon/qm.c b/drivers/crypto/hisilicon/qm.c
index e915cacef5c0..0448c68dbde4 100644
--- a/drivers/crypto/hisilicon/qm.c
+++ b/drivers/crypto/hisilicon/qm.c
@@ -3846,8 +3846,11 @@ static int hisi_qm_sort_devices(int node, struct list_head *head,
dev_node = 0;
res = kzalloc_obj(*res);
- if (!res)
+ if (!res) {
+ free_list(&non_full_list);
+ free_list(&full_list);
return -ENOMEM;
+ }
res->qm = qm;
res->distance = node_distance(dev_node, node);
--
2.43.0
next prev parent reply other threads:[~2026-09-11 10:29 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-11 10:29 [PATCH 0/4] crypto: hisilicon - fix several issues in QM and SEC drivers Chenghai Huang
2026-09-11 10:29 ` [PATCH 1/4] crypto: hisilicon/qm - fix devm_kcalloc argument order Chenghai Huang
2026-09-11 10:29 ` [PATCH 2/4] crypto: hisilicon/sec2 - fix scheduling while atomic in aead soft fallback Chenghai Huang
2026-09-18 9:13 ` Herbert Xu
[not found] ` <c19bbae6-e1f1-4ca4-8156-8b1fb6746319@huawei.com>
2026-09-28 5:14 ` Herbert Xu
[not found] ` <82938646-1ee4-4789-8911-051c43b84d57@huawei.com>
2026-10-08 8:27 ` Herbert Xu
2026-09-11 10:29 ` Chenghai Huang [this message]
2026-09-11 10:29 ` [PATCH 4/4] crypto: hisilicon/qm - fix GFP flag inconsistency in hisi_qm_memory_init Chenghai Huang
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=20260911102942.387778-4-huangchenghai2@huawei.com \
--to=huangchenghai2@huawei.com \
--cc=davem@davemloft.net \
--cc=herbert@gondor.apana.org.au \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linwenkai6@hisilicon.com \
--cc=liulongfang@huawei.com \
--cc=qianweili@huawei.com \
--cc=wangzhou1@hisilicon.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