Skip to contentSkip to conversation

sound: soc: fsl: Fix memory leak in imx-audmux.c

PATCH Superseded Felipe Pena 1 participant 1 message Oct 12, 2013

Subsystems (4)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 sound: soc: fsl: Fix memory leak in imx-audmux.c

When audmux_clk is used and clk_prepare_enable function succeed, the memory alloc'd to buf variable is leaked

---
 sound/soc/fsl/imx-audmux.c |    9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
sound/soc/fsl/imx-audmux.c +5 -4
index d3bf71a..977759a 100644
@@ -66,19 +66,20 @@ static ssize_t audmux_read_file(struct file *file, char __user *user_buf,
 				size_t count, loff_t *ppos)
 {
 	ssize_t ret;
-	char *buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
+	char *buf;
 	int port = (int)file->private_data;
 	u32 pdcr, ptcr;
 
-	if (!buf)
-		return -ENOMEM;
-
 	if (audmux_clk) {
 		ret = clk_prepare_enable(audmux_clk);
 		if (ret)
 			return ret;
 	}
 
+	buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
+	if (!buf)
+		return -ENOMEM;
+
 	ptcr = readl(audmux_base + IMX_AUDMUX_V2_PTCR(port));
 	pdcr = readl(audmux_base + IMX_AUDMUX_V2_PDCR(port));
 
Signature · 1 line
1.7.10.4