Commit 41414722 authored by Christoph Hellwig's avatar Christoph Hellwig Committed by Chandan Babu R
Browse files

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: default avatarChristoph Hellwig <hch@lst.de>
Reviewed-by: default avatar"Darrick J. Wong" <djwong@kernel.org>
Reviewed-by: default avatarDave Chinner <dchinner@redhat.com>
Signed-off-by: default avatarChandan Babu R <chandanbabu@kernel.org>
parent 1fb4b0de
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -1052,9 +1052,9 @@ xfs_attr_set(

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

	return be16_to_cpu(sf->hdr.totsize);
	return be16_to_cpu(sf->totsize);
}

/*
+18 −19
Original line number Diff line number Diff line
@@ -704,10 +704,10 @@ struct xfs_attr_sf_entry *
xfs_attr_sf_findname(
	struct xfs_da_args		*args)
{
	struct xfs_attr_shortform	*sf = args->dp->i_af.if_data;
	struct xfs_attr_sf_hdr		*sf = args->dp->i_af.if_data;
	struct xfs_attr_sf_entry	*sfe;

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

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

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

@@ -809,9 +809,9 @@ xfs_attr_sf_removename(
	end = xfs_attr_sf_endptr(sf);
	if (next < end)
		memmove(sfe, next, end - next);
	sf->hdr.count--;
	sf->count--;
	totsize -= size;
	sf->hdr.totsize = cpu_to_be16(totsize);
	sf->totsize = cpu_to_be16(totsize);

	/*
	 * Fix up the start offset of the attribute fork
@@ -868,21 +868,21 @@ xfs_attr_shortform_to_leaf(
{
	struct xfs_inode		*dp = args->dp;
	struct xfs_ifork		*ifp = &dp->i_af;
	struct xfs_attr_shortform	*sf = ifp->if_data;
	struct xfs_attr_sf_hdr		*sf = ifp->if_data;
	struct xfs_attr_sf_entry	*sfe;
	int				size = be16_to_cpu(sf->totsize);
	struct xfs_da_args		nargs;
	char				*tmpbuffer;
	int				error, i, size;
	int				error, i;
	xfs_dablk_t			blkno;
	struct xfs_buf			*bp;

	trace_xfs_attr_sf_to_leaf(args);

	size = be16_to_cpu(sf->hdr.totsize);
	tmpbuffer = kmem_alloc(size, 0);
	ASSERT(tmpbuffer != NULL);
	memcpy(tmpbuffer, ifp->if_data, size);
	sf = (struct xfs_attr_shortform *)tmpbuffer;
	sf = (struct xfs_attr_sf_hdr *)tmpbuffer;

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

	sfe = &sf->list[0];
	for (i = 0; i < sf->hdr.count; i++) {
	sfe = xfs_attr_sf_firstentry(sf);
	for (i = 0; i < sf->count; i++) {
		nargs.name = sfe->nameval;
		nargs.namelen = sfe->namelen;
		nargs.value = &sfe->nameval[nargs.namelen];
@@ -973,10 +973,10 @@ xfs_attr_shortform_allfit(
/* Verify the consistency of a raw inline attribute fork. */
xfs_failaddr_t
xfs_attr_shortform_verify(
	struct xfs_attr_shortform	*sfp,
	struct xfs_attr_sf_hdr		*sfp,
	size_t				size)
{
	struct xfs_attr_sf_entry	*sfep;
	struct xfs_attr_sf_entry	*sfep = xfs_attr_sf_firstentry(sfp);
	struct xfs_attr_sf_entry	*next_sfep;
	char				*endp;
	int				i;
@@ -990,8 +990,7 @@ xfs_attr_shortform_verify(
	endp = (char *)sfp + size;

	/* Check all reported entries */
	sfep = &sfp->list[0];
	for (i = 0; i < sfp->hdr.count; i++) {
	for (i = 0; i < sfp->count; i++) {
		/*
		 * struct xfs_attr_sf_entry has a variable length.
		 * Check the fixed-offset parts of the structure are
+1 −1
Original line number Diff line number Diff line
@@ -53,7 +53,7 @@ int xfs_attr_sf_removename(struct xfs_da_args *args);
struct xfs_attr_sf_entry *xfs_attr_sf_findname(struct xfs_da_args *args);
int	xfs_attr_shortform_allfit(struct xfs_buf *bp, struct xfs_inode *dp);
int	xfs_attr_shortform_bytesfit(struct xfs_inode *dp, int bytes);
xfs_failaddr_t xfs_attr_shortform_verify(struct xfs_attr_shortform *sfp,
xfs_failaddr_t xfs_attr_shortform_verify(struct xfs_attr_sf_hdr *sfp,
		size_t size);
void	xfs_attr_fork_remove(struct xfs_inode *ip, struct xfs_trans *tp);

+10 −3
Original line number Diff line number Diff line
@@ -41,7 +41,14 @@ static inline int xfs_attr_sf_entsize(struct xfs_attr_sf_entry *sfep)
	return struct_size(sfep, nameval, sfep->namelen + sfep->valuelen);
}

/* next entry in struct */
/* first entry in the SF attr fork */
static inline struct xfs_attr_sf_entry *
xfs_attr_sf_firstentry(struct xfs_attr_sf_hdr *hdr)
{
	return (struct xfs_attr_sf_entry *)(hdr + 1);
}

/* next entry after sfep */
static inline struct xfs_attr_sf_entry *
xfs_attr_sf_nextentry(struct xfs_attr_sf_entry *sfep)
{
@@ -50,9 +57,9 @@ xfs_attr_sf_nextentry(struct xfs_attr_sf_entry *sfep)

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

#endif	/* __XFS_ATTR_SF_H__ */
+19 −14
Original line number Diff line number Diff line
@@ -578,20 +578,25 @@ xfs_dir2_block_leaf_p(struct xfs_dir2_block_tail *btp)
#define XFS_ATTR_LEAF_MAPSIZE	3	/* how many freespace slots */

/*
 * Entries are packed toward the top as tight as possible.
 * Attribute storage when stored inside the inode.
 *
 * Small attribute lists are packed as tightly as possible so as to fit into the
 * literal area of the inode.
 *
 * These "shortform" attribute forks consist of a single xfs_attr_sf_hdr header
 * followed by zero or more xfs_attr_sf_entry structures.
 */
struct xfs_attr_shortform {
struct xfs_attr_sf_hdr {	/* constant-structure header block */
	__be16	totsize;	/* total bytes in shortform list */
	__u8	count;		/* count of active entries */
	__u8	padding;
	} hdr;
};

struct xfs_attr_sf_entry {
		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[];	/* name & value bytes concatenated */
	} list[];			/* variable sized array */
	__u8	namelen;	/* actual length of name (no NULL) */
	__u8	valuelen;	/* actual length of value (no NULL) */
	__u8	flags;		/* flags bits (XFS_ATTR_*) */
	__u8	nameval[];	/* name & value bytes concatenated */
};

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