The iflib core never modifies the isc_driver_version string. Allow
drivers to safely assign pointers to constant buffers by marking this
parameter const.
Signed-off-by: Jacob Keller <jacob.e.keller@intel.com>
Differential D19577
iflib: mark isc_driver_version as constant jacob.e.keller_intel.com on Mar 13 2019, 10:41 PM. Authored by Tags None Referenced Files
Details
The iflib core never modifies the isc_driver_version string. Allow Signed-off-by: Jacob Keller <jacob.e.keller@intel.com>
Diff Detail
Event TimelineComment Actions Drivers can sort of get around this by using an explicit cast, but that triggers a -Wcast-qual warning. Comment Actions Uhh, oh I see why it's marked as non-const.... SYSCTL_ADD_STRING with a read-only flag doesn't know to take a const value.... Comment Actions This still doesn't quite work 100%, because it causes a -Wcast-qual warning.... I'm not really sure how to fix this without using clang diagnostics. Comment Actions Looks like the best 'fix' would be to use _Pragma to drop the warnings in SYSCTL_ADD_STRING. That will take a bit more work to get correct. Comment Actions Probably through the addition of some sort of "__force_cast()" macro which expands to a pragma to ignore the warnings, the cast, and then the pragma to pop the ignoring... Comment Actions This version actually compilers without the warnings, but it *is* rather ugly to have to do it this way
Comment Actions I think I'd rather have a SYSCTL_ADD_CONST_STRING or the like, but presumably you'd just get the warning again. The other hack is to cast through uintptr_t and it's what we normally do via the __DECONST() macro. I would just do that unconditionally perhaps: char *__arg = __DECONST(arg, char *); Comment Actions I didn't know about __DECONST. I'll take a look at it, thanks! Yea, we could add a SYSCTL_ADD_CONST_STRING as well to be more explicit. Comment Actions Use __DECONST instead of a poor reimplementation Introduce SYSCTL_CONST_STRING and SYSCTL_ADD_CONST_STRING Comment Actions I like the addition of SYSCTL_ADD_CONST_STRING since it also ensures that we enforce that we don't have CTLFLAG_WR.
Comment Actions Just need to add the new macros to sysctl.9 and document them. I think I like having the explicit const string macros. |