[PATCH 22/25] net: dsa: felix: check return code of mdio_alloc and mdio_register
Ramon Fried
rfried.dev at gmail.com
Tue Sep 28 15:33:51 CEST 2021
On Mon, Sep 27, 2021 at 2:22 PM Vladimir Oltean <vladimir.oltean at nxp.com> wrote:
>
> These functions can return errors, it's best to catch them and trigger
> the driver unwind code path.
>
> Signed-off-by: Vladimir Oltean <vladimir.oltean at nxp.com>
> ---
> drivers/net/mscc_eswitch/felix_switch.c | 10 +++++++++-
> 1 file changed, 9 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/net/mscc_eswitch/felix_switch.c b/drivers/net/mscc_eswitch/felix_switch.c
> index 4c2e57755967..98ae39e81d65 100644
> --- a/drivers/net/mscc_eswitch/felix_switch.c
> +++ b/drivers/net/mscc_eswitch/felix_switch.c
> @@ -276,6 +276,7 @@ static void felix_init(struct udevice *dev)
> static int felix_probe(struct udevice *dev)
> {
> struct felix_priv *priv = dev_get_priv(dev);
> + int err;
>
> if (ofnode_valid(dev_ofnode(dev)) &&
> !ofnode_is_available(dev_ofnode(dev))) {
> @@ -300,11 +301,18 @@ static int felix_probe(struct udevice *dev)
> struct mii_dev *mii_bus;
>
> mii_bus = mdio_alloc();
> + if (!mii_bus)
> + return -ENOMEM;
> +
> mii_bus->read = felix_mdio_read;
> mii_bus->write = felix_mdio_write;
> mii_bus->priv = priv->imdio_base + FELIX_PM_IMDIO_BASE;
> strlcpy(mii_bus->name, dev->name, MDIO_NAME_LEN);
> - mdio_register(mii_bus);
> + err = mdio_register(mii_bus);
> + if (err) {
> + mdio_free(mii_bus);
> + return err;
> + }
> }
>
> dm_pci_clrset_config16(dev, PCI_COMMAND, 0, PCI_COMMAND_MEMORY);
> --
> 2.25.1
>
Reviewed-by: Ramon Fried <rfried.dev at gmail.com>
More information about the U-Boot
mailing list