From patchwork Mon Sep 9 09:29:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jinjie Ruan X-Patchwork-Id: 13796517 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A30FAECE57B for ; Mon, 9 Sep 2024 09:22:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type: Content-Transfer-Encoding:MIME-Version:Message-ID:Date:Subject:CC:To:From: Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender :Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=GIf8YPbBmx/jTHRF2c3lN8Gb/4QakoP6wkJ8GiJyoJM=; b=y60KWlVntlaOhFi9qdom6gdAw1 sP4E46JAXoctO9lXXH4T1yHJ8SxtZFYcwPLwg2GPWPfjpYzhH1K6CZL4jTlVbn6UljVZRosmyxiuZ bBkOaR5GVcaLlIRhgnUGN6HTyd54VcIFaKr8dME99lmKKjYuvTuPwN12V6dFH/E9dAHA5RAhdeUEu y8uLVIXkhyfKDJspIphIVOMYn2tQpiaJsaXbAawbJj4QcfqAv109O+x5Z4JsrmNdjAYA5SPhPzv5O NFrhwQ7dCAIW8C6NPOHCN9CGbx2INRrYttr1tEARQS5cZhVx0Iw+Bg9/VyO1XzHSCcWKFGbMylJiA AwHk5gPw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1snab0-00000001Hja-3qaX; Mon, 09 Sep 2024 09:22:06 +0000 Received: from szxga08-in.huawei.com ([45.249.212.255]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1snaZy-00000001HSI-26UG for linux-arm-kernel@lists.infradead.org; Mon, 09 Sep 2024 09:21:04 +0000 Received: from mail.maildlp.com (unknown [172.19.88.105]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4X2Lrj1vLYz1BNDl; Mon, 9 Sep 2024 17:19:49 +0800 (CST) Received: from kwepemh500013.china.huawei.com (unknown [7.202.181.146]) by mail.maildlp.com (Postfix) with ESMTPS id 283391402CF; Mon, 9 Sep 2024 17:20:53 +0800 (CST) Received: from huawei.com (10.90.53.73) by kwepemh500013.china.huawei.com (7.202.181.146) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Mon, 9 Sep 2024 17:20:52 +0800 From: Jinjie Ruan To: , , , , , , , , , CC: Subject: [PATCH] net: ethernet: nxp: Fix a possible memory leak in lpc_mii_probe() Date: Mon, 9 Sep 2024 17:29:48 +0800 Message-ID: <20240909092948.1118381-1-ruanjinjie@huawei.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Originating-IP: [10.90.53.73] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To kwepemh500013.china.huawei.com (7.202.181.146) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240909_022102_811155_2F6D80B1 X-CRM114-Status: GOOD ( 10.01 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org of_phy_find_device() calls bus_find_device(), which calls get_device() on the returned struct device * to increment the refcount. The current implementation does not decrement the refcount, which causes memory leak. So add the missing phy_device_free() call to decrement the refcount via put_device() to balance the refcount. Fixes: 3503bf024b3e ("net: lpc_eth: parse phy nodes from device tree") Signed-off-by: Jinjie Ruan --- drivers/net/ethernet/nxp/lpc_eth.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/net/ethernet/nxp/lpc_eth.c b/drivers/net/ethernet/nxp/lpc_eth.c index dd3e58a1319c..8bff394991e4 100644 --- a/drivers/net/ethernet/nxp/lpc_eth.c +++ b/drivers/net/ethernet/nxp/lpc_eth.c @@ -768,6 +768,9 @@ static int lpc_mii_probe(struct net_device *ndev) return -ENODEV; } + if (pldat->phy_node) + phy_device_free(phydev); + phydev = phy_connect(ndev, phydev_name(phydev), &lpc_handle_link_change, lpc_phy_interface_mode(&pldat->pdev->dev));