From: Wenkai Lin <linwenkai6@hisilicon.com> driver inclusion category: bugfix bugzilla: https://atomgit.com/openeuler/kernel/issues/10368 CVE: NA ---------------------------------------------------------------------- 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 — the already-allocated res entries are lost. Fix by freeing both local lists before returning -ENOMEM. Fixes: 3f1ec97aacf1 ("crypto: hisilicon/qm - Put device finding logic into QM") Signed-off-by: Wenkai Lin <linwenkai6@hisilicon.com> Signed-off-by: Ruibin Deng <dengruibin@h-partners.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 be8234664def..6fa8c08e9e7e 100644 --- a/drivers/crypto/hisilicon/qm.c +++ b/drivers/crypto/hisilicon/qm.c @@ -3925,8 +3925,11 @@ static int hisi_qm_sort_devices(int node, struct list_head *head, dev_node = 0; res = kzalloc(sizeof(*res), GFP_KERNEL); - 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