diff mbox

[U-Boot,1/2] spi: bfin_spi: Remove unnecessary test for bus and pins[bus]

Message ID 1385782695.28549.2.camel@phoenix
State Accepted
Delegated to: Sonic Zhang
Headers show

Commit Message

Axel Lin Nov. 30, 2013, 3:38 a.m. UTC
For invalid bus number, current code returns NULL in the default case of
switch-case statements. In additional, pins[bus] is always not NULL because
it is the address of specific row of the two-dimensional array.
Thus this patch removes these unnecessary test.

Signed-off-by: Axel Lin <axel.lin@ingics.com>
---
Also adjust the code position to avoid checkpatch.pl warning:
ERROR: trailing statements should be on next line

 drivers/spi/bfin_spi.c | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)

Comments

Scott Jiang Dec. 2, 2013, 3:42 a.m. UTC | #1
2013/11/30 Axel Lin <axel.lin@ingics.com>:
> For invalid bus number, current code returns NULL in the default case of
> switch-case statements. In additional, pins[bus] is always not NULL because
> it is the address of specific row of the two-dimensional array.
> Thus this patch removes these unnecessary test.
>
> Signed-off-by: Axel Lin <axel.lin@ingics.com>
> ---
> Also adjust the code position to avoid checkpatch.pl warning:
> ERROR: trailing statements should be on next line
>
>  drivers/spi/bfin_spi.c | 17 +++++++++--------
>  1 file changed, 9 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/spi/bfin_spi.c b/drivers/spi/bfin_spi.c
> index bb88f30..aa89d89 100644
> --- a/drivers/spi/bfin_spi.c
> +++ b/drivers/spi/bfin_spi.c
> @@ -162,21 +162,22 @@ struct spi_slave *spi_setup_slave(unsigned int bus, unsigned int cs,
>         if (!spi_cs_is_valid(bus, cs))
>                 return NULL;
>
> -       if (bus >= ARRAY_SIZE(pins) || pins[bus] == NULL) {
> -               debug("%s: invalid bus %u\n", __func__, bus);
> -               return NULL;
> -       }
>         switch (bus) {
>  #ifdef SPI0_CTL
> -               case 0: mmr_base = SPI0_CTL; break;
> +       case 0:
> +               mmr_base = SPI0_CTL; break;
>  #endif
>  #ifdef SPI1_CTL
> -               case 1: mmr_base = SPI1_CTL; break;
> +       case 1:
> +               mmr_base = SPI1_CTL; break;
>  #endif
>  #ifdef SPI2_CTL
> -               case 2: mmr_base = SPI2_CTL; break;
> +       case 2:
> +               mmr_base = SPI2_CTL; break;
>  #endif
> -               default: return NULL;
> +       default:
> +               debug("%s: invalid bus %u\n", __func__, bus);
> +               return NULL;
>         }
>
>         bss = spi_alloc_slave(struct bfin_spi_slave, bus, cs);
> --

Acked-by: Scott Jiang <scott.jiang.linux@gmail.com>
diff mbox

Patch

diff --git a/drivers/spi/bfin_spi.c b/drivers/spi/bfin_spi.c
index bb88f30..aa89d89 100644
--- a/drivers/spi/bfin_spi.c
+++ b/drivers/spi/bfin_spi.c
@@ -162,21 +162,22 @@  struct spi_slave *spi_setup_slave(unsigned int bus, unsigned int cs,
 	if (!spi_cs_is_valid(bus, cs))
 		return NULL;
 
-	if (bus >= ARRAY_SIZE(pins) || pins[bus] == NULL) {
-		debug("%s: invalid bus %u\n", __func__, bus);
-		return NULL;
-	}
 	switch (bus) {
 #ifdef SPI0_CTL
-		case 0: mmr_base = SPI0_CTL; break;
+	case 0:
+		mmr_base = SPI0_CTL; break;
 #endif
 #ifdef SPI1_CTL
-		case 1: mmr_base = SPI1_CTL; break;
+	case 1:
+		mmr_base = SPI1_CTL; break;
 #endif
 #ifdef SPI2_CTL
-		case 2: mmr_base = SPI2_CTL; break;
+	case 2:
+		mmr_base = SPI2_CTL; break;
 #endif
-		default: return NULL;
+	default:
+		debug("%s: invalid bus %u\n", __func__, bus);
+		return NULL;
 	}
 
 	bss = spi_alloc_slave(struct bfin_spi_slave, bus, cs);