Re: [PATCH] Avoid truncating to 'long' in ALIGN() macro

From: Linus Torvalds
Date: Sun Nov 26 2006 - 15:16:07 EST




On Sun, 26 Nov 2006, Andrew Morton wrote:
>
> I'd be inclined to merge it for 2.6.19. Is everyone OK with it?

I'd _much_ rather make it more readable while at it. Something like this
instead, which has just _one_ "typeof" cast, and at least to me makes it a
lot more obvious what is going on (aka "to align something, use a mask
that is of the same type as the thing to be aligned..").

Maybe it's just me, but I prefer to separate out the actual "action" from
the "type fluff" around it.

Linus

---
diff --git a/include/linux/kernel.h b/include/linux/kernel.h
index 24b6111..b9b5e4b 100644
--- a/include/linux/kernel.h
+++ b/include/linux/kernel.h
@@ -30,8 +30,10 @@ extern const char linux_banner[];

#define STACK_MAGIC 0xdeadbeef

+#define ALIGN(x,a) __ALIGN_MASK(x,(typeof(x))(a)-1)
+#define __ALIGN_MASK(x,mask) (((x)+(mask))&~(mask))
+
#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
-#define ALIGN(x,a) (((x)+(a)-1UL)&~((a)-1UL))
#define FIELD_SIZEOF(t, f) (sizeof(((t*)0)->f))
#define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d))
#define roundup(x, y) ((((x) + ((y) - 1)) / (y)) * (y))
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/