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: 50768 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2667456wrn; Tue, 31 Jan 2023 02:16:38 -0800 (PST) X-Google-Smtp-Source: AK7set+2xiKe2P/qLtjCUT/ZeV1deReKCYavjER57cWMsZ5mBzdQxkXanZ64e1w29gjYZPne5H3w X-Received: by 2002:a17:907:7f28:b0:887:6c23:193d with SMTP id qf40-20020a1709077f2800b008876c23193dmr9454921ejc.7.1675160198007; Tue, 31 Jan 2023 02:16:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675160197; cv=none; d=google.com; s=arc-20160816; b=DC/ZjMry4hPJ5PEFG5u2Ap4VcMXkIYIar09wQQmDWK5/jN6FjJ9RGBHtgENpIUhX/s RVYWKl8FkJqsNMxgR6MduzOx5PNpgn74U+Szk8whAZWzOBV3S0T52j249QwDpr8hTPcX EOm6QF/ivV9tjchziHAQlkhOJ0LKD9NErzOCpEGCOWGyN18KwYyv1GdgJgYR8S7JXQ7N lGjOFnU72LadrcWvdxtbgPUX0UvUjUGhimwPW5bcl/c6q8SNTJmASn4o2IKI8WuByRYN Vk7JJnOiUOXkmSYDDpH+ejVBwpj4T9UdtaB8jmd3/7QXBXYwWTJLi50qDFVwaSBxbuud qTzg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=aZg/iDWxJ7+7iB6HjrlykOAfUIjKx7WrcYo/FUoXaHA=; b=FUvD44Ry1b+1IzdUDVGdk2Vxi3ogPavyRQz5ZUJ8VeIRAK7vNzPSNLeyVuaYI3f5S7 Vs5hLG5ojdZb4Q3Gj2LHRF3E80zA527znqLl4CTlJp1IGCv6v3v+F7pN65tP47ljJQJU PrMfJUeMG0QPOcLVbHIlOOanfiqoERXnE2RnQARjPvxkO2QiVUjjyRS2zCvgBCSAd0kh agt8nA1FIsdSAHZQtCTHuDee099Oh7gGzxqDMN9BfpSUyVUGSehDHmibrMuykYgWIA7j B4iuqyJ8vtT+hCIb+UMRPgobO0JT3vTXP08eud99VDjDnVy3m8ht9EUscPQroKJoGr+h HILg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=kq3aI+oY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id fm19-20020a1709072ad300b008708a80a16dsi17066965ejc.235.2023.01.31.02.16.14; Tue, 31 Jan 2023 02:16:37 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=kq3aI+oY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230511AbjAaKA5 (ORCPT + 99 others); Tue, 31 Jan 2023 05:00:57 -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 X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1756532779498014822?= X-GMAIL-MSGID: =?utf-8?q?1756532779498014822?= 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)