Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/dev/pci virtio@pci: Fix assertion on detach.



details:   https://anonhg.NetBSD.org/src/rev/085f7403cde5
branches:  trunk
changeset: 374277:085f7403cde5
user:      riastradh <riastradh%NetBSD.org@localhost>
date:      Sun Apr 16 17:57:08 2023 +0000

description:
virtio@pci: Fix assertion on detach.

If the child never attached in the first place, it's OK for it to not
have detached.

XXX This should not be a set of flags; this should be a state
enumeration, because some flags make no sense, like FINISHED|FAILED.

XXX This should not be asserted separately in each bus; there should
be a single place in virtio.c to assert this, uniformly in all buses.

PR kern/57357

XXX pullup-10

diffstat:

 sys/dev/pci/virtio_pci.c |  11 +++++++----
 1 files changed, 7 insertions(+), 4 deletions(-)

diffs (32 lines):

diff -r bb5f302272df -r 085f7403cde5 sys/dev/pci/virtio_pci.c
--- a/sys/dev/pci/virtio_pci.c  Sun Apr 16 17:16:45 2023 +0000
+++ b/sys/dev/pci/virtio_pci.c  Sun Apr 16 17:57:08 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: virtio_pci.c,v 1.40 2023/03/31 07:34:26 yamaguchi Exp $ */
+/* $NetBSD: virtio_pci.c,v 1.41 2023/04/16 17:57:08 riastradh Exp $ */
 
 /*
  * Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -28,7 +28,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: virtio_pci.c,v 1.40 2023/03/31 07:34:26 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: virtio_pci.c,v 1.41 2023/04/16 17:57:08 riastradh Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -333,8 +333,11 @@ virtio_pci_detach(device_t self, int fla
        if (r != 0)
                return r;
 
-       /* Check that child detached properly */
-       KASSERT(ISSET(sc->sc_child_flags, VIRTIO_CHILD_DETACHED));
+       /* Check that child never attached, or detached properly */
+       KASSERTMSG(!ISSET(sc->sc_child_flags,
+               (VIRTIO_CHILD_ATTACH_FINISHED|VIRTIO_CHILD_ATTACH_FAILED)) ||
+           ISSET(sc->sc_child_flags, VIRTIO_CHILD_DETACHED),
+           "%s: child flags %x", device_xname(self), sc->sc_child_flags);
        KASSERT(sc->sc_vqs == NULL);
        KASSERT(psc->sc_ihs_num == 0);
 



Home | Main Index | Thread Index | Old Index