linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] mmc: sdhci-cadence: fix logically and structurally dead code
@ 2018-04-19 15:59 Gustavo A. R. Silva
  2018-04-20  1:07 ` Masahiro Yamada
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Gustavo A. R. Silva @ 2018-04-19 15:59 UTC (permalink / raw)
  To: Masahiro Yamada, Adrian Hunter, Ulf Hansson
  Cc: linux-mmc, Linux Kernel Mailing List, Gustavo A. R. Silva

Currently, the code block inside the for loop will never execute
more than once, because the function returns inmediately after
the first iteration, hence the execution of the code at the second
iteration is structurally dead and, code at line 281: return 0; is
never reached.

Fix this by checking _ret_ before return.

Addresses-Coverity-ID: 1468009 ("Logically dead code")
Addresses-Coverity-ID: 1468002 ("Structurally dead code")
Suggested-by: Masahiro Yamada <yamada.masahiro@socionext.com>
Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com>
---
Changes in v2:
 - Update changelog.
 - Drop the 'Fixes' tag.
 - Add check on ret instead of removing the "return ret;" line.
 - Thanks to Masahiro Yamada for the feedback provided.

 drivers/mmc/host/sdhci-cadence.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/mmc/host/sdhci-cadence.c b/drivers/mmc/host/sdhci-cadence.c
index bc30d16..7a343b8 100644
--- a/drivers/mmc/host/sdhci-cadence.c
+++ b/drivers/mmc/host/sdhci-cadence.c
@@ -274,8 +274,8 @@ static int sdhci_cdns_set_tune_val(struct sdhci_host *host, unsigned int val)
 		ret = readl_poll_timeout(reg, tmp,
 					 !(tmp & SDHCI_CDNS_HRS06_TUNE_UP),
 					 0, 1);
-
-		return ret;
+		if (ret)
+			return ret;
 	}
 
 	return 0;
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] mmc: sdhci-cadence: fix logically and structurally dead code
  2018-04-19 15:59 [PATCH v2] mmc: sdhci-cadence: fix logically and structurally dead code Gustavo A. R. Silva
@ 2018-04-20  1:07 ` Masahiro Yamada
  2018-04-20  6:08 ` Adrian Hunter
  2018-04-20  7:10 ` Ulf Hansson
  2 siblings, 0 replies; 4+ messages in thread
From: Masahiro Yamada @ 2018-04-20  1:07 UTC (permalink / raw)
  To: Gustavo A. R. Silva
  Cc: Adrian Hunter, Ulf Hansson, linux-mmc, Linux Kernel Mailing List

2018-04-20 0:59 GMT+09:00 Gustavo A. R. Silva <gustavo@embeddedor.com>:
> Currently, the code block inside the for loop will never execute
> more than once, because the function returns inmediately after
> the first iteration, hence the execution of the code at the second
> iteration is structurally dead and, code at line 281: return 0; is
> never reached.
>
> Fix this by checking _ret_ before return.
>
> Addresses-Coverity-ID: 1468009 ("Logically dead code")
> Addresses-Coverity-ID: 1468002 ("Structurally dead code")
> Suggested-by: Masahiro Yamada <yamada.masahiro@socionext.com>
> Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com>
> ---

Looks good to me except the typo in the log

inmediately -> immediately


Acked-by: Masahiro Yamada <yamada.masahiro@socionext.com>


> Changes in v2:
>  - Update changelog.
>  - Drop the 'Fixes' tag.
>  - Add check on ret instead of removing the "return ret;" line.
>  - Thanks to Masahiro Yamada for the feedback provided.
>
>  drivers/mmc/host/sdhci-cadence.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/mmc/host/sdhci-cadence.c b/drivers/mmc/host/sdhci-cadence.c
> index bc30d16..7a343b8 100644
> --- a/drivers/mmc/host/sdhci-cadence.c
> +++ b/drivers/mmc/host/sdhci-cadence.c
> @@ -274,8 +274,8 @@ static int sdhci_cdns_set_tune_val(struct sdhci_host *host, unsigned int val)
>                 ret = readl_poll_timeout(reg, tmp,
>                                          !(tmp & SDHCI_CDNS_HRS06_TUNE_UP),
>                                          0, 1);
> -
> -               return ret;
> +               if (ret)
> +                       return ret;
>         }
>
>         return 0;
> --
> 2.7.4
>



