* [PATCH] i2c-tiny-usb: do not use stack as URB transfer_buffer
@ 2013-08-06 11:17 Jussi Kivilinna
[not found] ` <20130806111742.25265.94046.stgit-bi+AKbBUZKagILUCTcTcHdKyNwTtLsGr@public.gmane.org>
0 siblings, 1 reply; 4+ messages in thread
From: Jussi Kivilinna @ 2013-08-06 11:17 UTC (permalink / raw)
To: linux-i2c-u79uwXL29TY76Z2rM5mHXA
Cc: linux-usb-u79uwXL29TY76Z2rM5mHXA, Till Harbaum, Wolfram Sang
Patch fixes i2c-tiny-usb not to use stack as URB transfer_buffer. URB buffers
need to be DMA-able, which stack is not.
Patch is only compile tested.
Cc: stable-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Signed-off-by: Jussi Kivilinna <jussi.kivilinna-X3B1VOXEql0@public.gmane.org>
---
drivers/i2c/busses/i2c-tiny-usb.c | 49 ++++++++++++++++++++++++++-----------
1 file changed, 34 insertions(+), 15 deletions(-)
diff --git a/drivers/i2c/busses/i2c-tiny-usb.c b/drivers/i2c/busses/i2c-tiny-usb.c
index 0510636..e7d3b75 100644
--- a/drivers/i2c/busses/i2c-tiny-usb.c
+++ b/drivers/i2c/busses/i2c-tiny-usb.c
@@ -54,12 +54,16 @@ static int usb_write(struct i2c_adapter *adapter, int cmd,
static int usb_xfer(struct i2c_adapter *adapter, struct i2c_msg *msgs, int num)
{
- unsigned char status;
+ unsigned char *pstatus;
struct i2c_msg *pmsg;
- int i;
+ int i, ret;
dev_dbg(&adapter->dev, "master xfer %d messages:\n", num);
+ pstatus = kmalloc(sizeof(*pstatus), GFP_KERNEL);
+ if (!pstatus)
+ return -ENOMEM;
+
for (i = 0 ; i < num ; i++) {
int cmd = CMD_I2C_IO;
@@ -84,7 +88,8 @@ static int usb_xfer(struct i2c_adapter *adapter, struct i2c_msg *msgs, int num)
pmsg->buf, pmsg->len) != pmsg->len) {
dev_err(&adapter->dev,
"failure reading data\n");
- return -EREMOTEIO;
+ ret = -EREMOTEIO;
+ goto out;
}
} else {
/* write data */
@@ -93,36 +98,50 @@ static int usb_xfer(struct i2c_adapter *adapter, struct i2c_msg *msgs, int num)
pmsg->buf, pmsg->len) != pmsg->len) {
dev_err(&adapter->dev,
"failure writing data\n");
- return -EREMOTEIO;
+ ret = -EREMOTEIO;
+ goto out;
}
}
/* read status */
- if (usb_read(adapter, CMD_GET_STATUS, 0, 0, &status, 1) != 1) {
+ if (usb_read(adapter, CMD_GET_STATUS, 0, 0, pstatus, 1) != 1) {
dev_err(&adapter->dev, "failure reading status\n");
- return -EREMOTEIO;
+ ret = -EREMOTEIO;
+ goto out;
}
- dev_dbg(&adapter->dev, " status = %d\n", status);
- if (status == STATUS_ADDRESS_NAK)
- return -EREMOTEIO;
+ dev_dbg(&adapter->dev, " status = %d\n", *pstatus);
+ if (*pstatus == STATUS_ADDRESS_NAK) {
+ ret = -EREMOTEIO;
+ goto out;
+ }
}
- return i;
+ ret = i;
+out:
+ kfree(pstatus);
+ return ret;
}
static u32 usb_func(struct i2c_adapter *adapter)
{
- __le32 func;
+ __le32 *pfunc;
+ u32 ret;
+
+ pfunc = kmalloc(sizeof(*pfunc), GFP_KERNEL);
/* get functionality from adapter */
- if (usb_read(adapter, CMD_GET_FUNC, 0, 0, &func, sizeof(func)) !=
- sizeof(func)) {
+ if (!pfunc || usb_read(adapter, CMD_GET_FUNC, 0, 0, pfunc,
+ sizeof(*pfunc)) != sizeof(*pfunc)) {
dev_err(&adapter->dev, "failure reading functionality\n");
- return 0;
+ ret = 0;
+ goto out;
}
- return le32_to_cpu(func);
+ ret = le32_to_cpup(pfunc);
+out:
+ kfree(pfunc);
+ return ret;
}
/* This is the actual algorithm we define */
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] i2c-tiny-usb: do not use stack as URB transfer_buffer
[not found] ` <20130806111742.25265.94046.stgit-bi+AKbBUZKagILUCTcTcHdKyNwTtLsGr@public.gmane.org>
@ 2013-08-15 17:55 ` Wolfram Sang
2013-08-15 19:46 ` Jussi Kivilinna
0 siblings, 1 reply; 4+ messages in thread
From: Wolfram Sang @ 2013-08-15 17:55 UTC (permalink / raw)
To: Jussi Kivilinna
Cc: linux-i2c-u79uwXL29TY76Z2rM5mHXA,
linux-usb-u79uwXL29TY76Z2rM5mHXA, Till Harbaum
[-- Attachment #1: Type: text/plain, Size: 409 bytes --]
On Tue, Aug 06, 2013 at 02:17:42PM +0300, Jussi Kivilinna wrote:
> Patch fixes i2c-tiny-usb not to use stack as URB transfer_buffer. URB buffers
> need to be DMA-able, which stack is not.
>
> Patch is only compile tested.
>
> Cc: stable-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
> Signed-off-by: Jussi Kivilinna <jussi.kivilinna-X3B1VOXEql0@public.gmane.org>
Looks OK to me. Till, are you there?
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] i2c-tiny-usb: do not use stack as URB transfer_buffer
2013-08-15 17:55 ` Wolfram Sang
@ 2013-08-15 19:46 ` Jussi Kivilinna
[not found] ` <520D3018.3000709-X3B1VOXEql0@public.gmane.org>
0 siblings, 1 reply; 4+ messages in thread
From: Jussi Kivilinna @ 2013-08-15 19:46 UTC (permalink / raw)
To: Wolfram Sang
Cc: linux-i2c-u79uwXL29TY76Z2rM5mHXA,
linux-usb-u79uwXL29TY76Z2rM5mHXA, Till Harbaum
On 15.08.2013 20:55, Wolfram Sang wrote:
> On Tue, Aug 06, 2013 at 02:17:42PM +0300, Jussi Kivilinna wrote:
>> Patch fixes i2c-tiny-usb not to use stack as URB transfer_buffer. URB buffers
>> need to be DMA-able, which stack is not.
>>
>> Patch is only compile tested.
>>
>> Cc: stable-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
>> Signed-off-by: Jussi Kivilinna <jussi.kivilinna-X3B1VOXEql0@public.gmane.org>
>
> Looks OK to me. Till, are you there?
That cc to stable should probably be removed if patch is not tested on hw.
-Jussi
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] i2c-tiny-usb: do not use stack as URB transfer_buffer
[not found] ` <520D3018.3000709-X3B1VOXEql0@public.gmane.org>
@ 2013-08-19 17:47 ` Wolfram Sang
0 siblings, 0 replies; 4+ messages in thread
From: Wolfram Sang @ 2013-08-19 17:47 UTC (permalink / raw)
To: Jussi Kivilinna
Cc: linux-i2c-u79uwXL29TY76Z2rM5mHXA,
linux-usb-u79uwXL29TY76Z2rM5mHXA, Till Harbaum
[-- Attachment #1: Type: text/plain, Size: 694 bytes --]
On Thu, Aug 15, 2013 at 10:46:32PM +0300, Jussi Kivilinna wrote:
> On 15.08.2013 20:55, Wolfram Sang wrote:
> > On Tue, Aug 06, 2013 at 02:17:42PM +0300, Jussi Kivilinna wrote:
> >> Patch fixes i2c-tiny-usb not to use stack as URB transfer_buffer. URB buffers
> >> need to be DMA-able, which stack is not.
> >>
> >> Patch is only compile tested.
> >>
> >> Cc: stable-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
> >> Signed-off-by: Jussi Kivilinna <jussi.kivilinna-X3B1VOXEql0@public.gmane.org>
> >
> > Looks OK to me. Till, are you there?
>
> That cc to stable should probably be removed if patch is not tested on hw.
Applied to for-next, thanks! And removed stable for now...
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2013-08-19 17:47 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-08-06 11:17 [PATCH] i2c-tiny-usb: do not use stack as URB transfer_buffer Jussi Kivilinna
[not found] ` <20130806111742.25265.94046.stgit-bi+AKbBUZKagILUCTcTcHdKyNwTtLsGr@public.gmane.org>
2013-08-15 17:55 ` Wolfram Sang
2013-08-15 19:46 ` Jussi Kivilinna
[not found] ` <520D3018.3000709-X3B1VOXEql0@public.gmane.org>
2013-08-19 17:47 ` Wolfram Sang
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.