From patchwork Tue Mar 15 00:30:39 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Daney X-Patchwork-Id: 8584491 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 02ECF9F54C for ; Tue, 15 Mar 2016 00:33:03 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 1CADE20263 for ; Tue, 15 Mar 2016 00:33:02 +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 32570201BB for ; Tue, 15 Mar 2016 00:33:01 +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 1afcth-0003L4-Qx; Tue, 15 Mar 2016 00:31:41 +0000 Received: from mail-pf0-x244.google.com ([2607:f8b0:400e:c00::244]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1afctE-0002yk-Av for linux-arm-kernel@lists.infradead.org; Tue, 15 Mar 2016 00:31:14 +0000 Received: by mail-pf0-x244.google.com with SMTP id x3so274395pfb.0 for ; Mon, 14 Mar 2016 17:30:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=g70WoWvYGEB64ezQmlbjTuqG3rHgUdUwqryne4k2aWI=; b=CKaMawGUfrUncduIDjvDVCXBKU8Dj7HBtYpgLEkWqawW0SUufReX7/N+8YQ5DBWsvy lpNpAnOIPj41efjEwDo1o/O2xnuJw1/++DJ6a/a0rHyBQzEAk3YkNqKu2w+j2QgFFYJ9 HHKqsBPWo47OPwopkR3eFwxd3cJFBGefrzmjGcuC3uUocd21NqIgpWdR+Lyic0XgEe+1 BCQYCpzYpNYqbgeJsHDveL3Hu8vi5QPn3gJi324+QQMxtz45tALf93ptBTOm+b4O6wXT 5vRCq06VDDjKmy3J0oFiHuJ8rToOHLJuL/iihqj4Mwra+kwDR+Yz9/0LebsxQ2g60Pjr /L8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=g70WoWvYGEB64ezQmlbjTuqG3rHgUdUwqryne4k2aWI=; b=hsx3/BlS2ZgXcMZEaDgK2afayRvzFvzBZVcCOL9FPFKel+FSK9bT0HrTlKDcVWUUFp nsTJOtlugyj9doEXU0Yp8//JPwTKP8qvWQA24/MLIr9oKOaf3T+VnFzpWknLj8tqjGtU j9FuWitbSLgMPEkLpC89RZe9mnjq5QBj8WWCfD2yE8XLymbpr1pmNn8Q9hy4djfPCxrz b/mTiAIxaCC6Ry4db7yGhN+03BxOSct2anlMrmYbefq5APJM7VYnBz8pD7hWm8GR8fnM 3zJSwzQEJBYgnMDMFa/cu7e5Spmk6z3Bo025U3KQV9WWw4EFWUzhLCHH/yrqyPrp3PG/ BMMQ== X-Gm-Message-State: AD7BkJKgs/IwEaW8lD6AsYpJFfDN0AxWE8bb0sT8sLgmx8K93reHRXwg9+bmE4s+Ne2PGA== X-Received: by 10.98.80.206 with SMTP id g75mr34291444pfj.127.1458001854789; Mon, 14 Mar 2016 17:30:54 -0700 (PDT) Received: from dl.caveonetworks.com ([64.2.3.194]) by smtp.gmail.com with ESMTPSA id d28sm34733966pfj.68.2016.03.14.17.30.48 (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 14 Mar 2016 17:30:51 -0700 (PDT) Received: from dl.caveonetworks.com (localhost.localdomain [127.0.0.1]) by dl.caveonetworks.com (8.14.5/8.14.5) with ESMTP id u2F0Ull3016043; Mon, 14 Mar 2016 17:30:47 -0700 Received: (from ddaney@localhost) by dl.caveonetworks.com (8.14.5/8.14.5/Submit) id u2F0UljO016042; Mon, 14 Mar 2016 17:30:47 -0700 From: David Daney To: "David S. Miller" , netdev@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Florian Fainelli , Robert Richter , Sunil Goutham Subject: [PATCH 3/3] net: thunderx: Don't leak phy device references on -EPROBE_DEFER condition. Date: Mon, 14 Mar 2016 17:30:39 -0700 Message-Id: <1458001839-15993-4-git-send-email-ddaney.cavm@gmail.com> X-Mailer: git-send-email 1.7.11.7 In-Reply-To: <1458001839-15993-1-git-send-email-ddaney.cavm@gmail.com> References: <1458001839-15993-1-git-send-email-ddaney.cavm@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160314_173112_449891_9ECAEBFE X-CRM114-Status: GOOD ( 16.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: Radha Mohan Chintakuntla , linux-kernel@vger.kernel.org, David Daney MIME-Version: 1.0 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.1 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 From: David Daney It is possible, although unlikely, that probing will find the phy_device for the first LMAC of a thunder BGX device, but then need to fail with -EPROBE_DEFER on a subsequent LMAC. In this case, we need to call put_device() on each of the phy_devices that were obtained, but will be unused due to returning -EPROBE_DEFER. Also, since we can break out of the probing loop early, we need to explicitly call of_node_put() outside of the loop. Signed-off-by: David Daney --- drivers/net/ethernet/cavium/thunder/thunder_bgx.c | 26 +++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/drivers/net/ethernet/cavium/thunder/thunder_bgx.c b/drivers/net/ethernet/cavium/thunder/thunder_bgx.c index feed231..9679515 100644 --- a/drivers/net/ethernet/cavium/thunder/thunder_bgx.c +++ b/drivers/net/ethernet/cavium/thunder/thunder_bgx.c @@ -974,17 +974,18 @@ static int bgx_init_acpi_phy(struct bgx *bgx) static int bgx_init_of_phy(struct bgx *bgx) { struct fwnode_handle *fwn; + struct device_node *node = NULL; u8 lmac = 0; - const char *mac; device_for_each_child_node(&bgx->pdev->dev, fwn) { struct phy_device *pd; struct device_node *phy_np; - struct device_node *node = to_of_node(fwn); + const char *mac; /* Should always be an OF node. But if it is not, we * cannot handle it, so exit the loop. */ + node = to_of_node(fwn); if (!node) break; @@ -1005,17 +1006,30 @@ static int bgx_init_of_phy(struct bgx *bgx) /* Wait until the phy drivers are available */ pd = of_phy_find_device(phy_np); if (!pd) - return -EPROBE_DEFER; + goto defer; bgx->lmac[lmac].phydev = pd; } lmac++; - if (lmac == MAX_LMAC_PER_BGX) { - of_node_put(node); + if (lmac == MAX_LMAC_PER_BGX) break; - } } + of_node_put(node); return 0; + +defer: + /* We are bailing out, try not to leak device reference counts + * for phy devices we may have already found. + */ + while (lmac) { + if (bgx->lmac[lmac].phydev) { + put_device(&bgx->lmac[lmac].phydev->mdio.dev); + bgx->lmac[lmac].phydev = NULL; + } + lmac--; + } + of_node_put(node); + return -EPROBE_DEFER; } #else