Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp360789ybt; Fri, 19 Jun 2020 03:47:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyZKB/nTNQYb8LlPK5ZTiAGwDbKmd311nBBrIoqpq6YsARx6Eu0D2CmBqa2bXD1q5iwjQMs X-Received: by 2002:a17:906:ca54:: with SMTP id jx20mr2946008ejb.549.1592563631419; Fri, 19 Jun 2020 03:47:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592563631; cv=none; d=google.com; s=arc-20160816; b=cVE+bcLwC8bwP5WmJTSAvs/xkzvFbuQZeo5koKR8QurQdtZzroqBhmHA1wFj99pLgK Q4uFJtXfgyD+NKk0txJ5XHxtps8QotaejUAoaYGi0yquokTPBh//LjPmY3a9E754Baxq 0VzCvnvSfIGXsoZcjxSb0KpzkyMFMKZ7nL4z1ODvLlsrUApZY0BmfM4ofXyKOJzVcOvN E3efSTYeD2Sq5DJQtGAcclRpsdfvEC4wSl37UmG2+/TuRRn8R+RtnW/mEseFwL/sKQDm iTHZhA3v4JqZQ3TeExiZmbYOutTjwGs4Fs4KprVMpn4NEsKyWYCg6/IDHt22M8IEp7yi zidA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=s9lWJwM/zrNI6sdLU8hkODCThLGchbQq8K2mTU1105U=; b=kTmT5BzDtpiw7PieGbcVpska/C5ZNOxHJatz0R2pAdl5w7W/yFeT3CsWYKkzAsjHg+ +P8eRtQi6k0NynJFrAFUmyQYVRX8h0ktXh8F834wZktZ57Oz3HQks1kw4ZO4zIqSDqxc QihXqO1v0uo7JN9eVoF8a5wGwfAkeuH4qv0ES0AzxyGDyOH2xagTk/3Kp2FDp5Ta0hqK K1uhcNo1Qh26lpl69r9m+ruw6jEM1ZyaRM+zpCDlF8/H4PJxZYybwDgAb4XhpcIb7U7z 4W6E2mJ6w1yCF0E7z6NlB4so7JnmmUxe7MZLtp3sYb3Watdf+vFdvaBFy1J2TG5nPLeO ypLQ== 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 k14si3670903edr.351.2020.06.19.03.46.47; Fri, 19 Jun 2020 03:47:11 -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 S1732725AbgFSKoU (ORCPT + 99 others); Fri, 19 Jun 2020 06:44:20 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:6364 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1732715AbgFSKoE (ORCPT ); Fri, 19 Jun 2020 06:44:04 -0400 Received: from DGGEMS409-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id 57BF814173BCF5B8416D; Fri, 19 Jun 2020 18:44:01 +0800 (CST) Received: from huawei.com (10.67.174.156) by DGGEMS409-HUB.china.huawei.com (10.3.19.209) with Microsoft SMTP Server id 14.3.487.0; Fri, 19 Jun 2020 18:43:52 +0800 From: Chen Tao To: , CC: , , , , Subject: [PATCH] ARM: OMAP2+: Fix possible memory leak in omap_hwmod_allocate_module Date: Fri, 19 Jun 2020 18:42:40 +0800 Message-ID: <20200619104240.55978-1-chentao107@huawei.com> X-Mailer: git-send-email 2.22.0 MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.67.174.156] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Fix memory leak in omap_hwmod_allocate_module not freeing in handling error path. Fixes: 8c87970543b17("ARM: OMAP2+: Add functions to allocate module data from device tree") Signed-off-by: Chen Tao --- arch/arm/mach-omap2/omap_hwmod.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/arch/arm/mach-omap2/omap_hwmod.c b/arch/arm/mach-omap2/omap_hwmod.c index 82706af307de..d2667f28e68e 100644 --- a/arch/arm/mach-omap2/omap_hwmod.c +++ b/arch/arm/mach-omap2/omap_hwmod.c @@ -3435,7 +3435,7 @@ static int omap_hwmod_allocate_module(struct device *dev, struct omap_hwmod *oh, regs = ioremap(data->module_pa, data->module_size); if (!regs) - return -ENOMEM; + goto out_free_sysc; } /* @@ -3445,13 +3445,13 @@ static int omap_hwmod_allocate_module(struct device *dev, struct omap_hwmod *oh, if (oh->class->name && strcmp(oh->class->name, data->name)) { class = kmemdup(oh->class, sizeof(*oh->class), GFP_KERNEL); if (!class) - return -ENOMEM; + goto out_unmap; } if (list_empty(&oh->slave_ports)) { oi = kcalloc(1, sizeof(*oi), GFP_KERNEL); if (!oi) - return -ENOMEM; + goto out_free_class; /* * Note that we assume interconnect interface clocks will be @@ -3478,6 +3478,14 @@ static int omap_hwmod_allocate_module(struct device *dev, struct omap_hwmod *oh, spin_unlock_irqrestore(&oh->_lock, flags); return 0; + +out_free_class: + kfree(class); +out_unmap: + iounmap(); +out_free_sysc: + kfree(sysc); + return -ENOMEM; } static const struct omap_hwmod_reset omap24xx_reset_quirks[] = { -- 2.22.0