2014-11-13 10:36:23

by Dan Carpenter

[permalink] [raw]
Subject: [patch 2/2 -next] mfd: dln2: a couple endian fixes

Sparse catches a couple endian bugs.

Signed-off-by: Dan Carpenter <[email protected]>
---
Not tested.

diff --git a/drivers/mfd/dln2.c b/drivers/mfd/dln2.c
index 3101e5e..babf7b6 100644
--- a/drivers/mfd/dln2.c
+++ b/drivers/mfd/dln2.c
@@ -437,6 +437,7 @@ static int _dln2_transfer(struct dln2_dev *dln2, u16 handle, u16 cmd,
struct device *dev = &dln2->interface->dev;
const unsigned long timeout = DLN2_USB_TIMEOUT * HZ / 1000;
struct dln2_mod_rx_slots *rxs = &dln2->mod_rx_slots[handle];
+ int size;

spin_lock(&dln2->disconnect_lock);
if (!dln2->disconnect)
@@ -476,8 +477,9 @@ static int _dln2_transfer(struct dln2_dev *dln2, u16 handle, u16 cmd,

/* if we got here we know that the response header has been checked */
rsp = rxc->urb->transfer_buffer;
+ size = le16_to_cpu(rsp->hdr.size);

- if (rsp->hdr.size < sizeof(*rsp)) {
+ if (size < sizeof(*rsp)) {
ret = -EPROTO;
goto out_free_rx_slot;
}
@@ -494,8 +496,8 @@ static int _dln2_transfer(struct dln2_dev *dln2, u16 handle, u16 cmd,
goto out_free_rx_slot;
}

- if (*ibuf_len > rsp->hdr.size - sizeof(*rsp))
- *ibuf_len = rsp->hdr.size - sizeof(*rsp);
+ if (*ibuf_len > size - sizeof(*rsp))
+ *ibuf_len = size - sizeof(*rsp);

memcpy(ibuf, rsp + 1, *ibuf_len);


2014-11-13 11:18:42

by Octavian Purdila

[permalink] [raw]
Subject: Re: [patch 2/2 -next] mfd: dln2: a couple endian fixes

On Thu, Nov 13, 2014 at 12:36 PM, Dan Carpenter
<[email protected]> wrote:
> Sparse catches a couple endian bugs.
>
> Signed-off-by: Dan Carpenter <[email protected]>

Acked-by: Octavian Purdila <[email protected]>

2014-11-18 15:54:06

by Lee Jones

[permalink] [raw]
Subject: Re: [patch 2/2 -next] mfd: dln2: a couple endian fixes

On Thu, 13 Nov 2014, Dan Carpenter wrote:

> Sparse catches a couple endian bugs.
>
> Signed-off-by: Dan Carpenter <[email protected]>
> ---
> Not tested.

Applied until someone screams.

> diff --git a/drivers/mfd/dln2.c b/drivers/mfd/dln2.c
> index 3101e5e..babf7b6 100644
> --- a/drivers/mfd/dln2.c
> +++ b/drivers/mfd/dln2.c
> @@ -437,6 +437,7 @@ static int _dln2_transfer(struct dln2_dev *dln2, u16 handle, u16 cmd,
> struct device *dev = &dln2->interface->dev;
> const unsigned long timeout = DLN2_USB_TIMEOUT * HZ / 1000;
> struct dln2_mod_rx_slots *rxs = &dln2->mod_rx_slots[handle];
> + int size;
>
> spin_lock(&dln2->disconnect_lock);
> if (!dln2->disconnect)
> @@ -476,8 +477,9 @@ static int _dln2_transfer(struct dln2_dev *dln2, u16 handle, u16 cmd,
>
> /* if we got here we know that the response header has been checked */
> rsp = rxc->urb->transfer_buffer;
> + size = le16_to_cpu(rsp->hdr.size);
>
> - if (rsp->hdr.size < sizeof(*rsp)) {
> + if (size < sizeof(*rsp)) {
> ret = -EPROTO;
> goto out_free_rx_slot;
> }
> @@ -494,8 +496,8 @@ static int _dln2_transfer(struct dln2_dev *dln2, u16 handle, u16 cmd,
> goto out_free_rx_slot;
> }
>
> - if (*ibuf_len > rsp->hdr.size - sizeof(*rsp))
> - *ibuf_len = rsp->hdr.size - sizeof(*rsp);
> + if (*ibuf_len > size - sizeof(*rsp))
> + *ibuf_len = size - sizeof(*rsp);
>
> memcpy(ibuf, rsp + 1, *ibuf_len);
>

--
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog