public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
* [U-Boot] [PATCH 1/2] fs: fat: dynamically allocate memory for temporary buffer
@ 2019-01-17  6:52 tien.fong.chee at intel.com
  2019-01-17  6:52 ` [U-Boot] [PATCH 2/2] fs: fat: Reduce default max clustersize 64KiB from malloc pool tien.fong.chee at intel.com
  2019-01-18  6:26 ` [U-Boot] [PATCH 1/2] fs: fat: dynamically allocate memory for temporary buffer Marek Vasut
  0 siblings, 2 replies; 5+ messages in thread
From: tien.fong.chee at intel.com @ 2019-01-17  6:52 UTC (permalink / raw)
  To: u-boot

From: Stefan Agner <stefan.ag...@toradex.com>

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>
---
 fs/fat/fat.c |   19 +++++++++++++------
 1 files changed, 13 insertions(+), 6 deletions(-)

diff --git a/fs/fat/fat.c b/fs/fat/fat.c
index 8803fb4..aa4636d 100644
--- a/fs/fat/fat.c
+++ b/fs/fat/fat.c
@@ -307,9 +307,6 @@ get_cluster(fsdata *mydata, __u32 clustnum, __u8 *buffer, unsigned long size)
  * into 'buffer'.
  * 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,
 			__u8 *buffer, loff_t maxsize, loff_t *gotsize)
 {
@@ -320,7 +317,7 @@ static int get_contents(fsdata *mydata, dir_entry *dentptr, loff_t pos,
 	loff_t actsize;
 
 	*gotsize = 0;
-	debug("Filesize: %llu bytes\n", filesize);
+	debug("Filesize: %llu bytes, starting at pos %llu\n", filesize, pos);
 
 	if (pos >= filesize) {
 		debug("Read position past EOF: %llu\n", pos);
@@ -352,15 +349,25 @@ static int get_contents(fsdata *mydata, dir_entry *dentptr, loff_t pos,
 
 	/* align to beginning of next cluster if any */
 	if (pos) {
+		__u8 *tmp_buffer;
+
+		tmp_buffer = malloc_cache_aligned(MAX_CLUSTSIZE);
+		if (!tmp_buffer) {
+			debug("Error: allocating buffer\n");
+			return -ENOMEM;
+		}
+
 		actsize = min(filesize, (loff_t)bytesperclust);
-		if (get_cluster(mydata, curclust, get_contents_vfatname_block,
+		if (get_cluster(mydata, curclust, tmp_buffer,
 				(int)actsize) != 0) {
 			printf("Error reading cluster\n");
+			free(tmp_buffer);
 			return -1;
 		}
 		filesize -= actsize;
 		actsize -= pos;
-		memcpy(buffer, get_contents_vfatname_block + pos, actsize);
+		memcpy(buffer, tmp_buffer + pos, actsize);
+		free(tmp_buffer);
 		*gotsize += actsize;
 		if (!filesize)
 			return 0;
-- 
1.7.7.4

^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2019-01-24  6:28 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-01-17  6:52 [U-Boot] [PATCH 1/2] fs: fat: dynamically allocate memory for temporary buffer tien.fong.chee at intel.com
2019-01-17  6:52 ` [U-Boot] [PATCH 2/2] fs: fat: Reduce default max clustersize 64KiB from malloc pool tien.fong.chee at intel.com
2019-01-24  6:28   ` Chee, Tien Fong
2019-01-18  6:26 ` [U-Boot] [PATCH 1/2] fs: fat: dynamically allocate memory for temporary buffer Marek Vasut
2019-01-24  6:26   ` Chee, Tien Fong

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox