[PATCH v2] staging: greybus: spilib: Handle SPI device types with a switch statement

From: singh . supreet14

Date: Thu Aug 06 2026 - 06:17:42 EST


From: Supreet Singh <singh.supreet14@xxxxxxxxx>

Replace the if/else chain that selects the SPI device type with a switch
statement. This makes the code easier to extend when additional device
types are introduced and improves readability.


Signed-off-by: Supreet Singh <singh.supreet14@xxxxxxxxx>
---
Changes in v2:
- Restore the temporary variable spidev
- Use the contributor's full name in the From and Signed-off-by lines.

drivers/staging/greybus/spilib.c | 15 ++++++++++-----
1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/drivers/staging/greybus/spilib.c b/drivers/staging/greybus/spilib.c
index e4d1ae8308aa..d1b7ca9c4ee3 100644
--- a/drivers/staging/greybus/spilib.c
+++ b/drivers/staging/greybus/spilib.c
@@ -458,17 +458,22 @@ static int gb_spi_setup_device(struct gb_spilib *spi, u8 cs)

dev_type = response.device_type;

- if (dev_type == GB_SPI_SPI_DEV)
+ switch (dev_type) {
+ case GB_SPI_SPI_DEV:
strscpy(spi_board.modalias, "spidev",
sizeof(spi_board.modalias));
- else if (dev_type == GB_SPI_SPI_NOR)
+ break;
+ case GB_SPI_SPI_NOR:
strscpy(spi_board.modalias, "spi-nor",
sizeof(spi_board.modalias));
- else if (dev_type == GB_SPI_SPI_MODALIAS)
+ break;
+ case GB_SPI_SPI_MODALIAS:
memcpy(spi_board.modalias, response.name,
- sizeof(spi_board.modalias));
- else
+ sizeof(spi_board.modalias));
+ break;
+ default:
return -EINVAL;
+ }

spi_board.mode = le16_to_cpu(response.mode);
spi_board.bus_num = ctlr->bus_num;
--
2.55.0