On 09/18/2012 01:57 AM, Dan Carpenter wrote:
> Hello Tino Reichardt,
> 
> The patch 0d59722ea777: "fs/jfs: TRIM support for JFS Filesystem"
> from Aug 29, 2012, leads to the following static checker warning:
> fs/jfs/jfs_dmap.c:1650 dbDiscardAG()
>        warn: check 'range_cnt' for negative values
> 
>   1648          nblocks = bmp->db_agfree[agno];
>   1649          range_cnt = min_t(int, range_cnt, nblocks / minlen + 1);
>                                   ^^^
> Could we make this unsigned?  The caller checks that minlen is >= 1 and
> probably someone checks nblocks as well, but it's annoying to have to
> audit this.

Dan, the following patch applies on top of the Sept. 18 linux-next
build or git://github.com/kleikamp/linux-shaggy.git jfs-next

> 
>   1650          totrim = kmalloc(sizeof(struct range2trim) * range_cnt, 
> GFP_NOFS);
>   1651          if (totrim == NULL) {
>   1652                  jfs_error(bmp->db_ipbmap->i_sb,
>   1653                            "dbDiscardAG: no memory for trim array");
>   1654                  IWRITE_UNLOCK(ipbmap);
>   1655                  return 0;
>   1656          }
> 
> regards,
> dan carpenter

jfs: Fix do_div precision in commit b40c2e66

In a hasty fix to replace a 64-bit division with do_div, I
unintentionally assigned the divisor to a 32-bit variable.

Signed-off-by: Dave Kleikamp <[email protected]>
Cc: Tino Reichardt <[email protected]>
---
 fs/jfs/jfs_dmap.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/fs/jfs/jfs_dmap.c b/fs/jfs/jfs_dmap.c
index 174feb6..9a55f53 100644
--- a/fs/jfs/jfs_dmap.c
+++ b/fs/jfs/jfs_dmap.c
@@ -1641,14 +1641,15 @@ s64 dbDiscardAG(struct inode *ip, int agno, s64 minlen)
 
        /* max blkno / nblocks pairs to trim */
        int count = 0, range_cnt;
+       u64 max_ranges;
 
        /* prevent others from writing new stuff here, while trimming */
        IWRITE_LOCK(ipbmap, RDWRLOCK_DMAP);
 
        nblocks = bmp->db_agfree[agno];
-       range_cnt = nblocks;
-       do_div(range_cnt, (int)minlen);
-       range_cnt = min(range_cnt + 1, 32 * 1024);
+       max_ranges = nblocks;
+       do_div(max_ranges, minlen);
+       range_cnt = min_t(u64, max_ranges + 1, 32 * 1024);
        totrim = kmalloc(sizeof(struct range2trim) * range_cnt, GFP_NOFS);
        if (totrim == NULL) {
                jfs_error(bmp->db_ipbmap->i_sb,
-- 
1.7.12


------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Jfs-discussion mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jfs-discussion

Reply via email to