spi: dw: fix spi_dw_init()

It is incorrect to call spi_context_release() on a
spi_dw_data object's ctx field before data->ctx->config is first
set in spi_dw_configure(). This is because spi_context_release()
reads ctx->config->operation. In particular, during spi_dw_init(),
calling spi_context_release() reads the uninitialized memory in
spi->ctx->config->operation.

Call spi_context_unlock_unconditionally() instead to properly increase
the semaphore count.

Without this patch, the first call to spi_transceive() can block
forever depending on the value of the uninitialized memory holding
spi->ctx->config->operation.

Signed-off-by: Marti Bolivar <marti.bolivar@linaro.org>
This commit is contained in:
Marti Bolivar 2017-07-13 18:37:41 -04:00 committed by Anas Nashif
parent 6318750837
commit 3ac9ca0859

View file

@ -418,7 +418,7 @@ int spi_dw_init(struct device *dev)
SYS_LOG_DBG("Designware SPI driver initialized on device: %p", dev);
spi_context_release(&spi->ctx, 0);
spi_context_unlock_unconditionally(&spi->ctx);
return 0;
}