From patchwork Mon Nov 11 09:59:05 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Faiz Abbas X-Patchwork-Id: 1192851 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=quarantine dis=none) header.from=ti.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ti.com header.i=@ti.com header.b="Km1/ZwWe"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 47BRCF27dBz9sPV for ; Mon, 11 Nov 2019 20:58:17 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id E0349C21DA2; Mon, 11 Nov 2019 09:58:10 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 4668FC21C29; Mon, 11 Nov 2019 09:58:09 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 129F3C21C29; Mon, 11 Nov 2019 09:58:07 +0000 (UTC) Received: from fllv0015.ext.ti.com (fllv0015.ext.ti.com [198.47.19.141]) by lists.denx.de (Postfix) with ESMTPS id 7BF0EC21BE5 for ; Mon, 11 Nov 2019 09:58:06 +0000 (UTC) Received: from fllv0035.itg.ti.com ([10.64.41.0]) by fllv0015.ext.ti.com (8.15.2/8.15.2) with ESMTP id xAB9w42R015127; Mon, 11 Nov 2019 03:58:04 -0600 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1573466284; bh=gjlFv+hTPAj1icL0hw3lcbriL7QgI7DIqmM2g0CtLxE=; h=From:To:CC:Subject:Date; b=Km1/ZwWeUwC2W7mIYjm6191ZwFmOYweQG3YfD2hD8NEROnNHfdeeskVxX+gk4/7gP O5guqkCW69h/2UaAhvckDCaqxKpuNx/RboRMz+9RnLv9RZyF77IErcIz8GXEynENpC TDLeuQQMboUyZvfMKenvZZt7JGgk16zazCtZDkaE= Received: from DFLE113.ent.ti.com (dfle113.ent.ti.com [10.64.6.34]) by fllv0035.itg.ti.com (8.15.2/8.15.2) with ESMTP id xAB9w46a098933; Mon, 11 Nov 2019 03:58:04 -0600 Received: from DFLE112.ent.ti.com (10.64.6.33) by DFLE113.ent.ti.com (10.64.6.34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1847.3; Mon, 11 Nov 2019 03:57:47 -0600 Received: from lelv0327.itg.ti.com (10.180.67.183) by DFLE112.ent.ti.com (10.64.6.33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1847.3 via Frontend Transport; Mon, 11 Nov 2019 03:57:47 -0600 Received: from a0230074-OptiPlex-7010.india.ti.com (ileax41-snat.itg.ti.com [10.172.224.153]) by lelv0327.itg.ti.com (8.15.2/8.15.2) with ESMTP id xAB9w2EO052571; Mon, 11 Nov 2019 03:58:03 -0600 From: Faiz Abbas To: Date: Mon, 11 Nov 2019 15:29:05 +0530 Message-ID: <20191111095905.4068-1-faiz_abbas@ti.com> X-Mailer: git-send-email 2.19.2 MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 Subject: [U-Boot] [PATCH] regmap: Fix potential memory leaks X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" Free allocated memory in case of an error in regmap_init_mem() and regmap_init_mem_index(). Signed-off-by: Faiz Abbas --- drivers/core/regmap.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/drivers/core/regmap.c b/drivers/core/regmap.c index e9e55c9d16..a974744a61 100644 --- a/drivers/core/regmap.c +++ b/drivers/core/regmap.c @@ -134,7 +134,7 @@ int regmap_init_mem_index(ofnode node, struct regmap **mapp, int index) ret = init_range(node, map->ranges, addr_len, size_len, index); if (ret) - return ret; + goto err; if (ofnode_read_bool(node, "little-endian")) map->endianness = REGMAP_LITTLE_ENDIAN; @@ -147,6 +147,10 @@ int regmap_init_mem_index(ofnode node, struct regmap **mapp, int index) *mapp = map; + return 0; +err: + regmap_uninit(map); + return ret; } @@ -158,6 +162,7 @@ int regmap_init_mem(ofnode node, struct regmap **mapp) int addr_len, size_len, both_len; int len; int index; + int ret; addr_len = ofnode_read_simple_addr_cells(ofnode_get_parent(node)); if (addr_len < 0) { @@ -200,10 +205,9 @@ int regmap_init_mem(ofnode node, struct regmap **mapp) for (range = map->ranges, index = 0; count > 0; count--, range++, index++) { - int ret = init_range(node, range, addr_len, size_len, index); - + ret = init_range(node, range, addr_len, size_len, index); if (ret) - return ret; + goto err; } if (ofnode_read_bool(node, "little-endian")) @@ -218,6 +222,10 @@ int regmap_init_mem(ofnode node, struct regmap **mapp) *mapp = map; return 0; +err: + regmap_uninit(map); + + return ret; } #endif