* [U-Boot] [PATCH] malloc: Use malloc simple before malloc is fully initialized in memalign() @ 2018-05-18 10:03 Ley Foon Tan 2018-05-18 8:21 ` Marek Vasut ` (2 more replies) 0 siblings, 3 replies; 12+ messages in thread From: Ley Foon Tan @ 2018-05-18 10:03 UTC (permalink / raw) To: u-boot Follow implementation in mALLOc(). Check GD_FLG_FULL_MALLOC_INIT flag and use malloc_simple if GD_FLG_FULL_MALLOC_INIT is unset. Adjust the malloc bytes to align with the requested alignment. The original memalign() function will access mchunkptr struct to adjust the alignment if there is misalignment happen, but mchunkptr struct is not being initialized before full malloc is initialized. This cause the system crash. Signed-off-by: Ley Foon Tan <ley.foon.tan@intel.com> --- common/dlmalloc.c | 7 +++++++ 1 files changed, 7 insertions(+), 0 deletions(-) diff --git a/common/dlmalloc.c b/common/dlmalloc.c index b395eef..edaad29 100644 --- a/common/dlmalloc.c +++ b/common/dlmalloc.c @@ -1891,6 +1891,13 @@ Void_t* mEMALIGn(alignment, bytes) size_t alignment; size_t bytes; if ((long)bytes < 0) return NULL; +#if CONFIG_VAL(SYS_MALLOC_F_LEN) + if (!(gd->flags & GD_FLG_FULL_MALLOC_INIT)) { + nb = roundup(bytes, alignment); + return malloc_simple(nb); + } +#endif + /* If need less alignment than we give anyway, just relay to malloc */ if (alignment <= MALLOC_ALIGNMENT) return mALLOc(bytes); -- 1.7.1 ^ permalink raw reply related [flat|nested] 12+ messages in thread
* [U-Boot] [PATCH] malloc: Use malloc simple before malloc is fully initialized in memalign() 2018-05-18 10:03 [U-Boot] [PATCH] malloc: Use malloc simple before malloc is fully initialized in memalign() Ley Foon Tan @ 2018-05-18 8:21 ` Marek Vasut 2018-05-19 14:37 ` Simon Glass 2018-05-28 19:13 ` [U-Boot] " Tom Rini 2 siblings, 0 replies; 12+ messages in thread From: Marek Vasut @ 2018-05-18 8:21 UTC (permalink / raw) To: u-boot On 05/18/2018 12:03 PM, Ley Foon Tan wrote: > Follow implementation in mALLOc(). Check GD_FLG_FULL_MALLOC_INIT flag and use > malloc_simple if GD_FLG_FULL_MALLOC_INIT is unset. Adjust the malloc bytes > to align with the requested alignment. > > The original memalign() function will access mchunkptr struct to adjust the > alignment if there is misalignment happen, but mchunkptr struct is not being > initialized before full malloc is initialized. This cause the system crash. > > Signed-off-by: Ley Foon Tan <ley.foon.tan@intel.com> Reviewed-by: Marek Vasut <marek.vasut@gmail.com> -- Best regards, Marek Vasut ^ permalink raw reply [flat|nested] 12+ messages in thread
* [U-Boot] [PATCH] malloc: Use malloc simple before malloc is fully initialized in memalign() 2018-05-18 10:03 [U-Boot] [PATCH] malloc: Use malloc simple before malloc is fully initialized in memalign() Ley Foon Tan 2018-05-18 8:21 ` Marek Vasut @ 2018-05-19 14:37 ` Simon Glass 2018-05-23 6:32 ` Ley Foon Tan 2018-05-28 19:13 ` [U-Boot] " Tom Rini 2 siblings, 1 reply; 12+ messages in thread From: Simon Glass @ 2018-05-19 14:37 UTC (permalink / raw) To: u-boot Hi Ley, On 18 May 2018 at 04:03, Ley Foon Tan <ley.foon.tan@intel.com> wrote: > Follow implementation in mALLOc(). Check GD_FLG_FULL_MALLOC_INIT flag and use > malloc_simple if GD_FLG_FULL_MALLOC_INIT is unset. Adjust the malloc bytes > to align with the requested alignment. > > The original memalign() function will access mchunkptr struct to adjust the > alignment if there is misalignment happen, but mchunkptr struct is not being > initialized before full malloc is initialized. This cause the system crash. > > Signed-off-by: Ley Foon Tan <ley.foon.tan@intel.com> > --- > common/dlmalloc.c | 7 +++++++ > 1 files changed, 7 insertions(+), 0 deletions(-) > > diff --git a/common/dlmalloc.c b/common/dlmalloc.c > index b395eef..edaad29 100644 > --- a/common/dlmalloc.c > +++ b/common/dlmalloc.c > @@ -1891,6 +1891,13 @@ Void_t* mEMALIGn(alignment, bytes) size_t alignment; size_t bytes; > > if ((long)bytes < 0) return NULL; > > +#if CONFIG_VAL(SYS_MALLOC_F_LEN) How about: if (IS_ENABLED(CONFIG_SYS_MALLOC_F)) ? > + if (!(gd->flags & GD_FLG_FULL_MALLOC_INIT)) { > + nb = roundup(bytes, alignment); > + return malloc_simple(nb); > + } > +#endif > + > /* If need less alignment than we give anyway, just relay to malloc */ > > if (alignment <= MALLOC_ALIGNMENT) return mALLOc(bytes); > -- > 1.7.1 > Regards, Simon ^ permalink raw reply [flat|nested] 12+ messages in thread
* [U-Boot] [PATCH] malloc: Use malloc simple before malloc is fully initialized in memalign() 2018-05-19 14:37 ` Simon Glass @ 2018-05-23 6:32 ` Ley Foon Tan 2018-05-23 16:33 ` Simon Glass 0 siblings, 1 reply; 12+ messages in thread From: Ley Foon Tan @ 2018-05-23 6:32 UTC (permalink / raw) To: u-boot On Sat, May 19, 2018 at 10:37 PM, Simon Glass <sjg@chromium.org> wrote: > Hi Ley, > > On 18 May 2018 at 04:03, Ley Foon Tan <ley.foon.tan@intel.com> wrote: >> Follow implementation in mALLOc(). Check GD_FLG_FULL_MALLOC_INIT flag and use >> malloc_simple if GD_FLG_FULL_MALLOC_INIT is unset. Adjust the malloc bytes >> to align with the requested alignment. >> >> The original memalign() function will access mchunkptr struct to adjust the >> alignment if there is misalignment happen, but mchunkptr struct is not being >> initialized before full malloc is initialized. This cause the system crash. >> >> Signed-off-by: Ley Foon Tan <ley.foon.tan@intel.com> >> --- >> common/dlmalloc.c | 7 +++++++ >> 1 files changed, 7 insertions(+), 0 deletions(-) >> >> diff --git a/common/dlmalloc.c b/common/dlmalloc.c >> index b395eef..edaad29 100644 >> --- a/common/dlmalloc.c >> +++ b/common/dlmalloc.c >> @@ -1891,6 +1891,13 @@ Void_t* mEMALIGn(alignment, bytes) size_t alignment; size_t bytes; >> >> if ((long)bytes < 0) return NULL; >> >> +#if CONFIG_VAL(SYS_MALLOC_F_LEN) > > How about: > > if (IS_ENABLED(CONFIG_SYS_MALLOC_F)) I think this is the reason it uses #if CONFIG_VAL(SYS_MALLOC_F_LEN), same for malloc(). "spl: make SPL and normal u-boot stage use independent SYS_MALLOC_F_LEN" http://git.denx.de/?p=u-boot.git;a=commit;h=f1896c45cb2f7d8dbed27e784a6459a129fc0762 > > ? > >> + if (!(gd->flags & GD_FLG_FULL_MALLOC_INIT)) { >> + nb = roundup(bytes, alignment); >> + return malloc_simple(nb); >> + } >> +#endif >> + >> /* If need less alignment than we give anyway, just relay to malloc */ >> >> if (alignment <= MALLOC_ALIGNMENT) return mALLOc(bytes); >> -- >> 1.7.1 >> > > Regards, > Simon Regards Ley Foon ^ permalink raw reply [flat|nested] 12+ messages in thread
* [U-Boot] [PATCH] malloc: Use malloc simple before malloc is fully initialized in memalign() 2018-05-23 6:32 ` Ley Foon Tan @ 2018-05-23 16:33 ` Simon Glass 2018-05-25 3:24 ` Ley Foon Tan 0 siblings, 1 reply; 12+ messages in thread From: Simon Glass @ 2018-05-23 16:33 UTC (permalink / raw) To: u-boot Hi, On 23 May 2018 at 00:32, Ley Foon Tan <lftan.linux@gmail.com> wrote: > On Sat, May 19, 2018 at 10:37 PM, Simon Glass <sjg@chromium.org> wrote: >> Hi Ley, >> >> On 18 May 2018 at 04:03, Ley Foon Tan <ley.foon.tan@intel.com> wrote: >>> Follow implementation in mALLOc(). Check GD_FLG_FULL_MALLOC_INIT flag and use >>> malloc_simple if GD_FLG_FULL_MALLOC_INIT is unset. Adjust the malloc bytes >>> to align with the requested alignment. >>> >>> The original memalign() function will access mchunkptr struct to adjust the >>> alignment if there is misalignment happen, but mchunkptr struct is not being >>> initialized before full malloc is initialized. This cause the system crash. >>> >>> Signed-off-by: Ley Foon Tan <ley.foon.tan@intel.com> >>> --- >>> common/dlmalloc.c | 7 +++++++ >>> 1 files changed, 7 insertions(+), 0 deletions(-) >>> >>> diff --git a/common/dlmalloc.c b/common/dlmalloc.c >>> index b395eef..edaad29 100644 >>> --- a/common/dlmalloc.c >>> +++ b/common/dlmalloc.c >>> @@ -1891,6 +1891,13 @@ Void_t* mEMALIGn(alignment, bytes) size_t alignment; size_t bytes; >>> >>> if ((long)bytes < 0) return NULL; >>> >>> +#if CONFIG_VAL(SYS_MALLOC_F_LEN) >> >> How about: >> >> if (IS_ENABLED(CONFIG_SYS_MALLOC_F)) > > I think this is the reason it uses #if CONFIG_VAL(SYS_MALLOC_F_LEN), > same for malloc(). > > "spl: make SPL and normal u-boot stage use independent SYS_MALLOC_F_LEN" > > http://git.denx.de/?p=u-boot.git;a=commit;h=f1896c45cb2f7d8dbed27e784a6459a129fc0762 So how about if (CONFIG_IS_ENABLED(SYS_MALLOC_F_LEN) Or you could use #if if you need to To me it seems better to use the setting itself (i.e. whether the pre-reloc malloc() is enabled) rather than one of its parameters (the size of the region). > > >> >> ? >> >>> + if (!(gd->flags & GD_FLG_FULL_MALLOC_INIT)) { >>> + nb = roundup(bytes, alignment); >>> + return malloc_simple(nb); >>> + } >>> +#endif >>> + >>> /* If need less alignment than we give anyway, just relay to malloc */ >>> >>> if (alignment <= MALLOC_ALIGNMENT) return mALLOc(bytes); >>> -- >>> 1.7.1 Regards, Simon ^ permalink raw reply [flat|nested] 12+ messages in thread
* [U-Boot] [PATCH] malloc: Use malloc simple before malloc is fully initialized in memalign() 2018-05-23 16:33 ` Simon Glass @ 2018-05-25 3:24 ` Ley Foon Tan 2018-05-25 3:33 ` Simon Glass 0 siblings, 1 reply; 12+ messages in thread From: Ley Foon Tan @ 2018-05-25 3:24 UTC (permalink / raw) To: u-boot On Thu, May 24, 2018 at 12:33 AM, Simon Glass <sjg@chromium.org> wrote: > Hi, > > On 23 May 2018 at 00:32, Ley Foon Tan <lftan.linux@gmail.com> wrote: >> On Sat, May 19, 2018 at 10:37 PM, Simon Glass <sjg@chromium.org> wrote: >>> Hi Ley, >>> >>> On 18 May 2018 at 04:03, Ley Foon Tan <ley.foon.tan@intel.com> wrote: >>>> Follow implementation in mALLOc(). Check GD_FLG_FULL_MALLOC_INIT flag and use >>>> malloc_simple if GD_FLG_FULL_MALLOC_INIT is unset. Adjust the malloc bytes >>>> to align with the requested alignment. >>>> >>>> The original memalign() function will access mchunkptr struct to adjust the >>>> alignment if there is misalignment happen, but mchunkptr struct is not being >>>> initialized before full malloc is initialized. This cause the system crash. >>>> >>>> Signed-off-by: Ley Foon Tan <ley.foon.tan@intel.com> >>>> --- >>>> common/dlmalloc.c | 7 +++++++ >>>> 1 files changed, 7 insertions(+), 0 deletions(-) >>>> >>>> diff --git a/common/dlmalloc.c b/common/dlmalloc.c >>>> index b395eef..edaad29 100644 >>>> --- a/common/dlmalloc.c >>>> +++ b/common/dlmalloc.c >>>> @@ -1891,6 +1891,13 @@ Void_t* mEMALIGn(alignment, bytes) size_t alignment; size_t bytes; >>>> >>>> if ((long)bytes < 0) return NULL; >>>> >>>> +#if CONFIG_VAL(SYS_MALLOC_F_LEN) >>> >>> How about: >>> >>> if (IS_ENABLED(CONFIG_SYS_MALLOC_F)) >> >> I think this is the reason it uses #if CONFIG_VAL(SYS_MALLOC_F_LEN), >> same for malloc(). >> >> "spl: make SPL and normal u-boot stage use independent SYS_MALLOC_F_LEN" >> >> http://git.denx.de/?p=u-boot.git;a=commit;h=f1896c45cb2f7d8dbed27e784a6459a129fc0762 > > So how about > > if (CONFIG_IS_ENABLED(SYS_MALLOC_F_LEN) > > Or you could use #if if you need to Tested both #if (CONFIG_IS_ENABLED(SYS_MALLOC_F_LEN)) and if (CONFIG_IS_ENABLED(SYS_MALLOC_F_LEN)), both are not working. It will not go into this code. > > To me it seems better to use the setting itself (i.e. whether the > pre-reloc malloc() is enabled) rather than one of its parameters (the > size of the region). > >> >> >>> >>> ? >>> >>>> + if (!(gd->flags & GD_FLG_FULL_MALLOC_INIT)) { >>>> + nb = roundup(bytes, alignment); >>>> + return malloc_simple(nb); >>>> + } >>>> +#endif >>>> + >>>> /* If need less alignment than we give anyway, just relay to malloc */ >>>> >>>> if (alignment <= MALLOC_ALIGNMENT) return mALLOc(bytes); >>>> -- >>>> 1.7.1 > Regards, > Simon Regards Ley Foon ^ permalink raw reply [flat|nested] 12+ messages in thread
* [U-Boot] [PATCH] malloc: Use malloc simple before malloc is fully initialized in memalign() 2018-05-25 3:24 ` Ley Foon Tan @ 2018-05-25 3:33 ` Simon Glass 2018-05-25 8:50 ` Ley Foon Tan 0 siblings, 1 reply; 12+ messages in thread From: Simon Glass @ 2018-05-25 3:33 UTC (permalink / raw) To: u-boot Hi, On 24 May 2018 at 21:24, Ley Foon Tan <lftan.linux@gmail.com> wrote: > > On Thu, May 24, 2018 at 12:33 AM, Simon Glass <sjg@chromium.org> wrote: > > Hi, > > > > On 23 May 2018 at 00:32, Ley Foon Tan <lftan.linux@gmail.com> wrote: > >> On Sat, May 19, 2018 at 10:37 PM, Simon Glass <sjg@chromium.org> wrote: > >>> Hi Ley, > >>> > >>> On 18 May 2018 at 04:03, Ley Foon Tan <ley.foon.tan@intel.com> wrote: > >>>> Follow implementation in mALLOc(). Check GD_FLG_FULL_MALLOC_INIT flag and use > >>>> malloc_simple if GD_FLG_FULL_MALLOC_INIT is unset. Adjust the malloc bytes > >>>> to align with the requested alignment. > >>>> > >>>> The original memalign() function will access mchunkptr struct to adjust the > >>>> alignment if there is misalignment happen, but mchunkptr struct is not being > >>>> initialized before full malloc is initialized. This cause the system crash. > >>>> > >>>> Signed-off-by: Ley Foon Tan <ley.foon.tan@intel.com> > >>>> --- > >>>> common/dlmalloc.c | 7 +++++++ > >>>> 1 files changed, 7 insertions(+), 0 deletions(-) > >>>> > >>>> diff --git a/common/dlmalloc.c b/common/dlmalloc.c > >>>> index b395eef..edaad29 100644 > >>>> --- a/common/dlmalloc.c > >>>> +++ b/common/dlmalloc.c > >>>> @@ -1891,6 +1891,13 @@ Void_t* mEMALIGn(alignment, bytes) size_t alignment; size_t bytes; > >>>> > >>>> if ((long)bytes < 0) return NULL; > >>>> > >>>> +#if CONFIG_VAL(SYS_MALLOC_F_LEN) > >>> > >>> How about: > >>> > >>> if (IS_ENABLED(CONFIG_SYS_MALLOC_F)) > >> > >> I think this is the reason it uses #if CONFIG_VAL(SYS_MALLOC_F_LEN), > >> same for malloc(). > >> > >> "spl: make SPL and normal u-boot stage use independent SYS_MALLOC_F_LEN" > >> > >> http://git.denx.de/?p=u-boot.git;a=commit;h=f1896c45cb2f7d8dbed27e784a6459a129fc0762 > > > > So how about > > > > if (CONFIG_IS_ENABLED(SYS_MALLOC_F_LEN) > > > > Or you could use #if if you need to > > Tested both #if (CONFIG_IS_ENABLED(SYS_MALLOC_F_LEN)) and if > (CONFIG_IS_ENABLED(SYS_MALLOC_F_LEN)), both are not working. Sorry I mean CONFIG_IS_ENABLED(SYS_MALLOC_F) That tells you whether the feature is enabled in U-Boot or SPL. > > It will not go into this code. > > > > > > To me it seems better to use the setting itself (i.e. whether the > > pre-reloc malloc() is enabled) rather than one of its parameters (the > > size of the region). [..] Regards, Simon ^ permalink raw reply [flat|nested] 12+ messages in thread
* [U-Boot] [PATCH] malloc: Use malloc simple before malloc is fully initialized in memalign() 2018-05-25 3:33 ` Simon Glass @ 2018-05-25 8:50 ` Ley Foon Tan 2018-05-26 2:06 ` Simon Glass 0 siblings, 1 reply; 12+ messages in thread From: Ley Foon Tan @ 2018-05-25 8:50 UTC (permalink / raw) To: u-boot On Fri, May 25, 2018 at 11:33 AM, Simon Glass <sjg@chromium.org> wrote: > Hi, > > On 24 May 2018 at 21:24, Ley Foon Tan <lftan.linux@gmail.com> wrote: >> >> On Thu, May 24, 2018 at 12:33 AM, Simon Glass <sjg@chromium.org> wrote: >> > Hi, >> > >> > On 23 May 2018 at 00:32, Ley Foon Tan <lftan.linux@gmail.com> wrote: >> >> On Sat, May 19, 2018 at 10:37 PM, Simon Glass <sjg@chromium.org> wrote: >> >>> Hi Ley, >> >>> >> >>> On 18 May 2018 at 04:03, Ley Foon Tan <ley.foon.tan@intel.com> wrote: >> >>>> Follow implementation in mALLOc(). Check GD_FLG_FULL_MALLOC_INIT flag and use >> >>>> malloc_simple if GD_FLG_FULL_MALLOC_INIT is unset. Adjust the malloc bytes >> >>>> to align with the requested alignment. >> >>>> >> >>>> The original memalign() function will access mchunkptr struct to adjust the >> >>>> alignment if there is misalignment happen, but mchunkptr struct is not being >> >>>> initialized before full malloc is initialized. This cause the system crash. >> >>>> >> >>>> Signed-off-by: Ley Foon Tan <ley.foon.tan@intel.com> >> >>>> --- >> >>>> common/dlmalloc.c | 7 +++++++ >> >>>> 1 files changed, 7 insertions(+), 0 deletions(-) >> >>>> >> >>>> diff --git a/common/dlmalloc.c b/common/dlmalloc.c >> >>>> index b395eef..edaad29 100644 >> >>>> --- a/common/dlmalloc.c >> >>>> +++ b/common/dlmalloc.c >> >>>> @@ -1891,6 +1891,13 @@ Void_t* mEMALIGn(alignment, bytes) size_t alignment; size_t bytes; >> >>>> >> >>>> if ((long)bytes < 0) return NULL; >> >>>> >> >>>> +#if CONFIG_VAL(SYS_MALLOC_F_LEN) >> >>> >> >>> How about: >> >>> >> >>> if (IS_ENABLED(CONFIG_SYS_MALLOC_F)) >> >> >> >> I think this is the reason it uses #if CONFIG_VAL(SYS_MALLOC_F_LEN), >> >> same for malloc(). >> >> >> >> "spl: make SPL and normal u-boot stage use independent SYS_MALLOC_F_LEN" >> >> >> >> http://git.denx.de/?p=u-boot.git;a=commit;h=f1896c45cb2f7d8dbed27e784a6459a129fc0762 >> > >> > So how about >> > >> > if (CONFIG_IS_ENABLED(SYS_MALLOC_F_LEN) >> > >> > Or you could use #if if you need to >> >> Tested both #if (CONFIG_IS_ENABLED(SYS_MALLOC_F_LEN)) and if >> (CONFIG_IS_ENABLED(SYS_MALLOC_F_LEN)), both are not working. > > Sorry I mean > > CONFIG_IS_ENABLED(SYS_MALLOC_F) > > That tells you whether the feature is enabled in U-Boot or SPL. #if CONFIG_IS_ENABLED(SYS_MALLOC_F) if not working in SPL build. CONFIG_IS_ENABLED() expects config with "y" or "m", but SPL config is with "1". Need to use #ifdef CONFIG_SYS_MALLOC_F. Do you want to change to this? Regards Ley Foon ^ permalink raw reply [flat|nested] 12+ messages in thread
* [U-Boot] [PATCH] malloc: Use malloc simple before malloc is fully initialized in memalign() 2018-05-25 8:50 ` Ley Foon Tan @ 2018-05-26 2:06 ` Simon Glass 2018-05-29 5:16 ` Masahiro Yamada 0 siblings, 1 reply; 12+ messages in thread From: Simon Glass @ 2018-05-26 2:06 UTC (permalink / raw) To: u-boot +Masahiro On 25 May 2018 at 02:50, Ley Foon Tan <lftan.linux@gmail.com> wrote: > > On Fri, May 25, 2018 at 11:33 AM, Simon Glass <sjg@chromium.org> wrote: > > Hi, > > > > On 24 May 2018 at 21:24, Ley Foon Tan <lftan.linux@gmail.com> wrote: > >> > >> On Thu, May 24, 2018 at 12:33 AM, Simon Glass <sjg@chromium.org> wrote: > >> > Hi, > >> > > >> > On 23 May 2018 at 00:32, Ley Foon Tan <lftan.linux@gmail.com> wrote: > >> >> On Sat, May 19, 2018 at 10:37 PM, Simon Glass <sjg@chromium.org> wrote: > >> >>> Hi Ley, > >> >>> > >> >>> On 18 May 2018 at 04:03, Ley Foon Tan <ley.foon.tan@intel.com> wrote: > >> >>>> Follow implementation in mALLOc(). Check GD_FLG_FULL_MALLOC_INIT flag and use > >> >>>> malloc_simple if GD_FLG_FULL_MALLOC_INIT is unset. Adjust the malloc bytes > >> >>>> to align with the requested alignment. > >> >>>> > >> >>>> The original memalign() function will access mchunkptr struct to adjust the > >> >>>> alignment if there is misalignment happen, but mchunkptr struct is not being > >> >>>> initialized before full malloc is initialized. This cause the system crash. > >> >>>> > >> >>>> Signed-off-by: Ley Foon Tan <ley.foon.tan@intel.com> > >> >>>> --- > >> >>>> common/dlmalloc.c | 7 +++++++ > >> >>>> 1 files changed, 7 insertions(+), 0 deletions(-) > >> >>>> > >> >>>> diff --git a/common/dlmalloc.c b/common/dlmalloc.c > >> >>>> index b395eef..edaad29 100644 > >> >>>> --- a/common/dlmalloc.c > >> >>>> +++ b/common/dlmalloc.c > >> >>>> @@ -1891,6 +1891,13 @@ Void_t* mEMALIGn(alignment, bytes) size_t alignment; size_t bytes; > >> >>>> > >> >>>> if ((long)bytes < 0) return NULL; > >> >>>> > >> >>>> +#if CONFIG_VAL(SYS_MALLOC_F_LEN) > >> >>> > >> >>> How about: > >> >>> > >> >>> if (IS_ENABLED(CONFIG_SYS_MALLOC_F)) > >> >> > >> >> I think this is the reason it uses #if CONFIG_VAL(SYS_MALLOC_F_LEN), > >> >> same for malloc(). > >> >> > >> >> "spl: make SPL and normal u-boot stage use independent SYS_MALLOC_F_LEN" > >> >> > >> >> http://git.denx.de/?p=u-boot.git;a=commit;h=f1896c45cb2f7d8dbed27e784a6459a129fc0762 > >> > > >> > So how about > >> > > >> > if (CONFIG_IS_ENABLED(SYS_MALLOC_F_LEN) > >> > > >> > Or you could use #if if you need to > >> > >> Tested both #if (CONFIG_IS_ENABLED(SYS_MALLOC_F_LEN)) and if > >> (CONFIG_IS_ENABLED(SYS_MALLOC_F_LEN)), both are not working. > > > > Sorry I mean > > > > CONFIG_IS_ENABLED(SYS_MALLOC_F) > > > > That tells you whether the feature is enabled in U-Boot or SPL. > > #if CONFIG_IS_ENABLED(SYS_MALLOC_F) if not working in SPL build. > CONFIG_IS_ENABLED() expects config with "y" or "m", but SPL config is > with "1". That seems very strange, since it defeats the purpose of the macro. Masahiro, do you know what going on here? > Need to use #ifdef CONFIG_SYS_MALLOC_F. Do you want to change to this? Regards, Simon ^ permalink raw reply [flat|nested] 12+ messages in thread
* [U-Boot] [PATCH] malloc: Use malloc simple before malloc is fully initialized in memalign() 2018-05-26 2:06 ` Simon Glass @ 2018-05-29 5:16 ` Masahiro Yamada 2018-05-30 19:18 ` Simon Glass 0 siblings, 1 reply; 12+ messages in thread From: Masahiro Yamada @ 2018-05-29 5:16 UTC (permalink / raw) To: u-boot 2018-05-26 11:06 GMT+09:00 Simon Glass <sjg@chromium.org>: > +Masahiro > > On 25 May 2018 at 02:50, Ley Foon Tan <lftan.linux@gmail.com> wrote: >> >> On Fri, May 25, 2018 at 11:33 AM, Simon Glass <sjg@chromium.org> wrote: >> > Hi, >> > >> > On 24 May 2018 at 21:24, Ley Foon Tan <lftan.linux@gmail.com> wrote: >> >> >> >> On Thu, May 24, 2018 at 12:33 AM, Simon Glass <sjg@chromium.org> wrote: >> >> > Hi, >> >> > >> >> > On 23 May 2018 at 00:32, Ley Foon Tan <lftan.linux@gmail.com> wrote: >> >> >> On Sat, May 19, 2018 at 10:37 PM, Simon Glass <sjg@chromium.org> wrote: >> >> >>> Hi Ley, >> >> >>> >> >> >>> On 18 May 2018 at 04:03, Ley Foon Tan <ley.foon.tan@intel.com> wrote: >> >> >>>> Follow implementation in mALLOc(). Check GD_FLG_FULL_MALLOC_INIT flag and use >> >> >>>> malloc_simple if GD_FLG_FULL_MALLOC_INIT is unset. Adjust the malloc bytes >> >> >>>> to align with the requested alignment. >> >> >>>> >> >> >>>> The original memalign() function will access mchunkptr struct to adjust the >> >> >>>> alignment if there is misalignment happen, but mchunkptr struct is not being >> >> >>>> initialized before full malloc is initialized. This cause the system crash. >> >> >>>> >> >> >>>> Signed-off-by: Ley Foon Tan <ley.foon.tan@intel.com> >> >> >>>> --- >> >> >>>> common/dlmalloc.c | 7 +++++++ >> >> >>>> 1 files changed, 7 insertions(+), 0 deletions(-) >> >> >>>> >> >> >>>> diff --git a/common/dlmalloc.c b/common/dlmalloc.c >> >> >>>> index b395eef..edaad29 100644 >> >> >>>> --- a/common/dlmalloc.c >> >> >>>> +++ b/common/dlmalloc.c >> >> >>>> @@ -1891,6 +1891,13 @@ Void_t* mEMALIGn(alignment, bytes) size_t alignment; size_t bytes; >> >> >>>> >> >> >>>> if ((long)bytes < 0) return NULL; >> >> >>>> >> >> >>>> +#if CONFIG_VAL(SYS_MALLOC_F_LEN) >> >> >>> >> >> >>> How about: >> >> >>> >> >> >>> if (IS_ENABLED(CONFIG_SYS_MALLOC_F)) >> >> >> >> >> >> I think this is the reason it uses #if CONFIG_VAL(SYS_MALLOC_F_LEN), >> >> >> same for malloc(). >> >> >> >> >> >> "spl: make SPL and normal u-boot stage use independent SYS_MALLOC_F_LEN" >> >> >> >> >> >> http://git.denx.de/?p=u-boot.git;a=commit;h=f1896c45cb2f7d8dbed27e784a6459a129fc0762 >> >> > >> >> > So how about >> >> > >> >> > if (CONFIG_IS_ENABLED(SYS_MALLOC_F_LEN) >> >> > >> >> > Or you could use #if if you need to >> >> >> >> Tested both #if (CONFIG_IS_ENABLED(SYS_MALLOC_F_LEN)) and if >> >> (CONFIG_IS_ENABLED(SYS_MALLOC_F_LEN)), both are not working. >> > >> > Sorry I mean >> > >> > CONFIG_IS_ENABLED(SYS_MALLOC_F) >> > >> > That tells you whether the feature is enabled in U-Boot or SPL. >> >> #if CONFIG_IS_ENABLED(SYS_MALLOC_F) if not working in SPL build. >> CONFIG_IS_ENABLED() expects config with "y" or "m", but SPL config is >> with "1". > > That seems very strange, since it defeats the purpose of the macro. > > Masahiro, do you know what going on here? CONFIG_IS_ENABLED(SYS_MALLOC_F) evaluates SYS_MALLOC_F, or SPL_SYS_MALLOC_F depending on which image is being built. I see SPL_SYS_MALLOC_F_LEN in Kconfig, but do not see SPL_SYS_MALLOC_F at all. -- Best Regards Masahiro Yamada ^ permalink raw reply [flat|nested] 12+ messages in thread
* [U-Boot] [PATCH] malloc: Use malloc simple before malloc is fully initialized in memalign() 2018-05-29 5:16 ` Masahiro Yamada @ 2018-05-30 19:18 ` Simon Glass 0 siblings, 0 replies; 12+ messages in thread From: Simon Glass @ 2018-05-30 19:18 UTC (permalink / raw) To: u-boot Hi Masahiro, On 28 May 2018 at 23:16, Masahiro Yamada <yamada.masahiro@socionext.com> wrote: > 2018-05-26 11:06 GMT+09:00 Simon Glass <sjg@chromium.org>: >> +Masahiro >> >> On 25 May 2018 at 02:50, Ley Foon Tan <lftan.linux@gmail.com> wrote: >>> >>> On Fri, May 25, 2018 at 11:33 AM, Simon Glass <sjg@chromium.org> wrote: >>> > Hi, >>> > >>> > On 24 May 2018 at 21:24, Ley Foon Tan <lftan.linux@gmail.com> wrote: >>> >> >>> >> On Thu, May 24, 2018 at 12:33 AM, Simon Glass <sjg@chromium.org> wrote: >>> >> > Hi, >>> >> > >>> >> > On 23 May 2018 at 00:32, Ley Foon Tan <lftan.linux@gmail.com> wrote: >>> >> >> On Sat, May 19, 2018 at 10:37 PM, Simon Glass <sjg@chromium.org> wrote: >>> >> >>> Hi Ley, >>> >> >>> >>> >> >>> On 18 May 2018 at 04:03, Ley Foon Tan <ley.foon.tan@intel.com> wrote: >>> >> >>>> Follow implementation in mALLOc(). Check GD_FLG_FULL_MALLOC_INIT flag and use >>> >> >>>> malloc_simple if GD_FLG_FULL_MALLOC_INIT is unset. Adjust the malloc bytes >>> >> >>>> to align with the requested alignment. >>> >> >>>> >>> >> >>>> The original memalign() function will access mchunkptr struct to adjust the >>> >> >>>> alignment if there is misalignment happen, but mchunkptr struct is not being >>> >> >>>> initialized before full malloc is initialized. This cause the system crash. >>> >> >>>> >>> >> >>>> Signed-off-by: Ley Foon Tan <ley.foon.tan@intel.com> >>> >> >>>> --- >>> >> >>>> common/dlmalloc.c | 7 +++++++ >>> >> >>>> 1 files changed, 7 insertions(+), 0 deletions(-) >>> >> >>>> >>> >> >>>> diff --git a/common/dlmalloc.c b/common/dlmalloc.c >>> >> >>>> index b395eef..edaad29 100644 >>> >> >>>> --- a/common/dlmalloc.c >>> >> >>>> +++ b/common/dlmalloc.c >>> >> >>>> @@ -1891,6 +1891,13 @@ Void_t* mEMALIGn(alignment, bytes) size_t alignment; size_t bytes; >>> >> >>>> >>> >> >>>> if ((long)bytes < 0) return NULL; >>> >> >>>> >>> >> >>>> +#if CONFIG_VAL(SYS_MALLOC_F_LEN) >>> >> >>> >>> >> >>> How about: >>> >> >>> >>> >> >>> if (IS_ENABLED(CONFIG_SYS_MALLOC_F)) >>> >> >> >>> >> >> I think this is the reason it uses #if CONFIG_VAL(SYS_MALLOC_F_LEN), >>> >> >> same for malloc(). >>> >> >> >>> >> >> "spl: make SPL and normal u-boot stage use independent SYS_MALLOC_F_LEN" >>> >> >> >>> >> >> http://git.denx.de/?p=u-boot.git;a=commit;h=f1896c45cb2f7d8dbed27e784a6459a129fc0762 >>> >> > >>> >> > So how about >>> >> > >>> >> > if (CONFIG_IS_ENABLED(SYS_MALLOC_F_LEN) >>> >> > >>> >> > Or you could use #if if you need to >>> >> >>> >> Tested both #if (CONFIG_IS_ENABLED(SYS_MALLOC_F_LEN)) and if >>> >> (CONFIG_IS_ENABLED(SYS_MALLOC_F_LEN)), both are not working. >>> > >>> > Sorry I mean >>> > >>> > CONFIG_IS_ENABLED(SYS_MALLOC_F) >>> > >>> > That tells you whether the feature is enabled in U-Boot or SPL. >>> >>> #if CONFIG_IS_ENABLED(SYS_MALLOC_F) if not working in SPL build. >>> CONFIG_IS_ENABLED() expects config with "y" or "m", but SPL config is >>> with "1". >> >> That seems very strange, since it defeats the purpose of the macro. >> >> Masahiro, do you know what going on here? > > > CONFIG_IS_ENABLED(SYS_MALLOC_F) evaluates > SYS_MALLOC_F, or SPL_SYS_MALLOC_F > depending on which image is being built. > > > I see SPL_SYS_MALLOC_F_LEN in Kconfig, > but do not see SPL_SYS_MALLOC_F at all. OK, well that explains the problem, thanks. Regards, Simon ^ permalink raw reply [flat|nested] 12+ messages in thread
* [U-Boot] malloc: Use malloc simple before malloc is fully initialized in memalign() 2018-05-18 10:03 [U-Boot] [PATCH] malloc: Use malloc simple before malloc is fully initialized in memalign() Ley Foon Tan 2018-05-18 8:21 ` Marek Vasut 2018-05-19 14:37 ` Simon Glass @ 2018-05-28 19:13 ` Tom Rini 2 siblings, 0 replies; 12+ messages in thread From: Tom Rini @ 2018-05-28 19:13 UTC (permalink / raw) To: u-boot On Fri, May 18, 2018 at 06:03:12PM +0800, Ley Foon Tan wrote: > Follow implementation in mALLOc(). Check GD_FLG_FULL_MALLOC_INIT flag and use > malloc_simple if GD_FLG_FULL_MALLOC_INIT is unset. Adjust the malloc bytes > to align with the requested alignment. > > The original memalign() function will access mchunkptr struct to adjust the > alignment if there is misalignment happen, but mchunkptr struct is not being > initialized before full malloc is initialized. This cause the system crash. > > Signed-off-by: Ley Foon Tan <ley.foon.tan@intel.com> > Reviewed-by: Marek Vasut <marek.vasut@gmail.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: not available URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180528/46a061ea/attachment.sig> ^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2018-05-30 19:18 UTC | newest] Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2018-05-18 10:03 [U-Boot] [PATCH] malloc: Use malloc simple before malloc is fully initialized in memalign() Ley Foon Tan 2018-05-18 8:21 ` Marek Vasut 2018-05-19 14:37 ` Simon Glass 2018-05-23 6:32 ` Ley Foon Tan 2018-05-23 16:33 ` Simon Glass 2018-05-25 3:24 ` Ley Foon Tan 2018-05-25 3:33 ` Simon Glass 2018-05-25 8:50 ` Ley Foon Tan 2018-05-26 2:06 ` Simon Glass 2018-05-29 5:16 ` Masahiro Yamada 2018-05-30 19:18 ` Simon Glass 2018-05-28 19:13 ` [U-Boot] " Tom Rini
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.