wandboard: Return error if the SDHC port index is invalid
PATCH 1/9 wandboard: Return error if the SDHC port index is invalid
When the SDHC port number index is invalid we should return an error code immediately.
Currently we return 'status', which has a value of zero, causing board_mmc_init() to incorrectly return sucess.
Fix this by returning -EINVAL instead.
--- board/wandboard/wandboard.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
board/wandboard/wandboard.c +1 -1
@@ -164,7 +164,7 @@ 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]);
Signature · 1 line
1.8.1.2
PATCH 2/9 mx53loco: Return error if the SDHC port index is invalid
When the SDHC port number index is invalid we should return an error code immediately.
Currently we return 'status', which has a value of zero, causing board_mmc_init() to incorrectly return sucess.
Fix this by returning -EINVAL instead.
--- board/freescale/mx53loco/mx53loco.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
board/freescale/mx53loco/mx53loco.c +1 -1
@@ -204,7 +204,7 @@ int board_mmc_init(bd_t *bis)printf ("Warning: you configured more ESDHC controller" "(%d) as supported by the board(2)\n" ,CONFIG_SYS_FSL_ESDHC_NUM ); -return status; +return -EINVAL ; } status |=fsl_esdhc_initialize (bis, &esdhc_cfg[index]); }
Signature · 1 line
1.8.1.2
PATCH 3/9 mx51evk: Return error if the SDHC port index is invalid
In reply to Fabio EstevamWhen the SDHC port number index is invalid we should return an error code immediately.
Currently we return 'status', which has a value of zero, causing board_mmc_init() to incorrectly return sucess.
Fix this by returning -EINVAL instead.
--- board/freescale/mx51evk/mx51evk.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
board/freescale/mx51evk/mx51evk.c +1 -1
@@ -356,7 +356,7 @@ int board_mmc_init(bd_t *bis)printf ("Warning: you configured more ESDHC controller" "(%d) as supported by the board(2)\n" ,CONFIG_SYS_FSL_ESDHC_NUM ); -return status; +return -EINVAL ; } status |=fsl_esdhc_initialize (bis, &esdhc_cfg[index]); }
Signature · 1 line
1.8.1.2
PATCH 4/9 mx53ard: Return error if the SDHC port index is invalid
In reply to Fabio EstevamWhen the SDHC port number index is invalid we should return an error code immediately.
Currently we return 'status', which has a value of zero, causing board_mmc_init() to incorrectly return sucess.
Fix this by returning -EINVAL instead.
--- board/freescale/mx53ard/mx53ard.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
board/freescale/mx53ard/mx53ard.c +1 -1
@@ -201,7 +201,7 @@ int board_mmc_init(bd_t *bis)printf ("Warning: you configured more ESDHC controller" "(%d) as supported by the board(2)\n" ,CONFIG_SYS_FSL_ESDHC_NUM ); -return status; +return -EINVAL ; } status |=fsl_esdhc_initialize (bis, &esdhc_cfg[index]); }
Signature · 1 line
1.8.1.2
PATCH 5/9 mx53evk: Return error if the SDHC port index is invalid
In reply to Fabio EstevamWhen the SDHC port number index is invalid we should return an error code immediately.
Currently we return 'status', which has a value of zero, causing board_mmc_init() to incorrectly return sucess.
Fix this by returning -EINVAL instead.
--- board/freescale/mx53evk/mx53evk.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
board/freescale/mx53evk/mx53evk.c +1 -1
@@ -230,7 +230,7 @@ int board_mmc_init(bd_t *bis)printf ("Warning: you configured more ESDHC controller" "(%d) as supported by the board(2)\n" ,CONFIG_SYS_FSL_ESDHC_NUM ); -return status; +return -EINVAL ; } status |=fsl_esdhc_initialize (bis, &esdhc_cfg[index]); }
Signature · 1 line
1.8.1.2
PATCH 6/9 mx53smd: Return error if the SDHC port index is invalid
In reply to Fabio EstevamWhen the SDHC port number index is invalid we should return an error code immediately.
Currently we return 'status', which has a value of zero, causing board_mmc_init() to incorrectly return sucess.
Fix this by returning -EINVAL instead.
--- board/freescale/mx53smd/mx53smd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
board/freescale/mx53smd/mx53smd.c +1 -1
@@ -137,7 +137,7 @@ int board_mmc_init(bd_t *bis)printf ("Warning: you configured more ESDHC controller" "(%d) as supported by the board(1)\n" ,CONFIG_SYS_FSL_ESDHC_NUM ); -return status; +return -EINVAL ; } status |=fsl_esdhc_initialize (bis, &esdhc_cfg[index]); }
Signature · 1 line
1.8.1.2
PATCH 7/9 mx6qarm2: Return error if the SDHC port index is invalid
In reply to Fabio EstevamWhen the SDHC port number index is invalid we should return an error code immediately.
Currently we return 'status', which has a value of zero, causing board_mmc_init() to incorrectly return sucess.
Fix this by returning -EINVAL instead.
--- board/freescale/mx6qarm2/mx6qarm2.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
board/freescale/mx6qarm2/mx6qarm2.c +1 -1
@@ -156,7 +156,7 @@ 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]);
Signature · 1 line
1.8.1.2
PATCH 8/9 mx6qsabrelite: Return error if the SDHC port index is invalid
In reply to Fabio EstevamWhen the SDHC port number index is invalid we should return an error code immediately.
Currently we return 'status', which has a value of zero, causing board_mmc_init() to incorrectly return sucess.
Fix this by returning -EINVAL instead.
--- board/freescale/mx6qsabrelite/mx6qsabrelite.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
board/freescale/mx6qsabrelite/mx6qsabrelite.c +1 -1
@@ -287,7 +287,7 @@ 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]);
Signature · 1 line
1.8.1.2
PATCH 9/9 mx6qsabresd: Return error if the SDHC port index is invalid
In reply to Fabio EstevamWhen the SDHC port number index is invalid we should return an error code immediately.
Currently we return 'status', which has a value of zero, causing board_mmc_init() to incorrectly return sucess.
Fix this by returning -EINVAL instead.
--- board/freescale/mx6qsabresd/mx6qsabresd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
board/freescale/mx6qsabresd/mx6qsabresd.c +1 -1
@@ -198,7 +198,7 @@ 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]);
Signature · 1 line
1.8.1.2
PATCH 1/9 wandboard: Return error if the SDHC port index is invalid
In reply to Fabio EstevamQuoted 10 lines · Fabio Estevam
When the SDHC port number index is invalid we should return an error code immediately.
Currently we return 'status', which has a value of zero, causing
board_mmc_init()to incorrectly return sucess.Fix this by returning
-EINVALinstead.Signed-off-by Fabio Estevam <[email protected]>
When I looked at this code I didn't change it because it raises a warning. So it returns the status if any failed.
Signature · 3 lines
Otavio Salvador O.S. Systems http://www.ossystems.com.br http://projetos.ossystems.com.br Mobile: +55 (53) 9981-7854 Mobile: +1 (347) 903-9750
PATCH 1/9 wandboard: Return error if the SDHC port index is invalid
Quoted 2 lines · Otavio Salvador
When I looked at this code I didn't change it because it raises a warning. So it returns the status if any failed.
Which warning are you talking about? Build warning or run-time warning?
I did not see any of these here.
status is zero at that point of code, so we should not 'return 0' on failure.
PATCH 1/9 wandboard: Return error if the SDHC port index is invalid
Quoted 5 lines · Fabio Estevam
Quoted 1 line · Otavio Salvador
When I looked at this code I didn't change it because it raises a
warning.
Quoted 9 lines
Quoted 1 line
So it returns the status if any failed.
Which warning are you talking about? Build warning or run-time warning?
I did not see any of these here.
status is zero at that point of code, so we should not 'return 0' on failure.
In the loop; it does:
status |= fsl...
so it gets the output of it. In case any fails it won't be 0.
Signature · 3 lines
Otavio Salvador O.S. Systems http://www.ossystems.com.br http://projetos.ossystems.com.br Mobile: +55 (53) 9981-7854 Mobile: +1 (347) 903-9750
PATCH 1/9 wandboard: Return error if the SDHC port index is invalid
Quoted 5 lines · Otavio Salvador
In the loop; it does:
status |= fsl...
so it gets the output of it. In case any fails it won't be 0.
It's good practice to return immediately when an error condition happens.
PATCH 1/9 wandboard: Return error if the SDHC port index is invalid
Quoted 11 lines · Fabio Estevam
Quoted 5 lines · Otavio Salvador
In the loop; it does:
status |= fsl...
so it gets the output of it. In case any fails it won't be 0.
It's good practice to return immediately when an error condition happens.
Well the idea of the code was to return in case anything goes wrong. So it outputs a 'WARN'. If you wish to change this, please change to ERROR.
Signature · 3 lines
Otavio Salvador O.S. Systems http://www.ossystems.com.br http://projetos.ossystems.com.br Mobile: +55 (53) 9981-7854 Mobile: +1 (347) 903-9750
PATCH 1/9 wandboard: Return error if the SDHC port index is invalid
In reply to Fabio EstevamDear Fabio Estevam,
Quoted 7 lines · In message <[email protected]> you…
When the SDHC port number index is invalid we should return an error code immediately.
Currently we return 'status', which has a value of zero, causing
board_mmc_init()to incorrectly return sucess.Fix this by returning
-EINVALinstead.
Can we _please_ remove all this code? A _runtime_ check for a _build_ _time_ _detectable_ situation makes no sense to me.
For such a misconfiguration, the build should fail.
Handling this at runtime is the wrong approach.
This comment applies for the whole series.
Actually - are you not surprised that you have to fix the same issue for all boards? This is a clear indication of duplicated code that needs to be factored out.
Best regards,
Wolfgang Denk
Signature · 6 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 There are two kinds of people, those who do the work and those who take the credit. Try to be in the first group; there is less competition there. - Indira Gandhi
PATCH 1/9 wandboard: Return error if the SDHC port index is invalid
Hi Wolfgang,
Quoted 9 lines · Wolfgang Denk
Can we _please_ remove all this code? A _runtime_ check for a _build_ _time_ _detectable_ situation makes no sense to me.
For such a misconfiguration, the build should fail.
Handling this at runtime is the wrong approach.
This comment applies for the whole series.
For the wandboard file, would the code bellow be better?
for (index = 0; index < CONFIG_SYS_FSL_USDHC_NUM; ++index) {
switch (index) {
case 0:
imx_iomux_v3_setup_multiple_pads(
usdhc3_pads, ARRAY_SIZE(usdhc3_pads));
usdhc_cfg[0].sdhc_clk = mxc_get_clock(MXC_ESDHC3_CLK);
usdhc_cfg[0].max_bus_width = 4;
gpio_direction_input(USDHC3_CD_GPIO);
break;
case 1:
imx_iomux_v3_setup_multiple_pads(
usdhc1_pads, ARRAY_SIZE(usdhc1_pads));
usdhc_cfg[1].sdhc_clk = mxc_get_clock(MXC_ESDHC_CLK);
usdhc_cfg[1].max_bus_width = 4;
gpio_direction_input(USDHC1_CD_GPIO);
break;
}
status = fsl_esdhc_initialize(bis, &usdhc_cfg[index]);
if (status)
return status;
}
return 0; Quoted 5 lines
Actually - are you not surprised that you have to fix the same issue for all boards? This is a clear indication of duplicated code that needs to be factored out.
I will try factor out.
Regards,
Fabio Estevam