linux-spi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] spi: add bits_per_word_mask check in spi_setup
@ 2013-06-26 22:54 Scott Jiang
       [not found] ` <1372287286-12682-1-git-send-email-scott.jiang.linux-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
  0 siblings, 1 reply; 4+ messages in thread
From: Scott Jiang @ 2013-06-26 22:54 UTC (permalink / raw)
  To: Grant Likely, Mark Brown
  Cc: spi-devel-general-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f, Scott Jiang,
	uclinux-dist-devel-ZG0+EudsQA8dtHy/vicBwGD2FQJk+8+b

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.linux-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
---
 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

^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2013-06-28 10:40 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-06-26 22:54 [PATCH] spi: add bits_per_word_mask check in spi_setup Scott Jiang
     [not found] ` <1372287286-12682-1-git-send-email-scott.jiang.linux-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2013-06-27 11:35   ` Mark Brown
     [not found]     ` <20130627113522.GZ27646-GFdadSzt00ze9xe1eoZjHA@public.gmane.org>
2013-06-28  2:51       ` Scott Jiang
     [not found]         ` <CAHG8p1DeSojQ-kn=GZTFpaepUTDCme7NA+=Vani3zK1QePDCzA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2013-06-28 10:40           ` Mark Brown

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).