Bluetooth: btrtl: Use kvmalloc for FW allocations
authorMaxim Mikityanskiy <maxtram95@gmail.com>
Fri, 24 Jan 2020 17:15:35 +0000 (19:15 +0200)
committerMarcel Holtmann <marcel@holtmann.org>
Fri, 24 Jan 2020 18:57:53 +0000 (19:57 +0100)
commit268d3636dfb22254324774de1f8875174b3be064
treee6ce27cdf4115656d14bc5c2fdace00f7c84a027
parent6613babaf662cfbd283fcd0abdd758e338dd181d
Bluetooth: btrtl: Use kvmalloc for FW allocations

Currently, kmemdup is applied to the firmware data, and it invokes
kmalloc under the hood. The firmware size and patch_length are big (more
than PAGE_SIZE), and on some low-end systems (like ASUS E202SA) kmalloc
may fail to allocate a contiguous chunk under high memory usage and
fragmentation:

Bluetooth: hci0: RTL: examining hci_ver=06 hci_rev=000a lmp_ver=06 lmp_subver=8821
Bluetooth: hci0: RTL: rom_version status=0 version=1
Bluetooth: hci0: RTL: loading rtl_bt/rtl8821a_fw.bin
kworker/u9:2: page allocation failure: order:4, mode:0x40cc0(GFP_KERNEL|__GFP_COMP), nodemask=(null),cpuset=/,mems_allowed=0
<stack trace follows>

As firmware load happens on each resume, Bluetooth will stop working
after several iterations, when the kernel fails to allocate an order-4
page.

This patch replaces kmemdup with kvmalloc+memcpy. It's not required to
have a contiguous chunk here, because it's not mapped to the device
directly.

Signed-off-by: Maxim Mikityanskiy <maxtram95@gmail.com>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
drivers/bluetooth/btrtl.c