public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
* [U-Boot] [PATCH please test] fs/fat: reduce stack usage for SPL
@ 2017-09-17 13:38 Rob Clark
  2017-09-17 13:42 ` Tom Rini
  2017-09-22 13:02 ` [U-Boot] [PATCHv2] fs/fat: Reduce stack usage Tom Rini
  0 siblings, 2 replies; 5+ messages in thread
From: Rob Clark @ 2017-09-17 13:38 UTC (permalink / raw)
  To: u-boot

It seems like stack usage is a problem for SPL builds.  So move itrblock
off the stack.

Please test this and see if it helps w/ current issues with SPL builds.
Long term, I'm not sure if it is better to do this conditional on SPL
builds, or move to malloc()?  At any rate, if this fixes SPL builds it
should be a perfectly ok short term solution.

Signed-off-by: Rob Clark <robdclark@gmail.com>
---
 fs/fat/fat.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/fs/fat/fat.c b/fs/fat/fat.c
index f0284398b4..93140c9bcb 100644
--- a/fs/fat/fat.c
+++ b/fs/fat/fat.c
@@ -1031,10 +1031,12 @@ int file_fat_detectfs(void)
 	return 0;
 }
 
+static fat_itr itrblock;
+
 int fat_exists(const char *filename)
 {
 	fsdata fsdata;
-	fat_itr itrblock, *itr = &itrblock;
+	fat_itr *itr = &itrblock;
 	int ret;
 
 	ret = fat_itr_root(itr, &fsdata);
@@ -1049,7 +1051,7 @@ int fat_exists(const char *filename)
 int fat_size(const char *filename, loff_t *size)
 {
 	fsdata fsdata;
-	fat_itr itrblock, *itr = &itrblock;
+	fat_itr *itr = &itrblock;
 	int ret;
 
 	ret = fat_itr_root(itr, &fsdata);
@@ -1081,7 +1083,7 @@ int file_fat_read_at(const char *filename, loff_t pos, void *buffer,
 		     loff_t maxsize, loff_t *actread)
 {
 	fsdata fsdata;
-	fat_itr itrblock, *itr = &itrblock;
+	fat_itr *itr = &itrblock;
 	int ret;
 
 	ret = fat_itr_root(itr, &fsdata);
-- 
2.13.5

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

* [U-Boot] [PATCH please test] fs/fat: reduce stack usage for SPL
  2017-09-17 13:38 [U-Boot] [PATCH please test] fs/fat: reduce stack usage for SPL Rob Clark
@ 2017-09-17 13:42 ` Tom Rini
  2017-09-17 13:50   ` Adam Ford
  2017-09-22 13:02 ` [U-Boot] [PATCHv2] fs/fat: Reduce stack usage Tom Rini
  1 sibling, 1 reply; 5+ messages in thread
From: Tom Rini @ 2017-09-17 13:42 UTC (permalink / raw)
  To: u-boot

On Sun, Sep 17, 2017 at 09:38:04AM -0400, Rob Clark wrote:

> It seems like stack usage is a problem for SPL builds.  So move itrblock
> off the stack.
> 
> Please test this and see if it helps w/ current issues with SPL builds.
> Long term, I'm not sure if it is better to do this conditional on SPL
> builds, or move to malloc()?  At any rate, if this fixes SPL builds it
> should be a perfectly ok short term solution.
> 
> Signed-off-by: Rob Clark <robdclark@gmail.com>

Tested-by: Tom Rini <trini@konsulko.com>

Note that malloc would also be fine as we already have a dependency on
malloc, that's just not (but should be!) expressed in Kconfig, for FAT
support already.  Thanks!

-- 
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20170917/10264044/attachment.sig>

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

* [U-Boot] [PATCH please test] fs/fat: reduce stack usage for SPL
  2017-09-17 13:42 ` Tom Rini
@ 2017-09-17 13:50   ` Adam Ford
  0 siblings, 0 replies; 5+ messages in thread
From: Adam Ford @ 2017-09-17 13:50 UTC (permalink / raw)
  To: u-boot

On Sun, Sep 17, 2017 at 8:42 AM, Tom Rini <trini@konsulko.com> wrote:
> On Sun, Sep 17, 2017 at 09:38:04AM -0400, Rob Clark wrote:
>
>> It seems like stack usage is a problem for SPL builds.  So move itrblock
>> off the stack.
>>
>> Please test this and see if it helps w/ current issues with SPL builds.
>> Long term, I'm not sure if it is better to do this conditional on SPL
>> builds, or move to malloc()?  At any rate, if this fixes SPL builds it
>> should be a perfectly ok short term solution.
>>
>> Signed-off-by: Rob Clark <robdclark@gmail.com>
>
> Tested-by: Tom Rini <trini@konsulko.com>
>

This fixed the problem on the am3517-evm.  Thank you,

Tested-by: Adam Ford <aford173@gmail.com>

> Note that malloc would also be fine as we already have a dependency on
> malloc, that's just not (but should be!) expressed in Kconfig, for FAT
> support already.  Thanks!
>
> --
> Tom

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

* [U-Boot] [PATCHv2] fs/fat: Reduce stack usage
  2017-09-17 13:38 [U-Boot] [PATCH please test] fs/fat: reduce stack usage for SPL Rob Clark
  2017-09-17 13:42 ` Tom Rini
@ 2017-09-22 13:02 ` Tom Rini
  2017-09-22 14:20   ` Tom Rini
  1 sibling, 1 reply; 5+ messages in thread
From: Tom Rini @ 2017-09-22 13:02 UTC (permalink / raw)
  To: u-boot

We have limited stack in SPL builds.  Drop itrblock and move to
malloc/free of itr to move this off of the stack.  As part of this fix a
double-free issue in fat_size().

Signed-off-by: Tom Rini <trini@konsulko.com>
---
Rework to use malloc/free as moving this to a global overflows some SH
targets.

 fs/fat/fat.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/fs/fat/fat.c b/fs/fat/fat.c
index f0284398b41d..36a309c73c27 100644
--- a/fs/fat/fat.c
+++ b/fs/fat/fat.c
@@ -1034,24 +1034,27 @@ int file_fat_detectfs(void)
 int fat_exists(const char *filename)
 {
 	fsdata fsdata;
-	fat_itr itrblock, *itr = &itrblock;
+	fat_itr *itr;
 	int ret;
 
+	itr = malloc(sizeof(fat_itr));
 	ret = fat_itr_root(itr, &fsdata);
 	if (ret)
 		return 0;
 
 	ret = fat_itr_resolve(itr, filename, TYPE_ANY);
 	free(fsdata.fatbuf);
+	free(itr);
 	return ret == 0;
 }
 
 int fat_size(const char *filename, loff_t *size)
 {
 	fsdata fsdata;
-	fat_itr itrblock, *itr = &itrblock;
+	fat_itr *itr;
 	int ret;
 
+	itr = malloc(sizeof(fat_itr));
 	ret = fat_itr_root(itr, &fsdata);
 	if (ret)
 		return ret;
@@ -1072,8 +1075,9 @@ int fat_size(const char *filename, loff_t *size)
 	}
 
 	*size = FAT2CPU32(itr->dent->size);
-out:
 	free(fsdata.fatbuf);
+out:
+	free(itr);
 	return ret;
 }
 
@@ -1081,9 +1085,10 @@ int file_fat_read_at(const char *filename, loff_t pos, void *buffer,
 		     loff_t maxsize, loff_t *actread)
 {
 	fsdata fsdata;
-	fat_itr itrblock, *itr = &itrblock;
+	fat_itr *itr;
 	int ret;
 
+	itr = malloc(sizeof(fat_itr));
 	ret = fat_itr_root(itr, &fsdata);
 	if (ret)
 		return ret;
@@ -1097,6 +1102,7 @@ int file_fat_read_at(const char *filename, loff_t pos, void *buffer,
 
 out:
 	free(fsdata.fatbuf);
+	free(itr);
 	return ret;
 }
 
-- 
1.9.1

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

* [U-Boot] [PATCHv2] fs/fat: Reduce stack usage
  2017-09-22 13:02 ` [U-Boot] [PATCHv2] fs/fat: Reduce stack usage Tom Rini
@ 2017-09-22 14:20   ` Tom Rini
  0 siblings, 0 replies; 5+ messages in thread
From: Tom Rini @ 2017-09-22 14:20 UTC (permalink / raw)
  To: u-boot

On Fri, Sep 22, 2017 at 09:02:09AM -0400, Tom Rini wrote:

> We have limited stack in SPL builds.  Drop itrblock and move to
> malloc/free of itr to move this off of the stack.  As part of this fix a
> double-free issue in fat_size().
> 
> Signed-off-by: Tom Rini <trini@konsulko.com>

Applied to u-boot/master, thanks!

-- 
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20170922/111c395a/attachment.sig>

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

end of thread, other threads:[~2017-09-22 14:20 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-09-17 13:38 [U-Boot] [PATCH please test] fs/fat: reduce stack usage for SPL Rob Clark
2017-09-17 13:42 ` Tom Rini
2017-09-17 13:50   ` Adam Ford
2017-09-22 13:02 ` [U-Boot] [PATCHv2] fs/fat: Reduce stack usage Tom Rini
2017-09-22 14:20   ` Tom Rini

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