linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Arnd Bergmann <arnd@arndb.de>
To: Alexander Viro <viro@zeniv.linux.org.uk>
Cc: Arnd Bergmann <arnd@arndb.de>,
	"Gustavo A . R . Silva" <gustavo@embeddedor.com>,
	"Darrick J. Wong" <darrick.wong@oracle.com>,
	Jan Kara <jack@suse.cz>,
	Andrew Morton <akpm@linux-foundation.org>,
	Amir Goldstein <amir73il@gmail.com>,
	linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH] fsnotify: avoid gcc-10 zero-length-bounds warning
Date: Tue,  5 May 2020 16:30:09 +0200	[thread overview]
Message-ID: <20200505143028.1290686-1-arnd@arndb.de> (raw)

gcc-10 warns about accesses into the f_handle[] zero-length array.

fs/notify/fdinfo.c: In function 'show_mark_fhandle':
fs/notify/fdinfo.c:66:47: error: array subscript 'i' is outside the bounds of an interior zero-length array 'unsigned char[0]' [-Werror=zero-length-bounds]
   66 |   seq_printf(m, "%02x", (int)f.handle.f_handle[i]);
      |                              ~~~~~~~~~~~~~~~~~^~~
In file included from fs/notify/fdinfo.c:3:
include/linux/fs.h:988:16: note: while referencing 'f_handle'
  988 |  unsigned char f_handle[0];
      |                ^~~~~~~~

This is solved by using a flexible array instead.

Cc: Gustavo A. R. Silva <gustavo@embeddedor.com>
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
Gustavo has done the same thing as part of a treewide change, but keeping
this separate lets us backport it to stable kernels more easily later.
---
 include/linux/fs.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/linux/fs.h b/include/linux/fs.h
index 8690dc56e883..b229c55a8232 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -986,7 +986,7 @@ struct file_handle {
 	__u32 handle_bytes;
 	int handle_type;
 	/* file identifier */
-	unsigned char f_handle[0];
+	unsigned char f_handle[];
 };
 
 static inline struct file *get_file(struct file *f)
-- 
2.26.0


             reply	other threads:[~2020-05-05 14:30 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-05 14:30 Arnd Bergmann [this message]
2020-05-05 14:39 ` [PATCH] fsnotify: avoid gcc-10 zero-length-bounds warning Gustavo A. R. Silva
2020-05-05 15:00   ` Arnd Bergmann
2020-05-05 15:11     ` Gustavo A. R. Silva
2020-05-05 15:23       ` Arnd Bergmann
2020-05-05 16:58         ` Linus Torvalds
2020-05-07  8:01     ` David Laight

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200505143028.1290686-1-arnd@arndb.de \
    --to=arnd@arndb.de \
    --cc=akpm@linux-foundation.org \
    --cc=amir73il@gmail.com \
    --cc=darrick.wong@oracle.com \
    --cc=gustavo@embeddedor.com \
    --cc=jack@suse.cz \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=viro@zeniv.linux.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).