Re: [PATCH 1/4] xfs: Use variable-size array for nameval in xfs_attr_sf_entry

Carlos Maiolino
2020-09-02T11:14:45Z

Hi.

> > #define XFS_ATTR_SF_ENTSIZE(sfep) /* space an entry uses */ \
> > - ((int)sizeof(xfs_attr_sf_entry_t)-1 + (sfep)->namelen+(sfep)->valuelen)
> > + ((int)sizeof(xfs_attr_sf_entry_t) + (sfep)->namelen+(sfep)->valuelen)
>
> Can this (and ENTSIZE_BYNAME) use struct_sizeof?

Regarding our talk on #xfs, I've been playing with it a while today, and IMHO,
converting xfs_attr_sf_entsize to use struct_size() is ok, although,
entsize_byname, I don't think it's worth it. entsize_byname doesn't get a
xfs_attr_sf_entry as argument, so it will require to change the callers to
actually pass a struct xfs_attr_sf_entry, and the respective sizes, but, some
callers actually don't even have a xfs_attr_sf_entry to pass into it, so IMHO, I
don't think it's worth to change it, but by any means, I'll send today a V2 of
my patchset containing the changes from V1, and adding the struct_size() into
xfs_attr_sf_entry.

Cheers.

>
> --D
>
> > #define XFS_ATTR_SF_NEXTENTRY(sfep) /* next entry in struct */ \
> > ((xfs_attr_sf_entry_t *)((char *)(sfep) + XFS_ATTR_SF_ENTSIZE(sfep)))
> > #define XFS_ATTR_SF_TOTSIZE(dp) /* total space in use */ \
> > diff --git a/fs/xfs/libxfs/xfs_da_format.h b/fs/xfs/libxfs/xfs_da_format.h
> > index 059ac108b1b39..e86185a1165b3 100644
> > --- a/fs/xfs/libxfs/xfs_da_format.h
> > +++ b/fs/xfs/libxfs/xfs_da_format.h
> > @@ -589,7 +589,7 @@ typedef struct xfs_attr_shortform {
> > uint8_t namelen; /* actual length of name (no NULL) */
> > uint8_t valuelen; /* actual length of value (no NULL) */
> > uint8_t flags; /* flags bits (see xfs_attr_leaf.h) */
> > - uint8_t nameval[1]; /* name & value bytes concatenated */
> > + uint8_t nameval[]; /* name & value bytes concatenated */
> > } list[1]; /* variable sized array */
> > } xfs_attr_shortform_t;
> >
> > --
> > 2.26.2
> >
>

--
Carlos