Received: by 10.192.165.148 with SMTP id m20csp128697imm; Wed, 9 May 2018 09:53:32 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrRBlFV5H8XS6KVtM8PfgEvw20vWVU4JbD0OdVbM1J563fvijnpQXxpHRWbvrXABu1C1MfO X-Received: by 2002:a17:902:8c81:: with SMTP id t1-v6mr41784529plo.310.1525884812153; Wed, 09 May 2018 09:53:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525884812; cv=none; d=google.com; s=arc-20160816; b=e5UH6nAyygxecym2NkzhIJwfWbaaW38jVumDVJvlv+pzPbz2d45d8m6SPOxiX/8tgj l8N5ckP0whRXhhmPduN0J1HNAh2tIgsdGaGrUrHdEDOIs6i2ZRhTbs4wUv1Jt1faD8Q2 d2/xqNQtkXH6yPkQsqsvyRcK1d3shH/yt+DeojgVi88dGu2EsFByeHMSbE86NrOrE9jV TXqlu5dngIjk9oLCLpa7fSQJA1jeZ6hAFEwVRnPncNmTLw+A11CM4Tg6ERJ/+8s//EHN Vnw+pkNPklNB+v3Ft8mcuKvFd+dNN9ugcV29XFef5nfBkQsN+tuuUwyWurSK814mIswe Jmog== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:arc-authentication-results; bh=onSYijMU/3wNaJla4344GYlkzxIBwVNIjGKj0+hvLLA=; b=Jr8tx5m1IxVlGWIu57hQLLklG5VnpLRFyvayeNoisfIHYbaY83u0UjVksjZBCnOkdm zQFRZlLG8vVFoZZqk0R0ReRv/cJCK+kkf5P7BueNaaBVYIcKFA9YuEMfc1/T2BEU92Nq KP6+q99d64D0Slqo928Ot8+w6vSASTBQuyTdGAGBc9CUVLiIjC8MhNNom5KSrSC+Ej5w DCyYMF6FzG/B7QnqD7zUrQg7iAQXxL5bqFp9ENhbyA7LTONYcMIr8/RfnZYOA53MRAO7 A70JzyNq9KA7Or8djfVSLGJMMbDALn4vJfnpyehDrfg+GWcqSBb9KX3K7/TxZ1H6NW/3 e7hg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 36-v6si13288833plb.140.2018.05.09.09.53.14; Wed, 09 May 2018 09:53:32 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965534AbeEIQxD (ORCPT + 99 others); Wed, 9 May 2018 12:53:03 -0400 Received: from 9pmail.ess.barracuda.com ([64.235.150.224]:47400 "EHLO 9pmail.ess.barracuda.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934971AbeEIQxB (ORCPT ); Wed, 9 May 2018 12:53:01 -0400 X-Greylist: delayed 913 seconds by postgrey-1.27 at vger.kernel.org; Wed, 09 May 2018 12:50:45 EDT Received: from mipsdag01.mipstec.com (mail1.mips.com [12.201.5.31]) by mx26.ess.sfj.cudaops.com (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA256 bits=128 verify=NO); Wed, 09 May 2018 16:50:37 +0000 Received: from mipsdag02.mipstec.com (10.20.40.47) by mipsdag01.mipstec.com (10.20.40.46) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1415.2; Wed, 9 May 2018 09:33:38 -0700 Received: from localhost (10.20.1.18) by mipsdag02.mipstec.com (10.20.40.47) with Microsoft SMTP Server id 15.1.1415.2 via Frontend Transport; Wed, 9 May 2018 09:33:38 -0700 Date: Wed, 9 May 2018 09:33:11 -0700 From: Paul Burton To: Dan Carpenter , Colin King CC: Michael Turquette , Stephen Boyd , , , , Subject: Re: [PATCH] clk: boston: fix memory leak of 'onecell' on error return paths Message-ID: <20180509163311.alvyibwwuwkumyxf@pburton-laptop> References: <20180509134031.11611-1-colin.king@canonical.com> <20180509140135.4dndt3baomtxups5@mwanda> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Disposition: inline In-Reply-To: <20180509140135.4dndt3baomtxups5@mwanda> User-Agent: NeoMutt/20180323 X-BESS-ID: 1525884637-853316-27024-312772-1 X-BESS-VER: 2018.5-r1804261738 X-BESS-Apparent-Source-IP: 12.201.5.31 X-BESS-Outbound-Spam-Score: 0.50 X-BESS-Outbound-Spam-Report: Code version 3.2, rules version 3.2.2.192850 Rule breakdown below pts rule name description ---- ---------------------- -------------------------------- 0.50 BSF_RULE7568M META: Custom Rule 7568M 0.00 BSF_BESS_OUTBOUND META: BESS Outbound X-BESS-Outbound-Spam-Status: SCORE=0.50 using account:ESS59374 scores of KILL_LEVEL=7.0 tests=BSF_RULE7568M, BSF_BESS_OUTBOUND X-BESS-BRTS-Status: 1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Colin & Dan, On Wed, May 09, 2018 at 05:01:35PM +0300, Dan Carpenter wrote: > On Wed, May 09, 2018 at 02:40:31PM +0100, Colin King wrote: > > From: Colin Ian King > > > > There are several error return paths that don't free up onecell > > and hence we have some memory leaks. Add an error exit path that > > kfree's onecell to fix the leaks. > > > > Signed-off-by: Colin Ian King > > --- > > drivers/clk/imgtec/clk-boston.c | 15 +++++++++++---- > > 1 file changed, 11 insertions(+), 4 deletions(-) > > > > diff --git a/drivers/clk/imgtec/clk-boston.c b/drivers/clk/imgtec/clk-boston.c > > index 15af423cc0c9..d6bc468ff551 100644 > > --- a/drivers/clk/imgtec/clk-boston.c > > +++ b/drivers/clk/imgtec/clk-boston.c > > @@ -73,27 +73,34 @@ static void __init clk_boston_setup(struct device_node *np) > > hw = clk_hw_register_fixed_rate(NULL, "input", NULL, 0, in_freq); > > if (IS_ERR(hw)) { > > pr_err("failed to register input clock: %ld\n", PTR_ERR(hw)); > > - return; > > + goto error; > > I hate vague label names like "error" and "out"... > > There are a bunch of other resources that we should free if we decide > it's worth freeing things. Agreed - for example unregistering the clocks that we'd be discarding references to by freeing onecell. > Can this even boot without the clk? Nope. If this clock setup fails then whether you free this memory or not you're going to be unable to do anything useful with it. I imagine this patch is the result of some static analysis rather than a problem being observed at runtime? Thanks, Paul > When > the label names says what is freed, then you mentally only have to keep > track of the most recently allocated resource. So if > > hw = clk_hw_register_fixed_rate(NULL, "input", NULL, 0, in_freq); > > succeeds then the next goto is going to "goto free_clk_input;". > > regards, > dan carpenter