[PATCH] i2c: avoid dynamic stack use in dm_i2c_write
Heiko Schocher
hs at denx.de
Tue Jul 19 13:54:52 CEST 2022
Hello Rasmus,
On 07.07.22 15:12, Rasmus Villemoes wrote:
> The size of the dynamic stack allocation here is bounded by the if()
> statement. However, just allocating the maximum size up-front and
> doing malloc() if necessary avoids code duplication (the
> i2c_setup_offset() until the invocation of ->xfer), and generates much
> better (smaller) code:
>
> bloat-o-meter drivers/i2c/i2c-uclass.o.{0,1}
> add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-144 (-144)
> Function old new delta
> dm_i2c_write 552 408 -144
> Total: Before=3828, After=3684, chg -3.76%
>
> It also makes static analysis of maximum stack usage (using the .su
> files that are automatically generated during build) easier if there
> are no lines saying "dynamic".
>
> [This is not entirely equivalent to the existing code; this now uses
> the stack for len <= 64 rather than len <= 63, but that seems like a
> more natural limit.]
>
> Signed-off-by: Rasmus Villemoes <rasmus.villemoes at prevas.dk>
> ---
> drivers/i2c/i2c-uclass.c | 30 ++++++++++++------------------
> 1 file changed, 12 insertions(+), 18 deletions(-)
Applied to u-boot-i2c master
Thanks!
bye,
Heiko
--
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-52 Fax: +49-8142-66989-80 Email: hs at denx.de
More information about the U-Boot
mailing list