spi: Dont call master->setup if not populated
authorLaxman Dewangan <ldewangan@nvidia.com>
Fri, 9 Nov 2012 09:05:22 +0000 (14:35 +0530)
committerMark Brown <broonie@opensource.wolfsonmicro.com>
Fri, 9 Nov 2012 16:46:48 +0000 (16:46 +0000)
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>
drivers/spi/spi.c

index 84c2861d6f4dde2a602e44f292c6efbd248c602b..619c7df0d27f25646044fe740b439c1c3feffa08 100644 (file)
@@ -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
@@ -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",