Gentoo Archives: gentoo-commits

From: Thomas Deutschmann <whissi@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/linux-patches:4.14 commit in: /
Date: Sun, 01 Dec 2019 14:08:44
Message-Id: 1575209299.b2b0eeb65d78aca5c04e40e87175b97bd02e67d8.whissi@gentoo
1 commit: b2b0eeb65d78aca5c04e40e87175b97bd02e67d8
2 Author: Thomas Deutschmann <whissi <AT> whissi <DOT> de>
3 AuthorDate: Sun Dec 1 14:08:19 2019 +0000
4 Commit: Thomas Deutschmann <whissi <AT> gentoo <DOT> org>
5 CommitDate: Sun Dec 1 14:08:19 2019 +0000
6 URL: https://gitweb.gentoo.org/proj/linux-patches.git/commit/?id=b2b0eeb6
7
8 Linux patch 4.14.157
9
10 Signed-off-by: Thomas Deutschmann <whissi <AT> whissi.de>
11
12 1156_linux-4.14.157.patch | 7579 +++++++++++++++++++++++++++++++++++++++++++++
13 1 file changed, 7579 insertions(+)
14
15 diff --git a/1156_linux-4.14.157.patch b/1156_linux-4.14.157.patch
16 new file mode 100644
17 index 0000000..ec8cede
18 --- /dev/null
19 +++ b/1156_linux-4.14.157.patch
20 @@ -0,0 +1,7579 @@
21 +diff --git a/Documentation/admin-guide/hw-vuln/mds.rst b/Documentation/admin-guide/hw-vuln/mds.rst
22 +index e3a796c0d3a2..2d19c9f4c1fe 100644
23 +--- a/Documentation/admin-guide/hw-vuln/mds.rst
24 ++++ b/Documentation/admin-guide/hw-vuln/mds.rst
25 +@@ -265,8 +265,11 @@ time with the option "mds=". The valid arguments for this option are:
26 +
27 + ============ =============================================================
28 +
29 +-Not specifying this option is equivalent to "mds=full".
30 +-
31 ++Not specifying this option is equivalent to "mds=full". For processors
32 ++that are affected by both TAA (TSX Asynchronous Abort) and MDS,
33 ++specifying just "mds=off" without an accompanying "tsx_async_abort=off"
34 ++will have no effect as the same mitigation is used for both
35 ++vulnerabilities.
36 +
37 + Mitigation selection guide
38 + --------------------------
39 +diff --git a/Documentation/admin-guide/hw-vuln/tsx_async_abort.rst b/Documentation/admin-guide/hw-vuln/tsx_async_abort.rst
40 +index fddbd7579c53..af6865b822d2 100644
41 +--- a/Documentation/admin-guide/hw-vuln/tsx_async_abort.rst
42 ++++ b/Documentation/admin-guide/hw-vuln/tsx_async_abort.rst
43 +@@ -174,7 +174,10 @@ the option "tsx_async_abort=". The valid arguments for this option are:
44 + CPU is not vulnerable to cross-thread TAA attacks.
45 + ============ =============================================================
46 +
47 +-Not specifying this option is equivalent to "tsx_async_abort=full".
48 ++Not specifying this option is equivalent to "tsx_async_abort=full". For
49 ++processors that are affected by both TAA and MDS, specifying just
50 ++"tsx_async_abort=off" without an accompanying "mds=off" will have no
51 ++effect as the same mitigation is used for both vulnerabilities.
52 +
53 + The kernel command line also allows to control the TSX feature using the
54 + parameter "tsx=" on CPUs which support TSX control. MSR_IA32_TSX_CTRL is used
55 +diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt
56 +index 05596e05bc71..b0da6050a254 100644
57 +--- a/Documentation/admin-guide/kernel-parameters.txt
58 ++++ b/Documentation/admin-guide/kernel-parameters.txt
59 +@@ -2254,6 +2254,12 @@
60 + SMT on vulnerable CPUs
61 + off - Unconditionally disable MDS mitigation
62 +
63 ++ On TAA-affected machines, mds=off can be prevented by
64 ++ an active TAA mitigation as both vulnerabilities are
65 ++ mitigated with the same mechanism so in order to disable
66 ++ this mitigation, you need to specify tsx_async_abort=off
67 ++ too.
68 ++
69 + Not specifying this option is equivalent to
70 + mds=full.
71 +
72 +@@ -4588,6 +4594,11 @@
73 + vulnerable to cross-thread TAA attacks.
74 + off - Unconditionally disable TAA mitigation
75 +
76 ++ On MDS-affected machines, tsx_async_abort=off can be
77 ++ prevented by an active MDS mitigation as both vulnerabilities
78 ++ are mitigated with the same mechanism so in order to disable
79 ++ this mitigation, you need to specify mds=off too.
80 ++
81 + Not specifying this option is equivalent to
82 + tsx_async_abort=full. On CPUs which are MDS affected
83 + and deploy MDS mitigation, TAA mitigation is not
84 +diff --git a/Makefile b/Makefile
85 +index b1db48ad832e..dad90f53faeb 100644
86 +--- a/Makefile
87 ++++ b/Makefile
88 +@@ -1,7 +1,7 @@
89 + # SPDX-License-Identifier: GPL-2.0
90 + VERSION = 4
91 + PATCHLEVEL = 14
92 +-SUBLEVEL = 156
93 ++SUBLEVEL = 157
94 + EXTRAVERSION =
95 + NAME = Petit Gorille
96 +
97 +diff --git a/arch/arc/kernel/perf_event.c b/arch/arc/kernel/perf_event.c
98 +index 2ce24e74f879..a509b77ef80d 100644
99 +--- a/arch/arc/kernel/perf_event.c
100 ++++ b/arch/arc/kernel/perf_event.c
101 +@@ -488,8 +488,8 @@ static int arc_pmu_device_probe(struct platform_device *pdev)
102 + /* loop thru all available h/w condition indexes */
103 + for (j = 0; j < cc_bcr.c; j++) {
104 + write_aux_reg(ARC_REG_CC_INDEX, j);
105 +- cc_name.indiv.word0 = read_aux_reg(ARC_REG_CC_NAME0);
106 +- cc_name.indiv.word1 = read_aux_reg(ARC_REG_CC_NAME1);
107 ++ cc_name.indiv.word0 = le32_to_cpu(read_aux_reg(ARC_REG_CC_NAME0));
108 ++ cc_name.indiv.word1 = le32_to_cpu(read_aux_reg(ARC_REG_CC_NAME1));
109 +
110 + /* See if it has been mapped to a perf event_id */
111 + for (i = 0; i < ARRAY_SIZE(arc_pmu_ev_hw_map); i++) {
112 +diff --git a/arch/arm/mm/mmu.c b/arch/arm/mm/mmu.c
113 +index 70e560cf8ca0..d8cbe772f690 100644
114 +--- a/arch/arm/mm/mmu.c
115 ++++ b/arch/arm/mm/mmu.c
116 +@@ -1195,6 +1195,9 @@ void __init adjust_lowmem_bounds(void)
117 + phys_addr_t block_start = reg->base;
118 + phys_addr_t block_end = reg->base + reg->size;
119 +
120 ++ if (memblock_is_nomap(reg))
121 ++ continue;
122 ++
123 + if (reg->base < vmalloc_limit) {
124 + if (block_end > lowmem_limit)
125 + /*
126 +diff --git a/arch/arm64/Makefile b/arch/arm64/Makefile
127 +index 0c5f70e6d5cf..8c4bc5a2c61f 100644
128 +--- a/arch/arm64/Makefile
129 ++++ b/arch/arm64/Makefile
130 +@@ -149,6 +149,7 @@ archclean:
131 + $(Q)$(MAKE) $(clean)=$(boot)
132 + $(Q)$(MAKE) $(clean)=$(boot)/dts
133 +
134 ++ifeq ($(KBUILD_EXTMOD),)
135 + # We need to generate vdso-offsets.h before compiling certain files in kernel/.
136 + # In order to do that, we should use the archprepare target, but we can't since
137 + # asm-offsets.h is included in some files used to generate vdso-offsets.h, and
138 +@@ -158,6 +159,7 @@ archclean:
139 + prepare: vdso_prepare
140 + vdso_prepare: prepare0
141 + $(Q)$(MAKE) $(build)=arch/arm64/kernel/vdso include/generated/vdso-offsets.h
142 ++endif
143 +
144 + define archhelp
145 + echo '* Image.gz - Compressed kernel image (arch/$(ARCH)/boot/Image.gz)'
146 +diff --git a/arch/arm64/include/asm/string.h b/arch/arm64/include/asm/string.h
147 +index dd95d33a5bd5..03a6c256b7ec 100644
148 +--- a/arch/arm64/include/asm/string.h
149 ++++ b/arch/arm64/include/asm/string.h
150 +@@ -16,6 +16,7 @@
151 + #ifndef __ASM_STRING_H
152 + #define __ASM_STRING_H
153 +
154 ++#ifndef CONFIG_KASAN
155 + #define __HAVE_ARCH_STRRCHR
156 + extern char *strrchr(const char *, int c);
157 +
158 +@@ -34,6 +35,13 @@ extern __kernel_size_t strlen(const char *);
159 + #define __HAVE_ARCH_STRNLEN
160 + extern __kernel_size_t strnlen(const char *, __kernel_size_t);
161 +
162 ++#define __HAVE_ARCH_MEMCMP
163 ++extern int memcmp(const void *, const void *, size_t);
164 ++
165 ++#define __HAVE_ARCH_MEMCHR
166 ++extern void *memchr(const void *, int, __kernel_size_t);
167 ++#endif
168 ++
169 + #define __HAVE_ARCH_MEMCPY
170 + extern void *memcpy(void *, const void *, __kernel_size_t);
171 + extern void *__memcpy(void *, const void *, __kernel_size_t);
172 +@@ -42,16 +50,10 @@ extern void *__memcpy(void *, const void *, __kernel_size_t);
173 + extern void *memmove(void *, const void *, __kernel_size_t);
174 + extern void *__memmove(void *, const void *, __kernel_size_t);
175 +
176 +-#define __HAVE_ARCH_MEMCHR
177 +-extern void *memchr(const void *, int, __kernel_size_t);
178 +-
179 + #define __HAVE_ARCH_MEMSET
180 + extern void *memset(void *, int, __kernel_size_t);
181 + extern void *__memset(void *, int, __kernel_size_t);
182 +
183 +-#define __HAVE_ARCH_MEMCMP
184 +-extern int memcmp(const void *, const void *, size_t);
185 +-
186 + #ifdef CONFIG_ARCH_HAS_UACCESS_FLUSHCACHE
187 + #define __HAVE_ARCH_MEMCPY_FLUSHCACHE
188 + void memcpy_flushcache(void *dst, const void *src, size_t cnt);
189 +diff --git a/arch/arm64/kernel/arm64ksyms.c b/arch/arm64/kernel/arm64ksyms.c
190 +index 66be504edb6c..9eedf839e739 100644
191 +--- a/arch/arm64/kernel/arm64ksyms.c
192 ++++ b/arch/arm64/kernel/arm64ksyms.c
193 +@@ -44,20 +44,23 @@ EXPORT_SYMBOL(__arch_copy_in_user);
194 + EXPORT_SYMBOL(memstart_addr);
195 +
196 + /* string / mem functions */
197 ++#ifndef CONFIG_KASAN
198 + EXPORT_SYMBOL(strchr);
199 + EXPORT_SYMBOL(strrchr);
200 + EXPORT_SYMBOL(strcmp);
201 + EXPORT_SYMBOL(strncmp);
202 + EXPORT_SYMBOL(strlen);
203 + EXPORT_SYMBOL(strnlen);
204 ++EXPORT_SYMBOL(memcmp);
205 ++EXPORT_SYMBOL(memchr);
206 ++#endif
207 ++
208 + EXPORT_SYMBOL(memset);
209 + EXPORT_SYMBOL(memcpy);
210 + EXPORT_SYMBOL(memmove);
211 + EXPORT_SYMBOL(__memset);
212 + EXPORT_SYMBOL(__memcpy);
213 + EXPORT_SYMBOL(__memmove);
214 +-EXPORT_SYMBOL(memchr);
215 +-EXPORT_SYMBOL(memcmp);
216 +
217 + /* atomic bitops */
218 + EXPORT_SYMBOL(set_bit);
219 +diff --git a/arch/arm64/kernel/traps.c b/arch/arm64/kernel/traps.c
220 +index a4e49e947684..5ae9c86c30d1 100644
221 +--- a/arch/arm64/kernel/traps.c
222 ++++ b/arch/arm64/kernel/traps.c
223 +@@ -648,7 +648,6 @@ asmlinkage void bad_mode(struct pt_regs *regs, int reason, unsigned int esr)
224 + handler[reason], smp_processor_id(), esr,
225 + esr_get_class_string(esr));
226 +
227 +- die("Oops - bad mode", regs, 0);
228 + local_irq_disable();
229 + panic("bad mode");
230 + }
231 +diff --git a/arch/arm64/lib/memchr.S b/arch/arm64/lib/memchr.S
232 +index 4444c1d25f4b..0f164a4baf52 100644
233 +--- a/arch/arm64/lib/memchr.S
234 ++++ b/arch/arm64/lib/memchr.S
235 +@@ -30,7 +30,7 @@
236 + * Returns:
237 + * x0 - address of first occurrence of 'c' or 0
238 + */
239 +-ENTRY(memchr)
240 ++WEAK(memchr)
241 + and w1, w1, #0xff
242 + 1: subs x2, x2, #1
243 + b.mi 2f
244 +diff --git a/arch/arm64/lib/memcmp.S b/arch/arm64/lib/memcmp.S
245 +index 2a4e239bd17a..fb295f52e9f8 100644
246 +--- a/arch/arm64/lib/memcmp.S
247 ++++ b/arch/arm64/lib/memcmp.S
248 +@@ -58,7 +58,7 @@ pos .req x11
249 + limit_wd .req x12
250 + mask .req x13
251 +
252 +-ENTRY(memcmp)
253 ++WEAK(memcmp)
254 + cbz limit, .Lret0
255 + eor tmp1, src1, src2
256 + tst tmp1, #7
257 +diff --git a/arch/arm64/lib/strchr.S b/arch/arm64/lib/strchr.S
258 +index dae0cf5591f9..7c83091d1bcd 100644
259 +--- a/arch/arm64/lib/strchr.S
260 ++++ b/arch/arm64/lib/strchr.S
261 +@@ -29,7 +29,7 @@
262 + * Returns:
263 + * x0 - address of first occurrence of 'c' or 0
264 + */
265 +-ENTRY(strchr)
266 ++WEAK(strchr)
267 + and w1, w1, #0xff
268 + 1: ldrb w2, [x0], #1
269 + cmp w2, w1
270 +diff --git a/arch/arm64/lib/strcmp.S b/arch/arm64/lib/strcmp.S
271 +index 471fe61760ef..7d5d15398bfb 100644
272 +--- a/arch/arm64/lib/strcmp.S
273 ++++ b/arch/arm64/lib/strcmp.S
274 +@@ -60,7 +60,7 @@ tmp3 .req x9
275 + zeroones .req x10
276 + pos .req x11
277 +
278 +-ENTRY(strcmp)
279 ++WEAK(strcmp)
280 + eor tmp1, src1, src2
281 + mov zeroones, #REP8_01
282 + tst tmp1, #7
283 +diff --git a/arch/arm64/lib/strlen.S b/arch/arm64/lib/strlen.S
284 +index 55ccc8e24c08..8e0b14205dcb 100644
285 +--- a/arch/arm64/lib/strlen.S
286 ++++ b/arch/arm64/lib/strlen.S
287 +@@ -56,7 +56,7 @@ pos .req x12
288 + #define REP8_7f 0x7f7f7f7f7f7f7f7f
289 + #define REP8_80 0x8080808080808080
290 +
291 +-ENTRY(strlen)
292 ++WEAK(strlen)
293 + mov zeroones, #REP8_01
294 + bic src, srcin, #15
295 + ands tmp1, srcin, #15
296 +diff --git a/arch/arm64/lib/strncmp.S b/arch/arm64/lib/strncmp.S
297 +index e267044761c6..66bd145935d9 100644
298 +--- a/arch/arm64/lib/strncmp.S
299 ++++ b/arch/arm64/lib/strncmp.S
300 +@@ -64,7 +64,7 @@ limit_wd .req x13
301 + mask .req x14
302 + endloop .req x15
303 +
304 +-ENTRY(strncmp)
305 ++WEAK(strncmp)
306 + cbz limit, .Lret0
307 + eor tmp1, src1, src2
308 + mov zeroones, #REP8_01
309 +diff --git a/arch/arm64/lib/strnlen.S b/arch/arm64/lib/strnlen.S
310 +index eae38da6e0bb..355be04441fe 100644
311 +--- a/arch/arm64/lib/strnlen.S
312 ++++ b/arch/arm64/lib/strnlen.S
313 +@@ -59,7 +59,7 @@ limit_wd .req x14
314 + #define REP8_7f 0x7f7f7f7f7f7f7f7f
315 + #define REP8_80 0x8080808080808080
316 +
317 +-ENTRY(strnlen)
318 ++WEAK(strnlen)
319 + cbz limit, .Lhit_limit
320 + mov zeroones, #REP8_01
321 + bic src, srcin, #15
322 +diff --git a/arch/arm64/lib/strrchr.S b/arch/arm64/lib/strrchr.S
323 +index 61eabd9a289a..f3b9f8e2917c 100644
324 +--- a/arch/arm64/lib/strrchr.S
325 ++++ b/arch/arm64/lib/strrchr.S
326 +@@ -29,7 +29,7 @@
327 + * Returns:
328 + * x0 - address of last occurrence of 'c' or 0
329 + */
330 +-ENTRY(strrchr)
331 ++WEAK(strrchr)
332 + mov x3, #0
333 + and w1, w1, #0xff
334 + 1: ldrb w2, [x0], #1
335 +diff --git a/arch/m68k/kernel/uboot.c b/arch/m68k/kernel/uboot.c
336 +index b29c3b241e1b..107082877064 100644
337 +--- a/arch/m68k/kernel/uboot.c
338 ++++ b/arch/m68k/kernel/uboot.c
339 +@@ -102,5 +102,5 @@ __init void process_uboot_commandline(char *commandp, int size)
340 + }
341 +
342 + parse_uboot_commandline(commandp, len);
343 +- commandp[size - 1] = 0;
344 ++ commandp[len - 1] = 0;
345 + }
346 +diff --git a/arch/powerpc/boot/Makefile b/arch/powerpc/boot/Makefile
347 +index e2a5a932c24a..5807c9d8e56d 100644
348 +--- a/arch/powerpc/boot/Makefile
349 ++++ b/arch/powerpc/boot/Makefile
350 +@@ -24,8 +24,8 @@ compress-$(CONFIG_KERNEL_GZIP) := CONFIG_KERNEL_GZIP
351 + compress-$(CONFIG_KERNEL_XZ) := CONFIG_KERNEL_XZ
352 +
353 + BOOTCFLAGS := -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs \
354 +- -fno-strict-aliasing -Os -msoft-float -pipe \
355 +- -fomit-frame-pointer -fno-builtin -fPIC -nostdinc \
356 ++ -fno-strict-aliasing -Os -msoft-float -mno-altivec -mno-vsx \
357 ++ -pipe -fomit-frame-pointer -fno-builtin -fPIC -nostdinc \
358 + -D$(compress-y)
359 +
360 + BOOTCC := $(CC)
361 +diff --git a/arch/powerpc/include/asm/asm-prototypes.h b/arch/powerpc/include/asm/asm-prototypes.h
362 +index ba4c75062d49..2d4444981c2c 100644
363 +--- a/arch/powerpc/include/asm/asm-prototypes.h
364 ++++ b/arch/powerpc/include/asm/asm-prototypes.h
365 +@@ -129,7 +129,10 @@ unsigned long prepare_ftrace_return(unsigned long parent, unsigned long ip);
366 + /* Patch sites */
367 + extern s32 patch__call_flush_count_cache;
368 + extern s32 patch__flush_count_cache_return;
369 ++extern s32 patch__flush_link_stack_return;
370 ++extern s32 patch__call_kvm_flush_link_stack;
371 +
372 + extern long flush_count_cache;
373 ++extern long kvm_flush_link_stack;
374 +
375 + #endif /* _ASM_POWERPC_ASM_PROTOTYPES_H */
376 +diff --git a/arch/powerpc/include/asm/security_features.h b/arch/powerpc/include/asm/security_features.h
377 +index 759597bf0fd8..ccf44c135389 100644
378 +--- a/arch/powerpc/include/asm/security_features.h
379 ++++ b/arch/powerpc/include/asm/security_features.h
380 +@@ -81,6 +81,9 @@ static inline bool security_ftr_enabled(unsigned long feature)
381 + // Software required to flush count cache on context switch
382 + #define SEC_FTR_FLUSH_COUNT_CACHE 0x0000000000000400ull
383 +
384 ++// Software required to flush link stack on context switch
385 ++#define SEC_FTR_FLUSH_LINK_STACK 0x0000000000001000ull
386 ++
387 +
388 + // Features enabled by default
389 + #define SEC_FTR_DEFAULT \
390 +diff --git a/arch/powerpc/kernel/eeh_pe.c b/arch/powerpc/kernel/eeh_pe.c
391 +index 8545a9523b9b..7339ca4fdc19 100644
392 +--- a/arch/powerpc/kernel/eeh_pe.c
393 ++++ b/arch/powerpc/kernel/eeh_pe.c
394 +@@ -381,7 +381,7 @@ int eeh_add_to_parent_pe(struct eeh_dev *edev)
395 + while (parent) {
396 + if (!(parent->type & EEH_PE_INVALID))
397 + break;
398 +- parent->type &= ~(EEH_PE_INVALID | EEH_PE_KEEP);
399 ++ parent->type &= ~EEH_PE_INVALID;
400 + parent = parent->parent;
401 + }
402 +
403 +diff --git a/arch/powerpc/kernel/entry_64.S b/arch/powerpc/kernel/entry_64.S
404 +index 12395895b9aa..02a0bf52aec0 100644
405 +--- a/arch/powerpc/kernel/entry_64.S
406 ++++ b/arch/powerpc/kernel/entry_64.S
407 +@@ -524,6 +524,7 @@ flush_count_cache:
408 + /* Save LR into r9 */
409 + mflr r9
410 +
411 ++ // Flush the link stack
412 + .rept 64
413 + bl .+4
414 + .endr
415 +@@ -533,6 +534,11 @@ flush_count_cache:
416 + .balign 32
417 + /* Restore LR */
418 + 1: mtlr r9
419 ++
420 ++ // If we're just flushing the link stack, return here
421 ++3: nop
422 ++ patch_site 3b patch__flush_link_stack_return
423 ++
424 + li r9,0x7fff
425 + mtctr r9
426 +
427 +diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
428 +index 5e5da2073fdf..ba0d4f9a99ba 100644
429 +--- a/arch/powerpc/kernel/process.c
430 ++++ b/arch/powerpc/kernel/process.c
431 +@@ -567,12 +567,11 @@ void flush_all_to_thread(struct task_struct *tsk)
432 + if (tsk->thread.regs) {
433 + preempt_disable();
434 + BUG_ON(tsk != current);
435 +- save_all(tsk);
436 +-
437 + #ifdef CONFIG_SPE
438 + if (tsk->thread.regs->msr & MSR_SPE)
439 + tsk->thread.spefscr = mfspr(SPRN_SPEFSCR);
440 + #endif
441 ++ save_all(tsk);
442 +
443 + preempt_enable();
444 + }
445 +diff --git a/arch/powerpc/kernel/security.c b/arch/powerpc/kernel/security.c
446 +index 68d4ec373cfc..f5d6541bf8c2 100644
447 +--- a/arch/powerpc/kernel/security.c
448 ++++ b/arch/powerpc/kernel/security.c
449 +@@ -24,11 +24,12 @@ enum count_cache_flush_type {
450 + COUNT_CACHE_FLUSH_HW = 0x4,
451 + };
452 + static enum count_cache_flush_type count_cache_flush_type = COUNT_CACHE_FLUSH_NONE;
453 ++static bool link_stack_flush_enabled;
454 +
455 + bool barrier_nospec_enabled;
456 + static bool no_nospec;
457 + static bool btb_flush_enabled;
458 +-#ifdef CONFIG_PPC_FSL_BOOK3E
459 ++#if defined(CONFIG_PPC_FSL_BOOK3E) || defined(CONFIG_PPC_BOOK3S_64)
460 + static bool no_spectrev2;
461 + #endif
462 +
463 +@@ -106,7 +107,7 @@ static __init int barrier_nospec_debugfs_init(void)
464 + device_initcall(barrier_nospec_debugfs_init);
465 + #endif /* CONFIG_DEBUG_FS */
466 +
467 +-#ifdef CONFIG_PPC_FSL_BOOK3E
468 ++#if defined(CONFIG_PPC_FSL_BOOK3E) || defined(CONFIG_PPC_BOOK3S_64)
469 + static int __init handle_nospectre_v2(char *p)
470 + {
471 + no_spectrev2 = true;
472 +@@ -114,6 +115,9 @@ static int __init handle_nospectre_v2(char *p)
473 + return 0;
474 + }
475 + early_param("nospectre_v2", handle_nospectre_v2);
476 ++#endif /* CONFIG_PPC_FSL_BOOK3E || CONFIG_PPC_BOOK3S_64 */
477 ++
478 ++#ifdef CONFIG_PPC_FSL_BOOK3E
479 + void setup_spectre_v2(void)
480 + {
481 + if (no_spectrev2 || cpu_mitigations_off())
482 +@@ -201,11 +205,19 @@ ssize_t cpu_show_spectre_v2(struct device *dev, struct device_attribute *attr, c
483 +
484 + if (ccd)
485 + seq_buf_printf(&s, "Indirect branch cache disabled");
486 ++
487 ++ if (link_stack_flush_enabled)
488 ++ seq_buf_printf(&s, ", Software link stack flush");
489 ++
490 + } else if (count_cache_flush_type != COUNT_CACHE_FLUSH_NONE) {
491 + seq_buf_printf(&s, "Mitigation: Software count cache flush");
492 +
493 + if (count_cache_flush_type == COUNT_CACHE_FLUSH_HW)
494 + seq_buf_printf(&s, " (hardware accelerated)");
495 ++
496 ++ if (link_stack_flush_enabled)
497 ++ seq_buf_printf(&s, ", Software link stack flush");
498 ++
499 + } else if (btb_flush_enabled) {
500 + seq_buf_printf(&s, "Mitigation: Branch predictor state flush");
501 + } else {
502 +@@ -366,18 +378,49 @@ static __init int stf_barrier_debugfs_init(void)
503 + device_initcall(stf_barrier_debugfs_init);
504 + #endif /* CONFIG_DEBUG_FS */
505 +
506 ++static void no_count_cache_flush(void)
507 ++{
508 ++ count_cache_flush_type = COUNT_CACHE_FLUSH_NONE;
509 ++ pr_info("count-cache-flush: software flush disabled.\n");
510 ++}
511 ++
512 + static void toggle_count_cache_flush(bool enable)
513 + {
514 +- if (!enable || !security_ftr_enabled(SEC_FTR_FLUSH_COUNT_CACHE)) {
515 ++ if (!security_ftr_enabled(SEC_FTR_FLUSH_COUNT_CACHE) &&
516 ++ !security_ftr_enabled(SEC_FTR_FLUSH_LINK_STACK))
517 ++ enable = false;
518 ++
519 ++ if (!enable) {
520 + patch_instruction_site(&patch__call_flush_count_cache, PPC_INST_NOP);
521 +- count_cache_flush_type = COUNT_CACHE_FLUSH_NONE;
522 +- pr_info("count-cache-flush: software flush disabled.\n");
523 ++#ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE
524 ++ patch_instruction_site(&patch__call_kvm_flush_link_stack, PPC_INST_NOP);
525 ++#endif
526 ++ pr_info("link-stack-flush: software flush disabled.\n");
527 ++ link_stack_flush_enabled = false;
528 ++ no_count_cache_flush();
529 + return;
530 + }
531 +
532 ++ // This enables the branch from _switch to flush_count_cache
533 + patch_branch_site(&patch__call_flush_count_cache,
534 + (u64)&flush_count_cache, BRANCH_SET_LINK);
535 +
536 ++#ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE
537 ++ // This enables the branch from guest_exit_cont to kvm_flush_link_stack
538 ++ patch_branch_site(&patch__call_kvm_flush_link_stack,
539 ++ (u64)&kvm_flush_link_stack, BRANCH_SET_LINK);
540 ++#endif
541 ++
542 ++ pr_info("link-stack-flush: software flush enabled.\n");
543 ++ link_stack_flush_enabled = true;
544 ++
545 ++ // If we just need to flush the link stack, patch an early return
546 ++ if (!security_ftr_enabled(SEC_FTR_FLUSH_COUNT_CACHE)) {
547 ++ patch_instruction_site(&patch__flush_link_stack_return, PPC_INST_BLR);
548 ++ no_count_cache_flush();
549 ++ return;
550 ++ }
551 ++
552 + if (!security_ftr_enabled(SEC_FTR_BCCTR_FLUSH_ASSIST)) {
553 + count_cache_flush_type = COUNT_CACHE_FLUSH_SW;
554 + pr_info("count-cache-flush: full software flush sequence enabled.\n");
555 +@@ -391,7 +434,26 @@ static void toggle_count_cache_flush(bool enable)
556 +
557 + void setup_count_cache_flush(void)
558 + {
559 +- toggle_count_cache_flush(true);
560 ++ bool enable = true;
561 ++
562 ++ if (no_spectrev2 || cpu_mitigations_off()) {
563 ++ if (security_ftr_enabled(SEC_FTR_BCCTRL_SERIALISED) ||
564 ++ security_ftr_enabled(SEC_FTR_COUNT_CACHE_DISABLED))
565 ++ pr_warn("Spectre v2 mitigations not fully under software control, can't disable\n");
566 ++
567 ++ enable = false;
568 ++ }
569 ++
570 ++ /*
571 ++ * There's no firmware feature flag/hypervisor bit to tell us we need to
572 ++ * flush the link stack on context switch. So we set it here if we see
573 ++ * either of the Spectre v2 mitigations that aim to protect userspace.
574 ++ */
575 ++ if (security_ftr_enabled(SEC_FTR_COUNT_CACHE_DISABLED) ||
576 ++ security_ftr_enabled(SEC_FTR_FLUSH_COUNT_CACHE))
577 ++ security_ftr_set(SEC_FTR_FLUSH_LINK_STACK);
578 ++
579 ++ toggle_count_cache_flush(enable);
580 + }
581 +
582 + #ifdef CONFIG_DEBUG_FS
583 +diff --git a/arch/powerpc/kvm/book3s_hv_rmhandlers.S b/arch/powerpc/kvm/book3s_hv_rmhandlers.S
584 +index 663a398449b7..46ea42f40334 100644
585 +--- a/arch/powerpc/kvm/book3s_hv_rmhandlers.S
586 ++++ b/arch/powerpc/kvm/book3s_hv_rmhandlers.S
587 +@@ -18,6 +18,7 @@
588 + */
589 +
590 + #include <asm/ppc_asm.h>
591 ++#include <asm/code-patching-asm.h>
592 + #include <asm/kvm_asm.h>
593 + #include <asm/reg.h>
594 + #include <asm/mmu.h>
595 +@@ -1445,6 +1446,10 @@ mc_cont:
596 + 1:
597 + #endif /* CONFIG_KVM_XICS */
598 +
599 ++ /* Possibly flush the link stack here. */
600 ++1: nop
601 ++ patch_site 1b patch__call_kvm_flush_link_stack
602 ++
603 + stw r12, STACK_SLOT_TRAP(r1)
604 + mr r3, r12
605 + /* Increment exit count, poke other threads to exit */
606 +@@ -1957,6 +1962,28 @@ END_MMU_FTR_SECTION_IFSET(MMU_FTR_TYPE_RADIX)
607 + mtlr r0
608 + blr
609 +
610 ++.balign 32
611 ++.global kvm_flush_link_stack
612 ++kvm_flush_link_stack:
613 ++ /* Save LR into r0 */
614 ++ mflr r0
615 ++
616 ++ /* Flush the link stack. On Power8 it's up to 32 entries in size. */
617 ++ .rept 32
618 ++ bl .+4
619 ++ .endr
620 ++
621 ++ /* And on Power9 it's up to 64. */
622 ++BEGIN_FTR_SECTION
623 ++ .rept 32
624 ++ bl .+4
625 ++ .endr
626 ++END_FTR_SECTION_IFSET(CPU_FTR_ARCH_300)
627 ++
628 ++ /* Restore LR */
629 ++ mtlr r0
630 ++ blr
631 ++
632 + /*
633 + * Check whether an HDSI is an HPTE not found fault or something else.
634 + * If it is an HPTE not found fault that is due to the guest accessing
635 +diff --git a/arch/powerpc/platforms/ps3/os-area.c b/arch/powerpc/platforms/ps3/os-area.c
636 +index 3db53e8aff92..9b2ef76578f0 100644
637 +--- a/arch/powerpc/platforms/ps3/os-area.c
638 ++++ b/arch/powerpc/platforms/ps3/os-area.c
639 +@@ -664,7 +664,7 @@ static int update_flash_db(void)
640 + db_set_64(db, &os_area_db_id_rtc_diff, saved_params.rtc_diff);
641 +
642 + count = os_area_flash_write(db, sizeof(struct os_area_db), pos);
643 +- if (count < sizeof(struct os_area_db)) {
644 ++ if (count < 0 || count < sizeof(struct os_area_db)) {
645 + pr_debug("%s: os_area_flash_write failed %zd\n", __func__,
646 + count);
647 + error = count < 0 ? count : -EIO;
648 +diff --git a/arch/powerpc/platforms/pseries/hotplug-memory.c b/arch/powerpc/platforms/pseries/hotplug-memory.c
649 +index 93e09f108ca1..99a3cf51c5ba 100644
650 +--- a/arch/powerpc/platforms/pseries/hotplug-memory.c
651 ++++ b/arch/powerpc/platforms/pseries/hotplug-memory.c
652 +@@ -787,7 +787,7 @@ static int dlpar_add_lmb(struct of_drconf_cell *lmb)
653 + nid = memory_add_physaddr_to_nid(lmb->base_addr);
654 +
655 + /* Add the memory */
656 +- rc = add_memory(nid, lmb->base_addr, block_sz);
657 ++ rc = __add_memory(nid, lmb->base_addr, block_sz);
658 + if (rc) {
659 + dlpar_remove_device_tree_lmb(lmb);
660 + return rc;
661 +diff --git a/arch/powerpc/platforms/pseries/lpar.c b/arch/powerpc/platforms/pseries/lpar.c
662 +index eb738ef57792..c0ae3847b8db 100644
663 +--- a/arch/powerpc/platforms/pseries/lpar.c
664 ++++ b/arch/powerpc/platforms/pseries/lpar.c
665 +@@ -48,6 +48,7 @@
666 + #include <asm/kexec.h>
667 + #include <asm/fadump.h>
668 + #include <asm/asm-prototypes.h>
669 ++#include <asm/debugfs.h>
670 +
671 + #include "pseries.h"
672 +
673 +@@ -1036,3 +1037,56 @@ static int __init reserve_vrma_context_id(void)
674 + return 0;
675 + }
676 + machine_device_initcall(pseries, reserve_vrma_context_id);
677 ++
678 ++#ifdef CONFIG_DEBUG_FS
679 ++/* debugfs file interface for vpa data */
680 ++static ssize_t vpa_file_read(struct file *filp, char __user *buf, size_t len,
681 ++ loff_t *pos)
682 ++{
683 ++ int cpu = (long)filp->private_data;
684 ++ struct lppaca *lppaca = &lppaca_of(cpu);
685 ++
686 ++ return simple_read_from_buffer(buf, len, pos, lppaca,
687 ++ sizeof(struct lppaca));
688 ++}
689 ++
690 ++static const struct file_operations vpa_fops = {
691 ++ .open = simple_open,
692 ++ .read = vpa_file_read,
693 ++ .llseek = default_llseek,
694 ++};
695 ++
696 ++static int __init vpa_debugfs_init(void)
697 ++{
698 ++ char name[16];
699 ++ long i;
700 ++ static struct dentry *vpa_dir;
701 ++
702 ++ if (!firmware_has_feature(FW_FEATURE_SPLPAR))
703 ++ return 0;
704 ++
705 ++ vpa_dir = debugfs_create_dir("vpa", powerpc_debugfs_root);
706 ++ if (!vpa_dir) {
707 ++ pr_warn("%s: can't create vpa root dir\n", __func__);
708 ++ return -ENOMEM;
709 ++ }
710 ++
711 ++ /* set up the per-cpu vpa file*/
712 ++ for_each_possible_cpu(i) {
713 ++ struct dentry *d;
714 ++
715 ++ sprintf(name, "cpu-%ld", i);
716 ++
717 ++ d = debugfs_create_file(name, 0400, vpa_dir, (void *)i,
718 ++ &vpa_fops);
719 ++ if (!d) {
720 ++ pr_warn("%s: can't create per-cpu vpa file\n",
721 ++ __func__);
722 ++ return -ENOMEM;
723 ++ }
724 ++ }
725 ++
726 ++ return 0;
727 ++}
728 ++machine_arch_initcall(pseries, vpa_debugfs_init);
729 ++#endif /* CONFIG_DEBUG_FS */
730 +diff --git a/arch/powerpc/xmon/Makefile b/arch/powerpc/xmon/Makefile
731 +index 549e99e71112..ac5ee067aa51 100644
732 +--- a/arch/powerpc/xmon/Makefile
733 ++++ b/arch/powerpc/xmon/Makefile
734 +@@ -13,6 +13,12 @@ UBSAN_SANITIZE := n
735 + ORIG_CFLAGS := $(KBUILD_CFLAGS)
736 + KBUILD_CFLAGS = $(subst -mno-sched-epilog,,$(subst $(CC_FLAGS_FTRACE),,$(ORIG_CFLAGS)))
737 +
738 ++ifdef CONFIG_CC_IS_CLANG
739 ++# clang stores addresses on the stack causing the frame size to blow
740 ++# out. See https://github.com/ClangBuiltLinux/linux/issues/252
741 ++KBUILD_CFLAGS += -Wframe-larger-than=4096
742 ++endif
743 ++
744 + ccflags-$(CONFIG_PPC64) := $(NO_MINIMAL_TOC)
745 +
746 + obj-y += xmon.o nonstdio.o spr_access.o
747 +diff --git a/arch/s390/kernel/perf_cpum_sf.c b/arch/s390/kernel/perf_cpum_sf.c
748 +index d99155793c26..2e2fd9535f86 100644
749 +--- a/arch/s390/kernel/perf_cpum_sf.c
750 ++++ b/arch/s390/kernel/perf_cpum_sf.c
751 +@@ -1610,14 +1610,17 @@ static int __init init_cpum_sampling_pmu(void)
752 + }
753 +
754 + sfdbg = debug_register(KMSG_COMPONENT, 2, 1, 80);
755 +- if (!sfdbg)
756 ++ if (!sfdbg) {
757 + pr_err("Registering for s390dbf failed\n");
758 ++ return -ENOMEM;
759 ++ }
760 + debug_register_view(sfdbg, &debug_sprintf_view);
761 +
762 + err = register_external_irq(EXT_IRQ_MEASURE_ALERT,
763 + cpumf_measurement_alert);
764 + if (err) {
765 + pr_cpumsf_err(RS_INIT_FAILURE_ALRT);
766 ++ debug_unregister(sfdbg);
767 + goto out;
768 + }
769 +
770 +@@ -1626,6 +1629,7 @@ static int __init init_cpum_sampling_pmu(void)
771 + pr_cpumsf_err(RS_INIT_FAILURE_PERF);
772 + unregister_external_irq(EXT_IRQ_MEASURE_ALERT,
773 + cpumf_measurement_alert);
774 ++ debug_unregister(sfdbg);
775 + goto out;
776 + }
777 +
778 +diff --git a/arch/sparc/include/asm/cmpxchg_64.h b/arch/sparc/include/asm/cmpxchg_64.h
779 +index f71ef3729888..316faa0130ba 100644
780 +--- a/arch/sparc/include/asm/cmpxchg_64.h
781 ++++ b/arch/sparc/include/asm/cmpxchg_64.h
782 +@@ -52,7 +52,12 @@ static inline unsigned long xchg64(__volatile__ unsigned long *m, unsigned long
783 + return val;
784 + }
785 +
786 +-#define xchg(ptr,x) ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
787 ++#define xchg(ptr,x) \
788 ++({ __typeof__(*(ptr)) __ret; \
789 ++ __ret = (__typeof__(*(ptr))) \
790 ++ __xchg((unsigned long)(x), (ptr), sizeof(*(ptr))); \
791 ++ __ret; \
792 ++})
793 +
794 + void __xchg_called_with_bad_pointer(void);
795 +
796 +diff --git a/arch/sparc/include/asm/parport.h b/arch/sparc/include/asm/parport.h
797 +index 05df5f043053..3c5a1c620f0f 100644
798 +--- a/arch/sparc/include/asm/parport.h
799 ++++ b/arch/sparc/include/asm/parport.h
800 +@@ -21,6 +21,7 @@
801 + */
802 + #define HAS_DMA
803 +
804 ++#ifdef CONFIG_PARPORT_PC_FIFO
805 + static DEFINE_SPINLOCK(dma_spin_lock);
806 +
807 + #define claim_dma_lock() \
808 +@@ -31,6 +32,7 @@ static DEFINE_SPINLOCK(dma_spin_lock);
809 +
810 + #define release_dma_lock(__flags) \
811 + spin_unlock_irqrestore(&dma_spin_lock, __flags);
812 ++#endif
813 +
814 + static struct sparc_ebus_info {
815 + struct ebus_dma_info info;
816 +diff --git a/arch/um/drivers/line.c b/arch/um/drivers/line.c
817 +index 366e57f5e8d6..7e524efed584 100644
818 +--- a/arch/um/drivers/line.c
819 ++++ b/arch/um/drivers/line.c
820 +@@ -261,7 +261,7 @@ static irqreturn_t line_write_interrupt(int irq, void *data)
821 + if (err == 0) {
822 + spin_unlock(&line->lock);
823 + return IRQ_NONE;
824 +- } else if (err < 0) {
825 ++ } else if ((err < 0) && (err != -EAGAIN)) {
826 + line->head = line->buffer;
827 + line->tail = line->buffer;
828 + }
829 +diff --git a/arch/x86/hyperv/hv_init.c b/arch/x86/hyperv/hv_init.c
830 +index 2653b7b25d17..924fa9c07368 100644
831 +--- a/arch/x86/hyperv/hv_init.c
832 ++++ b/arch/x86/hyperv/hv_init.c
833 +@@ -125,7 +125,7 @@ static int __init hv_pci_init(void)
834 + * 1. Setup the hypercall page.
835 + * 2. Register Hyper-V specific clocksource.
836 + */
837 +-void hyperv_init(void)
838 ++void __init hyperv_init(void)
839 + {
840 + u64 guest_id, required_msrs;
841 + union hv_x64_msr_hypercall_contents hypercall_msr;
842 +diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h
843 +index 14131dd06b29..8603d127f73c 100644
844 +--- a/arch/x86/include/asm/ptrace.h
845 ++++ b/arch/x86/include/asm/ptrace.h
846 +@@ -231,24 +231,52 @@ static inline int regs_within_kernel_stack(struct pt_regs *regs,
847 + (kernel_stack_pointer(regs) & ~(THREAD_SIZE - 1)));
848 + }
849 +
850 ++/**
851 ++ * regs_get_kernel_stack_nth_addr() - get the address of the Nth entry on stack
852 ++ * @regs: pt_regs which contains kernel stack pointer.
853 ++ * @n: stack entry number.
854 ++ *
855 ++ * regs_get_kernel_stack_nth() returns the address of the @n th entry of the
856 ++ * kernel stack which is specified by @regs. If the @n th entry is NOT in
857 ++ * the kernel stack, this returns NULL.
858 ++ */
859 ++static inline unsigned long *regs_get_kernel_stack_nth_addr(struct pt_regs *regs, unsigned int n)
860 ++{
861 ++ unsigned long *addr = (unsigned long *)kernel_stack_pointer(regs);
862 ++
863 ++ addr += n;
864 ++ if (regs_within_kernel_stack(regs, (unsigned long)addr))
865 ++ return addr;
866 ++ else
867 ++ return NULL;
868 ++}
869 ++
870 ++/* To avoid include hell, we can't include uaccess.h */
871 ++extern long probe_kernel_read(void *dst, const void *src, size_t size);
872 ++
873 + /**
874 + * regs_get_kernel_stack_nth() - get Nth entry of the stack
875 + * @regs: pt_regs which contains kernel stack pointer.
876 + * @n: stack entry number.
877 + *
878 + * regs_get_kernel_stack_nth() returns @n th entry of the kernel stack which
879 +- * is specified by @regs. If the @n th entry is NOT in the kernel stack,
880 ++ * is specified by @regs. If the @n th entry is NOT in the kernel stack
881 + * this returns 0.
882 + */
883 + static inline unsigned long regs_get_kernel_stack_nth(struct pt_regs *regs,
884 + unsigned int n)
885 + {
886 +- unsigned long *addr = (unsigned long *)kernel_stack_pointer(regs);
887 +- addr += n;
888 +- if (regs_within_kernel_stack(regs, (unsigned long)addr))
889 +- return *addr;
890 +- else
891 +- return 0;
892 ++ unsigned long *addr;
893 ++ unsigned long val;
894 ++ long ret;
895 ++
896 ++ addr = regs_get_kernel_stack_nth_addr(regs, n);
897 ++ if (addr) {
898 ++ ret = probe_kernel_read(&val, addr, sizeof(val));
899 ++ if (!ret)
900 ++ return val;
901 ++ }
902 ++ return 0;
903 + }
904 +
905 + #define arch_has_single_step() (1)
906 +diff --git a/arch/x86/kernel/cpu/bugs.c b/arch/x86/kernel/cpu/bugs.c
907 +index 8596811843cc..7896a34f53b5 100644
908 +--- a/arch/x86/kernel/cpu/bugs.c
909 ++++ b/arch/x86/kernel/cpu/bugs.c
910 +@@ -39,6 +39,7 @@ static void __init spectre_v2_select_mitigation(void);
911 + static void __init ssb_select_mitigation(void);
912 + static void __init l1tf_select_mitigation(void);
913 + static void __init mds_select_mitigation(void);
914 ++static void __init mds_print_mitigation(void);
915 + static void __init taa_select_mitigation(void);
916 +
917 + /* The base value of the SPEC_CTRL MSR that always has to be preserved. */
918 +@@ -108,6 +109,12 @@ void __init check_bugs(void)
919 + mds_select_mitigation();
920 + taa_select_mitigation();
921 +
922 ++ /*
923 ++ * As MDS and TAA mitigations are inter-related, print MDS
924 ++ * mitigation until after TAA mitigation selection is done.
925 ++ */
926 ++ mds_print_mitigation();
927 ++
928 + arch_smt_update();
929 +
930 + #ifdef CONFIG_X86_32
931 +@@ -245,6 +252,12 @@ static void __init mds_select_mitigation(void)
932 + (mds_nosmt || cpu_mitigations_auto_nosmt()))
933 + cpu_smt_disable(false);
934 + }
935 ++}
936 ++
937 ++static void __init mds_print_mitigation(void)
938 ++{
939 ++ if (!boot_cpu_has_bug(X86_BUG_MDS) || cpu_mitigations_off())
940 ++ return;
941 +
942 + pr_info("%s\n", mds_strings[mds_mitigation]);
943 + }
944 +@@ -304,8 +317,12 @@ static void __init taa_select_mitigation(void)
945 + return;
946 + }
947 +
948 +- /* TAA mitigation is turned off on the cmdline (tsx_async_abort=off) */
949 +- if (taa_mitigation == TAA_MITIGATION_OFF)
950 ++ /*
951 ++ * TAA mitigation via VERW is turned off if both
952 ++ * tsx_async_abort=off and mds=off are specified.
953 ++ */
954 ++ if (taa_mitigation == TAA_MITIGATION_OFF &&
955 ++ mds_mitigation == MDS_MITIGATION_OFF)
956 + goto out;
957 +
958 + if (boot_cpu_has(X86_FEATURE_MD_CLEAR))
959 +@@ -339,6 +356,15 @@ static void __init taa_select_mitigation(void)
960 + if (taa_nosmt || cpu_mitigations_auto_nosmt())
961 + cpu_smt_disable(false);
962 +
963 ++ /*
964 ++ * Update MDS mitigation, if necessary, as the mds_user_clear is
965 ++ * now enabled for TAA mitigation.
966 ++ */
967 ++ if (mds_mitigation == MDS_MITIGATION_OFF &&
968 ++ boot_cpu_has_bug(X86_BUG_MDS)) {
969 ++ mds_mitigation = MDS_MITIGATION_FULL;
970 ++ mds_select_mitigation();
971 ++ }
972 + out:
973 + pr_info("%s\n", taa_strings[taa_mitigation]);
974 + }
975 +diff --git a/arch/x86/kvm/mmu.c b/arch/x86/kvm/mmu.c
976 +index 8cd26e50d41c..c0b0135ef07f 100644
977 +--- a/arch/x86/kvm/mmu.c
978 ++++ b/arch/x86/kvm/mmu.c
979 +@@ -3177,7 +3177,7 @@ static void transparent_hugepage_adjust(struct kvm_vcpu *vcpu,
980 + * here.
981 + */
982 + if (!is_error_noslot_pfn(pfn) && !kvm_is_reserved_pfn(pfn) &&
983 +- level == PT_PAGE_TABLE_LEVEL &&
984 ++ !kvm_is_zone_device_pfn(pfn) && level == PT_PAGE_TABLE_LEVEL &&
985 + PageTransCompoundMap(pfn_to_page(pfn)) &&
986 + !mmu_gfn_lpage_is_disallowed(vcpu, gfn, PT_DIRECTORY_LEVEL)) {
987 + unsigned long mask;
988 +@@ -5344,9 +5344,9 @@ restart:
989 + * the guest, and the guest page table is using 4K page size
990 + * mapping if the indirect sp has level = 1.
991 + */
992 +- if (sp->role.direct &&
993 +- !kvm_is_reserved_pfn(pfn) &&
994 +- PageTransCompoundMap(pfn_to_page(pfn))) {
995 ++ if (sp->role.direct && !kvm_is_reserved_pfn(pfn) &&
996 ++ !kvm_is_zone_device_pfn(pfn) &&
997 ++ PageTransCompoundMap(pfn_to_page(pfn))) {
998 + drop_spte(kvm, sptep);
999 + need_tlb_flush = 1;
1000 + goto restart;
1001 +diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
1002 +index ab6384efc791..f67fc0f359ff 100644
1003 +--- a/arch/x86/kvm/vmx.c
1004 ++++ b/arch/x86/kvm/vmx.c
1005 +@@ -1602,7 +1602,7 @@ static int __find_msr_index(struct vcpu_vmx *vmx, u32 msr)
1006 + return -1;
1007 + }
1008 +
1009 +-static inline void __invvpid(int ext, u16 vpid, gva_t gva)
1010 ++static inline void __invvpid(unsigned long ext, u16 vpid, gva_t gva)
1011 + {
1012 + struct {
1013 + u64 vpid : 16;
1014 +@@ -1616,7 +1616,7 @@ static inline void __invvpid(int ext, u16 vpid, gva_t gva)
1015 + : : "a"(&operand), "c"(ext) : "cc", "memory");
1016 + }
1017 +
1018 +-static inline void __invept(int ext, u64 eptp, gpa_t gpa)
1019 ++static inline void __invept(unsigned long ext, u64 eptp, gpa_t gpa)
1020 + {
1021 + struct {
1022 + u64 eptp, gpa;
1023 +@@ -10000,6 +10000,10 @@ static void vmx_switch_vmcs(struct kvm_vcpu *vcpu, struct loaded_vmcs *vmcs)
1024 + vmx_vcpu_load(vcpu, cpu);
1025 + vcpu->cpu = cpu;
1026 + put_cpu();
1027 ++
1028 ++ vm_entry_controls_reset_shadow(vmx);
1029 ++ vm_exit_controls_reset_shadow(vmx);
1030 ++ vmx_segment_cache_clear(vmx);
1031 + }
1032 +
1033 + /*
1034 +@@ -11428,7 +11432,6 @@ static int enter_vmx_non_root_mode(struct kvm_vcpu *vcpu, bool from_vmentry)
1035 + vmx->nested.vmcs01_debugctl = vmcs_read64(GUEST_IA32_DEBUGCTL);
1036 +
1037 + vmx_switch_vmcs(vcpu, &vmx->nested.vmcs02);
1038 +- vmx_segment_cache_clear(vmx);
1039 +
1040 + if (prepare_vmcs02(vcpu, vmcs12, from_vmentry, &exit_qual)) {
1041 + leave_guest_mode(vcpu);
1042 +@@ -12172,9 +12175,6 @@ static void nested_vmx_vmexit(struct kvm_vcpu *vcpu, u32 exit_reason,
1043 + }
1044 +
1045 + vmx_switch_vmcs(vcpu, &vmx->vmcs01);
1046 +- vm_entry_controls_reset_shadow(vmx);
1047 +- vm_exit_controls_reset_shadow(vmx);
1048 +- vmx_segment_cache_clear(vmx);
1049 +
1050 + /* Update any VMCS fields that might have changed while L2 ran */
1051 + vmcs_write32(VM_EXIT_MSR_LOAD_COUNT, vmx->msr_autoload.host.nr);
1052 +diff --git a/arch/x86/tools/gen-insn-attr-x86.awk b/arch/x86/tools/gen-insn-attr-x86.awk
1053 +index b02a36b2c14f..a42015b305f4 100644
1054 +--- a/arch/x86/tools/gen-insn-attr-x86.awk
1055 ++++ b/arch/x86/tools/gen-insn-attr-x86.awk
1056 +@@ -69,7 +69,7 @@ BEGIN {
1057 +
1058 + lprefix1_expr = "\\((66|!F3)\\)"
1059 + lprefix2_expr = "\\(F3\\)"
1060 +- lprefix3_expr = "\\((F2|!F3|66\\&F2)\\)"
1061 ++ lprefix3_expr = "\\((F2|!F3|66&F2)\\)"
1062 + lprefix_expr = "\\((66|F2|F3)\\)"
1063 + max_lprefix = 4
1064 +
1065 +@@ -257,7 +257,7 @@ function convert_operands(count,opnd, i,j,imm,mod)
1066 + return add_flags(imm, mod)
1067 + }
1068 +
1069 +-/^[0-9a-f]+\:/ {
1070 ++/^[0-9a-f]+:/ {
1071 + if (NR == 1)
1072 + next
1073 + # get index
1074 +diff --git a/block/blk-merge.c b/block/blk-merge.c
1075 +index 8d60a5bbcef9..94650cdf2924 100644
1076 +--- a/block/blk-merge.c
1077 ++++ b/block/blk-merge.c
1078 +@@ -659,6 +659,31 @@ static void blk_account_io_merge(struct request *req)
1079 + part_stat_unlock();
1080 + }
1081 + }
1082 ++/*
1083 ++ * Two cases of handling DISCARD merge:
1084 ++ * If max_discard_segments > 1, the driver takes every bio
1085 ++ * as a range and send them to controller together. The ranges
1086 ++ * needn't to be contiguous.
1087 ++ * Otherwise, the bios/requests will be handled as same as
1088 ++ * others which should be contiguous.
1089 ++ */
1090 ++static inline bool blk_discard_mergable(struct request *req)
1091 ++{
1092 ++ if (req_op(req) == REQ_OP_DISCARD &&
1093 ++ queue_max_discard_segments(req->q) > 1)
1094 ++ return true;
1095 ++ return false;
1096 ++}
1097 ++
1098 ++enum elv_merge blk_try_req_merge(struct request *req, struct request *next)
1099 ++{
1100 ++ if (blk_discard_mergable(req))
1101 ++ return ELEVATOR_DISCARD_MERGE;
1102 ++ else if (blk_rq_pos(req) + blk_rq_sectors(req) == blk_rq_pos(next))
1103 ++ return ELEVATOR_BACK_MERGE;
1104 ++
1105 ++ return ELEVATOR_NO_MERGE;
1106 ++}
1107 +
1108 + /*
1109 + * For non-mq, this has to be called with the request spinlock acquired.
1110 +@@ -676,12 +701,6 @@ static struct request *attempt_merge(struct request_queue *q,
1111 + if (req_op(req) != req_op(next))
1112 + return NULL;
1113 +
1114 +- /*
1115 +- * not contiguous
1116 +- */
1117 +- if (blk_rq_pos(req) + blk_rq_sectors(req) != blk_rq_pos(next))
1118 +- return NULL;
1119 +-
1120 + if (rq_data_dir(req) != rq_data_dir(next)
1121 + || req->rq_disk != next->rq_disk
1122 + || req_no_special_merge(next))
1123 +@@ -705,11 +724,19 @@ static struct request *attempt_merge(struct request_queue *q,
1124 + * counts here. Handle DISCARDs separately, as they
1125 + * have separate settings.
1126 + */
1127 +- if (req_op(req) == REQ_OP_DISCARD) {
1128 ++
1129 ++ switch (blk_try_req_merge(req, next)) {
1130 ++ case ELEVATOR_DISCARD_MERGE:
1131 + if (!req_attempt_discard_merge(q, req, next))
1132 + return NULL;
1133 +- } else if (!ll_merge_requests_fn(q, req, next))
1134 ++ break;
1135 ++ case ELEVATOR_BACK_MERGE:
1136 ++ if (!ll_merge_requests_fn(q, req, next))
1137 ++ return NULL;
1138 ++ break;
1139 ++ default:
1140 + return NULL;
1141 ++ }
1142 +
1143 + /*
1144 + * If failfast settings disagree or any of the two is already
1145 +@@ -834,8 +861,7 @@ bool blk_rq_merge_ok(struct request *rq, struct bio *bio)
1146 +
1147 + enum elv_merge blk_try_merge(struct request *rq, struct bio *bio)
1148 + {
1149 +- if (req_op(rq) == REQ_OP_DISCARD &&
1150 +- queue_max_discard_segments(rq->q) > 1)
1151 ++ if (blk_discard_mergable(rq))
1152 + return ELEVATOR_DISCARD_MERGE;
1153 + else if (blk_rq_pos(rq) + blk_rq_sectors(rq) == bio->bi_iter.bi_sector)
1154 + return ELEVATOR_BACK_MERGE;
1155 +diff --git a/drivers/acpi/acpi_memhotplug.c b/drivers/acpi/acpi_memhotplug.c
1156 +index 6b0d3ef7309c..2ccfbb61ca89 100644
1157 +--- a/drivers/acpi/acpi_memhotplug.c
1158 ++++ b/drivers/acpi/acpi_memhotplug.c
1159 +@@ -228,7 +228,7 @@ static int acpi_memory_enable_device(struct acpi_memory_device *mem_device)
1160 + if (node < 0)
1161 + node = memory_add_physaddr_to_nid(info->start_addr);
1162 +
1163 +- result = add_memory(node, info->start_addr, info->length);
1164 ++ result = __add_memory(node, info->start_addr, info->length);
1165 +
1166 + /*
1167 + * If the memory block has been used by the kernel, add_memory()
1168 +diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
1169 +index 2c288d1f42bb..817c7edfec0b 100644
1170 +--- a/drivers/atm/zatm.c
1171 ++++ b/drivers/atm/zatm.c
1172 +@@ -126,7 +126,7 @@ static unsigned long dummy[2] = {0,0};
1173 + #define zin_n(r) inl(zatm_dev->base+r*4)
1174 + #define zin(r) inl(zatm_dev->base+uPD98401_##r*4)
1175 + #define zout(v,r) outl(v,zatm_dev->base+uPD98401_##r*4)
1176 +-#define zwait while (zin(CMR) & uPD98401_BUSY)
1177 ++#define zwait() do {} while (zin(CMR) & uPD98401_BUSY)
1178 +
1179 + /* RX0, RX1, TX0, TX1 */
1180 + static const int mbx_entries[NR_MBX] = { 1024,1024,1024,1024 };
1181 +@@ -140,7 +140,7 @@ static const int mbx_esize[NR_MBX] = { 16,16,4,4 }; /* entry size in bytes */
1182 +
1183 + static void zpokel(struct zatm_dev *zatm_dev,u32 value,u32 addr)
1184 + {
1185 +- zwait;
1186 ++ zwait();
1187 + zout(value,CER);
1188 + zout(uPD98401_IND_ACC | uPD98401_IA_BALL |
1189 + (uPD98401_IA_TGT_CM << uPD98401_IA_TGT_SHIFT) | addr,CMR);
1190 +@@ -149,10 +149,10 @@ static void zpokel(struct zatm_dev *zatm_dev,u32 value,u32 addr)
1191 +
1192 + static u32 zpeekl(struct zatm_dev *zatm_dev,u32 addr)
1193 + {
1194 +- zwait;
1195 ++ zwait();
1196 + zout(uPD98401_IND_ACC | uPD98401_IA_BALL | uPD98401_IA_RW |
1197 + (uPD98401_IA_TGT_CM << uPD98401_IA_TGT_SHIFT) | addr,CMR);
1198 +- zwait;
1199 ++ zwait();
1200 + return zin(CER);
1201 + }
1202 +
1203 +@@ -241,7 +241,7 @@ static void refill_pool(struct atm_dev *dev,int pool)
1204 + }
1205 + if (first) {
1206 + spin_lock_irqsave(&zatm_dev->lock, flags);
1207 +- zwait;
1208 ++ zwait();
1209 + zout(virt_to_bus(first),CER);
1210 + zout(uPD98401_ADD_BAT | (pool << uPD98401_POOL_SHIFT) | count,
1211 + CMR);
1212 +@@ -508,9 +508,9 @@ static int open_rx_first(struct atm_vcc *vcc)
1213 + }
1214 + if (zatm_vcc->pool < 0) return -EMSGSIZE;
1215 + spin_lock_irqsave(&zatm_dev->lock, flags);
1216 +- zwait;
1217 ++ zwait();
1218 + zout(uPD98401_OPEN_CHAN,CMR);
1219 +- zwait;
1220 ++ zwait();
1221 + DPRINTK("0x%x 0x%x\n",zin(CMR),zin(CER));
1222 + chan = (zin(CMR) & uPD98401_CHAN_ADDR) >> uPD98401_CHAN_ADDR_SHIFT;
1223 + spin_unlock_irqrestore(&zatm_dev->lock, flags);
1224 +@@ -571,21 +571,21 @@ static void close_rx(struct atm_vcc *vcc)
1225 + pos = vcc->vci >> 1;
1226 + shift = (1-(vcc->vci & 1)) << 4;
1227 + zpokel(zatm_dev,zpeekl(zatm_dev,pos) & ~(0xffff << shift),pos);
1228 +- zwait;
1229 ++ zwait();
1230 + zout(uPD98401_NOP,CMR);
1231 +- zwait;
1232 ++ zwait();
1233 + zout(uPD98401_NOP,CMR);
1234 + spin_unlock_irqrestore(&zatm_dev->lock, flags);
1235 + }
1236 + spin_lock_irqsave(&zatm_dev->lock, flags);
1237 +- zwait;
1238 ++ zwait();
1239 + zout(uPD98401_DEACT_CHAN | uPD98401_CHAN_RT | (zatm_vcc->rx_chan <<
1240 + uPD98401_CHAN_ADDR_SHIFT),CMR);
1241 +- zwait;
1242 ++ zwait();
1243 + udelay(10); /* why oh why ... ? */
1244 + zout(uPD98401_CLOSE_CHAN | uPD98401_CHAN_RT | (zatm_vcc->rx_chan <<
1245 + uPD98401_CHAN_ADDR_SHIFT),CMR);
1246 +- zwait;
1247 ++ zwait();
1248 + if (!(zin(CMR) & uPD98401_CHAN_ADDR))
1249 + printk(KERN_CRIT DEV_LABEL "(itf %d): can't close RX channel "
1250 + "%d\n",vcc->dev->number,zatm_vcc->rx_chan);
1251 +@@ -699,7 +699,7 @@ printk("NONONONOO!!!!\n");
1252 + skb_queue_tail(&zatm_vcc->tx_queue,skb);
1253 + DPRINTK("QRP=0x%08lx\n",zpeekl(zatm_dev,zatm_vcc->tx_chan*VC_SIZE/4+
1254 + uPD98401_TXVC_QRP));
1255 +- zwait;
1256 ++ zwait();
1257 + zout(uPD98401_TX_READY | (zatm_vcc->tx_chan <<
1258 + uPD98401_CHAN_ADDR_SHIFT),CMR);
1259 + spin_unlock_irqrestore(&zatm_dev->lock, flags);
1260 +@@ -891,12 +891,12 @@ static void close_tx(struct atm_vcc *vcc)
1261 + }
1262 + spin_lock_irqsave(&zatm_dev->lock, flags);
1263 + #if 0
1264 +- zwait;
1265 ++ zwait();
1266 + zout(uPD98401_DEACT_CHAN | (chan << uPD98401_CHAN_ADDR_SHIFT),CMR);
1267 + #endif
1268 +- zwait;
1269 ++ zwait();
1270 + zout(uPD98401_CLOSE_CHAN | (chan << uPD98401_CHAN_ADDR_SHIFT),CMR);
1271 +- zwait;
1272 ++ zwait();
1273 + if (!(zin(CMR) & uPD98401_CHAN_ADDR))
1274 + printk(KERN_CRIT DEV_LABEL "(itf %d): can't close TX channel "
1275 + "%d\n",vcc->dev->number,chan);
1276 +@@ -926,9 +926,9 @@ static int open_tx_first(struct atm_vcc *vcc)
1277 + zatm_vcc->tx_chan = 0;
1278 + if (vcc->qos.txtp.traffic_class == ATM_NONE) return 0;
1279 + spin_lock_irqsave(&zatm_dev->lock, flags);
1280 +- zwait;
1281 ++ zwait();
1282 + zout(uPD98401_OPEN_CHAN,CMR);
1283 +- zwait;
1284 ++ zwait();
1285 + DPRINTK("0x%x 0x%x\n",zin(CMR),zin(CER));
1286 + chan = (zin(CMR) & uPD98401_CHAN_ADDR) >> uPD98401_CHAN_ADDR_SHIFT;
1287 + spin_unlock_irqrestore(&zatm_dev->lock, flags);
1288 +@@ -1559,7 +1559,7 @@ static void zatm_phy_put(struct atm_dev *dev,unsigned char value,
1289 + struct zatm_dev *zatm_dev;
1290 +
1291 + zatm_dev = ZATM_DEV(dev);
1292 +- zwait;
1293 ++ zwait();
1294 + zout(value,CER);
1295 + zout(uPD98401_IND_ACC | uPD98401_IA_B0 |
1296 + (uPD98401_IA_TGT_PHY << uPD98401_IA_TGT_SHIFT) | addr,CMR);
1297 +@@ -1571,10 +1571,10 @@ static unsigned char zatm_phy_get(struct atm_dev *dev,unsigned long addr)
1298 + struct zatm_dev *zatm_dev;
1299 +
1300 + zatm_dev = ZATM_DEV(dev);
1301 +- zwait;
1302 ++ zwait();
1303 + zout(uPD98401_IND_ACC | uPD98401_IA_B0 | uPD98401_IA_RW |
1304 + (uPD98401_IA_TGT_PHY << uPD98401_IA_TGT_SHIFT) | addr,CMR);
1305 +- zwait;
1306 ++ zwait();
1307 + return zin(CER) & 0xff;
1308 + }
1309 +
1310 +diff --git a/drivers/base/memory.c b/drivers/base/memory.c
1311 +index c617e00f4361..fe1557aa9b10 100644
1312 +--- a/drivers/base/memory.c
1313 ++++ b/drivers/base/memory.c
1314 +@@ -517,15 +517,20 @@ memory_probe_store(struct device *dev, struct device_attribute *attr,
1315 + if (phys_addr & ((pages_per_block << PAGE_SHIFT) - 1))
1316 + return -EINVAL;
1317 +
1318 ++ ret = lock_device_hotplug_sysfs();
1319 ++ if (ret)
1320 ++ return ret;
1321 ++
1322 + nid = memory_add_physaddr_to_nid(phys_addr);
1323 +- ret = add_memory(nid, phys_addr,
1324 +- MIN_MEMORY_BLOCK_SIZE * sections_per_block);
1325 ++ ret = __add_memory(nid, phys_addr,
1326 ++ MIN_MEMORY_BLOCK_SIZE * sections_per_block);
1327 +
1328 + if (ret)
1329 + goto out;
1330 +
1331 + ret = count;
1332 + out:
1333 ++ unlock_device_hotplug();
1334 + return ret;
1335 + }
1336 +
1337 +diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c
1338 +index c276ba1c0a19..e811f2414889 100644
1339 +--- a/drivers/base/power/domain.c
1340 ++++ b/drivers/base/power/domain.c
1341 +@@ -369,6 +369,10 @@ static int genpd_power_off(struct generic_pm_domain *genpd, bool one_dev_on,
1342 + return -EAGAIN;
1343 + }
1344 +
1345 ++ /* Default to shallowest state. */
1346 ++ if (!genpd->gov)
1347 ++ genpd->state_idx = 0;
1348 ++
1349 + if (genpd->power_off) {
1350 + int ret;
1351 +
1352 +@@ -1598,6 +1602,8 @@ int pm_genpd_init(struct generic_pm_domain *genpd,
1353 + ret = genpd_set_default_power_state(genpd);
1354 + if (ret)
1355 + return ret;
1356 ++ } else if (!gov) {
1357 ++ pr_warn("%s : no governor for states\n", genpd->name);
1358 + }
1359 +
1360 + mutex_lock(&gpd_list_lock);
1361 +diff --git a/drivers/block/amiflop.c b/drivers/block/amiflop.c
1362 +index 49908c74bfcb..b0e8d8364876 100644
1363 +--- a/drivers/block/amiflop.c
1364 ++++ b/drivers/block/amiflop.c
1365 +@@ -1699,11 +1699,41 @@ static const struct block_device_operations floppy_fops = {
1366 + .check_events = amiga_check_events,
1367 + };
1368 +
1369 ++static struct gendisk *fd_alloc_disk(int drive)
1370 ++{
1371 ++ struct gendisk *disk;
1372 ++
1373 ++ disk = alloc_disk(1);
1374 ++ if (!disk)
1375 ++ goto out;
1376 ++
1377 ++ disk->queue = blk_init_queue(do_fd_request, &amiflop_lock);
1378 ++ if (IS_ERR(disk->queue)) {
1379 ++ disk->queue = NULL;
1380 ++ goto out_put_disk;
1381 ++ }
1382 ++
1383 ++ unit[drive].trackbuf = kmalloc(FLOPPY_MAX_SECTORS * 512, GFP_KERNEL);
1384 ++ if (!unit[drive].trackbuf)
1385 ++ goto out_cleanup_queue;
1386 ++
1387 ++ return disk;
1388 ++
1389 ++out_cleanup_queue:
1390 ++ blk_cleanup_queue(disk->queue);
1391 ++ disk->queue = NULL;
1392 ++out_put_disk:
1393 ++ put_disk(disk);
1394 ++out:
1395 ++ unit[drive].type->code = FD_NODRIVE;
1396 ++ return NULL;
1397 ++}
1398 ++
1399 + static int __init fd_probe_drives(void)
1400 + {
1401 + int drive,drives,nomem;
1402 +
1403 +- printk(KERN_INFO "FD: probing units\nfound ");
1404 ++ pr_info("FD: probing units\nfound");
1405 + drives=0;
1406 + nomem=0;
1407 + for(drive=0;drive<FD_MAX_UNITS;drive++) {
1408 +@@ -1711,27 +1741,17 @@ static int __init fd_probe_drives(void)
1409 + fd_probe(drive);
1410 + if (unit[drive].type->code == FD_NODRIVE)
1411 + continue;
1412 +- disk = alloc_disk(1);
1413 ++
1414 ++ disk = fd_alloc_disk(drive);
1415 + if (!disk) {
1416 +- unit[drive].type->code = FD_NODRIVE;
1417 ++ pr_cont(" no mem for fd%d", drive);
1418 ++ nomem = 1;
1419 + continue;
1420 + }
1421 + unit[drive].gendisk = disk;
1422 +-
1423 +- disk->queue = blk_init_queue(do_fd_request, &amiflop_lock);
1424 +- if (!disk->queue) {
1425 +- unit[drive].type->code = FD_NODRIVE;
1426 +- continue;
1427 +- }
1428 +-
1429 + drives++;
1430 +- if ((unit[drive].trackbuf = kmalloc(FLOPPY_MAX_SECTORS * 512, GFP_KERNEL)) == NULL) {
1431 +- printk("no mem for ");
1432 +- unit[drive].type = &drive_types[num_dr_types - 1]; /* FD_NODRIVE */
1433 +- drives--;
1434 +- nomem = 1;
1435 +- }
1436 +- printk("fd%d ",drive);
1437 ++
1438 ++ pr_cont(" fd%d",drive);
1439 + disk->major = FLOPPY_MAJOR;
1440 + disk->first_minor = drive;
1441 + disk->fops = &floppy_fops;
1442 +@@ -1742,11 +1762,11 @@ static int __init fd_probe_drives(void)
1443 + }
1444 + if ((drives > 0) || (nomem == 0)) {
1445 + if (drives == 0)
1446 +- printk("no drives");
1447 +- printk("\n");
1448 ++ pr_cont(" no drives");
1449 ++ pr_cont("\n");
1450 + return drives;
1451 + }
1452 +- printk("\n");
1453 ++ pr_cont("\n");
1454 + return -ENOMEM;
1455 + }
1456 +
1457 +@@ -1837,30 +1857,6 @@ out_blkdev:
1458 + return ret;
1459 + }
1460 +
1461 +-#if 0 /* not safe to unload */
1462 +-static int __exit amiga_floppy_remove(struct platform_device *pdev)
1463 +-{
1464 +- int i;
1465 +-
1466 +- for( i = 0; i < FD_MAX_UNITS; i++) {
1467 +- if (unit[i].type->code != FD_NODRIVE) {
1468 +- struct request_queue *q = unit[i].gendisk->queue;
1469 +- del_gendisk(unit[i].gendisk);
1470 +- put_disk(unit[i].gendisk);
1471 +- kfree(unit[i].trackbuf);
1472 +- if (q)
1473 +- blk_cleanup_queue(q);
1474 +- }
1475 +- }
1476 +- blk_unregister_region(MKDEV(FLOPPY_MAJOR, 0), 256);
1477 +- free_irq(IRQ_AMIGA_CIAA_TB, NULL);
1478 +- free_irq(IRQ_AMIGA_DSKBLK, NULL);
1479 +- custom.dmacon = DMAF_DISK; /* disable DMA */
1480 +- amiga_chip_free(raw_buf);
1481 +- unregister_blkdev(FLOPPY_MAJOR, "fd");
1482 +-}
1483 +-#endif
1484 +-
1485 + static struct platform_driver amiga_floppy_driver = {
1486 + .driver = {
1487 + .name = "amiga-floppy",
1488 +diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c
1489 +index 34dfadd4dcd4..929bd255a290 100644
1490 +--- a/drivers/block/nbd.c
1491 ++++ b/drivers/block/nbd.c
1492 +@@ -931,6 +931,7 @@ static struct socket *nbd_get_socket(struct nbd_device *nbd, unsigned long fd,
1493 + if (sock->ops->shutdown == sock_no_shutdown) {
1494 + dev_err(disk_to_dev(nbd->disk), "Unsupported socket: shutdown callout must be supported.\n");
1495 + *err = -EINVAL;
1496 ++ sockfd_put(sock);
1497 + return NULL;
1498 + }
1499 +
1500 +@@ -969,14 +970,15 @@ static int nbd_add_socket(struct nbd_device *nbd, unsigned long arg,
1501 + sockfd_put(sock);
1502 + return -ENOMEM;
1503 + }
1504 ++
1505 ++ config->socks = socks;
1506 ++
1507 + nsock = kzalloc(sizeof(struct nbd_sock), GFP_KERNEL);
1508 + if (!nsock) {
1509 + sockfd_put(sock);
1510 + return -ENOMEM;
1511 + }
1512 +
1513 +- config->socks = socks;
1514 +-
1515 + nsock->fallback_index = -1;
1516 + nsock->dead = false;
1517 + mutex_init(&nsock->tx_lock);
1518 +diff --git a/drivers/block/skd_main.c b/drivers/block/skd_main.c
1519 +index 64d0fc17c174..95649025cde7 100644
1520 +--- a/drivers/block/skd_main.c
1521 ++++ b/drivers/block/skd_main.c
1522 +@@ -1417,7 +1417,7 @@ static void skd_resolve_req_exception(struct skd_device *skdev,
1523 +
1524 + case SKD_CHECK_STATUS_BUSY_IMMINENT:
1525 + skd_log_skreq(skdev, skreq, "retry(busy)");
1526 +- blk_requeue_request(skdev->queue, req);
1527 ++ blk_mq_requeue_request(req, true);
1528 + dev_info(&skdev->pdev->dev, "drive BUSY imminent\n");
1529 + skdev->state = SKD_DRVR_STATE_BUSY_IMMINENT;
1530 + skdev->timer_countdown = SKD_TIMER_MINUTES(20);
1531 +@@ -1427,7 +1427,7 @@ static void skd_resolve_req_exception(struct skd_device *skdev,
1532 + case SKD_CHECK_STATUS_REQUEUE_REQUEST:
1533 + if ((unsigned long) ++req->special < SKD_MAX_RETRIES) {
1534 + skd_log_skreq(skdev, skreq, "retry");
1535 +- blk_requeue_request(skdev->queue, req);
1536 ++ blk_mq_requeue_request(req, true);
1537 + break;
1538 + }
1539 + /* fall through */
1540 +diff --git a/drivers/bluetooth/hci_bcsp.c b/drivers/bluetooth/hci_bcsp.c
1541 +index 57a7f4255ac0..ee6c403de6af 100644
1542 +--- a/drivers/bluetooth/hci_bcsp.c
1543 ++++ b/drivers/bluetooth/hci_bcsp.c
1544 +@@ -605,6 +605,7 @@ static int bcsp_recv(struct hci_uart *hu, const void *data, int count)
1545 + if (*ptr == 0xc0) {
1546 + BT_ERR("Short BCSP packet");
1547 + kfree_skb(bcsp->rx_skb);
1548 ++ bcsp->rx_skb = NULL;
1549 + bcsp->rx_state = BCSP_W4_PKT_START;
1550 + bcsp->rx_count = 0;
1551 + } else
1552 +@@ -620,6 +621,7 @@ static int bcsp_recv(struct hci_uart *hu, const void *data, int count)
1553 + bcsp->rx_skb->data[2])) != bcsp->rx_skb->data[3]) {
1554 + BT_ERR("Error in BCSP hdr checksum");
1555 + kfree_skb(bcsp->rx_skb);
1556 ++ bcsp->rx_skb = NULL;
1557 + bcsp->rx_state = BCSP_W4_PKT_DELIMITER;
1558 + bcsp->rx_count = 0;
1559 + continue;
1560 +@@ -644,6 +646,7 @@ static int bcsp_recv(struct hci_uart *hu, const void *data, int count)
1561 + bscp_get_crc(bcsp));
1562 +
1563 + kfree_skb(bcsp->rx_skb);
1564 ++ bcsp->rx_skb = NULL;
1565 + bcsp->rx_state = BCSP_W4_PKT_DELIMITER;
1566 + bcsp->rx_count = 0;
1567 + continue;
1568 +diff --git a/drivers/cdrom/cdrom.c b/drivers/cdrom/cdrom.c
1569 +index ea6558d4864c..90dd8e7291da 100644
1570 +--- a/drivers/cdrom/cdrom.c
1571 ++++ b/drivers/cdrom/cdrom.c
1572 +@@ -410,10 +410,10 @@ static int cdrom_get_disc_info(struct cdrom_device_info *cdi,
1573 + * hack to have the capability flags defined const, while we can still
1574 + * change it here without gcc complaining at every line.
1575 + */
1576 +-#define ENSURE(call, bits) \
1577 +-do { \
1578 +- if (cdo->call == NULL) \
1579 +- *change_capability &= ~(bits); \
1580 ++#define ENSURE(cdo, call, bits) \
1581 ++do { \
1582 ++ if (cdo->call == NULL) \
1583 ++ WARN_ON_ONCE((cdo)->capability & (bits)); \
1584 + } while (0)
1585 +
1586 + /*
1587 +@@ -589,7 +589,6 @@ int register_cdrom(struct cdrom_device_info *cdi)
1588 + {
1589 + static char banner_printed;
1590 + const struct cdrom_device_ops *cdo = cdi->ops;
1591 +- int *change_capability = (int *)&cdo->capability; /* hack */
1592 +
1593 + cd_dbg(CD_OPEN, "entering register_cdrom\n");
1594 +
1595 +@@ -601,16 +600,16 @@ int register_cdrom(struct cdrom_device_info *cdi)
1596 + cdrom_sysctl_register();
1597 + }
1598 +
1599 +- ENSURE(drive_status, CDC_DRIVE_STATUS);
1600 ++ ENSURE(cdo, drive_status, CDC_DRIVE_STATUS);
1601 + if (cdo->check_events == NULL && cdo->media_changed == NULL)
1602 +- *change_capability = ~(CDC_MEDIA_CHANGED | CDC_SELECT_DISC);
1603 +- ENSURE(tray_move, CDC_CLOSE_TRAY | CDC_OPEN_TRAY);
1604 +- ENSURE(lock_door, CDC_LOCK);
1605 +- ENSURE(select_speed, CDC_SELECT_SPEED);
1606 +- ENSURE(get_last_session, CDC_MULTI_SESSION);
1607 +- ENSURE(get_mcn, CDC_MCN);
1608 +- ENSURE(reset, CDC_RESET);
1609 +- ENSURE(generic_packet, CDC_GENERIC_PACKET);
1610 ++ WARN_ON_ONCE(cdo->capability & (CDC_MEDIA_CHANGED | CDC_SELECT_DISC));
1611 ++ ENSURE(cdo, tray_move, CDC_CLOSE_TRAY | CDC_OPEN_TRAY);
1612 ++ ENSURE(cdo, lock_door, CDC_LOCK);
1613 ++ ENSURE(cdo, select_speed, CDC_SELECT_SPEED);
1614 ++ ENSURE(cdo, get_last_session, CDC_MULTI_SESSION);
1615 ++ ENSURE(cdo, get_mcn, CDC_MCN);
1616 ++ ENSURE(cdo, reset, CDC_RESET);
1617 ++ ENSURE(cdo, generic_packet, CDC_GENERIC_PACKET);
1618 + cdi->mc_flags = 0;
1619 + cdi->options = CDO_USE_FFLAGS;
1620 +
1621 +diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
1622 +index 65454acd4b97..5200772ab0bd 100644
1623 +--- a/drivers/char/virtio_console.c
1624 ++++ b/drivers/char/virtio_console.c
1625 +@@ -1366,24 +1366,24 @@ static void set_console_size(struct port *port, u16 rows, u16 cols)
1626 + port->cons.ws.ws_col = cols;
1627 + }
1628 +
1629 +-static unsigned int fill_queue(struct virtqueue *vq, spinlock_t *lock)
1630 ++static int fill_queue(struct virtqueue *vq, spinlock_t *lock)
1631 + {
1632 + struct port_buffer *buf;
1633 +- unsigned int nr_added_bufs;
1634 ++ int nr_added_bufs;
1635 + int ret;
1636 +
1637 + nr_added_bufs = 0;
1638 + do {
1639 + buf = alloc_buf(vq->vdev, PAGE_SIZE, 0);
1640 + if (!buf)
1641 +- break;
1642 ++ return -ENOMEM;
1643 +
1644 + spin_lock_irq(lock);
1645 + ret = add_inbuf(vq, buf);
1646 + if (ret < 0) {
1647 + spin_unlock_irq(lock);
1648 + free_buf(buf, true);
1649 +- break;
1650 ++ return ret;
1651 + }
1652 + nr_added_bufs++;
1653 + spin_unlock_irq(lock);
1654 +@@ -1403,7 +1403,6 @@ static int add_port(struct ports_device *portdev, u32 id)
1655 + char debugfs_name[16];
1656 + struct port *port;
1657 + dev_t devt;
1658 +- unsigned int nr_added_bufs;
1659 + int err;
1660 +
1661 + port = kmalloc(sizeof(*port), GFP_KERNEL);
1662 +@@ -1462,11 +1461,13 @@ static int add_port(struct ports_device *portdev, u32 id)
1663 + spin_lock_init(&port->outvq_lock);
1664 + init_waitqueue_head(&port->waitqueue);
1665 +
1666 +- /* Fill the in_vq with buffers so the host can send us data. */
1667 +- nr_added_bufs = fill_queue(port->in_vq, &port->inbuf_lock);
1668 +- if (!nr_added_bufs) {
1669 ++ /* We can safely ignore ENOSPC because it means
1670 ++ * the queue already has buffers. Buffers are removed
1671 ++ * only by virtcons_remove(), not by unplug_port()
1672 ++ */
1673 ++ err = fill_queue(port->in_vq, &port->inbuf_lock);
1674 ++ if (err < 0 && err != -ENOSPC) {
1675 + dev_err(port->dev, "Error allocating inbufs\n");
1676 +- err = -ENOMEM;
1677 + goto free_device;
1678 + }
1679 +
1680 +@@ -2099,14 +2100,11 @@ static int virtcons_probe(struct virtio_device *vdev)
1681 + INIT_WORK(&portdev->control_work, &control_work_handler);
1682 +
1683 + if (multiport) {
1684 +- unsigned int nr_added_bufs;
1685 +-
1686 + spin_lock_init(&portdev->c_ivq_lock);
1687 + spin_lock_init(&portdev->c_ovq_lock);
1688 +
1689 +- nr_added_bufs = fill_queue(portdev->c_ivq,
1690 +- &portdev->c_ivq_lock);
1691 +- if (!nr_added_bufs) {
1692 ++ err = fill_queue(portdev->c_ivq, &portdev->c_ivq_lock);
1693 ++ if (err < 0) {
1694 + dev_err(&vdev->dev,
1695 + "Error allocating buffers for control queue\n");
1696 + /*
1697 +@@ -2117,7 +2115,7 @@ static int virtcons_probe(struct virtio_device *vdev)
1698 + VIRTIO_CONSOLE_DEVICE_READY, 0);
1699 + /* Device was functional: we need full cleanup. */
1700 + virtcons_remove(vdev);
1701 +- return -ENOMEM;
1702 ++ return err;
1703 + }
1704 + } else {
1705 + /*
1706 +diff --git a/drivers/clk/at91/clk-audio-pll.c b/drivers/clk/at91/clk-audio-pll.c
1707 +index da7bafcfbe70..b3eaf654fac9 100644
1708 +--- a/drivers/clk/at91/clk-audio-pll.c
1709 ++++ b/drivers/clk/at91/clk-audio-pll.c
1710 +@@ -509,7 +509,7 @@ static void __init of_sama5d2_clk_audio_pll_pad_setup(struct device_node *np)
1711 +
1712 + static void __init of_sama5d2_clk_audio_pll_pmc_setup(struct device_node *np)
1713 + {
1714 +- struct clk_audio_pad *apmc_ck;
1715 ++ struct clk_audio_pmc *apmc_ck;
1716 + struct clk_init_data init = {};
1717 +
1718 + apmc_ck = kzalloc(sizeof(*apmc_ck), GFP_KERNEL);
1719 +diff --git a/drivers/clk/mmp/clk-of-mmp2.c b/drivers/clk/mmp/clk-of-mmp2.c
1720 +index 0fc75c395957..d083b860f083 100644
1721 +--- a/drivers/clk/mmp/clk-of-mmp2.c
1722 ++++ b/drivers/clk/mmp/clk-of-mmp2.c
1723 +@@ -227,8 +227,8 @@ static struct mmp_param_gate_clk apmu_gate_clks[] = {
1724 + /* The gate clocks has mux parent. */
1725 + {MMP2_CLK_SDH0, "sdh0_clk", "sdh_mix_clk", CLK_SET_RATE_PARENT, APMU_SDH0, 0x1b, 0x1b, 0x0, 0, &sdh_lock},
1726 + {MMP2_CLK_SDH1, "sdh1_clk", "sdh_mix_clk", CLK_SET_RATE_PARENT, APMU_SDH1, 0x1b, 0x1b, 0x0, 0, &sdh_lock},
1727 +- {MMP2_CLK_SDH1, "sdh2_clk", "sdh_mix_clk", CLK_SET_RATE_PARENT, APMU_SDH2, 0x1b, 0x1b, 0x0, 0, &sdh_lock},
1728 +- {MMP2_CLK_SDH1, "sdh3_clk", "sdh_mix_clk", CLK_SET_RATE_PARENT, APMU_SDH3, 0x1b, 0x1b, 0x0, 0, &sdh_lock},
1729 ++ {MMP2_CLK_SDH2, "sdh2_clk", "sdh_mix_clk", CLK_SET_RATE_PARENT, APMU_SDH2, 0x1b, 0x1b, 0x0, 0, &sdh_lock},
1730 ++ {MMP2_CLK_SDH3, "sdh3_clk", "sdh_mix_clk", CLK_SET_RATE_PARENT, APMU_SDH3, 0x1b, 0x1b, 0x0, 0, &sdh_lock},
1731 + {MMP2_CLK_DISP0, "disp0_clk", "disp0_div", CLK_SET_RATE_PARENT, APMU_DISP0, 0x1b, 0x1b, 0x0, 0, &disp0_lock},
1732 + {MMP2_CLK_DISP0_SPHY, "disp0_sphy_clk", "disp0_sphy_div", CLK_SET_RATE_PARENT, APMU_DISP0, 0x1024, 0x1024, 0x0, 0, &disp0_lock},
1733 + {MMP2_CLK_DISP1, "disp1_clk", "disp1_div", CLK_SET_RATE_PARENT, APMU_DISP1, 0x1b, 0x1b, 0x0, 0, &disp1_lock},
1734 +diff --git a/drivers/clk/sunxi-ng/ccu-sun50i-a64.c b/drivers/clk/sunxi-ng/ccu-sun50i-a64.c
1735 +index 2bb4cabf802f..36a30a3cfad7 100644
1736 +--- a/drivers/clk/sunxi-ng/ccu-sun50i-a64.c
1737 ++++ b/drivers/clk/sunxi-ng/ccu-sun50i-a64.c
1738 +@@ -158,7 +158,12 @@ static SUNXI_CCU_NM_WITH_FRAC_GATE_LOCK(pll_gpu_clk, "pll-gpu",
1739 + #define SUN50I_A64_PLL_MIPI_REG 0x040
1740 +
1741 + static struct ccu_nkm pll_mipi_clk = {
1742 +- .enable = BIT(31),
1743 ++ /*
1744 ++ * The bit 23 and 22 are called "LDO{1,2}_EN" on the SoC's
1745 ++ * user manual, and by experiments the PLL doesn't work without
1746 ++ * these bits toggled.
1747 ++ */
1748 ++ .enable = BIT(31) | BIT(23) | BIT(22),
1749 + .lock = BIT(28),
1750 + .n = _SUNXI_CCU_MULT(8, 4),
1751 + .k = _SUNXI_CCU_MULT_MIN(4, 2, 2),
1752 +diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
1753 +index 4aa3c5331666..480e8c13567c 100644
1754 +--- a/drivers/cpufreq/cpufreq.c
1755 ++++ b/drivers/cpufreq/cpufreq.c
1756 +@@ -911,6 +911,9 @@ static ssize_t show(struct kobject *kobj, struct attribute *attr, char *buf)
1757 + struct freq_attr *fattr = to_attr(attr);
1758 + ssize_t ret;
1759 +
1760 ++ if (!fattr->show)
1761 ++ return -EIO;
1762 ++
1763 + down_read(&policy->rwsem);
1764 + ret = fattr->show(policy, buf);
1765 + up_read(&policy->rwsem);
1766 +@@ -925,6 +928,9 @@ static ssize_t store(struct kobject *kobj, struct attribute *attr,
1767 + struct freq_attr *fattr = to_attr(attr);
1768 + ssize_t ret = -EINVAL;
1769 +
1770 ++ if (!fattr->store)
1771 ++ return -EIO;
1772 ++
1773 + cpus_read_lock();
1774 +
1775 + if (cpu_online(policy->cpu)) {
1776 +@@ -1673,6 +1679,9 @@ void cpufreq_resume(void)
1777 + if (!cpufreq_driver)
1778 + return;
1779 +
1780 ++ if (unlikely(!cpufreq_suspended))
1781 ++ return;
1782 ++
1783 + cpufreq_suspended = false;
1784 +
1785 + if (!has_target() && !cpufreq_driver->resume)
1786 +diff --git a/drivers/edac/thunderx_edac.c b/drivers/edac/thunderx_edac.c
1787 +index f35d87519a3e..dfefa39e9351 100644
1788 +--- a/drivers/edac/thunderx_edac.c
1789 ++++ b/drivers/edac/thunderx_edac.c
1790 +@@ -1905,7 +1905,7 @@ static irqreturn_t thunderx_l2c_threaded_isr(int irq, void *irq_id)
1791 + default:
1792 + dev_err(&l2c->pdev->dev, "Unsupported device: %04x\n",
1793 + l2c->pdev->device);
1794 +- return IRQ_NONE;
1795 ++ goto err_free;
1796 + }
1797 +
1798 + while (CIRC_CNT(l2c->ring_head, l2c->ring_tail,
1799 +@@ -1927,7 +1927,7 @@ static irqreturn_t thunderx_l2c_threaded_isr(int irq, void *irq_id)
1800 + l2c->ring_tail++;
1801 + }
1802 +
1803 +- return IRQ_HANDLED;
1804 ++ ret = IRQ_HANDLED;
1805 +
1806 + err_free:
1807 + kfree(other);
1808 +diff --git a/drivers/firmware/google/gsmi.c b/drivers/firmware/google/gsmi.c
1809 +index c8f169bf2e27..62337be07afc 100644
1810 +--- a/drivers/firmware/google/gsmi.c
1811 ++++ b/drivers/firmware/google/gsmi.c
1812 +@@ -480,11 +480,10 @@ static ssize_t eventlog_write(struct file *filp, struct kobject *kobj,
1813 + if (count < sizeof(u32))
1814 + return -EINVAL;
1815 + param.type = *(u32 *)buf;
1816 +- count -= sizeof(u32);
1817 + buf += sizeof(u32);
1818 +
1819 + /* The remaining buffer is the data payload */
1820 +- if (count > gsmi_dev.data_buf->length)
1821 ++ if ((count - sizeof(u32)) > gsmi_dev.data_buf->length)
1822 + return -EINVAL;
1823 + param.data_len = count - sizeof(u32);
1824 +
1825 +@@ -504,7 +503,7 @@ static ssize_t eventlog_write(struct file *filp, struct kobject *kobj,
1826 +
1827 + spin_unlock_irqrestore(&gsmi_dev.lock, flags);
1828 +
1829 +- return rc;
1830 ++ return (rc == 0) ? count : rc;
1831 +
1832 + }
1833 +
1834 +diff --git a/drivers/gpio/gpio-max77620.c b/drivers/gpio/gpio-max77620.c
1835 +index ac6c1c0548b6..78254ed93206 100644
1836 +--- a/drivers/gpio/gpio-max77620.c
1837 ++++ b/drivers/gpio/gpio-max77620.c
1838 +@@ -163,13 +163,13 @@ static int max77620_gpio_set_debounce(struct max77620_gpio *mgpio,
1839 + case 0:
1840 + val = MAX77620_CNFG_GPIO_DBNC_None;
1841 + break;
1842 +- case 1000 ... 8000:
1843 ++ case 1 ... 8000:
1844 + val = MAX77620_CNFG_GPIO_DBNC_8ms;
1845 + break;
1846 +- case 9000 ... 16000:
1847 ++ case 8001 ... 16000:
1848 + val = MAX77620_CNFG_GPIO_DBNC_16ms;
1849 + break;
1850 +- case 17000 ... 32000:
1851 ++ case 16001 ... 32000:
1852 + val = MAX77620_CNFG_GPIO_DBNC_32ms;
1853 + break;
1854 + default:
1855 +diff --git a/drivers/gpu/drm/i915/i915_gem_userptr.c b/drivers/gpu/drm/i915/i915_gem_userptr.c
1856 +index 05ae8c4a8a1b..480d20758324 100644
1857 +--- a/drivers/gpu/drm/i915/i915_gem_userptr.c
1858 ++++ b/drivers/gpu/drm/i915/i915_gem_userptr.c
1859 +@@ -690,8 +690,28 @@ i915_gem_userptr_put_pages(struct drm_i915_gem_object *obj,
1860 + i915_gem_gtt_finish_pages(obj, pages);
1861 +
1862 + for_each_sgt_page(page, sgt_iter, pages) {
1863 +- if (obj->mm.dirty)
1864 ++ if (obj->mm.dirty && trylock_page(page)) {
1865 ++ /*
1866 ++ * As this may not be anonymous memory (e.g. shmem)
1867 ++ * but exist on a real mapping, we have to lock
1868 ++ * the page in order to dirty it -- holding
1869 ++ * the page reference is not sufficient to
1870 ++ * prevent the inode from being truncated.
1871 ++ * Play safe and take the lock.
1872 ++ *
1873 ++ * However...!
1874 ++ *
1875 ++ * The mmu-notifier can be invalidated for a
1876 ++ * migrate_page, that is alreadying holding the lock
1877 ++ * on the page. Such a try_to_unmap() will result
1878 ++ * in us calling put_pages() and so recursively try
1879 ++ * to lock the page. We avoid that deadlock with
1880 ++ * a trylock_page() and in exchange we risk missing
1881 ++ * some page dirtying.
1882 ++ */
1883 + set_page_dirty(page);
1884 ++ unlock_page(page);
1885 ++ }
1886 +
1887 + mark_page_accessed(page);
1888 + put_page(page);
1889 +diff --git a/drivers/i2c/busses/i2c-uniphier-f.c b/drivers/i2c/busses/i2c-uniphier-f.c
1890 +index bc26ec822e26..dd0687e36a47 100644
1891 +--- a/drivers/i2c/busses/i2c-uniphier-f.c
1892 ++++ b/drivers/i2c/busses/i2c-uniphier-f.c
1893 +@@ -98,6 +98,7 @@ struct uniphier_fi2c_priv {
1894 + unsigned int flags;
1895 + unsigned int busy_cnt;
1896 + unsigned int clk_cycle;
1897 ++ spinlock_t lock; /* IRQ synchronization */
1898 + };
1899 +
1900 + static void uniphier_fi2c_fill_txfifo(struct uniphier_fi2c_priv *priv,
1901 +@@ -142,9 +143,10 @@ static void uniphier_fi2c_set_irqs(struct uniphier_fi2c_priv *priv)
1902 + writel(priv->enabled_irqs, priv->membase + UNIPHIER_FI2C_IE);
1903 + }
1904 +
1905 +-static void uniphier_fi2c_clear_irqs(struct uniphier_fi2c_priv *priv)
1906 ++static void uniphier_fi2c_clear_irqs(struct uniphier_fi2c_priv *priv,
1907 ++ u32 mask)
1908 + {
1909 +- writel(-1, priv->membase + UNIPHIER_FI2C_IC);
1910 ++ writel(mask, priv->membase + UNIPHIER_FI2C_IC);
1911 + }
1912 +
1913 + static void uniphier_fi2c_stop(struct uniphier_fi2c_priv *priv)
1914 +@@ -162,7 +164,10 @@ static irqreturn_t uniphier_fi2c_interrupt(int irq, void *dev_id)
1915 + struct uniphier_fi2c_priv *priv = dev_id;
1916 + u32 irq_status;
1917 +
1918 ++ spin_lock(&priv->lock);
1919 ++
1920 + irq_status = readl(priv->membase + UNIPHIER_FI2C_INT);
1921 ++ irq_status &= priv->enabled_irqs;
1922 +
1923 + dev_dbg(&priv->adap.dev,
1924 + "interrupt: enabled_irqs=%04x, irq_status=%04x\n",
1925 +@@ -207,7 +212,13 @@ static irqreturn_t uniphier_fi2c_interrupt(int irq, void *dev_id)
1926 +
1927 + if (irq_status & (UNIPHIER_FI2C_INT_RF | UNIPHIER_FI2C_INT_RB)) {
1928 + uniphier_fi2c_drain_rxfifo(priv);
1929 +- if (!priv->len)
1930 ++ /*
1931 ++ * If the number of bytes to read is multiple of the FIFO size
1932 ++ * (msg->len == 8, 16, 24, ...), the INT_RF bit is set a little
1933 ++ * earlier than INT_RB. We wait for INT_RB to confirm the
1934 ++ * completion of the current message.
1935 ++ */
1936 ++ if (!priv->len && (irq_status & UNIPHIER_FI2C_INT_RB))
1937 + goto data_done;
1938 +
1939 + if (unlikely(priv->flags & UNIPHIER_FI2C_MANUAL_NACK)) {
1940 +@@ -230,6 +241,8 @@ static irqreturn_t uniphier_fi2c_interrupt(int irq, void *dev_id)
1941 + goto handled;
1942 + }
1943 +
1944 ++ spin_unlock(&priv->lock);
1945 ++
1946 + return IRQ_NONE;
1947 +
1948 + data_done:
1949 +@@ -244,7 +257,14 @@ complete:
1950 + }
1951 +
1952 + handled:
1953 +- uniphier_fi2c_clear_irqs(priv);
1954 ++ /*
1955 ++ * This controller makes a pause while any bit of the IRQ status is
1956 ++ * asserted. Clear the asserted bit to kick the controller just before
1957 ++ * exiting the handler.
1958 ++ */
1959 ++ uniphier_fi2c_clear_irqs(priv, irq_status);
1960 ++
1961 ++ spin_unlock(&priv->lock);
1962 +
1963 + return IRQ_HANDLED;
1964 + }
1965 +@@ -252,6 +272,8 @@ handled:
1966 + static void uniphier_fi2c_tx_init(struct uniphier_fi2c_priv *priv, u16 addr)
1967 + {
1968 + priv->enabled_irqs |= UNIPHIER_FI2C_INT_TE;
1969 ++ uniphier_fi2c_set_irqs(priv);
1970 ++
1971 + /* do not use TX byte counter */
1972 + writel(0, priv->membase + UNIPHIER_FI2C_TBC);
1973 + /* set slave address */
1974 +@@ -284,6 +306,8 @@ static void uniphier_fi2c_rx_init(struct uniphier_fi2c_priv *priv, u16 addr)
1975 + priv->enabled_irqs |= UNIPHIER_FI2C_INT_RF;
1976 + }
1977 +
1978 ++ uniphier_fi2c_set_irqs(priv);
1979 ++
1980 + /* set slave address with RD bit */
1981 + writel(UNIPHIER_FI2C_DTTX_CMD | UNIPHIER_FI2C_DTTX_RD | addr << 1,
1982 + priv->membase + UNIPHIER_FI2C_DTTX);
1983 +@@ -307,14 +331,16 @@ static void uniphier_fi2c_recover(struct uniphier_fi2c_priv *priv)
1984 + }
1985 +
1986 + static int uniphier_fi2c_master_xfer_one(struct i2c_adapter *adap,
1987 +- struct i2c_msg *msg, bool stop)
1988 ++ struct i2c_msg *msg, bool repeat,
1989 ++ bool stop)
1990 + {
1991 + struct uniphier_fi2c_priv *priv = i2c_get_adapdata(adap);
1992 + bool is_read = msg->flags & I2C_M_RD;
1993 +- unsigned long time_left;
1994 ++ unsigned long time_left, flags;
1995 +
1996 +- dev_dbg(&adap->dev, "%s: addr=0x%02x, len=%d, stop=%d\n",
1997 +- is_read ? "receive" : "transmit", msg->addr, msg->len, stop);
1998 ++ dev_dbg(&adap->dev, "%s: addr=0x%02x, len=%d, repeat=%d, stop=%d\n",
1999 ++ is_read ? "receive" : "transmit", msg->addr, msg->len,
2000 ++ repeat, stop);
2001 +
2002 + priv->len = msg->len;
2003 + priv->buf = msg->buf;
2004 +@@ -326,22 +352,36 @@ static int uniphier_fi2c_master_xfer_one(struct i2c_adapter *adap,
2005 + priv->flags |= UNIPHIER_FI2C_STOP;
2006 +
2007 + reinit_completion(&priv->comp);
2008 +- uniphier_fi2c_clear_irqs(priv);
2009 ++ uniphier_fi2c_clear_irqs(priv, U32_MAX);
2010 + writel(UNIPHIER_FI2C_RST_TBRST | UNIPHIER_FI2C_RST_RBRST,
2011 + priv->membase + UNIPHIER_FI2C_RST); /* reset TX/RX FIFO */
2012 +
2013 ++ spin_lock_irqsave(&priv->lock, flags);
2014 ++
2015 + if (is_read)
2016 + uniphier_fi2c_rx_init(priv, msg->addr);
2017 + else
2018 + uniphier_fi2c_tx_init(priv, msg->addr);
2019 +
2020 +- uniphier_fi2c_set_irqs(priv);
2021 +-
2022 + dev_dbg(&adap->dev, "start condition\n");
2023 +- writel(UNIPHIER_FI2C_CR_MST | UNIPHIER_FI2C_CR_STA,
2024 +- priv->membase + UNIPHIER_FI2C_CR);
2025 ++ /*
2026 ++ * For a repeated START condition, writing a slave address to the FIFO
2027 ++ * kicks the controller. So, the UNIPHIER_FI2C_CR register should be
2028 ++ * written only for a non-repeated START condition.
2029 ++ */
2030 ++ if (!repeat)
2031 ++ writel(UNIPHIER_FI2C_CR_MST | UNIPHIER_FI2C_CR_STA,
2032 ++ priv->membase + UNIPHIER_FI2C_CR);
2033 ++
2034 ++ spin_unlock_irqrestore(&priv->lock, flags);
2035 +
2036 + time_left = wait_for_completion_timeout(&priv->comp, adap->timeout);
2037 ++
2038 ++ spin_lock_irqsave(&priv->lock, flags);
2039 ++ priv->enabled_irqs = 0;
2040 ++ uniphier_fi2c_set_irqs(priv);
2041 ++ spin_unlock_irqrestore(&priv->lock, flags);
2042 ++
2043 + if (!time_left) {
2044 + dev_err(&adap->dev, "transaction timeout.\n");
2045 + uniphier_fi2c_recover(priv);
2046 +@@ -394,6 +434,7 @@ static int uniphier_fi2c_master_xfer(struct i2c_adapter *adap,
2047 + struct i2c_msg *msgs, int num)
2048 + {
2049 + struct i2c_msg *msg, *emsg = msgs + num;
2050 ++ bool repeat = false;
2051 + int ret;
2052 +
2053 + ret = uniphier_fi2c_check_bus_busy(adap);
2054 +@@ -404,9 +445,11 @@ static int uniphier_fi2c_master_xfer(struct i2c_adapter *adap,
2055 + /* Emit STOP if it is the last message or I2C_M_STOP is set. */
2056 + bool stop = (msg + 1 == emsg) || (msg->flags & I2C_M_STOP);
2057 +
2058 +- ret = uniphier_fi2c_master_xfer_one(adap, msg, stop);
2059 ++ ret = uniphier_fi2c_master_xfer_one(adap, msg, repeat, stop);
2060 + if (ret)
2061 + return ret;
2062 ++
2063 ++ repeat = !stop;
2064 + }
2065 +
2066 + return num;
2067 +@@ -546,6 +589,7 @@ static int uniphier_fi2c_probe(struct platform_device *pdev)
2068 +
2069 + priv->clk_cycle = clk_rate / bus_speed;
2070 + init_completion(&priv->comp);
2071 ++ spin_lock_init(&priv->lock);
2072 + priv->adap.owner = THIS_MODULE;
2073 + priv->adap.algo = &uniphier_fi2c_algo;
2074 + priv->adap.dev.parent = dev;
2075 +diff --git a/drivers/infiniband/hw/bnxt_re/main.c b/drivers/infiniband/hw/bnxt_re/main.c
2076 +index bf811b23bc95..7d00b6a53ed8 100644
2077 +--- a/drivers/infiniband/hw/bnxt_re/main.c
2078 ++++ b/drivers/infiniband/hw/bnxt_re/main.c
2079 +@@ -782,12 +782,17 @@ static void bnxt_re_dispatch_event(struct ib_device *ibdev, struct ib_qp *qp,
2080 + struct ib_event ib_event;
2081 +
2082 + ib_event.device = ibdev;
2083 +- if (qp)
2084 ++ if (qp) {
2085 + ib_event.element.qp = qp;
2086 +- else
2087 ++ ib_event.event = event;
2088 ++ if (qp->event_handler)
2089 ++ qp->event_handler(&ib_event, qp->qp_context);
2090 ++
2091 ++ } else {
2092 + ib_event.element.port_num = port_num;
2093 +- ib_event.event = event;
2094 +- ib_dispatch_event(&ib_event);
2095 ++ ib_event.event = event;
2096 ++ ib_dispatch_event(&ib_event);
2097 ++ }
2098 + }
2099 +
2100 + #define HWRM_QUEUE_PRI2COS_QCFG_INPUT_FLAGS_IVLAN 0x02
2101 +diff --git a/drivers/isdn/mISDN/tei.c b/drivers/isdn/mISDN/tei.c
2102 +index 12d9e5f4beb1..58635b5f296f 100644
2103 +--- a/drivers/isdn/mISDN/tei.c
2104 ++++ b/drivers/isdn/mISDN/tei.c
2105 +@@ -1180,8 +1180,7 @@ static int
2106 + ctrl_teimanager(struct manager *mgr, void *arg)
2107 + {
2108 + /* currently we only have one option */
2109 +- int *val = (int *)arg;
2110 +- int ret = 0;
2111 ++ unsigned int *val = (unsigned int *)arg;
2112 +
2113 + switch (val[0]) {
2114 + case IMCLEAR_L2:
2115 +@@ -1197,9 +1196,9 @@ ctrl_teimanager(struct manager *mgr, void *arg)
2116 + test_and_clear_bit(OPTION_L1_HOLD, &mgr->options);
2117 + break;
2118 + default:
2119 +- ret = -EINVAL;
2120 ++ return -EINVAL;
2121 + }
2122 +- return ret;
2123 ++ return 0;
2124 + }
2125 +
2126 + /* This function does create a L2 for fixed TEI in NT Mode */
2127 +diff --git a/drivers/macintosh/windfarm_smu_sat.c b/drivers/macintosh/windfarm_smu_sat.c
2128 +index da7f4fc1a51d..a0f61eb853c5 100644
2129 +--- a/drivers/macintosh/windfarm_smu_sat.c
2130 ++++ b/drivers/macintosh/windfarm_smu_sat.c
2131 +@@ -22,14 +22,6 @@
2132 +
2133 + #define VERSION "1.0"
2134 +
2135 +-#define DEBUG
2136 +-
2137 +-#ifdef DEBUG
2138 +-#define DBG(args...) printk(args)
2139 +-#else
2140 +-#define DBG(args...) do { } while(0)
2141 +-#endif
2142 +-
2143 + /* If the cache is older than 800ms we'll refetch it */
2144 + #define MAX_AGE msecs_to_jiffies(800)
2145 +
2146 +@@ -106,13 +98,10 @@ struct smu_sdbp_header *smu_sat_get_sdb_partition(unsigned int sat_id, int id,
2147 + buf[i+2] = data[3];
2148 + buf[i+3] = data[2];
2149 + }
2150 +-#ifdef DEBUG
2151 +- DBG(KERN_DEBUG "sat %d partition %x:", sat_id, id);
2152 +- for (i = 0; i < len; ++i)
2153 +- DBG(" %x", buf[i]);
2154 +- DBG("\n");
2155 +-#endif
2156 +
2157 ++ printk(KERN_DEBUG "sat %d partition %x:", sat_id, id);
2158 ++ print_hex_dump(KERN_DEBUG, " ", DUMP_PREFIX_OFFSET,
2159 ++ 16, 1, buf, len, false);
2160 + if (size)
2161 + *size = len;
2162 + return (struct smu_sdbp_header *) buf;
2163 +@@ -132,13 +121,13 @@ static int wf_sat_read_cache(struct wf_sat *sat)
2164 + if (err < 0)
2165 + return err;
2166 + sat->last_read = jiffies;
2167 ++
2168 + #ifdef LOTSA_DEBUG
2169 + {
2170 + int i;
2171 +- DBG(KERN_DEBUG "wf_sat_get: data is");
2172 +- for (i = 0; i < 16; ++i)
2173 +- DBG(" %.2x", sat->cache[i]);
2174 +- DBG("\n");
2175 ++ printk(KERN_DEBUG "wf_sat_get: data is");
2176 ++ print_hex_dump(KERN_DEBUG, " ", DUMP_PREFIX_OFFSET,
2177 ++ 16, 1, sat->cache, 16, false);
2178 + }
2179 + #endif
2180 + return 0;
2181 +diff --git a/drivers/md/dm-raid.c b/drivers/md/dm-raid.c
2182 +index 151211b4cb1b..2c5912e75514 100644
2183 +--- a/drivers/md/dm-raid.c
2184 ++++ b/drivers/md/dm-raid.c
2185 +@@ -2441,7 +2441,7 @@ static int super_validate(struct raid_set *rs, struct md_rdev *rdev)
2186 + }
2187 +
2188 + /* Enable bitmap creation for RAID levels != 0 */
2189 +- mddev->bitmap_info.offset = rt_is_raid0(rs->raid_type) ? 0 : to_sector(4096);
2190 ++ mddev->bitmap_info.offset = (rt_is_raid0(rs->raid_type) || rs->journal_dev.dev) ? 0 : to_sector(4096);
2191 + mddev->bitmap_info.default_offset = mddev->bitmap_info.offset;
2192 +
2193 + if (!test_and_clear_bit(FirstUse, &rdev->flags)) {
2194 +diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
2195 +index 433e78f453da..d08d77b9674f 100644
2196 +--- a/drivers/md/raid10.c
2197 ++++ b/drivers/md/raid10.c
2198 +@@ -226,7 +226,7 @@ static void * r10buf_pool_alloc(gfp_t gfp_flags, void *data)
2199 +
2200 + out_free_pages:
2201 + while (--j >= 0)
2202 +- resync_free_pages(&rps[j * 2]);
2203 ++ resync_free_pages(&rps[j]);
2204 +
2205 + j = 0;
2206 + out_free_bio:
2207 +diff --git a/drivers/media/platform/vivid/vivid-kthread-cap.c b/drivers/media/platform/vivid/vivid-kthread-cap.c
2208 +index d300e5e7eadc..2ca9c928ed2f 100644
2209 +--- a/drivers/media/platform/vivid/vivid-kthread-cap.c
2210 ++++ b/drivers/media/platform/vivid/vivid-kthread-cap.c
2211 +@@ -777,7 +777,11 @@ static int vivid_thread_vid_cap(void *data)
2212 + if (kthread_should_stop())
2213 + break;
2214 +
2215 +- mutex_lock(&dev->mutex);
2216 ++ if (!mutex_trylock(&dev->mutex)) {
2217 ++ schedule_timeout_uninterruptible(1);
2218 ++ continue;
2219 ++ }
2220 ++
2221 + cur_jiffies = jiffies;
2222 + if (dev->cap_seq_resync) {
2223 + dev->jiffies_vid_cap = cur_jiffies;
2224 +@@ -930,8 +934,6 @@ void vivid_stop_generating_vid_cap(struct vivid_dev *dev, bool *pstreaming)
2225 +
2226 + /* shutdown control thread */
2227 + vivid_grab_controls(dev, false);
2228 +- mutex_unlock(&dev->mutex);
2229 + kthread_stop(dev->kthread_vid_cap);
2230 + dev->kthread_vid_cap = NULL;
2231 +- mutex_lock(&dev->mutex);
2232 + }
2233 +diff --git a/drivers/media/platform/vivid/vivid-kthread-out.c b/drivers/media/platform/vivid/vivid-kthread-out.c
2234 +index 7c8d75852816..ed5d8fb854b4 100644
2235 +--- a/drivers/media/platform/vivid/vivid-kthread-out.c
2236 ++++ b/drivers/media/platform/vivid/vivid-kthread-out.c
2237 +@@ -147,7 +147,11 @@ static int vivid_thread_vid_out(void *data)
2238 + if (kthread_should_stop())
2239 + break;
2240 +
2241 +- mutex_lock(&dev->mutex);
2242 ++ if (!mutex_trylock(&dev->mutex)) {
2243 ++ schedule_timeout_uninterruptible(1);
2244 ++ continue;
2245 ++ }
2246 ++
2247 + cur_jiffies = jiffies;
2248 + if (dev->out_seq_resync) {
2249 + dev->jiffies_vid_out = cur_jiffies;
2250 +@@ -301,8 +305,6 @@ void vivid_stop_generating_vid_out(struct vivid_dev *dev, bool *pstreaming)
2251 +
2252 + /* shutdown control thread */
2253 + vivid_grab_controls(dev, false);
2254 +- mutex_unlock(&dev->mutex);
2255 + kthread_stop(dev->kthread_vid_out);
2256 + dev->kthread_vid_out = NULL;
2257 +- mutex_lock(&dev->mutex);
2258 + }
2259 +diff --git a/drivers/media/platform/vivid/vivid-sdr-cap.c b/drivers/media/platform/vivid/vivid-sdr-cap.c
2260 +index ebd7b9c4dd83..4f49c9a47d49 100644
2261 +--- a/drivers/media/platform/vivid/vivid-sdr-cap.c
2262 ++++ b/drivers/media/platform/vivid/vivid-sdr-cap.c
2263 +@@ -149,7 +149,11 @@ static int vivid_thread_sdr_cap(void *data)
2264 + if (kthread_should_stop())
2265 + break;
2266 +
2267 +- mutex_lock(&dev->mutex);
2268 ++ if (!mutex_trylock(&dev->mutex)) {
2269 ++ schedule_timeout_uninterruptible(1);
2270 ++ continue;
2271 ++ }
2272 ++
2273 + cur_jiffies = jiffies;
2274 + if (dev->sdr_cap_seq_resync) {
2275 + dev->jiffies_sdr_cap = cur_jiffies;
2276 +@@ -309,10 +313,8 @@ static void sdr_cap_stop_streaming(struct vb2_queue *vq)
2277 + }
2278 +
2279 + /* shutdown control thread */
2280 +- mutex_unlock(&dev->mutex);
2281 + kthread_stop(dev->kthread_sdr_cap);
2282 + dev->kthread_sdr_cap = NULL;
2283 +- mutex_lock(&dev->mutex);
2284 + }
2285 +
2286 + const struct vb2_ops vivid_sdr_cap_qops = {
2287 +diff --git a/drivers/media/platform/vivid/vivid-vid-cap.c b/drivers/media/platform/vivid/vivid-vid-cap.c
2288 +index 4ca3d600aa84..c66568e8f388 100644
2289 +--- a/drivers/media/platform/vivid/vivid-vid-cap.c
2290 ++++ b/drivers/media/platform/vivid/vivid-vid-cap.c
2291 +@@ -239,9 +239,6 @@ static int vid_cap_start_streaming(struct vb2_queue *vq, unsigned count)
2292 + if (vb2_is_streaming(&dev->vb_vid_out_q))
2293 + dev->can_loop_video = vivid_vid_can_loop(dev);
2294 +
2295 +- if (dev->kthread_vid_cap)
2296 +- return 0;
2297 +-
2298 + dev->vid_cap_seq_count = 0;
2299 + dprintk(dev, 1, "%s\n", __func__);
2300 + for (i = 0; i < VIDEO_MAX_FRAME; i++)
2301 +diff --git a/drivers/media/platform/vivid/vivid-vid-out.c b/drivers/media/platform/vivid/vivid-vid-out.c
2302 +index 0b1b6218ede8..3e7a26d15074 100644
2303 +--- a/drivers/media/platform/vivid/vivid-vid-out.c
2304 ++++ b/drivers/media/platform/vivid/vivid-vid-out.c
2305 +@@ -158,9 +158,6 @@ static int vid_out_start_streaming(struct vb2_queue *vq, unsigned count)
2306 + if (vb2_is_streaming(&dev->vb_vid_cap_q))
2307 + dev->can_loop_video = vivid_vid_can_loop(dev);
2308 +
2309 +- if (dev->kthread_vid_out)
2310 +- return 0;
2311 +-
2312 + dev->vid_out_seq_count = 0;
2313 + dprintk(dev, 1, "%s\n", __func__);
2314 + if (dev->start_streaming_error) {
2315 +diff --git a/drivers/media/rc/imon.c b/drivers/media/rc/imon.c
2316 +index a7547c88e4c3..edf8a7a76e86 100644
2317 +--- a/drivers/media/rc/imon.c
2318 ++++ b/drivers/media/rc/imon.c
2319 +@@ -1737,8 +1737,7 @@ static void imon_incoming_scancode(struct imon_context *ictx,
2320 + spin_unlock_irqrestore(&ictx->kc_lock, flags);
2321 +
2322 + /* send touchscreen events through input subsystem if touchpad data */
2323 +- if (ictx->display_type == IMON_DISPLAY_TYPE_VGA && len == 8 &&
2324 +- buf[7] == 0x86) {
2325 ++ if (ictx->touch && len == 8 && buf[7] == 0x86) {
2326 + imon_touch_event(ictx, buf);
2327 + return;
2328 +
2329 +diff --git a/drivers/media/usb/b2c2/flexcop-usb.c b/drivers/media/usb/b2c2/flexcop-usb.c
2330 +index a8f3169e30b3..ac4fddfd0a43 100644
2331 +--- a/drivers/media/usb/b2c2/flexcop-usb.c
2332 ++++ b/drivers/media/usb/b2c2/flexcop-usb.c
2333 +@@ -537,6 +537,9 @@ static int flexcop_usb_probe(struct usb_interface *intf,
2334 + struct flexcop_device *fc = NULL;
2335 + int ret;
2336 +
2337 ++ if (intf->cur_altsetting->desc.bNumEndpoints < 1)
2338 ++ return -ENODEV;
2339 ++
2340 + if ((fc = flexcop_device_kmalloc(sizeof(struct flexcop_usb))) == NULL) {
2341 + err("out of memory\n");
2342 + return -ENOMEM;
2343 +diff --git a/drivers/media/usb/dvb-usb/cxusb.c b/drivers/media/usb/dvb-usb/cxusb.c
2344 +index cfe86b4864b3..47a9a791ee7d 100644
2345 +--- a/drivers/media/usb/dvb-usb/cxusb.c
2346 ++++ b/drivers/media/usb/dvb-usb/cxusb.c
2347 +@@ -455,7 +455,8 @@ static int cxusb_rc_query(struct dvb_usb_device *d)
2348 + {
2349 + u8 ircode[4];
2350 +
2351 +- cxusb_ctrl_msg(d, CMD_GET_IR_CODE, NULL, 0, ircode, 4);
2352 ++ if (cxusb_ctrl_msg(d, CMD_GET_IR_CODE, NULL, 0, ircode, 4) < 0)
2353 ++ return 0;
2354 +
2355 + if (ircode[2] || ircode[3])
2356 + rc_keydown(d->rc_dev, RC_PROTO_NEC,
2357 +diff --git a/drivers/media/usb/usbvision/usbvision-video.c b/drivers/media/usb/usbvision/usbvision-video.c
2358 +index 960272d3c924..4c39c502d616 100644
2359 +--- a/drivers/media/usb/usbvision/usbvision-video.c
2360 ++++ b/drivers/media/usb/usbvision/usbvision-video.c
2361 +@@ -328,6 +328,10 @@ static int usbvision_v4l2_open(struct file *file)
2362 + if (mutex_lock_interruptible(&usbvision->v4l2_lock))
2363 + return -ERESTARTSYS;
2364 +
2365 ++ if (usbvision->remove_pending) {
2366 ++ err_code = -ENODEV;
2367 ++ goto unlock;
2368 ++ }
2369 + if (usbvision->user) {
2370 + err_code = -EBUSY;
2371 + } else {
2372 +@@ -391,6 +395,7 @@ unlock:
2373 + static int usbvision_v4l2_close(struct file *file)
2374 + {
2375 + struct usb_usbvision *usbvision = video_drvdata(file);
2376 ++ int r;
2377 +
2378 + PDEBUG(DBG_IO, "close");
2379 +
2380 +@@ -405,9 +410,10 @@ static int usbvision_v4l2_close(struct file *file)
2381 + usbvision_scratch_free(usbvision);
2382 +
2383 + usbvision->user--;
2384 ++ r = usbvision->remove_pending;
2385 + mutex_unlock(&usbvision->v4l2_lock);
2386 +
2387 +- if (usbvision->remove_pending) {
2388 ++ if (r) {
2389 + printk(KERN_INFO "%s: Final disconnect\n", __func__);
2390 + usbvision_release(usbvision);
2391 + return 0;
2392 +@@ -1091,6 +1097,11 @@ static int usbvision_radio_open(struct file *file)
2393 +
2394 + if (mutex_lock_interruptible(&usbvision->v4l2_lock))
2395 + return -ERESTARTSYS;
2396 ++
2397 ++ if (usbvision->remove_pending) {
2398 ++ err_code = -ENODEV;
2399 ++ goto out;
2400 ++ }
2401 + err_code = v4l2_fh_open(file);
2402 + if (err_code)
2403 + goto out;
2404 +@@ -1123,6 +1134,7 @@ out:
2405 + static int usbvision_radio_close(struct file *file)
2406 + {
2407 + struct usb_usbvision *usbvision = video_drvdata(file);
2408 ++ int r;
2409 +
2410 + PDEBUG(DBG_IO, "");
2411 +
2412 +@@ -1135,9 +1147,10 @@ static int usbvision_radio_close(struct file *file)
2413 + usbvision_audio_off(usbvision);
2414 + usbvision->radio = 0;
2415 + usbvision->user--;
2416 ++ r = usbvision->remove_pending;
2417 + mutex_unlock(&usbvision->v4l2_lock);
2418 +
2419 +- if (usbvision->remove_pending) {
2420 ++ if (r) {
2421 + printk(KERN_INFO "%s: Final disconnect\n", __func__);
2422 + v4l2_fh_release(file);
2423 + usbvision_release(usbvision);
2424 +@@ -1562,6 +1575,7 @@ err_usb:
2425 + static void usbvision_disconnect(struct usb_interface *intf)
2426 + {
2427 + struct usb_usbvision *usbvision = to_usbvision(usb_get_intfdata(intf));
2428 ++ int u;
2429 +
2430 + PDEBUG(DBG_PROBE, "");
2431 +
2432 +@@ -1578,13 +1592,14 @@ static void usbvision_disconnect(struct usb_interface *intf)
2433 + v4l2_device_disconnect(&usbvision->v4l2_dev);
2434 + usbvision_i2c_unregister(usbvision);
2435 + usbvision->remove_pending = 1; /* Now all ISO data will be ignored */
2436 ++ u = usbvision->user;
2437 +
2438 + usb_put_dev(usbvision->dev);
2439 + usbvision->dev = NULL; /* USB device is no more */
2440 +
2441 + mutex_unlock(&usbvision->v4l2_lock);
2442 +
2443 +- if (usbvision->user) {
2444 ++ if (u) {
2445 + printk(KERN_INFO "%s: In use, disconnect pending\n",
2446 + __func__);
2447 + wake_up_interruptible(&usbvision->wait_frame);
2448 +diff --git a/drivers/media/usb/uvc/uvc_driver.c b/drivers/media/usb/uvc/uvc_driver.c
2449 +index c2939d080997..6445b638f207 100644
2450 +--- a/drivers/media/usb/uvc/uvc_driver.c
2451 ++++ b/drivers/media/usb/uvc/uvc_driver.c
2452 +@@ -2059,6 +2059,20 @@ static int uvc_probe(struct usb_interface *intf,
2453 + sizeof(dev->name) - len);
2454 + }
2455 +
2456 ++ /* Initialize the media device. */
2457 ++#ifdef CONFIG_MEDIA_CONTROLLER
2458 ++ dev->mdev.dev = &intf->dev;
2459 ++ strscpy(dev->mdev.model, dev->name, sizeof(dev->mdev.model));
2460 ++ if (udev->serial)
2461 ++ strscpy(dev->mdev.serial, udev->serial,
2462 ++ sizeof(dev->mdev.serial));
2463 ++ usb_make_path(udev, dev->mdev.bus_info, sizeof(dev->mdev.bus_info));
2464 ++ dev->mdev.hw_revision = le16_to_cpu(udev->descriptor.bcdDevice);
2465 ++ media_device_init(&dev->mdev);
2466 ++
2467 ++ dev->vdev.mdev = &dev->mdev;
2468 ++#endif
2469 ++
2470 + /* Parse the Video Class control descriptor. */
2471 + if (uvc_parse_control(dev) < 0) {
2472 + uvc_trace(UVC_TRACE_PROBE, "Unable to parse UVC "
2473 +@@ -2079,19 +2093,7 @@ static int uvc_probe(struct usb_interface *intf,
2474 + "linux-uvc-devel mailing list.\n");
2475 + }
2476 +
2477 +- /* Initialize the media device and register the V4L2 device. */
2478 +-#ifdef CONFIG_MEDIA_CONTROLLER
2479 +- dev->mdev.dev = &intf->dev;
2480 +- strlcpy(dev->mdev.model, dev->name, sizeof(dev->mdev.model));
2481 +- if (udev->serial)
2482 +- strlcpy(dev->mdev.serial, udev->serial,
2483 +- sizeof(dev->mdev.serial));
2484 +- strcpy(dev->mdev.bus_info, udev->devpath);
2485 +- dev->mdev.hw_revision = le16_to_cpu(udev->descriptor.bcdDevice);
2486 +- media_device_init(&dev->mdev);
2487 +-
2488 +- dev->vdev.mdev = &dev->mdev;
2489 +-#endif
2490 ++ /* Register the V4L2 device. */
2491 + if (v4l2_device_register(&intf->dev, &dev->vdev) < 0)
2492 + goto error;
2493 +
2494 +diff --git a/drivers/mfd/arizona-core.c b/drivers/mfd/arizona-core.c
2495 +index d8e3184bd27c..ad8a5296c50b 100644
2496 +--- a/drivers/mfd/arizona-core.c
2497 ++++ b/drivers/mfd/arizona-core.c
2498 +@@ -52,8 +52,10 @@ int arizona_clk32k_enable(struct arizona *arizona)
2499 + if (ret != 0)
2500 + goto err_ref;
2501 + ret = clk_prepare_enable(arizona->mclk[ARIZONA_MCLK1]);
2502 +- if (ret != 0)
2503 +- goto err_pm;
2504 ++ if (ret != 0) {
2505 ++ pm_runtime_put_sync(arizona->dev);
2506 ++ goto err_ref;
2507 ++ }
2508 + break;
2509 + case ARIZONA_32KZ_MCLK2:
2510 + ret = clk_prepare_enable(arizona->mclk[ARIZONA_MCLK2]);
2511 +@@ -67,8 +69,6 @@ int arizona_clk32k_enable(struct arizona *arizona)
2512 + ARIZONA_CLK_32K_ENA);
2513 + }
2514 +
2515 +-err_pm:
2516 +- pm_runtime_put_sync(arizona->dev);
2517 + err_ref:
2518 + if (ret != 0)
2519 + arizona->clk32k_ref--;
2520 +diff --git a/drivers/mfd/intel_soc_pmic_bxtwc.c b/drivers/mfd/intel_soc_pmic_bxtwc.c
2521 +index 15bc052704a6..9ca1f8c015de 100644
2522 +--- a/drivers/mfd/intel_soc_pmic_bxtwc.c
2523 ++++ b/drivers/mfd/intel_soc_pmic_bxtwc.c
2524 +@@ -31,8 +31,8 @@
2525 +
2526 + /* Interrupt Status Registers */
2527 + #define BXTWC_IRQLVL1 0x4E02
2528 +-#define BXTWC_PWRBTNIRQ 0x4E03
2529 +
2530 ++#define BXTWC_PWRBTNIRQ 0x4E03
2531 + #define BXTWC_THRM0IRQ 0x4E04
2532 + #define BXTWC_THRM1IRQ 0x4E05
2533 + #define BXTWC_THRM2IRQ 0x4E06
2534 +@@ -47,10 +47,9 @@
2535 +
2536 + /* Interrupt MASK Registers */
2537 + #define BXTWC_MIRQLVL1 0x4E0E
2538 +-#define BXTWC_MPWRTNIRQ 0x4E0F
2539 +-
2540 + #define BXTWC_MIRQLVL1_MCHGR BIT(5)
2541 +
2542 ++#define BXTWC_MPWRBTNIRQ 0x4E0F
2543 + #define BXTWC_MTHRM0IRQ 0x4E12
2544 + #define BXTWC_MTHRM1IRQ 0x4E13
2545 + #define BXTWC_MTHRM2IRQ 0x4E14
2546 +@@ -66,9 +65,7 @@
2547 + /* Whiskey Cove PMIC share same ACPI ID between different platforms */
2548 + #define BROXTON_PMIC_WC_HRV 4
2549 +
2550 +-/* Manage in two IRQ chips since mask registers are not consecutive */
2551 + enum bxtwc_irqs {
2552 +- /* Level 1 */
2553 + BXTWC_PWRBTN_LVL1_IRQ = 0,
2554 + BXTWC_TMU_LVL1_IRQ,
2555 + BXTWC_THRM_LVL1_IRQ,
2556 +@@ -77,9 +74,11 @@ enum bxtwc_irqs {
2557 + BXTWC_CHGR_LVL1_IRQ,
2558 + BXTWC_GPIO_LVL1_IRQ,
2559 + BXTWC_CRIT_LVL1_IRQ,
2560 ++};
2561 +
2562 +- /* Level 2 */
2563 +- BXTWC_PWRBTN_IRQ,
2564 ++enum bxtwc_irqs_pwrbtn {
2565 ++ BXTWC_PWRBTN_IRQ = 0,
2566 ++ BXTWC_UIBTN_IRQ,
2567 + };
2568 +
2569 + enum bxtwc_irqs_bcu {
2570 +@@ -113,7 +112,10 @@ static const struct regmap_irq bxtwc_regmap_irqs[] = {
2571 + REGMAP_IRQ_REG(BXTWC_CHGR_LVL1_IRQ, 0, BIT(5)),
2572 + REGMAP_IRQ_REG(BXTWC_GPIO_LVL1_IRQ, 0, BIT(6)),
2573 + REGMAP_IRQ_REG(BXTWC_CRIT_LVL1_IRQ, 0, BIT(7)),
2574 +- REGMAP_IRQ_REG(BXTWC_PWRBTN_IRQ, 1, 0x03),
2575 ++};
2576 ++
2577 ++static const struct regmap_irq bxtwc_regmap_irqs_pwrbtn[] = {
2578 ++ REGMAP_IRQ_REG(BXTWC_PWRBTN_IRQ, 0, 0x01),
2579 + };
2580 +
2581 + static const struct regmap_irq bxtwc_regmap_irqs_bcu[] = {
2582 +@@ -125,7 +127,7 @@ static const struct regmap_irq bxtwc_regmap_irqs_adc[] = {
2583 + };
2584 +
2585 + static const struct regmap_irq bxtwc_regmap_irqs_chgr[] = {
2586 +- REGMAP_IRQ_REG(BXTWC_USBC_IRQ, 0, BIT(5)),
2587 ++ REGMAP_IRQ_REG(BXTWC_USBC_IRQ, 0, 0x20),
2588 + REGMAP_IRQ_REG(BXTWC_CHGR0_IRQ, 0, 0x1f),
2589 + REGMAP_IRQ_REG(BXTWC_CHGR1_IRQ, 1, 0x1f),
2590 + };
2591 +@@ -144,7 +146,16 @@ static struct regmap_irq_chip bxtwc_regmap_irq_chip = {
2592 + .mask_base = BXTWC_MIRQLVL1,
2593 + .irqs = bxtwc_regmap_irqs,
2594 + .num_irqs = ARRAY_SIZE(bxtwc_regmap_irqs),
2595 +- .num_regs = 2,
2596 ++ .num_regs = 1,
2597 ++};
2598 ++
2599 ++static struct regmap_irq_chip bxtwc_regmap_irq_chip_pwrbtn = {
2600 ++ .name = "bxtwc_irq_chip_pwrbtn",
2601 ++ .status_base = BXTWC_PWRBTNIRQ,
2602 ++ .mask_base = BXTWC_MPWRBTNIRQ,
2603 ++ .irqs = bxtwc_regmap_irqs_pwrbtn,
2604 ++ .num_irqs = ARRAY_SIZE(bxtwc_regmap_irqs_pwrbtn),
2605 ++ .num_regs = 1,
2606 + };
2607 +
2608 + static struct regmap_irq_chip bxtwc_regmap_irq_chip_tmu = {
2609 +@@ -472,6 +483,16 @@ static int bxtwc_probe(struct platform_device *pdev)
2610 + return ret;
2611 + }
2612 +
2613 ++ ret = bxtwc_add_chained_irq_chip(pmic, pmic->irq_chip_data,
2614 ++ BXTWC_PWRBTN_LVL1_IRQ,
2615 ++ IRQF_ONESHOT,
2616 ++ &bxtwc_regmap_irq_chip_pwrbtn,
2617 ++ &pmic->irq_chip_data_pwrbtn);
2618 ++ if (ret) {
2619 ++ dev_err(&pdev->dev, "Failed to add PWRBTN IRQ chip\n");
2620 ++ return ret;
2621 ++ }
2622 ++
2623 + ret = bxtwc_add_chained_irq_chip(pmic, pmic->irq_chip_data,
2624 + BXTWC_TMU_LVL1_IRQ,
2625 + IRQF_ONESHOT,
2626 +diff --git a/drivers/mfd/max8997.c b/drivers/mfd/max8997.c
2627 +index 2d6e2c392786..4a2fc59d5901 100644
2628 +--- a/drivers/mfd/max8997.c
2629 ++++ b/drivers/mfd/max8997.c
2630 +@@ -155,12 +155,6 @@ static struct max8997_platform_data *max8997_i2c_parse_dt_pdata(
2631 +
2632 + pd->ono = irq_of_parse_and_map(dev->of_node, 1);
2633 +
2634 +- /*
2635 +- * ToDo: the 'wakeup' member in the platform data is more of a linux
2636 +- * specfic information. Hence, there is no binding for that yet and
2637 +- * not parsed here.
2638 +- */
2639 +-
2640 + return pd;
2641 + }
2642 +
2643 +@@ -248,7 +242,7 @@ static int max8997_i2c_probe(struct i2c_client *i2c,
2644 + */
2645 +
2646 + /* MAX8997 has a power button input. */
2647 +- device_init_wakeup(max8997->dev, pdata->wakeup);
2648 ++ device_init_wakeup(max8997->dev, true);
2649 +
2650 + return ret;
2651 +
2652 +diff --git a/drivers/mfd/mc13xxx-core.c b/drivers/mfd/mc13xxx-core.c
2653 +index 6c16f170529f..75d52034f89d 100644
2654 +--- a/drivers/mfd/mc13xxx-core.c
2655 ++++ b/drivers/mfd/mc13xxx-core.c
2656 +@@ -278,7 +278,8 @@ int mc13xxx_adc_do_conversion(struct mc13xxx *mc13xxx, unsigned int mode,
2657 + if (ret)
2658 + goto out;
2659 +
2660 +- adc0 = MC13XXX_ADC0_ADINC1 | MC13XXX_ADC0_ADINC2;
2661 ++ adc0 = MC13XXX_ADC0_ADINC1 | MC13XXX_ADC0_ADINC2 |
2662 ++ MC13XXX_ADC0_CHRGRAWDIV;
2663 + adc1 = MC13XXX_ADC1_ADEN | MC13XXX_ADC1_ADTRIGIGN | MC13XXX_ADC1_ASC;
2664 +
2665 + if (channel > 7)
2666 +diff --git a/drivers/misc/mic/scif/scif_fence.c b/drivers/misc/mic/scif/scif_fence.c
2667 +index cac3bcc308a7..7bb929f05d85 100644
2668 +--- a/drivers/misc/mic/scif/scif_fence.c
2669 ++++ b/drivers/misc/mic/scif/scif_fence.c
2670 +@@ -272,7 +272,7 @@ static int _scif_prog_signal(scif_epd_t epd, dma_addr_t dst, u64 val)
2671 + dma_fail:
2672 + if (!x100)
2673 + dma_pool_free(ep->remote_dev->signal_pool, status,
2674 +- status->src_dma_addr);
2675 ++ src - offsetof(struct scif_status, val));
2676 + alloc_fail:
2677 + return err;
2678 + }
2679 +diff --git a/drivers/mmc/host/mtk-sd.c b/drivers/mmc/host/mtk-sd.c
2680 +index 267f7ab08420..a2ac9938d945 100644
2681 +--- a/drivers/mmc/host/mtk-sd.c
2682 ++++ b/drivers/mmc/host/mtk-sd.c
2683 +@@ -885,6 +885,7 @@ static void msdc_start_command(struct msdc_host *host,
2684 + WARN_ON(host->cmd);
2685 + host->cmd = cmd;
2686 +
2687 ++ mod_delayed_work(system_wq, &host->req_timeout, DAT_TIMEOUT);
2688 + if (!msdc_cmd_is_ready(host, mrq, cmd))
2689 + return;
2690 +
2691 +@@ -896,7 +897,6 @@ static void msdc_start_command(struct msdc_host *host,
2692 +
2693 + cmd->error = 0;
2694 + rawcmd = msdc_cmd_prepare_raw_cmd(host, mrq, cmd);
2695 +- mod_delayed_work(system_wq, &host->req_timeout, DAT_TIMEOUT);
2696 +
2697 + sdr_set_bits(host->base + MSDC_INTEN, cmd_ints_mask);
2698 + writel(cmd->arg, host->base + SDC_ARG);
2699 +diff --git a/drivers/net/dsa/bcm_sf2.c b/drivers/net/dsa/bcm_sf2.c
2700 +index 604c5abc08eb..af666951a959 100644
2701 +--- a/drivers/net/dsa/bcm_sf2.c
2702 ++++ b/drivers/net/dsa/bcm_sf2.c
2703 +@@ -1196,12 +1196,16 @@ static int bcm_sf2_sw_probe(struct platform_device *pdev)
2704 + return ret;
2705 + }
2706 +
2707 ++ bcm_sf2_gphy_enable_set(priv->dev->ds, true);
2708 ++
2709 + ret = bcm_sf2_mdio_register(ds);
2710 + if (ret) {
2711 + pr_err("failed to register MDIO bus\n");
2712 + return ret;
2713 + }
2714 +
2715 ++ bcm_sf2_gphy_enable_set(priv->dev->ds, false);
2716 ++
2717 + ret = bcm_sf2_cfp_rst(priv);
2718 + if (ret) {
2719 + pr_err("failed to reset CFP\n");
2720 +diff --git a/drivers/net/dsa/mv88e6xxx/chip.c b/drivers/net/dsa/mv88e6xxx/chip.c
2721 +index 0fff1502267a..be17194487c6 100644
2722 +--- a/drivers/net/dsa/mv88e6xxx/chip.c
2723 ++++ b/drivers/net/dsa/mv88e6xxx/chip.c
2724 +@@ -2527,7 +2527,7 @@ static const struct mv88e6xxx_ops mv88e6141_ops = {
2725 + .port_set_link = mv88e6xxx_port_set_link,
2726 + .port_set_duplex = mv88e6xxx_port_set_duplex,
2727 + .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
2728 +- .port_set_speed = mv88e6390_port_set_speed,
2729 ++ .port_set_speed = mv88e6341_port_set_speed,
2730 + .port_tag_remap = mv88e6095_port_tag_remap,
2731 + .port_set_frame_mode = mv88e6351_port_set_frame_mode,
2732 + .port_set_egress_floods = mv88e6352_port_set_egress_floods,
2733 +@@ -3029,7 +3029,7 @@ static const struct mv88e6xxx_ops mv88e6341_ops = {
2734 + .port_set_link = mv88e6xxx_port_set_link,
2735 + .port_set_duplex = mv88e6xxx_port_set_duplex,
2736 + .port_set_rgmii_delay = mv88e6390_port_set_rgmii_delay,
2737 +- .port_set_speed = mv88e6390_port_set_speed,
2738 ++ .port_set_speed = mv88e6341_port_set_speed,
2739 + .port_tag_remap = mv88e6095_port_tag_remap,
2740 + .port_set_frame_mode = mv88e6351_port_set_frame_mode,
2741 + .port_set_egress_floods = mv88e6352_port_set_egress_floods,
2742 +diff --git a/drivers/net/dsa/mv88e6xxx/port.c b/drivers/net/dsa/mv88e6xxx/port.c
2743 +index 2cffecfe86e3..fd0a88c56031 100644
2744 +--- a/drivers/net/dsa/mv88e6xxx/port.c
2745 ++++ b/drivers/net/dsa/mv88e6xxx/port.c
2746 +@@ -203,8 +203,11 @@ static int mv88e6xxx_port_set_speed(struct mv88e6xxx_chip *chip, int port,
2747 + ctrl = MV88E6XXX_PORT_MAC_CTL_SPEED_1000;
2748 + break;
2749 + case 2500:
2750 +- ctrl = MV88E6390_PORT_MAC_CTL_SPEED_10000 |
2751 +- MV88E6390_PORT_MAC_CTL_ALTSPEED;
2752 ++ if (alt_bit)
2753 ++ ctrl = MV88E6390_PORT_MAC_CTL_SPEED_10000 |
2754 ++ MV88E6390_PORT_MAC_CTL_ALTSPEED;
2755 ++ else
2756 ++ ctrl = MV88E6390_PORT_MAC_CTL_SPEED_10000;
2757 + break;
2758 + case 10000:
2759 + /* all bits set, fall through... */
2760 +@@ -266,6 +269,24 @@ int mv88e6185_port_set_speed(struct mv88e6xxx_chip *chip, int port, int speed)
2761 + return mv88e6xxx_port_set_speed(chip, port, speed, false, false);
2762 + }
2763 +
2764 ++/* Support 10, 100, 200, 1000, 2500 Mbps (e.g. 88E6341) */
2765 ++int mv88e6341_port_set_speed(struct mv88e6xxx_chip *chip, int port, int speed)
2766 ++{
2767 ++ if (speed == SPEED_MAX)
2768 ++ speed = port < 5 ? 1000 : 2500;
2769 ++
2770 ++ if (speed > 2500)
2771 ++ return -EOPNOTSUPP;
2772 ++
2773 ++ if (speed == 200 && port != 0)
2774 ++ return -EOPNOTSUPP;
2775 ++
2776 ++ if (speed == 2500 && port < 5)
2777 ++ return -EOPNOTSUPP;
2778 ++
2779 ++ return mv88e6xxx_port_set_speed(chip, port, speed, !port, true);
2780 ++}
2781 ++
2782 + /* Support 10, 100, 200, 1000 Mbps (e.g. 88E6352 family) */
2783 + int mv88e6352_port_set_speed(struct mv88e6xxx_chip *chip, int port, int speed)
2784 + {
2785 +diff --git a/drivers/net/dsa/mv88e6xxx/port.h b/drivers/net/dsa/mv88e6xxx/port.h
2786 +index ccdc67fe9079..8a645683cf6b 100644
2787 +--- a/drivers/net/dsa/mv88e6xxx/port.h
2788 ++++ b/drivers/net/dsa/mv88e6xxx/port.h
2789 +@@ -262,6 +262,7 @@ int mv88e6xxx_port_set_duplex(struct mv88e6xxx_chip *chip, int port, int dup);
2790 +
2791 + int mv88e6065_port_set_speed(struct mv88e6xxx_chip *chip, int port, int speed);
2792 + int mv88e6185_port_set_speed(struct mv88e6xxx_chip *chip, int port, int speed);
2793 ++int mv88e6341_port_set_speed(struct mv88e6xxx_chip *chip, int port, int speed);
2794 + int mv88e6352_port_set_speed(struct mv88e6xxx_chip *chip, int port, int speed);
2795 + int mv88e6390_port_set_speed(struct mv88e6xxx_chip *chip, int port, int speed);
2796 + int mv88e6390x_port_set_speed(struct mv88e6xxx_chip *chip, int port, int speed);
2797 +diff --git a/drivers/net/ethernet/amazon/Kconfig b/drivers/net/ethernet/amazon/Kconfig
2798 +index 99b30353541a..9e87d7b8360f 100644
2799 +--- a/drivers/net/ethernet/amazon/Kconfig
2800 ++++ b/drivers/net/ethernet/amazon/Kconfig
2801 +@@ -17,7 +17,7 @@ if NET_VENDOR_AMAZON
2802 +
2803 + config ENA_ETHERNET
2804 + tristate "Elastic Network Adapter (ENA) support"
2805 +- depends on (PCI_MSI && X86)
2806 ++ depends on PCI_MSI && !CPU_BIG_ENDIAN
2807 + ---help---
2808 + This driver supports Elastic Network Adapter (ENA)"
2809 +
2810 +diff --git a/drivers/net/ethernet/broadcom/genet/bcmgenet.c b/drivers/net/ethernet/broadcom/genet/bcmgenet.c
2811 +index 1cc4fb27c13b..b6af286fa5c7 100644
2812 +--- a/drivers/net/ethernet/broadcom/genet/bcmgenet.c
2813 ++++ b/drivers/net/ethernet/broadcom/genet/bcmgenet.c
2814 +@@ -1138,7 +1138,7 @@ static int bcmgenet_power_down(struct bcmgenet_priv *priv,
2815 + break;
2816 + }
2817 +
2818 +- return 0;
2819 ++ return ret;
2820 + }
2821 +
2822 + static void bcmgenet_power_up(struct bcmgenet_priv *priv,
2823 +diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hns3_enet.c b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hns3_enet.c
2824 +index 5483cb23c08a..e9cff8ed5e07 100644
2825 +--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hns3_enet.c
2826 ++++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hns3_enet.c
2827 +@@ -2300,7 +2300,7 @@ static int hns3_get_vector_ring_chain(struct hns3_enet_tqp_vector *tqp_vector,
2828 + chain = devm_kzalloc(&pdev->dev, sizeof(*chain),
2829 + GFP_KERNEL);
2830 + if (!chain)
2831 +- return -ENOMEM;
2832 ++ goto err_free_chain;
2833 +
2834 + cur_chain->next = chain;
2835 + chain->tqp_index = tx_ring->tqp->tqp_index;
2836 +@@ -2324,7 +2324,7 @@ static int hns3_get_vector_ring_chain(struct hns3_enet_tqp_vector *tqp_vector,
2837 + while (rx_ring) {
2838 + chain = devm_kzalloc(&pdev->dev, sizeof(*chain), GFP_KERNEL);
2839 + if (!chain)
2840 +- return -ENOMEM;
2841 ++ goto err_free_chain;
2842 +
2843 + cur_chain->next = chain;
2844 + chain->tqp_index = rx_ring->tqp->tqp_index;
2845 +@@ -2336,6 +2336,16 @@ static int hns3_get_vector_ring_chain(struct hns3_enet_tqp_vector *tqp_vector,
2846 + }
2847 +
2848 + return 0;
2849 ++
2850 ++err_free_chain:
2851 ++ cur_chain = head->next;
2852 ++ while (cur_chain) {
2853 ++ chain = cur_chain->next;
2854 ++ devm_kfree(&pdev->dev, chain);
2855 ++ cur_chain = chain;
2856 ++ }
2857 ++
2858 ++ return -ENOMEM;
2859 + }
2860 +
2861 + static void hns3_free_vector_ring_chain(struct hns3_enet_tqp_vector *tqp_vector,
2862 +@@ -2530,8 +2540,10 @@ static int hns3_queue_to_ring(struct hnae3_queue *tqp,
2863 + return ret;
2864 +
2865 + ret = hns3_ring_get_cfg(tqp, priv, HNAE3_RING_TYPE_RX);
2866 +- if (ret)
2867 ++ if (ret) {
2868 ++ devm_kfree(priv->dev, priv->ring_data[tqp->tqp_index].ring);
2869 + return ret;
2870 ++ }
2871 +
2872 + return 0;
2873 + }
2874 +@@ -2556,6 +2568,12 @@ static int hns3_get_ring_config(struct hns3_nic_priv *priv)
2875 +
2876 + return 0;
2877 + err:
2878 ++ while (i--) {
2879 ++ devm_kfree(priv->dev, priv->ring_data[i].ring);
2880 ++ devm_kfree(priv->dev,
2881 ++ priv->ring_data[i + h->kinfo.num_tqps].ring);
2882 ++ }
2883 ++
2884 + devm_kfree(&pdev->dev, priv->ring_data);
2885 + return ret;
2886 + }
2887 +diff --git a/drivers/net/ethernet/intel/igb/igb_ptp.c b/drivers/net/ethernet/intel/igb/igb_ptp.c
2888 +index 0746b19ec6d3..295d27f33104 100644
2889 +--- a/drivers/net/ethernet/intel/igb/igb_ptp.c
2890 ++++ b/drivers/net/ethernet/intel/igb/igb_ptp.c
2891 +@@ -65,9 +65,15 @@
2892 + *
2893 + * The 40 bit 82580 SYSTIM overflows every
2894 + * 2^40 * 10^-9 / 60 = 18.3 minutes.
2895 ++ *
2896 ++ * SYSTIM is converted to real time using a timecounter. As
2897 ++ * timecounter_cyc2time() allows old timestamps, the timecounter
2898 ++ * needs to be updated at least once per half of the SYSTIM interval.
2899 ++ * Scheduling of delayed work is not very accurate, so we aim for 8
2900 ++ * minutes to be sure the actual interval is shorter than 9.16 minutes.
2901 + */
2902 +
2903 +-#define IGB_SYSTIM_OVERFLOW_PERIOD (HZ * 60 * 9)
2904 ++#define IGB_SYSTIM_OVERFLOW_PERIOD (HZ * 60 * 8)
2905 + #define IGB_PTP_TX_TIMEOUT (HZ * 15)
2906 + #define INCPERIOD_82576 BIT(E1000_TIMINCA_16NS_SHIFT)
2907 + #define INCVALUE_82576_MASK GENMASK(E1000_TIMINCA_16NS_SHIFT - 1, 0)
2908 +diff --git a/drivers/net/ethernet/mellanox/mlx4/en_ethtool.c b/drivers/net/ethernet/mellanox/mlx4/en_ethtool.c
2909 +index d631cd94ee63..25a15bdc125e 100644
2910 +--- a/drivers/net/ethernet/mellanox/mlx4/en_ethtool.c
2911 ++++ b/drivers/net/ethernet/mellanox/mlx4/en_ethtool.c
2912 +@@ -1722,6 +1722,7 @@ static int mlx4_en_get_rxnfc(struct net_device *dev, struct ethtool_rxnfc *cmd,
2913 + err = mlx4_en_get_flow(dev, cmd, cmd->fs.location);
2914 + break;
2915 + case ETHTOOL_GRXCLSRLALL:
2916 ++ cmd->data = MAX_NUM_OF_FS_RULES;
2917 + while ((!err || err == -ENOENT) && priority < cmd->rule_cnt) {
2918 + err = mlx4_en_get_flow(dev, cmd, i);
2919 + if (!err)
2920 +diff --git a/drivers/net/ethernet/mellanox/mlx5/core/eswitch.c b/drivers/net/ethernet/mellanox/mlx5/core/eswitch.c
2921 +index 090d54275a7d..387758fc6be4 100644
2922 +--- a/drivers/net/ethernet/mellanox/mlx5/core/eswitch.c
2923 ++++ b/drivers/net/ethernet/mellanox/mlx5/core/eswitch.c
2924 +@@ -1783,7 +1783,7 @@ int mlx5_eswitch_set_vport_state(struct mlx5_eswitch *esw,
2925 +
2926 + unlock:
2927 + mutex_unlock(&esw->state_lock);
2928 +- return 0;
2929 ++ return err;
2930 + }
2931 +
2932 + int mlx5_eswitch_get_vport_config(struct mlx5_eswitch *esw,
2933 +diff --git a/drivers/net/ethernet/mellanox/mlxfw/mlxfw_fsm.c b/drivers/net/ethernet/mellanox/mlxfw/mlxfw_fsm.c
2934 +index 2cf89126fb23..d765e7a69d6b 100644
2935 +--- a/drivers/net/ethernet/mellanox/mlxfw/mlxfw_fsm.c
2936 ++++ b/drivers/net/ethernet/mellanox/mlxfw/mlxfw_fsm.c
2937 +@@ -86,6 +86,8 @@ retry:
2938 + return err;
2939 +
2940 + if (fsm_state_err != MLXFW_FSM_STATE_ERR_OK) {
2941 ++ fsm_state_err = min_t(enum mlxfw_fsm_state_err,
2942 ++ fsm_state_err, MLXFW_FSM_STATE_ERR_MAX);
2943 + pr_err("Firmware flash failed: %s\n",
2944 + mlxfw_fsm_state_err_str[fsm_state_err]);
2945 + return -EINVAL;
2946 +diff --git a/drivers/net/ethernet/qlogic/qed/qed.h b/drivers/net/ethernet/qlogic/qed/qed.h
2947 +index 91003bc6f00b..6c4714a8b54c 100644
2948 +--- a/drivers/net/ethernet/qlogic/qed/qed.h
2949 ++++ b/drivers/net/ethernet/qlogic/qed/qed.h
2950 +@@ -829,7 +829,7 @@ u16 qed_get_cm_pq_idx_vf(struct qed_hwfn *p_hwfn, u16 vf);
2951 + /* Prototypes */
2952 + int qed_fill_dev_info(struct qed_dev *cdev,
2953 + struct qed_dev_info *dev_info);
2954 +-void qed_link_update(struct qed_hwfn *hwfn);
2955 ++void qed_link_update(struct qed_hwfn *hwfn, struct qed_ptt *ptt);
2956 + u32 qed_unzip_data(struct qed_hwfn *p_hwfn,
2957 + u32 input_len, u8 *input_buf,
2958 + u32 max_size, u8 *unzip_buf);
2959 +diff --git a/drivers/net/ethernet/qlogic/qed/qed_main.c b/drivers/net/ethernet/qlogic/qed/qed_main.c
2960 +index 557332f1f886..52e747fd9c83 100644
2961 +--- a/drivers/net/ethernet/qlogic/qed/qed_main.c
2962 ++++ b/drivers/net/ethernet/qlogic/qed/qed_main.c
2963 +@@ -1389,6 +1389,7 @@ static int qed_get_link_data(struct qed_hwfn *hwfn,
2964 + }
2965 +
2966 + static void qed_fill_link(struct qed_hwfn *hwfn,
2967 ++ struct qed_ptt *ptt,
2968 + struct qed_link_output *if_link)
2969 + {
2970 + struct qed_mcp_link_params params;
2971 +@@ -1469,7 +1470,7 @@ static void qed_fill_link(struct qed_hwfn *hwfn,
2972 +
2973 + /* TODO - fill duplex properly */
2974 + if_link->duplex = DUPLEX_FULL;
2975 +- qed_mcp_get_media_type(hwfn->cdev, &media_type);
2976 ++ qed_mcp_get_media_type(hwfn, ptt, &media_type);
2977 + if_link->port = qed_get_port_type(media_type);
2978 +
2979 + if_link->autoneg = params.speed.autoneg;
2980 +@@ -1525,21 +1526,34 @@ static void qed_fill_link(struct qed_hwfn *hwfn,
2981 + static void qed_get_current_link(struct qed_dev *cdev,
2982 + struct qed_link_output *if_link)
2983 + {
2984 ++ struct qed_hwfn *hwfn;
2985 ++ struct qed_ptt *ptt;
2986 + int i;
2987 +
2988 +- qed_fill_link(&cdev->hwfns[0], if_link);
2989 ++ hwfn = &cdev->hwfns[0];
2990 ++ if (IS_PF(cdev)) {
2991 ++ ptt = qed_ptt_acquire(hwfn);
2992 ++ if (ptt) {
2993 ++ qed_fill_link(hwfn, ptt, if_link);
2994 ++ qed_ptt_release(hwfn, ptt);
2995 ++ } else {
2996 ++ DP_NOTICE(hwfn, "Failed to fill link; No PTT\n");
2997 ++ }
2998 ++ } else {
2999 ++ qed_fill_link(hwfn, NULL, if_link);
3000 ++ }
3001 +
3002 + for_each_hwfn(cdev, i)
3003 + qed_inform_vf_link_state(&cdev->hwfns[i]);
3004 + }
3005 +
3006 +-void qed_link_update(struct qed_hwfn *hwfn)
3007 ++void qed_link_update(struct qed_hwfn *hwfn, struct qed_ptt *ptt)
3008 + {
3009 + void *cookie = hwfn->cdev->ops_cookie;
3010 + struct qed_common_cb_ops *op = hwfn->cdev->protocol_ops.common;
3011 + struct qed_link_output if_link;
3012 +
3013 +- qed_fill_link(hwfn, &if_link);
3014 ++ qed_fill_link(hwfn, ptt, &if_link);
3015 + qed_inform_vf_link_state(hwfn);
3016 +
3017 + if (IS_LEAD_HWFN(hwfn) && cookie)
3018 +diff --git a/drivers/net/ethernet/qlogic/qed/qed_mcp.c b/drivers/net/ethernet/qlogic/qed/qed_mcp.c
3019 +index 7938abe9a301..ef17ca09d303 100644
3020 +--- a/drivers/net/ethernet/qlogic/qed/qed_mcp.c
3021 ++++ b/drivers/net/ethernet/qlogic/qed/qed_mcp.c
3022 +@@ -1352,7 +1352,7 @@ static void qed_mcp_handle_link_change(struct qed_hwfn *p_hwfn,
3023 + if (p_hwfn->mcp_info->capabilities & FW_MB_PARAM_FEATURE_SUPPORT_EEE)
3024 + qed_mcp_read_eee_config(p_hwfn, p_ptt, p_link);
3025 +
3026 +- qed_link_update(p_hwfn);
3027 ++ qed_link_update(p_hwfn, p_ptt);
3028 + out:
3029 + spin_unlock_bh(&p_hwfn->mcp_info->link_lock);
3030 + }
3031 +@@ -1722,12 +1722,10 @@ int qed_mcp_get_mbi_ver(struct qed_hwfn *p_hwfn,
3032 + return 0;
3033 + }
3034 +
3035 +-int qed_mcp_get_media_type(struct qed_dev *cdev, u32 *p_media_type)
3036 ++int qed_mcp_get_media_type(struct qed_hwfn *p_hwfn,
3037 ++ struct qed_ptt *p_ptt, u32 *p_media_type)
3038 + {
3039 +- struct qed_hwfn *p_hwfn = &cdev->hwfns[0];
3040 +- struct qed_ptt *p_ptt;
3041 +-
3042 +- if (IS_VF(cdev))
3043 ++ if (IS_VF(p_hwfn->cdev))
3044 + return -EINVAL;
3045 +
3046 + if (!qed_mcp_is_init(p_hwfn)) {
3047 +@@ -1735,16 +1733,15 @@ int qed_mcp_get_media_type(struct qed_dev *cdev, u32 *p_media_type)
3048 + return -EBUSY;
3049 + }
3050 +
3051 +- *p_media_type = MEDIA_UNSPECIFIED;
3052 +-
3053 +- p_ptt = qed_ptt_acquire(p_hwfn);
3054 +- if (!p_ptt)
3055 +- return -EBUSY;
3056 +-
3057 +- *p_media_type = qed_rd(p_hwfn, p_ptt, p_hwfn->mcp_info->port_addr +
3058 +- offsetof(struct public_port, media_type));
3059 ++ if (!p_ptt) {
3060 ++ *p_media_type = MEDIA_UNSPECIFIED;
3061 ++ return -EINVAL;
3062 ++ }
3063 +
3064 +- qed_ptt_release(p_hwfn, p_ptt);
3065 ++ *p_media_type = qed_rd(p_hwfn, p_ptt,
3066 ++ p_hwfn->mcp_info->port_addr +
3067 ++ offsetof(struct public_port,
3068 ++ media_type));
3069 +
3070 + return 0;
3071 + }
3072 +diff --git a/drivers/net/ethernet/qlogic/qed/qed_mcp.h b/drivers/net/ethernet/qlogic/qed/qed_mcp.h
3073 +index f1fe5e3427ea..8fcdb2c3e5db 100644
3074 +--- a/drivers/net/ethernet/qlogic/qed/qed_mcp.h
3075 ++++ b/drivers/net/ethernet/qlogic/qed/qed_mcp.h
3076 +@@ -284,14 +284,15 @@ int qed_mcp_get_mbi_ver(struct qed_hwfn *p_hwfn,
3077 + * @brief Get media type value of the port.
3078 + *
3079 + * @param cdev - qed dev pointer
3080 ++ * @param p_ptt
3081 + * @param mfw_ver - media type value
3082 + *
3083 + * @return int -
3084 + * 0 - Operation was successul.
3085 + * -EBUSY - Operation failed
3086 + */
3087 +-int qed_mcp_get_media_type(struct qed_dev *cdev,
3088 +- u32 *media_type);
3089 ++int qed_mcp_get_media_type(struct qed_hwfn *p_hwfn,
3090 ++ struct qed_ptt *p_ptt, u32 *media_type);
3091 +
3092 + /**
3093 + * @brief General function for sending commands to the MCP
3094 +diff --git a/drivers/net/ethernet/qlogic/qed/qed_vf.c b/drivers/net/ethernet/qlogic/qed/qed_vf.c
3095 +index 3220086f99de..a2a9921b467b 100644
3096 +--- a/drivers/net/ethernet/qlogic/qed/qed_vf.c
3097 ++++ b/drivers/net/ethernet/qlogic/qed/qed_vf.c
3098 +@@ -1669,7 +1669,7 @@ static void qed_handle_bulletin_change(struct qed_hwfn *hwfn)
3099 + ops->ports_update(cookie, vxlan_port, geneve_port);
3100 +
3101 + /* Always update link configuration according to bulletin */
3102 +- qed_link_update(hwfn);
3103 ++ qed_link_update(hwfn, NULL);
3104 + }
3105 +
3106 + void qed_iov_vf_task(struct work_struct *work)
3107 +diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_dcb.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_dcb.c
3108 +index 4b76c69fe86d..834208e55f7b 100644
3109 +--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_dcb.c
3110 ++++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_dcb.c
3111 +@@ -883,7 +883,7 @@ static u8 qlcnic_dcb_get_capability(struct net_device *netdev, int capid,
3112 + struct qlcnic_adapter *adapter = netdev_priv(netdev);
3113 +
3114 + if (!test_bit(QLCNIC_DCB_STATE, &adapter->dcb->state))
3115 +- return 0;
3116 ++ return 1;
3117 +
3118 + switch (capid) {
3119 + case DCB_CAP_ATTR_PG:
3120 +diff --git a/drivers/net/ethernet/sfc/ptp.c b/drivers/net/ethernet/sfc/ptp.c
3121 +index 60cdb97f58e2..f22690792697 100644
3122 +--- a/drivers/net/ethernet/sfc/ptp.c
3123 ++++ b/drivers/net/ethernet/sfc/ptp.c
3124 +@@ -1320,7 +1320,8 @@ void efx_ptp_remove(struct efx_nic *efx)
3125 + (void)efx_ptp_disable(efx);
3126 +
3127 + cancel_work_sync(&efx->ptp_data->work);
3128 +- cancel_work_sync(&efx->ptp_data->pps_work);
3129 ++ if (efx->ptp_data->pps_workwq)
3130 ++ cancel_work_sync(&efx->ptp_data->pps_work);
3131 +
3132 + skb_queue_purge(&efx->ptp_data->rxq);
3133 + skb_queue_purge(&efx->ptp_data->txq);
3134 +diff --git a/drivers/net/ethernet/ti/cpsw.c b/drivers/net/ethernet/ti/cpsw.c
3135 +index 8cb44eabc283..a44838aac97d 100644
3136 +--- a/drivers/net/ethernet/ti/cpsw.c
3137 ++++ b/drivers/net/ethernet/ti/cpsw.c
3138 +@@ -601,6 +601,7 @@ static void cpsw_set_promiscious(struct net_device *ndev, bool enable)
3139 +
3140 + /* Clear all mcast from ALE */
3141 + cpsw_ale_flush_multicast(ale, ALE_ALL_PORTS, -1);
3142 ++ __dev_mc_unsync(ndev, NULL);
3143 +
3144 + /* Flood All Unicast Packets to Host port */
3145 + cpsw_ale_control_set(ale, 0, ALE_P0_UNI_FLOOD, 1);
3146 +diff --git a/drivers/net/macsec.c b/drivers/net/macsec.c
3147 +index 9bcb7c3e879f..9bb65e0af7dd 100644
3148 +--- a/drivers/net/macsec.c
3149 ++++ b/drivers/net/macsec.c
3150 +@@ -2798,9 +2798,6 @@ static int macsec_dev_open(struct net_device *dev)
3151 + struct net_device *real_dev = macsec->real_dev;
3152 + int err;
3153 +
3154 +- if (!(real_dev->flags & IFF_UP))
3155 +- return -ENETDOWN;
3156 +-
3157 + err = dev_uc_add(real_dev, dev->dev_addr);
3158 + if (err < 0)
3159 + return err;
3160 +@@ -3273,6 +3270,9 @@ static int macsec_newlink(struct net *net, struct net_device *dev,
3161 + if (err < 0)
3162 + goto del_dev;
3163 +
3164 ++ netif_stacked_transfer_operstate(real_dev, dev);
3165 ++ linkwatch_fire_event(dev);
3166 ++
3167 + macsec_generation++;
3168 +
3169 + return 0;
3170 +@@ -3444,6 +3444,20 @@ static int macsec_notify(struct notifier_block *this, unsigned long event,
3171 + return NOTIFY_DONE;
3172 +
3173 + switch (event) {
3174 ++ case NETDEV_DOWN:
3175 ++ case NETDEV_UP:
3176 ++ case NETDEV_CHANGE: {
3177 ++ struct macsec_dev *m, *n;
3178 ++ struct macsec_rxh_data *rxd;
3179 ++
3180 ++ rxd = macsec_data_rtnl(real_dev);
3181 ++ list_for_each_entry_safe(m, n, &rxd->secys, secys) {
3182 ++ struct net_device *dev = m->secy.netdev;
3183 ++
3184 ++ netif_stacked_transfer_operstate(real_dev, dev);
3185 ++ }
3186 ++ break;
3187 ++ }
3188 + case NETDEV_UNREGISTER: {
3189 + struct macsec_dev *m, *n;
3190 + struct macsec_rxh_data *rxd;
3191 +diff --git a/drivers/net/ntb_netdev.c b/drivers/net/ntb_netdev.c
3192 +index 0250aa9ae2cb..97bf49ad81a6 100644
3193 +--- a/drivers/net/ntb_netdev.c
3194 ++++ b/drivers/net/ntb_netdev.c
3195 +@@ -236,7 +236,7 @@ static void ntb_netdev_tx_timer(unsigned long data)
3196 + struct ntb_netdev *dev = netdev_priv(ndev);
3197 +
3198 + if (ntb_transport_tx_free_entry(dev->qp) < tx_stop) {
3199 +- mod_timer(&dev->tx_timer, jiffies + msecs_to_jiffies(tx_time));
3200 ++ mod_timer(&dev->tx_timer, jiffies + usecs_to_jiffies(tx_time));
3201 + } else {
3202 + /* Make sure anybody stopping the queue after this sees the new
3203 + * value of ntb_transport_tx_free_entry()
3204 +diff --git a/drivers/net/phy/dp83867.c b/drivers/net/phy/dp83867.c
3205 +index 12b09e6e03ba..e03e91d5f1b1 100644
3206 +--- a/drivers/net/phy/dp83867.c
3207 ++++ b/drivers/net/phy/dp83867.c
3208 +@@ -33,10 +33,18 @@
3209 +
3210 + /* Extended Registers */
3211 + #define DP83867_CFG4 0x0031
3212 ++#define DP83867_CFG4_SGMII_ANEG_MASK (BIT(5) | BIT(6))
3213 ++#define DP83867_CFG4_SGMII_ANEG_TIMER_11MS (3 << 5)
3214 ++#define DP83867_CFG4_SGMII_ANEG_TIMER_800US (2 << 5)
3215 ++#define DP83867_CFG4_SGMII_ANEG_TIMER_2US (1 << 5)
3216 ++#define DP83867_CFG4_SGMII_ANEG_TIMER_16MS (0 << 5)
3217 ++
3218 + #define DP83867_RGMIICTL 0x0032
3219 + #define DP83867_STRAP_STS1 0x006E
3220 + #define DP83867_RGMIIDCTL 0x0086
3221 + #define DP83867_IO_MUX_CFG 0x0170
3222 ++#define DP83867_10M_SGMII_CFG 0x016F
3223 ++#define DP83867_10M_SGMII_RATE_ADAPT_MASK BIT(7)
3224 +
3225 + #define DP83867_SW_RESET BIT(15)
3226 + #define DP83867_SW_RESTART BIT(14)
3227 +@@ -283,6 +291,35 @@ static int dp83867_config_init(struct phy_device *phydev)
3228 + }
3229 + }
3230 +
3231 ++ if (phydev->interface == PHY_INTERFACE_MODE_SGMII) {
3232 ++ /* For support SPEED_10 in SGMII mode
3233 ++ * DP83867_10M_SGMII_RATE_ADAPT bit
3234 ++ * has to be cleared by software. That
3235 ++ * does not affect SPEED_100 and
3236 ++ * SPEED_1000.
3237 ++ */
3238 ++ val = phy_read_mmd(phydev, DP83867_DEVADDR,
3239 ++ DP83867_10M_SGMII_CFG);
3240 ++ val &= ~DP83867_10M_SGMII_RATE_ADAPT_MASK;
3241 ++ ret = phy_write_mmd(phydev, DP83867_DEVADDR,
3242 ++ DP83867_10M_SGMII_CFG, val);
3243 ++
3244 ++ if (ret)
3245 ++ return ret;
3246 ++
3247 ++ /* After reset SGMII Autoneg timer is set to 2us (bits 6 and 5
3248 ++ * are 01). That is not enough to finalize autoneg on some
3249 ++ * devices. Increase this timer duration to maximum 16ms.
3250 ++ */
3251 ++ val = phy_read_mmd(phydev, DP83867_DEVADDR, DP83867_CFG4);
3252 ++ val &= ~DP83867_CFG4_SGMII_ANEG_MASK;
3253 ++ val |= DP83867_CFG4_SGMII_ANEG_TIMER_16MS;
3254 ++ ret = phy_write_mmd(phydev, DP83867_DEVADDR, DP83867_CFG4, val);
3255 ++
3256 ++ if (ret)
3257 ++ return ret;
3258 ++ }
3259 ++
3260 + /* Enable Interrupt output INT_OE in CFG3 register */
3261 + if (phy_interrupt_is_valid(phydev)) {
3262 + val = phy_read(phydev, DP83867_CFG3);
3263 +diff --git a/drivers/net/vrf.c b/drivers/net/vrf.c
3264 +index 03e4fcdfeab7..e0cea5c05f0e 100644
3265 +--- a/drivers/net/vrf.c
3266 ++++ b/drivers/net/vrf.c
3267 +@@ -996,24 +996,23 @@ static struct sk_buff *vrf_ip6_rcv(struct net_device *vrf_dev,
3268 + struct sk_buff *skb)
3269 + {
3270 + int orig_iif = skb->skb_iif;
3271 +- bool need_strict;
3272 ++ bool need_strict = rt6_need_strict(&ipv6_hdr(skb)->daddr);
3273 ++ bool is_ndisc = ipv6_ndisc_frame(skb);
3274 +
3275 +- /* loopback traffic; do not push through packet taps again.
3276 +- * Reset pkt_type for upper layers to process skb
3277 ++ /* loopback, multicast & non-ND link-local traffic; do not push through
3278 ++ * packet taps again. Reset pkt_type for upper layers to process skb
3279 + */
3280 +- if (skb->pkt_type == PACKET_LOOPBACK) {
3281 ++ if (skb->pkt_type == PACKET_LOOPBACK || (need_strict && !is_ndisc)) {
3282 + skb->dev = vrf_dev;
3283 + skb->skb_iif = vrf_dev->ifindex;
3284 + IP6CB(skb)->flags |= IP6SKB_L3SLAVE;
3285 +- skb->pkt_type = PACKET_HOST;
3286 ++ if (skb->pkt_type == PACKET_LOOPBACK)
3287 ++ skb->pkt_type = PACKET_HOST;
3288 + goto out;
3289 + }
3290 +
3291 +- /* if packet is NDISC or addressed to multicast or link-local
3292 +- * then keep the ingress interface
3293 +- */
3294 +- need_strict = rt6_need_strict(&ipv6_hdr(skb)->daddr);
3295 +- if (!ipv6_ndisc_frame(skb) && !need_strict) {
3296 ++ /* if packet is NDISC then keep the ingress interface */
3297 ++ if (!is_ndisc) {
3298 + vrf_rx_stats(vrf_dev, skb->len);
3299 + skb->dev = vrf_dev;
3300 + skb->skb_iif = vrf_dev->ifindex;
3301 +diff --git a/drivers/net/wireless/ath/ath10k/pci.c b/drivers/net/wireless/ath/ath10k/pci.c
3302 +index 27ab3eb47534..0298ddc1ff06 100644
3303 +--- a/drivers/net/wireless/ath/ath10k/pci.c
3304 ++++ b/drivers/net/wireless/ath/ath10k/pci.c
3305 +@@ -1039,10 +1039,9 @@ int ath10k_pci_diag_write_mem(struct ath10k *ar, u32 address,
3306 + struct ath10k_ce *ce = ath10k_ce_priv(ar);
3307 + int ret = 0;
3308 + u32 *buf;
3309 +- unsigned int completed_nbytes, orig_nbytes, remaining_bytes;
3310 ++ unsigned int completed_nbytes, alloc_nbytes, remaining_bytes;
3311 + struct ath10k_ce_pipe *ce_diag;
3312 + void *data_buf = NULL;
3313 +- u32 ce_data; /* Host buffer address in CE space */
3314 + dma_addr_t ce_data_base = 0;
3315 + int i;
3316 +
3317 +@@ -1056,9 +1055,10 @@ int ath10k_pci_diag_write_mem(struct ath10k *ar, u32 address,
3318 + * 1) 4-byte alignment
3319 + * 2) Buffer in DMA-able space
3320 + */
3321 +- orig_nbytes = nbytes;
3322 ++ alloc_nbytes = min_t(unsigned int, nbytes, DIAG_TRANSFER_LIMIT);
3323 ++
3324 + data_buf = (unsigned char *)dma_alloc_coherent(ar->dev,
3325 +- orig_nbytes,
3326 ++ alloc_nbytes,
3327 + &ce_data_base,
3328 + GFP_ATOMIC);
3329 + if (!data_buf) {
3330 +@@ -1066,9 +1066,6 @@ int ath10k_pci_diag_write_mem(struct ath10k *ar, u32 address,
3331 + goto done;
3332 + }
3333 +
3334 +- /* Copy caller's data to allocated DMA buf */
3335 +- memcpy(data_buf, data, orig_nbytes);
3336 +-
3337 + /*
3338 + * The address supplied by the caller is in the
3339 + * Target CPU virtual address space.
3340 +@@ -1081,12 +1078,14 @@ int ath10k_pci_diag_write_mem(struct ath10k *ar, u32 address,
3341 + */
3342 + address = ath10k_pci_targ_cpu_to_ce_addr(ar, address);
3343 +
3344 +- remaining_bytes = orig_nbytes;
3345 +- ce_data = ce_data_base;
3346 ++ remaining_bytes = nbytes;
3347 + while (remaining_bytes) {
3348 + /* FIXME: check cast */
3349 + nbytes = min_t(int, remaining_bytes, DIAG_TRANSFER_LIMIT);
3350 +
3351 ++ /* Copy caller's data to allocated DMA buf */
3352 ++ memcpy(data_buf, data, nbytes);
3353 ++
3354 + /* Set up to receive directly into Target(!) address */
3355 + ret = __ath10k_ce_rx_post_buf(ce_diag, &address, address);
3356 + if (ret != 0)
3357 +@@ -1096,7 +1095,7 @@ int ath10k_pci_diag_write_mem(struct ath10k *ar, u32 address,
3358 + * Request CE to send caller-supplied data that
3359 + * was copied to bounce buffer to Target(!) address.
3360 + */
3361 +- ret = ath10k_ce_send_nolock(ce_diag, NULL, (u32)ce_data,
3362 ++ ret = ath10k_ce_send_nolock(ce_diag, NULL, ce_data_base,
3363 + nbytes, 0, 0);
3364 + if (ret != 0)
3365 + goto done;
3366 +@@ -1137,12 +1136,12 @@ int ath10k_pci_diag_write_mem(struct ath10k *ar, u32 address,
3367 +
3368 + remaining_bytes -= nbytes;
3369 + address += nbytes;
3370 +- ce_data += nbytes;
3371 ++ data += nbytes;
3372 + }
3373 +
3374 + done:
3375 + if (data_buf) {
3376 +- dma_free_coherent(ar->dev, orig_nbytes, data_buf,
3377 ++ dma_free_coherent(ar->dev, alloc_nbytes, data_buf,
3378 + ce_data_base);
3379 + }
3380 +
3381 +diff --git a/drivers/net/wireless/ath/ath10k/usb.c b/drivers/net/wireless/ath/ath10k/usb.c
3382 +index f09a4ad2e9de..f9c79e21ab22 100644
3383 +--- a/drivers/net/wireless/ath/ath10k/usb.c
3384 ++++ b/drivers/net/wireless/ath/ath10k/usb.c
3385 +@@ -49,6 +49,10 @@ ath10k_usb_alloc_urb_from_pipe(struct ath10k_usb_pipe *pipe)
3386 + struct ath10k_urb_context *urb_context = NULL;
3387 + unsigned long flags;
3388 +
3389 ++ /* bail if this pipe is not initialized */
3390 ++ if (!pipe->ar_usb)
3391 ++ return NULL;
3392 ++
3393 + spin_lock_irqsave(&pipe->ar_usb->cs_lock, flags);
3394 + if (!list_empty(&pipe->urb_list_head)) {
3395 + urb_context = list_first_entry(&pipe->urb_list_head,
3396 +@@ -66,6 +70,10 @@ static void ath10k_usb_free_urb_to_pipe(struct ath10k_usb_pipe *pipe,
3397 + {
3398 + unsigned long flags;
3399 +
3400 ++ /* bail if this pipe is not initialized */
3401 ++ if (!pipe->ar_usb)
3402 ++ return;
3403 ++
3404 + spin_lock_irqsave(&pipe->ar_usb->cs_lock, flags);
3405 +
3406 + pipe->urb_cnt++;
3407 +diff --git a/drivers/net/wireless/ath/ath9k/ar9003_eeprom.c b/drivers/net/wireless/ath/ath9k/ar9003_eeprom.c
3408 +index 3dbfd86ebe36..76385834a7de 100644
3409 +--- a/drivers/net/wireless/ath/ath9k/ar9003_eeprom.c
3410 ++++ b/drivers/net/wireless/ath/ath9k/ar9003_eeprom.c
3411 +@@ -4116,7 +4116,7 @@ static void ar9003_hw_thermometer_apply(struct ath_hw *ah)
3412 +
3413 + static void ar9003_hw_thermo_cal_apply(struct ath_hw *ah)
3414 + {
3415 +- u32 data, ko, kg;
3416 ++ u32 data = 0, ko, kg;
3417 +
3418 + if (!AR_SREV_9462_20_OR_LATER(ah))
3419 + return;
3420 +diff --git a/drivers/net/wireless/ath/wil6210/wmi.c b/drivers/net/wireless/ath/wil6210/wmi.c
3421 +index d63d7c326801..798516f42f2f 100644
3422 +--- a/drivers/net/wireless/ath/wil6210/wmi.c
3423 ++++ b/drivers/net/wireless/ath/wil6210/wmi.c
3424 +@@ -1002,15 +1002,16 @@ int wmi_call(struct wil6210_priv *wil, u16 cmdid, void *buf, u16 len,
3425 + {
3426 + int rc;
3427 + unsigned long remain;
3428 ++ ulong flags;
3429 +
3430 + mutex_lock(&wil->wmi_mutex);
3431 +
3432 +- spin_lock(&wil->wmi_ev_lock);
3433 ++ spin_lock_irqsave(&wil->wmi_ev_lock, flags);
3434 + wil->reply_id = reply_id;
3435 + wil->reply_buf = reply;
3436 + wil->reply_size = reply_size;
3437 + reinit_completion(&wil->wmi_call);
3438 +- spin_unlock(&wil->wmi_ev_lock);
3439 ++ spin_unlock_irqrestore(&wil->wmi_ev_lock, flags);
3440 +
3441 + rc = __wmi_send(wil, cmdid, buf, len);
3442 + if (rc)
3443 +@@ -1030,11 +1031,11 @@ int wmi_call(struct wil6210_priv *wil, u16 cmdid, void *buf, u16 len,
3444 + }
3445 +
3446 + out:
3447 +- spin_lock(&wil->wmi_ev_lock);
3448 ++ spin_lock_irqsave(&wil->wmi_ev_lock, flags);
3449 + wil->reply_id = 0;
3450 + wil->reply_buf = NULL;
3451 + wil->reply_size = 0;
3452 +- spin_unlock(&wil->wmi_ev_lock);
3453 ++ spin_unlock_irqrestore(&wil->wmi_ev_lock, flags);
3454 +
3455 + mutex_unlock(&wil->wmi_mutex);
3456 +
3457 +diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmsmac/mac80211_if.c b/drivers/net/wireless/broadcom/brcm80211/brcmsmac/mac80211_if.c
3458 +index ddfdfe177e24..66f1f41b1380 100644
3459 +--- a/drivers/net/wireless/broadcom/brcm80211/brcmsmac/mac80211_if.c
3460 ++++ b/drivers/net/wireless/broadcom/brcm80211/brcmsmac/mac80211_if.c
3461 +@@ -502,6 +502,7 @@ brcms_ops_add_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
3462 + }
3463 +
3464 + spin_lock_bh(&wl->lock);
3465 ++ wl->wlc->vif = vif;
3466 + wl->mute_tx = false;
3467 + brcms_c_mute(wl->wlc, false);
3468 + if (vif->type == NL80211_IFTYPE_STATION)
3469 +@@ -519,6 +520,11 @@ brcms_ops_add_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
3470 + static void
3471 + brcms_ops_remove_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
3472 + {
3473 ++ struct brcms_info *wl = hw->priv;
3474 ++
3475 ++ spin_lock_bh(&wl->lock);
3476 ++ wl->wlc->vif = NULL;
3477 ++ spin_unlock_bh(&wl->lock);
3478 + }
3479 +
3480 + static int brcms_ops_config(struct ieee80211_hw *hw, u32 changed)
3481 +@@ -840,8 +846,8 @@ brcms_ops_ampdu_action(struct ieee80211_hw *hw,
3482 + status = brcms_c_aggregatable(wl->wlc, tid);
3483 + spin_unlock_bh(&wl->lock);
3484 + if (!status) {
3485 +- brcms_err(wl->wlc->hw->d11core,
3486 +- "START: tid %d is not agg\'able\n", tid);
3487 ++ brcms_dbg_ht(wl->wlc->hw->d11core,
3488 ++ "START: tid %d is not agg\'able\n", tid);
3489 + return -EINVAL;
3490 + }
3491 + ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid);
3492 +@@ -937,6 +943,25 @@ static void brcms_ops_set_tsf(struct ieee80211_hw *hw,
3493 + spin_unlock_bh(&wl->lock);
3494 + }
3495 +
3496 ++static int brcms_ops_beacon_set_tim(struct ieee80211_hw *hw,
3497 ++ struct ieee80211_sta *sta, bool set)
3498 ++{
3499 ++ struct brcms_info *wl = hw->priv;
3500 ++ struct sk_buff *beacon = NULL;
3501 ++ u16 tim_offset = 0;
3502 ++
3503 ++ spin_lock_bh(&wl->lock);
3504 ++ if (wl->wlc->vif)
3505 ++ beacon = ieee80211_beacon_get_tim(hw, wl->wlc->vif,
3506 ++ &tim_offset, NULL);
3507 ++ if (beacon)
3508 ++ brcms_c_set_new_beacon(wl->wlc, beacon, tim_offset,
3509 ++ wl->wlc->vif->bss_conf.dtim_period);
3510 ++ spin_unlock_bh(&wl->lock);
3511 ++
3512 ++ return 0;
3513 ++}
3514 ++
3515 + static const struct ieee80211_ops brcms_ops = {
3516 + .tx = brcms_ops_tx,
3517 + .start = brcms_ops_start,
3518 +@@ -955,6 +980,7 @@ static const struct ieee80211_ops brcms_ops = {
3519 + .flush = brcms_ops_flush,
3520 + .get_tsf = brcms_ops_get_tsf,
3521 + .set_tsf = brcms_ops_set_tsf,
3522 ++ .set_tim = brcms_ops_beacon_set_tim,
3523 + };
3524 +
3525 + void brcms_dpc(unsigned long data)
3526 +diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmsmac/main.h b/drivers/net/wireless/broadcom/brcm80211/brcmsmac/main.h
3527 +index c4d135cff04a..9f76b880814e 100644
3528 +--- a/drivers/net/wireless/broadcom/brcm80211/brcmsmac/main.h
3529 ++++ b/drivers/net/wireless/broadcom/brcm80211/brcmsmac/main.h
3530 +@@ -563,6 +563,7 @@ struct brcms_c_info {
3531 +
3532 + struct wiphy *wiphy;
3533 + struct scb pri_scb;
3534 ++ struct ieee80211_vif *vif;
3535 +
3536 + struct sk_buff *beacon;
3537 + u16 beacon_tim_offset;
3538 +diff --git a/drivers/net/wireless/cisco/airo.c b/drivers/net/wireless/cisco/airo.c
3539 +index 54201c02fdb8..fc49255bab00 100644
3540 +--- a/drivers/net/wireless/cisco/airo.c
3541 ++++ b/drivers/net/wireless/cisco/airo.c
3542 +@@ -5464,7 +5464,7 @@ static int proc_BSSList_open( struct inode *inode, struct file *file ) {
3543 + we have to add a spin lock... */
3544 + rc = readBSSListRid(ai, doLoseSync, &BSSList_rid);
3545 + while(rc == 0 && BSSList_rid.index != cpu_to_le16(0xffff)) {
3546 +- ptr += sprintf(ptr, "%pM %*s rssi = %d",
3547 ++ ptr += sprintf(ptr, "%pM %.*s rssi = %d",
3548 + BSSList_rid.bssid,
3549 + (int)BSSList_rid.ssidLen,
3550 + BSSList_rid.ssid,
3551 +diff --git a/drivers/net/wireless/marvell/mwifiex/cfg80211.c b/drivers/net/wireless/marvell/mwifiex/cfg80211.c
3552 +index dde47c548818..5e8e34a08b2d 100644
3553 +--- a/drivers/net/wireless/marvell/mwifiex/cfg80211.c
3554 ++++ b/drivers/net/wireless/marvell/mwifiex/cfg80211.c
3555 +@@ -362,11 +362,20 @@ mwifiex_cfg80211_set_tx_power(struct wiphy *wiphy,
3556 + struct mwifiex_power_cfg power_cfg;
3557 + int dbm = MBM_TO_DBM(mbm);
3558 +
3559 +- if (type == NL80211_TX_POWER_FIXED) {
3560 ++ switch (type) {
3561 ++ case NL80211_TX_POWER_FIXED:
3562 + power_cfg.is_power_auto = 0;
3563 ++ power_cfg.is_power_fixed = 1;
3564 + power_cfg.power_level = dbm;
3565 +- } else {
3566 ++ break;
3567 ++ case NL80211_TX_POWER_LIMITED:
3568 ++ power_cfg.is_power_auto = 0;
3569 ++ power_cfg.is_power_fixed = 0;
3570 ++ power_cfg.power_level = dbm;
3571 ++ break;
3572 ++ case NL80211_TX_POWER_AUTOMATIC:
3573 + power_cfg.is_power_auto = 1;
3574 ++ break;
3575 + }
3576 +
3577 + priv = mwifiex_get_priv(adapter, MWIFIEX_BSS_ROLE_ANY);
3578 +diff --git a/drivers/net/wireless/marvell/mwifiex/ioctl.h b/drivers/net/wireless/marvell/mwifiex/ioctl.h
3579 +index 48e154e1865d..0dd592ea6e83 100644
3580 +--- a/drivers/net/wireless/marvell/mwifiex/ioctl.h
3581 ++++ b/drivers/net/wireless/marvell/mwifiex/ioctl.h
3582 +@@ -267,6 +267,7 @@ struct mwifiex_ds_encrypt_key {
3583 +
3584 + struct mwifiex_power_cfg {
3585 + u32 is_power_auto;
3586 ++ u32 is_power_fixed;
3587 + u32 power_level;
3588 + };
3589 +
3590 +diff --git a/drivers/net/wireless/marvell/mwifiex/sta_ioctl.c b/drivers/net/wireless/marvell/mwifiex/sta_ioctl.c
3591 +index 82828a207963..a8043d76152a 100644
3592 +--- a/drivers/net/wireless/marvell/mwifiex/sta_ioctl.c
3593 ++++ b/drivers/net/wireless/marvell/mwifiex/sta_ioctl.c
3594 +@@ -728,6 +728,9 @@ int mwifiex_set_tx_power(struct mwifiex_private *priv,
3595 + txp_cfg = (struct host_cmd_ds_txpwr_cfg *) buf;
3596 + txp_cfg->action = cpu_to_le16(HostCmd_ACT_GEN_SET);
3597 + if (!power_cfg->is_power_auto) {
3598 ++ u16 dbm_min = power_cfg->is_power_fixed ?
3599 ++ dbm : priv->min_tx_power_level;
3600 ++
3601 + txp_cfg->mode = cpu_to_le32(1);
3602 + pg_tlv = (struct mwifiex_types_power_group *)
3603 + (buf + sizeof(struct host_cmd_ds_txpwr_cfg));
3604 +@@ -742,7 +745,7 @@ int mwifiex_set_tx_power(struct mwifiex_private *priv,
3605 + pg->last_rate_code = 0x03;
3606 + pg->modulation_class = MOD_CLASS_HR_DSSS;
3607 + pg->power_step = 0;
3608 +- pg->power_min = (s8) dbm;
3609 ++ pg->power_min = (s8) dbm_min;
3610 + pg->power_max = (s8) dbm;
3611 + pg++;
3612 + /* Power group for modulation class OFDM */
3613 +@@ -750,7 +753,7 @@ int mwifiex_set_tx_power(struct mwifiex_private *priv,
3614 + pg->last_rate_code = 0x07;
3615 + pg->modulation_class = MOD_CLASS_OFDM;
3616 + pg->power_step = 0;
3617 +- pg->power_min = (s8) dbm;
3618 ++ pg->power_min = (s8) dbm_min;
3619 + pg->power_max = (s8) dbm;
3620 + pg++;
3621 + /* Power group for modulation class HTBW20 */
3622 +@@ -758,7 +761,7 @@ int mwifiex_set_tx_power(struct mwifiex_private *priv,
3623 + pg->last_rate_code = 0x20;
3624 + pg->modulation_class = MOD_CLASS_HT;
3625 + pg->power_step = 0;
3626 +- pg->power_min = (s8) dbm;
3627 ++ pg->power_min = (s8) dbm_min;
3628 + pg->power_max = (s8) dbm;
3629 + pg->ht_bandwidth = HT_BW_20;
3630 + pg++;
3631 +@@ -767,7 +770,7 @@ int mwifiex_set_tx_power(struct mwifiex_private *priv,
3632 + pg->last_rate_code = 0x20;
3633 + pg->modulation_class = MOD_CLASS_HT;
3634 + pg->power_step = 0;
3635 +- pg->power_min = (s8) dbm;
3636 ++ pg->power_min = (s8) dbm_min;
3637 + pg->power_max = (s8) dbm;
3638 + pg->ht_bandwidth = HT_BW_40;
3639 + }
3640 +diff --git a/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_core.c b/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_core.c
3641 +index 7806a4d2b1fc..91b01ca32e75 100644
3642 +--- a/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_core.c
3643 ++++ b/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_core.c
3644 +@@ -5691,6 +5691,7 @@ static int rtl8xxxu_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
3645 + break;
3646 + case WLAN_CIPHER_SUITE_TKIP:
3647 + key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
3648 ++ break;
3649 + default:
3650 + return -EOPNOTSUPP;
3651 + }
3652 +diff --git a/drivers/net/wireless/realtek/rtlwifi/rtl8192de/fw.c b/drivers/net/wireless/realtek/rtlwifi/rtl8192de/fw.c
3653 +index f4129cf96e7c..bad70a4206fb 100644
3654 +--- a/drivers/net/wireless/realtek/rtlwifi/rtl8192de/fw.c
3655 ++++ b/drivers/net/wireless/realtek/rtlwifi/rtl8192de/fw.c
3656 +@@ -173,7 +173,7 @@ static int _rtl92d_fw_init(struct ieee80211_hw *hw)
3657 + rtl_read_byte(rtlpriv, FW_MAC1_READY));
3658 + }
3659 + RT_TRACE(rtlpriv, COMP_FW, DBG_DMESG,
3660 +- "Polling FW ready fail!! REG_MCUFWDL:0x%08ul\n",
3661 ++ "Polling FW ready fail!! REG_MCUFWDL:0x%08x\n",
3662 + rtl_read_dword(rtlpriv, REG_MCUFWDL));
3663 + return -1;
3664 + }
3665 +diff --git a/drivers/net/wireless/ti/wlcore/vendor_cmd.c b/drivers/net/wireless/ti/wlcore/vendor_cmd.c
3666 +index 5c0bcb1fe1a1..e75c3cee0252 100644
3667 +--- a/drivers/net/wireless/ti/wlcore/vendor_cmd.c
3668 ++++ b/drivers/net/wireless/ti/wlcore/vendor_cmd.c
3669 +@@ -66,7 +66,7 @@ wlcore_vendor_cmd_smart_config_start(struct wiphy *wiphy,
3670 + out:
3671 + mutex_unlock(&wl->mutex);
3672 +
3673 +- return 0;
3674 ++ return ret;
3675 + }
3676 +
3677 + static int
3678 +diff --git a/drivers/nfc/port100.c b/drivers/nfc/port100.c
3679 +index bb43cebda9dc..60ae382f50da 100644
3680 +--- a/drivers/nfc/port100.c
3681 ++++ b/drivers/nfc/port100.c
3682 +@@ -792,7 +792,7 @@ static int port100_send_frame_async(struct port100 *dev, struct sk_buff *out,
3683 +
3684 + rc = port100_submit_urb_for_ack(dev, GFP_KERNEL);
3685 + if (rc)
3686 +- usb_unlink_urb(dev->out_urb);
3687 ++ usb_kill_urb(dev->out_urb);
3688 +
3689 + exit:
3690 + mutex_unlock(&dev->out_urb_lock);
3691 +diff --git a/drivers/ntb/hw/intel/ntb_hw_intel.c b/drivers/ntb/hw/intel/ntb_hw_intel.c
3692 +index 2557e2c05b90..58068f1447bb 100644
3693 +--- a/drivers/ntb/hw/intel/ntb_hw_intel.c
3694 ++++ b/drivers/ntb/hw/intel/ntb_hw_intel.c
3695 +@@ -348,7 +348,7 @@ static inline int ndev_db_clear_mask(struct intel_ntb_dev *ndev, u64 db_bits,
3696 + return 0;
3697 + }
3698 +
3699 +-static inline int ndev_vec_mask(struct intel_ntb_dev *ndev, int db_vector)
3700 ++static inline u64 ndev_vec_mask(struct intel_ntb_dev *ndev, int db_vector)
3701 + {
3702 + u64 shift, mask;
3703 +
3704 +diff --git a/drivers/nvme/target/fcloop.c b/drivers/nvme/target/fcloop.c
3705 +index 0b0a4825b3eb..096523d8dd42 100644
3706 +--- a/drivers/nvme/target/fcloop.c
3707 ++++ b/drivers/nvme/target/fcloop.c
3708 +@@ -535,6 +535,7 @@ fcloop_fcp_op(struct nvmet_fc_target_port *tgtport,
3709 + break;
3710 +
3711 + /* Fall-Thru to RSP handling */
3712 ++ /* FALLTHRU */
3713 +
3714 + case NVMET_FCOP_RSP:
3715 + if (fcpreq) {
3716 +diff --git a/drivers/of/unittest.c b/drivers/of/unittest.c
3717 +index 87650d42682f..9d204649c963 100644
3718 +--- a/drivers/of/unittest.c
3719 ++++ b/drivers/of/unittest.c
3720 +@@ -910,20 +910,44 @@ static void __init of_unittest_platform_populate(void)
3721 + * of np into dup node (present in live tree) and
3722 + * updates parent of children of np to dup.
3723 + *
3724 +- * @np: node already present in live tree
3725 ++ * @np: node whose properties are being added to the live tree
3726 + * @dup: node present in live tree to be updated
3727 + */
3728 + static void update_node_properties(struct device_node *np,
3729 + struct device_node *dup)
3730 + {
3731 + struct property *prop;
3732 ++ struct property *save_next;
3733 + struct device_node *child;
3734 +-
3735 +- for_each_property_of_node(np, prop)
3736 +- of_add_property(dup, prop);
3737 ++ int ret;
3738 +
3739 + for_each_child_of_node(np, child)
3740 + child->parent = dup;
3741 ++
3742 ++ /*
3743 ++ * "unittest internal error: unable to add testdata property"
3744 ++ *
3745 ++ * If this message reports a property in node '/__symbols__' then
3746 ++ * the respective unittest overlay contains a label that has the
3747 ++ * same name as a label in the live devicetree. The label will
3748 ++ * be in the live devicetree only if the devicetree source was
3749 ++ * compiled with the '-@' option. If you encounter this error,
3750 ++ * please consider renaming __all__ of the labels in the unittest
3751 ++ * overlay dts files with an odd prefix that is unlikely to be
3752 ++ * used in a real devicetree.
3753 ++ */
3754 ++
3755 ++ /*
3756 ++ * open code for_each_property_of_node() because of_add_property()
3757 ++ * sets prop->next to NULL
3758 ++ */
3759 ++ for (prop = np->properties; prop != NULL; prop = save_next) {
3760 ++ save_next = prop->next;
3761 ++ ret = of_add_property(dup, prop);
3762 ++ if (ret)
3763 ++ pr_err("unittest internal error: unable to add testdata property %pOF/%s",
3764 ++ np, prop->name);
3765 ++ }
3766 + }
3767 +
3768 + /**
3769 +@@ -932,18 +956,23 @@ static void update_node_properties(struct device_node *np,
3770 + *
3771 + * @np: Node to attach to live tree
3772 + */
3773 +-static int attach_node_and_children(struct device_node *np)
3774 ++static void attach_node_and_children(struct device_node *np)
3775 + {
3776 + struct device_node *next, *dup, *child;
3777 + unsigned long flags;
3778 + const char *full_name;
3779 +
3780 + full_name = kasprintf(GFP_KERNEL, "%pOF", np);
3781 ++
3782 ++ if (!strcmp(full_name, "/__local_fixups__") ||
3783 ++ !strcmp(full_name, "/__fixups__"))
3784 ++ return;
3785 ++
3786 + dup = of_find_node_by_path(full_name);
3787 + kfree(full_name);
3788 + if (dup) {
3789 + update_node_properties(np, dup);
3790 +- return 0;
3791 ++ return;
3792 + }
3793 +
3794 + child = np->child;
3795 +@@ -964,8 +993,6 @@ static int attach_node_and_children(struct device_node *np)
3796 + attach_node_and_children(child);
3797 + child = next;
3798 + }
3799 +-
3800 +- return 0;
3801 + }
3802 +
3803 + /**
3804 +diff --git a/drivers/pci/dwc/pci-keystone.c b/drivers/pci/dwc/pci-keystone.c
3805 +index 9bc52e4cf52a..3ea8288c1605 100644
3806 +--- a/drivers/pci/dwc/pci-keystone.c
3807 ++++ b/drivers/pci/dwc/pci-keystone.c
3808 +@@ -39,6 +39,7 @@
3809 + #define PCIE_RC_K2HK 0xb008
3810 + #define PCIE_RC_K2E 0xb009
3811 + #define PCIE_RC_K2L 0xb00a
3812 ++#define PCIE_RC_K2G 0xb00b
3813 +
3814 + #define to_keystone_pcie(x) dev_get_drvdata((x)->dev)
3815 +
3816 +@@ -53,6 +54,8 @@ static void quirk_limit_mrrs(struct pci_dev *dev)
3817 + .class = PCI_CLASS_BRIDGE_PCI << 8, .class_mask = ~0, },
3818 + { PCI_DEVICE(PCI_VENDOR_ID_TI, PCIE_RC_K2L),
3819 + .class = PCI_CLASS_BRIDGE_PCI << 8, .class_mask = ~0, },
3820 ++ { PCI_DEVICE(PCI_VENDOR_ID_TI, PCIE_RC_K2G),
3821 ++ .class = PCI_CLASS_BRIDGE_PCI << 8, .class_mask = ~0, },
3822 + { 0, },
3823 + };
3824 +
3825 +diff --git a/drivers/pci/host/vmd.c b/drivers/pci/host/vmd.c
3826 +index 2537b022f42d..af6d5da10ea5 100644
3827 +--- a/drivers/pci/host/vmd.c
3828 ++++ b/drivers/pci/host/vmd.c
3829 +@@ -753,12 +753,12 @@ static void vmd_remove(struct pci_dev *dev)
3830 + {
3831 + struct vmd_dev *vmd = pci_get_drvdata(dev);
3832 +
3833 +- vmd_detach_resources(vmd);
3834 + sysfs_remove_link(&vmd->dev->dev.kobj, "domain");
3835 + pci_stop_root_bus(vmd->bus);
3836 + pci_remove_root_bus(vmd->bus);
3837 + vmd_cleanup_srcu(vmd);
3838 + vmd_teardown_dma_ops(vmd);
3839 ++ vmd_detach_resources(vmd);
3840 + irq_domain_remove(vmd->irq_domain);
3841 + }
3842 +
3843 +diff --git a/drivers/pinctrl/pinctrl-lpc18xx.c b/drivers/pinctrl/pinctrl-lpc18xx.c
3844 +index d090f37ca4a1..8b4e3582af6e 100644
3845 +--- a/drivers/pinctrl/pinctrl-lpc18xx.c
3846 ++++ b/drivers/pinctrl/pinctrl-lpc18xx.c
3847 +@@ -630,14 +630,8 @@ static const struct pinctrl_pin_desc lpc18xx_pins[] = {
3848 + LPC18XX_PIN(i2c0_sda, PIN_I2C0_SDA),
3849 + };
3850 +
3851 +-/**
3852 +- * enum lpc18xx_pin_config_param - possible pin configuration parameters
3853 +- * @PIN_CONFIG_GPIO_PIN_INT: route gpio to the gpio pin interrupt
3854 +- * controller.
3855 +- */
3856 +-enum lpc18xx_pin_config_param {
3857 +- PIN_CONFIG_GPIO_PIN_INT = PIN_CONFIG_END + 1,
3858 +-};
3859 ++/* PIN_CONFIG_GPIO_PIN_INT: route gpio to the gpio pin interrupt controller */
3860 ++#define PIN_CONFIG_GPIO_PIN_INT (PIN_CONFIG_END + 1)
3861 +
3862 + static const struct pinconf_generic_params lpc18xx_params[] = {
3863 + {"nxp,gpio-pin-interrupt", PIN_CONFIG_GPIO_PIN_INT, 0},
3864 +diff --git a/drivers/pinctrl/pinctrl-zynq.c b/drivers/pinctrl/pinctrl-zynq.c
3865 +index a0daf27042bd..90fd37e8207b 100644
3866 +--- a/drivers/pinctrl/pinctrl-zynq.c
3867 ++++ b/drivers/pinctrl/pinctrl-zynq.c
3868 +@@ -971,15 +971,12 @@ enum zynq_io_standards {
3869 + zynq_iostd_max
3870 + };
3871 +
3872 +-/**
3873 +- * enum zynq_pin_config_param - possible pin configuration parameters
3874 +- * @PIN_CONFIG_IOSTANDARD: if the pin can select an IO standard, the argument to
3875 ++/*
3876 ++ * PIN_CONFIG_IOSTANDARD: if the pin can select an IO standard, the argument to
3877 + * this parameter (on a custom format) tells the driver which alternative
3878 + * IO standard to use.
3879 + */
3880 +-enum zynq_pin_config_param {
3881 +- PIN_CONFIG_IOSTANDARD = PIN_CONFIG_END + 1,
3882 +-};
3883 ++#define PIN_CONFIG_IOSTANDARD (PIN_CONFIG_END + 1)
3884 +
3885 + static const struct pinconf_generic_params zynq_dt_params[] = {
3886 + {"io-standard", PIN_CONFIG_IOSTANDARD, zynq_iostd_lvcmos18},
3887 +diff --git a/drivers/pinctrl/qcom/pinctrl-spmi-gpio.c b/drivers/pinctrl/qcom/pinctrl-spmi-gpio.c
3888 +index 22aaf4375fac..0f0049dfaa3a 100644
3889 +--- a/drivers/pinctrl/qcom/pinctrl-spmi-gpio.c
3890 ++++ b/drivers/pinctrl/qcom/pinctrl-spmi-gpio.c
3891 +@@ -1023,10 +1023,23 @@ static int pmic_gpio_probe(struct platform_device *pdev)
3892 + return ret;
3893 + }
3894 +
3895 +- ret = gpiochip_add_pin_range(&state->chip, dev_name(dev), 0, 0, npins);
3896 +- if (ret) {
3897 +- dev_err(dev, "failed to add pin range\n");
3898 +- goto err_range;
3899 ++ /*
3900 ++ * For DeviceTree-supported systems, the gpio core checks the
3901 ++ * pinctrl's device node for the "gpio-ranges" property.
3902 ++ * If it is present, it takes care of adding the pin ranges
3903 ++ * for the driver. In this case the driver can skip ahead.
3904 ++ *
3905 ++ * In order to remain compatible with older, existing DeviceTree
3906 ++ * files which don't set the "gpio-ranges" property or systems that
3907 ++ * utilize ACPI the driver has to call gpiochip_add_pin_range().
3908 ++ */
3909 ++ if (!of_property_read_bool(dev->of_node, "gpio-ranges")) {
3910 ++ ret = gpiochip_add_pin_range(&state->chip, dev_name(dev), 0, 0,
3911 ++ npins);
3912 ++ if (ret) {
3913 ++ dev_err(dev, "failed to add pin range\n");
3914 ++ goto err_range;
3915 ++ }
3916 + }
3917 +
3918 + return 0;
3919 +diff --git a/drivers/pinctrl/sunxi/pinctrl-sunxi.c b/drivers/pinctrl/sunxi/pinctrl-sunxi.c
3920 +index 52edf3b5988d..cc8b86a16da0 100644
3921 +--- a/drivers/pinctrl/sunxi/pinctrl-sunxi.c
3922 ++++ b/drivers/pinctrl/sunxi/pinctrl-sunxi.c
3923 +@@ -1039,6 +1039,7 @@ static int sunxi_pinctrl_add_function(struct sunxi_pinctrl *pctl,
3924 + static int sunxi_pinctrl_build_state(struct platform_device *pdev)
3925 + {
3926 + struct sunxi_pinctrl *pctl = platform_get_drvdata(pdev);
3927 ++ void *ptr;
3928 + int i;
3929 +
3930 + /*
3931 +@@ -1105,13 +1106,15 @@ static int sunxi_pinctrl_build_state(struct platform_device *pdev)
3932 + }
3933 +
3934 + /* And now allocated and fill the array for real */
3935 +- pctl->functions = krealloc(pctl->functions,
3936 +- pctl->nfunctions * sizeof(*pctl->functions),
3937 +- GFP_KERNEL);
3938 +- if (!pctl->functions) {
3939 ++ ptr = krealloc(pctl->functions,
3940 ++ pctl->nfunctions * sizeof(*pctl->functions),
3941 ++ GFP_KERNEL);
3942 ++ if (!ptr) {
3943 + kfree(pctl->functions);
3944 ++ pctl->functions = NULL;
3945 + return -ENOMEM;
3946 + }
3947 ++ pctl->functions = ptr;
3948 +
3949 + for (i = 0; i < pctl->desc->npins; i++) {
3950 + const struct sunxi_desc_pin *pin = pctl->desc->pins + i;
3951 +diff --git a/drivers/platform/x86/asus-nb-wmi.c b/drivers/platform/x86/asus-nb-wmi.c
3952 +index 9c4b0d7f15c3..59f3a37a44d7 100644
3953 +--- a/drivers/platform/x86/asus-nb-wmi.c
3954 ++++ b/drivers/platform/x86/asus-nb-wmi.c
3955 +@@ -78,10 +78,12 @@ static bool asus_q500a_i8042_filter(unsigned char data, unsigned char str,
3956 +
3957 + static struct quirk_entry quirk_asus_unknown = {
3958 + .wapf = 0,
3959 ++ .wmi_backlight_set_devstate = true,
3960 + };
3961 +
3962 + static struct quirk_entry quirk_asus_q500a = {
3963 + .i8042_filter = asus_q500a_i8042_filter,
3964 ++ .wmi_backlight_set_devstate = true,
3965 + };
3966 +
3967 + /*
3968 +@@ -92,26 +94,32 @@ static struct quirk_entry quirk_asus_q500a = {
3969 + static struct quirk_entry quirk_asus_x55u = {
3970 + .wapf = 4,
3971 + .wmi_backlight_power = true,
3972 ++ .wmi_backlight_set_devstate = true,
3973 + .no_display_toggle = true,
3974 + };
3975 +
3976 + static struct quirk_entry quirk_asus_wapf4 = {
3977 + .wapf = 4,
3978 ++ .wmi_backlight_set_devstate = true,
3979 + };
3980 +
3981 + static struct quirk_entry quirk_asus_x200ca = {
3982 + .wapf = 2,
3983 ++ .wmi_backlight_set_devstate = true,
3984 + };
3985 +
3986 + static struct quirk_entry quirk_asus_ux303ub = {
3987 + .wmi_backlight_native = true,
3988 ++ .wmi_backlight_set_devstate = true,
3989 + };
3990 +
3991 + static struct quirk_entry quirk_asus_x550lb = {
3992 ++ .wmi_backlight_set_devstate = true,
3993 + .xusb2pr = 0x01D9,
3994 + };
3995 +
3996 +-static struct quirk_entry quirk_asus_ux330uak = {
3997 ++static struct quirk_entry quirk_asus_forceals = {
3998 ++ .wmi_backlight_set_devstate = true,
3999 + .wmi_force_als_set = true,
4000 + };
4001 +
4002 +@@ -387,7 +395,7 @@ static const struct dmi_system_id asus_quirks[] = {
4003 + DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
4004 + DMI_MATCH(DMI_PRODUCT_NAME, "UX330UAK"),
4005 + },
4006 +- .driver_data = &quirk_asus_ux330uak,
4007 ++ .driver_data = &quirk_asus_forceals,
4008 + },
4009 + {
4010 + .callback = dmi_matched,
4011 +@@ -398,6 +406,15 @@ static const struct dmi_system_id asus_quirks[] = {
4012 + },
4013 + .driver_data = &quirk_asus_x550lb,
4014 + },
4015 ++ {
4016 ++ .callback = dmi_matched,
4017 ++ .ident = "ASUSTeK COMPUTER INC. UX430UQ",
4018 ++ .matches = {
4019 ++ DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
4020 ++ DMI_MATCH(DMI_PRODUCT_NAME, "UX430UQ"),
4021 ++ },
4022 ++ .driver_data = &quirk_asus_forceals,
4023 ++ },
4024 + {},
4025 + };
4026 +
4027 +diff --git a/drivers/platform/x86/asus-wmi.c b/drivers/platform/x86/asus-wmi.c
4028 +index 3f662cd774d7..1c1999600717 100644
4029 +--- a/drivers/platform/x86/asus-wmi.c
4030 ++++ b/drivers/platform/x86/asus-wmi.c
4031 +@@ -2147,7 +2147,7 @@ static int asus_wmi_add(struct platform_device *pdev)
4032 + err = asus_wmi_backlight_init(asus);
4033 + if (err && err != -ENODEV)
4034 + goto fail_backlight;
4035 +- } else
4036 ++ } else if (asus->driver->quirks->wmi_backlight_set_devstate)
4037 + err = asus_wmi_set_devstate(ASUS_WMI_DEVID_BACKLIGHT, 2, NULL);
4038 +
4039 + status = wmi_install_notify_handler(asus->driver->event_guid,
4040 +diff --git a/drivers/platform/x86/asus-wmi.h b/drivers/platform/x86/asus-wmi.h
4041 +index 6c1311f4b04d..57a79bddb286 100644
4042 +--- a/drivers/platform/x86/asus-wmi.h
4043 ++++ b/drivers/platform/x86/asus-wmi.h
4044 +@@ -44,6 +44,7 @@ struct quirk_entry {
4045 + bool store_backlight_power;
4046 + bool wmi_backlight_power;
4047 + bool wmi_backlight_native;
4048 ++ bool wmi_backlight_set_devstate;
4049 + bool wmi_force_als_set;
4050 + int wapf;
4051 + /*
4052 +diff --git a/drivers/pwm/pwm-lpss.c b/drivers/pwm/pwm-lpss.c
4053 +index 4721a264bac2..1e69c1c9ec09 100644
4054 +--- a/drivers/pwm/pwm-lpss.c
4055 ++++ b/drivers/pwm/pwm-lpss.c
4056 +@@ -97,7 +97,7 @@ static void pwm_lpss_prepare(struct pwm_lpss_chip *lpwm, struct pwm_device *pwm,
4057 + unsigned long long on_time_div;
4058 + unsigned long c = lpwm->info->clk_rate, base_unit_range;
4059 + unsigned long long base_unit, freq = NSEC_PER_SEC;
4060 +- u32 ctrl;
4061 ++ u32 orig_ctrl, ctrl;
4062 +
4063 + do_div(freq, period_ns);
4064 +
4065 +@@ -114,13 +114,17 @@ static void pwm_lpss_prepare(struct pwm_lpss_chip *lpwm, struct pwm_device *pwm,
4066 + do_div(on_time_div, period_ns);
4067 + on_time_div = 255ULL - on_time_div;
4068 +
4069 +- ctrl = pwm_lpss_read(pwm);
4070 ++ orig_ctrl = ctrl = pwm_lpss_read(pwm);
4071 + ctrl &= ~PWM_ON_TIME_DIV_MASK;
4072 + ctrl &= ~(base_unit_range << PWM_BASE_UNIT_SHIFT);
4073 + base_unit &= base_unit_range;
4074 + ctrl |= (u32) base_unit << PWM_BASE_UNIT_SHIFT;
4075 + ctrl |= on_time_div;
4076 +- pwm_lpss_write(pwm, ctrl);
4077 ++
4078 ++ if (orig_ctrl != ctrl) {
4079 ++ pwm_lpss_write(pwm, ctrl);
4080 ++ pwm_lpss_write(pwm, ctrl | PWM_SW_UPDATE);
4081 ++ }
4082 + }
4083 +
4084 + static inline void pwm_lpss_cond_enable(struct pwm_device *pwm, bool cond)
4085 +@@ -144,7 +148,6 @@ static int pwm_lpss_apply(struct pwm_chip *chip, struct pwm_device *pwm,
4086 + return ret;
4087 + }
4088 + pwm_lpss_prepare(lpwm, pwm, state->duty_cycle, state->period);
4089 +- pwm_lpss_write(pwm, pwm_lpss_read(pwm) | PWM_SW_UPDATE);
4090 + pwm_lpss_cond_enable(pwm, lpwm->info->bypass == false);
4091 + ret = pwm_lpss_wait_for_update(pwm);
4092 + if (ret) {
4093 +@@ -157,7 +160,6 @@ static int pwm_lpss_apply(struct pwm_chip *chip, struct pwm_device *pwm,
4094 + if (ret)
4095 + return ret;
4096 + pwm_lpss_prepare(lpwm, pwm, state->duty_cycle, state->period);
4097 +- pwm_lpss_write(pwm, pwm_lpss_read(pwm) | PWM_SW_UPDATE);
4098 + return pwm_lpss_wait_for_update(pwm);
4099 + }
4100 + } else if (pwm_is_enabled(pwm)) {
4101 +diff --git a/drivers/rtc/rtc-s35390a.c b/drivers/rtc/rtc-s35390a.c
4102 +index 7067bca5c20d..6bfff0a6d655 100644
4103 +--- a/drivers/rtc/rtc-s35390a.c
4104 ++++ b/drivers/rtc/rtc-s35390a.c
4105 +@@ -108,7 +108,7 @@ static int s35390a_get_reg(struct s35390a *s35390a, int reg, char *buf, int len)
4106 +
4107 + static int s35390a_init(struct s35390a *s35390a)
4108 + {
4109 +- char buf;
4110 ++ u8 buf;
4111 + int ret;
4112 + unsigned initcount = 0;
4113 +
4114 +diff --git a/drivers/scsi/dc395x.c b/drivers/scsi/dc395x.c
4115 +index 5ee7f44cf869..830b2d2dcf20 100644
4116 +--- a/drivers/scsi/dc395x.c
4117 ++++ b/drivers/scsi/dc395x.c
4118 +@@ -1972,6 +1972,11 @@ static void sg_update_list(struct ScsiReqBlk *srb, u32 left)
4119 + xferred -= psge->length;
4120 + } else {
4121 + /* Partial SG entry done */
4122 ++ pci_dma_sync_single_for_cpu(srb->dcb->
4123 ++ acb->dev,
4124 ++ srb->sg_bus_addr,
4125 ++ SEGMENTX_LEN,
4126 ++ PCI_DMA_TODEVICE);
4127 + psge->length -= xferred;
4128 + psge->address += xferred;
4129 + srb->sg_index = idx;
4130 +@@ -3450,14 +3455,12 @@ static void srb_done(struct AdapterCtlBlk *acb, struct DeviceCtlBlk *dcb,
4131 + }
4132 + }
4133 +
4134 +- if (dir != PCI_DMA_NONE && scsi_sg_count(cmd))
4135 +- pci_dma_sync_sg_for_cpu(acb->dev, scsi_sglist(cmd),
4136 +- scsi_sg_count(cmd), dir);
4137 +-
4138 + ckc_only = 0;
4139 + /* Check Error Conditions */
4140 + ckc_e:
4141 +
4142 ++ pci_unmap_srb(acb, srb);
4143 ++
4144 + if (cmd->cmnd[0] == INQUIRY) {
4145 + unsigned char *base = NULL;
4146 + struct ScsiInqData *ptr;
4147 +@@ -3511,7 +3514,6 @@ static void srb_done(struct AdapterCtlBlk *acb, struct DeviceCtlBlk *dcb,
4148 + cmd, cmd->result);
4149 + srb_free_insert(acb, srb);
4150 + }
4151 +- pci_unmap_srb(acb, srb);
4152 +
4153 + cmd->scsi_done(cmd);
4154 + waiting_process_next(acb);
4155 +diff --git a/drivers/scsi/ips.c b/drivers/scsi/ips.c
4156 +index 67621308eb9c..ea652f1e2071 100644
4157 +--- a/drivers/scsi/ips.c
4158 ++++ b/drivers/scsi/ips.c
4159 +@@ -3497,6 +3497,7 @@ ips_send_cmd(ips_ha_t * ha, ips_scb_t * scb)
4160 +
4161 + case START_STOP:
4162 + scb->scsi_cmd->result = DID_OK << 16;
4163 ++ break;
4164 +
4165 + case TEST_UNIT_READY:
4166 + case INQUIRY:
4167 +diff --git a/drivers/scsi/isci/host.c b/drivers/scsi/isci/host.c
4168 +index 609dafd661d1..da4583a2fa23 100644
4169 +--- a/drivers/scsi/isci/host.c
4170 ++++ b/drivers/scsi/isci/host.c
4171 +@@ -2717,9 +2717,9 @@ enum sci_status sci_controller_continue_io(struct isci_request *ireq)
4172 + * the task management request.
4173 + * @task_request: the handle to the task request object to start.
4174 + */
4175 +-enum sci_task_status sci_controller_start_task(struct isci_host *ihost,
4176 +- struct isci_remote_device *idev,
4177 +- struct isci_request *ireq)
4178 ++enum sci_status sci_controller_start_task(struct isci_host *ihost,
4179 ++ struct isci_remote_device *idev,
4180 ++ struct isci_request *ireq)
4181 + {
4182 + enum sci_status status;
4183 +
4184 +@@ -2728,7 +2728,7 @@ enum sci_task_status sci_controller_start_task(struct isci_host *ihost,
4185 + "%s: SCIC Controller starting task from invalid "
4186 + "state\n",
4187 + __func__);
4188 +- return SCI_TASK_FAILURE_INVALID_STATE;
4189 ++ return SCI_FAILURE_INVALID_STATE;
4190 + }
4191 +
4192 + status = sci_remote_device_start_task(ihost, idev, ireq);
4193 +diff --git a/drivers/scsi/isci/host.h b/drivers/scsi/isci/host.h
4194 +index b3539928073c..6bc3f022630a 100644
4195 +--- a/drivers/scsi/isci/host.h
4196 ++++ b/drivers/scsi/isci/host.h
4197 +@@ -489,7 +489,7 @@ enum sci_status sci_controller_start_io(
4198 + struct isci_remote_device *idev,
4199 + struct isci_request *ireq);
4200 +
4201 +-enum sci_task_status sci_controller_start_task(
4202 ++enum sci_status sci_controller_start_task(
4203 + struct isci_host *ihost,
4204 + struct isci_remote_device *idev,
4205 + struct isci_request *ireq);
4206 +diff --git a/drivers/scsi/isci/request.c b/drivers/scsi/isci/request.c
4207 +index ed197bc8e801..2f151708b59a 100644
4208 +--- a/drivers/scsi/isci/request.c
4209 ++++ b/drivers/scsi/isci/request.c
4210 +@@ -1626,9 +1626,9 @@ static enum sci_status atapi_d2h_reg_frame_handler(struct isci_request *ireq,
4211 +
4212 + if (status == SCI_SUCCESS) {
4213 + if (ireq->stp.rsp.status & ATA_ERR)
4214 +- status = SCI_IO_FAILURE_RESPONSE_VALID;
4215 ++ status = SCI_FAILURE_IO_RESPONSE_VALID;
4216 + } else {
4217 +- status = SCI_IO_FAILURE_RESPONSE_VALID;
4218 ++ status = SCI_FAILURE_IO_RESPONSE_VALID;
4219 + }
4220 +
4221 + if (status != SCI_SUCCESS) {
4222 +diff --git a/drivers/scsi/isci/task.c b/drivers/scsi/isci/task.c
4223 +index 6dcaed0c1fc8..fb6eba331ac6 100644
4224 +--- a/drivers/scsi/isci/task.c
4225 ++++ b/drivers/scsi/isci/task.c
4226 +@@ -258,7 +258,7 @@ static int isci_task_execute_tmf(struct isci_host *ihost,
4227 + struct isci_tmf *tmf, unsigned long timeout_ms)
4228 + {
4229 + DECLARE_COMPLETION_ONSTACK(completion);
4230 +- enum sci_task_status status = SCI_TASK_FAILURE;
4231 ++ enum sci_status status = SCI_FAILURE;
4232 + struct isci_request *ireq;
4233 + int ret = TMF_RESP_FUNC_FAILED;
4234 + unsigned long flags;
4235 +@@ -301,7 +301,7 @@ static int isci_task_execute_tmf(struct isci_host *ihost,
4236 + /* start the TMF io. */
4237 + status = sci_controller_start_task(ihost, idev, ireq);
4238 +
4239 +- if (status != SCI_TASK_SUCCESS) {
4240 ++ if (status != SCI_SUCCESS) {
4241 + dev_dbg(&ihost->pdev->dev,
4242 + "%s: start_io failed - status = 0x%x, request = %p\n",
4243 + __func__,
4244 +diff --git a/drivers/scsi/iscsi_tcp.c b/drivers/scsi/iscsi_tcp.c
4245 +index e11eff6b0e97..045207b5560e 100644
4246 +--- a/drivers/scsi/iscsi_tcp.c
4247 ++++ b/drivers/scsi/iscsi_tcp.c
4248 +@@ -798,7 +798,8 @@ static int iscsi_sw_tcp_host_get_param(struct Scsi_Host *shost,
4249 + return rc;
4250 +
4251 + return iscsi_conn_get_addr_param((struct sockaddr_storage *)
4252 +- &addr, param, buf);
4253 ++ &addr,
4254 ++ (enum iscsi_param)param, buf);
4255 + default:
4256 + return iscsi_host_get_param(shost, param, buf);
4257 + }
4258 +diff --git a/drivers/scsi/lpfc/lpfc_els.c b/drivers/scsi/lpfc/lpfc_els.c
4259 +index ddd29752d96d..e5db20e8979d 100644
4260 +--- a/drivers/scsi/lpfc/lpfc_els.c
4261 ++++ b/drivers/scsi/lpfc/lpfc_els.c
4262 +@@ -1152,6 +1152,7 @@ stop_rr_fcf_flogi:
4263 + phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
4264 + phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO);
4265 + spin_unlock_irq(&phba->hbalock);
4266 ++ phba->fcf.fcf_redisc_attempted = 0; /* reset */
4267 + goto out;
4268 + }
4269 + if (!rc) {
4270 +@@ -1166,6 +1167,7 @@ stop_rr_fcf_flogi:
4271 + phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
4272 + phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO);
4273 + spin_unlock_irq(&phba->hbalock);
4274 ++ phba->fcf.fcf_redisc_attempted = 0; /* reset */
4275 + goto out;
4276 + }
4277 + }
4278 +@@ -1548,8 +1550,10 @@ lpfc_plogi_confirm_nport(struct lpfc_hba *phba, uint32_t *prsp,
4279 + */
4280 + new_ndlp = lpfc_findnode_wwpn(vport, &sp->portName);
4281 +
4282 ++ /* return immediately if the WWPN matches ndlp */
4283 + if (new_ndlp == ndlp && NLP_CHK_NODE_ACT(new_ndlp))
4284 + return ndlp;
4285 ++
4286 + if (phba->sli_rev == LPFC_SLI_REV4) {
4287 + active_rrqs_xri_bitmap = mempool_alloc(phba->active_rrq_pool,
4288 + GFP_KERNEL);
4289 +@@ -1558,9 +1562,13 @@ lpfc_plogi_confirm_nport(struct lpfc_hba *phba, uint32_t *prsp,
4290 + phba->cfg_rrq_xri_bitmap_sz);
4291 + }
4292 +
4293 +- lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4294 +- "3178 PLOGI confirm: ndlp %p x%x: new_ndlp %p\n",
4295 +- ndlp, ndlp->nlp_DID, new_ndlp);
4296 ++ lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS | LOG_NODE,
4297 ++ "3178 PLOGI confirm: ndlp x%x x%x x%x: "
4298 ++ "new_ndlp x%x x%x x%x\n",
4299 ++ ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_fc4_type,
4300 ++ (new_ndlp ? new_ndlp->nlp_DID : 0),
4301 ++ (new_ndlp ? new_ndlp->nlp_flag : 0),
4302 ++ (new_ndlp ? new_ndlp->nlp_fc4_type : 0));
4303 +
4304 + if (!new_ndlp) {
4305 + rc = memcmp(&ndlp->nlp_portname, name,
4306 +@@ -1609,6 +1617,14 @@ lpfc_plogi_confirm_nport(struct lpfc_hba *phba, uint32_t *prsp,
4307 + phba->cfg_rrq_xri_bitmap_sz);
4308 + }
4309 +
4310 ++ /* At this point in this routine, we know new_ndlp will be
4311 ++ * returned. however, any previous GID_FTs that were done
4312 ++ * would have updated nlp_fc4_type in ndlp, so we must ensure
4313 ++ * new_ndlp has the right value.
4314 ++ */
4315 ++ if (vport->fc_flag & FC_FABRIC)
4316 ++ new_ndlp->nlp_fc4_type = ndlp->nlp_fc4_type;
4317 ++
4318 + lpfc_unreg_rpi(vport, new_ndlp);
4319 + new_ndlp->nlp_DID = ndlp->nlp_DID;
4320 + new_ndlp->nlp_prev_state = ndlp->nlp_prev_state;
4321 +@@ -1730,6 +1746,12 @@ lpfc_plogi_confirm_nport(struct lpfc_hba *phba, uint32_t *prsp,
4322 + active_rrqs_xri_bitmap)
4323 + mempool_free(active_rrqs_xri_bitmap,
4324 + phba->active_rrq_pool);
4325 ++
4326 ++ lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS | LOG_NODE,
4327 ++ "3173 PLOGI confirm exit: new_ndlp x%x x%x x%x\n",
4328 ++ new_ndlp->nlp_DID, new_ndlp->nlp_flag,
4329 ++ new_ndlp->nlp_fc4_type);
4330 ++
4331 + return new_ndlp;
4332 + }
4333 +
4334 +diff --git a/drivers/scsi/lpfc/lpfc_hbadisc.c b/drivers/scsi/lpfc/lpfc_hbadisc.c
4335 +index b970933a218d..d850077c5e22 100644
4336 +--- a/drivers/scsi/lpfc/lpfc_hbadisc.c
4337 ++++ b/drivers/scsi/lpfc/lpfc_hbadisc.c
4338 +@@ -1999,6 +1999,26 @@ int lpfc_sli4_fcf_rr_next_proc(struct lpfc_vport *vport, uint16_t fcf_index)
4339 + "failover and change port state:x%x/x%x\n",
4340 + phba->pport->port_state, LPFC_VPORT_UNKNOWN);
4341 + phba->pport->port_state = LPFC_VPORT_UNKNOWN;
4342 ++
4343 ++ if (!phba->fcf.fcf_redisc_attempted) {
4344 ++ lpfc_unregister_fcf(phba);
4345 ++
4346 ++ rc = lpfc_sli4_redisc_fcf_table(phba);
4347 ++ if (!rc) {
4348 ++ lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
4349 ++ "3195 Rediscover FCF table\n");
4350 ++ phba->fcf.fcf_redisc_attempted = 1;
4351 ++ lpfc_sli4_clear_fcf_rr_bmask(phba);
4352 ++ } else {
4353 ++ lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
4354 ++ "3196 Rediscover FCF table "
4355 ++ "failed. Status:x%x\n", rc);
4356 ++ }
4357 ++ } else {
4358 ++ lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
4359 ++ "3197 Already rediscover FCF table "
4360 ++ "attempted. No more retry\n");
4361 ++ }
4362 + goto stop_flogi_current_fcf;
4363 + } else {
4364 + lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_ELS,
4365 +diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
4366 +index 25612ccf6ff2..15bcd00dd7a2 100644
4367 +--- a/drivers/scsi/lpfc/lpfc_init.c
4368 ++++ b/drivers/scsi/lpfc/lpfc_init.c
4369 +@@ -4997,7 +4997,7 @@ lpfc_sli4_async_fip_evt(struct lpfc_hba *phba,
4370 + break;
4371 + }
4372 + /* If fast FCF failover rescan event is pending, do nothing */
4373 +- if (phba->fcf.fcf_flag & FCF_REDISC_EVT) {
4374 ++ if (phba->fcf.fcf_flag & (FCF_REDISC_EVT | FCF_REDISC_PEND)) {
4375 + spin_unlock_irq(&phba->hbalock);
4376 + break;
4377 + }
4378 +diff --git a/drivers/scsi/lpfc/lpfc_nportdisc.c b/drivers/scsi/lpfc/lpfc_nportdisc.c
4379 +index a0658d158228..043bca6449cd 100644
4380 +--- a/drivers/scsi/lpfc/lpfc_nportdisc.c
4381 ++++ b/drivers/scsi/lpfc/lpfc_nportdisc.c
4382 +@@ -2829,8 +2829,9 @@ lpfc_disc_state_machine(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
4383 + /* DSM in event <evt> on NPort <nlp_DID> in state <cur_state> */
4384 + lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4385 + "0211 DSM in event x%x on NPort x%x in "
4386 +- "state %d Data: x%x\n",
4387 +- evt, ndlp->nlp_DID, cur_state, ndlp->nlp_flag);
4388 ++ "state %d Data: x%x x%x\n",
4389 ++ evt, ndlp->nlp_DID, cur_state,
4390 ++ ndlp->nlp_flag, ndlp->nlp_fc4_type);
4391 +
4392 + lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_DSM,
4393 + "DSM in: evt:%d ste:%d did:x%x",
4394 +diff --git a/drivers/scsi/lpfc/lpfc_sli.c b/drivers/scsi/lpfc/lpfc_sli.c
4395 +index 6c2b098b7609..ebf7d3cda367 100644
4396 +--- a/drivers/scsi/lpfc/lpfc_sli.c
4397 ++++ b/drivers/scsi/lpfc/lpfc_sli.c
4398 +@@ -18056,15 +18056,8 @@ next_priority:
4399 + goto initial_priority;
4400 + lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
4401 + "2844 No roundrobin failover FCF available\n");
4402 +- if (next_fcf_index >= LPFC_SLI4_FCF_TBL_INDX_MAX)
4403 +- return LPFC_FCOE_FCF_NEXT_NONE;
4404 +- else {
4405 +- lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
4406 +- "3063 Only FCF available idx %d, flag %x\n",
4407 +- next_fcf_index,
4408 +- phba->fcf.fcf_pri[next_fcf_index].fcf_rec.flag);
4409 +- return next_fcf_index;
4410 +- }
4411 ++
4412 ++ return LPFC_FCOE_FCF_NEXT_NONE;
4413 + }
4414 +
4415 + if (next_fcf_index < LPFC_SLI4_FCF_TBL_INDX_MAX &&
4416 +diff --git a/drivers/scsi/lpfc/lpfc_sli4.h b/drivers/scsi/lpfc/lpfc_sli4.h
4417 +index 60200385fe00..a132a83ef233 100644
4418 +--- a/drivers/scsi/lpfc/lpfc_sli4.h
4419 ++++ b/drivers/scsi/lpfc/lpfc_sli4.h
4420 +@@ -265,6 +265,7 @@ struct lpfc_fcf {
4421 + #define FCF_REDISC_EVT 0x100 /* FCF rediscovery event to worker thread */
4422 + #define FCF_REDISC_FOV 0x200 /* Post FCF rediscovery fast failover */
4423 + #define FCF_REDISC_PROG (FCF_REDISC_PEND | FCF_REDISC_EVT)
4424 ++ uint16_t fcf_redisc_attempted;
4425 + uint32_t addr_mode;
4426 + uint32_t eligible_fcf_cnt;
4427 + struct lpfc_fcf_rec current_rec;
4428 +diff --git a/drivers/scsi/megaraid/megaraid_sas_base.c b/drivers/scsi/megaraid/megaraid_sas_base.c
4429 +index 8595d83229b7..577513649afb 100644
4430 +--- a/drivers/scsi/megaraid/megaraid_sas_base.c
4431 ++++ b/drivers/scsi/megaraid/megaraid_sas_base.c
4432 +@@ -3823,12 +3823,12 @@ megasas_transition_to_ready(struct megasas_instance *instance, int ocr)
4433 + /*
4434 + * The cur_state should not last for more than max_wait secs
4435 + */
4436 +- for (i = 0; i < (max_wait * 1000); i++) {
4437 ++ for (i = 0; i < max_wait; i++) {
4438 + curr_abs_state = instance->instancet->
4439 + read_fw_status_reg(instance->reg_set);
4440 +
4441 + if (abs_state == curr_abs_state) {
4442 +- msleep(1);
4443 ++ msleep(1000);
4444 + } else
4445 + break;
4446 + }
4447 +@@ -5324,7 +5324,7 @@ static int megasas_init_fw(struct megasas_instance *instance)
4448 + if (!instance->msix_vectors) {
4449 + i = pci_alloc_irq_vectors(instance->pdev, 1, 1, PCI_IRQ_LEGACY);
4450 + if (i < 0)
4451 +- goto fail_setup_irqs;
4452 ++ goto fail_init_adapter;
4453 + }
4454 +
4455 + megasas_setup_reply_map(instance);
4456 +@@ -5541,9 +5541,8 @@ static int megasas_init_fw(struct megasas_instance *instance)
4457 +
4458 + fail_get_ld_pd_list:
4459 + instance->instancet->disable_intr(instance);
4460 +-fail_init_adapter:
4461 + megasas_destroy_irqs(instance);
4462 +-fail_setup_irqs:
4463 ++fail_init_adapter:
4464 + if (instance->msix_vectors)
4465 + pci_free_irq_vectors(instance->pdev);
4466 + instance->msix_vectors = 0;
4467 +diff --git a/drivers/scsi/mpt3sas/mpt3sas_base.c b/drivers/scsi/mpt3sas/mpt3sas_base.c
4468 +index 7bfe53f48d1d..817a7963a038 100644
4469 +--- a/drivers/scsi/mpt3sas/mpt3sas_base.c
4470 ++++ b/drivers/scsi/mpt3sas/mpt3sas_base.c
4471 +@@ -3140,7 +3140,7 @@ _base_static_config_pages(struct MPT3SAS_ADAPTER *ioc)
4472 + * flag unset in NVDATA.
4473 + */
4474 + mpt3sas_config_get_manufacturing_pg11(ioc, &mpi_reply, &ioc->manu_pg11);
4475 +- if (ioc->manu_pg11.EEDPTagMode == 0) {
4476 ++ if (!ioc->is_gen35_ioc && ioc->manu_pg11.EEDPTagMode == 0) {
4477 + pr_err("%s: overriding NVDATA EEDPTagMode setting\n",
4478 + ioc->name);
4479 + ioc->manu_pg11.EEDPTagMode &= ~0x3;
4480 +diff --git a/drivers/scsi/mpt3sas/mpt3sas_config.c b/drivers/scsi/mpt3sas/mpt3sas_config.c
4481 +index dd6270125614..58acbff40abc 100644
4482 +--- a/drivers/scsi/mpt3sas/mpt3sas_config.c
4483 ++++ b/drivers/scsi/mpt3sas/mpt3sas_config.c
4484 +@@ -674,10 +674,6 @@ mpt3sas_config_set_manufacturing_pg11(struct MPT3SAS_ADAPTER *ioc,
4485 + r = _config_request(ioc, &mpi_request, mpi_reply,
4486 + MPT3_CONFIG_PAGE_DEFAULT_TIMEOUT, config_page,
4487 + sizeof(*config_page));
4488 +- mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_WRITE_NVRAM;
4489 +- r = _config_request(ioc, &mpi_request, mpi_reply,
4490 +- MPT3_CONFIG_PAGE_DEFAULT_TIMEOUT, config_page,
4491 +- sizeof(*config_page));
4492 + out:
4493 + return r;
4494 + }
4495 +diff --git a/drivers/scsi/mpt3sas/mpt3sas_scsih.c b/drivers/scsi/mpt3sas/mpt3sas_scsih.c
4496 +index b28efddab7b1..9ef0c6265cd2 100644
4497 +--- a/drivers/scsi/mpt3sas/mpt3sas_scsih.c
4498 ++++ b/drivers/scsi/mpt3sas/mpt3sas_scsih.c
4499 +@@ -3328,6 +3328,40 @@ _scsih_tm_tr_complete(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index,
4500 + return _scsih_check_for_pending_tm(ioc, smid);
4501 + }
4502 +
4503 ++/** _scsih_allow_scmd_to_device - check whether scmd needs to
4504 ++ * issue to IOC or not.
4505 ++ * @ioc: per adapter object
4506 ++ * @scmd: pointer to scsi command object
4507 ++ *
4508 ++ * Returns true if scmd can be issued to IOC otherwise returns false.
4509 ++ */
4510 ++inline bool _scsih_allow_scmd_to_device(struct MPT3SAS_ADAPTER *ioc,
4511 ++ struct scsi_cmnd *scmd)
4512 ++{
4513 ++
4514 ++ if (ioc->pci_error_recovery)
4515 ++ return false;
4516 ++
4517 ++ if (ioc->hba_mpi_version_belonged == MPI2_VERSION) {
4518 ++ if (ioc->remove_host)
4519 ++ return false;
4520 ++
4521 ++ return true;
4522 ++ }
4523 ++
4524 ++ if (ioc->remove_host) {
4525 ++
4526 ++ switch (scmd->cmnd[0]) {
4527 ++ case SYNCHRONIZE_CACHE:
4528 ++ case START_STOP:
4529 ++ return true;
4530 ++ default:
4531 ++ return false;
4532 ++ }
4533 ++ }
4534 ++
4535 ++ return true;
4536 ++}
4537 +
4538 + /**
4539 + * _scsih_sas_control_complete - completion routine
4540 +@@ -4100,7 +4134,7 @@ scsih_qcmd(struct Scsi_Host *shost, struct scsi_cmnd *scmd)
4541 + return 0;
4542 + }
4543 +
4544 +- if (ioc->pci_error_recovery || ioc->remove_host) {
4545 ++ if (!(_scsih_allow_scmd_to_device(ioc, scmd))) {
4546 + scmd->result = DID_NO_CONNECT << 16;
4547 + scmd->scsi_done(scmd);
4548 + return 0;
4549 +diff --git a/drivers/spi/spi-omap2-mcspi.c b/drivers/spi/spi-omap2-mcspi.c
4550 +index 9bf64e6eca9b..1db4d3c1d2bf 100644
4551 +--- a/drivers/spi/spi-omap2-mcspi.c
4552 ++++ b/drivers/spi/spi-omap2-mcspi.c
4553 +@@ -298,7 +298,7 @@ static void omap2_mcspi_set_fifo(const struct spi_device *spi,
4554 + struct omap2_mcspi_cs *cs = spi->controller_state;
4555 + struct omap2_mcspi *mcspi;
4556 + unsigned int wcnt;
4557 +- int max_fifo_depth, fifo_depth, bytes_per_word;
4558 ++ int max_fifo_depth, bytes_per_word;
4559 + u32 chconf, xferlevel;
4560 +
4561 + mcspi = spi_master_get_devdata(master);
4562 +@@ -314,10 +314,6 @@ static void omap2_mcspi_set_fifo(const struct spi_device *spi,
4563 + else
4564 + max_fifo_depth = OMAP2_MCSPI_MAX_FIFODEPTH;
4565 +
4566 +- fifo_depth = gcd(t->len, max_fifo_depth);
4567 +- if (fifo_depth < 2 || fifo_depth % bytes_per_word != 0)
4568 +- goto disable_fifo;
4569 +-
4570 + wcnt = t->len / bytes_per_word;
4571 + if (wcnt > OMAP2_MCSPI_MAX_FIFOWCNT)
4572 + goto disable_fifo;
4573 +@@ -325,16 +321,17 @@ static void omap2_mcspi_set_fifo(const struct spi_device *spi,
4574 + xferlevel = wcnt << 16;
4575 + if (t->rx_buf != NULL) {
4576 + chconf |= OMAP2_MCSPI_CHCONF_FFER;
4577 +- xferlevel |= (fifo_depth - 1) << 8;
4578 ++ xferlevel |= (bytes_per_word - 1) << 8;
4579 + }
4580 ++
4581 + if (t->tx_buf != NULL) {
4582 + chconf |= OMAP2_MCSPI_CHCONF_FFET;
4583 +- xferlevel |= fifo_depth - 1;
4584 ++ xferlevel |= bytes_per_word - 1;
4585 + }
4586 +
4587 + mcspi_write_reg(master, OMAP2_MCSPI_XFERLEVEL, xferlevel);
4588 + mcspi_write_chconf0(spi, chconf);
4589 +- mcspi->fifo_depth = fifo_depth;
4590 ++ mcspi->fifo_depth = max_fifo_depth;
4591 +
4592 + return;
4593 + }
4594 +@@ -601,7 +598,6 @@ omap2_mcspi_txrx_dma(struct spi_device *spi, struct spi_transfer *xfer)
4595 + struct dma_slave_config cfg;
4596 + enum dma_slave_buswidth width;
4597 + unsigned es;
4598 +- u32 burst;
4599 + void __iomem *chstat_reg;
4600 + void __iomem *irqstat_reg;
4601 + int wait_res;
4602 +@@ -623,22 +619,14 @@ omap2_mcspi_txrx_dma(struct spi_device *spi, struct spi_transfer *xfer)
4603 + }
4604 +
4605 + count = xfer->len;
4606 +- burst = 1;
4607 +-
4608 +- if (mcspi->fifo_depth > 0) {
4609 +- if (count > mcspi->fifo_depth)
4610 +- burst = mcspi->fifo_depth / es;
4611 +- else
4612 +- burst = count / es;
4613 +- }
4614 +
4615 + memset(&cfg, 0, sizeof(cfg));
4616 + cfg.src_addr = cs->phys + OMAP2_MCSPI_RX0;
4617 + cfg.dst_addr = cs->phys + OMAP2_MCSPI_TX0;
4618 + cfg.src_addr_width = width;
4619 + cfg.dst_addr_width = width;
4620 +- cfg.src_maxburst = burst;
4621 +- cfg.dst_maxburst = burst;
4622 ++ cfg.src_maxburst = 1;
4623 ++ cfg.dst_maxburst = 1;
4624 +
4625 + rx = xfer->rx_buf;
4626 + tx = xfer->tx_buf;
4627 +diff --git a/drivers/spi/spi-sh-msiof.c b/drivers/spi/spi-sh-msiof.c
4628 +index db2a529accae..a7bd3c92356b 100644
4629 +--- a/drivers/spi/spi-sh-msiof.c
4630 ++++ b/drivers/spi/spi-sh-msiof.c
4631 +@@ -1283,8 +1283,8 @@ static int sh_msiof_spi_probe(struct platform_device *pdev)
4632 +
4633 + i = platform_get_irq(pdev, 0);
4634 + if (i < 0) {
4635 +- dev_err(&pdev->dev, "cannot get platform IRQ\n");
4636 +- ret = -ENOENT;
4637 ++ dev_err(&pdev->dev, "cannot get IRQ\n");
4638 ++ ret = i;
4639 + goto err1;
4640 + }
4641 +
4642 +diff --git a/drivers/staging/ccree/cc_hw_queue_defs.h b/drivers/staging/ccree/cc_hw_queue_defs.h
4643 +index 2ae0f655e7a0..b86f47712e30 100644
4644 +--- a/drivers/staging/ccree/cc_hw_queue_defs.h
4645 ++++ b/drivers/staging/ccree/cc_hw_queue_defs.h
4646 +@@ -467,8 +467,7 @@ static inline void set_flow_mode(struct cc_hw_desc *pdesc,
4647 + * @pdesc: pointer HW descriptor struct
4648 + * @mode: Any one of the modes defined in [CC7x-DESC]
4649 + */
4650 +-static inline void set_cipher_mode(struct cc_hw_desc *pdesc,
4651 +- enum drv_cipher_mode mode)
4652 ++static inline void set_cipher_mode(struct cc_hw_desc *pdesc, int mode)
4653 + {
4654 + pdesc->word[4] |= FIELD_PREP(WORD4_CIPHER_MODE, mode);
4655 + }
4656 +@@ -479,8 +478,7 @@ static inline void set_cipher_mode(struct cc_hw_desc *pdesc,
4657 + * @pdesc: pointer HW descriptor struct
4658 + * @mode: Any one of the modes defined in [CC7x-DESC]
4659 + */
4660 +-static inline void set_cipher_config0(struct cc_hw_desc *pdesc,
4661 +- enum drv_crypto_direction mode)
4662 ++static inline void set_cipher_config0(struct cc_hw_desc *pdesc, int mode)
4663 + {
4664 + pdesc->word[4] |= FIELD_PREP(WORD4_CIPHER_CONF0, mode);
4665 + }
4666 +diff --git a/drivers/staging/comedi/drivers/usbduxfast.c b/drivers/staging/comedi/drivers/usbduxfast.c
4667 +index 608403c7586b..f0572d6a5f63 100644
4668 +--- a/drivers/staging/comedi/drivers/usbduxfast.c
4669 ++++ b/drivers/staging/comedi/drivers/usbduxfast.c
4670 +@@ -1,5 +1,5 @@
4671 + /*
4672 +- * Copyright (C) 2004-2014 Bernd Porr, mail@××××××××××××.uk
4673 ++ * Copyright (C) 2004-2019 Bernd Porr, mail@××××××××××××.uk
4674 + *
4675 + * This program is free software; you can redistribute it and/or modify
4676 + * it under the terms of the GNU General Public License as published by
4677 +@@ -17,7 +17,7 @@
4678 + * Description: University of Stirling USB DAQ & INCITE Technology Limited
4679 + * Devices: [ITL] USB-DUX-FAST (usbduxfast)
4680 + * Author: Bernd Porr <mail@××××××××××××.uk>
4681 +- * Updated: 10 Oct 2014
4682 ++ * Updated: 16 Nov 2019
4683 + * Status: stable
4684 + */
4685 +
4686 +@@ -31,6 +31,7 @@
4687 + *
4688 + *
4689 + * Revision history:
4690 ++ * 1.0: Fixed a rounding error in usbduxfast_ai_cmdtest
4691 + * 0.9: Dropping the first data packet which seems to be from the last transfer.
4692 + * Buffer overflows in the FX2 are handed over to comedi.
4693 + * 0.92: Dropping now 4 packets. The quad buffer has to be emptied.
4694 +@@ -359,6 +360,7 @@ static int usbduxfast_ai_cmdtest(struct comedi_device *dev,
4695 + struct comedi_cmd *cmd)
4696 + {
4697 + int err = 0;
4698 ++ int err2 = 0;
4699 + unsigned int steps;
4700 + unsigned int arg;
4701 +
4702 +@@ -408,11 +410,16 @@ static int usbduxfast_ai_cmdtest(struct comedi_device *dev,
4703 + */
4704 + steps = (cmd->convert_arg * 30) / 1000;
4705 + if (cmd->chanlist_len != 1)
4706 +- err |= comedi_check_trigger_arg_min(&steps,
4707 +- MIN_SAMPLING_PERIOD);
4708 +- err |= comedi_check_trigger_arg_max(&steps, MAX_SAMPLING_PERIOD);
4709 +- arg = (steps * 1000) / 30;
4710 +- err |= comedi_check_trigger_arg_is(&cmd->convert_arg, arg);
4711 ++ err2 |= comedi_check_trigger_arg_min(&steps,
4712 ++ MIN_SAMPLING_PERIOD);
4713 ++ else
4714 ++ err2 |= comedi_check_trigger_arg_min(&steps, 1);
4715 ++ err2 |= comedi_check_trigger_arg_max(&steps, MAX_SAMPLING_PERIOD);
4716 ++ if (err2) {
4717 ++ err |= err2;
4718 ++ arg = (steps * 1000) / 30;
4719 ++ err |= comedi_check_trigger_arg_is(&cmd->convert_arg, arg);
4720 ++ }
4721 +
4722 + if (cmd->stop_src == TRIG_COUNT)
4723 + err |= comedi_check_trigger_arg_min(&cmd->stop_arg, 1);
4724 +diff --git a/drivers/thermal/rcar_thermal.c b/drivers/thermal/rcar_thermal.c
4725 +index 73e5fee6cf1d..83126e2dce36 100644
4726 +--- a/drivers/thermal/rcar_thermal.c
4727 ++++ b/drivers/thermal/rcar_thermal.c
4728 +@@ -401,8 +401,8 @@ static irqreturn_t rcar_thermal_irq(int irq, void *data)
4729 + rcar_thermal_for_each_priv(priv, common) {
4730 + if (rcar_thermal_had_changed(priv, status)) {
4731 + rcar_thermal_irq_disable(priv);
4732 +- schedule_delayed_work(&priv->work,
4733 +- msecs_to_jiffies(300));
4734 ++ queue_delayed_work(system_freezable_wq, &priv->work,
4735 ++ msecs_to_jiffies(300));
4736 + }
4737 + }
4738 +
4739 +diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
4740 +index 9e26c530d2dd..b3208b1b1028 100644
4741 +--- a/drivers/tty/pty.c
4742 ++++ b/drivers/tty/pty.c
4743 +@@ -28,6 +28,7 @@
4744 + #include <linux/mount.h>
4745 + #include <linux/file.h>
4746 + #include <linux/ioctl.h>
4747 ++#include <linux/compat.h>
4748 +
4749 + #undef TTY_DEBUG_HANGUP
4750 + #ifdef TTY_DEBUG_HANGUP
4751 +@@ -488,6 +489,7 @@ static int pty_bsd_ioctl(struct tty_struct *tty,
4752 + return -ENOIOCTLCMD;
4753 + }
4754 +
4755 ++#ifdef CONFIG_COMPAT
4756 + static long pty_bsd_compat_ioctl(struct tty_struct *tty,
4757 + unsigned int cmd, unsigned long arg)
4758 + {
4759 +@@ -495,8 +497,11 @@ static long pty_bsd_compat_ioctl(struct tty_struct *tty,
4760 + * PTY ioctls don't require any special translation between 32-bit and
4761 + * 64-bit userspace, they are already compatible.
4762 + */
4763 +- return pty_bsd_ioctl(tty, cmd, arg);
4764 ++ return pty_bsd_ioctl(tty, cmd, (unsigned long)compat_ptr(arg));
4765 + }
4766 ++#else
4767 ++#define pty_bsd_compat_ioctl NULL
4768 ++#endif
4769 +
4770 + static int legacy_count = CONFIG_LEGACY_PTY_COUNT;
4771 + /*
4772 +@@ -676,6 +681,7 @@ static int pty_unix98_ioctl(struct tty_struct *tty,
4773 + return -ENOIOCTLCMD;
4774 + }
4775 +
4776 ++#ifdef CONFIG_COMPAT
4777 + static long pty_unix98_compat_ioctl(struct tty_struct *tty,
4778 + unsigned int cmd, unsigned long arg)
4779 + {
4780 +@@ -683,8 +689,12 @@ static long pty_unix98_compat_ioctl(struct tty_struct *tty,
4781 + * PTY ioctls don't require any special translation between 32-bit and
4782 + * 64-bit userspace, they are already compatible.
4783 + */
4784 +- return pty_unix98_ioctl(tty, cmd, arg);
4785 ++ return pty_unix98_ioctl(tty, cmd,
4786 ++ cmd == TIOCSIG ? arg : (unsigned long)compat_ptr(arg));
4787 + }
4788 ++#else
4789 ++#define pty_unix98_compat_ioctl NULL
4790 ++#endif
4791 +
4792 + /**
4793 + * ptm_unix98_lookup - find a pty master
4794 +diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c
4795 +index 636b8ae29b46..344e8c427c7e 100644
4796 +--- a/drivers/tty/synclink_gt.c
4797 ++++ b/drivers/tty/synclink_gt.c
4798 +@@ -1187,14 +1187,13 @@ static long slgt_compat_ioctl(struct tty_struct *tty,
4799 + unsigned int cmd, unsigned long arg)
4800 + {
4801 + struct slgt_info *info = tty->driver_data;
4802 +- int rc = -ENOIOCTLCMD;
4803 ++ int rc;
4804 +
4805 + if (sanity_check(info, tty->name, "compat_ioctl"))
4806 + return -ENODEV;
4807 + DBGINFO(("%s compat_ioctl() cmd=%08X\n", info->device_name, cmd));
4808 +
4809 + switch (cmd) {
4810 +-
4811 + case MGSL_IOCSPARAMS32:
4812 + rc = set_params32(info, compat_ptr(arg));
4813 + break;
4814 +@@ -1214,18 +1213,11 @@ static long slgt_compat_ioctl(struct tty_struct *tty,
4815 + case MGSL_IOCWAITGPIO:
4816 + case MGSL_IOCGXSYNC:
4817 + case MGSL_IOCGXCTRL:
4818 +- case MGSL_IOCSTXIDLE:
4819 +- case MGSL_IOCTXENABLE:
4820 +- case MGSL_IOCRXENABLE:
4821 +- case MGSL_IOCTXABORT:
4822 +- case TIOCMIWAIT:
4823 +- case MGSL_IOCSIF:
4824 +- case MGSL_IOCSXSYNC:
4825 +- case MGSL_IOCSXCTRL:
4826 +- rc = ioctl(tty, cmd, arg);
4827 ++ rc = ioctl(tty, cmd, (unsigned long)compat_ptr(arg));
4828 + break;
4829 ++ default:
4830 ++ rc = ioctl(tty, cmd, arg);
4831 + }
4832 +-
4833 + DBGINFO(("%s compat_ioctl() cmd=%08X rc=%d\n", info->device_name, cmd, rc));
4834 + return rc;
4835 + }
4836 +diff --git a/drivers/usb/misc/appledisplay.c b/drivers/usb/misc/appledisplay.c
4837 +index 03be7c75c5be..aad7963e40e7 100644
4838 +--- a/drivers/usb/misc/appledisplay.c
4839 ++++ b/drivers/usb/misc/appledisplay.c
4840 +@@ -160,8 +160,11 @@ static int appledisplay_bl_update_status(struct backlight_device *bd)
4841 + pdata->msgdata, 2,
4842 + ACD_USB_TIMEOUT);
4843 + mutex_unlock(&pdata->sysfslock);
4844 +-
4845 +- return retval;
4846 ++
4847 ++ if (retval < 0)
4848 ++ return retval;
4849 ++ else
4850 ++ return 0;
4851 + }
4852 +
4853 + static int appledisplay_bl_get_brightness(struct backlight_device *bd)
4854 +@@ -179,7 +182,12 @@ static int appledisplay_bl_get_brightness(struct backlight_device *bd)
4855 + 0,
4856 + pdata->msgdata, 2,
4857 + ACD_USB_TIMEOUT);
4858 +- brightness = pdata->msgdata[1];
4859 ++ if (retval < 2) {
4860 ++ if (retval >= 0)
4861 ++ retval = -EMSGSIZE;
4862 ++ } else {
4863 ++ brightness = pdata->msgdata[1];
4864 ++ }
4865 + mutex_unlock(&pdata->sysfslock);
4866 +
4867 + if (retval < 0)
4868 +@@ -314,6 +322,7 @@ error:
4869 + if (pdata) {
4870 + if (pdata->urb) {
4871 + usb_kill_urb(pdata->urb);
4872 ++ cancel_delayed_work_sync(&pdata->work);
4873 + if (pdata->urbdata)
4874 + usb_free_coherent(pdata->udev, ACD_URB_BUFFER_LEN,
4875 + pdata->urbdata, pdata->urb->transfer_dma);
4876 +diff --git a/drivers/usb/misc/chaoskey.c b/drivers/usb/misc/chaoskey.c
4877 +index eb0795c5ff7a..3a701c1e9e75 100644
4878 +--- a/drivers/usb/misc/chaoskey.c
4879 ++++ b/drivers/usb/misc/chaoskey.c
4880 +@@ -396,13 +396,17 @@ static int _chaoskey_fill(struct chaoskey *dev)
4881 + !dev->reading,
4882 + (started ? NAK_TIMEOUT : ALEA_FIRST_TIMEOUT) );
4883 +
4884 +- if (result < 0)
4885 ++ if (result < 0) {
4886 ++ usb_kill_urb(dev->urb);
4887 + goto out;
4888 ++ }
4889 +
4890 +- if (result == 0)
4891 ++ if (result == 0) {
4892 + result = -ETIMEDOUT;
4893 +- else
4894 ++ usb_kill_urb(dev->urb);
4895 ++ } else {
4896 + result = dev->valid;
4897 ++ }
4898 + out:
4899 + /* Let the device go back to sleep eventually */
4900 + usb_autopm_put_interface(dev->interface);
4901 +@@ -538,7 +542,21 @@ static int chaoskey_suspend(struct usb_interface *interface,
4902 +
4903 + static int chaoskey_resume(struct usb_interface *interface)
4904 + {
4905 ++ struct chaoskey *dev;
4906 ++ struct usb_device *udev = interface_to_usbdev(interface);
4907 ++
4908 + usb_dbg(interface, "resume");
4909 ++ dev = usb_get_intfdata(interface);
4910 ++
4911 ++ /*
4912 ++ * We may have lost power.
4913 ++ * In that case the device that needs a long time
4914 ++ * for the first requests needs an extended timeout
4915 ++ * again
4916 ++ */
4917 ++ if (le16_to_cpu(udev->descriptor.idVendor) == ALEA_VENDOR_ID)
4918 ++ dev->reads_started = false;
4919 ++
4920 + return 0;
4921 + }
4922 + #else
4923 +diff --git a/drivers/usb/serial/cp210x.c b/drivers/usb/serial/cp210x.c
4924 +index 98e466c3cfca..8dd9852f399d 100644
4925 +--- a/drivers/usb/serial/cp210x.c
4926 ++++ b/drivers/usb/serial/cp210x.c
4927 +@@ -128,6 +128,7 @@ static const struct usb_device_id id_table[] = {
4928 + { USB_DEVICE(0x10C4, 0x8341) }, /* Siemens MC35PU GPRS Modem */
4929 + { USB_DEVICE(0x10C4, 0x8382) }, /* Cygnal Integrated Products, Inc. */
4930 + { USB_DEVICE(0x10C4, 0x83A8) }, /* Amber Wireless AMB2560 */
4931 ++ { USB_DEVICE(0x10C4, 0x83AA) }, /* Mark-10 Digital Force Gauge */
4932 + { USB_DEVICE(0x10C4, 0x83D8) }, /* DekTec DTA Plus VHF/UHF Booster/Attenuator */
4933 + { USB_DEVICE(0x10C4, 0x8411) }, /* Kyocera GPS Module */
4934 + { USB_DEVICE(0x10C4, 0x8418) }, /* IRZ Automation Teleport SG-10 GSM/GPRS Modem */
4935 +diff --git a/drivers/usb/serial/mos7720.c b/drivers/usb/serial/mos7720.c
4936 +index 393a91ab56ed..37967f4d93fd 100644
4937 +--- a/drivers/usb/serial/mos7720.c
4938 ++++ b/drivers/usb/serial/mos7720.c
4939 +@@ -1905,10 +1905,6 @@ static int mos7720_startup(struct usb_serial *serial)
4940 + product = le16_to_cpu(serial->dev->descriptor.idProduct);
4941 + dev = serial->dev;
4942 +
4943 +- /* setting configuration feature to one */
4944 +- usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
4945 +- (__u8)0x03, 0x00, 0x01, 0x00, NULL, 0x00, 5000);
4946 +-
4947 + if (product == MOSCHIP_DEVICE_ID_7715) {
4948 + struct urb *urb = serial->port[0]->interrupt_in_urb;
4949 +
4950 +diff --git a/drivers/usb/serial/mos7840.c b/drivers/usb/serial/mos7840.c
4951 +index 5e490177cf75..285527f115dd 100644
4952 +--- a/drivers/usb/serial/mos7840.c
4953 ++++ b/drivers/usb/serial/mos7840.c
4954 +@@ -131,11 +131,15 @@
4955 + /* This driver also supports
4956 + * ATEN UC2324 device using Moschip MCS7840
4957 + * ATEN UC2322 device using Moschip MCS7820
4958 ++ * MOXA UPort 2210 device using Moschip MCS7820
4959 + */
4960 + #define USB_VENDOR_ID_ATENINTL 0x0557
4961 + #define ATENINTL_DEVICE_ID_UC2324 0x2011
4962 + #define ATENINTL_DEVICE_ID_UC2322 0x7820
4963 +
4964 ++#define USB_VENDOR_ID_MOXA 0x110a
4965 ++#define MOXA_DEVICE_ID_2210 0x2210
4966 ++
4967 + /* Interrupt Routine Defines */
4968 +
4969 + #define SERIAL_IIR_RLS 0x06
4970 +@@ -206,6 +210,7 @@ static const struct usb_device_id id_table[] = {
4971 + {USB_DEVICE(USB_VENDOR_ID_BANDB, BANDB_DEVICE_ID_USOPTL2_4)},
4972 + {USB_DEVICE(USB_VENDOR_ID_ATENINTL, ATENINTL_DEVICE_ID_UC2324)},
4973 + {USB_DEVICE(USB_VENDOR_ID_ATENINTL, ATENINTL_DEVICE_ID_UC2322)},
4974 ++ {USB_DEVICE(USB_VENDOR_ID_MOXA, MOXA_DEVICE_ID_2210)},
4975 + {} /* terminating entry */
4976 + };
4977 + MODULE_DEVICE_TABLE(usb, id_table);
4978 +@@ -2065,6 +2070,7 @@ static int mos7840_probe(struct usb_serial *serial,
4979 + const struct usb_device_id *id)
4980 + {
4981 + u16 product = le16_to_cpu(serial->dev->descriptor.idProduct);
4982 ++ u16 vid = le16_to_cpu(serial->dev->descriptor.idVendor);
4983 + u8 *buf;
4984 + int device_type;
4985 +
4986 +@@ -2074,6 +2080,11 @@ static int mos7840_probe(struct usb_serial *serial,
4987 + goto out;
4988 + }
4989 +
4990 ++ if (vid == USB_VENDOR_ID_MOXA && product == MOXA_DEVICE_ID_2210) {
4991 ++ device_type = MOSCHIP_DEVICE_ID_7820;
4992 ++ goto out;
4993 ++ }
4994 ++
4995 + buf = kzalloc(VENDOR_READ_LENGTH, GFP_KERNEL);
4996 + if (!buf)
4997 + return -ENOMEM;
4998 +@@ -2327,11 +2338,6 @@ out:
4999 + goto error;
5000 + } else
5001 + dev_dbg(&port->dev, "ZLP_REG5 Writing success status%d\n", status);
5002 +-
5003 +- /* setting configuration feature to one */
5004 +- usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
5005 +- 0x03, 0x00, 0x01, 0x00, NULL, 0x00,
5006 +- MOS_WDR_TIMEOUT);
5007 + }
5008 + return 0;
5009 + error:
5010 +diff --git a/drivers/usb/serial/option.c b/drivers/usb/serial/option.c
5011 +index b9fad046828d..8d349f2e5656 100644
5012 +--- a/drivers/usb/serial/option.c
5013 ++++ b/drivers/usb/serial/option.c
5014 +@@ -200,6 +200,7 @@ static void option_instat_callback(struct urb *urb);
5015 + #define DELL_PRODUCT_5804_MINICARD_ATT 0x819b /* Novatel E371 */
5016 +
5017 + #define DELL_PRODUCT_5821E 0x81d7
5018 ++#define DELL_PRODUCT_5821E_ESIM 0x81e0
5019 +
5020 + #define KYOCERA_VENDOR_ID 0x0c88
5021 + #define KYOCERA_PRODUCT_KPC650 0x17da
5022 +@@ -1047,6 +1048,8 @@ static const struct usb_device_id option_ids[] = {
5023 + { USB_DEVICE_AND_INTERFACE_INFO(DELL_VENDOR_ID, DELL_PRODUCT_5804_MINICARD_ATT, 0xff, 0xff, 0xff) },
5024 + { USB_DEVICE(DELL_VENDOR_ID, DELL_PRODUCT_5821E),
5025 + .driver_info = RSVD(0) | RSVD(1) | RSVD(6) },
5026 ++ { USB_DEVICE(DELL_VENDOR_ID, DELL_PRODUCT_5821E_ESIM),
5027 ++ .driver_info = RSVD(0) | RSVD(1) | RSVD(6) },
5028 + { USB_DEVICE(ANYDATA_VENDOR_ID, ANYDATA_PRODUCT_ADU_E100A) }, /* ADU-E100, ADU-310 */
5029 + { USB_DEVICE(ANYDATA_VENDOR_ID, ANYDATA_PRODUCT_ADU_500A) },
5030 + { USB_DEVICE(ANYDATA_VENDOR_ID, ANYDATA_PRODUCT_ADU_620UW) },
5031 +@@ -1992,6 +1995,10 @@ static const struct usb_device_id option_ids[] = {
5032 + { USB_DEVICE_AND_INTERFACE_INFO(0x03f0, 0xa31d, 0xff, 0x06, 0x13) },
5033 + { USB_DEVICE_AND_INTERFACE_INFO(0x03f0, 0xa31d, 0xff, 0x06, 0x14) },
5034 + { USB_DEVICE_AND_INTERFACE_INFO(0x03f0, 0xa31d, 0xff, 0x06, 0x1b) },
5035 ++ { USB_DEVICE(0x0489, 0xe0b4), /* Foxconn T77W968 */
5036 ++ .driver_info = RSVD(0) | RSVD(1) | RSVD(6) },
5037 ++ { USB_DEVICE(0x0489, 0xe0b5), /* Foxconn T77W968 ESIM */
5038 ++ .driver_info = RSVD(0) | RSVD(1) | RSVD(6) },
5039 + { USB_DEVICE(0x1508, 0x1001), /* Fibocom NL668 */
5040 + .driver_info = RSVD(4) | RSVD(5) | RSVD(6) },
5041 + { USB_DEVICE(0x2cb7, 0x0104), /* Fibocom NL678 series */
5042 +diff --git a/drivers/usb/usbip/stub_rx.c b/drivers/usb/usbip/stub_rx.c
5043 +index 8812d3edade1..cb24b22252e4 100644
5044 +--- a/drivers/usb/usbip/stub_rx.c
5045 ++++ b/drivers/usb/usbip/stub_rx.c
5046 +@@ -487,18 +487,50 @@ static void stub_recv_cmd_submit(struct stub_device *sdev,
5047 + if (pipe == -1)
5048 + return;
5049 +
5050 ++ /*
5051 ++ * Smatch reported the error case where use_sg is true and buf_len is 0.
5052 ++ * In this case, It adds SDEV_EVENT_ERROR_MALLOC and stub_priv will be
5053 ++ * released by stub event handler and connection will be shut down.
5054 ++ */
5055 + priv = stub_priv_alloc(sdev, pdu);
5056 + if (!priv)
5057 + return;
5058 +
5059 + buf_len = (unsigned long long)pdu->u.cmd_submit.transfer_buffer_length;
5060 +
5061 ++ if (use_sg && !buf_len) {
5062 ++ dev_err(&udev->dev, "sg buffer with zero length\n");
5063 ++ goto err_malloc;
5064 ++ }
5065 ++
5066 + /* allocate urb transfer buffer, if needed */
5067 + if (buf_len) {
5068 + if (use_sg) {
5069 + sgl = sgl_alloc(buf_len, GFP_KERNEL, &nents);
5070 + if (!sgl)
5071 + goto err_malloc;
5072 ++
5073 ++ /* Check if the server's HCD supports SG */
5074 ++ if (!udev->bus->sg_tablesize) {
5075 ++ /*
5076 ++ * If the server's HCD doesn't support SG, break
5077 ++ * a single SG request into several URBs and map
5078 ++ * each SG list entry to corresponding URB
5079 ++ * buffer. The previously allocated SG list is
5080 ++ * stored in priv->sgl (If the server's HCD
5081 ++ * support SG, SG list is stored only in
5082 ++ * urb->sg) and it is used as an indicator that
5083 ++ * the server split single SG request into
5084 ++ * several URBs. Later, priv->sgl is used by
5085 ++ * stub_complete() and stub_send_ret_submit() to
5086 ++ * reassemble the divied URBs.
5087 ++ */
5088 ++ support_sg = 0;
5089 ++ num_urbs = nents;
5090 ++ priv->completed_urbs = 0;
5091 ++ pdu->u.cmd_submit.transfer_flags &=
5092 ++ ~URB_DMA_MAP_SG;
5093 ++ }
5094 + } else {
5095 + buffer = kzalloc(buf_len, GFP_KERNEL);
5096 + if (!buffer)
5097 +@@ -506,24 +538,6 @@ static void stub_recv_cmd_submit(struct stub_device *sdev,
5098 + }
5099 + }
5100 +
5101 +- /* Check if the server's HCD supports SG */
5102 +- if (use_sg && !udev->bus->sg_tablesize) {
5103 +- /*
5104 +- * If the server's HCD doesn't support SG, break a single SG
5105 +- * request into several URBs and map each SG list entry to
5106 +- * corresponding URB buffer. The previously allocated SG
5107 +- * list is stored in priv->sgl (If the server's HCD support SG,
5108 +- * SG list is stored only in urb->sg) and it is used as an
5109 +- * indicator that the server split single SG request into
5110 +- * several URBs. Later, priv->sgl is used by stub_complete() and
5111 +- * stub_send_ret_submit() to reassemble the divied URBs.
5112 +- */
5113 +- support_sg = 0;
5114 +- num_urbs = nents;
5115 +- priv->completed_urbs = 0;
5116 +- pdu->u.cmd_submit.transfer_flags &= ~URB_DMA_MAP_SG;
5117 +- }
5118 +-
5119 + /* allocate urb array */
5120 + priv->num_urbs = num_urbs;
5121 + priv->urbs = kmalloc_array(num_urbs, sizeof(*priv->urbs), GFP_KERNEL);
5122 +diff --git a/drivers/vhost/vsock.c b/drivers/vhost/vsock.c
5123 +index 5b9db5deffbb..491de830b8d9 100644
5124 +--- a/drivers/vhost/vsock.c
5125 ++++ b/drivers/vhost/vsock.c
5126 +@@ -103,7 +103,7 @@ vhost_transport_do_send_pkt(struct vhost_vsock *vsock,
5127 + struct iov_iter iov_iter;
5128 + unsigned out, in;
5129 + size_t nbytes;
5130 +- size_t len;
5131 ++ size_t iov_len, payload_len;
5132 + int head;
5133 +
5134 + spin_lock_bh(&vsock->send_pkt_list_lock);
5135 +@@ -148,8 +148,24 @@ vhost_transport_do_send_pkt(struct vhost_vsock *vsock,
5136 + break;
5137 + }
5138 +
5139 +- len = iov_length(&vq->iov[out], in);
5140 +- iov_iter_init(&iov_iter, READ, &vq->iov[out], in, len);
5141 ++ iov_len = iov_length(&vq->iov[out], in);
5142 ++ if (iov_len < sizeof(pkt->hdr)) {
5143 ++ virtio_transport_free_pkt(pkt);
5144 ++ vq_err(vq, "Buffer len [%zu] too small\n", iov_len);
5145 ++ break;
5146 ++ }
5147 ++
5148 ++ iov_iter_init(&iov_iter, READ, &vq->iov[out], in, iov_len);
5149 ++ payload_len = pkt->len - pkt->off;
5150 ++
5151 ++ /* If the packet is greater than the space available in the
5152 ++ * buffer, we split it using multiple buffers.
5153 ++ */
5154 ++ if (payload_len > iov_len - sizeof(pkt->hdr))
5155 ++ payload_len = iov_len - sizeof(pkt->hdr);
5156 ++
5157 ++ /* Set the correct length in the header */
5158 ++ pkt->hdr.len = cpu_to_le32(payload_len);
5159 +
5160 + nbytes = copy_to_iter(&pkt->hdr, sizeof(pkt->hdr), &iov_iter);
5161 + if (nbytes != sizeof(pkt->hdr)) {
5162 +@@ -158,33 +174,47 @@ vhost_transport_do_send_pkt(struct vhost_vsock *vsock,
5163 + break;
5164 + }
5165 +
5166 +- nbytes = copy_to_iter(pkt->buf, pkt->len, &iov_iter);
5167 +- if (nbytes != pkt->len) {
5168 ++ nbytes = copy_to_iter(pkt->buf + pkt->off, payload_len,
5169 ++ &iov_iter);
5170 ++ if (nbytes != payload_len) {
5171 + virtio_transport_free_pkt(pkt);
5172 + vq_err(vq, "Faulted on copying pkt buf\n");
5173 + break;
5174 + }
5175 +
5176 +- vhost_add_used(vq, head, sizeof(pkt->hdr) + pkt->len);
5177 ++ vhost_add_used(vq, head, sizeof(pkt->hdr) + payload_len);
5178 + added = true;
5179 +
5180 +- if (pkt->reply) {
5181 +- int val;
5182 +-
5183 +- val = atomic_dec_return(&vsock->queued_replies);
5184 +-
5185 +- /* Do we have resources to resume tx processing? */
5186 +- if (val + 1 == tx_vq->num)
5187 +- restart_tx = true;
5188 +- }
5189 +-
5190 + /* Deliver to monitoring devices all correctly transmitted
5191 + * packets.
5192 + */
5193 + virtio_transport_deliver_tap_pkt(pkt);
5194 +
5195 +- total_len += pkt->len;
5196 +- virtio_transport_free_pkt(pkt);
5197 ++ pkt->off += payload_len;
5198 ++ total_len += payload_len;
5199 ++
5200 ++ /* If we didn't send all the payload we can requeue the packet
5201 ++ * to send it with the next available buffer.
5202 ++ */
5203 ++ if (pkt->off < pkt->len) {
5204 ++ spin_lock_bh(&vsock->send_pkt_list_lock);
5205 ++ list_add(&pkt->list, &vsock->send_pkt_list);
5206 ++ spin_unlock_bh(&vsock->send_pkt_list_lock);
5207 ++ } else {
5208 ++ if (pkt->reply) {
5209 ++ int val;
5210 ++
5211 ++ val = atomic_dec_return(&vsock->queued_replies);
5212 ++
5213 ++ /* Do we have resources to resume tx
5214 ++ * processing?
5215 ++ */
5216 ++ if (val + 1 == tx_vq->num)
5217 ++ restart_tx = true;
5218 ++ }
5219 ++
5220 ++ virtio_transport_free_pkt(pkt);
5221 ++ }
5222 + } while(likely(!vhost_exceeds_weight(vq, ++pkts, total_len)));
5223 + if (added)
5224 + vhost_signal(&vsock->dev, vq);
5225 +diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c
5226 +index cc9d421c0929..b82bb0b08161 100644
5227 +--- a/drivers/virtio/virtio_ring.c
5228 ++++ b/drivers/virtio/virtio_ring.c
5229 +@@ -432,7 +432,7 @@ unmap_release:
5230 + kfree(desc);
5231 +
5232 + END_USE(vq);
5233 +- return -EIO;
5234 ++ return -ENOMEM;
5235 + }
5236 +
5237 + /**
5238 +diff --git a/drivers/w1/slaves/w1_ds2438.c b/drivers/w1/slaves/w1_ds2438.c
5239 +index bf641a191d07..7c4e33dbee4d 100644
5240 +--- a/drivers/w1/slaves/w1_ds2438.c
5241 ++++ b/drivers/w1/slaves/w1_ds2438.c
5242 +@@ -186,8 +186,8 @@ static int w1_ds2438_change_config_bit(struct w1_slave *sl, u8 mask, u8 value)
5243 + return -1;
5244 + }
5245 +
5246 +-static uint16_t w1_ds2438_get_voltage(struct w1_slave *sl,
5247 +- int adc_input, uint16_t *voltage)
5248 ++static int w1_ds2438_get_voltage(struct w1_slave *sl,
5249 ++ int adc_input, uint16_t *voltage)
5250 + {
5251 + unsigned int retries = W1_DS2438_RETRIES;
5252 + u8 w1_buf[DS2438_PAGE_SIZE + 1 /*for CRC*/];
5253 +@@ -235,6 +235,25 @@ post_unlock:
5254 + return ret;
5255 + }
5256 +
5257 ++static int w1_ds2438_get_current(struct w1_slave *sl, int16_t *voltage)
5258 ++{
5259 ++ u8 w1_buf[DS2438_PAGE_SIZE + 1 /*for CRC*/];
5260 ++ int ret;
5261 ++
5262 ++ mutex_lock(&sl->master->bus_mutex);
5263 ++
5264 ++ if (w1_ds2438_get_page(sl, 0, w1_buf) == 0) {
5265 ++ /* The voltage measured across current sense resistor RSENS. */
5266 ++ *voltage = (((int16_t) w1_buf[DS2438_CURRENT_MSB]) << 8) | ((int16_t) w1_buf[DS2438_CURRENT_LSB]);
5267 ++ ret = 0;
5268 ++ } else
5269 ++ ret = -1;
5270 ++
5271 ++ mutex_unlock(&sl->master->bus_mutex);
5272 ++
5273 ++ return ret;
5274 ++}
5275 ++
5276 + static ssize_t iad_write(struct file *filp, struct kobject *kobj,
5277 + struct bin_attribute *bin_attr, char *buf,
5278 + loff_t off, size_t count)
5279 +@@ -257,6 +276,27 @@ static ssize_t iad_write(struct file *filp, struct kobject *kobj,
5280 + return ret;
5281 + }
5282 +
5283 ++static ssize_t iad_read(struct file *filp, struct kobject *kobj,
5284 ++ struct bin_attribute *bin_attr, char *buf,
5285 ++ loff_t off, size_t count)
5286 ++{
5287 ++ struct w1_slave *sl = kobj_to_w1_slave(kobj);
5288 ++ int ret;
5289 ++ int16_t voltage;
5290 ++
5291 ++ if (off != 0)
5292 ++ return 0;
5293 ++ if (!buf)
5294 ++ return -EINVAL;
5295 ++
5296 ++ if (w1_ds2438_get_current(sl, &voltage) == 0) {
5297 ++ ret = snprintf(buf, count, "%i\n", voltage);
5298 ++ } else
5299 ++ ret = -EIO;
5300 ++
5301 ++ return ret;
5302 ++}
5303 ++
5304 + static ssize_t page0_read(struct file *filp, struct kobject *kobj,
5305 + struct bin_attribute *bin_attr, char *buf,
5306 + loff_t off, size_t count)
5307 +@@ -272,9 +312,13 @@ static ssize_t page0_read(struct file *filp, struct kobject *kobj,
5308 +
5309 + mutex_lock(&sl->master->bus_mutex);
5310 +
5311 ++ /* Read no more than page0 size */
5312 ++ if (count > DS2438_PAGE_SIZE)
5313 ++ count = DS2438_PAGE_SIZE;
5314 ++
5315 + if (w1_ds2438_get_page(sl, 0, w1_buf) == 0) {
5316 +- memcpy(buf, &w1_buf, DS2438_PAGE_SIZE);
5317 +- ret = DS2438_PAGE_SIZE;
5318 ++ memcpy(buf, &w1_buf, count);
5319 ++ ret = count;
5320 + } else
5321 + ret = -EIO;
5322 +
5323 +@@ -289,7 +333,6 @@ static ssize_t temperature_read(struct file *filp, struct kobject *kobj,
5324 + {
5325 + struct w1_slave *sl = kobj_to_w1_slave(kobj);
5326 + int ret;
5327 +- ssize_t c = PAGE_SIZE;
5328 + int16_t temp;
5329 +
5330 + if (off != 0)
5331 +@@ -298,8 +341,7 @@ static ssize_t temperature_read(struct file *filp, struct kobject *kobj,
5332 + return -EINVAL;
5333 +
5334 + if (w1_ds2438_get_temperature(sl, &temp) == 0) {
5335 +- c -= snprintf(buf + PAGE_SIZE - c, c, "%d\n", temp);
5336 +- ret = PAGE_SIZE - c;
5337 ++ ret = snprintf(buf, count, "%i\n", temp);
5338 + } else
5339 + ret = -EIO;
5340 +
5341 +@@ -312,7 +354,6 @@ static ssize_t vad_read(struct file *filp, struct kobject *kobj,
5342 + {
5343 + struct w1_slave *sl = kobj_to_w1_slave(kobj);
5344 + int ret;
5345 +- ssize_t c = PAGE_SIZE;
5346 + uint16_t voltage;
5347 +
5348 + if (off != 0)
5349 +@@ -321,8 +362,7 @@ static ssize_t vad_read(struct file *filp, struct kobject *kobj,
5350 + return -EINVAL;
5351 +
5352 + if (w1_ds2438_get_voltage(sl, DS2438_ADC_INPUT_VAD, &voltage) == 0) {
5353 +- c -= snprintf(buf + PAGE_SIZE - c, c, "%d\n", voltage);
5354 +- ret = PAGE_SIZE - c;
5355 ++ ret = snprintf(buf, count, "%u\n", voltage);
5356 + } else
5357 + ret = -EIO;
5358 +
5359 +@@ -335,7 +375,6 @@ static ssize_t vdd_read(struct file *filp, struct kobject *kobj,
5360 + {
5361 + struct w1_slave *sl = kobj_to_w1_slave(kobj);
5362 + int ret;
5363 +- ssize_t c = PAGE_SIZE;
5364 + uint16_t voltage;
5365 +
5366 + if (off != 0)
5367 +@@ -344,15 +383,14 @@ static ssize_t vdd_read(struct file *filp, struct kobject *kobj,
5368 + return -EINVAL;
5369 +
5370 + if (w1_ds2438_get_voltage(sl, DS2438_ADC_INPUT_VDD, &voltage) == 0) {
5371 +- c -= snprintf(buf + PAGE_SIZE - c, c, "%d\n", voltage);
5372 +- ret = PAGE_SIZE - c;
5373 ++ ret = snprintf(buf, count, "%u\n", voltage);
5374 + } else
5375 + ret = -EIO;
5376 +
5377 + return ret;
5378 + }
5379 +
5380 +-static BIN_ATTR(iad, S_IRUGO | S_IWUSR | S_IWGRP, NULL, iad_write, 1);
5381 ++static BIN_ATTR(iad, S_IRUGO | S_IWUSR | S_IWGRP, iad_read, iad_write, 0);
5382 + static BIN_ATTR_RO(page0, DS2438_PAGE_SIZE);
5383 + static BIN_ATTR_RO(temperature, 0/* real length varies */);
5384 + static BIN_ATTR_RO(vad, 0/* real length varies */);
5385 +diff --git a/drivers/xen/balloon.c b/drivers/xen/balloon.c
5386 +index 7d521babc020..71a6deeb4e71 100644
5387 +--- a/drivers/xen/balloon.c
5388 ++++ b/drivers/xen/balloon.c
5389 +@@ -356,7 +356,10 @@ static enum bp_state reserve_additional_memory(void)
5390 + * callers drop the mutex before trying again.
5391 + */
5392 + mutex_unlock(&balloon_mutex);
5393 ++ /* add_memory_resource() requires the device_hotplug lock */
5394 ++ lock_device_hotplug();
5395 + rc = add_memory_resource(nid, resource, memhp_auto_online);
5396 ++ unlock_device_hotplug();
5397 + mutex_lock(&balloon_mutex);
5398 +
5399 + if (rc) {
5400 +diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
5401 +index 27983fd657ab..d2263caff307 100644
5402 +--- a/fs/btrfs/ctree.c
5403 ++++ b/fs/btrfs/ctree.c
5404 +@@ -2988,6 +2988,10 @@ int btrfs_search_old_slot(struct btrfs_root *root, const struct btrfs_key *key,
5405 +
5406 + again:
5407 + b = get_old_root(root, time_seq);
5408 ++ if (!b) {
5409 ++ ret = -EIO;
5410 ++ goto done;
5411 ++ }
5412 + level = btrfs_header_level(b);
5413 + p->locks[level] = BTRFS_READ_LOCK;
5414 +
5415 +diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
5416 +index 49a02bf091ae..204d585e012a 100644
5417 +--- a/fs/btrfs/super.c
5418 ++++ b/fs/btrfs/super.c
5419 +@@ -1863,7 +1863,7 @@ restore:
5420 + }
5421 +
5422 + /* Used to sort the devices by max_avail(descending sort) */
5423 +-static int btrfs_cmp_device_free_bytes(const void *dev_info1,
5424 ++static inline int btrfs_cmp_device_free_bytes(const void *dev_info1,
5425 + const void *dev_info2)
5426 + {
5427 + if (((struct btrfs_device_info *)dev_info1)->max_avail >
5428 +@@ -1892,8 +1892,8 @@ static inline void btrfs_descending_sort_devices(
5429 + * The helper to calc the free space on the devices that can be used to store
5430 + * file data.
5431 + */
5432 +-static int btrfs_calc_avail_data_space(struct btrfs_fs_info *fs_info,
5433 +- u64 *free_bytes)
5434 ++static inline int btrfs_calc_avail_data_space(struct btrfs_fs_info *fs_info,
5435 ++ u64 *free_bytes)
5436 + {
5437 + struct btrfs_device_info *devices_info;
5438 + struct btrfs_fs_devices *fs_devices = fs_info->fs_devices;
5439 +diff --git a/fs/ceph/inode.c b/fs/ceph/inode.c
5440 +index 3818027c12f5..5999d806de78 100644
5441 +--- a/fs/ceph/inode.c
5442 ++++ b/fs/ceph/inode.c
5443 +@@ -1631,7 +1631,6 @@ retry_lookup:
5444 + if (IS_ERR(realdn)) {
5445 + err = PTR_ERR(realdn);
5446 + d_drop(dn);
5447 +- dn = NULL;
5448 + goto next_item;
5449 + }
5450 + dn = realdn;
5451 +diff --git a/fs/dlm/member.c b/fs/dlm/member.c
5452 +index 3fda3832cf6a..cad6d85911a8 100644
5453 +--- a/fs/dlm/member.c
5454 ++++ b/fs/dlm/member.c
5455 +@@ -680,7 +680,7 @@ int dlm_ls_start(struct dlm_ls *ls)
5456 +
5457 + error = dlm_config_nodes(ls->ls_name, &nodes, &count);
5458 + if (error < 0)
5459 +- goto fail;
5460 ++ goto fail_rv;
5461 +
5462 + spin_lock(&ls->ls_recover_lock);
5463 +
5464 +@@ -712,8 +712,9 @@ int dlm_ls_start(struct dlm_ls *ls)
5465 + return 0;
5466 +
5467 + fail:
5468 +- kfree(rv);
5469 + kfree(nodes);
5470 ++ fail_rv:
5471 ++ kfree(rv);
5472 + return error;
5473 + }
5474 +
5475 +diff --git a/fs/dlm/user.c b/fs/dlm/user.c
5476 +index d18e7a539f11..1f0c071d4a86 100644
5477 +--- a/fs/dlm/user.c
5478 ++++ b/fs/dlm/user.c
5479 +@@ -702,7 +702,7 @@ static int copy_result_to_user(struct dlm_user_args *ua, int compat,
5480 + result.version[0] = DLM_DEVICE_VERSION_MAJOR;
5481 + result.version[1] = DLM_DEVICE_VERSION_MINOR;
5482 + result.version[2] = DLM_DEVICE_VERSION_PATCH;
5483 +- memcpy(&result.lksb, &ua->lksb, sizeof(struct dlm_lksb));
5484 ++ memcpy(&result.lksb, &ua->lksb, offsetof(struct dlm_lksb, sb_lvbptr));
5485 + result.user_lksb = ua->user_lksb;
5486 +
5487 + /* FIXME: dlm1 provides for the user's bastparam/addr to not be updated
5488 +diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c
5489 +index cc5729445194..ac3fa4bbed2d 100644
5490 +--- a/fs/f2fs/data.c
5491 ++++ b/fs/f2fs/data.c
5492 +@@ -1445,6 +1445,7 @@ int do_write_data_page(struct f2fs_io_info *fio)
5493 + /* This page is already truncated */
5494 + if (fio->old_blkaddr == NULL_ADDR) {
5495 + ClearPageUptodate(page);
5496 ++ clear_cold_data(page);
5497 + goto out_writepage;
5498 + }
5499 + got_it:
5500 +@@ -1597,8 +1598,10 @@ done:
5501 +
5502 + out:
5503 + inode_dec_dirty_pages(inode);
5504 +- if (err)
5505 ++ if (err) {
5506 + ClearPageUptodate(page);
5507 ++ clear_cold_data(page);
5508 ++ }
5509 +
5510 + if (wbc->for_reclaim) {
5511 + f2fs_submit_merged_write_cond(sbi, inode, 0, page->index, DATA);
5512 +@@ -2158,6 +2161,8 @@ void f2fs_invalidate_page(struct page *page, unsigned int offset,
5513 + }
5514 + }
5515 +
5516 ++ clear_cold_data(page);
5517 ++
5518 + /* This is atomic written page, keep Private */
5519 + if (IS_ATOMIC_WRITTEN_PAGE(page))
5520 + return drop_inmem_page(inode, page);
5521 +@@ -2176,6 +2181,7 @@ int f2fs_release_page(struct page *page, gfp_t wait)
5522 + if (IS_ATOMIC_WRITTEN_PAGE(page))
5523 + return 0;
5524 +
5525 ++ clear_cold_data(page);
5526 + set_page_private(page, 0);
5527 + ClearPagePrivate(page);
5528 + return 1;
5529 +diff --git a/fs/f2fs/dir.c b/fs/f2fs/dir.c
5530 +index c0c933ad43c8..4abefd841b6c 100644
5531 +--- a/fs/f2fs/dir.c
5532 ++++ b/fs/f2fs/dir.c
5533 +@@ -745,6 +745,7 @@ void f2fs_delete_entry(struct f2fs_dir_entry *dentry, struct page *page,
5534 + clear_page_dirty_for_io(page);
5535 + ClearPagePrivate(page);
5536 + ClearPageUptodate(page);
5537 ++ clear_cold_data(page);
5538 + inode_dec_dirty_pages(dir);
5539 + remove_dirty_inode(dir);
5540 + }
5541 +diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c
5542 +index 9e5fca35e47d..2cd0d126ef8f 100644
5543 +--- a/fs/f2fs/segment.c
5544 ++++ b/fs/f2fs/segment.c
5545 +@@ -251,8 +251,10 @@ retry:
5546 + }
5547 + next:
5548 + /* we don't need to invalidate this in the sccessful status */
5549 +- if (drop || recover)
5550 ++ if (drop || recover) {
5551 + ClearPageUptodate(page);
5552 ++ clear_cold_data(page);
5553 ++ }
5554 + set_page_private(page, 0);
5555 + ClearPagePrivate(page);
5556 + f2fs_put_page(page, 1);
5557 +diff --git a/fs/gfs2/rgrp.c b/fs/gfs2/rgrp.c
5558 +index 0d72baae5150..7cb0672294df 100644
5559 +--- a/fs/gfs2/rgrp.c
5560 ++++ b/fs/gfs2/rgrp.c
5561 +@@ -623,7 +623,10 @@ static void __rs_deltree(struct gfs2_blkreserv *rs)
5562 + RB_CLEAR_NODE(&rs->rs_node);
5563 +
5564 + if (rs->rs_free) {
5565 +- struct gfs2_bitmap *bi = rbm_bi(&rs->rs_rbm);
5566 ++ u64 last_block = gfs2_rbm_to_block(&rs->rs_rbm) +
5567 ++ rs->rs_free - 1;
5568 ++ struct gfs2_rbm last_rbm = { .rgd = rs->rs_rbm.rgd, };
5569 ++ struct gfs2_bitmap *start, *last;
5570 +
5571 + /* return reserved blocks to the rgrp */
5572 + BUG_ON(rs->rs_rbm.rgd->rd_reserved < rs->rs_free);
5573 +@@ -634,7 +637,13 @@ static void __rs_deltree(struct gfs2_blkreserv *rs)
5574 + it will force the number to be recalculated later. */
5575 + rgd->rd_extfail_pt += rs->rs_free;
5576 + rs->rs_free = 0;
5577 +- clear_bit(GBF_FULL, &bi->bi_flags);
5578 ++ if (gfs2_rbm_from_block(&last_rbm, last_block))
5579 ++ return;
5580 ++ start = rbm_bi(&rs->rs_rbm);
5581 ++ last = rbm_bi(&last_rbm);
5582 ++ do
5583 ++ clear_bit(GBF_FULL, &start->bi_flags);
5584 ++ while (start++ != last);
5585 + }
5586 + }
5587 +
5588 +diff --git a/fs/hfs/brec.c b/fs/hfs/brec.c
5589 +index da25c49203cc..896396554bcc 100644
5590 +--- a/fs/hfs/brec.c
5591 ++++ b/fs/hfs/brec.c
5592 +@@ -445,6 +445,7 @@ skip:
5593 + /* restore search_key */
5594 + hfs_bnode_read_key(node, fd->search_key, 14);
5595 + }
5596 ++ new_node = NULL;
5597 + }
5598 +
5599 + if (!rec && node->parent)
5600 +diff --git a/fs/hfs/btree.c b/fs/hfs/btree.c
5601 +index 9bdff5e40626..19017d296173 100644
5602 +--- a/fs/hfs/btree.c
5603 ++++ b/fs/hfs/btree.c
5604 +@@ -220,25 +220,17 @@ static struct hfs_bnode *hfs_bmap_new_bmap(struct hfs_bnode *prev, u32 idx)
5605 + return node;
5606 + }
5607 +
5608 +-struct hfs_bnode *hfs_bmap_alloc(struct hfs_btree *tree)
5609 ++/* Make sure @tree has enough space for the @rsvd_nodes */
5610 ++int hfs_bmap_reserve(struct hfs_btree *tree, int rsvd_nodes)
5611 + {
5612 +- struct hfs_bnode *node, *next_node;
5613 +- struct page **pagep;
5614 +- u32 nidx, idx;
5615 +- unsigned off;
5616 +- u16 off16;
5617 +- u16 len;
5618 +- u8 *data, byte, m;
5619 +- int i;
5620 +-
5621 +- while (!tree->free_nodes) {
5622 +- struct inode *inode = tree->inode;
5623 +- u32 count;
5624 +- int res;
5625 ++ struct inode *inode = tree->inode;
5626 ++ u32 count;
5627 ++ int res;
5628 +
5629 ++ while (tree->free_nodes < rsvd_nodes) {
5630 + res = hfs_extend_file(inode);
5631 + if (res)
5632 +- return ERR_PTR(res);
5633 ++ return res;
5634 + HFS_I(inode)->phys_size = inode->i_size =
5635 + (loff_t)HFS_I(inode)->alloc_blocks *
5636 + HFS_SB(tree->sb)->alloc_blksz;
5637 +@@ -246,9 +238,26 @@ struct hfs_bnode *hfs_bmap_alloc(struct hfs_btree *tree)
5638 + tree->sb->s_blocksize_bits;
5639 + inode_set_bytes(inode, inode->i_size);
5640 + count = inode->i_size >> tree->node_size_shift;
5641 +- tree->free_nodes = count - tree->node_count;
5642 ++ tree->free_nodes += count - tree->node_count;
5643 + tree->node_count = count;
5644 + }
5645 ++ return 0;
5646 ++}
5647 ++
5648 ++struct hfs_bnode *hfs_bmap_alloc(struct hfs_btree *tree)
5649 ++{
5650 ++ struct hfs_bnode *node, *next_node;
5651 ++ struct page **pagep;
5652 ++ u32 nidx, idx;
5653 ++ unsigned off;
5654 ++ u16 off16;
5655 ++ u16 len;
5656 ++ u8 *data, byte, m;
5657 ++ int i, res;
5658 ++
5659 ++ res = hfs_bmap_reserve(tree, 1);
5660 ++ if (res)
5661 ++ return ERR_PTR(res);
5662 +
5663 + nidx = 0;
5664 + node = hfs_bnode_find(tree, nidx);
5665 +diff --git a/fs/hfs/btree.h b/fs/hfs/btree.h
5666 +index c8b252dbb26c..dcc2aab1b2c4 100644
5667 +--- a/fs/hfs/btree.h
5668 ++++ b/fs/hfs/btree.h
5669 +@@ -82,6 +82,7 @@ struct hfs_find_data {
5670 + extern struct hfs_btree *hfs_btree_open(struct super_block *, u32, btree_keycmp);
5671 + extern void hfs_btree_close(struct hfs_btree *);
5672 + extern void hfs_btree_write(struct hfs_btree *);
5673 ++extern int hfs_bmap_reserve(struct hfs_btree *, int);
5674 + extern struct hfs_bnode * hfs_bmap_alloc(struct hfs_btree *);
5675 + extern void hfs_bmap_free(struct hfs_bnode *node);
5676 +
5677 +diff --git a/fs/hfs/catalog.c b/fs/hfs/catalog.c
5678 +index 8a66405b0f8b..d365bf0b8c77 100644
5679 +--- a/fs/hfs/catalog.c
5680 ++++ b/fs/hfs/catalog.c
5681 +@@ -97,6 +97,14 @@ int hfs_cat_create(u32 cnid, struct inode *dir, const struct qstr *str, struct i
5682 + if (err)
5683 + return err;
5684 +
5685 ++ /*
5686 ++ * Fail early and avoid ENOSPC during the btree operations. We may
5687 ++ * have to split the root node at most once.
5688 ++ */
5689 ++ err = hfs_bmap_reserve(fd.tree, 2 * fd.tree->depth);
5690 ++ if (err)
5691 ++ goto err2;
5692 ++
5693 + hfs_cat_build_key(sb, fd.search_key, cnid, NULL);
5694 + entry_size = hfs_cat_build_thread(sb, &entry, S_ISDIR(inode->i_mode) ?
5695 + HFS_CDR_THD : HFS_CDR_FTH,
5696 +@@ -295,6 +303,14 @@ int hfs_cat_move(u32 cnid, struct inode *src_dir, const struct qstr *src_name,
5697 + return err;
5698 + dst_fd = src_fd;
5699 +
5700 ++ /*
5701 ++ * Fail early and avoid ENOSPC during the btree operations. We may
5702 ++ * have to split the root node at most once.
5703 ++ */
5704 ++ err = hfs_bmap_reserve(src_fd.tree, 2 * src_fd.tree->depth);
5705 ++ if (err)
5706 ++ goto out;
5707 ++
5708 + /* find the old dir entry and read the data */
5709 + hfs_cat_build_key(sb, src_fd.search_key, src_dir->i_ino, src_name);
5710 + err = hfs_brec_find(&src_fd);
5711 +diff --git a/fs/hfs/extent.c b/fs/hfs/extent.c
5712 +index 5d0182654580..263d5028d9d1 100644
5713 +--- a/fs/hfs/extent.c
5714 ++++ b/fs/hfs/extent.c
5715 +@@ -117,6 +117,10 @@ static int __hfs_ext_write_extent(struct inode *inode, struct hfs_find_data *fd)
5716 + if (HFS_I(inode)->flags & HFS_FLG_EXT_NEW) {
5717 + if (res != -ENOENT)
5718 + return res;
5719 ++ /* Fail early and avoid ENOSPC during the btree operation */
5720 ++ res = hfs_bmap_reserve(fd->tree, fd->tree->depth + 1);
5721 ++ if (res)
5722 ++ return res;
5723 + hfs_brec_insert(fd, HFS_I(inode)->cached_extents, sizeof(hfs_extent_rec));
5724 + HFS_I(inode)->flags &= ~(HFS_FLG_EXT_DIRTY|HFS_FLG_EXT_NEW);
5725 + } else {
5726 +@@ -300,7 +304,7 @@ int hfs_free_fork(struct super_block *sb, struct hfs_cat_file *file, int type)
5727 + return 0;
5728 +
5729 + blocks = 0;
5730 +- for (i = 0; i < 3; extent++, i++)
5731 ++ for (i = 0; i < 3; i++)
5732 + blocks += be16_to_cpu(extent[i].count);
5733 +
5734 + res = hfs_free_extents(sb, extent, blocks, blocks);
5735 +@@ -341,7 +345,9 @@ int hfs_get_block(struct inode *inode, sector_t block,
5736 + ablock = (u32)block / HFS_SB(sb)->fs_div;
5737 +
5738 + if (block >= HFS_I(inode)->fs_blocks) {
5739 +- if (block > HFS_I(inode)->fs_blocks || !create)
5740 ++ if (!create)
5741 ++ return 0;
5742 ++ if (block > HFS_I(inode)->fs_blocks)
5743 + return -EIO;
5744 + if (ablock >= HFS_I(inode)->alloc_blocks) {
5745 + res = hfs_extend_file(inode);
5746 +diff --git a/fs/hfs/inode.c b/fs/hfs/inode.c
5747 +index 2538b49cc349..350afd67bd69 100644
5748 +--- a/fs/hfs/inode.c
5749 ++++ b/fs/hfs/inode.c
5750 +@@ -642,6 +642,8 @@ int hfs_inode_setattr(struct dentry *dentry, struct iattr * attr)
5751 +
5752 + truncate_setsize(inode, attr->ia_size);
5753 + hfs_file_truncate(inode);
5754 ++ inode->i_atime = inode->i_mtime = inode->i_ctime =
5755 ++ current_time(inode);
5756 + }
5757 +
5758 + setattr_copy(inode, attr);
5759 +diff --git a/fs/hfsplus/attributes.c b/fs/hfsplus/attributes.c
5760 +index 2bab6b3cdba4..e6d554476db4 100644
5761 +--- a/fs/hfsplus/attributes.c
5762 ++++ b/fs/hfsplus/attributes.c
5763 +@@ -217,6 +217,11 @@ int hfsplus_create_attr(struct inode *inode,
5764 + if (err)
5765 + goto failed_init_create_attr;
5766 +
5767 ++ /* Fail early and avoid ENOSPC during the btree operation */
5768 ++ err = hfs_bmap_reserve(fd.tree, fd.tree->depth + 1);
5769 ++ if (err)
5770 ++ goto failed_create_attr;
5771 ++
5772 + if (name) {
5773 + err = hfsplus_attr_build_key(sb, fd.search_key,
5774 + inode->i_ino, name);
5775 +@@ -313,6 +318,11 @@ int hfsplus_delete_attr(struct inode *inode, const char *name)
5776 + if (err)
5777 + return err;
5778 +
5779 ++ /* Fail early and avoid ENOSPC during the btree operation */
5780 ++ err = hfs_bmap_reserve(fd.tree, fd.tree->depth);
5781 ++ if (err)
5782 ++ goto out;
5783 ++
5784 + if (name) {
5785 + err = hfsplus_attr_build_key(sb, fd.search_key,
5786 + inode->i_ino, name);
5787 +diff --git a/fs/hfsplus/brec.c b/fs/hfsplus/brec.c
5788 +index d3f36982f685..0f53a486d2c1 100644
5789 +--- a/fs/hfsplus/brec.c
5790 ++++ b/fs/hfsplus/brec.c
5791 +@@ -448,6 +448,7 @@ skip:
5792 + /* restore search_key */
5793 + hfs_bnode_read_key(node, fd->search_key, 14);
5794 + }
5795 ++ new_node = NULL;
5796 + }
5797 +
5798 + if (!rec && node->parent)
5799 +diff --git a/fs/hfsplus/btree.c b/fs/hfsplus/btree.c
5800 +index 3de3bc4918b5..66774f4cb4fd 100644
5801 +--- a/fs/hfsplus/btree.c
5802 ++++ b/fs/hfsplus/btree.c
5803 +@@ -342,26 +342,21 @@ static struct hfs_bnode *hfs_bmap_new_bmap(struct hfs_bnode *prev, u32 idx)
5804 + return node;
5805 + }
5806 +
5807 +-struct hfs_bnode *hfs_bmap_alloc(struct hfs_btree *tree)
5808 ++/* Make sure @tree has enough space for the @rsvd_nodes */
5809 ++int hfs_bmap_reserve(struct hfs_btree *tree, int rsvd_nodes)
5810 + {
5811 +- struct hfs_bnode *node, *next_node;
5812 +- struct page **pagep;
5813 +- u32 nidx, idx;
5814 +- unsigned off;
5815 +- u16 off16;
5816 +- u16 len;
5817 +- u8 *data, byte, m;
5818 +- int i;
5819 ++ struct inode *inode = tree->inode;
5820 ++ struct hfsplus_inode_info *hip = HFSPLUS_I(inode);
5821 ++ u32 count;
5822 ++ int res;
5823 +
5824 +- while (!tree->free_nodes) {
5825 +- struct inode *inode = tree->inode;
5826 +- struct hfsplus_inode_info *hip = HFSPLUS_I(inode);
5827 +- u32 count;
5828 +- int res;
5829 ++ if (rsvd_nodes <= 0)
5830 ++ return 0;
5831 +
5832 ++ while (tree->free_nodes < rsvd_nodes) {
5833 + res = hfsplus_file_extend(inode, hfs_bnode_need_zeroout(tree));
5834 + if (res)
5835 +- return ERR_PTR(res);
5836 ++ return res;
5837 + hip->phys_size = inode->i_size =
5838 + (loff_t)hip->alloc_blocks <<
5839 + HFSPLUS_SB(tree->sb)->alloc_blksz_shift;
5840 +@@ -369,9 +364,26 @@ struct hfs_bnode *hfs_bmap_alloc(struct hfs_btree *tree)
5841 + hip->alloc_blocks << HFSPLUS_SB(tree->sb)->fs_shift;
5842 + inode_set_bytes(inode, inode->i_size);
5843 + count = inode->i_size >> tree->node_size_shift;
5844 +- tree->free_nodes = count - tree->node_count;
5845 ++ tree->free_nodes += count - tree->node_count;
5846 + tree->node_count = count;
5847 + }
5848 ++ return 0;
5849 ++}
5850 ++
5851 ++struct hfs_bnode *hfs_bmap_alloc(struct hfs_btree *tree)
5852 ++{
5853 ++ struct hfs_bnode *node, *next_node;
5854 ++ struct page **pagep;
5855 ++ u32 nidx, idx;
5856 ++ unsigned off;
5857 ++ u16 off16;
5858 ++ u16 len;
5859 ++ u8 *data, byte, m;
5860 ++ int i, res;
5861 ++
5862 ++ res = hfs_bmap_reserve(tree, 1);
5863 ++ if (res)
5864 ++ return ERR_PTR(res);
5865 +
5866 + nidx = 0;
5867 + node = hfs_bnode_find(tree, nidx);
5868 +diff --git a/fs/hfsplus/catalog.c b/fs/hfsplus/catalog.c
5869 +index a196369ba779..35472cba750e 100644
5870 +--- a/fs/hfsplus/catalog.c
5871 ++++ b/fs/hfsplus/catalog.c
5872 +@@ -265,6 +265,14 @@ int hfsplus_create_cat(u32 cnid, struct inode *dir,
5873 + if (err)
5874 + return err;
5875 +
5876 ++ /*
5877 ++ * Fail early and avoid ENOSPC during the btree operations. We may
5878 ++ * have to split the root node at most once.
5879 ++ */
5880 ++ err = hfs_bmap_reserve(fd.tree, 2 * fd.tree->depth);
5881 ++ if (err)
5882 ++ goto err2;
5883 ++
5884 + hfsplus_cat_build_key_with_cnid(sb, fd.search_key, cnid);
5885 + entry_size = hfsplus_fill_cat_thread(sb, &entry,
5886 + S_ISDIR(inode->i_mode) ?
5887 +@@ -333,6 +341,14 @@ int hfsplus_delete_cat(u32 cnid, struct inode *dir, const struct qstr *str)
5888 + if (err)
5889 + return err;
5890 +
5891 ++ /*
5892 ++ * Fail early and avoid ENOSPC during the btree operations. We may
5893 ++ * have to split the root node at most once.
5894 ++ */
5895 ++ err = hfs_bmap_reserve(fd.tree, 2 * (int)fd.tree->depth - 2);
5896 ++ if (err)
5897 ++ goto out;
5898 ++
5899 + if (!str) {
5900 + int len;
5901 +
5902 +@@ -433,6 +449,14 @@ int hfsplus_rename_cat(u32 cnid,
5903 + return err;
5904 + dst_fd = src_fd;
5905 +
5906 ++ /*
5907 ++ * Fail early and avoid ENOSPC during the btree operations. We may
5908 ++ * have to split the root node at most twice.
5909 ++ */
5910 ++ err = hfs_bmap_reserve(src_fd.tree, 4 * (int)src_fd.tree->depth - 1);
5911 ++ if (err)
5912 ++ goto out;
5913 ++
5914 + /* find the old dir entry and read the data */
5915 + err = hfsplus_cat_build_key(sb, src_fd.search_key,
5916 + src_dir->i_ino, src_name);
5917 +diff --git a/fs/hfsplus/extents.c b/fs/hfsplus/extents.c
5918 +index e8770935ce6d..58f296bfd438 100644
5919 +--- a/fs/hfsplus/extents.c
5920 ++++ b/fs/hfsplus/extents.c
5921 +@@ -100,6 +100,10 @@ static int __hfsplus_ext_write_extent(struct inode *inode,
5922 + if (hip->extent_state & HFSPLUS_EXT_NEW) {
5923 + if (res != -ENOENT)
5924 + return res;
5925 ++ /* Fail early and avoid ENOSPC during the btree operation */
5926 ++ res = hfs_bmap_reserve(fd->tree, fd->tree->depth + 1);
5927 ++ if (res)
5928 ++ return res;
5929 + hfs_brec_insert(fd, hip->cached_extents,
5930 + sizeof(hfsplus_extent_rec));
5931 + hip->extent_state &= ~(HFSPLUS_EXT_DIRTY | HFSPLUS_EXT_NEW);
5932 +@@ -233,7 +237,9 @@ int hfsplus_get_block(struct inode *inode, sector_t iblock,
5933 + ablock = iblock >> sbi->fs_shift;
5934 +
5935 + if (iblock >= hip->fs_blocks) {
5936 +- if (iblock > hip->fs_blocks || !create)
5937 ++ if (!create)
5938 ++ return 0;
5939 ++ if (iblock > hip->fs_blocks)
5940 + return -EIO;
5941 + if (ablock >= hip->alloc_blocks) {
5942 + res = hfsplus_file_extend(inode, false);
5943 +diff --git a/fs/hfsplus/hfsplus_fs.h b/fs/hfsplus/hfsplus_fs.h
5944 +index a015044daa05..dbb55d823385 100644
5945 +--- a/fs/hfsplus/hfsplus_fs.h
5946 ++++ b/fs/hfsplus/hfsplus_fs.h
5947 +@@ -312,6 +312,7 @@ static inline unsigned short hfsplus_min_io_size(struct super_block *sb)
5948 + #define hfs_btree_open hfsplus_btree_open
5949 + #define hfs_btree_close hfsplus_btree_close
5950 + #define hfs_btree_write hfsplus_btree_write
5951 ++#define hfs_bmap_reserve hfsplus_bmap_reserve
5952 + #define hfs_bmap_alloc hfsplus_bmap_alloc
5953 + #define hfs_bmap_free hfsplus_bmap_free
5954 + #define hfs_bnode_read hfsplus_bnode_read
5955 +@@ -396,6 +397,7 @@ u32 hfsplus_calc_btree_clump_size(u32 block_size, u32 node_size, u64 sectors,
5956 + struct hfs_btree *hfs_btree_open(struct super_block *sb, u32 id);
5957 + void hfs_btree_close(struct hfs_btree *tree);
5958 + int hfs_btree_write(struct hfs_btree *tree);
5959 ++int hfs_bmap_reserve(struct hfs_btree *tree, int rsvd_nodes);
5960 + struct hfs_bnode *hfs_bmap_alloc(struct hfs_btree *tree);
5961 + void hfs_bmap_free(struct hfs_bnode *node);
5962 +
5963 +diff --git a/fs/hfsplus/inode.c b/fs/hfsplus/inode.c
5964 +index 190c60efbc99..5b31f4730ee9 100644
5965 +--- a/fs/hfsplus/inode.c
5966 ++++ b/fs/hfsplus/inode.c
5967 +@@ -262,6 +262,7 @@ static int hfsplus_setattr(struct dentry *dentry, struct iattr *attr)
5968 + }
5969 + truncate_setsize(inode, attr->ia_size);
5970 + hfsplus_file_truncate(inode);
5971 ++ inode->i_mtime = inode->i_ctime = current_time(inode);
5972 + }
5973 +
5974 + setattr_copy(inode, attr);
5975 +diff --git a/fs/ocfs2/buffer_head_io.c b/fs/ocfs2/buffer_head_io.c
5976 +index 9f8250df99f1..f9b84f7a3e4b 100644
5977 +--- a/fs/ocfs2/buffer_head_io.c
5978 ++++ b/fs/ocfs2/buffer_head_io.c
5979 +@@ -99,25 +99,34 @@ out:
5980 + return ret;
5981 + }
5982 +
5983 ++/* Caller must provide a bhs[] with all NULL or non-NULL entries, so it
5984 ++ * will be easier to handle read failure.
5985 ++ */
5986 + int ocfs2_read_blocks_sync(struct ocfs2_super *osb, u64 block,
5987 + unsigned int nr, struct buffer_head *bhs[])
5988 + {
5989 + int status = 0;
5990 + unsigned int i;
5991 + struct buffer_head *bh;
5992 ++ int new_bh = 0;
5993 +
5994 + trace_ocfs2_read_blocks_sync((unsigned long long)block, nr);
5995 +
5996 + if (!nr)
5997 + goto bail;
5998 +
5999 ++ /* Don't put buffer head and re-assign it to NULL if it is allocated
6000 ++ * outside since the caller can't be aware of this alternation!
6001 ++ */
6002 ++ new_bh = (bhs[0] == NULL);
6003 ++
6004 + for (i = 0 ; i < nr ; i++) {
6005 + if (bhs[i] == NULL) {
6006 + bhs[i] = sb_getblk(osb->sb, block++);
6007 + if (bhs[i] == NULL) {
6008 + status = -ENOMEM;
6009 + mlog_errno(status);
6010 +- goto bail;
6011 ++ break;
6012 + }
6013 + }
6014 + bh = bhs[i];
6015 +@@ -157,9 +166,26 @@ int ocfs2_read_blocks_sync(struct ocfs2_super *osb, u64 block,
6016 + submit_bh(REQ_OP_READ, 0, bh);
6017 + }
6018 +
6019 ++read_failure:
6020 + for (i = nr; i > 0; i--) {
6021 + bh = bhs[i - 1];
6022 +
6023 ++ if (unlikely(status)) {
6024 ++ if (new_bh && bh) {
6025 ++ /* If middle bh fails, let previous bh
6026 ++ * finish its read and then put it to
6027 ++ * aovoid bh leak
6028 ++ */
6029 ++ if (!buffer_jbd(bh))
6030 ++ wait_on_buffer(bh);
6031 ++ put_bh(bh);
6032 ++ bhs[i - 1] = NULL;
6033 ++ } else if (bh && buffer_uptodate(bh)) {
6034 ++ clear_buffer_uptodate(bh);
6035 ++ }
6036 ++ continue;
6037 ++ }
6038 ++
6039 + /* No need to wait on the buffer if it's managed by JBD. */
6040 + if (!buffer_jbd(bh))
6041 + wait_on_buffer(bh);
6042 +@@ -169,8 +195,7 @@ int ocfs2_read_blocks_sync(struct ocfs2_super *osb, u64 block,
6043 + * so we can safely record this and loop back
6044 + * to cleanup the other buffers. */
6045 + status = -EIO;
6046 +- put_bh(bh);
6047 +- bhs[i - 1] = NULL;
6048 ++ goto read_failure;
6049 + }
6050 + }
6051 +
6052 +@@ -178,6 +203,9 @@ bail:
6053 + return status;
6054 + }
6055 +
6056 ++/* Caller must provide a bhs[] with all NULL or non-NULL entries, so it
6057 ++ * will be easier to handle read failure.
6058 ++ */
6059 + int ocfs2_read_blocks(struct ocfs2_caching_info *ci, u64 block, int nr,
6060 + struct buffer_head *bhs[], int flags,
6061 + int (*validate)(struct super_block *sb,
6062 +@@ -187,6 +215,7 @@ int ocfs2_read_blocks(struct ocfs2_caching_info *ci, u64 block, int nr,
6063 + int i, ignore_cache = 0;
6064 + struct buffer_head *bh;
6065 + struct super_block *sb = ocfs2_metadata_cache_get_super(ci);
6066 ++ int new_bh = 0;
6067 +
6068 + trace_ocfs2_read_blocks_begin(ci, (unsigned long long)block, nr, flags);
6069 +
6070 +@@ -212,6 +241,11 @@ int ocfs2_read_blocks(struct ocfs2_caching_info *ci, u64 block, int nr,
6071 + goto bail;
6072 + }
6073 +
6074 ++ /* Don't put buffer head and re-assign it to NULL if it is allocated
6075 ++ * outside since the caller can't be aware of this alternation!
6076 ++ */
6077 ++ new_bh = (bhs[0] == NULL);
6078 ++
6079 + ocfs2_metadata_cache_io_lock(ci);
6080 + for (i = 0 ; i < nr ; i++) {
6081 + if (bhs[i] == NULL) {
6082 +@@ -220,7 +254,8 @@ int ocfs2_read_blocks(struct ocfs2_caching_info *ci, u64 block, int nr,
6083 + ocfs2_metadata_cache_io_unlock(ci);
6084 + status = -ENOMEM;
6085 + mlog_errno(status);
6086 +- goto bail;
6087 ++ /* Don't forget to put previous bh! */
6088 ++ break;
6089 + }
6090 + }
6091 + bh = bhs[i];
6092 +@@ -314,16 +349,27 @@ int ocfs2_read_blocks(struct ocfs2_caching_info *ci, u64 block, int nr,
6093 + }
6094 + }
6095 +
6096 +- status = 0;
6097 +-
6098 ++read_failure:
6099 + for (i = (nr - 1); i >= 0; i--) {
6100 + bh = bhs[i];
6101 +
6102 + if (!(flags & OCFS2_BH_READAHEAD)) {
6103 +- if (status) {
6104 +- /* Clear the rest of the buffers on error */
6105 +- put_bh(bh);
6106 +- bhs[i] = NULL;
6107 ++ if (unlikely(status)) {
6108 ++ /* Clear the buffers on error including those
6109 ++ * ever succeeded in reading
6110 ++ */
6111 ++ if (new_bh && bh) {
6112 ++ /* If middle bh fails, let previous bh
6113 ++ * finish its read and then put it to
6114 ++ * aovoid bh leak
6115 ++ */
6116 ++ if (!buffer_jbd(bh))
6117 ++ wait_on_buffer(bh);
6118 ++ put_bh(bh);
6119 ++ bhs[i] = NULL;
6120 ++ } else if (bh && buffer_uptodate(bh)) {
6121 ++ clear_buffer_uptodate(bh);
6122 ++ }
6123 + continue;
6124 + }
6125 + /* We know this can't have changed as we hold the
6126 +@@ -341,9 +387,7 @@ int ocfs2_read_blocks(struct ocfs2_caching_info *ci, u64 block, int nr,
6127 + * uptodate. */
6128 + status = -EIO;
6129 + clear_buffer_needs_validate(bh);
6130 +- put_bh(bh);
6131 +- bhs[i] = NULL;
6132 +- continue;
6133 ++ goto read_failure;
6134 + }
6135 +
6136 + if (buffer_needs_validate(bh)) {
6137 +@@ -353,11 +397,8 @@ int ocfs2_read_blocks(struct ocfs2_caching_info *ci, u64 block, int nr,
6138 + BUG_ON(buffer_jbd(bh));
6139 + clear_buffer_needs_validate(bh);
6140 + status = validate(sb, bh);
6141 +- if (status) {
6142 +- put_bh(bh);
6143 +- bhs[i] = NULL;
6144 +- continue;
6145 +- }
6146 ++ if (status)
6147 ++ goto read_failure;
6148 + }
6149 + }
6150 +
6151 +diff --git a/fs/ocfs2/dlm/dlmdebug.c b/fs/ocfs2/dlm/dlmdebug.c
6152 +index 9b984cae4c4e..1d6dc8422899 100644
6153 +--- a/fs/ocfs2/dlm/dlmdebug.c
6154 ++++ b/fs/ocfs2/dlm/dlmdebug.c
6155 +@@ -329,7 +329,7 @@ void dlm_print_one_mle(struct dlm_master_list_entry *mle)
6156 + {
6157 + char *buf;
6158 +
6159 +- buf = (char *) get_zeroed_page(GFP_NOFS);
6160 ++ buf = (char *) get_zeroed_page(GFP_ATOMIC);
6161 + if (buf) {
6162 + dump_mle(mle, buf, PAGE_SIZE - 1);
6163 + free_page((unsigned long)buf);
6164 +diff --git a/fs/ocfs2/dlmglue.c b/fs/ocfs2/dlmglue.c
6165 +index 5193218f5889..e961015fb484 100644
6166 +--- a/fs/ocfs2/dlmglue.c
6167 ++++ b/fs/ocfs2/dlmglue.c
6168 +@@ -3422,7 +3422,7 @@ static int ocfs2_downconvert_lock(struct ocfs2_super *osb,
6169 + * we can recover correctly from node failure. Otherwise, we may get
6170 + * invalid LVB in LKB, but without DLM_SBF_VALNOTVALID being set.
6171 + */
6172 +- if (!ocfs2_is_o2cb_active() &&
6173 ++ if (ocfs2_userspace_stack(osb) &&
6174 + lockres->l_ops->flags & LOCK_TYPE_USES_LVB)
6175 + lvb = 1;
6176 +
6177 +diff --git a/fs/ocfs2/move_extents.c b/fs/ocfs2/move_extents.c
6178 +index f55f82ca3425..1565dd8e8856 100644
6179 +--- a/fs/ocfs2/move_extents.c
6180 ++++ b/fs/ocfs2/move_extents.c
6181 +@@ -25,6 +25,7 @@
6182 + #include "ocfs2_ioctl.h"
6183 +
6184 + #include "alloc.h"
6185 ++#include "localalloc.h"
6186 + #include "aops.h"
6187 + #include "dlmglue.h"
6188 + #include "extent_map.h"
6189 +@@ -222,6 +223,7 @@ static int ocfs2_defrag_extent(struct ocfs2_move_extents_context *context,
6190 + struct ocfs2_refcount_tree *ref_tree = NULL;
6191 + u32 new_phys_cpos, new_len;
6192 + u64 phys_blkno = ocfs2_clusters_to_blocks(inode->i_sb, phys_cpos);
6193 ++ int need_free = 0;
6194 +
6195 + if ((ext_flags & OCFS2_EXT_REFCOUNTED) && *len) {
6196 + BUG_ON(!ocfs2_is_refcount_inode(inode));
6197 +@@ -312,6 +314,7 @@ static int ocfs2_defrag_extent(struct ocfs2_move_extents_context *context,
6198 + if (!partial) {
6199 + context->range->me_flags &= ~OCFS2_MOVE_EXT_FL_COMPLETE;
6200 + ret = -ENOSPC;
6201 ++ need_free = 1;
6202 + goto out_commit;
6203 + }
6204 + }
6205 +@@ -336,6 +339,20 @@ static int ocfs2_defrag_extent(struct ocfs2_move_extents_context *context,
6206 + mlog_errno(ret);
6207 +
6208 + out_commit:
6209 ++ if (need_free && context->data_ac) {
6210 ++ struct ocfs2_alloc_context *data_ac = context->data_ac;
6211 ++
6212 ++ if (context->data_ac->ac_which == OCFS2_AC_USE_LOCAL)
6213 ++ ocfs2_free_local_alloc_bits(osb, handle, data_ac,
6214 ++ new_phys_cpos, new_len);
6215 ++ else
6216 ++ ocfs2_free_clusters(handle,
6217 ++ data_ac->ac_inode,
6218 ++ data_ac->ac_bh,
6219 ++ ocfs2_clusters_to_blocks(osb->sb, new_phys_cpos),
6220 ++ new_len);
6221 ++ }
6222 ++
6223 + ocfs2_commit_trans(osb, handle);
6224 +
6225 + out_unlock_mutex:
6226 +diff --git a/fs/ocfs2/stackglue.c b/fs/ocfs2/stackglue.c
6227 +index d6c350ba25b9..c4b029c43464 100644
6228 +--- a/fs/ocfs2/stackglue.c
6229 ++++ b/fs/ocfs2/stackglue.c
6230 +@@ -48,12 +48,6 @@ static char ocfs2_hb_ctl_path[OCFS2_MAX_HB_CTL_PATH] = "/sbin/ocfs2_hb_ctl";
6231 + */
6232 + static struct ocfs2_stack_plugin *active_stack;
6233 +
6234 +-inline int ocfs2_is_o2cb_active(void)
6235 +-{
6236 +- return !strcmp(active_stack->sp_name, OCFS2_STACK_PLUGIN_O2CB);
6237 +-}
6238 +-EXPORT_SYMBOL_GPL(ocfs2_is_o2cb_active);
6239 +-
6240 + static struct ocfs2_stack_plugin *ocfs2_stack_lookup(const char *name)
6241 + {
6242 + struct ocfs2_stack_plugin *p;
6243 +diff --git a/fs/ocfs2/stackglue.h b/fs/ocfs2/stackglue.h
6244 +index e3036e1790e8..f2dce10fae54 100644
6245 +--- a/fs/ocfs2/stackglue.h
6246 ++++ b/fs/ocfs2/stackglue.h
6247 +@@ -298,9 +298,6 @@ void ocfs2_stack_glue_set_max_proto_version(struct ocfs2_protocol_version *max_p
6248 + int ocfs2_stack_glue_register(struct ocfs2_stack_plugin *plugin);
6249 + void ocfs2_stack_glue_unregister(struct ocfs2_stack_plugin *plugin);
6250 +
6251 +-/* In ocfs2_downconvert_lock(), we need to know which stack we are using */
6252 +-int ocfs2_is_o2cb_active(void);
6253 +-
6254 + extern struct kset *ocfs2_kset;
6255 +
6256 + #endif /* STACKGLUE_H */
6257 +diff --git a/fs/ocfs2/xattr.c b/fs/ocfs2/xattr.c
6258 +index eca49da6d7e0..77740ef5a8e8 100644
6259 +--- a/fs/ocfs2/xattr.c
6260 ++++ b/fs/ocfs2/xattr.c
6261 +@@ -1497,6 +1497,18 @@ static int ocfs2_xa_check_space(struct ocfs2_xa_loc *loc,
6262 + return loc->xl_ops->xlo_check_space(loc, xi);
6263 + }
6264 +
6265 ++static void ocfs2_xa_add_entry(struct ocfs2_xa_loc *loc, u32 name_hash)
6266 ++{
6267 ++ loc->xl_ops->xlo_add_entry(loc, name_hash);
6268 ++ loc->xl_entry->xe_name_hash = cpu_to_le32(name_hash);
6269 ++ /*
6270 ++ * We can't leave the new entry's xe_name_offset at zero or
6271 ++ * add_namevalue() will go nuts. We set it to the size of our
6272 ++ * storage so that it can never be less than any other entry.
6273 ++ */
6274 ++ loc->xl_entry->xe_name_offset = cpu_to_le16(loc->xl_size);
6275 ++}
6276 ++
6277 + static void ocfs2_xa_add_namevalue(struct ocfs2_xa_loc *loc,
6278 + struct ocfs2_xattr_info *xi)
6279 + {
6280 +@@ -2128,31 +2140,29 @@ static int ocfs2_xa_prepare_entry(struct ocfs2_xa_loc *loc,
6281 + if (rc)
6282 + goto out;
6283 +
6284 +- if (!loc->xl_entry) {
6285 +- rc = -EINVAL;
6286 +- goto out;
6287 +- }
6288 +-
6289 +- if (ocfs2_xa_can_reuse_entry(loc, xi)) {
6290 +- orig_value_size = loc->xl_entry->xe_value_size;
6291 +- rc = ocfs2_xa_reuse_entry(loc, xi, ctxt);
6292 +- if (rc)
6293 +- goto out;
6294 +- goto alloc_value;
6295 +- }
6296 ++ if (loc->xl_entry) {
6297 ++ if (ocfs2_xa_can_reuse_entry(loc, xi)) {
6298 ++ orig_value_size = loc->xl_entry->xe_value_size;
6299 ++ rc = ocfs2_xa_reuse_entry(loc, xi, ctxt);
6300 ++ if (rc)
6301 ++ goto out;
6302 ++ goto alloc_value;
6303 ++ }
6304 +
6305 +- if (!ocfs2_xattr_is_local(loc->xl_entry)) {
6306 +- orig_clusters = ocfs2_xa_value_clusters(loc);
6307 +- rc = ocfs2_xa_value_truncate(loc, 0, ctxt);
6308 +- if (rc) {
6309 +- mlog_errno(rc);
6310 +- ocfs2_xa_cleanup_value_truncate(loc,
6311 +- "overwriting",
6312 +- orig_clusters);
6313 +- goto out;
6314 ++ if (!ocfs2_xattr_is_local(loc->xl_entry)) {
6315 ++ orig_clusters = ocfs2_xa_value_clusters(loc);
6316 ++ rc = ocfs2_xa_value_truncate(loc, 0, ctxt);
6317 ++ if (rc) {
6318 ++ mlog_errno(rc);
6319 ++ ocfs2_xa_cleanup_value_truncate(loc,
6320 ++ "overwriting",
6321 ++ orig_clusters);
6322 ++ goto out;
6323 ++ }
6324 + }
6325 +- }
6326 +- ocfs2_xa_wipe_namevalue(loc);
6327 ++ ocfs2_xa_wipe_namevalue(loc);
6328 ++ } else
6329 ++ ocfs2_xa_add_entry(loc, name_hash);
6330 +
6331 + /*
6332 + * If we get here, we have a blank entry. Fill it. We grow our
6333 +diff --git a/fs/read_write.c b/fs/read_write.c
6334 +index 38a8bcccf0dd..e8136a72c13f 100644
6335 +--- a/fs/read_write.c
6336 ++++ b/fs/read_write.c
6337 +@@ -1709,6 +1709,34 @@ static int clone_verify_area(struct file *file, loff_t pos, u64 len, bool write)
6338 +
6339 + return security_file_permission(file, write ? MAY_WRITE : MAY_READ);
6340 + }
6341 ++/*
6342 ++ * Ensure that we don't remap a partial EOF block in the middle of something
6343 ++ * else. Assume that the offsets have already been checked for block
6344 ++ * alignment.
6345 ++ *
6346 ++ * For deduplication we always scale down to the previous block because we
6347 ++ * can't meaningfully compare post-EOF contents.
6348 ++ *
6349 ++ * For clone we only link a partial EOF block above the destination file's EOF.
6350 ++ */
6351 ++static int generic_remap_check_len(struct inode *inode_in,
6352 ++ struct inode *inode_out,
6353 ++ loff_t pos_out,
6354 ++ u64 *len,
6355 ++ bool is_dedupe)
6356 ++{
6357 ++ u64 blkmask = i_blocksize(inode_in) - 1;
6358 ++
6359 ++ if ((*len & blkmask) == 0)
6360 ++ return 0;
6361 ++
6362 ++ if (is_dedupe)
6363 ++ *len &= ~blkmask;
6364 ++ else if (pos_out + *len < i_size_read(inode_out))
6365 ++ return -EINVAL;
6366 ++
6367 ++ return 0;
6368 ++}
6369 +
6370 + /*
6371 + * Check that the two inodes are eligible for cloning, the ranges make
6372 +@@ -1815,6 +1843,11 @@ int vfs_clone_file_prep_inodes(struct inode *inode_in, loff_t pos_in,
6373 + return -EBADE;
6374 + }
6375 +
6376 ++ ret = generic_remap_check_len(inode_in, inode_out, pos_out, len,
6377 ++ is_dedupe);
6378 ++ if (ret)
6379 ++ return ret;
6380 ++
6381 + return 1;
6382 + }
6383 + EXPORT_SYMBOL(vfs_clone_file_prep_inodes);
6384 +diff --git a/fs/xfs/xfs_buf.c b/fs/xfs/xfs_buf.c
6385 +index e4a623956df5..e5970ecdfd58 100644
6386 +--- a/fs/xfs/xfs_buf.c
6387 ++++ b/fs/xfs/xfs_buf.c
6388 +@@ -58,6 +58,32 @@ static kmem_zone_t *xfs_buf_zone;
6389 + #define xb_to_gfp(flags) \
6390 + ((((flags) & XBF_READ_AHEAD) ? __GFP_NORETRY : GFP_NOFS) | __GFP_NOWARN)
6391 +
6392 ++/*
6393 ++ * Locking orders
6394 ++ *
6395 ++ * xfs_buf_ioacct_inc:
6396 ++ * xfs_buf_ioacct_dec:
6397 ++ * b_sema (caller holds)
6398 ++ * b_lock
6399 ++ *
6400 ++ * xfs_buf_stale:
6401 ++ * b_sema (caller holds)
6402 ++ * b_lock
6403 ++ * lru_lock
6404 ++ *
6405 ++ * xfs_buf_rele:
6406 ++ * b_lock
6407 ++ * pag_buf_lock
6408 ++ * lru_lock
6409 ++ *
6410 ++ * xfs_buftarg_wait_rele
6411 ++ * lru_lock
6412 ++ * b_lock (trylock due to inversion)
6413 ++ *
6414 ++ * xfs_buftarg_isolate
6415 ++ * lru_lock
6416 ++ * b_lock (trylock due to inversion)
6417 ++ */
6418 +
6419 + static inline int
6420 + xfs_buf_is_vmapped(
6421 +@@ -983,8 +1009,18 @@ xfs_buf_rele(
6422 +
6423 + ASSERT(atomic_read(&bp->b_hold) > 0);
6424 +
6425 +- release = atomic_dec_and_lock(&bp->b_hold, &pag->pag_buf_lock);
6426 ++ /*
6427 ++ * We grab the b_lock here first to serialise racing xfs_buf_rele()
6428 ++ * calls. The pag_buf_lock being taken on the last reference only
6429 ++ * serialises against racing lookups in xfs_buf_find(). IOWs, the second
6430 ++ * to last reference we drop here is not serialised against the last
6431 ++ * reference until we take bp->b_lock. Hence if we don't grab b_lock
6432 ++ * first, the last "release" reference can win the race to the lock and
6433 ++ * free the buffer before the second-to-last reference is processed,
6434 ++ * leading to a use-after-free scenario.
6435 ++ */
6436 + spin_lock(&bp->b_lock);
6437 ++ release = atomic_dec_and_lock(&bp->b_hold, &pag->pag_buf_lock);
6438 + if (!release) {
6439 + /*
6440 + * Drop the in-flight state if the buffer is already on the LRU
6441 +diff --git a/include/linux/bitmap.h b/include/linux/bitmap.h
6442 +index 835c2271196a..aec255fb62aa 100644
6443 +--- a/include/linux/bitmap.h
6444 ++++ b/include/linux/bitmap.h
6445 +@@ -185,8 +185,13 @@ extern int bitmap_print_to_pagebuf(bool list, char *buf,
6446 + #define BITMAP_FIRST_WORD_MASK(start) (~0UL << ((start) & (BITS_PER_LONG - 1)))
6447 + #define BITMAP_LAST_WORD_MASK(nbits) (~0UL >> (-(nbits) & (BITS_PER_LONG - 1)))
6448 +
6449 ++/*
6450 ++ * The static inlines below do not handle constant nbits==0 correctly,
6451 ++ * so make such users (should any ever turn up) call the out-of-line
6452 ++ * versions.
6453 ++ */
6454 + #define small_const_nbits(nbits) \
6455 +- (__builtin_constant_p(nbits) && (nbits) <= BITS_PER_LONG)
6456 ++ (__builtin_constant_p(nbits) && (nbits) <= BITS_PER_LONG && (nbits) > 0)
6457 +
6458 + static inline void bitmap_zero(unsigned long *dst, unsigned int nbits)
6459 + {
6460 +@@ -350,7 +355,7 @@ static __always_inline void bitmap_clear(unsigned long *map, unsigned int start,
6461 + }
6462 +
6463 + static inline void bitmap_shift_right(unsigned long *dst, const unsigned long *src,
6464 +- unsigned int shift, int nbits)
6465 ++ unsigned int shift, unsigned int nbits)
6466 + {
6467 + if (small_const_nbits(nbits))
6468 + *dst = (*src & BITMAP_LAST_WORD_MASK(nbits)) >> shift;
6469 +diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
6470 +index bb4758ffd403..7668c68ddb5b 100644
6471 +--- a/include/linux/kvm_host.h
6472 ++++ b/include/linux/kvm_host.h
6473 +@@ -890,6 +890,7 @@ int kvm_cpu_has_pending_timer(struct kvm_vcpu *vcpu);
6474 + void kvm_vcpu_kick(struct kvm_vcpu *vcpu);
6475 +
6476 + bool kvm_is_reserved_pfn(kvm_pfn_t pfn);
6477 ++bool kvm_is_zone_device_pfn(kvm_pfn_t pfn);
6478 +
6479 + struct kvm_irq_ack_notifier {
6480 + struct hlist_node link;
6481 +diff --git a/include/linux/memory_hotplug.h b/include/linux/memory_hotplug.h
6482 +index 58e110aee7ab..d36a02935391 100644
6483 +--- a/include/linux/memory_hotplug.h
6484 ++++ b/include/linux/memory_hotplug.h
6485 +@@ -316,6 +316,7 @@ static inline void remove_memory(int nid, u64 start, u64 size) {}
6486 +
6487 + extern int walk_memory_range(unsigned long start_pfn, unsigned long end_pfn,
6488 + void *arg, int (*func)(struct memory_block *, void *));
6489 ++extern int __add_memory(int nid, u64 start, u64 size);
6490 + extern int add_memory(int nid, u64 start, u64 size);
6491 + extern int add_memory_resource(int nid, struct resource *resource, bool online);
6492 + extern int arch_add_memory(int nid, u64 start, u64 size, bool want_memblock);
6493 +diff --git a/include/linux/mfd/intel_soc_pmic.h b/include/linux/mfd/intel_soc_pmic.h
6494 +index 5aacdb017a9f..806a4f095312 100644
6495 +--- a/include/linux/mfd/intel_soc_pmic.h
6496 ++++ b/include/linux/mfd/intel_soc_pmic.h
6497 +@@ -25,6 +25,7 @@ struct intel_soc_pmic {
6498 + int irq;
6499 + struct regmap *regmap;
6500 + struct regmap_irq_chip_data *irq_chip_data;
6501 ++ struct regmap_irq_chip_data *irq_chip_data_pwrbtn;
6502 + struct regmap_irq_chip_data *irq_chip_data_tmu;
6503 + struct regmap_irq_chip_data *irq_chip_data_bcu;
6504 + struct regmap_irq_chip_data *irq_chip_data_adc;
6505 +diff --git a/include/linux/mfd/max8997.h b/include/linux/mfd/max8997.h
6506 +index cf815577bd68..3ae1fe743bc3 100644
6507 +--- a/include/linux/mfd/max8997.h
6508 ++++ b/include/linux/mfd/max8997.h
6509 +@@ -178,7 +178,6 @@ struct max8997_led_platform_data {
6510 + struct max8997_platform_data {
6511 + /* IRQ */
6512 + int ono;
6513 +- int wakeup;
6514 +
6515 + /* ---- PMIC ---- */
6516 + struct max8997_regulator_data *regulators;
6517 +diff --git a/include/linux/mfd/mc13xxx.h b/include/linux/mfd/mc13xxx.h
6518 +index 638222e43e48..93011c61aafd 100644
6519 +--- a/include/linux/mfd/mc13xxx.h
6520 ++++ b/include/linux/mfd/mc13xxx.h
6521 +@@ -247,6 +247,7 @@ struct mc13xxx_platform_data {
6522 + #define MC13XXX_ADC0_TSMOD0 (1 << 12)
6523 + #define MC13XXX_ADC0_TSMOD1 (1 << 13)
6524 + #define MC13XXX_ADC0_TSMOD2 (1 << 14)
6525 ++#define MC13XXX_ADC0_CHRGRAWDIV (1 << 15)
6526 + #define MC13XXX_ADC0_ADINC1 (1 << 16)
6527 + #define MC13XXX_ADC0_ADINC2 (1 << 17)
6528 +
6529 +diff --git a/kernel/auditsc.c b/kernel/auditsc.c
6530 +index 76d789d6cea0..ffa8d64f6fef 100644
6531 +--- a/kernel/auditsc.c
6532 ++++ b/kernel/auditsc.c
6533 +@@ -1102,7 +1102,7 @@ static void audit_log_execve_info(struct audit_context *context,
6534 + }
6535 +
6536 + /* write as much as we can to the audit log */
6537 +- if (len_buf > 0) {
6538 ++ if (len_buf >= 0) {
6539 + /* NOTE: some magic numbers here - basically if we
6540 + * can't fit a reasonable amount of data into the
6541 + * existing audit buffer, flush it and start with
6542 +diff --git a/kernel/bpf/devmap.c b/kernel/bpf/devmap.c
6543 +index 482bf42e21a4..1060eee6c8d5 100644
6544 +--- a/kernel/bpf/devmap.c
6545 ++++ b/kernel/bpf/devmap.c
6546 +@@ -388,8 +388,7 @@ static int dev_map_notification(struct notifier_block *notifier,
6547 + struct bpf_dtab_netdev *dev, *odev;
6548 +
6549 + dev = READ_ONCE(dtab->netdev_map[i]);
6550 +- if (!dev ||
6551 +- dev->dev->ifindex != netdev->ifindex)
6552 ++ if (!dev || netdev != dev->dev)
6553 + continue;
6554 + odev = cmpxchg(&dtab->netdev_map[i], dev, NULL);
6555 + if (dev == odev)
6556 +diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
6557 +index 5b33c14ab8b2..4e50beb162c0 100644
6558 +--- a/kernel/printk/printk.c
6559 ++++ b/kernel/printk/printk.c
6560 +@@ -1099,7 +1099,7 @@ void __init setup_log_buf(int early)
6561 + {
6562 + unsigned long flags;
6563 + char *new_log_buf;
6564 +- int free;
6565 ++ unsigned int free;
6566 +
6567 + if (log_buf != __log_buf)
6568 + return;
6569 +diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
6570 +index feeb52880d35..67433fbdcb5a 100644
6571 +--- a/kernel/sched/fair.c
6572 ++++ b/kernel/sched/fair.c
6573 +@@ -8319,13 +8319,22 @@ out_all_pinned:
6574 + sd->nr_balance_failed = 0;
6575 +
6576 + out_one_pinned:
6577 ++ ld_moved = 0;
6578 ++
6579 ++ /*
6580 ++ * idle_balance() disregards balance intervals, so we could repeatedly
6581 ++ * reach this code, which would lead to balance_interval skyrocketting
6582 ++ * in a short amount of time. Skip the balance_interval increase logic
6583 ++ * to avoid that.
6584 ++ */
6585 ++ if (env.idle == CPU_NEWLY_IDLE)
6586 ++ goto out;
6587 ++
6588 + /* tune up the balancing interval */
6589 + if (((env.flags & LBF_ALL_PINNED) &&
6590 + sd->balance_interval < MAX_PINNED_INTERVAL) ||
6591 + (sd->balance_interval < sd->max_interval))
6592 + sd->balance_interval *= 2;
6593 +-
6594 +- ld_moved = 0;
6595 + out:
6596 + return ld_moved;
6597 + }
6598 +diff --git a/kernel/sched/topology.c b/kernel/sched/topology.c
6599 +index 9dcd80ed9d4c..867d173dab48 100644
6600 +--- a/kernel/sched/topology.c
6601 ++++ b/kernel/sched/topology.c
6602 +@@ -1347,7 +1347,7 @@ void sched_init_numa(void)
6603 + int level = 0;
6604 + int i, j, k;
6605 +
6606 +- sched_domains_numa_distance = kzalloc(sizeof(int) * nr_node_ids, GFP_KERNEL);
6607 ++ sched_domains_numa_distance = kzalloc(sizeof(int) * (nr_node_ids + 1), GFP_KERNEL);
6608 + if (!sched_domains_numa_distance)
6609 + return;
6610 +
6611 +diff --git a/mm/ksm.c b/mm/ksm.c
6612 +index f50cc573815f..764486ffcd16 100644
6613 +--- a/mm/ksm.c
6614 ++++ b/mm/ksm.c
6615 +@@ -849,13 +849,13 @@ static int remove_stable_node(struct stable_node *stable_node)
6616 + return 0;
6617 + }
6618 +
6619 +- if (WARN_ON_ONCE(page_mapped(page))) {
6620 +- /*
6621 +- * This should not happen: but if it does, just refuse to let
6622 +- * merge_across_nodes be switched - there is no need to panic.
6623 +- */
6624 +- err = -EBUSY;
6625 +- } else {
6626 ++ /*
6627 ++ * Page could be still mapped if this races with __mmput() running in
6628 ++ * between ksm_exit() and exit_mmap(). Just refuse to let
6629 ++ * merge_across_nodes/max_page_sharing be switched.
6630 ++ */
6631 ++ err = -EBUSY;
6632 ++ if (!page_mapped(page)) {
6633 + /*
6634 + * The stable node did not yet appear stale to get_ksm_page(),
6635 + * since that allows for an unmapped ksm page to be recognized
6636 +diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c
6637 +index d4affa9982ca..2d6626ab29d1 100644
6638 +--- a/mm/memory_hotplug.c
6639 ++++ b/mm/memory_hotplug.c
6640 +@@ -343,12 +343,8 @@ static unsigned long find_smallest_section_pfn(int nid, struct zone *zone,
6641 + unsigned long start_pfn,
6642 + unsigned long end_pfn)
6643 + {
6644 +- struct mem_section *ms;
6645 +-
6646 + for (; start_pfn < end_pfn; start_pfn += PAGES_PER_SECTION) {
6647 +- ms = __pfn_to_section(start_pfn);
6648 +-
6649 +- if (unlikely(!valid_section(ms)))
6650 ++ if (unlikely(!pfn_to_online_page(start_pfn)))
6651 + continue;
6652 +
6653 + if (unlikely(pfn_to_nid(start_pfn) != nid))
6654 +@@ -368,15 +364,12 @@ static unsigned long find_biggest_section_pfn(int nid, struct zone *zone,
6655 + unsigned long start_pfn,
6656 + unsigned long end_pfn)
6657 + {
6658 +- struct mem_section *ms;
6659 + unsigned long pfn;
6660 +
6661 + /* pfn is the end pfn of a memory section. */
6662 + pfn = end_pfn - 1;
6663 + for (; pfn >= start_pfn; pfn -= PAGES_PER_SECTION) {
6664 +- ms = __pfn_to_section(pfn);
6665 +-
6666 +- if (unlikely(!valid_section(ms)))
6667 ++ if (unlikely(!pfn_to_online_page(pfn)))
6668 + continue;
6669 +
6670 + if (unlikely(pfn_to_nid(pfn) != nid))
6671 +@@ -398,7 +391,6 @@ static void shrink_zone_span(struct zone *zone, unsigned long start_pfn,
6672 + unsigned long z = zone_end_pfn(zone); /* zone_end_pfn namespace clash */
6673 + unsigned long zone_end_pfn = z;
6674 + unsigned long pfn;
6675 +- struct mem_section *ms;
6676 + int nid = zone_to_nid(zone);
6677 +
6678 + zone_span_writelock(zone);
6679 +@@ -436,9 +428,7 @@ static void shrink_zone_span(struct zone *zone, unsigned long start_pfn,
6680 + */
6681 + pfn = zone_start_pfn;
6682 + for (; pfn < zone_end_pfn; pfn += PAGES_PER_SECTION) {
6683 +- ms = __pfn_to_section(pfn);
6684 +-
6685 +- if (unlikely(!valid_section(ms)))
6686 ++ if (unlikely(!pfn_to_online_page(pfn)))
6687 + continue;
6688 +
6689 + if (page_zone(pfn_to_page(pfn)) != zone)
6690 +@@ -494,6 +484,16 @@ static void __remove_zone(struct zone *zone, unsigned long start_pfn)
6691 + int nr_pages = PAGES_PER_SECTION;
6692 + unsigned long flags;
6693 +
6694 ++#ifdef CONFIG_ZONE_DEVICE
6695 ++ /*
6696 ++ * Zone shrinking code cannot properly deal with ZONE_DEVICE. So
6697 ++ * we will not try to shrink the zones - which is okay as
6698 ++ * set_zone_contiguous() cannot deal with ZONE_DEVICE either way.
6699 ++ */
6700 ++ if (zone_idx(zone) == ZONE_DEVICE)
6701 ++ return;
6702 ++#endif
6703 ++
6704 + pgdat_resize_lock(zone->zone_pgdat, &flags);
6705 + shrink_zone_span(zone, start_pfn, start_pfn + nr_pages);
6706 + update_pgdat_span(pgdat);
6707 +@@ -1073,7 +1073,12 @@ static int online_memory_block(struct memory_block *mem, void *arg)
6708 + return device_online(&mem->dev);
6709 + }
6710 +
6711 +-/* we are OK calling __meminit stuff here - we have CONFIG_MEMORY_HOTPLUG */
6712 ++/*
6713 ++ * NOTE: The caller must call lock_device_hotplug() to serialize hotplug
6714 ++ * and online/offline operations (triggered e.g. by sysfs).
6715 ++ *
6716 ++ * we are OK calling __meminit stuff here - we have CONFIG_MEMORY_HOTPLUG
6717 ++ */
6718 + int __ref add_memory_resource(int nid, struct resource *res, bool online)
6719 + {
6720 + u64 start, size;
6721 +@@ -1166,9 +1171,9 @@ out:
6722 + mem_hotplug_done();
6723 + return ret;
6724 + }
6725 +-EXPORT_SYMBOL_GPL(add_memory_resource);
6726 +
6727 +-int __ref add_memory(int nid, u64 start, u64 size)
6728 ++/* requires device_hotplug_lock, see add_memory_resource() */
6729 ++int __ref __add_memory(int nid, u64 start, u64 size)
6730 + {
6731 + struct resource *res;
6732 + int ret;
6733 +@@ -1182,6 +1187,17 @@ int __ref add_memory(int nid, u64 start, u64 size)
6734 + release_memory_resource(res);
6735 + return ret;
6736 + }
6737 ++
6738 ++int add_memory(int nid, u64 start, u64 size)
6739 ++{
6740 ++ int rc;
6741 ++
6742 ++ lock_device_hotplug();
6743 ++ rc = __add_memory(nid, start, size);
6744 ++ unlock_device_hotplug();
6745 ++
6746 ++ return rc;
6747 ++}
6748 + EXPORT_SYMBOL_GPL(add_memory);
6749 +
6750 + #ifdef CONFIG_MEMORY_HOTREMOVE
6751 +diff --git a/mm/page-writeback.c b/mm/page-writeback.c
6752 +index e001de5ac50c..a40c075fd8f1 100644
6753 +--- a/mm/page-writeback.c
6754 ++++ b/mm/page-writeback.c
6755 +@@ -2150,6 +2150,13 @@ EXPORT_SYMBOL(tag_pages_for_writeback);
6756 + * not miss some pages (e.g., because some other process has cleared TOWRITE
6757 + * tag we set). The rule we follow is that TOWRITE tag can be cleared only
6758 + * by the process clearing the DIRTY tag (and submitting the page for IO).
6759 ++ *
6760 ++ * To avoid deadlocks between range_cyclic writeback and callers that hold
6761 ++ * pages in PageWriteback to aggregate IO until write_cache_pages() returns,
6762 ++ * we do not loop back to the start of the file. Doing so causes a page
6763 ++ * lock/page writeback access order inversion - we should only ever lock
6764 ++ * multiple pages in ascending page->index order, and looping back to the start
6765 ++ * of the file violates that rule and causes deadlocks.
6766 + */
6767 + int write_cache_pages(struct address_space *mapping,
6768 + struct writeback_control *wbc, writepage_t writepage,
6769 +@@ -2164,7 +2171,6 @@ int write_cache_pages(struct address_space *mapping,
6770 + pgoff_t index;
6771 + pgoff_t end; /* Inclusive */
6772 + pgoff_t done_index;
6773 +- int cycled;
6774 + int range_whole = 0;
6775 + int tag;
6776 +
6777 +@@ -2172,23 +2178,17 @@ int write_cache_pages(struct address_space *mapping,
6778 + if (wbc->range_cyclic) {
6779 + writeback_index = mapping->writeback_index; /* prev offset */
6780 + index = writeback_index;
6781 +- if (index == 0)
6782 +- cycled = 1;
6783 +- else
6784 +- cycled = 0;
6785 + end = -1;
6786 + } else {
6787 + index = wbc->range_start >> PAGE_SHIFT;
6788 + end = wbc->range_end >> PAGE_SHIFT;
6789 + if (wbc->range_start == 0 && wbc->range_end == LLONG_MAX)
6790 + range_whole = 1;
6791 +- cycled = 1; /* ignore range_cyclic tests */
6792 + }
6793 + if (wbc->sync_mode == WB_SYNC_ALL || wbc->tagged_writepages)
6794 + tag = PAGECACHE_TAG_TOWRITE;
6795 + else
6796 + tag = PAGECACHE_TAG_DIRTY;
6797 +-retry:
6798 + if (wbc->sync_mode == WB_SYNC_ALL || wbc->tagged_writepages)
6799 + tag_pages_for_writeback(mapping, index, end);
6800 + done_index = index;
6801 +@@ -2296,17 +2296,14 @@ continue_unlock:
6802 + pagevec_release(&pvec);
6803 + cond_resched();
6804 + }
6805 +- if (!cycled && !done) {
6806 +- /*
6807 +- * range_cyclic:
6808 +- * We hit the last page and there is more work to be done: wrap
6809 +- * back to the start of the file
6810 +- */
6811 +- cycled = 1;
6812 +- index = 0;
6813 +- end = writeback_index - 1;
6814 +- goto retry;
6815 +- }
6816 ++
6817 ++ /*
6818 ++ * If we hit the last page and there is more work to be done: wrap
6819 ++ * back the index back to the start of the file for the next
6820 ++ * time we are called.
6821 ++ */
6822 ++ if (wbc->range_cyclic && !done)
6823 ++ done_index = 0;
6824 + if (wbc->range_cyclic || (range_whole && wbc->nr_to_write > 0))
6825 + mapping->writeback_index = done_index;
6826 +
6827 +diff --git a/net/core/dev.c b/net/core/dev.c
6828 +index 9d6beb9de924..3ce68484ed5a 100644
6829 +--- a/net/core/dev.c
6830 ++++ b/net/core/dev.c
6831 +@@ -3029,7 +3029,7 @@ struct sk_buff *dev_hard_start_xmit(struct sk_buff *first, struct net_device *de
6832 + }
6833 +
6834 + skb = next;
6835 +- if (netif_xmit_stopped(txq) && skb) {
6836 ++ if (netif_tx_queue_stopped(txq) && skb) {
6837 + rc = NETDEV_TX_BUSY;
6838 + break;
6839 + }
6840 +diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
6841 +index 925af6b43017..b598e9909fec 100644
6842 +--- a/net/core/rtnetlink.c
6843 ++++ b/net/core/rtnetlink.c
6844 +@@ -1767,6 +1767,8 @@ static int do_setvfinfo(struct net_device *dev, struct nlattr **tb)
6845 + if (tb[IFLA_VF_MAC]) {
6846 + struct ifla_vf_mac *ivm = nla_data(tb[IFLA_VF_MAC]);
6847 +
6848 ++ if (ivm->vf >= INT_MAX)
6849 ++ return -EINVAL;
6850 + err = -EOPNOTSUPP;
6851 + if (ops->ndo_set_vf_mac)
6852 + err = ops->ndo_set_vf_mac(dev, ivm->vf,
6853 +@@ -1778,6 +1780,8 @@ static int do_setvfinfo(struct net_device *dev, struct nlattr **tb)
6854 + if (tb[IFLA_VF_VLAN]) {
6855 + struct ifla_vf_vlan *ivv = nla_data(tb[IFLA_VF_VLAN]);
6856 +
6857 ++ if (ivv->vf >= INT_MAX)
6858 ++ return -EINVAL;
6859 + err = -EOPNOTSUPP;
6860 + if (ops->ndo_set_vf_vlan)
6861 + err = ops->ndo_set_vf_vlan(dev, ivv->vf, ivv->vlan,
6862 +@@ -1810,6 +1814,8 @@ static int do_setvfinfo(struct net_device *dev, struct nlattr **tb)
6863 + if (len == 0)
6864 + return -EINVAL;
6865 +
6866 ++ if (ivvl[0]->vf >= INT_MAX)
6867 ++ return -EINVAL;
6868 + err = ops->ndo_set_vf_vlan(dev, ivvl[0]->vf, ivvl[0]->vlan,
6869 + ivvl[0]->qos, ivvl[0]->vlan_proto);
6870 + if (err < 0)
6871 +@@ -1820,6 +1826,8 @@ static int do_setvfinfo(struct net_device *dev, struct nlattr **tb)
6872 + struct ifla_vf_tx_rate *ivt = nla_data(tb[IFLA_VF_TX_RATE]);
6873 + struct ifla_vf_info ivf;
6874 +
6875 ++ if (ivt->vf >= INT_MAX)
6876 ++ return -EINVAL;
6877 + err = -EOPNOTSUPP;
6878 + if (ops->ndo_get_vf_config)
6879 + err = ops->ndo_get_vf_config(dev, ivt->vf, &ivf);
6880 +@@ -1838,6 +1846,8 @@ static int do_setvfinfo(struct net_device *dev, struct nlattr **tb)
6881 + if (tb[IFLA_VF_RATE]) {
6882 + struct ifla_vf_rate *ivt = nla_data(tb[IFLA_VF_RATE]);
6883 +
6884 ++ if (ivt->vf >= INT_MAX)
6885 ++ return -EINVAL;
6886 + err = -EOPNOTSUPP;
6887 + if (ops->ndo_set_vf_rate)
6888 + err = ops->ndo_set_vf_rate(dev, ivt->vf,
6889 +@@ -1850,6 +1860,8 @@ static int do_setvfinfo(struct net_device *dev, struct nlattr **tb)
6890 + if (tb[IFLA_VF_SPOOFCHK]) {
6891 + struct ifla_vf_spoofchk *ivs = nla_data(tb[IFLA_VF_SPOOFCHK]);
6892 +
6893 ++ if (ivs->vf >= INT_MAX)
6894 ++ return -EINVAL;
6895 + err = -EOPNOTSUPP;
6896 + if (ops->ndo_set_vf_spoofchk)
6897 + err = ops->ndo_set_vf_spoofchk(dev, ivs->vf,
6898 +@@ -1861,6 +1873,8 @@ static int do_setvfinfo(struct net_device *dev, struct nlattr **tb)
6899 + if (tb[IFLA_VF_LINK_STATE]) {
6900 + struct ifla_vf_link_state *ivl = nla_data(tb[IFLA_VF_LINK_STATE]);
6901 +
6902 ++ if (ivl->vf >= INT_MAX)
6903 ++ return -EINVAL;
6904 + err = -EOPNOTSUPP;
6905 + if (ops->ndo_set_vf_link_state)
6906 + err = ops->ndo_set_vf_link_state(dev, ivl->vf,
6907 +@@ -1874,6 +1888,8 @@ static int do_setvfinfo(struct net_device *dev, struct nlattr **tb)
6908 +
6909 + err = -EOPNOTSUPP;
6910 + ivrssq_en = nla_data(tb[IFLA_VF_RSS_QUERY_EN]);
6911 ++ if (ivrssq_en->vf >= INT_MAX)
6912 ++ return -EINVAL;
6913 + if (ops->ndo_set_vf_rss_query_en)
6914 + err = ops->ndo_set_vf_rss_query_en(dev, ivrssq_en->vf,
6915 + ivrssq_en->setting);
6916 +@@ -1884,6 +1900,8 @@ static int do_setvfinfo(struct net_device *dev, struct nlattr **tb)
6917 + if (tb[IFLA_VF_TRUST]) {
6918 + struct ifla_vf_trust *ivt = nla_data(tb[IFLA_VF_TRUST]);
6919 +
6920 ++ if (ivt->vf >= INT_MAX)
6921 ++ return -EINVAL;
6922 + err = -EOPNOTSUPP;
6923 + if (ops->ndo_set_vf_trust)
6924 + err = ops->ndo_set_vf_trust(dev, ivt->vf, ivt->setting);
6925 +@@ -1894,15 +1912,18 @@ static int do_setvfinfo(struct net_device *dev, struct nlattr **tb)
6926 + if (tb[IFLA_VF_IB_NODE_GUID]) {
6927 + struct ifla_vf_guid *ivt = nla_data(tb[IFLA_VF_IB_NODE_GUID]);
6928 +
6929 ++ if (ivt->vf >= INT_MAX)
6930 ++ return -EINVAL;
6931 + if (!ops->ndo_set_vf_guid)
6932 + return -EOPNOTSUPP;
6933 +-
6934 + return handle_vf_guid(dev, ivt, IFLA_VF_IB_NODE_GUID);
6935 + }
6936 +
6937 + if (tb[IFLA_VF_IB_PORT_GUID]) {
6938 + struct ifla_vf_guid *ivt = nla_data(tb[IFLA_VF_IB_PORT_GUID]);
6939 +
6940 ++ if (ivt->vf >= INT_MAX)
6941 ++ return -EINVAL;
6942 + if (!ops->ndo_set_vf_guid)
6943 + return -EOPNOTSUPP;
6944 +
6945 +diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
6946 +index 7b4ce3f9e2f4..5ec73cf386df 100644
6947 +--- a/net/ipv6/tcp_ipv6.c
6948 ++++ b/net/ipv6/tcp_ipv6.c
6949 +@@ -718,6 +718,7 @@ static void tcp_v6_init_req(struct request_sock *req,
6950 + const struct sock *sk_listener,
6951 + struct sk_buff *skb)
6952 + {
6953 ++ bool l3_slave = ipv6_l3mdev_skb(TCP_SKB_CB(skb)->header.h6.flags);
6954 + struct inet_request_sock *ireq = inet_rsk(req);
6955 + const struct ipv6_pinfo *np = inet6_sk(sk_listener);
6956 +
6957 +@@ -725,7 +726,7 @@ static void tcp_v6_init_req(struct request_sock *req,
6958 + ireq->ir_v6_loc_addr = ipv6_hdr(skb)->daddr;
6959 +
6960 + /* So that link locals have meaning */
6961 +- if (!sk_listener->sk_bound_dev_if &&
6962 ++ if ((!sk_listener->sk_bound_dev_if || l3_slave) &&
6963 + ipv6_addr_type(&ireq->ir_v6_rmt_addr) & IPV6_ADDR_LINKLOCAL)
6964 + ireq->ir_iif = tcp_v6_iif(skb);
6965 +
6966 +diff --git a/net/openvswitch/conntrack.c b/net/openvswitch/conntrack.c
6967 +index 0171b27a2b81..48d81857961c 100644
6968 +--- a/net/openvswitch/conntrack.c
6969 ++++ b/net/openvswitch/conntrack.c
6970 +@@ -1083,7 +1083,8 @@ static int ovs_ct_commit(struct net *net, struct sw_flow_key *key,
6971 + &info->labels.mask);
6972 + if (err)
6973 + return err;
6974 +- } else if (labels_nonzero(&info->labels.mask)) {
6975 ++ } else if (IS_ENABLED(CONFIG_NF_CONNTRACK_LABELS) &&
6976 ++ labels_nonzero(&info->labels.mask)) {
6977 + err = ovs_ct_set_labels(ct, key, &info->labels.value,
6978 + &info->labels.mask);
6979 + if (err)
6980 +diff --git a/net/sched/act_pedit.c b/net/sched/act_pedit.c
6981 +index b6f6bfad8b2a..fb0caa500ac8 100644
6982 +--- a/net/sched/act_pedit.c
6983 ++++ b/net/sched/act_pedit.c
6984 +@@ -46,7 +46,7 @@ static struct tcf_pedit_key_ex *tcf_pedit_keys_ex_parse(struct nlattr *nla,
6985 + int err = -EINVAL;
6986 + int rem;
6987 +
6988 +- if (!nla || !n)
6989 ++ if (!nla)
6990 + return NULL;
6991 +
6992 + keys_ex = kcalloc(n, sizeof(*k), GFP_KERNEL);
6993 +@@ -163,6 +163,9 @@ static int tcf_pedit_init(struct net *net, struct nlattr *nla,
6994 + return -EINVAL;
6995 +
6996 + parm = nla_data(pattr);
6997 ++ if (!parm->nkeys)
6998 ++ return -EINVAL;
6999 ++
7000 + ksize = parm->nkeys * sizeof(struct tc_pedit_key);
7001 + if (nla_len(pattr) < sizeof(*parm) + ksize)
7002 + return -EINVAL;
7003 +@@ -172,8 +175,6 @@ static int tcf_pedit_init(struct net *net, struct nlattr *nla,
7004 + return PTR_ERR(keys_ex);
7005 +
7006 + if (!tcf_idr_check(tn, parm->index, a, bind)) {
7007 +- if (!parm->nkeys)
7008 +- return -EINVAL;
7009 + ret = tcf_idr_create(tn, parm->index, est, a,
7010 + &act_pedit_ops, bind, false);
7011 + if (ret)
7012 +diff --git a/net/sunrpc/auth_gss/gss_krb5_seal.c b/net/sunrpc/auth_gss/gss_krb5_seal.c
7013 +index 1d74d653e6c0..ad0dcb69395d 100644
7014 +--- a/net/sunrpc/auth_gss/gss_krb5_seal.c
7015 ++++ b/net/sunrpc/auth_gss/gss_krb5_seal.c
7016 +@@ -63,6 +63,7 @@
7017 + #include <linux/sunrpc/gss_krb5.h>
7018 + #include <linux/random.h>
7019 + #include <linux/crypto.h>
7020 ++#include <linux/atomic.h>
7021 +
7022 + #if IS_ENABLED(CONFIG_SUNRPC_DEBUG)
7023 + # define RPCDBG_FACILITY RPCDBG_AUTH
7024 +diff --git a/net/sunrpc/xprtsock.c b/net/sunrpc/xprtsock.c
7025 +index a42871a59f3b..f75b5b7c1fc2 100644
7026 +--- a/net/sunrpc/xprtsock.c
7027 ++++ b/net/sunrpc/xprtsock.c
7028 +@@ -127,7 +127,7 @@ static struct ctl_table xs_tunables_table[] = {
7029 + .mode = 0644,
7030 + .proc_handler = proc_dointvec_minmax,
7031 + .extra1 = &xprt_min_resvport_limit,
7032 +- .extra2 = &xprt_max_resvport
7033 ++ .extra2 = &xprt_max_resvport_limit
7034 + },
7035 + {
7036 + .procname = "max_resvport",
7037 +@@ -135,7 +135,7 @@ static struct ctl_table xs_tunables_table[] = {
7038 + .maxlen = sizeof(unsigned int),
7039 + .mode = 0644,
7040 + .proc_handler = proc_dointvec_minmax,
7041 +- .extra1 = &xprt_min_resvport,
7042 ++ .extra1 = &xprt_min_resvport_limit,
7043 + .extra2 = &xprt_max_resvport_limit
7044 + },
7045 + {
7046 +@@ -1754,11 +1754,17 @@ static void xs_udp_timer(struct rpc_xprt *xprt, struct rpc_task *task)
7047 + spin_unlock_bh(&xprt->transport_lock);
7048 + }
7049 +
7050 +-static unsigned short xs_get_random_port(void)
7051 ++static int xs_get_random_port(void)
7052 + {
7053 +- unsigned short range = xprt_max_resvport - xprt_min_resvport + 1;
7054 +- unsigned short rand = (unsigned short) prandom_u32() % range;
7055 +- return rand + xprt_min_resvport;
7056 ++ unsigned short min = xprt_min_resvport, max = xprt_max_resvport;
7057 ++ unsigned short range;
7058 ++ unsigned short rand;
7059 ++
7060 ++ if (max < min)
7061 ++ return -EADDRINUSE;
7062 ++ range = max - min + 1;
7063 ++ rand = (unsigned short) prandom_u32() % range;
7064 ++ return rand + min;
7065 + }
7066 +
7067 + /**
7068 +@@ -1815,9 +1821,9 @@ static void xs_set_srcport(struct sock_xprt *transport, struct socket *sock)
7069 + transport->srcport = xs_sock_getport(sock);
7070 + }
7071 +
7072 +-static unsigned short xs_get_srcport(struct sock_xprt *transport)
7073 ++static int xs_get_srcport(struct sock_xprt *transport)
7074 + {
7075 +- unsigned short port = transport->srcport;
7076 ++ int port = transport->srcport;
7077 +
7078 + if (port == 0 && transport->xprt.resvport)
7079 + port = xs_get_random_port();
7080 +@@ -1838,7 +1844,7 @@ static int xs_bind(struct sock_xprt *transport, struct socket *sock)
7081 + {
7082 + struct sockaddr_storage myaddr;
7083 + int err, nloop = 0;
7084 +- unsigned short port = xs_get_srcport(transport);
7085 ++ int port = xs_get_srcport(transport);
7086 + unsigned short last;
7087 +
7088 + /*
7089 +@@ -1856,8 +1862,8 @@ static int xs_bind(struct sock_xprt *transport, struct socket *sock)
7090 + * transport->xprt.resvport == 1) xs_get_srcport above will
7091 + * ensure that port is non-zero and we will bind as needed.
7092 + */
7093 +- if (port == 0)
7094 +- return 0;
7095 ++ if (port <= 0)
7096 ++ return port;
7097 +
7098 + memcpy(&myaddr, &transport->srcaddr, transport->xprt.addrlen);
7099 + do {
7100 +@@ -3286,12 +3292,8 @@ static int param_set_uint_minmax(const char *val,
7101 +
7102 + static int param_set_portnr(const char *val, const struct kernel_param *kp)
7103 + {
7104 +- if (kp->arg == &xprt_min_resvport)
7105 +- return param_set_uint_minmax(val, kp,
7106 +- RPC_MIN_RESVPORT,
7107 +- xprt_max_resvport);
7108 + return param_set_uint_minmax(val, kp,
7109 +- xprt_min_resvport,
7110 ++ RPC_MIN_RESVPORT,
7111 + RPC_MAX_RESVPORT);
7112 + }
7113 +
7114 +diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
7115 +index 4de9dfd14d09..99f581a61cfa 100644
7116 +--- a/net/unix/af_unix.c
7117 ++++ b/net/unix/af_unix.c
7118 +@@ -225,6 +225,8 @@ static inline void unix_release_addr(struct unix_address *addr)
7119 +
7120 + static int unix_mkname(struct sockaddr_un *sunaddr, int len, unsigned int *hashp)
7121 + {
7122 ++ *hashp = 0;
7123 ++
7124 + if (len <= sizeof(short) || len > sizeof(*sunaddr))
7125 + return -EINVAL;
7126 + if (!sunaddr || sunaddr->sun_family != AF_UNIX)
7127 +diff --git a/net/vmw_vsock/virtio_transport_common.c b/net/vmw_vsock/virtio_transport_common.c
7128 +index a8eb0657c1e8..d20f43057323 100644
7129 +--- a/net/vmw_vsock/virtio_transport_common.c
7130 ++++ b/net/vmw_vsock/virtio_transport_common.c
7131 +@@ -92,8 +92,17 @@ static struct sk_buff *virtio_transport_build_skb(void *opaque)
7132 + struct virtio_vsock_pkt *pkt = opaque;
7133 + struct af_vsockmon_hdr *hdr;
7134 + struct sk_buff *skb;
7135 ++ size_t payload_len;
7136 ++ void *payload_buf;
7137 +
7138 +- skb = alloc_skb(sizeof(*hdr) + sizeof(pkt->hdr) + pkt->len,
7139 ++ /* A packet could be split to fit the RX buffer, so we can retrieve
7140 ++ * the payload length from the header and the buffer pointer taking
7141 ++ * care of the offset in the original packet.
7142 ++ */
7143 ++ payload_len = le32_to_cpu(pkt->hdr.len);
7144 ++ payload_buf = pkt->buf + pkt->off;
7145 ++
7146 ++ skb = alloc_skb(sizeof(*hdr) + sizeof(pkt->hdr) + payload_len,
7147 + GFP_ATOMIC);
7148 + if (!skb)
7149 + return NULL;
7150 +@@ -133,8 +142,8 @@ static struct sk_buff *virtio_transport_build_skb(void *opaque)
7151 +
7152 + skb_put_data(skb, &pkt->hdr, sizeof(pkt->hdr));
7153 +
7154 +- if (pkt->len) {
7155 +- skb_put_data(skb, pkt->buf, pkt->len);
7156 ++ if (payload_len) {
7157 ++ skb_put_data(skb, payload_buf, payload_len);
7158 + }
7159 +
7160 + return skb;
7161 +diff --git a/net/wireless/ap.c b/net/wireless/ap.c
7162 +index 63682176c96c..c4bd3ecef508 100644
7163 +--- a/net/wireless/ap.c
7164 ++++ b/net/wireless/ap.c
7165 +@@ -40,6 +40,8 @@ int __cfg80211_stop_ap(struct cfg80211_registered_device *rdev,
7166 + cfg80211_sched_dfs_chan_update(rdev);
7167 + }
7168 +
7169 ++ schedule_work(&cfg80211_disconnect_work);
7170 ++
7171 + return err;
7172 + }
7173 +
7174 +diff --git a/net/wireless/core.h b/net/wireless/core.h
7175 +index 90f90c7d8bf9..507ec6446eb6 100644
7176 +--- a/net/wireless/core.h
7177 ++++ b/net/wireless/core.h
7178 +@@ -429,6 +429,8 @@ void cfg80211_process_wdev_events(struct wireless_dev *wdev);
7179 + bool cfg80211_does_bw_fit_range(const struct ieee80211_freq_range *freq_range,
7180 + u32 center_freq_khz, u32 bw_khz);
7181 +
7182 ++extern struct work_struct cfg80211_disconnect_work;
7183 ++
7184 + /**
7185 + * cfg80211_chandef_dfs_usable - checks if chandef is DFS usable
7186 + * @wiphy: the wiphy to validate against
7187 +diff --git a/net/wireless/sme.c b/net/wireless/sme.c
7188 +index d014aea07160..8344153800e2 100644
7189 +--- a/net/wireless/sme.c
7190 ++++ b/net/wireless/sme.c
7191 +@@ -642,11 +642,15 @@ static bool cfg80211_is_all_idle(void)
7192 + * All devices must be idle as otherwise if you are actively
7193 + * scanning some new beacon hints could be learned and would
7194 + * count as new regulatory hints.
7195 ++ * Also if there is any other active beaconing interface we
7196 ++ * need not issue a disconnect hint and reset any info such
7197 ++ * as chan dfs state, etc.
7198 + */
7199 + list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
7200 + list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) {
7201 + wdev_lock(wdev);
7202 +- if (wdev->conn || wdev->current_bss)
7203 ++ if (wdev->conn || wdev->current_bss ||
7204 ++ cfg80211_beaconing_iface_active(wdev))
7205 + is_all_idle = false;
7206 + wdev_unlock(wdev);
7207 + }
7208 +@@ -663,7 +667,7 @@ static void disconnect_work(struct work_struct *work)
7209 + rtnl_unlock();
7210 + }
7211 +
7212 +-static DECLARE_WORK(cfg80211_disconnect_work, disconnect_work);
7213 ++DECLARE_WORK(cfg80211_disconnect_work, disconnect_work);
7214 +
7215 +
7216 + /*
7217 +diff --git a/sound/firewire/isight.c b/sound/firewire/isight.c
7218 +index 5826aa8362f1..9edb26ab16e9 100644
7219 +--- a/sound/firewire/isight.c
7220 ++++ b/sound/firewire/isight.c
7221 +@@ -639,7 +639,7 @@ static int isight_probe(struct fw_unit *unit,
7222 + if (!isight->audio_base) {
7223 + dev_err(&unit->device, "audio unit base not found\n");
7224 + err = -ENXIO;
7225 +- goto err_unit;
7226 ++ goto error;
7227 + }
7228 + fw_iso_resources_init(&isight->resources, unit);
7229 +
7230 +@@ -668,12 +668,12 @@ static int isight_probe(struct fw_unit *unit,
7231 + dev_set_drvdata(&unit->device, isight);
7232 +
7233 + return 0;
7234 +-
7235 +-err_unit:
7236 +- fw_unit_put(isight->unit);
7237 +- mutex_destroy(&isight->mutex);
7238 + error:
7239 + snd_card_free(card);
7240 ++
7241 ++ mutex_destroy(&isight->mutex);
7242 ++ fw_unit_put(isight->unit);
7243 ++
7244 + return err;
7245 + }
7246 +
7247 +diff --git a/sound/i2c/cs8427.c b/sound/i2c/cs8427.c
7248 +index 7e21621e492a..7fd1b4000883 100644
7249 +--- a/sound/i2c/cs8427.c
7250 ++++ b/sound/i2c/cs8427.c
7251 +@@ -118,7 +118,7 @@ static int snd_cs8427_send_corudata(struct snd_i2c_device *device,
7252 + struct cs8427 *chip = device->private_data;
7253 + char *hw_data = udata ?
7254 + chip->playback.hw_udata : chip->playback.hw_status;
7255 +- char data[32];
7256 ++ unsigned char data[32];
7257 + int err, idx;
7258 +
7259 + if (!memcmp(hw_data, ndata, count))
7260 +diff --git a/sound/soc/tegra/tegra_sgtl5000.c b/sound/soc/tegra/tegra_sgtl5000.c
7261 +index 45a4aa9d2a47..901457da25ec 100644
7262 +--- a/sound/soc/tegra/tegra_sgtl5000.c
7263 ++++ b/sound/soc/tegra/tegra_sgtl5000.c
7264 +@@ -149,14 +149,14 @@ static int tegra_sgtl5000_driver_probe(struct platform_device *pdev)
7265 + dev_err(&pdev->dev,
7266 + "Property 'nvidia,i2s-controller' missing/invalid\n");
7267 + ret = -EINVAL;
7268 +- goto err;
7269 ++ goto err_put_codec_of_node;
7270 + }
7271 +
7272 + tegra_sgtl5000_dai.platform_of_node = tegra_sgtl5000_dai.cpu_of_node;
7273 +
7274 + ret = tegra_asoc_utils_init(&machine->util_data, &pdev->dev);
7275 + if (ret)
7276 +- goto err;
7277 ++ goto err_put_cpu_of_node;
7278 +
7279 + ret = snd_soc_register_card(card);
7280 + if (ret) {
7281 +@@ -169,6 +169,13 @@ static int tegra_sgtl5000_driver_probe(struct platform_device *pdev)
7282 +
7283 + err_fini_utils:
7284 + tegra_asoc_utils_fini(&machine->util_data);
7285 ++err_put_cpu_of_node:
7286 ++ of_node_put(tegra_sgtl5000_dai.cpu_of_node);
7287 ++ tegra_sgtl5000_dai.cpu_of_node = NULL;
7288 ++ tegra_sgtl5000_dai.platform_of_node = NULL;
7289 ++err_put_codec_of_node:
7290 ++ of_node_put(tegra_sgtl5000_dai.codec_of_node);
7291 ++ tegra_sgtl5000_dai.codec_of_node = NULL;
7292 + err:
7293 + return ret;
7294 + }
7295 +@@ -183,6 +190,12 @@ static int tegra_sgtl5000_driver_remove(struct platform_device *pdev)
7296 +
7297 + tegra_asoc_utils_fini(&machine->util_data);
7298 +
7299 ++ of_node_put(tegra_sgtl5000_dai.cpu_of_node);
7300 ++ tegra_sgtl5000_dai.cpu_of_node = NULL;
7301 ++ tegra_sgtl5000_dai.platform_of_node = NULL;
7302 ++ of_node_put(tegra_sgtl5000_dai.codec_of_node);
7303 ++ tegra_sgtl5000_dai.codec_of_node = NULL;
7304 ++
7305 + return ret;
7306 + }
7307 +
7308 +diff --git a/tools/gpio/Build b/tools/gpio/Build
7309 +index 620c1937d957..4141f35837db 100644
7310 +--- a/tools/gpio/Build
7311 ++++ b/tools/gpio/Build
7312 +@@ -1,3 +1,4 @@
7313 ++gpio-utils-y += gpio-utils.o
7314 + lsgpio-y += lsgpio.o gpio-utils.o
7315 + gpio-hammer-y += gpio-hammer.o gpio-utils.o
7316 + gpio-event-mon-y += gpio-event-mon.o gpio-utils.o
7317 +diff --git a/tools/gpio/Makefile b/tools/gpio/Makefile
7318 +index f8bc8656a544..6a73c06e069c 100644
7319 +--- a/tools/gpio/Makefile
7320 ++++ b/tools/gpio/Makefile
7321 +@@ -35,11 +35,15 @@ $(OUTPUT)include/linux/gpio.h: ../../include/uapi/linux/gpio.h
7322 +
7323 + prepare: $(OUTPUT)include/linux/gpio.h
7324 +
7325 ++GPIO_UTILS_IN := $(output)gpio-utils-in.o
7326 ++$(GPIO_UTILS_IN): prepare FORCE
7327 ++ $(Q)$(MAKE) $(build)=gpio-utils
7328 ++
7329 + #
7330 + # lsgpio
7331 + #
7332 + LSGPIO_IN := $(OUTPUT)lsgpio-in.o
7333 +-$(LSGPIO_IN): prepare FORCE
7334 ++$(LSGPIO_IN): prepare FORCE $(OUTPUT)gpio-utils-in.o
7335 + $(Q)$(MAKE) $(build)=lsgpio
7336 + $(OUTPUT)lsgpio: $(LSGPIO_IN)
7337 + $(QUIET_LINK)$(CC) $(CFLAGS) $(LDFLAGS) $< -o $@
7338 +@@ -48,7 +52,7 @@ $(OUTPUT)lsgpio: $(LSGPIO_IN)
7339 + # gpio-hammer
7340 + #
7341 + GPIO_HAMMER_IN := $(OUTPUT)gpio-hammer-in.o
7342 +-$(GPIO_HAMMER_IN): prepare FORCE
7343 ++$(GPIO_HAMMER_IN): prepare FORCE $(OUTPUT)gpio-utils-in.o
7344 + $(Q)$(MAKE) $(build)=gpio-hammer
7345 + $(OUTPUT)gpio-hammer: $(GPIO_HAMMER_IN)
7346 + $(QUIET_LINK)$(CC) $(CFLAGS) $(LDFLAGS) $< -o $@
7347 +@@ -57,7 +61,7 @@ $(OUTPUT)gpio-hammer: $(GPIO_HAMMER_IN)
7348 + # gpio-event-mon
7349 + #
7350 + GPIO_EVENT_MON_IN := $(OUTPUT)gpio-event-mon-in.o
7351 +-$(GPIO_EVENT_MON_IN): prepare FORCE
7352 ++$(GPIO_EVENT_MON_IN): prepare FORCE $(OUTPUT)gpio-utils-in.o
7353 + $(Q)$(MAKE) $(build)=gpio-event-mon
7354 + $(OUTPUT)gpio-event-mon: $(GPIO_EVENT_MON_IN)
7355 + $(QUIET_LINK)$(CC) $(CFLAGS) $(LDFLAGS) $< -o $@
7356 +diff --git a/tools/objtool/arch/x86/tools/gen-insn-attr-x86.awk b/tools/objtool/arch/x86/tools/gen-insn-attr-x86.awk
7357 +index b02a36b2c14f..a42015b305f4 100644
7358 +--- a/tools/objtool/arch/x86/tools/gen-insn-attr-x86.awk
7359 ++++ b/tools/objtool/arch/x86/tools/gen-insn-attr-x86.awk
7360 +@@ -69,7 +69,7 @@ BEGIN {
7361 +
7362 + lprefix1_expr = "\\((66|!F3)\\)"
7363 + lprefix2_expr = "\\(F3\\)"
7364 +- lprefix3_expr = "\\((F2|!F3|66\\&F2)\\)"
7365 ++ lprefix3_expr = "\\((F2|!F3|66&F2)\\)"
7366 + lprefix_expr = "\\((66|F2|F3)\\)"
7367 + max_lprefix = 4
7368 +
7369 +@@ -257,7 +257,7 @@ function convert_operands(count,opnd, i,j,imm,mod)
7370 + return add_flags(imm, mod)
7371 + }
7372 +
7373 +-/^[0-9a-f]+\:/ {
7374 ++/^[0-9a-f]+:/ {
7375 + if (NR == 1)
7376 + next
7377 + # get index
7378 +diff --git a/tools/power/acpi/tools/acpidump/apmain.c b/tools/power/acpi/tools/acpidump/apmain.c
7379 +index 943b6b614683..bed0794e3295 100644
7380 +--- a/tools/power/acpi/tools/acpidump/apmain.c
7381 ++++ b/tools/power/acpi/tools/acpidump/apmain.c
7382 +@@ -139,7 +139,7 @@ static int ap_insert_action(char *argument, u32 to_be_done)
7383 +
7384 + current_action++;
7385 + if (current_action > AP_MAX_ACTIONS) {
7386 +- fprintf(stderr, "Too many table options (max %u)\n",
7387 ++ fprintf(stderr, "Too many table options (max %d)\n",
7388 + AP_MAX_ACTIONS);
7389 + return (-1);
7390 + }
7391 +diff --git a/tools/testing/selftests/ftrace/test.d/kprobe/kprobe_args_syntax.tc b/tools/testing/selftests/ftrace/test.d/kprobe/kprobe_args_syntax.tc
7392 +index 231bcd2c4eb5..1e7ac6f3362f 100644
7393 +--- a/tools/testing/selftests/ftrace/test.d/kprobe/kprobe_args_syntax.tc
7394 ++++ b/tools/testing/selftests/ftrace/test.d/kprobe/kprobe_args_syntax.tc
7395 +@@ -71,8 +71,11 @@ test_badarg "\$stackp" "\$stack0+10" "\$stack1-10"
7396 + echo "r ${PROBEFUNC} \$retval" > kprobe_events
7397 + ! echo "p ${PROBEFUNC} \$retval" > kprobe_events
7398 +
7399 ++# $comm was introduced in 4.8, older kernels reject it.
7400 ++if grep -A1 "fetcharg:" README | grep -q '\$comm' ; then
7401 + : "Comm access"
7402 + test_goodarg "\$comm"
7403 ++fi
7404 +
7405 + : "Indirect memory access"
7406 + test_goodarg "+0(${GOODREG})" "-0(${GOODREG})" "+10(\$stack)" \
7407 +diff --git a/tools/testing/selftests/powerpc/cache_shape/Makefile b/tools/testing/selftests/powerpc/cache_shape/Makefile
7408 +index 1be547434a49..7e0c175b8297 100644
7409 +--- a/tools/testing/selftests/powerpc/cache_shape/Makefile
7410 ++++ b/tools/testing/selftests/powerpc/cache_shape/Makefile
7411 +@@ -1,11 +1,6 @@
7412 + # SPDX-License-Identifier: GPL-2.0
7413 +-TEST_PROGS := cache_shape
7414 +-
7415 +-all: $(TEST_PROGS)
7416 +-
7417 +-$(TEST_PROGS): ../harness.c ../utils.c
7418 ++TEST_GEN_PROGS := cache_shape
7419 +
7420 + include ../../lib.mk
7421 +
7422 +-clean:
7423 +- rm -f $(TEST_PROGS) *.o
7424 ++$(TEST_GEN_PROGS): ../harness.c ../utils.c
7425 +diff --git a/tools/testing/selftests/powerpc/signal/Makefile b/tools/testing/selftests/powerpc/signal/Makefile
7426 +index a7cbd5082e27..4213978f3ee2 100644
7427 +--- a/tools/testing/selftests/powerpc/signal/Makefile
7428 ++++ b/tools/testing/selftests/powerpc/signal/Makefile
7429 +@@ -1,14 +1,9 @@
7430 + # SPDX-License-Identifier: GPL-2.0
7431 +-TEST_PROGS := signal signal_tm
7432 +-
7433 +-all: $(TEST_PROGS)
7434 +-
7435 +-$(TEST_PROGS): ../harness.c ../utils.c signal.S
7436 ++TEST_GEN_PROGS := signal signal_tm
7437 +
7438 + CFLAGS += -maltivec
7439 +-signal_tm: CFLAGS += -mhtm
7440 ++$(OUTPUT)/signal_tm: CFLAGS += -mhtm
7441 +
7442 + include ../../lib.mk
7443 +
7444 +-clean:
7445 +- rm -f $(TEST_PROGS) *.o
7446 ++$(TEST_GEN_PROGS): ../harness.c ../utils.c signal.S
7447 +diff --git a/tools/testing/selftests/powerpc/switch_endian/Makefile b/tools/testing/selftests/powerpc/switch_endian/Makefile
7448 +index 30b8ff8fb82e..e4cedfe9753d 100644
7449 +--- a/tools/testing/selftests/powerpc/switch_endian/Makefile
7450 ++++ b/tools/testing/selftests/powerpc/switch_endian/Makefile
7451 +@@ -7,6 +7,7 @@ EXTRA_CLEAN = $(OUTPUT)/*.o $(OUTPUT)/check-reversed.S
7452 +
7453 + include ../../lib.mk
7454 +
7455 ++$(OUTPUT)/switch_endian_test: ASFLAGS += -I $(OUTPUT)
7456 + $(OUTPUT)/switch_endian_test: $(OUTPUT)/check-reversed.S
7457 +
7458 + $(OUTPUT)/check-reversed.o: $(OUTPUT)/check.o
7459 +diff --git a/tools/testing/selftests/watchdog/watchdog-test.c b/tools/testing/selftests/watchdog/watchdog-test.c
7460 +index 6e290874b70e..f1c6e025cbe5 100644
7461 +--- a/tools/testing/selftests/watchdog/watchdog-test.c
7462 ++++ b/tools/testing/selftests/watchdog/watchdog-test.c
7463 +@@ -89,7 +89,13 @@ int main(int argc, char *argv[])
7464 + fd = open("/dev/watchdog", O_WRONLY);
7465 +
7466 + if (fd == -1) {
7467 +- printf("Watchdog device not enabled.\n");
7468 ++ if (errno == ENOENT)
7469 ++ printf("Watchdog device not enabled.\n");
7470 ++ else if (errno == EACCES)
7471 ++ printf("Run watchdog as root.\n");
7472 ++ else
7473 ++ printf("Watchdog device open failed %s\n",
7474 ++ strerror(errno));
7475 + exit(-1);
7476 + }
7477 +
7478 +@@ -103,7 +109,7 @@ int main(int argc, char *argv[])
7479 + printf("Last boot is caused by: %s.\n", (flags != 0) ?
7480 + "Watchdog" : "Power-On-Reset");
7481 + else
7482 +- printf("WDIOC_GETBOOTSTATUS errno '%s'\n", strerror(errno));
7483 ++ printf("WDIOC_GETBOOTSTATUS error '%s'\n", strerror(errno));
7484 + break;
7485 + case 'd':
7486 + flags = WDIOS_DISABLECARD;
7487 +@@ -111,7 +117,7 @@ int main(int argc, char *argv[])
7488 + if (!ret)
7489 + printf("Watchdog card disabled.\n");
7490 + else
7491 +- printf("WDIOS_DISABLECARD errno '%s'\n", strerror(errno));
7492 ++ printf("WDIOS_DISABLECARD error '%s'\n", strerror(errno));
7493 + break;
7494 + case 'e':
7495 + flags = WDIOS_ENABLECARD;
7496 +@@ -119,7 +125,7 @@ int main(int argc, char *argv[])
7497 + if (!ret)
7498 + printf("Watchdog card enabled.\n");
7499 + else
7500 +- printf("WDIOS_ENABLECARD errno '%s'\n", strerror(errno));
7501 ++ printf("WDIOS_ENABLECARD error '%s'\n", strerror(errno));
7502 + break;
7503 + case 'p':
7504 + ping_rate = strtoul(optarg, NULL, 0);
7505 +@@ -133,7 +139,7 @@ int main(int argc, char *argv[])
7506 + if (!ret)
7507 + printf("Watchdog timeout set to %u seconds.\n", flags);
7508 + else
7509 +- printf("WDIOC_SETTIMEOUT errno '%s'\n", strerror(errno));
7510 ++ printf("WDIOC_SETTIMEOUT error '%s'\n", strerror(errno));
7511 + break;
7512 + default:
7513 + usage(argv[0]);
7514 +diff --git a/tools/usb/usbip/libsrc/usbip_host_common.c b/tools/usb/usbip/libsrc/usbip_host_common.c
7515 +index 6ff7b601f854..4bb905925b0e 100644
7516 +--- a/tools/usb/usbip/libsrc/usbip_host_common.c
7517 ++++ b/tools/usb/usbip/libsrc/usbip_host_common.c
7518 +@@ -43,7 +43,7 @@ static int32_t read_attr_usbip_status(struct usbip_usb_device *udev)
7519 + int size;
7520 + int fd;
7521 + int length;
7522 +- char status;
7523 ++ char status[2] = { 0 };
7524 + int value = 0;
7525 +
7526 + size = snprintf(status_attr_path, sizeof(status_attr_path),
7527 +@@ -61,15 +61,15 @@ static int32_t read_attr_usbip_status(struct usbip_usb_device *udev)
7528 + return -1;
7529 + }
7530 +
7531 +- length = read(fd, &status, 1);
7532 ++ length = read(fd, status, 1);
7533 + if (length < 0) {
7534 + err("error reading attribute %s", status_attr_path);
7535 + close(fd);
7536 + return -1;
7537 + }
7538 +
7539 +- value = atoi(&status);
7540 +-
7541 ++ value = atoi(status);
7542 ++ close(fd);
7543 + return value;
7544 + }
7545 +
7546 +diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
7547 +index ea61162b2b53..cdaacdf7bc87 100644
7548 +--- a/virt/kvm/kvm_main.c
7549 ++++ b/virt/kvm/kvm_main.c
7550 +@@ -142,10 +142,30 @@ __weak void kvm_arch_mmu_notifier_invalidate_range(struct kvm *kvm,
7551 + {
7552 + }
7553 +
7554 ++bool kvm_is_zone_device_pfn(kvm_pfn_t pfn)
7555 ++{
7556 ++ /*
7557 ++ * The metadata used by is_zone_device_page() to determine whether or
7558 ++ * not a page is ZONE_DEVICE is guaranteed to be valid if and only if
7559 ++ * the device has been pinned, e.g. by get_user_pages(). WARN if the
7560 ++ * page_count() is zero to help detect bad usage of this helper.
7561 ++ */
7562 ++ if (!pfn_valid(pfn) || WARN_ON_ONCE(!page_count(pfn_to_page(pfn))))
7563 ++ return false;
7564 ++
7565 ++ return is_zone_device_page(pfn_to_page(pfn));
7566 ++}
7567 ++
7568 + bool kvm_is_reserved_pfn(kvm_pfn_t pfn)
7569 + {
7570 ++ /*
7571 ++ * ZONE_DEVICE pages currently set PG_reserved, but from a refcounting
7572 ++ * perspective they are "normal" pages, albeit with slightly different
7573 ++ * usage rules.
7574 ++ */
7575 + if (pfn_valid(pfn))
7576 +- return PageReserved(pfn_to_page(pfn));
7577 ++ return PageReserved(pfn_to_page(pfn)) &&
7578 ++ !kvm_is_zone_device_pfn(pfn);
7579 +
7580 + return true;
7581 + }
7582 +@@ -1730,7 +1750,7 @@ static void kvm_release_pfn_dirty(kvm_pfn_t pfn)
7583 +
7584 + void kvm_set_pfn_dirty(kvm_pfn_t pfn)
7585 + {
7586 +- if (!kvm_is_reserved_pfn(pfn)) {
7587 ++ if (!kvm_is_reserved_pfn(pfn) && !kvm_is_zone_device_pfn(pfn)) {
7588 + struct page *page = pfn_to_page(pfn);
7589 +
7590 + if (!PageReserved(page))
7591 +@@ -1741,7 +1761,7 @@ EXPORT_SYMBOL_GPL(kvm_set_pfn_dirty);
7592 +
7593 + void kvm_set_pfn_accessed(kvm_pfn_t pfn)
7594 + {
7595 +- if (!kvm_is_reserved_pfn(pfn))
7596 ++ if (!kvm_is_reserved_pfn(pfn) && !kvm_is_zone_device_pfn(pfn))
7597 + mark_page_accessed(pfn_to_page(pfn));
7598 + }
7599 + EXPORT_SYMBOL_GPL(kvm_set_pfn_accessed);