Page MenuHomeFreeBSD

<net/sff8472.h>: Conditionally export table of ID names
ClosedPublic

Authored by jhb on Apr 22 2025, 3:04 AM.
Tags
None
Referenced Files
Unknown Object (File)
Fri, Oct 10, 2:39 PM
Unknown Object (File)
Thu, Oct 9, 7:57 PM
Unknown Object (File)
Mon, Oct 6, 4:52 AM
Unknown Object (File)
Fri, Oct 3, 5:05 PM
Unknown Object (File)
Fri, Sep 12, 3:51 PM
Unknown Object (File)
Sep 11 2025, 2:30 AM
Unknown Object (File)
Sep 5 2025, 3:28 AM
Unknown Object (File)
Aug 29 2025, 9:54 AM

Details

Summary

Only export the array of ID names if either _WANT_SFF_8024_ID or
_WANT_SFF_8472_ID is defined. Exporting them unconditionally can
trigger unused variable warnings if a consumer doesn't use the array.

Diff Detail

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

Event Timeline

If this header is used outside of base and the _id[] array is used from it, then we might need to instead disable the warning for this header during the test-includes phase.

This revision is now accepted and ready to land.Apr 22 2025, 5:52 PM
In D49955#1139102, @jhb wrote:

If this header is used outside of base and the _id[] array is used from it, then we might need to instead disable the warning for this header during the test-includes phase.

Yes. That's why this approach seems somewhat impractical, and also ad-hoc as we would have to do that anytime we add some static constant to some header. This is a rare case, and right now I'm not really sure why we would need to do that. Perhaps to simplify cases where the same header is used in the kernel and in userland?

From D49830, I gather you also tried to disable -Wunused-variable. Isn't that approach enough? It has the benefit to be more generic. That said, the macro guard is anyway needed if the header is included by userspace and the constant not used.

There's an argument there should be a DECLARE_SFF_8024_ID macro that consumers add to their .c file, but is easy and has precedent.

IMO it's a bug to add static definitions to headers to they should warn when not appropriately guarded.

IMO it's a bug to add static definitions to headers to they should warn when not appropriately guarded.

I think you're right (if these occurrences exist for the reason I guessed above).

In D49955#1139102, @jhb wrote:

If this header is used outside of base and the _id[] array is used from it, then we might need to instead disable the warning for this header during the test-includes phase.

Yes. That's why this approach seems somewhat impractical, and also ad-hoc as we would have to do that anytime we add some static constant to some header. This is a rare case, and right now I'm not really sure why we would need to do that. Perhaps to simplify cases where the same header is used in the kernel and in userland?

From D49830, I gather you also tried to disable -Wunused-variable. Isn't that approach enough? It has the benefit to be more generic. That said, the macro guard is anyway needed if the header is included by userspace and the constant not used.

I just don't like promulgating more special cases in the test-includes Makefile. Also, the static variables are kind of gross as they end up in .rodata of all compiled binaries even when not used.