Received: by 2002:a05:6a10:eb17:0:0:0:0 with SMTP id hx23csp1250425pxb; Sat, 4 Sep 2021 04:43:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzG6PZMDS8f3bsb/zmlCoseg2Ve5zX7wplSnlpBQQut/bo7IdBe7XK/c6PKFFtaQJDasmUd X-Received: by 2002:a17:906:a012:: with SMTP id p18mr3819216ejy.331.1630755806417; Sat, 04 Sep 2021 04:43:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1630755806; cv=none; d=google.com; s=arc-20160816; b=m10JS350Z1BTrxuOUmD9GIfyjwvJAReYItDNDXc1T4K45q99TdA1jZAQOcTD61HlGK c0vO/wKULdK0HT/wgVDifbAoyigxxbaG5kE5iuEY1UE2SX1DRcaUWu3pPmu5Abnt0JIR EBuQzDz8mFvj5eFIZm3mwvs86n0eYu5eqzJc0GfYkyU2U0s8YT+42mKL87745OuHTe8/ yLWy5XOR7bFFbHbEpHQoOEZITLMrJV620ErhSEh5K1B6UsJvsaRExrAMBA9/TD9Edisa /BFfYabpPH/EZVNCB084IvxmYJsXCOveofG4/kFRvokn3LPgYL4Hh54OX9dn/aNoDsJd gWEQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=BAKzZwi2oyIzVnhLsnwQEtdmLWvUzm7TtuHKGODnbE0=; b=EDJMy1PgN6mVu0tnTGFzpDUYqKUqMfGGKKovaY8e+HUcREGitvHVGVg+TYtNPnjq/4 uv5elgxY0ZIf+dCYeTxoPPE6riEz/6ojwmy61gJVa+uc5x0bdUlgyjd3IwNThwzs7v5E DwROPgE8bmxMkX+Ey4z37KchsK3c3//DcugiJFeg6TOae7vwSwCVla/VFVikObDFvCuR 0pnGE8M292ZSBgOUrV3ti8iFEcHaEPRXwkCuHPs1kw5S/OLeQk1ZQmuRV7+pEiRhKbfj H9tdFl9UUE6ZVGqzU1me9CadB0das8vh4Ct3d+/siO85YVFSSUgogbNPk+LnK4qypPXy KoVA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ec12si2304144edb.85.2021.09.04.04.42.34; Sat, 04 Sep 2021 04:43:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235943AbhIDLij (ORCPT + 99 others); Sat, 4 Sep 2021 07:38:39 -0400 Received: from smtp08.smtpout.orange.fr ([80.12.242.130]:56261 "EHLO smtp.smtpout.orange.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236285AbhIDLii (ORCPT ); Sat, 4 Sep 2021 07:38:38 -0400 Received: from pop-os.home ([90.126.253.178]) by mwinf5d31 with ME id pndZ250093riaq203ndZ3n; Sat, 04 Sep 2021 13:37:35 +0200 X-ME-Helo: pop-os.home X-ME-Auth: Y2hyaXN0b3BoZS5qYWlsbGV0QHdhbmFkb28uZnI= X-ME-Date: Sat, 04 Sep 2021 13:37:35 +0200 X-ME-IP: 90.126.253.178 From: Christophe JAILLET To: ohad@wizery.com, bjorn.andersson@linaro.org, mathieu.poirier@linaro.org, james.quinlan@broadcom.com Cc: linux-remoteproc@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org, Christophe JAILLET Subject: [PATCH] remoteproc: Fix a memory leak in an error handling path in 'rproc_handle_vdev()' Date: Sat, 4 Sep 2021 13:37:32 +0200 Message-Id: X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org If 'copy_dma_range_map() fails, the memory allocated for 'rvdev' will leak. Move the 'copy_dma_range_map()' call after the device registration so that 'rproc_rvdev_release()' can be called to free some resources. Also, branch to the error handling path if 'copy_dma_range_map()' instead of a direct return to avoid some other leaks. Fixes: e0d072782c73 ("dma-mapping: introduce DMA range map, supplanting dma_pfn_offset") Signed-off-by: Christophe JAILLET --- Compile tested only. Review with care. I don't like to move code around because of possible side-effect. --- drivers/remoteproc/remoteproc_core.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c index 502b6604b757..775df165eb45 100644 --- a/drivers/remoteproc/remoteproc_core.c +++ b/drivers/remoteproc/remoteproc_core.c @@ -556,9 +556,6 @@ static int rproc_handle_vdev(struct rproc *rproc, void *ptr, /* Initialise vdev subdevice */ snprintf(name, sizeof(name), "vdev%dbuffer", rvdev->index); rvdev->dev.parent = &rproc->dev; - ret = copy_dma_range_map(&rvdev->dev, rproc->dev.parent); - if (ret) - return ret; rvdev->dev.release = rproc_rvdev_release; dev_set_name(&rvdev->dev, "%s#%s", dev_name(rvdev->dev.parent), name); dev_set_drvdata(&rvdev->dev, rvdev); @@ -568,6 +565,11 @@ static int rproc_handle_vdev(struct rproc *rproc, void *ptr, put_device(&rvdev->dev); return ret; } + + ret = copy_dma_range_map(&rvdev->dev, rproc->dev.parent); + if (ret) + goto free_rvdev; + /* Make device dma capable by inheriting from parent's capabilities */ set_dma_ops(&rvdev->dev, get_dma_ops(rproc->dev.parent)); -- 2.30.2