From patchwork Tue Jan 31 10:02:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= X-Patchwork-Id: 13122759 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 37194C636CC for ; Tue, 31 Jan 2023 10:00:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232064AbjAaKA4 (ORCPT ); Tue, 31 Jan 2023 05:00:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59720 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232182AbjAaKAx (ORCPT ); Tue, 31 Jan 2023 05:00:53 -0500 Received: from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net [217.70.183.197]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E14E44ABF6; Tue, 31 Jan 2023 02:00:46 -0800 (PST) Received: (Authenticated sender: clement.leger@bootlin.com) by mail.gandi.net (Postfix) with ESMTPSA id 79BB91C0003; Tue, 31 Jan 2023 10:00:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1675159245; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=aZg/iDWxJ7+7iB6HjrlykOAfUIjKx7WrcYo/FUoXaHA=; b=kq3aI+oYfe/kfZ5btHKDVbJE8LcUPQVmUQr8mSsYlYnPBMu1JIq3A+LtMZ/Icjwuo9ZjrM pUOnT1hCZRlbgHaDwlEWufBdbUY0zE6uWyEYw1Vz6sdnVu5jUoGoxZkAPWqITFC9uJOAIV PGDGJJb96HC4iRczrw006pzPrwruLE1BdAA7BJM/nUPq6Asr+5WdvrM/OQwzpZ85BDzvjn gAZnCWxvoL3AM24GIGkfc+BAY8kdDYq87SjjbO4h1htl21GAuZVBNCcCQIC8GjnCx+RakN LU2NCRsgP4FNpNTAjhZ7PIBTEg/V2Xy76Q73R0uJiQdmHVsaR+zw99xrMOpkSg== From: =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= To: Russell King , Andrew Lunn , Heiner Kallweit , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Grant Likely , Calvin Johnson , Ioana Ciornei Cc: =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net] net: phylink: move phy_device_free() to correctly release phy device Date: Tue, 31 Jan 2023 11:02:42 +0100 Message-Id: <20230131100242.33514-1-clement.leger@bootlin.com> X-Mailer: git-send-email 2.39.0 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org After calling fwnode_phy_find_device(), the phy device refcount is incremented. Then, when the phy device is attached to a netdev with phy_attach_direct(), the refcount is also incremented but only decremented in the caller if phy_attach_direct() fails. Move phy_device_free() before the "if" to always release it correctly. Indeed, either phy_attach_direct() failed and we don't want to keep a reference to the phydev or it succeeded and a reference has been taken internally. Fixes: 25396f680dd6 ("net: phylink: introduce phylink_fwnode_phy_connect()") Signed-off-by: Clément Léger --- drivers/net/phy/phylink.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/drivers/net/phy/phylink.c b/drivers/net/phy/phylink.c index 09cc65c0da93..4d2519cdb801 100644 --- a/drivers/net/phy/phylink.c +++ b/drivers/net/phy/phylink.c @@ -1812,10 +1812,9 @@ int phylink_fwnode_phy_connect(struct phylink *pl, ret = phy_attach_direct(pl->netdev, phy_dev, flags, pl->link_interface); - if (ret) { - phy_device_free(phy_dev); + phy_device_free(phy_dev); + if (ret) return ret; - } ret = phylink_bringup_phy(pl, phy_dev, pl->link_config.interface); if (ret)