FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.

» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > Redhat > Device-mapper Development

LinkBack Thread Tools
Old 10-21-2010, 02:18 PM
"Ulrich Windl"
Default /usr/src/linux/drivers/md/bitmap.c: strange rounding lines 855-875


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

/* 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),

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))


dm-devel mailing list

Thread Tools

All times are GMT. The time now is 07:28 AM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org