diff mbox series

[U-Boot,2/2] fs: fat: Reduce default max clustersize 64KiB from malloc pool

Message ID 1547707948-21484-2-git-send-email-tien.fong.chee@intel.com
State Deferred
Delegated to: Tom Rini
Headers show
Series [U-Boot,1/2] fs: fat: dynamically allocate memory for temporary buffer | expand

Commit Message

Chee, Tien Fong Jan. 17, 2019, 6:52 a.m. UTC
From: Tien Fong Chee <tien.fong.chee@intel.com>

Release cluster block immediately when no longer use would help to reduce
64KiB memory allocated to the memory pool.

Signed-off-by: Tien Fong Chee <tien.fong.chee@intel.com>
---
 fs/fat/fat.c |   11 +++++++++--
 1 files changed, 9 insertions(+), 2 deletions(-)

Comments

Chee, Tien Fong Jan. 24, 2019, 6:28 a.m. UTC | #1
On Thu, 2019-01-17 at 14:52 +0800, tien.fong.chee@intel.com wrote:
> From: Tien Fong Chee <tien.fong.chee@intel.com>
> 
> Release cluster block immediately when no longer use would help to
> reduce
> 64KiB memory allocated to the memory pool.
> 
> Signed-off-by: Tien Fong Chee <tien.fong.chee@intel.com>
> ---
>  fs/fat/fat.c |   11 +++++++++--
>  1 files changed, 9 insertions(+), 2 deletions(-)
> 
> diff --git a/fs/fat/fat.c b/fs/fat/fat.c
> index aa4636d..5574620 100644
> --- a/fs/fat/fat.c
> +++ b/fs/fat/fat.c
> @@ -1153,12 +1153,19 @@ int file_fat_read_at(const char *filename,
> loff_t pos, void *buffer,
>  		goto out_free_both;
>  
>  	debug("reading %s at pos %llu\n", filename, pos);
> -	ret = get_contents(&fsdata, itr->dent, pos, buffer, maxsize,
> actread);
> +
> +	/* For saving default max clustersize memory allocated to
> malloc pool */
> +	dir_entry *dentptr = itr->dent;
> +
> +	free(itr);
I noticed msising of assignning NULL to itr after freeing it. Other
than this, any comment about this implementation to maximise the
reusable on reduce memory pool.
> +
> +	ret = get_contents(&fsdata, dentptr, pos, buffer, maxsize,
> actread);
>  
>  out_free_both:
>  	free(fsdata.fatbuf);
>  out_free_itr:
> -	free(itr);
> +	if (!itr)
> +		free(itr);
>  	return ret;
>  }
>
diff mbox series

Patch

diff --git a/fs/fat/fat.c b/fs/fat/fat.c
index aa4636d..5574620 100644
--- a/fs/fat/fat.c
+++ b/fs/fat/fat.c
@@ -1153,12 +1153,19 @@  int file_fat_read_at(const char *filename, loff_t pos, void *buffer,
 		goto out_free_both;
 
 	debug("reading %s at pos %llu\n", filename, pos);
-	ret = get_contents(&fsdata, itr->dent, pos, buffer, maxsize, actread);
+
+	/* For saving default max clustersize memory allocated to malloc pool */
+	dir_entry *dentptr = itr->dent;
+
+	free(itr);
+
+	ret = get_contents(&fsdata, dentptr, pos, buffer, maxsize, actread);
 
 out_free_both:
 	free(fsdata.fatbuf);
 out_free_itr:
-	free(itr);
+	if (!itr)
+		free(itr);
 	return ret;
 }