summaryrefslogtreecommitdiff
path: root/fs
diff options
context:
space:
mode:
authorTom Rini <trini@konsulko.com>2017-09-22 07:37:43 -0400
committerTom Rini <trini@konsulko.com>2017-09-22 07:37:43 -0400
commit2460098cffacd18729262e3ed36656e6943783ed (patch)
tree1c23bcec4fbcb250aeb5667aff8287751abafaea /fs
parent2dc5b553b9bcd701bd7abd60f99f407cb0c37762 (diff)
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.
Diffstat (limited to 'fs')
-rw-r--r--fs/fat/fat.c14
1 files changed, 10 insertions, 4 deletions
diff --git a/fs/fat/fat.c b/fs/fat/fat.c
index f0284398b4..36a309c73c 100644
--- a/fs/fat/fat.c
+++ b/fs/fat/fat.c
@@ -1034,24 +1034,27 @@ int file_fat_detectfs(void)
int fat_exists(const char *filename)
{
fsdata fsdata;
- fat_itr itrblock, *itr = &itrblock;
+ fat_itr *itr;
int ret;
+ itr = malloc(sizeof(fat_itr));
ret = fat_itr_root(itr, &fsdata);
if (ret)
return 0;
ret = fat_itr_resolve(itr, filename, TYPE_ANY);
free(fsdata.fatbuf);
+ free(itr);
return ret == 0;
}
int fat_size(const char *filename, loff_t *size)
{
fsdata fsdata;
- fat_itr itrblock, *itr = &itrblock;
+ fat_itr *itr;
int ret;
+ itr = malloc(sizeof(fat_itr));
ret = fat_itr_root(itr, &fsdata);
if (ret)
return ret;
@@ -1072,8 +1075,9 @@ int fat_size(const char *filename, loff_t *size)
}
*size = FAT2CPU32(itr->dent->size);
-out:
free(fsdata.fatbuf);
+out:
+ free(itr);
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)
{
fsdata fsdata;
- fat_itr itrblock, *itr = &itrblock;
+ fat_itr *itr;
int ret;
+ itr = malloc(sizeof(fat_itr));
ret = fat_itr_root(itr, &fsdata);
if (ret)
return ret;
@@ -1097,6 +1102,7 @@ int file_fat_read_at(const char *filename, loff_t pos, void *buffer,
out:
free(fsdata.fatbuf);
+ free(itr);
return ret;
}