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

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



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




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