2014-11-18 12:58:58

by Octavian Purdila

[permalink] [raw]
Subject: [PATCH v2 0/4] dln2 fixes for ib-mfd-gpio-i2c-3.19

Hi Lee,

Here are a few fixes for the DLN2 drivers for the ib-mfd-gpio-i2c-3.19 branch.

Thanks,
Tavi

Changes since v1:

* fix coding style (add braces) and remove redundant ret = 0 statement

* add two more fixes for issues reported by Dan Carpenter


Dan Carpenter (1):
mfd: dln2: a couple endian fixes

Octavian Purdila (3):
mfd: dln2: fix _dln2_transfer return code
i2c: dln2: simplify return flow for dln2_i2c_enable
mfd: dln2: add a limit check for invalid echo

drivers/i2c/busses/i2c-dln2.c | 7 +------
drivers/mfd/dln2.c | 18 ++++++++++++------
2 files changed, 13 insertions(+), 12 deletions(-)

--
1.9.1


2014-11-18 12:59:00

by Octavian Purdila

[permalink] [raw]
Subject: [PATCH v2 2/4] i2c: dln2: simplify return flow for dln2_i2c_enable

This fixes the following kbuild test robot warning:

>> drivers/i2c/busses/i2c-dln2.c:70:1-4: WARNING: end returns can be simplified if negative or 0 value

Reported-by: kbuild test robot <[email protected]>
Reported-by: Julia Lawall <[email protected]>
Signed-off-by: Octavian Purdila <[email protected]>
Acked-by: Wolfram Sang <[email protected]>
---
drivers/i2c/busses/i2c-dln2.c | 7 +------
1 file changed, 1 insertion(+), 6 deletions(-)

