--- zzzz-none-000/linux-4.4.271/drivers/mtd/redboot.c 2021-06-03 06:22:09.000000000 +0000 +++ dakota-7530ac-750/linux-4.4.271/drivers/mtd/redboot.c 2023-01-11 09:25:42.000000000 +0000 @@ -76,12 +76,18 @@ static char nullstring[] = "unallocated"; #endif + buf = vmalloc(master->erasesize); + if (!buf) + return -ENOMEM; + + restart: if ( directory < 0 ) { offset = master->size + directory * master->erasesize; while (mtd_block_isbad(master, offset)) { if (!offset) { nogood: printk(KERN_NOTICE "Failed to find a non-bad block to check for RedBoot partition table\n"); + vfree(buf); return -EIO; } offset -= master->erasesize; @@ -94,10 +100,6 @@ goto nogood; } } - buf = vmalloc(master->erasesize); - - if (!buf) - return -ENOMEM; printk(KERN_NOTICE "Searching for RedBoot partition table in %s at offset 0x%lx\n", master->name, offset); @@ -170,6 +172,11 @@ } if (i == numslots) { /* Didn't find it */ + if (offset + master->erasesize < master->size) { + /* not at the end of the flash yet, maybe next block :) */ + directory++; + goto restart; + } printk(KERN_NOTICE "No RedBoot partition table detected in %s\n", master->name); ret = 0; @@ -265,14 +272,21 @@ #endif names += strlen(names)+1; -#ifdef CONFIG_MTD_REDBOOT_PARTS_UNALLOCATED if(fl->next && fl->img->flash_base + fl->img->size + master->erasesize <= fl->next->img->flash_base) { - i++; - parts[i].offset = parts[i-1].size + parts[i-1].offset; - parts[i].size = fl->next->img->flash_base - parts[i].offset; - parts[i].name = nullname; - } + if (!strcmp(parts[i].name, "rootfs")) { + parts[i].size = fl->next->img->flash_base; + parts[i].size &= ~(master->erasesize - 1); + parts[i].size -= parts[i].offset; +#ifdef CONFIG_MTD_REDBOOT_PARTS_UNALLOCATED + nrparts--; + } else { + i++; + parts[i].offset = parts[i-1].size + parts[i-1].offset; + parts[i].size = fl->next->img->flash_base - parts[i].offset; + parts[i].name = nullname; #endif + } + } tmp_fl = fl; fl = fl->next; kfree(tmp_fl);