git: e65e4e61f530 - main - vmd: Clean up resources properly when vmd_attach() fails
Mark Johnston
markj at FreeBSD.org
Fri Jan 8 18:32:31 UTC 2021
The branch main has been updated by markj:
URL: https://cgit.FreeBSD.org/src/commit/?id=e65e4e61f5302ddbba3b2a8c2186548072ba49ad
commit e65e4e61f5302ddbba3b2a8c2186548072ba49ad
Author: Mark Johnston <markj at FreeBSD.org>
AuthorDate: 2021-01-08 18:32:05 +0000
Commit: Mark Johnston <markj at FreeBSD.org>
CommitDate: 2021-01-08 18:32:05 +0000
vmd: Clean up resources properly when vmd_attach() fails
- Free the resource container by calling rman_fini().[1]
- Call device_delete_child() if device_probe_and_attach() fails.
Reported by: nc [1]
MFC after: 2 weeks
---
sys/dev/vmd/vmd.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/sys/dev/vmd/vmd.c b/sys/dev/vmd/vmd.c
index 2cc6f45bed9e..616fd4c8373e 100644
--- a/sys/dev/vmd/vmd.c
+++ b/sys/dev/vmd/vmd.c
@@ -101,6 +101,9 @@ vmd_free(struct vmd_softc *sc)
int i;
struct vmd_irq_handler *elm, *tmp;
+ if (sc->vmd_bus.rman.rm_end != 0)
+ rman_fini(&sc->vmd_bus.rman);
+
#ifdef TASK_QUEUE_INTR
if (sc->vmd_irq_tq != NULL) {
taskqueue_drain(sc->vmd_irq_tq, &sc->vmd_irq_task);
@@ -334,10 +337,10 @@ vmd_attach(device_t dev)
snprintf(buf, sizeof(buf), "%s bus numbers", device_get_nameunit(dev));
bus->rman.rm_descr = strdup(buf, M_DEVBUF);
error = rman_init(&bus->rman);
-
if (error) {
device_printf(dev, "Failed to initialize %s bus number rman\n",
device_get_nameunit(dev));
+ bus->rman.rm_end = 0;
goto fail;
}
@@ -410,7 +413,6 @@ vmd_attach(device_t dev)
}
sc->vmd_child = device_add_child(dev, NULL, -1);
-
if (sc->vmd_child == NULL) {
device_printf(dev, "Failed to attach child\n");
goto fail;
@@ -418,7 +420,8 @@ vmd_attach(device_t dev)
error = device_probe_and_attach(sc->vmd_child);
if (error) {
- device_printf(dev, "Failed to add probe child\n");
+ device_printf(dev, "Failed to add probe child: %d\n", error);
+ (void)device_delete_child(dev, sc->vmd_child);
goto fail;
}
@@ -444,9 +447,6 @@ vmd_detach(device_t dev)
if (err)
return (err);
}
- if (sc->vmd_bus.rman.rm_end != 0)
- rman_fini(&sc->vmd_bus.rman);
-
vmd_free(sc);
return (0);
}
More information about the dev-commits-src-main
mailing list