Skip to content

Commit be5a925

Browse files
authored
Merge pull request #55 from henrygab/patch-4
Use local variable to store partially-calculated size.
2 parents ae28f5b + b8a0551 commit be5a925

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

src/usb/uf2/ghostfat.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -124,35 +124,37 @@ static FAT_BootBlock const BootBlock = {
124124
static uint32_t current_flash_size(void)
125125
{
126126
static uint32_t flash_sz = 0;
127+
uint32_t result = flash_sz; // presumes atomic 32-bit read/write and static result
127128

128129
// only need to compute once
129-
if ( flash_sz == 0 )
130+
if ( result == 0 )
130131
{
131132
// return 1 block of 256 bytes
132133
if ( !bootloader_app_is_valid(DFU_BANK_0_REGION_START) )
133134
{
134-
flash_sz = 256;
135+
result = 256;
135136
}else
136137
{
137138
bootloader_settings_t const * boot_setting;
138139
bootloader_util_settings_get(&boot_setting);
139140

140-
flash_sz = boot_setting->bank_0_size;
141+
result = boot_setting->bank_0_size;
141142

142143
// Copy size must be multiple of 256 bytes
143144
// else we will got an issue copying current.uf2
144-
if (flash_sz & 0xff)
145+
if (result & 0xff)
145146
{
146-
flash_sz = (flash_sz & ~0xff) + 256;
147+
result = (result & ~0xff) + 256;
147148
}
148149

149150
// if bank0 size is not valid, happens when flashed with jlink
150151
// use maximum application size
151-
if ( (flash_sz == 0) || (flash_sz == 0xFFFFFFFFUL) )
152+
if ( (result == 0) || (result == 0xFFFFFFFFUL) )
152153
{
153-
flash_sz = FLASH_SIZE;
154+
result = FLASH_SIZE;
154155
}
155156
}
157+
flash_sz = result; // presumes atomic 32-bit read/write and static result
156158
}
157159

158160
return flash_sz;

0 commit comments

Comments
 (0)