diff mbox series

[V2] xfsprogs: xfs_fsr: Verify bulkstat version information in qsort's cmp()

Message ID 20210128052058.30328-1-chandanrlinux@gmail.com (mailing list archive)
State Accepted, archived
Headers show
Series [V2] xfsprogs: xfs_fsr: Verify bulkstat version information in qsort's cmp() | expand

Commit Message

Chandan Babu R Jan. 28, 2021, 5:20 a.m. UTC
This commit introduces a check to verify that correct bulkstat structures are
being processed by qsort's cmp() function.

Suggested-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Chandan Babu R <chandanrlinux@gmail.com>
---
V1 -> V2:
   1. Include XFS_BULKSTAT_VERSION_V1 as a possible bulkstat version
      number. 
   2. Fix coding style issue.
   
 fsr/xfs_fsr.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

Comments

Chaitanya Kulkarni Jan. 28, 2021, 6:56 a.m. UTC | #1
On 1/27/21 9:23 PM, Chandan Babu R wrote:
> This commit introduces a check to verify that correct bulkstat structures are
> being processed by qsort's cmp() function.
>
> Suggested-by: Darrick J. Wong <djwong@kernel.org>
> Signed-off-by: Chandan Babu R <chandanrlinux@gmail.com>

Looks good.

Reviewed-by: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
Darrick J. Wong Jan. 28, 2021, 5:36 p.m. UTC | #2
On Thu, Jan 28, 2021 at 10:50:58AM +0530, Chandan Babu R wrote:
> This commit introduces a check to verify that correct bulkstat structures are
> being processed by qsort's cmp() function.
> 
> Suggested-by: Darrick J. Wong <djwong@kernel.org>
> Signed-off-by: Chandan Babu R <chandanrlinux@gmail.com>
> ---

Looks good to me,
Reviewed-by: Darrick J. Wong <djwong@kernel.org>

--D

> V1 -> V2:
>    1. Include XFS_BULKSTAT_VERSION_V1 as a possible bulkstat version
>       number. 
>    2. Fix coding style issue.
>    
>  fsr/xfs_fsr.c | 11 +++++++++--
>  1 file changed, 9 insertions(+), 2 deletions(-)
> 
> diff --git a/fsr/xfs_fsr.c b/fsr/xfs_fsr.c
> index b885395e..6cf8bfb7 100644
> --- a/fsr/xfs_fsr.c
> +++ b/fsr/xfs_fsr.c
> @@ -582,8 +582,15 @@ fsrall_cleanup(int timeout)
>  static int
>  cmp(const void *s1, const void *s2)
>  {
> -	return( ((struct xfs_bulkstat *)s2)->bs_extents -
> -	        ((struct xfs_bulkstat *)s1)->bs_extents);
> +	const struct xfs_bulkstat	*bs1 = s1;
> +	const struct xfs_bulkstat	*bs2 = s2;
> +
> +	ASSERT((bs1->bs_version == XFS_BULKSTAT_VERSION_V1 &&
> +		bs2->bs_version == XFS_BULKSTAT_VERSION_V1) ||
> +		(bs1->bs_version == XFS_BULKSTAT_VERSION_V5 &&
> +		bs2->bs_version == XFS_BULKSTAT_VERSION_V5));
> +
> +	return (bs2->bs_extents - bs1->bs_extents);
>  }
>  
>  /*
> -- 
> 2.29.2
>
diff mbox series

Patch

diff --git a/fsr/xfs_fsr.c b/fsr/xfs_fsr.c
index b885395e..6cf8bfb7 100644
--- a/fsr/xfs_fsr.c
+++ b/fsr/xfs_fsr.c
@@ -582,8 +582,15 @@  fsrall_cleanup(int timeout)
 static int
 cmp(const void *s1, const void *s2)
 {
-	return( ((struct xfs_bulkstat *)s2)->bs_extents -
-	        ((struct xfs_bulkstat *)s1)->bs_extents);
+	const struct xfs_bulkstat	*bs1 = s1;
+	const struct xfs_bulkstat	*bs2 = s2;
+
+	ASSERT((bs1->bs_version == XFS_BULKSTAT_VERSION_V1 &&
+		bs2->bs_version == XFS_BULKSTAT_VERSION_V1) ||
+		(bs1->bs_version == XFS_BULKSTAT_VERSION_V5 &&
+		bs2->bs_version == XFS_BULKSTAT_VERSION_V5));
+
+	return (bs2->bs_extents - bs1->bs_extents);
 }
 
 /*