mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jonas Gorski <jonas.gorski@gmail.com>
To: Mark Brown <broonie@kernel.org>,
	Amit Kumar Mahapatra <amit.kumar-mahapatra@amd.com>
Cc: linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org,
	Marc Kleine-Budde <mkl@pengutronix.de>
Subject: [PATCH v2 4/7] spi: drop check for validity of device chip selects
Date: Mon, 15 Sep 2025 20:37:22 +0200	[thread overview]
Message-ID: <20250915183725.219473-5-jonas.gorski@gmail.com> (raw)
In-Reply-To: <20250915183725.219473-1-jonas.gorski@gmail.com>

Now that we know the number of chip selects of a device, we can assume
these are valid, and do not need to check them first.

Signed-off-by: Jonas Gorski <jonas.gorski@gmail.com>
---
v1 -> v2:
* dropped removal of initialization to SPI_CS_INVALID

 drivers/spi/spi.c | 12 +++---------
 1 file changed, 3 insertions(+), 9 deletions(-)

diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index ad965eae9c9f..91e2f4f504e8 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -623,11 +623,6 @@ static void spi_dev_set_name(struct spi_device *spi)
  */
 #define SPI_INVALID_CS		((s8)-1)
 
-static inline bool is_valid_cs(s8 chip_select)
-{
-	return chip_select != SPI_INVALID_CS;
-}
-
 static inline int spi_dev_check_cs(struct device *dev,
 				   struct spi_device *spi, u8 idx,
 				   struct spi_device *new_spi, u8 new_idx)
@@ -638,7 +633,7 @@ static inline int spi_dev_check_cs(struct device *dev,
 	cs = spi_get_chipselect(spi, idx);
 	for (idx_new = new_idx; idx_new < new_spi->num_chipselect; idx_new++) {
 		cs_new = spi_get_chipselect(new_spi, idx_new);
-		if (is_valid_cs(cs) && is_valid_cs(cs_new) && cs == cs_new) {
+		if (cs == cs_new) {
 			dev_err(dev, "chipselect %u already in use\n", cs_new);
 			return -EBUSY;
 		}
@@ -684,7 +679,7 @@ static int __spi_add_device(struct spi_device *spi)
 	for (idx = 0; idx < spi->num_chipselect; idx++) {
 		/* Chipselects are numbered 0..max; validate. */
 		cs = spi_get_chipselect(spi, idx);
-		if (is_valid_cs(cs) && cs >= ctlr->num_chipselect) {
+		if (cs >= ctlr->num_chipselect) {
 			dev_err(dev, "cs%d >= max %d\n", spi_get_chipselect(spi, idx),
 				ctlr->num_chipselect);
 			return -EINVAL;
@@ -730,8 +725,7 @@ static int __spi_add_device(struct spi_device *spi)
 
 		for (idx = 0; idx < spi->num_chipselect; idx++) {
 			cs = spi_get_chipselect(spi, idx);
-			if (is_valid_cs(cs))
-				spi_set_csgpiod(spi, idx, ctlr->cs_gpiods[cs]);
+			spi_set_csgpiod(spi, idx, ctlr->cs_gpiods[cs]);
 		}
 	}
 
-- 
2.43.0


  parent reply	other threads:[~2025-09-15 18:37 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-15 18:37 [PATCH v2 0/7] spi: multi CS cleanup and controller CS limit removal Jonas Gorski
2025-09-15 18:37 ` [PATCH v2 1/7] spi: fix return code when spi device has too many chipselects Jonas Gorski
2025-09-15 18:37 ` [PATCH v2 2/7] spi: keep track of number of chipselects in spi_device Jonas Gorski
2025-09-15 18:37 ` [PATCH v2 3/7] spi: move unused device CS initialization to __spi_add_device() Jonas Gorski
2025-09-15 18:37 ` Jonas Gorski [this message]
2025-09-15 18:37 ` [PATCH v2 5/7] spi: don't check spi_controller::num_chipselect when parsing a dt device Jonas Gorski
2025-09-15 18:37 ` [PATCH v2 6/7] spi: reduce device chip select limit again Jonas Gorski
2025-09-15 18:37 ` [PATCH v2 7/7] spi: rename SPI_CS_CNT_MAX => SPI_DEVICE_CS_CNT_MAX Jonas Gorski
2025-09-23 11:25 ` [PATCH v2 0/7] spi: multi CS cleanup and controller CS limit removal Mark Brown

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250915183725.219473-5-jonas.gorski@gmail.com \
    --to=jonas.gorski@gmail.com \
    --cc=amit.kumar-mahapatra@amd.com \
    --cc=broonie@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-spi@vger.kernel.org \
    --cc=mkl@pengutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®