Skip to content

Commit f3982da

Browse files
KanjiMonsterbroonie
authored andcommitted
spi: drop check for validity of device chip selects
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> Link: https://patch.msgid.link/20250915183725.219473-5-jonas.gorski@gmail.com Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent 1c923f6 commit f3982da

1 file changed

Lines changed: 3 additions & 9 deletions

File tree

drivers/spi/spi.c

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -623,11 +623,6 @@ static void spi_dev_set_name(struct spi_device *spi)
623623
*/
624624
#define SPI_INVALID_CS ((s8)-1)
625625

626-
static inline bool is_valid_cs(s8 chip_select)
627-
{
628-
return chip_select != SPI_INVALID_CS;
629-
}
630-
631626
static inline int spi_dev_check_cs(struct device *dev,
632627
struct spi_device *spi, u8 idx,
633628
struct spi_device *new_spi, u8 new_idx)
@@ -638,7 +633,7 @@ static inline int spi_dev_check_cs(struct device *dev,
638633
cs = spi_get_chipselect(spi, idx);
639634
for (idx_new = new_idx; idx_new < new_spi->num_chipselect; idx_new++) {
640635
cs_new = spi_get_chipselect(new_spi, idx_new);
641-
if (is_valid_cs(cs) && is_valid_cs(cs_new) && cs == cs_new) {
636+
if (cs == cs_new) {
642637
dev_err(dev, "chipselect %u already in use\n", cs_new);
643638
return -EBUSY;
644639
}
@@ -684,7 +679,7 @@ static int __spi_add_device(struct spi_device *spi)
684679
for (idx = 0; idx < spi->num_chipselect; idx++) {
685680
/* Chipselects are numbered 0..max; validate. */
686681
cs = spi_get_chipselect(spi, idx);
687-
if (is_valid_cs(cs) && cs >= ctlr->num_chipselect) {
682+
if (cs >= ctlr->num_chipselect) {
688683
dev_err(dev, "cs%d >= max %d\n", spi_get_chipselect(spi, idx),
689684
ctlr->num_chipselect);
690685
return -EINVAL;
@@ -730,8 +725,7 @@ static int __spi_add_device(struct spi_device *spi)
730725

731726
for (idx = 0; idx < spi->num_chipselect; idx++) {
732727
cs = spi_get_chipselect(spi, idx);
733-
if (is_valid_cs(cs))
734-
spi_set_csgpiod(spi, idx, ctlr->cs_gpiods[cs]);
728+
spi_set_csgpiod(spi, idx, ctlr->cs_gpiods[cs]);
735729
}
736730
}
737731

0 commit comments

Comments
 (0)