Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp2999812pxa; Tue, 18 Aug 2020 04:03:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJye2IfcIiETaE7Uy1KkvHVeUMYqi5u3/kDlhfXwJT3QPpv1nhxf5Wh/XkAZVr/w+zX+VsWN X-Received: by 2002:aa7:dd91:: with SMTP id g17mr19957734edv.186.1597748611400; Tue, 18 Aug 2020 04:03:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597748611; cv=none; d=google.com; s=arc-20160816; b=H5P5j9H5aIKEK4XlA9IwD4qqH0bwcazjD/946eJWbtDwF2mHJt3w9BTvBEBJEEJBIV gwmNATcW+gAjjDB+Xd6OUiMZy0Nz40pocViejn5SmJc5ESmt2xiHJx4eHuJ/39IOzF/H aFfjkj4kylHuF6D1Hy34+eyfZ9lfTY2VXvDHY6VZu1Iz7pJM7i6I4jiaNwezPHWunmIf ifqZyqhq4XyDlQTTzbfgLbXfHJSXQZb4IMIbQw8XerC6oQTd5fUaBDtOZI02wo1PhJM6 yr7BmLrXDHzR5ss02V1c6EO0KQc0IbwzeA14s28oNw9YeC04FwU2yPBXBfruwPvIYMHY SpxA== 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:dkim-signature; bh=5V8irRRRxRnwftdg2ujt2Pfnni+sPye5ForxfSVU5CI=; b=gQ+GBOdYSx2OG16SB1Dcb+LeW52eA/jwPnJZFIi7yjgJv85xCU1mjnJ/UjNUer22iW lS7txmAXw2sDZEuStKjVijkFMjzmAFFNzV/ps5hKUWDZGbj24iW1QC0gN64HdH1RQ1PJ e6wF2AgMLMe1S8SydpUEU0RPQvgA55qCAwZXS7UOvyQ+v0GHejhzlKKivgX5Oq3kUxLf cZo/y2PRq1jLPXlefkFTBiDH8XeqypB0kySwrPlPOkxpDgS0d1me5EmvoT8PndPlEUXu ght0J07urG3WUw0ZAu72f9fGd9gv37BuFSn02F9lNtosiAiEnoASSUQeqySxDj0k6eSg oV3w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=lTziVxCt; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h25si13320320eje.30.2020.08.18.04.03.08; Tue, 18 Aug 2020 04:03:31 -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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=lTziVxCt; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726585AbgHRLCW (ORCPT + 99 others); Tue, 18 Aug 2020 07:02:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47060 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726043AbgHRLCU (ORCPT ); Tue, 18 Aug 2020 07:02:20 -0400 Received: from mail-wr1-x442.google.com (mail-wr1-x442.google.com [IPv6:2a00:1450:4864:20::442]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2461EC061389 for ; Tue, 18 Aug 2020 04:02:20 -0700 (PDT) Received: by mail-wr1-x442.google.com with SMTP id z18so17815311wrm.12 for ; Tue, 18 Aug 2020 04:02:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=5V8irRRRxRnwftdg2ujt2Pfnni+sPye5ForxfSVU5CI=; b=lTziVxCtCNaxClvjURD4ZAxeMl9SLrTRlo3tg9crwli+r+Ce+zS9oaxdHt3NdqfTdI 5Fa86ptTQwsxUkO9bE4EJHhH7nFgmxcQtRPOtU0SkOeqHJEOYhhX0YrrKOkhCGWsoRWa QKLpz1YxCI5P9F3dR1VL8yg0zvKFYE2imoLJba7ljEc/eaDsx9MtuMlQ6Vu3k7XPobXH K5MO/spovlbi4X6oyPMcjijkDLT5/Y3C/XeU8q9UBIaXMScrHr98IzaxDssaZNSgb74h pr21KG9upxRA892xblwe9bkCDcobrcUbshJgg2vA3e91W4CTOL4/2sHH7XdwqD+bwjfE LTbA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=5V8irRRRxRnwftdg2ujt2Pfnni+sPye5ForxfSVU5CI=; b=Acu1yomptHJJXHmey4x9f/CsCOTtWG4yd9g3gjjn6Xhv9xTCyt8mI7GUknCur4vINW BF1WMHtP3YCffYticwGFR5CWbwLqRDClLokzItyrggMS1CpW//fBdDLd41bGXSv/FdiF BSn+ITRm0EVpkwEOk4JArF36/FFiyHtPi+dLanPLuPVlBk1FzZbrcJDaHMUDA361Ag2M J7Mnl4i7UHBKTCmW6GXoheHzMpaD6P3cA965AHNxT8qU/MCoZzL5uvO835kYXjQqSQgN mOZxvlzydbczAmMGgW4ucCmtkCuZwFbLdUYIVoPi/FXZwUnAU93bfdmKzN3l7EKiM/N6 ISRg== X-Gm-Message-State: AOAM533tzLlmJieC4xYkyNyTBaZVTxRoNJtbBa8NRezRPC6MiCrsi5Hp yoNNp25cGttRxDMbk/L02tI= X-Received: by 2002:adf:97d3:: with SMTP id t19mr18635202wrb.138.1597748538730; Tue, 18 Aug 2020 04:02:18 -0700 (PDT) Received: from localhost.localdomain (cpc83661-brig20-2-0-cust443.3-3.cable.virginm.net. [82.28.105.188]) by smtp.gmail.com with ESMTPSA id k13sm32825220wmj.14.2020.08.18.04.02.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Aug 2020 04:02:10 -0700 (PDT) From: Alex Dewar To: Markus Mayer , bcm-kernel-feedback-list@broadcom.com, Krzysztof Kozlowski , Florian Fainelli , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Alex Dewar Subject: [PATCH] memory: brcmstb_dpfe: Fix memory leak Date: Tue, 18 Aug 2020 12:02:01 +0100 Message-Id: <20200818110201.69933-1-alex.dewar90@gmail.com> X-Mailer: git-send-email 2.28.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In brcmstb_dpfe_download_firmware(), memory is allocated to variable fw by firmware_request_nowarn(), but never released. Fix up to release fw on all return paths. Signed-off-by: Alex Dewar --- drivers/memory/brcmstb_dpfe.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/drivers/memory/brcmstb_dpfe.c b/drivers/memory/brcmstb_dpfe.c index 60e8633b1175..f24a9dc65f3c 100644 --- a/drivers/memory/brcmstb_dpfe.c +++ b/drivers/memory/brcmstb_dpfe.c @@ -616,7 +616,7 @@ static int brcmstb_dpfe_download_firmware(struct brcmstb_dpfe_priv *priv) const u32 *dmem, *imem; struct init_data init; const void *fw_blob; - int ret; + int ret = 0; /* * Skip downloading the firmware if the DCPU is already running and @@ -647,8 +647,10 @@ static int brcmstb_dpfe_download_firmware(struct brcmstb_dpfe_priv *priv) return (ret == -ENOENT) ? -EPROBE_DEFER : ret; ret = __verify_firmware(&init, fw); - if (ret) - return -EFAULT; + if (ret) { + ret = -EFAULT; + goto release_fw; + } __disable_dcpu(priv); @@ -667,18 +669,20 @@ static int brcmstb_dpfe_download_firmware(struct brcmstb_dpfe_priv *priv) ret = __write_firmware(priv->dmem, dmem, dmem_size, is_big_endian); if (ret) - return ret; + goto release_fw; ret = __write_firmware(priv->imem, imem, imem_size, is_big_endian); if (ret) - return ret; + goto release_fw; ret = __verify_fw_checksum(&init, priv, header, init.chksum); if (ret) - return ret; + goto release_fw; __enable_dcpu(priv); - return 0; +release_fw: + release_firmware(fw); + return ret; } static ssize_t generic_show(unsigned int command, u32 response[], -- 2.28.0