From: Ben Dooks <ben-mtd@fluff.org>
To: linux-mtd@lists.infradead.org
Cc: ben@fluff.org
Subject: Incorrect word calculation in some configs
Date: Tue, 21 Sep 2004 00:40:02 +0100 [thread overview]
Message-ID: <20040920234002.GA17073@home.fluff.org> (raw)
There seems to be a problem with map_words() if there are
types longer than `unsigned long` enabled at the same time
as anything shorted than an `unsigned long`
Tested on an EB2410ITX (ARM9 SoC)
Patch against 2.6.9-rc2 patched with 19th September CVS
Signed-off-by: Ben Dooks <ben-mtd@fluff.org>
--- linux-2.6.9-rc2-bk6-mtd20040919/include/linux/mtd/map.h 2004-09-20 13:02:46.000000000 +0100
+++ linux-2.6.9-rc2-bk6-mtd20040919-work/include/linux/mtd/map.h 2004-09-21 00:25:47.000000000 +0100
@@ -56,6 +56,11 @@
#define map_bankwidth_is_4(map) (0)
#endif
+/* ensure we never evaluate anything shorted than an unsigned long
+ * to zero, and ensure we'll never miss the end of an comparison (bjd) */
+
+#define map_calc_words(map) ((map_bankwidth(map) + (sizeof(unsigned long)-1))/ sizeof(unsigned long))
+
#ifdef CONFIG_MTD_MAP_BANK_WIDTH_8
# ifdef map_bankwidth
# undef map_bankwidth
@@ -64,12 +69,12 @@
# undef map_bankwidth_is_large
# define map_bankwidth_is_large(map) (map_bankwidth(map) > BITS_PER_LONG/8)
# undef map_words
-# define map_words(map) (map_bankwidth(map) / sizeof(unsigned long))
+# define map_words(map) map_calc_words(map)
# endif
# else
# define map_bankwidth(map) 8
# define map_bankwidth_is_large(map) (BITS_PER_LONG < 64)
-# define map_words(map) (map_bankwidth(map) / sizeof(unsigned long))
+# define map_words(map) map_calc_words(map)
# endif
#define map_bankwidth_is_8(map) (map_bankwidth(map) == 8)
#undef MAX_MAP_BANKWIDTH
@@ -85,11 +90,11 @@
# undef map_bankwidth_is_large
# define map_bankwidth_is_large(map) (map_bankwidth(map) > BITS_PER_LONG/8)
# undef map_words
-# define map_words(map) (map_bankwidth(map) / sizeof(unsigned long))
+# define map_words(map) map_calc_words(map)
# else
# define map_bankwidth(map) 16
# define map_bankwidth_is_large(map) (1)
-# define map_words(map) (map_bankwidth(map) / sizeof(unsigned long))
+# define map_words(map) map_calc_words(map)
# endif
#define map_bankwidth_is_16(map) (map_bankwidth(map) == 16)
#undef MAX_MAP_BANKWIDTH
@@ -105,11 +110,11 @@
# undef map_bankwidth_is_large
# define map_bankwidth_is_large(map) (map_bankwidth(map) > BITS_PER_LONG/8)
# undef map_words
-# define map_words(map) (map_bankwidth(map) / sizeof(unsigned long))
+# define map_words(map) map_calc_words(map)
# else
# define map_bankwidth(map) 32
# define map_bankwidth_is_large(map) (1)
-# define map_words(map) (map_bankwidth(map) / sizeof(unsigned long))
+# define map_words(map) map_calc_words(map)
# endif
#define map_bankwidth_is_32(map) (map_bankwidth(map) == 32)
#undef MAX_MAP_BANKWIDTH
reply other threads:[~2004-09-20 23:40 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20040920234002.GA17073@home.fluff.org \
--to=ben-mtd@fluff.org \
--cc=ben@fluff.org \
--cc=linux-mtd@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox