mirror of
https://github.com/Fishwaldo/u-boot.git
synced 2025-03-17 20:51:39 +00:00
fs/fat: Reduce stack usage
We have limited stack in SPL builds. Drop itrblock and move to malloc/free of itr to move this off of the stack. As part of this fix a double-free issue in fat_size(). Signed-off-by: Tom Rini <trini@konsulko.com> --- Rework to use malloc/free as moving this to a global overflows some SH targets.
This commit is contained in:
parent
2dc5b553b9
commit
2460098cff
1 changed files with 10 additions and 4 deletions
14
fs/fat/fat.c
14
fs/fat/fat.c
|
@ -1034,24 +1034,27 @@ int file_fat_detectfs(void)
|
||||||
int fat_exists(const char *filename)
|
int fat_exists(const char *filename)
|
||||||
{
|
{
|
||||||
fsdata fsdata;
|
fsdata fsdata;
|
||||||
fat_itr itrblock, *itr = &itrblock;
|
fat_itr *itr;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
|
itr = malloc(sizeof(fat_itr));
|
||||||
ret = fat_itr_root(itr, &fsdata);
|
ret = fat_itr_root(itr, &fsdata);
|
||||||
if (ret)
|
if (ret)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
ret = fat_itr_resolve(itr, filename, TYPE_ANY);
|
ret = fat_itr_resolve(itr, filename, TYPE_ANY);
|
||||||
free(fsdata.fatbuf);
|
free(fsdata.fatbuf);
|
||||||
|
free(itr);
|
||||||
return ret == 0;
|
return ret == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int fat_size(const char *filename, loff_t *size)
|
int fat_size(const char *filename, loff_t *size)
|
||||||
{
|
{
|
||||||
fsdata fsdata;
|
fsdata fsdata;
|
||||||
fat_itr itrblock, *itr = &itrblock;
|
fat_itr *itr;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
|
itr = malloc(sizeof(fat_itr));
|
||||||
ret = fat_itr_root(itr, &fsdata);
|
ret = fat_itr_root(itr, &fsdata);
|
||||||
if (ret)
|
if (ret)
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -1072,8 +1075,9 @@ int fat_size(const char *filename, loff_t *size)
|
||||||
}
|
}
|
||||||
|
|
||||||
*size = FAT2CPU32(itr->dent->size);
|
*size = FAT2CPU32(itr->dent->size);
|
||||||
out:
|
|
||||||
free(fsdata.fatbuf);
|
free(fsdata.fatbuf);
|
||||||
|
out:
|
||||||
|
free(itr);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1081,9 +1085,10 @@ int file_fat_read_at(const char *filename, loff_t pos, void *buffer,
|
||||||
loff_t maxsize, loff_t *actread)
|
loff_t maxsize, loff_t *actread)
|
||||||
{
|
{
|
||||||
fsdata fsdata;
|
fsdata fsdata;
|
||||||
fat_itr itrblock, *itr = &itrblock;
|
fat_itr *itr;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
|
itr = malloc(sizeof(fat_itr));
|
||||||
ret = fat_itr_root(itr, &fsdata);
|
ret = fat_itr_root(itr, &fsdata);
|
||||||
if (ret)
|
if (ret)
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -1097,6 +1102,7 @@ int file_fat_read_at(const char *filename, loff_t pos, void *buffer,
|
||||||
|
|
||||||
out:
|
out:
|
||||||
free(fsdata.fatbuf);
|
free(fsdata.fatbuf);
|
||||||
|
free(itr);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue