virtio_random: avoid using vtrnd_detach in the failure path

On the off chance that we discover more than one virtio-random device,
the second one will deregister the global instance or trip an invariant
when it fails to attach and calls vtrnd_detach().

We don't have that many resources to free, so just inline those.  This
is purely a hygiene thing, we haven't seen an instance of this in the
wild (to my knowledge).

Reviewed by:	bnovkov, kfv
Sponsored by:	Stormshield
Sponsored by:	Klara, Inc.
Differential Revision:	https://reviews.freebsd.org/D61050
This commit is contained in:
Kyle Evans committed 2026-11-04 15:33:33 -06:00
1 parent db8444c1b7
commit 26ba71f73e
1 file changed
+9 -2
+9 -2
View File
@@ -184,8 +184,15 @@ vtrnd_attach(device_t dev)
vtrnd_enqueue(sc);
fail:
if (error)
vtrnd_detach(dev);
if (error != 0) {
/* Parent will free the virtqueue. */
if (g_vtrnd_softc == sc) {
atomic_store_explicit(&g_vtrnd_softc, NULL,
memory_order_release);
}
sglist_free(sc->vtrnd_sg);
zfree(sc->vtrnd_value, M_DEVBUF);
}
return (error);
}