fritz-tools: fritz_tffs_nand: get rid of struct tffs_sectors

This doesn't help and "[0]" gets in the way of bounds checks.

Signed-off-by: Andre Heider <a.heider@gmail.com>
This commit is contained in:
Andre Heider 2021-12-15 12:21:48 +01:00 committed by David Bauer
parent 4e2d5f4f9f
commit 902378dc87

View File

@ -73,21 +73,17 @@ static uint8_t readbuf[TFFS_SECTOR_SIZE];
static uint8_t oobbuf[TFFS_SECTOR_OOB_SIZE]; static uint8_t oobbuf[TFFS_SECTOR_OOB_SIZE];
static uint32_t blocksize; static uint32_t blocksize;
static int mtdfd; static int mtdfd;
struct tffs_sectors *sectors; static uint32_t num_sectors;
static uint8_t *sectors;
struct tffs_sectors {
uint32_t num_sectors;
uint8_t sectors[0];
};
static inline void sector_mark_bad(int num) static inline void sector_mark_bad(int num)
{ {
sectors->sectors[num / 8] &= ~(0x80 >> (num % 8)); sectors[num / 8] &= ~(0x80 >> (num % 8));
}; };
static inline uint8_t sector_get_good(int num) static inline uint8_t sector_get_good(int num)
{ {
return sectors->sectors[num / 8] & 0x80 >> (num % 8); return sectors[num / 8] & 0x80 >> (num % 8);
}; };
struct tffs_entry_segment { struct tffs_entry_segment {
@ -176,7 +172,7 @@ static int find_entry(uint32_t id, struct tffs_entry *entry)
off_t pos = 0; off_t pos = 0;
uint8_t block_end = 0; uint8_t block_end = 0;
for (uint32_t sector = 0; sector < sectors->num_sectors; sector++, pos += TFFS_SECTOR_SIZE) { for (uint32_t sector = 0; sector < num_sectors; sector++, pos += TFFS_SECTOR_SIZE) {
if (block_end) { if (block_end) {
if (pos % blocksize == 0) { if (pos % blocksize == 0) {
block_end = 0; block_end = 0;
@ -417,13 +413,13 @@ static int scan_mtd(void)
blocksize = info.erasesize; blocksize = info.erasesize;
sectors = malloc(sizeof(*sectors) + (info.size / TFFS_SECTOR_SIZE + 7) / 8); num_sectors = info.size / TFFS_SECTOR_SIZE;
sectors = malloc((num_sectors + 7) / 8);
if (sectors == NULL) { if (sectors == NULL) {
fprintf(stderr, "ERROR: memory allocation failed!\n"); fprintf(stderr, "ERROR: memory allocation failed!\n");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
sectors->num_sectors = info.size / TFFS_SECTOR_SIZE; memset(sectors, 0xff, (num_sectors + 7) / 8);
memset(sectors->sectors, 0xff, (info.size / TFFS_SECTOR_SIZE + 7) / 8);
uint32_t sector = 0, valid_blocks = 0; uint32_t sector = 0, valid_blocks = 0;
uint8_t block_ok = 0; uint8_t block_ok = 0;