Skip to contentSkip to conversation

spi: bfin_spi: Remove unnecessary test for bus and pins[bus]

PATCH New Axel Lin 2 participants 4 messages Nov 30, 2013 – Dec 2, 2013 SPI

lore
Share & tools
lore

Axel Lin

author
#0 lore raw

PATCH 1/2 spi: bfin_spi: Remove unnecessary test for bus and pins[bus]

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.

---
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(-)
drivers/spi/bfin_spi.c +9 -8
index bb88f30..aa89d89 100644
@@ -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);
Signature · 1 line
1.8.1.2
author
#1 lore raw

PATCH 2/2 spi: bfin_spi6xx: Remove unnecessary test for bus and pins[bus]

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.

---
 drivers/spi/bfin_spi6xx.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
drivers/spi/bfin_spi6xx.c +1 -4
index c25c4a9..07b833d 100644
@@ -154,10 +154,6 @@ 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_REGBASE
 	case 0:
@@ -175,6 +171,7 @@ struct spi_slave *spi_setup_slave(unsigned int bus, unsigned int cs,
 		break;
 #endif
 	default:
+		debug("%s: invalid bus %u\n", __func__, bus);
 		return NULL;
 	}
 
Signature · 1 line
1.8.1.2
#3 lore raw

PATCH 1/2 spi: bfin_spi: Remove unnecessary test for bus and pins[bus]

In reply to Axel Lin

2013/11/30 Axel Lin <[email protected]>:

Quoted 39 lines

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.

---
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(-)
drivers/spi/bfin_spi.c +5 -7
index bb88f30..aa89d89 100644
@@ -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:

drivers/spi/bfin_spi.c struct spi_slave *spi_setup_slave(unsigned int bus, unsigned int cs,

Quoted 10 lines
drivers/spi/bfin_spi.c +4 -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);
--
#2 lore raw

PATCH 2/2 spi: bfin_spi6xx: Remove unnecessary test for bus and pins[bus]

In reply to Axel Lin

2013/11/30 Axel Lin <[email protected]>:

Quoted 26 lines

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.

---
 drivers/spi/bfin_spi6xx.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
drivers/spi/bfin_spi6xx.c +0 -4
index c25c4a9..07b833d 100644
@@ -154,10 +154,6 @@ 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_REGBASE
        case 0:

drivers/spi/bfin_spi6xx.c struct spi_slave *spi_setup_slave(unsigned int bus, unsigned int cs, · line 177

Quoted 7 lines
drivers/spi/bfin_spi6xx.c +1 -0
@@ -175,6 +171,7 @@ struct spi_slave *spi_setup_slave(unsigned int bus, unsigned int cs,
                break;
 #endif
        default:
+               debug("%s: invalid bus %u\n", __func__, bus);
                return NULL;
        }