[PATCH] Do not oops when configured flash size is less then chip size
David Woodhouse
dwmw2 at infradead.org
Sat May 13 07:22:42 EDT 2006
On Thu, 2006-05-11 at 16:52 +0100, David Vrabel wrote:
> This sounds like a valid, if unlikely, board configuration. e.g., a
> board with chips fitted that are larger than the chip-select memory
> window.
>
> It might be better to pretend such configuration is a single chip
> that's smaller than it physically is.
Yes, I agree.
> Maybe something as simple as:
>
> /* there's at least one chip present */
> max_chips = max(map->size >> cfi.chipshift, 1);
>
> ?
You also need to reduce mtd->size after you've done the probe.
And while we're at it, we'll slap Deepak around a little bit and stop
using byte arrays with the Linux bitops.
Please could you test this for me?
diff --git a/drivers/mtd/chips/gen_probe.c b/drivers/mtd/chips/gen_probe.c
index 9b252d2..9915ab8 100644
--- a/drivers/mtd/chips/gen_probe.c
+++ b/drivers/mtd/chips/gen_probe.c
@@ -37,8 +37,14 @@ struct mtd_info *mtd_do_chip_probe(struc
if (!mtd)
mtd = check_cmd_set(map, 0); /* Then the secondary */
- if (mtd)
+ if (mtd) {
+ if (mtd->size > map->size) {
+ printk(KERN_WARNING "Reducing visibility of %dKiB chip to %dKiB\n",
+ mtd->size >> 10, map->size >> 10);
+ mtd->size = map->size;
+ }
return mtd;
+ }
printk(KERN_WARNING"gen_probe: No supported Vendor Command Set found\n");
@@ -100,7 +106,12 @@ #endif
* Align bitmap storage size to full byte.
*/
max_chips = map->size >> cfi.chipshift;
- mapsize = (max_chips / 8) + ((max_chips % 8) ? 1 : 0);
+ if (!max_chips) {
+ printk(KERN_WARNING "NOR chip too large to fit in mapping. Attempting to cope...\n");
+ max_chips = 1;
+ }
+
+ mapsize = (max_chips + BITS_PER_LONG-1) / BITS_PER_LONG;
chip_map = kmalloc(mapsize, GFP_KERNEL);
if (!chip_map) {
printk(KERN_WARNING "%s: kmalloc failed for CFI chip map\n", map->name);
--
dwmw2
More information about the linux-mtd
mailing list