git: 183633079178 - main - thunderbolt: make code -Wunused clean

From: Enji Cooper <ngie_at_FreeBSD.org>
Date: Sat, 16 May 2026 01:00:53 UTC
The branch main has been updated by ngie:

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

commit 1836330791789f18d0c9f0a63322a7f33b373c5b
Author:     Enji Cooper <ngie@FreeBSD.org>
AuthorDate: 2026-02-26 08:06:49 +0000
Commit:     Enji Cooper <ngie@FreeBSD.org>
CommitDate: 2026-05-16 01:00:36 +0000

    thunderbolt: make code -Wunused clean
    
    This change modifies code paths and uses `__diagused` to address `-Wunused`
    issues that occur when `THUNDERBOLT_DEBUG` == `0`.
    
    MFC after:      1 month
    Differential Revision:  https://reviews.freebsd.org/D55575
---
 sys/dev/thunderbolt/nhi.c          | 18 +++++++++++-------
 sys/dev/thunderbolt/router.c       | 11 +++++++----
 sys/dev/thunderbolt/tb_acpi_pcib.c |  2 +-
 sys/dev/thunderbolt/tb_debug.c     |  6 +++---
 sys/dev/thunderbolt/tb_debug.h     |  2 +-
 sys/dev/thunderbolt/tb_pcib.c      |  2 +-
 6 files changed, 24 insertions(+), 17 deletions(-)

diff --git a/sys/dev/thunderbolt/nhi.c b/sys/dev/thunderbolt/nhi.c
index 9550de258dab..6cbe79779c13 100644
--- a/sys/dev/thunderbolt/nhi.c
+++ b/sys/dev/thunderbolt/nhi.c
@@ -788,8 +788,11 @@ nhi_tx_schedule(struct nhi_ring_pair *r, struct nhi_cmd_frame *cmd)
 int
 nhi_tx_synchronous(struct nhi_ring_pair *r, struct nhi_cmd_frame *cmd)
 {
+	struct nhi_softc *sc __diagused;
 	int error, count;
 
+	sc = r->sc;
+
 	if ((error = nhi_tx_schedule(r, cmd)) != 0)
 		return (error);
 
@@ -812,16 +815,16 @@ nhi_tx_synchronous(struct nhi_ring_pair *r, struct nhi_cmd_frame *cmd)
 	if ((cmd->flags & CMD_REQ_COMPLETE) == 0)
 		error = ETIMEDOUT;
 
-	tb_debug(r->sc, DBG_TXQ|DBG_FULL, "tx_synchronous done waiting, "
+	tb_debug(sc, DBG_TXQ|DBG_FULL, "tx_synchronous done waiting, "
 	    "err= %d, TX_COMPLETE= %d\n", error,
 	    !!(cmd->flags & CMD_REQ_COMPLETE));
 
 	if (error == ERESTART) {
-		tb_printf(r->sc, "TX command interrupted\n");
+		tb_printf(sc, "TX command interrupted\n");
 	} else if ((error == EWOULDBLOCK) || (error == ETIMEDOUT)) {
-		tb_printf(r->sc, "TX command timed out\n");
+		tb_printf(sc, "TX command timed out\n");
 	} else if (error != 0) {
-		tb_printf(r->sc, "TX command failed error= %d\n", error);
+		tb_printf(sc, "TX command failed error= %d\n", error);
 	}
 
 	return (error);
@@ -831,7 +834,7 @@ static int
 nhi_tx_complete(struct nhi_ring_pair *r, struct nhi_tx_buffer_desc *desc,
     struct nhi_cmd_frame *cmd)
 {
-	struct nhi_softc *sc;
+	struct nhi_softc *sc __diagused;
 	struct nhi_pdf_dispatch *txpdf;
 	u_int sof;
 
@@ -865,9 +868,10 @@ static int
 nhi_rx_complete(struct nhi_ring_pair *r, struct nhi_rx_post_desc *desc,
     struct nhi_cmd_frame *cmd)
 {
-	struct nhi_softc *sc;
+	struct nhi_softc *sc __diagused;
 	struct nhi_pdf_dispatch *rxpdf;
-	u_int eof, len;
+	u_int eof;
+	u_int len __diagused;
 
 	sc = r->sc;
 	eof = desc->eof_len >> RX_BUFFER_DESC_EOF_SHIFT;
diff --git a/sys/dev/thunderbolt/router.c b/sys/dev/thunderbolt/router.c
index a3b418d77fac..fe7ad7026b2e 100644
--- a/sys/dev/thunderbolt/router.c
+++ b/sys/dev/thunderbolt/router.c
@@ -277,7 +277,8 @@ _tb_router_attach(struct router_softc *sc)
 {
 	struct tb_cfg_router *cfg;
 	uint32_t *buf;
-	int error, up;
+	int error;
+	int up __diagused;
 
 	buf = malloc(9 * 4, M_THUNDERBOLT, M_NOWAIT|M_ZERO);
 	if (buf == NULL)
@@ -297,8 +298,9 @@ _tb_router_attach(struct router_softc *sc)
 	sc->uuid[1] = cfg->uuid_hi;
 	sc->uuid[2] = 0xffffffff;
 	sc->uuid[3] = 0xffffffff;
-	tb_debug(sc, DBG_ROUTER, "Router upstream_port= %d, max_port= %d, "
-	    "depth= %d\n", up, sc->max_adap, sc->depth);
+	tb_debug(sc, DBG_ROUTER,
+	    "Router upstream_port= %d, max_port= %d, depth= %d\n",
+	    up, sc->max_adap, sc->depth);
 	free(buf, M_THUNDERBOLT);
 
 	/* Downstream adapters are indexed in the array allocated here. */
@@ -718,7 +720,8 @@ router_notify_intr(void *context, union nhi_ring_desc *ring, struct nhi_cmd_fram
 	struct router_softc *sc;
 	struct router_command *cmd;
 	struct tb_cfg_notify event;
-	u_int ev, adap;
+	u_int adap __diagused;
+	u_int ev;
 
 	KASSERT(context != NULL, ("context cannot be NULL\n"));
 
diff --git a/sys/dev/thunderbolt/tb_acpi_pcib.c b/sys/dev/thunderbolt/tb_acpi_pcib.c
index 947df3688535..57ad916d4435 100644
--- a/sys/dev/thunderbolt/tb_acpi_pcib.c
+++ b/sys/dev/thunderbolt/tb_acpi_pcib.c
@@ -120,7 +120,7 @@ tb_acpi_pcib_attach(device_t dev)
 		ACPI_OBJECT_LIST list;
 		ACPI_OBJECT arg;
 		ACPI_BUFFER buf;
-		ACPI_STATUS s;
+		ACPI_STATUS s __diagused;
 
 		tb_debug(sc, DBG_BRIDGE, "Executing OSUP\n");
 
diff --git a/sys/dev/thunderbolt/tb_debug.c b/sys/dev/thunderbolt/tb_debug.c
index f455ee72e9f6..fe65b2a5c034 100644
--- a/sys/dev/thunderbolt/tb_debug.c
+++ b/sys/dev/thunderbolt/tb_debug.c
@@ -206,7 +206,7 @@ int
 tb_debug_sysctl(SYSCTL_HANDLER_ARGS)
 {
 	struct sbuf *sbuf;
-#if defined (THUNDERBOLT_DEBUG) && (THUNDERBOLT_DEBUG > 0)
+#ifdef THUNDERBOLT_DEBUG
 	struct tb_debug_string *string;
 	char *buffer;
 	size_t sz;
@@ -221,7 +221,7 @@ tb_debug_sysctl(SYSCTL_HANDLER_ARGS)
 
 	sbuf = sbuf_new_for_sysctl(NULL, NULL, 128, req);
 
-#if defined (THUNDERBOLT_DEBUG) && (THUNDERBOLT_DEBUG > 0)
+#ifdef THUNDERBOLT_DEBUG
 	debug = (u_int *)arg1;
 
 	sbuf_printf(sbuf, "%#x", *debug);
@@ -317,7 +317,7 @@ tb_parse_debug(u_int *debug, char *list)
 void
 tbdbg_dprintf(device_t dev, u_int debug, u_int val, const char *fmt, ...)
 {
-#if defined(THUNDERBOLT_DEBUG) && (THUNDERBOLT_DEBUG > 0)
+#ifdef THUNDERBOLT_DEBUG
 	va_list ap;
 	u_int lvl, dbg;
 
diff --git a/sys/dev/thunderbolt/tb_debug.h b/sys/dev/thunderbolt/tb_debug.h
index 4f5584420882..6ce479a42389 100644
--- a/sys/dev/thunderbolt/tb_debug.h
+++ b/sys/dev/thunderbolt/tb_debug.h
@@ -81,7 +81,7 @@ enum {
  */
 void tbdbg_dprintf(device_t dev, u_int debug, u_int val, const char *fmt, ...) __printflike(4, 5);
 
-#if defined(THUNDERBOLT_DEBUG) && (THUNDERBOLT_DEBUG > 0)
+#ifdef THUNDERBOLT_DEBUG
 #define tb_debug(sc, level, fmt...)	\
 	tbdbg_dprintf((sc)->dev, (sc)->debug, level, ##fmt)
 #else
diff --git a/sys/dev/thunderbolt/tb_pcib.c b/sys/dev/thunderbolt/tb_pcib.c
index b30de5a7493c..65ff42e4f831 100644
--- a/sys/dev/thunderbolt/tb_pcib.c
+++ b/sys/dev/thunderbolt/tb_pcib.c
@@ -304,7 +304,7 @@ static int
 tb_pcib_detach(device_t dev)
 {
 	struct tb_pcib_softc *sc;
-	int error;
+	int error __diagused;
 
 	sc = device_get_softc(dev);