usb: dwc3: switch to peripheral mode when exiting
[oweals/u-boot.git] / common / memsize.c
index 6dc4bb21b01e18e4079df7f3c8a06744dd0bc562..13b004778667f98d15b6f8dfbcbdea808ab0e0a8 100644 (file)
@@ -1,8 +1,7 @@
+// SPDX-License-Identifier: GPL-2.0+
 /*
  * (C) Copyright 2004
  * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
- *
- * SPDX-License-Identifier:    GPL-2.0+
  */
 
 #include <common.h>
@@ -27,7 +26,7 @@ DECLARE_GLOBAL_DATA_PTR;
 long get_ram_size(long *base, long maxsize)
 {
        volatile long *addr;
-       long           save[31];
+       long           save[BITS_PER_LONG - 1];
        long           save_base;
        long           cnt;
        long           val;
@@ -77,9 +76,16 @@ long get_ram_size(long *base, long maxsize)
                                addr  = base + cnt;
                                *addr = save[--i];
                        }
+                       /* warning: don't restore save_base in this case,
+                        * it is already done in the loop because
+                        * base and base+size share the same physical memory
+                        * and *base is saved after *(base+size) modification
+                        * in first loop
+                        */
                        return (size);
                }
        }
+       *base = save_base;
 
        return (maxsize);
 }