[PATCH v3] staging: greybus: spilib: Handle SPI device types with a switch statement
| Newsgroups | org.kernel.vger.linux-kernel,dev.linux.lists.linux-staging |
|---|---|
| Message-ID | <[email protected]> |
From: Supreet Singh <[email protected]> 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 <[email protected]> --- Changes in v3: - Fixed the memcpy indentation issue - Removed the extra blank line in the commit message drivers/staging/greybus/spilib.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/drivers/staging/greybus/spilib.c b/drivers/staging/greybus/spilib.c index e4d1ae8308aa..39d5bf234c61 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 + break; + default: return -EINVAL; + } spi_board.mode = le16_to_cpu(response.mode); spi_board.bus_num = ctlr->bus_num; -- 2.55.0