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.
I have just changed this code since the division is invalid on 32-bit
hardware. I'm guessing that the issue still remains.
The code now looks like:
nblocks = bmp->db_agfree[agno];
range_cnt = nblocks;
do_div(range_cnt, (int)minlen);
range_cnt = min(range_cnt + 1, 32 * 1024);
range_cnt is still declared as an int.
Dang. I just realized how broken my fix is. range_cnt isn't 64 bits so
the do_div doesn't make sense anymore. I'll come up with a better fix
for this, and take into account the possibility of negative values.
> 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
Thanks,
Shaggy
------------------------------------------------------------------------------
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