xfs
[Top] [All Lists]

[PATCH 30/37] libxfs: work around do_div() not handling 32 bit numerator

To: xfs@xxxxxxxxxxx
Subject: [PATCH 30/37] libxfs: work around do_div() not handling 32 bit numerators
From: Dave Chinner <david@xxxxxxxxxxxxx>
Date: Wed, 6 Nov 2013 12:07:16 +1100
Delivered-to: xfs@xxxxxxxxxxx
In-reply-to: <1383700043-32305-1-git-send-email-david@xxxxxxxxxxxxx>
References: <1383700043-32305-1-git-send-email-david@xxxxxxxxxxxxx>
From: Dave Chinner <dchinner@xxxxxxxxxx>

The libxfs dquot buffer code uses do_div() with a 32 bit numerator.
This gives incorrect results as do_div() passes the numerator by
reference as a pointer to a 64 bit value. Hence it does the division
using 32 bits of garbage gives the wrong result.

As per Christoph's suggestion, we can kill the usage of do_div()
here completely and just do the division directly, both in userspace
and kernel space.

Signed-off-by: Dave Chinner <dchinner@xxxxxxxxxx>
---
 libxfs/xfs_dquot_buf.c | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)

diff --git a/libxfs/xfs_dquot_buf.c b/libxfs/xfs_dquot_buf.c
index 620d9d3..6bbb0ff 100644
--- a/libxfs/xfs_dquot_buf.c
+++ b/libxfs/xfs_dquot_buf.c
@@ -23,13 +23,8 @@ xfs_calc_dquots_per_chunk(
        struct xfs_mount        *mp,
        unsigned int            nbblks) /* basic block units */
 {
-       unsigned int    ndquots;
-
        ASSERT(nbblks > 0);
-       ndquots = BBTOB(nbblks);
-       do_div(ndquots, sizeof(xfs_dqblk_t));
-
-       return ndquots;
+       return BBTOB(nbblks) / sizeof(xfs_dqblk_t);
 }
 
 /*
-- 
1.8.4.rc3

<Prev in Thread] Current Thread [Next in Thread>