From d8864856e7f998f55519d8bfb72d5562b891febf Mon Sep 17 00:00:00 2001 From: Aditya Bavanari Date: Wed, 27 May 2020 13:09:33 +0530 Subject: [PATCH] asoc: Fix a memory leak issue when nvmem read returns invalid length When nvmem cell read returns invalid length the allocated buffer is not freed. Free the buffer in this scenario to fix memory leak issue. Change-Id: I68585c1dd45b0a40c471bf42dea201cd0ebb497f Signed-off-by: Aditya Bavanari --- asoc/bengal.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/asoc/bengal.c b/asoc/bengal.c index 22677cb258f8..e82736e611da 100644 --- a/asoc/bengal.c +++ b/asoc/bengal.c @@ -6714,10 +6714,16 @@ static int msm_asoc_machine_probe(struct platform_device *pdev) } buf = nvmem_cell_read(cell, &len); nvmem_cell_put(cell); - if (IS_ERR_OR_NULL(buf) || len <= 0 || len > sizeof(32)) { + if (IS_ERR_OR_NULL(buf)) { dev_dbg(&pdev->dev, "%s: FAILED to read nvmem cell \n", __func__); goto ret; } + if (len <= 0 || len > sizeof(u32)) { + dev_dbg(&pdev->dev, "%s: nvmem cell length out of range: %d\n", + __func__, len); + kfree(buf); + goto ret; + } memcpy(&adsp_var_idx, buf, len); kfree(buf); va_disable = adsp_var_idx;