[PATCH] net: ethernet: mediatek: fix refcount leak in mtk_probe()
Simon Horman
horms at kernel.org
Thu Jun 11 09:11:02 PDT 2026
On Tue, Jun 09, 2026 at 08:13:00AM +0000, Wentao Liang wrote:
> If mtk_sgmii_init() fails after successfully creating some PCS
> instances, it returns an error without cleaning up the partially
> created ones. mtk_pcs_lynxi_create() increments the fwnode
> refcount for each PCS it creates, but this refcount is never
> released because mtk_probe() uses a plain "return err" instead of
> a goto to the err_destroy_sgmii label. This leaks both the PCS
> devices and their fwnode references.
>
> Fix the leak by jumping to the existing err_destroy_sgmii path
> which calls mtk_sgmii_destroy() to safely release all allocated
> resources.
>
> Cc: stable at vger.kernel.org
> Fixes: 9ffee4a8276c ("net: ethernet: mediatek: Extend SGMII related functions")
> Signed-off-by: Wentao Liang <vulab at iscas.ac.cn>
I think that a better approach would be, on error, for mtk_sgmii_init()
to release any resources it has allocated before returning.
Also, I'm not convinced this is stable material
as I'm not sure it's bothering anyone.
...
More information about the linux-arm-kernel
mailing list