linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/4] dln2 fixes for ib-mfd-gpio-i2c-3.19
@ 2014-11-18 12:57 Octavian Purdila
  2014-11-18 12:57 ` [PATCH v2 1/4] mfd: dln2: fix _dln2_transfer return code Octavian Purdila
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Octavian Purdila @ 2014-11-18 12:57 UTC (permalink / raw)
  To: lee.jones
  Cc: wsa, julia.lawall, dan.carpenter, johan, linux-i2c, linux-kernel,
	Octavian Purdila

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


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH v2 1/4] mfd: dln2: fix _dln2_transfer return code
  2014-11-18 12:57 [PATCH v2 0/4] dln2 fixes for ib-mfd-gpio-i2c-3.19 Octavian Purdila
@ 2014-11-18 12:57 ` Octavian Purdila
  2014-11-18 12:57 ` [PATCH v2 2/4] i2c: dln2: simplify return flow for dln2_i2c_enable Octavian Purdila
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Octavian Purdila @ 2014-11-18 12:57 UTC (permalink / raw)
  To: lee.jones
  Cc: wsa, julia.lawall, dan.carpenter, johan, linux-i2c, linux-kernel,
	Octavian Purdila

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 <julia.lawall@lip6.fr>
Signed-off-by: Octavian Purdila <octavian.purdila@intel.com>
---
 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


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH v2 2/4] i2c: dln2: simplify return flow for dln2_i2c_enable
  2014-11-18 12:57 [PATCH v2 0/4] dln2 fixes for ib-mfd-gpio-i2c-3.19 Octavian Purdila
  2014-11-18 12:57 ` [PATCH v2 1/4] mfd: dln2: fix _dln2_transfer return code Octavian Purdila
@ 2014-11-18 12:57 ` Octavian Purdila
  2014-11-18 12:57 ` [PATCH v2 3/4] mfd: dln2: add a limit check for invalid echo Octavian Purdila
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Octavian Purdila @ 2014-11-18 12:57 UTC (permalink / raw)
  To: lee.jones
  Cc: wsa, julia.lawall, dan.carpenter, johan, linux-i2c, linux-kernel,
	Octavian Purdila

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 <fengguang.wu@intel.com>
Reported-by: Julia Lawall <julia.lawall@lip6.fr>
Signed-off-by: Octavian Purdila <octavian.purdila@intel.com>
Acked-by: Wolfram Sang <wsa@the-dreams.de>
---
 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


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH v2 3/4] mfd: dln2: add a limit check for invalid echo
  2014-11-18 12:57 [PATCH v2 0/4] dln2 fixes for ib-mfd-gpio-i2c-3.19 Octavian Purdila
  2014-11-18 12:57 ` [PATCH v2 1/4] mfd: dln2: fix _dln2_transfer return code Octavian Purdila
  2014-11-18 12:57 ` [PATCH v2 2/4] i2c: dln2: simplify return flow for dln2_i2c_enable Octavian Purdila
@ 2014-11-18 12:57 ` Octavian Purdila
  2014-11-18 12:58 ` [PATCH v2 4/4] mfd: dln2: a couple endian fixes Octavian Purdila
  2014-11-19 17:34 ` [GIT PULL] Immutable branch between MFD, GPIO and I2C (Second batch) Lee Jones
  4 siblings, 0 replies; 6+ messages in thread
From: Octavian Purdila @ 2014-11-18 12:57 UTC (permalink / raw)
  To: lee.jones
  Cc: wsa, julia.lawall, dan.carpenter, johan, linux-i2c, linux-kernel,
	Octavian Purdila

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 <dan.carpenter@oracle.com>
Signed-off-by: Octavian Purdila <octavian.purdila@intel.com>
---
 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


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH v2 4/4] mfd: dln2: a couple endian fixes
  2014-11-18 12:57 [PATCH v2 0/4] dln2 fixes for ib-mfd-gpio-i2c-3.19 Octavian Purdila
                   ` (2 preceding siblings ...)
  2014-11-18 12:57 ` [PATCH v2 3/4] mfd: dln2: add a limit check for invalid echo Octavian Purdila
@ 2014-11-18 12:58 ` Octavian Purdila
  2014-11-19 17:34 ` [GIT PULL] Immutable branch between MFD, GPIO and I2C (Second batch) Lee Jones
  4 siblings, 0 replies; 6+ messages in thread
From: Octavian Purdila @ 2014-11-18 12:58 UTC (permalink / raw)
  To: lee.jones
  Cc: wsa, julia.lawall, dan.carpenter, johan, linux-i2c, linux-kernel

From: Dan Carpenter <dan.carpenter@oracle.com>

Sparse catches a couple endian bugs.

Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Acked-by: Octavian Purdila <octavian.purdila@intel.com>
---
 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


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [GIT PULL] Immutable branch between MFD, GPIO and I2C (Second batch)
  2014-11-18 12:57 [PATCH v2 0/4] dln2 fixes for ib-mfd-gpio-i2c-3.19 Octavian Purdila
                   ` (3 preceding siblings ...)
  2014-11-18 12:58 ` [PATCH v2 4/4] mfd: dln2: a couple endian fixes Octavian Purdila
@ 2014-11-19 17:34 ` Lee Jones
  4 siblings, 0 replies; 6+ messages in thread
From: Lee Jones @ 2014-11-19 17:34 UTC (permalink / raw)
  To: Octavian Purdila
  Cc: wsa, julia.lawall, dan.carpenter, johan, linux-i2c, linux-kernel

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

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2014-11-19 17:34 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-11-18 12:57 [PATCH v2 0/4] dln2 fixes for ib-mfd-gpio-i2c-3.19 Octavian Purdila
2014-11-18 12:57 ` [PATCH v2 1/4] mfd: dln2: fix _dln2_transfer return code Octavian Purdila
2014-11-18 12:57 ` [PATCH v2 2/4] i2c: dln2: simplify return flow for dln2_i2c_enable Octavian Purdila
2014-11-18 12:57 ` [PATCH v2 3/4] mfd: dln2: add a limit check for invalid echo Octavian Purdila
2014-11-18 12:58 ` [PATCH v2 4/4] mfd: dln2: a couple endian fixes Octavian Purdila
2014-11-19 17:34 ` [GIT PULL] Immutable branch between MFD, GPIO and I2C (Second batch) Lee Jones

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).