mirror of
https://xff.cz/git/u-boot/
synced 2025-09-29 14:31:16 +02:00
fs: fat: dynamically allocate memory for temporary buffer
Drop the statically allocated get_contents_vfatname_block and dynamically allocate a buffer only if required. This saves 64KiB of memory. Signed-off-by: Stefan Agner <stefan.ag...@toradex.com> Signed-off-by: Tien Fong Chee <tien.fong.chee@intel.com>
This commit is contained in:
18
fs/fat/fat.c
18
fs/fat/fat.c
@@ -306,9 +306,6 @@ get_cluster(fsdata *mydata, __u32 clustnum, __u8 *buffer, unsigned long size)
|
|||||||
* into 'buffer'.
|
* into 'buffer'.
|
||||||
* Update the number of bytes read in *gotsize or return -1 on fatal errors.
|
* Update the number of bytes read in *gotsize or return -1 on fatal errors.
|
||||||
*/
|
*/
|
||||||
__u8 get_contents_vfatname_block[MAX_CLUSTSIZE]
|
|
||||||
__aligned(ARCH_DMA_MINALIGN);
|
|
||||||
|
|
||||||
static int get_contents(fsdata *mydata, dir_entry *dentptr, loff_t pos,
|
static int get_contents(fsdata *mydata, dir_entry *dentptr, loff_t pos,
|
||||||
__u8 *buffer, loff_t maxsize, loff_t *gotsize)
|
__u8 *buffer, loff_t maxsize, loff_t *gotsize)
|
||||||
{
|
{
|
||||||
@@ -351,15 +348,24 @@ static int get_contents(fsdata *mydata, dir_entry *dentptr, loff_t pos,
|
|||||||
|
|
||||||
/* align to beginning of next cluster if any */
|
/* align to beginning of next cluster if any */
|
||||||
if (pos) {
|
if (pos) {
|
||||||
|
__u8 *tmp_buffer;
|
||||||
|
|
||||||
actsize = min(filesize, (loff_t)bytesperclust);
|
actsize = min(filesize, (loff_t)bytesperclust);
|
||||||
if (get_cluster(mydata, curclust, get_contents_vfatname_block,
|
tmp_buffer = malloc_cache_aligned(actsize);
|
||||||
(int)actsize) != 0) {
|
if (!tmp_buffer) {
|
||||||
|
debug("Error: allocating buffer\n");
|
||||||
|
return -ENOMEM;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (get_cluster(mydata, curclust, tmp_buffer, actsize) != 0) {
|
||||||
printf("Error reading cluster\n");
|
printf("Error reading cluster\n");
|
||||||
|
free(tmp_buffer);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
filesize -= actsize;
|
filesize -= actsize;
|
||||||
actsize -= pos;
|
actsize -= pos;
|
||||||
memcpy(buffer, get_contents_vfatname_block + pos, actsize);
|
memcpy(buffer, tmp_buffer + pos, actsize);
|
||||||
|
free(tmp_buffer);
|
||||||
*gotsize += actsize;
|
*gotsize += actsize;
|
||||||
if (!filesize)
|
if (!filesize)
|
||||||
return 0;
|
return 0;
|
||||||
|
Reference in New Issue
Block a user