From: Jorge Ramirez-Ortiz Date: Fri, 5 Jul 2019 08:13:03 +0000 (+0200) Subject: misc: fastrpc: fix memory leak when out of memory X-Git-Tag: v5.4-rc1~133^2~96 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=41db5f8397eee75afff82655a4884b5786a1d302;p=platform%2Fkernel%2Flinux-rpi.git misc: fastrpc: fix memory leak when out of memory Do the necessary house-keeping if the allocated memory wont be used Signed-off-by: Jorge Ramirez-Ortiz Link: https://lore.kernel.org/r/20190705081303.14170-1-jorge.ramirez-ortiz@linaro.org Signed-off-by: Greg Kroah-Hartman --- diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c index 98603e2..c790585 100644 --- a/drivers/misc/fastrpc.c +++ b/drivers/misc/fastrpc.c @@ -279,8 +279,11 @@ static int fastrpc_buf_alloc(struct fastrpc_user *fl, struct device *dev, buf->virt = dma_alloc_coherent(dev, buf->size, (dma_addr_t *)&buf->phys, GFP_KERNEL); - if (!buf->virt) + if (!buf->virt) { + mutex_destroy(&buf->lock); + kfree(buf); return -ENOMEM; + } if (fl->sctx && fl->sctx->sid) buf->phys += ((u64)fl->sctx->sid << 32);