Gentoo Archives: gentoo-commits

From: Mike Pagano <mpagano@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/linux-patches:4.9 commit in: /
Date: Fri, 31 May 2019 16:42:41
Message-Id: 1559320938.a18abc2809788f1c84a8a54f98b0a59babe97ed8.mpagano@gentoo
1 commit: a18abc2809788f1c84a8a54f98b0a59babe97ed8
2 Author: Mike Pagano <mpagano <AT> gentoo <DOT> org>
3 AuthorDate: Fri May 31 16:42:18 2019 +0000
4 Commit: Mike Pagano <mpagano <AT> gentoo <DOT> org>
5 CommitDate: Fri May 31 16:42:18 2019 +0000
6 URL: https://gitweb.gentoo.org/proj/linux-patches.git/commit/?id=a18abc28
7
8 Linux patch 4.9.180
9
10 Signed-off-by: Mike Pagano <mpagano <AT> gentoo.org>
11
12 0000_README | 4 +
13 1179_linux-4.9.180.patch | 3776 ++++++++++++++++++++++++++++++++++++++++++++++
14 2 files changed, 3780 insertions(+)
15
16 diff --git a/0000_README b/0000_README
17 index 1ff80f1..531733f 100644
18 --- a/0000_README
19 +++ b/0000_README
20 @@ -759,6 +759,10 @@ Patch: 1178_linux-4.9.179.patch
21 From: http://www.kernel.org
22 Desc: Linux 4.9.179
23
24 +Patch: 1179_linux-4.9.180.patch
25 +From: http://www.kernel.org
26 +Desc: Linux 4.9.180
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/1179_linux-4.9.180.patch b/1179_linux-4.9.180.patch
33 new file mode 100644
34 index 0000000..27bf989
35 --- /dev/null
36 +++ b/1179_linux-4.9.180.patch
37 @@ -0,0 +1,3776 @@
38 +diff --git a/Makefile b/Makefile
39 +index d60795319d8a..0b996e9d2c5f 100644
40 +--- a/Makefile
41 ++++ b/Makefile
42 +@@ -1,6 +1,6 @@
43 + VERSION = 4
44 + PATCHLEVEL = 9
45 +-SUBLEVEL = 179
46 ++SUBLEVEL = 180
47 + EXTRAVERSION =
48 + NAME = Roaring Lionus
49 +
50 +diff --git a/arch/arm/include/asm/cp15.h b/arch/arm/include/asm/cp15.h
51 +index b74b174ac9fc..b458e4122794 100644
52 +--- a/arch/arm/include/asm/cp15.h
53 ++++ b/arch/arm/include/asm/cp15.h
54 +@@ -67,6 +67,8 @@
55 + #define BPIALL __ACCESS_CP15(c7, 0, c5, 6)
56 + #define ICIALLU __ACCESS_CP15(c7, 0, c5, 0)
57 +
58 ++#define CNTVCT __ACCESS_CP15_64(1, c14)
59 ++
60 + extern unsigned long cr_alignment; /* defined in entry-armv.S */
61 +
62 + static inline unsigned long get_cr(void)
63 +diff --git a/arch/arm/vdso/vgettimeofday.c b/arch/arm/vdso/vgettimeofday.c
64 +index 79214d5ff097..3af02d2a0b7f 100644
65 +--- a/arch/arm/vdso/vgettimeofday.c
66 ++++ b/arch/arm/vdso/vgettimeofday.c
67 +@@ -18,9 +18,9 @@
68 + #include <linux/compiler.h>
69 + #include <linux/hrtimer.h>
70 + #include <linux/time.h>
71 +-#include <asm/arch_timer.h>
72 + #include <asm/barrier.h>
73 + #include <asm/bug.h>
74 ++#include <asm/cp15.h>
75 + #include <asm/page.h>
76 + #include <asm/unistd.h>
77 + #include <asm/vdso_datapage.h>
78 +@@ -123,7 +123,8 @@ static notrace u64 get_ns(struct vdso_data *vdata)
79 + u64 cycle_now;
80 + u64 nsec;
81 +
82 +- cycle_now = arch_counter_get_cntvct();
83 ++ isb();
84 ++ cycle_now = read_sysreg(CNTVCT);
85 +
86 + cycle_delta = (cycle_now - vdata->cs_cycle_last) & vdata->cs_mask;
87 +
88 +diff --git a/arch/arm64/include/asm/pgtable.h b/arch/arm64/include/asm/pgtable.h
89 +index 3a30a3994e4a..73e3718356b0 100644
90 +--- a/arch/arm64/include/asm/pgtable.h
91 ++++ b/arch/arm64/include/asm/pgtable.h
92 +@@ -413,6 +413,8 @@ static inline phys_addr_t pmd_page_paddr(pmd_t pmd)
93 + return pmd_val(pmd) & PHYS_MASK & (s32)PAGE_MASK;
94 + }
95 +
96 ++static inline void pte_unmap(pte_t *pte) { }
97 ++
98 + /* Find an entry in the third-level page table. */
99 + #define pte_index(addr) (((addr) >> PAGE_SHIFT) & (PTRS_PER_PTE - 1))
100 +
101 +@@ -421,7 +423,6 @@ static inline phys_addr_t pmd_page_paddr(pmd_t pmd)
102 +
103 + #define pte_offset_map(dir,addr) pte_offset_kernel((dir), (addr))
104 + #define pte_offset_map_nested(dir,addr) pte_offset_kernel((dir), (addr))
105 +-#define pte_unmap(pte) do { } while (0)
106 + #define pte_unmap_nested(pte) do { } while (0)
107 +
108 + #define pte_set_fixmap(addr) ((pte_t *)set_fixmap_offset(FIX_PTE, addr))
109 +diff --git a/arch/arm64/include/asm/vdso_datapage.h b/arch/arm64/include/asm/vdso_datapage.h
110 +index 2b9a63771eda..f89263c8e11a 100644
111 +--- a/arch/arm64/include/asm/vdso_datapage.h
112 ++++ b/arch/arm64/include/asm/vdso_datapage.h
113 +@@ -38,6 +38,7 @@ struct vdso_data {
114 + __u32 tz_minuteswest; /* Whacky timezone stuff */
115 + __u32 tz_dsttime;
116 + __u32 use_syscall;
117 ++ __u32 hrtimer_res;
118 + };
119 +
120 + #endif /* !__ASSEMBLY__ */
121 +diff --git a/arch/arm64/kernel/asm-offsets.c b/arch/arm64/kernel/asm-offsets.c
122 +index bd239b1b7a68..95878bea27f9 100644
123 +--- a/arch/arm64/kernel/asm-offsets.c
124 ++++ b/arch/arm64/kernel/asm-offsets.c
125 +@@ -92,7 +92,7 @@ int main(void)
126 + DEFINE(CLOCK_REALTIME, CLOCK_REALTIME);
127 + DEFINE(CLOCK_MONOTONIC, CLOCK_MONOTONIC);
128 + DEFINE(CLOCK_MONOTONIC_RAW, CLOCK_MONOTONIC_RAW);
129 +- DEFINE(CLOCK_REALTIME_RES, MONOTONIC_RES_NSEC);
130 ++ DEFINE(CLOCK_REALTIME_RES, offsetof(struct vdso_data, hrtimer_res));
131 + DEFINE(CLOCK_REALTIME_COARSE, CLOCK_REALTIME_COARSE);
132 + DEFINE(CLOCK_MONOTONIC_COARSE,CLOCK_MONOTONIC_COARSE);
133 + DEFINE(CLOCK_COARSE_RES, LOW_RES_NSEC);
134 +diff --git a/arch/arm64/kernel/cpu_ops.c b/arch/arm64/kernel/cpu_ops.c
135 +index e137ceaf5016..82b465207ed0 100644
136 +--- a/arch/arm64/kernel/cpu_ops.c
137 ++++ b/arch/arm64/kernel/cpu_ops.c
138 +@@ -85,6 +85,7 @@ static const char *__init cpu_read_enable_method(int cpu)
139 + pr_err("%s: missing enable-method property\n",
140 + dn->full_name);
141 + }
142 ++ of_node_put(dn);
143 + } else {
144 + enable_method = acpi_get_enable_method(cpu);
145 + if (!enable_method) {
146 +diff --git a/arch/arm64/kernel/vdso.c b/arch/arm64/kernel/vdso.c
147 +index 4bcfe01b5aad..c9b9a5a322eb 100644
148 +--- a/arch/arm64/kernel/vdso.c
149 ++++ b/arch/arm64/kernel/vdso.c
150 +@@ -213,6 +213,9 @@ void update_vsyscall(struct timekeeper *tk)
151 + vdso_data->wtm_clock_sec = tk->wall_to_monotonic.tv_sec;
152 + vdso_data->wtm_clock_nsec = tk->wall_to_monotonic.tv_nsec;
153 +
154 ++ /* Read without the seqlock held by clock_getres() */
155 ++ WRITE_ONCE(vdso_data->hrtimer_res, hrtimer_resolution);
156 ++
157 + if (!use_syscall) {
158 + /* tkr_mono.cycle_last == tkr_raw.cycle_last */
159 + vdso_data->cs_cycle_last = tk->tkr_mono.cycle_last;
160 +diff --git a/arch/arm64/kernel/vdso/gettimeofday.S b/arch/arm64/kernel/vdso/gettimeofday.S
161 +index 76320e920965..df829c4346fa 100644
162 +--- a/arch/arm64/kernel/vdso/gettimeofday.S
163 ++++ b/arch/arm64/kernel/vdso/gettimeofday.S
164 +@@ -301,13 +301,14 @@ ENTRY(__kernel_clock_getres)
165 + ccmp w0, #CLOCK_MONOTONIC_RAW, #0x4, ne
166 + b.ne 1f
167 +
168 +- ldr x2, 5f
169 ++ adr vdso_data, _vdso_data
170 ++ ldr w2, [vdso_data, #CLOCK_REALTIME_RES]
171 + b 2f
172 + 1:
173 + cmp w0, #CLOCK_REALTIME_COARSE
174 + ccmp w0, #CLOCK_MONOTONIC_COARSE, #0x4, ne
175 + b.ne 4f
176 +- ldr x2, 6f
177 ++ ldr x2, 5f
178 + 2:
179 + cbz w1, 3f
180 + stp xzr, x2, [x1]
181 +@@ -321,8 +322,6 @@ ENTRY(__kernel_clock_getres)
182 + svc #0
183 + ret
184 + 5:
185 +- .quad CLOCK_REALTIME_RES
186 +-6:
187 + .quad CLOCK_COARSE_RES
188 + .cfi_endproc
189 + ENDPROC(__kernel_clock_getres)
190 +diff --git a/arch/arm64/mm/proc.S b/arch/arm64/mm/proc.S
191 +index f5fde8d389c9..3ceec224d3d2 100644
192 +--- a/arch/arm64/mm/proc.S
193 ++++ b/arch/arm64/mm/proc.S
194 +@@ -64,17 +64,18 @@ ENTRY(cpu_do_suspend)
195 + mrs x2, tpidr_el0
196 + mrs x3, tpidrro_el0
197 + mrs x4, contextidr_el1
198 +- mrs x5, cpacr_el1
199 +- mrs x6, tcr_el1
200 +- mrs x7, vbar_el1
201 +- mrs x8, mdscr_el1
202 +- mrs x9, oslsr_el1
203 +- mrs x10, sctlr_el1
204 ++ mrs x5, osdlr_el1
205 ++ mrs x6, cpacr_el1
206 ++ mrs x7, tcr_el1
207 ++ mrs x8, vbar_el1
208 ++ mrs x9, mdscr_el1
209 ++ mrs x10, oslsr_el1
210 ++ mrs x11, sctlr_el1
211 + stp x2, x3, [x0]
212 +- stp x4, xzr, [x0, #16]
213 +- stp x5, x6, [x0, #32]
214 +- stp x7, x8, [x0, #48]
215 +- stp x9, x10, [x0, #64]
216 ++ stp x4, x5, [x0, #16]
217 ++ stp x6, x7, [x0, #32]
218 ++ stp x8, x9, [x0, #48]
219 ++ stp x10, x11, [x0, #64]
220 + ret
221 + ENDPROC(cpu_do_suspend)
222 +
223 +@@ -96,8 +97,8 @@ ENTRY(cpu_do_resume)
224 + msr cpacr_el1, x6
225 +
226 + /* Don't change t0sz here, mask those bits when restoring */
227 +- mrs x5, tcr_el1
228 +- bfi x8, x5, TCR_T0SZ_OFFSET, TCR_TxSZ_WIDTH
229 ++ mrs x7, tcr_el1
230 ++ bfi x8, x7, TCR_T0SZ_OFFSET, TCR_TxSZ_WIDTH
231 +
232 + msr tcr_el1, x8
233 + msr vbar_el1, x9
234 +@@ -115,6 +116,7 @@ ENTRY(cpu_do_resume)
235 + /*
236 + * Restore oslsr_el1 by writing oslar_el1
237 + */
238 ++ msr osdlr_el1, x5
239 + ubfx x11, x11, #1, #1
240 + msr oslar_el1, x11
241 + reset_pmuserenr_el0 x0 // Disable PMU access from EL0
242 +diff --git a/arch/powerpc/boot/addnote.c b/arch/powerpc/boot/addnote.c
243 +index 9d9f6f334d3c..3da3e2b1b51b 100644
244 +--- a/arch/powerpc/boot/addnote.c
245 ++++ b/arch/powerpc/boot/addnote.c
246 +@@ -223,7 +223,11 @@ main(int ac, char **av)
247 + PUT_16(E_PHNUM, np + 2);
248 +
249 + /* write back */
250 +- lseek(fd, (long) 0, SEEK_SET);
251 ++ i = lseek(fd, (long) 0, SEEK_SET);
252 ++ if (i < 0) {
253 ++ perror("lseek");
254 ++ exit(1);
255 ++ }
256 + i = write(fd, buf, n);
257 + if (i < 0) {
258 + perror("write");
259 +diff --git a/arch/powerpc/mm/numa.c b/arch/powerpc/mm/numa.c
260 +index 9cad2ed812ab..31e9064ba628 100644
261 +--- a/arch/powerpc/mm/numa.c
262 ++++ b/arch/powerpc/mm/numa.c
263 +@@ -1574,6 +1574,9 @@ int start_topology_update(void)
264 + {
265 + int rc = 0;
266 +
267 ++ if (!topology_updates_enabled)
268 ++ return 0;
269 ++
270 + if (firmware_has_feature(FW_FEATURE_PRRN)) {
271 + if (!prrn_enabled) {
272 + prrn_enabled = 1;
273 +@@ -1603,6 +1606,9 @@ int stop_topology_update(void)
274 + {
275 + int rc = 0;
276 +
277 ++ if (!topology_updates_enabled)
278 ++ return 0;
279 ++
280 + if (prrn_enabled) {
281 + prrn_enabled = 0;
282 + #ifdef CONFIG_SMP
283 +@@ -1648,11 +1654,13 @@ static ssize_t topology_write(struct file *file, const char __user *buf,
284 +
285 + kbuf[read_len] = '\0';
286 +
287 +- if (!strncmp(kbuf, "on", 2))
288 ++ if (!strncmp(kbuf, "on", 2)) {
289 ++ topology_updates_enabled = true;
290 + start_topology_update();
291 +- else if (!strncmp(kbuf, "off", 3))
292 ++ } else if (!strncmp(kbuf, "off", 3)) {
293 + stop_topology_update();
294 +- else
295 ++ topology_updates_enabled = false;
296 ++ } else
297 + return -EINVAL;
298 +
299 + return count;
300 +@@ -1667,9 +1675,7 @@ static const struct file_operations topology_ops = {
301 +
302 + static int topology_update_init(void)
303 + {
304 +- /* Do not poll for changes if disabled at boot */
305 +- if (topology_updates_enabled)
306 +- start_topology_update();
307 ++ start_topology_update();
308 +
309 + if (!proc_create("powerpc/topology_updates", 0644, NULL, &topology_ops))
310 + return -ENOMEM;
311 +diff --git a/arch/x86/Makefile b/arch/x86/Makefile
312 +index b5226a009973..2996a1d0a410 100644
313 +--- a/arch/x86/Makefile
314 ++++ b/arch/x86/Makefile
315 +@@ -47,7 +47,7 @@ export REALMODE_CFLAGS
316 + export BITS
317 +
318 + ifdef CONFIG_X86_NEED_RELOCS
319 +- LDFLAGS_vmlinux := --emit-relocs
320 ++ LDFLAGS_vmlinux := --emit-relocs --discard-none
321 + endif
322 +
323 + #
324 +diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c
325 +index cb13c0564ea7..9978ea4382bf 100644
326 +--- a/arch/x86/ia32/ia32_signal.c
327 ++++ b/arch/x86/ia32/ia32_signal.c
328 +@@ -60,9 +60,8 @@
329 + } while (0)
330 +
331 + #define RELOAD_SEG(seg) { \
332 +- unsigned int pre = GET_SEG(seg); \
333 ++ unsigned int pre = (seg) | 3; \
334 + unsigned int cur = get_user_seg(seg); \
335 +- pre |= 3; \
336 + if (pre != cur) \
337 + set_user_seg(seg, pre); \
338 + }
339 +@@ -71,6 +70,7 @@ static int ia32_restore_sigcontext(struct pt_regs *regs,
340 + struct sigcontext_32 __user *sc)
341 + {
342 + unsigned int tmpflags, err = 0;
343 ++ u16 gs, fs, es, ds;
344 + void __user *buf;
345 + u32 tmp;
346 +
347 +@@ -78,16 +78,10 @@ static int ia32_restore_sigcontext(struct pt_regs *regs,
348 + current->restart_block.fn = do_no_restart_syscall;
349 +
350 + get_user_try {
351 +- /*
352 +- * Reload fs and gs if they have changed in the signal
353 +- * handler. This does not handle long fs/gs base changes in
354 +- * the handler, but does not clobber them at least in the
355 +- * normal case.
356 +- */
357 +- RELOAD_SEG(gs);
358 +- RELOAD_SEG(fs);
359 +- RELOAD_SEG(ds);
360 +- RELOAD_SEG(es);
361 ++ gs = GET_SEG(gs);
362 ++ fs = GET_SEG(fs);
363 ++ ds = GET_SEG(ds);
364 ++ es = GET_SEG(es);
365 +
366 + COPY(di); COPY(si); COPY(bp); COPY(sp); COPY(bx);
367 + COPY(dx); COPY(cx); COPY(ip); COPY(ax);
368 +@@ -105,6 +99,17 @@ static int ia32_restore_sigcontext(struct pt_regs *regs,
369 + buf = compat_ptr(tmp);
370 + } get_user_catch(err);
371 +
372 ++ /*
373 ++ * Reload fs and gs if they have changed in the signal
374 ++ * handler. This does not handle long fs/gs base changes in
375 ++ * the handler, but does not clobber them at least in the
376 ++ * normal case.
377 ++ */
378 ++ RELOAD_SEG(gs);
379 ++ RELOAD_SEG(fs);
380 ++ RELOAD_SEG(ds);
381 ++ RELOAD_SEG(es);
382 ++
383 + err |= fpu__restore_sig(buf, 1);
384 +
385 + force_iret();
386 +diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
387 +index d9ad49ca3cbe..e348bee411e3 100644
388 +--- a/arch/x86/kernel/cpu/mcheck/mce.c
389 ++++ b/arch/x86/kernel/cpu/mcheck/mce.c
390 +@@ -673,20 +673,50 @@ bool machine_check_poll(enum mcp_flags flags, mce_banks_t *b)
391 +
392 + barrier();
393 + m.status = mce_rdmsrl(msr_ops.status(i));
394 ++
395 ++ /* If this entry is not valid, ignore it */
396 + if (!(m.status & MCI_STATUS_VAL))
397 + continue;
398 +
399 +
400 + /*
401 +- * Uncorrected or signalled events are handled by the exception
402 +- * handler when it is enabled, so don't process those here.
403 +- *
404 +- * TBD do the same check for MCI_STATUS_EN here?
405 ++ * If we are logging everything (at CPU online) or this
406 ++ * is a corrected error, then we must log it.
407 + */
408 +- if (!(flags & MCP_UC) &&
409 +- (m.status & (mca_cfg.ser ? MCI_STATUS_S : MCI_STATUS_UC)))
410 +- continue;
411 ++ if ((flags & MCP_UC) || !(m.status & MCI_STATUS_UC))
412 ++ goto log_it;
413 ++
414 ++ /*
415 ++ * Newer Intel systems that support software error
416 ++ * recovery need to make additional checks. Other
417 ++ * CPUs should skip over uncorrected errors, but log
418 ++ * everything else.
419 ++ */
420 ++ if (!mca_cfg.ser) {
421 ++ if (m.status & MCI_STATUS_UC)
422 ++ continue;
423 ++ goto log_it;
424 ++ }
425 ++
426 ++ /* Log "not enabled" (speculative) errors */
427 ++ if (!(m.status & MCI_STATUS_EN))
428 ++ goto log_it;
429 ++
430 ++ /*
431 ++ * Log UCNA (SDM: 15.6.3 "UCR Error Classification")
432 ++ * UC == 1 && PCC == 0 && S == 0
433 ++ */
434 ++ if (!(m.status & MCI_STATUS_PCC) && !(m.status & MCI_STATUS_S))
435 ++ goto log_it;
436 ++
437 ++ /*
438 ++ * Skip anything else. Presumption is that our read of this
439 ++ * bank is racing with a machine check. Leave the log alone
440 ++ * for do_machine_check() to deal with it.
441 ++ */
442 ++ continue;
443 +
444 ++log_it:
445 + error_seen = true;
446 +
447 + mce_read_aux(&m, i);
448 +diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c
449 +index bcd1b82c86e8..005e9a77a664 100644
450 +--- a/arch/x86/kernel/irq_64.c
451 ++++ b/arch/x86/kernel/irq_64.c
452 +@@ -25,9 +25,18 @@ int sysctl_panic_on_stackoverflow;
453 + /*
454 + * Probabilistic stack overflow check:
455 + *
456 +- * Only check the stack in process context, because everything else
457 +- * runs on the big interrupt stacks. Checking reliably is too expensive,
458 +- * so we just check from interrupts.
459 ++ * Regular device interrupts can enter on the following stacks:
460 ++ *
461 ++ * - User stack
462 ++ *
463 ++ * - Kernel task stack
464 ++ *
465 ++ * - Interrupt stack if a device driver reenables interrupts
466 ++ * which should only happen in really old drivers.
467 ++ *
468 ++ * - Debug IST stack
469 ++ *
470 ++ * All other contexts are invalid.
471 + */
472 + static inline void stack_overflow_check(struct pt_regs *regs)
473 + {
474 +@@ -52,8 +61,8 @@ static inline void stack_overflow_check(struct pt_regs *regs)
475 + return;
476 +
477 + oist = this_cpu_ptr(&orig_ist);
478 +- estack_top = (u64)oist->ist[0] - EXCEPTION_STKSZ + STACK_TOP_MARGIN;
479 +- estack_bottom = (u64)oist->ist[N_EXCEPTION_STACKS - 1];
480 ++ estack_bottom = (u64)oist->ist[DEBUG_STACK];
481 ++ estack_top = estack_bottom - DEBUG_STKSZ + STACK_TOP_MARGIN;
482 + if (regs->sp >= estack_top && regs->sp <= estack_bottom)
483 + return;
484 +
485 +diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
486 +index b1a5d252d482..ca010dfb9682 100644
487 +--- a/arch/x86/kernel/signal.c
488 ++++ b/arch/x86/kernel/signal.c
489 +@@ -129,16 +129,6 @@ static int restore_sigcontext(struct pt_regs *regs,
490 + COPY_SEG_CPL3(cs);
491 + COPY_SEG_CPL3(ss);
492 +
493 +-#ifdef CONFIG_X86_64
494 +- /*
495 +- * Fix up SS if needed for the benefit of old DOSEMU and
496 +- * CRIU.
497 +- */
498 +- if (unlikely(!(uc_flags & UC_STRICT_RESTORE_SS) &&
499 +- user_64bit_mode(regs)))
500 +- force_valid_ss(regs);
501 +-#endif
502 +-
503 + get_user_ex(tmpflags, &sc->flags);
504 + regs->flags = (regs->flags & ~FIX_EFLAGS) | (tmpflags & FIX_EFLAGS);
505 + regs->orig_ax = -1; /* disable syscall checks */
506 +@@ -147,6 +137,15 @@ static int restore_sigcontext(struct pt_regs *regs,
507 + buf = (void __user *)buf_val;
508 + } get_user_catch(err);
509 +
510 ++#ifdef CONFIG_X86_64
511 ++ /*
512 ++ * Fix up SS if needed for the benefit of old DOSEMU and
513 ++ * CRIU.
514 ++ */
515 ++ if (unlikely(!(uc_flags & UC_STRICT_RESTORE_SS) && user_64bit_mode(regs)))
516 ++ force_valid_ss(regs);
517 ++#endif
518 ++
519 + err |= fpu__restore_sig(buf, IS_ENABLED(CONFIG_X86_32));
520 +
521 + force_iret();
522 +@@ -458,6 +457,7 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
523 + {
524 + struct rt_sigframe __user *frame;
525 + void __user *fp = NULL;
526 ++ unsigned long uc_flags;
527 + int err = 0;
528 +
529 + frame = get_sigframe(&ksig->ka, regs, sizeof(struct rt_sigframe), &fp);
530 +@@ -470,9 +470,11 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
531 + return -EFAULT;
532 + }
533 +
534 ++ uc_flags = frame_uc_flags(regs);
535 ++
536 + put_user_try {
537 + /* Create the ucontext. */
538 +- put_user_ex(frame_uc_flags(regs), &frame->uc.uc_flags);
539 ++ put_user_ex(uc_flags, &frame->uc.uc_flags);
540 + put_user_ex(0, &frame->uc.uc_link);
541 + save_altstack_ex(&frame->uc.uc_stack, regs->sp);
542 +
543 +@@ -538,6 +540,7 @@ static int x32_setup_rt_frame(struct ksignal *ksig,
544 + {
545 + #ifdef CONFIG_X86_X32_ABI
546 + struct rt_sigframe_x32 __user *frame;
547 ++ unsigned long uc_flags;
548 + void __user *restorer;
549 + int err = 0;
550 + void __user *fpstate = NULL;
551 +@@ -552,9 +555,11 @@ static int x32_setup_rt_frame(struct ksignal *ksig,
552 + return -EFAULT;
553 + }
554 +
555 ++ uc_flags = frame_uc_flags(regs);
556 ++
557 + put_user_try {
558 + /* Create the ucontext. */
559 +- put_user_ex(frame_uc_flags(regs), &frame->uc.uc_flags);
560 ++ put_user_ex(uc_flags, &frame->uc.uc_flags);
561 + put_user_ex(0, &frame->uc.uc_link);
562 + compat_save_altstack_ex(&frame->uc.uc_stack, regs->sp);
563 + put_user_ex(0, &frame->uc.uc__pad0);
564 +diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
565 +index 55f04875293f..51b772f9d886 100644
566 +--- a/arch/x86/kernel/vmlinux.lds.S
567 ++++ b/arch/x86/kernel/vmlinux.lds.S
568 +@@ -111,11 +111,11 @@ SECTIONS
569 + *(.text.__x86.indirect_thunk)
570 + __indirect_thunk_end = .;
571 + #endif
572 +-
573 +- /* End of text section */
574 +- _etext = .;
575 + } :text = 0x9090
576 +
577 ++ /* End of text section */
578 ++ _etext = .;
579 ++
580 + NOTES :text :note
581 +
582 + EXCEPTION_TABLE(16) :text = 0x9090
583 +diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
584 +index 9338136a6a23..f7a7b98b3271 100644
585 +--- a/arch/x86/kvm/svm.c
586 ++++ b/arch/x86/kvm/svm.c
587 +@@ -1518,7 +1518,11 @@ static void avic_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
588 + if (!kvm_vcpu_apicv_active(vcpu))
589 + return;
590 +
591 +- if (WARN_ON(h_physical_id >= AVIC_MAX_PHYSICAL_ID_COUNT))
592 ++ /*
593 ++ * Since the host physical APIC id is 8 bits,
594 ++ * we can support host APIC ID upto 255.
595 ++ */
596 ++ if (WARN_ON(h_physical_id > AVIC_PHYSICAL_ID_ENTRY_HOST_PHYSICAL_ID_MASK))
597 + return;
598 +
599 + entry = READ_ONCE(*(svm->avic_physical_id_cache));
600 +diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
601 +index 1f32c4e32a00..72efecc4288b 100644
602 +--- a/arch/x86/kvm/x86.c
603 ++++ b/arch/x86/kvm/x86.c
604 +@@ -1109,7 +1109,7 @@ static int set_efer(struct kvm_vcpu *vcpu, struct msr_data *msr_info)
605 + u64 efer = msr_info->data;
606 +
607 + if (efer & efer_reserved_bits)
608 +- return false;
609 ++ return 1;
610 +
611 + if (!msr_info->host_initiated) {
612 + if (!__kvm_valid_efer(vcpu, efer))
613 +diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
614 +index 5c419b8f99a0..c140198d9fa5 100644
615 +--- a/arch/x86/mm/fault.c
616 ++++ b/arch/x86/mm/fault.c
617 +@@ -430,8 +430,6 @@ static noinline int vmalloc_fault(unsigned long address)
618 + if (!(address >= VMALLOC_START && address < VMALLOC_END))
619 + return -1;
620 +
621 +- WARN_ON_ONCE(in_nmi());
622 +-
623 + /*
624 + * Copy kernel mappings over when needed. This can also
625 + * happen within a race in page table update. In the later
626 +diff --git a/drivers/base/power/main.c b/drivers/base/power/main.c
627 +index 98517216879d..a2714890fe43 100644
628 +--- a/drivers/base/power/main.c
629 ++++ b/drivers/base/power/main.c
630 +@@ -1383,6 +1383,10 @@ static int __device_suspend(struct device *dev, pm_message_t state, bool async)
631 + if (dev->power.syscore)
632 + goto Complete;
633 +
634 ++ /* Avoid direct_complete to let wakeup_path propagate. */
635 ++ if (device_may_wakeup(dev) || dev->power.wakeup_path)
636 ++ dev->power.direct_complete = false;
637 ++
638 + if (dev->power.direct_complete) {
639 + if (pm_runtime_status_suspended(dev)) {
640 + pm_runtime_disable(dev);
641 +diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
642 +index 8c0017d48571..800ced0a5a24 100644
643 +--- a/drivers/char/virtio_console.c
644 ++++ b/drivers/char/virtio_console.c
645 +@@ -75,7 +75,7 @@ struct ports_driver_data {
646 + /* All the console devices handled by this driver */
647 + struct list_head consoles;
648 + };
649 +-static struct ports_driver_data pdrvdata;
650 ++static struct ports_driver_data pdrvdata = { .next_vtermno = 1};
651 +
652 + static DEFINE_SPINLOCK(pdrvdata_lock);
653 + static DECLARE_COMPLETION(early_console_added);
654 +@@ -1425,6 +1425,7 @@ static int add_port(struct ports_device *portdev, u32 id)
655 + port->async_queue = NULL;
656 +
657 + port->cons.ws.ws_row = port->cons.ws.ws_col = 0;
658 ++ port->cons.vtermno = 0;
659 +
660 + port->host_connected = port->guest_connected = false;
661 + port->stats = (struct port_stats) { 0 };
662 +diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
663 +index a38a23f0b3f4..e917521a3ef9 100644
664 +--- a/drivers/cpufreq/cpufreq.c
665 ++++ b/drivers/cpufreq/cpufreq.c
666 +@@ -1065,6 +1065,7 @@ static struct cpufreq_policy *cpufreq_policy_alloc(unsigned int cpu)
667 + cpufreq_global_kobject, "policy%u", cpu);
668 + if (ret) {
669 + pr_err("%s: failed to init policy->kobj: %d\n", __func__, ret);
670 ++ kobject_put(&policy->kobj);
671 + goto err_free_real_cpus;
672 + }
673 +
674 +diff --git a/drivers/cpufreq/cpufreq_governor.c b/drivers/cpufreq/cpufreq_governor.c
675 +index 38d1a8216084..32c9524a6ec5 100644
676 +--- a/drivers/cpufreq/cpufreq_governor.c
677 ++++ b/drivers/cpufreq/cpufreq_governor.c
678 +@@ -449,6 +449,8 @@ int cpufreq_dbs_governor_init(struct cpufreq_policy *policy)
679 + /* Failure, so roll back. */
680 + pr_err("initialization failed (dbs_data kobject init error %d)\n", ret);
681 +
682 ++ kobject_put(&dbs_data->attr_set.kobj);
683 ++
684 + policy->governor_data = NULL;
685 +
686 + if (!have_governor_per_policy())
687 +diff --git a/drivers/cpufreq/pasemi-cpufreq.c b/drivers/cpufreq/pasemi-cpufreq.c
688 +index 35dd4d7ffee0..58c933f48300 100644
689 +--- a/drivers/cpufreq/pasemi-cpufreq.c
690 ++++ b/drivers/cpufreq/pasemi-cpufreq.c
691 +@@ -146,6 +146,7 @@ static int pas_cpufreq_cpu_init(struct cpufreq_policy *policy)
692 +
693 + cpu = of_get_cpu_node(policy->cpu, NULL);
694 +
695 ++ of_node_put(cpu);
696 + if (!cpu)
697 + goto out;
698 +
699 +diff --git a/drivers/cpufreq/pmac32-cpufreq.c b/drivers/cpufreq/pmac32-cpufreq.c
700 +index ff44016ea031..641f8021855a 100644
701 +--- a/drivers/cpufreq/pmac32-cpufreq.c
702 ++++ b/drivers/cpufreq/pmac32-cpufreq.c
703 +@@ -551,6 +551,7 @@ static int pmac_cpufreq_init_7447A(struct device_node *cpunode)
704 + volt_gpio_np = of_find_node_by_name(NULL, "cpu-vcore-select");
705 + if (volt_gpio_np)
706 + voltage_gpio = read_gpio(volt_gpio_np);
707 ++ of_node_put(volt_gpio_np);
708 + if (!voltage_gpio){
709 + pr_err("missing cpu-vcore-select gpio\n");
710 + return 1;
711 +@@ -587,6 +588,7 @@ static int pmac_cpufreq_init_750FX(struct device_node *cpunode)
712 + if (volt_gpio_np)
713 + voltage_gpio = read_gpio(volt_gpio_np);
714 +
715 ++ of_node_put(volt_gpio_np);
716 + pvr = mfspr(SPRN_PVR);
717 + has_cpu_l2lve = !((pvr & 0xf00) == 0x100);
718 +
719 +diff --git a/drivers/cpufreq/ppc_cbe_cpufreq.c b/drivers/cpufreq/ppc_cbe_cpufreq.c
720 +index 5a4c5a639f61..2eaeebcc93af 100644
721 +--- a/drivers/cpufreq/ppc_cbe_cpufreq.c
722 ++++ b/drivers/cpufreq/ppc_cbe_cpufreq.c
723 +@@ -86,6 +86,7 @@ static int cbe_cpufreq_cpu_init(struct cpufreq_policy *policy)
724 + if (!cbe_get_cpu_pmd_regs(policy->cpu) ||
725 + !cbe_get_cpu_mic_tm_regs(policy->cpu)) {
726 + pr_info("invalid CBE regs pointers for cpufreq\n");
727 ++ of_node_put(cpu);
728 + return -EINVAL;
729 + }
730 +
731 +diff --git a/drivers/crypto/sunxi-ss/sun4i-ss-hash.c b/drivers/crypto/sunxi-ss/sun4i-ss-hash.c
732 +index 0de2f62d51ff..ec16ec2e284d 100644
733 +--- a/drivers/crypto/sunxi-ss/sun4i-ss-hash.c
734 ++++ b/drivers/crypto/sunxi-ss/sun4i-ss-hash.c
735 +@@ -250,7 +250,10 @@ static int sun4i_hash(struct ahash_request *areq)
736 + }
737 + } else {
738 + /* Since we have the flag final, we can go up to modulo 4 */
739 +- end = ((areq->nbytes + op->len) / 4) * 4 - op->len;
740 ++ if (areq->nbytes < 4)
741 ++ end = 0;
742 ++ else
743 ++ end = ((areq->nbytes + op->len) / 4) * 4 - op->len;
744 + }
745 +
746 + /* TODO if SGlen % 4 and op->len == 0 then DMA */
747 +diff --git a/drivers/crypto/vmx/aesp8-ppc.pl b/drivers/crypto/vmx/aesp8-ppc.pl
748 +index d9281a28818d..930a3f1e3ec0 100644
749 +--- a/drivers/crypto/vmx/aesp8-ppc.pl
750 ++++ b/drivers/crypto/vmx/aesp8-ppc.pl
751 +@@ -1318,7 +1318,7 @@ Loop_ctr32_enc:
752 + addi $idx,$idx,16
753 + bdnz Loop_ctr32_enc
754 +
755 +- vadduwm $ivec,$ivec,$one
756 ++ vadduqm $ivec,$ivec,$one
757 + vmr $dat,$inptail
758 + lvx $inptail,0,$inp
759 + addi $inp,$inp,16
760 +diff --git a/drivers/dma/at_xdmac.c b/drivers/dma/at_xdmac.c
761 +index b222dd7afe8e..12d904829324 100644
762 +--- a/drivers/dma/at_xdmac.c
763 ++++ b/drivers/dma/at_xdmac.c
764 +@@ -1608,7 +1608,11 @@ static void at_xdmac_tasklet(unsigned long data)
765 + struct at_xdmac_desc,
766 + xfer_node);
767 + dev_vdbg(chan2dev(&atchan->chan), "%s: desc 0x%p\n", __func__, desc);
768 +- BUG_ON(!desc->active_xfer);
769 ++ if (!desc->active_xfer) {
770 ++ dev_err(chan2dev(&atchan->chan), "Xfer not active: exiting");
771 ++ spin_unlock_bh(&atchan->lock);
772 ++ return;
773 ++ }
774 +
775 + txd = &desc->tx_dma_desc;
776 +
777 +diff --git a/drivers/dma/pl330.c b/drivers/dma/pl330.c
778 +index 6d7e3cd4aba4..57b375d0de29 100644
779 +--- a/drivers/dma/pl330.c
780 ++++ b/drivers/dma/pl330.c
781 +@@ -1020,6 +1020,7 @@ static void _stop(struct pl330_thread *thrd)
782 + {
783 + void __iomem *regs = thrd->dmac->base;
784 + u8 insn[6] = {0, 0, 0, 0, 0, 0};
785 ++ u32 inten = readl(regs + INTEN);
786 +
787 + if (_state(thrd) == PL330_STATE_FAULT_COMPLETING)
788 + UNTIL(thrd, PL330_STATE_FAULTING | PL330_STATE_KILLING);
789 +@@ -1032,10 +1033,13 @@ static void _stop(struct pl330_thread *thrd)
790 +
791 + _emit_KILL(0, insn);
792 +
793 +- /* Stop generating interrupts for SEV */
794 +- writel(readl(regs + INTEN) & ~(1 << thrd->ev), regs + INTEN);
795 +-
796 + _execute_DBGINSN(thrd, insn, is_manager(thrd));
797 ++
798 ++ /* clear the event */
799 ++ if (inten & (1 << thrd->ev))
800 ++ writel(1 << thrd->ev, regs + INTCLR);
801 ++ /* Stop generating interrupts for SEV */
802 ++ writel(inten & ~(1 << thrd->ev), regs + INTEN);
803 + }
804 +
805 + /* Start doing req 'idx' of thread 'thrd' */
806 +diff --git a/drivers/dma/tegra210-adma.c b/drivers/dma/tegra210-adma.c
807 +index b10cbaa82ff5..e9e46a520745 100644
808 +--- a/drivers/dma/tegra210-adma.c
809 ++++ b/drivers/dma/tegra210-adma.c
810 +@@ -22,7 +22,6 @@
811 + #include <linux/of_device.h>
812 + #include <linux/of_dma.h>
813 + #include <linux/of_irq.h>
814 +-#include <linux/pm_clock.h>
815 + #include <linux/pm_runtime.h>
816 + #include <linux/slab.h>
817 +
818 +@@ -141,6 +140,7 @@ struct tegra_adma {
819 + struct dma_device dma_dev;
820 + struct device *dev;
821 + void __iomem *base_addr;
822 ++ struct clk *ahub_clk;
823 + unsigned int nr_channels;
824 + unsigned long rx_requests_reserved;
825 + unsigned long tx_requests_reserved;
826 +@@ -637,8 +637,9 @@ static int tegra_adma_runtime_suspend(struct device *dev)
827 + struct tegra_adma *tdma = dev_get_drvdata(dev);
828 +
829 + tdma->global_cmd = tdma_read(tdma, ADMA_GLOBAL_CMD);
830 ++ clk_disable_unprepare(tdma->ahub_clk);
831 +
832 +- return pm_clk_suspend(dev);
833 ++ return 0;
834 + }
835 +
836 + static int tegra_adma_runtime_resume(struct device *dev)
837 +@@ -646,10 +647,11 @@ static int tegra_adma_runtime_resume(struct device *dev)
838 + struct tegra_adma *tdma = dev_get_drvdata(dev);
839 + int ret;
840 +
841 +- ret = pm_clk_resume(dev);
842 +- if (ret)
843 ++ ret = clk_prepare_enable(tdma->ahub_clk);
844 ++ if (ret) {
845 ++ dev_err(dev, "ahub clk_enable failed: %d\n", ret);
846 + return ret;
847 +-
848 ++ }
849 + tdma_write(tdma, ADMA_GLOBAL_CMD, tdma->global_cmd);
850 +
851 + return 0;
852 +@@ -692,13 +694,11 @@ static int tegra_adma_probe(struct platform_device *pdev)
853 + if (IS_ERR(tdma->base_addr))
854 + return PTR_ERR(tdma->base_addr);
855 +
856 +- ret = pm_clk_create(&pdev->dev);
857 +- if (ret)
858 +- return ret;
859 +-
860 +- ret = of_pm_clk_add_clk(&pdev->dev, "d_audio");
861 +- if (ret)
862 +- goto clk_destroy;
863 ++ tdma->ahub_clk = devm_clk_get(&pdev->dev, "d_audio");
864 ++ if (IS_ERR(tdma->ahub_clk)) {
865 ++ dev_err(&pdev->dev, "Error: Missing ahub controller clock\n");
866 ++ return PTR_ERR(tdma->ahub_clk);
867 ++ }
868 +
869 + pm_runtime_enable(&pdev->dev);
870 +
871 +@@ -775,8 +775,6 @@ rpm_put:
872 + pm_runtime_put_sync(&pdev->dev);
873 + rpm_disable:
874 + pm_runtime_disable(&pdev->dev);
875 +-clk_destroy:
876 +- pm_clk_destroy(&pdev->dev);
877 +
878 + return ret;
879 + }
880 +@@ -786,6 +784,7 @@ static int tegra_adma_remove(struct platform_device *pdev)
881 + struct tegra_adma *tdma = platform_get_drvdata(pdev);
882 + int i;
883 +
884 ++ of_dma_controller_free(pdev->dev.of_node);
885 + dma_async_device_unregister(&tdma->dma_dev);
886 +
887 + for (i = 0; i < tdma->nr_channels; ++i)
888 +@@ -793,7 +792,6 @@ static int tegra_adma_remove(struct platform_device *pdev)
889 +
890 + pm_runtime_put_sync(&pdev->dev);
891 + pm_runtime_disable(&pdev->dev);
892 +- pm_clk_destroy(&pdev->dev);
893 +
894 + return 0;
895 + }
896 +diff --git a/drivers/extcon/extcon-arizona.c b/drivers/extcon/extcon-arizona.c
897 +index 56e6c4c7c60d..4c0b6df8b5dd 100644
898 +--- a/drivers/extcon/extcon-arizona.c
899 ++++ b/drivers/extcon/extcon-arizona.c
900 +@@ -1684,6 +1684,16 @@ static int arizona_extcon_remove(struct platform_device *pdev)
901 + struct arizona_extcon_info *info = platform_get_drvdata(pdev);
902 + struct arizona *arizona = info->arizona;
903 + int jack_irq_rise, jack_irq_fall;
904 ++ bool change;
905 ++
906 ++ regmap_update_bits_check(arizona->regmap, ARIZONA_MIC_DETECT_1,
907 ++ ARIZONA_MICD_ENA, 0,
908 ++ &change);
909 ++
910 ++ if (change) {
911 ++ regulator_disable(info->micvdd);
912 ++ pm_runtime_put(info->dev);
913 ++ }
914 +
915 + gpiod_put(info->micd_pol_gpio);
916 +
917 +diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
918 +index c37b7b5f1dd3..921f7f690ae9 100644
919 +--- a/drivers/gpu/drm/drm_fops.c
920 ++++ b/drivers/gpu/drm/drm_fops.c
921 +@@ -515,6 +515,7 @@ put_back_event:
922 + file_priv->event_space -= length;
923 + list_add(&e->link, &file_priv->event_list);
924 + spin_unlock_irq(&dev->event_lock);
925 ++ wake_up_interruptible(&file_priv->event_wait);
926 + break;
927 + }
928 +
929 +diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
930 +index 70597854397f..ceb4df96e0d5 100644
931 +--- a/drivers/hid/hid-core.c
932 ++++ b/drivers/hid/hid-core.c
933 +@@ -200,13 +200,14 @@ static unsigned hid_lookup_collection(struct hid_parser *parser, unsigned type)
934 + * Add a usage to the temporary parser table.
935 + */
936 +
937 +-static int hid_add_usage(struct hid_parser *parser, unsigned usage)
938 ++static int hid_add_usage(struct hid_parser *parser, unsigned usage, u8 size)
939 + {
940 + if (parser->local.usage_index >= HID_MAX_USAGES) {
941 + hid_err(parser->device, "usage index exceeded\n");
942 + return -1;
943 + }
944 + parser->local.usage[parser->local.usage_index] = usage;
945 ++ parser->local.usage_size[parser->local.usage_index] = size;
946 + parser->local.collection_index[parser->local.usage_index] =
947 + parser->collection_stack_ptr ?
948 + parser->collection_stack[parser->collection_stack_ptr - 1] : 0;
949 +@@ -463,10 +464,7 @@ static int hid_parser_local(struct hid_parser *parser, struct hid_item *item)
950 + return 0;
951 + }
952 +
953 +- if (item->size <= 2)
954 +- data = (parser->global.usage_page << 16) + data;
955 +-
956 +- return hid_add_usage(parser, data);
957 ++ return hid_add_usage(parser, data, item->size);
958 +
959 + case HID_LOCAL_ITEM_TAG_USAGE_MINIMUM:
960 +
961 +@@ -475,9 +473,6 @@ static int hid_parser_local(struct hid_parser *parser, struct hid_item *item)
962 + return 0;
963 + }
964 +
965 +- if (item->size <= 2)
966 +- data = (parser->global.usage_page << 16) + data;
967 +-
968 + parser->local.usage_minimum = data;
969 + return 0;
970 +
971 +@@ -488,9 +483,6 @@ static int hid_parser_local(struct hid_parser *parser, struct hid_item *item)
972 + return 0;
973 + }
974 +
975 +- if (item->size <= 2)
976 +- data = (parser->global.usage_page << 16) + data;
977 +-
978 + count = data - parser->local.usage_minimum;
979 + if (count + parser->local.usage_index >= HID_MAX_USAGES) {
980 + /*
981 +@@ -510,7 +502,7 @@ static int hid_parser_local(struct hid_parser *parser, struct hid_item *item)
982 + }
983 +
984 + for (n = parser->local.usage_minimum; n <= data; n++)
985 +- if (hid_add_usage(parser, n)) {
986 ++ if (hid_add_usage(parser, n, item->size)) {
987 + dbg_hid("hid_add_usage failed\n");
988 + return -1;
989 + }
990 +@@ -524,6 +516,22 @@ static int hid_parser_local(struct hid_parser *parser, struct hid_item *item)
991 + return 0;
992 + }
993 +
994 ++/*
995 ++ * Concatenate Usage Pages into Usages where relevant:
996 ++ * As per specification, 6.2.2.8: "When the parser encounters a main item it
997 ++ * concatenates the last declared Usage Page with a Usage to form a complete
998 ++ * usage value."
999 ++ */
1000 ++
1001 ++static void hid_concatenate_usage_page(struct hid_parser *parser)
1002 ++{
1003 ++ int i;
1004 ++
1005 ++ for (i = 0; i < parser->local.usage_index; i++)
1006 ++ if (parser->local.usage_size[i] <= 2)
1007 ++ parser->local.usage[i] += parser->global.usage_page << 16;
1008 ++}
1009 ++
1010 + /*
1011 + * Process a main item.
1012 + */
1013 +@@ -533,6 +541,8 @@ static int hid_parser_main(struct hid_parser *parser, struct hid_item *item)
1014 + __u32 data;
1015 + int ret;
1016 +
1017 ++ hid_concatenate_usage_page(parser);
1018 ++
1019 + data = item_udata(item);
1020 +
1021 + switch (item->tag) {
1022 +@@ -746,6 +756,8 @@ static int hid_scan_main(struct hid_parser *parser, struct hid_item *item)
1023 + __u32 data;
1024 + int i;
1025 +
1026 ++ hid_concatenate_usage_page(parser);
1027 ++
1028 + data = item_udata(item);
1029 +
1030 + switch (item->tag) {
1031 +diff --git a/drivers/hid/hid-logitech-hidpp.c b/drivers/hid/hid-logitech-hidpp.c
1032 +index 3198faf5cff4..38d9deb03d16 100644
1033 +--- a/drivers/hid/hid-logitech-hidpp.c
1034 ++++ b/drivers/hid/hid-logitech-hidpp.c
1035 +@@ -449,13 +449,16 @@ static int hidpp_root_get_feature(struct hidpp_device *hidpp, u16 feature,
1036 +
1037 + static int hidpp_root_get_protocol_version(struct hidpp_device *hidpp)
1038 + {
1039 ++ const u8 ping_byte = 0x5a;
1040 ++ u8 ping_data[3] = { 0, 0, ping_byte };
1041 + struct hidpp_report response;
1042 + int ret;
1043 +
1044 +- ret = hidpp_send_fap_command_sync(hidpp,
1045 ++ ret = hidpp_send_rap_command_sync(hidpp,
1046 ++ REPORT_ID_HIDPP_SHORT,
1047 + HIDPP_PAGE_ROOT_IDX,
1048 + CMD_ROOT_GET_PROTOCOL_VERSION,
1049 +- NULL, 0, &response);
1050 ++ ping_data, sizeof(ping_data), &response);
1051 +
1052 + if (ret == HIDPP_ERROR_INVALID_SUBID) {
1053 + hidpp->protocol_major = 1;
1054 +@@ -475,8 +478,14 @@ static int hidpp_root_get_protocol_version(struct hidpp_device *hidpp)
1055 + if (ret)
1056 + return ret;
1057 +
1058 +- hidpp->protocol_major = response.fap.params[0];
1059 +- hidpp->protocol_minor = response.fap.params[1];
1060 ++ if (response.rap.params[2] != ping_byte) {
1061 ++ hid_err(hidpp->hid_dev, "%s: ping mismatch 0x%02x != 0x%02x\n",
1062 ++ __func__, response.rap.params[2], ping_byte);
1063 ++ return -EPROTO;
1064 ++ }
1065 ++
1066 ++ hidpp->protocol_major = response.rap.params[0];
1067 ++ hidpp->protocol_minor = response.rap.params[1];
1068 +
1069 + return ret;
1070 + }
1071 +diff --git a/drivers/hwmon/f71805f.c b/drivers/hwmon/f71805f.c
1072 +index facd05cda26d..e8c089886427 100644
1073 +--- a/drivers/hwmon/f71805f.c
1074 ++++ b/drivers/hwmon/f71805f.c
1075 +@@ -96,17 +96,23 @@ superio_select(int base, int ld)
1076 + outb(ld, base + 1);
1077 + }
1078 +
1079 +-static inline void
1080 ++static inline int
1081 + superio_enter(int base)
1082 + {
1083 ++ if (!request_muxed_region(base, 2, DRVNAME))
1084 ++ return -EBUSY;
1085 ++
1086 + outb(0x87, base);
1087 + outb(0x87, base);
1088 ++
1089 ++ return 0;
1090 + }
1091 +
1092 + static inline void
1093 + superio_exit(int base)
1094 + {
1095 + outb(0xaa, base);
1096 ++ release_region(base, 2);
1097 + }
1098 +
1099 + /*
1100 +@@ -1561,7 +1567,7 @@ exit:
1101 + static int __init f71805f_find(int sioaddr, unsigned short *address,
1102 + struct f71805f_sio_data *sio_data)
1103 + {
1104 +- int err = -ENODEV;
1105 ++ int err;
1106 + u16 devid;
1107 +
1108 + static const char * const names[] = {
1109 +@@ -1569,8 +1575,11 @@ static int __init f71805f_find(int sioaddr, unsigned short *address,
1110 + "F71872F/FG or F71806F/FG",
1111 + };
1112 +
1113 +- superio_enter(sioaddr);
1114 ++ err = superio_enter(sioaddr);
1115 ++ if (err)
1116 ++ return err;
1117 +
1118 ++ err = -ENODEV;
1119 + devid = superio_inw(sioaddr, SIO_REG_MANID);
1120 + if (devid != SIO_FINTEK_ID)
1121 + goto exit;
1122 +diff --git a/drivers/hwmon/pc87427.c b/drivers/hwmon/pc87427.c
1123 +index cb9fdd37bd0d..2b5b8c3de8fc 100644
1124 +--- a/drivers/hwmon/pc87427.c
1125 ++++ b/drivers/hwmon/pc87427.c
1126 +@@ -106,6 +106,13 @@ static const char *logdev_str[2] = { DRVNAME " FMC", DRVNAME " HMC" };
1127 + #define LD_IN 1
1128 + #define LD_TEMP 1
1129 +
1130 ++static inline int superio_enter(int sioaddr)
1131 ++{
1132 ++ if (!request_muxed_region(sioaddr, 2, DRVNAME))
1133 ++ return -EBUSY;
1134 ++ return 0;
1135 ++}
1136 ++
1137 + static inline void superio_outb(int sioaddr, int reg, int val)
1138 + {
1139 + outb(reg, sioaddr);
1140 +@@ -122,6 +129,7 @@ static inline void superio_exit(int sioaddr)
1141 + {
1142 + outb(0x02, sioaddr);
1143 + outb(0x02, sioaddr + 1);
1144 ++ release_region(sioaddr, 2);
1145 + }
1146 +
1147 + /*
1148 +@@ -1220,7 +1228,11 @@ static int __init pc87427_find(int sioaddr, struct pc87427_sio_data *sio_data)
1149 + {
1150 + u16 val;
1151 + u8 cfg, cfg_b;
1152 +- int i, err = 0;
1153 ++ int i, err;
1154 ++
1155 ++ err = superio_enter(sioaddr);
1156 ++ if (err)
1157 ++ return err;
1158 +
1159 + /* Identify device */
1160 + val = force_id ? force_id : superio_inb(sioaddr, SIOREG_DEVID);
1161 +diff --git a/drivers/hwmon/smsc47b397.c b/drivers/hwmon/smsc47b397.c
1162 +index 6bd200756560..cbdb5c4991ae 100644
1163 +--- a/drivers/hwmon/smsc47b397.c
1164 ++++ b/drivers/hwmon/smsc47b397.c
1165 +@@ -72,14 +72,19 @@ static inline void superio_select(int ld)
1166 + superio_outb(0x07, ld);
1167 + }
1168 +
1169 +-static inline void superio_enter(void)
1170 ++static inline int superio_enter(void)
1171 + {
1172 ++ if (!request_muxed_region(REG, 2, DRVNAME))
1173 ++ return -EBUSY;
1174 ++
1175 + outb(0x55, REG);
1176 ++ return 0;
1177 + }
1178 +
1179 + static inline void superio_exit(void)
1180 + {
1181 + outb(0xAA, REG);
1182 ++ release_region(REG, 2);
1183 + }
1184 +
1185 + #define SUPERIO_REG_DEVID 0x20
1186 +@@ -300,8 +305,12 @@ static int __init smsc47b397_find(void)
1187 + u8 id, rev;
1188 + char *name;
1189 + unsigned short addr;
1190 ++ int err;
1191 ++
1192 ++ err = superio_enter();
1193 ++ if (err)
1194 ++ return err;
1195 +
1196 +- superio_enter();
1197 + id = force_id ? force_id : superio_inb(SUPERIO_REG_DEVID);
1198 +
1199 + switch (id) {
1200 +diff --git a/drivers/hwmon/smsc47m1.c b/drivers/hwmon/smsc47m1.c
1201 +index 5d323186d2c1..d24df0c50bea 100644
1202 +--- a/drivers/hwmon/smsc47m1.c
1203 ++++ b/drivers/hwmon/smsc47m1.c
1204 +@@ -73,16 +73,21 @@ superio_inb(int reg)
1205 + /* logical device for fans is 0x0A */
1206 + #define superio_select() superio_outb(0x07, 0x0A)
1207 +
1208 +-static inline void
1209 ++static inline int
1210 + superio_enter(void)
1211 + {
1212 ++ if (!request_muxed_region(REG, 2, DRVNAME))
1213 ++ return -EBUSY;
1214 ++
1215 + outb(0x55, REG);
1216 ++ return 0;
1217 + }
1218 +
1219 + static inline void
1220 + superio_exit(void)
1221 + {
1222 + outb(0xAA, REG);
1223 ++ release_region(REG, 2);
1224 + }
1225 +
1226 + #define SUPERIO_REG_ACT 0x30
1227 +@@ -531,8 +536,12 @@ static int __init smsc47m1_find(struct smsc47m1_sio_data *sio_data)
1228 + {
1229 + u8 val;
1230 + unsigned short addr;
1231 ++ int err;
1232 ++
1233 ++ err = superio_enter();
1234 ++ if (err)
1235 ++ return err;
1236 +
1237 +- superio_enter();
1238 + val = force_id ? force_id : superio_inb(SUPERIO_REG_DEVID);
1239 +
1240 + /*
1241 +@@ -608,13 +617,14 @@ static int __init smsc47m1_find(struct smsc47m1_sio_data *sio_data)
1242 + static void smsc47m1_restore(const struct smsc47m1_sio_data *sio_data)
1243 + {
1244 + if ((sio_data->activate & 0x01) == 0) {
1245 +- superio_enter();
1246 +- superio_select();
1247 +-
1248 +- pr_info("Disabling device\n");
1249 +- superio_outb(SUPERIO_REG_ACT, sio_data->activate);
1250 +-
1251 +- superio_exit();
1252 ++ if (!superio_enter()) {
1253 ++ superio_select();
1254 ++ pr_info("Disabling device\n");
1255 ++ superio_outb(SUPERIO_REG_ACT, sio_data->activate);
1256 ++ superio_exit();
1257 ++ } else {
1258 ++ pr_warn("Failed to disable device\n");
1259 ++ }
1260 + }
1261 + }
1262 +
1263 +diff --git a/drivers/hwmon/vt1211.c b/drivers/hwmon/vt1211.c
1264 +index 3a6bfa51cb94..95d5e8ec8b7f 100644
1265 +--- a/drivers/hwmon/vt1211.c
1266 ++++ b/drivers/hwmon/vt1211.c
1267 +@@ -226,15 +226,21 @@ static inline void superio_select(int sio_cip, int ldn)
1268 + outb(ldn, sio_cip + 1);
1269 + }
1270 +
1271 +-static inline void superio_enter(int sio_cip)
1272 ++static inline int superio_enter(int sio_cip)
1273 + {
1274 ++ if (!request_muxed_region(sio_cip, 2, DRVNAME))
1275 ++ return -EBUSY;
1276 ++
1277 + outb(0x87, sio_cip);
1278 + outb(0x87, sio_cip);
1279 ++
1280 ++ return 0;
1281 + }
1282 +
1283 + static inline void superio_exit(int sio_cip)
1284 + {
1285 + outb(0xaa, sio_cip);
1286 ++ release_region(sio_cip, 2);
1287 + }
1288 +
1289 + /* ---------------------------------------------------------------------
1290 +@@ -1282,11 +1288,14 @@ EXIT:
1291 +
1292 + static int __init vt1211_find(int sio_cip, unsigned short *address)
1293 + {
1294 +- int err = -ENODEV;
1295 ++ int err;
1296 + int devid;
1297 +
1298 +- superio_enter(sio_cip);
1299 ++ err = superio_enter(sio_cip);
1300 ++ if (err)
1301 ++ return err;
1302 +
1303 ++ err = -ENODEV;
1304 + devid = force_id ? force_id : superio_inb(sio_cip, SIO_VT1211_DEVID);
1305 + if (devid != SIO_VT1211_ID)
1306 + goto EXIT;
1307 +diff --git a/drivers/iio/adc/ad_sigma_delta.c b/drivers/iio/adc/ad_sigma_delta.c
1308 +index a1d072ecb717..30f200ad6b97 100644
1309 +--- a/drivers/iio/adc/ad_sigma_delta.c
1310 ++++ b/drivers/iio/adc/ad_sigma_delta.c
1311 +@@ -62,7 +62,7 @@ int ad_sd_write_reg(struct ad_sigma_delta *sigma_delta, unsigned int reg,
1312 + struct spi_transfer t = {
1313 + .tx_buf = data,
1314 + .len = size + 1,
1315 +- .cs_change = sigma_delta->bus_locked,
1316 ++ .cs_change = sigma_delta->keep_cs_asserted,
1317 + };
1318 + struct spi_message m;
1319 + int ret;
1320 +@@ -217,6 +217,7 @@ static int ad_sd_calibrate(struct ad_sigma_delta *sigma_delta,
1321 +
1322 + spi_bus_lock(sigma_delta->spi->master);
1323 + sigma_delta->bus_locked = true;
1324 ++ sigma_delta->keep_cs_asserted = true;
1325 + reinit_completion(&sigma_delta->completion);
1326 +
1327 + ret = ad_sigma_delta_set_mode(sigma_delta, mode);
1328 +@@ -234,9 +235,10 @@ static int ad_sd_calibrate(struct ad_sigma_delta *sigma_delta,
1329 + ret = 0;
1330 + }
1331 + out:
1332 ++ sigma_delta->keep_cs_asserted = false;
1333 ++ ad_sigma_delta_set_mode(sigma_delta, AD_SD_MODE_IDLE);
1334 + sigma_delta->bus_locked = false;
1335 + spi_bus_unlock(sigma_delta->spi->master);
1336 +- ad_sigma_delta_set_mode(sigma_delta, AD_SD_MODE_IDLE);
1337 +
1338 + return ret;
1339 + }
1340 +@@ -288,6 +290,7 @@ int ad_sigma_delta_single_conversion(struct iio_dev *indio_dev,
1341 +
1342 + spi_bus_lock(sigma_delta->spi->master);
1343 + sigma_delta->bus_locked = true;
1344 ++ sigma_delta->keep_cs_asserted = true;
1345 + reinit_completion(&sigma_delta->completion);
1346 +
1347 + ad_sigma_delta_set_mode(sigma_delta, AD_SD_MODE_SINGLE);
1348 +@@ -297,9 +300,6 @@ int ad_sigma_delta_single_conversion(struct iio_dev *indio_dev,
1349 + ret = wait_for_completion_interruptible_timeout(
1350 + &sigma_delta->completion, HZ);
1351 +
1352 +- sigma_delta->bus_locked = false;
1353 +- spi_bus_unlock(sigma_delta->spi->master);
1354 +-
1355 + if (ret == 0)
1356 + ret = -EIO;
1357 + if (ret < 0)
1358 +@@ -315,7 +315,10 @@ out:
1359 + sigma_delta->irq_dis = true;
1360 + }
1361 +
1362 ++ sigma_delta->keep_cs_asserted = false;
1363 + ad_sigma_delta_set_mode(sigma_delta, AD_SD_MODE_IDLE);
1364 ++ sigma_delta->bus_locked = false;
1365 ++ spi_bus_unlock(sigma_delta->spi->master);
1366 + mutex_unlock(&indio_dev->mlock);
1367 +
1368 + if (ret)
1369 +@@ -352,6 +355,8 @@ static int ad_sd_buffer_postenable(struct iio_dev *indio_dev)
1370 +
1371 + spi_bus_lock(sigma_delta->spi->master);
1372 + sigma_delta->bus_locked = true;
1373 ++ sigma_delta->keep_cs_asserted = true;
1374 ++
1375 + ret = ad_sigma_delta_set_mode(sigma_delta, AD_SD_MODE_CONTINUOUS);
1376 + if (ret)
1377 + goto err_unlock;
1378 +@@ -380,6 +385,7 @@ static int ad_sd_buffer_postdisable(struct iio_dev *indio_dev)
1379 + sigma_delta->irq_dis = true;
1380 + }
1381 +
1382 ++ sigma_delta->keep_cs_asserted = false;
1383 + ad_sigma_delta_set_mode(sigma_delta, AD_SD_MODE_IDLE);
1384 +
1385 + sigma_delta->bus_locked = false;
1386 +diff --git a/drivers/iio/common/ssp_sensors/ssp_iio.c b/drivers/iio/common/ssp_sensors/ssp_iio.c
1387 +index a3ae165f8d9f..16180e6321bd 100644
1388 +--- a/drivers/iio/common/ssp_sensors/ssp_iio.c
1389 ++++ b/drivers/iio/common/ssp_sensors/ssp_iio.c
1390 +@@ -80,7 +80,7 @@ int ssp_common_process_data(struct iio_dev *indio_dev, void *buf,
1391 + unsigned int len, int64_t timestamp)
1392 + {
1393 + __le32 time;
1394 +- int64_t calculated_time;
1395 ++ int64_t calculated_time = 0;
1396 + struct ssp_sensor_data *spd = iio_priv(indio_dev);
1397 +
1398 + if (indio_dev->scan_bytes == 0)
1399 +diff --git a/drivers/iio/magnetometer/hmc5843_i2c.c b/drivers/iio/magnetometer/hmc5843_i2c.c
1400 +index 3de7f4426ac4..86abba5827a2 100644
1401 +--- a/drivers/iio/magnetometer/hmc5843_i2c.c
1402 ++++ b/drivers/iio/magnetometer/hmc5843_i2c.c
1403 +@@ -58,8 +58,13 @@ static const struct regmap_config hmc5843_i2c_regmap_config = {
1404 + static int hmc5843_i2c_probe(struct i2c_client *cli,
1405 + const struct i2c_device_id *id)
1406 + {
1407 ++ struct regmap *regmap = devm_regmap_init_i2c(cli,
1408 ++ &hmc5843_i2c_regmap_config);
1409 ++ if (IS_ERR(regmap))
1410 ++ return PTR_ERR(regmap);
1411 ++
1412 + return hmc5843_common_probe(&cli->dev,
1413 +- devm_regmap_init_i2c(cli, &hmc5843_i2c_regmap_config),
1414 ++ regmap,
1415 + id->driver_data, id->name);
1416 + }
1417 +
1418 +diff --git a/drivers/iio/magnetometer/hmc5843_spi.c b/drivers/iio/magnetometer/hmc5843_spi.c
1419 +index 535f03a70d63..79b2b707f90e 100644
1420 +--- a/drivers/iio/magnetometer/hmc5843_spi.c
1421 ++++ b/drivers/iio/magnetometer/hmc5843_spi.c
1422 +@@ -58,6 +58,7 @@ static const struct regmap_config hmc5843_spi_regmap_config = {
1423 + static int hmc5843_spi_probe(struct spi_device *spi)
1424 + {
1425 + int ret;
1426 ++ struct regmap *regmap;
1427 + const struct spi_device_id *id = spi_get_device_id(spi);
1428 +
1429 + spi->mode = SPI_MODE_3;
1430 +@@ -67,8 +68,12 @@ static int hmc5843_spi_probe(struct spi_device *spi)
1431 + if (ret)
1432 + return ret;
1433 +
1434 ++ regmap = devm_regmap_init_spi(spi, &hmc5843_spi_regmap_config);
1435 ++ if (IS_ERR(regmap))
1436 ++ return PTR_ERR(regmap);
1437 ++
1438 + return hmc5843_common_probe(&spi->dev,
1439 +- devm_regmap_init_spi(spi, &hmc5843_spi_regmap_config),
1440 ++ regmap,
1441 + id->driver_data, id->name);
1442 + }
1443 +
1444 +diff --git a/drivers/infiniband/hw/cxgb4/cm.c b/drivers/infiniband/hw/cxgb4/cm.c
1445 +index a2322b2dbd82..e5752352e0fb 100644
1446 +--- a/drivers/infiniband/hw/cxgb4/cm.c
1447 ++++ b/drivers/infiniband/hw/cxgb4/cm.c
1448 +@@ -455,6 +455,8 @@ static struct sk_buff *get_skb(struct sk_buff *skb, int len, gfp_t gfp)
1449 + skb_reset_transport_header(skb);
1450 + } else {
1451 + skb = alloc_skb(len, gfp);
1452 ++ if (!skb)
1453 ++ return NULL;
1454 + }
1455 + t4_set_arp_err_handler(skb, NULL, NULL);
1456 + return skb;
1457 +diff --git a/drivers/md/bcache/alloc.c b/drivers/md/bcache/alloc.c
1458 +index dd344ee9e62b..ebacd21714ef 100644
1459 +--- a/drivers/md/bcache/alloc.c
1460 ++++ b/drivers/md/bcache/alloc.c
1461 +@@ -322,10 +322,11 @@ static int bch_allocator_thread(void *arg)
1462 + * possibly issue discards to them, then we add the bucket to
1463 + * the free list:
1464 + */
1465 +- while (!fifo_empty(&ca->free_inc)) {
1466 ++ while (1) {
1467 + long bucket;
1468 +
1469 +- fifo_pop(&ca->free_inc, bucket);
1470 ++ if (!fifo_pop(&ca->free_inc, bucket))
1471 ++ break;
1472 +
1473 + if (ca->discard) {
1474 + mutex_unlock(&ca->set->bucket_lock);
1475 +diff --git a/drivers/md/bcache/journal.c b/drivers/md/bcache/journal.c
1476 +index c76a0176b5c6..6ee5370eb916 100644
1477 +--- a/drivers/md/bcache/journal.c
1478 ++++ b/drivers/md/bcache/journal.c
1479 +@@ -309,6 +309,18 @@ void bch_journal_mark(struct cache_set *c, struct list_head *list)
1480 + }
1481 + }
1482 +
1483 ++bool is_discard_enabled(struct cache_set *s)
1484 ++{
1485 ++ struct cache *ca;
1486 ++ unsigned int i;
1487 ++
1488 ++ for_each_cache(ca, s, i)
1489 ++ if (ca->discard)
1490 ++ return true;
1491 ++
1492 ++ return false;
1493 ++}
1494 ++
1495 + int bch_journal_replay(struct cache_set *s, struct list_head *list)
1496 + {
1497 + int ret = 0, keys = 0, entries = 0;
1498 +@@ -322,9 +334,17 @@ int bch_journal_replay(struct cache_set *s, struct list_head *list)
1499 + list_for_each_entry(i, list, list) {
1500 + BUG_ON(i->pin && atomic_read(i->pin) != 1);
1501 +
1502 +- cache_set_err_on(n != i->j.seq, s,
1503 +-"bcache: journal entries %llu-%llu missing! (replaying %llu-%llu)",
1504 +- n, i->j.seq - 1, start, end);
1505 ++ if (n != i->j.seq) {
1506 ++ if (n == start && is_discard_enabled(s))
1507 ++ pr_info("bcache: journal entries %llu-%llu may be discarded! (replaying %llu-%llu)",
1508 ++ n, i->j.seq - 1, start, end);
1509 ++ else {
1510 ++ pr_err("bcache: journal entries %llu-%llu missing! (replaying %llu-%llu)",
1511 ++ n, i->j.seq - 1, start, end);
1512 ++ ret = -EIO;
1513 ++ goto err;
1514 ++ }
1515 ++ }
1516 +
1517 + for (k = i->j.start;
1518 + k < bset_bkey_last(&i->j);
1519 +diff --git a/drivers/md/bcache/super.c b/drivers/md/bcache/super.c
1520 +index 362efc8dd16f..9f2588eaaf5f 100644
1521 +--- a/drivers/md/bcache/super.c
1522 ++++ b/drivers/md/bcache/super.c
1523 +@@ -1561,7 +1561,7 @@ err:
1524 + return NULL;
1525 + }
1526 +
1527 +-static void run_cache_set(struct cache_set *c)
1528 ++static int run_cache_set(struct cache_set *c)
1529 + {
1530 + const char *err = "cannot allocate memory";
1531 + struct cached_dev *dc, *t;
1532 +@@ -1653,7 +1653,9 @@ static void run_cache_set(struct cache_set *c)
1533 + if (j->version < BCACHE_JSET_VERSION_UUID)
1534 + __uuid_write(c);
1535 +
1536 +- bch_journal_replay(c, &journal);
1537 ++ err = "bcache: replay journal failed";
1538 ++ if (bch_journal_replay(c, &journal))
1539 ++ goto err;
1540 + } else {
1541 + pr_notice("invalidating existing data");
1542 +
1543 +@@ -1721,11 +1723,13 @@ static void run_cache_set(struct cache_set *c)
1544 + flash_devs_run(c);
1545 +
1546 + set_bit(CACHE_SET_RUNNING, &c->flags);
1547 +- return;
1548 ++ return 0;
1549 + err:
1550 + closure_sync(&cl);
1551 + /* XXX: test this, it's broken */
1552 + bch_cache_set_error(c, "%s", err);
1553 ++
1554 ++ return -EIO;
1555 + }
1556 +
1557 + static bool can_attach_cache(struct cache *ca, struct cache_set *c)
1558 +@@ -1789,8 +1793,11 @@ found:
1559 + ca->set->cache[ca->sb.nr_this_dev] = ca;
1560 + c->cache_by_alloc[c->caches_loaded++] = ca;
1561 +
1562 +- if (c->caches_loaded == c->sb.nr_in_set)
1563 +- run_cache_set(c);
1564 ++ if (c->caches_loaded == c->sb.nr_in_set) {
1565 ++ err = "failed to run cache set";
1566 ++ if (run_cache_set(c) < 0)
1567 ++ goto err;
1568 ++ }
1569 +
1570 + return NULL;
1571 + err:
1572 +diff --git a/drivers/media/dvb-frontends/m88ds3103.c b/drivers/media/dvb-frontends/m88ds3103.c
1573 +index 31f16105184c..59a4563c0466 100644
1574 +--- a/drivers/media/dvb-frontends/m88ds3103.c
1575 ++++ b/drivers/media/dvb-frontends/m88ds3103.c
1576 +@@ -309,6 +309,9 @@ static int m88ds3103_set_frontend(struct dvb_frontend *fe)
1577 + u16 u16tmp;
1578 + u32 tuner_frequency_khz, target_mclk;
1579 + s32 s32tmp;
1580 ++ static const struct reg_sequence reset_buf[] = {
1581 ++ {0x07, 0x80}, {0x07, 0x00}
1582 ++ };
1583 +
1584 + dev_dbg(&client->dev,
1585 + "delivery_system=%d modulation=%d frequency=%u symbol_rate=%d inversion=%d pilot=%d rolloff=%d\n",
1586 +@@ -321,11 +324,7 @@ static int m88ds3103_set_frontend(struct dvb_frontend *fe)
1587 + }
1588 +
1589 + /* reset */
1590 +- ret = regmap_write(dev->regmap, 0x07, 0x80);
1591 +- if (ret)
1592 +- goto err;
1593 +-
1594 +- ret = regmap_write(dev->regmap, 0x07, 0x00);
1595 ++ ret = regmap_multi_reg_write(dev->regmap, reset_buf, 2);
1596 + if (ret)
1597 + goto err;
1598 +
1599 +diff --git a/drivers/media/i2c/ov2659.c b/drivers/media/i2c/ov2659.c
1600 +index 1f999e9c0118..3554eea77e04 100644
1601 +--- a/drivers/media/i2c/ov2659.c
1602 ++++ b/drivers/media/i2c/ov2659.c
1603 +@@ -1117,8 +1117,10 @@ static int ov2659_set_fmt(struct v4l2_subdev *sd,
1604 + if (ov2659_formats[index].code == mf->code)
1605 + break;
1606 +
1607 +- if (index < 0)
1608 +- return -EINVAL;
1609 ++ if (index < 0) {
1610 ++ index = 0;
1611 ++ mf->code = ov2659_formats[index].code;
1612 ++ }
1613 +
1614 + mf->colorspace = V4L2_COLORSPACE_SRGB;
1615 + mf->code = ov2659_formats[index].code;
1616 +diff --git a/drivers/media/i2c/soc_camera/ov6650.c b/drivers/media/i2c/soc_camera/ov6650.c
1617 +index e21b7e1c2ee1..fc187c5aeb1e 100644
1618 +--- a/drivers/media/i2c/soc_camera/ov6650.c
1619 ++++ b/drivers/media/i2c/soc_camera/ov6650.c
1620 +@@ -840,9 +840,16 @@ static int ov6650_video_probe(struct i2c_client *client)
1621 + u8 pidh, pidl, midh, midl;
1622 + int ret;
1623 +
1624 ++ priv->clk = v4l2_clk_get(&client->dev, NULL);
1625 ++ if (IS_ERR(priv->clk)) {
1626 ++ ret = PTR_ERR(priv->clk);
1627 ++ dev_err(&client->dev, "v4l2_clk request err: %d\n", ret);
1628 ++ return ret;
1629 ++ }
1630 ++
1631 + ret = ov6650_s_power(&priv->subdev, 1);
1632 + if (ret < 0)
1633 +- return ret;
1634 ++ goto eclkput;
1635 +
1636 + msleep(20);
1637 +
1638 +@@ -879,6 +886,11 @@ static int ov6650_video_probe(struct i2c_client *client)
1639 +
1640 + done:
1641 + ov6650_s_power(&priv->subdev, 0);
1642 ++ if (!ret)
1643 ++ return 0;
1644 ++eclkput:
1645 ++ v4l2_clk_put(priv->clk);
1646 ++
1647 + return ret;
1648 + }
1649 +
1650 +@@ -1035,18 +1047,9 @@ static int ov6650_probe(struct i2c_client *client,
1651 + priv->code = MEDIA_BUS_FMT_YUYV8_2X8;
1652 + priv->colorspace = V4L2_COLORSPACE_JPEG;
1653 +
1654 +- priv->clk = v4l2_clk_get(&client->dev, NULL);
1655 +- if (IS_ERR(priv->clk)) {
1656 +- ret = PTR_ERR(priv->clk);
1657 +- goto eclkget;
1658 +- }
1659 +-
1660 + ret = ov6650_video_probe(client);
1661 +- if (ret) {
1662 +- v4l2_clk_put(priv->clk);
1663 +-eclkget:
1664 ++ if (ret)
1665 + v4l2_ctrl_handler_free(&priv->hdl);
1666 +- }
1667 +
1668 + return ret;
1669 + }
1670 +diff --git a/drivers/media/pci/saa7146/hexium_gemini.c b/drivers/media/pci/saa7146/hexium_gemini.c
1671 +index c889ec9f8a5a..f5fc8bcbd14b 100644
1672 +--- a/drivers/media/pci/saa7146/hexium_gemini.c
1673 ++++ b/drivers/media/pci/saa7146/hexium_gemini.c
1674 +@@ -270,9 +270,8 @@ static int hexium_attach(struct saa7146_dev *dev, struct saa7146_pci_extension_d
1675 + /* enable i2c-port pins */
1676 + saa7146_write(dev, MC1, (MASK_08 | MASK_24 | MASK_10 | MASK_26));
1677 +
1678 +- hexium->i2c_adapter = (struct i2c_adapter) {
1679 +- .name = "hexium gemini",
1680 +- };
1681 ++ strscpy(hexium->i2c_adapter.name, "hexium gemini",
1682 ++ sizeof(hexium->i2c_adapter.name));
1683 + saa7146_i2c_adapter_prepare(dev, &hexium->i2c_adapter, SAA7146_I2C_BUS_BIT_RATE_480);
1684 + if (i2c_add_adapter(&hexium->i2c_adapter) < 0) {
1685 + DEB_S("cannot register i2c-device. skipping.\n");
1686 +diff --git a/drivers/media/pci/saa7146/hexium_orion.c b/drivers/media/pci/saa7146/hexium_orion.c
1687 +index c306a92e8909..dc07ca37ebd0 100644
1688 +--- a/drivers/media/pci/saa7146/hexium_orion.c
1689 ++++ b/drivers/media/pci/saa7146/hexium_orion.c
1690 +@@ -232,9 +232,8 @@ static int hexium_probe(struct saa7146_dev *dev)
1691 + saa7146_write(dev, DD1_STREAM_B, 0x00000000);
1692 + saa7146_write(dev, MC2, (MASK_09 | MASK_25 | MASK_10 | MASK_26));
1693 +
1694 +- hexium->i2c_adapter = (struct i2c_adapter) {
1695 +- .name = "hexium orion",
1696 +- };
1697 ++ strscpy(hexium->i2c_adapter.name, "hexium orion",
1698 ++ sizeof(hexium->i2c_adapter.name));
1699 + saa7146_i2c_adapter_prepare(dev, &hexium->i2c_adapter, SAA7146_I2C_BUS_BIT_RATE_480);
1700 + if (i2c_add_adapter(&hexium->i2c_adapter) < 0) {
1701 + DEB_S("cannot register i2c-device. skipping.\n");
1702 +diff --git a/drivers/media/platform/coda/coda-bit.c b/drivers/media/platform/coda/coda-bit.c
1703 +index b6625047250d..717ee9a6a80e 100644
1704 +--- a/drivers/media/platform/coda/coda-bit.c
1705 ++++ b/drivers/media/platform/coda/coda-bit.c
1706 +@@ -1829,6 +1829,9 @@ static int coda_prepare_decode(struct coda_ctx *ctx)
1707 + /* Clear decode success flag */
1708 + coda_write(dev, 0, CODA_RET_DEC_PIC_SUCCESS);
1709 +
1710 ++ /* Clear error return value */
1711 ++ coda_write(dev, 0, CODA_RET_DEC_PIC_ERR_MB);
1712 ++
1713 + trace_coda_dec_pic_run(ctx, meta);
1714 +
1715 + coda_command_async(ctx, CODA_COMMAND_PIC_RUN);
1716 +diff --git a/drivers/media/platform/vivid/vivid-vid-cap.c b/drivers/media/platform/vivid/vivid-vid-cap.c
1717 +index 25d4fd4f4c0b..a72982df4777 100644
1718 +--- a/drivers/media/platform/vivid/vivid-vid-cap.c
1719 ++++ b/drivers/media/platform/vivid/vivid-vid-cap.c
1720 +@@ -984,7 +984,7 @@ int vivid_vid_cap_s_selection(struct file *file, void *fh, struct v4l2_selection
1721 + v4l2_rect_map_inside(&s->r, &dev->fmt_cap_rect);
1722 + if (dev->bitmap_cap && (compose->width != s->r.width ||
1723 + compose->height != s->r.height)) {
1724 +- kfree(dev->bitmap_cap);
1725 ++ vfree(dev->bitmap_cap);
1726 + dev->bitmap_cap = NULL;
1727 + }
1728 + *compose = s->r;
1729 +diff --git a/drivers/media/radio/wl128x/fmdrv_common.c b/drivers/media/radio/wl128x/fmdrv_common.c
1730 +index 642b89c66bcb..c1457cf46698 100644
1731 +--- a/drivers/media/radio/wl128x/fmdrv_common.c
1732 ++++ b/drivers/media/radio/wl128x/fmdrv_common.c
1733 +@@ -494,7 +494,8 @@ int fmc_send_cmd(struct fmdev *fmdev, u8 fm_op, u16 type, void *payload,
1734 + return -EIO;
1735 + }
1736 + /* Send response data to caller */
1737 +- if (response != NULL && response_len != NULL && evt_hdr->dlen) {
1738 ++ if (response != NULL && response_len != NULL && evt_hdr->dlen &&
1739 ++ evt_hdr->dlen <= payload_len) {
1740 + /* Skip header info and copy only response data */
1741 + skb_pull(skb, sizeof(struct fm_event_msg_hdr));
1742 + memcpy(response, skb->data, evt_hdr->dlen);
1743 +@@ -590,6 +591,8 @@ static void fm_irq_handle_flag_getcmd_resp(struct fmdev *fmdev)
1744 + return;
1745 +
1746 + fm_evt_hdr = (void *)skb->data;
1747 ++ if (fm_evt_hdr->dlen > sizeof(fmdev->irq_info.flag))
1748 ++ return;
1749 +
1750 + /* Skip header info and copy only response data */
1751 + skb_pull(skb, sizeof(struct fm_event_msg_hdr));
1752 +@@ -1315,7 +1318,7 @@ static int load_default_rx_configuration(struct fmdev *fmdev)
1753 + static int fm_power_up(struct fmdev *fmdev, u8 mode)
1754 + {
1755 + u16 payload;
1756 +- __be16 asic_id, asic_ver;
1757 ++ __be16 asic_id = 0, asic_ver = 0;
1758 + int resp_len, ret;
1759 + u8 fw_name[50];
1760 +
1761 +diff --git a/drivers/media/usb/au0828/au0828-video.c b/drivers/media/usb/au0828/au0828-video.c
1762 +index 85dd9a8e83ff..48eeb5a6a209 100644
1763 +--- a/drivers/media/usb/au0828/au0828-video.c
1764 ++++ b/drivers/media/usb/au0828/au0828-video.c
1765 +@@ -764,6 +764,9 @@ static int au0828_analog_stream_enable(struct au0828_dev *d)
1766 +
1767 + dprintk(1, "au0828_analog_stream_enable called\n");
1768 +
1769 ++ if (test_bit(DEV_DISCONNECTED, &d->dev_state))
1770 ++ return -ENODEV;
1771 ++
1772 + iface = usb_ifnum_to_if(d->usbdev, 0);
1773 + if (iface && iface->cur_altsetting->desc.bAlternateSetting != 5) {
1774 + dprintk(1, "Changing intf#0 to alt 5\n");
1775 +@@ -852,9 +855,9 @@ int au0828_start_analog_streaming(struct vb2_queue *vq, unsigned int count)
1776 + return rc;
1777 + }
1778 +
1779 ++ v4l2_device_call_all(&dev->v4l2_dev, 0, video, s_stream, 1);
1780 ++
1781 + if (vq->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) {
1782 +- v4l2_device_call_all(&dev->v4l2_dev, 0, video,
1783 +- s_stream, 1);
1784 + dev->vid_timeout_running = 1;
1785 + mod_timer(&dev->vid_timeout, jiffies + (HZ / 10));
1786 + } else if (vq->type == V4L2_BUF_TYPE_VBI_CAPTURE) {
1787 +@@ -874,10 +877,11 @@ static void au0828_stop_streaming(struct vb2_queue *vq)
1788 +
1789 + dprintk(1, "au0828_stop_streaming called %d\n", dev->streaming_users);
1790 +
1791 +- if (dev->streaming_users-- == 1)
1792 ++ if (dev->streaming_users-- == 1) {
1793 + au0828_uninit_isoc(dev);
1794 ++ v4l2_device_call_all(&dev->v4l2_dev, 0, video, s_stream, 0);
1795 ++ }
1796 +
1797 +- v4l2_device_call_all(&dev->v4l2_dev, 0, video, s_stream, 0);
1798 + dev->vid_timeout_running = 0;
1799 + del_timer_sync(&dev->vid_timeout);
1800 +
1801 +@@ -906,8 +910,10 @@ void au0828_stop_vbi_streaming(struct vb2_queue *vq)
1802 + dprintk(1, "au0828_stop_vbi_streaming called %d\n",
1803 + dev->streaming_users);
1804 +
1805 +- if (dev->streaming_users-- == 1)
1806 ++ if (dev->streaming_users-- == 1) {
1807 + au0828_uninit_isoc(dev);
1808 ++ v4l2_device_call_all(&dev->v4l2_dev, 0, video, s_stream, 0);
1809 ++ }
1810 +
1811 + spin_lock_irqsave(&dev->slock, flags);
1812 + if (dev->isoc_ctl.vbi_buf != NULL) {
1813 +diff --git a/drivers/media/usb/cpia2/cpia2_v4l.c b/drivers/media/usb/cpia2/cpia2_v4l.c
1814 +index d793c630f1dd..05e7edb213de 100644
1815 +--- a/drivers/media/usb/cpia2/cpia2_v4l.c
1816 ++++ b/drivers/media/usb/cpia2/cpia2_v4l.c
1817 +@@ -1248,8 +1248,7 @@ static int __init cpia2_init(void)
1818 + LOG("%s v%s\n",
1819 + ABOUT, CPIA_VERSION);
1820 + check_parameters();
1821 +- cpia2_usb_init();
1822 +- return 0;
1823 ++ return cpia2_usb_init();
1824 + }
1825 +
1826 +
1827 +diff --git a/drivers/media/usb/go7007/go7007-fw.c b/drivers/media/usb/go7007/go7007-fw.c
1828 +index 60bf5f0644d1..a5efcd4f7b4f 100644
1829 +--- a/drivers/media/usb/go7007/go7007-fw.c
1830 ++++ b/drivers/media/usb/go7007/go7007-fw.c
1831 +@@ -1499,8 +1499,8 @@ static int modet_to_package(struct go7007 *go, __le16 *code, int space)
1832 + return cnt;
1833 + }
1834 +
1835 +-static int do_special(struct go7007 *go, u16 type, __le16 *code, int space,
1836 +- int *framelen)
1837 ++static noinline_for_stack int do_special(struct go7007 *go, u16 type,
1838 ++ __le16 *code, int space, int *framelen)
1839 + {
1840 + switch (type) {
1841 + case SPECIAL_FRM_HEAD:
1842 +diff --git a/drivers/media/usb/pvrusb2/pvrusb2-hdw.c b/drivers/media/usb/pvrusb2/pvrusb2-hdw.c
1843 +index 1eb4f7ba2967..ff489645e070 100644
1844 +--- a/drivers/media/usb/pvrusb2/pvrusb2-hdw.c
1845 ++++ b/drivers/media/usb/pvrusb2/pvrusb2-hdw.c
1846 +@@ -670,6 +670,8 @@ static int ctrl_get_input(struct pvr2_ctrl *cptr,int *vp)
1847 +
1848 + static int ctrl_check_input(struct pvr2_ctrl *cptr,int v)
1849 + {
1850 ++ if (v < 0 || v > PVR2_CVAL_INPUT_MAX)
1851 ++ return 0;
1852 + return ((1 << v) & cptr->hdw->input_allowed_mask) != 0;
1853 + }
1854 +
1855 +diff --git a/drivers/media/usb/pvrusb2/pvrusb2-hdw.h b/drivers/media/usb/pvrusb2/pvrusb2-hdw.h
1856 +index a82a00dd7329..80869990ffbb 100644
1857 +--- a/drivers/media/usb/pvrusb2/pvrusb2-hdw.h
1858 ++++ b/drivers/media/usb/pvrusb2/pvrusb2-hdw.h
1859 +@@ -54,6 +54,7 @@
1860 + #define PVR2_CVAL_INPUT_COMPOSITE 2
1861 + #define PVR2_CVAL_INPUT_SVIDEO 3
1862 + #define PVR2_CVAL_INPUT_RADIO 4
1863 ++#define PVR2_CVAL_INPUT_MAX PVR2_CVAL_INPUT_RADIO
1864 +
1865 + enum pvr2_config {
1866 + pvr2_config_empty, /* No configuration */
1867 +diff --git a/drivers/mmc/core/pwrseq_emmc.c b/drivers/mmc/core/pwrseq_emmc.c
1868 +index adc9c0c614fb..4493c299d85e 100644
1869 +--- a/drivers/mmc/core/pwrseq_emmc.c
1870 ++++ b/drivers/mmc/core/pwrseq_emmc.c
1871 +@@ -30,19 +30,14 @@ struct mmc_pwrseq_emmc {
1872 +
1873 + #define to_pwrseq_emmc(p) container_of(p, struct mmc_pwrseq_emmc, pwrseq)
1874 +
1875 +-static void __mmc_pwrseq_emmc_reset(struct mmc_pwrseq_emmc *pwrseq)
1876 +-{
1877 +- gpiod_set_value(pwrseq->reset_gpio, 1);
1878 +- udelay(1);
1879 +- gpiod_set_value(pwrseq->reset_gpio, 0);
1880 +- udelay(200);
1881 +-}
1882 +-
1883 + static void mmc_pwrseq_emmc_reset(struct mmc_host *host)
1884 + {
1885 + struct mmc_pwrseq_emmc *pwrseq = to_pwrseq_emmc(host->pwrseq);
1886 +
1887 +- __mmc_pwrseq_emmc_reset(pwrseq);
1888 ++ gpiod_set_value_cansleep(pwrseq->reset_gpio, 1);
1889 ++ udelay(1);
1890 ++ gpiod_set_value_cansleep(pwrseq->reset_gpio, 0);
1891 ++ udelay(200);
1892 + }
1893 +
1894 + static int mmc_pwrseq_emmc_reset_nb(struct notifier_block *this,
1895 +@@ -50,8 +45,11 @@ static int mmc_pwrseq_emmc_reset_nb(struct notifier_block *this,
1896 + {
1897 + struct mmc_pwrseq_emmc *pwrseq = container_of(this,
1898 + struct mmc_pwrseq_emmc, reset_nb);
1899 ++ gpiod_set_value(pwrseq->reset_gpio, 1);
1900 ++ udelay(1);
1901 ++ gpiod_set_value(pwrseq->reset_gpio, 0);
1902 ++ udelay(200);
1903 +
1904 +- __mmc_pwrseq_emmc_reset(pwrseq);
1905 + return NOTIFY_DONE;
1906 + }
1907 +
1908 +@@ -72,14 +70,18 @@ static int mmc_pwrseq_emmc_probe(struct platform_device *pdev)
1909 + if (IS_ERR(pwrseq->reset_gpio))
1910 + return PTR_ERR(pwrseq->reset_gpio);
1911 +
1912 +- /*
1913 +- * register reset handler to ensure emmc reset also from
1914 +- * emergency_reboot(), priority 255 is the highest priority
1915 +- * so it will be executed before any system reboot handler.
1916 +- */
1917 +- pwrseq->reset_nb.notifier_call = mmc_pwrseq_emmc_reset_nb;
1918 +- pwrseq->reset_nb.priority = 255;
1919 +- register_restart_handler(&pwrseq->reset_nb);
1920 ++ if (!gpiod_cansleep(pwrseq->reset_gpio)) {
1921 ++ /*
1922 ++ * register reset handler to ensure emmc reset also from
1923 ++ * emergency_reboot(), priority 255 is the highest priority
1924 ++ * so it will be executed before any system reboot handler.
1925 ++ */
1926 ++ pwrseq->reset_nb.notifier_call = mmc_pwrseq_emmc_reset_nb;
1927 ++ pwrseq->reset_nb.priority = 255;
1928 ++ register_restart_handler(&pwrseq->reset_nb);
1929 ++ } else {
1930 ++ dev_notice(dev, "EMMC reset pin tied to a sleepy GPIO driver; reset on emergency-reboot disabled\n");
1931 ++ }
1932 +
1933 + pwrseq->pwrseq.ops = &mmc_pwrseq_emmc_ops;
1934 + pwrseq->pwrseq.dev = dev;
1935 +diff --git a/drivers/mmc/core/sd.c b/drivers/mmc/core/sd.c
1936 +index f09148a4ab55..00ba8807dafe 100644
1937 +--- a/drivers/mmc/core/sd.c
1938 ++++ b/drivers/mmc/core/sd.c
1939 +@@ -214,6 +214,14 @@ static int mmc_decode_scr(struct mmc_card *card)
1940 +
1941 + if (scr->sda_spec3)
1942 + scr->cmds = UNSTUFF_BITS(resp, 32, 2);
1943 ++
1944 ++ /* SD Spec says: any SD Card shall set at least bits 0 and 2 */
1945 ++ if (!(scr->bus_widths & SD_SCR_BUS_WIDTH_1) ||
1946 ++ !(scr->bus_widths & SD_SCR_BUS_WIDTH_4)) {
1947 ++ pr_err("%s: invalid bus width\n", mmc_hostname(card->host));
1948 ++ return -EINVAL;
1949 ++ }
1950 ++
1951 + return 0;
1952 + }
1953 +
1954 +diff --git a/drivers/mmc/host/mmc_spi.c b/drivers/mmc/host/mmc_spi.c
1955 +index 6224ad37fd80..c2df68e958b3 100644
1956 +--- a/drivers/mmc/host/mmc_spi.c
1957 ++++ b/drivers/mmc/host/mmc_spi.c
1958 +@@ -819,6 +819,10 @@ mmc_spi_readblock(struct mmc_spi_host *host, struct spi_transfer *t,
1959 + }
1960 +
1961 + status = spi_sync_locked(spi, &host->m);
1962 ++ if (status < 0) {
1963 ++ dev_dbg(&spi->dev, "read error %d\n", status);
1964 ++ return status;
1965 ++ }
1966 +
1967 + if (host->dma_dev) {
1968 + dma_sync_single_for_cpu(host->dma_dev,
1969 +diff --git a/drivers/mmc/host/sdhci-of-esdhc.c b/drivers/mmc/host/sdhci-of-esdhc.c
1970 +index a51d636c2312..6f11cd95bb5f 100644
1971 +--- a/drivers/mmc/host/sdhci-of-esdhc.c
1972 ++++ b/drivers/mmc/host/sdhci-of-esdhc.c
1973 +@@ -636,6 +636,11 @@ static int sdhci_esdhc_probe(struct platform_device *pdev)
1974 + if (esdhc->vendor_ver > VENDOR_V_22)
1975 + host->quirks &= ~SDHCI_QUIRK_NO_BUSY_IRQ;
1976 +
1977 ++ if (of_find_compatible_node(NULL, NULL, "fsl,p2020-esdhc")) {
1978 ++ host->quirks2 |= SDHCI_QUIRK_RESET_AFTER_REQUEST;
1979 ++ host->quirks2 |= SDHCI_QUIRK_BROKEN_TIMEOUT_VAL;
1980 ++ }
1981 ++
1982 + if (of_device_is_compatible(np, "fsl,p5040-esdhc") ||
1983 + of_device_is_compatible(np, "fsl,p5020-esdhc") ||
1984 + of_device_is_compatible(np, "fsl,p4080-esdhc") ||
1985 +diff --git a/drivers/net/ethernet/amazon/ena/ena_netdev.c b/drivers/net/ethernet/amazon/ena/ena_netdev.c
1986 +index 0c298878bf46..0780900b37c7 100644
1987 +--- a/drivers/net/ethernet/amazon/ena/ena_netdev.c
1988 ++++ b/drivers/net/ethernet/amazon/ena/ena_netdev.c
1989 +@@ -2116,7 +2116,7 @@ static void ena_config_host_info(struct ena_com_dev *ena_dev)
1990 +
1991 + host_info->os_type = ENA_ADMIN_OS_LINUX;
1992 + host_info->kernel_ver = LINUX_VERSION_CODE;
1993 +- strncpy(host_info->kernel_ver_str, utsname()->version,
1994 ++ strlcpy(host_info->kernel_ver_str, utsname()->version,
1995 + sizeof(host_info->kernel_ver_str) - 1);
1996 + host_info->os_dist = 0;
1997 + strncpy(host_info->os_dist_str, utsname()->release,
1998 +diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
1999 +index 8cffcdfd5678..38b5858c335a 100644
2000 +--- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
2001 ++++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
2002 +@@ -75,8 +75,8 @@ struct l2t_data {
2003 + struct l2t_entry *rover; /* starting point for next allocation */
2004 + atomic_t nfree; /* number of free entries */
2005 + rwlock_t lock;
2006 +- struct l2t_entry l2tab[0];
2007 + struct rcu_head rcu_head; /* to handle rcu cleanup */
2008 ++ struct l2t_entry l2tab[];
2009 + };
2010 +
2011 + typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
2012 +diff --git a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
2013 +index c71a52a2f801..5478a2ab45c4 100644
2014 +--- a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
2015 ++++ b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
2016 +@@ -5203,15 +5203,24 @@ static int __init cxgb4_init_module(void)
2017 +
2018 + ret = pci_register_driver(&cxgb4_driver);
2019 + if (ret < 0)
2020 +- debugfs_remove(cxgb4_debugfs_root);
2021 ++ goto err_pci;
2022 +
2023 + #if IS_ENABLED(CONFIG_IPV6)
2024 + if (!inet6addr_registered) {
2025 +- register_inet6addr_notifier(&cxgb4_inet6addr_notifier);
2026 +- inet6addr_registered = true;
2027 ++ ret = register_inet6addr_notifier(&cxgb4_inet6addr_notifier);
2028 ++ if (ret)
2029 ++ pci_unregister_driver(&cxgb4_driver);
2030 ++ else
2031 ++ inet6addr_registered = true;
2032 + }
2033 + #endif
2034 +
2035 ++ if (ret == 0)
2036 ++ return ret;
2037 ++
2038 ++err_pci:
2039 ++ debugfs_remove(cxgb4_debugfs_root);
2040 ++
2041 + return ret;
2042 + }
2043 +
2044 +diff --git a/drivers/net/ethernet/intel/i40e/i40e_main.c b/drivers/net/ethernet/intel/i40e/i40e_main.c
2045 +index 7836072d3f63..886378c5334f 100644
2046 +--- a/drivers/net/ethernet/intel/i40e/i40e_main.c
2047 ++++ b/drivers/net/ethernet/intel/i40e/i40e_main.c
2048 +@@ -2285,6 +2285,10 @@ void i40e_vlan_stripping_enable(struct i40e_vsi *vsi)
2049 + struct i40e_vsi_context ctxt;
2050 + i40e_status ret;
2051 +
2052 ++ /* Don't modify stripping options if a port VLAN is active */
2053 ++ if (vsi->info.pvid)
2054 ++ return;
2055 ++
2056 + if ((vsi->info.valid_sections &
2057 + cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID)) &&
2058 + ((vsi->info.port_vlan_flags & I40E_AQ_VSI_PVLAN_MODE_MASK) == 0))
2059 +@@ -2315,6 +2319,10 @@ void i40e_vlan_stripping_disable(struct i40e_vsi *vsi)
2060 + struct i40e_vsi_context ctxt;
2061 + i40e_status ret;
2062 +
2063 ++ /* Don't modify stripping options if a port VLAN is active */
2064 ++ if (vsi->info.pvid)
2065 ++ return;
2066 ++
2067 + if ((vsi->info.valid_sections &
2068 + cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID)) &&
2069 + ((vsi->info.port_vlan_flags & I40E_AQ_VSI_PVLAN_EMOD_MASK) ==
2070 +diff --git a/drivers/net/wireless/atmel/at76c50x-usb.c b/drivers/net/wireless/atmel/at76c50x-usb.c
2071 +index 0e180677c7fc..09dbab464fe1 100644
2072 +--- a/drivers/net/wireless/atmel/at76c50x-usb.c
2073 ++++ b/drivers/net/wireless/atmel/at76c50x-usb.c
2074 +@@ -2583,8 +2583,8 @@ static int __init at76_mod_init(void)
2075 + if (result < 0)
2076 + printk(KERN_ERR DRIVER_NAME
2077 + ": usb_register failed (status %d)\n", result);
2078 +-
2079 +- led_trigger_register_simple("at76_usb-tx", &ledtrig_tx);
2080 ++ else
2081 ++ led_trigger_register_simple("at76_usb-tx", &ledtrig_tx);
2082 + return result;
2083 + }
2084 +
2085 +diff --git a/drivers/net/wireless/broadcom/b43/phy_lp.c b/drivers/net/wireless/broadcom/b43/phy_lp.c
2086 +index 6922cbb99a04..5a0699fb4b9a 100644
2087 +--- a/drivers/net/wireless/broadcom/b43/phy_lp.c
2088 ++++ b/drivers/net/wireless/broadcom/b43/phy_lp.c
2089 +@@ -1834,7 +1834,7 @@ static void lpphy_papd_cal(struct b43_wldev *dev, struct lpphy_tx_gains gains,
2090 + static void lpphy_papd_cal_txpwr(struct b43_wldev *dev)
2091 + {
2092 + struct b43_phy_lp *lpphy = dev->phy.lp;
2093 +- struct lpphy_tx_gains gains, oldgains;
2094 ++ struct lpphy_tx_gains oldgains;
2095 + int old_txpctl, old_afe_ovr, old_rf, old_bbmult;
2096 +
2097 + lpphy_read_tx_pctl_mode_from_hardware(dev);
2098 +@@ -1848,9 +1848,9 @@ static void lpphy_papd_cal_txpwr(struct b43_wldev *dev)
2099 + lpphy_set_tx_power_control(dev, B43_LPPHY_TXPCTL_OFF);
2100 +
2101 + if (dev->dev->chip_id == 0x4325 && dev->dev->chip_rev == 0)
2102 +- lpphy_papd_cal(dev, gains, 0, 1, 30);
2103 ++ lpphy_papd_cal(dev, oldgains, 0, 1, 30);
2104 + else
2105 +- lpphy_papd_cal(dev, gains, 0, 1, 65);
2106 ++ lpphy_papd_cal(dev, oldgains, 0, 1, 65);
2107 +
2108 + if (old_afe_ovr)
2109 + lpphy_set_tx_gains(dev, oldgains);
2110 +diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c
2111 +index 530f52120972..8f8fe6f2af5b 100644
2112 +--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c
2113 ++++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c
2114 +@@ -5374,6 +5374,8 @@ static s32 brcmf_get_assoc_ies(struct brcmf_cfg80211_info *cfg,
2115 + conn_info->req_ie =
2116 + kmemdup(cfg->extra_buf, conn_info->req_ie_len,
2117 + GFP_KERNEL);
2118 ++ if (!conn_info->req_ie)
2119 ++ conn_info->req_ie_len = 0;
2120 + } else {
2121 + conn_info->req_ie_len = 0;
2122 + conn_info->req_ie = NULL;
2123 +@@ -5390,6 +5392,8 @@ static s32 brcmf_get_assoc_ies(struct brcmf_cfg80211_info *cfg,
2124 + conn_info->resp_ie =
2125 + kmemdup(cfg->extra_buf, conn_info->resp_ie_len,
2126 + GFP_KERNEL);
2127 ++ if (!conn_info->resp_ie)
2128 ++ conn_info->resp_ie_len = 0;
2129 + } else {
2130 + conn_info->resp_ie_len = 0;
2131 + conn_info->resp_ie = NULL;
2132 +diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/core.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/core.c
2133 +index f877301c9454..ecfe056d7643 100644
2134 +--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/core.c
2135 ++++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/core.c
2136 +@@ -685,17 +685,17 @@ static void brcmf_del_if(struct brcmf_pub *drvr, s32 bsscfgidx,
2137 + bool rtnl_locked)
2138 + {
2139 + struct brcmf_if *ifp;
2140 ++ int ifidx;
2141 +
2142 + ifp = drvr->iflist[bsscfgidx];
2143 +- drvr->iflist[bsscfgidx] = NULL;
2144 + if (!ifp) {
2145 + brcmf_err("Null interface, bsscfgidx=%d\n", bsscfgidx);
2146 + return;
2147 + }
2148 + brcmf_dbg(TRACE, "Enter, bsscfgidx=%d, ifidx=%d\n", bsscfgidx,
2149 + ifp->ifidx);
2150 +- if (drvr->if2bss[ifp->ifidx] == bsscfgidx)
2151 +- drvr->if2bss[ifp->ifidx] = BRCMF_BSSIDX_INVALID;
2152 ++ ifidx = ifp->ifidx;
2153 ++
2154 + if (ifp->ndev) {
2155 + if (bsscfgidx == 0) {
2156 + if (ifp->ndev->netdev_ops == &brcmf_netdev_ops_pri) {
2157 +@@ -723,6 +723,10 @@ static void brcmf_del_if(struct brcmf_pub *drvr, s32 bsscfgidx,
2158 + brcmf_p2p_ifp_removed(ifp, rtnl_locked);
2159 + kfree(ifp);
2160 + }
2161 ++
2162 ++ drvr->iflist[bsscfgidx] = NULL;
2163 ++ if (drvr->if2bss[ifidx] == bsscfgidx)
2164 ++ drvr->if2bss[ifidx] = BRCMF_BSSIDX_INVALID;
2165 + }
2166 +
2167 + void brcmf_remove_interface(struct brcmf_if *ifp, bool rtnl_locked)
2168 +diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/usb.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/usb.c
2169 +index 053f3b59f21e..acf513fd9e6d 100644
2170 +--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/usb.c
2171 ++++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/usb.c
2172 +@@ -157,7 +157,7 @@ struct brcmf_usbdev_info {
2173 +
2174 + struct usb_device *usbdev;
2175 + struct device *dev;
2176 +- struct mutex dev_init_lock;
2177 ++ struct completion dev_init_done;
2178 +
2179 + int ctl_in_pipe, ctl_out_pipe;
2180 + struct urb *ctl_urb; /* URB for control endpoint */
2181 +@@ -681,12 +681,18 @@ static int brcmf_usb_up(struct device *dev)
2182 +
2183 + static void brcmf_cancel_all_urbs(struct brcmf_usbdev_info *devinfo)
2184 + {
2185 ++ int i;
2186 ++
2187 + if (devinfo->ctl_urb)
2188 + usb_kill_urb(devinfo->ctl_urb);
2189 + if (devinfo->bulk_urb)
2190 + usb_kill_urb(devinfo->bulk_urb);
2191 +- brcmf_usb_free_q(&devinfo->tx_postq, true);
2192 +- brcmf_usb_free_q(&devinfo->rx_postq, true);
2193 ++ if (devinfo->tx_reqs)
2194 ++ for (i = 0; i < devinfo->bus_pub.ntxq; i++)
2195 ++ usb_kill_urb(devinfo->tx_reqs[i].urb);
2196 ++ if (devinfo->rx_reqs)
2197 ++ for (i = 0; i < devinfo->bus_pub.nrxq; i++)
2198 ++ usb_kill_urb(devinfo->rx_reqs[i].urb);
2199 + }
2200 +
2201 + static void brcmf_usb_down(struct device *dev)
2202 +@@ -1189,11 +1195,11 @@ static void brcmf_usb_probe_phase2(struct device *dev, int ret,
2203 + if (ret)
2204 + goto error;
2205 +
2206 +- mutex_unlock(&devinfo->dev_init_lock);
2207 ++ complete(&devinfo->dev_init_done);
2208 + return;
2209 + error:
2210 + brcmf_dbg(TRACE, "failed: dev=%s, err=%d\n", dev_name(dev), ret);
2211 +- mutex_unlock(&devinfo->dev_init_lock);
2212 ++ complete(&devinfo->dev_init_done);
2213 + device_release_driver(dev);
2214 + }
2215 +
2216 +@@ -1239,7 +1245,7 @@ static int brcmf_usb_probe_cb(struct brcmf_usbdev_info *devinfo)
2217 + if (ret)
2218 + goto fail;
2219 + /* we are done */
2220 +- mutex_unlock(&devinfo->dev_init_lock);
2221 ++ complete(&devinfo->dev_init_done);
2222 + return 0;
2223 + }
2224 + bus->chip = bus_pub->devid;
2225 +@@ -1300,11 +1306,10 @@ brcmf_usb_probe(struct usb_interface *intf, const struct usb_device_id *id)
2226 +
2227 + devinfo->usbdev = usb;
2228 + devinfo->dev = &usb->dev;
2229 +- /* Take an init lock, to protect for disconnect while still loading.
2230 ++ /* Init completion, to protect for disconnect while still loading.
2231 + * Necessary because of the asynchronous firmware load construction
2232 + */
2233 +- mutex_init(&devinfo->dev_init_lock);
2234 +- mutex_lock(&devinfo->dev_init_lock);
2235 ++ init_completion(&devinfo->dev_init_done);
2236 +
2237 + usb_set_intfdata(intf, devinfo);
2238 +
2239 +@@ -1382,7 +1387,7 @@ brcmf_usb_probe(struct usb_interface *intf, const struct usb_device_id *id)
2240 + return 0;
2241 +
2242 + fail:
2243 +- mutex_unlock(&devinfo->dev_init_lock);
2244 ++ complete(&devinfo->dev_init_done);
2245 + kfree(devinfo);
2246 + usb_set_intfdata(intf, NULL);
2247 + return ret;
2248 +@@ -1397,7 +1402,7 @@ brcmf_usb_disconnect(struct usb_interface *intf)
2249 + devinfo = (struct brcmf_usbdev_info *)usb_get_intfdata(intf);
2250 +
2251 + if (devinfo) {
2252 +- mutex_lock(&devinfo->dev_init_lock);
2253 ++ wait_for_completion(&devinfo->dev_init_done);
2254 + /* Make sure that devinfo still exists. Firmware probe routines
2255 + * may have released the device and cleared the intfdata.
2256 + */
2257 +diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/vendor.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/vendor.c
2258 +index 8eff2753abad..d493021f6031 100644
2259 +--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/vendor.c
2260 ++++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/vendor.c
2261 +@@ -35,9 +35,10 @@ static int brcmf_cfg80211_vndr_cmds_dcmd_handler(struct wiphy *wiphy,
2262 + struct brcmf_if *ifp;
2263 + const struct brcmf_vndr_dcmd_hdr *cmdhdr = data;
2264 + struct sk_buff *reply;
2265 +- int ret, payload, ret_len;
2266 ++ unsigned int payload, ret_len;
2267 + void *dcmd_buf = NULL, *wr_pointer;
2268 + u16 msglen, maxmsglen = PAGE_SIZE - 0x100;
2269 ++ int ret;
2270 +
2271 + if (len < sizeof(*cmdhdr)) {
2272 + brcmf_err("vendor command too short: %d\n", len);
2273 +@@ -65,7 +66,7 @@ static int brcmf_cfg80211_vndr_cmds_dcmd_handler(struct wiphy *wiphy,
2274 + brcmf_err("oversize return buffer %d\n", ret_len);
2275 + ret_len = BRCMF_DCMD_MAXLEN;
2276 + }
2277 +- payload = max(ret_len, len) + 1;
2278 ++ payload = max_t(unsigned int, ret_len, len) + 1;
2279 + dcmd_buf = vzalloc(payload);
2280 + if (NULL == dcmd_buf)
2281 + return -ENOMEM;
2282 +diff --git a/drivers/net/wireless/intel/iwlwifi/pcie/rx.c b/drivers/net/wireless/intel/iwlwifi/pcie/rx.c
2283 +index c21f8bd32d08..25f2a0aceaa2 100644
2284 +--- a/drivers/net/wireless/intel/iwlwifi/pcie/rx.c
2285 ++++ b/drivers/net/wireless/intel/iwlwifi/pcie/rx.c
2286 +@@ -1225,10 +1225,15 @@ static void iwl_pcie_rx_handle_rb(struct iwl_trans *trans,
2287 + static void iwl_pcie_rx_handle(struct iwl_trans *trans, int queue)
2288 + {
2289 + struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
2290 +- struct iwl_rxq *rxq = &trans_pcie->rxq[queue];
2291 ++ struct iwl_rxq *rxq;
2292 + u32 r, i, count = 0;
2293 + bool emergency = false;
2294 +
2295 ++ if (WARN_ON_ONCE(!trans_pcie->rxq || !trans_pcie->rxq[queue].bd))
2296 ++ return;
2297 ++
2298 ++ rxq = &trans_pcie->rxq[queue];
2299 ++
2300 + restart:
2301 + spin_lock(&rxq->lock);
2302 + /* uCode's read index (stored in shared DRAM) indicates the last Rx
2303 +diff --git a/drivers/net/wireless/marvell/mwifiex/cfg80211.c b/drivers/net/wireless/marvell/mwifiex/cfg80211.c
2304 +index 4da3541471e6..46d0099fd6e8 100644
2305 +--- a/drivers/net/wireless/marvell/mwifiex/cfg80211.c
2306 ++++ b/drivers/net/wireless/marvell/mwifiex/cfg80211.c
2307 +@@ -4018,16 +4018,20 @@ static int mwifiex_tm_cmd(struct wiphy *wiphy, struct wireless_dev *wdev,
2308 +
2309 + if (mwifiex_send_cmd(priv, 0, 0, 0, hostcmd, true)) {
2310 + dev_err(priv->adapter->dev, "Failed to process hostcmd\n");
2311 ++ kfree(hostcmd);
2312 + return -EFAULT;
2313 + }
2314 +
2315 + /* process hostcmd response*/
2316 + skb = cfg80211_testmode_alloc_reply_skb(wiphy, hostcmd->len);
2317 +- if (!skb)
2318 ++ if (!skb) {
2319 ++ kfree(hostcmd);
2320 + return -ENOMEM;
2321 ++ }
2322 + err = nla_put(skb, MWIFIEX_TM_ATTR_DATA,
2323 + hostcmd->len, hostcmd->cmd);
2324 + if (err) {
2325 ++ kfree(hostcmd);
2326 + kfree_skb(skb);
2327 + return -EMSGSIZE;
2328 + }
2329 +diff --git a/drivers/net/wireless/marvell/mwifiex/cfp.c b/drivers/net/wireless/marvell/mwifiex/cfp.c
2330 +index 1ff22055e54f..9ddaa767ea74 100644
2331 +--- a/drivers/net/wireless/marvell/mwifiex/cfp.c
2332 ++++ b/drivers/net/wireless/marvell/mwifiex/cfp.c
2333 +@@ -533,5 +533,8 @@ u8 mwifiex_adjust_data_rate(struct mwifiex_private *priv,
2334 + rate_index = (rx_rate > MWIFIEX_RATE_INDEX_OFDM0) ?
2335 + rx_rate - 1 : rx_rate;
2336 +
2337 ++ if (rate_index >= MWIFIEX_MAX_AC_RX_RATES)
2338 ++ rate_index = MWIFIEX_MAX_AC_RX_RATES - 1;
2339 ++
2340 + return rate_index;
2341 + }
2342 +diff --git a/drivers/net/wireless/realtek/rtlwifi/base.c b/drivers/net/wireless/realtek/rtlwifi/base.c
2343 +index 4ac928bf1f8e..7de18ed10db8 100644
2344 +--- a/drivers/net/wireless/realtek/rtlwifi/base.c
2345 ++++ b/drivers/net/wireless/realtek/rtlwifi/base.c
2346 +@@ -466,6 +466,11 @@ static void _rtl_init_deferred_work(struct ieee80211_hw *hw)
2347 + /* <2> work queue */
2348 + rtlpriv->works.hw = hw;
2349 + rtlpriv->works.rtl_wq = alloc_workqueue("%s", 0, 0, rtlpriv->cfg->name);
2350 ++ if (unlikely(!rtlpriv->works.rtl_wq)) {
2351 ++ pr_err("Failed to allocate work queue\n");
2352 ++ return;
2353 ++ }
2354 ++
2355 + INIT_DELAYED_WORK(&rtlpriv->works.watchdog_wq,
2356 + (void *)rtl_watchdog_wq_callback);
2357 + INIT_DELAYED_WORK(&rtlpriv->works.ips_nic_off_wq,
2358 +diff --git a/drivers/net/wireless/st/cw1200/main.c b/drivers/net/wireless/st/cw1200/main.c
2359 +index dc478cedbde0..84624c812a15 100644
2360 +--- a/drivers/net/wireless/st/cw1200/main.c
2361 ++++ b/drivers/net/wireless/st/cw1200/main.c
2362 +@@ -345,6 +345,11 @@ static struct ieee80211_hw *cw1200_init_common(const u8 *macaddr,
2363 + mutex_init(&priv->wsm_cmd_mux);
2364 + mutex_init(&priv->conf_mutex);
2365 + priv->workqueue = create_singlethread_workqueue("cw1200_wq");
2366 ++ if (!priv->workqueue) {
2367 ++ ieee80211_free_hw(hw);
2368 ++ return NULL;
2369 ++ }
2370 ++
2371 + sema_init(&priv->scan.lock, 1);
2372 + INIT_WORK(&priv->scan.work, cw1200_scan_work);
2373 + INIT_DELAYED_WORK(&priv->scan.probe_work, cw1200_probe_work);
2374 +diff --git a/drivers/nvdimm/label.c b/drivers/nvdimm/label.c
2375 +index 66a089d561cf..9108004a0d9b 100644
2376 +--- a/drivers/nvdimm/label.c
2377 ++++ b/drivers/nvdimm/label.c
2378 +@@ -490,15 +490,26 @@ static unsigned long nd_label_offset(struct nvdimm_drvdata *ndd,
2379 + - (unsigned long) to_namespace_index(ndd, 0);
2380 + }
2381 +
2382 ++static void reap_victim(struct nd_mapping *nd_mapping,
2383 ++ struct nd_label_ent *victim)
2384 ++{
2385 ++ struct nvdimm_drvdata *ndd = to_ndd(nd_mapping);
2386 ++ u32 slot = to_slot(ndd, victim->label);
2387 ++
2388 ++ dev_dbg(ndd->dev, "free: %d\n", slot);
2389 ++ nd_label_free_slot(ndd, slot);
2390 ++ victim->label = NULL;
2391 ++}
2392 ++
2393 + static int __pmem_label_update(struct nd_region *nd_region,
2394 + struct nd_mapping *nd_mapping, struct nd_namespace_pmem *nspm,
2395 + int pos, unsigned long flags)
2396 + {
2397 + u64 cookie = nd_region_interleave_set_cookie(nd_region);
2398 + struct nvdimm_drvdata *ndd = to_ndd(nd_mapping);
2399 +- struct nd_label_ent *label_ent, *victim = NULL;
2400 + struct nd_namespace_label *nd_label;
2401 + struct nd_namespace_index *nsindex;
2402 ++ struct nd_label_ent *label_ent;
2403 + struct nd_label_id label_id;
2404 + struct resource *res;
2405 + unsigned long *free;
2406 +@@ -551,18 +562,10 @@ static int __pmem_label_update(struct nd_region *nd_region,
2407 + list_for_each_entry(label_ent, &nd_mapping->labels, list) {
2408 + if (!label_ent->label)
2409 + continue;
2410 +- if (memcmp(nspm->uuid, label_ent->label->uuid,
2411 +- NSLABEL_UUID_LEN) != 0)
2412 +- continue;
2413 +- victim = label_ent;
2414 +- list_move_tail(&victim->list, &nd_mapping->labels);
2415 +- break;
2416 +- }
2417 +- if (victim) {
2418 +- dev_dbg(ndd->dev, "%s: free: %d\n", __func__, slot);
2419 +- slot = to_slot(ndd, victim->label);
2420 +- nd_label_free_slot(ndd, slot);
2421 +- victim->label = NULL;
2422 ++ if (test_and_clear_bit(ND_LABEL_REAP, &label_ent->flags)
2423 ++ || memcmp(nspm->uuid, label_ent->label->uuid,
2424 ++ NSLABEL_UUID_LEN) == 0)
2425 ++ reap_victim(nd_mapping, label_ent);
2426 + }
2427 +
2428 + /* update index */
2429 +diff --git a/drivers/nvdimm/namespace_devs.c b/drivers/nvdimm/namespace_devs.c
2430 +index cf4a90b50f8b..e83453e1b308 100644
2431 +--- a/drivers/nvdimm/namespace_devs.c
2432 ++++ b/drivers/nvdimm/namespace_devs.c
2433 +@@ -1210,12 +1210,27 @@ static int namespace_update_uuid(struct nd_region *nd_region,
2434 + for (i = 0; i < nd_region->ndr_mappings; i++) {
2435 + struct nd_mapping *nd_mapping = &nd_region->mapping[i];
2436 + struct nvdimm_drvdata *ndd = to_ndd(nd_mapping);
2437 ++ struct nd_label_ent *label_ent;
2438 + struct resource *res;
2439 +
2440 + for_each_dpa_resource(ndd, res)
2441 + if (strcmp(res->name, old_label_id.id) == 0)
2442 + sprintf((void *) res->name, "%s",
2443 + new_label_id.id);
2444 ++
2445 ++ mutex_lock(&nd_mapping->lock);
2446 ++ list_for_each_entry(label_ent, &nd_mapping->labels, list) {
2447 ++ struct nd_namespace_label *nd_label = label_ent->label;
2448 ++ struct nd_label_id label_id;
2449 ++
2450 ++ if (!nd_label)
2451 ++ continue;
2452 ++ nd_label_gen_id(&label_id, nd_label->uuid,
2453 ++ __le32_to_cpu(nd_label->flags));
2454 ++ if (strcmp(old_label_id.id, label_id.id) == 0)
2455 ++ set_bit(ND_LABEL_REAP, &label_ent->flags);
2456 ++ }
2457 ++ mutex_unlock(&nd_mapping->lock);
2458 + }
2459 + kfree(*old_uuid);
2460 + out:
2461 +diff --git a/drivers/nvdimm/nd.h b/drivers/nvdimm/nd.h
2462 +index d869236b474f..bd29e598bac1 100644
2463 +--- a/drivers/nvdimm/nd.h
2464 ++++ b/drivers/nvdimm/nd.h
2465 +@@ -113,8 +113,12 @@ struct nd_percpu_lane {
2466 + spinlock_t lock;
2467 + };
2468 +
2469 ++enum nd_label_flags {
2470 ++ ND_LABEL_REAP,
2471 ++};
2472 + struct nd_label_ent {
2473 + struct list_head list;
2474 ++ unsigned long flags;
2475 + struct nd_namespace_label *label;
2476 + };
2477 +
2478 +diff --git a/drivers/pinctrl/pinctrl-pistachio.c b/drivers/pinctrl/pinctrl-pistachio.c
2479 +index 55375b1b3cc8..b2b7e238bda9 100644
2480 +--- a/drivers/pinctrl/pinctrl-pistachio.c
2481 ++++ b/drivers/pinctrl/pinctrl-pistachio.c
2482 +@@ -1368,6 +1368,7 @@ static int pistachio_gpio_register(struct pistachio_pinctrl *pctl)
2483 + if (!of_find_property(child, "gpio-controller", NULL)) {
2484 + dev_err(pctl->dev,
2485 + "No gpio-controller property for bank %u\n", i);
2486 ++ of_node_put(child);
2487 + ret = -ENODEV;
2488 + goto err;
2489 + }
2490 +@@ -1375,6 +1376,7 @@ static int pistachio_gpio_register(struct pistachio_pinctrl *pctl)
2491 + irq = irq_of_parse_and_map(child, 0);
2492 + if (irq < 0) {
2493 + dev_err(pctl->dev, "No IRQ for bank %u: %d\n", i, irq);
2494 ++ of_node_put(child);
2495 + ret = irq;
2496 + goto err;
2497 + }
2498 +diff --git a/drivers/rtc/rtc-88pm860x.c b/drivers/rtc/rtc-88pm860x.c
2499 +index 19e53b3b8e00..166faae3a59c 100644
2500 +--- a/drivers/rtc/rtc-88pm860x.c
2501 ++++ b/drivers/rtc/rtc-88pm860x.c
2502 +@@ -414,7 +414,7 @@ static int pm860x_rtc_remove(struct platform_device *pdev)
2503 + struct pm860x_rtc_info *info = platform_get_drvdata(pdev);
2504 +
2505 + #ifdef VRTC_CALIBRATION
2506 +- flush_scheduled_work();
2507 ++ cancel_delayed_work_sync(&info->calib_work);
2508 + /* disable measurement */
2509 + pm860x_set_bits(info->i2c, PM8607_MEAS_EN2, MEAS2_VRTC, 0);
2510 + #endif /* VRTC_CALIBRATION */
2511 +diff --git a/drivers/s390/cio/cio.h b/drivers/s390/cio/cio.h
2512 +index f0e57aefb5f2..d167652a6a23 100644
2513 +--- a/drivers/s390/cio/cio.h
2514 ++++ b/drivers/s390/cio/cio.h
2515 +@@ -114,7 +114,7 @@ struct subchannel {
2516 + struct schib_config config;
2517 + } __attribute__ ((aligned(8)));
2518 +
2519 +-DECLARE_PER_CPU(struct irb, cio_irb);
2520 ++DECLARE_PER_CPU_ALIGNED(struct irb, cio_irb);
2521 +
2522 + #define to_subchannel(n) container_of(n, struct subchannel, dev)
2523 +
2524 +diff --git a/drivers/scsi/libsas/sas_expander.c b/drivers/scsi/libsas/sas_expander.c
2525 +index 1a6f65db615e..ee1f9ee995e5 100644
2526 +--- a/drivers/scsi/libsas/sas_expander.c
2527 ++++ b/drivers/scsi/libsas/sas_expander.c
2528 +@@ -2027,6 +2027,11 @@ static int sas_rediscover_dev(struct domain_device *dev, int phy_id, bool last)
2529 + if ((SAS_ADDR(sas_addr) == 0) || (res == -ECOMM)) {
2530 + phy->phy_state = PHY_EMPTY;
2531 + sas_unregister_devs_sas_addr(dev, phy_id, last);
2532 ++ /*
2533 ++ * Even though the PHY is empty, for convenience we discover
2534 ++ * the PHY to update the PHY info, like negotiated linkrate.
2535 ++ */
2536 ++ sas_ex_phy_discover(dev, phy_id);
2537 + return res;
2538 + } else if (SAS_ADDR(sas_addr) == SAS_ADDR(phy->attached_sas_addr) &&
2539 + dev_type_flutter(type, phy->attached_dev_type)) {
2540 +diff --git a/drivers/scsi/lpfc/lpfc_ct.c b/drivers/scsi/lpfc/lpfc_ct.c
2541 +index 4ac03b16d17f..52afbcff362f 100644
2542 +--- a/drivers/scsi/lpfc/lpfc_ct.c
2543 ++++ b/drivers/scsi/lpfc/lpfc_ct.c
2544 +@@ -1561,6 +1561,9 @@ lpfc_fdmi_hba_attr_manufacturer(struct lpfc_vport *vport,
2545 + ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
2546 + memset(ae, 0, 256);
2547 +
2548 ++ /* This string MUST be consistent with other FC platforms
2549 ++ * supported by Broadcom.
2550 ++ */
2551 + strncpy(ae->un.AttrString,
2552 + "Emulex Corporation",
2553 + sizeof(ae->un.AttrString));
2554 +diff --git a/drivers/scsi/lpfc/lpfc_hbadisc.c b/drivers/scsi/lpfc/lpfc_hbadisc.c
2555 +index 81736457328a..9cca5ddbc50c 100644
2556 +--- a/drivers/scsi/lpfc/lpfc_hbadisc.c
2557 ++++ b/drivers/scsi/lpfc/lpfc_hbadisc.c
2558 +@@ -901,7 +901,11 @@ lpfc_linkdown(struct lpfc_hba *phba)
2559 + lpfc_linkdown_port(vports[i]);
2560 + }
2561 + lpfc_destroy_vport_work_array(phba, vports);
2562 +- /* Clean up any firmware default rpi's */
2563 ++
2564 ++ /* Clean up any SLI3 firmware default rpi's */
2565 ++ if (phba->sli_rev > LPFC_SLI_REV3)
2566 ++ goto skip_unreg_did;
2567 ++
2568 + mb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2569 + if (mb) {
2570 + lpfc_unreg_did(phba, 0xffff, LPFC_UNREG_ALL_DFLT_RPIS, mb);
2571 +@@ -913,6 +917,7 @@ lpfc_linkdown(struct lpfc_hba *phba)
2572 + }
2573 + }
2574 +
2575 ++ skip_unreg_did:
2576 + /* Setup myDID for link up if we are in pt2pt mode */
2577 + if (phba->pport->fc_flag & FC_PT2PT) {
2578 + phba->pport->fc_myDID = 0;
2579 +@@ -4654,6 +4659,10 @@ lpfc_unreg_default_rpis(struct lpfc_vport *vport)
2580 + LPFC_MBOXQ_t *mbox;
2581 + int rc;
2582 +
2583 ++ /* Unreg DID is an SLI3 operation. */
2584 ++ if (phba->sli_rev > LPFC_SLI_REV3)
2585 ++ return;
2586 ++
2587 + mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2588 + if (mbox) {
2589 + lpfc_unreg_did(phba, vport->vpi, LPFC_UNREG_ALL_DFLT_RPIS,
2590 +diff --git a/drivers/scsi/qla2xxx/qla_isr.c b/drivers/scsi/qla2xxx/qla_isr.c
2591 +index 73c99f237b10..f0fcff032f8a 100644
2592 +--- a/drivers/scsi/qla2xxx/qla_isr.c
2593 ++++ b/drivers/scsi/qla2xxx/qla_isr.c
2594 +@@ -3089,7 +3089,7 @@ qla24xx_enable_msix(struct qla_hw_data *ha, struct rsp_que *rsp)
2595 + ql_log(ql_log_fatal, vha, 0x00c8,
2596 + "Failed to allocate memory for ha->msix_entries.\n");
2597 + ret = -ENOMEM;
2598 +- goto msix_out;
2599 ++ goto free_irqs;
2600 + }
2601 + ha->flags.msix_enabled = 1;
2602 +
2603 +@@ -3177,6 +3177,10 @@ msix_register_fail:
2604 + msix_out:
2605 + kfree(entries);
2606 + return ret;
2607 ++
2608 ++free_irqs:
2609 ++ pci_free_irq_vectors(ha->pdev);
2610 ++ goto msix_out;
2611 + }
2612 +
2613 + int
2614 +diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
2615 +index c158967b59d7..d220b4f691c7 100644
2616 +--- a/drivers/scsi/qla4xxx/ql4_os.c
2617 ++++ b/drivers/scsi/qla4xxx/ql4_os.c
2618 +@@ -5939,7 +5939,7 @@ static int get_fw_boot_info(struct scsi_qla_host *ha, uint16_t ddb_index[])
2619 + val = rd_nvram_byte(ha, sec_addr);
2620 + if (val & BIT_7)
2621 + ddb_index[1] = (val & 0x7f);
2622 +-
2623 ++ goto exit_boot_info;
2624 + } else if (is_qla80XX(ha)) {
2625 + buf = dma_alloc_coherent(&ha->pdev->dev, size,
2626 + &buf_dma, GFP_KERNEL);
2627 +diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
2628 +index 58345d3d4682..b40fe8d583c0 100644
2629 +--- a/drivers/scsi/sd.c
2630 ++++ b/drivers/scsi/sd.c
2631 +@@ -2403,7 +2403,6 @@ sd_read_write_protect_flag(struct scsi_disk *sdkp, unsigned char *buffer)
2632 + int res;
2633 + struct scsi_device *sdp = sdkp->device;
2634 + struct scsi_mode_data data;
2635 +- int disk_ro = get_disk_ro(sdkp->disk);
2636 + int old_wp = sdkp->write_prot;
2637 +
2638 + set_disk_ro(sdkp->disk, 0);
2639 +@@ -2444,7 +2443,7 @@ sd_read_write_protect_flag(struct scsi_disk *sdkp, unsigned char *buffer)
2640 + "Test WP failed, assume Write Enabled\n");
2641 + } else {
2642 + sdkp->write_prot = ((data.device_specific & 0x80) != 0);
2643 +- set_disk_ro(sdkp->disk, sdkp->write_prot || disk_ro);
2644 ++ set_disk_ro(sdkp->disk, sdkp->write_prot);
2645 + if (sdkp->first_scan || old_wp != sdkp->write_prot) {
2646 + sd_printk(KERN_NOTICE, sdkp, "Write Protect is %s\n",
2647 + sdkp->write_prot ? "on" : "off");
2648 +diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c
2649 +index 0b858414c558..0fe4f8e8c8c9 100644
2650 +--- a/drivers/scsi/ufs/ufshcd.c
2651 ++++ b/drivers/scsi/ufs/ufshcd.c
2652 +@@ -4875,19 +4875,19 @@ static u32 ufshcd_find_max_sup_active_icc_level(struct ufs_hba *hba,
2653 + goto out;
2654 + }
2655 +
2656 +- if (hba->vreg_info.vcc)
2657 ++ if (hba->vreg_info.vcc && hba->vreg_info.vcc->max_uA)
2658 + icc_level = ufshcd_get_max_icc_level(
2659 + hba->vreg_info.vcc->max_uA,
2660 + POWER_DESC_MAX_ACTV_ICC_LVLS - 1,
2661 + &desc_buf[PWR_DESC_ACTIVE_LVLS_VCC_0]);
2662 +
2663 +- if (hba->vreg_info.vccq)
2664 ++ if (hba->vreg_info.vccq && hba->vreg_info.vccq->max_uA)
2665 + icc_level = ufshcd_get_max_icc_level(
2666 + hba->vreg_info.vccq->max_uA,
2667 + icc_level,
2668 + &desc_buf[PWR_DESC_ACTIVE_LVLS_VCCQ_0]);
2669 +
2670 +- if (hba->vreg_info.vccq2)
2671 ++ if (hba->vreg_info.vccq2 && hba->vreg_info.vccq2->max_uA)
2672 + icc_level = ufshcd_get_max_icc_level(
2673 + hba->vreg_info.vccq2->max_uA,
2674 + icc_level,
2675 +@@ -5449,6 +5449,15 @@ static int ufshcd_config_vreg_load(struct device *dev, struct ufs_vreg *vreg,
2676 + if (!vreg)
2677 + return 0;
2678 +
2679 ++ /*
2680 ++ * "set_load" operation shall be required on those regulators
2681 ++ * which specifically configured current limitation. Otherwise
2682 ++ * zero max_uA may cause unexpected behavior when regulator is
2683 ++ * enabled or set as high power mode.
2684 ++ */
2685 ++ if (!vreg->max_uA)
2686 ++ return 0;
2687 ++
2688 + ret = regulator_set_load(vreg->reg, ua);
2689 + if (ret < 0) {
2690 + dev_err(dev, "%s: %s set load (ua=%d) failed, err=%d\n",
2691 +@@ -5495,12 +5504,15 @@ static int ufshcd_config_vreg(struct device *dev,
2692 + name = vreg->name;
2693 +
2694 + if (regulator_count_voltages(reg) > 0) {
2695 +- min_uV = on ? vreg->min_uV : 0;
2696 +- ret = regulator_set_voltage(reg, min_uV, vreg->max_uV);
2697 +- if (ret) {
2698 +- dev_err(dev, "%s: %s set voltage failed, err=%d\n",
2699 ++ if (vreg->min_uV && vreg->max_uV) {
2700 ++ min_uV = on ? vreg->min_uV : 0;
2701 ++ ret = regulator_set_voltage(reg, min_uV, vreg->max_uV);
2702 ++ if (ret) {
2703 ++ dev_err(dev,
2704 ++ "%s: %s set voltage failed, err=%d\n",
2705 + __func__, name, ret);
2706 +- goto out;
2707 ++ goto out;
2708 ++ }
2709 + }
2710 +
2711 + uA_load = on ? vreg->max_uA : 0;
2712 +diff --git a/drivers/spi/spi-pxa2xx.c b/drivers/spi/spi-pxa2xx.c
2713 +index f2209ec4cb68..8b618f0fa459 100644
2714 +--- a/drivers/spi/spi-pxa2xx.c
2715 ++++ b/drivers/spi/spi-pxa2xx.c
2716 +@@ -921,10 +921,14 @@ static unsigned int ssp_get_clk_div(struct driver_data *drv_data, int rate)
2717 +
2718 + rate = min_t(int, ssp_clk, rate);
2719 +
2720 ++ /*
2721 ++ * Calculate the divisor for the SCR (Serial Clock Rate), avoiding
2722 ++ * that the SSP transmission rate can be greater than the device rate
2723 ++ */
2724 + if (ssp->type == PXA25x_SSP || ssp->type == CE4100_SSP)
2725 +- return (ssp_clk / (2 * rate) - 1) & 0xff;
2726 ++ return (DIV_ROUND_UP(ssp_clk, 2 * rate) - 1) & 0xff;
2727 + else
2728 +- return (ssp_clk / rate - 1) & 0xfff;
2729 ++ return (DIV_ROUND_UP(ssp_clk, rate) - 1) & 0xfff;
2730 + }
2731 +
2732 + static unsigned int pxa2xx_ssp_get_clk_div(struct driver_data *drv_data,
2733 +diff --git a/drivers/spi/spi-rspi.c b/drivers/spi/spi-rspi.c
2734 +index 093c9cf92bfd..07612e8c58ee 100644
2735 +--- a/drivers/spi/spi-rspi.c
2736 ++++ b/drivers/spi/spi-rspi.c
2737 +@@ -279,7 +279,8 @@ static int rspi_set_config_register(struct rspi_data *rspi, int access_size)
2738 + /* Sets parity, interrupt mask */
2739 + rspi_write8(rspi, 0x00, RSPI_SPCR2);
2740 +
2741 +- /* Sets SPCMD */
2742 ++ /* Resets sequencer */
2743 ++ rspi_write8(rspi, 0, RSPI_SPSCR);
2744 + rspi->spcmd |= SPCMD_SPB_8_TO_16(access_size);
2745 + rspi_write16(rspi, rspi->spcmd, RSPI_SPCMD0);
2746 +
2747 +@@ -323,7 +324,8 @@ static int rspi_rz_set_config_register(struct rspi_data *rspi, int access_size)
2748 + rspi_write8(rspi, 0x00, RSPI_SSLND);
2749 + rspi_write8(rspi, 0x00, RSPI_SPND);
2750 +
2751 +- /* Sets SPCMD */
2752 ++ /* Resets sequencer */
2753 ++ rspi_write8(rspi, 0, RSPI_SPSCR);
2754 + rspi->spcmd |= SPCMD_SPB_8_TO_16(access_size);
2755 + rspi_write16(rspi, rspi->spcmd, RSPI_SPCMD0);
2756 +
2757 +@@ -374,7 +376,8 @@ static int qspi_set_config_register(struct rspi_data *rspi, int access_size)
2758 + /* Sets buffer to allow normal operation */
2759 + rspi_write8(rspi, 0x00, QSPI_SPBFCR);
2760 +
2761 +- /* Sets SPCMD */
2762 ++ /* Resets sequencer */
2763 ++ rspi_write8(rspi, 0, RSPI_SPSCR);
2764 + rspi_write16(rspi, rspi->spcmd, RSPI_SPCMD0);
2765 +
2766 + /* Enables SPI function in master mode */
2767 +diff --git a/drivers/spi/spi-tegra114.c b/drivers/spi/spi-tegra114.c
2768 +index 73779cecc3bb..705f515863d4 100644
2769 +--- a/drivers/spi/spi-tegra114.c
2770 ++++ b/drivers/spi/spi-tegra114.c
2771 +@@ -1067,27 +1067,19 @@ static int tegra_spi_probe(struct platform_device *pdev)
2772 +
2773 + spi_irq = platform_get_irq(pdev, 0);
2774 + tspi->irq = spi_irq;
2775 +- ret = request_threaded_irq(tspi->irq, tegra_spi_isr,
2776 +- tegra_spi_isr_thread, IRQF_ONESHOT,
2777 +- dev_name(&pdev->dev), tspi);
2778 +- if (ret < 0) {
2779 +- dev_err(&pdev->dev, "Failed to register ISR for IRQ %d\n",
2780 +- tspi->irq);
2781 +- goto exit_free_master;
2782 +- }
2783 +
2784 + tspi->clk = devm_clk_get(&pdev->dev, "spi");
2785 + if (IS_ERR(tspi->clk)) {
2786 + dev_err(&pdev->dev, "can not get clock\n");
2787 + ret = PTR_ERR(tspi->clk);
2788 +- goto exit_free_irq;
2789 ++ goto exit_free_master;
2790 + }
2791 +
2792 + tspi->rst = devm_reset_control_get(&pdev->dev, "spi");
2793 + if (IS_ERR(tspi->rst)) {
2794 + dev_err(&pdev->dev, "can not get reset\n");
2795 + ret = PTR_ERR(tspi->rst);
2796 +- goto exit_free_irq;
2797 ++ goto exit_free_master;
2798 + }
2799 +
2800 + tspi->max_buf_size = SPI_FIFO_DEPTH << 2;
2801 +@@ -1095,7 +1087,7 @@ static int tegra_spi_probe(struct platform_device *pdev)
2802 +
2803 + ret = tegra_spi_init_dma_param(tspi, true);
2804 + if (ret < 0)
2805 +- goto exit_free_irq;
2806 ++ goto exit_free_master;
2807 + ret = tegra_spi_init_dma_param(tspi, false);
2808 + if (ret < 0)
2809 + goto exit_rx_dma_free;
2810 +@@ -1117,18 +1109,32 @@ static int tegra_spi_probe(struct platform_device *pdev)
2811 + dev_err(&pdev->dev, "pm runtime get failed, e = %d\n", ret);
2812 + goto exit_pm_disable;
2813 + }
2814 ++
2815 ++ reset_control_assert(tspi->rst);
2816 ++ udelay(2);
2817 ++ reset_control_deassert(tspi->rst);
2818 + tspi->def_command1_reg = SPI_M_S;
2819 + tegra_spi_writel(tspi, tspi->def_command1_reg, SPI_COMMAND1);
2820 + pm_runtime_put(&pdev->dev);
2821 ++ ret = request_threaded_irq(tspi->irq, tegra_spi_isr,
2822 ++ tegra_spi_isr_thread, IRQF_ONESHOT,
2823 ++ dev_name(&pdev->dev), tspi);
2824 ++ if (ret < 0) {
2825 ++ dev_err(&pdev->dev, "Failed to register ISR for IRQ %d\n",
2826 ++ tspi->irq);
2827 ++ goto exit_pm_disable;
2828 ++ }
2829 +
2830 + master->dev.of_node = pdev->dev.of_node;
2831 + ret = devm_spi_register_master(&pdev->dev, master);
2832 + if (ret < 0) {
2833 + dev_err(&pdev->dev, "can not register to master err %d\n", ret);
2834 +- goto exit_pm_disable;
2835 ++ goto exit_free_irq;
2836 + }
2837 + return ret;
2838 +
2839 ++exit_free_irq:
2840 ++ free_irq(spi_irq, tspi);
2841 + exit_pm_disable:
2842 + pm_runtime_disable(&pdev->dev);
2843 + if (!pm_runtime_status_suspended(&pdev->dev))
2844 +@@ -1136,8 +1142,6 @@ exit_pm_disable:
2845 + tegra_spi_deinit_dma_param(tspi, false);
2846 + exit_rx_dma_free:
2847 + tegra_spi_deinit_dma_param(tspi, true);
2848 +-exit_free_irq:
2849 +- free_irq(spi_irq, tspi);
2850 + exit_free_master:
2851 + spi_master_put(master);
2852 + return ret;
2853 +diff --git a/drivers/spi/spi-topcliff-pch.c b/drivers/spi/spi-topcliff-pch.c
2854 +index c54ee6674471..fe707440f8c3 100644
2855 +--- a/drivers/spi/spi-topcliff-pch.c
2856 ++++ b/drivers/spi/spi-topcliff-pch.c
2857 +@@ -1306,18 +1306,27 @@ static void pch_free_dma_buf(struct pch_spi_board_data *board_dat,
2858 + return;
2859 + }
2860 +
2861 +-static void pch_alloc_dma_buf(struct pch_spi_board_data *board_dat,
2862 ++static int pch_alloc_dma_buf(struct pch_spi_board_data *board_dat,
2863 + struct pch_spi_data *data)
2864 + {
2865 + struct pch_spi_dma_ctrl *dma;
2866 ++ int ret;
2867 +
2868 + dma = &data->dma;
2869 ++ ret = 0;
2870 + /* Get Consistent memory for Tx DMA */
2871 + dma->tx_buf_virt = dma_alloc_coherent(&board_dat->pdev->dev,
2872 + PCH_BUF_SIZE, &dma->tx_buf_dma, GFP_KERNEL);
2873 ++ if (!dma->tx_buf_virt)
2874 ++ ret = -ENOMEM;
2875 ++
2876 + /* Get Consistent memory for Rx DMA */
2877 + dma->rx_buf_virt = dma_alloc_coherent(&board_dat->pdev->dev,
2878 + PCH_BUF_SIZE, &dma->rx_buf_dma, GFP_KERNEL);
2879 ++ if (!dma->rx_buf_virt)
2880 ++ ret = -ENOMEM;
2881 ++
2882 ++ return ret;
2883 + }
2884 +
2885 + static int pch_spi_pd_probe(struct platform_device *plat_dev)
2886 +@@ -1394,7 +1403,9 @@ static int pch_spi_pd_probe(struct platform_device *plat_dev)
2887 +
2888 + if (use_dma) {
2889 + dev_info(&plat_dev->dev, "Use DMA for data transfers\n");
2890 +- pch_alloc_dma_buf(board_dat, data);
2891 ++ ret = pch_alloc_dma_buf(board_dat, data);
2892 ++ if (ret)
2893 ++ goto err_spi_register_master;
2894 + }
2895 +
2896 + ret = spi_register_master(master);
2897 +diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
2898 +index c2e85e23d538..d74d341f9890 100644
2899 +--- a/drivers/spi/spi.c
2900 ++++ b/drivers/spi/spi.c
2901 +@@ -955,6 +955,8 @@ static int spi_map_msg(struct spi_master *master, struct spi_message *msg)
2902 + if (max_tx || max_rx) {
2903 + list_for_each_entry(xfer, &msg->transfers,
2904 + transfer_list) {
2905 ++ if (!xfer->len)
2906 ++ continue;
2907 + if (!xfer->tx_buf)
2908 + xfer->tx_buf = master->dummy_tx;
2909 + if (!xfer->rx_buf)
2910 +diff --git a/drivers/ssb/bridge_pcmcia_80211.c b/drivers/ssb/bridge_pcmcia_80211.c
2911 +index d70568ea02d5..2ff7d90e166a 100644
2912 +--- a/drivers/ssb/bridge_pcmcia_80211.c
2913 ++++ b/drivers/ssb/bridge_pcmcia_80211.c
2914 +@@ -113,16 +113,21 @@ static struct pcmcia_driver ssb_host_pcmcia_driver = {
2915 + .resume = ssb_host_pcmcia_resume,
2916 + };
2917 +
2918 ++static int pcmcia_init_failed;
2919 ++
2920 + /*
2921 + * These are not module init/exit functions!
2922 + * The module_pcmcia_driver() helper cannot be used here.
2923 + */
2924 + int ssb_host_pcmcia_init(void)
2925 + {
2926 +- return pcmcia_register_driver(&ssb_host_pcmcia_driver);
2927 ++ pcmcia_init_failed = pcmcia_register_driver(&ssb_host_pcmcia_driver);
2928 ++
2929 ++ return pcmcia_init_failed;
2930 + }
2931 +
2932 + void ssb_host_pcmcia_exit(void)
2933 + {
2934 +- pcmcia_unregister_driver(&ssb_host_pcmcia_driver);
2935 ++ if (!pcmcia_init_failed)
2936 ++ pcmcia_unregister_driver(&ssb_host_pcmcia_driver);
2937 + }
2938 +diff --git a/drivers/tty/ipwireless/main.c b/drivers/tty/ipwireless/main.c
2939 +index 655c7948261c..2fa4f9123469 100644
2940 +--- a/drivers/tty/ipwireless/main.c
2941 ++++ b/drivers/tty/ipwireless/main.c
2942 +@@ -113,6 +113,10 @@ static int ipwireless_probe(struct pcmcia_device *p_dev, void *priv_data)
2943 +
2944 + ipw->common_memory = ioremap(p_dev->resource[2]->start,
2945 + resource_size(p_dev->resource[2]));
2946 ++ if (!ipw->common_memory) {
2947 ++ ret = -ENOMEM;
2948 ++ goto exit1;
2949 ++ }
2950 + if (!request_mem_region(p_dev->resource[2]->start,
2951 + resource_size(p_dev->resource[2]),
2952 + IPWIRELESS_PCCARD_NAME)) {
2953 +@@ -133,6 +137,10 @@ static int ipwireless_probe(struct pcmcia_device *p_dev, void *priv_data)
2954 +
2955 + ipw->attr_memory = ioremap(p_dev->resource[3]->start,
2956 + resource_size(p_dev->resource[3]));
2957 ++ if (!ipw->attr_memory) {
2958 ++ ret = -ENOMEM;
2959 ++ goto exit3;
2960 ++ }
2961 + if (!request_mem_region(p_dev->resource[3]->start,
2962 + resource_size(p_dev->resource[3]),
2963 + IPWIRELESS_PCCARD_NAME)) {
2964 +diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
2965 +index bdb0d7a08ff9..1dd4c65e9188 100644
2966 +--- a/drivers/usb/core/hcd.c
2967 ++++ b/drivers/usb/core/hcd.c
2968 +@@ -3033,6 +3033,9 @@ usb_hcd_platform_shutdown(struct platform_device *dev)
2969 + {
2970 + struct usb_hcd *hcd = platform_get_drvdata(dev);
2971 +
2972 ++ /* No need for pm_runtime_put(), we're shutting down */
2973 ++ pm_runtime_get_sync(&dev->dev);
2974 ++
2975 + if (hcd->driver->shutdown)
2976 + hcd->driver->shutdown(hcd);
2977 + }
2978 +diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
2979 +index 8fddb94f1874..3941df076cca 100644
2980 +--- a/drivers/usb/core/hub.c
2981 ++++ b/drivers/usb/core/hub.c
2982 +@@ -5703,7 +5703,10 @@ int usb_reset_device(struct usb_device *udev)
2983 + cintf->needs_binding = 1;
2984 + }
2985 + }
2986 +- usb_unbind_and_rebind_marked_interfaces(udev);
2987 ++
2988 ++ /* If the reset failed, hub_wq will unbind drivers later */
2989 ++ if (ret == 0)
2990 ++ usb_unbind_and_rebind_marked_interfaces(udev);
2991 + }
2992 +
2993 + usb_autosuspend_device(udev);
2994 +diff --git a/drivers/video/fbdev/core/fbcmap.c b/drivers/video/fbdev/core/fbcmap.c
2995 +index 68a113594808..2811c4afde01 100644
2996 +--- a/drivers/video/fbdev/core/fbcmap.c
2997 ++++ b/drivers/video/fbdev/core/fbcmap.c
2998 +@@ -94,6 +94,8 @@ int fb_alloc_cmap_gfp(struct fb_cmap *cmap, int len, int transp, gfp_t flags)
2999 + int size = len * sizeof(u16);
3000 + int ret = -ENOMEM;
3001 +
3002 ++ flags |= __GFP_NOWARN;
3003 ++
3004 + if (cmap->len != len) {
3005 + fb_dealloc_cmap(cmap);
3006 + if (!len)
3007 +diff --git a/drivers/video/fbdev/core/modedb.c b/drivers/video/fbdev/core/modedb.c
3008 +index de119f11b78f..455a15f70172 100644
3009 +--- a/drivers/video/fbdev/core/modedb.c
3010 ++++ b/drivers/video/fbdev/core/modedb.c
3011 +@@ -933,6 +933,9 @@ void fb_var_to_videomode(struct fb_videomode *mode,
3012 + if (var->vmode & FB_VMODE_DOUBLE)
3013 + vtotal *= 2;
3014 +
3015 ++ if (!htotal || !vtotal)
3016 ++ return;
3017 ++
3018 + hfreq = pixclock/htotal;
3019 + mode->refresh = hfreq/vtotal;
3020 + }
3021 +diff --git a/drivers/w1/w1_io.c b/drivers/w1/w1_io.c
3022 +index f4bc8c100a01..a3ac582420ec 100644
3023 +--- a/drivers/w1/w1_io.c
3024 ++++ b/drivers/w1/w1_io.c
3025 +@@ -437,8 +437,7 @@ int w1_reset_resume_command(struct w1_master *dev)
3026 + if (w1_reset_bus(dev))
3027 + return -1;
3028 +
3029 +- /* This will make only the last matched slave perform a skip ROM. */
3030 +- w1_write_8(dev, W1_RESUME_CMD);
3031 ++ w1_write_8(dev, dev->slave_count > 1 ? W1_RESUME_CMD : W1_SKIP_ROM);
3032 + return 0;
3033 + }
3034 + EXPORT_SYMBOL_GPL(w1_reset_resume_command);
3035 +diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
3036 +index 6b29165f766f..7938c48c72ff 100644
3037 +--- a/fs/btrfs/extent-tree.c
3038 ++++ b/fs/btrfs/extent-tree.c
3039 +@@ -11150,9 +11150,9 @@ int btrfs_error_unpin_extent_range(struct btrfs_root *root, u64 start, u64 end)
3040 + * transaction.
3041 + */
3042 + static int btrfs_trim_free_extents(struct btrfs_device *device,
3043 +- struct fstrim_range *range, u64 *trimmed)
3044 ++ u64 minlen, u64 *trimmed)
3045 + {
3046 +- u64 start = range->start, len = 0;
3047 ++ u64 start = 0, len = 0;
3048 + int ret;
3049 +
3050 + *trimmed = 0;
3051 +@@ -11188,8 +11188,8 @@ static int btrfs_trim_free_extents(struct btrfs_device *device,
3052 + atomic_inc(&trans->use_count);
3053 + spin_unlock(&fs_info->trans_lock);
3054 +
3055 +- ret = find_free_dev_extent_start(trans, device, range->minlen,
3056 +- start, &start, &len);
3057 ++ ret = find_free_dev_extent_start(trans, device, minlen, start,
3058 ++ &start, &len);
3059 + if (trans)
3060 + btrfs_put_transaction(trans);
3061 +
3062 +@@ -11201,16 +11201,6 @@ static int btrfs_trim_free_extents(struct btrfs_device *device,
3063 + break;
3064 + }
3065 +
3066 +- /* If we are out of the passed range break */
3067 +- if (start > range->start + range->len - 1) {
3068 +- mutex_unlock(&fs_info->chunk_mutex);
3069 +- ret = 0;
3070 +- break;
3071 +- }
3072 +-
3073 +- start = max(range->start, start);
3074 +- len = min(range->len, len);
3075 +-
3076 + ret = btrfs_issue_discard(device->bdev, start, len, &bytes);
3077 + up_read(&fs_info->commit_root_sem);
3078 + mutex_unlock(&fs_info->chunk_mutex);
3079 +@@ -11221,10 +11211,6 @@ static int btrfs_trim_free_extents(struct btrfs_device *device,
3080 + start += len;
3081 + *trimmed += bytes;
3082 +
3083 +- /* We've trimmed enough */
3084 +- if (*trimmed >= range->len)
3085 +- break;
3086 +-
3087 + if (fatal_signal_pending(current)) {
3088 + ret = -ERESTARTSYS;
3089 + break;
3090 +@@ -11309,7 +11295,8 @@ int btrfs_trim_fs(struct btrfs_root *root, struct fstrim_range *range)
3091 + mutex_lock(&fs_info->fs_devices->device_list_mutex);
3092 + devices = &fs_info->fs_devices->devices;
3093 + list_for_each_entry(device, devices, dev_list) {
3094 +- ret = btrfs_trim_free_extents(device, range, &group_trimmed);
3095 ++ ret = btrfs_trim_free_extents(device, range->minlen,
3096 ++ &group_trimmed);
3097 + if (ret) {
3098 + dev_failed++;
3099 + dev_ret = ret;
3100 +diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c
3101 +index 437544846e4e..c77114ce884b 100644
3102 +--- a/fs/btrfs/file.c
3103 ++++ b/fs/btrfs/file.c
3104 +@@ -1951,6 +1951,18 @@ int btrfs_sync_file(struct file *file, loff_t start, loff_t end, int datasync)
3105 + bool full_sync = 0;
3106 + u64 len;
3107 +
3108 ++ /*
3109 ++ * If the inode needs a full sync, make sure we use a full range to
3110 ++ * avoid log tree corruption, due to hole detection racing with ordered
3111 ++ * extent completion for adjacent ranges, and assertion failures during
3112 ++ * hole detection.
3113 ++ */
3114 ++ if (test_bit(BTRFS_INODE_NEEDS_FULL_SYNC,
3115 ++ &BTRFS_I(inode)->runtime_flags)) {
3116 ++ start = 0;
3117 ++ end = LLONG_MAX;
3118 ++ }
3119 ++
3120 + /*
3121 + * The range length can be represented by u64, we have to do the typecasts
3122 + * to avoid signed overflow if it's [0, LLONG_MAX] eg. from fsync()
3123 +diff --git a/fs/btrfs/root-tree.c b/fs/btrfs/root-tree.c
3124 +index edae751e870c..307b8baaf0e9 100644
3125 +--- a/fs/btrfs/root-tree.c
3126 ++++ b/fs/btrfs/root-tree.c
3127 +@@ -144,10 +144,8 @@ int btrfs_update_root(struct btrfs_trans_handle *trans, struct btrfs_root
3128 + return -ENOMEM;
3129 +
3130 + ret = btrfs_search_slot(trans, root, key, path, 0, 1);
3131 +- if (ret < 0) {
3132 +- btrfs_abort_transaction(trans, ret);
3133 ++ if (ret < 0)
3134 + goto out;
3135 +- }
3136 +
3137 + if (ret != 0) {
3138 + btrfs_print_leaf(root, path->nodes[0]);
3139 +diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
3140 +index 1f157fba8940..510cad48e519 100644
3141 +--- a/fs/btrfs/sysfs.c
3142 ++++ b/fs/btrfs/sysfs.c
3143 +@@ -751,7 +751,12 @@ int btrfs_sysfs_add_fsid(struct btrfs_fs_devices *fs_devs,
3144 + fs_devs->fsid_kobj.kset = btrfs_kset;
3145 + error = kobject_init_and_add(&fs_devs->fsid_kobj,
3146 + &btrfs_ktype, parent, "%pU", fs_devs->fsid);
3147 +- return error;
3148 ++ if (error) {
3149 ++ kobject_put(&fs_devs->fsid_kobj);
3150 ++ return error;
3151 ++ }
3152 ++
3153 ++ return 0;
3154 + }
3155 +
3156 + int btrfs_sysfs_add_mounted(struct btrfs_fs_info *fs_info)
3157 +diff --git a/fs/char_dev.c b/fs/char_dev.c
3158 +index 44a240c4bb65..a112a4745d8b 100644
3159 +--- a/fs/char_dev.c
3160 ++++ b/fs/char_dev.c
3161 +@@ -134,6 +134,12 @@ __register_chrdev_region(unsigned int major, unsigned int baseminor,
3162 + ret = -EBUSY;
3163 + goto out;
3164 + }
3165 ++
3166 ++ if (new_min < old_min && new_max > old_max) {
3167 ++ ret = -EBUSY;
3168 ++ goto out;
3169 ++ }
3170 ++
3171 + }
3172 +
3173 + cd->next = *cp;
3174 +diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
3175 +index 4815be26b15f..b8046182efb0 100644
3176 +--- a/fs/ext4/inode.c
3177 ++++ b/fs/ext4/inode.c
3178 +@@ -5223,7 +5223,7 @@ int ext4_setattr(struct dentry *dentry, struct iattr *attr)
3179 + up_write(&EXT4_I(inode)->i_data_sem);
3180 + ext4_journal_stop(handle);
3181 + if (error) {
3182 +- if (orphan)
3183 ++ if (orphan && inode->i_nlink)
3184 + ext4_orphan_del(NULL, inode);
3185 + goto err_out;
3186 + }
3187 +diff --git a/fs/gfs2/glock.c b/fs/gfs2/glock.c
3188 +index 7a8b1d72e3d9..efd44d5645d8 100644
3189 +--- a/fs/gfs2/glock.c
3190 ++++ b/fs/gfs2/glock.c
3191 +@@ -136,22 +136,26 @@ static int demote_ok(const struct gfs2_glock *gl)
3192 +
3193 + void gfs2_glock_add_to_lru(struct gfs2_glock *gl)
3194 + {
3195 ++ if (!(gl->gl_ops->go_flags & GLOF_LRU))
3196 ++ return;
3197 ++
3198 + spin_lock(&lru_lock);
3199 +
3200 +- if (!list_empty(&gl->gl_lru))
3201 +- list_del_init(&gl->gl_lru);
3202 +- else
3203 ++ list_del(&gl->gl_lru);
3204 ++ list_add_tail(&gl->gl_lru, &lru_list);
3205 ++
3206 ++ if (!test_bit(GLF_LRU, &gl->gl_flags)) {
3207 ++ set_bit(GLF_LRU, &gl->gl_flags);
3208 + atomic_inc(&lru_count);
3209 ++ }
3210 +
3211 +- list_add_tail(&gl->gl_lru, &lru_list);
3212 +- set_bit(GLF_LRU, &gl->gl_flags);
3213 + spin_unlock(&lru_lock);
3214 + }
3215 +
3216 + static void gfs2_glock_remove_from_lru(struct gfs2_glock *gl)
3217 + {
3218 + spin_lock(&lru_lock);
3219 +- if (!list_empty(&gl->gl_lru)) {
3220 ++ if (test_bit(GLF_LRU, &gl->gl_flags)) {
3221 + list_del_init(&gl->gl_lru);
3222 + atomic_dec(&lru_count);
3223 + clear_bit(GLF_LRU, &gl->gl_flags);
3224 +@@ -1048,8 +1052,7 @@ void gfs2_glock_dq(struct gfs2_holder *gh)
3225 + !test_bit(GLF_DEMOTE, &gl->gl_flags))
3226 + fast_path = 1;
3227 + }
3228 +- if (!test_bit(GLF_LFLUSH, &gl->gl_flags) && demote_ok(gl) &&
3229 +- (glops->go_flags & GLOF_LRU))
3230 ++ if (!test_bit(GLF_LFLUSH, &gl->gl_flags) && demote_ok(gl))
3231 + gfs2_glock_add_to_lru(gl);
3232 +
3233 + trace_gfs2_glock_queue(gh, 0);
3234 +@@ -1349,6 +1352,7 @@ __acquires(&lru_lock)
3235 + if (!spin_trylock(&gl->gl_lockref.lock)) {
3236 + add_back_to_lru:
3237 + list_add(&gl->gl_lru, &lru_list);
3238 ++ set_bit(GLF_LRU, &gl->gl_flags);
3239 + atomic_inc(&lru_count);
3240 + continue;
3241 + }
3242 +@@ -1356,7 +1360,6 @@ add_back_to_lru:
3243 + spin_unlock(&gl->gl_lockref.lock);
3244 + goto add_back_to_lru;
3245 + }
3246 +- clear_bit(GLF_LRU, &gl->gl_flags);
3247 + gl->gl_lockref.count++;
3248 + if (demote_ok(gl))
3249 + handle_callback(gl, LM_ST_UNLOCKED, 0, false);
3250 +@@ -1392,6 +1395,7 @@ static long gfs2_scan_glock_lru(int nr)
3251 + if (!test_bit(GLF_LOCK, &gl->gl_flags)) {
3252 + list_move(&gl->gl_lru, &dispose);
3253 + atomic_dec(&lru_count);
3254 ++ clear_bit(GLF_LRU, &gl->gl_flags);
3255 + freed++;
3256 + continue;
3257 + }
3258 +diff --git a/fs/gfs2/lock_dlm.c b/fs/gfs2/lock_dlm.c
3259 +index 8b907c5cc913..3c3d037df824 100644
3260 +--- a/fs/gfs2/lock_dlm.c
3261 ++++ b/fs/gfs2/lock_dlm.c
3262 +@@ -32,9 +32,10 @@ extern struct workqueue_struct *gfs2_control_wq;
3263 + * @delta is the difference between the current rtt sample and the
3264 + * running average srtt. We add 1/8 of that to the srtt in order to
3265 + * update the current srtt estimate. The variance estimate is a bit
3266 +- * more complicated. We subtract the abs value of the @delta from
3267 +- * the current variance estimate and add 1/4 of that to the running
3268 +- * total.
3269 ++ * more complicated. We subtract the current variance estimate from
3270 ++ * the abs value of the @delta and add 1/4 of that to the running
3271 ++ * total. That's equivalent to 3/4 of the current variance
3272 ++ * estimate plus 1/4 of the abs of @delta.
3273 + *
3274 + * Note that the index points at the array entry containing the smoothed
3275 + * mean value, and the variance is always in the following entry
3276 +@@ -50,7 +51,7 @@ static inline void gfs2_update_stats(struct gfs2_lkstats *s, unsigned index,
3277 + s64 delta = sample - s->stats[index];
3278 + s->stats[index] += (delta >> 3);
3279 + index++;
3280 +- s->stats[index] += ((abs(delta) - s->stats[index]) >> 2);
3281 ++ s->stats[index] += (s64)(abs(delta) - s->stats[index]) >> 2;
3282 + }
3283 +
3284 + /**
3285 +diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
3286 +index 4acc677ac8fb..253b03451b72 100644
3287 +--- a/fs/hugetlbfs/inode.c
3288 ++++ b/fs/hugetlbfs/inode.c
3289 +@@ -451,9 +451,7 @@ static void remove_inode_hugepages(struct inode *inode, loff_t lstart,
3290 + if (next >= end)
3291 + break;
3292 +
3293 +- hash = hugetlb_fault_mutex_hash(h, current->mm,
3294 +- &pseudo_vma,
3295 +- mapping, next, 0);
3296 ++ hash = hugetlb_fault_mutex_hash(h, mapping, next, 0);
3297 + mutex_lock(&hugetlb_fault_mutex_table[hash]);
3298 +
3299 + /*
3300 +@@ -573,7 +571,6 @@ static long hugetlbfs_fallocate(struct file *file, int mode, loff_t offset,
3301 + struct address_space *mapping = inode->i_mapping;
3302 + struct hstate *h = hstate_inode(inode);
3303 + struct vm_area_struct pseudo_vma;
3304 +- struct mm_struct *mm = current->mm;
3305 + loff_t hpage_size = huge_page_size(h);
3306 + unsigned long hpage_shift = huge_page_shift(h);
3307 + pgoff_t start, index, end;
3308 +@@ -637,8 +634,7 @@ static long hugetlbfs_fallocate(struct file *file, int mode, loff_t offset,
3309 + addr = index * hpage_size;
3310 +
3311 + /* mutex taken here, fault path and hole punch */
3312 +- hash = hugetlb_fault_mutex_hash(h, mm, &pseudo_vma, mapping,
3313 +- index, addr);
3314 ++ hash = hugetlb_fault_mutex_hash(h, mapping, index, addr);
3315 + mutex_lock(&hugetlb_fault_mutex_table[hash]);
3316 +
3317 + /* See if already present in mapping to avoid alloc/free */
3318 +diff --git a/include/linux/bio.h b/include/linux/bio.h
3319 +index 97cb48f03dc7..a5ca6f199b88 100644
3320 +--- a/include/linux/bio.h
3321 ++++ b/include/linux/bio.h
3322 +@@ -237,7 +237,7 @@ static inline void bio_cnt_set(struct bio *bio, unsigned int count)
3323 + {
3324 + if (count != 1) {
3325 + bio->bi_flags |= (1 << BIO_REFFED);
3326 +- smp_mb__before_atomic();
3327 ++ smp_mb();
3328 + }
3329 + atomic_set(&bio->__bi_cnt, count);
3330 + }
3331 +diff --git a/include/linux/hid.h b/include/linux/hid.h
3332 +index fab65b61d6d4..04bdf5477ec5 100644
3333 +--- a/include/linux/hid.h
3334 ++++ b/include/linux/hid.h
3335 +@@ -374,6 +374,7 @@ struct hid_global {
3336 +
3337 + struct hid_local {
3338 + unsigned usage[HID_MAX_USAGES]; /* usage array */
3339 ++ u8 usage_size[HID_MAX_USAGES]; /* usage size array */
3340 + unsigned collection_index[HID_MAX_USAGES]; /* collection index array */
3341 + unsigned usage_index;
3342 + unsigned usage_minimum;
3343 +diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h
3344 +index b699d59d0f4f..6b8a7b654771 100644
3345 +--- a/include/linux/hugetlb.h
3346 ++++ b/include/linux/hugetlb.h
3347 +@@ -92,9 +92,7 @@ void putback_active_hugepage(struct page *page);
3348 + void free_huge_page(struct page *page);
3349 + void hugetlb_fix_reserve_counts(struct inode *inode);
3350 + extern struct mutex *hugetlb_fault_mutex_table;
3351 +-u32 hugetlb_fault_mutex_hash(struct hstate *h, struct mm_struct *mm,
3352 +- struct vm_area_struct *vma,
3353 +- struct address_space *mapping,
3354 ++u32 hugetlb_fault_mutex_hash(struct hstate *h, struct address_space *mapping,
3355 + pgoff_t idx, unsigned long address);
3356 +
3357 + pte_t *huge_pmd_share(struct mm_struct *mm, unsigned long addr, pud_t *pud);
3358 +diff --git a/include/linux/iio/adc/ad_sigma_delta.h b/include/linux/iio/adc/ad_sigma_delta.h
3359 +index 6cc48ac55fd2..40b14736c73d 100644
3360 +--- a/include/linux/iio/adc/ad_sigma_delta.h
3361 ++++ b/include/linux/iio/adc/ad_sigma_delta.h
3362 +@@ -66,6 +66,7 @@ struct ad_sigma_delta {
3363 + bool irq_dis;
3364 +
3365 + bool bus_locked;
3366 ++ bool keep_cs_asserted;
3367 +
3368 + uint8_t comm;
3369 +
3370 +diff --git a/include/linux/smpboot.h b/include/linux/smpboot.h
3371 +index 12910cf19869..12a4b09f4d08 100644
3372 +--- a/include/linux/smpboot.h
3373 ++++ b/include/linux/smpboot.h
3374 +@@ -30,7 +30,7 @@ struct smpboot_thread_data;
3375 + * @thread_comm: The base name of the thread
3376 + */
3377 + struct smp_hotplug_thread {
3378 +- struct task_struct __percpu **store;
3379 ++ struct task_struct * __percpu *store;
3380 + struct list_head list;
3381 + int (*thread_should_run)(unsigned int cpu);
3382 + void (*thread_fn)(unsigned int cpu);
3383 +diff --git a/kernel/auditfilter.c b/kernel/auditfilter.c
3384 +index cd4f41397c7e..42b7251c597f 100644
3385 +--- a/kernel/auditfilter.c
3386 ++++ b/kernel/auditfilter.c
3387 +@@ -1095,22 +1095,24 @@ int audit_rule_change(int type, __u32 portid, int seq, void *data,
3388 + int err = 0;
3389 + struct audit_entry *entry;
3390 +
3391 +- entry = audit_data_to_entry(data, datasz);
3392 +- if (IS_ERR(entry))
3393 +- return PTR_ERR(entry);
3394 +-
3395 + switch (type) {
3396 + case AUDIT_ADD_RULE:
3397 ++ entry = audit_data_to_entry(data, datasz);
3398 ++ if (IS_ERR(entry))
3399 ++ return PTR_ERR(entry);
3400 + err = audit_add_rule(entry);
3401 + audit_log_rule_change("add_rule", &entry->rule, !err);
3402 + break;
3403 + case AUDIT_DEL_RULE:
3404 ++ entry = audit_data_to_entry(data, datasz);
3405 ++ if (IS_ERR(entry))
3406 ++ return PTR_ERR(entry);
3407 + err = audit_del_rule(entry);
3408 + audit_log_rule_change("remove_rule", &entry->rule, !err);
3409 + break;
3410 + default:
3411 +- err = -EINVAL;
3412 + WARN_ON(1);
3413 ++ return -EINVAL;
3414 + }
3415 +
3416 + if (err || type == AUDIT_DEL_RULE) {
3417 +diff --git a/kernel/rcu/rcuperf.c b/kernel/rcu/rcuperf.c
3418 +index 123ccbd22449..2b8579d5a544 100644
3419 +--- a/kernel/rcu/rcuperf.c
3420 ++++ b/kernel/rcu/rcuperf.c
3421 +@@ -453,6 +453,10 @@ rcu_perf_cleanup(void)
3422 +
3423 + if (torture_cleanup_begin())
3424 + return;
3425 ++ if (!cur_ops) {
3426 ++ torture_cleanup_end();
3427 ++ return;
3428 ++ }
3429 +
3430 + if (reader_tasks) {
3431 + for (i = 0; i < nrealreaders; i++)
3432 +@@ -574,6 +578,7 @@ rcu_perf_init(void)
3433 + pr_alert(" %s", perf_ops[i]->name);
3434 + pr_alert("\n");
3435 + firsterr = -EINVAL;
3436 ++ cur_ops = NULL;
3437 + goto unwind;
3438 + }
3439 + if (cur_ops->init)
3440 +diff --git a/kernel/rcu/rcutorture.c b/kernel/rcu/rcutorture.c
3441 +index bf08fee53dc7..5393bbcf3c1a 100644
3442 +--- a/kernel/rcu/rcutorture.c
3443 ++++ b/kernel/rcu/rcutorture.c
3444 +@@ -1595,6 +1595,10 @@ rcu_torture_cleanup(void)
3445 + cur_ops->cb_barrier();
3446 + return;
3447 + }
3448 ++ if (!cur_ops) {
3449 ++ torture_cleanup_end();
3450 ++ return;
3451 ++ }
3452 +
3453 + rcu_torture_barrier_cleanup();
3454 + torture_stop_kthread(rcu_torture_stall, stall_task);
3455 +@@ -1730,6 +1734,7 @@ rcu_torture_init(void)
3456 + pr_alert(" %s", torture_ops[i]->name);
3457 + pr_alert("\n");
3458 + firsterr = -EINVAL;
3459 ++ cur_ops = NULL;
3460 + goto unwind;
3461 + }
3462 + if (cur_ops->fqs == NULL && fqs_duration != 0) {
3463 +diff --git a/kernel/sched/core.c b/kernel/sched/core.c
3464 +index 50e80b1be2c8..3861dd6da91e 100644
3465 +--- a/kernel/sched/core.c
3466 ++++ b/kernel/sched/core.c
3467 +@@ -8512,6 +8512,8 @@ static void cpu_cgroup_attach(struct cgroup_taskset *tset)
3468 + static int cpu_shares_write_u64(struct cgroup_subsys_state *css,
3469 + struct cftype *cftype, u64 shareval)
3470 + {
3471 ++ if (shareval > scale_load_down(ULONG_MAX))
3472 ++ shareval = MAX_SHARES;
3473 + return sched_group_set_shares(css_tg(css), scale_load(shareval));
3474 + }
3475 +
3476 +@@ -8611,8 +8613,10 @@ int tg_set_cfs_quota(struct task_group *tg, long cfs_quota_us)
3477 + period = ktime_to_ns(tg->cfs_bandwidth.period);
3478 + if (cfs_quota_us < 0)
3479 + quota = RUNTIME_INF;
3480 +- else
3481 ++ else if ((u64)cfs_quota_us <= U64_MAX / NSEC_PER_USEC)
3482 + quota = (u64)cfs_quota_us * NSEC_PER_USEC;
3483 ++ else
3484 ++ return -EINVAL;
3485 +
3486 + return tg_set_cfs_bandwidth(tg, period, quota);
3487 + }
3488 +@@ -8634,6 +8638,9 @@ int tg_set_cfs_period(struct task_group *tg, long cfs_period_us)
3489 + {
3490 + u64 quota, period;
3491 +
3492 ++ if ((u64)cfs_period_us > U64_MAX / NSEC_PER_USEC)
3493 ++ return -EINVAL;
3494 ++
3495 + period = (u64)cfs_period_us * NSEC_PER_USEC;
3496 + quota = tg->cfs_bandwidth.quota;
3497 +
3498 +diff --git a/lib/strncpy_from_user.c b/lib/strncpy_from_user.c
3499 +index 7e35fc450c5b..5a07f19059c3 100644
3500 +--- a/lib/strncpy_from_user.c
3501 ++++ b/lib/strncpy_from_user.c
3502 +@@ -22,10 +22,11 @@
3503 + * hit it), 'max' is the address space maximum (and we return
3504 + * -EFAULT if we hit it).
3505 + */
3506 +-static inline long do_strncpy_from_user(char *dst, const char __user *src, long count, unsigned long max)
3507 ++static inline long do_strncpy_from_user(char *dst, const char __user *src,
3508 ++ unsigned long count, unsigned long max)
3509 + {
3510 + const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
3511 +- long res = 0;
3512 ++ unsigned long res = 0;
3513 +
3514 + /*
3515 + * Truncate 'max' to the user-specified limit, so that
3516 +diff --git a/lib/strnlen_user.c b/lib/strnlen_user.c
3517 +index 8e105ed4df12..9ff4f3bbb1aa 100644
3518 +--- a/lib/strnlen_user.c
3519 ++++ b/lib/strnlen_user.c
3520 +@@ -27,7 +27,7 @@
3521 + static inline long do_strnlen_user(const char __user *src, unsigned long count, unsigned long max)
3522 + {
3523 + const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
3524 +- long align, res = 0;
3525 ++ unsigned long align, res = 0;
3526 + unsigned long c;
3527 +
3528 + /*
3529 +@@ -41,7 +41,7 @@ static inline long do_strnlen_user(const char __user *src, unsigned long count,
3530 + * Do everything aligned. But that means that we
3531 + * need to also expand the maximum..
3532 + */
3533 +- align = (sizeof(long) - 1) & (unsigned long)src;
3534 ++ align = (sizeof(unsigned long) - 1) & (unsigned long)src;
3535 + src -= align;
3536 + max += align;
3537 +
3538 +diff --git a/mm/hugetlb.c b/mm/hugetlb.c
3539 +index 8b682da98d95..75d8bd7e8798 100644
3540 +--- a/mm/hugetlb.c
3541 ++++ b/mm/hugetlb.c
3542 +@@ -3812,21 +3812,14 @@ backout_unlocked:
3543 + }
3544 +
3545 + #ifdef CONFIG_SMP
3546 +-u32 hugetlb_fault_mutex_hash(struct hstate *h, struct mm_struct *mm,
3547 +- struct vm_area_struct *vma,
3548 +- struct address_space *mapping,
3549 ++u32 hugetlb_fault_mutex_hash(struct hstate *h, struct address_space *mapping,
3550 + pgoff_t idx, unsigned long address)
3551 + {
3552 + unsigned long key[2];
3553 + u32 hash;
3554 +
3555 +- if (vma->vm_flags & VM_SHARED) {
3556 +- key[0] = (unsigned long) mapping;
3557 +- key[1] = idx;
3558 +- } else {
3559 +- key[0] = (unsigned long) mm;
3560 +- key[1] = address >> huge_page_shift(h);
3561 +- }
3562 ++ key[0] = (unsigned long) mapping;
3563 ++ key[1] = idx;
3564 +
3565 + hash = jhash2((u32 *)&key, sizeof(key)/sizeof(u32), 0);
3566 +
3567 +@@ -3837,9 +3830,7 @@ u32 hugetlb_fault_mutex_hash(struct hstate *h, struct mm_struct *mm,
3568 + * For uniprocesor systems we always use a single mutex, so just
3569 + * return 0 and avoid the hashing overhead.
3570 + */
3571 +-u32 hugetlb_fault_mutex_hash(struct hstate *h, struct mm_struct *mm,
3572 +- struct vm_area_struct *vma,
3573 +- struct address_space *mapping,
3574 ++u32 hugetlb_fault_mutex_hash(struct hstate *h, struct address_space *mapping,
3575 + pgoff_t idx, unsigned long address)
3576 + {
3577 + return 0;
3578 +@@ -3885,7 +3876,7 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
3579 + * get spurious allocation failures if two CPUs race to instantiate
3580 + * the same page in the page cache.
3581 + */
3582 +- hash = hugetlb_fault_mutex_hash(h, mm, vma, mapping, idx, address);
3583 ++ hash = hugetlb_fault_mutex_hash(h, mapping, idx, address);
3584 + mutex_lock(&hugetlb_fault_mutex_table[hash]);
3585 +
3586 + entry = huge_ptep_get(ptep);
3587 +diff --git a/net/mac80211/mlme.c b/net/mac80211/mlme.c
3588 +index 6e0aa296f134..d787717140e5 100644
3589 +--- a/net/mac80211/mlme.c
3590 ++++ b/net/mac80211/mlme.c
3591 +@@ -1072,9 +1072,6 @@ static void ieee80211_chswitch_work(struct work_struct *work)
3592 + goto out;
3593 + }
3594 +
3595 +- /* XXX: shouldn't really modify cfg80211-owned data! */
3596 +- ifmgd->associated->channel = sdata->csa_chandef.chan;
3597 +-
3598 + ifmgd->csa_waiting_bcn = true;
3599 +
3600 + ieee80211_sta_reset_beacon_monitor(sdata);
3601 +diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c
3602 +index 09a353c6373a..d6e629315771 100644
3603 +--- a/net/wireless/nl80211.c
3604 ++++ b/net/wireless/nl80211.c
3605 +@@ -14014,6 +14014,11 @@ void cfg80211_ch_switch_notify(struct net_device *dev,
3606 +
3607 + wdev->chandef = *chandef;
3608 + wdev->preset_chandef = *chandef;
3609 ++
3610 ++ if (wdev->iftype == NL80211_IFTYPE_STATION &&
3611 ++ !WARN_ON(!wdev->current_bss))
3612 ++ wdev->current_bss->pub.channel = chandef->chan;
3613 ++
3614 + nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL,
3615 + NL80211_CMD_CH_SWITCH_NOTIFY, 0);
3616 + }
3617 +diff --git a/sound/soc/codecs/hdmi-codec.c b/sound/soc/codecs/hdmi-codec.c
3618 +index 90b5948e0ff3..cba5b5a29da0 100644
3619 +--- a/sound/soc/codecs/hdmi-codec.c
3620 ++++ b/sound/soc/codecs/hdmi-codec.c
3621 +@@ -137,8 +137,12 @@ static int hdmi_codec_startup(struct snd_pcm_substream *substream,
3622 + if (!ret) {
3623 + ret = snd_pcm_hw_constraint_eld(substream->runtime,
3624 + hcp->eld);
3625 +- if (ret)
3626 ++ if (ret) {
3627 ++ mutex_lock(&hcp->current_stream_lock);
3628 ++ hcp->current_stream = NULL;
3629 ++ mutex_unlock(&hcp->current_stream_lock);
3630 + return ret;
3631 ++ }
3632 + }
3633 + }
3634 + return 0;
3635 +diff --git a/sound/soc/davinci/davinci-mcasp.c b/sound/soc/davinci/davinci-mcasp.c
3636 +index 3c5a9804d3f5..5a0b17ebfc02 100644
3637 +--- a/sound/soc/davinci/davinci-mcasp.c
3638 ++++ b/sound/soc/davinci/davinci-mcasp.c
3639 +@@ -43,6 +43,7 @@
3640 +
3641 + #define MCASP_MAX_AFIFO_DEPTH 64
3642 +
3643 ++#ifdef CONFIG_PM
3644 + static u32 context_regs[] = {
3645 + DAVINCI_MCASP_TXFMCTL_REG,
3646 + DAVINCI_MCASP_RXFMCTL_REG,
3647 +@@ -65,6 +66,7 @@ struct davinci_mcasp_context {
3648 + u32 *xrsr_regs; /* for serializer configuration */
3649 + bool pm_state;
3650 + };
3651 ++#endif
3652 +
3653 + struct davinci_mcasp_ruledata {
3654 + struct davinci_mcasp *mcasp;
3655 +diff --git a/sound/soc/fsl/Kconfig b/sound/soc/fsl/Kconfig
3656 +index a732b3a065c9..8a2873a7899a 100644
3657 +--- a/sound/soc/fsl/Kconfig
3658 ++++ b/sound/soc/fsl/Kconfig
3659 +@@ -172,16 +172,17 @@ config SND_MPC52xx_SOC_EFIKA
3660 +
3661 + endif # SND_POWERPC_SOC
3662 +
3663 ++config SND_SOC_IMX_PCM_FIQ
3664 ++ tristate
3665 ++ default y if SND_SOC_IMX_SSI=y && (SND_SOC_FSL_SSI=m || SND_SOC_FSL_SPDIF=m) && (MXC_TZIC || MXC_AVIC)
3666 ++ select FIQ
3667 ++
3668 + if SND_IMX_SOC
3669 +
3670 + config SND_SOC_IMX_SSI
3671 + tristate
3672 + select SND_SOC_FSL_UTILS
3673 +
3674 +-config SND_SOC_IMX_PCM_FIQ
3675 +- tristate
3676 +- select FIQ
3677 +-
3678 + comment "SoC Audio support for Freescale i.MX boards:"
3679 +
3680 + config SND_MXC_SOC_WM1133_EV1
3681 +diff --git a/sound/soc/fsl/eukrea-tlv320.c b/sound/soc/fsl/eukrea-tlv320.c
3682 +index 883087f2b092..38132143b7d5 100644
3683 +--- a/sound/soc/fsl/eukrea-tlv320.c
3684 ++++ b/sound/soc/fsl/eukrea-tlv320.c
3685 +@@ -119,13 +119,13 @@ static int eukrea_tlv320_probe(struct platform_device *pdev)
3686 + if (ret) {
3687 + dev_err(&pdev->dev,
3688 + "fsl,mux-int-port node missing or invalid.\n");
3689 +- return ret;
3690 ++ goto err;
3691 + }
3692 + ret = of_property_read_u32(np, "fsl,mux-ext-port", &ext_port);
3693 + if (ret) {
3694 + dev_err(&pdev->dev,
3695 + "fsl,mux-ext-port node missing or invalid.\n");
3696 +- return ret;
3697 ++ goto err;
3698 + }
3699 +
3700 + /*
3701 +diff --git a/sound/soc/fsl/fsl_sai.c b/sound/soc/fsl/fsl_sai.c
3702 +index 9fadf7e31c5f..cb43f57f978b 100644
3703 +--- a/sound/soc/fsl/fsl_sai.c
3704 ++++ b/sound/soc/fsl/fsl_sai.c
3705 +@@ -274,12 +274,14 @@ static int fsl_sai_set_dai_fmt_tr(struct snd_soc_dai *cpu_dai,
3706 + case SND_SOC_DAIFMT_CBS_CFS:
3707 + val_cr2 |= FSL_SAI_CR2_BCD_MSTR;
3708 + val_cr4 |= FSL_SAI_CR4_FSD_MSTR;
3709 ++ sai->is_slave_mode = false;
3710 + break;
3711 + case SND_SOC_DAIFMT_CBM_CFM:
3712 + sai->is_slave_mode = true;
3713 + break;
3714 + case SND_SOC_DAIFMT_CBS_CFM:
3715 + val_cr2 |= FSL_SAI_CR2_BCD_MSTR;
3716 ++ sai->is_slave_mode = false;
3717 + break;
3718 + case SND_SOC_DAIFMT_CBM_CFS:
3719 + val_cr4 |= FSL_SAI_CR4_FSD_MSTR;
3720 +diff --git a/sound/soc/fsl/fsl_utils.c b/sound/soc/fsl/fsl_utils.c
3721 +index b9e42b503a37..4f8bdb7650e8 100644
3722 +--- a/sound/soc/fsl/fsl_utils.c
3723 ++++ b/sound/soc/fsl/fsl_utils.c
3724 +@@ -75,6 +75,7 @@ int fsl_asoc_get_dma_channel(struct device_node *ssi_np,
3725 + iprop = of_get_property(dma_np, "cell-index", NULL);
3726 + if (!iprop) {
3727 + of_node_put(dma_np);
3728 ++ of_node_put(dma_channel_np);
3729 + return -EINVAL;
3730 + }
3731 + *dma_id = be32_to_cpup(iprop);
3732 +diff --git a/tools/include/linux/bitops.h b/tools/include/linux/bitops.h
3733 +index fc446343ff41..7e3b87a77334 100644
3734 +--- a/tools/include/linux/bitops.h
3735 ++++ b/tools/include/linux/bitops.h
3736 +@@ -3,8 +3,6 @@
3737 +
3738 + #include <asm/types.h>
3739 + #include <linux/kernel.h>
3740 +-#include <linux/compiler.h>
3741 +-
3742 + #ifndef __WORDSIZE
3743 + #define __WORDSIZE (__SIZEOF_LONG__ * 8)
3744 + #endif
3745 +@@ -12,10 +10,9 @@
3746 + #ifndef BITS_PER_LONG
3747 + # define BITS_PER_LONG __WORDSIZE
3748 + #endif
3749 ++#include <linux/bits.h>
3750 ++#include <linux/compiler.h>
3751 +
3752 +-#define BIT_MASK(nr) (1UL << ((nr) % BITS_PER_LONG))
3753 +-#define BIT_WORD(nr) ((nr) / BITS_PER_LONG)
3754 +-#define BITS_PER_BYTE 8
3755 + #define BITS_TO_LONGS(nr) DIV_ROUND_UP(nr, BITS_PER_BYTE * sizeof(long))
3756 + #define BITS_TO_U64(nr) DIV_ROUND_UP(nr, BITS_PER_BYTE * sizeof(u64))
3757 + #define BITS_TO_U32(nr) DIV_ROUND_UP(nr, BITS_PER_BYTE * sizeof(u32))
3758 +diff --git a/tools/include/linux/bits.h b/tools/include/linux/bits.h
3759 +new file mode 100644
3760 +index 000000000000..2b7b532c1d51
3761 +--- /dev/null
3762 ++++ b/tools/include/linux/bits.h
3763 +@@ -0,0 +1,26 @@
3764 ++/* SPDX-License-Identifier: GPL-2.0 */
3765 ++#ifndef __LINUX_BITS_H
3766 ++#define __LINUX_BITS_H
3767 ++#include <asm/bitsperlong.h>
3768 ++
3769 ++#define BIT(nr) (1UL << (nr))
3770 ++#define BIT_ULL(nr) (1ULL << (nr))
3771 ++#define BIT_MASK(nr) (1UL << ((nr) % BITS_PER_LONG))
3772 ++#define BIT_WORD(nr) ((nr) / BITS_PER_LONG)
3773 ++#define BIT_ULL_MASK(nr) (1ULL << ((nr) % BITS_PER_LONG_LONG))
3774 ++#define BIT_ULL_WORD(nr) ((nr) / BITS_PER_LONG_LONG)
3775 ++#define BITS_PER_BYTE 8
3776 ++
3777 ++/*
3778 ++ * Create a contiguous bitmask starting at bit position @l and ending at
3779 ++ * position @h. For example
3780 ++ * GENMASK_ULL(39, 21) gives us the 64bit vector 0x000000ffffe00000.
3781 ++ */
3782 ++#define GENMASK(h, l) \
3783 ++ (((~0UL) - (1UL << (l)) + 1) & (~0UL >> (BITS_PER_LONG - 1 - (h))))
3784 ++
3785 ++#define GENMASK_ULL(h, l) \
3786 ++ (((~0ULL) - (1ULL << (l)) + 1) & \
3787 ++ (~0ULL >> (BITS_PER_LONG_LONG - 1 - (h))))
3788 ++
3789 ++#endif /* __LINUX_BITS_H */
3790 +diff --git a/tools/perf/check-headers.sh b/tools/perf/check-headers.sh
3791 +index 83fe2202382e..ff38fc63bceb 100755
3792 +--- a/tools/perf/check-headers.sh
3793 ++++ b/tools/perf/check-headers.sh
3794 +@@ -4,6 +4,7 @@ HEADERS='
3795 + include/uapi/linux/fcntl.h
3796 + include/uapi/linux/perf_event.h
3797 + include/uapi/linux/stat.h
3798 ++include/linux/bits.h
3799 + include/linux/hash.h
3800 + include/uapi/linux/hw_breakpoint.h
3801 + arch/x86/include/asm/disabled-features.h
3802 +diff --git a/tools/perf/util/util.h b/tools/perf/util/util.h
3803 +index e72d370889f8..8b39e8086c2d 100644
3804 +--- a/tools/perf/util/util.h
3805 ++++ b/tools/perf/util/util.h
3806 +@@ -74,7 +74,6 @@
3807 + #include <sys/ttydefaults.h>
3808 + #include <api/fs/tracing_path.h>
3809 + #include <termios.h>
3810 +-#include <linux/bitops.h>
3811 + #include <termios.h>
3812 + #include "strlist.h"
3813 +