From: Hayes Wang <hayeswang@realtek.com>
To: <gregkh@linuxfoundation.org>
Cc: <netdev@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
<linux-usb@vger.kernel.org>, Hayes Wang <hayeswang@realtek.com>
Subject: [PATCH v2 2/3] net/usb/r8152: make sure the USB buffer is DMA-able
Date: Thu, 25 Jul 2013 15:59:03 +0800 [thread overview]
Message-ID: <1374739144-732-2-git-send-email-hayeswang@realtek.com> (raw)
In-Reply-To: <1374739144-732-1-git-send-email-hayeswang@realtek.com>
Allocate the required memory before calling usb_control_msg. And
the additional memory copy is necessary.
Signed-off-by: Hayes Wang <hayeswang@realtek.com>
---
drivers/net/usb/r8152.c | 60 ++++++++++++++++++++++++++++---------------------
1 file changed, 35 insertions(+), 25 deletions(-)
diff --git a/drivers/net/usb/r8152.c b/drivers/net/usb/r8152.c
index ee13f9e..ef033ab 100644
--- a/drivers/net/usb/r8152.c
+++ b/drivers/net/usb/r8152.c
@@ -344,17 +344,41 @@ static const int multicast_filter_limit = 32;
static
int get_registers(struct r8152 *tp, u16 value, u16 index, u16 size, void *data)
{
- return usb_control_msg(tp->udev, usb_rcvctrlpipe(tp->udev, 0),
+ int ret;
+ void *tmp;
+
+ tmp = kmalloc(size, GFP_KERNEL);
+ if (!tmp)
+ return -ENOMEM;
+
+ ret = usb_control_msg(tp->udev, usb_rcvctrlpipe(tp->udev, 0),
RTL8152_REQ_GET_REGS, RTL8152_REQT_READ,
- value, index, data, size, 500);
+ value, index, tmp, size, 500);
+
+ memcpy(data, tmp, size);
+ kfree(tmp);
+
+ return ret;
}
static
int set_registers(struct r8152 *tp, u16 value, u16 index, u16 size, void *data)
{
- return usb_control_msg(tp->udev, usb_sndctrlpipe(tp->udev, 0),
+ int ret;
+ void *tmp;
+
+ tmp = kmalloc(size, GFP_KERNEL);
+ if (!tmp)
+ return -ENOMEM;
+
+ memcpy(tmp, data, size);
+
+ ret = usb_control_msg(tp->udev, usb_sndctrlpipe(tp->udev, 0),
RTL8152_REQ_SET_REGS, RTL8152_REQT_WRITE,
- value, index, data, size, 500);
+ value, index, tmp, size, 500);
+
+ kfree(tmp);
+ return ret;
}
static int generic_ocp_read(struct r8152 *tp, u16 index, u16 size,
@@ -685,21 +709,14 @@ static void ocp_reg_write(struct r8152 *tp, u16 addr, u16 data)
static inline void set_ethernet_addr(struct r8152 *tp)
{
struct net_device *dev = tp->netdev;
- u8 *node_id;
+ u8 node_id[8] = {0};
- node_id = kmalloc(sizeof(u8) * 8, GFP_KERNEL);
- if (!node_id) {
- netif_err(tp, probe, dev, "out of memory");
- return;
- }
-
- if (pla_ocp_read(tp, PLA_IDR, sizeof(u8) * 8, node_id) < 0)
+ if (pla_ocp_read(tp, PLA_IDR, sizeof(node_id), node_id) < 0)
netif_notice(tp, probe, dev, "inet addr fail\n");
else {
memcpy(dev->dev_addr, node_id, dev->addr_len);
memcpy(dev->perm_addr, dev->dev_addr, dev->addr_len);
}
- kfree(node_id);
}
static int rtl8152_set_mac_address(struct net_device *netdev, void *p)
@@ -882,15 +899,10 @@ static void rtl8152_set_rx_mode(struct net_device *netdev)
static void _rtl8152_set_rx_mode(struct net_device *netdev)
{
struct r8152 *tp = netdev_priv(netdev);
- u32 tmp, *mc_filter; /* Multicast hash filter */
+ u32 mc_filter[2]; /* Multicast hash filter */
+ __le32 tmp[2];
u32 ocp_data;
- mc_filter = kmalloc(sizeof(u32) * 2, GFP_KERNEL);
- if (!mc_filter) {
- netif_err(tp, link, netdev, "out of memory");
- return;
- }
-
clear_bit(RTL8152_SET_RX_MODE, &tp->flags);
netif_stop_queue(netdev);
ocp_data = ocp_read_dword(tp, MCU_TYPE_PLA, PLA_RCR);
@@ -918,14 +930,12 @@ static void _rtl8152_set_rx_mode(struct net_device *netdev)
}
}
- tmp = mc_filter[0];
- mc_filter[0] = __cpu_to_le32(swab32(mc_filter[1]));
- mc_filter[1] = __cpu_to_le32(swab32(tmp));
+ tmp[0] = __cpu_to_le32(swab32(mc_filter[1]));
+ tmp[1] = __cpu_to_le32(swab32(mc_filter[0]));
- pla_ocp_write(tp, PLA_MAR, BYTE_EN_DWORD, sizeof(u32) * 2, mc_filter);
+ pla_ocp_write(tp, PLA_MAR, BYTE_EN_DWORD, sizeof(tmp), tmp);
ocp_write_dword(tp, MCU_TYPE_PLA, PLA_RCR, ocp_data);
netif_wake_queue(netdev);
- kfree(mc_filter);
}
static netdev_tx_t rtl8152_start_xmit(struct sk_buff *skb,
--
1.8.3.1
next prev parent reply other threads:[~2013-07-25 7:59 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
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 ` Hayes Wang [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1374739144-732-2-git-send-email-hayeswang@realtek.com \
--to=hayeswang@realtek.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=netdev@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).