From patchwork Tue Nov 17 01:38:30 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brian Norris X-Patchwork-Id: 7631811 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 06396BF90C for ; Tue, 17 Nov 2015 01:40:58 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 1F0A3204A2 for ; Tue, 17 Nov 2015 01:40:57 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 322AA2049E for ; Tue, 17 Nov 2015 01:40:56 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1ZyVEX-000661-7Z; Tue, 17 Nov 2015 01:38:57 +0000 Received: from mail-pa0-x231.google.com ([2607:f8b0:400e:c03::231]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1ZyVEU-00061b-7D for linux-arm-kernel@lists.infradead.org; Tue, 17 Nov 2015 01:38:54 +0000 Received: by padhx2 with SMTP id hx2so193236246pad.1 for ; Mon, 16 Nov 2015 17:38:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=date:from:to:cc:subject:message-id:references:mime-version :content-type:content-disposition:in-reply-to:user-agent; bh=TAMd0l9YhLajieIbVA7dDCddmm4S7EPh06axHhQkIZI=; b=rKo797H6xBPVkKGvQit2RqY7sCdlGnqNngo2znD8L3uMNgoMHlZqnlJFYE9NbGXll+ gaMfOkmk8KeRHz54XBhvYl2Tk0KC8mf2se15zautjcR/2jeDAhteN8hG7mjQZNwtMJj+ WrpaQzF2ShIl88zLXv0W6np7FWj3WZA4a9OCHheezC3aUjnUcI9a3l53gqVi1tykSIWJ ij/uSnG2J/XGl/lc3nmuTTZA352ncku3TFg+/tKU+Xln6B/mCvLHxSfPbVONJn/as6/H +y8ikxDbNVYecFGuisH3Yi9BBD3GnQualuAOdEQyEQhN+xbNCTi0uHQ4rVRp7HMDMsT9 wDAg== X-Received: by 10.67.5.193 with SMTP id co1mr58159742pad.134.1447724313745; Mon, 16 Nov 2015 17:38:33 -0800 (PST) Received: from google.com ([2620:0:1000:1301:64ae:171:73e1:bc49]) by smtp.gmail.com with ESMTPSA id nl10sm4963934pbc.64.2015.11.16.17.38.32 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Mon, 16 Nov 2015 17:38:32 -0800 (PST) Date: Mon, 16 Nov 2015 17:38:30 -0800 From: Brian Norris To: Julia Lawall Subject: Re: [PATCH 1/7] phy: brcmstb-sata: add missing of_node_put Message-ID: <20151117013830.GV8456@google.com> References: <1447673600-8881-1-git-send-email-Julia.Lawall@lip6.fr> <1447673600-8881-2-git-send-email-Julia.Lawall@lip6.fr> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <1447673600-8881-2-git-send-email-Julia.Lawall@lip6.fr> User-Agent: Mutt/1.5.21 (2010-09-15) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20151116_173854_319436_CC4DB610 X-CRM114-Status: GOOD ( 19.12 ) X-Spam-Score: -2.7 (--) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Thomas Petazzoni , Andrew Lunn , Florian Fainelli , Russell King - ARM Linux , Jason Cooper , kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org, Kishon Vijay Abraham I , Gregory Fong , Bjorn Helgaas , linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.9 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP On Mon, Nov 16, 2015 at 12:33:14PM +0100, Julia Lawall wrote: > for_each_available_child_of_node performs an of_node_get on each iteration, > so a return from the middle of the loop requires an of_node_put. > > A simplified version of the semantic patch that finds this problem is as > follows (http://coccinelle.lip6.fr): > > // > @@ > expression root,e; > local idexpression child; > @@ > > for_each_available_child_of_node(root, child) { > ... when != of_node_put(child) > when != e = child > ( > return child; > | > * return ...; > ) > ... > } > // > > Signed-off-by: Julia Lawall > > --- For this patch: Acked-by: Brian Norris > drivers/phy/phy-brcmstb-sata.c | 17 ++++++++++++----- > 1 file changed, 12 insertions(+), 5 deletions(-) [snip patch, which fixes of_node_put() handling for for_each_available_child_of_node() loop, which creates PHY devices with devm_phy_create()] This reminds me of a potential problem I'm looking at in other subsystems: from code reading (I haven't seen any issues in practice, probably because I don't use OF_DYNAMIC) it looks like device-creating infrastructure like the PHY subsystem should be acquiring a reference to the device_node when they stash it away. But drivers/phy/phy-core.c does not do this, AFAICT. See phy_create(), which does phy->dev.of_node = node ?: dev->of_node; and later might reuse this of_node pointer, even though it never called of_node_get() on this node. Potential patch to fix this (not tested). Signed-off-by: Brian Norris diff --git a/drivers/phy/phy-core.c b/drivers/phy/phy-core.c index fc48fac003a6..8df29caeeef9 100644 --- a/drivers/phy/phy-core.c +++ b/drivers/phy/phy-core.c @@ -697,6 +697,7 @@ struct phy *phy_create(struct device *dev, struct device_node *node, phy->dev.class = phy_class; phy->dev.parent = dev; phy->dev.of_node = node ?: dev->of_node; + of_node_get(phy->dev.of_node); phy->id = id; phy->ops = ops; @@ -726,6 +727,7 @@ struct phy *phy_create(struct device *dev, struct device_node *node, return phy; put_dev: + of_node_put(phy->dev.of_node); put_device(&phy->dev); /* calls phy_release() which frees resources */ return ERR_PTR(ret); @@ -775,6 +777,7 @@ EXPORT_SYMBOL_GPL(devm_phy_create); */ void phy_destroy(struct phy *phy) { + of_node_put(phy->dev.of_node); pm_runtime_disable(&phy->dev); device_unregister(&phy->dev); }