Gentoo Archives: gentoo-commits

From: Mike Pagano <mpagano@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/linux-patches:4.4 commit in: /
Date: Sat, 01 Dec 2018 15:02:24
Message-Id: 1543676511.31dc94d27031b69ce9ee6a4acb3974a4e64a98b4.mpagano@gentoo
1 commit: 31dc94d27031b69ce9ee6a4acb3974a4e64a98b4
2 Author: Mike Pagano <mpagano <AT> gentoo <DOT> org>
3 AuthorDate: Sat Dec 1 15:01:51 2018 +0000
4 Commit: Mike Pagano <mpagano <AT> gentoo <DOT> org>
5 CommitDate: Sat Dec 1 15:01:51 2018 +0000
6 URL: https://gitweb.gentoo.org/proj/linux-patches.git/commit/?id=31dc94d2
7
8 proj/linux-patches: Linux patch 4.4.166
9
10 Signed-off-by: Mike Pagano <mpagano <AT> gentoo.org>
11
12 0000_README | 4 +
13 1165_linux-4.4.166.patch | 2967 ++++++++++++++++++++++++++++++++++++++++++++++
14 2 files changed, 2971 insertions(+)
15
16 diff --git a/0000_README b/0000_README
17 index d3f97eb..d122069 100644
18 --- a/0000_README
19 +++ b/0000_README
20 @@ -703,6 +703,10 @@ Patch: 1164_linux-4.4.165.patch
21 From: http://www.kernel.org
22 Desc: Linux 4.4.165
23
24 +Patch: 1165_linux-4.4.166.patch
25 +From: http://www.kernel.org
26 +Desc: Linux 4.4.166
27 +
28 Patch: 1500_XATTR_USER_PREFIX.patch
29 From: https://bugs.gentoo.org/show_bug.cgi?id=470644
30 Desc: Support for namespace user.pax.* on tmpfs.
31
32 diff --git a/1165_linux-4.4.166.patch b/1165_linux-4.4.166.patch
33 new file mode 100644
34 index 0000000..f5a8669
35 --- /dev/null
36 +++ b/1165_linux-4.4.166.patch
37 @@ -0,0 +1,2967 @@
38 +diff --git a/Documentation/sysctl/fs.txt b/Documentation/sysctl/fs.txt
39 +index 35e17f748ca7..af5859b2d0f9 100644
40 +--- a/Documentation/sysctl/fs.txt
41 ++++ b/Documentation/sysctl/fs.txt
42 +@@ -34,7 +34,9 @@ Currently, these files are in /proc/sys/fs:
43 + - overflowgid
44 + - pipe-user-pages-hard
45 + - pipe-user-pages-soft
46 ++- protected_fifos
47 + - protected_hardlinks
48 ++- protected_regular
49 + - protected_symlinks
50 + - suid_dumpable
51 + - super-max
52 +@@ -182,6 +184,24 @@ applied.
53 +
54 + ==============================================================
55 +
56 ++protected_fifos:
57 ++
58 ++The intent of this protection is to avoid unintentional writes to
59 ++an attacker-controlled FIFO, where a program expected to create a regular
60 ++file.
61 ++
62 ++When set to "0", writing to FIFOs is unrestricted.
63 ++
64 ++When set to "1" don't allow O_CREAT open on FIFOs that we don't own
65 ++in world writable sticky directories, unless they are owned by the
66 ++owner of the directory.
67 ++
68 ++When set to "2" it also applies to group writable sticky directories.
69 ++
70 ++This protection is based on the restrictions in Openwall.
71 ++
72 ++==============================================================
73 ++
74 + protected_hardlinks:
75 +
76 + A long-standing class of security issues is the hardlink-based
77 +@@ -202,6 +222,22 @@ This protection is based on the restrictions in Openwall and grsecurity.
78 +
79 + ==============================================================
80 +
81 ++protected_regular:
82 ++
83 ++This protection is similar to protected_fifos, but it
84 ++avoids writes to an attacker-controlled regular file, where a program
85 ++expected to create one.
86 ++
87 ++When set to "0", writing to regular files is unrestricted.
88 ++
89 ++When set to "1" don't allow O_CREAT open on regular files that we
90 ++don't own in world writable sticky directories, unless they are
91 ++owned by the owner of the directory.
92 ++
93 ++When set to "2" it also applies to group writable sticky directories.
94 ++
95 ++==============================================================
96 ++
97 + protected_symlinks:
98 +
99 + A long-standing class of security issues is the symlink-based
100 +diff --git a/MAINTAINERS b/MAINTAINERS
101 +index ab65bbecb159..f4d4a5544dc1 100644
102 +--- a/MAINTAINERS
103 ++++ b/MAINTAINERS
104 +@@ -10135,6 +10135,7 @@ F: arch/alpha/kernel/srm_env.c
105 +
106 + STABLE BRANCH
107 + M: Greg Kroah-Hartman <gregkh@×××××××××××××××.org>
108 ++M: Sasha Levin <sashal@××××××.org>
109 + L: stable@×××××××××××.org
110 + S: Supported
111 + F: Documentation/stable_kernel_rules.txt
112 +diff --git a/Makefile b/Makefile
113 +index 441a760dc5a4..64521458d35e 100644
114 +--- a/Makefile
115 ++++ b/Makefile
116 +@@ -1,6 +1,6 @@
117 + VERSION = 4
118 + PATCHLEVEL = 4
119 +-SUBLEVEL = 165
120 ++SUBLEVEL = 166
121 + EXTRAVERSION =
122 + NAME = Blurry Fish Butt
123 +
124 +diff --git a/arch/arm64/Makefile b/arch/arm64/Makefile
125 +index c10bb98144b0..fb4ac87fc398 100644
126 +--- a/arch/arm64/Makefile
127 ++++ b/arch/arm64/Makefile
128 +@@ -10,7 +10,7 @@
129 + #
130 + # Copyright (C) 1995-2001 by Russell King
131 +
132 +-LDFLAGS_vmlinux :=-p --no-undefined -X
133 ++LDFLAGS_vmlinux :=--no-undefined -X
134 + CPPFLAGS_vmlinux.lds = -DTEXT_OFFSET=$(TEXT_OFFSET)
135 + OBJCOPYFLAGS :=-O binary -R .note -R .note.gnu.build-id -R .comment -S
136 + GZFLAGS :=-9
137 +diff --git a/arch/powerpc/kvm/trace.h b/arch/powerpc/kvm/trace.h
138 +index 2e0e67ef3544..e8cedf32345a 100644
139 +--- a/arch/powerpc/kvm/trace.h
140 ++++ b/arch/powerpc/kvm/trace.h
141 +@@ -5,8 +5,6 @@
142 +
143 + #undef TRACE_SYSTEM
144 + #define TRACE_SYSTEM kvm
145 +-#define TRACE_INCLUDE_PATH .
146 +-#define TRACE_INCLUDE_FILE trace
147 +
148 + /*
149 + * Tracepoint for guest mode entry.
150 +@@ -119,4 +117,10 @@ TRACE_EVENT(kvm_check_requests,
151 + #endif /* _TRACE_KVM_H */
152 +
153 + /* This part must be outside protection */
154 ++#undef TRACE_INCLUDE_PATH
155 ++#undef TRACE_INCLUDE_FILE
156 ++
157 ++#define TRACE_INCLUDE_PATH .
158 ++#define TRACE_INCLUDE_FILE trace
159 ++
160 + #include <trace/define_trace.h>
161 +diff --git a/arch/powerpc/kvm/trace_booke.h b/arch/powerpc/kvm/trace_booke.h
162 +index 7ec534d1db9f..7eadbf449a1f 100644
163 +--- a/arch/powerpc/kvm/trace_booke.h
164 ++++ b/arch/powerpc/kvm/trace_booke.h
165 +@@ -5,8 +5,6 @@
166 +
167 + #undef TRACE_SYSTEM
168 + #define TRACE_SYSTEM kvm_booke
169 +-#define TRACE_INCLUDE_PATH .
170 +-#define TRACE_INCLUDE_FILE trace_booke
171 +
172 + #define kvm_trace_symbol_exit \
173 + {0, "CRITICAL"}, \
174 +@@ -217,4 +215,11 @@ TRACE_EVENT(kvm_booke_queue_irqprio,
175 + #endif
176 +
177 + /* This part must be outside protection */
178 ++
179 ++#undef TRACE_INCLUDE_PATH
180 ++#undef TRACE_INCLUDE_FILE
181 ++
182 ++#define TRACE_INCLUDE_PATH .
183 ++#define TRACE_INCLUDE_FILE trace_booke
184 ++
185 + #include <trace/define_trace.h>
186 +diff --git a/arch/powerpc/kvm/trace_hv.h b/arch/powerpc/kvm/trace_hv.h
187 +index 33d9daff5783..d1bfe017d751 100644
188 +--- a/arch/powerpc/kvm/trace_hv.h
189 ++++ b/arch/powerpc/kvm/trace_hv.h
190 +@@ -8,8 +8,6 @@
191 +
192 + #undef TRACE_SYSTEM
193 + #define TRACE_SYSTEM kvm_hv
194 +-#define TRACE_INCLUDE_PATH .
195 +-#define TRACE_INCLUDE_FILE trace_hv
196 +
197 + #define kvm_trace_symbol_hcall \
198 + {H_REMOVE, "H_REMOVE"}, \
199 +@@ -474,4 +472,11 @@ TRACE_EVENT(kvmppc_run_vcpu_exit,
200 + #endif /* _TRACE_KVM_HV_H */
201 +
202 + /* This part must be outside protection */
203 ++
204 ++#undef TRACE_INCLUDE_PATH
205 ++#undef TRACE_INCLUDE_FILE
206 ++
207 ++#define TRACE_INCLUDE_PATH .
208 ++#define TRACE_INCLUDE_FILE trace_hv
209 ++
210 + #include <trace/define_trace.h>
211 +diff --git a/arch/powerpc/kvm/trace_pr.h b/arch/powerpc/kvm/trace_pr.h
212 +index 810507cb688a..1e40aa2aa5af 100644
213 +--- a/arch/powerpc/kvm/trace_pr.h
214 ++++ b/arch/powerpc/kvm/trace_pr.h
215 +@@ -7,8 +7,6 @@
216 +
217 + #undef TRACE_SYSTEM
218 + #define TRACE_SYSTEM kvm_pr
219 +-#define TRACE_INCLUDE_PATH .
220 +-#define TRACE_INCLUDE_FILE trace_pr
221 +
222 + TRACE_EVENT(kvm_book3s_reenter,
223 + TP_PROTO(int r, struct kvm_vcpu *vcpu),
224 +@@ -271,4 +269,11 @@ TRACE_EVENT(kvm_unmap_hva,
225 + #endif /* _TRACE_KVM_H */
226 +
227 + /* This part must be outside protection */
228 ++
229 ++#undef TRACE_INCLUDE_PATH
230 ++#undef TRACE_INCLUDE_FILE
231 ++
232 ++#define TRACE_INCLUDE_PATH .
233 ++#define TRACE_INCLUDE_FILE trace_pr
234 ++
235 + #include <trace/define_trace.h>
236 +diff --git a/arch/powerpc/mm/numa.c b/arch/powerpc/mm/numa.c
237 +index 3c4faa4c2742..bb3df222ae71 100644
238 +--- a/arch/powerpc/mm/numa.c
239 ++++ b/arch/powerpc/mm/numa.c
240 +@@ -1319,7 +1319,7 @@ static long vphn_get_associativity(unsigned long cpu,
241 +
242 + switch (rc) {
243 + case H_FUNCTION:
244 +- printk(KERN_INFO
245 ++ printk_once(KERN_INFO
246 + "VPHN is not supported. Disabling polling...\n");
247 + stop_topology_update();
248 + break;
249 +diff --git a/arch/s390/mm/pgtable.c b/arch/s390/mm/pgtable.c
250 +index 05ae254f84cf..1866b6a5171a 100644
251 +--- a/arch/s390/mm/pgtable.c
252 ++++ b/arch/s390/mm/pgtable.c
253 +@@ -637,6 +637,8 @@ void gmap_discard(struct gmap *gmap, unsigned long from, unsigned long to)
254 + vmaddr |= gaddr & ~PMD_MASK;
255 + /* Find vma in the parent mm */
256 + vma = find_vma(gmap->mm, vmaddr);
257 ++ if (!vma)
258 ++ continue;
259 + size = min(to - gaddr, PMD_SIZE - (gaddr & ~PMD_MASK));
260 + zap_page_range(vma, vmaddr, size, NULL);
261 + }
262 +diff --git a/arch/x86/entry/entry_64.S b/arch/x86/entry/entry_64.S
263 +index 8be48b1d7596..375ed605c83d 100644
264 +--- a/arch/x86/entry/entry_64.S
265 ++++ b/arch/x86/entry/entry_64.S
266 +@@ -856,7 +856,7 @@ ENTRY(\sym)
267 +
268 + call \do_sym
269 +
270 +- jmp error_exit /* %ebx: no swapgs flag */
271 ++ jmp error_exit
272 + .endif
273 + END(\sym)
274 + .endm
275 +@@ -1118,7 +1118,6 @@ END(paranoid_exit)
276 +
277 + /*
278 + * Save all registers in pt_regs, and switch gs if needed.
279 +- * Return: EBX=0: came from user mode; EBX=1: otherwise
280 + */
281 + ENTRY(error_entry)
282 + cld
283 +@@ -1131,7 +1130,6 @@ ENTRY(error_entry)
284 + * the kernel CR3 here.
285 + */
286 + SWITCH_KERNEL_CR3
287 +- xorl %ebx, %ebx
288 + testb $3, CS+8(%rsp)
289 + jz .Lerror_kernelspace
290 +
291 +@@ -1165,7 +1163,6 @@ ENTRY(error_entry)
292 + * for these here too.
293 + */
294 + .Lerror_kernelspace:
295 +- incl %ebx
296 + leaq native_irq_return_iret(%rip), %rcx
297 + cmpq %rcx, RIP+8(%rsp)
298 + je .Lerror_bad_iret
299 +@@ -1196,28 +1193,19 @@ ENTRY(error_entry)
300 +
301 + /*
302 + * Pretend that the exception came from user mode: set up pt_regs
303 +- * as if we faulted immediately after IRET and clear EBX so that
304 +- * error_exit knows that we will be returning to user mode.
305 ++ * as if we faulted immediately after IRET.
306 + */
307 + mov %rsp, %rdi
308 + call fixup_bad_iret
309 + mov %rax, %rsp
310 +- decl %ebx
311 + jmp .Lerror_entry_from_usermode_after_swapgs
312 + END(error_entry)
313 +
314 +-
315 +-/*
316 +- * On entry, EBS is a "return to kernel mode" flag:
317 +- * 1: already in kernel mode, don't need SWAPGS
318 +- * 0: user gsbase is loaded, we need SWAPGS and standard preparation for return to usermode
319 +- */
320 + ENTRY(error_exit)
321 +- movl %ebx, %eax
322 + DISABLE_INTERRUPTS(CLBR_NONE)
323 + TRACE_IRQS_OFF
324 +- testl %eax, %eax
325 +- jnz retint_kernel
326 ++ testb $3, CS(%rsp)
327 ++ jz retint_kernel
328 + jmp retint_user
329 + END(error_exit)
330 +
331 +diff --git a/drivers/cpufreq/imx6q-cpufreq.c b/drivers/cpufreq/imx6q-cpufreq.c
332 +index ef1fa8145419..fa86946d12aa 100644
333 +--- a/drivers/cpufreq/imx6q-cpufreq.c
334 ++++ b/drivers/cpufreq/imx6q-cpufreq.c
335 +@@ -130,8 +130,13 @@ static int imx6q_set_target(struct cpufreq_policy *policy, unsigned int index)
336 + /* Ensure the arm clock divider is what we expect */
337 + ret = clk_set_rate(arm_clk, new_freq * 1000);
338 + if (ret) {
339 ++ int ret1;
340 ++
341 + dev_err(cpu_dev, "failed to set clock rate: %d\n", ret);
342 +- regulator_set_voltage_tol(arm_reg, volt_old, 0);
343 ++ ret1 = regulator_set_voltage_tol(arm_reg, volt_old, 0);
344 ++ if (ret1)
345 ++ dev_warn(cpu_dev,
346 ++ "failed to restore vddarm voltage: %d\n", ret1);
347 + return ret;
348 + }
349 +
350 +diff --git a/drivers/gpu/drm/ast/ast_drv.c b/drivers/gpu/drm/ast/ast_drv.c
351 +index 9a32d9dfdd26..011700262824 100644
352 +--- a/drivers/gpu/drm/ast/ast_drv.c
353 ++++ b/drivers/gpu/drm/ast/ast_drv.c
354 +@@ -60,8 +60,29 @@ static const struct pci_device_id pciidlist[] = {
355 +
356 + MODULE_DEVICE_TABLE(pci, pciidlist);
357 +
358 ++static void ast_kick_out_firmware_fb(struct pci_dev *pdev)
359 ++{
360 ++ struct apertures_struct *ap;
361 ++ bool primary = false;
362 ++
363 ++ ap = alloc_apertures(1);
364 ++ if (!ap)
365 ++ return;
366 ++
367 ++ ap->ranges[0].base = pci_resource_start(pdev, 0);
368 ++ ap->ranges[0].size = pci_resource_len(pdev, 0);
369 ++
370 ++#ifdef CONFIG_X86
371 ++ primary = pdev->resource[PCI_ROM_RESOURCE].flags & IORESOURCE_ROM_SHADOW;
372 ++#endif
373 ++ remove_conflicting_framebuffers(ap, "astdrmfb", primary);
374 ++ kfree(ap);
375 ++}
376 ++
377 + static int ast_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
378 + {
379 ++ ast_kick_out_firmware_fb(pdev);
380 ++
381 + return drm_get_pci_dev(pdev, ent, &driver);
382 + }
383 +
384 +diff --git a/drivers/gpu/drm/ast/ast_mode.c b/drivers/gpu/drm/ast/ast_mode.c
385 +index 69d19f3304a5..21085f669e21 100644
386 +--- a/drivers/gpu/drm/ast/ast_mode.c
387 ++++ b/drivers/gpu/drm/ast/ast_mode.c
388 +@@ -552,6 +552,7 @@ static int ast_crtc_do_set_base(struct drm_crtc *crtc,
389 + }
390 + ast_bo_unreserve(bo);
391 +
392 ++ ast_set_offset_reg(crtc);
393 + ast_set_start_address_crt1(crtc, (u32)gpu_addr);
394 +
395 + return 0;
396 +@@ -1249,7 +1250,7 @@ static int ast_cursor_move(struct drm_crtc *crtc,
397 + ast_set_index_reg(ast, AST_IO_CRTC_PORT, 0xc7, ((y >> 8) & 0x07));
398 +
399 + /* dummy write to fire HWC */
400 +- ast_set_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xCB, 0xFF, 0x00);
401 ++ ast_show_cursor(crtc);
402 +
403 + return 0;
404 + }
405 +diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
406 +index 3258baf3282e..2e52015634f9 100644
407 +--- a/drivers/input/joystick/xpad.c
408 ++++ b/drivers/input/joystick/xpad.c
409 +@@ -76,18 +76,23 @@
410 + */
411 +
412 + #include <linux/kernel.h>
413 ++#include <linux/input.h>
414 ++#include <linux/rcupdate.h>
415 + #include <linux/slab.h>
416 + #include <linux/stat.h>
417 + #include <linux/module.h>
418 + #include <linux/usb/input.h>
419 ++#include <linux/usb/quirks.h>
420 +
421 + #define DRIVER_AUTHOR "Marko Friedemann <mfr@××××××××××××.de>"
422 + #define DRIVER_DESC "X-Box pad driver"
423 +
424 +-#define XPAD_PKT_LEN 32
425 ++#define XPAD_PKT_LEN 64
426 +
427 +-/* xbox d-pads should map to buttons, as is required for DDR pads
428 +- but we map them to axes when possible to simplify things */
429 ++/*
430 ++ * xbox d-pads should map to buttons, as is required for DDR pads
431 ++ * but we map them to axes when possible to simplify things
432 ++ */
433 + #define MAP_DPAD_TO_BUTTONS (1 << 0)
434 + #define MAP_TRIGGERS_TO_BUTTONS (1 << 1)
435 + #define MAP_STICKS_TO_NULL (1 << 2)
436 +@@ -112,6 +117,10 @@ static bool sticks_to_null;
437 + module_param(sticks_to_null, bool, S_IRUGO);
438 + MODULE_PARM_DESC(sticks_to_null, "Do not map sticks at all for unknown pads");
439 +
440 ++static bool auto_poweroff = true;
441 ++module_param(auto_poweroff, bool, S_IWUSR | S_IRUGO);
442 ++MODULE_PARM_DESC(auto_poweroff, "Power off wireless controllers on suspend");
443 ++
444 + static const struct xpad_device {
445 + u16 idVendor;
446 + u16 idProduct;
447 +@@ -119,43 +128,77 @@ static const struct xpad_device {
448 + u8 mapping;
449 + u8 xtype;
450 + } xpad_device[] = {
451 ++ { 0x0079, 0x18d4, "GPD Win 2 X-Box Controller", 0, XTYPE_XBOX360 },
452 ++ { 0x044f, 0x0f00, "Thrustmaster Wheel", 0, XTYPE_XBOX },
453 ++ { 0x044f, 0x0f03, "Thrustmaster Wheel", 0, XTYPE_XBOX },
454 ++ { 0x044f, 0x0f07, "Thrustmaster, Inc. Controller", 0, XTYPE_XBOX },
455 ++ { 0x044f, 0x0f10, "Thrustmaster Modena GT Wheel", 0, XTYPE_XBOX },
456 ++ { 0x044f, 0xb326, "Thrustmaster Gamepad GP XID", 0, XTYPE_XBOX360 },
457 + { 0x045e, 0x0202, "Microsoft X-Box pad v1 (US)", 0, XTYPE_XBOX },
458 + { 0x045e, 0x0285, "Microsoft X-Box pad (Japan)", 0, XTYPE_XBOX },
459 + { 0x045e, 0x0287, "Microsoft Xbox Controller S", 0, XTYPE_XBOX },
460 ++ { 0x045e, 0x0288, "Microsoft Xbox Controller S v2", 0, XTYPE_XBOX },
461 + { 0x045e, 0x0289, "Microsoft X-Box pad v2 (US)", 0, XTYPE_XBOX },
462 + { 0x045e, 0x028e, "Microsoft X-Box 360 pad", 0, XTYPE_XBOX360 },
463 +- { 0x045e, 0x02d1, "Microsoft X-Box One pad", 0, XTYPE_XBOXONE },
464 +- { 0x045e, 0x02dd, "Microsoft X-Box One pad (Covert Forces)", 0, XTYPE_XBOXONE },
465 ++ { 0x045e, 0x028f, "Microsoft X-Box 360 pad v2", 0, XTYPE_XBOX360 },
466 + { 0x045e, 0x0291, "Xbox 360 Wireless Receiver (XBOX)", MAP_DPAD_TO_BUTTONS, XTYPE_XBOX360W },
467 ++ { 0x045e, 0x02d1, "Microsoft X-Box One pad", 0, XTYPE_XBOXONE },
468 ++ { 0x045e, 0x02dd, "Microsoft X-Box One pad (Firmware 2015)", 0, XTYPE_XBOXONE },
469 ++ { 0x045e, 0x02e3, "Microsoft X-Box One Elite pad", 0, XTYPE_XBOXONE },
470 ++ { 0x045e, 0x02ea, "Microsoft X-Box One S pad", 0, XTYPE_XBOXONE },
471 + { 0x045e, 0x0719, "Xbox 360 Wireless Receiver", MAP_DPAD_TO_BUTTONS, XTYPE_XBOX360W },
472 +- { 0x044f, 0x0f07, "Thrustmaster, Inc. Controller", 0, XTYPE_XBOX },
473 +- { 0x044f, 0xb326, "Thrustmaster Gamepad GP XID", 0, XTYPE_XBOX360 },
474 + { 0x046d, 0xc21d, "Logitech Gamepad F310", 0, XTYPE_XBOX360 },
475 + { 0x046d, 0xc21e, "Logitech Gamepad F510", 0, XTYPE_XBOX360 },
476 + { 0x046d, 0xc21f, "Logitech Gamepad F710", 0, XTYPE_XBOX360 },
477 + { 0x046d, 0xc242, "Logitech Chillstream Controller", 0, XTYPE_XBOX360 },
478 + { 0x046d, 0xca84, "Logitech Xbox Cordless Controller", 0, XTYPE_XBOX },
479 + { 0x046d, 0xca88, "Logitech Compact Controller for Xbox", 0, XTYPE_XBOX },
480 ++ { 0x046d, 0xca8a, "Logitech Precision Vibration Feedback Wheel", 0, XTYPE_XBOX },
481 ++ { 0x046d, 0xcaa3, "Logitech DriveFx Racing Wheel", 0, XTYPE_XBOX360 },
482 ++ { 0x056e, 0x2004, "Elecom JC-U3613M", 0, XTYPE_XBOX360 },
483 + { 0x05fd, 0x1007, "Mad Catz Controller (unverified)", 0, XTYPE_XBOX },
484 + { 0x05fd, 0x107a, "InterAct 'PowerPad Pro' X-Box pad (Germany)", 0, XTYPE_XBOX },
485 ++ { 0x05fe, 0x3030, "Chic Controller", 0, XTYPE_XBOX },
486 ++ { 0x05fe, 0x3031, "Chic Controller", 0, XTYPE_XBOX },
487 ++ { 0x062a, 0x0020, "Logic3 Xbox GamePad", 0, XTYPE_XBOX },
488 ++ { 0x062a, 0x0033, "Competition Pro Steering Wheel", 0, XTYPE_XBOX },
489 ++ { 0x06a3, 0x0200, "Saitek Racing Wheel", 0, XTYPE_XBOX },
490 ++ { 0x06a3, 0x0201, "Saitek Adrenalin", 0, XTYPE_XBOX },
491 ++ { 0x06a3, 0xf51a, "Saitek P3600", 0, XTYPE_XBOX360 },
492 ++ { 0x0738, 0x4506, "Mad Catz 4506 Wireless Controller", 0, XTYPE_XBOX },
493 + { 0x0738, 0x4516, "Mad Catz Control Pad", 0, XTYPE_XBOX },
494 ++ { 0x0738, 0x4520, "Mad Catz Control Pad Pro", 0, XTYPE_XBOX },
495 + { 0x0738, 0x4522, "Mad Catz LumiCON", 0, XTYPE_XBOX },
496 + { 0x0738, 0x4526, "Mad Catz Control Pad Pro", 0, XTYPE_XBOX },
497 ++ { 0x0738, 0x4530, "Mad Catz Universal MC2 Racing Wheel and Pedals", 0, XTYPE_XBOX },
498 + { 0x0738, 0x4536, "Mad Catz MicroCON", 0, XTYPE_XBOX },
499 + { 0x0738, 0x4540, "Mad Catz Beat Pad", MAP_DPAD_TO_BUTTONS, XTYPE_XBOX },
500 + { 0x0738, 0x4556, "Mad Catz Lynx Wireless Controller", 0, XTYPE_XBOX },
501 ++ { 0x0738, 0x4586, "Mad Catz MicroCon Wireless Controller", 0, XTYPE_XBOX },
502 ++ { 0x0738, 0x4588, "Mad Catz Blaster", 0, XTYPE_XBOX },
503 ++ { 0x0738, 0x45ff, "Mad Catz Beat Pad (w/ Handle)", MAP_DPAD_TO_BUTTONS, XTYPE_XBOX },
504 + { 0x0738, 0x4716, "Mad Catz Wired Xbox 360 Controller", 0, XTYPE_XBOX360 },
505 + { 0x0738, 0x4718, "Mad Catz Street Fighter IV FightStick SE", 0, XTYPE_XBOX360 },
506 + { 0x0738, 0x4726, "Mad Catz Xbox 360 Controller", 0, XTYPE_XBOX360 },
507 + { 0x0738, 0x4728, "Mad Catz Street Fighter IV FightPad", MAP_TRIGGERS_TO_BUTTONS, XTYPE_XBOX360 },
508 ++ { 0x0738, 0x4736, "Mad Catz MicroCon Gamepad", 0, XTYPE_XBOX360 },
509 + { 0x0738, 0x4738, "Mad Catz Wired Xbox 360 Controller (SFIV)", MAP_TRIGGERS_TO_BUTTONS, XTYPE_XBOX360 },
510 + { 0x0738, 0x4740, "Mad Catz Beat Pad", 0, XTYPE_XBOX360 },
511 ++ { 0x0738, 0x4743, "Mad Catz Beat Pad Pro", MAP_DPAD_TO_BUTTONS, XTYPE_XBOX },
512 ++ { 0x0738, 0x4758, "Mad Catz Arcade Game Stick", MAP_TRIGGERS_TO_BUTTONS, XTYPE_XBOX360 },
513 ++ { 0x0738, 0x4a01, "Mad Catz FightStick TE 2", MAP_TRIGGERS_TO_BUTTONS, XTYPE_XBOXONE },
514 + { 0x0738, 0x6040, "Mad Catz Beat Pad Pro", MAP_DPAD_TO_BUTTONS, XTYPE_XBOX },
515 ++ { 0x0738, 0x9871, "Mad Catz Portable Drum", 0, XTYPE_XBOX360 },
516 + { 0x0738, 0xb726, "Mad Catz Xbox controller - MW2", 0, XTYPE_XBOX360 },
517 ++ { 0x0738, 0xb738, "Mad Catz MVC2TE Stick 2", MAP_TRIGGERS_TO_BUTTONS, XTYPE_XBOX360 },
518 + { 0x0738, 0xbeef, "Mad Catz JOYTECH NEO SE Advanced GamePad", XTYPE_XBOX360 },
519 + { 0x0738, 0xcb02, "Saitek Cyborg Rumble Pad - PC/Xbox 360", 0, XTYPE_XBOX360 },
520 + { 0x0738, 0xcb03, "Saitek P3200 Rumble Pad - PC/Xbox 360", 0, XTYPE_XBOX360 },
521 ++ { 0x0738, 0xcb29, "Saitek Aviator Stick AV8R02", 0, XTYPE_XBOX360 },
522 + { 0x0738, 0xf738, "Super SFIV FightStick TE S", 0, XTYPE_XBOX360 },
523 ++ { 0x07ff, 0xffff, "Mad Catz GamePad", 0, XTYPE_XBOX360 },
524 ++ { 0x0c12, 0x0005, "Intec wireless", 0, XTYPE_XBOX },
525 ++ { 0x0c12, 0x8801, "Nyko Xbox Controller", 0, XTYPE_XBOX },
526 + { 0x0c12, 0x8802, "Zeroplus Xbox Controller", 0, XTYPE_XBOX },
527 + { 0x0c12, 0x8809, "RedOctane Xbox Dance Pad", DANCEPAD_MAP_CONFIG, XTYPE_XBOX },
528 + { 0x0c12, 0x880a, "Pelican Eclipse PL-2023", 0, XTYPE_XBOX },
529 +@@ -163,32 +206,66 @@ static const struct xpad_device {
530 + { 0x0c12, 0x9902, "HAMA VibraX - *FAULTY HARDWARE*", 0, XTYPE_XBOX },
531 + { 0x0d2f, 0x0002, "Andamiro Pump It Up pad", MAP_DPAD_TO_BUTTONS, XTYPE_XBOX },
532 + { 0x0e4c, 0x1097, "Radica Gamester Controller", 0, XTYPE_XBOX },
533 ++ { 0x0e4c, 0x1103, "Radica Gamester Reflex", MAP_TRIGGERS_TO_BUTTONS, XTYPE_XBOX },
534 + { 0x0e4c, 0x2390, "Radica Games Jtech Controller", 0, XTYPE_XBOX },
535 ++ { 0x0e4c, 0x3510, "Radica Gamester", 0, XTYPE_XBOX },
536 + { 0x0e6f, 0x0003, "Logic3 Freebird wireless Controller", 0, XTYPE_XBOX },
537 + { 0x0e6f, 0x0005, "Eclipse wireless Controller", 0, XTYPE_XBOX },
538 + { 0x0e6f, 0x0006, "Edge wireless Controller", 0, XTYPE_XBOX },
539 ++ { 0x0e6f, 0x0008, "After Glow Pro Controller", 0, XTYPE_XBOX },
540 + { 0x0e6f, 0x0105, "HSM3 Xbox360 dancepad", MAP_DPAD_TO_BUTTONS, XTYPE_XBOX360 },
541 + { 0x0e6f, 0x0113, "Afterglow AX.1 Gamepad for Xbox 360", 0, XTYPE_XBOX360 },
542 ++ { 0x0e6f, 0x011f, "Rock Candy Gamepad Wired Controller", 0, XTYPE_XBOX360 },
543 ++ { 0x0e6f, 0x0131, "PDP EA Sports Controller", 0, XTYPE_XBOX360 },
544 ++ { 0x0e6f, 0x0133, "Xbox 360 Wired Controller", 0, XTYPE_XBOX360 },
545 ++ { 0x0e6f, 0x0139, "Afterglow Prismatic Wired Controller", 0, XTYPE_XBOXONE },
546 ++ { 0x0e6f, 0x013a, "PDP Xbox One Controller", 0, XTYPE_XBOXONE },
547 ++ { 0x0e6f, 0x0146, "Rock Candy Wired Controller for Xbox One", 0, XTYPE_XBOXONE },
548 ++ { 0x0e6f, 0x0147, "PDP Marvel Xbox One Controller", 0, XTYPE_XBOXONE },
549 ++ { 0x0e6f, 0x015c, "PDP Xbox One Arcade Stick", MAP_TRIGGERS_TO_BUTTONS, XTYPE_XBOXONE },
550 ++ { 0x0e6f, 0x0161, "PDP Xbox One Controller", 0, XTYPE_XBOXONE },
551 ++ { 0x0e6f, 0x0162, "PDP Xbox One Controller", 0, XTYPE_XBOXONE },
552 ++ { 0x0e6f, 0x0163, "PDP Xbox One Controller", 0, XTYPE_XBOXONE },
553 ++ { 0x0e6f, 0x0164, "PDP Battlefield One", 0, XTYPE_XBOXONE },
554 ++ { 0x0e6f, 0x0165, "PDP Titanfall 2", 0, XTYPE_XBOXONE },
555 + { 0x0e6f, 0x0201, "Pelican PL-3601 'TSZ' Wired Xbox 360 Controller", 0, XTYPE_XBOX360 },
556 + { 0x0e6f, 0x0213, "Afterglow Gamepad for Xbox 360", 0, XTYPE_XBOX360 },
557 + { 0x0e6f, 0x021f, "Rock Candy Gamepad for Xbox 360", 0, XTYPE_XBOX360 },
558 ++ { 0x0e6f, 0x0246, "Rock Candy Gamepad for Xbox One 2015", 0, XTYPE_XBOXONE },
559 ++ { 0x0e6f, 0x02ab, "PDP Controller for Xbox One", 0, XTYPE_XBOXONE },
560 ++ { 0x0e6f, 0x02a4, "PDP Wired Controller for Xbox One - Stealth Series", 0, XTYPE_XBOXONE },
561 ++ { 0x0e6f, 0x02a6, "PDP Wired Controller for Xbox One - Camo Series", 0, XTYPE_XBOXONE },
562 + { 0x0e6f, 0x0301, "Logic3 Controller", 0, XTYPE_XBOX360 },
563 ++ { 0x0e6f, 0x0346, "Rock Candy Gamepad for Xbox One 2016", 0, XTYPE_XBOXONE },
564 + { 0x0e6f, 0x0401, "Logic3 Controller", 0, XTYPE_XBOX360 },
565 ++ { 0x0e6f, 0x0413, "Afterglow AX.1 Gamepad for Xbox 360", 0, XTYPE_XBOX360 },
566 ++ { 0x0e6f, 0x0501, "PDP Xbox 360 Controller", 0, XTYPE_XBOX360 },
567 ++ { 0x0e6f, 0xf900, "PDP Afterglow AX.1", 0, XTYPE_XBOX360 },
568 + { 0x0e8f, 0x0201, "SmartJoy Frag Xpad/PS2 adaptor", 0, XTYPE_XBOX },
569 + { 0x0e8f, 0x3008, "Generic xbox control (dealextreme)", 0, XTYPE_XBOX },
570 + { 0x0f0d, 0x000a, "Hori Co. DOA4 FightStick", 0, XTYPE_XBOX360 },
571 ++ { 0x0f0d, 0x000c, "Hori PadEX Turbo", 0, XTYPE_XBOX360 },
572 + { 0x0f0d, 0x000d, "Hori Fighting Stick EX2", MAP_TRIGGERS_TO_BUTTONS, XTYPE_XBOX360 },
573 + { 0x0f0d, 0x0016, "Hori Real Arcade Pro.EX", MAP_TRIGGERS_TO_BUTTONS, XTYPE_XBOX360 },
574 ++ { 0x0f0d, 0x001b, "Hori Real Arcade Pro VX", MAP_TRIGGERS_TO_BUTTONS, XTYPE_XBOX360 },
575 ++ { 0x0f0d, 0x0063, "Hori Real Arcade Pro Hayabusa (USA) Xbox One", MAP_TRIGGERS_TO_BUTTONS, XTYPE_XBOXONE },
576 ++ { 0x0f0d, 0x0067, "HORIPAD ONE", 0, XTYPE_XBOXONE },
577 ++ { 0x0f0d, 0x0078, "Hori Real Arcade Pro V Kai Xbox One", MAP_TRIGGERS_TO_BUTTONS, XTYPE_XBOXONE },
578 ++ { 0x0f30, 0x010b, "Philips Recoil", 0, XTYPE_XBOX },
579 + { 0x0f30, 0x0202, "Joytech Advanced Controller", 0, XTYPE_XBOX },
580 + { 0x0f30, 0x8888, "BigBen XBMiniPad Controller", 0, XTYPE_XBOX },
581 + { 0x102c, 0xff0c, "Joytech Wireless Advanced Controller", 0, XTYPE_XBOX },
582 ++ { 0x11c9, 0x55f0, "Nacon GC-100XF", 0, XTYPE_XBOX360 },
583 + { 0x12ab, 0x0004, "Honey Bee Xbox360 dancepad", MAP_DPAD_TO_BUTTONS, XTYPE_XBOX360 },
584 + { 0x12ab, 0x0301, "PDP AFTERGLOW AX.1", 0, XTYPE_XBOX360 },
585 ++ { 0x12ab, 0x0303, "Mortal Kombat Klassic FightStick", MAP_TRIGGERS_TO_BUTTONS, XTYPE_XBOX360 },
586 + { 0x12ab, 0x8809, "Xbox DDR dancepad", MAP_DPAD_TO_BUTTONS, XTYPE_XBOX },
587 + { 0x1430, 0x4748, "RedOctane Guitar Hero X-plorer", 0, XTYPE_XBOX360 },
588 + { 0x1430, 0x8888, "TX6500+ Dance Pad (first generation)", MAP_DPAD_TO_BUTTONS, XTYPE_XBOX },
589 ++ { 0x1430, 0xf801, "RedOctane Controller", 0, XTYPE_XBOX360 },
590 + { 0x146b, 0x0601, "BigBen Interactive XBOX 360 Controller", 0, XTYPE_XBOX360 },
591 + { 0x1532, 0x0037, "Razer Sabertooth", 0, XTYPE_XBOX360 },
592 ++ { 0x1532, 0x0a00, "Razer Atrox Arcade Stick", MAP_TRIGGERS_TO_BUTTONS, XTYPE_XBOXONE },
593 + { 0x1532, 0x0a03, "Razer Wildcat", 0, XTYPE_XBOXONE },
594 + { 0x15e4, 0x3f00, "Power A Mini Pro Elite", 0, XTYPE_XBOX360 },
595 + { 0x15e4, 0x3f0a, "Xbox Airflo wired controller", 0, XTYPE_XBOX360 },
596 +@@ -196,24 +273,67 @@ static const struct xpad_device {
597 + { 0x162e, 0xbeef, "Joytech Neo-Se Take2", 0, XTYPE_XBOX360 },
598 + { 0x1689, 0xfd00, "Razer Onza Tournament Edition", 0, XTYPE_XBOX360 },
599 + { 0x1689, 0xfd01, "Razer Onza Classic Edition", 0, XTYPE_XBOX360 },
600 +- { 0x24c6, 0x5d04, "Razer Sabertooth", 0, XTYPE_XBOX360 },
601 ++ { 0x1689, 0xfe00, "Razer Sabertooth", 0, XTYPE_XBOX360 },
602 + { 0x1bad, 0x0002, "Harmonix Rock Band Guitar", 0, XTYPE_XBOX360 },
603 + { 0x1bad, 0x0003, "Harmonix Rock Band Drumkit", MAP_DPAD_TO_BUTTONS, XTYPE_XBOX360 },
604 ++ { 0x1bad, 0x0130, "Ion Drum Rocker", MAP_DPAD_TO_BUTTONS, XTYPE_XBOX360 },
605 + { 0x1bad, 0xf016, "Mad Catz Xbox 360 Controller", 0, XTYPE_XBOX360 },
606 ++ { 0x1bad, 0xf018, "Mad Catz Street Fighter IV SE Fighting Stick", MAP_TRIGGERS_TO_BUTTONS, XTYPE_XBOX360 },
607 ++ { 0x1bad, 0xf019, "Mad Catz Brawlstick for Xbox 360", MAP_TRIGGERS_TO_BUTTONS, XTYPE_XBOX360 },
608 ++ { 0x1bad, 0xf021, "Mad Cats Ghost Recon FS GamePad", 0, XTYPE_XBOX360 },
609 + { 0x1bad, 0xf023, "MLG Pro Circuit Controller (Xbox)", 0, XTYPE_XBOX360 },
610 ++ { 0x1bad, 0xf025, "Mad Catz Call Of Duty", 0, XTYPE_XBOX360 },
611 ++ { 0x1bad, 0xf027, "Mad Catz FPS Pro", 0, XTYPE_XBOX360 },
612 + { 0x1bad, 0xf028, "Street Fighter IV FightPad", 0, XTYPE_XBOX360 },
613 ++ { 0x1bad, 0xf02e, "Mad Catz Fightpad", MAP_TRIGGERS_TO_BUTTONS, XTYPE_XBOX360 },
614 ++ { 0x1bad, 0xf030, "Mad Catz Xbox 360 MC2 MicroCon Racing Wheel", 0, XTYPE_XBOX360 },
615 ++ { 0x1bad, 0xf036, "Mad Catz MicroCon GamePad Pro", 0, XTYPE_XBOX360 },
616 + { 0x1bad, 0xf038, "Street Fighter IV FightStick TE", 0, XTYPE_XBOX360 },
617 ++ { 0x1bad, 0xf039, "Mad Catz MvC2 TE", MAP_TRIGGERS_TO_BUTTONS, XTYPE_XBOX360 },
618 ++ { 0x1bad, 0xf03a, "Mad Catz SFxT Fightstick Pro", MAP_TRIGGERS_TO_BUTTONS, XTYPE_XBOX360 },
619 ++ { 0x1bad, 0xf03d, "Street Fighter IV Arcade Stick TE - Chun Li", MAP_TRIGGERS_TO_BUTTONS, XTYPE_XBOX360 },
620 ++ { 0x1bad, 0xf03e, "Mad Catz MLG FightStick TE", MAP_TRIGGERS_TO_BUTTONS, XTYPE_XBOX360 },
621 ++ { 0x1bad, 0xf03f, "Mad Catz FightStick SoulCaliber", MAP_TRIGGERS_TO_BUTTONS, XTYPE_XBOX360 },
622 ++ { 0x1bad, 0xf042, "Mad Catz FightStick TES+", MAP_TRIGGERS_TO_BUTTONS, XTYPE_XBOX360 },
623 ++ { 0x1bad, 0xf080, "Mad Catz FightStick TE2", MAP_TRIGGERS_TO_BUTTONS, XTYPE_XBOX360 },
624 ++ { 0x1bad, 0xf501, "HoriPad EX2 Turbo", 0, XTYPE_XBOX360 },
625 ++ { 0x1bad, 0xf502, "Hori Real Arcade Pro.VX SA", MAP_TRIGGERS_TO_BUTTONS, XTYPE_XBOX360 },
626 ++ { 0x1bad, 0xf503, "Hori Fighting Stick VX", MAP_TRIGGERS_TO_BUTTONS, XTYPE_XBOX360 },
627 ++ { 0x1bad, 0xf504, "Hori Real Arcade Pro. EX", MAP_TRIGGERS_TO_BUTTONS, XTYPE_XBOX360 },
628 ++ { 0x1bad, 0xf505, "Hori Fighting Stick EX2B", MAP_TRIGGERS_TO_BUTTONS, XTYPE_XBOX360 },
629 ++ { 0x1bad, 0xf506, "Hori Real Arcade Pro.EX Premium VLX", 0, XTYPE_XBOX360 },
630 + { 0x1bad, 0xf900, "Harmonix Xbox 360 Controller", 0, XTYPE_XBOX360 },
631 + { 0x1bad, 0xf901, "Gamestop Xbox 360 Controller", 0, XTYPE_XBOX360 },
632 + { 0x1bad, 0xf903, "Tron Xbox 360 controller", 0, XTYPE_XBOX360 },
633 ++ { 0x1bad, 0xf904, "PDP Versus Fighting Pad", 0, XTYPE_XBOX360 },
634 ++ { 0x1bad, 0xf906, "MortalKombat FightStick", MAP_TRIGGERS_TO_BUTTONS, XTYPE_XBOX360 },
635 ++ { 0x1bad, 0xfa01, "MadCatz GamePad", 0, XTYPE_XBOX360 },
636 ++ { 0x1bad, 0xfd00, "Razer Onza TE", 0, XTYPE_XBOX360 },
637 ++ { 0x1bad, 0xfd01, "Razer Onza", 0, XTYPE_XBOX360 },
638 + { 0x24c6, 0x5000, "Razer Atrox Arcade Stick", MAP_TRIGGERS_TO_BUTTONS, XTYPE_XBOX360 },
639 + { 0x24c6, 0x5300, "PowerA MINI PROEX Controller", 0, XTYPE_XBOX360 },
640 + { 0x24c6, 0x5303, "Xbox Airflo wired controller", 0, XTYPE_XBOX360 },
641 ++ { 0x24c6, 0x530a, "Xbox 360 Pro EX Controller", 0, XTYPE_XBOX360 },
642 ++ { 0x24c6, 0x531a, "PowerA Pro Ex", 0, XTYPE_XBOX360 },
643 ++ { 0x24c6, 0x5397, "FUS1ON Tournament Controller", 0, XTYPE_XBOX360 },
644 ++ { 0x24c6, 0x541a, "PowerA Xbox One Mini Wired Controller", 0, XTYPE_XBOXONE },
645 ++ { 0x24c6, 0x542a, "Xbox ONE spectra", 0, XTYPE_XBOXONE },
646 ++ { 0x24c6, 0x543a, "PowerA Xbox One wired controller", 0, XTYPE_XBOXONE },
647 + { 0x24c6, 0x5500, "Hori XBOX 360 EX 2 with Turbo", 0, XTYPE_XBOX360 },
648 + { 0x24c6, 0x5501, "Hori Real Arcade Pro VX-SA", 0, XTYPE_XBOX360 },
649 ++ { 0x24c6, 0x5502, "Hori Fighting Stick VX Alt", MAP_TRIGGERS_TO_BUTTONS, XTYPE_XBOX360 },
650 ++ { 0x24c6, 0x5503, "Hori Fighting Edge", MAP_TRIGGERS_TO_BUTTONS, XTYPE_XBOX360 },
651 + { 0x24c6, 0x5506, "Hori SOULCALIBUR V Stick", 0, XTYPE_XBOX360 },
652 ++ { 0x24c6, 0x550d, "Hori GEM Xbox controller", 0, XTYPE_XBOX360 },
653 ++ { 0x24c6, 0x550e, "Hori Real Arcade Pro V Kai 360", MAP_TRIGGERS_TO_BUTTONS, XTYPE_XBOX360 },
654 ++ { 0x24c6, 0x551a, "PowerA FUSION Pro Controller", 0, XTYPE_XBOXONE },
655 ++ { 0x24c6, 0x561a, "PowerA FUSION Controller", 0, XTYPE_XBOXONE },
656 ++ { 0x24c6, 0x5b00, "ThrustMaster Ferrari 458 Racing Wheel", 0, XTYPE_XBOX360 },
657 + { 0x24c6, 0x5b02, "Thrustmaster, Inc. GPX Controller", 0, XTYPE_XBOX360 },
658 + { 0x24c6, 0x5b03, "Thrustmaster Ferrari 458 Racing Wheel", 0, XTYPE_XBOX360 },
659 ++ { 0x24c6, 0x5d04, "Razer Sabertooth", 0, XTYPE_XBOX360 },
660 ++ { 0x24c6, 0xfafe, "Rock Candy Gamepad for Xbox 360", 0, XTYPE_XBOX360 },
661 ++ { 0x3767, 0x0101, "Fanatec Speedster 3 Forceshock Wheel", 0, XTYPE_XBOX },
662 + { 0xffff, 0xffff, "Chinese-made Xbox Controller", 0, XTYPE_XBOX },
663 + { 0x0000, 0x0000, "Generic X-Box pad", 0, XTYPE_UNKNOWN }
664 + };
665 +@@ -274,15 +394,15 @@ static const signed short xpad_abs_triggers[] = {
666 + * match against vendor id as well. Wired Xbox 360 devices have protocol 1,
667 + * wireless controllers have protocol 129.
668 + */
669 +-#define XPAD_XBOX360_VENDOR_PROTOCOL(vend,pr) \
670 ++#define XPAD_XBOX360_VENDOR_PROTOCOL(vend, pr) \
671 + .match_flags = USB_DEVICE_ID_MATCH_VENDOR | USB_DEVICE_ID_MATCH_INT_INFO, \
672 + .idVendor = (vend), \
673 + .bInterfaceClass = USB_CLASS_VENDOR_SPEC, \
674 + .bInterfaceSubClass = 93, \
675 + .bInterfaceProtocol = (pr)
676 + #define XPAD_XBOX360_VENDOR(vend) \
677 +- { XPAD_XBOX360_VENDOR_PROTOCOL(vend,1) }, \
678 +- { XPAD_XBOX360_VENDOR_PROTOCOL(vend,129) }
679 ++ { XPAD_XBOX360_VENDOR_PROTOCOL((vend), 1) }, \
680 ++ { XPAD_XBOX360_VENDOR_PROTOCOL((vend), 129) }
681 +
682 + /* The Xbox One controller uses subclass 71 and protocol 208. */
683 + #define XPAD_XBOXONE_VENDOR_PROTOCOL(vend, pr) \
684 +@@ -292,33 +412,138 @@ static const signed short xpad_abs_triggers[] = {
685 + .bInterfaceSubClass = 71, \
686 + .bInterfaceProtocol = (pr)
687 + #define XPAD_XBOXONE_VENDOR(vend) \
688 +- { XPAD_XBOXONE_VENDOR_PROTOCOL(vend, 208) }
689 ++ { XPAD_XBOXONE_VENDOR_PROTOCOL((vend), 208) }
690 +
691 +-static struct usb_device_id xpad_table[] = {
692 ++static const struct usb_device_id xpad_table[] = {
693 + { USB_INTERFACE_INFO('X', 'B', 0) }, /* X-Box USB-IF not approved class */
694 ++ XPAD_XBOX360_VENDOR(0x0079), /* GPD Win 2 Controller */
695 + XPAD_XBOX360_VENDOR(0x044f), /* Thrustmaster X-Box 360 controllers */
696 + XPAD_XBOX360_VENDOR(0x045e), /* Microsoft X-Box 360 controllers */
697 + XPAD_XBOXONE_VENDOR(0x045e), /* Microsoft X-Box One controllers */
698 + XPAD_XBOX360_VENDOR(0x046d), /* Logitech X-Box 360 style controllers */
699 ++ XPAD_XBOX360_VENDOR(0x056e), /* Elecom JC-U3613M */
700 ++ XPAD_XBOX360_VENDOR(0x06a3), /* Saitek P3600 */
701 + XPAD_XBOX360_VENDOR(0x0738), /* Mad Catz X-Box 360 controllers */
702 + { USB_DEVICE(0x0738, 0x4540) }, /* Mad Catz Beat Pad */
703 ++ XPAD_XBOXONE_VENDOR(0x0738), /* Mad Catz FightStick TE 2 */
704 ++ XPAD_XBOX360_VENDOR(0x07ff), /* Mad Catz GamePad */
705 + XPAD_XBOX360_VENDOR(0x0e6f), /* 0x0e6f X-Box 360 controllers */
706 ++ XPAD_XBOXONE_VENDOR(0x0e6f), /* 0x0e6f X-Box One controllers */
707 ++ XPAD_XBOX360_VENDOR(0x0f0d), /* Hori Controllers */
708 ++ XPAD_XBOXONE_VENDOR(0x0f0d), /* Hori Controllers */
709 ++ XPAD_XBOX360_VENDOR(0x11c9), /* Nacon GC100XF */
710 + XPAD_XBOX360_VENDOR(0x12ab), /* X-Box 360 dance pads */
711 + XPAD_XBOX360_VENDOR(0x1430), /* RedOctane X-Box 360 controllers */
712 + XPAD_XBOX360_VENDOR(0x146b), /* BigBen Interactive Controllers */
713 +- XPAD_XBOX360_VENDOR(0x1bad), /* Harminix Rock Band Guitar and Drums */
714 +- XPAD_XBOX360_VENDOR(0x0f0d), /* Hori Controllers */
715 +- XPAD_XBOX360_VENDOR(0x1689), /* Razer Onza */
716 +- XPAD_XBOX360_VENDOR(0x24c6), /* PowerA Controllers */
717 + XPAD_XBOX360_VENDOR(0x1532), /* Razer Sabertooth */
718 + XPAD_XBOXONE_VENDOR(0x1532), /* Razer Wildcat */
719 + XPAD_XBOX360_VENDOR(0x15e4), /* Numark X-Box 360 controllers */
720 + XPAD_XBOX360_VENDOR(0x162e), /* Joytech X-Box 360 controllers */
721 ++ XPAD_XBOX360_VENDOR(0x1689), /* Razer Onza */
722 ++ XPAD_XBOX360_VENDOR(0x1bad), /* Harminix Rock Band Guitar and Drums */
723 ++ XPAD_XBOX360_VENDOR(0x24c6), /* PowerA Controllers */
724 ++ XPAD_XBOXONE_VENDOR(0x24c6), /* PowerA Controllers */
725 + { }
726 + };
727 +
728 + MODULE_DEVICE_TABLE(usb, xpad_table);
729 +
730 ++struct xboxone_init_packet {
731 ++ u16 idVendor;
732 ++ u16 idProduct;
733 ++ const u8 *data;
734 ++ u8 len;
735 ++};
736 ++
737 ++#define XBOXONE_INIT_PKT(_vid, _pid, _data) \
738 ++ { \
739 ++ .idVendor = (_vid), \
740 ++ .idProduct = (_pid), \
741 ++ .data = (_data), \
742 ++ .len = ARRAY_SIZE(_data), \
743 ++ }
744 ++
745 ++
746 ++/*
747 ++ * This packet is required for all Xbox One pads with 2015
748 ++ * or later firmware installed (or present from the factory).
749 ++ */
750 ++static const u8 xboxone_fw2015_init[] = {
751 ++ 0x05, 0x20, 0x00, 0x01, 0x00
752 ++};
753 ++
754 ++/*
755 ++ * This packet is required for the Titanfall 2 Xbox One pads
756 ++ * (0x0e6f:0x0165) to finish initialization and for Hori pads
757 ++ * (0x0f0d:0x0067) to make the analog sticks work.
758 ++ */
759 ++static const u8 xboxone_hori_init[] = {
760 ++ 0x01, 0x20, 0x00, 0x09, 0x00, 0x04, 0x20, 0x3a,
761 ++ 0x00, 0x00, 0x00, 0x80, 0x00
762 ++};
763 ++
764 ++/*
765 ++ * This packet is required for some of the PDP pads to start
766 ++ * sending input reports. These pads include: (0x0e6f:0x02ab),
767 ++ * (0x0e6f:0x02a4).
768 ++ */
769 ++static const u8 xboxone_pdp_init1[] = {
770 ++ 0x0a, 0x20, 0x00, 0x03, 0x00, 0x01, 0x14
771 ++};
772 ++
773 ++/*
774 ++ * This packet is required for some of the PDP pads to start
775 ++ * sending input reports. These pads include: (0x0e6f:0x02ab),
776 ++ * (0x0e6f:0x02a4).
777 ++ */
778 ++static const u8 xboxone_pdp_init2[] = {
779 ++ 0x06, 0x20, 0x00, 0x02, 0x01, 0x00
780 ++};
781 ++
782 ++/*
783 ++ * A specific rumble packet is required for some PowerA pads to start
784 ++ * sending input reports. One of those pads is (0x24c6:0x543a).
785 ++ */
786 ++static const u8 xboxone_rumblebegin_init[] = {
787 ++ 0x09, 0x00, 0x00, 0x09, 0x00, 0x0F, 0x00, 0x00,
788 ++ 0x1D, 0x1D, 0xFF, 0x00, 0x00
789 ++};
790 ++
791 ++/*
792 ++ * A rumble packet with zero FF intensity will immediately
793 ++ * terminate the rumbling required to init PowerA pads.
794 ++ * This should happen fast enough that the motors don't
795 ++ * spin up to enough speed to actually vibrate the gamepad.
796 ++ */
797 ++static const u8 xboxone_rumbleend_init[] = {
798 ++ 0x09, 0x00, 0x00, 0x09, 0x00, 0x0F, 0x00, 0x00,
799 ++ 0x00, 0x00, 0x00, 0x00, 0x00
800 ++};
801 ++
802 ++/*
803 ++ * This specifies the selection of init packets that a gamepad
804 ++ * will be sent on init *and* the order in which they will be
805 ++ * sent. The correct sequence number will be added when the
806 ++ * packet is going to be sent.
807 ++ */
808 ++static const struct xboxone_init_packet xboxone_init_packets[] = {
809 ++ XBOXONE_INIT_PKT(0x0e6f, 0x0165, xboxone_hori_init),
810 ++ XBOXONE_INIT_PKT(0x0f0d, 0x0067, xboxone_hori_init),
811 ++ XBOXONE_INIT_PKT(0x0000, 0x0000, xboxone_fw2015_init),
812 ++ XBOXONE_INIT_PKT(0x0e6f, 0x02ab, xboxone_pdp_init1),
813 ++ XBOXONE_INIT_PKT(0x0e6f, 0x02ab, xboxone_pdp_init2),
814 ++ XBOXONE_INIT_PKT(0x0e6f, 0x02a4, xboxone_pdp_init1),
815 ++ XBOXONE_INIT_PKT(0x0e6f, 0x02a4, xboxone_pdp_init2),
816 ++ XBOXONE_INIT_PKT(0x0e6f, 0x02a6, xboxone_pdp_init1),
817 ++ XBOXONE_INIT_PKT(0x0e6f, 0x02a6, xboxone_pdp_init2),
818 ++ XBOXONE_INIT_PKT(0x24c6, 0x541a, xboxone_rumblebegin_init),
819 ++ XBOXONE_INIT_PKT(0x24c6, 0x542a, xboxone_rumblebegin_init),
820 ++ XBOXONE_INIT_PKT(0x24c6, 0x543a, xboxone_rumblebegin_init),
821 ++ XBOXONE_INIT_PKT(0x24c6, 0x541a, xboxone_rumbleend_init),
822 ++ XBOXONE_INIT_PKT(0x24c6, 0x542a, xboxone_rumbleend_init),
823 ++ XBOXONE_INIT_PKT(0x24c6, 0x543a, xboxone_rumbleend_init),
824 ++};
825 ++
826 + struct xpad_output_packet {
827 + u8 data[XPAD_PKT_LEN];
828 + u8 len;
829 +@@ -334,23 +559,28 @@ struct xpad_output_packet {
830 +
831 + struct usb_xpad {
832 + struct input_dev *dev; /* input device interface */
833 ++ struct input_dev __rcu *x360w_dev;
834 + struct usb_device *udev; /* usb device */
835 + struct usb_interface *intf; /* usb interface */
836 +
837 +- int pad_present;
838 ++ bool pad_present;
839 ++ bool input_created;
840 +
841 + struct urb *irq_in; /* urb for interrupt in report */
842 + unsigned char *idata; /* input data */
843 + dma_addr_t idata_dma;
844 +
845 + struct urb *irq_out; /* urb for interrupt out report */
846 ++ struct usb_anchor irq_out_anchor;
847 + bool irq_out_active; /* we must not use an active URB */
848 ++ u8 odata_serial; /* serial number for xbox one protocol */
849 + unsigned char *odata; /* output data */
850 + dma_addr_t odata_dma;
851 + spinlock_t odata_lock;
852 +
853 + struct xpad_output_packet out_packets[XPAD_NUM_OUT_PACKETS];
854 + int last_out_packet;
855 ++ int init_seq;
856 +
857 + #if defined(CONFIG_JOYSTICK_XPAD_LEDS)
858 + struct xpad_led *led;
859 +@@ -362,8 +592,13 @@ struct usb_xpad {
860 + int xtype; /* type of xbox device */
861 + int pad_nr; /* the order x360 pads were attached */
862 + const char *name; /* name of the device */
863 ++ struct work_struct work; /* init/remove device from callback */
864 + };
865 +
866 ++static int xpad_init_input(struct usb_xpad *xpad);
867 ++static void xpad_deinit_input(struct usb_xpad *xpad);
868 ++static void xpadone_ack_mode_report(struct usb_xpad *xpad, u8 seq_num);
869 ++
870 + /*
871 + * xpad_process_packet
872 + *
873 +@@ -443,10 +678,12 @@ static void xpad_process_packet(struct usb_xpad *xpad, u16 cmd, unsigned char *d
874 + * http://www.free60.org/wiki/Gamepad
875 + */
876 +
877 +-static void xpad360_process_packet(struct usb_xpad *xpad,
878 ++static void xpad360_process_packet(struct usb_xpad *xpad, struct input_dev *dev,
879 + u16 cmd, unsigned char *data)
880 + {
881 +- struct input_dev *dev = xpad->dev;
882 ++ /* valid pad data */
883 ++ if (data[0] != 0x00)
884 ++ return;
885 +
886 + /* digital pad */
887 + if (xpad->mapping & MAP_DPAD_TO_BUTTONS) {
888 +@@ -514,7 +751,30 @@ static void xpad360_process_packet(struct usb_xpad *xpad,
889 + input_sync(dev);
890 + }
891 +
892 +-static void xpad_identify_controller(struct usb_xpad *xpad);
893 ++static void xpad_presence_work(struct work_struct *work)
894 ++{
895 ++ struct usb_xpad *xpad = container_of(work, struct usb_xpad, work);
896 ++ int error;
897 ++
898 ++ if (xpad->pad_present) {
899 ++ error = xpad_init_input(xpad);
900 ++ if (error) {
901 ++ /* complain only, not much else we can do here */
902 ++ dev_err(&xpad->dev->dev,
903 ++ "unable to init device: %d\n", error);
904 ++ } else {
905 ++ rcu_assign_pointer(xpad->x360w_dev, xpad->dev);
906 ++ }
907 ++ } else {
908 ++ RCU_INIT_POINTER(xpad->x360w_dev, NULL);
909 ++ synchronize_rcu();
910 ++ /*
911 ++ * Now that we are sure xpad360w_process_packet is not
912 ++ * using input device we can get rid of it.
913 ++ */
914 ++ xpad_deinit_input(xpad);
915 ++ }
916 ++}
917 +
918 + /*
919 + * xpad360w_process_packet
920 +@@ -532,35 +792,61 @@ static void xpad_identify_controller(struct usb_xpad *xpad);
921 + */
922 + static void xpad360w_process_packet(struct usb_xpad *xpad, u16 cmd, unsigned char *data)
923 + {
924 ++ struct input_dev *dev;
925 ++ bool present;
926 ++
927 + /* Presence change */
928 + if (data[0] & 0x08) {
929 +- if (data[1] & 0x80) {
930 +- xpad->pad_present = 1;
931 +- /*
932 +- * Light up the segment corresponding to
933 +- * controller number.
934 +- */
935 +- xpad_identify_controller(xpad);
936 +- } else
937 +- xpad->pad_present = 0;
938 ++ present = (data[1] & 0x80) != 0;
939 ++
940 ++ if (xpad->pad_present != present) {
941 ++ xpad->pad_present = present;
942 ++ schedule_work(&xpad->work);
943 ++ }
944 + }
945 +
946 + /* Valid pad data */
947 +- if (!(data[1] & 0x1))
948 ++ if (data[1] != 0x1)
949 + return;
950 +
951 +- xpad360_process_packet(xpad, cmd, &data[4]);
952 ++ rcu_read_lock();
953 ++ dev = rcu_dereference(xpad->x360w_dev);
954 ++ if (dev)
955 ++ xpad360_process_packet(xpad, dev, cmd, &data[4]);
956 ++ rcu_read_unlock();
957 + }
958 +
959 + /*
960 +- * xpadone_process_buttons
961 ++ * xpadone_process_packet
962 + *
963 +- * Process a button update packet from an Xbox one controller.
964 ++ * Completes a request by converting the data into events for the
965 ++ * input subsystem. This version is for the Xbox One controller.
966 ++ *
967 ++ * The report format was gleaned from
968 ++ * https://github.com/kylelemons/xbox/blob/master/xbox.go
969 + */
970 +-static void xpadone_process_buttons(struct usb_xpad *xpad,
971 +- struct input_dev *dev,
972 +- unsigned char *data)
973 ++static void xpadone_process_packet(struct usb_xpad *xpad, u16 cmd, unsigned char *data)
974 + {
975 ++ struct input_dev *dev = xpad->dev;
976 ++
977 ++ /* the xbox button has its own special report */
978 ++ if (data[0] == 0X07) {
979 ++ /*
980 ++ * The Xbox One S controller requires these reports to be
981 ++ * acked otherwise it continues sending them forever and
982 ++ * won't report further mode button events.
983 ++ */
984 ++ if (data[1] == 0x30)
985 ++ xpadone_ack_mode_report(xpad, data[2]);
986 ++
987 ++ input_report_key(dev, BTN_MODE, data[4] & 0x01);
988 ++ input_sync(dev);
989 ++ return;
990 ++ }
991 ++ /* check invalid packet */
992 ++ else if (data[0] != 0X20)
993 ++ return;
994 ++
995 + /* menu/view buttons */
996 + input_report_key(dev, BTN_START, data[4] & 0x04);
997 + input_report_key(dev, BTN_SELECT, data[4] & 0x08);
998 +@@ -623,34 +909,6 @@ static void xpadone_process_buttons(struct usb_xpad *xpad,
999 + input_sync(dev);
1000 + }
1001 +
1002 +-/*
1003 +- * xpadone_process_packet
1004 +- *
1005 +- * Completes a request by converting the data into events for the
1006 +- * input subsystem. This version is for the Xbox One controller.
1007 +- *
1008 +- * The report format was gleaned from
1009 +- * https://github.com/kylelemons/xbox/blob/master/xbox.go
1010 +- */
1011 +-
1012 +-static void xpadone_process_packet(struct usb_xpad *xpad,
1013 +- u16 cmd, unsigned char *data)
1014 +-{
1015 +- struct input_dev *dev = xpad->dev;
1016 +-
1017 +- switch (data[0]) {
1018 +- case 0x20:
1019 +- xpadone_process_buttons(xpad, dev, data);
1020 +- break;
1021 +-
1022 +- case 0x07:
1023 +- /* the xbox button has its own special report */
1024 +- input_report_key(dev, BTN_MODE, data[4] & 0x01);
1025 +- input_sync(dev);
1026 +- break;
1027 +- }
1028 +-}
1029 +-
1030 + static void xpad_irq_in(struct urb *urb)
1031 + {
1032 + struct usb_xpad *xpad = urb->context;
1033 +@@ -678,7 +936,7 @@ static void xpad_irq_in(struct urb *urb)
1034 +
1035 + switch (xpad->xtype) {
1036 + case XTYPE_XBOX360:
1037 +- xpad360_process_packet(xpad, 0, xpad->idata);
1038 ++ xpad360_process_packet(xpad, xpad->dev, 0, xpad->idata);
1039 + break;
1040 + case XTYPE_XBOX360W:
1041 + xpad360w_process_packet(xpad, 0, xpad->idata);
1042 +@@ -697,12 +955,48 @@ exit:
1043 + __func__, retval);
1044 + }
1045 +
1046 ++/* Callers must hold xpad->odata_lock spinlock */
1047 ++static bool xpad_prepare_next_init_packet(struct usb_xpad *xpad)
1048 ++{
1049 ++ const struct xboxone_init_packet *init_packet;
1050 ++
1051 ++ if (xpad->xtype != XTYPE_XBOXONE)
1052 ++ return false;
1053 ++
1054 ++ /* Perform initialization sequence for Xbox One pads that require it */
1055 ++ while (xpad->init_seq < ARRAY_SIZE(xboxone_init_packets)) {
1056 ++ init_packet = &xboxone_init_packets[xpad->init_seq++];
1057 ++
1058 ++ if (init_packet->idVendor != 0 &&
1059 ++ init_packet->idVendor != xpad->dev->id.vendor)
1060 ++ continue;
1061 ++
1062 ++ if (init_packet->idProduct != 0 &&
1063 ++ init_packet->idProduct != xpad->dev->id.product)
1064 ++ continue;
1065 ++
1066 ++ /* This packet applies to our device, so prepare to send it */
1067 ++ memcpy(xpad->odata, init_packet->data, init_packet->len);
1068 ++ xpad->irq_out->transfer_buffer_length = init_packet->len;
1069 ++
1070 ++ /* Update packet with current sequence number */
1071 ++ xpad->odata[2] = xpad->odata_serial++;
1072 ++ return true;
1073 ++ }
1074 ++
1075 ++ return false;
1076 ++}
1077 ++
1078 + /* Callers must hold xpad->odata_lock spinlock */
1079 + static bool xpad_prepare_next_out_packet(struct usb_xpad *xpad)
1080 + {
1081 + struct xpad_output_packet *pkt, *packet = NULL;
1082 + int i;
1083 +
1084 ++ /* We may have init packets to send before we can send user commands */
1085 ++ if (xpad_prepare_next_init_packet(xpad))
1086 ++ return true;
1087 ++
1088 + for (i = 0; i < XPAD_NUM_OUT_PACKETS; i++) {
1089 + if (++xpad->last_out_packet >= XPAD_NUM_OUT_PACKETS)
1090 + xpad->last_out_packet = 0;
1091 +@@ -733,11 +1027,13 @@ static int xpad_try_sending_next_out_packet(struct usb_xpad *xpad)
1092 + int error;
1093 +
1094 + if (!xpad->irq_out_active && xpad_prepare_next_out_packet(xpad)) {
1095 ++ usb_anchor_urb(xpad->irq_out, &xpad->irq_out_anchor);
1096 + error = usb_submit_urb(xpad->irq_out, GFP_ATOMIC);
1097 + if (error) {
1098 + dev_err(&xpad->intf->dev,
1099 + "%s - usb_submit_urb failed with result %d\n",
1100 + __func__, error);
1101 ++ usb_unanchor_urb(xpad->irq_out);
1102 + return -EIO;
1103 + }
1104 +
1105 +@@ -779,11 +1075,13 @@ static void xpad_irq_out(struct urb *urb)
1106 + }
1107 +
1108 + if (xpad->irq_out_active) {
1109 ++ usb_anchor_urb(urb, &xpad->irq_out_anchor);
1110 + error = usb_submit_urb(urb, GFP_ATOMIC);
1111 + if (error) {
1112 + dev_err(dev,
1113 + "%s - usb_submit_urb failed with result %d\n",
1114 + __func__, error);
1115 ++ usb_unanchor_urb(urb);
1116 + xpad->irq_out_active = false;
1117 + }
1118 + }
1119 +@@ -791,34 +1089,29 @@ static void xpad_irq_out(struct urb *urb)
1120 + spin_unlock_irqrestore(&xpad->odata_lock, flags);
1121 + }
1122 +
1123 +-static int xpad_init_output(struct usb_interface *intf, struct usb_xpad *xpad)
1124 ++static int xpad_init_output(struct usb_interface *intf, struct usb_xpad *xpad,
1125 ++ struct usb_endpoint_descriptor *ep_irq_out)
1126 + {
1127 +- struct usb_endpoint_descriptor *ep_irq_out;
1128 +- int ep_irq_out_idx;
1129 + int error;
1130 +
1131 + if (xpad->xtype == XTYPE_UNKNOWN)
1132 + return 0;
1133 +
1134 ++ init_usb_anchor(&xpad->irq_out_anchor);
1135 ++
1136 + xpad->odata = usb_alloc_coherent(xpad->udev, XPAD_PKT_LEN,
1137 + GFP_KERNEL, &xpad->odata_dma);
1138 +- if (!xpad->odata) {
1139 +- error = -ENOMEM;
1140 +- goto fail1;
1141 +- }
1142 ++ if (!xpad->odata)
1143 ++ return -ENOMEM;
1144 +
1145 + spin_lock_init(&xpad->odata_lock);
1146 +
1147 + xpad->irq_out = usb_alloc_urb(0, GFP_KERNEL);
1148 + if (!xpad->irq_out) {
1149 + error = -ENOMEM;
1150 +- goto fail2;
1151 ++ goto err_free_coherent;
1152 + }
1153 +
1154 +- /* Xbox One controller has in/out endpoints swapped. */
1155 +- ep_irq_out_idx = xpad->xtype == XTYPE_XBOXONE ? 0 : 1;
1156 +- ep_irq_out = &intf->cur_altsetting->endpoint[ep_irq_out_idx].desc;
1157 +-
1158 + usb_fill_int_urb(xpad->irq_out, xpad->udev,
1159 + usb_sndintpipe(xpad->udev, ep_irq_out->bEndpointAddress),
1160 + xpad->odata, XPAD_PKT_LEN,
1161 +@@ -828,14 +1121,21 @@ static int xpad_init_output(struct usb_interface *intf, struct usb_xpad *xpad)
1162 +
1163 + return 0;
1164 +
1165 +- fail2: usb_free_coherent(xpad->udev, XPAD_PKT_LEN, xpad->odata, xpad->odata_dma);
1166 +- fail1: return error;
1167 ++err_free_coherent:
1168 ++ usb_free_coherent(xpad->udev, XPAD_PKT_LEN, xpad->odata, xpad->odata_dma);
1169 ++ return error;
1170 + }
1171 +
1172 + static void xpad_stop_output(struct usb_xpad *xpad)
1173 + {
1174 +- if (xpad->xtype != XTYPE_UNKNOWN)
1175 +- usb_kill_urb(xpad->irq_out);
1176 ++ if (xpad->xtype != XTYPE_UNKNOWN) {
1177 ++ if (!usb_wait_anchor_empty_timeout(&xpad->irq_out_anchor,
1178 ++ 5000)) {
1179 ++ dev_warn(&xpad->intf->dev,
1180 ++ "timed out waiting for output URB to complete, killing\n");
1181 ++ usb_kill_anchored_urbs(&xpad->irq_out_anchor);
1182 ++ }
1183 ++ }
1184 + }
1185 +
1186 + static void xpad_deinit_output(struct usb_xpad *xpad)
1187 +@@ -882,21 +1182,17 @@ static int xpad_inquiry_pad_presence(struct usb_xpad *xpad)
1188 +
1189 + static int xpad_start_xbox_one(struct usb_xpad *xpad)
1190 + {
1191 +- struct xpad_output_packet *packet =
1192 +- &xpad->out_packets[XPAD_OUT_CMD_IDX];
1193 + unsigned long flags;
1194 + int retval;
1195 +
1196 + spin_lock_irqsave(&xpad->odata_lock, flags);
1197 +
1198 +- /* Xbox one controller needs to be initialized. */
1199 +- packet->data[0] = 0x05;
1200 +- packet->data[1] = 0x20;
1201 +- packet->len = 2;
1202 +- packet->pending = true;
1203 +-
1204 +- /* Reset the sequence so we send out start packet first */
1205 +- xpad->last_out_packet = -1;
1206 ++ /*
1207 ++ * Begin the init sequence by attempting to send a packet.
1208 ++ * We will cycle through the init packet sequence before
1209 ++ * sending any packets from the output ring.
1210 ++ */
1211 ++ xpad->init_seq = 0;
1212 + retval = xpad_try_sending_next_out_packet(xpad);
1213 +
1214 + spin_unlock_irqrestore(&xpad->odata_lock, flags);
1215 +@@ -904,6 +1200,30 @@ static int xpad_start_xbox_one(struct usb_xpad *xpad)
1216 + return retval;
1217 + }
1218 +
1219 ++static void xpadone_ack_mode_report(struct usb_xpad *xpad, u8 seq_num)
1220 ++{
1221 ++ unsigned long flags;
1222 ++ struct xpad_output_packet *packet =
1223 ++ &xpad->out_packets[XPAD_OUT_CMD_IDX];
1224 ++ static const u8 mode_report_ack[] = {
1225 ++ 0x01, 0x20, 0x00, 0x09, 0x00, 0x07, 0x20, 0x02,
1226 ++ 0x00, 0x00, 0x00, 0x00, 0x00
1227 ++ };
1228 ++
1229 ++ spin_lock_irqsave(&xpad->odata_lock, flags);
1230 ++
1231 ++ packet->len = sizeof(mode_report_ack);
1232 ++ memcpy(packet->data, mode_report_ack, packet->len);
1233 ++ packet->data[2] = seq_num;
1234 ++ packet->pending = true;
1235 ++
1236 ++ /* Reset the sequence so we send out the ack now */
1237 ++ xpad->last_out_packet = -1;
1238 ++ xpad_try_sending_next_out_packet(xpad);
1239 ++
1240 ++ spin_unlock_irqrestore(&xpad->odata_lock, flags);
1241 ++}
1242 ++
1243 + #ifdef CONFIG_JOYSTICK_XPAD_FF
1244 + static int xpad_play_effect(struct input_dev *dev, void *data, struct ff_effect *effect)
1245 + {
1246 +@@ -966,18 +1286,19 @@ static int xpad_play_effect(struct input_dev *dev, void *data, struct ff_effect
1247 +
1248 + case XTYPE_XBOXONE:
1249 + packet->data[0] = 0x09; /* activate rumble */
1250 +- packet->data[1] = 0x08;
1251 +- packet->data[2] = 0x00;
1252 +- packet->data[3] = 0x08; /* continuous effect */
1253 +- packet->data[4] = 0x00; /* simple rumble mode */
1254 +- packet->data[5] = 0x03; /* L and R actuator only */
1255 +- packet->data[6] = 0x00; /* TODO: LT actuator */
1256 +- packet->data[7] = 0x00; /* TODO: RT actuator */
1257 +- packet->data[8] = strong / 256; /* left actuator */
1258 +- packet->data[9] = weak / 256; /* right actuator */
1259 +- packet->data[10] = 0x80; /* length of pulse */
1260 +- packet->data[11] = 0x00; /* stop period of pulse */
1261 +- packet->len = 12;
1262 ++ packet->data[1] = 0x00;
1263 ++ packet->data[2] = xpad->odata_serial++;
1264 ++ packet->data[3] = 0x09;
1265 ++ packet->data[4] = 0x00;
1266 ++ packet->data[5] = 0x0F;
1267 ++ packet->data[6] = 0x00;
1268 ++ packet->data[7] = 0x00;
1269 ++ packet->data[8] = strong / 512; /* left actuator */
1270 ++ packet->data[9] = weak / 512; /* right actuator */
1271 ++ packet->data[10] = 0xFF; /* on period */
1272 ++ packet->data[11] = 0x00; /* off period */
1273 ++ packet->data[12] = 0xFF; /* repeat count */
1274 ++ packet->len = 13;
1275 + packet->pending = true;
1276 + break;
1277 +
1278 +@@ -1090,7 +1411,7 @@ static void xpad_send_led_command(struct usb_xpad *xpad, int command)
1279 + */
1280 + static void xpad_identify_controller(struct usb_xpad *xpad)
1281 + {
1282 +- xpad_send_led_command(xpad, (xpad->pad_nr % 4) + 2);
1283 ++ led_set_brightness(&xpad->led->led_cdev, (xpad->pad_nr % 4) + 2);
1284 + }
1285 +
1286 + static void xpad_led_set(struct led_classdev *led_cdev,
1287 +@@ -1127,19 +1448,13 @@ static int xpad_led_probe(struct usb_xpad *xpad)
1288 + led_cdev = &led->led_cdev;
1289 + led_cdev->name = led->name;
1290 + led_cdev->brightness_set = xpad_led_set;
1291 ++ led_cdev->flags = LED_CORE_SUSPENDRESUME;
1292 +
1293 + error = led_classdev_register(&xpad->udev->dev, led_cdev);
1294 + if (error)
1295 + goto err_free_id;
1296 +
1297 +- if (xpad->xtype == XTYPE_XBOX360) {
1298 +- /*
1299 +- * Light up the segment corresponding to controller
1300 +- * number on wired devices. On wireless we'll do that
1301 +- * when they respond to "presence" packet.
1302 +- */
1303 +- xpad_identify_controller(xpad);
1304 +- }
1305 ++ xpad_identify_controller(xpad);
1306 +
1307 + return 0;
1308 +
1309 +@@ -1164,41 +1479,110 @@ static void xpad_led_disconnect(struct usb_xpad *xpad)
1310 + #else
1311 + static int xpad_led_probe(struct usb_xpad *xpad) { return 0; }
1312 + static void xpad_led_disconnect(struct usb_xpad *xpad) { }
1313 +-static void xpad_identify_controller(struct usb_xpad *xpad) { }
1314 + #endif
1315 +
1316 +-static int xpad_open(struct input_dev *dev)
1317 ++static int xpad_start_input(struct usb_xpad *xpad)
1318 + {
1319 +- struct usb_xpad *xpad = input_get_drvdata(dev);
1320 +-
1321 +- /* URB was submitted in probe */
1322 +- if (xpad->xtype == XTYPE_XBOX360W)
1323 +- return 0;
1324 ++ int error;
1325 +
1326 +- xpad->irq_in->dev = xpad->udev;
1327 + if (usb_submit_urb(xpad->irq_in, GFP_KERNEL))
1328 + return -EIO;
1329 +
1330 +- if (xpad->xtype == XTYPE_XBOXONE)
1331 +- return xpad_start_xbox_one(xpad);
1332 ++ if (xpad->xtype == XTYPE_XBOXONE) {
1333 ++ error = xpad_start_xbox_one(xpad);
1334 ++ if (error) {
1335 ++ usb_kill_urb(xpad->irq_in);
1336 ++ return error;
1337 ++ }
1338 ++ }
1339 +
1340 + return 0;
1341 + }
1342 +
1343 +-static void xpad_close(struct input_dev *dev)
1344 ++static void xpad_stop_input(struct usb_xpad *xpad)
1345 + {
1346 +- struct usb_xpad *xpad = input_get_drvdata(dev);
1347 ++ usb_kill_urb(xpad->irq_in);
1348 ++}
1349 +
1350 +- if (xpad->xtype != XTYPE_XBOX360W)
1351 ++static void xpad360w_poweroff_controller(struct usb_xpad *xpad)
1352 ++{
1353 ++ unsigned long flags;
1354 ++ struct xpad_output_packet *packet =
1355 ++ &xpad->out_packets[XPAD_OUT_CMD_IDX];
1356 ++
1357 ++ spin_lock_irqsave(&xpad->odata_lock, flags);
1358 ++
1359 ++ packet->data[0] = 0x00;
1360 ++ packet->data[1] = 0x00;
1361 ++ packet->data[2] = 0x08;
1362 ++ packet->data[3] = 0xC0;
1363 ++ packet->data[4] = 0x00;
1364 ++ packet->data[5] = 0x00;
1365 ++ packet->data[6] = 0x00;
1366 ++ packet->data[7] = 0x00;
1367 ++ packet->data[8] = 0x00;
1368 ++ packet->data[9] = 0x00;
1369 ++ packet->data[10] = 0x00;
1370 ++ packet->data[11] = 0x00;
1371 ++ packet->len = 12;
1372 ++ packet->pending = true;
1373 ++
1374 ++ /* Reset the sequence so we send out poweroff now */
1375 ++ xpad->last_out_packet = -1;
1376 ++ xpad_try_sending_next_out_packet(xpad);
1377 ++
1378 ++ spin_unlock_irqrestore(&xpad->odata_lock, flags);
1379 ++}
1380 ++
1381 ++static int xpad360w_start_input(struct usb_xpad *xpad)
1382 ++{
1383 ++ int error;
1384 ++
1385 ++ error = usb_submit_urb(xpad->irq_in, GFP_KERNEL);
1386 ++ if (error)
1387 ++ return -EIO;
1388 ++
1389 ++ /*
1390 ++ * Send presence packet.
1391 ++ * This will force the controller to resend connection packets.
1392 ++ * This is useful in the case we activate the module after the
1393 ++ * adapter has been plugged in, as it won't automatically
1394 ++ * send us info about the controllers.
1395 ++ */
1396 ++ error = xpad_inquiry_pad_presence(xpad);
1397 ++ if (error) {
1398 + usb_kill_urb(xpad->irq_in);
1399 ++ return error;
1400 ++ }
1401 +
1402 +- xpad_stop_output(xpad);
1403 ++ return 0;
1404 ++}
1405 ++
1406 ++static void xpad360w_stop_input(struct usb_xpad *xpad)
1407 ++{
1408 ++ usb_kill_urb(xpad->irq_in);
1409 ++
1410 ++ /* Make sure we are done with presence work if it was scheduled */
1411 ++ flush_work(&xpad->work);
1412 ++}
1413 ++
1414 ++static int xpad_open(struct input_dev *dev)
1415 ++{
1416 ++ struct usb_xpad *xpad = input_get_drvdata(dev);
1417 ++
1418 ++ return xpad_start_input(xpad);
1419 ++}
1420 ++
1421 ++static void xpad_close(struct input_dev *dev)
1422 ++{
1423 ++ struct usb_xpad *xpad = input_get_drvdata(dev);
1424 ++
1425 ++ xpad_stop_input(xpad);
1426 + }
1427 +
1428 + static void xpad_set_up_abs(struct input_dev *input_dev, signed short abs)
1429 + {
1430 + struct usb_xpad *xpad = input_get_drvdata(input_dev);
1431 +- set_bit(abs, input_dev->absbit);
1432 +
1433 + switch (abs) {
1434 + case ABS_X:
1435 +@@ -1218,13 +1602,19 @@ static void xpad_set_up_abs(struct input_dev *input_dev, signed short abs)
1436 + case ABS_HAT0Y: /* the d-pad (only if dpad is mapped to axes */
1437 + input_set_abs_params(input_dev, abs, -1, 1, 0, 0);
1438 + break;
1439 ++ default:
1440 ++ input_set_abs_params(input_dev, abs, 0, 0, 0, 0);
1441 ++ break;
1442 + }
1443 + }
1444 +
1445 + static void xpad_deinit_input(struct usb_xpad *xpad)
1446 + {
1447 +- xpad_led_disconnect(xpad);
1448 +- input_unregister_device(xpad->dev);
1449 ++ if (xpad->input_created) {
1450 ++ xpad->input_created = false;
1451 ++ xpad_led_disconnect(xpad);
1452 ++ input_unregister_device(xpad->dev);
1453 ++ }
1454 + }
1455 +
1456 + static int xpad_init_input(struct usb_xpad *xpad)
1457 +@@ -1250,13 +1640,12 @@ static int xpad_init_input(struct usb_xpad *xpad)
1458 +
1459 + input_set_drvdata(input_dev, xpad);
1460 +
1461 +- input_dev->open = xpad_open;
1462 +- input_dev->close = xpad_close;
1463 +-
1464 +- __set_bit(EV_KEY, input_dev->evbit);
1465 ++ if (xpad->xtype != XTYPE_XBOX360W) {
1466 ++ input_dev->open = xpad_open;
1467 ++ input_dev->close = xpad_close;
1468 ++ }
1469 +
1470 + if (!(xpad->mapping & MAP_STICKS_TO_NULL)) {
1471 +- __set_bit(EV_ABS, input_dev->evbit);
1472 + /* set up axes */
1473 + for (i = 0; xpad_abs[i] >= 0; i++)
1474 + xpad_set_up_abs(input_dev, xpad_abs[i]);
1475 +@@ -1264,21 +1653,22 @@ static int xpad_init_input(struct usb_xpad *xpad)
1476 +
1477 + /* set up standard buttons */
1478 + for (i = 0; xpad_common_btn[i] >= 0; i++)
1479 +- __set_bit(xpad_common_btn[i], input_dev->keybit);
1480 ++ input_set_capability(input_dev, EV_KEY, xpad_common_btn[i]);
1481 +
1482 + /* set up model-specific ones */
1483 + if (xpad->xtype == XTYPE_XBOX360 || xpad->xtype == XTYPE_XBOX360W ||
1484 + xpad->xtype == XTYPE_XBOXONE) {
1485 + for (i = 0; xpad360_btn[i] >= 0; i++)
1486 +- __set_bit(xpad360_btn[i], input_dev->keybit);
1487 ++ input_set_capability(input_dev, EV_KEY, xpad360_btn[i]);
1488 + } else {
1489 + for (i = 0; xpad_btn[i] >= 0; i++)
1490 +- __set_bit(xpad_btn[i], input_dev->keybit);
1491 ++ input_set_capability(input_dev, EV_KEY, xpad_btn[i]);
1492 + }
1493 +
1494 + if (xpad->mapping & MAP_DPAD_TO_BUTTONS) {
1495 + for (i = 0; xpad_btn_pad[i] >= 0; i++)
1496 +- __set_bit(xpad_btn_pad[i], input_dev->keybit);
1497 ++ input_set_capability(input_dev, EV_KEY,
1498 ++ xpad_btn_pad[i]);
1499 + }
1500 +
1501 + /*
1502 +@@ -1295,7 +1685,8 @@ static int xpad_init_input(struct usb_xpad *xpad)
1503 +
1504 + if (xpad->mapping & MAP_TRIGGERS_TO_BUTTONS) {
1505 + for (i = 0; xpad_btn_triggers[i] >= 0; i++)
1506 +- __set_bit(xpad_btn_triggers[i], input_dev->keybit);
1507 ++ input_set_capability(input_dev, EV_KEY,
1508 ++ xpad_btn_triggers[i]);
1509 + } else {
1510 + for (i = 0; xpad_abs_triggers[i] >= 0; i++)
1511 + xpad_set_up_abs(input_dev, xpad_abs_triggers[i]);
1512 +@@ -1313,6 +1704,7 @@ static int xpad_init_input(struct usb_xpad *xpad)
1513 + if (error)
1514 + goto err_disconnect_led;
1515 +
1516 ++ xpad->input_created = true;
1517 + return 0;
1518 +
1519 + err_disconnect_led:
1520 +@@ -1328,8 +1720,7 @@ static int xpad_probe(struct usb_interface *intf, const struct usb_device_id *id
1521 + {
1522 + struct usb_device *udev = interface_to_usbdev(intf);
1523 + struct usb_xpad *xpad;
1524 +- struct usb_endpoint_descriptor *ep_irq_in;
1525 +- int ep_irq_in_idx;
1526 ++ struct usb_endpoint_descriptor *ep_irq_in, *ep_irq_out;
1527 + int i, error;
1528 +
1529 + if (intf->cur_altsetting->desc.bNumEndpoints != 2)
1530 +@@ -1366,6 +1757,7 @@ static int xpad_probe(struct usb_interface *intf, const struct usb_device_id *id
1531 + xpad->mapping = xpad_device[i].mapping;
1532 + xpad->xtype = xpad_device[i].xtype;
1533 + xpad->name = xpad_device[i].name;
1534 ++ INIT_WORK(&xpad->work, xpad_presence_work);
1535 +
1536 + if (xpad->xtype == XTYPE_UNKNOWN) {
1537 + if (intf->cur_altsetting->desc.bInterfaceClass == USB_CLASS_VENDOR_SPEC) {
1538 +@@ -1398,13 +1790,28 @@ static int xpad_probe(struct usb_interface *intf, const struct usb_device_id *id
1539 + goto err_free_in_urb;
1540 + }
1541 +
1542 +- error = xpad_init_output(intf, xpad);
1543 +- if (error)
1544 ++ ep_irq_in = ep_irq_out = NULL;
1545 ++
1546 ++ for (i = 0; i < 2; i++) {
1547 ++ struct usb_endpoint_descriptor *ep =
1548 ++ &intf->cur_altsetting->endpoint[i].desc;
1549 ++
1550 ++ if (usb_endpoint_xfer_int(ep)) {
1551 ++ if (usb_endpoint_dir_in(ep))
1552 ++ ep_irq_in = ep;
1553 ++ else
1554 ++ ep_irq_out = ep;
1555 ++ }
1556 ++ }
1557 ++
1558 ++ if (!ep_irq_in || !ep_irq_out) {
1559 ++ error = -ENODEV;
1560 + goto err_free_in_urb;
1561 ++ }
1562 +
1563 +- /* Xbox One controller has in/out endpoints swapped. */
1564 +- ep_irq_in_idx = xpad->xtype == XTYPE_XBOXONE ? 1 : 0;
1565 +- ep_irq_in = &intf->cur_altsetting->endpoint[ep_irq_in_idx].desc;
1566 ++ error = xpad_init_output(intf, xpad, ep_irq_out);
1567 ++ if (error)
1568 ++ goto err_free_in_urb;
1569 +
1570 + usb_fill_int_urb(xpad->irq_in, udev,
1571 + usb_rcvintpipe(udev, ep_irq_in->bEndpointAddress),
1572 +@@ -1415,10 +1822,6 @@ static int xpad_probe(struct usb_interface *intf, const struct usb_device_id *id
1573 +
1574 + usb_set_intfdata(intf, xpad);
1575 +
1576 +- error = xpad_init_input(xpad);
1577 +- if (error)
1578 +- goto err_deinit_output;
1579 +-
1580 + if (xpad->xtype == XTYPE_XBOX360W) {
1581 + /*
1582 + * Submit the int URB immediately rather than waiting for open
1583 +@@ -1427,28 +1830,24 @@ static int xpad_probe(struct usb_interface *intf, const struct usb_device_id *id
1584 + * exactly the message that a controller has arrived that
1585 + * we're waiting for.
1586 + */
1587 +- xpad->irq_in->dev = xpad->udev;
1588 +- error = usb_submit_urb(xpad->irq_in, GFP_KERNEL);
1589 ++ error = xpad360w_start_input(xpad);
1590 + if (error)
1591 +- goto err_deinit_input;
1592 +-
1593 ++ goto err_deinit_output;
1594 + /*
1595 +- * Send presence packet.
1596 +- * This will force the controller to resend connection packets.
1597 +- * This is useful in the case we activate the module after the
1598 +- * adapter has been plugged in, as it won't automatically
1599 +- * send us info about the controllers.
1600 ++ * Wireless controllers require RESET_RESUME to work properly
1601 ++ * after suspend. Ideally this quirk should be in usb core
1602 ++ * quirk list, but we have too many vendors producing these
1603 ++ * controllers and we'd need to maintain 2 identical lists
1604 ++ * here in this driver and in usb core.
1605 + */
1606 +- error = xpad_inquiry_pad_presence(xpad);
1607 ++ udev->quirks |= USB_QUIRK_RESET_RESUME;
1608 ++ } else {
1609 ++ error = xpad_init_input(xpad);
1610 + if (error)
1611 +- goto err_kill_in_urb;
1612 ++ goto err_deinit_output;
1613 + }
1614 + return 0;
1615 +
1616 +-err_kill_in_urb:
1617 +- usb_kill_urb(xpad->irq_in);
1618 +-err_deinit_input:
1619 +- xpad_deinit_input(xpad);
1620 + err_deinit_output:
1621 + xpad_deinit_output(xpad);
1622 + err_free_in_urb:
1623 +@@ -1458,19 +1857,24 @@ err_free_idata:
1624 + err_free_mem:
1625 + kfree(xpad);
1626 + return error;
1627 +-
1628 + }
1629 +
1630 + static void xpad_disconnect(struct usb_interface *intf)
1631 + {
1632 +- struct usb_xpad *xpad = usb_get_intfdata (intf);
1633 ++ struct usb_xpad *xpad = usb_get_intfdata(intf);
1634 ++
1635 ++ if (xpad->xtype == XTYPE_XBOX360W)
1636 ++ xpad360w_stop_input(xpad);
1637 +
1638 + xpad_deinit_input(xpad);
1639 +- xpad_deinit_output(xpad);
1640 +
1641 +- if (xpad->xtype == XTYPE_XBOX360W) {
1642 +- usb_kill_urb(xpad->irq_in);
1643 +- }
1644 ++ /*
1645 ++ * Now that both input device and LED device are gone we can
1646 ++ * stop output URB.
1647 ++ */
1648 ++ xpad_stop_output(xpad);
1649 ++
1650 ++ xpad_deinit_output(xpad);
1651 +
1652 + usb_free_urb(xpad->irq_in);
1653 + usb_free_coherent(xpad->udev, XPAD_PKT_LEN,
1654 +@@ -1481,10 +1885,72 @@ static void xpad_disconnect(struct usb_interface *intf)
1655 + usb_set_intfdata(intf, NULL);
1656 + }
1657 +
1658 ++static int xpad_suspend(struct usb_interface *intf, pm_message_t message)
1659 ++{
1660 ++ struct usb_xpad *xpad = usb_get_intfdata(intf);
1661 ++ struct input_dev *input = xpad->dev;
1662 ++
1663 ++ if (xpad->xtype == XTYPE_XBOX360W) {
1664 ++ /*
1665 ++ * Wireless controllers always listen to input so
1666 ++ * they are notified when controller shows up
1667 ++ * or goes away.
1668 ++ */
1669 ++ xpad360w_stop_input(xpad);
1670 ++
1671 ++ /*
1672 ++ * The wireless adapter is going off now, so the
1673 ++ * gamepads are going to become disconnected.
1674 ++ * Unless explicitly disabled, power them down
1675 ++ * so they don't just sit there flashing.
1676 ++ */
1677 ++ if (auto_poweroff && xpad->pad_present)
1678 ++ xpad360w_poweroff_controller(xpad);
1679 ++ } else {
1680 ++ mutex_lock(&input->mutex);
1681 ++ if (input->users)
1682 ++ xpad_stop_input(xpad);
1683 ++ mutex_unlock(&input->mutex);
1684 ++ }
1685 ++
1686 ++ xpad_stop_output(xpad);
1687 ++
1688 ++ return 0;
1689 ++}
1690 ++
1691 ++static int xpad_resume(struct usb_interface *intf)
1692 ++{
1693 ++ struct usb_xpad *xpad = usb_get_intfdata(intf);
1694 ++ struct input_dev *input = xpad->dev;
1695 ++ int retval = 0;
1696 ++
1697 ++ if (xpad->xtype == XTYPE_XBOX360W) {
1698 ++ retval = xpad360w_start_input(xpad);
1699 ++ } else {
1700 ++ mutex_lock(&input->mutex);
1701 ++ if (input->users) {
1702 ++ retval = xpad_start_input(xpad);
1703 ++ } else if (xpad->xtype == XTYPE_XBOXONE) {
1704 ++ /*
1705 ++ * Even if there are no users, we'll send Xbox One pads
1706 ++ * the startup sequence so they don't sit there and
1707 ++ * blink until somebody opens the input device again.
1708 ++ */
1709 ++ retval = xpad_start_xbox_one(xpad);
1710 ++ }
1711 ++ mutex_unlock(&input->mutex);
1712 ++ }
1713 ++
1714 ++ return retval;
1715 ++}
1716 ++
1717 + static struct usb_driver xpad_driver = {
1718 + .name = "xpad",
1719 + .probe = xpad_probe,
1720 + .disconnect = xpad_disconnect,
1721 ++ .suspend = xpad_suspend,
1722 ++ .resume = xpad_resume,
1723 ++ .reset_resume = xpad_resume,
1724 + .id_table = xpad_table,
1725 + };
1726 +
1727 +diff --git a/drivers/net/can/dev.c b/drivers/net/can/dev.c
1728 +index eab132778e67..1dbee1cb3df9 100644
1729 +--- a/drivers/net/can/dev.c
1730 ++++ b/drivers/net/can/dev.c
1731 +@@ -423,6 +423,34 @@ void can_put_echo_skb(struct sk_buff *skb, struct net_device *dev,
1732 + }
1733 + EXPORT_SYMBOL_GPL(can_put_echo_skb);
1734 +
1735 ++struct sk_buff *__can_get_echo_skb(struct net_device *dev, unsigned int idx, u8 *len_ptr)
1736 ++{
1737 ++ struct can_priv *priv = netdev_priv(dev);
1738 ++ struct sk_buff *skb = priv->echo_skb[idx];
1739 ++ struct canfd_frame *cf;
1740 ++
1741 ++ if (idx >= priv->echo_skb_max) {
1742 ++ netdev_err(dev, "%s: BUG! Trying to access can_priv::echo_skb out of bounds (%u/max %u)\n",
1743 ++ __func__, idx, priv->echo_skb_max);
1744 ++ return NULL;
1745 ++ }
1746 ++
1747 ++ if (!skb) {
1748 ++ netdev_err(dev, "%s: BUG! Trying to echo non existing skb: can_priv::echo_skb[%u]\n",
1749 ++ __func__, idx);
1750 ++ return NULL;
1751 ++ }
1752 ++
1753 ++ /* Using "struct canfd_frame::len" for the frame
1754 ++ * length is supported on both CAN and CANFD frames.
1755 ++ */
1756 ++ cf = (struct canfd_frame *)skb->data;
1757 ++ *len_ptr = cf->len;
1758 ++ priv->echo_skb[idx] = NULL;
1759 ++
1760 ++ return skb;
1761 ++}
1762 ++
1763 + /*
1764 + * Get the skb from the stack and loop it back locally
1765 + *
1766 +@@ -432,22 +460,16 @@ EXPORT_SYMBOL_GPL(can_put_echo_skb);
1767 + */
1768 + unsigned int can_get_echo_skb(struct net_device *dev, unsigned int idx)
1769 + {
1770 +- struct can_priv *priv = netdev_priv(dev);
1771 +-
1772 +- BUG_ON(idx >= priv->echo_skb_max);
1773 +-
1774 +- if (priv->echo_skb[idx]) {
1775 +- struct sk_buff *skb = priv->echo_skb[idx];
1776 +- struct can_frame *cf = (struct can_frame *)skb->data;
1777 +- u8 dlc = cf->can_dlc;
1778 ++ struct sk_buff *skb;
1779 ++ u8 len;
1780 +
1781 +- netif_rx(priv->echo_skb[idx]);
1782 +- priv->echo_skb[idx] = NULL;
1783 ++ skb = __can_get_echo_skb(dev, idx, &len);
1784 ++ if (!skb)
1785 ++ return 0;
1786 +
1787 +- return dlc;
1788 +- }
1789 ++ netif_rx(skb);
1790 +
1791 +- return 0;
1792 ++ return len;
1793 + }
1794 + EXPORT_SYMBOL_GPL(can_get_echo_skb);
1795 +
1796 +diff --git a/drivers/net/ethernet/broadcom/genet/bcmmii.c b/drivers/net/ethernet/broadcom/genet/bcmmii.c
1797 +index 4c73feca4842..0565efad6e6e 100644
1798 +--- a/drivers/net/ethernet/broadcom/genet/bcmmii.c
1799 ++++ b/drivers/net/ethernet/broadcom/genet/bcmmii.c
1800 +@@ -491,7 +491,7 @@ static int bcmgenet_mii_of_init(struct bcmgenet_priv *priv)
1801 + if (!compat)
1802 + return -ENOMEM;
1803 +
1804 +- priv->mdio_dn = of_find_compatible_node(dn, NULL, compat);
1805 ++ priv->mdio_dn = of_get_compatible_child(dn, compat);
1806 + kfree(compat);
1807 + if (!priv->mdio_dn) {
1808 + dev_err(kdev, "unable to find MDIO bus node\n");
1809 +diff --git a/drivers/net/wireless/ath/ath10k/mac.c b/drivers/net/wireless/ath/ath10k/mac.c
1810 +index 4644357d291a..398068ad0b62 100644
1811 +--- a/drivers/net/wireless/ath/ath10k/mac.c
1812 ++++ b/drivers/net/wireless/ath/ath10k/mac.c
1813 +@@ -4470,7 +4470,9 @@ static int ath10k_add_interface(struct ieee80211_hw *hw,
1814 + }
1815 +
1816 + ar->free_vdev_map &= ~(1LL << arvif->vdev_id);
1817 ++ spin_lock_bh(&ar->data_lock);
1818 + list_add(&arvif->list, &ar->arvifs);
1819 ++ spin_unlock_bh(&ar->data_lock);
1820 +
1821 + /* It makes no sense to have firmware do keepalives. mac80211 already
1822 + * takes care of this with idle connection polling.
1823 +@@ -4603,7 +4605,9 @@ err_peer_delete:
1824 + err_vdev_delete:
1825 + ath10k_wmi_vdev_delete(ar, arvif->vdev_id);
1826 + ar->free_vdev_map |= 1LL << arvif->vdev_id;
1827 ++ spin_lock_bh(&ar->data_lock);
1828 + list_del(&arvif->list);
1829 ++ spin_unlock_bh(&ar->data_lock);
1830 +
1831 + err:
1832 + if (arvif->beacon_buf) {
1833 +@@ -4647,7 +4651,9 @@ static void ath10k_remove_interface(struct ieee80211_hw *hw,
1834 + arvif->vdev_id, ret);
1835 +
1836 + ar->free_vdev_map |= 1LL << arvif->vdev_id;
1837 ++ spin_lock_bh(&ar->data_lock);
1838 + list_del(&arvif->list);
1839 ++ spin_unlock_bh(&ar->data_lock);
1840 +
1841 + if (arvif->vdev_type == WMI_VDEV_TYPE_AP ||
1842 + arvif->vdev_type == WMI_VDEV_TYPE_IBSS) {
1843 +diff --git a/drivers/net/wireless/cw1200/wsm.c b/drivers/net/wireless/cw1200/wsm.c
1844 +index 3dd46c78c1cc..5a595f9f47ff 100644
1845 +--- a/drivers/net/wireless/cw1200/wsm.c
1846 ++++ b/drivers/net/wireless/cw1200/wsm.c
1847 +@@ -1805,16 +1805,18 @@ static int wsm_buf_reserve(struct wsm_buf *buf, size_t extra_size)
1848 + {
1849 + size_t pos = buf->data - buf->begin;
1850 + size_t size = pos + extra_size;
1851 ++ u8 *tmp;
1852 +
1853 + size = round_up(size, FWLOAD_BLOCK_SIZE);
1854 +
1855 +- buf->begin = krealloc(buf->begin, size, GFP_KERNEL | GFP_DMA);
1856 +- if (buf->begin) {
1857 +- buf->data = &buf->begin[pos];
1858 +- buf->end = &buf->begin[size];
1859 +- return 0;
1860 +- } else {
1861 +- buf->end = buf->data = buf->begin;
1862 ++ tmp = krealloc(buf->begin, size, GFP_KERNEL | GFP_DMA);
1863 ++ if (!tmp) {
1864 ++ wsm_buf_deinit(buf);
1865 + return -ENOMEM;
1866 + }
1867 ++
1868 ++ buf->begin = tmp;
1869 ++ buf->data = &buf->begin[pos];
1870 ++ buf->end = &buf->begin[size];
1871 ++ return 0;
1872 + }
1873 +diff --git a/drivers/net/wireless/iwlwifi/mvm/mac80211.c b/drivers/net/wireless/iwlwifi/mvm/mac80211.c
1874 +index 984cd2f05c4a..7b2a7d848a56 100644
1875 +--- a/drivers/net/wireless/iwlwifi/mvm/mac80211.c
1876 ++++ b/drivers/net/wireless/iwlwifi/mvm/mac80211.c
1877 +@@ -322,8 +322,12 @@ struct ieee80211_regdomain *iwl_mvm_get_regdomain(struct wiphy *wiphy,
1878 + goto out;
1879 + }
1880 +
1881 +- if (changed)
1882 +- *changed = (resp->status == MCC_RESP_NEW_CHAN_PROFILE);
1883 ++ if (changed) {
1884 ++ u32 status = le32_to_cpu(resp->status);
1885 ++
1886 ++ *changed = (status == MCC_RESP_NEW_CHAN_PROFILE ||
1887 ++ status == MCC_RESP_ILLEGAL);
1888 ++ }
1889 +
1890 + regd = iwl_parse_nvm_mcc_info(mvm->trans->dev, mvm->cfg,
1891 + __le32_to_cpu(resp->n_channels),
1892 +@@ -4050,10 +4054,6 @@ static void iwl_mvm_mac_sta_statistics(struct ieee80211_hw *hw,
1893 + struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1894 + struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
1895 +
1896 +- if (!fw_has_capa(&mvm->fw->ucode_capa,
1897 +- IWL_UCODE_TLV_CAPA_RADIO_BEACON_STATS))
1898 +- return;
1899 +-
1900 + /* if beacon filtering isn't on mac80211 does it anyway */
1901 + if (!(vif->driver_flags & IEEE80211_VIF_BEACON_FILTER))
1902 + return;
1903 +diff --git a/drivers/net/wireless/iwlwifi/mvm/nvm.c b/drivers/net/wireless/iwlwifi/mvm/nvm.c
1904 +index 2ee0f6fe56a1..5509c5024352 100644
1905 +--- a/drivers/net/wireless/iwlwifi/mvm/nvm.c
1906 ++++ b/drivers/net/wireless/iwlwifi/mvm/nvm.c
1907 +@@ -667,9 +667,8 @@ iwl_mvm_update_mcc(struct iwl_mvm *mvm, const char *alpha2,
1908 +
1909 + n_channels = __le32_to_cpu(mcc_resp->n_channels);
1910 + IWL_DEBUG_LAR(mvm,
1911 +- "MCC response status: 0x%x. new MCC: 0x%x ('%c%c') change: %d n_chans: %d\n",
1912 +- status, mcc, mcc >> 8, mcc & 0xff,
1913 +- !!(status == MCC_RESP_NEW_CHAN_PROFILE), n_channels);
1914 ++ "MCC response status: 0x%x. new MCC: 0x%x ('%c%c') n_chans: %d\n",
1915 ++ status, mcc, mcc >> 8, mcc & 0xff, n_channels);
1916 +
1917 + resp_len = sizeof(*mcc_resp) + n_channels * sizeof(__le32);
1918 + resp_cp = kmemdup(mcc_resp, resp_len, GFP_KERNEL);
1919 +diff --git a/drivers/net/wireless/mwifiex/cfg80211.c b/drivers/net/wireless/mwifiex/cfg80211.c
1920 +index 9a8982f581c5..1e074eaf613d 100644
1921 +--- a/drivers/net/wireless/mwifiex/cfg80211.c
1922 ++++ b/drivers/net/wireless/mwifiex/cfg80211.c
1923 +@@ -1150,6 +1150,12 @@ mwifiex_cfg80211_change_virtual_intf(struct wiphy *wiphy,
1924 + priv->adapter->curr_iface_comb.p2p_intf--;
1925 + priv->adapter->curr_iface_comb.sta_intf++;
1926 + dev->ieee80211_ptr->iftype = type;
1927 ++ if (mwifiex_deinit_priv_params(priv))
1928 ++ return -1;
1929 ++ if (mwifiex_init_new_priv_params(priv, dev, type))
1930 ++ return -1;
1931 ++ if (mwifiex_sta_init_cmd(priv, false, false))
1932 ++ return -1;
1933 + break;
1934 + case NL80211_IFTYPE_ADHOC:
1935 + if (mwifiex_cfg80211_deinit_p2p(priv))
1936 +@@ -2839,8 +2845,10 @@ int mwifiex_del_virtual_intf(struct wiphy *wiphy, struct wireless_dev *wdev)
1937 +
1938 + mwifiex_stop_net_dev_queue(priv->netdev, adapter);
1939 +
1940 +- skb_queue_walk_safe(&priv->bypass_txq, skb, tmp)
1941 ++ skb_queue_walk_safe(&priv->bypass_txq, skb, tmp) {
1942 ++ skb_unlink(skb, &priv->bypass_txq);
1943 + mwifiex_write_data_complete(priv->adapter, skb, 0, -1);
1944 ++ }
1945 +
1946 + if (netif_carrier_ok(priv->netdev))
1947 + netif_carrier_off(priv->netdev);
1948 +diff --git a/drivers/net/wireless/mwifiex/wmm.c b/drivers/net/wireless/mwifiex/wmm.c
1949 +index acccd6734e3b..ed8b69d1d65c 100644
1950 +--- a/drivers/net/wireless/mwifiex/wmm.c
1951 ++++ b/drivers/net/wireless/mwifiex/wmm.c
1952 +@@ -501,8 +501,10 @@ mwifiex_wmm_del_pkts_in_ralist_node(struct mwifiex_private *priv,
1953 + struct mwifiex_adapter *adapter = priv->adapter;
1954 + struct sk_buff *skb, *tmp;
1955 +
1956 +- skb_queue_walk_safe(&ra_list->skb_head, skb, tmp)
1957 ++ skb_queue_walk_safe(&ra_list->skb_head, skb, tmp) {
1958 ++ skb_unlink(skb, &ra_list->skb_head);
1959 + mwifiex_write_data_complete(adapter, skb, 0, -1);
1960 ++ }
1961 + }
1962 +
1963 + /*
1964 +@@ -598,11 +600,15 @@ mwifiex_clean_txrx(struct mwifiex_private *priv)
1965 + priv->adapter->if_ops.clean_pcie_ring(priv->adapter);
1966 + spin_unlock_irqrestore(&priv->wmm.ra_list_spinlock, flags);
1967 +
1968 +- skb_queue_walk_safe(&priv->tdls_txq, skb, tmp)
1969 ++ skb_queue_walk_safe(&priv->tdls_txq, skb, tmp) {
1970 ++ skb_unlink(skb, &priv->tdls_txq);
1971 + mwifiex_write_data_complete(priv->adapter, skb, 0, -1);
1972 ++ }
1973 +
1974 +- skb_queue_walk_safe(&priv->bypass_txq, skb, tmp)
1975 ++ skb_queue_walk_safe(&priv->bypass_txq, skb, tmp) {
1976 ++ skb_unlink(skb, &priv->bypass_txq);
1977 + mwifiex_write_data_complete(priv->adapter, skb, 0, -1);
1978 ++ }
1979 + atomic_set(&priv->adapter->bypass_tx_pending, 0);
1980 +
1981 + idr_for_each(&priv->ack_status_frames, mwifiex_free_ack_frame, NULL);
1982 +diff --git a/drivers/nfc/nfcmrvl/uart.c b/drivers/nfc/nfcmrvl/uart.c
1983 +index 6c0c301611c4..1b11ded79c4f 100644
1984 +--- a/drivers/nfc/nfcmrvl/uart.c
1985 ++++ b/drivers/nfc/nfcmrvl/uart.c
1986 +@@ -73,10 +73,9 @@ static int nfcmrvl_uart_parse_dt(struct device_node *node,
1987 + struct device_node *matched_node;
1988 + int ret;
1989 +
1990 +- matched_node = of_find_compatible_node(node, NULL, "marvell,nfc-uart");
1991 ++ matched_node = of_get_compatible_child(node, "marvell,nfc-uart");
1992 + if (!matched_node) {
1993 +- matched_node = of_find_compatible_node(node, NULL,
1994 +- "mrvl,nfc-uart");
1995 ++ matched_node = of_get_compatible_child(node, "mrvl,nfc-uart");
1996 + if (!matched_node)
1997 + return -ENODEV;
1998 + }
1999 +diff --git a/drivers/of/base.c b/drivers/of/base.c
2000 +index 31341290cd91..c6e019208d17 100644
2001 +--- a/drivers/of/base.c
2002 ++++ b/drivers/of/base.c
2003 +@@ -712,6 +712,31 @@ struct device_node *of_get_next_available_child(const struct device_node *node,
2004 + }
2005 + EXPORT_SYMBOL(of_get_next_available_child);
2006 +
2007 ++/**
2008 ++ * of_get_compatible_child - Find compatible child node
2009 ++ * @parent: parent node
2010 ++ * @compatible: compatible string
2011 ++ *
2012 ++ * Lookup child node whose compatible property contains the given compatible
2013 ++ * string.
2014 ++ *
2015 ++ * Returns a node pointer with refcount incremented, use of_node_put() on it
2016 ++ * when done; or NULL if not found.
2017 ++ */
2018 ++struct device_node *of_get_compatible_child(const struct device_node *parent,
2019 ++ const char *compatible)
2020 ++{
2021 ++ struct device_node *child;
2022 ++
2023 ++ for_each_child_of_node(parent, child) {
2024 ++ if (of_device_is_compatible(child, compatible))
2025 ++ break;
2026 ++ }
2027 ++
2028 ++ return child;
2029 ++}
2030 ++EXPORT_SYMBOL(of_get_compatible_child);
2031 ++
2032 + /**
2033 + * of_get_child_by_name - Find the child node by name for a given parent
2034 + * @node: parent node
2035 +diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
2036 +index 18b19744398a..ff5df33fc740 100644
2037 +--- a/drivers/scsi/qla2xxx/qla_os.c
2038 ++++ b/drivers/scsi/qla2xxx/qla_os.c
2039 +@@ -685,6 +685,11 @@ qla2xxx_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd)
2040 + srb_t *sp;
2041 + int rval;
2042 +
2043 ++ if (unlikely(test_bit(UNLOADING, &base_vha->dpc_flags))) {
2044 ++ cmd->result = DID_NO_CONNECT << 16;
2045 ++ goto qc24_fail_command;
2046 ++ }
2047 ++
2048 + if (ha->flags.eeh_busy) {
2049 + if (ha->flags.pci_channel_io_perm_failure) {
2050 + ql_dbg(ql_dbg_aer, vha, 0x9010,
2051 +diff --git a/drivers/scsi/ufs/ufs.h b/drivers/scsi/ufs/ufs.h
2052 +index 42c459a9d3fe..ce5234555cc9 100644
2053 +--- a/drivers/scsi/ufs/ufs.h
2054 ++++ b/drivers/scsi/ufs/ufs.h
2055 +@@ -45,6 +45,7 @@
2056 + #define QUERY_DESC_MIN_SIZE 2
2057 + #define QUERY_OSF_SIZE (GENERAL_UPIU_REQUEST_SIZE - \
2058 + (sizeof(struct utp_upiu_header)))
2059 ++#define RESPONSE_UPIU_SENSE_DATA_LENGTH 18
2060 +
2061 + #define UPIU_HEADER_DWORD(byte3, byte2, byte1, byte0)\
2062 + cpu_to_be32((byte3 << 24) | (byte2 << 16) |\
2063 +@@ -383,7 +384,7 @@ struct utp_cmd_rsp {
2064 + __be32 residual_transfer_count;
2065 + __be32 reserved[4];
2066 + __be16 sense_data_len;
2067 +- u8 sense_data[18];
2068 ++ u8 sense_data[RESPONSE_UPIU_SENSE_DATA_LENGTH];
2069 + };
2070 +
2071 + /**
2072 +diff --git a/drivers/scsi/ufs/ufshcd-pci.c b/drivers/scsi/ufs/ufshcd-pci.c
2073 +index d15eaa466c59..52b546fb509b 100644
2074 +--- a/drivers/scsi/ufs/ufshcd-pci.c
2075 ++++ b/drivers/scsi/ufs/ufshcd-pci.c
2076 +@@ -104,6 +104,7 @@ static void ufshcd_pci_remove(struct pci_dev *pdev)
2077 + pm_runtime_forbid(&pdev->dev);
2078 + pm_runtime_get_noresume(&pdev->dev);
2079 + ufshcd_remove(hba);
2080 ++ ufshcd_dealloc_host(hba);
2081 + }
2082 +
2083 + /**
2084 +@@ -147,6 +148,7 @@ ufshcd_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
2085 + err = ufshcd_init(hba, mmio_base, pdev->irq);
2086 + if (err) {
2087 + dev_err(&pdev->dev, "Initialization failed\n");
2088 ++ ufshcd_dealloc_host(hba);
2089 + return err;
2090 + }
2091 +
2092 +diff --git a/drivers/scsi/ufs/ufshcd-pltfrm.c b/drivers/scsi/ufs/ufshcd-pltfrm.c
2093 +index 9714f2a8b329..f58abfcdfe81 100644
2094 +--- a/drivers/scsi/ufs/ufshcd-pltfrm.c
2095 ++++ b/drivers/scsi/ufs/ufshcd-pltfrm.c
2096 +@@ -161,7 +161,7 @@ static int ufshcd_populate_vreg(struct device *dev, const char *name,
2097 + if (ret) {
2098 + dev_err(dev, "%s: unable to find %s err %d\n",
2099 + __func__, prop_name, ret);
2100 +- goto out_free;
2101 ++ goto out;
2102 + }
2103 +
2104 + vreg->min_uA = 0;
2105 +@@ -183,9 +183,6 @@ static int ufshcd_populate_vreg(struct device *dev, const char *name,
2106 +
2107 + goto out;
2108 +
2109 +-out_free:
2110 +- devm_kfree(dev, vreg);
2111 +- vreg = NULL;
2112 + out:
2113 + if (!ret)
2114 + *out_vreg = vreg;
2115 +diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c
2116 +index 8c58adadb728..c94d465de941 100644
2117 +--- a/drivers/scsi/ufs/ufshcd.c
2118 ++++ b/drivers/scsi/ufs/ufshcd.c
2119 +@@ -585,6 +585,21 @@ int ufshcd_hold(struct ufs_hba *hba, bool async)
2120 + start:
2121 + switch (hba->clk_gating.state) {
2122 + case CLKS_ON:
2123 ++ /*
2124 ++ * Wait for the ungate work to complete if in progress.
2125 ++ * Though the clocks may be in ON state, the link could
2126 ++ * still be in hibner8 state if hibern8 is allowed
2127 ++ * during clock gating.
2128 ++ * Make sure we exit hibern8 state also in addition to
2129 ++ * clocks being ON.
2130 ++ */
2131 ++ if (ufshcd_can_hibern8_during_gating(hba) &&
2132 ++ ufshcd_is_link_hibern8(hba)) {
2133 ++ spin_unlock_irqrestore(hba->host->host_lock, flags);
2134 ++ flush_work(&hba->clk_gating.ungate_work);
2135 ++ spin_lock_irqsave(hba->host->host_lock, flags);
2136 ++ goto start;
2137 ++ }
2138 + break;
2139 + case REQ_CLKS_OFF:
2140 + if (cancel_delayed_work(&hba->clk_gating.gate_work)) {
2141 +@@ -813,10 +828,14 @@ static inline void ufshcd_copy_sense_data(struct ufshcd_lrb *lrbp)
2142 + int len;
2143 + if (lrbp->sense_buffer &&
2144 + ufshcd_get_rsp_upiu_data_seg_len(lrbp->ucd_rsp_ptr)) {
2145 ++ int len_to_copy;
2146 ++
2147 + len = be16_to_cpu(lrbp->ucd_rsp_ptr->sr.sense_data_len);
2148 ++ len_to_copy = min_t(int, RESPONSE_UPIU_SENSE_DATA_LENGTH, len);
2149 ++
2150 + memcpy(lrbp->sense_buffer,
2151 + lrbp->ucd_rsp_ptr->sr.sense_data,
2152 +- min_t(int, len, SCSI_SENSE_BUFFERSIZE));
2153 ++ min_t(int, len_to_copy, SCSI_SENSE_BUFFERSIZE));
2154 + }
2155 + }
2156 +
2157 +@@ -5251,7 +5270,10 @@ EXPORT_SYMBOL(ufshcd_system_suspend);
2158 +
2159 + int ufshcd_system_resume(struct ufs_hba *hba)
2160 + {
2161 +- if (!hba || !hba->is_powered || pm_runtime_suspended(hba->dev))
2162 ++ if (!hba)
2163 ++ return -EINVAL;
2164 ++
2165 ++ if (!hba->is_powered || pm_runtime_suspended(hba->dev))
2166 + /*
2167 + * Let the runtime resume take care of resuming
2168 + * if runtime suspended.
2169 +@@ -5272,7 +5294,10 @@ EXPORT_SYMBOL(ufshcd_system_resume);
2170 + */
2171 + int ufshcd_runtime_suspend(struct ufs_hba *hba)
2172 + {
2173 +- if (!hba || !hba->is_powered)
2174 ++ if (!hba)
2175 ++ return -EINVAL;
2176 ++
2177 ++ if (!hba->is_powered)
2178 + return 0;
2179 +
2180 + return ufshcd_suspend(hba, UFS_RUNTIME_PM);
2181 +@@ -5302,10 +5327,13 @@ EXPORT_SYMBOL(ufshcd_runtime_suspend);
2182 + */
2183 + int ufshcd_runtime_resume(struct ufs_hba *hba)
2184 + {
2185 +- if (!hba || !hba->is_powered)
2186 ++ if (!hba)
2187 ++ return -EINVAL;
2188 ++
2189 ++ if (!hba->is_powered)
2190 + return 0;
2191 +- else
2192 +- return ufshcd_resume(hba, UFS_RUNTIME_PM);
2193 ++
2194 ++ return ufshcd_resume(hba, UFS_RUNTIME_PM);
2195 + }
2196 + EXPORT_SYMBOL(ufshcd_runtime_resume);
2197 +
2198 +@@ -5357,8 +5385,6 @@ void ufshcd_remove(struct ufs_hba *hba)
2199 + ufshcd_disable_intr(hba, hba->intr_mask);
2200 + ufshcd_hba_stop(hba);
2201 +
2202 +- scsi_host_put(hba->host);
2203 +-
2204 + ufshcd_exit_clk_gating(hba);
2205 + if (ufshcd_is_clkscaling_enabled(hba))
2206 + devfreq_remove_device(hba->devfreq);
2207 +@@ -5483,15 +5509,47 @@ static int ufshcd_devfreq_target(struct device *dev,
2208 + {
2209 + int err = 0;
2210 + struct ufs_hba *hba = dev_get_drvdata(dev);
2211 ++ bool release_clk_hold = false;
2212 ++ unsigned long irq_flags;
2213 +
2214 + if (!ufshcd_is_clkscaling_enabled(hba))
2215 + return -EINVAL;
2216 +
2217 ++ spin_lock_irqsave(hba->host->host_lock, irq_flags);
2218 ++ if (ufshcd_eh_in_progress(hba)) {
2219 ++ spin_unlock_irqrestore(hba->host->host_lock, irq_flags);
2220 ++ return 0;
2221 ++ }
2222 ++
2223 ++ if (ufshcd_is_clkgating_allowed(hba) &&
2224 ++ (hba->clk_gating.state != CLKS_ON)) {
2225 ++ if (cancel_delayed_work(&hba->clk_gating.gate_work)) {
2226 ++ /* hold the vote until the scaling work is completed */
2227 ++ hba->clk_gating.active_reqs++;
2228 ++ release_clk_hold = true;
2229 ++ hba->clk_gating.state = CLKS_ON;
2230 ++ } else {
2231 ++ /*
2232 ++ * Clock gating work seems to be running in parallel
2233 ++ * hence skip scaling work to avoid deadlock between
2234 ++ * current scaling work and gating work.
2235 ++ */
2236 ++ spin_unlock_irqrestore(hba->host->host_lock, irq_flags);
2237 ++ return 0;
2238 ++ }
2239 ++ }
2240 ++ spin_unlock_irqrestore(hba->host->host_lock, irq_flags);
2241 ++
2242 + if (*freq == UINT_MAX)
2243 + err = ufshcd_scale_clks(hba, true);
2244 + else if (*freq == 0)
2245 + err = ufshcd_scale_clks(hba, false);
2246 +
2247 ++ spin_lock_irqsave(hba->host->host_lock, irq_flags);
2248 ++ if (release_clk_hold)
2249 ++ __ufshcd_release(hba);
2250 ++ spin_unlock_irqrestore(hba->host->host_lock, irq_flags);
2251 ++
2252 + return err;
2253 + }
2254 +
2255 +@@ -5673,7 +5731,6 @@ exit_gating:
2256 + ufshcd_exit_clk_gating(hba);
2257 + out_disable:
2258 + hba->is_irq_enabled = false;
2259 +- scsi_host_put(host);
2260 + ufshcd_hba_exit(hba);
2261 + out_error:
2262 + return err;
2263 +diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
2264 +index b1ec202099b2..b74de014cef1 100644
2265 +--- a/drivers/tty/n_tty.c
2266 ++++ b/drivers/tty/n_tty.c
2267 +@@ -165,15 +165,29 @@ static inline int tty_put_user(struct tty_struct *tty, unsigned char x,
2268 + return put_user(x, ptr);
2269 + }
2270 +
2271 ++/* If we are not echoing the data, perhaps this is a secret so erase it */
2272 ++static inline void zero_buffer(struct tty_struct *tty, u8 *buffer, int size)
2273 ++{
2274 ++ bool icanon = !!L_ICANON(tty);
2275 ++ bool no_echo = !L_ECHO(tty);
2276 ++
2277 ++ if (icanon && no_echo)
2278 ++ memset(buffer, 0x00, size);
2279 ++}
2280 ++
2281 + static inline int tty_copy_to_user(struct tty_struct *tty,
2282 + void __user *to,
2283 +- const void *from,
2284 ++ void *from,
2285 + unsigned long n)
2286 + {
2287 + struct n_tty_data *ldata = tty->disc_data;
2288 ++ int retval;
2289 +
2290 + tty_audit_add_data(tty, from, n, ldata->icanon);
2291 +- return copy_to_user(to, from, n);
2292 ++ retval = copy_to_user(to, from, n);
2293 ++ if (!retval)
2294 ++ zero_buffer(tty, from, n);
2295 ++ return retval;
2296 + }
2297 +
2298 + /**
2299 +@@ -2005,6 +2019,7 @@ static int copy_from_read_buf(struct tty_struct *tty,
2300 + is_eof = n == 1 && read_buf(ldata, tail) == EOF_CHAR(tty);
2301 + tty_audit_add_data(tty, read_buf_addr(ldata, tail), n,
2302 + ldata->icanon);
2303 ++ zero_buffer(tty, read_buf_addr(ldata, tail), n);
2304 + smp_store_release(&ldata->read_tail, ldata->read_tail + n);
2305 + /* Turn single EOF into zero-length read */
2306 + if (L_EXTPROC(tty) && ldata->icanon && is_eof &&
2307 +diff --git a/drivers/tty/tty_buffer.c b/drivers/tty/tty_buffer.c
2308 +index 8f3566cde3eb..355e9cad680d 100644
2309 +--- a/drivers/tty/tty_buffer.c
2310 ++++ b/drivers/tty/tty_buffer.c
2311 +@@ -454,6 +454,8 @@ receive_buf(struct tty_struct *tty, struct tty_buffer *head, int count)
2312 + if (count && disc->ops->receive_buf)
2313 + disc->ops->receive_buf(tty, p, f, count);
2314 + }
2315 ++ if (count > 0)
2316 ++ memset(p, 0, count);
2317 + return count;
2318 + }
2319 +
2320 +diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
2321 +index 2facffea2ee0..f7af730aae82 100644
2322 +--- a/drivers/usb/core/hub.c
2323 ++++ b/drivers/usb/core/hub.c
2324 +@@ -2757,7 +2757,9 @@ static int hub_port_reset(struct usb_hub *hub, int port1,
2325 + USB_PORT_FEAT_C_BH_PORT_RESET);
2326 + usb_clear_port_feature(hub->hdev, port1,
2327 + USB_PORT_FEAT_C_PORT_LINK_STATE);
2328 +- usb_clear_port_feature(hub->hdev, port1,
2329 ++
2330 ++ if (udev)
2331 ++ usb_clear_port_feature(hub->hdev, port1,
2332 + USB_PORT_FEAT_C_CONNECTION);
2333 +
2334 + /*
2335 +diff --git a/drivers/usb/host/xhci-hub.c b/drivers/usb/host/xhci-hub.c
2336 +index aee29604bd79..5d21cd8359d4 100644
2337 +--- a/drivers/usb/host/xhci-hub.c
2338 ++++ b/drivers/usb/host/xhci-hub.c
2339 +@@ -744,7 +744,7 @@ static u32 xhci_get_port_status(struct usb_hcd *hcd,
2340 + status |= USB_PORT_STAT_SUSPEND;
2341 + }
2342 + if ((raw_port_status & PORT_PLS_MASK) == XDEV_RESUME &&
2343 +- !DEV_SUPERSPEED_ANY(raw_port_status)) {
2344 ++ !DEV_SUPERSPEED_ANY(raw_port_status) && hcd->speed < HCD_USB3) {
2345 + if ((raw_port_status & PORT_RESET) ||
2346 + !(raw_port_status & PORT_PE))
2347 + return 0xffffffff;
2348 +@@ -790,7 +790,7 @@ static u32 xhci_get_port_status(struct usb_hcd *hcd,
2349 + time_left = wait_for_completion_timeout(
2350 + &bus_state->rexit_done[wIndex],
2351 + msecs_to_jiffies(
2352 +- XHCI_MAX_REXIT_TIMEOUT));
2353 ++ XHCI_MAX_REXIT_TIMEOUT_MS));
2354 + spin_lock_irqsave(&xhci->lock, flags);
2355 +
2356 + if (time_left) {
2357 +@@ -804,7 +804,7 @@ static u32 xhci_get_port_status(struct usb_hcd *hcd,
2358 + } else {
2359 + int port_status = readl(port_array[wIndex]);
2360 + xhci_warn(xhci, "Port resume took longer than %i msec, port status = 0x%x\n",
2361 +- XHCI_MAX_REXIT_TIMEOUT,
2362 ++ XHCI_MAX_REXIT_TIMEOUT_MS,
2363 + port_status);
2364 + status |= USB_PORT_STAT_SUSPEND;
2365 + clear_bit(wIndex, &bus_state->rexit_ports);
2366 +@@ -1298,13 +1298,16 @@ int xhci_bus_suspend(struct usb_hcd *hcd)
2367 + __le32 __iomem **port_array;
2368 + struct xhci_bus_state *bus_state;
2369 + unsigned long flags;
2370 ++ u32 portsc_buf[USB_MAXCHILDREN];
2371 ++ bool wake_enabled;
2372 +
2373 + max_ports = xhci_get_ports(hcd, &port_array);
2374 + bus_state = &xhci->bus_state[hcd_index(hcd)];
2375 ++ wake_enabled = hcd->self.root_hub->do_remote_wakeup;
2376 +
2377 + spin_lock_irqsave(&xhci->lock, flags);
2378 +
2379 +- if (hcd->self.root_hub->do_remote_wakeup) {
2380 ++ if (wake_enabled) {
2381 + if (bus_state->resuming_ports || /* USB2 */
2382 + bus_state->port_remote_wakeup) { /* USB3 */
2383 + spin_unlock_irqrestore(&xhci->lock, flags);
2384 +@@ -1312,26 +1315,36 @@ int xhci_bus_suspend(struct usb_hcd *hcd)
2385 + return -EBUSY;
2386 + }
2387 + }
2388 +-
2389 +- port_index = max_ports;
2390 ++ /*
2391 ++ * Prepare ports for suspend, but don't write anything before all ports
2392 ++ * are checked and we know bus suspend can proceed
2393 ++ */
2394 + bus_state->bus_suspended = 0;
2395 ++ port_index = max_ports;
2396 + while (port_index--) {
2397 +- /* suspend the port if the port is not suspended */
2398 + u32 t1, t2;
2399 +- int slot_id;
2400 +
2401 + t1 = readl(port_array[port_index]);
2402 + t2 = xhci_port_state_to_neutral(t1);
2403 ++ portsc_buf[port_index] = 0;
2404 +
2405 +- if ((t1 & PORT_PE) && !(t1 & PORT_PLS_MASK)) {
2406 +- xhci_dbg(xhci, "port %d not suspended\n", port_index);
2407 +- slot_id = xhci_find_slot_id_by_port(hcd, xhci,
2408 +- port_index + 1);
2409 +- if (slot_id) {
2410 ++ /* Bail out if a USB3 port has a new device in link training */
2411 ++ if ((t1 & PORT_PLS_MASK) == XDEV_POLLING) {
2412 ++ bus_state->bus_suspended = 0;
2413 ++ spin_unlock_irqrestore(&xhci->lock, flags);
2414 ++ xhci_dbg(xhci, "Bus suspend bailout, port in polling\n");
2415 ++ return -EBUSY;
2416 ++ }
2417 ++
2418 ++ /* suspend ports in U0, or bail out for new connect changes */
2419 ++ if ((t1 & PORT_PE) && (t1 & PORT_PLS_MASK) == XDEV_U0) {
2420 ++ if ((t1 & PORT_CSC) && wake_enabled) {
2421 ++ bus_state->bus_suspended = 0;
2422 + spin_unlock_irqrestore(&xhci->lock, flags);
2423 +- xhci_stop_device(xhci, slot_id, 1);
2424 +- spin_lock_irqsave(&xhci->lock, flags);
2425 ++ xhci_dbg(xhci, "Bus suspend bailout, port connect change\n");
2426 ++ return -EBUSY;
2427 + }
2428 ++ xhci_dbg(xhci, "port %d not suspended\n", port_index);
2429 + t2 &= ~PORT_PLS_MASK;
2430 + t2 |= PORT_LINK_STROBE | XDEV_U3;
2431 + set_bit(port_index, &bus_state->bus_suspended);
2432 +@@ -1340,7 +1353,7 @@ int xhci_bus_suspend(struct usb_hcd *hcd)
2433 + * including the USB 3.0 roothub, but only if CONFIG_PM
2434 + * is enabled, so also enable remote wake here.
2435 + */
2436 +- if (hcd->self.root_hub->do_remote_wakeup) {
2437 ++ if (wake_enabled) {
2438 + if (t1 & PORT_CONNECT) {
2439 + t2 |= PORT_WKOC_E | PORT_WKDISC_E;
2440 + t2 &= ~PORT_WKCONN_E;
2441 +@@ -1353,7 +1366,26 @@ int xhci_bus_suspend(struct usb_hcd *hcd)
2442 +
2443 + t1 = xhci_port_state_to_neutral(t1);
2444 + if (t1 != t2)
2445 +- writel(t2, port_array[port_index]);
2446 ++ portsc_buf[port_index] = t2;
2447 ++ }
2448 ++
2449 ++ /* write port settings, stopping and suspending ports if needed */
2450 ++ port_index = max_ports;
2451 ++ while (port_index--) {
2452 ++ if (!portsc_buf[port_index])
2453 ++ continue;
2454 ++ if (test_bit(port_index, &bus_state->bus_suspended)) {
2455 ++ int slot_id;
2456 ++
2457 ++ slot_id = xhci_find_slot_id_by_port(hcd, xhci,
2458 ++ port_index + 1);
2459 ++ if (slot_id) {
2460 ++ spin_unlock_irqrestore(&xhci->lock, flags);
2461 ++ xhci_stop_device(xhci, slot_id, 1);
2462 ++ spin_lock_irqsave(&xhci->lock, flags);
2463 ++ }
2464 ++ }
2465 ++ writel(portsc_buf[port_index], port_array[port_index]);
2466 + }
2467 + hcd->state = HC_STATE_SUSPENDED;
2468 + bus_state->next_statechange = jiffies + msecs_to_jiffies(10);
2469 +diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c
2470 +index ece0787d62bf..845fa426fa0d 100644
2471 +--- a/drivers/usb/host/xhci-ring.c
2472 ++++ b/drivers/usb/host/xhci-ring.c
2473 +@@ -1673,7 +1673,7 @@ static void handle_port_status(struct xhci_hcd *xhci,
2474 + * RExit to a disconnect state). If so, let the the driver know it's
2475 + * out of the RExit state.
2476 + */
2477 +- if (!DEV_SUPERSPEED_ANY(temp) &&
2478 ++ if (!DEV_SUPERSPEED_ANY(temp) && hcd->speed < HCD_USB3 &&
2479 + test_and_clear_bit(faked_port_index,
2480 + &bus_state->rexit_ports)) {
2481 + complete(&bus_state->rexit_done[faked_port_index]);
2482 +diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h
2483 +index 84d8871755b7..0635cea42e6f 100644
2484 +--- a/drivers/usb/host/xhci.h
2485 ++++ b/drivers/usb/host/xhci.h
2486 +@@ -1490,7 +1490,7 @@ struct xhci_bus_state {
2487 + * It can take up to 20 ms to transition from RExit to U0 on the
2488 + * Intel Lynx Point LP xHCI host.
2489 + */
2490 +-#define XHCI_MAX_REXIT_TIMEOUT (20 * 1000)
2491 ++#define XHCI_MAX_REXIT_TIMEOUT_MS 20
2492 +
2493 + static inline unsigned int hcd_index(struct usb_hcd *hcd)
2494 + {
2495 +diff --git a/fs/9p/vfs_dir.c b/fs/9p/vfs_dir.c
2496 +index 5cc00e56206e..7d889f56b8e7 100644
2497 +--- a/fs/9p/vfs_dir.c
2498 ++++ b/fs/9p/vfs_dir.c
2499 +@@ -76,15 +76,6 @@ static inline int dt_type(struct p9_wstat *mistat)
2500 + return rettype;
2501 + }
2502 +
2503 +-static void p9stat_init(struct p9_wstat *stbuf)
2504 +-{
2505 +- stbuf->name = NULL;
2506 +- stbuf->uid = NULL;
2507 +- stbuf->gid = NULL;
2508 +- stbuf->muid = NULL;
2509 +- stbuf->extension = NULL;
2510 +-}
2511 +-
2512 + /**
2513 + * v9fs_alloc_rdir_buf - Allocate buffer used for read and readdir
2514 + * @filp: opened file structure
2515 +@@ -145,12 +136,10 @@ static int v9fs_dir_readdir(struct file *file, struct dir_context *ctx)
2516 + rdir->tail = n;
2517 + }
2518 + while (rdir->head < rdir->tail) {
2519 +- p9stat_init(&st);
2520 + err = p9stat_read(fid->clnt, rdir->buf + rdir->head,
2521 + rdir->tail - rdir->head, &st);
2522 + if (err) {
2523 + p9_debug(P9_DEBUG_VFS, "returned %d\n", err);
2524 +- p9stat_free(&st);
2525 + return -EIO;
2526 + }
2527 + reclen = st.size+2;
2528 +diff --git a/fs/bfs/inode.c b/fs/bfs/inode.c
2529 +index fdcb4d69f430..4714c55c1ae5 100644
2530 +--- a/fs/bfs/inode.c
2531 ++++ b/fs/bfs/inode.c
2532 +@@ -350,7 +350,8 @@ static int bfs_fill_super(struct super_block *s, void *data, int silent)
2533 +
2534 + s->s_magic = BFS_MAGIC;
2535 +
2536 +- if (le32_to_cpu(bfs_sb->s_start) > le32_to_cpu(bfs_sb->s_end)) {
2537 ++ if (le32_to_cpu(bfs_sb->s_start) > le32_to_cpu(bfs_sb->s_end) ||
2538 ++ le32_to_cpu(bfs_sb->s_start) < BFS_BSIZE) {
2539 + printf("Superblock is corrupted\n");
2540 + goto out1;
2541 + }
2542 +@@ -359,9 +360,11 @@ static int bfs_fill_super(struct super_block *s, void *data, int silent)
2543 + sizeof(struct bfs_inode)
2544 + + BFS_ROOT_INO - 1;
2545 + imap_len = (info->si_lasti / 8) + 1;
2546 +- info->si_imap = kzalloc(imap_len, GFP_KERNEL);
2547 +- if (!info->si_imap)
2548 ++ info->si_imap = kzalloc(imap_len, GFP_KERNEL | __GFP_NOWARN);
2549 ++ if (!info->si_imap) {
2550 ++ printf("Cannot allocate %u bytes\n", imap_len);
2551 + goto out1;
2552 ++ }
2553 + for (i = 0; i < BFS_ROOT_INO; i++)
2554 + set_bit(i, info->si_imap);
2555 +
2556 +diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
2557 +index 80cd28456f08..13ff0fdae03e 100644
2558 +--- a/fs/btrfs/extent-tree.c
2559 ++++ b/fs/btrfs/extent-tree.c
2560 +@@ -10708,17 +10708,9 @@ int btrfs_trim_fs(struct btrfs_root *root, struct fstrim_range *range)
2561 + u64 start;
2562 + u64 end;
2563 + u64 trimmed = 0;
2564 +- u64 total_bytes = btrfs_super_total_bytes(fs_info->super_copy);
2565 + int ret = 0;
2566 +
2567 +- /*
2568 +- * try to trim all FS space, our block group may start from non-zero.
2569 +- */
2570 +- if (range->len == total_bytes)
2571 +- cache = btrfs_lookup_first_block_group(fs_info, range->start);
2572 +- else
2573 +- cache = btrfs_lookup_block_group(fs_info, range->start);
2574 +-
2575 ++ cache = btrfs_lookup_first_block_group(fs_info, range->start);
2576 + while (cache) {
2577 + if (cache->key.objectid >= (range->start + range->len)) {
2578 + btrfs_put_block_group(cache);
2579 +diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
2580 +index 150d3c891815..3379490ce54d 100644
2581 +--- a/fs/btrfs/ioctl.c
2582 ++++ b/fs/btrfs/ioctl.c
2583 +@@ -378,7 +378,6 @@ static noinline int btrfs_ioctl_fitrim(struct file *file, void __user *arg)
2584 + struct fstrim_range range;
2585 + u64 minlen = ULLONG_MAX;
2586 + u64 num_devices = 0;
2587 +- u64 total_bytes = btrfs_super_total_bytes(fs_info->super_copy);
2588 + int ret;
2589 +
2590 + if (!capable(CAP_SYS_ADMIN))
2591 +@@ -402,11 +401,15 @@ static noinline int btrfs_ioctl_fitrim(struct file *file, void __user *arg)
2592 + return -EOPNOTSUPP;
2593 + if (copy_from_user(&range, arg, sizeof(range)))
2594 + return -EFAULT;
2595 +- if (range.start > total_bytes ||
2596 +- range.len < fs_info->sb->s_blocksize)
2597 ++
2598 ++ /*
2599 ++ * NOTE: Don't truncate the range using super->total_bytes. Bytenr of
2600 ++ * block group is in the logical address space, which can be any
2601 ++ * sectorsize aligned bytenr in the range [0, U64_MAX].
2602 ++ */
2603 ++ if (range.len < fs_info->sb->s_blocksize)
2604 + return -EINVAL;
2605 +
2606 +- range.len = min(range.len, total_bytes - range.start);
2607 + range.minlen = max(range.minlen, minlen);
2608 + ret = btrfs_trim_fs(fs_info->tree_root, &range);
2609 + if (ret < 0)
2610 +diff --git a/fs/gfs2/ops_fstype.c b/fs/gfs2/ops_fstype.c
2611 +index d9178388cf48..de7143e2b361 100644
2612 +--- a/fs/gfs2/ops_fstype.c
2613 ++++ b/fs/gfs2/ops_fstype.c
2614 +@@ -71,13 +71,13 @@ static struct gfs2_sbd *init_sbd(struct super_block *sb)
2615 + if (!sdp)
2616 + return NULL;
2617 +
2618 +- sb->s_fs_info = sdp;
2619 + sdp->sd_vfs = sb;
2620 + sdp->sd_lkstats = alloc_percpu(struct gfs2_pcpu_lkstats);
2621 + if (!sdp->sd_lkstats) {
2622 + kfree(sdp);
2623 + return NULL;
2624 + }
2625 ++ sb->s_fs_info = sdp;
2626 +
2627 + set_bit(SDF_NOJOURNALID, &sdp->sd_flags);
2628 + gfs2_tune_init(&sdp->sd_tune);
2629 +diff --git a/fs/namei.c b/fs/namei.c
2630 +index de57dd59d95f..40049d61ef37 100644
2631 +--- a/fs/namei.c
2632 ++++ b/fs/namei.c
2633 +@@ -869,6 +869,8 @@ static inline void put_link(struct nameidata *nd)
2634 +
2635 + int sysctl_protected_symlinks __read_mostly = 0;
2636 + int sysctl_protected_hardlinks __read_mostly = 0;
2637 ++int sysctl_protected_fifos __read_mostly;
2638 ++int sysctl_protected_regular __read_mostly;
2639 +
2640 + /**
2641 + * may_follow_link - Check symlink following for unsafe situations
2642 +@@ -982,6 +984,45 @@ static int may_linkat(struct path *link)
2643 + return -EPERM;
2644 + }
2645 +
2646 ++/**
2647 ++ * may_create_in_sticky - Check whether an O_CREAT open in a sticky directory
2648 ++ * should be allowed, or not, on files that already
2649 ++ * exist.
2650 ++ * @dir: the sticky parent directory
2651 ++ * @inode: the inode of the file to open
2652 ++ *
2653 ++ * Block an O_CREAT open of a FIFO (or a regular file) when:
2654 ++ * - sysctl_protected_fifos (or sysctl_protected_regular) is enabled
2655 ++ * - the file already exists
2656 ++ * - we are in a sticky directory
2657 ++ * - we don't own the file
2658 ++ * - the owner of the directory doesn't own the file
2659 ++ * - the directory is world writable
2660 ++ * If the sysctl_protected_fifos (or sysctl_protected_regular) is set to 2
2661 ++ * the directory doesn't have to be world writable: being group writable will
2662 ++ * be enough.
2663 ++ *
2664 ++ * Returns 0 if the open is allowed, -ve on error.
2665 ++ */
2666 ++static int may_create_in_sticky(struct dentry * const dir,
2667 ++ struct inode * const inode)
2668 ++{
2669 ++ if ((!sysctl_protected_fifos && S_ISFIFO(inode->i_mode)) ||
2670 ++ (!sysctl_protected_regular && S_ISREG(inode->i_mode)) ||
2671 ++ likely(!(dir->d_inode->i_mode & S_ISVTX)) ||
2672 ++ uid_eq(inode->i_uid, dir->d_inode->i_uid) ||
2673 ++ uid_eq(current_fsuid(), inode->i_uid))
2674 ++ return 0;
2675 ++
2676 ++ if (likely(dir->d_inode->i_mode & 0002) ||
2677 ++ (dir->d_inode->i_mode & 0020 &&
2678 ++ ((sysctl_protected_fifos >= 2 && S_ISFIFO(inode->i_mode)) ||
2679 ++ (sysctl_protected_regular >= 2 && S_ISREG(inode->i_mode))))) {
2680 ++ return -EACCES;
2681 ++ }
2682 ++ return 0;
2683 ++}
2684 ++
2685 + static __always_inline
2686 + const char *get_link(struct nameidata *nd)
2687 + {
2688 +@@ -3166,9 +3207,15 @@ finish_open:
2689 + error = -ELOOP;
2690 + goto out;
2691 + }
2692 +- error = -EISDIR;
2693 +- if ((open_flag & O_CREAT) && d_is_dir(nd->path.dentry))
2694 +- goto out;
2695 ++ if (open_flag & O_CREAT) {
2696 ++ error = -EISDIR;
2697 ++ if (d_is_dir(nd->path.dentry))
2698 ++ goto out;
2699 ++ error = may_create_in_sticky(dir,
2700 ++ d_backing_inode(nd->path.dentry));
2701 ++ if (unlikely(error))
2702 ++ goto out;
2703 ++ }
2704 + error = -ENOTDIR;
2705 + if ((nd->flags & LOOKUP_DIRECTORY) && !d_can_lookup(nd->path.dentry))
2706 + goto out;
2707 +diff --git a/include/linux/can/dev.h b/include/linux/can/dev.h
2708 +index 5f5270941ba0..f7178f44825b 100644
2709 +--- a/include/linux/can/dev.h
2710 ++++ b/include/linux/can/dev.h
2711 +@@ -154,6 +154,7 @@ void can_change_state(struct net_device *dev, struct can_frame *cf,
2712 +
2713 + void can_put_echo_skb(struct sk_buff *skb, struct net_device *dev,
2714 + unsigned int idx);
2715 ++struct sk_buff *__can_get_echo_skb(struct net_device *dev, unsigned int idx, u8 *len_ptr);
2716 + unsigned int can_get_echo_skb(struct net_device *dev, unsigned int idx);
2717 + void can_free_echo_skb(struct net_device *dev, unsigned int idx);
2718 +
2719 +diff --git a/include/linux/fs.h b/include/linux/fs.h
2720 +index 240cbaee819f..13277d2715df 100644
2721 +--- a/include/linux/fs.h
2722 ++++ b/include/linux/fs.h
2723 +@@ -65,6 +65,8 @@ extern struct inodes_stat_t inodes_stat;
2724 + extern int leases_enable, lease_break_time;
2725 + extern int sysctl_protected_symlinks;
2726 + extern int sysctl_protected_hardlinks;
2727 ++extern int sysctl_protected_fifos;
2728 ++extern int sysctl_protected_regular;
2729 +
2730 + struct buffer_head;
2731 + typedef int (get_block_t)(struct inode *inode, sector_t iblock,
2732 +diff --git a/include/linux/of.h b/include/linux/of.h
2733 +index dd10626a615f..d9371c9cd88a 100644
2734 +--- a/include/linux/of.h
2735 ++++ b/include/linux/of.h
2736 +@@ -265,6 +265,8 @@ extern struct device_node *of_get_next_child(const struct device_node *node,
2737 + extern struct device_node *of_get_next_available_child(
2738 + const struct device_node *node, struct device_node *prev);
2739 +
2740 ++extern struct device_node *of_get_compatible_child(const struct device_node *parent,
2741 ++ const char *compatible);
2742 + extern struct device_node *of_get_child_by_name(const struct device_node *node,
2743 + const char *name);
2744 +
2745 +@@ -462,6 +464,12 @@ static inline bool of_have_populated_dt(void)
2746 + return false;
2747 + }
2748 +
2749 ++static inline struct device_node *of_get_compatible_child(const struct device_node *parent,
2750 ++ const char *compatible)
2751 ++{
2752 ++ return NULL;
2753 ++}
2754 ++
2755 + static inline struct device_node *of_get_child_by_name(
2756 + const struct device_node *node,
2757 + const char *name)
2758 +diff --git a/kernel/debug/kdb/kdb_io.c b/kernel/debug/kdb/kdb_io.c
2759 +index 77777d918676..cc892a9e109d 100644
2760 +--- a/kernel/debug/kdb/kdb_io.c
2761 ++++ b/kernel/debug/kdb/kdb_io.c
2762 +@@ -215,7 +215,7 @@ static char *kdb_read(char *buffer, size_t bufsize)
2763 + int count;
2764 + int i;
2765 + int diag, dtab_count;
2766 +- int key;
2767 ++ int key, buf_size, ret;
2768 +
2769 +
2770 + diag = kdbgetintenv("DTABCOUNT", &dtab_count);
2771 +@@ -335,9 +335,8 @@ poll_again:
2772 + else
2773 + p_tmp = tmpbuffer;
2774 + len = strlen(p_tmp);
2775 +- count = kallsyms_symbol_complete(p_tmp,
2776 +- sizeof(tmpbuffer) -
2777 +- (p_tmp - tmpbuffer));
2778 ++ buf_size = sizeof(tmpbuffer) - (p_tmp - tmpbuffer);
2779 ++ count = kallsyms_symbol_complete(p_tmp, buf_size);
2780 + if (tab == 2 && count > 0) {
2781 + kdb_printf("\n%d symbols are found.", count);
2782 + if (count > dtab_count) {
2783 +@@ -349,9 +348,13 @@ poll_again:
2784 + }
2785 + kdb_printf("\n");
2786 + for (i = 0; i < count; i++) {
2787 +- if (WARN_ON(!kallsyms_symbol_next(p_tmp, i)))
2788 ++ ret = kallsyms_symbol_next(p_tmp, i, buf_size);
2789 ++ if (WARN_ON(!ret))
2790 + break;
2791 +- kdb_printf("%s ", p_tmp);
2792 ++ if (ret != -E2BIG)
2793 ++ kdb_printf("%s ", p_tmp);
2794 ++ else
2795 ++ kdb_printf("%s... ", p_tmp);
2796 + *(p_tmp + len) = '\0';
2797 + }
2798 + if (i >= dtab_count)
2799 +diff --git a/kernel/debug/kdb/kdb_private.h b/kernel/debug/kdb/kdb_private.h
2800 +index 75014d7f4568..533e04e75a9c 100644
2801 +--- a/kernel/debug/kdb/kdb_private.h
2802 ++++ b/kernel/debug/kdb/kdb_private.h
2803 +@@ -83,7 +83,7 @@ typedef struct __ksymtab {
2804 + unsigned long sym_start;
2805 + unsigned long sym_end;
2806 + } kdb_symtab_t;
2807 +-extern int kallsyms_symbol_next(char *prefix_name, int flag);
2808 ++extern int kallsyms_symbol_next(char *prefix_name, int flag, int buf_size);
2809 + extern int kallsyms_symbol_complete(char *prefix_name, int max_len);
2810 +
2811 + /* Exported Symbols for kernel loadable modules to use. */
2812 +diff --git a/kernel/debug/kdb/kdb_support.c b/kernel/debug/kdb/kdb_support.c
2813 +index d35cc2d3a4cc..2aed4a33521b 100644
2814 +--- a/kernel/debug/kdb/kdb_support.c
2815 ++++ b/kernel/debug/kdb/kdb_support.c
2816 +@@ -221,11 +221,13 @@ int kallsyms_symbol_complete(char *prefix_name, int max_len)
2817 + * Parameters:
2818 + * prefix_name prefix of a symbol name to lookup
2819 + * flag 0 means search from the head, 1 means continue search.
2820 ++ * buf_size maximum length that can be written to prefix_name
2821 ++ * buffer
2822 + * Returns:
2823 + * 1 if a symbol matches the given prefix.
2824 + * 0 if no string found
2825 + */
2826 +-int kallsyms_symbol_next(char *prefix_name, int flag)
2827 ++int kallsyms_symbol_next(char *prefix_name, int flag, int buf_size)
2828 + {
2829 + int prefix_len = strlen(prefix_name);
2830 + static loff_t pos;
2831 +@@ -235,10 +237,8 @@ int kallsyms_symbol_next(char *prefix_name, int flag)
2832 + pos = 0;
2833 +
2834 + while ((name = kdb_walk_kallsyms(&pos))) {
2835 +- if (strncmp(name, prefix_name, prefix_len) == 0) {
2836 +- strncpy(prefix_name, name, strlen(name)+1);
2837 +- return 1;
2838 +- }
2839 ++ if (!strncmp(name, prefix_name, prefix_len))
2840 ++ return strscpy(prefix_name, name, buf_size);
2841 + }
2842 + return 0;
2843 + }
2844 +diff --git a/kernel/sched/core.c b/kernel/sched/core.c
2845 +index 4743e1f2a3d1..d0618951014b 100644
2846 +--- a/kernel/sched/core.c
2847 ++++ b/kernel/sched/core.c
2848 +@@ -3822,8 +3822,8 @@ static int __sched_setscheduler(struct task_struct *p,
2849 + struct rq *rq;
2850 + int reset_on_fork;
2851 +
2852 +- /* may grab non-irq protected spin_locks */
2853 +- BUG_ON(in_interrupt());
2854 ++ /* The pi code expects interrupts enabled */
2855 ++ BUG_ON(pi && in_interrupt());
2856 + recheck:
2857 + /* double check policy once rq lock held */
2858 + if (policy < 0) {
2859 +diff --git a/kernel/sysctl.c b/kernel/sysctl.c
2860 +index 66100d1bc3f7..7e832f9a8f42 100644
2861 +--- a/kernel/sysctl.c
2862 ++++ b/kernel/sysctl.c
2863 +@@ -1715,6 +1715,24 @@ static struct ctl_table fs_table[] = {
2864 + .extra1 = &zero,
2865 + .extra2 = &one,
2866 + },
2867 ++ {
2868 ++ .procname = "protected_fifos",
2869 ++ .data = &sysctl_protected_fifos,
2870 ++ .maxlen = sizeof(int),
2871 ++ .mode = 0600,
2872 ++ .proc_handler = proc_dointvec_minmax,
2873 ++ .extra1 = &zero,
2874 ++ .extra2 = &two,
2875 ++ },
2876 ++ {
2877 ++ .procname = "protected_regular",
2878 ++ .data = &sysctl_protected_regular,
2879 ++ .maxlen = sizeof(int),
2880 ++ .mode = 0600,
2881 ++ .proc_handler = proc_dointvec_minmax,
2882 ++ .extra1 = &zero,
2883 ++ .extra2 = &two,
2884 ++ },
2885 + {
2886 + .procname = "suid_dumpable",
2887 + .data = &suid_dumpable,
2888 +diff --git a/mm/shmem.c b/mm/shmem.c
2889 +index 8e506a45a6ef..d902b413941a 100644
2890 +--- a/mm/shmem.c
2891 ++++ b/mm/shmem.c
2892 +@@ -1818,9 +1818,7 @@ static loff_t shmem_file_llseek(struct file *file, loff_t offset, int whence)
2893 + mutex_lock(&inode->i_mutex);
2894 + /* We're holding i_mutex so we can access i_size directly */
2895 +
2896 +- if (offset < 0)
2897 +- offset = -EINVAL;
2898 +- else if (offset >= inode->i_size)
2899 ++ if (offset < 0 || offset >= inode->i_size)
2900 + offset = -ENXIO;
2901 + else {
2902 + start = offset >> PAGE_CACHE_SHIFT;
2903 +diff --git a/net/llc/af_llc.c b/net/llc/af_llc.c
2904 +index 83e8a295c806..c153fc2883a8 100644
2905 +--- a/net/llc/af_llc.c
2906 ++++ b/net/llc/af_llc.c
2907 +@@ -726,7 +726,6 @@ static int llc_ui_recvmsg(struct socket *sock, struct msghdr *msg, size_t len,
2908 + struct sk_buff *skb = NULL;
2909 + struct sock *sk = sock->sk;
2910 + struct llc_sock *llc = llc_sk(sk);
2911 +- unsigned long cpu_flags;
2912 + size_t copied = 0;
2913 + u32 peek_seq = 0;
2914 + u32 *seq, skb_len;
2915 +@@ -851,9 +850,8 @@ static int llc_ui_recvmsg(struct socket *sock, struct msghdr *msg, size_t len,
2916 + goto copy_uaddr;
2917 +
2918 + if (!(flags & MSG_PEEK)) {
2919 +- spin_lock_irqsave(&sk->sk_receive_queue.lock, cpu_flags);
2920 +- sk_eat_skb(sk, skb);
2921 +- spin_unlock_irqrestore(&sk->sk_receive_queue.lock, cpu_flags);
2922 ++ skb_unlink(skb, &sk->sk_receive_queue);
2923 ++ kfree_skb(skb);
2924 + *seq = 0;
2925 + }
2926 +
2927 +@@ -874,9 +872,8 @@ copy_uaddr:
2928 + llc_cmsg_rcv(msg, skb);
2929 +
2930 + if (!(flags & MSG_PEEK)) {
2931 +- spin_lock_irqsave(&sk->sk_receive_queue.lock, cpu_flags);
2932 +- sk_eat_skb(sk, skb);
2933 +- spin_unlock_irqrestore(&sk->sk_receive_queue.lock, cpu_flags);
2934 ++ skb_unlink(skb, &sk->sk_receive_queue);
2935 ++ kfree_skb(skb);
2936 + *seq = 0;
2937 + }
2938 +
2939 +diff --git a/net/netfilter/nf_tables_api.c b/net/netfilter/nf_tables_api.c
2940 +index 120e9ae04db3..a7967af0da82 100644
2941 +--- a/net/netfilter/nf_tables_api.c
2942 ++++ b/net/netfilter/nf_tables_api.c
2943 +@@ -3452,6 +3452,7 @@ static int nft_add_set_elem(struct nft_ctx *ctx, struct nft_set *set,
2944 + dreg = nft_type_to_reg(set->dtype);
2945 + list_for_each_entry(binding, &set->bindings, list) {
2946 + struct nft_ctx bind_ctx = {
2947 ++ .net = ctx->net,
2948 + .afi = ctx->afi,
2949 + .table = ctx->table,
2950 + .chain = (struct nft_chain *)binding->chain,
2951 +diff --git a/net/sctp/associola.c b/net/sctp/associola.c
2952 +index a40b8b0ef0d5..f085b01b6603 100644
2953 +--- a/net/sctp/associola.c
2954 ++++ b/net/sctp/associola.c
2955 +@@ -486,8 +486,9 @@ void sctp_assoc_set_primary(struct sctp_association *asoc,
2956 + void sctp_assoc_rm_peer(struct sctp_association *asoc,
2957 + struct sctp_transport *peer)
2958 + {
2959 +- struct list_head *pos;
2960 +- struct sctp_transport *transport;
2961 ++ struct sctp_transport *transport;
2962 ++ struct list_head *pos;
2963 ++ struct sctp_chunk *ch;
2964 +
2965 + pr_debug("%s: association:%p addr:%pISpc\n",
2966 + __func__, asoc, &peer->ipaddr.sa);
2967 +@@ -543,7 +544,6 @@ void sctp_assoc_rm_peer(struct sctp_association *asoc,
2968 + */
2969 + if (!list_empty(&peer->transmitted)) {
2970 + struct sctp_transport *active = asoc->peer.active_path;
2971 +- struct sctp_chunk *ch;
2972 +
2973 + /* Reset the transport of each chunk on this list */
2974 + list_for_each_entry(ch, &peer->transmitted,
2975 +@@ -565,6 +565,10 @@ void sctp_assoc_rm_peer(struct sctp_association *asoc,
2976 + sctp_transport_hold(active);
2977 + }
2978 +
2979 ++ list_for_each_entry(ch, &asoc->outqueue.out_chunk_list, list)
2980 ++ if (ch->transport == peer)
2981 ++ ch->transport = NULL;
2982 ++
2983 + asoc->peer.transport_count--;
2984 +
2985 + sctp_transport_free(peer);
2986 +diff --git a/net/sunrpc/auth_generic.c b/net/sunrpc/auth_generic.c
2987 +index 41248b1820c7..cc27e38392ea 100644
2988 +--- a/net/sunrpc/auth_generic.c
2989 ++++ b/net/sunrpc/auth_generic.c
2990 +@@ -272,13 +272,7 @@ static bool generic_key_to_expire(struct rpc_cred *cred)
2991 + {
2992 + struct auth_cred *acred = &container_of(cred, struct generic_cred,
2993 + gc_base)->acred;
2994 +- bool ret;
2995 +-
2996 +- get_rpccred(cred);
2997 +- ret = test_bit(RPC_CRED_KEY_EXPIRE_SOON, &acred->ac_flags);
2998 +- put_rpccred(cred);
2999 +-
3000 +- return ret;
3001 ++ return test_bit(RPC_CRED_KEY_EXPIRE_SOON, &acred->ac_flags);
3002 + }
3003 +
3004 + static const struct rpc_credops generic_credops = {