Messages in this thread |  | | Date | Tue, 1 Sep 2026 11:44:26 +0200 | | From | Greg Kroah-Hartman <> | | Subject | Re: [PATCH v3] staging: greybus: spilib: Handle SPI device types with a switch statement |
| |
On Fri, Aug 07, 2026 at 12:45:42PM +0530, singh.supreet14@gmail.com wrote: > From: Supreet Singh <singh.supreet14@gmail.com> > > 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.
But let's deal with that when it happens, you are adding more code here than removing:
> > Signed-off-by: Supreet Singh <singh.supreet14@gmail.com> > --- > 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(-)
So it's not really a benefit overall, right?
> > 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; > + }
thanks,
greg k-h
|  |