Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp12079597ybi; Fri, 26 Jul 2019 04:28:00 -0700 (PDT) X-Google-Smtp-Source: APXvYqzhzlOuPyYoFSkRjsezVpAxGMPDir6kbTWfFRaQtgO8XviBkRVZKNOApikhVTQ/H0ck3mWB X-Received: by 2002:a17:902:2987:: with SMTP id h7mr1795620plb.37.1564140480271; Fri, 26 Jul 2019 04:28:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564140480; cv=none; d=google.com; s=arc-20160816; b=Kngegepz4lY+Gd1DXR5u+P9ORUsbuoDX5llvteYI/tvwuoChXlpwpjj3h4tbXF2wJa d//UQKFEwpzquULynPw8XrixFvM882RE8x588r6riNNPVBNWoXy3W8dq4V+SDylRl/VX spyaO7qjz1+W1qcaFltbdwehSa/uFjfSO9lFcq+VrYcd2qpjV+HiP1mOlifiJ63xax+4 4CugcAijZIe8cCyH8p+k6SGlURxyuasZEkImJUCa4m+9hWkZrZkCV3gb1fxFIErPRfgY gKBXRQeLxrF7XS2C62Ix/LuUkE3frVTyGZEyTg2d+8zGjVW/T4/zbkhQtxacp/eS6/gu J6Qg== 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:dkim-signature; bh=DiLw617umykXb2Ab64YhiIyIqGLqcMOLE/qOfe0nhxg=; b=cn+7jCFqW1T1BXBcUuL4UIZPiLOszyBj5DvGXc+bdBaVkG+s/SfCQNgCmV3uapynBQ Vc+AM2OSJjqqLL0sn9Ye35/E9KSvYog6l44atnIopWWl82JoTpQfOL0DS+VqGYlDhtBG RpKV6eiPfJekJSzGUvdMzMaZMwhyw+8PGEKfthjShiR2FntJCQPW1NsArk9j3/7oBR7u 2SwkBeC11kNfqeUrxMcYUGNdiwWWf5t4MG1vAgfZVvNqxfGjCox7ChZvyC93NagBatKc ynJlagAm5yg/8bb3amm3lH9Tt7/mOA5oNZanexlDTTMitQHPLhfv3jVwsgMsMVOElQLm wD4g== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@sirena.org.uk header.s=20170815-heliosphere header.b="Zj5fo/Ze"; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p62si17986630pjp.66.2019.07.26.04.27.45; Fri, 26 Jul 2019 04:28:00 -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; dkim=fail header.i=@sirena.org.uk header.s=20170815-heliosphere header.b="Zj5fo/Ze"; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726496AbfGZKpu (ORCPT + 99 others); Fri, 26 Jul 2019 06:45:50 -0400 Received: from heliosphere.sirena.org.uk ([172.104.155.198]:59924 "EHLO heliosphere.sirena.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726203AbfGZKpu (ORCPT ); Fri, 26 Jul 2019 06:45:50 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sirena.org.uk; s=20170815-heliosphere; h=In-Reply-To:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=DiLw617umykXb2Ab64YhiIyIqGLqcMOLE/qOfe0nhxg=; b=Zj5fo/Ze6u/+6R7jl/2UE8DZP XvkRoAiAuQiWDsCeWbifjJhRwmf8ruIxKTO+fB5ASu6V4Yr3I5EbKAwvpHU+sTgSrHAIJzb1V7Np6 +fHp1FzJkjGwILI8fpHSJpw+sRRYNwKB/iN44KJpTzuVWA6CIjabdweLWjVIyUC78ESZw=; Received: from cpc102320-sgyl38-2-0-cust46.18-2.cable.virginm.net ([82.37.168.47] helo=ypsilon.sirena.org.uk) by heliosphere.sirena.org.uk with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1hqxjR-00018l-4g; Fri, 26 Jul 2019 10:45:49 +0000 Received: by ypsilon.sirena.org.uk (Postfix, from userid 1000) id DD4052742B63; Fri, 26 Jul 2019 11:45:47 +0100 (BST) Date: Fri, 26 Jul 2019 11:45:47 +0100 From: Mark Brown To: Nishka Dasgupta Cc: lgirdwood@gmail.com, linux-kernel@vger.kernel.org Subject: Re: [PATCH] regulator: of: Add of_node_put() before return in function Message-ID: <20190726104547.GA4902@sirena.org.uk> References: <20190724083231.10276-1-nishkadg.linux@gmail.com> <20190724154701.GA4524@sirena.org.uk> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="C7zPtVaVf+AK4Oqc" Content-Disposition: inline In-Reply-To: X-Cookie: List at least two alternate dates. User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --C7zPtVaVf+AK4Oqc Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Fri, Jul 26, 2019 at 01:02:52PM +0530, Nishka Dasgupta wrote: > On 24/07/19 9:17 PM, Mark Brown wrote: > > On Wed, Jul 24, 2019 at 02:02:31PM +0530, Nishka Dasgupta wrote: > > > The local variable search in regulator_of_get_init_node takes the value > > > returned by either of_get_child_by_name or of_node_get, both of which > > > get a node. If this node is not put before returning, it could cause a > > > memory leak. Hence put search before a mid-loop return statement. > > > Issue found with Coccinelle. > > > - if (!strcmp(desc->of_match, name)) > > > + if (!strcmp(desc->of_match, name)) { > > > + of_node_put(search); > > > return of_node_get(child); > > > + } > > Why not just remove the extra of_node_get() and a comment explaining why > > it's not needed? > I'm sorry, I don't think I understand. I'm putting search in this patch; the > program was already getting child. Should I also return child directly > instead of getting it again, and continue to put search? Your new code is dropping a reference then immediately reacquiring one to return it (introducing a race condition along the way). Why not just return the already held reference and not call any functions at all? --C7zPtVaVf+AK4Oqc Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEEreZoqmdXGLWf4p/qJNaLcl1Uh9AFAl062dgACgkQJNaLcl1U h9BqfAf/XkPCA/poexRgHnpFE+r37fkrF/5xoqRAFbobrvS42H1YdMPKPDuShBG2 akn59PB6QIRjUgSVJVgdCRvAVDR6/HvvR55SUD66w6iQY3qHIFGxn426t9huP++T Rox4MQtM4W/6QKb9jXN8fxstr+bvw7LXgXoc5ZHBQ2boMfWormTWe7TtNIp+uZkc o2Id8iUdXPRk6fwQcRtTAiL3cJpLKWEGh0zK3EB8gFSFolgacoOooY4XeR02lP2T zmNYrdrGlNPG9ddjKW+RBerO1v8PObzmWmY3hcsTnbhQMnolKklzsJB3egv9FpLW pbq3pldG5+VJsEHoOmcAnq9DgAUAGQ== =k/xs -----END PGP SIGNATURE----- --C7zPtVaVf+AK4Oqc--