@@ -8,7 +8,7 @@
#include <linux/slab.h>
#include "internal.h"
-static const char cachefiles_charmap[64] =
+static const char cachefiles_charmap[64] __attribute((nonstring)) =
"0123456789" /* 0 - 9 */
"abcdefghijklmnopqrstuvwxyz" /* 10 - 35 */
"ABCDEFGHIJKLMNOPQRSTUVWXYZ" /* 36 - 61 */
@@ -372,7 +372,8 @@ void fscache_withdraw_cache(struct fscache_cache *cache)
EXPORT_SYMBOL(fscache_withdraw_cache);
#ifdef CONFIG_PROC_FS
-static const char fscache_cache_states[NR__FSCACHE_CACHE_STATE] = "-PAEW";
+static const char fscache_cache_states[NR__FSCACHE_CACHE_STATE]
+ __attribute__((nonstring)) = "-PAEW";
/*
* Generate a list of caches in /proc/fs/fscache/caches
@@ -29,7 +29,8 @@ static LIST_HEAD(fscache_cookie_lru);
static DEFINE_SPINLOCK(fscache_cookie_lru_lock);
DEFINE_TIMER(fscache_cookie_lru_timer, fscache_cookie_lru_timed_out);
static DECLARE_WORK(fscache_cookie_lru_work, fscache_cookie_lru_worker);
-static const char fscache_cookie_states[FSCACHE_COOKIE_STATE__NR] = "-LCAIFUWRD";
+static const char fscache_cookie_states[FSCACHE_COOKIE_STATE__NR]
+ __attribute__((nonstring)) = "-LCAIFUWRD";
static unsigned int fscache_lru_cookie_timeout = 10 * HZ;
void fscache_print_cookie(struct fscache_cookie *cookie, char prefix)
Since the Linux kernel initializes many non-C-string char arrays with literals. While it would be possible to convert initializers from: { "BOOP", ... } to: { { 'B', 'O', 'O', 'P' }, ... } that is annoying. Making -Wunterminated-string-initialization stay silent about char arrays marked with nonstring would be much better. Without the __attribute__((nonstring)) we would get the following build error: fs/netfs/fscache_cache.c:375:67: error: initializer-string for array of ‘char’ is too long [-Werror=unterminated-string-initialization] 375 | static const char fscache_cache_states[NR__FSCACHE_CACHE_STATE] = "-PAEW"; | ^~~~~~~ ... fs/netfs/fscache_cookie.c:32:69: error: initializer-string for array of ‘char’ is too long [-Werror=unterminated-string-initialization] 32 | static const char fscache_cookie_states[FSCACHE_COOKIE_STATE__NR] = "-LCAIFUWRD"; | ^~~~~~~~~~~~ cc1: all warnings being treated as errors Upstream GCC has added this commit 622968990beee7499e951590258363545b4a3b57[0][1] which silences warning about truncating NUL char when initializing nonstring arrays. [0]: https://gcc.gnu.org/cgit/gcc/commit/?id=622968990beee7499e951590258363545b4a3b57 [1]: https://gcc.gnu.org/cgit/gcc/commit/?id=afb46540d3921e96c4cd7ba8fa2c8b0901759455 Thanks to Jakub Jelinek <jakub@gcc.gnu.org> for the gcc patch. Signed-off-by: Brahmajit Das <listout@listout.xyz> --- fs/cachefiles/key.c | 2 +- fs/netfs/fscache_cache.c | 3 ++- fs/netfs/fscache_cookie.c | 3 ++- 3 files changed, 5 insertions(+), 3 deletions(-)