Skip to content

Commit

Permalink
spi: Dont call master->setup if not populated
Browse files Browse the repository at this point in the history
Currently the master->setup() is called unconditionally.
The assumption is that every driver need to implement this
callback. This encourages drivers to populate empty functions
to prevent crashing.

This patch prevents the call of master->setup() if it is not
populated.

Signed-off-by: Laxman Dewangan <ldewangan@nvidia.com>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
  • Loading branch information
Laxman Dewangan authored and Mark Brown committed Nov 9, 2012
1 parent 3d70f8c commit caae070
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions drivers/spi/spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -1156,7 +1156,7 @@ EXPORT_SYMBOL_GPL(spi_busnum_to_master);
int spi_setup(struct spi_device *spi)
{
unsigned bad_bits;
int status;
int status = 0;

/* help drivers fail *cleanly* when they need options
* that aren't supported with their current master
Expand All @@ -1171,7 +1171,8 @@ int spi_setup(struct spi_device *spi)
if (!spi->bits_per_word)
spi->bits_per_word = 8;

status = spi->master->setup(spi);
if (spi->master->setup)
status = spi->master->setup(spi);

dev_dbg(&spi->dev, "setup mode %d, %s%s%s%s"
"%u bits/w, %u Hz max --> %d\n",
Expand Down

0 comments on commit caae070

Please sign in to comment.