netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/3] net/usb/r815x: replace USB buffer from stack to DMA-able
@ 2013-07-23  9:26 hayeswang
  2013-07-25  0:49 ` David Miller
                   ` (2 more replies)
  0 siblings, 3 replies; 33+ messages in thread
From: hayeswang @ 2013-07-23  9:26 UTC (permalink / raw)
  To: gregkh; +Cc: netdev, linux-kernel, linux-usb

Some USB buffers use stack which may not be DMA-able.
Use the buffers from kmalloc to replace those one.
 
Signed-off-by: Hayes Wang <hayeswang@realtek.com>
---
 drivers/net/usb/r815x.c | 44 +++++++++++++++++++++++++++-----------------
 1 file changed, 27 insertions(+), 17 deletions(-)
 
diff --git a/drivers/net/usb/r815x.c b/drivers/net/usb/r815x.c
index 8523922..e9b99ba 100644
--- a/drivers/net/usb/r815x.c
+++ b/drivers/net/usb/r815x.c
@@ -24,34 +24,43 @@
 
 static int pla_read_word(struct usb_device *udev, u16 index)
 {
- int data, ret;
+ int ret;
  u8 shift = index & 2;
- __le32 ocp_data;
+ __le32 *tmp;
+
+ tmp = kmalloc(sizeof(*tmp), GFP_KERNEL);
+ if (!tmp)
+  return -ENOMEM;
 
  index &= ~3;
 
  ret = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
          RTL815x_REQ_GET_REGS, RTL815x_REQT_READ,
-         index, MCU_TYPE_PLA, &ocp_data, sizeof(ocp_data),
-         500);
+         index, MCU_TYPE_PLA, tmp, sizeof(*tmp), 500);
  if (ret < 0)
-  return ret;
+  goto out2;
 
- data = __le32_to_cpu(ocp_data);
- data >>= (shift * 8);
- data &= 0xffff;
+ ret = __le32_to_cpu(*tmp);
+ ret >>= (shift * 8);
+ ret &= 0xffff;
 
- return data;
+out2:
+ kfree(tmp);
+ return ret;
 }
 
 static int pla_write_word(struct usb_device *udev, u16 index, u32 data)
 {
- __le32 ocp_data;
+ __le32 *tmp;
  u32 mask = 0xffff;
  u16 byen = BYTE_EN_WORD;
  u8 shift = index & 2;
  int ret;
 
+ tmp = kmalloc(sizeof(*tmp), GFP_KERNEL);
+ if (!tmp)
+  return -ENOMEM;
+
  data &= mask;
 
  if (shift) {
@@ -63,19 +72,20 @@ static int pla_write_word(struct usb_device *udev, u16 index, u32 data)
 
  ret = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
          RTL815x_REQ_GET_REGS, RTL815x_REQT_READ,
-         index, MCU_TYPE_PLA, &ocp_data, sizeof(ocp_data),
-         500);
+         index, MCU_TYPE_PLA, tmp, sizeof(*tmp), 500);
  if (ret < 0)
-  return ret;
+  goto out3;
 
- data |= __le32_to_cpu(ocp_data) & ~mask;
- ocp_data = __cpu_to_le32(data);
+ data |= __le32_to_cpu(*tmp) & ~mask;
+ *tmp = __cpu_to_le32(data);
 
  ret = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
          RTL815x_REQ_SET_REGS, RTL815x_REQT_WRITE,
-         index, MCU_TYPE_PLA | byen, &ocp_data,
-         sizeof(ocp_data), 500);
+         index, MCU_TYPE_PLA | byen, tmp, sizeof(*tmp),
+         500);
 
+out3:
+ kfree(tmp);
  return ret;
 }
 
-- 
1.8.3.1
 

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

end of thread, other threads:[~2013-07-31 21:50 UTC | newest]

Thread overview: 33+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-07-23  9:26 [PATCH 1/3] net/usb/r815x: replace USB buffer from stack to DMA-able hayeswang
2013-07-25  0:49 ` David Miller
2013-07-25  7:59   ` [PATCH v2 " Hayes Wang
2013-07-25  7:59     ` [PATCH v2 2/3] net/usb/r8152: make sure the USB buffer is DMA-able Hayes Wang
2013-07-25  7:59     ` [PATCH v2 3/3] net/usb/r8152: adjust relative ocp function Hayes Wang
     [not found]     ` <1374739144-732-1-git-send-email-hayeswang-Rasf1IRRPZFBDgjK7y7TUQ@public.gmane.org>
2013-07-28  3:21       ` [PATCH v2 1/3] net/usb/r815x: replace USB buffer from stack to DMA-able David Miller
2013-07-29  5:20         ` Oliver Neukum
2013-07-29  7:46           ` David Miller
2013-07-30  8:28 ` [PATCH v3 " Hayes Wang
2013-07-30  8:28   ` [PATCH v3 2/3] net/usb/r8152: " Hayes Wang
2013-07-30 14:01     ` Greg KH
2013-07-30  8:28   ` [PATCH v3 3/3] net/usb/r8152: adjust relative ocp function Hayes Wang
2013-07-30 13:58   ` [PATCH v3 1/3] net/usb/r815x: replace USB buffer from stack to DMA-able Greg KH
2013-07-30 15:17     ` [PATCH] MAINTAINERS: USB, remove F: drivers/net/usb/ pattern Joe Perches
2013-07-30 14:00   ` [PATCH v3 1/3] net/usb/r815x: replace USB buffer from stack to DMA-able Greg KH
2013-07-30 18:33     ` David Miller
2013-07-30 18:41       ` Joe Perches
2013-07-30 18:49         ` David Miller
2013-07-31 10:29           ` Ming Lei
2013-07-30 18:58       ` Greg KH
2013-07-30 14:29   ` Ming Lei
2013-07-31  9:21 ` [PATCH v4 1/5] " Hayes Wang
2013-07-31  9:21   ` [PATCH v4 2/5] net/usb/r815x: avoid to call mdio functions for runtime-suspended device Hayes Wang
2013-07-31 21:49     ` David Miller
2013-07-31  9:21   ` [PATCH v4 3/5] net/usb/r815x: change the return value for bind functions Hayes Wang
     [not found]     ` <1375262486-5373-3-git-send-email-hayeswang-Rasf1IRRPZFBDgjK7y7TUQ@public.gmane.org>
2013-07-31 21:49       ` David Miller
     [not found]   ` <1375262486-5373-1-git-send-email-hayeswang-Rasf1IRRPZFBDgjK7y7TUQ@public.gmane.org>
2013-07-31  9:21     ` [PATCH v4 4/5] net/usb/r8152: make sure the USB buffer is DMA-able Hayes Wang
2013-07-31 12:54       ` Greg KH
2013-07-31 21:50       ` David Miller
2013-07-31  9:21   ` [PATCH v4 5/5] net/usb/r8152: adjust relative ocp function Hayes Wang
2013-07-31 21:50     ` David Miller
2013-07-31 12:53   ` [PATCH v4 1/5] net/usb/r815x: replace USB buffer from stack to DMA-able Greg KH
2013-07-31 21:49   ` David Miller

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