-- 
Best Regards
Masahiro Yamada

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] mmc: sdhci-cadence: fix logically and structurally dead code
  2018-04-19 15:59 [PATCH v2] mmc: sdhci-cadence: fix logically and structurally dead code Gustavo A. R. Silva
  2018-04-20  1:07 ` Masahiro Yamada
@ 2018-04-20  6:08 ` Adrian Hunter
  2018-04-20  7:10 ` Ulf Hansson
  2 siblings, 0 replies; 4+ messages in thread
From: Adrian Hunter @ 2018-04-20  6:08 UTC (permalink / raw)
  To: Gustavo A. R. Silva, Masahiro Yamada, Ulf Hansson
  Cc: linux-mmc, Linux Kernel Mailing List

On 19/04/18 18:59, Gustavo A. R. Silva wrote:
> Currently, the code block inside the for loop will never execute
> more than once, because the function returns inmediately after
> the first iteration, hence the execution of the code at the second
> iteration is structurally dead and, code at line 281: return 0; is
> never reached.
> 
> Fix this by checking _ret_ before return.
> 
> Addresses-Coverity-ID: 1468009 ("Logically dead code")
> Addresses-Coverity-ID: 1468002 ("Structurally dead code")
> Suggested-by: Masahiro Yamada <yamada.masahiro@socionext.com>
> Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com>

Acked-by: Adrian Hunter <adrian.hunter@intel.com>

> ---
> Changes in v2:
>  - Update changelog.
>  - Drop the 'Fixes' tag.
>  - Add check on ret instead of removing the "return ret;" line.
>  - Thanks to Masahiro Yamada for the feedback provided.
> 
>  drivers/mmc/host/sdhci-cadence.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/mmc/host/sdhci-cadence.c b/drivers/mmc/host/sdhci-cadence.c
> index bc30d16..7a343b8 100644
> --- a/drivers/mmc/host/sdhci-cadence.c
> +++ b/drivers/mmc/host/sdhci-cadence.c
> @@ -274,8 +274,8 @@ static int sdhci_cdns_set_tune_val(struct sdhci_host *host, unsigned int val)
>  		ret = readl_poll_timeout(reg, tmp,
>  					 !(tmp & SDHCI_CDNS_HRS06_TUNE_UP),
>  					 0, 1);
> -
> -		return ret;
> +		if (ret)
> +			return ret;
>  	}
>  
>  	return 0;
> 

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] mmc: sdhci-cadence: fix logically and structurally dead code
  2018-04-19 15:59 [PATCH v2] mmc: sdhci-cadence: fix logically and structurally dead code Gustavo A. R. Silva
  2018-04-20  1:07 ` Masahiro Yamada
  2018-04-20  6:08 ` Adrian Hunter
@ 2018-04-20  7:10 ` Ulf Hansson
  2 siblings, 0 replies; 4+ messages in thread
From: Ulf Hansson @ 2018-04-20  7:10 UTC (permalink / raw)
  To: Gustavo A. R. Silva
  Cc: Masahiro Yamada, Adrian Hunter, linux-mmc, Linux Kernel Mailing List

On 19 April 2018 at 17:59, Gustavo A. R. Silva <gustavo@embeddedor.com> wrote:
> Currently, the code block inside the for loop will never execute
> more than once, because the function returns inmediately after
> the first iteration, hence the execution of the code at the second
> iteration is structurally dead and, code at line 281: return 0; is
> never reached.
>
> Fix this by checking _ret_ before return.
>
> Addresses-Coverity-ID: 1468009 ("Logically dead code")
> Addresses-Coverity-ID: 1468002 ("Structurally dead code")
> Suggested-by: Masahiro Yamada <yamada.masahiro@socionext.com>
> Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com>

Thanks, applied for next and by fixing the minor spelling mistake in
the changelog.

Kind regards
Uffe

> ---
> Changes in v2:
>  - Update changelog.
>  - Drop the 'Fixes' tag.
>  - Add check on ret instead of removing the "return ret;" line.
>  - Thanks to Masahiro Yamada for the feedback provided.
>
>  drivers/mmc/host/sdhci-cadence.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/mmc/host/sdhci-cadence.c b/drivers/mmc/host/sdhci-cadence.c
> index bc30d16..7a343b8 100644
> --- a/drivers/mmc/host/sdhci-cadence.c
> +++ b/drivers/mmc/host/sdhci-cadence.c
> @@ -274,8 +274,8 @@ static int sdhci_cdns_set_tune_val(struct sdhci_host *host, unsigned int val)
>                 ret = readl_poll_timeout(reg, tmp,
>                                          !(tmp & SDHCI_CDNS_HRS06_TUNE_UP),
>                                          0, 1);
> -
> -               return ret;
> +               if (ret)
> +                       return ret;
>         }
>
>         return 0;
> --
> 2.7.4
>

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2018-04-20  7:10 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-04-19 15:59 [PATCH v2] mmc: sdhci-cadence: fix logically and structurally dead code Gustavo A. R. Silva
2018-04-20  1:07 ` Masahiro Yamada
2018-04-20  6:08 ` Adrian Hunter
2018-04-20  7:10 ` Ulf Hansson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).