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

From: Greg Kroah-Hartman

Date: Wed Aug 05 2026 - 07:29:12 EST


On Wed, Aug 05, 2026 at 04:49:57PM +0530, singh.supreet14@xxxxxxxxx wrote:
> From: Supreet <singh.supreet14@xxxxxxxxx>

We need a full name please.


>
> Replaced the if/else chain with switch statement. makes it easier to
> extend support for additional device types.
>
> Remove the temporary spidev variable since it is only used to test the
> return value of spi_new_device(). Call spi_new_device() directly in
> the conditional instead.
>
> checkpatch was run, had no warnings and errors.
>
> Signed-off-by: Supreet <singh.supreet14@xxxxxxxxx>
> ---
> drivers/staging/greybus/spilib.c | 19 +++++++++++--------
> 1 file changed, 11 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/staging/greybus/spilib.c b/drivers/staging/greybus/spilib.c
> index e4d1ae8308aa..53fc0c124754 100644
> --- a/drivers/staging/greybus/spilib.c
> +++ b/drivers/staging/greybus/spilib.c
> @@ -444,7 +444,6 @@ static int gb_spi_setup_device(struct gb_spilib *spi, u8 cs)
> struct gb_spi_device_config_request request;
> struct gb_spi_device_config_response response;
> struct spi_board_info spi_board = { {0} };
> - struct spi_device *spidev;
> int ret;
> u8 dev_type;
>
> @@ -458,25 +457,29 @@ 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;
> spi_board.chip_select = cs;
> spi_board.max_speed_hz = le32_to_cpu(response.max_speed_hz);
>
> - spidev = spi_new_device(ctlr, &spi_board);
> - if (!spidev)
> + if (!spi_new_device(ctlr, &spi_board))

Why was this change made? It's a different one than the switch
statement, right?

thanks,

greg k-h