The spi_setup should fail if underlying controller or its driver
does not support requested bits_per_word. So if the master driver
set mask and let core do bits_per_word check then we should also
test this mask in spi_setup.

Signed-off-by: Scott Jiang <scott.jiang.li...@gmail.com>
---
 drivers/spi/spi.c |    9 +++++++++
 1 files changed, 9 insertions(+), 0 deletions(-)

diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index 45cb6a9..dc8fde0 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -1326,6 +1326,15 @@ int spi_setup(struct spi_device *spi)
        if (!spi->bits_per_word)
                spi->bits_per_word = 8;
 
+       if (spi->master->bits_per_word_mask) {
+               /* Only 32 bits fit in the mask */
+               if (spi->bits_per_word > 32)
+                       return -EINVAL;
+               if (!(spi->master->bits_per_word_mask &
+                               BIT(spi->bits_per_word - 1)))
+                       return -EINVAL;
+       }
+
        if (spi->master->setup)
                status = spi->master->setup(spi);
 
-- 
1.7.0.4


_______________________________________________
Uclinux-dist-devel mailing list
Uclinux-dist-devel@blackfin.uclinux.org
https://blackfin.uclinux.org/mailman/listinfo/uclinux-dist-devel

Reply via email to