RFC: introduce malloc_cleared() ?
Hello,
instead of adding or having the sequence of
malloc(), memset()
in all places where a definitely sane initialized structure is required it would make more sense to introduce a single function doing both. (The standard "calloc()" does not suit well here.) Overall that should even slightly decrease code size.
Reinhard
Dear Reinhard Meyer,
Quoted 9 lines · In message <[email protected]> you wrote:
instead of adding or having the sequence of
malloc(),memset()in all places where a definitely sane initialized structure is required it would make more sense to introduce a single function doing both. (The standard "
calloc()" does not suit well here.) Overall that should even slightly decrease code size.
And why exactly does calloc() not fit?
Best regards,
Wolfgang Denk
Signature · 5 lines
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
A verbal contract isn't worth the paper it's written on.
-- Samuel GoldwynQuoted 5 lines · Wolfgang Denk
Dear Reinhard Meyer,
Quoted 2 lines · In message <[email protected]> you wrote:
instead of adding or having the sequence of
Quoted 8 lines
Quoted 6 lines
malloc(),memset()in all places where a definitely sane initialized structure is required it would make more sense to introduce a single function doing both. (The standard "
calloc()" does not suit well here.) Overall that should even slightly decrease code size.And why exactly does
calloc()not fit?
It has two parameters... Produces more code to always supply an extra "1"...
I am game with using calloc(). That's all.
But for malloc() in such driver init situations, another code saving function with error message would be more effective. I don't see any possible way of continuing u-boot when malloc() for a relatively small structure already fails, and a (apparently) needed driver cannot be initialized.
I am not talking about malloc()'s for buffers or similar where continuing of u-boot might be possible.
Reinhard
Quoted 21 lines
Quoted 5 lines · Wolfgang Denk
Dear Reinhard Meyer,
Quoted 2 lines · In message <[email protected]> you wrote:
instead of adding or having the sequence of
Quoted 8 lines
Quoted 6 lines
malloc(),memset()in all places where a definitely sane initialized structure is required it would make more sense to introduce a single function doing both. (The standard "
calloc()" does not suit well here.) Overall that should even slightly decrease code size.And why exactly does
calloc()not fit?It has two parameters... Produces more code to always supply an extra "1"...
I am game with using
calloc(). That's all.
Quoted 7 lines
But for
malloc()in such driver init situations, another code saving function with error message would be more effective. I don't see any possible way of continuing u-boot whenmalloc()for a relatively small structure already fails, and a (apparently) needed driver cannot be initialized.I am not talking about malloc()'s for buffers or similar where
continuing
Quoted 1 line
of u-boot might be possible.
I would borrow the naming from linux and call it mallocz
Jocke
Dear Joakim Tjernlund,
Quoted 2 lines · In message <OF32166834.809C7D71-ONC12577BC.0031112B-C12577BC.00313F63@transmode…
I would borrow the naming from linux and call it mallocz
... except that Linux does not use any "mallocz" anywhere :-)
I guess you mean [k]zalloc() ?
Best regards,
Wolfgang Denk
Signature · 5 lines
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de When a program is being tested, it is too late to make design changes. -- Geoffrey James, "The Tao of Programming"
Wolfgang Denk <[email protected]> wrote on 2010/10/14 11:38:57:
Quoted 11 lines
Dear Joakim Tjernlund,
In message <OF32166834.809C7D71-ONC12577BC.0031112B-C12577BC.
Quoted 2 lines · 00313F63 at transmode.se> you wrote:
I would borrow the naming from linux and call it mallocz
... except that Linux does not use any "mallocz" anywhere :-)
I guess you mean [k]zalloc() ?
Yes, memory played tricks on me :)
Quoted 18 lines · Reinhard Meyer
Quoted 5 lines · Wolfgang Denk
Dear Reinhard Meyer,
Quoted 2 lines · In message <[email protected]> you wrote:
instead of adding or having the sequence of
Quoted 8 lines
Quoted 6 lines
malloc(),memset()in all places where a definitely sane initialized structure is required it would make more sense to introduce a single function doing both. (The standard "
calloc()" does not suit well here.) Overall that should even slightly decrease code size.And why exactly does
calloc()not fit?It has two parameters... Produces more code to always supply an extra "1"...
Quoted 7 lines
I am game with using
calloc(). That's all.But for
malloc()in such driver init situations, another code saving function with error message would be more effective. I don't see any possible way of continuing u-boot whenmalloc()for a relatively small structure already fails, and a (apparently) needed driver cannot be initialized.
The failed malloc can cause the dailed driver to unload malloc'd memory and print a warning to the console. User intervention (changing environment variables to avoid the out-of-memory on reboot for example) can still be possible even though the driver failed.
Quoted 4 lines
I am not talking about malloc()'s for buffers or similar where continuing of u-boot might be possible.
Regards,
Graeme
Dear Reinhard Meyer,
Quoted 5 lines · In message <[email protected]> you wrote:
Quoted 2 lines
And why exactly does
calloc()not fit?It has two parameters... Produces more code to always supply an extra "1"...
Ah.
Quoted 2 lines
But for
malloc()in such driver init situations, another code saving function with error message would be more effective. I don't see any
Would it? You still need to check the return code of the allocation function then, because you want to breeak out of the caller.
Quoted 3 lines
possible way of continuing u-boot when
malloc()for a relatively small structure already fails, and a (apparently) needed driver cannot be initialized.
Maybe, maybe not. As mentioned before: network access may not be so important at all.
Quoted 2 lines
I am not talking about malloc()'s for buffers or similar where continuing of u-boot might be possible.
Continuing U-Boot without network access is also possible. If someone pulls the cable you also continue, or don't you?
Best regards,
Wolfgang Denk
Signature · 7 lines
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
"Pardon me for breathing, which I never do anyway so I don't know why
I bother to say it, oh God, I'm so depressed. Here's another of those
self-satisfied doors. Life! Don't talk to me about life."
- Marvin the Paranoid Android