[U-Boot] [PATCH 1/3] ot1200: Fix error handling in board_mmc_init()

From: Fabio Estevam fabio.estevam@freescale.com
When an invalid USDHC port is passed we should return -EINVAL instead of 0.
Also, return the error immediately on fsl_esdhc_initialize() failure.
Cc: Christian Gmeiner christian.gmeiner@gmail.com Signed-off-by: Fabio Estevam fabio.estevam@freescale.com --- board/bachmann/ot1200/ot1200.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/board/bachmann/ot1200/ot1200.c b/board/bachmann/ot1200/ot1200.c index 007c1ef..93f3d65 100644 --- a/board/bachmann/ot1200/ot1200.c +++ b/board/bachmann/ot1200/ot1200.c @@ -173,7 +173,7 @@ struct fsl_esdhc_cfg usdhc_cfg[2] = {
int board_mmc_init(bd_t *bis) { - s32 status = 0; + int ret; u32 index = 0;
usdhc_cfg[0].sdhc_clk = mxc_get_clock(MXC_ESDHC3_CLK); @@ -196,13 +196,15 @@ int board_mmc_init(bd_t *bis) printf("Warning: you configured more USDHC controllers" "(%d) then supported by the board (%d)\n", index + 1, CONFIG_SYS_FSL_USDHC_NUM); - return status; + return -EINVAL; }
- status |= fsl_esdhc_initialize(bis, &usdhc_cfg[index]); + ret = fsl_esdhc_initialize(bis, &usdhc_cfg[index]); + if (ret) + return ret; }
- return status; + return 0; }
#define PC MUX_PAD_CTRL(I2C_PAD_CTRL)

From: Fabio Estevam fabio.estevam@freescale.com
When an invalid USDHC port is passed we should return -EINVAL instead of 0.
Also, return the error immediately on fsl_esdhc_initialize() failure.
Cc: Eric Nelson eric.nelson@boundarydevices.com Signed-off-by: Fabio Estevam fabio.estevam@freescale.com --- board/boundary/nitrogen6x/nitrogen6x.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/board/boundary/nitrogen6x/nitrogen6x.c b/board/boundary/nitrogen6x/nitrogen6x.c index fcd4d82..e8ea256 100644 --- a/board/boundary/nitrogen6x/nitrogen6x.c +++ b/board/boundary/nitrogen6x/nitrogen6x.c @@ -302,7 +302,7 @@ int board_mmc_getcd(struct mmc *mmc)
int board_mmc_init(bd_t *bis) { - s32 status = 0; + int ret; u32 index = 0;
usdhc_cfg[0].sdhc_clk = mxc_get_clock(MXC_ESDHC3_CLK); @@ -325,13 +325,15 @@ int board_mmc_init(bd_t *bis) printf("Warning: you configured more USDHC controllers" "(%d) then supported by the board (%d)\n", index + 1, CONFIG_SYS_FSL_USDHC_NUM); - return status; + return -EINVAL; }
- status |= fsl_esdhc_initialize(bis, &usdhc_cfg[index]); + ret = fsl_esdhc_initialize(bis, &usdhc_cfg[index]); + if (ret) + return ret; }
- return status; + return 0; } #endif

On 21/11/2014 19:42, Fabio Estevam wrote:
From: Fabio Estevam fabio.estevam@freescale.com
When an invalid USDHC port is passed we should return -EINVAL instead of 0.
Also, return the error immediately on fsl_esdhc_initialize() failure.
Cc: Eric Nelson eric.nelson@boundarydevices.com Signed-off-by: Fabio Estevam fabio.estevam@freescale.com
Applied to u-boot-imx, thanks !
Best regards, Stefano Babic
===================================================================== 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@denx.de =====================================================================

