* [PATCH] spi: detect wrong transfer->len values
@ 2011-09-23 11:59 Michael Thalmeier
2011-09-23 23:32 ` Grant Likely
0 siblings, 1 reply; 3+ messages in thread
From: Michael Thalmeier @ 2011-09-23 11:59 UTC (permalink / raw)
To: Grant Likely; +Cc: spi-devel-general, linux-kernel
From: Helmut Raiger <helmut.raiger@hale.at>
Signed-off-by: Michael Thalmeier <michael.thalmeier@hale.at>
---
drivers/spi/spi.c | 12 +++++++++++-
1 files changed, 11 insertions(+), 1 deletions(-)
diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index 4d1b9f5..70adac3 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -760,6 +760,17 @@ EXPORT_SYMBOL_GPL(spi_setup);
static int __spi_async(struct spi_device *spi, struct spi_message *message)
{
struct spi_master *master = spi->master;
+ struct spi_transfer *xfer;
+
+ /* check if number of bytes relates to bits per word mode */
+ list_for_each_entry(xfer, &message->transfers, transfer_list) {
+ u8 bpw = xfer->bits_per_word ?
+ xfer->bits_per_word : spi->bits_per_word;
+
+ if ((bpw == 16 && (xfer->len & 1)) ||
+ (bpw == 32 && (xfer->len & 3)))
+ return -EINVAL;
+ }
/* Half-duplex links include original MicroWire, and ones with
* only one data pin like SPI_3WIRE (switches direction) or where
@@ -768,7 +779,6 @@ static int __spi_async(struct spi_device *spi, struct spi_message *message)
*/
if ((master->flags & SPI_MASTER_HALF_DUPLEX)
|| (spi->mode & SPI_3WIRE)) {
- struct spi_transfer *xfer;
unsigned flags = master->flags;
list_for_each_entry(xfer, &message->transfers, transfer_list) {
--
1.7.6.2
--
Scanned by MailScanner.
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] spi: detect wrong transfer->len values
2011-09-23 11:59 [PATCH] spi: detect wrong transfer->len values Michael Thalmeier
@ 2011-09-23 23:32 ` Grant Likely
[not found] ` <20110923233204.GJ24631-e0URQFbLeQY2iJbIjFUEsiwD8/FfD2ys@public.gmane.org>
0 siblings, 1 reply; 3+ messages in thread
From: Grant Likely @ 2011-09-23 23:32 UTC (permalink / raw)
To: Michael Thalmeier; +Cc: spi-devel-general, linux-kernel
On Fri, Sep 23, 2011 at 01:59:18PM +0200, Michael Thalmeier wrote:
> From: Helmut Raiger <helmut.raiger@hale.at>
>
>
> Signed-off-by: Michael Thalmeier <michael.thalmeier@hale.at>
> ---
> drivers/spi/spi.c | 12 +++++++++++-
> 1 files changed, 11 insertions(+), 1 deletions(-)
>
> diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
> index 4d1b9f5..70adac3 100644
> --- a/drivers/spi/spi.c
> +++ b/drivers/spi/spi.c
> @@ -760,6 +760,17 @@ EXPORT_SYMBOL_GPL(spi_setup);
> static int __spi_async(struct spi_device *spi, struct spi_message *message)
> {
> struct spi_master *master = spi->master;
> + struct spi_transfer *xfer;
> +
> + /* check if number of bytes relates to bits per word mode */
> + list_for_each_entry(xfer, &message->transfers, transfer_list) {
> + u8 bpw = xfer->bits_per_word ?
> + xfer->bits_per_word : spi->bits_per_word;
> +
> + if ((bpw == 16 && (xfer->len & 1)) ||
> + (bpw == 32 && (xfer->len & 3)))
> + return -EINVAL;
> + }
Rather than turning this into a hard fail; you should make it a
WARN_ONCE(). I wouldn't be surprised if a lot of drivers have the bad
behaviour, and applying this patch could have far reaching
consequences, including boards failing to boot.
g.
>
> /* Half-duplex links include original MicroWire, and ones with
> * only one data pin like SPI_3WIRE (switches direction) or where
> @@ -768,7 +779,6 @@ static int __spi_async(struct spi_device *spi, struct spi_message *message)
> */
> if ((master->flags & SPI_MASTER_HALF_DUPLEX)
> || (spi->mode & SPI_3WIRE)) {
> - struct spi_transfer *xfer;
Unrelated change?
> unsigned flags = master->flags;
>
> list_for_each_entry(xfer, &message->transfers, transfer_list) {
> --
> 1.7.6.2
>
>
>
> --
> Scanned by MailScanner.
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2011-09-26 8:55 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-09-23 11:59 [PATCH] spi: detect wrong transfer->len values Michael Thalmeier
2011-09-23 23:32 ` Grant Likely
[not found] ` <20110923233204.GJ24631-e0URQFbLeQY2iJbIjFUEsiwD8/FfD2ys@public.gmane.org>
2011-09-26 8:55 ` [PATCH v2] " Michael Thalmeier
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).