/usr/src/linux/drivers/md/bitmap.c: strange rounding lines 855-875

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

I just found this strange rounding code in /usr/src/linux/drivers/md/bitmap.c:

-----snip-------
        /* We need 4 bits per page, rounded up to a multiple of sizeof(unsigned
long) */
        bitmap->filemap_attr = kzalloc(
                (((num_pages*4/8)+sizeof(unsigned long))
                 /sizeof(unsigned long))
                *sizeof(unsigned long),
                GFP_KERNEL);
---------snip-----

IMHO, this is not rounding, it's just adding one extra "sizeof(unsigned long)":

Instead of using the pattern "((a + b) / b) * b" ==  (a/b + 1) * b == a + b the pattern "((a + b - 1) / b) * b" should be used. Even preferrable: define one macro that does it right, then use it. Example:
#define   ROUND_UP(n, g)  ((((n) + (g) - 1) / (g)) * (g))
#define   ROUND_DWN(n, g) (((n) / (g)) * (g))

Regards,
Ulrich



--
dm-devel mailing list
dm-devel@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/dm-devel


[Index of Archives]     [DM Crypt]     [Fedora Desktop]     [ATA RAID]     [Fedora Marketing]     [Fedora Packaging]     [Fedora SELinux]     [Yosemite Discussion]     [KDE Users]     [Fedora Docs]

  Powered by Linux