Skip to content

Commit

Permalink
spi: fix ctrl->num_chipselect constraint
Browse files Browse the repository at this point in the history
at91sam9g25ek showed the following error at probe:
atmel_spi f0000000.spi: Using dma0chan2 (tx) and dma0chan3 (rx)
for DMA transfers
atmel_spi: probe of f0000000.spi failed with error -22

Commit 0a919ae ("spi: Don't call spi_get_gpio_descs() before device name is set")
moved the calling of spi_get_gpio_descs() after ctrl->dev is set,
but didn't move the !ctrl->num_chipselect check. When there are
chip selects in the device tree, the spi-atmel driver lets the
SPI core discover them when registering the SPI master.
The ctrl->num_chipselect is thus expected to be set by
spi_get_gpio_descs().

Move the !ctlr->num_chipselect after spi_get_gpio_descs() as it was
before the aforementioned commit. While touching this block, get rid
of the explicit comparison with 0 and update the commenting style.

Fixes: 0a919ae ("spi: Don't call spi_get_gpio_descs() before device name is set")
Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
  • Loading branch information
Tudor Ambarus authored and Mark Brown committed Jun 20, 2019
1 parent 51c711f commit f9481b0
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions drivers/spi/spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -2375,11 +2375,6 @@ int spi_register_controller(struct spi_controller *ctlr)
if (status)
return status;

/* even if it's just one always-selected device, there must
* be at least one chipselect
*/
if (ctlr->num_chipselect == 0)
return -EINVAL;
if (ctlr->bus_num >= 0) {
/* devices with a fixed bus num must check-in with the num */
mutex_lock(&board_lock);
Expand Down Expand Up @@ -2450,6 +2445,13 @@ int spi_register_controller(struct spi_controller *ctlr)
}
}

/*
* Even if it's just one always-selected device, there must
* be at least one chipselect.
*/
if (!ctlr->num_chipselect)
return -EINVAL;

status = device_add(&ctlr->dev);
if (status < 0) {
/* free bus id */
Expand Down

0 comments on commit f9481b0

Please sign in to comment.