On Thu, Oct 24, 2019 at 12:13:00PM +0100, Mark Brown wrote: > On Thu, Oct 24, 2019 at 01:07:57PM +0200, Alvaro Gamez Machado wrote: > > By leaving this value unset, a default value of 8 was being set later on. > > > > If it happens that the SPI master driver doesn't support this value of 8, > > there will be an initial inconsistency between the SPI master and the device > > itself. This isn't a problem for most devices because kernel drivers > > This will break things, client devices are working on the basis that the > default transfer width is 8 bits. As I've repeatedly said if we have > different parts of the system with different ideas about the word size > we're going to end up with data corruption. Please take this feedback > on board. Oh, ok. I didn't understand this cleary from previous mails, now I see what you mean. I think then the only way this would be feasible is to check if 8 bits is an acceptable number for the master and, if it isn't, apply the lowest available data width. I believe this cannot break anything, as it leaves 8 as the default unless the master can't work with that number, in which case it really doesn't matter what client device wants because the hardware can't provide it. Thanks! diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c index 794e20e54237..4e26ac79e133 100644 --- a/drivers/spi/spi.c +++ b/drivers/spi/spi.c @@ -3079,8 +3079,12 @@ int spi_setup(struct spi_device *spi) return -EINVAL; } - if (!spi->bits_per_word) - spi->bits_per_word = 8; + if (!spi->bits_per_word) { + if (spi->controller->bits_per_word_mask & SPI_BPW_MASK(8)) + spi->bits_per_word = 8; + else + spi->bits_per_word = ffs(spi->controller->bits_per_word_mask); + } status = __spi_validate_bits_per_word(spi->controller, spi->bits_per_word); -- Alvaro G. M.