Page MenuHomeFreeBSD

thunderbolt: make code -Wunused clean
Needs ReviewPublic

Authored by ngie on Feb 27 2026, 8:52 PM.
Tags
None
Referenced Files
F156522113: D55575.id172894.diff
Thu, May 14, 9:31 AM
F156454200: D55575.id177324.diff
Wed, May 13, 7:22 PM
Unknown Object (File)
Sun, May 10, 8:44 PM
Unknown Object (File)
Fri, May 8, 8:17 PM
Unknown Object (File)
Sun, May 3, 4:04 PM
Unknown Object (File)
Sun, May 3, 9:39 AM
Unknown Object (File)
Fri, May 1, 10:23 PM
Unknown Object (File)
Fri, May 1, 10:19 PM
This revision needs review, but there are no reviewers specified.

Details

Reviewers
None
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 Skipped
Unit
Tests Skipped
Build Status
Buildable 72860
Build 69743: arc lint + arc unit

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.Wed, May 6, 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.