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

From: Tien Fong Chee <tien.fong.chee@intel.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>

---

changes for v3
- Removed the cast on actsize
---
 fs/fat/fat.c | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)

diff --git a/fs/fat/fat.c b/fs/fat/fat.c
index ecfa255..ea11250 100644
--- a/fs/fat/fat.c
+++ b/fs/fat/fat.c
@@ -306,9 +306,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)
 {
@@ -351,15 +348,24 @@ 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;
+
 		actsize = min(filesize, (loff_t)bytesperclust);
-		if (get_cluster(mydata, curclust, get_contents_vfatname_block,
-				(int)actsize) != 0) {
+		tmp_buffer = malloc_cache_aligned(actsize);
+		if (!tmp_buffer) {
+			debug("Error: allocating buffer\n");
+			return -ENOMEM;
+		}
+
+		if (get_cluster(mydata, curclust, tmp_buffer, 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;
-- 
2.2.0

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

end of thread, other threads:[~2019-02-25  3:33 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-02-11  6:56 [U-Boot] [PATCH v3 1/2] fs: fat: dynamically allocate memory for temporary buffer tien.fong.chee at intel.com
2019-02-11  6:56 ` [U-Boot] [PATCH v3 2/2] fs: fat: Reduce default max clustersize 64KiB from malloc pool tien.fong.chee at intel.com
2019-02-20  1:58   ` [U-Boot] [U-Boot, v3, " Tom Rini
2019-02-20  1:58 ` [U-Boot] [U-Boot, v3, 1/2] fs: fat: dynamically allocate memory for temporary buffer Tom Rini
2019-02-21  7:45   ` Michal Simek
2019-02-21  8:23     ` Chee, Tien Fong
2019-02-21  8:29       ` Alexander Graf
2019-02-21  8:40         ` Chee, Tien Fong
2019-02-21  8:41           ` Marek Vasut
2019-02-21  8:44             ` Alexander Graf
2019-02-21  8:49               ` Marek Vasut
2019-02-21  8:55                 ` Alexander Graf
2019-02-21  9:04                   ` Marek Vasut
2019-02-21 12:13                     ` Michal Simek
2019-02-21 12:51                       ` Marek Vasut
2019-02-21 13:39                         ` Adam Ford
2019-02-22  3:22     ` Tom Rini
2019-02-22  3:49       ` Chee, Tien Fong
2019-02-22  9:16         ` Michal Simek
2019-02-25  3:33           ` 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