Page MenuHomeFreeBSD

thunderbolt: make code -Wunused clean
ClosedPublic

Authored by ngie on Feb 27 2026, 8:52 PM.
Tags
None
Referenced Files
Unknown Object (File)
Sat, Jun 20, 5:19 PM
Unknown Object (File)
Tue, Jun 16, 1:25 PM
Unknown Object (File)
Mon, Jun 15, 8:05 PM
Unknown Object (File)
Thu, Jun 11, 10:15 AM
Unknown Object (File)
Thu, Jun 4, 6:03 AM
Unknown Object (File)
Sun, May 31, 5:39 PM
Unknown Object (File)
Sun, May 31, 3:10 PM
Unknown Object (File)
Sat, May 30, 4:40 PM

Details

Summary

This change modifies code paths and uses __diagused to address -Wunused
issues that occur when THUNDERBOLT_DEBUG == 0.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

ngie requested review of this revision.Feb 27 2026, 8:52 PM

thanks for this!

in general, can't we just use __used on maybe-unused declarations? smaller diff & more idiomatic wrt having sc defined everywhere without doing r->sc. but I'm nitpicking here so I'm okay with accepting this as is

sys/dev/thunderbolt/nhi.c
874–877

why don't we just use __used here as suggested in the description of this revision?

sys/dev/thunderbolt/tb_debug.h
84

why this change? Do we want this code to be built if THUNDERBOLT_DEBUG is 0?

but also if we wanted to preserve the existing logic we could simplify the previous check with just #if THUNDERBOLT_DEBUG > 0 since undefined identifiers evaluate to 0.

sys/dev/thunderbolt/nhi.c
874–877

I tried using it universally, but __used is only applicable to function arguments, not local variables in functions, etc. I did this to avoid #ifdef soup, but I suppose there are alternative ways I could try applying these changes. I'm open to suggestions.

ngie added inline comments.
sys/dev/thunderbolt/nhi.c
874–877

I have an idea... maybe something like this?

#ifdef THUNDERBOLT_DEBUG
#define WUNUSED_IF_DEBUG(x) (void)(x)
#else
#define WUNUSED_IF_DEBUG(x) (x)
#endif
sys/dev/thunderbolt/tb_debug.h
84

The latter is actually a source of grief with certain compilers/versions of compilers. I remember a fair bit of effort being spent by @dim dealing with that particular scenario with drivers and higher values of WARNS (was that llvm 5.x~6.x? I forget...).

sys/dev/thunderbolt/nhi.c
874–877

I flip-flopped the conditional by accident and also s/WUNUSED/UNUSED/g.

sys/dev/thunderbolt/nhi.c
874–877

you could also do __unused, as that applies to everything. In fact I think that may be more correct than __used, as that forces the compiler to emit code even if not used:

https://clang.llvm.org/docs/AttributeReference.html#used

sys/dev/thunderbolt/tb_debug.h
84

but then what was wrong with the original code? in the case where THUNDERBOLT_DEBUG is not defined, the behaviour is the same here

Use __diagused instead of diagnostic popping, etc.

ngie marked an inline comment as done.May 6 2026, 10:01 PM
ngie added a subscriber: markj.
ngie added inline comments.
sys/dev/thunderbolt/nhi.c
874–877

__diagused is something I stumbled on after looking at a commit from @markj; it maps to __unused when INVARIANTS isn't defined. This seems like the right path forward given that it semantically makes the most sense here and (IMHO) THUNDERBOLT_DEBUG should be enabled by default if INVARIANTS is enabled.

This revision was not accepted when it landed; it landed in state Needs Review.May 16 2026, 1:01 AM
This revision was automatically updated to reflect the committed changes.
ngie marked an inline comment as done.