Magellan Linux

Contents of /trunk/kernel-alx/patches-5.4/0135-5.4.36-all-fixes.patch

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3516 - (show annotations) (download)
Mon May 11 14:36:41 2020 UTC (3 years, 11 months ago) by niro
File size: 217255 byte(s)
-linux-5.4.36
1 diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt
2 index 94fa4a8de2ca..1f77c99e2cba 100644
3 --- a/Documentation/admin-guide/kernel-parameters.txt
4 +++ b/Documentation/admin-guide/kernel-parameters.txt
5 @@ -5005,8 +5005,7 @@
6
7 usbcore.old_scheme_first=
8 [USB] Start with the old device initialization
9 - scheme, applies only to low and full-speed devices
10 - (default 0 = off).
11 + scheme (default 0 = off).
12
13 usbcore.usbfs_memory_mb=
14 [USB] Memory limit (in MB) for buffers allocated by
15 diff --git a/Documentation/arm64/silicon-errata.rst b/Documentation/arm64/silicon-errata.rst
16 index 5a09661330fc..59daa4c21816 100644
17 --- a/Documentation/arm64/silicon-errata.rst
18 +++ b/Documentation/arm64/silicon-errata.rst
19 @@ -88,6 +88,8 @@ stable kernels.
20 +----------------+-----------------+-----------------+-----------------------------+
21 | ARM | Neoverse-N1 | #1349291 | N/A |
22 +----------------+-----------------+-----------------+-----------------------------+
23 +| ARM | Neoverse-N1 | #1542419 | ARM64_ERRATUM_1542419 |
24 ++----------------+-----------------+-----------------+-----------------------------+
25 | ARM | MMU-500 | #841119,826419 | N/A |
26 +----------------+-----------------+-----------------+-----------------------------+
27 +----------------+-----------------+-----------------+-----------------------------+
28 diff --git a/Makefile b/Makefile
29 index 6055a94aa4ce..947bf9e3a954 100644
30 --- a/Makefile
31 +++ b/Makefile
32 @@ -1,7 +1,7 @@
33 # SPDX-License-Identifier: GPL-2.0
34 VERSION = 5
35 PATCHLEVEL = 4
36 -SUBLEVEL = 35
37 +SUBLEVEL = 36
38 EXTRAVERSION =
39 NAME = Kleptomaniac Octopus
40
41 diff --git a/arch/arm/mach-imx/Makefile b/arch/arm/mach-imx/Makefile
42 index 03506ce46149..e7364e6c8c6b 100644
43 --- a/arch/arm/mach-imx/Makefile
44 +++ b/arch/arm/mach-imx/Makefile
45 @@ -91,8 +91,10 @@ AFLAGS_suspend-imx6.o :=-Wa,-march=armv7-a
46 obj-$(CONFIG_SOC_IMX6) += suspend-imx6.o
47 obj-$(CONFIG_SOC_IMX53) += suspend-imx53.o
48 endif
49 +ifeq ($(CONFIG_ARM_CPU_SUSPEND),y)
50 AFLAGS_resume-imx6.o :=-Wa,-march=armv7-a
51 obj-$(CONFIG_SOC_IMX6) += resume-imx6.o
52 +endif
53 obj-$(CONFIG_SOC_IMX6) += pm-imx6.o
54
55 obj-$(CONFIG_SOC_IMX1) += mach-imx1.o
56 diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig
57 index 6ccd2ed30963..a0bc9bbb92f3 100644
58 --- a/arch/arm64/Kconfig
59 +++ b/arch/arm64/Kconfig
60 @@ -559,6 +559,22 @@ config ARM64_ERRATUM_1463225
61
62 If unsure, say Y.
63
64 +config ARM64_ERRATUM_1542419
65 + bool "Neoverse-N1: workaround mis-ordering of instruction fetches"
66 + default y
67 + help
68 + This option adds a workaround for ARM Neoverse-N1 erratum
69 + 1542419.
70 +
71 + Affected Neoverse-N1 cores could execute a stale instruction when
72 + modified by another CPU. The workaround depends on a firmware
73 + counterpart.
74 +
75 + Workaround the issue by hiding the DIC feature from EL0. This
76 + forces user-space to perform cache maintenance.
77 +
78 + If unsure, say Y.
79 +
80 config CAVIUM_ERRATUM_22375
81 bool "Cavium erratum 22375, 24313"
82 default y
83 diff --git a/arch/arm64/include/asm/cache.h b/arch/arm64/include/asm/cache.h
84 index 43da6dd29592..806e9dc2a852 100644
85 --- a/arch/arm64/include/asm/cache.h
86 +++ b/arch/arm64/include/asm/cache.h
87 @@ -11,6 +11,7 @@
88 #define CTR_L1IP_MASK 3
89 #define CTR_DMINLINE_SHIFT 16
90 #define CTR_IMINLINE_SHIFT 0
91 +#define CTR_IMINLINE_MASK 0xf
92 #define CTR_ERG_SHIFT 20
93 #define CTR_CWG_SHIFT 24
94 #define CTR_CWG_MASK 15
95 @@ -18,7 +19,7 @@
96 #define CTR_DIC_SHIFT 29
97
98 #define CTR_CACHE_MINLINE_MASK \
99 - (0xf << CTR_DMINLINE_SHIFT | 0xf << CTR_IMINLINE_SHIFT)
100 + (0xf << CTR_DMINLINE_SHIFT | CTR_IMINLINE_MASK << CTR_IMINLINE_SHIFT)
101
102 #define CTR_L1IP(ctr) (((ctr) >> CTR_L1IP_SHIFT) & CTR_L1IP_MASK)
103
104 diff --git a/arch/arm64/include/asm/compat.h b/arch/arm64/include/asm/compat.h
105 index b0d53a265f1d..7b4172ce497c 100644
106 --- a/arch/arm64/include/asm/compat.h
107 +++ b/arch/arm64/include/asm/compat.h
108 @@ -4,6 +4,9 @@
109 */
110 #ifndef __ASM_COMPAT_H
111 #define __ASM_COMPAT_H
112 +
113 +#include <asm-generic/compat.h>
114 +
115 #ifdef CONFIG_COMPAT
116
117 /*
118 @@ -13,8 +16,6 @@
119 #include <linux/sched.h>
120 #include <linux/sched/task_stack.h>
121
122 -#include <asm-generic/compat.h>
123 -
124 #define COMPAT_USER_HZ 100
125 #ifdef __AARCH64EB__
126 #define COMPAT_UTS_MACHINE "armv8b\0\0"
127 diff --git a/arch/arm64/include/asm/cpucaps.h b/arch/arm64/include/asm/cpucaps.h
128 index ac1dbca3d0cd..1dc3c762fdcb 100644
129 --- a/arch/arm64/include/asm/cpucaps.h
130 +++ b/arch/arm64/include/asm/cpucaps.h
131 @@ -54,7 +54,8 @@
132 #define ARM64_WORKAROUND_1463225 44
133 #define ARM64_WORKAROUND_CAVIUM_TX2_219_TVM 45
134 #define ARM64_WORKAROUND_CAVIUM_TX2_219_PRFM 46
135 +#define ARM64_WORKAROUND_1542419 47
136
137 -#define ARM64_NCAPS 47
138 +#define ARM64_NCAPS 48
139
140 #endif /* __ASM_CPUCAPS_H */
141 diff --git a/arch/arm64/kernel/cpu_errata.c b/arch/arm64/kernel/cpu_errata.c
142 index 96f576e9ea46..0b2830379fe0 100644
143 --- a/arch/arm64/kernel/cpu_errata.c
144 +++ b/arch/arm64/kernel/cpu_errata.c
145 @@ -88,13 +88,21 @@ has_mismatched_cache_type(const struct arm64_cpu_capabilities *entry,
146 }
147
148 static void
149 -cpu_enable_trap_ctr_access(const struct arm64_cpu_capabilities *__unused)
150 +cpu_enable_trap_ctr_access(const struct arm64_cpu_capabilities *cap)
151 {
152 u64 mask = arm64_ftr_reg_ctrel0.strict_mask;
153 + bool enable_uct_trap = false;
154
155 /* Trap CTR_EL0 access on this CPU, only if it has a mismatch */
156 if ((read_cpuid_cachetype() & mask) !=
157 (arm64_ftr_reg_ctrel0.sys_val & mask))
158 + enable_uct_trap = true;
159 +
160 + /* ... or if the system is affected by an erratum */
161 + if (cap->capability == ARM64_WORKAROUND_1542419)
162 + enable_uct_trap = true;
163 +
164 + if (enable_uct_trap)
165 sysreg_clear_set(sctlr_el1, SCTLR_EL1_UCT, 0);
166 }
167
168 @@ -651,6 +659,18 @@ needs_tx2_tvm_workaround(const struct arm64_cpu_capabilities *entry,
169 return false;
170 }
171
172 +static bool __maybe_unused
173 +has_neoverse_n1_erratum_1542419(const struct arm64_cpu_capabilities *entry,
174 + int scope)
175 +{
176 + u32 midr = read_cpuid_id();
177 + bool has_dic = read_cpuid_cachetype() & BIT(CTR_DIC_SHIFT);
178 + const struct midr_range range = MIDR_ALL_VERSIONS(MIDR_NEOVERSE_N1);
179 +
180 + WARN_ON(scope != SCOPE_LOCAL_CPU || preemptible());
181 + return is_midr_in_range(midr, &range) && has_dic;
182 +}
183 +
184 #ifdef CONFIG_HARDEN_EL2_VECTORS
185
186 static const struct midr_range arm64_harden_el2_vectors[] = {
187 @@ -927,6 +947,16 @@ const struct arm64_cpu_capabilities arm64_errata[] = {
188 .capability = ARM64_WORKAROUND_CAVIUM_TX2_219_PRFM,
189 ERRATA_MIDR_RANGE_LIST(tx2_family_cpus),
190 },
191 +#endif
192 +#ifdef CONFIG_ARM64_ERRATUM_1542419
193 + {
194 + /* we depend on the firmware portion for correctness */
195 + .desc = "ARM erratum 1542419 (kernel portion)",
196 + .capability = ARM64_WORKAROUND_1542419,
197 + .type = ARM64_CPUCAP_LOCAL_CPU_ERRATUM,
198 + .matches = has_neoverse_n1_erratum_1542419,
199 + .cpu_enable = cpu_enable_trap_ctr_access,
200 + },
201 #endif
202 {
203 }
204 diff --git a/arch/arm64/kernel/sys_compat.c b/arch/arm64/kernel/sys_compat.c
205 index f1cb64959427..3c18c2454089 100644
206 --- a/arch/arm64/kernel/sys_compat.c
207 +++ b/arch/arm64/kernel/sys_compat.c
208 @@ -8,6 +8,7 @@
209 */
210
211 #include <linux/compat.h>
212 +#include <linux/cpufeature.h>
213 #include <linux/personality.h>
214 #include <linux/sched.h>
215 #include <linux/sched/signal.h>
216 @@ -17,6 +18,7 @@
217
218 #include <asm/cacheflush.h>
219 #include <asm/system_misc.h>
220 +#include <asm/tlbflush.h>
221 #include <asm/unistd.h>
222
223 static long
224 @@ -30,6 +32,15 @@ __do_compat_cache_op(unsigned long start, unsigned long end)
225 if (fatal_signal_pending(current))
226 return 0;
227
228 + if (cpus_have_const_cap(ARM64_WORKAROUND_1542419)) {
229 + /*
230 + * The workaround requires an inner-shareable tlbi.
231 + * We pick the reserved-ASID to minimise the impact.
232 + */
233 + __tlbi(aside1is, __TLBI_VADDR(0, 0));
234 + dsb(ish);
235 + }
236 +
237 ret = __flush_cache_user_range(start, start + chunk);
238 if (ret)
239 return ret;
240 diff --git a/arch/arm64/kernel/traps.c b/arch/arm64/kernel/traps.c
241 index 34739e80211b..4e3e9d9c8151 100644
242 --- a/arch/arm64/kernel/traps.c
243 +++ b/arch/arm64/kernel/traps.c
244 @@ -470,6 +470,15 @@ static void ctr_read_handler(unsigned int esr, struct pt_regs *regs)
245 int rt = ESR_ELx_SYS64_ISS_RT(esr);
246 unsigned long val = arm64_ftr_reg_user_value(&arm64_ftr_reg_ctrel0);
247
248 + if (cpus_have_const_cap(ARM64_WORKAROUND_1542419)) {
249 + /* Hide DIC so that we can trap the unnecessary maintenance...*/
250 + val &= ~BIT(CTR_DIC_SHIFT);
251 +
252 + /* ... and fake IminLine to reduce the number of traps. */
253 + val &= ~CTR_IMINLINE_MASK;
254 + val |= (PAGE_SHIFT - 2) & CTR_IMINLINE_MASK;
255 + }
256 +
257 pt_regs_write_reg(regs, rt, val);
258
259 arm64_skip_faulting_instruction(regs, AARCH64_INSN_SIZE);
260 diff --git a/arch/powerpc/kernel/entry_32.S b/arch/powerpc/kernel/entry_32.S
261 index 13f699256258..f29bb176381f 100644
262 --- a/arch/powerpc/kernel/entry_32.S
263 +++ b/arch/powerpc/kernel/entry_32.S
264 @@ -705,7 +705,7 @@ END_FTR_SECTION_IFSET(CPU_FTR_SPE)
265 stw r10,_CCR(r1)
266 stw r1,KSP(r3) /* Set old stack pointer */
267
268 - kuap_check r2, r4
269 + kuap_check r2, r0
270 #ifdef CONFIG_SMP
271 /* We need a sync somewhere here to make sure that if the
272 * previous task gets rescheduled on another CPU, it sees all
273 diff --git a/arch/powerpc/kernel/setup_64.c b/arch/powerpc/kernel/setup_64.c
274 index d7ff21316cfa..e50fbed36651 100644
275 --- a/arch/powerpc/kernel/setup_64.c
276 +++ b/arch/powerpc/kernel/setup_64.c
277 @@ -541,6 +541,8 @@ static bool __init parse_cache_info(struct device_node *np,
278 lsizep = of_get_property(np, propnames[3], NULL);
279 if (bsizep == NULL)
280 bsizep = lsizep;
281 + if (lsizep == NULL)
282 + lsizep = bsizep;
283 if (lsizep != NULL)
284 lsize = be32_to_cpu(*lsizep);
285 if (bsizep != NULL)
286 diff --git a/arch/powerpc/kernel/time.c b/arch/powerpc/kernel/time.c
287 index 11301a1187f3..0e0a2227af7d 100644
288 --- a/arch/powerpc/kernel/time.c
289 +++ b/arch/powerpc/kernel/time.c
290 @@ -522,35 +522,6 @@ static inline void clear_irq_work_pending(void)
291 "i" (offsetof(struct paca_struct, irq_work_pending)));
292 }
293
294 -void arch_irq_work_raise(void)
295 -{
296 - preempt_disable();
297 - set_irq_work_pending_flag();
298 - /*
299 - * Non-nmi code running with interrupts disabled will replay
300 - * irq_happened before it re-enables interrupts, so setthe
301 - * decrementer there instead of causing a hardware exception
302 - * which would immediately hit the masked interrupt handler
303 - * and have the net effect of setting the decrementer in
304 - * irq_happened.
305 - *
306 - * NMI interrupts can not check this when they return, so the
307 - * decrementer hardware exception is raised, which will fire
308 - * when interrupts are next enabled.
309 - *
310 - * BookE does not support this yet, it must audit all NMI
311 - * interrupt handlers to ensure they call nmi_enter() so this
312 - * check would be correct.
313 - */
314 - if (IS_ENABLED(CONFIG_BOOKE) || !irqs_disabled() || in_nmi()) {
315 - set_dec(1);
316 - } else {
317 - hard_irq_disable();
318 - local_paca->irq_happened |= PACA_IRQ_DEC;
319 - }
320 - preempt_enable();
321 -}
322 -
323 #else /* 32-bit */
324
325 DEFINE_PER_CPU(u8, irq_work_pending);
326 @@ -559,16 +530,27 @@ DEFINE_PER_CPU(u8, irq_work_pending);
327 #define test_irq_work_pending() __this_cpu_read(irq_work_pending)
328 #define clear_irq_work_pending() __this_cpu_write(irq_work_pending, 0)
329
330 +#endif /* 32 vs 64 bit */
331 +
332 void arch_irq_work_raise(void)
333 {
334 + /*
335 + * 64-bit code that uses irq soft-mask can just cause an immediate
336 + * interrupt here that gets soft masked, if this is called under
337 + * local_irq_disable(). It might be possible to prevent that happening
338 + * by noticing interrupts are disabled and setting decrementer pending
339 + * to be replayed when irqs are enabled. The problem there is that
340 + * tracing can call irq_work_raise, including in code that does low
341 + * level manipulations of irq soft-mask state (e.g., trace_hardirqs_on)
342 + * which could get tangled up if we're messing with the same state
343 + * here.
344 + */
345 preempt_disable();
346 set_irq_work_pending_flag();
347 set_dec(1);
348 preempt_enable();
349 }
350
351 -#endif /* 32 vs 64 bit */
352 -
353 #else /* CONFIG_IRQ_WORK */
354
355 #define test_irq_work_pending() 0
356 diff --git a/arch/powerpc/platforms/Kconfig.cputype b/arch/powerpc/platforms/Kconfig.cputype
357 index 12543e53fa96..f0330ce498d1 100644
358 --- a/arch/powerpc/platforms/Kconfig.cputype
359 +++ b/arch/powerpc/platforms/Kconfig.cputype
360 @@ -389,7 +389,7 @@ config PPC_KUAP
361
362 config PPC_KUAP_DEBUG
363 bool "Extra debugging for Kernel Userspace Access Protection"
364 - depends on PPC_HAVE_KUAP && (PPC_RADIX_MMU || PPC_32)
365 + depends on PPC_KUAP && (PPC_RADIX_MMU || PPC32)
366 help
367 Add extra debugging for Kernel Userspace Access Protection (KUAP)
368 If you're unsure, say N.
369 diff --git a/arch/powerpc/platforms/pseries/ras.c b/arch/powerpc/platforms/pseries/ras.c
370 index 3acdcc3bb908..753adeb624f2 100644
371 --- a/arch/powerpc/platforms/pseries/ras.c
372 +++ b/arch/powerpc/platforms/pseries/ras.c
373 @@ -683,6 +683,17 @@ static int mce_handle_error(struct pt_regs *regs, struct rtas_error_log *errp)
374 #endif
375
376 out:
377 + /*
378 + * Enable translation as we will be accessing per-cpu variables
379 + * in save_mce_event() which may fall outside RMO region, also
380 + * leave it enabled because subsequently we will be queuing work
381 + * to workqueues where again per-cpu variables accessed, besides
382 + * fwnmi_release_errinfo() crashes when called in realmode on
383 + * pseries.
384 + * Note: All the realmode handling like flushing SLB entries for
385 + * SLB multihit is done by now.
386 + */
387 + mtmsr(mfmsr() | MSR_IR | MSR_DR);
388 save_mce_event(regs, disposition == RTAS_DISP_FULLY_RECOVERED,
389 &mce_err, regs->nip, eaddr, paddr);
390
391 diff --git a/arch/s390/kvm/kvm-s390.c b/arch/s390/kvm/kvm-s390.c
392 index 756c627f7e54..6fb17b550a80 100644
393 --- a/arch/s390/kvm/kvm-s390.c
394 +++ b/arch/s390/kvm/kvm-s390.c
395 @@ -1932,6 +1932,9 @@ static int gfn_to_memslot_approx(struct kvm_memslots *slots, gfn_t gfn)
396 start = slot + 1;
397 }
398
399 + if (start >= slots->used_slots)
400 + return slots->used_slots - 1;
401 +
402 if (gfn >= memslots[start].base_gfn &&
403 gfn < memslots[start].base_gfn + memslots[start].npages) {
404 atomic_set(&slots->lru_slot, start);
405 diff --git a/arch/s390/lib/uaccess.c b/arch/s390/lib/uaccess.c
406 index c4f8039a35e8..0267405ab7c6 100644
407 --- a/arch/s390/lib/uaccess.c
408 +++ b/arch/s390/lib/uaccess.c
409 @@ -64,10 +64,13 @@ mm_segment_t enable_sacf_uaccess(void)
410 {
411 mm_segment_t old_fs;
412 unsigned long asce, cr;
413 + unsigned long flags;
414
415 old_fs = current->thread.mm_segment;
416 if (old_fs & 1)
417 return old_fs;
418 + /* protect against a concurrent page table upgrade */
419 + local_irq_save(flags);
420 current->thread.mm_segment |= 1;
421 asce = S390_lowcore.kernel_asce;
422 if (likely(old_fs == USER_DS)) {
423 @@ -83,6 +86,7 @@ mm_segment_t enable_sacf_uaccess(void)
424 __ctl_load(asce, 7, 7);
425 set_cpu_flag(CIF_ASCE_SECONDARY);
426 }
427 + local_irq_restore(flags);
428 return old_fs;
429 }
430 EXPORT_SYMBOL(enable_sacf_uaccess);
431 diff --git a/arch/s390/mm/pgalloc.c b/arch/s390/mm/pgalloc.c
432 index 3dd253f81a77..46071be897ab 100644
433 --- a/arch/s390/mm/pgalloc.c
434 +++ b/arch/s390/mm/pgalloc.c
435 @@ -70,8 +70,20 @@ static void __crst_table_upgrade(void *arg)
436 {
437 struct mm_struct *mm = arg;
438
439 - if (current->active_mm == mm)
440 - set_user_asce(mm);
441 + /* we must change all active ASCEs to avoid the creation of new TLBs */
442 + if (current->active_mm == mm) {
443 + S390_lowcore.user_asce = mm->context.asce;
444 + if (current->thread.mm_segment == USER_DS) {
445 + __ctl_load(S390_lowcore.user_asce, 1, 1);
446 + /* Mark user-ASCE present in CR1 */
447 + clear_cpu_flag(CIF_ASCE_PRIMARY);
448 + }
449 + if (current->thread.mm_segment == USER_DS_SACF) {
450 + __ctl_load(S390_lowcore.user_asce, 7, 7);
451 + /* enable_sacf_uaccess does all or nothing */
452 + WARN_ON(!test_cpu_flag(CIF_ASCE_SECONDARY));
453 + }
454 + }
455 __tlb_flush_local();
456 }
457
458 diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c
459 index 39a116d43993..72f51275247e 100644
460 --- a/arch/x86/kvm/vmx/vmx.c
461 +++ b/arch/x86/kvm/vmx/vmx.c
462 @@ -4566,7 +4566,7 @@ static int handle_rmode_exception(struct kvm_vcpu *vcpu,
463 */
464 static void kvm_machine_check(void)
465 {
466 -#if defined(CONFIG_X86_MCE) && defined(CONFIG_X86_64)
467 +#if defined(CONFIG_X86_MCE)
468 struct pt_regs regs = {
469 .cs = 3, /* Fake ring 3 no matter what the guest ran on */
470 .flags = X86_EFLAGS_IF,
471 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
472 index ef6e251857c8..57ed6b70d295 100644
473 --- a/drivers/block/loop.c
474 +++ b/drivers/block/loop.c
475 @@ -427,11 +427,12 @@ static int lo_fallocate(struct loop_device *lo, struct request *rq, loff_t pos,
476 * information.
477 */
478 struct file *file = lo->lo_backing_file;
479 + struct request_queue *q = lo->lo_queue;
480 int ret;
481
482 mode |= FALLOC_FL_KEEP_SIZE;
483
484 - if ((!file->f_op->fallocate) || lo->lo_encrypt_key_size) {
485 + if (!blk_queue_discard(q)) {
486 ret = -EOPNOTSUPP;
487 goto out;
488 }
489 @@ -863,28 +864,47 @@ static void loop_config_discard(struct loop_device *lo)
490 struct inode *inode = file->f_mapping->host;
491 struct request_queue *q = lo->lo_queue;
492
493 + /*
494 + * If the backing device is a block device, mirror its zeroing
495 + * capability. Set the discard sectors to the block device's zeroing
496 + * capabilities because loop discards result in blkdev_issue_zeroout(),
497 + * not blkdev_issue_discard(). This maintains consistent behavior with
498 + * file-backed loop devices: discarded regions read back as zero.
499 + */
500 + if (S_ISBLK(inode->i_mode) && !lo->lo_encrypt_key_size) {
501 + struct request_queue *backingq;
502 +
503 + backingq = bdev_get_queue(inode->i_bdev);
504 + blk_queue_max_discard_sectors(q,
505 + backingq->limits.max_write_zeroes_sectors);
506 +
507 + blk_queue_max_write_zeroes_sectors(q,
508 + backingq->limits.max_write_zeroes_sectors);
509 +
510 /*
511 * We use punch hole to reclaim the free space used by the
512 * image a.k.a. discard. However we do not support discard if
513 * encryption is enabled, because it may give an attacker
514 * useful information.
515 */
516 - if ((!file->f_op->fallocate) ||
517 - lo->lo_encrypt_key_size) {
518 + } else if (!file->f_op->fallocate || lo->lo_encrypt_key_size) {
519 q->limits.discard_granularity = 0;
520 q->limits.discard_alignment = 0;
521 blk_queue_max_discard_sectors(q, 0);
522 blk_queue_max_write_zeroes_sectors(q, 0);
523 - blk_queue_flag_clear(QUEUE_FLAG_DISCARD, q);
524 - return;
525 - }
526
527 - q->limits.discard_granularity = inode->i_sb->s_blocksize;
528 - q->limits.discard_alignment = 0;
529 + } else {
530 + q->limits.discard_granularity = inode->i_sb->s_blocksize;
531 + q->limits.discard_alignment = 0;
532
533 - blk_queue_max_discard_sectors(q, UINT_MAX >> 9);
534 - blk_queue_max_write_zeroes_sectors(q, UINT_MAX >> 9);
535 - blk_queue_flag_set(QUEUE_FLAG_DISCARD, q);
536 + blk_queue_max_discard_sectors(q, UINT_MAX >> 9);
537 + blk_queue_max_write_zeroes_sectors(q, UINT_MAX >> 9);
538 + }
539 +
540 + if (q->limits.max_write_zeroes_sectors)
541 + blk_queue_flag_set(QUEUE_FLAG_DISCARD, q);
542 + else
543 + blk_queue_flag_clear(QUEUE_FLAG_DISCARD, q);
544 }
545
546 static void loop_unprepare_queue(struct loop_device *lo)
547 diff --git a/drivers/block/virtio_blk.c b/drivers/block/virtio_blk.c
548 index c2ed3e9128e3..a55383b139df 100644
549 --- a/drivers/block/virtio_blk.c
550 +++ b/drivers/block/virtio_blk.c
551 @@ -345,9 +345,14 @@ static blk_status_t virtio_queue_rq(struct blk_mq_hw_ctx *hctx,
552 if (err == -ENOSPC)
553 blk_mq_stop_hw_queue(hctx);
554 spin_unlock_irqrestore(&vblk->vqs[qid].lock, flags);
555 - if (err == -ENOMEM || err == -ENOSPC)
556 + switch (err) {
557 + case -ENOSPC:
558 return BLK_STS_DEV_RESOURCE;
559 - return BLK_STS_IOERR;
560 + case -ENOMEM:
561 + return BLK_STS_RESOURCE;
562 + default:
563 + return BLK_STS_IOERR;
564 + }
565 }
566
567 if (bd->last && virtqueue_kick_prepare(vblk->vqs[qid].vq))
568 diff --git a/drivers/char/tpm/tpm-interface.c b/drivers/char/tpm/tpm-interface.c
569 index d7a3888ad80f..b86ee5b18855 100644
570 --- a/drivers/char/tpm/tpm-interface.c
571 +++ b/drivers/char/tpm/tpm-interface.c
572 @@ -322,7 +322,7 @@ int tpm_pcr_extend(struct tpm_chip *chip, u32 pcr_idx,
573
574 for (i = 0; i < chip->nr_allocated_banks; i++) {
575 if (digests[i].alg_id != chip->allocated_banks[i].alg_id) {
576 - rc = EINVAL;
577 + rc = -EINVAL;
578 goto out;
579 }
580 }
581 diff --git a/drivers/char/tpm/tpm_ibmvtpm.c b/drivers/char/tpm/tpm_ibmvtpm.c
582 index 78cc52690177..e82013d587b4 100644
583 --- a/drivers/char/tpm/tpm_ibmvtpm.c
584 +++ b/drivers/char/tpm/tpm_ibmvtpm.c
585 @@ -1,6 +1,6 @@
586 // SPDX-License-Identifier: GPL-2.0-only
587 /*
588 - * Copyright (C) 2012 IBM Corporation
589 + * Copyright (C) 2012-2020 IBM Corporation
590 *
591 * Author: Ashley Lai <ashleydlai@gmail.com>
592 *
593 @@ -133,6 +133,64 @@ static int tpm_ibmvtpm_recv(struct tpm_chip *chip, u8 *buf, size_t count)
594 return len;
595 }
596
597 +/**
598 + * ibmvtpm_crq_send_init - Send a CRQ initialize message
599 + * @ibmvtpm: vtpm device struct
600 + *
601 + * Return:
602 + * 0 on success.
603 + * Non-zero on failure.
604 + */
605 +static int ibmvtpm_crq_send_init(struct ibmvtpm_dev *ibmvtpm)
606 +{
607 + int rc;
608 +
609 + rc = ibmvtpm_send_crq_word(ibmvtpm->vdev, INIT_CRQ_CMD);
610 + if (rc != H_SUCCESS)
611 + dev_err(ibmvtpm->dev,
612 + "%s failed rc=%d\n", __func__, rc);
613 +
614 + return rc;
615 +}
616 +
617 +/**
618 + * tpm_ibmvtpm_resume - Resume from suspend
619 + *
620 + * @dev: device struct
621 + *
622 + * Return: Always 0.
623 + */
624 +static int tpm_ibmvtpm_resume(struct device *dev)
625 +{
626 + struct tpm_chip *chip = dev_get_drvdata(dev);
627 + struct ibmvtpm_dev *ibmvtpm = dev_get_drvdata(&chip->dev);
628 + int rc = 0;
629 +
630 + do {
631 + if (rc)
632 + msleep(100);
633 + rc = plpar_hcall_norets(H_ENABLE_CRQ,
634 + ibmvtpm->vdev->unit_address);
635 + } while (rc == H_IN_PROGRESS || rc == H_BUSY || H_IS_LONG_BUSY(rc));
636 +
637 + if (rc) {
638 + dev_err(dev, "Error enabling ibmvtpm rc=%d\n", rc);
639 + return rc;
640 + }
641 +
642 + rc = vio_enable_interrupts(ibmvtpm->vdev);
643 + if (rc) {
644 + dev_err(dev, "Error vio_enable_interrupts rc=%d\n", rc);
645 + return rc;
646 + }
647 +
648 + rc = ibmvtpm_crq_send_init(ibmvtpm);
649 + if (rc)
650 + dev_err(dev, "Error send_init rc=%d\n", rc);
651 +
652 + return rc;
653 +}
654 +
655 /**
656 * tpm_ibmvtpm_send() - Send a TPM command
657 * @chip: tpm chip struct
658 @@ -146,6 +204,7 @@ static int tpm_ibmvtpm_recv(struct tpm_chip *chip, u8 *buf, size_t count)
659 static int tpm_ibmvtpm_send(struct tpm_chip *chip, u8 *buf, size_t count)
660 {
661 struct ibmvtpm_dev *ibmvtpm = dev_get_drvdata(&chip->dev);
662 + bool retry = true;
663 int rc, sig;
664
665 if (!ibmvtpm->rtce_buf) {
666 @@ -179,18 +238,27 @@ static int tpm_ibmvtpm_send(struct tpm_chip *chip, u8 *buf, size_t count)
667 */
668 ibmvtpm->tpm_processing_cmd = true;
669
670 +again:
671 rc = ibmvtpm_send_crq(ibmvtpm->vdev,
672 IBMVTPM_VALID_CMD, VTPM_TPM_COMMAND,
673 count, ibmvtpm->rtce_dma_handle);
674 if (rc != H_SUCCESS) {
675 + /*
676 + * H_CLOSED can be returned after LPM resume. Call
677 + * tpm_ibmvtpm_resume() to re-enable the CRQ then retry
678 + * ibmvtpm_send_crq() once before failing.
679 + */
680 + if (rc == H_CLOSED && retry) {
681 + tpm_ibmvtpm_resume(ibmvtpm->dev);
682 + retry = false;
683 + goto again;
684 + }
685 dev_err(ibmvtpm->dev, "tpm_ibmvtpm_send failed rc=%d\n", rc);
686 - rc = 0;
687 ibmvtpm->tpm_processing_cmd = false;
688 - } else
689 - rc = 0;
690 + }
691
692 spin_unlock(&ibmvtpm->rtce_lock);
693 - return rc;
694 + return 0;
695 }
696
697 static void tpm_ibmvtpm_cancel(struct tpm_chip *chip)
698 @@ -268,26 +336,6 @@ static int ibmvtpm_crq_send_init_complete(struct ibmvtpm_dev *ibmvtpm)
699 return rc;
700 }
701
702 -/**
703 - * ibmvtpm_crq_send_init - Send a CRQ initialize message
704 - * @ibmvtpm: vtpm device struct
705 - *
706 - * Return:
707 - * 0 on success.
708 - * Non-zero on failure.
709 - */
710 -static int ibmvtpm_crq_send_init(struct ibmvtpm_dev *ibmvtpm)
711 -{
712 - int rc;
713 -
714 - rc = ibmvtpm_send_crq_word(ibmvtpm->vdev, INIT_CRQ_CMD);
715 - if (rc != H_SUCCESS)
716 - dev_err(ibmvtpm->dev,
717 - "ibmvtpm_crq_send_init failed rc=%d\n", rc);
718 -
719 - return rc;
720 -}
721 -
722 /**
723 * tpm_ibmvtpm_remove - ibm vtpm remove entry point
724 * @vdev: vio device struct
725 @@ -400,44 +448,6 @@ static int ibmvtpm_reset_crq(struct ibmvtpm_dev *ibmvtpm)
726 ibmvtpm->crq_dma_handle, CRQ_RES_BUF_SIZE);
727 }
728
729 -/**
730 - * tpm_ibmvtpm_resume - Resume from suspend
731 - *
732 - * @dev: device struct
733 - *
734 - * Return: Always 0.
735 - */
736 -static int tpm_ibmvtpm_resume(struct device *dev)
737 -{
738 - struct tpm_chip *chip = dev_get_drvdata(dev);
739 - struct ibmvtpm_dev *ibmvtpm = dev_get_drvdata(&chip->dev);
740 - int rc = 0;
741 -
742 - do {
743 - if (rc)
744 - msleep(100);
745 - rc = plpar_hcall_norets(H_ENABLE_CRQ,
746 - ibmvtpm->vdev->unit_address);
747 - } while (rc == H_IN_PROGRESS || rc == H_BUSY || H_IS_LONG_BUSY(rc));
748 -
749 - if (rc) {
750 - dev_err(dev, "Error enabling ibmvtpm rc=%d\n", rc);
751 - return rc;
752 - }
753 -
754 - rc = vio_enable_interrupts(ibmvtpm->vdev);
755 - if (rc) {
756 - dev_err(dev, "Error vio_enable_interrupts rc=%d\n", rc);
757 - return rc;
758 - }
759 -
760 - rc = ibmvtpm_crq_send_init(ibmvtpm);
761 - if (rc)
762 - dev_err(dev, "Error send_init rc=%d\n", rc);
763 -
764 - return rc;
765 -}
766 -
767 static bool tpm_ibmvtpm_req_canceled(struct tpm_chip *chip, u8 status)
768 {
769 return (status == 0);
770 diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c
771 index c3181ea9f271..bdcf8f25cd0d 100644
772 --- a/drivers/char/tpm/tpm_tis_core.c
773 +++ b/drivers/char/tpm/tpm_tis_core.c
774 @@ -433,6 +433,9 @@ static void disable_interrupts(struct tpm_chip *chip)
775 u32 intmask;
776 int rc;
777
778 + if (priv->irq == 0)
779 + return;
780 +
781 rc = tpm_tis_read32(priv, TPM_INT_ENABLE(priv->locality), &intmask);
782 if (rc < 0)
783 intmask = 0;
784 @@ -983,9 +986,12 @@ int tpm_tis_core_init(struct device *dev, struct tpm_tis_data *priv, int irq,
785 if (irq) {
786 tpm_tis_probe_irq_single(chip, intmask, IRQF_SHARED,
787 irq);
788 - if (!(chip->flags & TPM_CHIP_FLAG_IRQ))
789 + if (!(chip->flags & TPM_CHIP_FLAG_IRQ)) {
790 dev_err(&chip->dev, FW_BUG
791 "TPM interrupt not working, polling instead\n");
792 +
793 + disable_interrupts(chip);
794 + }
795 } else {
796 tpm_tis_probe_irq(chip, intmask);
797 }
798 diff --git a/drivers/fpga/dfl-pci.c b/drivers/fpga/dfl-pci.c
799 index 89ca292236ad..538755062ab7 100644
800 --- a/drivers/fpga/dfl-pci.c
801 +++ b/drivers/fpga/dfl-pci.c
802 @@ -248,11 +248,13 @@ static int cci_pci_sriov_configure(struct pci_dev *pcidev, int num_vfs)
803 return ret;
804
805 ret = pci_enable_sriov(pcidev, num_vfs);
806 - if (ret)
807 + if (ret) {
808 dfl_fpga_cdev_config_ports_pf(cdev);
809 + return ret;
810 + }
811 }
812
813 - return ret;
814 + return num_vfs;
815 }
816
817 static void cci_pci_remove(struct pci_dev *pcidev)
818 diff --git a/drivers/gpu/drm/amd/display/dc/core/dc.c b/drivers/gpu/drm/amd/display/dc/core/dc.c
819 index 4704aac336c2..2028dc017f7a 100644
820 --- a/drivers/gpu/drm/amd/display/dc/core/dc.c
821 +++ b/drivers/gpu/drm/amd/display/dc/core/dc.c
822 @@ -283,6 +283,8 @@ bool dc_stream_adjust_vmin_vmax(struct dc *dc,
823 int i = 0;
824 bool ret = false;
825
826 + stream->adjust = *adjust;
827 +
828 for (i = 0; i < MAX_PIPES; i++) {
829 struct pipe_ctx *pipe = &dc->current_state->res_ctx.pipe_ctx[i];
830
831 @@ -1180,6 +1182,26 @@ bool dc_commit_state(struct dc *dc, struct dc_state *context)
832 return (result == DC_OK);
833 }
834
835 +static bool is_flip_pending_in_pipes(struct dc *dc, struct dc_state *context)
836 +{
837 + int i;
838 + struct pipe_ctx *pipe;
839 +
840 + for (i = 0; i < MAX_PIPES; i++) {
841 + pipe = &context->res_ctx.pipe_ctx[i];
842 +
843 + if (!pipe->plane_state)
844 + continue;
845 +
846 + /* Must set to false to start with, due to OR in update function */
847 + pipe->plane_state->status.is_flip_pending = false;
848 + dc->hwss.update_pending_status(pipe);
849 + if (pipe->plane_state->status.is_flip_pending)
850 + return true;
851 + }
852 + return false;
853 +}
854 +
855 bool dc_post_update_surfaces_to_stream(struct dc *dc)
856 {
857 int i;
858 @@ -1190,6 +1212,9 @@ bool dc_post_update_surfaces_to_stream(struct dc *dc)
859
860 post_surface_trace(dc);
861
862 + if (is_flip_pending_in_pipes(dc, context))
863 + return true;
864 +
865 for (i = 0; i < dc->res_pool->pipe_count; i++)
866 if (context->res_ctx.pipe_ctx[i].stream == NULL ||
867 context->res_ctx.pipe_ctx[i].plane_state == NULL) {
868 @@ -2152,7 +2177,7 @@ void dc_commit_updates_for_stream(struct dc *dc,
869 enum surface_update_type update_type;
870 struct dc_state *context;
871 struct dc_context *dc_ctx = dc->ctx;
872 - int i;
873 + int i, j;
874
875 stream_status = dc_stream_get_status(stream);
876 context = dc->current_state;
877 @@ -2190,6 +2215,17 @@ void dc_commit_updates_for_stream(struct dc *dc,
878
879 copy_surface_update_to_plane(surface, &srf_updates[i]);
880
881 + if (update_type >= UPDATE_TYPE_MED) {
882 + for (j = 0; j < dc->res_pool->pipe_count; j++) {
883 + struct pipe_ctx *pipe_ctx =
884 + &context->res_ctx.pipe_ctx[j];
885 +
886 + if (pipe_ctx->plane_state != surface)
887 + continue;
888 +
889 + resource_build_scaling_params(pipe_ctx);
890 + }
891 + }
892 }
893
894 copy_stream_update_to_stream(dc, context, stream, stream_update);
895 diff --git a/drivers/iio/adc/stm32-adc.c b/drivers/iio/adc/stm32-adc.c
896 index 73aee5949b6b..9f63ceb15865 100644
897 --- a/drivers/iio/adc/stm32-adc.c
898 +++ b/drivers/iio/adc/stm32-adc.c
899 @@ -1367,8 +1367,30 @@ static unsigned int stm32_adc_dma_residue(struct stm32_adc *adc)
900 static void stm32_adc_dma_buffer_done(void *data)
901 {
902 struct iio_dev *indio_dev = data;
903 + struct stm32_adc *adc = iio_priv(indio_dev);
904 + int residue = stm32_adc_dma_residue(adc);
905 +
906 + /*
907 + * In DMA mode the trigger services of IIO are not used
908 + * (e.g. no call to iio_trigger_poll).
909 + * Calling irq handler associated to the hardware trigger is not
910 + * relevant as the conversions have already been done. Data
911 + * transfers are performed directly in DMA callback instead.
912 + * This implementation avoids to call trigger irq handler that
913 + * may sleep, in an atomic context (DMA irq handler context).
914 + */
915 + dev_dbg(&indio_dev->dev, "%s bufi=%d\n", __func__, adc->bufi);
916
917 - iio_trigger_poll_chained(indio_dev->trig);
918 + while (residue >= indio_dev->scan_bytes) {
919 + u16 *buffer = (u16 *)&adc->rx_buf[adc->bufi];
920 +
921 + iio_push_to_buffers(indio_dev, buffer);
922 +
923 + residue -= indio_dev->scan_bytes;
924 + adc->bufi += indio_dev->scan_bytes;
925 + if (adc->bufi >= adc->rx_buf_sz)
926 + adc->bufi = 0;
927 + }
928 }
929
930 static int stm32_adc_dma_start(struct iio_dev *indio_dev)
931 @@ -1778,6 +1800,7 @@ static int stm32_adc_probe(struct platform_device *pdev)
932 {
933 struct iio_dev *indio_dev;
934 struct device *dev = &pdev->dev;
935 + irqreturn_t (*handler)(int irq, void *p) = NULL;
936 struct stm32_adc *adc;
937 int ret;
938
939 @@ -1843,9 +1866,11 @@ static int stm32_adc_probe(struct platform_device *pdev)
940 if (ret < 0)
941 return ret;
942
943 + if (!adc->dma_chan)
944 + handler = &stm32_adc_trigger_handler;
945 +
946 ret = iio_triggered_buffer_setup(indio_dev,
947 - &iio_pollfunc_store_time,
948 - &stm32_adc_trigger_handler,
949 + &iio_pollfunc_store_time, handler,
950 &stm32_adc_buffer_setup_ops);
951 if (ret) {
952 dev_err(&pdev->dev, "buffer setup failed\n");
953 diff --git a/drivers/iio/adc/ti-ads8344.c b/drivers/iio/adc/ti-ads8344.c
954 index 9a460807d46d..abe4b56c847c 100644
955 --- a/drivers/iio/adc/ti-ads8344.c
956 +++ b/drivers/iio/adc/ti-ads8344.c
957 @@ -29,7 +29,7 @@ struct ads8344 {
958 struct mutex lock;
959
960 u8 tx_buf ____cacheline_aligned;
961 - u16 rx_buf;
962 + u8 rx_buf[3];
963 };
964
965 #define ADS8344_VOLTAGE_CHANNEL(chan, si) \
966 @@ -89,11 +89,11 @@ static int ads8344_adc_conversion(struct ads8344 *adc, int channel,
967
968 udelay(9);
969
970 - ret = spi_read(spi, &adc->rx_buf, 2);
971 + ret = spi_read(spi, adc->rx_buf, sizeof(adc->rx_buf));
972 if (ret)
973 return ret;
974
975 - return adc->rx_buf;
976 + return adc->rx_buf[0] << 9 | adc->rx_buf[1] << 1 | adc->rx_buf[2] >> 7;
977 }
978
979 static int ads8344_read_raw(struct iio_dev *iio,
980 diff --git a/drivers/iio/adc/xilinx-xadc-core.c b/drivers/iio/adc/xilinx-xadc-core.c
981 index 4fd389678dba..3f0b88b13dd3 100644
982 --- a/drivers/iio/adc/xilinx-xadc-core.c
983 +++ b/drivers/iio/adc/xilinx-xadc-core.c
984 @@ -102,6 +102,16 @@ static const unsigned int XADC_ZYNQ_UNMASK_TIMEOUT = 500;
985
986 #define XADC_FLAGS_BUFFERED BIT(0)
987
988 +/*
989 + * The XADC hardware supports a samplerate of up to 1MSPS. Unfortunately it does
990 + * not have a hardware FIFO. Which means an interrupt is generated for each
991 + * conversion sequence. At 1MSPS sample rate the CPU in ZYNQ7000 is completely
992 + * overloaded by the interrupts that it soft-lockups. For this reason the driver
993 + * limits the maximum samplerate 150kSPS. At this rate the CPU is fairly busy,
994 + * but still responsive.
995 + */
996 +#define XADC_MAX_SAMPLERATE 150000
997 +
998 static void xadc_write_reg(struct xadc *xadc, unsigned int reg,
999 uint32_t val)
1000 {
1001 @@ -674,7 +684,7 @@ static int xadc_trigger_set_state(struct iio_trigger *trigger, bool state)
1002
1003 spin_lock_irqsave(&xadc->lock, flags);
1004 xadc_read_reg(xadc, XADC_AXI_REG_IPIER, &val);
1005 - xadc_write_reg(xadc, XADC_AXI_REG_IPISR, val & XADC_AXI_INT_EOS);
1006 + xadc_write_reg(xadc, XADC_AXI_REG_IPISR, XADC_AXI_INT_EOS);
1007 if (state)
1008 val |= XADC_AXI_INT_EOS;
1009 else
1010 @@ -722,13 +732,14 @@ static int xadc_power_adc_b(struct xadc *xadc, unsigned int seq_mode)
1011 {
1012 uint16_t val;
1013
1014 + /* Powerdown the ADC-B when it is not needed. */
1015 switch (seq_mode) {
1016 case XADC_CONF1_SEQ_SIMULTANEOUS:
1017 case XADC_CONF1_SEQ_INDEPENDENT:
1018 - val = XADC_CONF2_PD_ADC_B;
1019 + val = 0;
1020 break;
1021 default:
1022 - val = 0;
1023 + val = XADC_CONF2_PD_ADC_B;
1024 break;
1025 }
1026
1027 @@ -797,6 +808,16 @@ static int xadc_preenable(struct iio_dev *indio_dev)
1028 if (ret)
1029 goto err;
1030
1031 + /*
1032 + * In simultaneous mode the upper and lower aux channels are samples at
1033 + * the same time. In this mode the upper 8 bits in the sequencer
1034 + * register are don't care and the lower 8 bits control two channels
1035 + * each. As such we must set the bit if either the channel in the lower
1036 + * group or the upper group is enabled.
1037 + */
1038 + if (seq_mode == XADC_CONF1_SEQ_SIMULTANEOUS)
1039 + scan_mask = ((scan_mask >> 8) | scan_mask) & 0xff0000;
1040 +
1041 ret = xadc_write_adc_reg(xadc, XADC_REG_SEQ(1), scan_mask >> 16);
1042 if (ret)
1043 goto err;
1044 @@ -823,11 +844,27 @@ static const struct iio_buffer_setup_ops xadc_buffer_ops = {
1045 .postdisable = &xadc_postdisable,
1046 };
1047
1048 +static int xadc_read_samplerate(struct xadc *xadc)
1049 +{
1050 + unsigned int div;
1051 + uint16_t val16;
1052 + int ret;
1053 +
1054 + ret = xadc_read_adc_reg(xadc, XADC_REG_CONF2, &val16);
1055 + if (ret)
1056 + return ret;
1057 +
1058 + div = (val16 & XADC_CONF2_DIV_MASK) >> XADC_CONF2_DIV_OFFSET;
1059 + if (div < 2)
1060 + div = 2;
1061 +
1062 + return xadc_get_dclk_rate(xadc) / div / 26;
1063 +}
1064 +
1065 static int xadc_read_raw(struct iio_dev *indio_dev,
1066 struct iio_chan_spec const *chan, int *val, int *val2, long info)
1067 {
1068 struct xadc *xadc = iio_priv(indio_dev);
1069 - unsigned int div;
1070 uint16_t val16;
1071 int ret;
1072
1073 @@ -880,41 +917,31 @@ static int xadc_read_raw(struct iio_dev *indio_dev,
1074 *val = -((273150 << 12) / 503975);
1075 return IIO_VAL_INT;
1076 case IIO_CHAN_INFO_SAMP_FREQ:
1077 - ret = xadc_read_adc_reg(xadc, XADC_REG_CONF2, &val16);
1078 - if (ret)
1079 + ret = xadc_read_samplerate(xadc);
1080 + if (ret < 0)
1081 return ret;
1082
1083 - div = (val16 & XADC_CONF2_DIV_MASK) >> XADC_CONF2_DIV_OFFSET;
1084 - if (div < 2)
1085 - div = 2;
1086 -
1087 - *val = xadc_get_dclk_rate(xadc) / div / 26;
1088 -
1089 + *val = ret;
1090 return IIO_VAL_INT;
1091 default:
1092 return -EINVAL;
1093 }
1094 }
1095
1096 -static int xadc_write_raw(struct iio_dev *indio_dev,
1097 - struct iio_chan_spec const *chan, int val, int val2, long info)
1098 +static int xadc_write_samplerate(struct xadc *xadc, int val)
1099 {
1100 - struct xadc *xadc = iio_priv(indio_dev);
1101 unsigned long clk_rate = xadc_get_dclk_rate(xadc);
1102 unsigned int div;
1103
1104 if (!clk_rate)
1105 return -EINVAL;
1106
1107 - if (info != IIO_CHAN_INFO_SAMP_FREQ)
1108 - return -EINVAL;
1109 -
1110 if (val <= 0)
1111 return -EINVAL;
1112
1113 /* Max. 150 kSPS */
1114 - if (val > 150000)
1115 - val = 150000;
1116 + if (val > XADC_MAX_SAMPLERATE)
1117 + val = XADC_MAX_SAMPLERATE;
1118
1119 val *= 26;
1120
1121 @@ -927,7 +954,7 @@ static int xadc_write_raw(struct iio_dev *indio_dev,
1122 * limit.
1123 */
1124 div = clk_rate / val;
1125 - if (clk_rate / div / 26 > 150000)
1126 + if (clk_rate / div / 26 > XADC_MAX_SAMPLERATE)
1127 div++;
1128 if (div < 2)
1129 div = 2;
1130 @@ -938,6 +965,17 @@ static int xadc_write_raw(struct iio_dev *indio_dev,
1131 div << XADC_CONF2_DIV_OFFSET);
1132 }
1133
1134 +static int xadc_write_raw(struct iio_dev *indio_dev,
1135 + struct iio_chan_spec const *chan, int val, int val2, long info)
1136 +{
1137 + struct xadc *xadc = iio_priv(indio_dev);
1138 +
1139 + if (info != IIO_CHAN_INFO_SAMP_FREQ)
1140 + return -EINVAL;
1141 +
1142 + return xadc_write_samplerate(xadc, val);
1143 +}
1144 +
1145 static const struct iio_event_spec xadc_temp_events[] = {
1146 {
1147 .type = IIO_EV_TYPE_THRESH,
1148 @@ -1225,6 +1263,21 @@ static int xadc_probe(struct platform_device *pdev)
1149 if (ret)
1150 goto err_free_samplerate_trigger;
1151
1152 + /*
1153 + * Make sure not to exceed the maximum samplerate since otherwise the
1154 + * resulting interrupt storm will soft-lock the system.
1155 + */
1156 + if (xadc->ops->flags & XADC_FLAGS_BUFFERED) {
1157 + ret = xadc_read_samplerate(xadc);
1158 + if (ret < 0)
1159 + goto err_free_samplerate_trigger;
1160 + if (ret > XADC_MAX_SAMPLERATE) {
1161 + ret = xadc_write_samplerate(xadc, XADC_MAX_SAMPLERATE);
1162 + if (ret < 0)
1163 + goto err_free_samplerate_trigger;
1164 + }
1165 + }
1166 +
1167 ret = request_irq(xadc->irq, xadc->ops->interrupt_handler, 0,
1168 dev_name(&pdev->dev), indio_dev);
1169 if (ret)
1170 diff --git a/drivers/iio/common/st_sensors/st_sensors_core.c b/drivers/iio/common/st_sensors/st_sensors_core.c
1171 index 4a3064fb6cd9..364683783ae5 100644
1172 --- a/drivers/iio/common/st_sensors/st_sensors_core.c
1173 +++ b/drivers/iio/common/st_sensors/st_sensors_core.c
1174 @@ -80,7 +80,7 @@ int st_sensors_set_odr(struct iio_dev *indio_dev, unsigned int odr)
1175 struct st_sensor_odr_avl odr_out = {0, 0};
1176 struct st_sensor_data *sdata = iio_priv(indio_dev);
1177
1178 - if (!sdata->sensor_settings->odr.addr)
1179 + if (!sdata->sensor_settings->odr.mask)
1180 return 0;
1181
1182 err = st_sensors_match_odr(sdata->sensor_settings, odr, &odr_out);
1183 diff --git a/drivers/net/dsa/b53/b53_common.c b/drivers/net/dsa/b53/b53_common.c
1184 index d618650533b6..14850b7fe6d7 100644
1185 --- a/drivers/net/dsa/b53/b53_common.c
1186 +++ b/drivers/net/dsa/b53/b53_common.c
1187 @@ -1441,6 +1441,10 @@ static int b53_arl_rw_op(struct b53_device *dev, unsigned int op)
1188 reg |= ARLTBL_RW;
1189 else
1190 reg &= ~ARLTBL_RW;
1191 + if (dev->vlan_enabled)
1192 + reg &= ~ARLTBL_IVL_SVL_SELECT;
1193 + else
1194 + reg |= ARLTBL_IVL_SVL_SELECT;
1195 b53_write8(dev, B53_ARLIO_PAGE, B53_ARLTBL_RW_CTRL, reg);
1196
1197 return b53_arl_op_wait(dev);
1198 @@ -1450,6 +1454,7 @@ static int b53_arl_read(struct b53_device *dev, u64 mac,
1199 u16 vid, struct b53_arl_entry *ent, u8 *idx,
1200 bool is_valid)
1201 {
1202 + DECLARE_BITMAP(free_bins, B53_ARLTBL_MAX_BIN_ENTRIES);
1203 unsigned int i;
1204 int ret;
1205
1206 @@ -1457,6 +1462,8 @@ static int b53_arl_read(struct b53_device *dev, u64 mac,
1207 if (ret)
1208 return ret;
1209
1210 + bitmap_zero(free_bins, dev->num_arl_entries);
1211 +
1212 /* Read the bins */
1213 for (i = 0; i < dev->num_arl_entries; i++) {
1214 u64 mac_vid;
1215 @@ -1468,13 +1475,24 @@ static int b53_arl_read(struct b53_device *dev, u64 mac,
1216 B53_ARLTBL_DATA_ENTRY(i), &fwd_entry);
1217 b53_arl_to_entry(ent, mac_vid, fwd_entry);
1218
1219 - if (!(fwd_entry & ARLTBL_VALID))
1220 + if (!(fwd_entry & ARLTBL_VALID)) {
1221 + set_bit(i, free_bins);
1222 continue;
1223 + }
1224 if ((mac_vid & ARLTBL_MAC_MASK) != mac)
1225 continue;
1226 + if (dev->vlan_enabled &&
1227 + ((mac_vid >> ARLTBL_VID_S) & ARLTBL_VID_MASK) != vid)
1228 + continue;
1229 *idx = i;
1230 + return 0;
1231 }
1232
1233 + if (bitmap_weight(free_bins, dev->num_arl_entries) == 0)
1234 + return -ENOSPC;
1235 +
1236 + *idx = find_first_bit(free_bins, dev->num_arl_entries);
1237 +
1238 return -ENOENT;
1239 }
1240
1241 @@ -1504,15 +1522,25 @@ static int b53_arl_op(struct b53_device *dev, int op, int port,
1242 if (op)
1243 return ret;
1244
1245 - /* We could not find a matching MAC, so reset to a new entry */
1246 - if (ret) {
1247 + switch (ret) {
1248 + case -ENOSPC:
1249 + dev_dbg(dev->dev, "{%pM,%.4d} no space left in ARL\n",
1250 + addr, vid);
1251 + return is_valid ? ret : 0;
1252 + case -ENOENT:
1253 + /* We could not find a matching MAC, so reset to a new entry */
1254 + dev_dbg(dev->dev, "{%pM,%.4d} not found, using idx: %d\n",
1255 + addr, vid, idx);
1256 fwd_entry = 0;
1257 - idx = 1;
1258 + break;
1259 + default:
1260 + dev_dbg(dev->dev, "{%pM,%.4d} found, using idx: %d\n",
1261 + addr, vid, idx);
1262 + break;
1263 }
1264
1265 memset(&ent, 0, sizeof(ent));
1266 ent.port = port;
1267 - ent.is_valid = is_valid;
1268 ent.vid = vid;
1269 ent.is_static = true;
1270 memcpy(ent.mac, addr, ETH_ALEN);
1271 diff --git a/drivers/net/dsa/b53/b53_regs.h b/drivers/net/dsa/b53/b53_regs.h
1272 index 2a9f421680aa..c90985c294a2 100644
1273 --- a/drivers/net/dsa/b53/b53_regs.h
1274 +++ b/drivers/net/dsa/b53/b53_regs.h
1275 @@ -292,6 +292,7 @@
1276 /* ARL Table Read/Write Register (8 bit) */
1277 #define B53_ARLTBL_RW_CTRL 0x00
1278 #define ARLTBL_RW BIT(0)
1279 +#define ARLTBL_IVL_SVL_SELECT BIT(6)
1280 #define ARLTBL_START_DONE BIT(7)
1281
1282 /* MAC Address Index Register (48 bit) */
1283 @@ -304,7 +305,7 @@
1284 *
1285 * BCM5325 and BCM5365 share most definitions below
1286 */
1287 -#define B53_ARLTBL_MAC_VID_ENTRY(n) (0x10 * (n))
1288 +#define B53_ARLTBL_MAC_VID_ENTRY(n) ((0x10 * (n)) + 0x10)
1289 #define ARLTBL_MAC_MASK 0xffffffffffffULL
1290 #define ARLTBL_VID_S 48
1291 #define ARLTBL_VID_MASK_25 0xff
1292 @@ -316,13 +317,16 @@
1293 #define ARLTBL_VALID_25 BIT(63)
1294
1295 /* ARL Table Data Entry N Registers (32 bit) */
1296 -#define B53_ARLTBL_DATA_ENTRY(n) ((0x10 * (n)) + 0x08)
1297 +#define B53_ARLTBL_DATA_ENTRY(n) ((0x10 * (n)) + 0x18)
1298 #define ARLTBL_DATA_PORT_ID_MASK 0x1ff
1299 #define ARLTBL_TC(tc) ((3 & tc) << 11)
1300 #define ARLTBL_AGE BIT(14)
1301 #define ARLTBL_STATIC BIT(15)
1302 #define ARLTBL_VALID BIT(16)
1303
1304 +/* Maximum number of bin entries in the ARL for all switches */
1305 +#define B53_ARLTBL_MAX_BIN_ENTRIES 4
1306 +
1307 /* ARL Search Control Register (8 bit) */
1308 #define B53_ARL_SRCH_CTL 0x50
1309 #define B53_ARL_SRCH_CTL_25 0x20
1310 diff --git a/drivers/net/ethernet/broadcom/genet/bcmgenet.c b/drivers/net/ethernet/broadcom/genet/bcmgenet.c
1311 index 8f909d57501f..ff09ee777b2b 100644
1312 --- a/drivers/net/ethernet/broadcom/genet/bcmgenet.c
1313 +++ b/drivers/net/ethernet/broadcom/genet/bcmgenet.c
1314 @@ -995,6 +995,8 @@ static void bcmgenet_get_ethtool_stats(struct net_device *dev,
1315 if (netif_running(dev))
1316 bcmgenet_update_mib_counters(priv);
1317
1318 + dev->netdev_ops->ndo_get_stats(dev);
1319 +
1320 for (i = 0; i < BCMGENET_STATS_LEN; i++) {
1321 const struct bcmgenet_stats *s;
1322 char *p;
1323 @@ -3204,6 +3206,7 @@ static struct net_device_stats *bcmgenet_get_stats(struct net_device *dev)
1324 dev->stats.rx_packets = rx_packets;
1325 dev->stats.rx_errors = rx_errors;
1326 dev->stats.rx_missed_errors = rx_errors;
1327 + dev->stats.rx_dropped = rx_dropped;
1328 return &dev->stats;
1329 }
1330
1331 diff --git a/drivers/net/ethernet/chelsio/cxgb4/cudbg_lib.c b/drivers/net/ethernet/chelsio/cxgb4/cudbg_lib.c
1332 index c2e92786608b..7bcdce182ee5 100644
1333 --- a/drivers/net/ethernet/chelsio/cxgb4/cudbg_lib.c
1334 +++ b/drivers/net/ethernet/chelsio/cxgb4/cudbg_lib.c
1335 @@ -1054,9 +1054,9 @@ static void cudbg_t4_fwcache(struct cudbg_init *pdbg_init,
1336 }
1337 }
1338
1339 -static unsigned long cudbg_mem_region_size(struct cudbg_init *pdbg_init,
1340 - struct cudbg_error *cudbg_err,
1341 - u8 mem_type)
1342 +static int cudbg_mem_region_size(struct cudbg_init *pdbg_init,
1343 + struct cudbg_error *cudbg_err,
1344 + u8 mem_type, unsigned long *region_size)
1345 {
1346 struct adapter *padap = pdbg_init->adap;
1347 struct cudbg_meminfo mem_info;
1348 @@ -1065,15 +1065,23 @@ static unsigned long cudbg_mem_region_size(struct cudbg_init *pdbg_init,
1349
1350 memset(&mem_info, 0, sizeof(struct cudbg_meminfo));
1351 rc = cudbg_fill_meminfo(padap, &mem_info);
1352 - if (rc)
1353 + if (rc) {
1354 + cudbg_err->sys_err = rc;
1355 return rc;
1356 + }
1357
1358 cudbg_t4_fwcache(pdbg_init, cudbg_err);
1359 rc = cudbg_meminfo_get_mem_index(padap, &mem_info, mem_type, &mc_idx);
1360 - if (rc)
1361 + if (rc) {
1362 + cudbg_err->sys_err = rc;
1363 return rc;
1364 + }
1365 +
1366 + if (region_size)
1367 + *region_size = mem_info.avail[mc_idx].limit -
1368 + mem_info.avail[mc_idx].base;
1369
1370 - return mem_info.avail[mc_idx].limit - mem_info.avail[mc_idx].base;
1371 + return 0;
1372 }
1373
1374 static int cudbg_collect_mem_region(struct cudbg_init *pdbg_init,
1375 @@ -1081,7 +1089,12 @@ static int cudbg_collect_mem_region(struct cudbg_init *pdbg_init,
1376 struct cudbg_error *cudbg_err,
1377 u8 mem_type)
1378 {
1379 - unsigned long size = cudbg_mem_region_size(pdbg_init, cudbg_err, mem_type);
1380 + unsigned long size = 0;
1381 + int rc;
1382 +
1383 + rc = cudbg_mem_region_size(pdbg_init, cudbg_err, mem_type, &size);
1384 + if (rc)
1385 + return rc;
1386
1387 return cudbg_read_fw_mem(pdbg_init, dbg_buff, mem_type, size,
1388 cudbg_err);
1389 diff --git a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_ptp.c b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_ptp.c
1390 index af1f40cbccc8..f5bc996ac77d 100644
1391 --- a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_ptp.c
1392 +++ b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_ptp.c
1393 @@ -311,32 +311,17 @@ static int cxgb4_ptp_adjtime(struct ptp_clock_info *ptp, s64 delta)
1394 */
1395 static int cxgb4_ptp_gettime(struct ptp_clock_info *ptp, struct timespec64 *ts)
1396 {
1397 - struct adapter *adapter = (struct adapter *)container_of(ptp,
1398 - struct adapter, ptp_clock_info);
1399 - struct fw_ptp_cmd c;
1400 + struct adapter *adapter = container_of(ptp, struct adapter,
1401 + ptp_clock_info);
1402 u64 ns;
1403 - int err;
1404 -
1405 - memset(&c, 0, sizeof(c));
1406 - c.op_to_portid = cpu_to_be32(FW_CMD_OP_V(FW_PTP_CMD) |
1407 - FW_CMD_REQUEST_F |
1408 - FW_CMD_READ_F |
1409 - FW_PTP_CMD_PORTID_V(0));
1410 - c.retval_len16 = cpu_to_be32(FW_CMD_LEN16_V(sizeof(c) / 16));
1411 - c.u.ts.sc = FW_PTP_SC_GET_TIME;
1412
1413 - err = t4_wr_mbox(adapter, adapter->mbox, &c, sizeof(c), &c);
1414 - if (err < 0) {
1415 - dev_err(adapter->pdev_dev,
1416 - "PTP: %s error %d\n", __func__, -err);
1417 - return err;
1418 - }
1419 + ns = t4_read_reg(adapter, T5_PORT_REG(0, MAC_PORT_PTP_SUM_LO_A));
1420 + ns |= (u64)t4_read_reg(adapter,
1421 + T5_PORT_REG(0, MAC_PORT_PTP_SUM_HI_A)) << 32;
1422
1423 /* convert to timespec*/
1424 - ns = be64_to_cpu(c.u.ts.tm);
1425 *ts = ns_to_timespec64(ns);
1426 -
1427 - return err;
1428 + return 0;
1429 }
1430
1431 /**
1432 diff --git a/drivers/net/ethernet/chelsio/cxgb4/t4_regs.h b/drivers/net/ethernet/chelsio/cxgb4/t4_regs.h
1433 index a957a6e4d4c4..b0519c326692 100644
1434 --- a/drivers/net/ethernet/chelsio/cxgb4/t4_regs.h
1435 +++ b/drivers/net/ethernet/chelsio/cxgb4/t4_regs.h
1436 @@ -1900,6 +1900,9 @@
1437
1438 #define MAC_PORT_CFG2_A 0x818
1439
1440 +#define MAC_PORT_PTP_SUM_LO_A 0x990
1441 +#define MAC_PORT_PTP_SUM_HI_A 0x994
1442 +
1443 #define MPS_CMN_CTL_A 0x9000
1444
1445 #define COUNTPAUSEMCRX_S 5
1446 diff --git a/drivers/net/ethernet/mellanox/mlx4/en_tx.c b/drivers/net/ethernet/mellanox/mlx4/en_tx.c
1447 index 4d5ca302c067..a30edb436f4a 100644
1448 --- a/drivers/net/ethernet/mellanox/mlx4/en_tx.c
1449 +++ b/drivers/net/ethernet/mellanox/mlx4/en_tx.c
1450 @@ -43,6 +43,7 @@
1451 #include <linux/ip.h>
1452 #include <linux/ipv6.h>
1453 #include <linux/moduleparam.h>
1454 +#include <linux/indirect_call_wrapper.h>
1455
1456 #include "mlx4_en.h"
1457
1458 @@ -261,6 +262,10 @@ static void mlx4_en_stamp_wqe(struct mlx4_en_priv *priv,
1459 }
1460 }
1461
1462 +INDIRECT_CALLABLE_DECLARE(u32 mlx4_en_free_tx_desc(struct mlx4_en_priv *priv,
1463 + struct mlx4_en_tx_ring *ring,
1464 + int index, u64 timestamp,
1465 + int napi_mode));
1466
1467 u32 mlx4_en_free_tx_desc(struct mlx4_en_priv *priv,
1468 struct mlx4_en_tx_ring *ring,
1469 @@ -329,6 +334,11 @@ u32 mlx4_en_free_tx_desc(struct mlx4_en_priv *priv,
1470 return tx_info->nr_txbb;
1471 }
1472
1473 +INDIRECT_CALLABLE_DECLARE(u32 mlx4_en_recycle_tx_desc(struct mlx4_en_priv *priv,
1474 + struct mlx4_en_tx_ring *ring,
1475 + int index, u64 timestamp,
1476 + int napi_mode));
1477 +
1478 u32 mlx4_en_recycle_tx_desc(struct mlx4_en_priv *priv,
1479 struct mlx4_en_tx_ring *ring,
1480 int index, u64 timestamp,
1481 @@ -449,7 +459,9 @@ bool mlx4_en_process_tx_cq(struct net_device *dev,
1482 timestamp = mlx4_en_get_cqe_ts(cqe);
1483
1484 /* free next descriptor */
1485 - last_nr_txbb = ring->free_tx_desc(
1486 + last_nr_txbb = INDIRECT_CALL_2(ring->free_tx_desc,
1487 + mlx4_en_free_tx_desc,
1488 + mlx4_en_recycle_tx_desc,
1489 priv, ring, ring_index,
1490 timestamp, napi_budget);
1491
1492 diff --git a/drivers/net/ethernet/mellanox/mlxsw/core_acl_flex_actions.c b/drivers/net/ethernet/mellanox/mlxsw/core_acl_flex_actions.c
1493 index c51b2adfc1e1..2cbfa5cfefab 100644
1494 --- a/drivers/net/ethernet/mellanox/mlxsw/core_acl_flex_actions.c
1495 +++ b/drivers/net/ethernet/mellanox/mlxsw/core_acl_flex_actions.c
1496 @@ -316,7 +316,7 @@ struct mlxsw_afa_block *mlxsw_afa_block_create(struct mlxsw_afa *mlxsw_afa)
1497
1498 block = kzalloc(sizeof(*block), GFP_KERNEL);
1499 if (!block)
1500 - return NULL;
1501 + return ERR_PTR(-ENOMEM);
1502 INIT_LIST_HEAD(&block->resource_list);
1503 block->afa = mlxsw_afa;
1504
1505 @@ -344,7 +344,7 @@ err_second_set_create:
1506 mlxsw_afa_set_destroy(block->first_set);
1507 err_first_set_create:
1508 kfree(block);
1509 - return NULL;
1510 + return ERR_PTR(-ENOMEM);
1511 }
1512 EXPORT_SYMBOL(mlxsw_afa_block_create);
1513
1514 diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum2_acl_tcam.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum2_acl_tcam.c
1515 index 6c66a0f1b79e..ad69913f19c1 100644
1516 --- a/drivers/net/ethernet/mellanox/mlxsw/spectrum2_acl_tcam.c
1517 +++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum2_acl_tcam.c
1518 @@ -88,8 +88,8 @@ static int mlxsw_sp2_acl_tcam_init(struct mlxsw_sp *mlxsw_sp, void *priv,
1519 * to be written using PEFA register to all indexes for all regions.
1520 */
1521 afa_block = mlxsw_afa_block_create(mlxsw_sp->afa);
1522 - if (!afa_block) {
1523 - err = -ENOMEM;
1524 + if (IS_ERR(afa_block)) {
1525 + err = PTR_ERR(afa_block);
1526 goto err_afa_block;
1527 }
1528 err = mlxsw_afa_block_continue(afa_block);
1529 diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum_acl.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum_acl.c
1530 index 3d3cca596116..d77cdcb5c642 100644
1531 --- a/drivers/net/ethernet/mellanox/mlxsw/spectrum_acl.c
1532 +++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_acl.c
1533 @@ -444,7 +444,7 @@ mlxsw_sp_acl_rulei_create(struct mlxsw_sp_acl *acl,
1534
1535 rulei = kzalloc(sizeof(*rulei), GFP_KERNEL);
1536 if (!rulei)
1537 - return NULL;
1538 + return ERR_PTR(-ENOMEM);
1539
1540 if (afa_block) {
1541 rulei->act_block = afa_block;
1542 diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum_mr_tcam.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum_mr_tcam.c
1543 index 346f4a5fe053..221aa6a474eb 100644
1544 --- a/drivers/net/ethernet/mellanox/mlxsw/spectrum_mr_tcam.c
1545 +++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_mr_tcam.c
1546 @@ -199,8 +199,8 @@ mlxsw_sp_mr_tcam_afa_block_create(struct mlxsw_sp *mlxsw_sp,
1547 int err;
1548
1549 afa_block = mlxsw_afa_block_create(mlxsw_sp->afa);
1550 - if (!afa_block)
1551 - return ERR_PTR(-ENOMEM);
1552 + if (IS_ERR(afa_block))
1553 + return afa_block;
1554
1555 err = mlxsw_afa_block_append_allocated_counter(afa_block,
1556 counter_index);
1557 diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-meson8b.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-meson8b.c
1558 index 33ce139f090f..d1d6ba9cdccd 100644
1559 --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-meson8b.c
1560 +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-meson8b.c
1561 @@ -119,6 +119,7 @@ static int meson8b_init_rgmii_tx_clk(struct meson8b_dwmac *dwmac)
1562 { .div = 5, .val = 5, },
1563 { .div = 6, .val = 6, },
1564 { .div = 7, .val = 7, },
1565 + { /* end of array */ }
1566 };
1567
1568 clk_configs = devm_kzalloc(dev, sizeof(*clk_configs), GFP_KERNEL);
1569 diff --git a/drivers/net/geneve.c b/drivers/net/geneve.c
1570 index 730ab57201bd..aa101f72d405 100644
1571 --- a/drivers/net/geneve.c
1572 +++ b/drivers/net/geneve.c
1573 @@ -1207,7 +1207,7 @@ static int geneve_validate(struct nlattr *tb[], struct nlattr *data[],
1574 enum ifla_geneve_df df = nla_get_u8(data[IFLA_GENEVE_DF]);
1575
1576 if (df < 0 || df > GENEVE_DF_MAX) {
1577 - NL_SET_ERR_MSG_ATTR(extack, tb[IFLA_GENEVE_DF],
1578 + NL_SET_ERR_MSG_ATTR(extack, data[IFLA_GENEVE_DF],
1579 "Invalid DF attribute");
1580 return -EINVAL;
1581 }
1582 diff --git a/drivers/net/macsec.c b/drivers/net/macsec.c
1583 index 32c627702ac5..a0abc729f0ca 100644
1584 --- a/drivers/net/macsec.c
1585 +++ b/drivers/net/macsec.c
1586 @@ -3226,11 +3226,11 @@ static int macsec_newlink(struct net *net, struct net_device *dev,
1587 struct netlink_ext_ack *extack)
1588 {
1589 struct macsec_dev *macsec = macsec_priv(dev);
1590 + rx_handler_func_t *rx_handler;
1591 + u8 icv_len = DEFAULT_ICV_LEN;
1592 struct net_device *real_dev;
1593 - int err;
1594 + int err, mtu;
1595 sci_t sci;
1596 - u8 icv_len = DEFAULT_ICV_LEN;
1597 - rx_handler_func_t *rx_handler;
1598
1599 if (!tb[IFLA_LINK])
1600 return -EINVAL;
1601 @@ -3246,7 +3246,11 @@ static int macsec_newlink(struct net *net, struct net_device *dev,
1602
1603 if (data && data[IFLA_MACSEC_ICV_LEN])
1604 icv_len = nla_get_u8(data[IFLA_MACSEC_ICV_LEN]);
1605 - dev->mtu = real_dev->mtu - icv_len - macsec_extra_len(true);
1606 + mtu = real_dev->mtu - icv_len - macsec_extra_len(true);
1607 + if (mtu < 0)
1608 + dev->mtu = 0;
1609 + else
1610 + dev->mtu = mtu;
1611
1612 rx_handler = rtnl_dereference(real_dev->rx_handler);
1613 if (rx_handler && rx_handler != macsec_handle_frame)
1614 diff --git a/drivers/net/macvlan.c b/drivers/net/macvlan.c
1615 index 26f6be4796c7..0ce1004a8d0d 100644
1616 --- a/drivers/net/macvlan.c
1617 +++ b/drivers/net/macvlan.c
1618 @@ -1704,7 +1704,7 @@ static int macvlan_device_event(struct notifier_block *unused,
1619 struct macvlan_dev,
1620 list);
1621
1622 - if (macvlan_sync_address(vlan->dev, dev->dev_addr))
1623 + if (vlan && macvlan_sync_address(vlan->dev, dev->dev_addr))
1624 return NOTIFY_BAD;
1625
1626 break;
1627 diff --git a/drivers/net/team/team.c b/drivers/net/team/team.c
1628 index 4004f98e50d9..04845a4017f9 100644
1629 --- a/drivers/net/team/team.c
1630 +++ b/drivers/net/team/team.c
1631 @@ -468,6 +468,9 @@ static const struct team_mode *team_mode_get(const char *kind)
1632 struct team_mode_item *mitem;
1633 const struct team_mode *mode = NULL;
1634
1635 + if (!try_module_get(THIS_MODULE))
1636 + return NULL;
1637 +
1638 spin_lock(&mode_list_lock);
1639 mitem = __find_mode(kind);
1640 if (!mitem) {
1641 @@ -483,6 +486,7 @@ static const struct team_mode *team_mode_get(const char *kind)
1642 }
1643
1644 spin_unlock(&mode_list_lock);
1645 + module_put(THIS_MODULE);
1646 return mode;
1647 }
1648
1649 diff --git a/drivers/net/vrf.c b/drivers/net/vrf.c
1650 index b8228f50bc94..6716deeb35e3 100644
1651 --- a/drivers/net/vrf.c
1652 +++ b/drivers/net/vrf.c
1653 @@ -188,8 +188,8 @@ static netdev_tx_t vrf_process_v6_outbound(struct sk_buff *skb,
1654 fl6.flowi6_proto = iph->nexthdr;
1655 fl6.flowi6_flags = FLOWI_FLAG_SKIP_NH_OIF;
1656
1657 - dst = ip6_route_output(net, NULL, &fl6);
1658 - if (dst == dst_null)
1659 + dst = ip6_dst_lookup_flow(net, NULL, &fl6, NULL);
1660 + if (IS_ERR(dst) || dst == dst_null)
1661 goto err;
1662
1663 skb_dst_drop(skb);
1664 @@ -474,7 +474,8 @@ static struct sk_buff *vrf_ip6_out(struct net_device *vrf_dev,
1665 if (rt6_need_strict(&ipv6_hdr(skb)->daddr))
1666 return skb;
1667
1668 - if (qdisc_tx_is_default(vrf_dev))
1669 + if (qdisc_tx_is_default(vrf_dev) ||
1670 + IP6CB(skb)->flags & IP6SKB_XFRM_TRANSFORMED)
1671 return vrf_ip6_out_direct(vrf_dev, sk, skb);
1672
1673 return vrf_ip6_out_redirect(vrf_dev, skb);
1674 @@ -686,7 +687,8 @@ static struct sk_buff *vrf_ip_out(struct net_device *vrf_dev,
1675 ipv4_is_lbcast(ip_hdr(skb)->daddr))
1676 return skb;
1677
1678 - if (qdisc_tx_is_default(vrf_dev))
1679 + if (qdisc_tx_is_default(vrf_dev) ||
1680 + IPCB(skb)->flags & IPSKB_XFRM_TRANSFORMED)
1681 return vrf_ip_out_direct(vrf_dev, sk, skb);
1682
1683 return vrf_ip_out_redirect(vrf_dev, skb);
1684 diff --git a/drivers/net/vxlan.c b/drivers/net/vxlan.c
1685 index 93690f77ec9c..ae59fca96032 100644
1686 --- a/drivers/net/vxlan.c
1687 +++ b/drivers/net/vxlan.c
1688 @@ -3144,7 +3144,7 @@ static int vxlan_validate(struct nlattr *tb[], struct nlattr *data[],
1689 u32 id = nla_get_u32(data[IFLA_VXLAN_ID]);
1690
1691 if (id >= VXLAN_N_VID) {
1692 - NL_SET_ERR_MSG_ATTR(extack, tb[IFLA_VXLAN_ID],
1693 + NL_SET_ERR_MSG_ATTR(extack, data[IFLA_VXLAN_ID],
1694 "VXLAN ID must be lower than 16777216");
1695 return -ERANGE;
1696 }
1697 @@ -3155,7 +3155,7 @@ static int vxlan_validate(struct nlattr *tb[], struct nlattr *data[],
1698 = nla_data(data[IFLA_VXLAN_PORT_RANGE]);
1699
1700 if (ntohs(p->high) < ntohs(p->low)) {
1701 - NL_SET_ERR_MSG_ATTR(extack, tb[IFLA_VXLAN_PORT_RANGE],
1702 + NL_SET_ERR_MSG_ATTR(extack, data[IFLA_VXLAN_PORT_RANGE],
1703 "Invalid source port range");
1704 return -EINVAL;
1705 }
1706 @@ -3165,7 +3165,7 @@ static int vxlan_validate(struct nlattr *tb[], struct nlattr *data[],
1707 enum ifla_vxlan_df df = nla_get_u8(data[IFLA_VXLAN_DF]);
1708
1709 if (df < 0 || df > VXLAN_DF_MAX) {
1710 - NL_SET_ERR_MSG_ATTR(extack, tb[IFLA_VXLAN_DF],
1711 + NL_SET_ERR_MSG_ATTR(extack, data[IFLA_VXLAN_DF],
1712 "Invalid DF attribute");
1713 return -EINVAL;
1714 }
1715 diff --git a/drivers/net/wireless/intel/iwlegacy/3945-rs.c b/drivers/net/wireless/intel/iwlegacy/3945-rs.c
1716 index 6209f85a71dd..0af9e997c9f6 100644
1717 --- a/drivers/net/wireless/intel/iwlegacy/3945-rs.c
1718 +++ b/drivers/net/wireless/intel/iwlegacy/3945-rs.c
1719 @@ -374,7 +374,7 @@ out:
1720 }
1721
1722 static void *
1723 -il3945_rs_alloc(struct ieee80211_hw *hw, struct dentry *debugfsdir)
1724 +il3945_rs_alloc(struct ieee80211_hw *hw)
1725 {
1726 return hw->priv;
1727 }
1728 diff --git a/drivers/net/wireless/intel/iwlegacy/4965-rs.c b/drivers/net/wireless/intel/iwlegacy/4965-rs.c
1729 index 7c6e2c863497..0a02d8aca320 100644
1730 --- a/drivers/net/wireless/intel/iwlegacy/4965-rs.c
1731 +++ b/drivers/net/wireless/intel/iwlegacy/4965-rs.c
1732 @@ -2474,7 +2474,7 @@ il4965_rs_fill_link_cmd(struct il_priv *il, struct il_lq_sta *lq_sta,
1733 }
1734
1735 static void *
1736 -il4965_rs_alloc(struct ieee80211_hw *hw, struct dentry *debugfsdir)
1737 +il4965_rs_alloc(struct ieee80211_hw *hw)
1738 {
1739 return hw->priv;
1740 }
1741 diff --git a/drivers/net/wireless/intel/iwlwifi/dvm/rs.c b/drivers/net/wireless/intel/iwlwifi/dvm/rs.c
1742 index 74229fcb63a9..e68a13c33c45 100644
1743 --- a/drivers/net/wireless/intel/iwlwifi/dvm/rs.c
1744 +++ b/drivers/net/wireless/intel/iwlwifi/dvm/rs.c
1745 @@ -3019,7 +3019,7 @@ static void rs_fill_link_cmd(struct iwl_priv *priv,
1746 cpu_to_le16(priv->lib->bt_params->agg_time_limit);
1747 }
1748
1749 -static void *rs_alloc(struct ieee80211_hw *hw, struct dentry *debugfsdir)
1750 +static void *rs_alloc(struct ieee80211_hw *hw)
1751 {
1752 return hw->priv;
1753 }
1754 diff --git a/drivers/net/wireless/intel/iwlwifi/fw/api/txq.h b/drivers/net/wireless/intel/iwlwifi/fw/api/txq.h
1755 index 73196cbc7fbe..75d958bab0e3 100644
1756 --- a/drivers/net/wireless/intel/iwlwifi/fw/api/txq.h
1757 +++ b/drivers/net/wireless/intel/iwlwifi/fw/api/txq.h
1758 @@ -8,7 +8,7 @@
1759 * Copyright(c) 2007 - 2014 Intel Corporation. All rights reserved.
1760 * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
1761 * Copyright(c) 2016 - 2017 Intel Deutschland GmbH
1762 - * Copyright(c) 2019 Intel Corporation
1763 + * Copyright(c) 2019 - 2020 Intel Corporation
1764 *
1765 * This program is free software; you can redistribute it and/or modify
1766 * it under the terms of version 2 of the GNU General Public License as
1767 @@ -31,7 +31,7 @@
1768 * Copyright(c) 2005 - 2014 Intel Corporation. All rights reserved.
1769 * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
1770 * Copyright(c) 2016 - 2017 Intel Deutschland GmbH
1771 - * Copyright(c) 2019 Intel Corporation
1772 + * Copyright(c) 2019 - 2020 Intel Corporation
1773 * All rights reserved.
1774 *
1775 * Redistribution and use in source and binary forms, with or without
1776 @@ -99,7 +99,7 @@ enum iwl_mvm_dqa_txq {
1777 IWL_MVM_DQA_MAX_MGMT_QUEUE = 8,
1778 IWL_MVM_DQA_AP_PROBE_RESP_QUEUE = 9,
1779 IWL_MVM_DQA_MIN_DATA_QUEUE = 10,
1780 - IWL_MVM_DQA_MAX_DATA_QUEUE = 31,
1781 + IWL_MVM_DQA_MAX_DATA_QUEUE = 30,
1782 };
1783
1784 enum iwl_mvm_tx_fifo {
1785 diff --git a/drivers/net/wireless/intel/iwlwifi/iwl-nvm-parse.c b/drivers/net/wireless/intel/iwlwifi/iwl-nvm-parse.c
1786 index 5d546dac7814..022f2faccab4 100644
1787 --- a/drivers/net/wireless/intel/iwlwifi/iwl-nvm-parse.c
1788 +++ b/drivers/net/wireless/intel/iwlwifi/iwl-nvm-parse.c
1789 @@ -525,8 +525,7 @@ static struct ieee80211_sband_iftype_data iwl_he_capa[] = {
1790 IEEE80211_HE_MAC_CAP1_TF_MAC_PAD_DUR_16US |
1791 IEEE80211_HE_MAC_CAP1_MULTI_TID_AGG_RX_QOS_8,
1792 .mac_cap_info[2] =
1793 - IEEE80211_HE_MAC_CAP2_32BIT_BA_BITMAP |
1794 - IEEE80211_HE_MAC_CAP2_ACK_EN,
1795 + IEEE80211_HE_MAC_CAP2_32BIT_BA_BITMAP,
1796 .mac_cap_info[3] =
1797 IEEE80211_HE_MAC_CAP3_OMI_CONTROL |
1798 IEEE80211_HE_MAC_CAP3_MAX_AMPDU_LEN_EXP_VHT_2,
1799 @@ -610,8 +609,7 @@ static struct ieee80211_sband_iftype_data iwl_he_capa[] = {
1800 IEEE80211_HE_MAC_CAP1_TF_MAC_PAD_DUR_16US |
1801 IEEE80211_HE_MAC_CAP1_MULTI_TID_AGG_RX_QOS_8,
1802 .mac_cap_info[2] =
1803 - IEEE80211_HE_MAC_CAP2_BSR |
1804 - IEEE80211_HE_MAC_CAP2_ACK_EN,
1805 + IEEE80211_HE_MAC_CAP2_BSR,
1806 .mac_cap_info[3] =
1807 IEEE80211_HE_MAC_CAP3_OMI_CONTROL |
1808 IEEE80211_HE_MAC_CAP3_MAX_AMPDU_LEN_EXP_VHT_2,
1809 diff --git a/drivers/net/wireless/intel/iwlwifi/mvm/rs.c b/drivers/net/wireless/intel/iwlwifi/mvm/rs.c
1810 index 42d525e46e80..9af657820b38 100644
1811 --- a/drivers/net/wireless/intel/iwlwifi/mvm/rs.c
1812 +++ b/drivers/net/wireless/intel/iwlwifi/mvm/rs.c
1813 @@ -3663,7 +3663,7 @@ static void rs_fill_lq_cmd(struct iwl_mvm *mvm,
1814 cpu_to_le16(iwl_mvm_coex_agg_time_limit(mvm, sta));
1815 }
1816
1817 -static void *rs_alloc(struct ieee80211_hw *hw, struct dentry *debugfsdir)
1818 +static void *rs_alloc(struct ieee80211_hw *hw)
1819 {
1820 return hw->priv;
1821 }
1822 diff --git a/drivers/net/wireless/intel/iwlwifi/mvm/rx.c b/drivers/net/wireless/intel/iwlwifi/mvm/rx.c
1823 index 5ee33c8ae9d2..77b8def26edb 100644
1824 --- a/drivers/net/wireless/intel/iwlwifi/mvm/rx.c
1825 +++ b/drivers/net/wireless/intel/iwlwifi/mvm/rx.c
1826 @@ -8,7 +8,7 @@
1827 * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
1828 * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
1829 * Copyright(c) 2016 - 2017 Intel Deutschland GmbH
1830 - * Copyright(c) 2018 - 2019 Intel Corporation
1831 + * Copyright(c) 2018 - 2020 Intel Corporation
1832 *
1833 * This program is free software; you can redistribute it and/or modify
1834 * it under the terms of version 2 of the GNU General Public License as
1835 @@ -31,7 +31,7 @@
1836 * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
1837 * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
1838 * Copyright(c) 2016 - 2017 Intel Deutschland GmbH
1839 - * Copyright(c) 2018 - 2019 Intel Corporation
1840 + * Copyright(c) 2018 - 2020 Intel Corporation
1841 * All rights reserved.
1842 *
1843 * Redistribution and use in source and binary forms, with or without
1844 @@ -566,6 +566,7 @@ void iwl_mvm_rx_rx_mpdu(struct iwl_mvm *mvm, struct napi_struct *napi,
1845
1846 struct iwl_mvm_stat_data {
1847 struct iwl_mvm *mvm;
1848 + __le32 flags;
1849 __le32 mac_id;
1850 u8 beacon_filter_average_energy;
1851 void *general;
1852 @@ -606,6 +607,13 @@ static void iwl_mvm_stat_iterator(void *_data, u8 *mac,
1853 -general->beacon_average_energy[vif_id];
1854 }
1855
1856 + /* make sure that beacon statistics don't go backwards with TCM
1857 + * request to clear statistics
1858 + */
1859 + if (le32_to_cpu(data->flags) & IWL_STATISTICS_REPLY_FLG_CLEAR)
1860 + mvmvif->beacon_stats.accu_num_beacons +=
1861 + mvmvif->beacon_stats.num_beacons;
1862 +
1863 if (mvmvif->id != id)
1864 return;
1865
1866 @@ -763,6 +771,7 @@ void iwl_mvm_handle_rx_statistics(struct iwl_mvm *mvm,
1867
1868 flags = stats->flag;
1869 }
1870 + data.flags = flags;
1871
1872 iwl_mvm_rx_stats_check_trigger(mvm, pkt);
1873
1874 diff --git a/drivers/net/wireless/intel/iwlwifi/mvm/sta.c b/drivers/net/wireless/intel/iwlwifi/mvm/sta.c
1875 index 8ad2d889179c..71d339e90a9e 100644
1876 --- a/drivers/net/wireless/intel/iwlwifi/mvm/sta.c
1877 +++ b/drivers/net/wireless/intel/iwlwifi/mvm/sta.c
1878 @@ -722,6 +722,11 @@ static int iwl_mvm_find_free_queue(struct iwl_mvm *mvm, u8 sta_id,
1879
1880 lockdep_assert_held(&mvm->mutex);
1881
1882 + if (WARN(maxq >= mvm->trans->trans_cfg->base_params->num_of_queues,
1883 + "max queue %d >= num_of_queues (%d)", maxq,
1884 + mvm->trans->trans_cfg->base_params->num_of_queues))
1885 + maxq = mvm->trans->trans_cfg->base_params->num_of_queues - 1;
1886 +
1887 /* This should not be hit with new TX path */
1888 if (WARN_ON(iwl_mvm_has_new_tx_api(mvm)))
1889 return -ENOSPC;
1890 @@ -1164,9 +1169,9 @@ static int iwl_mvm_inactivity_check(struct iwl_mvm *mvm, u8 alloc_for_sta)
1891 inactive_tid_bitmap,
1892 &unshare_queues,
1893 &changetid_queues);
1894 - if (ret >= 0 && free_queue < 0) {
1895 + if (ret && free_queue < 0) {
1896 queue_owner = sta;
1897 - free_queue = ret;
1898 + free_queue = i;
1899 }
1900 /* only unlock sta lock - we still need the queue info lock */
1901 spin_unlock_bh(&mvmsta->lock);
1902 diff --git a/drivers/net/wireless/intel/iwlwifi/pcie/tx-gen2.c b/drivers/net/wireless/intel/iwlwifi/pcie/tx-gen2.c
1903 index ff4c34d7b74f..248d42bf00c1 100644
1904 --- a/drivers/net/wireless/intel/iwlwifi/pcie/tx-gen2.c
1905 +++ b/drivers/net/wireless/intel/iwlwifi/pcie/tx-gen2.c
1906 @@ -1283,6 +1283,9 @@ void iwl_trans_pcie_dyn_txq_free(struct iwl_trans *trans, int queue)
1907
1908 iwl_pcie_gen2_txq_unmap(trans, queue);
1909
1910 + iwl_pcie_gen2_txq_free_memory(trans, trans_pcie->txq[queue]);
1911 + trans_pcie->txq[queue] = NULL;
1912 +
1913 IWL_DEBUG_TX_QUEUES(trans, "Deactivate queue %d\n", queue);
1914 }
1915
1916 diff --git a/drivers/net/wireless/realtek/rtlwifi/rc.c b/drivers/net/wireless/realtek/rtlwifi/rc.c
1917 index 0c7d74902d33..4b5ea0ec9109 100644
1918 --- a/drivers/net/wireless/realtek/rtlwifi/rc.c
1919 +++ b/drivers/net/wireless/realtek/rtlwifi/rc.c
1920 @@ -261,7 +261,7 @@ static void rtl_rate_update(void *ppriv,
1921 {
1922 }
1923
1924 -static void *rtl_rate_alloc(struct ieee80211_hw *hw, struct dentry *debugfsdir)
1925 +static void *rtl_rate_alloc(struct ieee80211_hw *hw)
1926 {
1927 struct rtl_priv *rtlpriv = rtl_priv(hw);
1928 return rtlpriv;
1929 diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
1930 index b8fe42f4b3c5..f97c48fd3eda 100644
1931 --- a/drivers/nvme/host/core.c
1932 +++ b/drivers/nvme/host/core.c
1933 @@ -6,6 +6,7 @@
1934
1935 #include <linux/blkdev.h>
1936 #include <linux/blk-mq.h>
1937 +#include <linux/compat.h>
1938 #include <linux/delay.h>
1939 #include <linux/errno.h>
1940 #include <linux/hdreg.h>
1941 @@ -1244,6 +1245,18 @@ static void nvme_enable_aen(struct nvme_ctrl *ctrl)
1942 queue_work(nvme_wq, &ctrl->async_event_work);
1943 }
1944
1945 +/*
1946 + * Convert integer values from ioctl structures to user pointers, silently
1947 + * ignoring the upper bits in the compat case to match behaviour of 32-bit
1948 + * kernels.
1949 + */
1950 +static void __user *nvme_to_user_ptr(uintptr_t ptrval)
1951 +{
1952 + if (in_compat_syscall())
1953 + ptrval = (compat_uptr_t)ptrval;
1954 + return (void __user *)ptrval;
1955 +}
1956 +
1957 static int nvme_submit_io(struct nvme_ns *ns, struct nvme_user_io __user *uio)
1958 {
1959 struct nvme_user_io io;
1960 @@ -1267,7 +1280,7 @@ static int nvme_submit_io(struct nvme_ns *ns, struct nvme_user_io __user *uio)
1961
1962 length = (io.nblocks + 1) << ns->lba_shift;
1963 meta_len = (io.nblocks + 1) * ns->ms;
1964 - metadata = (void __user *)(uintptr_t)io.metadata;
1965 + metadata = nvme_to_user_ptr(io.metadata);
1966
1967 if (ns->ext) {
1968 length += meta_len;
1969 @@ -1290,7 +1303,7 @@ static int nvme_submit_io(struct nvme_ns *ns, struct nvme_user_io __user *uio)
1970 c.rw.appmask = cpu_to_le16(io.appmask);
1971
1972 return nvme_submit_user_cmd(ns->queue, &c,
1973 - (void __user *)(uintptr_t)io.addr, length,
1974 + nvme_to_user_ptr(io.addr), length,
1975 metadata, meta_len, lower_32_bits(io.slba), NULL, 0);
1976 }
1977
1978 @@ -1410,9 +1423,9 @@ static int nvme_user_cmd(struct nvme_ctrl *ctrl, struct nvme_ns *ns,
1979
1980 effects = nvme_passthru_start(ctrl, ns, cmd.opcode);
1981 status = nvme_submit_user_cmd(ns ? ns->queue : ctrl->admin_q, &c,
1982 - (void __user *)(uintptr_t)cmd.addr, cmd.data_len,
1983 - (void __user *)(uintptr_t)cmd.metadata,
1984 - cmd.metadata_len, 0, &result, timeout);
1985 + nvme_to_user_ptr(cmd.addr), cmd.data_len,
1986 + nvme_to_user_ptr(cmd.metadata), cmd.metadata_len,
1987 + 0, &result, timeout);
1988 nvme_passthru_end(ctrl, effects);
1989
1990 if (status >= 0) {
1991 @@ -1457,8 +1470,8 @@ static int nvme_user_cmd64(struct nvme_ctrl *ctrl, struct nvme_ns *ns,
1992
1993 effects = nvme_passthru_start(ctrl, ns, cmd.opcode);
1994 status = nvme_submit_user_cmd(ns ? ns->queue : ctrl->admin_q, &c,
1995 - (void __user *)(uintptr_t)cmd.addr, cmd.data_len,
1996 - (void __user *)(uintptr_t)cmd.metadata, cmd.metadata_len,
1997 + nvme_to_user_ptr(cmd.addr), cmd.data_len,
1998 + nvme_to_user_ptr(cmd.metadata), cmd.metadata_len,
1999 0, &cmd.result, timeout);
2000 nvme_passthru_end(ctrl, effects);
2001
2002 diff --git a/drivers/nvme/host/multipath.c b/drivers/nvme/host/multipath.c
2003 index aed6354cb271..56caddeabb5e 100644
2004 --- a/drivers/nvme/host/multipath.c
2005 +++ b/drivers/nvme/host/multipath.c
2006 @@ -510,7 +510,7 @@ static int nvme_update_ana_state(struct nvme_ctrl *ctrl,
2007 if (!nr_nsids)
2008 return 0;
2009
2010 - down_write(&ctrl->namespaces_rwsem);
2011 + down_read(&ctrl->namespaces_rwsem);
2012 list_for_each_entry(ns, &ctrl->namespaces, list) {
2013 unsigned nsid = le32_to_cpu(desc->nsids[n]);
2014
2015 @@ -521,7 +521,7 @@ static int nvme_update_ana_state(struct nvme_ctrl *ctrl,
2016 if (++n == nr_nsids)
2017 break;
2018 }
2019 - up_write(&ctrl->namespaces_rwsem);
2020 + up_read(&ctrl->namespaces_rwsem);
2021 return 0;
2022 }
2023
2024 diff --git a/drivers/nvme/host/tcp.c b/drivers/nvme/host/tcp.c
2025 index 244984420b41..11e84ed4de36 100644
2026 --- a/drivers/nvme/host/tcp.c
2027 +++ b/drivers/nvme/host/tcp.c
2028 @@ -164,16 +164,14 @@ static inline bool nvme_tcp_async_req(struct nvme_tcp_request *req)
2029 static inline bool nvme_tcp_has_inline_data(struct nvme_tcp_request *req)
2030 {
2031 struct request *rq;
2032 - unsigned int bytes;
2033
2034 if (unlikely(nvme_tcp_async_req(req)))
2035 return false; /* async events don't have a request */
2036
2037 rq = blk_mq_rq_from_pdu(req);
2038 - bytes = blk_rq_payload_bytes(rq);
2039
2040 - return rq_data_dir(rq) == WRITE && bytes &&
2041 - bytes <= nvme_tcp_inline_data_size(req->queue);
2042 + return rq_data_dir(rq) == WRITE && req->data_len &&
2043 + req->data_len <= nvme_tcp_inline_data_size(req->queue);
2044 }
2045
2046 static inline struct page *nvme_tcp_req_cur_page(struct nvme_tcp_request *req)
2047 @@ -2090,7 +2088,9 @@ static blk_status_t nvme_tcp_map_data(struct nvme_tcp_queue *queue,
2048
2049 c->common.flags |= NVME_CMD_SGL_METABUF;
2050
2051 - if (rq_data_dir(rq) == WRITE && req->data_len &&
2052 + if (!blk_rq_nr_phys_segments(rq))
2053 + nvme_tcp_set_sg_null(c);
2054 + else if (rq_data_dir(rq) == WRITE &&
2055 req->data_len <= nvme_tcp_inline_data_size(queue))
2056 nvme_tcp_set_sg_inline(queue, c, req->data_len);
2057 else
2058 @@ -2117,7 +2117,8 @@ static blk_status_t nvme_tcp_setup_cmd_pdu(struct nvme_ns *ns,
2059 req->data_sent = 0;
2060 req->pdu_len = 0;
2061 req->pdu_sent = 0;
2062 - req->data_len = blk_rq_payload_bytes(rq);
2063 + req->data_len = blk_rq_nr_phys_segments(rq) ?
2064 + blk_rq_payload_bytes(rq) : 0;
2065 req->curr_bio = rq->bio;
2066
2067 if (rq_data_dir(rq) == WRITE &&
2068 diff --git a/drivers/pci/hotplug/pciehp.h b/drivers/pci/hotplug/pciehp.h
2069 index 882ce82c4699..aa61d4c219d7 100644
2070 --- a/drivers/pci/hotplug/pciehp.h
2071 +++ b/drivers/pci/hotplug/pciehp.h
2072 @@ -174,10 +174,10 @@ void pciehp_set_indicators(struct controller *ctrl, int pwr, int attn);
2073
2074 void pciehp_get_latch_status(struct controller *ctrl, u8 *status);
2075 int pciehp_query_power_fault(struct controller *ctrl);
2076 -bool pciehp_card_present(struct controller *ctrl);
2077 -bool pciehp_card_present_or_link_active(struct controller *ctrl);
2078 +int pciehp_card_present(struct controller *ctrl);
2079 +int pciehp_card_present_or_link_active(struct controller *ctrl);
2080 int pciehp_check_link_status(struct controller *ctrl);
2081 -bool pciehp_check_link_active(struct controller *ctrl);
2082 +int pciehp_check_link_active(struct controller *ctrl);
2083 void pciehp_release_ctrl(struct controller *ctrl);
2084
2085 int pciehp_sysfs_enable_slot(struct hotplug_slot *hotplug_slot);
2086 diff --git a/drivers/pci/hotplug/pciehp_core.c b/drivers/pci/hotplug/pciehp_core.c
2087 index 56daad828c9e..312cc45c44c7 100644
2088 --- a/drivers/pci/hotplug/pciehp_core.c
2089 +++ b/drivers/pci/hotplug/pciehp_core.c
2090 @@ -139,10 +139,15 @@ static int get_adapter_status(struct hotplug_slot *hotplug_slot, u8 *value)
2091 {
2092 struct controller *ctrl = to_ctrl(hotplug_slot);
2093 struct pci_dev *pdev = ctrl->pcie->port;
2094 + int ret;
2095
2096 pci_config_pm_runtime_get(pdev);
2097 - *value = pciehp_card_present_or_link_active(ctrl);
2098 + ret = pciehp_card_present_or_link_active(ctrl);
2099 pci_config_pm_runtime_put(pdev);
2100 + if (ret < 0)
2101 + return ret;
2102 +
2103 + *value = ret;
2104 return 0;
2105 }
2106
2107 @@ -158,13 +163,13 @@ static int get_adapter_status(struct hotplug_slot *hotplug_slot, u8 *value)
2108 */
2109 static void pciehp_check_presence(struct controller *ctrl)
2110 {
2111 - bool occupied;
2112 + int occupied;
2113
2114 down_read(&ctrl->reset_lock);
2115 mutex_lock(&ctrl->state_lock);
2116
2117 occupied = pciehp_card_present_or_link_active(ctrl);
2118 - if ((occupied && (ctrl->state == OFF_STATE ||
2119 + if ((occupied > 0 && (ctrl->state == OFF_STATE ||
2120 ctrl->state == BLINKINGON_STATE)) ||
2121 (!occupied && (ctrl->state == ON_STATE ||
2122 ctrl->state == BLINKINGOFF_STATE)))
2123 diff --git a/drivers/pci/hotplug/pciehp_ctrl.c b/drivers/pci/hotplug/pciehp_ctrl.c
2124 index dd8e4a5fb282..6503d15effbb 100644
2125 --- a/drivers/pci/hotplug/pciehp_ctrl.c
2126 +++ b/drivers/pci/hotplug/pciehp_ctrl.c
2127 @@ -226,7 +226,7 @@ void pciehp_handle_disable_request(struct controller *ctrl)
2128
2129 void pciehp_handle_presence_or_link_change(struct controller *ctrl, u32 events)
2130 {
2131 - bool present, link_active;
2132 + int present, link_active;
2133
2134 /*
2135 * If the slot is on and presence or link has changed, turn it off.
2136 @@ -257,7 +257,7 @@ void pciehp_handle_presence_or_link_change(struct controller *ctrl, u32 events)
2137 mutex_lock(&ctrl->state_lock);
2138 present = pciehp_card_present(ctrl);
2139 link_active = pciehp_check_link_active(ctrl);
2140 - if (!present && !link_active) {
2141 + if (present <= 0 && link_active <= 0) {
2142 mutex_unlock(&ctrl->state_lock);
2143 return;
2144 }
2145 diff --git a/drivers/pci/hotplug/pciehp_hpc.c b/drivers/pci/hotplug/pciehp_hpc.c
2146 index d74a71712cde..356786a3b7f4 100644
2147 --- a/drivers/pci/hotplug/pciehp_hpc.c
2148 +++ b/drivers/pci/hotplug/pciehp_hpc.c
2149 @@ -201,17 +201,29 @@ static void pcie_write_cmd_nowait(struct controller *ctrl, u16 cmd, u16 mask)
2150 pcie_do_write_cmd(ctrl, cmd, mask, false);
2151 }
2152
2153 -bool pciehp_check_link_active(struct controller *ctrl)
2154 +/**
2155 + * pciehp_check_link_active() - Is the link active
2156 + * @ctrl: PCIe hotplug controller
2157 + *
2158 + * Check whether the downstream link is currently active. Note it is
2159 + * possible that the card is removed immediately after this so the
2160 + * caller may need to take it into account.
2161 + *
2162 + * If the hotplug controller itself is not available anymore returns
2163 + * %-ENODEV.
2164 + */
2165 +int pciehp_check_link_active(struct controller *ctrl)
2166 {
2167 struct pci_dev *pdev = ctrl_dev(ctrl);
2168 u16 lnk_status;
2169 - bool ret;
2170 + int ret;
2171
2172 - pcie_capability_read_word(pdev, PCI_EXP_LNKSTA, &lnk_status);
2173 - ret = !!(lnk_status & PCI_EXP_LNKSTA_DLLLA);
2174 + ret = pcie_capability_read_word(pdev, PCI_EXP_LNKSTA, &lnk_status);
2175 + if (ret == PCIBIOS_DEVICE_NOT_FOUND || lnk_status == (u16)~0)
2176 + return -ENODEV;
2177
2178 - if (ret)
2179 - ctrl_dbg(ctrl, "%s: lnk_status = %x\n", __func__, lnk_status);
2180 + ret = !!(lnk_status & PCI_EXP_LNKSTA_DLLLA);
2181 + ctrl_dbg(ctrl, "%s: lnk_status = %x\n", __func__, lnk_status);
2182
2183 return ret;
2184 }
2185 @@ -373,13 +385,29 @@ void pciehp_get_latch_status(struct controller *ctrl, u8 *status)
2186 *status = !!(slot_status & PCI_EXP_SLTSTA_MRLSS);
2187 }
2188
2189 -bool pciehp_card_present(struct controller *ctrl)
2190 +/**
2191 + * pciehp_card_present() - Is the card present
2192 + * @ctrl: PCIe hotplug controller
2193 + *
2194 + * Function checks whether the card is currently present in the slot and
2195 + * in that case returns true. Note it is possible that the card is
2196 + * removed immediately after the check so the caller may need to take
2197 + * this into account.
2198 + *
2199 + * It the hotplug controller itself is not available anymore returns
2200 + * %-ENODEV.
2201 + */
2202 +int pciehp_card_present(struct controller *ctrl)
2203 {
2204 struct pci_dev *pdev = ctrl_dev(ctrl);
2205 u16 slot_status;
2206 + int ret;
2207
2208 - pcie_capability_read_word(pdev, PCI_EXP_SLTSTA, &slot_status);
2209 - return slot_status & PCI_EXP_SLTSTA_PDS;
2210 + ret = pcie_capability_read_word(pdev, PCI_EXP_SLTSTA, &slot_status);
2211 + if (ret == PCIBIOS_DEVICE_NOT_FOUND || slot_status == (u16)~0)
2212 + return -ENODEV;
2213 +
2214 + return !!(slot_status & PCI_EXP_SLTSTA_PDS);
2215 }
2216
2217 /**
2218 @@ -390,10 +418,19 @@ bool pciehp_card_present(struct controller *ctrl)
2219 * Presence Detect State bit, this helper also returns true if the Link Active
2220 * bit is set. This is a concession to broken hotplug ports which hardwire
2221 * Presence Detect State to zero, such as Wilocity's [1ae9:0200].
2222 + *
2223 + * Returns: %1 if the slot is occupied and %0 if it is not. If the hotplug
2224 + * port is not present anymore returns %-ENODEV.
2225 */
2226 -bool pciehp_card_present_or_link_active(struct controller *ctrl)
2227 +int pciehp_card_present_or_link_active(struct controller *ctrl)
2228 {
2229 - return pciehp_card_present(ctrl) || pciehp_check_link_active(ctrl);
2230 + int ret;
2231 +
2232 + ret = pciehp_card_present(ctrl);
2233 + if (ret)
2234 + return ret;
2235 +
2236 + return pciehp_check_link_active(ctrl);
2237 }
2238
2239 int pciehp_query_power_fault(struct controller *ctrl)
2240 diff --git a/drivers/pci/pci-driver.c b/drivers/pci/pci-driver.c
2241 index 0c3086793e4e..5ea612a15550 100644
2242 --- a/drivers/pci/pci-driver.c
2243 +++ b/drivers/pci/pci-driver.c
2244 @@ -919,6 +919,8 @@ static int pci_pm_resume_noirq(struct device *dev)
2245 struct pci_dev *pci_dev = to_pci_dev(dev);
2246 struct device_driver *drv = dev->driver;
2247 int error = 0;
2248 + pci_power_t prev_state = pci_dev->current_state;
2249 + bool skip_bus_pm = pci_dev->skip_bus_pm;
2250
2251 if (dev_pm_may_skip_resume(dev))
2252 return 0;
2253 @@ -937,12 +939,15 @@ static int pci_pm_resume_noirq(struct device *dev)
2254 * configuration here and attempting to put them into D0 again is
2255 * pointless, so avoid doing that.
2256 */
2257 - if (!(pci_dev->skip_bus_pm && pm_suspend_no_platform()))
2258 + if (!(skip_bus_pm && pm_suspend_no_platform()))
2259 pci_pm_default_resume_early(pci_dev);
2260
2261 pci_fixup_device(pci_fixup_resume_early, pci_dev);
2262 pcie_pme_root_status_cleanup(pci_dev);
2263
2264 + if (!skip_bus_pm && prev_state == PCI_D3cold)
2265 + pci_bridge_wait_for_secondary_bus(pci_dev);
2266 +
2267 if (pci_has_legacy_pm_support(pci_dev))
2268 return pci_legacy_resume_early(dev);
2269
2270 @@ -1333,6 +1338,7 @@ static int pci_pm_runtime_resume(struct device *dev)
2271 int rc = 0;
2272 struct pci_dev *pci_dev = to_pci_dev(dev);
2273 const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
2274 + pci_power_t prev_state = pci_dev->current_state;
2275
2276 /*
2277 * Restoring config space is necessary even if the device is not bound
2278 @@ -1348,6 +1354,9 @@ static int pci_pm_runtime_resume(struct device *dev)
2279 pci_enable_wake(pci_dev, PCI_D0, false);
2280 pci_fixup_device(pci_fixup_resume, pci_dev);
2281
2282 + if (prev_state == PCI_D3cold)
2283 + pci_bridge_wait_for_secondary_bus(pci_dev);
2284 +
2285 if (pm && pm->runtime_resume)
2286 rc = pm->runtime_resume(dev);
2287
2288 diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
2289 index 981ae16f935b..779132aef0fb 100644
2290 --- a/drivers/pci/pci.c
2291 +++ b/drivers/pci/pci.c
2292 @@ -1019,8 +1019,6 @@ static void __pci_start_power_transition(struct pci_dev *dev, pci_power_t state)
2293 * because have already delayed for the bridge.
2294 */
2295 if (dev->runtime_d3cold) {
2296 - if (dev->d3cold_delay && !dev->imm_ready)
2297 - msleep(dev->d3cold_delay);
2298 /*
2299 * When powering on a bridge from D3cold, the
2300 * whole hierarchy may be powered on into
2301 @@ -4605,14 +4603,17 @@ static int pci_pm_reset(struct pci_dev *dev, int probe)
2302
2303 return pci_dev_wait(dev, "PM D3->D0", PCIE_RESET_READY_POLL_MS);
2304 }
2305 +
2306 /**
2307 - * pcie_wait_for_link - Wait until link is active or inactive
2308 + * pcie_wait_for_link_delay - Wait until link is active or inactive
2309 * @pdev: Bridge device
2310 * @active: waiting for active or inactive?
2311 + * @delay: Delay to wait after link has become active (in ms)
2312 *
2313 * Use this to wait till link becomes active or inactive.
2314 */
2315 -bool pcie_wait_for_link(struct pci_dev *pdev, bool active)
2316 +static bool pcie_wait_for_link_delay(struct pci_dev *pdev, bool active,
2317 + int delay)
2318 {
2319 int timeout = 1000;
2320 bool ret;
2321 @@ -4649,13 +4650,144 @@ bool pcie_wait_for_link(struct pci_dev *pdev, bool active)
2322 timeout -= 10;
2323 }
2324 if (active && ret)
2325 - msleep(100);
2326 + msleep(delay);
2327 else if (ret != active)
2328 pci_info(pdev, "Data Link Layer Link Active not %s in 1000 msec\n",
2329 active ? "set" : "cleared");
2330 return ret == active;
2331 }
2332
2333 +/**
2334 + * pcie_wait_for_link - Wait until link is active or inactive
2335 + * @pdev: Bridge device
2336 + * @active: waiting for active or inactive?
2337 + *
2338 + * Use this to wait till link becomes active or inactive.
2339 + */
2340 +bool pcie_wait_for_link(struct pci_dev *pdev, bool active)
2341 +{
2342 + return pcie_wait_for_link_delay(pdev, active, 100);
2343 +}
2344 +
2345 +/*
2346 + * Find maximum D3cold delay required by all the devices on the bus. The
2347 + * spec says 100 ms, but firmware can lower it and we allow drivers to
2348 + * increase it as well.
2349 + *
2350 + * Called with @pci_bus_sem locked for reading.
2351 + */
2352 +static int pci_bus_max_d3cold_delay(const struct pci_bus *bus)
2353 +{
2354 + const struct pci_dev *pdev;
2355 + int min_delay = 100;
2356 + int max_delay = 0;
2357 +
2358 + list_for_each_entry(pdev, &bus->devices, bus_list) {
2359 + if (pdev->d3cold_delay < min_delay)
2360 + min_delay = pdev->d3cold_delay;
2361 + if (pdev->d3cold_delay > max_delay)
2362 + max_delay = pdev->d3cold_delay;
2363 + }
2364 +
2365 + return max(min_delay, max_delay);
2366 +}
2367 +
2368 +/**
2369 + * pci_bridge_wait_for_secondary_bus - Wait for secondary bus to be accessible
2370 + * @dev: PCI bridge
2371 + *
2372 + * Handle necessary delays before access to the devices on the secondary
2373 + * side of the bridge are permitted after D3cold to D0 transition.
2374 + *
2375 + * For PCIe this means the delays in PCIe 5.0 section 6.6.1. For
2376 + * conventional PCI it means Tpvrh + Trhfa specified in PCI 3.0 section
2377 + * 4.3.2.
2378 + */
2379 +void pci_bridge_wait_for_secondary_bus(struct pci_dev *dev)
2380 +{
2381 + struct pci_dev *child;
2382 + int delay;
2383 +
2384 + if (pci_dev_is_disconnected(dev))
2385 + return;
2386 +
2387 + if (!pci_is_bridge(dev) || !dev->bridge_d3)
2388 + return;
2389 +
2390 + down_read(&pci_bus_sem);
2391 +
2392 + /*
2393 + * We only deal with devices that are present currently on the bus.
2394 + * For any hot-added devices the access delay is handled in pciehp
2395 + * board_added(). In case of ACPI hotplug the firmware is expected
2396 + * to configure the devices before OS is notified.
2397 + */
2398 + if (!dev->subordinate || list_empty(&dev->subordinate->devices)) {
2399 + up_read(&pci_bus_sem);
2400 + return;
2401 + }
2402 +
2403 + /* Take d3cold_delay requirements into account */
2404 + delay = pci_bus_max_d3cold_delay(dev->subordinate);
2405 + if (!delay) {
2406 + up_read(&pci_bus_sem);
2407 + return;
2408 + }
2409 +
2410 + child = list_first_entry(&dev->subordinate->devices, struct pci_dev,
2411 + bus_list);
2412 + up_read(&pci_bus_sem);
2413 +
2414 + /*
2415 + * Conventional PCI and PCI-X we need to wait Tpvrh + Trhfa before
2416 + * accessing the device after reset (that is 1000 ms + 100 ms). In
2417 + * practice this should not be needed because we don't do power
2418 + * management for them (see pci_bridge_d3_possible()).
2419 + */
2420 + if (!pci_is_pcie(dev)) {
2421 + pci_dbg(dev, "waiting %d ms for secondary bus\n", 1000 + delay);
2422 + msleep(1000 + delay);
2423 + return;
2424 + }
2425 +
2426 + /*
2427 + * For PCIe downstream and root ports that do not support speeds
2428 + * greater than 5 GT/s need to wait minimum 100 ms. For higher
2429 + * speeds (gen3) we need to wait first for the data link layer to
2430 + * become active.
2431 + *
2432 + * However, 100 ms is the minimum and the PCIe spec says the
2433 + * software must allow at least 1s before it can determine that the
2434 + * device that did not respond is a broken device. There is
2435 + * evidence that 100 ms is not always enough, for example certain
2436 + * Titan Ridge xHCI controller does not always respond to
2437 + * configuration requests if we only wait for 100 ms (see
2438 + * https://bugzilla.kernel.org/show_bug.cgi?id=203885).
2439 + *
2440 + * Therefore we wait for 100 ms and check for the device presence.
2441 + * If it is still not present give it an additional 100 ms.
2442 + */
2443 + if (!pcie_downstream_port(dev))
2444 + return;
2445 +
2446 + if (pcie_get_speed_cap(dev) <= PCIE_SPEED_5_0GT) {
2447 + pci_dbg(dev, "waiting %d ms for downstream link\n", delay);
2448 + msleep(delay);
2449 + } else {
2450 + pci_dbg(dev, "waiting %d ms for downstream link, after activation\n",
2451 + delay);
2452 + if (!pcie_wait_for_link_delay(dev, true, delay)) {
2453 + /* Did not train, no need to wait any further */
2454 + return;
2455 + }
2456 + }
2457 +
2458 + if (!pci_device_is_present(child)) {
2459 + pci_dbg(child, "waiting additional %d ms to become accessible\n", delay);
2460 + msleep(delay);
2461 + }
2462 +}
2463 +
2464 void pci_reset_secondary_bus(struct pci_dev *dev)
2465 {
2466 u16 ctrl;
2467 diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
2468 index 273d60cb0762..a5adc2e2c351 100644
2469 --- a/drivers/pci/pci.h
2470 +++ b/drivers/pci/pci.h
2471 @@ -107,6 +107,7 @@ void pci_allocate_cap_save_buffers(struct pci_dev *dev);
2472 void pci_free_cap_save_buffers(struct pci_dev *dev);
2473 bool pci_bridge_d3_possible(struct pci_dev *dev);
2474 void pci_bridge_d3_update(struct pci_dev *dev);
2475 +void pci_bridge_wait_for_secondary_bus(struct pci_dev *dev);
2476
2477 static inline void pci_wakeup_event(struct pci_dev *dev)
2478 {
2479 diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
2480 index 32c34330e5a6..5a1bbf2cb7e9 100644
2481 --- a/drivers/pci/pcie/aspm.c
2482 +++ b/drivers/pci/pcie/aspm.c
2483 @@ -64,6 +64,7 @@ struct pcie_link_state {
2484 u32 clkpm_capable:1; /* Clock PM capable? */
2485 u32 clkpm_enabled:1; /* Current Clock PM state */
2486 u32 clkpm_default:1; /* Default Clock PM state by BIOS */
2487 + u32 clkpm_disable:1; /* Clock PM disabled */
2488
2489 /* Exit latencies */
2490 struct aspm_latency latency_up; /* Upstream direction exit latency */
2491 @@ -161,8 +162,11 @@ static void pcie_set_clkpm_nocheck(struct pcie_link_state *link, int enable)
2492
2493 static void pcie_set_clkpm(struct pcie_link_state *link, int enable)
2494 {
2495 - /* Don't enable Clock PM if the link is not Clock PM capable */
2496 - if (!link->clkpm_capable)
2497 + /*
2498 + * Don't enable Clock PM if the link is not Clock PM capable
2499 + * or Clock PM is disabled
2500 + */
2501 + if (!link->clkpm_capable || link->clkpm_disable)
2502 enable = 0;
2503 /* Need nothing if the specified equals to current state */
2504 if (link->clkpm_enabled == enable)
2505 @@ -192,7 +196,8 @@ static void pcie_clkpm_cap_init(struct pcie_link_state *link, int blacklist)
2506 }
2507 link->clkpm_enabled = enabled;
2508 link->clkpm_default = enabled;
2509 - link->clkpm_capable = (blacklist) ? 0 : capable;
2510 + link->clkpm_capable = capable;
2511 + link->clkpm_disable = blacklist ? 1 : 0;
2512 }
2513
2514 static bool pcie_retrain_link(struct pcie_link_state *link)
2515 @@ -1097,10 +1102,9 @@ static int __pci_disable_link_state(struct pci_dev *pdev, int state, bool sem)
2516 link->aspm_disable |= ASPM_STATE_L1;
2517 pcie_config_aspm_link(link, policy_to_aspm_state(link));
2518
2519 - if (state & PCIE_LINK_STATE_CLKPM) {
2520 - link->clkpm_capable = 0;
2521 - pcie_set_clkpm(link, 0);
2522 - }
2523 + if (state & PCIE_LINK_STATE_CLKPM)
2524 + link->clkpm_disable = 1;
2525 + pcie_set_clkpm(link, policy_to_clkpm_state(link));
2526 mutex_unlock(&aspm_lock);
2527 if (sem)
2528 up_read(&pci_bus_sem);
2529 diff --git a/drivers/pwm/pwm-bcm2835.c b/drivers/pwm/pwm-bcm2835.c
2530 index 91e24f01b54e..d78f86f8e462 100644
2531 --- a/drivers/pwm/pwm-bcm2835.c
2532 +++ b/drivers/pwm/pwm-bcm2835.c
2533 @@ -166,6 +166,7 @@ static int bcm2835_pwm_probe(struct platform_device *pdev)
2534
2535 pc->chip.dev = &pdev->dev;
2536 pc->chip.ops = &bcm2835_pwm_ops;
2537 + pc->chip.base = -1;
2538 pc->chip.npwm = 2;
2539 pc->chip.of_xlate = of_pwm_xlate_with_flags;
2540 pc->chip.of_pwm_n_cells = 3;
2541 diff --git a/drivers/pwm/pwm-rcar.c b/drivers/pwm/pwm-rcar.c
2542 index 852eb2347954..b98ec8847b48 100644
2543 --- a/drivers/pwm/pwm-rcar.c
2544 +++ b/drivers/pwm/pwm-rcar.c
2545 @@ -228,24 +228,28 @@ static int rcar_pwm_probe(struct platform_device *pdev)
2546 rcar_pwm->chip.base = -1;
2547 rcar_pwm->chip.npwm = 1;
2548
2549 + pm_runtime_enable(&pdev->dev);
2550 +
2551 ret = pwmchip_add(&rcar_pwm->chip);
2552 if (ret < 0) {
2553 dev_err(&pdev->dev, "failed to register PWM chip: %d\n", ret);
2554 + pm_runtime_disable(&pdev->dev);
2555 return ret;
2556 }
2557
2558 - pm_runtime_enable(&pdev->dev);
2559 -
2560 return 0;
2561 }
2562
2563 static int rcar_pwm_remove(struct platform_device *pdev)
2564 {
2565 struct rcar_pwm_chip *rcar_pwm = platform_get_drvdata(pdev);
2566 + int ret;
2567 +
2568 + ret = pwmchip_remove(&rcar_pwm->chip);
2569
2570 pm_runtime_disable(&pdev->dev);
2571
2572 - return pwmchip_remove(&rcar_pwm->chip);
2573 + return ret;
2574 }
2575
2576 static const struct of_device_id rcar_pwm_of_table[] = {
2577 diff --git a/drivers/pwm/pwm-renesas-tpu.c b/drivers/pwm/pwm-renesas-tpu.c
2578 index 4a855a21b782..8032acc84161 100644
2579 --- a/drivers/pwm/pwm-renesas-tpu.c
2580 +++ b/drivers/pwm/pwm-renesas-tpu.c
2581 @@ -415,16 +415,17 @@ static int tpu_probe(struct platform_device *pdev)
2582 tpu->chip.base = -1;
2583 tpu->chip.npwm = TPU_CHANNEL_MAX;
2584
2585 + pm_runtime_enable(&pdev->dev);
2586 +
2587 ret = pwmchip_add(&tpu->chip);
2588 if (ret < 0) {
2589 dev_err(&pdev->dev, "failed to register PWM chip\n");
2590 + pm_runtime_disable(&pdev->dev);
2591 return ret;
2592 }
2593
2594 dev_info(&pdev->dev, "TPU PWM %d registered\n", tpu->pdev->id);
2595
2596 - pm_runtime_enable(&pdev->dev);
2597 -
2598 return 0;
2599 }
2600
2601 @@ -434,12 +435,10 @@ static int tpu_remove(struct platform_device *pdev)
2602 int ret;
2603
2604 ret = pwmchip_remove(&tpu->chip);
2605 - if (ret)
2606 - return ret;
2607
2608 pm_runtime_disable(&pdev->dev);
2609
2610 - return 0;
2611 + return ret;
2612 }
2613
2614 #ifdef CONFIG_OF
2615 diff --git a/drivers/s390/cio/device.c b/drivers/s390/cio/device.c
2616 index 0c6245fc7706..983f9c9e08de 100644
2617 --- a/drivers/s390/cio/device.c
2618 +++ b/drivers/s390/cio/device.c
2619 @@ -849,8 +849,10 @@ static void io_subchannel_register(struct ccw_device *cdev)
2620 * Now we know this subchannel will stay, we can throw
2621 * our delayed uevent.
2622 */
2623 - dev_set_uevent_suppress(&sch->dev, 0);
2624 - kobject_uevent(&sch->dev.kobj, KOBJ_ADD);
2625 + if (dev_get_uevent_suppress(&sch->dev)) {
2626 + dev_set_uevent_suppress(&sch->dev, 0);
2627 + kobject_uevent(&sch->dev.kobj, KOBJ_ADD);
2628 + }
2629 /* make it known to the system */
2630 ret = ccw_device_add(cdev);
2631 if (ret) {
2632 @@ -1058,8 +1060,11 @@ static int io_subchannel_probe(struct subchannel *sch)
2633 * Throw the delayed uevent for the subchannel, register
2634 * the ccw_device and exit.
2635 */
2636 - dev_set_uevent_suppress(&sch->dev, 0);
2637 - kobject_uevent(&sch->dev.kobj, KOBJ_ADD);
2638 + if (dev_get_uevent_suppress(&sch->dev)) {
2639 + /* should always be the case for the console */
2640 + dev_set_uevent_suppress(&sch->dev, 0);
2641 + kobject_uevent(&sch->dev.kobj, KOBJ_ADD);
2642 + }
2643 cdev = sch_get_cdev(sch);
2644 rc = ccw_device_add(cdev);
2645 if (rc) {
2646 diff --git a/drivers/s390/cio/vfio_ccw_drv.c b/drivers/s390/cio/vfio_ccw_drv.c
2647 index e401a3d0aa57..339a6bc0339b 100644
2648 --- a/drivers/s390/cio/vfio_ccw_drv.c
2649 +++ b/drivers/s390/cio/vfio_ccw_drv.c
2650 @@ -167,6 +167,11 @@ static int vfio_ccw_sch_probe(struct subchannel *sch)
2651 if (ret)
2652 goto out_disable;
2653
2654 + if (dev_get_uevent_suppress(&sch->dev)) {
2655 + dev_set_uevent_suppress(&sch->dev, 0);
2656 + kobject_uevent(&sch->dev.kobj, KOBJ_ADD);
2657 + }
2658 +
2659 VFIO_CCW_MSG_EVENT(4, "bound to subchannel %x.%x.%04x\n",
2660 sch->schid.cssid, sch->schid.ssid,
2661 sch->schid.sch_no);
2662 diff --git a/drivers/scsi/libfc/fc_rport.c b/drivers/scsi/libfc/fc_rport.c
2663 index da6e97d8dc3b..6bb8917b99a1 100644
2664 --- a/drivers/scsi/libfc/fc_rport.c
2665 +++ b/drivers/scsi/libfc/fc_rport.c
2666 @@ -1208,9 +1208,15 @@ static void fc_rport_prli_resp(struct fc_seq *sp, struct fc_frame *fp,
2667 rjt = fc_frame_payload_get(fp, sizeof(*rjt));
2668 if (!rjt)
2669 FC_RPORT_DBG(rdata, "PRLI bad response\n");
2670 - else
2671 + else {
2672 FC_RPORT_DBG(rdata, "PRLI ELS rejected, reason %x expl %x\n",
2673 rjt->er_reason, rjt->er_explan);
2674 + if (rjt->er_reason == ELS_RJT_UNAB &&
2675 + rjt->er_explan == ELS_EXPL_PLOGI_REQD) {
2676 + fc_rport_enter_plogi(rdata);
2677 + goto out;
2678 + }
2679 + }
2680 fc_rport_error_retry(rdata, FC_EX_ELS_RJT);
2681 }
2682
2683 diff --git a/drivers/scsi/lpfc/lpfc_nvme.c b/drivers/scsi/lpfc/lpfc_nvme.c
2684 index a227e36cbdc2..5a86a1ee0de3 100644
2685 --- a/drivers/scsi/lpfc/lpfc_nvme.c
2686 +++ b/drivers/scsi/lpfc/lpfc_nvme.c
2687 @@ -342,13 +342,15 @@ lpfc_nvme_remoteport_delete(struct nvme_fc_remote_port *remoteport)
2688 if (ndlp->upcall_flags & NLP_WAIT_FOR_UNREG) {
2689 ndlp->nrport = NULL;
2690 ndlp->upcall_flags &= ~NLP_WAIT_FOR_UNREG;
2691 - }
2692 - spin_unlock_irq(&vport->phba->hbalock);
2693 + spin_unlock_irq(&vport->phba->hbalock);
2694
2695 - /* Remove original register reference. The host transport
2696 - * won't reference this rport/remoteport any further.
2697 - */
2698 - lpfc_nlp_put(ndlp);
2699 + /* Remove original register reference. The host transport
2700 + * won't reference this rport/remoteport any further.
2701 + */
2702 + lpfc_nlp_put(ndlp);
2703 + } else {
2704 + spin_unlock_irq(&vport->phba->hbalock);
2705 + }
2706
2707 rport_err:
2708 return;
2709 diff --git a/drivers/scsi/lpfc/lpfc_sli.c b/drivers/scsi/lpfc/lpfc_sli.c
2710 index 0717e850bcbf..a951e1c8165e 100644
2711 --- a/drivers/scsi/lpfc/lpfc_sli.c
2712 +++ b/drivers/scsi/lpfc/lpfc_sli.c
2713 @@ -2481,6 +2481,8 @@ lpfc_sli_def_mbox_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
2714 !pmb->u.mb.mbxStatus) {
2715 rpi = pmb->u.mb.un.varWords[0];
2716 vpi = pmb->u.mb.un.varRegLogin.vpi;
2717 + if (phba->sli_rev == LPFC_SLI_REV4)
2718 + vpi -= phba->sli4_hba.max_cfg_param.vpi_base;
2719 lpfc_unreg_login(phba, vpi, rpi, pmb);
2720 pmb->vport = vport;
2721 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
2722 @@ -4011,6 +4013,11 @@ lpfc_sli_flush_io_rings(struct lpfc_hba *phba)
2723 struct lpfc_iocbq *piocb, *next_iocb;
2724
2725 spin_lock_irq(&phba->hbalock);
2726 + if (phba->hba_flag & HBA_IOQ_FLUSH ||
2727 + !phba->sli4_hba.hdwq) {
2728 + spin_unlock_irq(&phba->hbalock);
2729 + return;
2730 + }
2731 /* Indicate the I/O queues are flushed */
2732 phba->hba_flag |= HBA_IOQ_FLUSH;
2733 spin_unlock_irq(&phba->hbalock);
2734 diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
2735 index 271afea654e2..a5c78b38d302 100644
2736 --- a/drivers/scsi/scsi_transport_iscsi.c
2737 +++ b/drivers/scsi/scsi_transport_iscsi.c
2738 @@ -2012,7 +2012,7 @@ static void __iscsi_unbind_session(struct work_struct *work)
2739 if (session->target_id == ISCSI_MAX_TARGET) {
2740 spin_unlock_irqrestore(&session->lock, flags);
2741 mutex_unlock(&ihost->mutex);
2742 - return;
2743 + goto unbind_session_exit;
2744 }
2745
2746 target_id = session->target_id;
2747 @@ -2024,6 +2024,8 @@ static void __iscsi_unbind_session(struct work_struct *work)
2748 ida_simple_remove(&iscsi_sess_ida, target_id);
2749
2750 scsi_remove_target(&session->dev);
2751 +
2752 +unbind_session_exit:
2753 iscsi_session_event(session, ISCSI_KEVENT_UNBIND_SESSION);
2754 ISCSI_DBG_TRANS_SESSION(session, "Completed target removal\n");
2755 }
2756 diff --git a/drivers/scsi/smartpqi/smartpqi.h b/drivers/scsi/smartpqi/smartpqi.h
2757 index 79d2af36f655..7a3a942b40df 100644
2758 --- a/drivers/scsi/smartpqi/smartpqi.h
2759 +++ b/drivers/scsi/smartpqi/smartpqi.h
2760 @@ -907,7 +907,6 @@ struct pqi_scsi_dev {
2761 u8 scsi3addr[8];
2762 __be64 wwid;
2763 u8 volume_id[16];
2764 - u8 unique_id[16];
2765 u8 is_physical_device : 1;
2766 u8 is_external_raid_device : 1;
2767 u8 is_expander_smp_device : 1;
2768 @@ -1130,8 +1129,9 @@ struct pqi_ctrl_info {
2769 struct mutex ofa_mutex; /* serialize ofa */
2770 bool controller_online;
2771 bool block_requests;
2772 - bool in_shutdown;
2773 + bool block_device_reset;
2774 bool in_ofa;
2775 + bool in_shutdown;
2776 u8 inbound_spanning_supported : 1;
2777 u8 outbound_spanning_supported : 1;
2778 u8 pqi_mode_enabled : 1;
2779 @@ -1173,6 +1173,7 @@ struct pqi_ctrl_info {
2780 struct pqi_ofa_memory *pqi_ofa_mem_virt_addr;
2781 dma_addr_t pqi_ofa_mem_dma_handle;
2782 void **pqi_ofa_chunk_virt_addr;
2783 + atomic_t sync_cmds_outstanding;
2784 };
2785
2786 enum pqi_ctrl_mode {
2787 @@ -1423,6 +1424,11 @@ static inline bool pqi_ctrl_blocked(struct pqi_ctrl_info *ctrl_info)
2788 return ctrl_info->block_requests;
2789 }
2790
2791 +static inline bool pqi_device_reset_blocked(struct pqi_ctrl_info *ctrl_info)
2792 +{
2793 + return ctrl_info->block_device_reset;
2794 +}
2795 +
2796 void pqi_sas_smp_handler(struct bsg_job *job, struct Scsi_Host *shost,
2797 struct sas_rphy *rphy);
2798
2799 diff --git a/drivers/scsi/smartpqi/smartpqi_init.c b/drivers/scsi/smartpqi/smartpqi_init.c
2800 index ea5409bebf57..5ae074505386 100644
2801 --- a/drivers/scsi/smartpqi/smartpqi_init.c
2802 +++ b/drivers/scsi/smartpqi/smartpqi_init.c
2803 @@ -249,6 +249,11 @@ static inline void pqi_ctrl_unblock_requests(struct pqi_ctrl_info *ctrl_info)
2804 scsi_unblock_requests(ctrl_info->scsi_host);
2805 }
2806
2807 +static inline void pqi_ctrl_block_device_reset(struct pqi_ctrl_info *ctrl_info)
2808 +{
2809 + ctrl_info->block_device_reset = true;
2810 +}
2811 +
2812 static unsigned long pqi_wait_if_ctrl_blocked(struct pqi_ctrl_info *ctrl_info,
2813 unsigned long timeout_msecs)
2814 {
2815 @@ -331,6 +336,16 @@ static inline bool pqi_device_in_remove(struct pqi_ctrl_info *ctrl_info,
2816 return device->in_remove && !ctrl_info->in_shutdown;
2817 }
2818
2819 +static inline void pqi_ctrl_shutdown_start(struct pqi_ctrl_info *ctrl_info)
2820 +{
2821 + ctrl_info->in_shutdown = true;
2822 +}
2823 +
2824 +static inline bool pqi_ctrl_in_shutdown(struct pqi_ctrl_info *ctrl_info)
2825 +{
2826 + return ctrl_info->in_shutdown;
2827 +}
2828 +
2829 static inline void pqi_schedule_rescan_worker_with_delay(
2830 struct pqi_ctrl_info *ctrl_info, unsigned long delay)
2831 {
2832 @@ -360,6 +375,11 @@ static inline void pqi_cancel_rescan_worker(struct pqi_ctrl_info *ctrl_info)
2833 cancel_delayed_work_sync(&ctrl_info->rescan_work);
2834 }
2835
2836 +static inline void pqi_cancel_event_worker(struct pqi_ctrl_info *ctrl_info)
2837 +{
2838 + cancel_work_sync(&ctrl_info->event_work);
2839 +}
2840 +
2841 static inline u32 pqi_read_heartbeat_counter(struct pqi_ctrl_info *ctrl_info)
2842 {
2843 if (!ctrl_info->heartbeat_counter)
2844 @@ -628,79 +648,6 @@ static inline int pqi_scsi_inquiry(struct pqi_ctrl_info *ctrl_info,
2845 buffer, buffer_length, vpd_page, NULL, NO_TIMEOUT);
2846 }
2847
2848 -static bool pqi_vpd_page_supported(struct pqi_ctrl_info *ctrl_info,
2849 - u8 *scsi3addr, u16 vpd_page)
2850 -{
2851 - int rc;
2852 - int i;
2853 - int pages;
2854 - unsigned char *buf, bufsize;
2855 -
2856 - buf = kzalloc(256, GFP_KERNEL);
2857 - if (!buf)
2858 - return false;
2859 -
2860 - /* Get the size of the page list first */
2861 - rc = pqi_scsi_inquiry(ctrl_info, scsi3addr,
2862 - VPD_PAGE | SCSI_VPD_SUPPORTED_PAGES,
2863 - buf, SCSI_VPD_HEADER_SZ);
2864 - if (rc != 0)
2865 - goto exit_unsupported;
2866 -
2867 - pages = buf[3];
2868 - if ((pages + SCSI_VPD_HEADER_SZ) <= 255)
2869 - bufsize = pages + SCSI_VPD_HEADER_SZ;
2870 - else
2871 - bufsize = 255;
2872 -
2873 - /* Get the whole VPD page list */
2874 - rc = pqi_scsi_inquiry(ctrl_info, scsi3addr,
2875 - VPD_PAGE | SCSI_VPD_SUPPORTED_PAGES,
2876 - buf, bufsize);
2877 - if (rc != 0)
2878 - goto exit_unsupported;
2879 -
2880 - pages = buf[3];
2881 - for (i = 1; i <= pages; i++)
2882 - if (buf[3 + i] == vpd_page)
2883 - goto exit_supported;
2884 -
2885 -exit_unsupported:
2886 - kfree(buf);
2887 - return false;
2888 -
2889 -exit_supported:
2890 - kfree(buf);
2891 - return true;
2892 -}
2893 -
2894 -static int pqi_get_device_id(struct pqi_ctrl_info *ctrl_info,
2895 - u8 *scsi3addr, u8 *device_id, int buflen)
2896 -{
2897 - int rc;
2898 - unsigned char *buf;
2899 -
2900 - if (!pqi_vpd_page_supported(ctrl_info, scsi3addr, SCSI_VPD_DEVICE_ID))
2901 - return 1; /* function not supported */
2902 -
2903 - buf = kzalloc(64, GFP_KERNEL);
2904 - if (!buf)
2905 - return -ENOMEM;
2906 -
2907 - rc = pqi_scsi_inquiry(ctrl_info, scsi3addr,
2908 - VPD_PAGE | SCSI_VPD_DEVICE_ID,
2909 - buf, 64);
2910 - if (rc == 0) {
2911 - if (buflen > 16)
2912 - buflen = 16;
2913 - memcpy(device_id, &buf[SCSI_VPD_DEVICE_ID_IDX], buflen);
2914 - }
2915 -
2916 - kfree(buf);
2917 -
2918 - return rc;
2919 -}
2920 -
2921 static int pqi_identify_physical_device(struct pqi_ctrl_info *ctrl_info,
2922 struct pqi_scsi_dev *device,
2923 struct bmic_identify_physical_device *buffer,
2924 @@ -1385,14 +1332,6 @@ static int pqi_get_device_info(struct pqi_ctrl_info *ctrl_info,
2925 }
2926 }
2927
2928 - if (pqi_get_device_id(ctrl_info, device->scsi3addr,
2929 - device->unique_id, sizeof(device->unique_id)) < 0)
2930 - dev_warn(&ctrl_info->pci_dev->dev,
2931 - "Can't get device id for scsi %d:%d:%d:%d\n",
2932 - ctrl_info->scsi_host->host_no,
2933 - device->bus, device->target,
2934 - device->lun);
2935 -
2936 out:
2937 kfree(buffer);
2938
2939 @@ -4122,6 +4061,8 @@ static int pqi_submit_raid_request_synchronous(struct pqi_ctrl_info *ctrl_info,
2940 goto out;
2941 }
2942
2943 + atomic_inc(&ctrl_info->sync_cmds_outstanding);
2944 +
2945 io_request = pqi_alloc_io_request(ctrl_info);
2946
2947 put_unaligned_le16(io_request->index,
2948 @@ -4168,6 +4109,7 @@ static int pqi_submit_raid_request_synchronous(struct pqi_ctrl_info *ctrl_info,
2949
2950 pqi_free_io_request(io_request);
2951
2952 + atomic_dec(&ctrl_info->sync_cmds_outstanding);
2953 out:
2954 up(&ctrl_info->sync_request_sem);
2955
2956 @@ -5402,7 +5344,7 @@ static int pqi_scsi_queue_command(struct Scsi_Host *shost,
2957
2958 pqi_ctrl_busy(ctrl_info);
2959 if (pqi_ctrl_blocked(ctrl_info) || pqi_device_in_reset(device) ||
2960 - pqi_ctrl_in_ofa(ctrl_info)) {
2961 + pqi_ctrl_in_ofa(ctrl_info) || pqi_ctrl_in_shutdown(ctrl_info)) {
2962 rc = SCSI_MLQUEUE_HOST_BUSY;
2963 goto out;
2964 }
2965 @@ -5650,6 +5592,18 @@ static int pqi_ctrl_wait_for_pending_io(struct pqi_ctrl_info *ctrl_info,
2966 return 0;
2967 }
2968
2969 +static int pqi_ctrl_wait_for_pending_sync_cmds(struct pqi_ctrl_info *ctrl_info)
2970 +{
2971 + while (atomic_read(&ctrl_info->sync_cmds_outstanding)) {
2972 + pqi_check_ctrl_health(ctrl_info);
2973 + if (pqi_ctrl_offline(ctrl_info))
2974 + return -ENXIO;
2975 + usleep_range(1000, 2000);
2976 + }
2977 +
2978 + return 0;
2979 +}
2980 +
2981 static void pqi_lun_reset_complete(struct pqi_io_request *io_request,
2982 void *context)
2983 {
2984 @@ -5787,17 +5741,17 @@ static int pqi_eh_device_reset_handler(struct scsi_cmnd *scmd)
2985 shost->host_no, device->bus, device->target, device->lun);
2986
2987 pqi_check_ctrl_health(ctrl_info);
2988 - if (pqi_ctrl_offline(ctrl_info)) {
2989 - dev_err(&ctrl_info->pci_dev->dev,
2990 - "controller %u offlined - cannot send device reset\n",
2991 - ctrl_info->ctrl_id);
2992 + if (pqi_ctrl_offline(ctrl_info) ||
2993 + pqi_device_reset_blocked(ctrl_info)) {
2994 rc = FAILED;
2995 goto out;
2996 }
2997
2998 pqi_wait_until_ofa_finished(ctrl_info);
2999
3000 + atomic_inc(&ctrl_info->sync_cmds_outstanding);
3001 rc = pqi_device_reset(ctrl_info, device);
3002 + atomic_dec(&ctrl_info->sync_cmds_outstanding);
3003
3004 out:
3005 dev_err(&ctrl_info->pci_dev->dev,
3006 @@ -6119,7 +6073,8 @@ static int pqi_ioctl(struct scsi_device *sdev, unsigned int cmd,
3007
3008 ctrl_info = shost_to_hba(sdev->host);
3009
3010 - if (pqi_ctrl_in_ofa(ctrl_info))
3011 + if (pqi_ctrl_in_ofa(ctrl_info) ||
3012 + pqi_ctrl_in_shutdown(ctrl_info))
3013 return -EBUSY;
3014
3015 switch (cmd) {
3016 @@ -6283,7 +6238,7 @@ static ssize_t pqi_unique_id_show(struct device *dev,
3017 struct scsi_device *sdev;
3018 struct pqi_scsi_dev *device;
3019 unsigned long flags;
3020 - unsigned char uid[16];
3021 + u8 unique_id[16];
3022
3023 sdev = to_scsi_device(dev);
3024 ctrl_info = shost_to_hba(sdev->host);
3025 @@ -6296,16 +6251,22 @@ static ssize_t pqi_unique_id_show(struct device *dev,
3026 flags);
3027 return -ENODEV;
3028 }
3029 - memcpy(uid, device->unique_id, sizeof(uid));
3030 +
3031 + if (device->is_physical_device) {
3032 + memset(unique_id, 0, 8);
3033 + memcpy(unique_id + 8, &device->wwid, sizeof(device->wwid));
3034 + } else {
3035 + memcpy(unique_id, device->volume_id, sizeof(device->volume_id));
3036 + }
3037
3038 spin_unlock_irqrestore(&ctrl_info->scsi_device_list_lock, flags);
3039
3040 return snprintf(buffer, PAGE_SIZE,
3041 "%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X\n",
3042 - uid[0], uid[1], uid[2], uid[3],
3043 - uid[4], uid[5], uid[6], uid[7],
3044 - uid[8], uid[9], uid[10], uid[11],
3045 - uid[12], uid[13], uid[14], uid[15]);
3046 + unique_id[0], unique_id[1], unique_id[2], unique_id[3],
3047 + unique_id[4], unique_id[5], unique_id[6], unique_id[7],
3048 + unique_id[8], unique_id[9], unique_id[10], unique_id[11],
3049 + unique_id[12], unique_id[13], unique_id[14], unique_id[15]);
3050 }
3051
3052 static ssize_t pqi_lunid_show(struct device *dev,
3053 @@ -7074,13 +7035,20 @@ static int pqi_force_sis_mode(struct pqi_ctrl_info *ctrl_info)
3054 return pqi_revert_to_sis_mode(ctrl_info);
3055 }
3056
3057 +#define PQI_POST_RESET_DELAY_B4_MSGU_READY 5000
3058 +
3059 static int pqi_ctrl_init(struct pqi_ctrl_info *ctrl_info)
3060 {
3061 int rc;
3062
3063 - rc = pqi_force_sis_mode(ctrl_info);
3064 - if (rc)
3065 - return rc;
3066 + if (reset_devices) {
3067 + sis_soft_reset(ctrl_info);
3068 + msleep(PQI_POST_RESET_DELAY_B4_MSGU_READY);
3069 + } else {
3070 + rc = pqi_force_sis_mode(ctrl_info);
3071 + if (rc)
3072 + return rc;
3073 + }
3074
3075 /*
3076 * Wait until the controller is ready to start accepting SIS
3077 @@ -7514,6 +7482,7 @@ static struct pqi_ctrl_info *pqi_alloc_ctrl_info(int numa_node)
3078
3079 INIT_WORK(&ctrl_info->event_work, pqi_event_worker);
3080 atomic_set(&ctrl_info->num_interrupts, 0);
3081 + atomic_set(&ctrl_info->sync_cmds_outstanding, 0);
3082
3083 INIT_DELAYED_WORK(&ctrl_info->rescan_work, pqi_rescan_worker);
3084 INIT_DELAYED_WORK(&ctrl_info->update_time_work, pqi_update_time_worker);
3085 @@ -7787,8 +7756,6 @@ static int pqi_ofa_host_memory_update(struct pqi_ctrl_info *ctrl_info)
3086 0, NULL, NO_TIMEOUT);
3087 }
3088
3089 -#define PQI_POST_RESET_DELAY_B4_MSGU_READY 5000
3090 -
3091 static int pqi_ofa_ctrl_restart(struct pqi_ctrl_info *ctrl_info)
3092 {
3093 msleep(PQI_POST_RESET_DELAY_B4_MSGU_READY);
3094 @@ -7956,28 +7923,74 @@ static void pqi_pci_remove(struct pci_dev *pci_dev)
3095 pqi_remove_ctrl(ctrl_info);
3096 }
3097
3098 +static void pqi_crash_if_pending_command(struct pqi_ctrl_info *ctrl_info)
3099 +{
3100 + unsigned int i;
3101 + struct pqi_io_request *io_request;
3102 + struct scsi_cmnd *scmd;
3103 +
3104 + for (i = 0; i < ctrl_info->max_io_slots; i++) {
3105 + io_request = &ctrl_info->io_request_pool[i];
3106 + if (atomic_read(&io_request->refcount) == 0)
3107 + continue;
3108 + scmd = io_request->scmd;
3109 + WARN_ON(scmd != NULL); /* IO command from SML */
3110 + WARN_ON(scmd == NULL); /* Non-IO cmd or driver initiated*/
3111 + }
3112 +}
3113 +
3114 static void pqi_shutdown(struct pci_dev *pci_dev)
3115 {
3116 int rc;
3117 struct pqi_ctrl_info *ctrl_info;
3118
3119 ctrl_info = pci_get_drvdata(pci_dev);
3120 - if (!ctrl_info)
3121 - goto error;
3122 + if (!ctrl_info) {
3123 + dev_err(&pci_dev->dev,
3124 + "cache could not be flushed\n");
3125 + return;
3126 + }
3127 +
3128 + pqi_disable_events(ctrl_info);
3129 + pqi_wait_until_ofa_finished(ctrl_info);
3130 + pqi_cancel_update_time_worker(ctrl_info);
3131 + pqi_cancel_rescan_worker(ctrl_info);
3132 + pqi_cancel_event_worker(ctrl_info);
3133 +
3134 + pqi_ctrl_shutdown_start(ctrl_info);
3135 + pqi_ctrl_wait_until_quiesced(ctrl_info);
3136 +
3137 + rc = pqi_ctrl_wait_for_pending_io(ctrl_info, NO_TIMEOUT);
3138 + if (rc) {
3139 + dev_err(&pci_dev->dev,
3140 + "wait for pending I/O failed\n");
3141 + return;
3142 + }
3143 +
3144 + pqi_ctrl_block_device_reset(ctrl_info);
3145 + pqi_wait_until_lun_reset_finished(ctrl_info);
3146
3147 /*
3148 * Write all data in the controller's battery-backed cache to
3149 * storage.
3150 */
3151 rc = pqi_flush_cache(ctrl_info, SHUTDOWN);
3152 - pqi_free_interrupts(ctrl_info);
3153 - pqi_reset(ctrl_info);
3154 - if (rc == 0)
3155 + if (rc)
3156 + dev_err(&pci_dev->dev,
3157 + "unable to flush controller cache\n");
3158 +
3159 + pqi_ctrl_block_requests(ctrl_info);
3160 +
3161 + rc = pqi_ctrl_wait_for_pending_sync_cmds(ctrl_info);
3162 + if (rc) {
3163 + dev_err(&pci_dev->dev,
3164 + "wait for pending sync cmds failed\n");
3165 return;
3166 + }
3167 +
3168 + pqi_crash_if_pending_command(ctrl_info);
3169 + pqi_reset(ctrl_info);
3170
3171 -error:
3172 - dev_warn(&pci_dev->dev,
3173 - "unable to flush controller cache\n");
3174 }
3175
3176 static void pqi_process_lockup_action_param(void)
3177 diff --git a/drivers/scsi/smartpqi/smartpqi_sas_transport.c b/drivers/scsi/smartpqi/smartpqi_sas_transport.c
3178 index 6776dfc1d317..b7e28b9f8589 100644
3179 --- a/drivers/scsi/smartpqi/smartpqi_sas_transport.c
3180 +++ b/drivers/scsi/smartpqi/smartpqi_sas_transport.c
3181 @@ -45,9 +45,9 @@ static void pqi_free_sas_phy(struct pqi_sas_phy *pqi_sas_phy)
3182 struct sas_phy *phy = pqi_sas_phy->phy;
3183
3184 sas_port_delete_phy(pqi_sas_phy->parent_port->port, phy);
3185 - sas_phy_free(phy);
3186 if (pqi_sas_phy->added_to_port)
3187 list_del(&pqi_sas_phy->phy_list_entry);
3188 + sas_phy_delete(phy);
3189 kfree(pqi_sas_phy);
3190 }
3191
3192 diff --git a/drivers/staging/comedi/comedi_fops.c b/drivers/staging/comedi/comedi_fops.c
3193 index 08d1bbbebf2d..e84b4fb493d6 100644
3194 --- a/drivers/staging/comedi/comedi_fops.c
3195 +++ b/drivers/staging/comedi/comedi_fops.c
3196 @@ -2725,8 +2725,10 @@ static int comedi_open(struct inode *inode, struct file *file)
3197 }
3198
3199 cfp = kzalloc(sizeof(*cfp), GFP_KERNEL);
3200 - if (!cfp)
3201 + if (!cfp) {
3202 + comedi_dev_put(dev);
3203 return -ENOMEM;
3204 + }
3205
3206 cfp->dev = dev;
3207
3208 diff --git a/drivers/staging/comedi/drivers/dt2815.c b/drivers/staging/comedi/drivers/dt2815.c
3209 index 83026ba63d1c..78a7c1b3448a 100644
3210 --- a/drivers/staging/comedi/drivers/dt2815.c
3211 +++ b/drivers/staging/comedi/drivers/dt2815.c
3212 @@ -92,6 +92,7 @@ static int dt2815_ao_insn(struct comedi_device *dev, struct comedi_subdevice *s,
3213 int ret;
3214
3215 for (i = 0; i < insn->n; i++) {
3216 + /* FIXME: lo bit 0 chooses voltage output or current output */
3217 lo = ((data[i] & 0x0f) << 4) | (chan << 1) | 0x01;
3218 hi = (data[i] & 0xff0) >> 4;
3219
3220 @@ -105,6 +106,8 @@ static int dt2815_ao_insn(struct comedi_device *dev, struct comedi_subdevice *s,
3221 if (ret)
3222 return ret;
3223
3224 + outb(hi, dev->iobase + DT2815_DATA);
3225 +
3226 devpriv->ao_readback[chan] = data[i];
3227 }
3228 return i;
3229 diff --git a/drivers/staging/gasket/gasket_sysfs.c b/drivers/staging/gasket/gasket_sysfs.c
3230 index a2d67c28f530..5f0e089573a2 100644
3231 --- a/drivers/staging/gasket/gasket_sysfs.c
3232 +++ b/drivers/staging/gasket/gasket_sysfs.c
3233 @@ -228,8 +228,7 @@ int gasket_sysfs_create_entries(struct device *device,
3234 }
3235
3236 mutex_lock(&mapping->mutex);
3237 - for (i = 0; strcmp(attrs[i].attr.attr.name, GASKET_ARRAY_END_MARKER);
3238 - i++) {
3239 + for (i = 0; attrs[i].attr.attr.name != NULL; i++) {
3240 if (mapping->attribute_count == GASKET_SYSFS_MAX_NODES) {
3241 dev_err(device,
3242 "Maximum number of sysfs nodes reached for device\n");
3243 diff --git a/drivers/staging/gasket/gasket_sysfs.h b/drivers/staging/gasket/gasket_sysfs.h
3244 index 1d0eed66a7f4..ab5aa351d555 100644
3245 --- a/drivers/staging/gasket/gasket_sysfs.h
3246 +++ b/drivers/staging/gasket/gasket_sysfs.h
3247 @@ -30,10 +30,6 @@
3248 */
3249 #define GASKET_SYSFS_MAX_NODES 196
3250
3251 -/* End markers for sysfs struct arrays. */
3252 -#define GASKET_ARRAY_END_TOKEN GASKET_RESERVED_ARRAY_END
3253 -#define GASKET_ARRAY_END_MARKER __stringify(GASKET_ARRAY_END_TOKEN)
3254 -
3255 /*
3256 * Terminator struct for a gasket_sysfs_attr array. Must be at the end of
3257 * all gasket_sysfs_attribute arrays.
3258 diff --git a/drivers/staging/vt6656/int.c b/drivers/staging/vt6656/int.c
3259 index af215860be4c..ac563e23868e 100644
3260 --- a/drivers/staging/vt6656/int.c
3261 +++ b/drivers/staging/vt6656/int.c
3262 @@ -145,7 +145,8 @@ void vnt_int_process_data(struct vnt_private *priv)
3263 priv->wake_up_count =
3264 priv->hw->conf.listen_interval;
3265
3266 - --priv->wake_up_count;
3267 + if (priv->wake_up_count)
3268 + --priv->wake_up_count;
3269
3270 /* Turn on wake up to listen next beacon */
3271 if (priv->wake_up_count == 1)
3272 diff --git a/drivers/staging/vt6656/key.c b/drivers/staging/vt6656/key.c
3273 index dcd933a6b66e..40c58ac4e209 100644
3274 --- a/drivers/staging/vt6656/key.c
3275 +++ b/drivers/staging/vt6656/key.c
3276 @@ -83,9 +83,6 @@ static int vnt_set_keymode(struct ieee80211_hw *hw, u8 *mac_addr,
3277 case VNT_KEY_PAIRWISE:
3278 key_mode |= mode;
3279 key_inx = 4;
3280 - /* Don't save entry for pairwise key for station mode */
3281 - if (priv->op_mode == NL80211_IFTYPE_STATION)
3282 - clear_bit(entry, &priv->key_entry_inuse);
3283 break;
3284 default:
3285 return -EINVAL;
3286 @@ -109,7 +106,6 @@ static int vnt_set_keymode(struct ieee80211_hw *hw, u8 *mac_addr,
3287 int vnt_set_keys(struct ieee80211_hw *hw, struct ieee80211_sta *sta,
3288 struct ieee80211_vif *vif, struct ieee80211_key_conf *key)
3289 {
3290 - struct ieee80211_bss_conf *conf = &vif->bss_conf;
3291 struct vnt_private *priv = hw->priv;
3292 u8 *mac_addr = NULL;
3293 u8 key_dec_mode = 0;
3294 @@ -151,16 +147,12 @@ int vnt_set_keys(struct ieee80211_hw *hw, struct ieee80211_sta *sta,
3295 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
3296 }
3297
3298 - if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE) {
3299 + if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
3300 vnt_set_keymode(hw, mac_addr, key, VNT_KEY_PAIRWISE,
3301 key_dec_mode, true);
3302 - } else {
3303 - vnt_set_keymode(hw, mac_addr, key, VNT_KEY_DEFAULTKEY,
3304 + else
3305 + vnt_set_keymode(hw, mac_addr, key, VNT_KEY_GROUP_ADDRESS,
3306 key_dec_mode, true);
3307
3308 - vnt_set_keymode(hw, (u8 *)conf->bssid, key,
3309 - VNT_KEY_GROUP_ADDRESS, key_dec_mode, true);
3310 - }
3311 -
3312 return 0;
3313 }
3314 diff --git a/drivers/staging/vt6656/main_usb.c b/drivers/staging/vt6656/main_usb.c
3315 index 69a48383611f..48db31238d56 100644
3316 --- a/drivers/staging/vt6656/main_usb.c
3317 +++ b/drivers/staging/vt6656/main_usb.c
3318 @@ -633,8 +633,6 @@ static int vnt_add_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
3319
3320 priv->op_mode = vif->type;
3321
3322 - vnt_set_bss_mode(priv);
3323 -
3324 /* LED blink on TX */
3325 vnt_mac_set_led(priv, LEDSTS_STS, LEDSTS_INTER);
3326
3327 @@ -721,7 +719,6 @@ static void vnt_bss_info_changed(struct ieee80211_hw *hw,
3328 priv->basic_rates = conf->basic_rates;
3329
3330 vnt_update_top_rates(priv);
3331 - vnt_set_bss_mode(priv);
3332
3333 dev_dbg(&priv->usb->dev, "basic rates %x\n", conf->basic_rates);
3334 }
3335 @@ -750,11 +747,14 @@ static void vnt_bss_info_changed(struct ieee80211_hw *hw,
3336 priv->short_slot_time = false;
3337
3338 vnt_set_short_slot_time(priv);
3339 - vnt_update_ifs(priv);
3340 vnt_set_vga_gain_offset(priv, priv->bb_vga[0]);
3341 vnt_update_pre_ed_threshold(priv, false);
3342 }
3343
3344 + if (changed & (BSS_CHANGED_BASIC_RATES | BSS_CHANGED_ERP_PREAMBLE |
3345 + BSS_CHANGED_ERP_SLOT))
3346 + vnt_set_bss_mode(priv);
3347 +
3348 if (changed & BSS_CHANGED_TXPOWER)
3349 vnt_rf_setpower(priv, priv->current_rate,
3350 conf->chandef.chan->hw_value);
3351 @@ -778,12 +778,15 @@ static void vnt_bss_info_changed(struct ieee80211_hw *hw,
3352 vnt_mac_reg_bits_on(priv, MAC_REG_TFTCTL,
3353 TFTCTL_TSFCNTREN);
3354
3355 - vnt_adjust_tsf(priv, conf->beacon_rate->hw_value,
3356 - conf->sync_tsf, priv->current_tsf);
3357 -
3358 vnt_mac_set_beacon_interval(priv, conf->beacon_int);
3359
3360 vnt_reset_next_tbtt(priv, conf->beacon_int);
3361 +
3362 + vnt_adjust_tsf(priv, conf->beacon_rate->hw_value,
3363 + conf->sync_tsf, priv->current_tsf);
3364 +
3365 + vnt_update_next_tbtt(priv,
3366 + conf->sync_tsf, conf->beacon_int);
3367 } else {
3368 vnt_clear_current_tsf(priv);
3369
3370 @@ -818,15 +821,11 @@ static void vnt_configure(struct ieee80211_hw *hw,
3371 {
3372 struct vnt_private *priv = hw->priv;
3373 u8 rx_mode = 0;
3374 - int rc;
3375
3376 *total_flags &= FIF_ALLMULTI | FIF_OTHER_BSS | FIF_BCN_PRBRESP_PROMISC;
3377
3378 - rc = vnt_control_in(priv, MESSAGE_TYPE_READ, MAC_REG_RCR,
3379 - MESSAGE_REQUEST_MACREG, sizeof(u8), &rx_mode);
3380 -
3381 - if (!rc)
3382 - rx_mode = RCR_MULTICAST | RCR_BROADCAST;
3383 + vnt_control_in(priv, MESSAGE_TYPE_READ, MAC_REG_RCR,
3384 + MESSAGE_REQUEST_MACREG, sizeof(u8), &rx_mode);
3385
3386 dev_dbg(&priv->usb->dev, "rx mode in = %x\n", rx_mode);
3387
3388 @@ -867,8 +866,12 @@ static int vnt_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
3389 return -EOPNOTSUPP;
3390 break;
3391 case DISABLE_KEY:
3392 - if (test_bit(key->hw_key_idx, &priv->key_entry_inuse))
3393 + if (test_bit(key->hw_key_idx, &priv->key_entry_inuse)) {
3394 clear_bit(key->hw_key_idx, &priv->key_entry_inuse);
3395 +
3396 + vnt_mac_disable_keyentry(priv, key->hw_key_idx);
3397 + }
3398 +
3399 default:
3400 break;
3401 }
3402 diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c
3403 index 27284a2dcd2b..436cc51c92c3 100644
3404 --- a/drivers/tty/hvc/hvc_console.c
3405 +++ b/drivers/tty/hvc/hvc_console.c
3406 @@ -302,10 +302,6 @@ int hvc_instantiate(uint32_t vtermno, int index, const struct hv_ops *ops)
3407 vtermnos[index] = vtermno;
3408 cons_ops[index] = ops;
3409
3410 - /* reserve all indices up to and including this index */
3411 - if (last_hvc < index)
3412 - last_hvc = index;
3413 -
3414 /* check if we need to re-register the kernel console */
3415 hvc_check_console(index);
3416
3417 @@ -960,13 +956,22 @@ struct hvc_struct *hvc_alloc(uint32_t vtermno, int data,
3418 cons_ops[i] == hp->ops)
3419 break;
3420
3421 - /* no matching slot, just use a counter */
3422 - if (i >= MAX_NR_HVC_CONSOLES)
3423 - i = ++last_hvc;
3424 + if (i >= MAX_NR_HVC_CONSOLES) {
3425 +
3426 + /* find 'empty' slot for console */
3427 + for (i = 0; i < MAX_NR_HVC_CONSOLES && vtermnos[i] != -1; i++) {
3428 + }
3429 +
3430 + /* no matching slot, just use a counter */
3431 + if (i == MAX_NR_HVC_CONSOLES)
3432 + i = ++last_hvc + MAX_NR_HVC_CONSOLES;
3433 + }
3434
3435 hp->index = i;
3436 - cons_ops[i] = ops;
3437 - vtermnos[i] = vtermno;
3438 + if (i < MAX_NR_HVC_CONSOLES) {
3439 + cons_ops[i] = ops;
3440 + vtermnos[i] = vtermno;
3441 + }
3442
3443 list_add_tail(&(hp->next), &hvc_structs);
3444 mutex_unlock(&hvc_structs_mutex);
3445 diff --git a/drivers/tty/rocket.c b/drivers/tty/rocket.c
3446 index 5ba6816ebf81..bbaad2887ce7 100644
3447 --- a/drivers/tty/rocket.c
3448 +++ b/drivers/tty/rocket.c
3449 @@ -632,18 +632,21 @@ init_r_port(int board, int aiop, int chan, struct pci_dev *pci_dev)
3450 tty_port_init(&info->port);
3451 info->port.ops = &rocket_port_ops;
3452 info->flags &= ~ROCKET_MODE_MASK;
3453 - switch (pc104[board][line]) {
3454 - case 422:
3455 - info->flags |= ROCKET_MODE_RS422;
3456 - break;
3457 - case 485:
3458 - info->flags |= ROCKET_MODE_RS485;
3459 - break;
3460 - case 232:
3461 - default:
3462 + if (board < ARRAY_SIZE(pc104) && line < ARRAY_SIZE(pc104_1))
3463 + switch (pc104[board][line]) {
3464 + case 422:
3465 + info->flags |= ROCKET_MODE_RS422;
3466 + break;
3467 + case 485:
3468 + info->flags |= ROCKET_MODE_RS485;
3469 + break;
3470 + case 232:
3471 + default:
3472 + info->flags |= ROCKET_MODE_RS232;
3473 + break;
3474 + }
3475 + else
3476 info->flags |= ROCKET_MODE_RS232;
3477 - break;
3478 - }
3479
3480 info->intmask = RXF_TRIG | TXFIFO_MT | SRC_INT | DELTA_CD | DELTA_CTS | DELTA_DSR;
3481 if (sInitChan(ctlp, &info->channel, aiop, chan) == 0) {
3482 diff --git a/drivers/tty/serial/owl-uart.c b/drivers/tty/serial/owl-uart.c
3483 index d2d8b3494685..c55c8507713c 100644
3484 --- a/drivers/tty/serial/owl-uart.c
3485 +++ b/drivers/tty/serial/owl-uart.c
3486 @@ -680,6 +680,12 @@ static int owl_uart_probe(struct platform_device *pdev)
3487 return PTR_ERR(owl_port->clk);
3488 }
3489
3490 + ret = clk_prepare_enable(owl_port->clk);
3491 + if (ret) {
3492 + dev_err(&pdev->dev, "could not enable clk\n");
3493 + return ret;
3494 + }
3495 +
3496 owl_port->port.dev = &pdev->dev;
3497 owl_port->port.line = pdev->id;
3498 owl_port->port.type = PORT_OWL;
3499 @@ -712,6 +718,7 @@ static int owl_uart_remove(struct platform_device *pdev)
3500
3501 uart_remove_one_port(&owl_uart_driver, &owl_port->port);
3502 owl_uart_ports[pdev->id] = NULL;
3503 + clk_disable_unprepare(owl_port->clk);
3504
3505 return 0;
3506 }
3507 diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c
3508 index 22e5d4e13714..7d1529b11ae9 100644
3509 --- a/drivers/tty/serial/sh-sci.c
3510 +++ b/drivers/tty/serial/sh-sci.c
3511 @@ -873,9 +873,16 @@ static void sci_receive_chars(struct uart_port *port)
3512 tty_insert_flip_char(tport, c, TTY_NORMAL);
3513 } else {
3514 for (i = 0; i < count; i++) {
3515 - char c = serial_port_in(port, SCxRDR);
3516 -
3517 - status = serial_port_in(port, SCxSR);
3518 + char c;
3519 +
3520 + if (port->type == PORT_SCIF ||
3521 + port->type == PORT_HSCIF) {
3522 + status = serial_port_in(port, SCxSR);
3523 + c = serial_port_in(port, SCxRDR);
3524 + } else {
3525 + c = serial_port_in(port, SCxRDR);
3526 + status = serial_port_in(port, SCxSR);
3527 + }
3528 if (uart_handle_sysrq_char(port, c)) {
3529 count--; i--;
3530 continue;
3531 diff --git a/drivers/tty/serial/xilinx_uartps.c b/drivers/tty/serial/xilinx_uartps.c
3532 index 4e55bc327a54..fe098cf14e6a 100644
3533 --- a/drivers/tty/serial/xilinx_uartps.c
3534 +++ b/drivers/tty/serial/xilinx_uartps.c
3535 @@ -30,13 +30,15 @@
3536
3537 #define CDNS_UART_TTY_NAME "ttyPS"
3538 #define CDNS_UART_NAME "xuartps"
3539 +#define CDNS_UART_MAJOR 0 /* use dynamic node allocation */
3540 +#define CDNS_UART_MINOR 0 /* works best with devtmpfs */
3541 +#define CDNS_UART_NR_PORTS 16
3542 #define CDNS_UART_FIFO_SIZE 64 /* FIFO size */
3543 #define CDNS_UART_REGISTER_SPACE 0x1000
3544 #define TX_TIMEOUT 500000
3545
3546 /* Rx Trigger level */
3547 static int rx_trigger_level = 56;
3548 -static int uartps_major;
3549 module_param(rx_trigger_level, uint, 0444);
3550 MODULE_PARM_DESC(rx_trigger_level, "Rx trigger level, 1-63 bytes");
3551
3552 @@ -182,7 +184,6 @@ MODULE_PARM_DESC(rx_timeout, "Rx timeout, 1-255");
3553 * @pclk: APB clock
3554 * @cdns_uart_driver: Pointer to UART driver
3555 * @baud: Current baud rate
3556 - * @id: Port ID
3557 * @clk_rate_change_nb: Notifier block for clock changes
3558 * @quirks: Flags for RXBS support.
3559 */
3560 @@ -192,7 +193,6 @@ struct cdns_uart {
3561 struct clk *pclk;
3562 struct uart_driver *cdns_uart_driver;
3563 unsigned int baud;
3564 - int id;
3565 struct notifier_block clk_rate_change_nb;
3566 u32 quirks;
3567 bool cts_override;
3568 @@ -1119,6 +1119,8 @@ static const struct uart_ops cdns_uart_ops = {
3569 #endif
3570 };
3571
3572 +static struct uart_driver cdns_uart_uart_driver;
3573 +
3574 #ifdef CONFIG_SERIAL_XILINX_PS_UART_CONSOLE
3575 /**
3576 * cdns_uart_console_putchar - write the character to the FIFO buffer
3577 @@ -1258,6 +1260,16 @@ static int cdns_uart_console_setup(struct console *co, char *options)
3578
3579 return uart_set_options(port, co, baud, parity, bits, flow);
3580 }
3581 +
3582 +static struct console cdns_uart_console = {
3583 + .name = CDNS_UART_TTY_NAME,
3584 + .write = cdns_uart_console_write,
3585 + .device = uart_console_device,
3586 + .setup = cdns_uart_console_setup,
3587 + .flags = CON_PRINTBUFFER,
3588 + .index = -1, /* Specified on the cmdline (e.g. console=ttyPS ) */
3589 + .data = &cdns_uart_uart_driver,
3590 +};
3591 #endif /* CONFIG_SERIAL_XILINX_PS_UART_CONSOLE */
3592
3593 #ifdef CONFIG_PM_SLEEP
3594 @@ -1389,89 +1401,8 @@ static const struct of_device_id cdns_uart_of_match[] = {
3595 };
3596 MODULE_DEVICE_TABLE(of, cdns_uart_of_match);
3597
3598 -/*
3599 - * Maximum number of instances without alias IDs but if there is alias
3600 - * which target "< MAX_UART_INSTANCES" range this ID can't be used.
3601 - */
3602 -#define MAX_UART_INSTANCES 32
3603 -
3604 -/* Stores static aliases list */
3605 -static DECLARE_BITMAP(alias_bitmap, MAX_UART_INSTANCES);
3606 -static int alias_bitmap_initialized;
3607 -
3608 -/* Stores actual bitmap of allocated IDs with alias IDs together */
3609 -static DECLARE_BITMAP(bitmap, MAX_UART_INSTANCES);
3610 -/* Protect bitmap operations to have unique IDs */
3611 -static DEFINE_MUTEX(bitmap_lock);
3612 -
3613 -static int cdns_get_id(struct platform_device *pdev)
3614 -{
3615 - int id, ret;
3616 -
3617 - mutex_lock(&bitmap_lock);
3618 -
3619 - /* Alias list is stable that's why get alias bitmap only once */
3620 - if (!alias_bitmap_initialized) {
3621 - ret = of_alias_get_alias_list(cdns_uart_of_match, "serial",
3622 - alias_bitmap, MAX_UART_INSTANCES);
3623 - if (ret && ret != -EOVERFLOW) {
3624 - mutex_unlock(&bitmap_lock);
3625 - return ret;
3626 - }
3627 -
3628 - alias_bitmap_initialized++;
3629 - }
3630 -
3631 - /* Make sure that alias ID is not taken by instance without alias */
3632 - bitmap_or(bitmap, bitmap, alias_bitmap, MAX_UART_INSTANCES);
3633 -
3634 - dev_dbg(&pdev->dev, "Alias bitmap: %*pb\n",
3635 - MAX_UART_INSTANCES, bitmap);
3636 -
3637 - /* Look for a serialN alias */
3638 - id = of_alias_get_id(pdev->dev.of_node, "serial");
3639 - if (id < 0) {
3640 - dev_warn(&pdev->dev,
3641 - "No serial alias passed. Using the first free id\n");
3642 -
3643 - /*
3644 - * Start with id 0 and check if there is no serial0 alias
3645 - * which points to device which is compatible with this driver.
3646 - * If alias exists then try next free position.
3647 - */
3648 - id = 0;
3649 -
3650 - for (;;) {
3651 - dev_info(&pdev->dev, "Checking id %d\n", id);
3652 - id = find_next_zero_bit(bitmap, MAX_UART_INSTANCES, id);
3653 -
3654 - /* No free empty instance */
3655 - if (id == MAX_UART_INSTANCES) {
3656 - dev_err(&pdev->dev, "No free ID\n");
3657 - mutex_unlock(&bitmap_lock);
3658 - return -EINVAL;
3659 - }
3660 -
3661 - dev_dbg(&pdev->dev, "The empty id is %d\n", id);
3662 - /* Check if ID is empty */
3663 - if (!test_and_set_bit(id, bitmap)) {
3664 - /* Break the loop if bit is taken */
3665 - dev_dbg(&pdev->dev,
3666 - "Selected ID %d allocation passed\n",
3667 - id);
3668 - break;
3669 - }
3670 - dev_dbg(&pdev->dev,
3671 - "Selected ID %d allocation failed\n", id);
3672 - /* if taking bit fails then try next one */
3673 - id++;
3674 - }
3675 - }
3676 -
3677 - mutex_unlock(&bitmap_lock);
3678 -
3679 - return id;
3680 -}
3681 +/* Temporary variable for storing number of instances */
3682 +static int instances;
3683
3684 /**
3685 * cdns_uart_probe - Platform driver probe
3686 @@ -1481,16 +1412,11 @@ static int cdns_get_id(struct platform_device *pdev)
3687 */
3688 static int cdns_uart_probe(struct platform_device *pdev)
3689 {
3690 - int rc, irq;
3691 + int rc, id, irq;
3692 struct uart_port *port;
3693 struct resource *res;
3694 struct cdns_uart *cdns_uart_data;
3695 const struct of_device_id *match;
3696 - struct uart_driver *cdns_uart_uart_driver;
3697 - char *driver_name;
3698 -#ifdef CONFIG_SERIAL_XILINX_PS_UART_CONSOLE
3699 - struct console *cdns_uart_console;
3700 -#endif
3701
3702 cdns_uart_data = devm_kzalloc(&pdev->dev, sizeof(*cdns_uart_data),
3703 GFP_KERNEL);
3704 @@ -1500,64 +1426,35 @@ static int cdns_uart_probe(struct platform_device *pdev)
3705 if (!port)
3706 return -ENOMEM;
3707
3708 - cdns_uart_uart_driver = devm_kzalloc(&pdev->dev,
3709 - sizeof(*cdns_uart_uart_driver),
3710 - GFP_KERNEL);
3711 - if (!cdns_uart_uart_driver)
3712 - return -ENOMEM;
3713 -
3714 - cdns_uart_data->id = cdns_get_id(pdev);
3715 - if (cdns_uart_data->id < 0)
3716 - return cdns_uart_data->id;
3717 + /* Look for a serialN alias */
3718 + id = of_alias_get_id(pdev->dev.of_node, "serial");
3719 + if (id < 0)
3720 + id = 0;
3721
3722 - /* There is a need to use unique driver name */
3723 - driver_name = devm_kasprintf(&pdev->dev, GFP_KERNEL, "%s%d",
3724 - CDNS_UART_NAME, cdns_uart_data->id);
3725 - if (!driver_name) {
3726 - rc = -ENOMEM;
3727 - goto err_out_id;
3728 + if (id >= CDNS_UART_NR_PORTS) {
3729 + dev_err(&pdev->dev, "Cannot get uart_port structure\n");
3730 + return -ENODEV;
3731 }
3732
3733 - cdns_uart_uart_driver->owner = THIS_MODULE;
3734 - cdns_uart_uart_driver->driver_name = driver_name;
3735 - cdns_uart_uart_driver->dev_name = CDNS_UART_TTY_NAME;
3736 - cdns_uart_uart_driver->major = uartps_major;
3737 - cdns_uart_uart_driver->minor = cdns_uart_data->id;
3738 - cdns_uart_uart_driver->nr = 1;
3739 -
3740 + if (!cdns_uart_uart_driver.state) {
3741 + cdns_uart_uart_driver.owner = THIS_MODULE;
3742 + cdns_uart_uart_driver.driver_name = CDNS_UART_NAME;
3743 + cdns_uart_uart_driver.dev_name = CDNS_UART_TTY_NAME;
3744 + cdns_uart_uart_driver.major = CDNS_UART_MAJOR;
3745 + cdns_uart_uart_driver.minor = CDNS_UART_MINOR;
3746 + cdns_uart_uart_driver.nr = CDNS_UART_NR_PORTS;
3747 #ifdef CONFIG_SERIAL_XILINX_PS_UART_CONSOLE
3748 - cdns_uart_console = devm_kzalloc(&pdev->dev, sizeof(*cdns_uart_console),
3749 - GFP_KERNEL);
3750 - if (!cdns_uart_console) {
3751 - rc = -ENOMEM;
3752 - goto err_out_id;
3753 - }
3754 -
3755 - strncpy(cdns_uart_console->name, CDNS_UART_TTY_NAME,
3756 - sizeof(cdns_uart_console->name));
3757 - cdns_uart_console->index = cdns_uart_data->id;
3758 - cdns_uart_console->write = cdns_uart_console_write;
3759 - cdns_uart_console->device = uart_console_device;
3760 - cdns_uart_console->setup = cdns_uart_console_setup;
3761 - cdns_uart_console->flags = CON_PRINTBUFFER;
3762 - cdns_uart_console->data = cdns_uart_uart_driver;
3763 - cdns_uart_uart_driver->cons = cdns_uart_console;
3764 + cdns_uart_uart_driver.cons = &cdns_uart_console;
3765 #endif
3766
3767 - rc = uart_register_driver(cdns_uart_uart_driver);
3768 - if (rc < 0) {
3769 - dev_err(&pdev->dev, "Failed to register driver\n");
3770 - goto err_out_id;
3771 + rc = uart_register_driver(&cdns_uart_uart_driver);
3772 + if (rc < 0) {
3773 + dev_err(&pdev->dev, "Failed to register driver\n");
3774 + return rc;
3775 + }
3776 }
3777
3778 - cdns_uart_data->cdns_uart_driver = cdns_uart_uart_driver;
3779 -
3780 - /*
3781 - * Setting up proper name_base needs to be done after uart
3782 - * registration because tty_driver structure is not filled.
3783 - * name_base is 0 by default.
3784 - */
3785 - cdns_uart_uart_driver->tty_driver->name_base = cdns_uart_data->id;
3786 + cdns_uart_data->cdns_uart_driver = &cdns_uart_uart_driver;
3787
3788 match = of_match_node(cdns_uart_of_match, pdev->dev.of_node);
3789 if (match && match->data) {
3790 @@ -1634,6 +1531,7 @@ static int cdns_uart_probe(struct platform_device *pdev)
3791 port->flags = UPF_BOOT_AUTOCONF;
3792 port->ops = &cdns_uart_ops;
3793 port->fifosize = CDNS_UART_FIFO_SIZE;
3794 + port->line = id;
3795
3796 /*
3797 * Register the port.
3798 @@ -1665,7 +1563,7 @@ static int cdns_uart_probe(struct platform_device *pdev)
3799 console_port = port;
3800 #endif
3801
3802 - rc = uart_add_one_port(cdns_uart_uart_driver, port);
3803 + rc = uart_add_one_port(&cdns_uart_uart_driver, port);
3804 if (rc) {
3805 dev_err(&pdev->dev,
3806 "uart_add_one_port() failed; err=%i\n", rc);
3807 @@ -1675,13 +1573,15 @@ static int cdns_uart_probe(struct platform_device *pdev)
3808 #ifdef CONFIG_SERIAL_XILINX_PS_UART_CONSOLE
3809 /* This is not port which is used for console that's why clean it up */
3810 if (console_port == port &&
3811 - !(cdns_uart_uart_driver->cons->flags & CON_ENABLED))
3812 + !(cdns_uart_uart_driver.cons->flags & CON_ENABLED))
3813 console_port = NULL;
3814 #endif
3815
3816 - uartps_major = cdns_uart_uart_driver->tty_driver->major;
3817 cdns_uart_data->cts_override = of_property_read_bool(pdev->dev.of_node,
3818 "cts-override");
3819 +
3820 + instances++;
3821 +
3822 return 0;
3823
3824 err_out_pm_disable:
3825 @@ -1697,12 +1597,8 @@ err_out_clk_disable:
3826 err_out_clk_dis_pclk:
3827 clk_disable_unprepare(cdns_uart_data->pclk);
3828 err_out_unregister_driver:
3829 - uart_unregister_driver(cdns_uart_data->cdns_uart_driver);
3830 -err_out_id:
3831 - mutex_lock(&bitmap_lock);
3832 - if (cdns_uart_data->id < MAX_UART_INSTANCES)
3833 - clear_bit(cdns_uart_data->id, bitmap);
3834 - mutex_unlock(&bitmap_lock);
3835 + if (!instances)
3836 + uart_unregister_driver(cdns_uart_data->cdns_uart_driver);
3837 return rc;
3838 }
3839
3840 @@ -1725,10 +1621,6 @@ static int cdns_uart_remove(struct platform_device *pdev)
3841 #endif
3842 rc = uart_remove_one_port(cdns_uart_data->cdns_uart_driver, port);
3843 port->mapbase = 0;
3844 - mutex_lock(&bitmap_lock);
3845 - if (cdns_uart_data->id < MAX_UART_INSTANCES)
3846 - clear_bit(cdns_uart_data->id, bitmap);
3847 - mutex_unlock(&bitmap_lock);
3848 clk_disable_unprepare(cdns_uart_data->uartclk);
3849 clk_disable_unprepare(cdns_uart_data->pclk);
3850 pm_runtime_disable(&pdev->dev);
3851 @@ -1741,13 +1633,8 @@ static int cdns_uart_remove(struct platform_device *pdev)
3852 console_port = NULL;
3853 #endif
3854
3855 - /* If this is last instance major number should be initialized */
3856 - mutex_lock(&bitmap_lock);
3857 - if (bitmap_empty(bitmap, MAX_UART_INSTANCES))
3858 - uartps_major = 0;
3859 - mutex_unlock(&bitmap_lock);
3860 -
3861 - uart_unregister_driver(cdns_uart_data->cdns_uart_driver);
3862 + if (!--instances)
3863 + uart_unregister_driver(cdns_uart_data->cdns_uart_driver);
3864 return rc;
3865 }
3866
3867 diff --git a/drivers/tty/vt/vt.c b/drivers/tty/vt/vt.c
3868 index fa9433e6cdc7..8b3ecef50394 100644
3869 --- a/drivers/tty/vt/vt.c
3870 +++ b/drivers/tty/vt/vt.c
3871 @@ -81,6 +81,7 @@
3872 #include <linux/errno.h>
3873 #include <linux/kd.h>
3874 #include <linux/slab.h>
3875 +#include <linux/vmalloc.h>
3876 #include <linux/major.h>
3877 #include <linux/mm.h>
3878 #include <linux/console.h>
3879 @@ -350,7 +351,7 @@ static struct uni_screen *vc_uniscr_alloc(unsigned int cols, unsigned int rows)
3880 /* allocate everything in one go */
3881 memsize = cols * rows * sizeof(char32_t);
3882 memsize += rows * sizeof(char32_t *);
3883 - p = kmalloc(memsize, GFP_KERNEL);
3884 + p = vmalloc(memsize);
3885 if (!p)
3886 return NULL;
3887
3888 @@ -366,7 +367,7 @@ static struct uni_screen *vc_uniscr_alloc(unsigned int cols, unsigned int rows)
3889
3890 static void vc_uniscr_set(struct vc_data *vc, struct uni_screen *new_uniscr)
3891 {
3892 - kfree(vc->vc_uni_screen);
3893 + vfree(vc->vc_uni_screen);
3894 vc->vc_uni_screen = new_uniscr;
3895 }
3896
3897 @@ -1206,7 +1207,7 @@ static int vc_do_resize(struct tty_struct *tty, struct vc_data *vc,
3898 if (new_cols == vc->vc_cols && new_rows == vc->vc_rows)
3899 return 0;
3900
3901 - if (new_screen_size > (4 << 20))
3902 + if (new_screen_size > KMALLOC_MAX_SIZE)
3903 return -EINVAL;
3904 newscreen = kzalloc(new_screen_size, GFP_USER);
3905 if (!newscreen)
3906 diff --git a/drivers/usb/class/cdc-acm.c b/drivers/usb/class/cdc-acm.c
3907 index 84d6f7df09a4..8ca72d80501d 100644
3908 --- a/drivers/usb/class/cdc-acm.c
3909 +++ b/drivers/usb/class/cdc-acm.c
3910 @@ -412,9 +412,12 @@ static void acm_ctrl_irq(struct urb *urb)
3911
3912 exit:
3913 retval = usb_submit_urb(urb, GFP_ATOMIC);
3914 - if (retval && retval != -EPERM)
3915 + if (retval && retval != -EPERM && retval != -ENODEV)
3916 dev_err(&acm->control->dev,
3917 "%s - usb_submit_urb failed: %d\n", __func__, retval);
3918 + else
3919 + dev_vdbg(&acm->control->dev,
3920 + "control resubmission terminated %d\n", retval);
3921 }
3922
3923 static int acm_submit_read_urb(struct acm *acm, int index, gfp_t mem_flags)
3924 @@ -430,6 +433,8 @@ static int acm_submit_read_urb(struct acm *acm, int index, gfp_t mem_flags)
3925 dev_err(&acm->data->dev,
3926 "urb %d failed submission with %d\n",
3927 index, res);
3928 + } else {
3929 + dev_vdbg(&acm->data->dev, "intended failure %d\n", res);
3930 }
3931 set_bit(index, &acm->read_urbs_free);
3932 return res;
3933 @@ -471,6 +476,7 @@ static void acm_read_bulk_callback(struct urb *urb)
3934 int status = urb->status;
3935 bool stopped = false;
3936 bool stalled = false;
3937 + bool cooldown = false;
3938
3939 dev_vdbg(&acm->data->dev, "got urb %d, len %d, status %d\n",
3940 rb->index, urb->actual_length, status);
3941 @@ -497,6 +503,14 @@ static void acm_read_bulk_callback(struct urb *urb)
3942 __func__, status);
3943 stopped = true;
3944 break;
3945 + case -EOVERFLOW:
3946 + case -EPROTO:
3947 + dev_dbg(&acm->data->dev,
3948 + "%s - cooling babbling device\n", __func__);
3949 + usb_mark_last_busy(acm->dev);
3950 + set_bit(rb->index, &acm->urbs_in_error_delay);
3951 + cooldown = true;
3952 + break;
3953 default:
3954 dev_dbg(&acm->data->dev,
3955 "%s - nonzero urb status received: %d\n",
3956 @@ -518,9 +532,11 @@ static void acm_read_bulk_callback(struct urb *urb)
3957 */
3958 smp_mb__after_atomic();
3959
3960 - if (stopped || stalled) {
3961 + if (stopped || stalled || cooldown) {
3962 if (stalled)
3963 schedule_work(&acm->work);
3964 + else if (cooldown)
3965 + schedule_delayed_work(&acm->dwork, HZ / 2);
3966 return;
3967 }
3968
3969 @@ -557,14 +573,20 @@ static void acm_softint(struct work_struct *work)
3970 struct acm *acm = container_of(work, struct acm, work);
3971
3972 if (test_bit(EVENT_RX_STALL, &acm->flags)) {
3973 - if (!(usb_autopm_get_interface(acm->data))) {
3974 + smp_mb(); /* against acm_suspend() */
3975 + if (!acm->susp_count) {
3976 for (i = 0; i < acm->rx_buflimit; i++)
3977 usb_kill_urb(acm->read_urbs[i]);
3978 usb_clear_halt(acm->dev, acm->in);
3979 acm_submit_read_urbs(acm, GFP_KERNEL);
3980 - usb_autopm_put_interface(acm->data);
3981 + clear_bit(EVENT_RX_STALL, &acm->flags);
3982 }
3983 - clear_bit(EVENT_RX_STALL, &acm->flags);
3984 + }
3985 +
3986 + if (test_and_clear_bit(ACM_ERROR_DELAY, &acm->flags)) {
3987 + for (i = 0; i < ACM_NR; i++)
3988 + if (test_and_clear_bit(i, &acm->urbs_in_error_delay))
3989 + acm_submit_read_urb(acm, i, GFP_NOIO);
3990 }
3991
3992 if (test_and_clear_bit(EVENT_TTY_WAKEUP, &acm->flags))
3993 @@ -1333,6 +1355,7 @@ made_compressed_probe:
3994 acm->readsize = readsize;
3995 acm->rx_buflimit = num_rx_buf;
3996 INIT_WORK(&acm->work, acm_softint);
3997 + INIT_DELAYED_WORK(&acm->dwork, acm_softint);
3998 init_waitqueue_head(&acm->wioctl);
3999 spin_lock_init(&acm->write_lock);
4000 spin_lock_init(&acm->read_lock);
4001 @@ -1542,6 +1565,7 @@ static void acm_disconnect(struct usb_interface *intf)
4002
4003 acm_kill_urbs(acm);
4004 cancel_work_sync(&acm->work);
4005 + cancel_delayed_work_sync(&acm->dwork);
4006
4007 tty_unregister_device(acm_tty_driver, acm->minor);
4008
4009 @@ -1584,6 +1608,8 @@ static int acm_suspend(struct usb_interface *intf, pm_message_t message)
4010
4011 acm_kill_urbs(acm);
4012 cancel_work_sync(&acm->work);
4013 + cancel_delayed_work_sync(&acm->dwork);
4014 + acm->urbs_in_error_delay = 0;
4015
4016 return 0;
4017 }
4018 diff --git a/drivers/usb/class/cdc-acm.h b/drivers/usb/class/cdc-acm.h
4019 index ca1c026382c2..cd5e9d8ab237 100644
4020 --- a/drivers/usb/class/cdc-acm.h
4021 +++ b/drivers/usb/class/cdc-acm.h
4022 @@ -109,8 +109,11 @@ struct acm {
4023 # define EVENT_TTY_WAKEUP 0
4024 # define EVENT_RX_STALL 1
4025 # define ACM_THROTTLED 2
4026 +# define ACM_ERROR_DELAY 3
4027 + unsigned long urbs_in_error_delay; /* these need to be restarted after a delay */
4028 struct usb_cdc_line_coding line; /* bits, stop, parity */
4029 - struct work_struct work; /* work queue entry for line discipline waking up */
4030 + struct work_struct work; /* work queue entry for various purposes*/
4031 + struct delayed_work dwork; /* for cool downs needed in error recovery */
4032 unsigned int ctrlin; /* input control lines (DCD, DSR, RI, break, overruns) */
4033 unsigned int ctrlout; /* output control lines (DTR, RTS) */
4034 struct async_icount iocount; /* counters for control line changes */
4035 diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
4036 index 243577656177..847c85430b05 100644
4037 --- a/drivers/usb/core/hub.c
4038 +++ b/drivers/usb/core/hub.c
4039 @@ -1222,6 +1222,11 @@ static void hub_activate(struct usb_hub *hub, enum hub_activation_type type)
4040 #ifdef CONFIG_PM
4041 udev->reset_resume = 1;
4042 #endif
4043 + /* Don't set the change_bits when the device
4044 + * was powered off.
4045 + */
4046 + if (test_bit(port1, hub->power_bits))
4047 + set_bit(port1, hub->change_bits);
4048
4049 } else {
4050 /* The power session is gone; tell hub_wq */
4051 @@ -2722,13 +2727,11 @@ static bool use_new_scheme(struct usb_device *udev, int retry,
4052 {
4053 int old_scheme_first_port =
4054 port_dev->quirks & USB_PORT_QUIRK_OLD_SCHEME;
4055 - int quick_enumeration = (udev->speed == USB_SPEED_HIGH);
4056
4057 if (udev->speed >= USB_SPEED_SUPER)
4058 return false;
4059
4060 - return USE_NEW_SCHEME(retry, old_scheme_first_port || old_scheme_first
4061 - || quick_enumeration);
4062 + return USE_NEW_SCHEME(retry, old_scheme_first_port || old_scheme_first);
4063 }
4064
4065 /* Is a USB 3.0 port in the Inactive or Compliance Mode state?
4066 @@ -3087,6 +3090,15 @@ static int check_port_resume_type(struct usb_device *udev,
4067 if (portchange & USB_PORT_STAT_C_ENABLE)
4068 usb_clear_port_feature(hub->hdev, port1,
4069 USB_PORT_FEAT_C_ENABLE);
4070 +
4071 + /*
4072 + * Whatever made this reset-resume necessary may have
4073 + * turned on the port1 bit in hub->change_bits. But after
4074 + * a successful reset-resume we want the bit to be clear;
4075 + * if it was on it would indicate that something happened
4076 + * following the reset-resume.
4077 + */
4078 + clear_bit(port1, hub->change_bits);
4079 }
4080
4081 return status;
4082 diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c
4083 index 5adf489428aa..02eaac7e1e34 100644
4084 --- a/drivers/usb/core/message.c
4085 +++ b/drivers/usb/core/message.c
4086 @@ -588,12 +588,13 @@ void usb_sg_cancel(struct usb_sg_request *io)
4087 int i, retval;
4088
4089 spin_lock_irqsave(&io->lock, flags);
4090 - if (io->status) {
4091 + if (io->status || io->count == 0) {
4092 spin_unlock_irqrestore(&io->lock, flags);
4093 return;
4094 }
4095 /* shut everything down */
4096 io->status = -ECONNRESET;
4097 + io->count++; /* Keep the request alive until we're done */
4098 spin_unlock_irqrestore(&io->lock, flags);
4099
4100 for (i = io->entries - 1; i >= 0; --i) {
4101 @@ -607,6 +608,12 @@ void usb_sg_cancel(struct usb_sg_request *io)
4102 dev_warn(&io->dev->dev, "%s, unlink --> %d\n",
4103 __func__, retval);
4104 }
4105 +
4106 + spin_lock_irqsave(&io->lock, flags);
4107 + io->count--;
4108 + if (!io->count)
4109 + complete(&io->complete);
4110 + spin_unlock_irqrestore(&io->lock, flags);
4111 }
4112 EXPORT_SYMBOL_GPL(usb_sg_cancel);
4113
4114 diff --git a/drivers/usb/core/quirks.c b/drivers/usb/core/quirks.c
4115 index da30b5664ff3..3e8efe759c3e 100644
4116 --- a/drivers/usb/core/quirks.c
4117 +++ b/drivers/usb/core/quirks.c
4118 @@ -430,6 +430,10 @@ static const struct usb_device_id usb_quirk_list[] = {
4119 /* Corsair K70 LUX */
4120 { USB_DEVICE(0x1b1c, 0x1b36), .driver_info = USB_QUIRK_DELAY_INIT },
4121
4122 + /* Corsair K70 RGB RAPDIFIRE */
4123 + { USB_DEVICE(0x1b1c, 0x1b38), .driver_info = USB_QUIRK_DELAY_INIT |
4124 + USB_QUIRK_DELAY_CTRL_MSG },
4125 +
4126 /* MIDI keyboard WORLDE MINI */
4127 { USB_DEVICE(0x1c75, 0x0204), .driver_info =
4128 USB_QUIRK_CONFIG_INTF_STRINGS },
4129 diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
4130 index 384f26322609..18251efd216d 100644
4131 --- a/drivers/usb/dwc3/gadget.c
4132 +++ b/drivers/usb/dwc3/gadget.c
4133 @@ -2481,14 +2481,7 @@ static int dwc3_gadget_ep_reclaim_trb_linear(struct dwc3_ep *dep,
4134
4135 static bool dwc3_gadget_ep_request_completed(struct dwc3_request *req)
4136 {
4137 - /*
4138 - * For OUT direction, host may send less than the setup
4139 - * length. Return true for all OUT requests.
4140 - */
4141 - if (!req->direction)
4142 - return true;
4143 -
4144 - return req->request.actual == req->request.length;
4145 + return req->num_pending_sgs == 0;
4146 }
4147
4148 static int dwc3_gadget_ep_cleanup_completed_request(struct dwc3_ep *dep,
4149 @@ -2512,8 +2505,7 @@ static int dwc3_gadget_ep_cleanup_completed_request(struct dwc3_ep *dep,
4150
4151 req->request.actual = req->request.length - req->remaining;
4152
4153 - if (!dwc3_gadget_ep_request_completed(req) ||
4154 - req->num_pending_sgs) {
4155 + if (!dwc3_gadget_ep_request_completed(req)) {
4156 __dwc3_gadget_kick_transfer(dep);
4157 goto out;
4158 }
4159 diff --git a/drivers/usb/early/xhci-dbc.c b/drivers/usb/early/xhci-dbc.c
4160 index cac991173ac0..5a462a1d1896 100644
4161 --- a/drivers/usb/early/xhci-dbc.c
4162 +++ b/drivers/usb/early/xhci-dbc.c
4163 @@ -728,19 +728,19 @@ static void xdbc_handle_tx_event(struct xdbc_trb *evt_trb)
4164 case COMP_USB_TRANSACTION_ERROR:
4165 case COMP_STALL_ERROR:
4166 default:
4167 - if (ep_id == XDBC_EPID_OUT)
4168 + if (ep_id == XDBC_EPID_OUT || ep_id == XDBC_EPID_OUT_INTEL)
4169 xdbc.flags |= XDBC_FLAGS_OUT_STALL;
4170 - if (ep_id == XDBC_EPID_IN)
4171 + if (ep_id == XDBC_EPID_IN || ep_id == XDBC_EPID_IN_INTEL)
4172 xdbc.flags |= XDBC_FLAGS_IN_STALL;
4173
4174 xdbc_trace("endpoint %d stalled\n", ep_id);
4175 break;
4176 }
4177
4178 - if (ep_id == XDBC_EPID_IN) {
4179 + if (ep_id == XDBC_EPID_IN || ep_id == XDBC_EPID_IN_INTEL) {
4180 xdbc.flags &= ~XDBC_FLAGS_IN_PROCESS;
4181 xdbc_bulk_transfer(NULL, XDBC_MAX_PACKET, true);
4182 - } else if (ep_id == XDBC_EPID_OUT) {
4183 + } else if (ep_id == XDBC_EPID_OUT || ep_id == XDBC_EPID_OUT_INTEL) {
4184 xdbc.flags &= ~XDBC_FLAGS_OUT_PROCESS;
4185 } else {
4186 xdbc_trace("invalid endpoint id %d\n", ep_id);
4187 diff --git a/drivers/usb/early/xhci-dbc.h b/drivers/usb/early/xhci-dbc.h
4188 index 673686eeddd7..6e2b7266a695 100644
4189 --- a/drivers/usb/early/xhci-dbc.h
4190 +++ b/drivers/usb/early/xhci-dbc.h
4191 @@ -120,8 +120,22 @@ struct xdbc_ring {
4192 u32 cycle_state;
4193 };
4194
4195 -#define XDBC_EPID_OUT 2
4196 -#define XDBC_EPID_IN 3
4197 +/*
4198 + * These are the "Endpoint ID" (also known as "Context Index") values for the
4199 + * OUT Transfer Ring and the IN Transfer Ring of a Debug Capability Context data
4200 + * structure.
4201 + * According to the "eXtensible Host Controller Interface for Universal Serial
4202 + * Bus (xHCI)" specification, section "7.6.3.2 Endpoint Contexts and Transfer
4203 + * Rings", these should be 0 and 1, and those are the values AMD machines give
4204 + * you; but Intel machines seem to use the formula from section "4.5.1 Device
4205 + * Context Index", which is supposed to be used for the Device Context only.
4206 + * Luckily the values from Intel don't overlap with those from AMD, so we can
4207 + * just test for both.
4208 + */
4209 +#define XDBC_EPID_OUT 0
4210 +#define XDBC_EPID_IN 1
4211 +#define XDBC_EPID_OUT_INTEL 2
4212 +#define XDBC_EPID_IN_INTEL 3
4213
4214 struct xdbc_state {
4215 u16 vendor;
4216 diff --git a/drivers/usb/gadget/function/f_fs.c b/drivers/usb/gadget/function/f_fs.c
4217 index 87fdeb042c67..f8bcfc506f4a 100644
4218 --- a/drivers/usb/gadget/function/f_fs.c
4219 +++ b/drivers/usb/gadget/function/f_fs.c
4220 @@ -1828,6 +1828,10 @@ static void ffs_data_reset(struct ffs_data *ffs)
4221 ffs->state = FFS_READ_DESCRIPTORS;
4222 ffs->setup_state = FFS_NO_SETUP;
4223 ffs->flags = 0;
4224 +
4225 + ffs->ms_os_descs_ext_prop_count = 0;
4226 + ffs->ms_os_descs_ext_prop_name_len = 0;
4227 + ffs->ms_os_descs_ext_prop_data_len = 0;
4228 }
4229
4230
4231 diff --git a/drivers/usb/host/xhci-hub.c b/drivers/usb/host/xhci-hub.c
4232 index af92b2576fe9..3196de2931b1 100644
4233 --- a/drivers/usb/host/xhci-hub.c
4234 +++ b/drivers/usb/host/xhci-hub.c
4235 @@ -1306,7 +1306,47 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
4236 wIndex, link_state);
4237 goto error;
4238 }
4239 +
4240 + /*
4241 + * set link to U0, steps depend on current link state.
4242 + * U3: set link to U0 and wait for u3exit completion.
4243 + * U1/U2: no PLC complete event, only set link to U0.
4244 + * Resume/Recovery: device initiated U0, only wait for
4245 + * completion
4246 + */
4247 + if (link_state == USB_SS_PORT_LS_U0) {
4248 + u32 pls = temp & PORT_PLS_MASK;
4249 + bool wait_u0 = false;
4250 +
4251 + /* already in U0 */
4252 + if (pls == XDEV_U0)
4253 + break;
4254 + if (pls == XDEV_U3 ||
4255 + pls == XDEV_RESUME ||
4256 + pls == XDEV_RECOVERY) {
4257 + wait_u0 = true;
4258 + reinit_completion(&bus_state->u3exit_done[wIndex]);
4259 + }
4260 + if (pls <= XDEV_U3) /* U1, U2, U3 */
4261 + xhci_set_link_state(xhci, ports[wIndex],
4262 + USB_SS_PORT_LS_U0);
4263 + if (!wait_u0) {
4264 + if (pls > XDEV_U3)
4265 + goto error;
4266 + break;
4267 + }
4268 + spin_unlock_irqrestore(&xhci->lock, flags);
4269 + if (!wait_for_completion_timeout(&bus_state->u3exit_done[wIndex],
4270 + msecs_to_jiffies(100)))
4271 + xhci_dbg(xhci, "missing U0 port change event for port %d\n",
4272 + wIndex);
4273 + spin_lock_irqsave(&xhci->lock, flags);
4274 + temp = readl(ports[wIndex]->addr);
4275 + break;
4276 + }
4277 +
4278 if (link_state == USB_SS_PORT_LS_U3) {
4279 + int retries = 16;
4280 slot_id = xhci_find_slot_id_by_port(hcd, xhci,
4281 wIndex + 1);
4282 if (slot_id) {
4283 @@ -1317,17 +1357,18 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
4284 xhci_stop_device(xhci, slot_id, 1);
4285 spin_lock_irqsave(&xhci->lock, flags);
4286 }
4287 - }
4288 -
4289 - xhci_set_link_state(xhci, ports[wIndex], link_state);
4290 -
4291 - spin_unlock_irqrestore(&xhci->lock, flags);
4292 - msleep(20); /* wait device to enter */
4293 - spin_lock_irqsave(&xhci->lock, flags);
4294 -
4295 - temp = readl(ports[wIndex]->addr);
4296 - if (link_state == USB_SS_PORT_LS_U3)
4297 + xhci_set_link_state(xhci, ports[wIndex], USB_SS_PORT_LS_U3);
4298 + spin_unlock_irqrestore(&xhci->lock, flags);
4299 + while (retries--) {
4300 + usleep_range(4000, 8000);
4301 + temp = readl(ports[wIndex]->addr);
4302 + if ((temp & PORT_PLS_MASK) == XDEV_U3)
4303 + break;
4304 + }
4305 + spin_lock_irqsave(&xhci->lock, flags);
4306 + temp = readl(ports[wIndex]->addr);
4307 bus_state->suspended_ports |= 1 << wIndex;
4308 + }
4309 break;
4310 case USB_PORT_FEAT_POWER:
4311 /*
4312 @@ -1528,6 +1569,8 @@ int xhci_hub_status_data(struct usb_hcd *hcd, char *buf)
4313 }
4314 if ((temp & PORT_RC))
4315 reset_change = true;
4316 + if (temp & PORT_OC)
4317 + status = 1;
4318 }
4319 if (!status && !reset_change) {
4320 xhci_dbg(xhci, "%s: stopping port polling.\n", __func__);
4321 @@ -1593,6 +1636,13 @@ retry:
4322 port_index);
4323 goto retry;
4324 }
4325 + /* bail out if port detected a over-current condition */
4326 + if (t1 & PORT_OC) {
4327 + bus_state->bus_suspended = 0;
4328 + spin_unlock_irqrestore(&xhci->lock, flags);
4329 + xhci_dbg(xhci, "Bus suspend bailout, port over-current detected\n");
4330 + return -EBUSY;
4331 + }
4332 /* suspend ports in U0, or bail out for new connect changes */
4333 if ((t1 & PORT_PE) && (t1 & PORT_PLS_MASK) == XDEV_U0) {
4334 if ((t1 & PORT_CSC) && wake_enabled) {
4335 diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c
4336 index 884c601bfa15..9764122c9cdf 100644
4337 --- a/drivers/usb/host/xhci-mem.c
4338 +++ b/drivers/usb/host/xhci-mem.c
4339 @@ -2552,6 +2552,7 @@ int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags)
4340 xhci->usb3_rhub.bus_state.resume_done[i] = 0;
4341 /* Only the USB 2.0 completions will ever be used. */
4342 init_completion(&xhci->usb2_rhub.bus_state.rexit_done[i]);
4343 + init_completion(&xhci->usb3_rhub.bus_state.u3exit_done[i]);
4344 }
4345
4346 if (scratchpad_alloc(xhci, flags))
4347 diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c
4348 index f7a190fb2353..a54f8f3234f9 100644
4349 --- a/drivers/usb/host/xhci-ring.c
4350 +++ b/drivers/usb/host/xhci-ring.c
4351 @@ -541,6 +541,23 @@ void xhci_find_new_dequeue_state(struct xhci_hcd *xhci,
4352 stream_id);
4353 return;
4354 }
4355 + /*
4356 + * A cancelled TD can complete with a stall if HW cached the trb.
4357 + * In this case driver can't find cur_td, but if the ring is empty we
4358 + * can move the dequeue pointer to the current enqueue position.
4359 + */
4360 + if (!cur_td) {
4361 + if (list_empty(&ep_ring->td_list)) {
4362 + state->new_deq_seg = ep_ring->enq_seg;
4363 + state->new_deq_ptr = ep_ring->enqueue;
4364 + state->new_cycle_state = ep_ring->cycle_state;
4365 + goto done;
4366 + } else {
4367 + xhci_warn(xhci, "Can't find new dequeue state, missing cur_td\n");
4368 + return;
4369 + }
4370 + }
4371 +
4372 /* Dig out the cycle state saved by the xHC during the stop ep cmd */
4373 xhci_dbg_trace(xhci, trace_xhci_dbg_cancel_urb,
4374 "Finding endpoint context");
4375 @@ -586,6 +603,7 @@ void xhci_find_new_dequeue_state(struct xhci_hcd *xhci,
4376 state->new_deq_seg = new_seg;
4377 state->new_deq_ptr = new_deq;
4378
4379 +done:
4380 /* Don't update the ring cycle state for the producer (us). */
4381 xhci_dbg_trace(xhci, trace_xhci_dbg_cancel_urb,
4382 "Cycle state = 0x%x", state->new_cycle_state);
4383 @@ -1673,6 +1691,7 @@ static void handle_port_status(struct xhci_hcd *xhci,
4384 (portsc & PORT_PLS_MASK) == XDEV_U1 ||
4385 (portsc & PORT_PLS_MASK) == XDEV_U2)) {
4386 xhci_dbg(xhci, "resume SS port %d finished\n", port_id);
4387 + complete(&bus_state->u3exit_done[hcd_portnum]);
4388 /* We've just brought the device into U0/1/2 through either the
4389 * Resume state after a device remote wakeup, or through the
4390 * U3Exit state after a host-initiated resume. If it's a device
4391 @@ -1847,8 +1866,8 @@ static void xhci_cleanup_halted_endpoint(struct xhci_hcd *xhci,
4392
4393 if (reset_type == EP_HARD_RESET) {
4394 ep->ep_state |= EP_HARD_CLEAR_TOGGLE;
4395 - xhci_cleanup_stalled_ring(xhci, ep_index, stream_id, td);
4396 - xhci_clear_hub_tt_buffer(xhci, td, ep);
4397 + xhci_cleanup_stalled_ring(xhci, slot_id, ep_index, stream_id,
4398 + td);
4399 }
4400 xhci_ring_cmd_db(xhci);
4401 }
4402 @@ -1969,11 +1988,18 @@ static int finish_td(struct xhci_hcd *xhci, struct xhci_td *td,
4403 if (trb_comp_code == COMP_STALL_ERROR ||
4404 xhci_requires_manual_halt_cleanup(xhci, ep_ctx,
4405 trb_comp_code)) {
4406 - /* Issue a reset endpoint command to clear the host side
4407 - * halt, followed by a set dequeue command to move the
4408 - * dequeue pointer past the TD.
4409 - * The class driver clears the device side halt later.
4410 + /*
4411 + * xhci internal endpoint state will go to a "halt" state for
4412 + * any stall, including default control pipe protocol stall.
4413 + * To clear the host side halt we need to issue a reset endpoint
4414 + * command, followed by a set dequeue command to move past the
4415 + * TD.
4416 + * Class drivers clear the device side halt from a functional
4417 + * stall later. Hub TT buffer should only be cleared for FS/LS
4418 + * devices behind HS hubs for functional stalls.
4419 */
4420 + if ((ep_index != 0) || (trb_comp_code != COMP_STALL_ERROR))
4421 + xhci_clear_hub_tt_buffer(xhci, td, ep);
4422 xhci_cleanup_halted_endpoint(xhci, slot_id, ep_index,
4423 ep_ring->stream_id, td, EP_HARD_RESET);
4424 } else {
4425 @@ -2526,6 +2552,15 @@ static int handle_tx_event(struct xhci_hcd *xhci,
4426 xhci_dbg(xhci, "td_list is empty while skip flag set. Clear skip flag for slot %u ep %u.\n",
4427 slot_id, ep_index);
4428 }
4429 + if (trb_comp_code == COMP_STALL_ERROR ||
4430 + xhci_requires_manual_halt_cleanup(xhci, ep_ctx,
4431 + trb_comp_code)) {
4432 + xhci_cleanup_halted_endpoint(xhci, slot_id,
4433 + ep_index,
4434 + ep_ring->stream_id,
4435 + NULL,
4436 + EP_HARD_RESET);
4437 + }
4438 goto cleanup;
4439 }
4440
4441 diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c
4442 index 2f49a7b3ce85..81b54a3d2910 100644
4443 --- a/drivers/usb/host/xhci.c
4444 +++ b/drivers/usb/host/xhci.c
4445 @@ -3031,19 +3031,19 @@ static void xhci_setup_input_ctx_for_quirk(struct xhci_hcd *xhci,
4446 added_ctxs, added_ctxs);
4447 }
4448
4449 -void xhci_cleanup_stalled_ring(struct xhci_hcd *xhci, unsigned int ep_index,
4450 - unsigned int stream_id, struct xhci_td *td)
4451 +void xhci_cleanup_stalled_ring(struct xhci_hcd *xhci, unsigned int slot_id,
4452 + unsigned int ep_index, unsigned int stream_id,
4453 + struct xhci_td *td)
4454 {
4455 struct xhci_dequeue_state deq_state;
4456 - struct usb_device *udev = td->urb->dev;
4457
4458 xhci_dbg_trace(xhci, trace_xhci_dbg_reset_ep,
4459 "Cleaning up stalled endpoint ring");
4460 /* We need to move the HW's dequeue pointer past this TD,
4461 * or it will attempt to resend it on the next doorbell ring.
4462 */
4463 - xhci_find_new_dequeue_state(xhci, udev->slot_id,
4464 - ep_index, stream_id, td, &deq_state);
4465 + xhci_find_new_dequeue_state(xhci, slot_id, ep_index, stream_id, td,
4466 + &deq_state);
4467
4468 if (!deq_state.new_deq_ptr || !deq_state.new_deq_seg)
4469 return;
4470 @@ -3054,7 +3054,7 @@ void xhci_cleanup_stalled_ring(struct xhci_hcd *xhci, unsigned int ep_index,
4471 if (!(xhci->quirks & XHCI_RESET_EP_QUIRK)) {
4472 xhci_dbg_trace(xhci, trace_xhci_dbg_reset_ep,
4473 "Queueing new dequeue state");
4474 - xhci_queue_new_dequeue_state(xhci, udev->slot_id,
4475 + xhci_queue_new_dequeue_state(xhci, slot_id,
4476 ep_index, &deq_state);
4477 } else {
4478 /* Better hope no one uses the input context between now and the
4479 @@ -3065,7 +3065,7 @@ void xhci_cleanup_stalled_ring(struct xhci_hcd *xhci, unsigned int ep_index,
4480 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks,
4481 "Setting up input context for "
4482 "configure endpoint command");
4483 - xhci_setup_input_ctx_for_quirk(xhci, udev->slot_id,
4484 + xhci_setup_input_ctx_for_quirk(xhci, slot_id,
4485 ep_index, &deq_state);
4486 }
4487 }
4488 diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h
4489 index 98b98a0cd2a8..23a1abdc2b43 100644
4490 --- a/drivers/usb/host/xhci.h
4491 +++ b/drivers/usb/host/xhci.h
4492 @@ -1694,6 +1694,7 @@ struct xhci_bus_state {
4493 /* Which ports are waiting on RExit to U0 transition. */
4494 unsigned long rexit_ports;
4495 struct completion rexit_done[USB_MAXCHILDREN];
4496 + struct completion u3exit_done[USB_MAXCHILDREN];
4497 };
4498
4499
4500 @@ -2115,8 +2116,9 @@ void xhci_find_new_dequeue_state(struct xhci_hcd *xhci,
4501 void xhci_queue_new_dequeue_state(struct xhci_hcd *xhci,
4502 unsigned int slot_id, unsigned int ep_index,
4503 struct xhci_dequeue_state *deq_state);
4504 -void xhci_cleanup_stalled_ring(struct xhci_hcd *xhci, unsigned int ep_index,
4505 - unsigned int stream_id, struct xhci_td *td);
4506 +void xhci_cleanup_stalled_ring(struct xhci_hcd *xhci, unsigned int slot_id,
4507 + unsigned int ep_index, unsigned int stream_id,
4508 + struct xhci_td *td);
4509 void xhci_stop_endpoint_command_watchdog(struct timer_list *t);
4510 void xhci_handle_command_timeout(struct work_struct *work);
4511
4512 diff --git a/drivers/usb/misc/sisusbvga/sisusb.c b/drivers/usb/misc/sisusbvga/sisusb.c
4513 index 2ab9600d0898..fc8a5da4a07c 100644
4514 --- a/drivers/usb/misc/sisusbvga/sisusb.c
4515 +++ b/drivers/usb/misc/sisusbvga/sisusb.c
4516 @@ -1199,18 +1199,18 @@ static int sisusb_read_mem_bulk(struct sisusb_usb_data *sisusb, u32 addr,
4517 /* High level: Gfx (indexed) register access */
4518
4519 #ifdef CONFIG_USB_SISUSBVGA_CON
4520 -int sisusb_setreg(struct sisusb_usb_data *sisusb, int port, u8 data)
4521 +int sisusb_setreg(struct sisusb_usb_data *sisusb, u32 port, u8 data)
4522 {
4523 return sisusb_write_memio_byte(sisusb, SISUSB_TYPE_IO, port, data);
4524 }
4525
4526 -int sisusb_getreg(struct sisusb_usb_data *sisusb, int port, u8 *data)
4527 +int sisusb_getreg(struct sisusb_usb_data *sisusb, u32 port, u8 *data)
4528 {
4529 return sisusb_read_memio_byte(sisusb, SISUSB_TYPE_IO, port, data);
4530 }
4531 #endif
4532
4533 -int sisusb_setidxreg(struct sisusb_usb_data *sisusb, int port,
4534 +int sisusb_setidxreg(struct sisusb_usb_data *sisusb, u32 port,
4535 u8 index, u8 data)
4536 {
4537 int ret;
4538 @@ -1220,7 +1220,7 @@ int sisusb_setidxreg(struct sisusb_usb_data *sisusb, int port,
4539 return ret;
4540 }
4541
4542 -int sisusb_getidxreg(struct sisusb_usb_data *sisusb, int port,
4543 +int sisusb_getidxreg(struct sisusb_usb_data *sisusb, u32 port,
4544 u8 index, u8 *data)
4545 {
4546 int ret;
4547 @@ -1230,7 +1230,7 @@ int sisusb_getidxreg(struct sisusb_usb_data *sisusb, int port,
4548 return ret;
4549 }
4550
4551 -int sisusb_setidxregandor(struct sisusb_usb_data *sisusb, int port, u8 idx,
4552 +int sisusb_setidxregandor(struct sisusb_usb_data *sisusb, u32 port, u8 idx,
4553 u8 myand, u8 myor)
4554 {
4555 int ret;
4556 @@ -1245,7 +1245,7 @@ int sisusb_setidxregandor(struct sisusb_usb_data *sisusb, int port, u8 idx,
4557 }
4558
4559 static int sisusb_setidxregmask(struct sisusb_usb_data *sisusb,
4560 - int port, u8 idx, u8 data, u8 mask)
4561 + u32 port, u8 idx, u8 data, u8 mask)
4562 {
4563 int ret;
4564 u8 tmp;
4565 @@ -1258,13 +1258,13 @@ static int sisusb_setidxregmask(struct sisusb_usb_data *sisusb,
4566 return ret;
4567 }
4568
4569 -int sisusb_setidxregor(struct sisusb_usb_data *sisusb, int port,
4570 +int sisusb_setidxregor(struct sisusb_usb_data *sisusb, u32 port,
4571 u8 index, u8 myor)
4572 {
4573 return sisusb_setidxregandor(sisusb, port, index, 0xff, myor);
4574 }
4575
4576 -int sisusb_setidxregand(struct sisusb_usb_data *sisusb, int port,
4577 +int sisusb_setidxregand(struct sisusb_usb_data *sisusb, u32 port,
4578 u8 idx, u8 myand)
4579 {
4580 return sisusb_setidxregandor(sisusb, port, idx, myand, 0x00);
4581 @@ -2785,8 +2785,8 @@ static loff_t sisusb_lseek(struct file *file, loff_t offset, int orig)
4582 static int sisusb_handle_command(struct sisusb_usb_data *sisusb,
4583 struct sisusb_command *y, unsigned long arg)
4584 {
4585 - int retval, port, length;
4586 - u32 address;
4587 + int retval, length;
4588 + u32 port, address;
4589
4590 /* All our commands require the device
4591 * to be initialized.
4592 diff --git a/drivers/usb/misc/sisusbvga/sisusb_init.h b/drivers/usb/misc/sisusbvga/sisusb_init.h
4593 index 1782c759c4ad..ace09985dae4 100644
4594 --- a/drivers/usb/misc/sisusbvga/sisusb_init.h
4595 +++ b/drivers/usb/misc/sisusbvga/sisusb_init.h
4596 @@ -812,17 +812,17 @@ static const struct SiS_VCLKData SiSUSB_VCLKData[] = {
4597 int SiSUSBSetMode(struct SiS_Private *SiS_Pr, unsigned short ModeNo);
4598 int SiSUSBSetVESAMode(struct SiS_Private *SiS_Pr, unsigned short VModeNo);
4599
4600 -extern int sisusb_setreg(struct sisusb_usb_data *sisusb, int port, u8 data);
4601 -extern int sisusb_getreg(struct sisusb_usb_data *sisusb, int port, u8 * data);
4602 -extern int sisusb_setidxreg(struct sisusb_usb_data *sisusb, int port,
4603 +extern int sisusb_setreg(struct sisusb_usb_data *sisusb, u32 port, u8 data);
4604 +extern int sisusb_getreg(struct sisusb_usb_data *sisusb, u32 port, u8 * data);
4605 +extern int sisusb_setidxreg(struct sisusb_usb_data *sisusb, u32 port,
4606 u8 index, u8 data);
4607 -extern int sisusb_getidxreg(struct sisusb_usb_data *sisusb, int port,
4608 +extern int sisusb_getidxreg(struct sisusb_usb_data *sisusb, u32 port,
4609 u8 index, u8 * data);
4610 -extern int sisusb_setidxregandor(struct sisusb_usb_data *sisusb, int port,
4611 +extern int sisusb_setidxregandor(struct sisusb_usb_data *sisusb, u32 port,
4612 u8 idx, u8 myand, u8 myor);
4613 -extern int sisusb_setidxregor(struct sisusb_usb_data *sisusb, int port,
4614 +extern int sisusb_setidxregor(struct sisusb_usb_data *sisusb, u32 port,
4615 u8 index, u8 myor);
4616 -extern int sisusb_setidxregand(struct sisusb_usb_data *sisusb, int port,
4617 +extern int sisusb_setidxregand(struct sisusb_usb_data *sisusb, u32 port,
4618 u8 idx, u8 myand);
4619
4620 void sisusb_delete(struct kref *kref);
4621 diff --git a/drivers/usb/storage/uas.c b/drivers/usb/storage/uas.c
4622 index bb2198496f42..5fcad96e0656 100644
4623 --- a/drivers/usb/storage/uas.c
4624 +++ b/drivers/usb/storage/uas.c
4625 @@ -81,6 +81,19 @@ static void uas_free_streams(struct uas_dev_info *devinfo);
4626 static void uas_log_cmd_state(struct scsi_cmnd *cmnd, const char *prefix,
4627 int status);
4628
4629 +/*
4630 + * This driver needs its own workqueue, as we need to control memory allocation.
4631 + *
4632 + * In the course of error handling and power management uas_wait_for_pending_cmnds()
4633 + * needs to flush pending work items. In these contexts we cannot allocate memory
4634 + * by doing block IO as we would deadlock. For the same reason we cannot wait
4635 + * for anything allocating memory not heeding these constraints.
4636 + *
4637 + * So we have to control all work items that can be on the workqueue we flush.
4638 + * Hence we cannot share a queue and need our own.
4639 + */
4640 +static struct workqueue_struct *workqueue;
4641 +
4642 static void uas_do_work(struct work_struct *work)
4643 {
4644 struct uas_dev_info *devinfo =
4645 @@ -109,7 +122,7 @@ static void uas_do_work(struct work_struct *work)
4646 if (!err)
4647 cmdinfo->state &= ~IS_IN_WORK_LIST;
4648 else
4649 - schedule_work(&devinfo->work);
4650 + queue_work(workqueue, &devinfo->work);
4651 }
4652 out:
4653 spin_unlock_irqrestore(&devinfo->lock, flags);
4654 @@ -134,7 +147,7 @@ static void uas_add_work(struct uas_cmd_info *cmdinfo)
4655
4656 lockdep_assert_held(&devinfo->lock);
4657 cmdinfo->state |= IS_IN_WORK_LIST;
4658 - schedule_work(&devinfo->work);
4659 + queue_work(workqueue, &devinfo->work);
4660 }
4661
4662 static void uas_zap_pending(struct uas_dev_info *devinfo, int result)
4663 @@ -190,6 +203,9 @@ static void uas_log_cmd_state(struct scsi_cmnd *cmnd, const char *prefix,
4664 struct uas_cmd_info *ci = (void *)&cmnd->SCp;
4665 struct uas_cmd_info *cmdinfo = (void *)&cmnd->SCp;
4666
4667 + if (status == -ENODEV) /* too late */
4668 + return;
4669 +
4670 scmd_printk(KERN_INFO, cmnd,
4671 "%s %d uas-tag %d inflight:%s%s%s%s%s%s%s%s%s%s%s%s ",
4672 prefix, status, cmdinfo->uas_tag,
4673 @@ -1227,7 +1243,31 @@ static struct usb_driver uas_driver = {
4674 .id_table = uas_usb_ids,
4675 };
4676
4677 -module_usb_driver(uas_driver);
4678 +static int __init uas_init(void)
4679 +{
4680 + int rv;
4681 +
4682 + workqueue = alloc_workqueue("uas", WQ_MEM_RECLAIM, 0);
4683 + if (!workqueue)
4684 + return -ENOMEM;
4685 +
4686 + rv = usb_register(&uas_driver);
4687 + if (rv) {
4688 + destroy_workqueue(workqueue);
4689 + return -ENOMEM;
4690 + }
4691 +
4692 + return 0;
4693 +}
4694 +
4695 +static void __exit uas_exit(void)
4696 +{
4697 + usb_deregister(&uas_driver);
4698 + destroy_workqueue(workqueue);
4699 +}
4700 +
4701 +module_init(uas_init);
4702 +module_exit(uas_exit);
4703
4704 MODULE_LICENSE("GPL");
4705 MODULE_IMPORT_NS(USB_STORAGE);
4706 diff --git a/drivers/usb/storage/unusual_devs.h b/drivers/usb/storage/unusual_devs.h
4707 index 1880f3e13f57..f6c3681fa2e9 100644
4708 --- a/drivers/usb/storage/unusual_devs.h
4709 +++ b/drivers/usb/storage/unusual_devs.h
4710 @@ -2323,6 +2323,13 @@ UNUSUAL_DEV( 0x3340, 0xffff, 0x0000, 0x0000,
4711 USB_SC_DEVICE,USB_PR_DEVICE,NULL,
4712 US_FL_MAX_SECTORS_64 ),
4713
4714 +/* Reported by Cyril Roelandt <tipecaml@gmail.com> */
4715 +UNUSUAL_DEV( 0x357d, 0x7788, 0x0114, 0x0114,
4716 + "JMicron",
4717 + "USB to ATA/ATAPI Bridge",
4718 + USB_SC_DEVICE, USB_PR_DEVICE, NULL,
4719 + US_FL_BROKEN_FUA ),
4720 +
4721 /* Reported by Andrey Rahmatullin <wrar@altlinux.org> */
4722 UNUSUAL_DEV( 0x4102, 0x1020, 0x0100, 0x0100,
4723 "iRiver",
4724 diff --git a/drivers/usb/typec/bus.c b/drivers/usb/typec/bus.c
4725 index 74cb3c2ecb34..c950171556d8 100644
4726 --- a/drivers/usb/typec/bus.c
4727 +++ b/drivers/usb/typec/bus.c
4728 @@ -192,7 +192,10 @@ EXPORT_SYMBOL_GPL(typec_altmode_vdm);
4729 const struct typec_altmode *
4730 typec_altmode_get_partner(struct typec_altmode *adev)
4731 {
4732 - return adev ? &to_altmode(adev)->partner->adev : NULL;
4733 + if (!adev || !to_altmode(adev)->partner)
4734 + return NULL;
4735 +
4736 + return &to_altmode(adev)->partner->adev;
4737 }
4738 EXPORT_SYMBOL_GPL(typec_altmode_get_partner);
4739
4740 diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c
4741 index 5f61d9977a15..355a2c7fac0b 100644
4742 --- a/drivers/usb/typec/tcpm/tcpm.c
4743 +++ b/drivers/usb/typec/tcpm/tcpm.c
4744 @@ -3768,6 +3768,14 @@ static void _tcpm_cc_change(struct tcpm_port *port, enum typec_cc_status cc1,
4745 */
4746 break;
4747
4748 + case PORT_RESET:
4749 + case PORT_RESET_WAIT_OFF:
4750 + /*
4751 + * State set back to default mode once the timer completes.
4752 + * Ignore CC changes here.
4753 + */
4754 + break;
4755 +
4756 default:
4757 if (tcpm_port_is_disconnected(port))
4758 tcpm_set_state(port, unattached_state(port), 0);
4759 @@ -3829,6 +3837,15 @@ static void _tcpm_pd_vbus_on(struct tcpm_port *port)
4760 case SRC_TRY_DEBOUNCE:
4761 /* Do nothing, waiting for sink detection */
4762 break;
4763 +
4764 + case PORT_RESET:
4765 + case PORT_RESET_WAIT_OFF:
4766 + /*
4767 + * State set back to default mode once the timer completes.
4768 + * Ignore vbus changes here.
4769 + */
4770 + break;
4771 +
4772 default:
4773 break;
4774 }
4775 @@ -3882,10 +3899,19 @@ static void _tcpm_pd_vbus_off(struct tcpm_port *port)
4776 case PORT_RESET_WAIT_OFF:
4777 tcpm_set_state(port, tcpm_default_state(port), 0);
4778 break;
4779 +
4780 case SRC_TRY_WAIT:
4781 case SRC_TRY_DEBOUNCE:
4782 /* Do nothing, waiting for sink detection */
4783 break;
4784 +
4785 + case PORT_RESET:
4786 + /*
4787 + * State set back to default mode once the timer completes.
4788 + * Ignore vbus changes here.
4789 + */
4790 + break;
4791 +
4792 default:
4793 if (port->pwr_role == TYPEC_SINK &&
4794 port->attached)
4795 diff --git a/drivers/watchdog/watchdog_dev.c b/drivers/watchdog/watchdog_dev.c
4796 index ce04edc69e5f..c4147e93aa7d 100644
4797 --- a/drivers/watchdog/watchdog_dev.c
4798 +++ b/drivers/watchdog/watchdog_dev.c
4799 @@ -282,6 +282,7 @@ static int watchdog_start(struct watchdog_device *wdd)
4800 if (err == 0) {
4801 set_bit(WDOG_ACTIVE, &wdd->status);
4802 wd_data->last_keepalive = started_at;
4803 + wd_data->last_hw_keepalive = started_at;
4804 watchdog_update_worker(wdd);
4805 }
4806
4807 diff --git a/fs/ceph/caps.c b/fs/ceph/caps.c
4808 index f5a38910a82b..703945cce0e5 100644
4809 --- a/fs/ceph/caps.c
4810 +++ b/fs/ceph/caps.c
4811 @@ -1976,8 +1976,12 @@ retry_locked:
4812 }
4813
4814 /* want more caps from mds? */
4815 - if (want & ~(cap->mds_wanted | cap->issued))
4816 - goto ack;
4817 + if (want & ~cap->mds_wanted) {
4818 + if (want & ~(cap->mds_wanted | cap->issued))
4819 + goto ack;
4820 + if (!__cap_is_valid(cap))
4821 + goto ack;
4822 + }
4823
4824 /* things we might delay */
4825 if ((cap->issued & ~retain) == 0)
4826 diff --git a/fs/ceph/export.c b/fs/ceph/export.c
4827 index b6bfa94332c3..79dc06881e78 100644
4828 --- a/fs/ceph/export.c
4829 +++ b/fs/ceph/export.c
4830 @@ -315,6 +315,11 @@ static struct dentry *__get_parent(struct super_block *sb,
4831
4832 req->r_num_caps = 1;
4833 err = ceph_mdsc_do_request(mdsc, NULL, req);
4834 + if (err) {
4835 + ceph_mdsc_put_request(req);
4836 + return ERR_PTR(err);
4837 + }
4838 +
4839 inode = req->r_target_inode;
4840 if (inode)
4841 ihold(inode);
4842 diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
4843 index 76eacffb24d8..58915d882285 100644
4844 --- a/fs/cifs/smb2ops.c
4845 +++ b/fs/cifs/smb2ops.c
4846 @@ -664,6 +664,11 @@ int open_shroot(unsigned int xid, struct cifs_tcon *tcon, struct cifs_fid *pfid)
4847 if (smb3_encryption_required(tcon))
4848 flags |= CIFS_TRANSFORM_REQ;
4849
4850 + if (!server->ops->new_lease_key)
4851 + return -EIO;
4852 +
4853 + server->ops->new_lease_key(pfid);
4854 +
4855 memset(rqst, 0, sizeof(rqst));
4856 resp_buftype[0] = resp_buftype[1] = CIFS_NO_BUFFER;
4857 memset(rsp_iov, 0, sizeof(rsp_iov));
4858 diff --git a/fs/coredump.c b/fs/coredump.c
4859 index b1ea7dfbd149..d25bad2ed061 100644
4860 --- a/fs/coredump.c
4861 +++ b/fs/coredump.c
4862 @@ -211,6 +211,8 @@ static int format_corename(struct core_name *cn, struct coredump_params *cprm,
4863 return -ENOMEM;
4864 (*argv)[(*argc)++] = 0;
4865 ++pat_ptr;
4866 + if (!(*pat_ptr))
4867 + return -ENOMEM;
4868 }
4869
4870 /* Repeat as long as we have more pattern to process and more output
4871 diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c
4872 index 164dbfd40c52..9bd44588eb77 100644
4873 --- a/fs/ext4/extents.c
4874 +++ b/fs/ext4/extents.c
4875 @@ -498,6 +498,30 @@ int ext4_ext_check_inode(struct inode *inode)
4876 return ext4_ext_check(inode, ext_inode_hdr(inode), ext_depth(inode), 0);
4877 }
4878
4879 +static void ext4_cache_extents(struct inode *inode,
4880 + struct ext4_extent_header *eh)
4881 +{
4882 + struct ext4_extent *ex = EXT_FIRST_EXTENT(eh);
4883 + ext4_lblk_t prev = 0;
4884 + int i;
4885 +
4886 + for (i = le16_to_cpu(eh->eh_entries); i > 0; i--, ex++) {
4887 + unsigned int status = EXTENT_STATUS_WRITTEN;
4888 + ext4_lblk_t lblk = le32_to_cpu(ex->ee_block);
4889 + int len = ext4_ext_get_actual_len(ex);
4890 +
4891 + if (prev && (prev != lblk))
4892 + ext4_es_cache_extent(inode, prev, lblk - prev, ~0,
4893 + EXTENT_STATUS_HOLE);
4894 +
4895 + if (ext4_ext_is_unwritten(ex))
4896 + status = EXTENT_STATUS_UNWRITTEN;
4897 + ext4_es_cache_extent(inode, lblk, len,
4898 + ext4_ext_pblock(ex), status);
4899 + prev = lblk + len;
4900 + }
4901 +}
4902 +
4903 static struct buffer_head *
4904 __read_extent_tree_block(const char *function, unsigned int line,
4905 struct inode *inode, ext4_fsblk_t pblk, int depth,
4906 @@ -532,26 +556,7 @@ __read_extent_tree_block(const char *function, unsigned int line,
4907 */
4908 if (!(flags & EXT4_EX_NOCACHE) && depth == 0) {
4909 struct ext4_extent_header *eh = ext_block_hdr(bh);
4910 - struct ext4_extent *ex = EXT_FIRST_EXTENT(eh);
4911 - ext4_lblk_t prev = 0;
4912 - int i;
4913 -
4914 - for (i = le16_to_cpu(eh->eh_entries); i > 0; i--, ex++) {
4915 - unsigned int status = EXTENT_STATUS_WRITTEN;
4916 - ext4_lblk_t lblk = le32_to_cpu(ex->ee_block);
4917 - int len = ext4_ext_get_actual_len(ex);
4918 -
4919 - if (prev && (prev != lblk))
4920 - ext4_es_cache_extent(inode, prev,
4921 - lblk - prev, ~0,
4922 - EXTENT_STATUS_HOLE);
4923 -
4924 - if (ext4_ext_is_unwritten(ex))
4925 - status = EXTENT_STATUS_UNWRITTEN;
4926 - ext4_es_cache_extent(inode, lblk, len,
4927 - ext4_ext_pblock(ex), status);
4928 - prev = lblk + len;
4929 - }
4930 + ext4_cache_extents(inode, eh);
4931 }
4932 return bh;
4933 errout:
4934 @@ -899,6 +904,8 @@ ext4_find_extent(struct inode *inode, ext4_lblk_t block,
4935 path[0].p_bh = NULL;
4936
4937 i = depth;
4938 + if (!(flags & EXT4_EX_NOCACHE) && depth == 0)
4939 + ext4_cache_extents(inode, eh);
4940 /* walk through the tree */
4941 while (i) {
4942 ext_debug("depth %d: num %d, max %d\n",
4943 diff --git a/fs/f2fs/xattr.c b/fs/f2fs/xattr.c
4944 index 181900af2576..296b3189448a 100644
4945 --- a/fs/f2fs/xattr.c
4946 +++ b/fs/f2fs/xattr.c
4947 @@ -539,8 +539,9 @@ out:
4948 ssize_t f2fs_listxattr(struct dentry *dentry, char *buffer, size_t buffer_size)
4949 {
4950 struct inode *inode = d_inode(dentry);
4951 + nid_t xnid = F2FS_I(inode)->i_xattr_nid;
4952 struct f2fs_xattr_entry *entry;
4953 - void *base_addr;
4954 + void *base_addr, *last_base_addr;
4955 int error = 0;
4956 size_t rest = buffer_size;
4957
4958 @@ -550,6 +551,8 @@ ssize_t f2fs_listxattr(struct dentry *dentry, char *buffer, size_t buffer_size)
4959 if (error)
4960 return error;
4961
4962 + last_base_addr = (void *)base_addr + XATTR_SIZE(xnid, inode);
4963 +
4964 list_for_each_xattr(entry, base_addr) {
4965 const struct xattr_handler *handler =
4966 f2fs_xattr_handler(entry->e_name_index);
4967 @@ -557,6 +560,15 @@ ssize_t f2fs_listxattr(struct dentry *dentry, char *buffer, size_t buffer_size)
4968 size_t prefix_len;
4969 size_t size;
4970
4971 + if ((void *)(entry) + sizeof(__u32) > last_base_addr ||
4972 + (void *)XATTR_NEXT_ENTRY(entry) > last_base_addr) {
4973 + f2fs_err(F2FS_I_SB(inode), "inode (%lu) has corrupted xattr",
4974 + inode->i_ino);
4975 + set_sbi_flag(F2FS_I_SB(inode), SBI_NEED_FSCK);
4976 + error = -EFSCORRUPTED;
4977 + goto cleanup;
4978 + }
4979 +
4980 if (!handler || (handler->list && !handler->list(dentry)))
4981 continue;
4982
4983 diff --git a/fs/nfsd/nfs4callback.c b/fs/nfsd/nfs4callback.c
4984 index 524111420b48..afca3287184b 100644
4985 --- a/fs/nfsd/nfs4callback.c
4986 +++ b/fs/nfsd/nfs4callback.c
4987 @@ -1241,6 +1241,7 @@ nfsd4_run_cb_work(struct work_struct *work)
4988 container_of(work, struct nfsd4_callback, cb_work);
4989 struct nfs4_client *clp = cb->cb_clp;
4990 struct rpc_clnt *clnt;
4991 + int flags;
4992
4993 if (cb->cb_need_restart) {
4994 cb->cb_need_restart = false;
4995 @@ -1269,7 +1270,8 @@ nfsd4_run_cb_work(struct work_struct *work)
4996 }
4997
4998 cb->cb_msg.rpc_cred = clp->cl_cb_cred;
4999 - rpc_call_async(clnt, &cb->cb_msg, RPC_TASK_SOFT | RPC_TASK_SOFTCONN,
5000 + flags = clp->cl_minorversion ? RPC_TASK_NOCONNECT : RPC_TASK_SOFTCONN;
5001 + rpc_call_async(clnt, &cb->cb_msg, RPC_TASK_SOFT | flags,
5002 cb->cb_ops ? &nfsd4_cb_ops : &nfsd4_cb_probe_ops, cb);
5003 }
5004
5005 diff --git a/fs/proc/vmcore.c b/fs/proc/vmcore.c
5006 index 7b13988796e1..080ca9d5eccb 100644
5007 --- a/fs/proc/vmcore.c
5008 +++ b/fs/proc/vmcore.c
5009 @@ -266,7 +266,8 @@ static int vmcoredd_mmap_dumps(struct vm_area_struct *vma, unsigned long dst,
5010 if (start < offset + dump->size) {
5011 tsz = min(offset + (u64)dump->size - start, (u64)size);
5012 buf = dump->buf + start - offset;
5013 - if (remap_vmalloc_range_partial(vma, dst, buf, tsz)) {
5014 + if (remap_vmalloc_range_partial(vma, dst, buf, 0,
5015 + tsz)) {
5016 ret = -EFAULT;
5017 goto out_unlock;
5018 }
5019 @@ -624,7 +625,7 @@ static int mmap_vmcore(struct file *file, struct vm_area_struct *vma)
5020 tsz = min(elfcorebuf_sz + elfnotes_sz - (size_t)start, size);
5021 kaddr = elfnotes_buf + start - elfcorebuf_sz - vmcoredd_orig_sz;
5022 if (remap_vmalloc_range_partial(vma, vma->vm_start + len,
5023 - kaddr, tsz))
5024 + kaddr, 0, tsz))
5025 goto fail;
5026
5027 size -= tsz;
5028 diff --git a/include/linux/iio/iio.h b/include/linux/iio/iio.h
5029 index 8e132cf819e4..e5341847e3a0 100644
5030 --- a/include/linux/iio/iio.h
5031 +++ b/include/linux/iio/iio.h
5032 @@ -596,7 +596,7 @@ void iio_device_unregister(struct iio_dev *indio_dev);
5033 * 0 on success, negative error number on failure.
5034 */
5035 #define devm_iio_device_register(dev, indio_dev) \
5036 - __devm_iio_device_register((dev), (indio_dev), THIS_MODULE);
5037 + __devm_iio_device_register((dev), (indio_dev), THIS_MODULE)
5038 int __devm_iio_device_register(struct device *dev, struct iio_dev *indio_dev,
5039 struct module *this_mod);
5040 void devm_iio_device_unregister(struct device *dev, struct iio_dev *indio_dev);
5041 diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
5042 index b81f0f1ded5f..678b0a5797a0 100644
5043 --- a/include/linux/kvm_host.h
5044 +++ b/include/linux/kvm_host.h
5045 @@ -1027,7 +1027,7 @@ search_memslots(struct kvm_memslots *slots, gfn_t gfn)
5046 start = slot + 1;
5047 }
5048
5049 - if (gfn >= memslots[start].base_gfn &&
5050 + if (start < slots->used_slots && gfn >= memslots[start].base_gfn &&
5051 gfn < memslots[start].base_gfn + memslots[start].npages) {
5052 atomic_set(&slots->lru_slot, start);
5053 return &memslots[start];
5054 diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
5055 index decac0790fc1..01a1334c5fc5 100644
5056 --- a/include/linux/vmalloc.h
5057 +++ b/include/linux/vmalloc.h
5058 @@ -122,7 +122,7 @@ extern void vunmap(const void *addr);
5059
5060 extern int remap_vmalloc_range_partial(struct vm_area_struct *vma,
5061 unsigned long uaddr, void *kaddr,
5062 - unsigned long size);
5063 + unsigned long pgoff, unsigned long size);
5064
5065 extern int remap_vmalloc_range(struct vm_area_struct *vma, void *addr,
5066 unsigned long pgoff);
5067 diff --git a/include/net/mac80211.h b/include/net/mac80211.h
5068 index 523c6a09e1c8..d9ba9a77bcf2 100644
5069 --- a/include/net/mac80211.h
5070 +++ b/include/net/mac80211.h
5071 @@ -5933,7 +5933,9 @@ enum rate_control_capabilities {
5072 struct rate_control_ops {
5073 unsigned long capa;
5074 const char *name;
5075 - void *(*alloc)(struct ieee80211_hw *hw, struct dentry *debugfsdir);
5076 + void *(*alloc)(struct ieee80211_hw *hw);
5077 + void (*add_debugfs)(struct ieee80211_hw *hw, void *priv,
5078 + struct dentry *debugfsdir);
5079 void (*free)(void *priv);
5080
5081 void *(*alloc_sta)(void *priv, struct ieee80211_sta *sta, gfp_t gfp);
5082 diff --git a/include/net/tcp.h b/include/net/tcp.h
5083 index 830c89db1245..cce285f70c8e 100644
5084 --- a/include/net/tcp.h
5085 +++ b/include/net/tcp.h
5086 @@ -50,7 +50,7 @@ extern struct inet_hashinfo tcp_hashinfo;
5087 extern struct percpu_counter tcp_orphan_count;
5088 void tcp_time_wait(struct sock *sk, int state, int timeo);
5089
5090 -#define MAX_TCP_HEADER (128 + MAX_HEADER)
5091 +#define MAX_TCP_HEADER L1_CACHE_ALIGN(128 + MAX_HEADER)
5092 #define MAX_TCP_OPTION_SPACE 40
5093 #define TCP_MIN_SND_MSS 48
5094 #define TCP_MIN_GSO_SIZE (TCP_MIN_SND_MSS - MAX_TCP_OPTION_SPACE)
5095 diff --git a/ipc/util.c b/ipc/util.c
5096 index d126d156efc6..594871610d45 100644
5097 --- a/ipc/util.c
5098 +++ b/ipc/util.c
5099 @@ -764,13 +764,13 @@ static struct kern_ipc_perm *sysvipc_find_ipc(struct ipc_ids *ids, loff_t pos,
5100 total++;
5101 }
5102
5103 + *new_pos = pos + 1;
5104 if (total >= ids->in_use)
5105 return NULL;
5106
5107 for (; pos < ipc_mni; pos++) {
5108 ipc = idr_find(&ids->ipcs_idr, pos);
5109 if (ipc != NULL) {
5110 - *new_pos = pos + 1;
5111 rcu_read_lock();
5112 ipc_lock_object(ipc);
5113 return ipc;
5114 diff --git a/kernel/audit.c b/kernel/audit.c
5115 index dfc45063cb56..fcfbb3476ccd 100644
5116 --- a/kernel/audit.c
5117 +++ b/kernel/audit.c
5118 @@ -1325,6 +1325,9 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
5119 case AUDIT_FIRST_USER_MSG2 ... AUDIT_LAST_USER_MSG2:
5120 if (!audit_enabled && msg_type != AUDIT_USER_AVC)
5121 return 0;
5122 + /* exit early if there isn't at least one character to print */
5123 + if (data_len < 2)
5124 + return -EINVAL;
5125
5126 err = audit_filter(msg_type, AUDIT_FILTER_USER);
5127 if (err == 1) { /* match or error */
5128 diff --git a/kernel/dma/direct.c b/kernel/dma/direct.c
5129 index 867fd72cb260..0a093a675b63 100644
5130 --- a/kernel/dma/direct.c
5131 +++ b/kernel/dma/direct.c
5132 @@ -45,7 +45,8 @@ static inline dma_addr_t phys_to_dma_direct(struct device *dev,
5133
5134 u64 dma_direct_get_required_mask(struct device *dev)
5135 {
5136 - u64 max_dma = phys_to_dma_direct(dev, (max_pfn - 1) << PAGE_SHIFT);
5137 + phys_addr_t phys = (phys_addr_t)(max_pfn - 1) << PAGE_SHIFT;
5138 + u64 max_dma = phys_to_dma_direct(dev, phys);
5139
5140 return (1ULL << (fls64(max_dma) - 1)) * 2 - 1;
5141 }
5142 diff --git a/kernel/events/core.c b/kernel/events/core.c
5143 index 15b123bdcaf5..72d0cfd73cf1 100644
5144 --- a/kernel/events/core.c
5145 +++ b/kernel/events/core.c
5146 @@ -6537,9 +6537,12 @@ static u64 perf_virt_to_phys(u64 virt)
5147 * Try IRQ-safe __get_user_pages_fast first.
5148 * If failed, leave phys_addr as 0.
5149 */
5150 - if ((current->mm != NULL) &&
5151 - (__get_user_pages_fast(virt, 1, 0, &p) == 1))
5152 - phys_addr = page_to_phys(p) + virt % PAGE_SIZE;
5153 + if (current->mm != NULL) {
5154 + pagefault_disable();
5155 + if (__get_user_pages_fast(virt, 1, 0, &p) == 1)
5156 + phys_addr = page_to_phys(p) + virt % PAGE_SIZE;
5157 + pagefault_enable();
5158 + }
5159
5160 if (p)
5161 put_page(p);
5162 diff --git a/kernel/gcov/fs.c b/kernel/gcov/fs.c
5163 index e5eb5ea7ea59..cc4ee482d3fb 100644
5164 --- a/kernel/gcov/fs.c
5165 +++ b/kernel/gcov/fs.c
5166 @@ -108,9 +108,9 @@ static void *gcov_seq_next(struct seq_file *seq, void *data, loff_t *pos)
5167 {
5168 struct gcov_iterator *iter = data;
5169
5170 + (*pos)++;
5171 if (gcov_iter_next(iter))
5172 return NULL;
5173 - (*pos)++;
5174
5175 return iter;
5176 }
5177 diff --git a/kernel/signal.c b/kernel/signal.c
5178 index 7d3d35eb7a0b..2b9295f2d244 100644
5179 --- a/kernel/signal.c
5180 +++ b/kernel/signal.c
5181 @@ -1993,8 +1993,12 @@ bool do_notify_parent(struct task_struct *tsk, int sig)
5182 if (psig->action[SIGCHLD-1].sa.sa_handler == SIG_IGN)
5183 sig = 0;
5184 }
5185 + /*
5186 + * Send with __send_signal as si_pid and si_uid are in the
5187 + * parent's namespaces.
5188 + */
5189 if (valid_signal(sig) && sig)
5190 - __group_send_sig_info(sig, &info, tsk->parent);
5191 + __send_signal(sig, &info, tsk->parent, PIDTYPE_TGID, false);
5192 __wake_up_parent(tsk, tsk->parent);
5193 spin_unlock_irqrestore(&psig->siglock, flags);
5194
5195 diff --git a/lib/raid6/test/Makefile b/lib/raid6/test/Makefile
5196 index 3ab8720aa2f8..b9e6c3648be1 100644
5197 --- a/lib/raid6/test/Makefile
5198 +++ b/lib/raid6/test/Makefile
5199 @@ -35,13 +35,13 @@ endif
5200 ifeq ($(IS_X86),yes)
5201 OBJS += mmx.o sse1.o sse2.o avx2.o recov_ssse3.o recov_avx2.o avx512.o recov_avx512.o
5202 CFLAGS += $(shell echo "pshufb %xmm0, %xmm0" | \
5203 - gcc -c -x assembler - >&/dev/null && \
5204 + gcc -c -x assembler - >/dev/null 2>&1 && \
5205 rm ./-.o && echo -DCONFIG_AS_SSSE3=1)
5206 CFLAGS += $(shell echo "vpbroadcastb %xmm0, %ymm1" | \
5207 - gcc -c -x assembler - >&/dev/null && \
5208 + gcc -c -x assembler - >/dev/null 2>&1 && \
5209 rm ./-.o && echo -DCONFIG_AS_AVX2=1)
5210 CFLAGS += $(shell echo "vpmovm2b %k1, %zmm5" | \
5211 - gcc -c -x assembler - >&/dev/null && \
5212 + gcc -c -x assembler - >/dev/null 2>&1 && \
5213 rm ./-.o && echo -DCONFIG_AS_AVX512=1)
5214 else ifeq ($(HAS_NEON),yes)
5215 OBJS += neon.o neon1.o neon2.o neon4.o neon8.o recov_neon.o recov_neon_inner.o
5216 diff --git a/mm/hugetlb.c b/mm/hugetlb.c
5217 index e0afd582ca01..2af1831596f2 100644
5218 --- a/mm/hugetlb.c
5219 +++ b/mm/hugetlb.c
5220 @@ -5016,8 +5016,8 @@ pte_t *huge_pte_offset(struct mm_struct *mm,
5221 {
5222 pgd_t *pgd;
5223 p4d_t *p4d;
5224 - pud_t *pud;
5225 - pmd_t *pmd;
5226 + pud_t *pud, pud_entry;
5227 + pmd_t *pmd, pmd_entry;
5228
5229 pgd = pgd_offset(mm, addr);
5230 if (!pgd_present(*pgd))
5231 @@ -5027,17 +5027,19 @@ pte_t *huge_pte_offset(struct mm_struct *mm,
5232 return NULL;
5233
5234 pud = pud_offset(p4d, addr);
5235 - if (sz != PUD_SIZE && pud_none(*pud))
5236 + pud_entry = READ_ONCE(*pud);
5237 + if (sz != PUD_SIZE && pud_none(pud_entry))
5238 return NULL;
5239 /* hugepage or swap? */
5240 - if (pud_huge(*pud) || !pud_present(*pud))
5241 + if (pud_huge(pud_entry) || !pud_present(pud_entry))
5242 return (pte_t *)pud;
5243
5244 pmd = pmd_offset(pud, addr);
5245 - if (sz != PMD_SIZE && pmd_none(*pmd))
5246 + pmd_entry = READ_ONCE(*pmd);
5247 + if (sz != PMD_SIZE && pmd_none(pmd_entry))
5248 return NULL;
5249 /* hugepage or swap? */
5250 - if (pmd_huge(*pmd) || !pmd_present(*pmd))
5251 + if (pmd_huge(pmd_entry) || !pmd_present(pmd_entry))
5252 return (pte_t *)pmd;
5253
5254 return NULL;
5255 diff --git a/mm/ksm.c b/mm/ksm.c
5256 index 7905934cd3ad..e486c54d921b 100644
5257 --- a/mm/ksm.c
5258 +++ b/mm/ksm.c
5259 @@ -2112,8 +2112,16 @@ static void cmp_and_merge_page(struct page *page, struct rmap_item *rmap_item)
5260
5261 down_read(&mm->mmap_sem);
5262 vma = find_mergeable_vma(mm, rmap_item->address);
5263 - err = try_to_merge_one_page(vma, page,
5264 - ZERO_PAGE(rmap_item->address));
5265 + if (vma) {
5266 + err = try_to_merge_one_page(vma, page,
5267 + ZERO_PAGE(rmap_item->address));
5268 + } else {
5269 + /*
5270 + * If the vma is out of date, we do not need to
5271 + * continue.
5272 + */
5273 + err = 0;
5274 + }
5275 up_read(&mm->mmap_sem);
5276 /*
5277 * In case of failure, the page was not really empty, so we
5278 diff --git a/mm/vmalloc.c b/mm/vmalloc.c
5279 index 7d05834e594c..ad4d00bd7914 100644
5280 --- a/mm/vmalloc.c
5281 +++ b/mm/vmalloc.c
5282 @@ -34,6 +34,7 @@
5283 #include <linux/llist.h>
5284 #include <linux/bitops.h>
5285 #include <linux/rbtree_augmented.h>
5286 +#include <linux/overflow.h>
5287
5288 #include <linux/uaccess.h>
5289 #include <asm/tlbflush.h>
5290 @@ -2976,6 +2977,7 @@ finished:
5291 * @vma: vma to cover
5292 * @uaddr: target user address to start at
5293 * @kaddr: virtual address of vmalloc kernel memory
5294 + * @pgoff: offset from @kaddr to start at
5295 * @size: size of map area
5296 *
5297 * Returns: 0 for success, -Exxx on failure
5298 @@ -2988,9 +2990,15 @@ finished:
5299 * Similar to remap_pfn_range() (see mm/memory.c)
5300 */
5301 int remap_vmalloc_range_partial(struct vm_area_struct *vma, unsigned long uaddr,
5302 - void *kaddr, unsigned long size)
5303 + void *kaddr, unsigned long pgoff,
5304 + unsigned long size)
5305 {
5306 struct vm_struct *area;
5307 + unsigned long off;
5308 + unsigned long end_index;
5309 +
5310 + if (check_shl_overflow(pgoff, PAGE_SHIFT, &off))
5311 + return -EINVAL;
5312
5313 size = PAGE_ALIGN(size);
5314
5315 @@ -3004,8 +3012,10 @@ int remap_vmalloc_range_partial(struct vm_area_struct *vma, unsigned long uaddr,
5316 if (!(area->flags & (VM_USERMAP | VM_DMA_COHERENT)))
5317 return -EINVAL;
5318
5319 - if (kaddr + size > area->addr + get_vm_area_size(area))
5320 + if (check_add_overflow(size, off, &end_index) ||
5321 + end_index > get_vm_area_size(area))
5322 return -EINVAL;
5323 + kaddr += off;
5324
5325 do {
5326 struct page *page = vmalloc_to_page(kaddr);
5327 @@ -3044,7 +3054,7 @@ int remap_vmalloc_range(struct vm_area_struct *vma, void *addr,
5328 unsigned long pgoff)
5329 {
5330 return remap_vmalloc_range_partial(vma, vma->vm_start,
5331 - addr + (pgoff << PAGE_SHIFT),
5332 + addr, pgoff,
5333 vma->vm_end - vma->vm_start);
5334 }
5335 EXPORT_SYMBOL(remap_vmalloc_range);
5336 diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
5337 index f1888c683426..01588eef0cee 100644
5338 --- a/net/ipv4/fib_semantics.c
5339 +++ b/net/ipv4/fib_semantics.c
5340 @@ -1999,7 +1999,7 @@ static void fib_select_default(const struct flowi4 *flp, struct fib_result *res)
5341
5342 hlist_for_each_entry_rcu(fa, fa_head, fa_list) {
5343 struct fib_info *next_fi = fa->fa_info;
5344 - struct fib_nh *nh;
5345 + struct fib_nh_common *nhc;
5346
5347 if (fa->fa_slen != slen)
5348 continue;
5349 @@ -2022,8 +2022,8 @@ static void fib_select_default(const struct flowi4 *flp, struct fib_result *res)
5350 fa->fa_type != RTN_UNICAST)
5351 continue;
5352
5353 - nh = fib_info_nh(next_fi, 0);
5354 - if (!nh->fib_nh_gw4 || nh->fib_nh_scope != RT_SCOPE_LINK)
5355 + nhc = fib_info_nhc(next_fi, 0);
5356 + if (!nhc->nhc_gw_family || nhc->nhc_scope != RT_SCOPE_LINK)
5357 continue;
5358
5359 fib_alias_accessed(fa);
5360 diff --git a/net/ipv4/ip_tunnel.c b/net/ipv4/ip_tunnel.c
5361 index 74e1d964a615..cd4b84310d92 100644
5362 --- a/net/ipv4/ip_tunnel.c
5363 +++ b/net/ipv4/ip_tunnel.c
5364 @@ -142,11 +142,8 @@ struct ip_tunnel *ip_tunnel_lookup(struct ip_tunnel_net *itn,
5365 cand = t;
5366 }
5367
5368 - if (flags & TUNNEL_NO_KEY)
5369 - goto skip_key_lookup;
5370 -
5371 hlist_for_each_entry_rcu(t, head, hash_node) {
5372 - if (t->parms.i_key != key ||
5373 + if ((!(flags & TUNNEL_NO_KEY) && t->parms.i_key != key) ||
5374 t->parms.iph.saddr != 0 ||
5375 t->parms.iph.daddr != 0 ||
5376 !(t->dev->flags & IFF_UP))
5377 @@ -158,7 +155,6 @@ struct ip_tunnel *ip_tunnel_lookup(struct ip_tunnel_net *itn,
5378 cand = t;
5379 }
5380
5381 -skip_key_lookup:
5382 if (cand)
5383 return cand;
5384
5385 diff --git a/net/ipv4/xfrm4_output.c b/net/ipv4/xfrm4_output.c
5386 index ecff3fce9807..ab343ae686d4 100644
5387 --- a/net/ipv4/xfrm4_output.c
5388 +++ b/net/ipv4/xfrm4_output.c
5389 @@ -58,9 +58,7 @@ int xfrm4_output_finish(struct sock *sk, struct sk_buff *skb)
5390 {
5391 memset(IPCB(skb), 0, sizeof(*IPCB(skb)));
5392
5393 -#ifdef CONFIG_NETFILTER
5394 IPCB(skb)->flags |= IPSKB_XFRM_TRANSFORMED;
5395 -#endif
5396
5397 return xfrm_output(sk, skb);
5398 }
5399 diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
5400 index debdaeba5d8c..18d05403d3b5 100644
5401 --- a/net/ipv6/ipv6_sockglue.c
5402 +++ b/net/ipv6/ipv6_sockglue.c
5403 @@ -183,15 +183,14 @@ static int do_ipv6_setsockopt(struct sock *sk, int level, int optname,
5404 retv = -EBUSY;
5405 break;
5406 }
5407 - } else if (sk->sk_protocol == IPPROTO_TCP) {
5408 - if (sk->sk_prot != &tcpv6_prot) {
5409 - retv = -EBUSY;
5410 - break;
5411 - }
5412 - break;
5413 - } else {
5414 + }
5415 + if (sk->sk_protocol == IPPROTO_TCP &&
5416 + sk->sk_prot != &tcpv6_prot) {
5417 + retv = -EBUSY;
5418 break;
5419 }
5420 + if (sk->sk_protocol != IPPROTO_TCP)
5421 + break;
5422 if (sk->sk_state != TCP_ESTABLISHED) {
5423 retv = -ENOTCONN;
5424 break;
5425 diff --git a/net/ipv6/xfrm6_output.c b/net/ipv6/xfrm6_output.c
5426 index eecac1b7148e..cf2a0ce15c1c 100644
5427 --- a/net/ipv6/xfrm6_output.c
5428 +++ b/net/ipv6/xfrm6_output.c
5429 @@ -111,9 +111,7 @@ int xfrm6_output_finish(struct sock *sk, struct sk_buff *skb)
5430 {
5431 memset(IP6CB(skb), 0, sizeof(*IP6CB(skb)));
5432
5433 -#ifdef CONFIG_NETFILTER
5434 IP6CB(skb)->flags |= IP6SKB_XFRM_TRANSFORMED;
5435 -#endif
5436
5437 return xfrm_output(sk, skb);
5438 }
5439 diff --git a/net/mac80211/main.c b/net/mac80211/main.c
5440 index bc4bed021066..3e8561c3b0e7 100644
5441 --- a/net/mac80211/main.c
5442 +++ b/net/mac80211/main.c
5443 @@ -1155,8 +1155,6 @@ int ieee80211_register_hw(struct ieee80211_hw *hw)
5444 local->tx_headroom = max_t(unsigned int , local->hw.extra_tx_headroom,
5445 IEEE80211_TX_STATUS_HEADROOM);
5446
5447 - debugfs_hw_add(local);
5448 -
5449 /*
5450 * if the driver doesn't specify a max listen interval we
5451 * use 5 which should be a safe default
5452 @@ -1248,6 +1246,9 @@ int ieee80211_register_hw(struct ieee80211_hw *hw)
5453 if (result < 0)
5454 goto fail_wiphy_register;
5455
5456 + debugfs_hw_add(local);
5457 + rate_control_add_debugfs(local);
5458 +
5459 rtnl_lock();
5460
5461 /* add one default STA interface if supported */
5462 diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
5463 index a1e9fc7878aa..b051f125d3af 100644
5464 --- a/net/mac80211/rate.c
5465 +++ b/net/mac80211/rate.c
5466 @@ -214,17 +214,16 @@ static ssize_t rcname_read(struct file *file, char __user *userbuf,
5467 ref->ops->name, len);
5468 }
5469
5470 -static const struct file_operations rcname_ops = {
5471 +const struct file_operations rcname_ops = {
5472 .read = rcname_read,
5473 .open = simple_open,
5474 .llseek = default_llseek,
5475 };
5476 #endif
5477
5478 -static struct rate_control_ref *rate_control_alloc(const char *name,
5479 - struct ieee80211_local *local)
5480 +static struct rate_control_ref *
5481 +rate_control_alloc(const char *name, struct ieee80211_local *local)
5482 {
5483 - struct dentry *debugfsdir = NULL;
5484 struct rate_control_ref *ref;
5485
5486 ref = kmalloc(sizeof(struct rate_control_ref), GFP_KERNEL);
5487 @@ -234,13 +233,7 @@ static struct rate_control_ref *rate_control_alloc(const char *name,
5488 if (!ref->ops)
5489 goto free;
5490
5491 -#ifdef CONFIG_MAC80211_DEBUGFS
5492 - debugfsdir = debugfs_create_dir("rc", local->hw.wiphy->debugfsdir);
5493 - local->debugfs.rcdir = debugfsdir;
5494 - debugfs_create_file("name", 0400, debugfsdir, ref, &rcname_ops);
5495 -#endif
5496 -
5497 - ref->priv = ref->ops->alloc(&local->hw, debugfsdir);
5498 + ref->priv = ref->ops->alloc(&local->hw);
5499 if (!ref->priv)
5500 goto free;
5501 return ref;
5502 diff --git a/net/mac80211/rate.h b/net/mac80211/rate.h
5503 index 5397c6dad056..79b44d3db171 100644
5504 --- a/net/mac80211/rate.h
5505 +++ b/net/mac80211/rate.h
5506 @@ -60,6 +60,29 @@ static inline void rate_control_add_sta_debugfs(struct sta_info *sta)
5507 #endif
5508 }
5509
5510 +extern const struct file_operations rcname_ops;
5511 +
5512 +static inline void rate_control_add_debugfs(struct ieee80211_local *local)
5513 +{
5514 +#ifdef CONFIG_MAC80211_DEBUGFS
5515 + struct dentry *debugfsdir;
5516 +
5517 + if (!local->rate_ctrl)
5518 + return;
5519 +
5520 + if (!local->rate_ctrl->ops->add_debugfs)
5521 + return;
5522 +
5523 + debugfsdir = debugfs_create_dir("rc", local->hw.wiphy->debugfsdir);
5524 + local->debugfs.rcdir = debugfsdir;
5525 + debugfs_create_file("name", 0400, debugfsdir,
5526 + local->rate_ctrl, &rcname_ops);
5527 +
5528 + local->rate_ctrl->ops->add_debugfs(&local->hw, local->rate_ctrl->priv,
5529 + debugfsdir);
5530 +#endif
5531 +}
5532 +
5533 void ieee80211_check_rate_mask(struct ieee80211_sub_if_data *sdata);
5534
5535 /* Get a reference to the rate control algorithm. If `name' is NULL, get the
5536 diff --git a/net/mac80211/rc80211_minstrel_ht.c b/net/mac80211/rc80211_minstrel_ht.c
5537 index 0ef2633349b5..f2abe1f77dfc 100644
5538 --- a/net/mac80211/rc80211_minstrel_ht.c
5539 +++ b/net/mac80211/rc80211_minstrel_ht.c
5540 @@ -1631,7 +1631,7 @@ minstrel_ht_init_cck_rates(struct minstrel_priv *mp)
5541 }
5542
5543 static void *
5544 -minstrel_ht_alloc(struct ieee80211_hw *hw, struct dentry *debugfsdir)
5545 +minstrel_ht_alloc(struct ieee80211_hw *hw)
5546 {
5547 struct minstrel_priv *mp;
5548
5549 @@ -1668,18 +1668,24 @@ minstrel_ht_alloc(struct ieee80211_hw *hw, struct dentry *debugfsdir)
5550 mp->hw = hw;
5551 mp->update_interval = 100;
5552
5553 + minstrel_ht_init_cck_rates(mp);
5554 +
5555 + return mp;
5556 +}
5557 +
5558 #ifdef CONFIG_MAC80211_DEBUGFS
5559 +static void minstrel_ht_add_debugfs(struct ieee80211_hw *hw, void *priv,
5560 + struct dentry *debugfsdir)
5561 +{
5562 + struct minstrel_priv *mp = priv;
5563 +
5564 mp->fixed_rate_idx = (u32) -1;
5565 debugfs_create_u32("fixed_rate_idx", S_IRUGO | S_IWUGO, debugfsdir,
5566 &mp->fixed_rate_idx);
5567 debugfs_create_u32("sample_switch", S_IRUGO | S_IWUSR, debugfsdir,
5568 &mp->sample_switch);
5569 -#endif
5570 -
5571 - minstrel_ht_init_cck_rates(mp);
5572 -
5573 - return mp;
5574 }
5575 +#endif
5576
5577 static void
5578 minstrel_ht_free(void *priv)
5579 @@ -1718,6 +1724,7 @@ static const struct rate_control_ops mac80211_minstrel_ht = {
5580 .alloc = minstrel_ht_alloc,
5581 .free = minstrel_ht_free,
5582 #ifdef CONFIG_MAC80211_DEBUGFS
5583 + .add_debugfs = minstrel_ht_add_debugfs,
5584 .add_sta_debugfs = minstrel_ht_add_sta_debugfs,
5585 #endif
5586 .get_expected_throughput = minstrel_ht_get_expected_throughput,
5587 diff --git a/net/netrom/nr_route.c b/net/netrom/nr_route.c
5588 index d41335bad1f8..89cd9de21594 100644
5589 --- a/net/netrom/nr_route.c
5590 +++ b/net/netrom/nr_route.c
5591 @@ -208,6 +208,7 @@ static int __must_check nr_add_node(ax25_address *nr, const char *mnemonic,
5592 /* refcount initialized at 1 */
5593 spin_unlock_bh(&nr_node_list_lock);
5594
5595 + nr_neigh_put(nr_neigh);
5596 return 0;
5597 }
5598 nr_node_lock(nr_node);
5599 diff --git a/net/openvswitch/conntrack.c b/net/openvswitch/conntrack.c
5600 index 283e8f9a5fd2..8b70298857e3 100644
5601 --- a/net/openvswitch/conntrack.c
5602 +++ b/net/openvswitch/conntrack.c
5603 @@ -1890,7 +1890,8 @@ static void ovs_ct_limit_exit(struct net *net, struct ovs_net *ovs_net)
5604 struct hlist_head *head = &info->limits[i];
5605 struct ovs_ct_limit *ct_limit;
5606
5607 - hlist_for_each_entry_rcu(ct_limit, head, hlist_node)
5608 + hlist_for_each_entry_rcu(ct_limit, head, hlist_node,
5609 + lockdep_ovsl_is_held())
5610 kfree_rcu(ct_limit, rcu);
5611 }
5612 kfree(ovs_net->ct_limit_info->limits);
5613 diff --git a/net/openvswitch/datapath.c b/net/openvswitch/datapath.c
5614 index 3eed90bfa2bf..4f097bd3339e 100644
5615 --- a/net/openvswitch/datapath.c
5616 +++ b/net/openvswitch/datapath.c
5617 @@ -2430,8 +2430,10 @@ static void __net_exit ovs_exit_net(struct net *dnet)
5618 struct net *net;
5619 LIST_HEAD(head);
5620
5621 - ovs_ct_exit(dnet);
5622 ovs_lock();
5623 +
5624 + ovs_ct_exit(dnet);
5625 +
5626 list_for_each_entry_safe(dp, dp_next, &ovs_net->dps, list_node)
5627 __dp_destroy(dp);
5628
5629 diff --git a/net/sched/sch_etf.c b/net/sched/sch_etf.c
5630 index b1da5589a0c6..c48f91075b5c 100644
5631 --- a/net/sched/sch_etf.c
5632 +++ b/net/sched/sch_etf.c
5633 @@ -82,7 +82,7 @@ static bool is_packet_valid(struct Qdisc *sch, struct sk_buff *nskb)
5634 if (q->skip_sock_check)
5635 goto skip;
5636
5637 - if (!sk)
5638 + if (!sk || !sk_fullsock(sk))
5639 return false;
5640
5641 if (!sock_flag(sk, SOCK_TXTIME))
5642 @@ -137,8 +137,9 @@ static void report_sock_error(struct sk_buff *skb, u32 err, u8 code)
5643 struct sock_exterr_skb *serr;
5644 struct sk_buff *clone;
5645 ktime_t txtime = skb->tstamp;
5646 + struct sock *sk = skb->sk;
5647
5648 - if (!skb->sk || !(skb->sk->sk_txtime_report_errors))
5649 + if (!sk || !sk_fullsock(sk) || !(sk->sk_txtime_report_errors))
5650 return;
5651
5652 clone = skb_clone(skb, GFP_ATOMIC);
5653 @@ -154,7 +155,7 @@ static void report_sock_error(struct sk_buff *skb, u32 err, u8 code)
5654 serr->ee.ee_data = (txtime >> 32); /* high part of tstamp */
5655 serr->ee.ee_info = txtime; /* low part of tstamp */
5656
5657 - if (sock_queue_err_skb(skb->sk, clone))
5658 + if (sock_queue_err_skb(sk, clone))
5659 kfree_skb(clone);
5660 }
5661
5662 diff --git a/net/sunrpc/svc_xprt.c b/net/sunrpc/svc_xprt.c
5663 index de3c077733a7..298557744818 100644
5664 --- a/net/sunrpc/svc_xprt.c
5665 +++ b/net/sunrpc/svc_xprt.c
5666 @@ -1028,6 +1028,8 @@ static void svc_delete_xprt(struct svc_xprt *xprt)
5667
5668 dprintk("svc: svc_delete_xprt(%p)\n", xprt);
5669 xprt->xpt_ops->xpo_detach(xprt);
5670 + if (xprt->xpt_bc_xprt)
5671 + xprt->xpt_bc_xprt->ops->close(xprt->xpt_bc_xprt);
5672
5673 spin_lock_bh(&serv->sv_lock);
5674 list_del_init(&xprt->xpt_list);
5675 diff --git a/net/sunrpc/xprtrdma/svc_rdma_backchannel.c b/net/sunrpc/xprtrdma/svc_rdma_backchannel.c
5676 index 908e78bb87c6..cf80394b2db3 100644
5677 --- a/net/sunrpc/xprtrdma/svc_rdma_backchannel.c
5678 +++ b/net/sunrpc/xprtrdma/svc_rdma_backchannel.c
5679 @@ -242,6 +242,8 @@ static void
5680 xprt_rdma_bc_close(struct rpc_xprt *xprt)
5681 {
5682 dprintk("svcrdma: %s: xprt %p\n", __func__, xprt);
5683 +
5684 + xprt_disconnect_done(xprt);
5685 xprt->cwnd = RPC_CWNDSHIFT;
5686 }
5687
5688 diff --git a/net/sunrpc/xprtsock.c b/net/sunrpc/xprtsock.c
5689 index 5361b98f31ae..934e30e67537 100644
5690 --- a/net/sunrpc/xprtsock.c
5691 +++ b/net/sunrpc/xprtsock.c
5692 @@ -2714,6 +2714,7 @@ static int bc_send_request(struct rpc_rqst *req)
5693
5694 static void bc_close(struct rpc_xprt *xprt)
5695 {
5696 + xprt_disconnect_done(xprt);
5697 }
5698
5699 /*
5700 diff --git a/net/x25/x25_dev.c b/net/x25/x25_dev.c
5701 index 00e782335cb0..25bf72ee6cad 100644
5702 --- a/net/x25/x25_dev.c
5703 +++ b/net/x25/x25_dev.c
5704 @@ -115,8 +115,10 @@ int x25_lapb_receive_frame(struct sk_buff *skb, struct net_device *dev,
5705 goto drop;
5706 }
5707
5708 - if (!pskb_may_pull(skb, 1))
5709 + if (!pskb_may_pull(skb, 1)) {
5710 + x25_neigh_put(nb);
5711 return 0;
5712 + }
5713
5714 switch (skb->data[0]) {
5715
5716 diff --git a/samples/vfio-mdev/mdpy.c b/samples/vfio-mdev/mdpy.c
5717 index cc86bf6566e4..9894693f3be1 100644
5718 --- a/samples/vfio-mdev/mdpy.c
5719 +++ b/samples/vfio-mdev/mdpy.c
5720 @@ -418,7 +418,7 @@ static int mdpy_mmap(struct mdev_device *mdev, struct vm_area_struct *vma)
5721 return -EINVAL;
5722
5723 return remap_vmalloc_range_partial(vma, vma->vm_start,
5724 - mdev_state->memblk,
5725 + mdev_state->memblk, 0,
5726 vma->vm_end - vma->vm_start);
5727 }
5728
5729 diff --git a/scripts/kconfig/qconf.cc b/scripts/kconfig/qconf.cc
5730 index 82773cc35d35..0f8c77f84711 100644
5731 --- a/scripts/kconfig/qconf.cc
5732 +++ b/scripts/kconfig/qconf.cc
5733 @@ -627,7 +627,7 @@ void ConfigList::updateMenuList(ConfigItem *parent, struct menu* menu)
5734 last = item;
5735 continue;
5736 }
5737 - hide:
5738 +hide:
5739 if (item && item->menu == child) {
5740 last = parent->firstChild();
5741 if (last == item)
5742 @@ -692,7 +692,7 @@ void ConfigList::updateMenuList(ConfigList *parent, struct menu* menu)
5743 last = item;
5744 continue;
5745 }
5746 - hide:
5747 +hide:
5748 if (item && item->menu == child) {
5749 last = (ConfigItem*)parent->topLevelItem(0);
5750 if (last == item)
5751 @@ -1225,10 +1225,11 @@ QMenu* ConfigInfoView::createStandardContextMenu(const QPoint & pos)
5752 {
5753 QMenu* popup = Parent::createStandardContextMenu(pos);
5754 QAction* action = new QAction("Show Debug Info", popup);
5755 - action->setCheckable(true);
5756 - connect(action, SIGNAL(toggled(bool)), SLOT(setShowDebug(bool)));
5757 - connect(this, SIGNAL(showDebugChanged(bool)), action, SLOT(setOn(bool)));
5758 - action->setChecked(showDebug());
5759 +
5760 + action->setCheckable(true);
5761 + connect(action, SIGNAL(toggled(bool)), SLOT(setShowDebug(bool)));
5762 + connect(this, SIGNAL(showDebugChanged(bool)), action, SLOT(setOn(bool)));
5763 + action->setChecked(showDebug());
5764 popup->addSeparator();
5765 popup->addAction(action);
5766 return popup;
5767 diff --git a/security/keys/internal.h b/security/keys/internal.h
5768 index c039373488bd..7e9914943616 100644
5769 --- a/security/keys/internal.h
5770 +++ b/security/keys/internal.h
5771 @@ -16,6 +16,8 @@
5772 #include <linux/keyctl.h>
5773 #include <linux/refcount.h>
5774 #include <linux/compat.h>
5775 +#include <linux/mm.h>
5776 +#include <linux/vmalloc.h>
5777
5778 struct iovec;
5779
5780 @@ -349,4 +351,14 @@ static inline void key_check(const struct key *key)
5781
5782 #endif
5783
5784 +/*
5785 + * Helper function to clear and free a kvmalloc'ed memory object.
5786 + */
5787 +static inline void __kvzfree(const void *addr, size_t len)
5788 +{
5789 + if (addr) {
5790 + memset((void *)addr, 0, len);
5791 + kvfree(addr);
5792 + }
5793 +}
5794 #endif /* _INTERNAL_H */
5795 diff --git a/security/keys/keyctl.c b/security/keys/keyctl.c
5796 index 106e16f9006b..5e01192e222a 100644
5797 --- a/security/keys/keyctl.c
5798 +++ b/security/keys/keyctl.c
5799 @@ -339,7 +339,7 @@ long keyctl_update_key(key_serial_t id,
5800 payload = NULL;
5801 if (plen) {
5802 ret = -ENOMEM;
5803 - payload = kmalloc(plen, GFP_KERNEL);
5804 + payload = kvmalloc(plen, GFP_KERNEL);
5805 if (!payload)
5806 goto error;
5807
5808 @@ -360,7 +360,7 @@ long keyctl_update_key(key_serial_t id,
5809
5810 key_ref_put(key_ref);
5811 error2:
5812 - kzfree(payload);
5813 + __kvzfree(payload, plen);
5814 error:
5815 return ret;
5816 }
5817 @@ -827,7 +827,8 @@ long keyctl_read_key(key_serial_t keyid, char __user *buffer, size_t buflen)
5818 struct key *key;
5819 key_ref_t key_ref;
5820 long ret;
5821 - char *key_data;
5822 + char *key_data = NULL;
5823 + size_t key_data_len;
5824
5825 /* find the key first */
5826 key_ref = lookup_user_key(keyid, 0, 0);
5827 @@ -878,24 +879,51 @@ can_read_key:
5828 * Allocating a temporary buffer to hold the keys before
5829 * transferring them to user buffer to avoid potential
5830 * deadlock involving page fault and mmap_sem.
5831 + *
5832 + * key_data_len = (buflen <= PAGE_SIZE)
5833 + * ? buflen : actual length of key data
5834 + *
5835 + * This prevents allocating arbitrary large buffer which can
5836 + * be much larger than the actual key length. In the latter case,
5837 + * at least 2 passes of this loop is required.
5838 */
5839 - key_data = kmalloc(buflen, GFP_KERNEL);
5840 + key_data_len = (buflen <= PAGE_SIZE) ? buflen : 0;
5841 + for (;;) {
5842 + if (key_data_len) {
5843 + key_data = kvmalloc(key_data_len, GFP_KERNEL);
5844 + if (!key_data) {
5845 + ret = -ENOMEM;
5846 + goto key_put_out;
5847 + }
5848 + }
5849
5850 - if (!key_data) {
5851 - ret = -ENOMEM;
5852 - goto key_put_out;
5853 - }
5854 - ret = __keyctl_read_key(key, key_data, buflen);
5855 + ret = __keyctl_read_key(key, key_data, key_data_len);
5856 +
5857 + /*
5858 + * Read methods will just return the required length without
5859 + * any copying if the provided length isn't large enough.
5860 + */
5861 + if (ret <= 0 || ret > buflen)
5862 + break;
5863 +
5864 + /*
5865 + * The key may change (unlikely) in between 2 consecutive
5866 + * __keyctl_read_key() calls. In this case, we reallocate
5867 + * a larger buffer and redo the key read when
5868 + * key_data_len < ret <= buflen.
5869 + */
5870 + if (ret > key_data_len) {
5871 + if (unlikely(key_data))
5872 + __kvzfree(key_data, key_data_len);
5873 + key_data_len = ret;
5874 + continue; /* Allocate buffer */
5875 + }
5876
5877 - /*
5878 - * Read methods will just return the required length without
5879 - * any copying if the provided length isn't large enough.
5880 - */
5881 - if (ret > 0 && ret <= buflen) {
5882 if (copy_to_user(buffer, key_data, ret))
5883 ret = -EFAULT;
5884 + break;
5885 }
5886 - kzfree(key_data);
5887 + __kvzfree(key_data, key_data_len);
5888
5889 key_put_out:
5890 key_put(key);
5891 diff --git a/sound/pci/hda/hda_intel.c b/sound/pci/hda/hda_intel.c
5892 index 72bbfeddea24..dd77b9ffe5fd 100644
5893 --- a/sound/pci/hda/hda_intel.c
5894 +++ b/sound/pci/hda/hda_intel.c
5895 @@ -2024,7 +2024,6 @@ static void pcm_mmap_prepare(struct snd_pcm_substream *substream,
5896 * should be ignored from the beginning.
5897 */
5898 static const struct snd_pci_quirk driver_blacklist[] = {
5899 - SND_PCI_QUIRK(0x1043, 0x874f, "ASUS ROG Zenith II / Strix", 0),
5900 SND_PCI_QUIRK(0x1462, 0xcb59, "MSI TRX40 Creator", 0),
5901 SND_PCI_QUIRK(0x1462, 0xcb60, "MSI TRX40", 0),
5902 {}
5903 diff --git a/sound/pci/hda/patch_hdmi.c b/sound/pci/hda/patch_hdmi.c
5904 index 307ca1f03676..f1febfc47ba6 100644
5905 --- a/sound/pci/hda/patch_hdmi.c
5906 +++ b/sound/pci/hda/patch_hdmi.c
5907 @@ -57,6 +57,10 @@ MODULE_PARM_DESC(static_hdmi_pcm, "Don't restrict PCM parameters per ELD info");
5908 #define is_cherryview(codec) ((codec)->core.vendor_id == 0x80862883)
5909 #define is_valleyview_plus(codec) (is_valleyview(codec) || is_cherryview(codec))
5910
5911 +static bool enable_acomp = true;
5912 +module_param(enable_acomp, bool, 0444);
5913 +MODULE_PARM_DESC(enable_acomp, "Enable audio component binding (default=yes)");
5914 +
5915 struct hdmi_spec_per_cvt {
5916 hda_nid_t cvt_nid;
5917 int assigned;
5918 @@ -2550,6 +2554,11 @@ static void generic_acomp_init(struct hda_codec *codec,
5919 {
5920 struct hdmi_spec *spec = codec->spec;
5921
5922 + if (!enable_acomp) {
5923 + codec_info(codec, "audio component disabled by module option\n");
5924 + return;
5925 + }
5926 +
5927 spec->port2pin = port2pin;
5928 setup_drm_audio_ops(codec, ops);
5929 if (!snd_hdac_acomp_init(&codec->bus->core, &spec->drm_audio_ops,
5930 diff --git a/sound/pci/hda/patch_realtek.c b/sound/pci/hda/patch_realtek.c
5931 index 10c8b31f8507..ee1b89f2bcd5 100644
5932 --- a/sound/pci/hda/patch_realtek.c
5933 +++ b/sound/pci/hda/patch_realtek.c
5934 @@ -369,6 +369,7 @@ static void alc_fill_eapd_coef(struct hda_codec *codec)
5935 case 0x10ec0233:
5936 case 0x10ec0235:
5937 case 0x10ec0236:
5938 + case 0x10ec0245:
5939 case 0x10ec0255:
5940 case 0x10ec0256:
5941 case 0x10ec0257:
5942 @@ -789,9 +790,11 @@ static void alc_ssid_check(struct hda_codec *codec, const hda_nid_t *ports)
5943 {
5944 if (!alc_subsystem_id(codec, ports)) {
5945 struct alc_spec *spec = codec->spec;
5946 - codec_dbg(codec,
5947 - "realtek: Enable default setup for auto mode as fallback\n");
5948 - spec->init_amp = ALC_INIT_DEFAULT;
5949 + if (spec->init_amp == ALC_INIT_UNDEFINED) {
5950 + codec_dbg(codec,
5951 + "realtek: Enable default setup for auto mode as fallback\n");
5952 + spec->init_amp = ALC_INIT_DEFAULT;
5953 + }
5954 }
5955 }
5956
5957 @@ -8100,6 +8103,7 @@ static int patch_alc269(struct hda_codec *codec)
5958 spec->gen.mixer_nid = 0;
5959 break;
5960 case 0x10ec0215:
5961 + case 0x10ec0245:
5962 case 0x10ec0285:
5963 case 0x10ec0289:
5964 spec->codec_variant = ALC269_TYPE_ALC215;
5965 @@ -9361,6 +9365,7 @@ static const struct hda_device_id snd_hda_id_realtek[] = {
5966 HDA_CODEC_ENTRY(0x10ec0234, "ALC234", patch_alc269),
5967 HDA_CODEC_ENTRY(0x10ec0235, "ALC233", patch_alc269),
5968 HDA_CODEC_ENTRY(0x10ec0236, "ALC236", patch_alc269),
5969 + HDA_CODEC_ENTRY(0x10ec0245, "ALC245", patch_alc269),
5970 HDA_CODEC_ENTRY(0x10ec0255, "ALC255", patch_alc269),
5971 HDA_CODEC_ENTRY(0x10ec0256, "ALC256", patch_alc269),
5972 HDA_CODEC_ENTRY(0x10ec0257, "ALC257", patch_alc269),
5973 diff --git a/sound/soc/intel/atom/sst-atom-controls.c b/sound/soc/intel/atom/sst-atom-controls.c
5974 index f883c9340eee..df8f7994d3b7 100644
5975 --- a/sound/soc/intel/atom/sst-atom-controls.c
5976 +++ b/sound/soc/intel/atom/sst-atom-controls.c
5977 @@ -966,7 +966,9 @@ static int sst_set_be_modules(struct snd_soc_dapm_widget *w,
5978 dev_dbg(c->dev, "Enter: widget=%s\n", w->name);
5979
5980 if (SND_SOC_DAPM_EVENT_ON(event)) {
5981 + mutex_lock(&drv->lock);
5982 ret = sst_send_slot_map(drv);
5983 + mutex_unlock(&drv->lock);
5984 if (ret)
5985 return ret;
5986 ret = sst_send_pipe_module_params(w, k);
5987 diff --git a/sound/soc/intel/boards/bytcr_rt5640.c b/sound/soc/intel/boards/bytcr_rt5640.c
5988 index 243f683bc02a..e62e1d7815aa 100644
5989 --- a/sound/soc/intel/boards/bytcr_rt5640.c
5990 +++ b/sound/soc/intel/boards/bytcr_rt5640.c
5991 @@ -591,6 +591,17 @@ static const struct dmi_system_id byt_rt5640_quirk_table[] = {
5992 BYT_RT5640_SSP0_AIF1 |
5993 BYT_RT5640_MCLK_EN),
5994 },
5995 + {
5996 + /* MPMAN MPWIN895CL */
5997 + .matches = {
5998 + DMI_EXACT_MATCH(DMI_SYS_VENDOR, "MPMAN"),
5999 + DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "MPWIN8900CL"),
6000 + },
6001 + .driver_data = (void *)(BYTCR_INPUT_DEFAULTS |
6002 + BYT_RT5640_MONO_SPEAKER |
6003 + BYT_RT5640_SSP0_AIF1 |
6004 + BYT_RT5640_MCLK_EN),
6005 + },
6006 { /* MSI S100 tablet */
6007 .matches = {
6008 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Micro-Star International Co., Ltd."),
6009 diff --git a/sound/soc/soc-dapm.c b/sound/soc/soc-dapm.c
6010 index e0ff40b10d85..06aa39379749 100644
6011 --- a/sound/soc/soc-dapm.c
6012 +++ b/sound/soc/soc-dapm.c
6013 @@ -423,7 +423,7 @@ static int dapm_kcontrol_data_alloc(struct snd_soc_dapm_widget *widget,
6014
6015 memset(&template, 0, sizeof(template));
6016 template.reg = e->reg;
6017 - template.mask = e->mask << e->shift_l;
6018 + template.mask = e->mask;
6019 template.shift = e->shift_l;
6020 template.off_val = snd_soc_enum_item_to_val(e, 0);
6021 template.on_val = template.off_val;
6022 @@ -546,8 +546,22 @@ static bool dapm_kcontrol_set_value(const struct snd_kcontrol *kcontrol,
6023 if (data->value == value)
6024 return false;
6025
6026 - if (data->widget)
6027 - data->widget->on_val = value;
6028 + if (data->widget) {
6029 + switch (dapm_kcontrol_get_wlist(kcontrol)->widgets[0]->id) {
6030 + case snd_soc_dapm_switch:
6031 + case snd_soc_dapm_mixer:
6032 + case snd_soc_dapm_mixer_named_ctl:
6033 + data->widget->on_val = value & data->widget->mask;
6034 + break;
6035 + case snd_soc_dapm_demux:
6036 + case snd_soc_dapm_mux:
6037 + data->widget->on_val = value >> data->widget->shift;
6038 + break;
6039 + default:
6040 + data->widget->on_val = value;
6041 + break;
6042 + }
6043 + }
6044
6045 data->value = value;
6046
6047 diff --git a/sound/soc/sof/trace.c b/sound/soc/sof/trace.c
6048 index 4c3cff031fd6..fd6f5913782b 100644
6049 --- a/sound/soc/sof/trace.c
6050 +++ b/sound/soc/sof/trace.c
6051 @@ -328,7 +328,10 @@ void snd_sof_free_trace(struct snd_sof_dev *sdev)
6052 {
6053 snd_sof_release_trace(sdev);
6054
6055 - snd_dma_free_pages(&sdev->dmatb);
6056 - snd_dma_free_pages(&sdev->dmatp);
6057 + if (sdev->dma_trace_pages) {
6058 + snd_dma_free_pages(&sdev->dmatb);
6059 + snd_dma_free_pages(&sdev->dmatp);
6060 + sdev->dma_trace_pages = 0;
6061 + }
6062 }
6063 EXPORT_SYMBOL(snd_sof_free_trace);
6064 diff --git a/sound/usb/format.c b/sound/usb/format.c
6065 index f4f0cf3deaf0..1f9ea513230a 100644
6066 --- a/sound/usb/format.c
6067 +++ b/sound/usb/format.c
6068 @@ -226,6 +226,52 @@ static int parse_audio_format_rates_v1(struct snd_usb_audio *chip, struct audiof
6069 return 0;
6070 }
6071
6072 +/*
6073 + * Many Focusrite devices supports a limited set of sampling rates per
6074 + * altsetting. Maximum rate is exposed in the last 4 bytes of Format Type
6075 + * descriptor which has a non-standard bLength = 10.
6076 + */
6077 +static bool focusrite_valid_sample_rate(struct snd_usb_audio *chip,
6078 + struct audioformat *fp,
6079 + unsigned int rate)
6080 +{
6081 + struct usb_interface *iface;
6082 + struct usb_host_interface *alts;
6083 + unsigned char *fmt;
6084 + unsigned int max_rate;
6085 +
6086 + iface = usb_ifnum_to_if(chip->dev, fp->iface);
6087 + if (!iface)
6088 + return true;
6089 +
6090 + alts = &iface->altsetting[fp->altset_idx];
6091 + fmt = snd_usb_find_csint_desc(alts->extra, alts->extralen,
6092 + NULL, UAC_FORMAT_TYPE);
6093 + if (!fmt)
6094 + return true;
6095 +
6096 + if (fmt[0] == 10) { /* bLength */
6097 + max_rate = combine_quad(&fmt[6]);
6098 +
6099 + /* Validate max rate */
6100 + if (max_rate != 48000 &&
6101 + max_rate != 96000 &&
6102 + max_rate != 192000 &&
6103 + max_rate != 384000) {
6104 +
6105 + usb_audio_info(chip,
6106 + "%u:%d : unexpected max rate: %u\n",
6107 + fp->iface, fp->altsetting, max_rate);
6108 +
6109 + return true;
6110 + }
6111 +
6112 + return rate <= max_rate;
6113 + }
6114 +
6115 + return true;
6116 +}
6117 +
6118 /*
6119 * Helper function to walk the array of sample rate triplets reported by
6120 * the device. The problem is that we need to parse whole array first to
6121 @@ -262,6 +308,11 @@ static int parse_uac2_sample_rate_range(struct snd_usb_audio *chip,
6122 }
6123
6124 for (rate = min; rate <= max; rate += res) {
6125 + /* Filter out invalid rates on Focusrite devices */
6126 + if (USB_ID_VENDOR(chip->usb_id) == 0x1235 &&
6127 + !focusrite_valid_sample_rate(chip, fp, rate))
6128 + goto skip_rate;
6129 +
6130 if (fp->rate_table)
6131 fp->rate_table[nr_rates] = rate;
6132 if (!fp->rate_min || rate < fp->rate_min)
6133 @@ -276,6 +327,7 @@ static int parse_uac2_sample_rate_range(struct snd_usb_audio *chip,
6134 break;
6135 }
6136
6137 +skip_rate:
6138 /* avoid endless loop */
6139 if (res == 0)
6140 break;
6141 diff --git a/sound/usb/mixer.c b/sound/usb/mixer.c
6142 index 5661994e13e7..583edacc9fe8 100644
6143 --- a/sound/usb/mixer.c
6144 +++ b/sound/usb/mixer.c
6145 @@ -1755,8 +1755,10 @@ static void build_connector_control(struct usb_mixer_interface *mixer,
6146 {
6147 struct snd_kcontrol *kctl;
6148 struct usb_mixer_elem_info *cval;
6149 + const struct usbmix_name_map *map;
6150
6151 - if (check_ignored_ctl(find_map(imap, term->id, 0)))
6152 + map = find_map(imap, term->id, 0);
6153 + if (check_ignored_ctl(map))
6154 return;
6155
6156 cval = kzalloc(sizeof(*cval), GFP_KERNEL);
6157 @@ -1788,8 +1790,12 @@ static void build_connector_control(struct usb_mixer_interface *mixer,
6158 usb_mixer_elem_info_free(cval);
6159 return;
6160 }
6161 - get_connector_control_name(mixer, term, is_input, kctl->id.name,
6162 - sizeof(kctl->id.name));
6163 +
6164 + if (check_mapped_name(map, kctl->id.name, sizeof(kctl->id.name)))
6165 + strlcat(kctl->id.name, " Jack", sizeof(kctl->id.name));
6166 + else
6167 + get_connector_control_name(mixer, term, is_input, kctl->id.name,
6168 + sizeof(kctl->id.name));
6169 kctl->private_free = snd_usb_mixer_elem_free;
6170 snd_usb_mixer_add_control(&cval->head, kctl);
6171 }
6172 @@ -3090,6 +3096,7 @@ static int snd_usb_mixer_controls(struct usb_mixer_interface *mixer)
6173 if (map->id == state.chip->usb_id) {
6174 state.map = map->map;
6175 state.selector_map = map->selector_map;
6176 + mixer->connector_map = map->connector_map;
6177 mixer->ignore_ctl_error |= map->ignore_ctl_error;
6178 break;
6179 }
6180 @@ -3171,10 +3178,32 @@ static int snd_usb_mixer_controls(struct usb_mixer_interface *mixer)
6181 return 0;
6182 }
6183
6184 +static int delegate_notify(struct usb_mixer_interface *mixer, int unitid,
6185 + u8 *control, u8 *channel)
6186 +{
6187 + const struct usbmix_connector_map *map = mixer->connector_map;
6188 +
6189 + if (!map)
6190 + return unitid;
6191 +
6192 + for (; map->id; map++) {
6193 + if (map->id == unitid) {
6194 + if (control && map->control)
6195 + *control = map->control;
6196 + if (channel && map->channel)
6197 + *channel = map->channel;
6198 + return map->delegated_id;
6199 + }
6200 + }
6201 + return unitid;
6202 +}
6203 +
6204 void snd_usb_mixer_notify_id(struct usb_mixer_interface *mixer, int unitid)
6205 {
6206 struct usb_mixer_elem_list *list;
6207
6208 + unitid = delegate_notify(mixer, unitid, NULL, NULL);
6209 +
6210 for_each_mixer_elem(list, mixer, unitid) {
6211 struct usb_mixer_elem_info *info =
6212 mixer_elem_list_to_info(list);
6213 @@ -3244,6 +3273,8 @@ static void snd_usb_mixer_interrupt_v2(struct usb_mixer_interface *mixer,
6214 return;
6215 }
6216
6217 + unitid = delegate_notify(mixer, unitid, &control, &channel);
6218 +
6219 for_each_mixer_elem(list, mixer, unitid)
6220 count++;
6221
6222 diff --git a/sound/usb/mixer.h b/sound/usb/mixer.h
6223 index 37e1b234c802..8e0fb7fdf1a0 100644
6224 --- a/sound/usb/mixer.h
6225 +++ b/sound/usb/mixer.h
6226 @@ -6,6 +6,13 @@
6227
6228 struct media_mixer_ctl;
6229
6230 +struct usbmix_connector_map {
6231 + u8 id;
6232 + u8 delegated_id;
6233 + u8 control;
6234 + u8 channel;
6235 +};
6236 +
6237 struct usb_mixer_interface {
6238 struct snd_usb_audio *chip;
6239 struct usb_host_interface *hostif;
6240 @@ -18,6 +25,9 @@ struct usb_mixer_interface {
6241 /* the usb audio specification version this interface complies to */
6242 int protocol;
6243
6244 + /* optional connector delegation map */
6245 + const struct usbmix_connector_map *connector_map;
6246 +
6247 /* Sound Blaster remote control stuff */
6248 const struct rc_config *rc_cfg;
6249 u32 rc_code;
6250 diff --git a/sound/usb/mixer_maps.c b/sound/usb/mixer_maps.c
6251 index 3a54ca04ec4c..39d6c6fa5e33 100644
6252 --- a/sound/usb/mixer_maps.c
6253 +++ b/sound/usb/mixer_maps.c
6254 @@ -27,6 +27,7 @@ struct usbmix_ctl_map {
6255 u32 id;
6256 const struct usbmix_name_map *map;
6257 const struct usbmix_selector_map *selector_map;
6258 + const struct usbmix_connector_map *connector_map;
6259 int ignore_ctl_error;
6260 };
6261
6262 @@ -359,6 +360,33 @@ static const struct usbmix_name_map asus_rog_map[] = {
6263 {}
6264 };
6265
6266 +/* TRX40 mobos with Realtek ALC1220-VB */
6267 +static const struct usbmix_name_map trx40_mobo_map[] = {
6268 + { 18, NULL }, /* OT, IEC958 - broken response, disabled */
6269 + { 19, NULL, 12 }, /* FU, Input Gain Pad - broken response, disabled */
6270 + { 16, "Speaker" }, /* OT */
6271 + { 22, "Speaker Playback" }, /* FU */
6272 + { 7, "Line" }, /* IT */
6273 + { 19, "Line Capture" }, /* FU */
6274 + { 17, "Front Headphone" }, /* OT */
6275 + { 23, "Front Headphone Playback" }, /* FU */
6276 + { 8, "Mic" }, /* IT */
6277 + { 20, "Mic Capture" }, /* FU */
6278 + { 9, "Front Mic" }, /* IT */
6279 + { 21, "Front Mic Capture" }, /* FU */
6280 + { 24, "IEC958 Playback" }, /* FU */
6281 + {}
6282 +};
6283 +
6284 +static const struct usbmix_connector_map trx40_mobo_connector_map[] = {
6285 + { 10, 16 }, /* (Back) Speaker */
6286 + { 11, 17 }, /* Front Headphone */
6287 + { 13, 7 }, /* Line */
6288 + { 14, 8 }, /* Mic */
6289 + { 15, 9 }, /* Front Mic */
6290 + {}
6291 +};
6292 +
6293 /*
6294 * Control map entries
6295 */
6296 @@ -480,7 +508,8 @@ static struct usbmix_ctl_map usbmix_ctl_maps[] = {
6297 },
6298 { /* Gigabyte TRX40 Aorus Pro WiFi */
6299 .id = USB_ID(0x0414, 0xa002),
6300 - .map = asus_rog_map,
6301 + .map = trx40_mobo_map,
6302 + .connector_map = trx40_mobo_connector_map,
6303 },
6304 { /* ASUS ROG Zenith II */
6305 .id = USB_ID(0x0b05, 0x1916),
6306 @@ -492,11 +521,13 @@ static struct usbmix_ctl_map usbmix_ctl_maps[] = {
6307 },
6308 { /* MSI TRX40 Creator */
6309 .id = USB_ID(0x0db0, 0x0d64),
6310 - .map = asus_rog_map,
6311 + .map = trx40_mobo_map,
6312 + .connector_map = trx40_mobo_connector_map,
6313 },
6314 { /* MSI TRX40 */
6315 .id = USB_ID(0x0db0, 0x543d),
6316 - .map = asus_rog_map,
6317 + .map = trx40_mobo_map,
6318 + .connector_map = trx40_mobo_connector_map,
6319 },
6320 { 0 } /* terminator */
6321 };
6322 diff --git a/sound/usb/mixer_quirks.c b/sound/usb/mixer_quirks.c
6323 index 39e27ae6c597..dc181066c799 100644
6324 --- a/sound/usb/mixer_quirks.c
6325 +++ b/sound/usb/mixer_quirks.c
6326 @@ -1508,11 +1508,15 @@ static int snd_microii_spdif_default_get(struct snd_kcontrol *kcontrol,
6327
6328 /* use known values for that card: interface#1 altsetting#1 */
6329 iface = usb_ifnum_to_if(chip->dev, 1);
6330 - if (!iface || iface->num_altsetting < 2)
6331 - return -EINVAL;
6332 + if (!iface || iface->num_altsetting < 2) {
6333 + err = -EINVAL;
6334 + goto end;
6335 + }
6336 alts = &iface->altsetting[1];
6337 - if (get_iface_desc(alts)->bNumEndpoints < 1)
6338 - return -EINVAL;
6339 + if (get_iface_desc(alts)->bNumEndpoints < 1) {
6340 + err = -EINVAL;
6341 + goto end;
6342 + }
6343 ep = get_endpoint(alts, 0)->bEndpointAddress;
6344
6345 err = snd_usb_ctl_msg(chip->dev,
6346 diff --git a/sound/usb/quirks-table.h b/sound/usb/quirks-table.h
6347 index d187aa6d50db..8c2f5c23e1b4 100644
6348 --- a/sound/usb/quirks-table.h
6349 +++ b/sound/usb/quirks-table.h
6350 @@ -3592,5 +3592,61 @@ AU0828_DEVICE(0x2040, 0x7270, "Hauppauge", "HVR-950Q"),
6351 }
6352 }
6353 },
6354 +{
6355 + /*
6356 + * Pioneer DJ DJM-250MK2
6357 + * PCM is 8 channels out @ 48 fixed (endpoints 0x01).
6358 + * The output from computer to the mixer is usable.
6359 + *
6360 + * The input (phono or line to computer) is not working.
6361 + * It should be at endpoint 0x82 and probably also 8 channels,
6362 + * but it seems that it works only with Pioneer proprietary software.
6363 + * Even on officially supported OS, the Audacity was unable to record
6364 + * and Mixxx to recognize the control vinyls.
6365 + */
6366 + USB_DEVICE_VENDOR_SPEC(0x2b73, 0x0017),
6367 + .driver_info = (unsigned long) &(const struct snd_usb_audio_quirk) {
6368 + .ifnum = QUIRK_ANY_INTERFACE,
6369 + .type = QUIRK_COMPOSITE,
6370 + .data = (const struct snd_usb_audio_quirk[]) {
6371 + {
6372 + .ifnum = 0,
6373 + .type = QUIRK_AUDIO_FIXED_ENDPOINT,
6374 + .data = &(const struct audioformat) {
6375 + .formats = SNDRV_PCM_FMTBIT_S24_3LE,
6376 + .channels = 8, // outputs
6377 + .iface = 0,
6378 + .altsetting = 1,
6379 + .altset_idx = 1,
6380 + .endpoint = 0x01,
6381 + .ep_attr = USB_ENDPOINT_XFER_ISOC|
6382 + USB_ENDPOINT_SYNC_ASYNC,
6383 + .rates = SNDRV_PCM_RATE_48000,
6384 + .rate_min = 48000,
6385 + .rate_max = 48000,
6386 + .nr_rates = 1,
6387 + .rate_table = (unsigned int[]) { 48000 }
6388 + }
6389 + },
6390 + {
6391 + .ifnum = -1
6392 + }
6393 + }
6394 + }
6395 +},
6396 +
6397 +#define ALC1220_VB_DESKTOP(vend, prod) { \
6398 + USB_DEVICE(vend, prod), \
6399 + .driver_info = (unsigned long) & (const struct snd_usb_audio_quirk) { \
6400 + .vendor_name = "Realtek", \
6401 + .product_name = "ALC1220-VB-DT", \
6402 + .profile_name = "Realtek-ALC1220-VB-Desktop", \
6403 + .ifnum = QUIRK_NO_INTERFACE \
6404 + } \
6405 +}
6406 +ALC1220_VB_DESKTOP(0x0414, 0xa002), /* Gigabyte TRX40 Aorus Pro WiFi */
6407 +ALC1220_VB_DESKTOP(0x0db0, 0x0d64), /* MSI TRX40 Creator */
6408 +ALC1220_VB_DESKTOP(0x0db0, 0x543d), /* MSI TRX40 */
6409 +#undef ALC1220_VB_DESKTOP
6410
6411 #undef USB_DEVICE_VENDOR_SPEC
6412 diff --git a/sound/usb/usx2y/usbusx2yaudio.c b/sound/usb/usx2y/usbusx2yaudio.c
6413 index 89fa287678fc..e0bace4d1c40 100644
6414 --- a/sound/usb/usx2y/usbusx2yaudio.c
6415 +++ b/sound/usb/usx2y/usbusx2yaudio.c
6416 @@ -681,6 +681,8 @@ static int usX2Y_rate_set(struct usX2Ydev *usX2Y, int rate)
6417 us->submitted = 2*NOOF_SETRATE_URBS;
6418 for (i = 0; i < NOOF_SETRATE_URBS; ++i) {
6419 struct urb *urb = us->urb[i];
6420 + if (!urb)
6421 + continue;
6422 if (urb->status) {
6423 if (!err)
6424 err = -ENODEV;
6425 diff --git a/tools/lib/bpf/Makefile b/tools/lib/bpf/Makefile
6426 index 33e2638ef7f0..122321d54922 100644
6427 --- a/tools/lib/bpf/Makefile
6428 +++ b/tools/lib/bpf/Makefile
6429 @@ -145,7 +145,7 @@ PC_FILE := $(addprefix $(OUTPUT),$(PC_FILE))
6430
6431 GLOBAL_SYM_COUNT = $(shell readelf -s --wide $(BPF_IN_SHARED) | \
6432 cut -d "@" -f1 | sed 's/_v[0-9]_[0-9]_[0-9].*//' | \
6433 - awk '/GLOBAL/ && /DEFAULT/ && !/UND/ {print $$8}' | \
6434 + awk '/GLOBAL/ && /DEFAULT/ && !/UND/ {print $$NF}' | \
6435 sort -u | wc -l)
6436 VERSIONED_SYM_COUNT = $(shell readelf -s --wide $(OUTPUT)libbpf.so | \
6437 grep -Eo '[^ ]+@LIBBPF_' | cut -d@ -f1 | sort -u | wc -l)
6438 @@ -217,7 +217,7 @@ check_abi: $(OUTPUT)libbpf.so
6439 "versioned in $(VERSION_SCRIPT)." >&2; \
6440 readelf -s --wide $(BPF_IN_SHARED) | \
6441 cut -d "@" -f1 | sed 's/_v[0-9]_[0-9]_[0-9].*//' | \
6442 - awk '/GLOBAL/ && /DEFAULT/ && !/UND/ {print $$8}'| \
6443 + awk '/GLOBAL/ && /DEFAULT/ && !/UND/ {print $$NF}'| \
6444 sort -u > $(OUTPUT)libbpf_global_syms.tmp; \
6445 readelf -s --wide $(OUTPUT)libbpf.so | \
6446 grep -Eo '[^ ]+@LIBBPF_' | cut -d@ -f1 | \
6447 diff --git a/tools/testing/nvdimm/Kbuild b/tools/testing/nvdimm/Kbuild
6448 index c4a9196d794c..cb80d3b81179 100644
6449 --- a/tools/testing/nvdimm/Kbuild
6450 +++ b/tools/testing/nvdimm/Kbuild
6451 @@ -21,8 +21,8 @@ DRIVERS := ../../../drivers
6452 NVDIMM_SRC := $(DRIVERS)/nvdimm
6453 ACPI_SRC := $(DRIVERS)/acpi/nfit
6454 DAX_SRC := $(DRIVERS)/dax
6455 -ccflags-y := -I$(src)/$(NVDIMM_SRC)/
6456 -ccflags-y += -I$(src)/$(ACPI_SRC)/
6457 +ccflags-y := -I$(srctree)/drivers/nvdimm/
6458 +ccflags-y += -I$(srctree)/drivers/acpi/nfit/
6459
6460 obj-$(CONFIG_LIBNVDIMM) += libnvdimm.o
6461 obj-$(CONFIG_BLK_DEV_PMEM) += nd_pmem.o
6462 diff --git a/tools/testing/nvdimm/test/Kbuild b/tools/testing/nvdimm/test/Kbuild
6463 index fb3c3d7cdb9b..75baebf8f4ba 100644
6464 --- a/tools/testing/nvdimm/test/Kbuild
6465 +++ b/tools/testing/nvdimm/test/Kbuild
6466 @@ -1,6 +1,6 @@
6467 # SPDX-License-Identifier: GPL-2.0
6468 -ccflags-y := -I$(src)/../../../../drivers/nvdimm/
6469 -ccflags-y += -I$(src)/../../../../drivers/acpi/nfit/
6470 +ccflags-y := -I$(srctree)/drivers/nvdimm/
6471 +ccflags-y += -I$(srctree)/drivers/acpi/nfit/
6472
6473 obj-m += nfit_test.o
6474 obj-m += nfit_test_iomap.o
6475 diff --git a/tools/testing/nvdimm/test/nfit.c b/tools/testing/nvdimm/test/nfit.c
6476 index bf6422a6af7f..a8ee5c4d41eb 100644
6477 --- a/tools/testing/nvdimm/test/nfit.c
6478 +++ b/tools/testing/nvdimm/test/nfit.c
6479 @@ -3164,7 +3164,9 @@ static __init int nfit_test_init(void)
6480 mcsafe_test();
6481 dax_pmem_test();
6482 dax_pmem_core_test();
6483 +#ifdef CONFIG_DEV_DAX_PMEM_COMPAT
6484 dax_pmem_compat_test();
6485 +#endif
6486
6487 nfit_test_setup(nfit_test_lookup, nfit_test_evaluate_dsm);
6488
6489 diff --git a/tools/testing/selftests/ftrace/settings b/tools/testing/selftests/ftrace/settings
6490 new file mode 100644
6491 index 000000000000..e7b9417537fb
6492 --- /dev/null
6493 +++ b/tools/testing/selftests/ftrace/settings
6494 @@ -0,0 +1 @@
6495 +timeout=0
6496 diff --git a/tools/testing/selftests/kmod/kmod.sh b/tools/testing/selftests/kmod/kmod.sh
6497 index 8b944cf042f6..315a43111e04 100755
6498 --- a/tools/testing/selftests/kmod/kmod.sh
6499 +++ b/tools/testing/selftests/kmod/kmod.sh
6500 @@ -505,18 +505,23 @@ function test_num()
6501 fi
6502 }
6503
6504 -function get_test_count()
6505 +function get_test_data()
6506 {
6507 test_num $1
6508 - TEST_DATA=$(echo $ALL_TESTS | awk '{print $'$1'}')
6509 + local field_num=$(echo $1 | sed 's/^0*//')
6510 + echo $ALL_TESTS | awk '{print $'$field_num'}'
6511 +}
6512 +
6513 +function get_test_count()
6514 +{
6515 + TEST_DATA=$(get_test_data $1)
6516 LAST_TWO=${TEST_DATA#*:*}
6517 echo ${LAST_TWO%:*}
6518 }
6519
6520 function get_test_enabled()
6521 {
6522 - test_num $1
6523 - TEST_DATA=$(echo $ALL_TESTS | awk '{print $'$1'}')
6524 + TEST_DATA=$(get_test_data $1)
6525 echo ${TEST_DATA#*:*:}
6526 }
6527
6528 diff --git a/tools/testing/selftests/net/fib_nexthops.sh b/tools/testing/selftests/net/fib_nexthops.sh
6529 index 796670ebc65b..6560ed796ac4 100755
6530 --- a/tools/testing/selftests/net/fib_nexthops.sh
6531 +++ b/tools/testing/selftests/net/fib_nexthops.sh
6532 @@ -749,6 +749,29 @@ ipv4_fcnal_runtime()
6533 run_cmd "ip netns exec me ping -c1 -w1 172.16.101.1"
6534 log_test $? 0 "Ping - multipath"
6535
6536 + run_cmd "$IP ro delete 172.16.101.1/32 nhid 122"
6537 +
6538 + #
6539 + # multiple default routes
6540 + # - tests fib_select_default
6541 + run_cmd "$IP nexthop add id 501 via 172.16.1.2 dev veth1"
6542 + run_cmd "$IP ro add default nhid 501"
6543 + run_cmd "$IP ro add default via 172.16.1.3 dev veth1 metric 20"
6544 + run_cmd "ip netns exec me ping -c1 -w1 172.16.101.1"
6545 + log_test $? 0 "Ping - multiple default routes, nh first"
6546 +
6547 + # flip the order
6548 + run_cmd "$IP ro del default nhid 501"
6549 + run_cmd "$IP ro del default via 172.16.1.3 dev veth1 metric 20"
6550 + run_cmd "$IP ro add default via 172.16.1.2 dev veth1 metric 20"
6551 + run_cmd "$IP nexthop replace id 501 via 172.16.1.3 dev veth1"
6552 + run_cmd "$IP ro add default nhid 501 metric 20"
6553 + run_cmd "ip netns exec me ping -c1 -w1 172.16.101.1"
6554 + log_test $? 0 "Ping - multiple default routes, nh second"
6555 +
6556 + run_cmd "$IP nexthop delete nhid 501"
6557 + run_cmd "$IP ro del default"
6558 +
6559 #
6560 # IPv4 with blackhole nexthops
6561 #
6562 diff --git a/tools/testing/selftests/net/fib_tests.sh b/tools/testing/selftests/net/fib_tests.sh
6563 index 09854f8a0b57..4811067d9b05 100755
6564 --- a/tools/testing/selftests/net/fib_tests.sh
6565 +++ b/tools/testing/selftests/net/fib_tests.sh
6566 @@ -618,16 +618,22 @@ fib_nexthop_test()
6567
6568 fib_suppress_test()
6569 {
6570 + echo
6571 + echo "FIB rule with suppress_prefixlength"
6572 + setup
6573 +
6574 $IP link add dummy1 type dummy
6575 $IP link set dummy1 up
6576 $IP -6 route add default dev dummy1
6577 $IP -6 rule add table main suppress_prefixlength 0
6578 - ping -f -c 1000 -W 1 1234::1 || true
6579 + ping -f -c 1000 -W 1 1234::1 >/dev/null 2>&1
6580 $IP -6 rule del table main suppress_prefixlength 0
6581 $IP link del dummy1
6582
6583 # If we got here without crashing, we're good.
6584 - return 0
6585 + log_test 0 0 "FIB rule suppress test"
6586 +
6587 + cleanup
6588 }
6589
6590 ################################################################################
6591 diff --git a/tools/vm/Makefile b/tools/vm/Makefile
6592 index 20f6cf04377f..9860622cbb15 100644
6593 --- a/tools/vm/Makefile
6594 +++ b/tools/vm/Makefile
6595 @@ -1,6 +1,8 @@
6596 # SPDX-License-Identifier: GPL-2.0
6597 # Makefile for vm tools
6598 #
6599 +include ../scripts/Makefile.include
6600 +
6601 TARGETS=page-types slabinfo page_owner_sort
6602
6603 LIB_DIR = ../lib/api