From f78e14ee96da1c493f09d007d32141a5bf02f85d Mon Sep 17 00:00:00 2001
From: Jan Egil Ruud <janegil.ruud@micrchip.com>
Date: Thu, 1 Dec 2022 20:01:11 +0100
Subject: [PATCH] Revert "Skip chaching when size of memory is 0."

This reverts commit bb808e8d5fb438dcc736e511a0d54118cf7c2dfb.
---
 src/avrcache.c | 18 +++++++-----------
 1 file changed, 7 insertions(+), 11 deletions(-)

diff --git a/src/avrcache.c b/src/avrcache.c
index ebb8fd89..a0fa9082 100644
--- a/src/avrcache.c
+++ b/src/avrcache.c
@@ -343,7 +343,7 @@ int avr_flush_cache(const PROGRAMMER *pgm, const AVRPART *p) {
   for(size_t i = 0; i < sizeof mems/sizeof*mems; i++) {
     AVRMEM *mem = mems[i].mem;
     AVR_Cache *cp = mems[i].cp;
-    if(!mem || !cp->cont || !cp->size)
+    if(!mem || !cp->cont)
       continue;
 
     for(int pgno = 0, n = 0; n < cp->size; pgno++, n += cp->page_size) {
@@ -367,8 +367,6 @@ int avr_flush_cache(const PROGRAMMER *pgm, const AVRPART *p) {
     AVRMEM *mem = mems[i].mem;
     AVR_Cache *cp = mems[i].cp;
 
-    if(!cp->size)
-      continue;
     if(!cp->cont)           // Ensure cache is initialised from now on
       if(initCache(cp, pgm, p) < 0) {
         if(quell_progress)
@@ -421,7 +419,7 @@ int avr_flush_cache(const PROGRAMMER *pgm, const AVRPART *p) {
     for(size_t i = 0; i < sizeof mems/sizeof*mems; i++) {
       AVRMEM *mem = mems[i].mem;
       AVR_Cache *cp = mems[i].cp;
-      if(!mem || !cp->size)
+      if(!mem)
         continue;
 
       for(int pgno = 0, n = 0; n < cp->size; pgno++, n += cp->page_size)
@@ -435,7 +433,7 @@ int avr_flush_cache(const PROGRAMMER *pgm, const AVRPART *p) {
       for(size_t i = 0; i < sizeof mems/sizeof*mems; i++) {
         AVRMEM *mem = mems[i].mem;
         AVR_Cache *cp = mems[i].cp;
-        if(!mem || !cp->size)
+        if(!mem)
           continue;
 
         for(int ird = 0, pgno = 0, n = 0; n < cp->size; pgno++, n += cp->page_size) {
@@ -462,7 +460,7 @@ int avr_flush_cache(const PROGRAMMER *pgm, const AVRPART *p) {
     for(size_t i = 0; i < sizeof mems/sizeof*mems; i++) {
       AVRMEM *mem = mems[i].mem;
       AVR_Cache *cp = mems[i].cp;
-      if(!mem || !cp->size)
+      if(!mem)
         continue;
 
       if(mems[i].isflash) {     // flash
@@ -510,7 +508,7 @@ int avr_flush_cache(const PROGRAMMER *pgm, const AVRPART *p) {
   for(size_t i = 0; i < sizeof mems/sizeof*mems; i++) {
     AVRMEM *mem = mems[i].mem;
     AVR_Cache *cp = mems[i].cp;
-    if(!mem || !cp->size)
+    if(!mem)
       continue;
 
     for(int pgno = 0, n = 0; n < cp->size; pgno++, n += cp->page_size)
@@ -524,7 +522,7 @@ int avr_flush_cache(const PROGRAMMER *pgm, const AVRPART *p) {
     for(size_t i = 0; i < sizeof mems/sizeof*mems; i++) {
       AVRMEM *mem = mems[i].mem;
       AVR_Cache *cp = mems[i].cp;
-      if(!mem || !cp->cont || !cp->size)
+      if(!mem || !cp->cont)
         continue;
 
       for(int iwr = 0, pgno = 0, n = 0; n < cp->size; pgno++, n += cp->page_size) {
@@ -646,7 +644,7 @@ int avr_chip_erase_cached(const PROGRAMMER *pgm, const AVRPART *p) {
     AVRMEM *mem = mems[i].mem;
     AVR_Cache *cp = mems[i].cp;
 
-    if(!mem || !cp->size || !avr_has_paged_access(pgm, mem))
+    if(!mem || !avr_has_paged_access(pgm, mem))
       continue;
 
     if(!cp->cont)               // Init cache if needed
@@ -736,8 +734,6 @@ int avr_reset_cache(const PROGRAMMER *pgm, const AVRPART *p) {
 
   for(size_t i = 0; i < sizeof mems/sizeof*mems; i++) {
     AVR_Cache *cp = mems[i];
-    if(!cp->size)
-      continue;
     if(cp->cont)
       free(cp->cont);
     if(cp->copy)