From: Fabio Estevam fabio.estevam@freescale.com
When an invalid USDHC port is passed we should return -EINVAL instead of 0.
Also, return the error immediately on fsl_esdhc_initialize() failure.
Cc: Eric Benard eric@eukrea.com Signed-off-by: Fabio Estevam fabio.estevam@freescale.com --- board/embest/mx6boards/mx6boards.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/board/embest/mx6boards/mx6boards.c b/board/embest/mx6boards/mx6boards.c index 02fb3fa..f8c7468 100644 --- a/board/embest/mx6boards/mx6boards.c +++ b/board/embest/mx6boards/mx6boards.c @@ -216,7 +216,7 @@ int board_mmc_getcd(struct mmc *mmc)
int board_mmc_init(bd_t *bis) { - s32 status = 0; + int ret; int i;
/* @@ -268,13 +268,15 @@ int board_mmc_init(bd_t *bis) printf("Warning: you configured more USDHC controllers" "(%d) then supported by the board (%d)\n", i + 1, CONFIG_SYS_FSL_USDHC_NUM); - return status; + return -EINVAL; }
- status |= fsl_esdhc_initialize(bis, &usdhc_cfg[i]); + ret = fsl_esdhc_initialize(bis, &usdhc_cfg[i]); + if (ret) + return ret; }
- return status; + return 0; } #endif

On 21/11/2014 19:42, Fabio Estevam wrote:
From: Fabio Estevam fabio.estevam@freescale.com
When an invalid USDHC port is passed we should return -EINVAL instead of 0.
Also, return the error immediately on fsl_esdhc_initialize() failure.
Cc: Eric Benard eric@eukrea.com Signed-off-by: Fabio Estevam fabio.estevam@freescale.com
Applied to u-boot-imx, thanks !
Best regards, Stefano Babic

Hi Fabio,
On 11/21/2014 08:42 PM, Fabio Estevam wrote:
From: Fabio Estevam fabio.estevam@freescale.com
When an invalid USDHC port is passed we should return -EINVAL instead of 0.
Also, return the error immediately on fsl_esdhc_initialize() failure.
Cc: Eric Benard eric@eukrea.com Signed-off-by: Fabio Estevam fabio.estevam@freescale.com
board/embest/mx6boards/mx6boards.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/board/embest/mx6boards/mx6boards.c b/board/embest/mx6boards/mx6boards.c index 02fb3fa..f8c7468 100644 --- a/board/embest/mx6boards/mx6boards.c +++ b/board/embest/mx6boards/mx6boards.c @@ -216,7 +216,7 @@ int board_mmc_getcd(struct mmc *mmc)
int board_mmc_init(bd_t *bis) {
- s32 status = 0;
int ret; int i;
/*
@@ -268,13 +268,15 @@ int board_mmc_init(bd_t *bis) printf("Warning: you configured more USDHC controllers" "(%d) then supported by the board (%d)\n", i + 1, CONFIG_SYS_FSL_USDHC_NUM);
return status;
}return -EINVAL;
status |= fsl_esdhc_initialize(bis, &usdhc_cfg[i]);
ret = fsl_esdhc_initialize(bis, &usdhc_cfg[i]);
if (ret)
}return ret;
- return status;
- return 0; } #endif
Excuse me for the (very) late question, but just stumbled upon this patch.
Isn't it possible to continue the initialization of the next ESDHC module when the current one fails?
Even if there's a case of common initialization failure across all ESDHC interfaces, isn't it better to continue the initialization and preserve the interface abstraction, as if we don't know the implementation details, e.g. pretend we don't know there's a common failure mechanism across all ESDHCs and still try to init them 1 by 1.
Please don't consider this as NACK, I'm just sharing my thoughts.
Kind regards, Nikolay

On Mon, Dec 22, 2014 at 2:32 PM, Nikolay Dimitrov picmaster@mail.bg wrote:
Excuse me for the (very) late question, but just stumbled upon this patch.
Isn't it possible to continue the initialization of the next ESDHC module when the current one fails?
If the initialization of any esdhc port failed, it means that something very bad happened, so better to return the error immediately.
Regards,
Fabio Estevam

On 21/11/2014 19:42, Fabio Estevam wrote:
From: Fabio Estevam fabio.estevam@freescale.com
When an invalid USDHC port is passed we should return -EINVAL instead of 0.
Also, return the error immediately on fsl_esdhc_initialize() failure.
Cc: Christian Gmeiner christian.gmeiner@gmail.com Signed-off-by: Fabio Estevam fabio.estevam@freescale.com
Applied to u-boot-imx, thanks !
Best regards, Stefano Babic

2014-11-24 12:05 GMT+01:00 Stefano Babic sbabic@denx.de:
On 21/11/2014 19:42, Fabio Estevam wrote:
From: Fabio Estevam fabio.estevam@freescale.com
When an invalid USDHC port is passed we should return -EINVAL instead of 0.
Also, return the error immediately on fsl_esdhc_initialize() failure.
Cc: Christian Gmeiner christian.gmeiner@gmail.com Signed-off-by: Fabio Estevam fabio.estevam@freescale.com
Applied to u-boot-imx, thanks !
Thanks Fabio for the patch!
greets -- Christian Gmeiner, MSc
participants (4)
-
Christian Gmeiner
-
Fabio Estevam
-
Nikolay Dimitrov
-
Stefano Babic