fanotify: Drop use of flex array in fanotify_fh
Subsystems (3)
Jan Kara
maintainerPATCH 1/1 fanotify: Drop use of flex array in fanotify_fh
We use flex array 'buf' in fanotify_fh to contain the file handle content. However the buffer is not a proper flex array. It has a preconfigured fixed size. Furthermore if fixed size is not big enough, we use external separately allocated buffer. Hence don't pretend buf is a flex array since we have to use special accessors anyway and instead just modify the accessors to do the pointer math without flex array. This fixes warnings that flex array is not the last struct member in fanotify_fid_event or fanotify_error_event.
--- fs/notify/fanotify/fanotify.c | 2 +- fs/notify/fanotify/fanotify.h | 9 ++++----- 2 files changed, 5 insertions(+), 6 deletions(-)
Amir, how about this solution for the flex array warnings?
fs/notify/fanotify/fanotify.c +1 -1
@@ -415,7 +415,7 @@ static int fanotify_encode_fh(struct fanotify_fh *fh, struct inode *inode, {int dwords, type =0 ;char *ext_buf =NULL ; -void *buf = fh->buf; +void *buf = fh +1 ;int err; fh->type =FILEID_ROOT ;
fs/notify/fanotify/fanotify.h +4 -5
@@ -25,7 +25,7 @@ enum {* stored in either the first or last 2 dwords. */ #define FANOTIFY_INLINE_FH_LEN (3 << 2) -#define FANOTIFY_FH_HDR_LEN offsetof(struct fanotify_fh, buf) +#define FANOTIFY_FH_HDR_LEN sizeof(struct fanotify_fh)/* Fixed size struct for file handle */ struct fanotify_fh {
@@ -34,7 +34,6 @@ struct fanotify_fh {#define FANOTIFY_FH_FLAG_EXT_BUF 1u8 flags;u8 pad; -unsigned char buf[]; }__aligned(4) ;/* Variable size struct for dir file handle + child file handle + name */
@@ -92,7 +91,7 @@ static inline char **fanotify_fh_ext_buf_ptr(struct fanotify_fh *fh)BUILD_BUG_ON (FANOTIFY_FH_HDR_LEN %4 );BUILD_BUG_ON (__alignof__(char *) -4 +sizeof (char *) >FANOTIFY_INLINE_FH_LEN ); -return (char **)ALIGN ((unsigned long )(fh->buf), __alignof__(char *)); +return (char **)ALIGN ((unsigned long )(fh +1 ), __alignof__(char *)); }static inline void *fanotify_fh_ext_buf (struct fanotify_fh *fh)
@@ -102,7 +101,7 @@ static inline void *fanotify_fh_ext_buf(struct fanotify_fh *fh)static inline void *fanotify_fh_buf (struct fanotify_fh *fh) { -return fanotify_fh_has_ext_buf (fh) ?fanotify_fh_ext_buf (fh) : fh->buf; +return fanotify_fh_has_ext_buf (fh) ?fanotify_fh_ext_buf (fh) : fh +1 ; }static inline int fanotify_info_dir_fh_len (struct fanotify_info *info)
@@ -278,7 +277,7 @@ static inline void fanotify_init_event(struct fanotify_event *event,#define FANOTIFY_INLINE_FH (name, size) \ struct { \ struct fanotify_fh name; \ -/* Space for object_fh.buf[] - access with fanotify_fh_buf() */ \ +/* Space for filehandle - access with fanotify_fh_buf() */ \unsigned char _inline_fh_buf[size]; \ }
Signature · 1 line
2.43.0
Quoted 11 lines · Jan Kara
We use flex array 'buf' in
fanotify_fhto contain the file handle content. However the buffer is not a proper flex array. It has a preconfigured fixed size. Furthermore if fixed size is not big enough, we use external separately allocated buffer. Hence don't pretend buf is a flex array since we have to use special accessors anyway and instead just modify the accessors to do the pointer math without flex array. This fixes warnings that flex array is not the last struct member infanotify_fid_eventorfanotify_error_event.Signed-off-by Jan Kara <[email protected]>
Makes sense.
Quoted 71 lines
--- fs/notify/fanotify/fanotify.c | 2 +- fs/notify/fanotify/fanotify.h | 9 ++++----- 2 files changed, 5 insertions(+), 6 deletions(-)Amir, how about this solution for the flex array warnings?
fs/notify/fanotify/fanotify.c +1
-1@@ -415,7 +415,7 @@ static int fanotify_encode_fh(struct fanotify_fh *fh, struct inode *inode, {int dwords, type =0 ;char *ext_buf =NULL ; -void *buf = fh->buf; +void *buf = fh +1 ;int err; fh->type =FILEID_ROOT ;fs/notify/fanotify/fanotify.h +4
-6@@ -25,7 +25,7 @@ enum {* stored in either the first or last 2 dwords. */ #define FANOTIFY_INLINE_FH_LEN (3 << 2) -#define FANOTIFY_FH_HDR_LEN offsetof(struct fanotify_fh, buf) +#define FANOTIFY_FH_HDR_LEN sizeof(struct fanotify_fh)/* Fixed size struct for file handle */ struct fanotify_fh {@@ -34,7 +34,6 @@ struct fanotify_fh {#define FANOTIFY_FH_FLAG_EXT_BUF 1u8 flags;u8 pad; -unsigned char buf[]; }__aligned(4) ;/* Variable size struct for dir file handle + child file handle + name */ @@ -92,7 +91,7 @@ static inline char **fanotify_fh_ext_buf_ptr(struct fanotify_fh *fh)BUILD_BUG_ON (FANOTIFY_FH_HDR_LEN %4 );BUILD_BUG_ON (__alignof__(char *) -4 +sizeof (char *) >FANOTIFY_INLINE_FH_LEN ); -return (char **)ALIGN ((unsigned long )(fh->buf), __alignof__(char *)); +return (char **)ALIGN ((unsigned long )(fh +1 ), __alignof__(char *)); }static inline void *fanotify_fh_ext_buf (struct fanotify_fh *fh)@@ -102,7 +101,7 @@ static inline void *fanotify_fh_ext_buf(struct fanotify_fh *fh)static inline void *fanotify_fh_buf (struct fanotify_fh *fh) { -return fanotify_fh_has_ext_buf (fh) ?fanotify_fh_ext_buf (fh) : fh->buf; +return fanotify_fh_has_ext_buf (fh) ?fanotify_fh_ext_buf (fh) : fh +1 ; }static inline int fanotify_info_dir_fh_len (struct fanotify_info *info)@@ -278,7 +277,7 @@ static inline void fanotify_init_event(struct fanotify_event *event,#define FANOTIFY_INLINE_FH (name, size) \ struct { \ struct fanotify_fh name; \ -/* Space for object_fh.buf[] - access with fanotify_fh_buf() */ \ +/* Space for filehandle - access with fanotify_fh_buf() */ \unsigned char _inline_fh_buf[size]; \ } --2.43.0