All of lore.kernel.org
 help / color / mirror / Atom feed
From: Carlos Maiolino <cmaiolino@redhat.com>
To: linux-xfs@vger.kernel.org
Subject: [PATCH v4 3/4] xfs: Use variable-size array for nameval in xfs_attr_sf_entry
Date: Thu,  3 Sep 2020 18:17:24 +0200	[thread overview]
Message-ID: <20200903161724.85328-1-cmaiolino@redhat.com> (raw)
In-Reply-To: <20200903142839.72710-4-cmaiolino@redhat.com>

nameval is a variable-size array, so, define it as it, and remove all
the -1 magic number subtractions

Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Carlos Maiolino <cmaiolino@redhat.com>
---

Changelog:

	V2:
	 - Drop wrong change to XFS_ATTR_SF_ENTSIZE_MAX
	V3:
	- Use XFS_ATTR_SF_ENTSIZE_BYNAME in xfs_attr_shortform_allfit()
	- Remove int casting and fix spacing on
	  XFS_ATTR_SF_ENTSIZE_BYNAME
	V4:
	- Fix indentation on xfs_attr_shortform_allfit()

 fs/xfs/libxfs/xfs_attr_leaf.c | 9 +++------
 fs/xfs/libxfs/xfs_attr_sf.h   | 4 ++--
 fs/xfs/libxfs/xfs_da_format.h | 2 +-
 3 files changed, 6 insertions(+), 9 deletions(-)

diff --git a/fs/xfs/libxfs/xfs_attr_leaf.c b/fs/xfs/libxfs/xfs_attr_leaf.c
index d920183b08a99..b0c8626e166ac 100644
--- a/fs/xfs/libxfs/xfs_attr_leaf.c
+++ b/fs/xfs/libxfs/xfs_attr_leaf.c
@@ -992,9 +992,8 @@ xfs_attr_shortform_allfit(
 			return 0;
 		if (be16_to_cpu(name_loc->valuelen) >= XFS_ATTR_SF_ENTSIZE_MAX)
 			return 0;
-		bytes += sizeof(struct xfs_attr_sf_entry) - 1
-				+ name_loc->namelen
-				+ be16_to_cpu(name_loc->valuelen);
+		bytes += XFS_ATTR_SF_ENTSIZE_BYNAME(name_loc->namelen,
+					be16_to_cpu(name_loc->valuelen));
 	}
 	if ((dp->i_mount->m_flags & XFS_MOUNT_ATTR2) &&
 	    (dp->i_df.if_format != XFS_DINODE_FMT_BTREE) &&
@@ -1036,10 +1035,8 @@ xfs_attr_shortform_verify(
 		 * struct xfs_attr_sf_entry has a variable length.
 		 * Check the fixed-offset parts of the structure are
 		 * within the data buffer.
-		 * xfs_attr_sf_entry is defined with a 1-byte variable
-		 * array at the end, so we must subtract that off.
 		 */
-		if (((char *)sfep + sizeof(*sfep) - 1) >= endp)
+		if (((char *)sfep + sizeof(*sfep)) >= endp)
 			return __this_address;
 
 		/* Don't allow names with known bad length. */
diff --git a/fs/xfs/libxfs/xfs_attr_sf.h b/fs/xfs/libxfs/xfs_attr_sf.h
index c4afb33079184..29934103ce559 100644
--- a/fs/xfs/libxfs/xfs_attr_sf.h
+++ b/fs/xfs/libxfs/xfs_attr_sf.h
@@ -27,11 +27,11 @@ typedef struct xfs_attr_sf_sort {
 } xfs_attr_sf_sort_t;
 
 #define XFS_ATTR_SF_ENTSIZE_BYNAME(nlen,vlen)	/* space name/value uses */ \
-	(((int)sizeof(struct xfs_attr_sf_entry)-1 + (nlen)+(vlen)))
+	((sizeof(struct xfs_attr_sf_entry) + (nlen) + (vlen)))
 #define XFS_ATTR_SF_ENTSIZE_MAX			/* max space for name&value */ \
 	((1 << (NBBY*(int)sizeof(uint8_t))) - 1)
 #define XFS_ATTR_SF_ENTSIZE(sfep)		/* space an entry uses */ \
-	((int)sizeof(struct xfs_attr_sf_entry)-1 + \
+	((int)sizeof(struct xfs_attr_sf_entry) + \
 		(sfep)->namelen+(sfep)->valuelen)
 #define XFS_ATTR_SF_NEXTENTRY(sfep)		/* next entry in struct */ \
 	((struct xfs_attr_sf_entry *)((char *)(sfep) + \
diff --git a/fs/xfs/libxfs/xfs_da_format.h b/fs/xfs/libxfs/xfs_da_format.h
index e708b714bf99d..b40a4e80f5ee6 100644
--- a/fs/xfs/libxfs/xfs_da_format.h
+++ b/fs/xfs/libxfs/xfs_da_format.h
@@ -589,7 +589,7 @@ 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 */
 };
 
-- 
2.26.2


  parent reply	other threads:[~2020-09-03 16:17 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-03 14:28 [PATCH v3 0/4] Clean up xfs_attr_sf_entry Carlos Maiolino
2020-09-03 14:28 ` [PATCH 1/4] xfs: remove typedef xfs_attr_sf_entry_t Carlos Maiolino
2020-09-06 21:52   ` Dave Chinner
2020-09-03 14:28 ` [PATCH 2/4] xfs: Remove typedef xfs_attr_shortform_t Carlos Maiolino
2020-09-06 21:53   ` Dave Chinner
2020-09-03 14:28 ` [PATCH v3 3/4] xfs: Use variable-size array for nameval in xfs_attr_sf_entry Carlos Maiolino
2020-09-03 14:32   ` Christoph Hellwig
2020-09-03 16:17   ` Carlos Maiolino [this message]
2020-09-03 16:18     ` [PATCH v4 4/4] xfs: Convert xfs_attr_sf macros to inline functions Carlos Maiolino
2020-09-04  7:53       ` Carlos Maiolino
2020-09-04 15:42         ` Darrick J. Wong
2020-09-04 15:41       ` Darrick J. Wong
2020-09-06 22:00       ` Dave Chinner
2020-09-07 11:33         ` Carlos Maiolino
2020-09-07 11:47       ` [PATCH V5 " Carlos Maiolino
2020-09-04 15:42     ` [PATCH v4 3/4] xfs: Use variable-size array for nameval in xfs_attr_sf_entry Darrick J. Wong
2020-09-06 21:53     ` Dave Chinner
2020-09-03 14:28 ` [PATCH v3 4/4] xfs: Convert xfs_attr_sf macros to inline functions Carlos Maiolino
2020-09-03 14:33   ` Christoph Hellwig
2020-09-03 16:05     ` Carlos Maiolino

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=20200903161724.85328-1-cmaiolino@redhat.com \
    --to=cmaiolino@redhat.com \
    --cc=linux-xfs@vger.kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.