Skip to content

Commit

Permalink
spi: bitbang: Make setup_transfer() callback optional
Browse files Browse the repository at this point in the history
Some controller drivers have no need of this callback (spi-altera even
causes a NULL pointer dereference because it doesn't register the callback,
falsely assuming that it is already optional).

Fixes: 30af9b5 ("spi/bitbang: Drop empty setup() functions")
Signed-off-by: Pelle Nilsson <per.nilsson@xelmo.com>
Reviewed-by: Ezequiel Garcia <ezequiel.garcia@vanguardiasur.com.ar>
Signed-off-by: Mark Brown <broonie@kernel.org>
  • Loading branch information
Pelle Nilsson authored and Mark Brown committed Apr 18, 2015
1 parent c517d83 commit 7d0ec8b
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions drivers/spi/spi-bitbang.c
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,6 @@ int spi_bitbang_setup(struct spi_device *spi)
{
struct spi_bitbang_cs *cs = spi->controller_state;
struct spi_bitbang *bitbang;
int retval;
unsigned long flags;

bitbang = spi_master_get_devdata(spi->master);
Expand All @@ -197,9 +196,11 @@ int spi_bitbang_setup(struct spi_device *spi)
if (!cs->txrx_word)
return -EINVAL;

retval = bitbang->setup_transfer(spi, NULL);
if (retval < 0)
return retval;
if (bitbang->setup_transfer) {
int retval = bitbang->setup_transfer(spi, NULL);
if (retval < 0)
return retval;
}

dev_dbg(&spi->dev, "%s, %u nsec/bit\n", __func__, 2 * cs->nsecs);

Expand Down Expand Up @@ -295,9 +296,11 @@ static int spi_bitbang_transfer_one(struct spi_master *master,

/* init (-1) or override (1) transfer params */
if (do_setup != 0) {
status = bitbang->setup_transfer(spi, t);
if (status < 0)
break;
if (bitbang->setup_transfer) {
status = bitbang->setup_transfer(spi, t);
if (status < 0)
break;
}
if (do_setup == -1)
do_setup = 0;
}
Expand Down

0 comments on commit 7d0ec8b

Please sign in to comment.