Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp1396925pxa; Thu, 20 Aug 2020 10:10:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyWR34Y78P+EUY4BiP8IFxQLu0VHOdWPPTUMBirptbuf1+8kTf83vJ+cIxdtEb3QD8M1V93 X-Received: by 2002:a05:6402:1457:: with SMTP id d23mr3870231edx.149.1597943457232; Thu, 20 Aug 2020 10:10:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597943457; cv=none; d=google.com; s=arc-20160816; b=XsrFCoLMkdmv1yooamNF0u7wqppYLu0qkexuuKm90fHSAVy7KHOKEsjmc4VGyLZiID +Pr8ED7vVoahvK4A0ni5kbJiqCD0UVU6JHZup8Pe/3IjV3G9TudGoj2mZWWdcgkFipPm vTAH1MvcAqJbuTY6g/Oo65LTOgjPE4CHbSoiGk6gD4lRelIKNxDMG/aQgr2HDlhPLM75 z88mNKoLLpEjUlc9FGOkObwOX/BJUk2ypfdm4QQ/SEynpwAL+x5/3h+3ITGSYTvxlXDE ulrAOk0CZRcoSqNHZ97nNEyiJVpWpGx17UF08ayqD44/duBpvuEvWfemdMmjyTqeF4Aa 4SsQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:date:from :dkim-signature; bh=/R0k1jGWuhMoblqt/y/Rxs518YQHPPA6fBEtJHgtyO8=; b=c0Ru7RBNUhxWpDpkEE6kw2L9/o3PowGbhLTSJfJZRSx+rAkGyIKTZCuDmjQBDcFcTf doHBvdVeyJd4ul5re3aVsfM2eP0cUj3hRoPDi0Uh0JVSwamVMGfmSRMR4Bmew+Zl23/h +q1Q2iJXDT6BQZBb85NJsKYalvDsgH/+X+haCKJQCFlEkk7KdpN8eGiHnnDrXojvKoZf wsC+aY3rifgUsYGvGpTgrLIZoL5SMIUv26jfYWQ6RstF6yRDhn1hI43g47KbpKh31rJ8 yD5wL08LacNsWqGEhfhLECA7HQ//DA3uq37ABJGP6Z/sy2M3Sqw34F65LMQ0fco76W1Q yFQw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=sZDJL8G2; 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 u18si1584839ejr.700.2020.08.20.10.10.33; Thu, 20 Aug 2020 10:10:57 -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=sZDJL8G2; 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 S1730370AbgHTRJ0 (ORCPT + 99 others); Thu, 20 Aug 2020 13:09:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43046 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730423AbgHTRIk (ORCPT ); Thu, 20 Aug 2020 13:08:40 -0400 Received: from mail-wm1-x342.google.com (mail-wm1-x342.google.com [IPv6:2a00:1450:4864:20::342]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CF0BBC061385 for ; Thu, 20 Aug 2020 10:08:39 -0700 (PDT) Received: by mail-wm1-x342.google.com with SMTP id t14so2279541wmi.3 for ; Thu, 20 Aug 2020 10:08:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:date:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=/R0k1jGWuhMoblqt/y/Rxs518YQHPPA6fBEtJHgtyO8=; b=sZDJL8G2LfU/6BRu0eKseTlgdQByMRU40zPpzst1uny/m8nTPOncCx5nHSPisw+m1g 4py17touSYiqoYFABUof5XWPk1yi2mV8BWjgQ4ZpFiA+dgrVgu9aQvDJm3t9FUVRSZMT a43MfyC9LoMebQyjh93lIS9SRJOZ15G9Le26Ntg8wbn75qbt4wJcIEyvTFF2xvrxqND9 lHpWeg/QCRKlvAiin/QIyOe+mbCvJ3vUDn0MXORn3YpTqK3abccdpfiPgsrb/2qHK2UA 32BwTAtT6SUSfkiWtn977+lSApwriSRvtcopuHAVP7DumSl0u5UmEp5Ny6FYpo6ViqPl ycQA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:date:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=/R0k1jGWuhMoblqt/y/Rxs518YQHPPA6fBEtJHgtyO8=; b=CCrLlZz/X4z6MV11NvruFaPm+sgOChfeBakA6yR9HYx+y78DaaHJTV92MJYPKGvKlH LowWYbMAHUghy1VVv9HKbp6eveI+KUQUyMO9onzGlqML6EfHZd5TPyq1DVaOjVVXP9/Y zWciL1QbNFRLmUl3Vw4AcP28dwyQOZJPSd4/QcmGPSw5by5SURTRsRJN5I90kRnfipbQ viKeiGcHLv9//uSZU5qGJeUh5tKVe8wj2cFzBBKKCsVxVVQ591Ql8P9CkSV3rjLfDtfw K9HzpfLcno4Ig++4d7GuG5/A7AOteN0mRVWENwku0mgHwsBloFk4nuLBHTM24awJP446 LAzw== X-Gm-Message-State: AOAM531TkFDWkukjOY5hnUDMlybBECASDdXOYxw2L11caNBlMUkDMhDx RNoY4kuKgG65qRz8vvSc/ms= X-Received: by 2002:a1c:4b0d:: with SMTP id y13mr4338861wma.6.1597943318553; Thu, 20 Aug 2020 10:08:38 -0700 (PDT) Received: from medion (cpc83661-brig20-2-0-cust443.3-3.cable.virginm.net. [82.28.105.188]) by smtp.gmail.com with ESMTPSA id z12sm5359904wrp.20.2020.08.20.10.08.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Aug 2020 10:08:37 -0700 (PDT) From: Alex Dewar X-Google-Original-From: Alex Dewar Date: Thu, 20 Aug 2020 18:08:35 +0100 To: Krzysztof Kozlowski Cc: Alex Dewar , Markus Mayer , bcm-kernel-feedback-list@broadcom.com, Florian Fainelli , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] memory: brcmstb_dpfe: Fix memory leak Message-ID: <20200820170835.eos4mia5aokkikog@medion> References: <20200818110201.69933-1-alex.dewar90@gmail.com> <20200820152944.GB17144@kozik-lap> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200820152944.GB17144@kozik-lap> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Aug 20, 2020 at 05:29:44PM +0200, Krzysztof Kozlowski wrote: > On Tue, Aug 18, 2020 at 12:02:01PM +0100, Alex Dewar wrote: > > 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; > > This does not look needed. Why initializing it? You cannot jump to > release_fw label or reach it without going through assignment. > > Best regards, > Krzysztof Good spot! I'll send a v2. > > > > > /* > > * 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 > >