diff options
author | Andrea Merello <andrea.merello@gmail.com> | 2014-07-05 15:07:17 -0400 |
---|---|---|
committer | John W. Linville <linville@tuxdriver.com> | 2014-07-07 15:04:34 -0400 |
commit | 2c4db12ec469b9fcdad9f6bfd6fa20e65a563ac5 (patch) | |
tree | 436a0401718649925551de0b9cf76ce82c47bd8a | |
parent | 1b2388d03f871faec084666fe71acc770fad5160 (diff) |
rt2800usb: Don't perform DMA from stack
Function rt2800usb_autorun_detect() passes the address of a variable
allocated onto the stack to be used for DMA by the USB layer. This has
been caught by my debugging-enabled kernel.
This patch change things in order to allocate that variable via
kmalloc, and it adjusts things to handle the kmalloc failure case,
propagating the error.
[ 7363.238852] ------------[ cut here ]------------
[ 7363.243529] WARNING: CPU: 1 PID: 5235 at lib/dma-debug.c:1153 check_for_stack+0xa4/0xf0()
[ 7363.251759] ehci-pci 0000:00:04.1: DMA-API: device driver maps memory fromstack [addr=ffff88006b81bad4]
[ 7363.261210] Modules linked in: rt2800usb(O+) rt2800lib(O) rt2x00usb(O) rt2x00lib(O) rtl818x_pci(O) rtl8187 led_class eeprom_93cx6 mac80211 cfg80211 [last unloaded: rt2x00lib]
[ 7363.277143] CPU: 1 PID: 5235 Comm: systemd-udevd Tainted: G O 3.16.0-rc3-wl+ #31
[ 7363.285546] Hardware name: System manufacturer System Product Name/M3N78 PRO, BIOS ASUS M3N78 PRO ACPI BIOS Revision 1402 12/04/2009
[ 7363.297511] 0000000000000009 ffff88006b81b710 ffffffff8175dcad ffff88006b81b758
[ 7363.305062] ffff88006b81b748 ffffffff8106d372 ffff88006cf10098 ffff88006cead6a0
[ 7363.312622] ffff88006b81bad4 ffffffff81c1e7c0 ffff88006cf10098 ffff88006b81b7a8
[ 7363.320161] Call Trace:
[ 7363.322661] [<ffffffff8175dcad>] dump_stack+0x4d/0x6f
[ 7363.327847] [<ffffffff8106d372>] warn_slowpath_common+0x82/0xb0
[ 7363.333893] [<ffffffff8106d3e7>] warn_slowpath_fmt+0x47/0x50
[ 7363.339686] [<ffffffff813a93b4>] check_for_stack+0xa4/0xf0
[ 7363.345298] [<ffffffff813a995c>] debug_dma_map_page+0x10c/0x150
[ 7363.351367] [<ffffffff81521bd9>] usb_hcd_map_urb_for_dma+0x229/0x720
[ 7363.357890] [<ffffffff8152256d>] usb_hcd_submit_urb+0x2fd/0x930
[ 7363.363929] [<ffffffff810eac31>] ? irq_work_queue+0x71/0xd0
[ 7363.369617] [<ffffffff810ab5a7>] ? wake_up_klogd+0x37/0x50
[ 7363.375219] [<ffffffff810ab7a5>] ? console_unlock+0x1e5/0x420
[ 7363.381081] [<ffffffff810abc25>] ? vprintk_emit+0x245/0x530
[ 7363.386773] [<ffffffff81523d3c>] usb_submit_urb+0x30c/0x580
[ 7363.392462] [<ffffffff81524295>] usb_start_wait_urb+0x65/0xf0
[ 7363.398325] [<ffffffff815243ed>] usb_control_msg+0xcd/0x110
[ 7363.404014] [<ffffffffa005514d>] rt2x00usb_vendor_request+0xbd/0x170 [rt2x00usb]
[ 7363.411544] [<ffffffffa0074292>] rt2800usb_autorun_detect+0x32/0x50 [rt2800usb]
[ 7363.418986] [<ffffffffa0074aa1>] rt2800usb_read_eeprom+0x11/0x70 [rt2800usb]
[ 7363.426168] [<ffffffffa0063ffd>] rt2800_probe_hw+0x11d/0xf90 [rt2800lib]
[ 7363.432989] [<ffffffffa0074b7d>] rt2800usb_probe_hw+0xd/0x50 [rt2800usb]
[ 7363.439808] [<ffffffffa00453d8>] rt2x00lib_probe_dev+0x238/0x7c0 [rt2x00lib]
[ 7363.446992] [<ffffffffa00bfa48>] ? ieee80211_led_names+0xb8/0x100 [mac80211]
[ 7363.454156] [<ffffffffa0056116>] rt2x00usb_probe+0x156/0x1f0 [rt2x00usb]
[ 7363.460971] [<ffffffffa0074250>] rt2800usb_probe+0x10/0x20 [rt2800usb]
[ 7363.467616] [<ffffffff8152799e>] usb_probe_interface+0xce/0x1c0
[ 7363.473651] [<ffffffff81480c20>] really_probe+0x70/0x240
[ 7363.479079] [<ffffffff81480f01>] __driver_attach+0xa1/0xb0
[ 7363.484682] [<ffffffff81480e60>] ? __device_attach+0x70/0x70
[ 7363.490461] [<ffffffff8147eef3>] bus_for_each_dev+0x63/0xa0
[ 7363.496146] [<ffffffff814807c9>] driver_attach+0x19/0x20
[ 7363.501570] [<ffffffff81480468>] bus_add_driver+0x178/0x220
[ 7363.507270] [<ffffffff8148151b>] driver_register+0x5b/0xe0
[ 7363.512874] [<ffffffff815271b0>] usb_register_driver+0xa0/0x170
[ 7363.518905] [<ffffffffa007a000>] ? 0xffffffffa0079fff
[ 7363.524074] [<ffffffffa007a01e>] rt2800usb_driver_init+0x1e/0x20 [rt2800usb]
[ 7363.531247] [<ffffffff810002d4>] do_one_initcall+0x84/0x1b0
[ 7363.536932] [<ffffffff8113aa60>] ? kfree+0xd0/0x110
[ 7363.541931] [<ffffffff8112730a>] ? __vunmap+0xaa/0xf0
[ 7363.547538] [<ffffffff810ca07e>] load_module+0x1aee/0x2040
[ 7363.553141] [<ffffffff810c6f10>] ? store_uevent+0x50/0x50
[ 7363.558676] [<ffffffff810ca66e>] SyS_init_module+0x9e/0xc0
[ 7363.564285] [<ffffffff81764012>] system_call_fastpath+0x16/0x1b
[ 7363.570338] ---[ end trace 01ef5f822bea9882 ]---
Signed-off-by: Andrea Merello <andrea.merello@gmail.com>
Acked-by: Helmut Schaa <helmut.schaa@googlemail.com>
Signed-off-by: John W. Linville <linville@tuxdriver.com>
-rw-r--r-- | drivers/net/wireless/rt2x00/rt2800usb.c | 28 |
1 files changed, 22 insertions, 6 deletions
diff --git a/drivers/net/wireless/rt2x00/rt2800usb.c b/drivers/net/wireless/rt2x00/rt2800usb.c index e11dab2216c6..832006b5aab1 100644 --- a/drivers/net/wireless/rt2x00/rt2800usb.c +++ b/drivers/net/wireless/rt2x00/rt2800usb.c | |||
@@ -231,9 +231,12 @@ static enum hrtimer_restart rt2800usb_tx_sta_fifo_timeout(struct hrtimer *timer) | |||
231 | */ | 231 | */ |
232 | static int rt2800usb_autorun_detect(struct rt2x00_dev *rt2x00dev) | 232 | static int rt2800usb_autorun_detect(struct rt2x00_dev *rt2x00dev) |
233 | { | 233 | { |
234 | __le32 reg; | 234 | __le32 *reg; |
235 | u32 fw_mode; | 235 | u32 fw_mode; |
236 | 236 | ||
237 | reg = kmalloc(sizeof(*reg), GFP_KERNEL); | ||
238 | if (reg == NULL) | ||
239 | return -ENOMEM; | ||
237 | /* cannot use rt2x00usb_register_read here as it uses different | 240 | /* cannot use rt2x00usb_register_read here as it uses different |
238 | * mode (MULTI_READ vs. DEVICE_MODE) and does not pass the | 241 | * mode (MULTI_READ vs. DEVICE_MODE) and does not pass the |
239 | * magic value USB_MODE_AUTORUN (0x11) to the device, thus the | 242 | * magic value USB_MODE_AUTORUN (0x11) to the device, thus the |
@@ -241,8 +244,9 @@ static int rt2800usb_autorun_detect(struct rt2x00_dev *rt2x00dev) | |||
241 | */ | 244 | */ |
242 | rt2x00usb_vendor_request(rt2x00dev, USB_DEVICE_MODE, | 245 | rt2x00usb_vendor_request(rt2x00dev, USB_DEVICE_MODE, |
243 | USB_VENDOR_REQUEST_IN, 0, USB_MODE_AUTORUN, | 246 | USB_VENDOR_REQUEST_IN, 0, USB_MODE_AUTORUN, |
244 | ®, sizeof(reg), REGISTER_TIMEOUT_FIRMWARE); | 247 | reg, sizeof(*reg), REGISTER_TIMEOUT_FIRMWARE); |
245 | fw_mode = le32_to_cpu(reg); | 248 | fw_mode = le32_to_cpu(*reg); |
249 | kfree(reg); | ||
246 | 250 | ||
247 | if ((fw_mode & 0x00000003) == 2) | 251 | if ((fw_mode & 0x00000003) == 2) |
248 | return 1; | 252 | return 1; |
@@ -261,6 +265,7 @@ static int rt2800usb_write_firmware(struct rt2x00_dev *rt2x00dev, | |||
261 | int status; | 265 | int status; |
262 | u32 offset; | 266 | u32 offset; |
263 | u32 length; | 267 | u32 length; |
268 | int retval; | ||
264 | 269 | ||
265 | /* | 270 | /* |
266 | * Check which section of the firmware we need. | 271 | * Check which section of the firmware we need. |
@@ -278,7 +283,10 @@ static int rt2800usb_write_firmware(struct rt2x00_dev *rt2x00dev, | |||
278 | /* | 283 | /* |
279 | * Write firmware to device. | 284 | * Write firmware to device. |
280 | */ | 285 | */ |
281 | if (rt2800usb_autorun_detect(rt2x00dev)) { | 286 | retval = rt2800usb_autorun_detect(rt2x00dev); |
287 | if (retval < 0) | ||
288 | return retval; | ||
289 | if (retval) { | ||
282 | rt2x00_info(rt2x00dev, | 290 | rt2x00_info(rt2x00dev, |
283 | "Firmware loading not required - NIC in AutoRun mode\n"); | 291 | "Firmware loading not required - NIC in AutoRun mode\n"); |
284 | } else { | 292 | } else { |
@@ -763,7 +771,12 @@ static void rt2800usb_fill_rxdone(struct queue_entry *entry, | |||
763 | */ | 771 | */ |
764 | static int rt2800usb_efuse_detect(struct rt2x00_dev *rt2x00dev) | 772 | static int rt2800usb_efuse_detect(struct rt2x00_dev *rt2x00dev) |
765 | { | 773 | { |
766 | if (rt2800usb_autorun_detect(rt2x00dev)) | 774 | int retval; |
775 | |||
776 | retval = rt2800usb_autorun_detect(rt2x00dev); | ||
777 | if (retval < 0) | ||
778 | return retval; | ||
779 | if (retval) | ||
767 | return 1; | 780 | return 1; |
768 | return rt2800_efuse_detect(rt2x00dev); | 781 | return rt2800_efuse_detect(rt2x00dev); |
769 | } | 782 | } |
@@ -772,7 +785,10 @@ static int rt2800usb_read_eeprom(struct rt2x00_dev *rt2x00dev) | |||
772 | { | 785 | { |
773 | int retval; | 786 | int retval; |
774 | 787 | ||
775 | if (rt2800usb_efuse_detect(rt2x00dev)) | 788 | retval = rt2800usb_efuse_detect(rt2x00dev); |
789 | if (retval < 0) | ||
790 | return retval; | ||
791 | if (retval) | ||
776 | retval = rt2800_read_eeprom_efuse(rt2x00dev); | 792 | retval = rt2800_read_eeprom_efuse(rt2x00dev); |
777 | else | 793 | else |
778 | retval = rt2x00usb_eeprom_read(rt2x00dev, rt2x00dev->eeprom, | 794 | retval = rt2x00usb_eeprom_read(rt2x00dev, rt2x00dev->eeprom, |