The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH] staging: greybus: spilib: Handle SPI device types with a switch statement
@ 2026-08-05 11:19 singh.supreet14
  2026-08-05 11:28 ` Greg Kroah-Hartman
  2026-08-06 10:11 ` [PATCH v2] " singh.supreet14
  0 siblings, 2 replies; 5+ messages in thread
From: singh.supreet14 @ 2026-08-05 11:19 UTC (permalink / raw)
  To: Viresh Kumar
  Cc: Rui Miguel Silva, Johan Hovold, Alex Elder, Greg Kroah-Hartman,
	greybus-dev, linux-staging, linux-kernel, Supreet

From: Supreet <singh.supreet14@gmail.com>

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@gmail.com>
---
 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))
 		return -EINVAL;
 
 	return 0;
-- 
2.55.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-08-06 15:46 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-05 11:19 [PATCH] staging: greybus: spilib: Handle SPI device types with a switch statement singh.supreet14
2026-08-05 11:28 ` Greg Kroah-Hartman
2026-08-05 12:19   ` Supreet Singh
2026-08-06 10:11 ` [PATCH v2] " singh.supreet14
2026-08-06 15:46   ` Dan Carpenter

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox