diff mbox

[U-Boot,02/10] ext4: avoid calling ext4fs_mount() twice, which leaks

Message ID 1441425831-3441-2-git-send-email-swarren@wwwdotorg.org
State Accepted
Delegated to: Tom Rini
Headers show

Commit Message

Stephen Warren Sept. 5, 2015, 4:03 a.m. UTC
From: Stephen Warren <swarren@nvidia.com>

ext4_write_file() is only called from the "fs" layer, which calls both
ext4fs_mount() and ext4fs_close() before/after calling ext4_write_file().
Fix ext4_write_file() not to call ext4fs_mount() again, since the mount
operation malloc()s some RAM which is leaked when a second mount call
over-writes the pointer to that data, if no intervening close call is
made.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
---
 fs/ext4/ext4_write.c | 9 ---------
 1 file changed, 9 deletions(-)

Comments

Ɓukasz Majewski Sept. 8, 2015, 1:22 p.m. UTC | #1
Hi Stephen,

> From: Stephen Warren <swarren@nvidia.com>
> 
> ext4_write_file() is only called from the "fs" layer, which calls both
> ext4fs_mount() and ext4fs_close() before/after calling
> ext4_write_file(). Fix ext4_write_file() not to call ext4fs_mount()
> again, since the mount operation malloc()s some RAM which is leaked
> when a second mount call over-writes the pointer to that data, if no
> intervening close call is made.
> 
> Signed-off-by: Stephen Warren <swarren@nvidia.com>
> ---
>  fs/ext4/ext4_write.c | 9 ---------
>  1 file changed, 9 deletions(-)
> 
> diff --git a/fs/ext4/ext4_write.c b/fs/ext4/ext4_write.c
> index fbc4c4b1cc1a..fa67eb6a56b4 100644
> --- a/fs/ext4/ext4_write.c
> +++ b/fs/ext4/ext4_write.c
> @@ -986,26 +986,17 @@ int ext4_write_file(const char *filename, void
> *buf, loff_t offset, return -1;
>  	}
>  
> -	/* mount the filesystem */
> -	if (!ext4fs_mount(0)) {
> -		printf("** Error Bad ext4 partition **\n");
> -		goto fail;
> -	}
> -
>  	ret = ext4fs_write(filename, buf, len);
> -
>  	if (ret) {
>  		printf("** Error ext4fs_write() **\n");
>  		goto fail;
>  	}
> -	ext4fs_close();
>  
>  	*actwrite = len;
>  
>  	return 0;
>  
>  fail:
> -	ext4fs_close();
>  	*actwrite = 0;
>  
>  	return -1;


Acked-by: Lukasz Majewski <l.majewski@samsung.com>
Tested-by: Lukasz Majewski <l.majewski@samsung.com>

Test HW: Odroid XU3 - Exynos5433
[DFU tests]
Tom Rini Sept. 12, 2015, 12:51 p.m. UTC | #2
On Fri, Sep 04, 2015 at 10:03:43PM -0600, Stephen Warren wrote:

> From: Stephen Warren <swarren@nvidia.com>
> 
> ext4_write_file() is only called from the "fs" layer, which calls both
> ext4fs_mount() and ext4fs_close() before/after calling ext4_write_file().
> Fix ext4_write_file() not to call ext4fs_mount() again, since the mount
> operation malloc()s some RAM which is leaked when a second mount call
> over-writes the pointer to that data, if no intervening close call is
> made.
> 
> Signed-off-by: Stephen Warren <swarren@nvidia.com>
> Acked-by: Lukasz Majewski <l.majewski@samsung.com>
> Tested-by: Lukasz Majewski <l.majewski@samsung.com>

Applied to u-boot/master, thanks!
diff mbox

Patch

diff --git a/fs/ext4/ext4_write.c b/fs/ext4/ext4_write.c
index fbc4c4b1cc1a..fa67eb6a56b4 100644
--- a/fs/ext4/ext4_write.c
+++ b/fs/ext4/ext4_write.c
@@ -986,26 +986,17 @@  int ext4_write_file(const char *filename, void *buf, loff_t offset,
 		return -1;
 	}
 
-	/* mount the filesystem */
-	if (!ext4fs_mount(0)) {
-		printf("** Error Bad ext4 partition **\n");
-		goto fail;
-	}
-
 	ret = ext4fs_write(filename, buf, len);
-
 	if (ret) {
 		printf("** Error ext4fs_write() **\n");
 		goto fail;
 	}
-	ext4fs_close();
 
 	*actwrite = len;
 
 	return 0;
 
 fail:
-	ext4fs_close();
 	*actwrite = 0;
 
 	return -1;