spi: core: Validate Tx/Rx buffers for non-zero length transfer
Subsystems (3)
PATCH 1/7 spi: core: Validate Tx/Rx buffers for non-zero length transfer
Reject transfer if both tx_buf and rx_buf are NULL for non-zero length transfer. Add the checking in spi core so we can remove the same checking in various drivers.
--- drivers/spi/spi.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/spi/spi.c +4 -0
@@ -1876,6 +1876,10 @@ static int __spi_validate(struct spi_device *spi, struct spi_message *message)if (xfer->len % w_size)return -EINVAL ; +/* non-zero length transfer must has tx_buf or rx_buf */ +if (xfer->len && !xfer->tx_buf && !xfer->rx_buf) +return -EINVAL ; +if (xfer->speed_hz && master->min_speed_hz && xfer->speed_hz < master->min_speed_hz)return -EINVAL ;
Signature · 8 lines
1.8.3.2 -- To unsubscribe from this list: send the line "unsubscribe linux-spi" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH 2/7 spi: atmel: Let spi core validate Tx/Rx buffers for non-zero length transfer
--- drivers/spi/spi-atmel.c | 5 ----- 1 file changed, 5 deletions(-)
drivers/spi/spi-atmel.c +0 -5
@@ -1065,11 +1065,6 @@ static int atmel_spi_one_transfer(struct spi_master *master, as =spi_master_get_devdata (master); -if (!(xfer->tx_buf || xfer->rx_buf) && xfer->len) { -dev_dbg (&spi->dev,"missing rx or tx buf\n" ); -return -EINVAL ; - } -if (xfer->bits_per_word) { asd = spi->controller_state; bits = (asd->csr >>4 ) &0xf ;
Signature · 8 lines
1.8.3.2 -- To unsubscribe from this list: send the line "unsubscribe linux-spi" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
RE: [PATCH 2/7] spi: atmel: Let spi core validate Tx/Rx buffers for non-zero length transfer
DQoNCj4gLS0tLS1PcmlnaW5hbCBNZXNzYWdlLS0tLS0NCj4gRnJvbTogQXhlbCBMaW4gW21haWx0 bzpheGVsLmxpbkBpbmdpY3MuY29tXQ0KPiBTZW50OiBXZWRuZXNkYXksIE1hcmNoIDE5LCAyMDE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XJuIC1FSU5WQUw7 DQo+IC0JfQ0KPiAtDQo+ICAJaWYgKHhmZXItPmJpdHNfcGVyX3dvcmQpIHsNCj4gIAkJYXNkID0g c3BpLT5jb250cm9sbGVyX3N0YXRlOw0KPiAgCQliaXRzID0gKGFzZC0+Y3NyID4+IDQpICYgMHhm Ow0KPiAtLQ0KPiAxLjguMy4yDQo+IA0KPiANCg0K
--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH 3/7 spi: omap-100k: Let spi core validate Tx/Rx buffers for non-zero length transfer
In reply to Axel Lin--- drivers/spi/spi-omap-100k.c | 4 ---- 1 file changed, 4 deletions(-)
drivers/spi/spi-omap-100k.c +0 -4
@@ -324,10 +324,6 @@ static int omap1_spi100k_transfer_one_message(struct spi_master *master,int status =0 ;list_for_each_entry (t, &m->transfers, transfer_list) { -if (t->tx_buf ==NULL && t->rx_buf ==NULL && t->len) { - status = -EINVAL ; -break ; - }if (par_override || t->speed_hz || t->bits_per_word) { par_override =1 ; status =omap1_spi100k_setup_transfer (spi, t);
Signature · 8 lines
1.8.3.2 -- To unsubscribe from this list: send the line "unsubscribe linux-spi" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH 4/7 spi: omap2-mcspi: Let spi core validate Tx/Rx buffers for non-zero length transfer
In reply to Axel Lin--- drivers/spi/spi-omap2-mcspi.c | 14 -------------- 1 file changed, 14 deletions(-)
drivers/spi/spi-omap2-mcspi.c +0 -14
@@ -1081,10 +1081,6 @@ static void omap2_mcspi_work(struct omap2_mcspi *mcspi, struct spi_message *m)omap2_mcspi_set_enable (spi,0 );list_for_each_entry (t, &m->transfers, transfer_list) { -if (t->tx_buf ==NULL && t->rx_buf ==NULL && t->len) { - status = -EINVAL ; -break ; - }if (par_override || (t->speed_hz != spi->max_speed_hz) || (t->bits_per_word != spi->bits_per_word)) {
@@ -1212,16 +1208,6 @@ static int omap2_mcspi_transfer_one_message(struct spi_master *master,void *rx_buf = t->rx_buf;unsigned len = t->len; -if ((len && !(rx_buf || tx_buf))) { -dev_dbg (mcspi->dev,"transfer: %d Hz, %d %s%s, %d bpw\n" , - t->speed_hz, - len, - tx_buf ?"tx" :"" , - rx_buf ?"rx" :"" , - t->bits_per_word); -return -EINVAL ; - } -if (m->is_dma_mapped || len <DMA_MIN_BYTES )continue ;
Signature · 8 lines
1.8.3.2 -- To unsubscribe from this list: send the line "unsubscribe linux-spi" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH 5/7 spi: txx9: Let spi core validate Tx/Rx buffers for non-zero length transfer
In reply to Axel Lin--- drivers/spi/spi-txx9.c | 7 ------- 1 file changed, 7 deletions(-)
drivers/spi/spi-txx9.c +0 -7
@@ -299,17 +299,10 @@ static int txx9spi_transfer(struct spi_device *spi, struct spi_message *m) {struct spi_master *master = spi->master;struct txx9spi *c =spi_master_get_devdata (master); -struct spi_transfer *t;unsigned long flags; m->actual_length =0 ; -/* check each transfer's parameters */ -list_for_each_entry (t, &m->transfers, transfer_list) { -if (!t->tx_buf && !t->rx_buf && t->len) -return -EINVAL ; - } -spin_lock_irqsave (&c->lock, flags);list_add_tail (&m->queue, &c->queue);queue_work (c->workqueue, &c->work);
Signature · 8 lines
1.8.3.2 -- To unsubscribe from this list: send the line "unsubscribe linux-spi" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH 6/7 spi: xcomm: Let spi core validate Tx/Rx buffers for non-zero length transfer
In reply to Axel Lin--- drivers/spi/spi-xcomm.c | 5 ----- 1 file changed, 5 deletions(-)
drivers/spi/spi-xcomm.c +0 -5
@@ -149,11 +149,6 @@ static int spi_xcomm_transfer_one(struct spi_master *master,list_for_each_entry (t, &msg->transfers, transfer_list) { -if (!t->tx_buf && !t->rx_buf && t->len) { - status = -EINVAL ; -break ; - } - status =spi_xcomm_setup_transfer (spi_xcomm, spi, t, &settings);if (status <0 )break ;
Signature · 8 lines
1.8.3.2 -- To unsubscribe from this list: send the line "unsubscribe linux-spi" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 6/7] spi: xcomm: Let spi core validate Tx/Rx buffers for non-zero length transfer
Quoted 1 line · Axel Lin
Signed-off-by Axel Lin <[email protected]>
Thanks.
--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH 7/7 spi: bitbang: Let spi core validate Tx/Rx buffers for non-zero length transfer
In reply to Axel Lin--- drivers/spi/spi-bitbang.c | 4 ---- 1 file changed, 4 deletions(-)
drivers/spi/spi-bitbang.c +0 -4
@@ -317,10 +317,6 @@ static int spi_bitbang_transfer_one(struct spi_master *master,ndelay (nsecs); } cs_change = t->cs_change; -if (!t->tx_buf && !t->rx_buf && t->len) { - status = -EINVAL ; -break ; - }/* transfer data. the lower level code handles any * new dma mappings it needs. our caller always gave
Signature · 8 lines
1.8.3.2 -- To unsubscribe from this list: send the line "unsubscribe linux-spi" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 3 lines · Axel Lin
Reject transfer if both
tx_bufandrx_bufare NULL for non-zero length transfer. Add the checking in spi core so we can remove the same checking in various drivers.
Just wondering: are there any SPI slave drivers that implement dummy cycles this way?
Quoted 10 lines
Signed-off-by Axel Lin <[email protected]>--- drivers/spi/spi.c | 4 ++++ 1 file changed, 4 insertions(+)drivers/spi/spi.c +0
-0
drivers/spi/spi.c static int __spi_validate(struct spi_device *spi, struct spi_message *message) · line 1879
Quoted 4 lines
drivers/spi/spi.c +1
-0@@ -1876,6 +1876,10 @@ static int __spi_validate(struct spi_device *spi, struct spi_message *message)if (xfer->len % w_size)return -EINVAL ; +/* non-zero length transfer must has tx_buf or rx_buf */
have
drivers/spi/spi.c static int __spi_validate(struct spi_device *spi, struct spi_message *message) · line 1882
Quoted 3 lines
drivers/spi/spi.c +3
-0+if (xfer->len && !xfer->tx_buf && !xfer->rx_buf) +return -EINVAL ; +
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]
In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
A message that is not in the archive (sent off-list or not yet received): CAMuHMdWCdp_SW5CNt50cSfG700JRU3tr=Pbyhv8nv-1Ve=XUNw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org
2014-03-19 16:06 GMT+08:00 Geert Uytterhoeven <[email protected]>:
Quoted 7 lines · Axel Lin
Quoted 3 lines
Reject transfer if both
tx_bufandrx_bufare NULL for non-zero length transfer. Add the checking in spi core so we can remove the same checking in various drivers.Just wondering: are there any SPI slave drivers that implement dummy cycles this way?
I think I found one such case:drivers/net/wireless/libertas/if_spi.c
the dummy_trans has non-zero length, and both tx_buf and rx_buf are NULL.
But that means it doesn't work with master drivers with this checking, e.g. all drivers using bitbang library has this checking.
Regards,
Axel
--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
A message that is not in the archive (sent off-list or not yet received): CAFRkauCUUOQ0xxa-k5_TMKUA7jnnz1FPjXnGT4T10v7upyOy8Q-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org
Quoted 11 lines · Axel Lin
2014-03-19 16:06 GMT+08:00 Geert Uytterhoeven <[email protected]>:
Quoted 2 lines
Just wondering: are there any SPI slave drivers that implement dummy cycles this way?
I think I found one such case:
drivers/net/wireless/libertas/if_spi.c
thedummy_transhas non-zero length, and bothtx_bufandrx_bufare NULL.But that means it doesn't work with master drivers with this checking, e.g. all drivers using bitbang library has this checking.
I have to say that this seems rather abusive on the part of the driver, it's going to cause implementation issues in the masters - I expect more than just those that check aren't doing to do the right thing.
Quoted 8 lines · Geert Uytterhoeven
Quoted 3 lines · Axel Lin
Reject transfer if both
tx_bufandrx_bufare NULL for non-zero length transfer. Add the checking in spi core so we can remove the same checking in various drivers.Just wondering: are there any SPI slave drivers that implement dummy cycles this way?
The ChromeOS EC apparently does this.