git: b6c0d81f7db2 - stable/13 - cxgbe(4): Fix panic on driver detach after a partially failed attach.

From: Navdeep Parhar <np_at_FreeBSD.org>
Date: Mon, 28 Feb 2022 06:55:44 UTC
The branch stable/13 has been updated by np:

URL: https://cgit.FreeBSD.org/src/commit/?id=b6c0d81f7db21e5b5a08b006afcd2ff9645595c0

commit b6c0d81f7db21e5b5a08b006afcd2ff9645595c0
Author:     Navdeep Parhar <np@FreeBSD.org>
AuthorDate: 2021-12-29 00:46:09 +0000
Commit:     Navdeep Parhar <np@FreeBSD.org>
CommitDate: 2022-02-28 06:47:19 +0000

    cxgbe(4): Fix panic on driver detach after a partially failed attach.
    
    sge->ctrlq is not always allocated during attach (eg. if firmware
    initialization fails) and detach should be able to deal with this.
    
    Sponsored by:   Chelsio Communications
    
    (cherry picked from commit b99651c52fa52cdef5688859e0bc7f3fb2085a2f)
---
 sys/dev/cxgbe/t4_sge.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/sys/dev/cxgbe/t4_sge.c b/sys/dev/cxgbe/t4_sge.c
index bddacb448ff5..cbfaa7a6db60 100644
--- a/sys/dev/cxgbe/t4_sge.c
+++ b/sys/dev/cxgbe/t4_sge.c
@@ -1077,7 +1077,8 @@ t4_teardown_adapter_queues(struct adapter *sc)
 
 	ADAPTER_LOCK_ASSERT_NOTOWNED(sc);
 
-	if (!(sc->flags & IS_VF)) {
+	if (sc->sge.ctrlq != NULL) {
+		MPASS(!(sc->flags & IS_VF));	/* VFs don't allocate ctrlq. */
 		for_each_port(sc, i)
 			free_ctrlq(sc, i);
 	}