From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0E82A18732C; Mon, 12 Aug 2024 16:24:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723479885; cv=none; b=oXDr6NukOnxhQSVqi/+RqSUGfu9Tv2Ng3fTa48APqvS18aNWE0oiRpe9Bo2ltwv8qd2bMlHl3NXxRvUzsXdS79SrW2w4hcsRucxmiCJiOV/Emx5ihpH8RebxL839fF5Z9gji8aZyDfXS7gGYUqxiFbXXnaksjUT+fEIeWol94VQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723479885; c=relaxed/simple; bh=QJ8XsaqjKyJKQ/btndW80HrWgUPBW4npWqyactEG3bc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=N/YQU72PmM/NFkeKbdrNDt4CTcZZ8OSgNHIHTyMmuv36hPhGDUTZ+IWSF/rNBZLba8qixu9BSVJmnPaTT1wIT28f8cgNJyXf/W+FwOQBdeY68pT8T4IzpHMQEU9HTSjPTQhZ8cZy5jMIHB+vRhjleC+piJwNQEsG5ve4zeoHqaM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=MhW6t3xR; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="MhW6t3xR" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 51A8EC32782; Mon, 12 Aug 2024 16:24:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1723479884; bh=QJ8XsaqjKyJKQ/btndW80HrWgUPBW4npWqyactEG3bc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MhW6t3xR/ni78/R2VriIKqoyOvKbo+IvSXp4I7wdvc0S8tuniEYuNAQgWkjwz6Gen XILrmJI7mZvEDucinbGF13zlT3fW7ia2H5Yu3Nr4FRopaMLBaVX7hUHL4gyAFjS9sX AHma/2xhmDR0v3aeB7SQ/UApjE+/TwkL2QVIRlpM= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Joe Hattori , Florian Fainelli , Jakub Kicinski , Sasha Levin Subject: [PATCH 6.10 031/263] net: dsa: bcm_sf2: Fix a possible memory leak in bcm_sf2_mdio_register() Date: Mon, 12 Aug 2024 18:00:32 +0200 Message-ID: <20240812160147.733578835@linuxfoundation.org> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240812160146.517184156@linuxfoundation.org> References: <20240812160146.517184156@linuxfoundation.org> User-Agent: quilt/0.67 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.10-stable review patch. If anyone has any objections, please let me know. ------------------ From: Joe Hattori [ Upstream commit e3862093ee93fcfbdadcb7957f5f8974fffa806a ] bcm_sf2_mdio_register() calls of_phy_find_device() and then phy_device_remove() in a loop to remove existing PHY devices. of_phy_find_device() eventually 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. This commit adds the missing phy_device_free() call to decrement the refcount via put_device() to balance the refcount. Fixes: 771089c2a485 ("net: dsa: bcm_sf2: Ensure that MDIO diversion is used") Signed-off-by: Joe Hattori Tested-by: Florian Fainelli Reviewed-by: Florian Fainelli Link: https://patch.msgid.link/20240806011327.3817861-1-joe@pf.is.s.u-tokyo.ac.jp Signed-off-by: Jakub Kicinski Signed-off-by: Sasha Levin --- drivers/net/dsa/bcm_sf2.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/net/dsa/bcm_sf2.c b/drivers/net/dsa/bcm_sf2.c index ed1e6560df25e..0e663ec0c12a3 100644 --- a/drivers/net/dsa/bcm_sf2.c +++ b/drivers/net/dsa/bcm_sf2.c @@ -675,8 +675,10 @@ static int bcm_sf2_mdio_register(struct dsa_switch *ds) of_remove_property(child, prop); phydev = of_phy_find_device(child); - if (phydev) + if (phydev) { phy_device_remove(phydev); + phy_device_free(phydev); + } } err = mdiobus_register(priv->user_mii_bus); -- 2.43.0