diff --git a/drivers/i2c/busses/i2c-dln2.c b/drivers/i2c/busses/i2c-dln2.c
index 010a5fa..b3fb86a 100644
--- a/drivers/i2c/busses/i2c-dln2.c
+++ b/drivers/i2c/busses/i2c-dln2.c
@@ -54,7 +54,6 @@ struct dln2_i2c {

static int dln2_i2c_enable(struct dln2_i2c *dln2, bool enable)
{
- int ret;
u16 cmd;
struct {
u8 port;
@@ -67,11 +66,7 @@ static int dln2_i2c_enable(struct dln2_i2c *dln2, bool enable)
else
cmd = DLN2_I2C_DISABLE;

- ret = dln2_transfer_tx(dln2->pdev, cmd, &tx, sizeof(tx));
- if (ret < 0)
- return ret;
-
- return 0;
+ return dln2_transfer_tx(dln2->pdev, cmd, &tx, sizeof(tx));
}

static int dln2_i2c_write(struct dln2_i2c *dln2, u8 addr,
--
1.9.1

2014-11-18 12:59:07

by Octavian Purdila

[permalink] [raw]
Subject: [PATCH v2 4/4] mfd: dln2: a couple endian fixes

From: Dan Carpenter <[email protected]>

Sparse catches a couple endian bugs.

Signed-off-by: Dan Carpenter <[email protected]>
Acked-by: Octavian Purdila <[email protected]>
---
drivers/mfd/dln2.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/drivers/mfd/dln2.c b/drivers/mfd/dln2.c
index df2fda9..559e6cc 100644
--- a/drivers/mfd/dln2.c
+++ b/drivers/mfd/dln2.c
@@ -436,6 +436,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)
@@ -477,8 +478,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;
}
@@ -493,8 +495,8 @@ static int _dln2_transfer(struct dln2_dev *dln2, u16 handle, u16 cmd,
if (!ibuf)
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);

--
1.9.1

2014-11-18 12:59:05

by Octavian Purdila

[permalink] [raw]
Subject: [PATCH v2 3/4] mfd: dln2: add a limit check for invalid echo

The echo field in dln2_transfer_complete comes directly from an USB
transfer and we should not trust it is valid.

Reported-by: Dan Carpenter <[email protected]>
Signed-off-by: Octavian Purdila <[email protected]>
---
drivers/mfd/dln2.c | 4 ++++
1 file changed, 4 insertions(+)

diff --git a/drivers/mfd/dln2.c b/drivers/mfd/dln2.c
index cf22841..df2fda9 100644
--- a/drivers/mfd/dln2.c
+++ b/drivers/mfd/dln2.c
@@ -195,6 +195,9 @@ static bool dln2_transfer_complete(struct dln2_dev *dln2, struct urb *urb,
struct dln2_rx_context *rxc;
bool valid_slot = false;

+ if (rx_slot >= DLN2_MAX_RX_SLOTS)
+ goto out;
+
rxc = &rxs->slots[rx_slot];

/*
@@ -210,6 +213,7 @@ static bool dln2_transfer_complete(struct dln2_dev *dln2, struct urb *urb,
}
spin_unlock(&rxs->lock);

+out:
if (!valid_slot)
dev_warn(dev, "bad/late response %d/%d\n", handle, rx_slot);

--
1.9.1

2014-11-18 12:59:56

by Octavian Purdila

[permalink] [raw]
Subject: [PATCH v2 1/4] mfd: dln2: fix _dln2_transfer return code

If wait_for_completion_interruptible_timeout returns a positive value
it may be propagated as the return value of _dln2_transfer. This
contradicts the documentation of the function and exposes unnecessary
internals to the callers.

This patch makes sure to set the return value to 0 in that case.

Reported-by: Julia Lawall <[email protected]>
Signed-off-by: Octavian Purdila <[email protected]>
---
drivers/mfd/dln2.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/mfd/dln2.c b/drivers/mfd/dln2.c
index 9765a17..cf22841 100644
--- a/drivers/mfd/dln2.c
+++ b/drivers/mfd/dln2.c
@@ -462,6 +462,8 @@ static int _dln2_transfer(struct dln2_dev *dln2, u16 handle, u16 cmd,
if (!ret)
ret = -ETIMEDOUT;
goto out_free_rx_slot;
+ } else {
+ ret = 0;
}

if (dln2->disconnect) {
@@ -484,10 +486,8 @@ static int _dln2_transfer(struct dln2_dev *dln2, u16 handle, u16 cmd,
goto out_free_rx_slot;
}

- if (!ibuf) {
- ret = 0;
+ if (!ibuf)
goto out_free_rx_slot;
- }

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

2014-11-19 17:34:10

by Lee Jones

[permalink] [raw]
Subject: [GIT PULL] Immutable branch between MFD, GPIO and I2C (Second batch)

Linus, Wolfram,

Second instalment. Enjoy!

The following changes since commit f114040e3ea6e07372334ade75d1ee0775c355e1:

Linux 3.18-rc1 (2014-10-19 18:08:38 -0700)

are available in the git repository at:

git://git.kernel.org/pub/scm/linux/kernel/git/lee/mfd.git tags/ib-mfd-gpio-i2c-v3.19-1

for you to fetch changes up to 2fc2b4846c14c8c2d2c6e9114b4548f846521cfb:

mfd: dln2: A couple endian fixes (2014-11-19 17:12:59 +0000)

----------------------------------------------------------------
Immutable branch between MFD, GPIO and I2C due for v3.19.

This is the second such tag, due to more patches (fixes) added.

----------------------------------------------------------------
Dan Carpenter (1):
mfd: dln2: A couple endian fixes

Daniel Baluta (1):
gpio: add support for the Diolan DLN-2 USB GPIO driver

Johan Hovold (1):
mfd: core: Add helper function to register hotplug devices

Laurentiu Palcu (1):
i2c: add support for Diolan DLN-2 USB-I2C adapter

Octavian Purdila (4):
mfd: Add support for Diolan DLN-2 devices
mfd: dln2: Fix _dln2_transfer return code
i2c: dln2: Simplify return flow for dln2_i2c_enable
mfd: dln2: Add a limit check for invalid echo

drivers/gpio/Kconfig | 12 +
drivers/gpio/Makefile | 1 +
drivers/gpio/gpio-dln2.c | 553 ++++++++++++++++++++++++++++++
drivers/i2c/busses/Kconfig | 10 +
drivers/i2c/busses/Makefile | 1 +
drivers/i2c/busses/i2c-dln2.c | 262 ++++++++++++++
drivers/mfd/Kconfig | 10 +
drivers/mfd/Makefile | 1 +
drivers/mfd/dln2.c | 769 ++++++++++++++++++++++++++++++++++++++++++
include/linux/mfd/core.h | 7 +
include/linux/mfd/dln2.h | 103 ++++++
11 files changed, 1729 insertions(+)
create mode 100644 drivers/gpio/gpio-dln2.c
create mode 100644 drivers/i2c/busses/i2c-dln2.c
create mode 100644 drivers/mfd/dln2.c
create mode 100644 include/linux/mfd/dln2.h

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