Re: [PATCH v2] staging: greybus: spilib: Handle SPI device types with a switch statement
From: Dan Carpenter
Date: Thu Aug 06 2026 - 11:50:56 EST
On Thu, Aug 06, 2026 at 03:41:18PM +0530, singh.supreet14@xxxxxxxxx wrote:
> 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.
>
>
Delete the extra blank line.
> 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));
This line is indented badly now.
regards,
dan carpenter
> + break;
> + default:
> return -EINVAL;
> + }