Page MenuHomeFreeBSD

thunderbolt: make code -Wunused clean
Needs ReviewPublic

Authored by ngie on Feb 27 2026, 8:52 PM.
Tags
None
Referenced Files
Unknown Object (File)
Tue, Apr 7, 8:51 PM
Unknown Object (File)
Sun, Apr 5, 1:12 PM
Unknown Object (File)
Wed, Apr 1, 3:53 AM
Unknown Object (File)
Sun, Mar 29, 12:55 PM
Unknown Object (File)
Tue, Mar 24, 10:34 AM
Unknown Object (File)
Fri, Mar 20, 9:29 PM
Unknown Object (File)
Fri, Mar 20, 12:53 AM
Unknown Object (File)
Fri, Mar 20, 12:44 AM
This revision needs review, but there are no reviewers specified.

Details

Reviewers
None
Summary

This change modifies code paths and uses __used 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 71082
Build 67965: 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
908–911

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
908–911

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
908–911

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
908–911

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

sys/dev/thunderbolt/nhi.c
908–911

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