Patchwork [U-Boot,v3,1/3] mx6qsabresd: Fix card detection for invalid card id case

login
register
mail settings
Submitter Otavio Salvador
Date March 6, 2013, 3:46 p.m.
Message ID <1362584767-14105-2-git-send-email-otavio@ossystems.com.br>
Download mbox | patch
Permalink /patch/225533/
State Superseded
Delegated to: Stefano Babic
Headers show

Comments

Otavio Salvador - March 6, 2013, 3:46 p.m.
This changes the code so in case an unkown value is passed it will
return as invalid.

Signed-off-by: Otavio Salvador <otavio@ossystems.com.br>
---
Changes in v3: None
Changes in v2:
- Rework code to use a 'ret' variable (Fabio)

 board/freescale/mx6qsabresd/mx6qsabresd.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
Stefano Babic - March 13, 2013, 8:10 a.m.
On 06/03/2013 16:46, Otavio Salvador wrote:
> This changes the code so in case an unkown value is passed it will
> return as invalid.
> 
> Signed-off-by: Otavio Salvador <otavio@ossystems.com.br>
> ---

Hi Otavio,

> Changes in v3: None
> Changes in v2:
> - Rework code to use a 'ret' variable (Fabio)
> 
>  board/freescale/mx6qsabresd/mx6qsabresd.c | 11 +++++++----
>  1 file changed, 7 insertions(+), 4 deletions(-)
> 
> diff --git a/board/freescale/mx6qsabresd/mx6qsabresd.c b/board/freescale/mx6qsabresd/mx6qsabresd.c
> index 65c4a1a..e556476 100644
> --- a/board/freescale/mx6qsabresd/mx6qsabresd.c
> +++ b/board/freescale/mx6qsabresd/mx6qsabresd.c
> @@ -145,15 +145,18 @@ struct fsl_esdhc_cfg usdhc_cfg[3] = {
>  int board_mmc_getcd(struct mmc *mmc)
>  {
>  	struct fsl_esdhc_cfg *cfg = (struct fsl_esdhc_cfg *)mmc->priv;
> +	int ret = 0;
>  
>  	switch (cfg->esdhc_base) {
>  	case USDHC2_BASE_ADDR:
> -		return !gpio_get_value(USDHC2_CD_GPIO);
> +		ret = !gpio_get_value(USDHC2_CD_GPIO);

I do not understand. Is there no "break" statement here ? ret will be
overwritten then.

>  	case USDHC3_BASE_ADDR:
> -		return !gpio_get_value(USDHC3_CD_GPIO);
> -	default:
> -		return 1; /* eMMC/uSDHC4 is always present */
> +		ret = !gpio_get_value(USDHC3_CD_GPIO);
> +	case USDHC4_BASE_ADDR:
> +		ret = 1; /* eMMC/uSDHC4 is always present */
>  	}
> +
> +	return ret;
>  }
>  
>  int board_mmc_init(bd_t *bis)
> 

Best regards,
Stefano Babic
Otavio Salvador - March 13, 2013, 3:10 p.m.
On Wed, Mar 13, 2013 at 5:10 AM, Stefano Babic <sbabic@denx.de> wrote:
> On 06/03/2013 16:46, Otavio Salvador wrote:
>> This changes the code so in case an unkown value is passed it will
>> return as invalid.
>>
>> Signed-off-by: Otavio Salvador <otavio@ossystems.com.br>
>> ---
>
> Hi Otavio,
>
>> Changes in v3: None
>> Changes in v2:
>> - Rework code to use a 'ret' variable (Fabio)
>>
>>  board/freescale/mx6qsabresd/mx6qsabresd.c | 11 +++++++----
>>  1 file changed, 7 insertions(+), 4 deletions(-)
>>
>> diff --git a/board/freescale/mx6qsabresd/mx6qsabresd.c b/board/freescale/mx6qsabresd/mx6qsabresd.c
>> index 65c4a1a..e556476 100644
>> --- a/board/freescale/mx6qsabresd/mx6qsabresd.c
>> +++ b/board/freescale/mx6qsabresd/mx6qsabresd.c
>> @@ -145,15 +145,18 @@ struct fsl_esdhc_cfg usdhc_cfg[3] = {
>>  int board_mmc_getcd(struct mmc *mmc)
>>  {
>>       struct fsl_esdhc_cfg *cfg = (struct fsl_esdhc_cfg *)mmc->priv;
>> +     int ret = 0;
>>
>>       switch (cfg->esdhc_base) {
>>       case USDHC2_BASE_ADDR:
>> -             return !gpio_get_value(USDHC2_CD_GPIO);
>> +             ret = !gpio_get_value(USDHC2_CD_GPIO);
>
> I do not understand. Is there no "break" statement here ? ret will be
> overwritten then.

Good catch and this will indeed fail. I did the change when Fabio
asked but did not test it. I will rework it and test, before sending
new version of patchset.

>>       case USDHC3_BASE_ADDR:
>> -             return !gpio_get_value(USDHC3_CD_GPIO);
>> -     default:
>> -             return 1; /* eMMC/uSDHC4 is always present */
>> +             ret = !gpio_get_value(USDHC3_CD_GPIO);
>> +     case USDHC4_BASE_ADDR:
>> +             ret = 1; /* eMMC/uSDHC4 is always present */
>>       }
>> +
>> +     return ret;
>>  }
>>
>>  int board_mmc_init(bd_t *bis)
>>
>
> 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
> =====================================================================

Patch

diff --git a/board/freescale/mx6qsabresd/mx6qsabresd.c b/board/freescale/mx6qsabresd/mx6qsabresd.c
index 65c4a1a..e556476 100644
--- a/board/freescale/mx6qsabresd/mx6qsabresd.c
+++ b/board/freescale/mx6qsabresd/mx6qsabresd.c
@@ -145,15 +145,18 @@  struct fsl_esdhc_cfg usdhc_cfg[3] = {
 int board_mmc_getcd(struct mmc *mmc)
 {
 	struct fsl_esdhc_cfg *cfg = (struct fsl_esdhc_cfg *)mmc->priv;
+	int ret = 0;
 
 	switch (cfg->esdhc_base) {
 	case USDHC2_BASE_ADDR:
-		return !gpio_get_value(USDHC2_CD_GPIO);
+		ret = !gpio_get_value(USDHC2_CD_GPIO);
 	case USDHC3_BASE_ADDR:
-		return !gpio_get_value(USDHC3_CD_GPIO);
-	default:
-		return 1; /* eMMC/uSDHC4 is always present */
+		ret = !gpio_get_value(USDHC3_CD_GPIO);
+	case USDHC4_BASE_ADDR:
+		ret = 1; /* eMMC/uSDHC4 is always present */
 	}
+
+	return ret;
 }
 
 int board_mmc_init(bd_t *bis)