Re: [PATCH 5.4 01/32] net: dsa: bcm_sf2: put device node before return

From: Pavel Machek
Date: Sun Feb 07 2021 - 04:26:35 EST


Hi!

> From: Pan Bian <bianpan2016@xxxxxxx>
>
> commit cf3c46631e1637582f517a574c77cd6c05793817 upstream.
>
> Put the device node dn before return error code on failure path.

This fixes one resource leak, but exposes next one: get_device() is
not undone in the second error path and in the end of function.

Best regards,
Pavel

> +++ b/drivers/net/dsa/bcm_sf2.c
> @@ -421,15 +421,19 @@ static int bcm_sf2_mdio_register(struct
> /* Find our integrated MDIO bus node */
> dn = of_find_compatible_node(NULL, NULL, "brcm,unimac-mdio");
> priv->master_mii_bus = of_mdio_find_bus(dn);
> - if (!priv->master_mii_bus)
> + if (!priv->master_mii_bus) {
> + of_node_put(dn);
> return -EPROBE_DEFER;
> + }
>
> get_device(&priv->master_mii_bus->dev);
> priv->master_mii_dn = dn;
>
> priv->slave_mii_bus = devm_mdiobus_alloc(ds->dev);
> - if (!priv->slave_mii_bus)
> + if (!priv->slave_mii_bus) {
> + of_node_put(dn);
> return -ENOMEM;
> + }
>
> priv->slave_mii_bus->priv = priv;
> priv->slave_mii_bus->name = "sf2 slave mii";
>

--
http://www.livejournal.com/~pavelmachek

Attachment: signature.asc
Description: Digital signature