Skip to content
Snippets Groups Projects
Commit 72ebfe86 authored by Simon Glass's avatar Simon Glass
Browse files

dm: core: Tidy up error handling in device_bind()


Make the error handling more standard to make it easier to build on top of
it. Also correct a bug in the error path where there is no parent.

Signed-off-by: default avatarSimon Glass <sjg@chromium.org>
Reviewed-by: default avatarMasahiro Yamada <yamada.m@jp.panasonic.com>
parent 2f3b95db
No related branches found
No related tags found
No related merge requests found
...@@ -81,18 +81,13 @@ int device_bind(struct udevice *parent, struct driver *drv, const char *name, ...@@ -81,18 +81,13 @@ int device_bind(struct udevice *parent, struct driver *drv, const char *name,
ret = uclass_bind_device(dev); ret = uclass_bind_device(dev);
if (ret) if (ret)
goto fail_bind; goto fail_uclass_bind;
/* if we fail to bind we remove device from successors and free it */ /* if we fail to bind we remove device from successors and free it */
if (drv->bind) { if (drv->bind) {
ret = drv->bind(dev); ret = drv->bind(dev);
if (ret) { if (ret)
if (uclass_unbind_device(dev)) {
dm_warn("Failed to unbind dev '%s' on error path\n",
dev->name);
}
goto fail_bind; goto fail_bind;
}
} }
if (parent) if (parent)
dm_dbg("Bound device %s to %s\n", dev->name, parent->name); dm_dbg("Bound device %s to %s\n", dev->name, parent->name);
...@@ -101,8 +96,15 @@ int device_bind(struct udevice *parent, struct driver *drv, const char *name, ...@@ -101,8 +96,15 @@ int device_bind(struct udevice *parent, struct driver *drv, const char *name,
return 0; return 0;
fail_bind: fail_bind:
list_del(&dev->sibling_node); if (uclass_unbind_device(dev)) {
dm_warn("Failed to unbind dev '%s' on error path\n",
dev->name);
}
fail_uclass_bind:
if (parent)
list_del(&dev->sibling_node);
free(dev); free(dev);
return ret; return ret;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment