Skip to content

Commit 4141472

Browse files
Christoph HellwigChandan Babu R
authored andcommitted
xfs: remove struct xfs_attr_shortform
sparse complains about struct xfs_attr_shortform because it embeds a structure with a variable sized array in a variable sized array. Given that xfs_attr_shortform is not a very useful structure, and the dir2 equivalent has been removed a long time ago, remove it as well. Provide a xfs_attr_sf_firstentry helper that returns the first xfs_attr_sf_entry behind a xfs_attr_sf_hdr to replace the structure dereference. Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: "Darrick J. Wong" <djwong@kernel.org> Reviewed-by: Dave Chinner <dchinner@redhat.com> Signed-off-by: Chandan Babu R <chandanbabu@kernel.org>
1 parent 1fb4b0d commit 4141472

File tree

10 files changed

+71
-62
lines changed

10 files changed

+71
-62
lines changed

fs/xfs/libxfs/xfs_attr.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1052,9 +1052,9 @@ xfs_attr_set(
10521052

10531053
static inline int xfs_attr_sf_totsize(struct xfs_inode *dp)
10541054
{
1055-
struct xfs_attr_shortform *sf = dp->i_af.if_data;
1055+
struct xfs_attr_sf_hdr *sf = dp->i_af.if_data;
10561056

1057-
return be16_to_cpu(sf->hdr.totsize);
1057+
return be16_to_cpu(sf->totsize);
10581058
}
10591059

10601060
/*

fs/xfs/libxfs/xfs_attr_leaf.c

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -704,10 +704,10 @@ struct xfs_attr_sf_entry *
704704
xfs_attr_sf_findname(
705705
struct xfs_da_args *args)
706706
{
707-
struct xfs_attr_shortform *sf = args->dp->i_af.if_data;
707+
struct xfs_attr_sf_hdr *sf = args->dp->i_af.if_data;
708708
struct xfs_attr_sf_entry *sfe;
709709

710-
for (sfe = &sf->list[0];
710+
for (sfe = xfs_attr_sf_firstentry(sf);
711711
sfe < xfs_attr_sf_endptr(sf);
712712
sfe = xfs_attr_sf_nextentry(sfe)) {
713713
if (xfs_attr_match(args, sfe->namelen, sfe->nameval,
@@ -730,7 +730,7 @@ xfs_attr_shortform_add(
730730
struct xfs_inode *dp = args->dp;
731731
struct xfs_mount *mp = dp->i_mount;
732732
struct xfs_ifork *ifp = &dp->i_af;
733-
struct xfs_attr_shortform *sf = ifp->if_data;
733+
struct xfs_attr_sf_hdr *sf = ifp->if_data;
734734
struct xfs_attr_sf_entry *sfe;
735735
int size;
736736

@@ -750,8 +750,8 @@ xfs_attr_shortform_add(
750750
sfe->flags = args->attr_filter;
751751
memcpy(sfe->nameval, args->name, args->namelen);
752752
memcpy(&sfe->nameval[args->namelen], args->value, args->valuelen);
753-
sf->hdr.count++;
754-
be16_add_cpu(&sf->hdr.totsize, size);
753+
sf->count++;
754+
be16_add_cpu(&sf->totsize, size);
755755
xfs_trans_log_inode(args->trans, dp, XFS_ILOG_CORE | XFS_ILOG_ADATA);
756756

757757
xfs_sbversion_add_attr2(mp, args->trans);
@@ -782,9 +782,9 @@ xfs_attr_sf_removename(
782782
{
783783
struct xfs_inode *dp = args->dp;
784784
struct xfs_mount *mp = dp->i_mount;
785-
struct xfs_attr_shortform *sf = dp->i_af.if_data;
785+
struct xfs_attr_sf_hdr *sf = dp->i_af.if_data;
786786
struct xfs_attr_sf_entry *sfe;
787-
uint16_t totsize = be16_to_cpu(sf->hdr.totsize);
787+
uint16_t totsize = be16_to_cpu(sf->totsize);
788788
void *next, *end;
789789
int size = 0;
790790

@@ -809,9 +809,9 @@ xfs_attr_sf_removename(
809809
end = xfs_attr_sf_endptr(sf);
810810
if (next < end)
811811
memmove(sfe, next, end - next);
812-
sf->hdr.count--;
812+
sf->count--;
813813
totsize -= size;
814-
sf->hdr.totsize = cpu_to_be16(totsize);
814+
sf->totsize = cpu_to_be16(totsize);
815815

816816
/*
817817
* Fix up the start offset of the attribute fork
@@ -868,21 +868,21 @@ xfs_attr_shortform_to_leaf(
868868
{
869869
struct xfs_inode *dp = args->dp;
870870
struct xfs_ifork *ifp = &dp->i_af;
871-
struct xfs_attr_shortform *sf = ifp->if_data;
871+
struct xfs_attr_sf_hdr *sf = ifp->if_data;
872872
struct xfs_attr_sf_entry *sfe;
873+
int size = be16_to_cpu(sf->totsize);
873874
struct xfs_da_args nargs;
874875
char *tmpbuffer;
875-
int error, i, size;
876+
int error, i;
876877
xfs_dablk_t blkno;
877878
struct xfs_buf *bp;
878879

879880
trace_xfs_attr_sf_to_leaf(args);
880881

881-
size = be16_to_cpu(sf->hdr.totsize);
882882
tmpbuffer = kmem_alloc(size, 0);
883883
ASSERT(tmpbuffer != NULL);
884884
memcpy(tmpbuffer, ifp->if_data, size);
885-
sf = (struct xfs_attr_shortform *)tmpbuffer;
885+
sf = (struct xfs_attr_sf_hdr *)tmpbuffer;
886886

887887
xfs_idata_realloc(dp, -size, XFS_ATTR_FORK);
888888
xfs_bmap_local_to_extents_empty(args->trans, dp, XFS_ATTR_FORK);
@@ -905,8 +905,8 @@ xfs_attr_shortform_to_leaf(
905905
nargs.trans = args->trans;
906906
nargs.op_flags = XFS_DA_OP_OKNOENT;
907907

908-
sfe = &sf->list[0];
909-
for (i = 0; i < sf->hdr.count; i++) {
908+
sfe = xfs_attr_sf_firstentry(sf);
909+
for (i = 0; i < sf->count; i++) {
910910
nargs.name = sfe->nameval;
911911
nargs.namelen = sfe->namelen;
912912
nargs.value = &sfe->nameval[nargs.namelen];
@@ -973,10 +973,10 @@ xfs_attr_shortform_allfit(
973973
/* Verify the consistency of a raw inline attribute fork. */
974974
xfs_failaddr_t
975975
xfs_attr_shortform_verify(
976-
struct xfs_attr_shortform *sfp,
976+
struct xfs_attr_sf_hdr *sfp,
977977
size_t size)
978978
{
979-
struct xfs_attr_sf_entry *sfep;
979+
struct xfs_attr_sf_entry *sfep = xfs_attr_sf_firstentry(sfp);
980980
struct xfs_attr_sf_entry *next_sfep;
981981
char *endp;
982982
int i;
@@ -990,8 +990,7 @@ xfs_attr_shortform_verify(
990990
endp = (char *)sfp + size;
991991

992992
/* Check all reported entries */
993-
sfep = &sfp->list[0];
994-
for (i = 0; i < sfp->hdr.count; i++) {
993+
for (i = 0; i < sfp->count; i++) {
995994
/*
996995
* struct xfs_attr_sf_entry has a variable length.
997996
* Check the fixed-offset parts of the structure are

fs/xfs/libxfs/xfs_attr_leaf.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ int xfs_attr_sf_removename(struct xfs_da_args *args);
5353
struct xfs_attr_sf_entry *xfs_attr_sf_findname(struct xfs_da_args *args);
5454
int xfs_attr_shortform_allfit(struct xfs_buf *bp, struct xfs_inode *dp);
5555
int xfs_attr_shortform_bytesfit(struct xfs_inode *dp, int bytes);
56-
xfs_failaddr_t xfs_attr_shortform_verify(struct xfs_attr_shortform *sfp,
56+
xfs_failaddr_t xfs_attr_shortform_verify(struct xfs_attr_sf_hdr *sfp,
5757
size_t size);
5858
void xfs_attr_fork_remove(struct xfs_inode *ip, struct xfs_trans *tp);
5959

fs/xfs/libxfs/xfs_attr_sf.h

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,14 @@ static inline int xfs_attr_sf_entsize(struct xfs_attr_sf_entry *sfep)
4141
return struct_size(sfep, nameval, sfep->namelen + sfep->valuelen);
4242
}
4343

44-
/* next entry in struct */
44+
/* first entry in the SF attr fork */
45+
static inline struct xfs_attr_sf_entry *
46+
xfs_attr_sf_firstentry(struct xfs_attr_sf_hdr *hdr)
47+
{
48+
return (struct xfs_attr_sf_entry *)(hdr + 1);
49+
}
50+
51+
/* next entry after sfep */
4552
static inline struct xfs_attr_sf_entry *
4653
xfs_attr_sf_nextentry(struct xfs_attr_sf_entry *sfep)
4754
{
@@ -50,9 +57,9 @@ xfs_attr_sf_nextentry(struct xfs_attr_sf_entry *sfep)
5057

5158
/* pointer to the space after the last entry, e.g. for adding a new one */
5259
static inline struct xfs_attr_sf_entry *
53-
xfs_attr_sf_endptr(struct xfs_attr_shortform *sf)
60+
xfs_attr_sf_endptr(struct xfs_attr_sf_hdr *sf)
5461
{
55-
return (void *)sf + be16_to_cpu(sf->hdr.totsize);
62+
return (void *)sf + be16_to_cpu(sf->totsize);
5663
}
5764

5865
#endif /* __XFS_ATTR_SF_H__ */

fs/xfs/libxfs/xfs_da_format.h

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -578,20 +578,25 @@ xfs_dir2_block_leaf_p(struct xfs_dir2_block_tail *btp)
578578
#define XFS_ATTR_LEAF_MAPSIZE 3 /* how many freespace slots */
579579

580580
/*
581-
* Entries are packed toward the top as tight as possible.
582-
*/
583-
struct xfs_attr_shortform {
584-
struct xfs_attr_sf_hdr { /* constant-structure header block */
585-
__be16 totsize; /* total bytes in shortform list */
586-
__u8 count; /* count of active entries */
587-
__u8 padding;
588-
} hdr;
589-
struct xfs_attr_sf_entry {
590-
uint8_t namelen; /* actual length of name (no NULL) */
591-
uint8_t valuelen; /* actual length of value (no NULL) */
592-
uint8_t flags; /* flags bits (see xfs_attr_leaf.h) */
593-
uint8_t nameval[]; /* name & value bytes concatenated */
594-
} list[]; /* variable sized array */
581+
* Attribute storage when stored inside the inode.
582+
*
583+
* Small attribute lists are packed as tightly as possible so as to fit into the
584+
* literal area of the inode.
585+
*
586+
* These "shortform" attribute forks consist of a single xfs_attr_sf_hdr header
587+
* followed by zero or more xfs_attr_sf_entry structures.
588+
*/
589+
struct xfs_attr_sf_hdr { /* constant-structure header block */
590+
__be16 totsize; /* total bytes in shortform list */
591+
__u8 count; /* count of active entries */
592+
__u8 padding;
593+
};
594+
595+
struct xfs_attr_sf_entry {
596+
__u8 namelen; /* actual length of name (no NULL) */
597+
__u8 valuelen; /* actual length of value (no NULL) */
598+
__u8 flags; /* flags bits (XFS_ATTR_*) */
599+
__u8 nameval[]; /* name & value bytes concatenated */
595600
};
596601

597602
typedef struct xfs_attr_leaf_map { /* RLE map of free bytes */

fs/xfs/libxfs/xfs_inode_fork.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -279,10 +279,9 @@ static uint16_t
279279
xfs_dfork_attr_shortform_size(
280280
struct xfs_dinode *dip)
281281
{
282-
struct xfs_attr_shortform *atp =
283-
(struct xfs_attr_shortform *)XFS_DFORK_APTR(dip);
282+
struct xfs_attr_sf_hdr *sf = XFS_DFORK_APTR(dip);
284283

285-
return be16_to_cpu(atp->hdr.totsize);
284+
return be16_to_cpu(sf->totsize);
286285
}
287286

288287
void

fs/xfs/libxfs/xfs_ondisk.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -93,13 +93,13 @@ xfs_check_ondisk_structs(void)
9393
XFS_CHECK_OFFSET(xfs_attr_leaf_name_remote_t, namelen, 8);
9494
XFS_CHECK_OFFSET(xfs_attr_leaf_name_remote_t, name, 9);
9595
XFS_CHECK_STRUCT_SIZE(xfs_attr_leafblock_t, 32);
96-
XFS_CHECK_STRUCT_SIZE(struct xfs_attr_shortform, 4);
97-
XFS_CHECK_OFFSET(struct xfs_attr_shortform, hdr.totsize, 0);
98-
XFS_CHECK_OFFSET(struct xfs_attr_shortform, hdr.count, 2);
99-
XFS_CHECK_OFFSET(struct xfs_attr_shortform, list[0].namelen, 4);
100-
XFS_CHECK_OFFSET(struct xfs_attr_shortform, list[0].valuelen, 5);
101-
XFS_CHECK_OFFSET(struct xfs_attr_shortform, list[0].flags, 6);
102-
XFS_CHECK_OFFSET(struct xfs_attr_shortform, list[0].nameval, 7);
96+
XFS_CHECK_STRUCT_SIZE(struct xfs_attr_sf_hdr, 4);
97+
XFS_CHECK_OFFSET(struct xfs_attr_sf_hdr, totsize, 0);
98+
XFS_CHECK_OFFSET(struct xfs_attr_sf_hdr, count, 2);
99+
XFS_CHECK_OFFSET(struct xfs_attr_sf_entry, namelen, 0);
100+
XFS_CHECK_OFFSET(struct xfs_attr_sf_entry, valuelen, 1);
101+
XFS_CHECK_OFFSET(struct xfs_attr_sf_entry, flags, 2);
102+
XFS_CHECK_OFFSET(struct xfs_attr_sf_entry, nameval, 3);
103103
XFS_CHECK_STRUCT_SIZE(xfs_da_blkinfo_t, 12);
104104
XFS_CHECK_STRUCT_SIZE(xfs_da_intnode_t, 16);
105105
XFS_CHECK_STRUCT_SIZE(xfs_da_node_entry_t, 8);

fs/xfs/scrub/attr.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -528,23 +528,22 @@ xchk_xattr_check_sf(
528528
{
529529
struct xchk_xattr_buf *ab = sc->buf;
530530
struct xfs_ifork *ifp = &sc->ip->i_af;
531-
struct xfs_attr_shortform *sf = ifp->if_data;
532-
struct xfs_attr_sf_entry *sfe;
531+
struct xfs_attr_sf_hdr *sf = ifp->if_data;
532+
struct xfs_attr_sf_entry *sfe = xfs_attr_sf_firstentry(sf);
533533
struct xfs_attr_sf_entry *next;
534534
unsigned char *end = ifp->if_data + ifp->if_bytes;
535535
int i;
536536
int error = 0;
537537

538538
bitmap_zero(ab->usedmap, ifp->if_bytes);
539-
xchk_xattr_set_map(sc, ab->usedmap, 0, sizeof(sf->hdr));
539+
xchk_xattr_set_map(sc, ab->usedmap, 0, sizeof(*sf));
540540

541-
sfe = &sf->list[0];
542541
if ((unsigned char *)sfe > end) {
543542
xchk_fblock_set_corrupt(sc, XFS_ATTR_FORK, 0);
544543
return 0;
545544
}
546545

547-
for (i = 0; i < sf->hdr.count; i++) {
546+
for (i = 0; i < sf->count; i++) {
548547
unsigned char *name = sfe->nameval;
549548
unsigned char *value = &sfe->nameval[sfe->namelen];
550549

fs/xfs/scrub/inode_repair.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -760,7 +760,7 @@ xrep_dinode_check_afork(
760760
struct xfs_scrub *sc,
761761
struct xfs_dinode *dip)
762762
{
763-
struct xfs_attr_shortform *afork_ptr;
763+
struct xfs_attr_sf_hdr *afork_ptr;
764764
size_t attr_size;
765765
unsigned int afork_size;
766766

@@ -778,7 +778,7 @@ xrep_dinode_check_afork(
778778
return true;
779779

780780
/* xattr structure cannot be larger than the fork */
781-
attr_size = be16_to_cpu(afork_ptr->hdr.totsize);
781+
attr_size = be16_to_cpu(afork_ptr->totsize);
782782
if (attr_size > afork_size)
783783
return true;
784784

fs/xfs/xfs_attr_list.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,13 @@ xfs_attr_shortform_list(
5656
struct xfs_attrlist_cursor_kern *cursor = &context->cursor;
5757
struct xfs_inode *dp = context->dp;
5858
struct xfs_attr_sf_sort *sbuf, *sbp;
59-
struct xfs_attr_shortform *sf = dp->i_af.if_data;
59+
struct xfs_attr_sf_hdr *sf = dp->i_af.if_data;
6060
struct xfs_attr_sf_entry *sfe;
6161
int sbsize, nsbuf, count, i;
6262
int error = 0;
6363

6464
ASSERT(sf != NULL);
65-
if (!sf->hdr.count)
65+
if (!sf->count)
6666
return 0;
6767

6868
trace_xfs_attr_list_sf(context);
@@ -78,8 +78,8 @@ xfs_attr_shortform_list(
7878
*/
7979
if (context->bufsize == 0 ||
8080
(XFS_ISRESET_CURSOR(cursor) &&
81-
(dp->i_af.if_bytes + sf->hdr.count * 16) < context->bufsize)) {
82-
for (i = 0, sfe = &sf->list[0]; i < sf->hdr.count; i++) {
81+
(dp->i_af.if_bytes + sf->count * 16) < context->bufsize)) {
82+
for (i = 0, sfe = xfs_attr_sf_firstentry(sf); i < sf->count; i++) {
8383
if (XFS_IS_CORRUPT(context->dp->i_mount,
8484
!xfs_attr_namecheck(sfe->nameval,
8585
sfe->namelen)))
@@ -108,15 +108,15 @@ xfs_attr_shortform_list(
108108
/*
109109
* It didn't all fit, so we have to sort everything on hashval.
110110
*/
111-
sbsize = sf->hdr.count * sizeof(*sbuf);
111+
sbsize = sf->count * sizeof(*sbuf);
112112
sbp = sbuf = kmem_alloc(sbsize, KM_NOFS);
113113

114114
/*
115115
* Scan the attribute list for the rest of the entries, storing
116116
* the relevant info from only those that match into a buffer.
117117
*/
118118
nsbuf = 0;
119-
for (i = 0, sfe = &sf->list[0]; i < sf->hdr.count; i++) {
119+
for (i = 0, sfe = xfs_attr_sf_firstentry(sf); i < sf->count; i++) {
120120
if (unlikely(
121121
((char *)sfe < (char *)sf) ||
122122
((char *)sfe >= ((char *)sf + dp->i_af.if_bytes)))) {

0 commit comments

Comments
 (0)