imx: i2c: Zap unnecessary malloc() calls
Subsystems (2)
PATCH 1/8 imx: i2c: Zap unnecessary malloc() calls
The malloc() calls are unnecessary, just allocate the stuff on stack. While at it, reorder the code a little, so that only one variable is used for the text, use snprintf() instead of sprintf() and use %01d as a formatting string to avoid any possible overflows.
--- arch/arm/imx-common/i2c-mxv7.c | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-)
arch/arm/imx-common/i2c-mxv7.c +8 -16
@@ -73,26 +73,21 @@ static void * const i2c_bases[] = {int setup_i2c (unsigned i2c_index,int speed,int slave_addr,struct i2c_pads_info *p) { -char *name1, *name2; +char name[9 ];int ret;if (i2c_index >=ARRAY_SIZE (i2c_bases))return -EINVAL ; - name1 =malloc (9 ); - name2 =malloc (9 ); -if (!name1 || !name2) -return -ENOMEM ; - -sprintf (name1,"i2c_sda%d" , i2c_index); -sprintf (name2,"i2c_scl%d" , i2c_index); - ret =gpio_request (p->sda.gp, name1); +snprintf (name,sizeof (name),"i2c_sda%01d" , i2c_index); + ret =gpio_request (p->sda.gp, name);if (ret) - goto err_req1; +return ret; - ret =gpio_request (p->scl.gp, name2); +snprintf (name,sizeof (name),"i2c_scl%01d" , i2c_index); + ret =gpio_request (p->scl.gp, name);if (ret) - goto err_req2; + goto err_req;/* Enable i2c clock */ ret =enable_i2c_clk (1 , i2c_index);
@@ -112,11 +107,8 @@ int setup_i2c(unsigned i2c_index, int speed, int slave_addr, err_idle: err_clk:gpio_free (p->scl.gp); -err_req2: +err_req:gpio_free (p->sda.gp); -err_req1: -free (name1); -free (name2);return ret; }
Signature · 1 line
2.1.3
PATCH 2/8 arm: mx6: gw_ventana: Define CONFIG_SYS_MALLOC_F_LEN
This board uses setup_i2c() in SPL. The setup_i2c() function internally calls gpio_request(), which in turn internally calls strdup(). The strdup() requires a running mallocator, so this patch makes the mallocator available.
--- include/configs/gw_ventana.h | 1 + 1 file changed, 1 insertion(+)
include/configs/gw_ventana.h +1 -0
@@ -39,6 +39,7 @@/* Size of malloc() pool */ #define CONFIG_SYS_MALLOC_LEN (10 * 1024 * 1024) +#define CONFIG_SYS_MALLOC_F_LEN (1 << 10)/* Init Functions */ #define CONFIG_BOARD_EARLY_INIT_F
Signature · 1 line
2.1.3
PATCH 2/8 arm: mx6: gw_ventana: Define CONFIG_SYS_MALLOC_F_LEN
Quoted 4 lines · Marek Vasut
This board uses
setup_i2c()in SPL. Thesetup_i2c()function internally callsgpio_request(), which in turn internally callsstrdup(). Thestrdup()requires a running mallocator, so this patch makes the mallocator available.
Quoted 8 lines
Signed-off-by Marek Vasut <[email protected]>Cc Igor Grinberg <[email protected]>Cc Nikita Kiryanov <[email protected]>Cc Sean Cross <[email protected]>Cc Simon Glass <[email protected]>Cc Stefano Babic <[email protected]>Cc Tim Harvey <[email protected]>---
Applied to u-boot-imx, thanks !
Best regards,
Stefano Babic
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-53 Fax: +49-8142-66989-80 Email: sbabic at denx.de =====================================================================
PATCH 3/8 arm: mx6: novena: Define CONFIG_SYS_MALLOC_F_LEN
In reply to Marek VasutThis board uses setup_i2c() in SPL. The setup_i2c() function internally calls gpio_request(), which in turn internally calls strdup(). The strdup() requires a running mallocator, so this patch makes the mallocator available.
--- include/configs/novena.h | 1 + 1 file changed, 1 insertion(+)
include/configs/novena.h +1 -0
@@ -115,6 +115,7 @@#define CONFIG_SYS_MEMTEST_END 0x20000000#define CONFIG_SYS_MALLOC_LEN (64 * 1024 * 1024) +#define CONFIG_SYS_MALLOC_F_LEN (1 << 10)/* SPL */ #define CONFIG_SPL_FAT_SUPPORT
Signature · 1 line
2.1.3
PATCH 3/8 arm: mx6: novena: Define CONFIG_SYS_MALLOC_F_LEN
Quoted 21 lines · Marek Vasut
This board uses
setup_i2c()in SPL. Thesetup_i2c()function internally callsgpio_request(), which in turn internally callsstrdup(). Thestrdup()requires a running mallocator, so this patch makes the mallocator available.Signed-off-by Marek Vasut <[email protected]>Cc Igor Grinberg <[email protected]>Cc Nikita Kiryanov <[email protected]>Cc Sean Cross <[email protected]>Cc Simon Glass <[email protected]>Cc Stefano Babic <[email protected]>Cc Tim Harvey <[email protected]>--- include/configs/novena.h | 1 + 1 file changed, 1 insertion(+)include/configs/novena.h +0
-0
include/configs/novena.h line 121
Quoted 7 lines
include/configs/novena.h +1
-0@@ -115,6 +115,7 @@#define CONFIG_SYS_MEMTEST_END 0x20000000#define CONFIG_SYS_MALLOC_LEN (64 * 1024 * 1024) +#define CONFIG_SYS_MALLOC_F_LEN (1 << 10)/* SPL */ #define CONFIG_SPL_FAT_SUPPORT
Applied to u-boot-imx, thanks !
Best regards,
Stefano Babic
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-53 Fax: +49-8142-66989-80 Email: sbabic at denx.de =====================================================================
PATCH 4/8 arm: mx6: novena: Minor coding style fix
In reply to Marek VasutJust zap multiple spaces and replace them with tabs properly.
--- board/kosagi/novena/novena.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-)
board/kosagi/novena/novena.c +13 -13
@@ -172,19 +172,19 @@ struct display_info_t const displays[] = { .detect = detect_hdmi, .enable = enable_hdmi, .mode = { - .name = "HDMI", - .refresh = 60, - .xres = 1024, - .yres = 768, - .pixclock = 15385, - .left_margin = 220, - .right_margin = 40, - .upper_margin = 21, - .lower_margin = 7, - .hsync_len = 60, - .vsync_len = 10, - .sync = FB_SYNC_EXT, - .vmode = FB_VMODE_NONINTERLACED + .name = "HDMI", + .refresh = 60, + .xres = 1024, + .yres = 768, + .pixclock = 15385, + .left_margin = 220, + .right_margin = 40, + .upper_margin = 21, + .lower_margin = 7, + .hsync_len = 60, + .vsync_len = 10, + .sync = FB_SYNC_EXT, + .vmode = FB_VMODE_NONINTERLACED } } };
Signature · 1 line
2.1.3
PATCH 4/8 arm: mx6: novena: Minor coding style fix
Quoted 10 lines · Marek Vasut
Just zap multiple spaces and replace them with tabs properly.
Signed-off-by Marek Vasut <[email protected]>Cc Igor Grinberg <[email protected]>Cc Nikita Kiryanov <[email protected]>Cc Sean Cross <[email protected]>Cc Simon Glass <[email protected]>Cc Stefano Babic <[email protected]>Cc Tim Harvey <[email protected]>---
Applied to u-boot-imx, thanks !
Best regards,
Stefano Babic
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-53 Fax: +49-8142-66989-80 Email: sbabic at denx.de =====================================================================
PATCH 5/8 arm: mx6: novena: Minor config file fix
In reply to Marek VasutSequence like the following is completely useless and results from an errorneous ordering of the statements during development. Zap it.
#ifdef FOO
#define FOO
--- include/configs/novena.h | 1 - 1 file changed, 1 deletion(-)
include/configs/novena.h +0 -1
@@ -226,7 +226,6 @@/* Video output */ #ifdef CONFIG_VIDEO -#define CONFIG_VIDEO #define CONFIG_VIDEO_IPUV3 #define CONFIG_CFB_CONSOLE #define CONFIG_VGA_AS_SINGLE_DEVICE
Signature · 1 line
2.1.3
PATCH 5/8 arm: mx6: novena: Minor config file fix
Quoted 5 lines · Marek Vasut
Sequence like the following is completely useless and results from an errorneous ordering of the statements during development. Zap it.
#ifdef FOO
#define FOO
Quoted 8 lines
Signed-off-by Marek Vasut <[email protected]>Cc Igor Grinberg <[email protected]>Cc Nikita Kiryanov <[email protected]>Cc Sean Cross <[email protected]>Cc Simon Glass <[email protected]>Cc Stefano Babic <[email protected]>Cc Tim Harvey <[email protected]>---
Applied to u-boot-imx, thanks !
Best regards,
Stefano Babic
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-53 Fax: +49-8142-66989-80 Email: sbabic at denx.de =====================================================================
PATCH 6/8 arm: mx6: novena: Pull GPIO definitions into header
In reply to Marek VasutPull the definitions of GPIOs into a separate header file, so that they can be used across all source files.
--- board/kosagi/novena/novena.c | 6 ++---- board/kosagi/novena/novena.h | 23 +++++++++++++++++++++++ board/kosagi/novena/novena_spl.c | 10 ++-------- 3 files changed, 27 insertions(+), 12 deletions(-) create mode 100644 board/kosagi/novena/novena.h
board/kosagi/novena/novena.c +2 -4
@@ -36,11 +36,9 @@#include <power/pfuze100_pmic.h> #include <stdio_dev.h> -DECLARE_GLOBAL_DATA_PTR ; +#include "novena.h" -#define NOVENA_BUTTON_GPIO IMX_GPIO_NR(4, 14) -#define NOVENA_SD_WP IMX_GPIO_NR(1, 2) -#define NOVENA_SD_CD IMX_GPIO_NR(1, 4) +DECLARE_GLOBAL_DATA_PTR ;/* * GPIO button
board/kosagi/novena/novena.h new file +23 -0
@@ -0,0 +1,23 @@ +/* +* Novena board support +* +* Copyright (C) 2014 Marek Vasut <[email protected]> +* +* SPDX-License-Identifier: GPL-2.0+ +*/ + +#ifndef __BOARD_KOSAGI_NOVENA_NOVENA_H__ +#define __BOARD_KOSAGI_NOVENA_NOVENA_H__ + +#define NOVENA_AUDIO_PWRON IMX_GPIO_NR(5, 17) +#define NOVENA_BUTTON_GPIO IMX_GPIO_NR(4, 14) +#define NOVENA_FPGA_RESET_N_GPIO IMX_GPIO_NR(5, 7) +#define NOVENA_HDMI_GHOST_HPD IMX_GPIO_NR(5, 4) +#define NOVENA_PCIE_DISABLE_GPIO IMX_GPIO_NR(2, 16) +#define NOVENA_PCIE_POWER_ON_GPIO IMX_GPIO_NR(7, 12) +#define NOVENA_PCIE_RESET_GPIO IMX_GPIO_NR(3, 29) +#define NOVENA_PCIE_WAKE_UP_GPIO IMX_GPIO_NR(3, 22) +#define NOVENA_SD_CD IMX_GPIO_NR(1, 4) +#define NOVENA_SD_WP IMX_GPIO_NR(1, 2) + +#endif /* __BOARD_KOSAGI_NOVENA_NOVENA_H__ */
board/kosagi/novena/novena_spl.c +2 -8
@@ -25,6 +25,8 @@#include <asm/arch/mx6-ddr.h> +#include "novena.h" +DECLARE_GLOBAL_DATA_PTR ;#define UART_PAD_CTRL \
@@ -68,14 +70,6 @@ DECLARE_GLOBAL_DATA_PTR;#define PC MUX_PAD_CTRL(I2C_PAD_CTRL) -#define NOVENA_AUDIO_PWRON IMX_GPIO_NR(5, 17) -#define NOVENA_FPGA_RESET_N_GPIO IMX_GPIO_NR(5, 7) -#define NOVENA_HDMI_GHOST_HPD IMX_GPIO_NR(5, 4) -#define NOVENA_PCIE_RESET_GPIO IMX_GPIO_NR(3, 29) -#define NOVENA_PCIE_POWER_ON_GPIO IMX_GPIO_NR(7, 12) -#define NOVENA_PCIE_WAKE_UP_GPIO IMX_GPIO_NR(3, 22) -#define NOVENA_PCIE_DISABLE_GPIO IMX_GPIO_NR(2, 16) -/* * Audio */
Signature · 1 line
2.1.3
PATCH 6/8 arm: mx6: novena: Pull GPIO definitions into header
Quoted 11 lines · Marek Vasut
Pull the definitions of GPIOs into a separate header file, so that they can be used across all source files.
Signed-off-by Marek Vasut <[email protected]>Cc Igor Grinberg <[email protected]>Cc Nikita Kiryanov <[email protected]>Cc Sean Cross <[email protected]>Cc Simon Glass <[email protected]>Cc Stefano Babic <[email protected]>Cc Tim Harvey <[email protected]>---
Applied to u-boot-imx, thanks !
Best regards,
Stefano Babic
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-53 Fax: +49-8142-66989-80 Email: sbabic at denx.de =====================================================================
PATCH 7/8 arm: mx6: novena: Pull video handling into separate file
In reply to Marek VasutPull all of the video handling into a separate file, since a lot more code will be added and such code would polute the board file.
--- board/kosagi/novena/Makefile | 1 + board/kosagi/novena/novena.c | 79 +-------------------------------- board/kosagi/novena/novena.h | 2 + board/kosagi/novena/video.c | 102 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 106 insertions(+), 78 deletions(-) create mode 100644 board/kosagi/novena/video.c
board/kosagi/novena/Makefile +1 -0
@@ -8,4 +8,5 @@ ifdef CONFIG_SPL_BUILD obj-y := novena_spl.o else obj-y := novena.o +obj-$(CONFIG_VIDEO_IPUV3) += video.o endif
board/kosagi/novena/novena.c +1 -78
88 lines not on this page · raw message
board/kosagi/novena/novena.h +2 -0
@@ -20,4 +20,6 @@#define NOVENA_SD_CD IMX_GPIO_NR(1, 4)#define NOVENA_SD_WP IMX_GPIO_NR(1, 2) +void setup_display_clock (void ); +#endif /* __BOARD_KOSAGI_NOVENA_NOVENA_H__ */
board/kosagi/novena/video.c new file +102 -0
102 lines not on this page · raw message
Signature · 1 line
2.1.3
PATCH 7/8 arm: mx6: novena: Pull video handling into separate file
Quoted 11 lines · Marek Vasut
Pull all of the video handling into a separate file, since a lot more code will be added and such code would polute the board file.
Signed-off-by Marek Vasut <[email protected]>Cc Igor Grinberg <[email protected]>Cc Nikita Kiryanov <[email protected]>Cc Sean Cross <[email protected]>Cc Simon Glass <[email protected]>Cc Stefano Babic <[email protected]>Cc Tim Harvey <[email protected]>---
Applied to u-boot-imx, thanks !
Best regards,
Stefano Babic
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-53 Fax: +49-8142-66989-80 Email: sbabic at denx.de =====================================================================
PATCH 8/8 arm: mx6: novena: Add proper LVDS display support
In reply to Marek VasutRepair the register configuration and add proper support for the display attached to both LVDS channels.
--- board/kosagi/novena/novena.c | 8 + board/kosagi/novena/novena.h | 8 + board/kosagi/novena/novena_spl.c | 7 + board/kosagi/novena/video.c | 400 ++++++++++++++++++++++++++++++++++++--- include/configs/novena.h | 1 + 5 files changed, 401 insertions(+), 23 deletions(-)
board/kosagi/novena/novena.c +8 -0
@@ -173,6 +173,14 @@ int board_init(void)return 0 ; } +int board_late_init (void ) +{ +#if defined(CONFIG_VIDEO_IPUV3 ) +setup_display_lvds (); +#endif +return 0 ; +} +int checkboard (void ) {puts ("Board: Novena 4x\n" );
board/kosagi/novena/novena.h +8 -0
@@ -10,9 +10,12 @@#define __BOARD_KOSAGI_NOVENA_NOVENA_H__#define NOVENA_AUDIO_PWRON IMX_GPIO_NR(5, 17) +#define NOVENA_BACKLIGHT_PWM_GPIO IMX_GPIO_NR(4, 29) +#define NOVENA_BACKLIGHT_PWR_GPIO IMX_GPIO_NR(4, 15)#define NOVENA_BUTTON_GPIO IMX_GPIO_NR(4, 14)#define NOVENA_FPGA_RESET_N_GPIO IMX_GPIO_NR(5, 7)#define NOVENA_HDMI_GHOST_HPD IMX_GPIO_NR(5, 4) +#define NOVENA_ITE6251_PWR_GPIO IMX_GPIO_NR(5, 28)#define NOVENA_PCIE_DISABLE_GPIO IMX_GPIO_NR(2, 16)#define NOVENA_PCIE_POWER_ON_GPIO IMX_GPIO_NR(7, 12)#define NOVENA_PCIE_RESET_GPIO IMX_GPIO_NR(3, 29)
@@ -20,6 +23,11 @@#define NOVENA_SD_CD IMX_GPIO_NR(1, 4)#define NOVENA_SD_WP IMX_GPIO_NR(1, 2) +#define NOVENA_IT6251_I2C_BUS 2 +#define NOVENA_IT6251_CHIPADDR 0x5c +#define NOVENA_IT6251_LVDSADDR 0x5e +void setup_display_clock (void ); +void setup_display_lvds (void );#endif /* __BOARD_KOSAGI_NOVENA_NOVENA_H__ */
board/kosagi/novena/novena_spl.c +7 -0
@@ -386,6 +386,13 @@ static void novena_spl_setup_iomux_uart(void)static iomux_v3_cfg_t hdmi_pads[] = {/* "Ghost HPD" pin */ MX6_PAD_EIM_A24__GPIO5_IO04 |MUX_PAD_CTRL (NO_PAD_CTRL ), + +/* LCD_PWR_CTL */ +MX6_PAD_CSI0_DAT10__GPIO5_IO28 |MUX_PAD_CTRL (NO_PAD_CTRL ), +/* LCD_BL_ON */ +MX6_PAD_KEY_ROW4__GPIO4_IO15 |MUX_PAD_CTRL (NO_PAD_CTRL ), +/* GPIO_PWM1 */ +MX6_PAD_DISP0_DAT8__GPIO4_IO29 |MUX_PAD_CTRL (NO_PAD_CTRL ), };static void novena_spl_setup_iomux_video (void )
board/kosagi/novena/video.c +377 -23
440 lines not on this page · raw message
include/configs/novena.h +1 -0
@@ -12,6 +12,7 @@/* System configurations */ #define CONFIG_MX6 #define CONFIG_BOARD_EARLY_INIT_F +#define CONFIG_BOARD_LATE_INIT #define CONFIG_MISC_INIT_R #define CONFIG_DISPLAY_BOARDINFO #define CONFIG_DISPLAY_CPUINFO
Signature · 1 line
2.1.3
PATCH 8/8 arm: mx6: novena: Add proper LVDS display support
Hi Marek,
Quoted 10 lines · Marek Vasut
Repair the register configuration and add proper support for the display attached to both LVDS channels.
Signed-off-by Marek Vasut <[email protected]>Cc Igor Grinberg <[email protected]>Cc Nikita Kiryanov <[email protected]>Cc Sean Cross <[email protected]>Cc Simon Glass <[email protected]>Cc Stefano Babic <[email protected]>Cc Tim Harvey <[email protected]>
Quoted 7 lines
--- board/kosagi/novena/novena.c | 8 + board/kosagi/novena/novena.h | 8 + board/kosagi/novena/novena_spl.c | 7 + board/kosagi/novena/video.c | 400 ++++++++++++++++++++++++++++++++++++--- include/configs/novena.h | 1 + 5 files changed, 401 insertions(+), 23 deletions(-)
Could perhaps move the board to driver model for I2C.
Regards,
Simon
PATCH 8/8 arm: mx6: novena: Add proper LVDS display support
Quoted 23 lines · Simon Glass
Hi Marek,
Quoted 12 lines · Marek Vasut
Repair the register configuration and add proper support for the display attached to both LVDS channels.
Signed-off-by Marek Vasut <[email protected]>Cc Igor Grinberg <[email protected]>Cc Nikita Kiryanov <[email protected]>Cc Sean Cross <[email protected]>Cc Simon Glass <[email protected]>Cc Stefano Babic <[email protected]>Cc Tim Harvey <[email protected]>---
Quoted 7 lines
board/kosagi/novena/novena.c | 8 + board/kosagi/novena/novena.h | 8 + board/kosagi/novena/novena_spl.c | 7 + board/kosagi/novena/video.c | 400 ++++++++++++++++++++++++++++++++++++--- include/configs/novena.h | 1 + 5 files changed, 401 insertions(+), 23 deletions(-)
Quoted 1 line
Could perhaps move the board to driver model for I2C.
That's the plan, not only this one, but SoCFPGA in general and all the DENX boards.
Best regards,
Marek Vasut
PATCH 8/8 arm: mx6: novena: Add proper LVDS display support
In reply to Marek VasutQuoted 11 lines · Marek Vasut
Repair the register configuration and add proper support for the display attached to both LVDS channels.
Signed-off-by Marek Vasut <[email protected]>Cc Igor Grinberg <[email protected]>Cc Nikita Kiryanov <[email protected]>Cc Sean Cross <[email protected]>Cc Simon Glass <[email protected]>Cc Stefano Babic <[email protected]>Cc Tim Harvey <[email protected]>---
After fixing checkpatch warnings:
Applied to u-boot-imx, thanks !
Best regards,
Stefano Babic
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-53 Fax: +49-8142-66989-80 Email: sbabic at denx.de =====================================================================
PATCH 1/8 imx: i2c: Zap unnecessary malloc() calls
In reply to Marek Vasut2014-12-16 14:09 GMT+01:00 Marek Vasut <[email protected]>:
Quoted 68 lines
The
malloc()calls are unnecessary, just allocate the stuff on stack. While at it, reorder the code a little, so that only one variable is used for the text, usesnprintf()instead ofsprintf()and use %01d as a formatting string to avoid any possible overflows.Signed-off-by Marek Vasut <[email protected]>Cc Igor Grinberg <[email protected]>Cc Nikita Kiryanov <[email protected]>Cc Sean Cross <[email protected]>Cc Simon Glass <[email protected]>Cc Stefano Babic <[email protected]>Cc Tim Harvey <[email protected]>--- arch/arm/imx-common/i2c-mxv7.c | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-)arch/arm/imx-common/i2c-mxv7.c +8
-17@@ -73,26 +73,21 @@ static void * const i2c_bases[] = {int setup_i2c (unsigned i2c_index,int speed,int slave_addr,struct i2c_pads_info *p) { -char *name1, *name2; +char name[9 ];int ret;if (i2c_index >=ARRAY_SIZE (i2c_bases))return -EINVAL ; - name1 =malloc (9 ); - name2 =malloc (9 ); -if (!name1 || !name2) -return -ENOMEM ; - -sprintf (name1,"i2c_sda%d" , i2c_index); -sprintf (name2,"i2c_scl%d" , i2c_index); - ret =gpio_request (p->sda.gp, name1); +snprintf (name,sizeof (name),"i2c_sda%01d" , i2c_index); + ret =gpio_request (p->sda.gp, name);if (ret) - goto err_req1; +return ret; - ret =gpio_request (p->scl.gp, name2); +snprintf (name,sizeof (name),"i2c_scl%01d" , i2c_index); + ret =gpio_request (p->scl.gp, name);if (ret) - goto err_req2; + goto err_req;/* Enable i2c clock */ ret =enable_i2c_clk (1 , i2c_index);@@ -112,11 +107,8 @@ int setup_i2c(unsigned i2c_index, int speed, int slave_addr, err_idle: err_clk:gpio_free (p->scl.gp); -err_req2: +err_req:gpio_free (p->sda.gp); -err_req1: -free (name1); -free (name2);return ret; } --
Quoted 2 lines
2.1.3
PATCH 1/8 imx: i2c: Zap unnecessary malloc() calls
In reply to Marek VasutHi Marek,
Quoted 31 lines · Marek Vasut
The
malloc()calls are unnecessary, just allocate the stuff on stack. While at it, reorder the code a little, so that only one variable is used for the text, usesnprintf()instead ofsprintf()and use %01d as a formatting string to avoid any possible overflows.Signed-off-by Marek Vasut <[email protected]>Cc Igor Grinberg <[email protected]>Cc Nikita Kiryanov <[email protected]>Cc Sean Cross <[email protected]>Cc Simon Glass <[email protected]>Cc Stefano Babic <[email protected]>Cc Tim Harvey <[email protected]>--- arch/arm/imx-common/i2c-mxv7.c | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-)arch/arm/imx-common/i2c-mxv7.c +1
-1@@ -73,26 +73,21 @@ static void * const i2c_bases[] = {int setup_i2c (unsigned i2c_index,int speed,int slave_addr,struct i2c_pads_info *p) { -char *name1, *name2; +char name[9 ];int ret;if (i2c_index >=ARRAY_SIZE (i2c_bases))return -EINVAL ;
arch/arm/imx-common/i2c-mxv7.c static void * const i2c_bases[] = { · line 83
Quoted 10 lines
arch/arm/imx-common/i2c-mxv7.c +2
-8- name1 =malloc (9 ); - name2 =malloc (9 ); -if (!name1 || !name2) -return -ENOMEM ; - -sprintf (name1,"i2c_sda%d" , i2c_index); -sprintf (name2,"i2c_scl%d" , i2c_index); - ret =gpio_request (p->sda.gp, name1); +snprintf (name,sizeof (name),"i2c_sda%01d" , i2c_index); + ret =gpio_request (p->sda.gp, name);
Does this board use driver model? If not it should be easy to convert since one MX6 board supports it. With driver model there is gpio_requestf("i2c_sda%01d", i2c_index);
Quoted 27 lines
arch/arm/imx-common/i2c-mxv7.c +5
-8if (ret) - goto err_req1; +return ret; - ret =gpio_request (p->scl.gp, name2); +snprintf (name,sizeof (name),"i2c_scl%01d" , i2c_index); + ret =gpio_request (p->scl.gp, name);if (ret) - goto err_req2; + goto err_req;/* Enable i2c clock */ ret =enable_i2c_clk (1 , i2c_index);@@ -112,11 +107,8 @@ int setup_i2c(unsigned i2c_index, int speed, int slave_addr, err_idle: err_clk:gpio_free (p->scl.gp); -err_req2: +err_req:gpio_free (p->sda.gp); -err_req1: -free (name1); -free (name2);return ret; } --
Quoted 2 lines
2.1.3
Regards,
Simon
PATCH 1/8 imx: i2c: Zap unnecessary malloc() calls
Quoted 41 lines · Simon Glass
Hi Marek,
Quoted 38 lines · Marek Vasut
The
malloc()calls are unnecessary, just allocate the stuff on stack. While at it, reorder the code a little, so that only one variable is used for the text, usesnprintf()instead ofsprintf()and use %01d as a formatting string to avoid any possible overflows.Signed-off-by Marek Vasut <[email protected]>Cc Igor Grinberg <[email protected]>Cc Nikita Kiryanov <[email protected]>Cc Sean Cross <[email protected]>Cc Simon Glass <[email protected]>Cc Stefano Babic <[email protected]>Cc Tim Harvey <[email protected]>---
arch/arm/imx-common/i2c-mxv7.c | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-)(quoted diff) +0
-0
b/arch/arm/imx-common/i2c-mxv7.cindex 34f5387..1a632e7 100644arch/arm/imx-common/i2c-mxv7.c +1
-1@@ -73,26 +73,21 @@ static void * const i2c_bases[] = {int setup_i2c (unsigned i2c_index,int speed,int slave_addr,struct i2c_pads_info *p) { -char *name1, *name2; +char name[9 ];int ret;if (i2c_index >=ARRAY_SIZE (i2c_bases))return -EINVAL ;
Quoted 14 lines
arch/arm/imx-common/i2c-mxv7.c static void * const i2c_bases[] = { · line 83
Quoted 10 lines
arch/arm/imx-common/i2c-mxv7.c +2
-8- name1 =malloc (9 ); - name2 =malloc (9 ); -if (!name1 || !name2) -return -ENOMEM ; - -sprintf (name1,"i2c_sda%d" , i2c_index); -sprintf (name2,"i2c_scl%d" , i2c_index); - ret =gpio_request (p->sda.gp, name1); +snprintf (name,sizeof (name),"i2c_sda%01d" , i2c_index); + ret =gpio_request (p->sda.gp, name);Does this board use driver model? If not it should be easy to convert since one MX6 board supports it. With driver model there is
gpio_requestf("i2c_sda%01d", i2c_index);
No, not yet, but it's in the pipeline. I am already keeping an eye on a few conversion patches to get this done.
PATCH 1/8 imx: i2c: Zap unnecessary malloc() calls
In reply to Marek VasutQuoted 5 lines · Marek Vasut
The
malloc()calls are unnecessary, just allocate the stuff on stack. While at it, reorder the code a little, so that only one variable is used for the text, usesnprintf()instead ofsprintf()and use %01d as a formatting string to avoid any possible overflows.
Quoted 8 lines
Signed-off-by Marek Vasut <[email protected]>Cc Igor Grinberg <[email protected]>Cc Nikita Kiryanov <[email protected]>Cc Sean Cross <[email protected]>Cc Simon Glass <[email protected]>Cc Stefano Babic <[email protected]>Cc Tim Harvey <[email protected]>---
Applied to u-boot-imx, thanks !
Best regards,
Stefano Babic
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-53 Fax: +49-8142-66989-80 Email: sbabic at denx.de =====================================================================
PATCH 1/8 imx: i2c: Zap unnecessary malloc() calls
Quoted 15 lines · Stefano Babic
Quoted 5 lines · Marek Vasut
The
malloc()calls are unnecessary, just allocate the stuff on stack. While at it, reorder the code a little, so that only one variable is used for the text, usesnprintf()instead ofsprintf()and use %01d as a formatting string to avoid any possible overflows.Quoted 8 lines
Signed-off-by Marek Vasut <[email protected]>Cc Igor Grinberg <[email protected]>Cc Nikita Kiryanov <[email protected]>Cc Sean Cross <[email protected]>Cc Simon Glass <[email protected]>Cc Stefano Babic <[email protected]>Cc Tim Harvey <[email protected]>---
Quoted 1 line
Applied to u-boot-imx, thanks !
Hey!
hope you had a nice holiday :) You might want to apply 2/8 and 3/8 to current codebase and send it to Tom, since they fix real problem and the board doesn't boot without this. I should have separated them out, sorry.
Best regards,
Marek Vasut