Magellan Linux

Annotation of /trunk/kernel-alx/patches-5.4/0163-5.4.64-all-fixes.patch

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3628 - (hide annotations) (download)
Fri Sep 11 05:55:49 2020 UTC (3 years, 8 months ago) by niro
File size: 166500 byte(s)
-linux-5.4.64
1 niro 3628 diff --git a/Documentation/devicetree/bindings/mmc/mtk-sd.txt b/Documentation/devicetree/bindings/mmc/mtk-sd.txt
2     index 8a532f4453f26..09aecec47003a 100644
3     --- a/Documentation/devicetree/bindings/mmc/mtk-sd.txt
4     +++ b/Documentation/devicetree/bindings/mmc/mtk-sd.txt
5     @@ -49,6 +49,8 @@ Optional properties:
6     error caused by stop clock(fifo full)
7     Valid range = [0:0x7]. if not present, default value is 0.
8     applied to compatible "mediatek,mt2701-mmc".
9     +- resets: Phandle and reset specifier pair to softreset line of MSDC IP.
10     +- reset-names: Should be "hrst".
11    
12     Examples:
13     mmc0: mmc@11230000 {
14     diff --git a/Documentation/filesystems/affs.txt b/Documentation/filesystems/affs.txt
15     index 71b63c2b98410..a8f1a58e36922 100644
16     --- a/Documentation/filesystems/affs.txt
17     +++ b/Documentation/filesystems/affs.txt
18     @@ -93,13 +93,15 @@ The Amiga protection flags RWEDRWEDHSPARWED are handled as follows:
19    
20     - R maps to r for user, group and others. On directories, R implies x.
21    
22     - - If both W and D are allowed, w will be set.
23     + - W maps to w.
24    
25     - E maps to x.
26    
27     - - H and P are always retained and ignored under Linux.
28     + - D is ignored.
29    
30     - - A is always reset when a file is written to.
31     + - H, S and P are always retained and ignored under Linux.
32     +
33     + - A is cleared when a file is written to.
34    
35     User id and group id will be used unless set[gu]id are given as mount
36     options. Since most of the Amiga file systems are single user systems
37     @@ -111,11 +113,13 @@ Linux -> Amiga:
38    
39     The Linux rwxrwxrwx file mode is handled as follows:
40    
41     - - r permission will set R for user, group and others.
42     + - r permission will allow R for user, group and others.
43     +
44     + - w permission will allow W for user, group and others.
45    
46     - - w permission will set W and D for user, group and others.
47     + - x permission of the user will allow E for plain files.
48    
49     - - x permission of the user will set E for plain files.
50     + - D will be allowed for user, group and others.
51    
52     - All other flags (suid, sgid, ...) are ignored and will
53     not be retained.
54     diff --git a/Makefile b/Makefile
55     index 418814b108ae6..7bdfb21bb9269 100644
56     --- a/Makefile
57     +++ b/Makefile
58     @@ -1,7 +1,7 @@
59     # SPDX-License-Identifier: GPL-2.0
60     VERSION = 5
61     PATCHLEVEL = 4
62     -SUBLEVEL = 63
63     +SUBLEVEL = 64
64     EXTRAVERSION =
65     NAME = Kleptomaniac Octopus
66    
67     diff --git a/arch/arc/kernel/perf_event.c b/arch/arc/kernel/perf_event.c
68     index 661fd842ea97d..79849f37e782c 100644
69     --- a/arch/arc/kernel/perf_event.c
70     +++ b/arch/arc/kernel/perf_event.c
71     @@ -562,7 +562,7 @@ static int arc_pmu_device_probe(struct platform_device *pdev)
72     {
73     struct arc_reg_pct_build pct_bcr;
74     struct arc_reg_cc_build cc_bcr;
75     - int i, has_interrupts;
76     + int i, has_interrupts, irq;
77     int counter_size; /* in bits */
78    
79     union cc_name {
80     @@ -637,13 +637,7 @@ static int arc_pmu_device_probe(struct platform_device *pdev)
81     .attr_groups = arc_pmu->attr_groups,
82     };
83    
84     - if (has_interrupts) {
85     - int irq = platform_get_irq(pdev, 0);
86     -
87     - if (irq < 0) {
88     - pr_err("Cannot get IRQ number for the platform\n");
89     - return -ENODEV;
90     - }
91     + if (has_interrupts && (irq = platform_get_irq(pdev, 0) >= 0)) {
92    
93     arc_pmu->irq = irq;
94    
95     @@ -652,9 +646,9 @@ static int arc_pmu_device_probe(struct platform_device *pdev)
96     this_cpu_ptr(&arc_pmu_cpu));
97    
98     on_each_cpu(arc_cpu_pmu_irq_init, &irq, 1);
99     -
100     - } else
101     + } else {
102     arc_pmu->pmu.capabilities |= PERF_PMU_CAP_NO_INTERRUPT;
103     + }
104    
105     /*
106     * perf parser doesn't really like '-' symbol in events name, so let's
107     diff --git a/arch/arm64/boot/dts/mediatek/mt7622.dtsi b/arch/arm64/boot/dts/mediatek/mt7622.dtsi
108     index dac51e98204c0..7cd8c3f52b471 100644
109     --- a/arch/arm64/boot/dts/mediatek/mt7622.dtsi
110     +++ b/arch/arm64/boot/dts/mediatek/mt7622.dtsi
111     @@ -686,6 +686,8 @@
112     clocks = <&pericfg CLK_PERI_MSDC30_0_PD>,
113     <&topckgen CLK_TOP_MSDC50_0_SEL>;
114     clock-names = "source", "hclk";
115     + resets = <&pericfg MT7622_PERI_MSDC0_SW_RST>;
116     + reset-names = "hrst";
117     status = "disabled";
118     };
119    
120     diff --git a/arch/mips/kernel/smp-bmips.c b/arch/mips/kernel/smp-bmips.c
121     index 712c15de6ab9f..6b304acf506fe 100644
122     --- a/arch/mips/kernel/smp-bmips.c
123     +++ b/arch/mips/kernel/smp-bmips.c
124     @@ -241,6 +241,8 @@ static int bmips_boot_secondary(int cpu, struct task_struct *idle)
125     */
126     static void bmips_init_secondary(void)
127     {
128     + bmips_cpu_setup();
129     +
130     switch (current_cpu_type()) {
131     case CPU_BMIPS4350:
132     case CPU_BMIPS4380:
133     diff --git a/arch/mips/kernel/traps.c b/arch/mips/kernel/traps.c
134     index 6a25364600266..8282d0feb0b21 100644
135     --- a/arch/mips/kernel/traps.c
136     +++ b/arch/mips/kernel/traps.c
137     @@ -1240,6 +1240,18 @@ static int enable_restore_fp_context(int msa)
138     err = own_fpu_inatomic(1);
139     if (msa && !err) {
140     enable_msa();
141     + /*
142     + * with MSA enabled, userspace can see MSACSR
143     + * and MSA regs, but the values in them are from
144     + * other task before current task, restore them
145     + * from saved fp/msa context
146     + */
147     + write_msa_csr(current->thread.fpu.msacsr);
148     + /*
149     + * own_fpu_inatomic(1) just restore low 64bit,
150     + * fix the high 64bit
151     + */
152     + init_msa_upper();
153     set_thread_flag(TIF_USEDMSA);
154     set_thread_flag(TIF_MSA_CTX_LIVE);
155     }
156     diff --git a/arch/mips/mm/c-r4k.c b/arch/mips/mm/c-r4k.c
157     index 89b9c851d8227..c4785a456dedc 100644
158     --- a/arch/mips/mm/c-r4k.c
159     +++ b/arch/mips/mm/c-r4k.c
160     @@ -1676,7 +1676,11 @@ static void setup_scache(void)
161     printk("MIPS secondary cache %ldkB, %s, linesize %d bytes.\n",
162     scache_size >> 10,
163     way_string[c->scache.ways], c->scache.linesz);
164     +
165     + if (current_cpu_type() == CPU_BMIPS5000)
166     + c->options |= MIPS_CPU_INCLUSIVE_CACHES;
167     }
168     +
169     #else
170     if (!(c->scache.flags & MIPS_CACHE_NOT_PRESENT))
171     panic("Dunno how to handle MIPS32 / MIPS64 second level cache");
172     diff --git a/arch/s390/include/asm/percpu.h b/arch/s390/include/asm/percpu.h
173     index 50b4ce8cddfdc..918f0ba4f4d20 100644
174     --- a/arch/s390/include/asm/percpu.h
175     +++ b/arch/s390/include/asm/percpu.h
176     @@ -29,7 +29,7 @@
177     typedef typeof(pcp) pcp_op_T__; \
178     pcp_op_T__ old__, new__, prev__; \
179     pcp_op_T__ *ptr__; \
180     - preempt_disable(); \
181     + preempt_disable_notrace(); \
182     ptr__ = raw_cpu_ptr(&(pcp)); \
183     prev__ = *ptr__; \
184     do { \
185     @@ -37,7 +37,7 @@
186     new__ = old__ op (val); \
187     prev__ = cmpxchg(ptr__, old__, new__); \
188     } while (prev__ != old__); \
189     - preempt_enable(); \
190     + preempt_enable_notrace(); \
191     new__; \
192     })
193    
194     @@ -68,7 +68,7 @@
195     typedef typeof(pcp) pcp_op_T__; \
196     pcp_op_T__ val__ = (val); \
197     pcp_op_T__ old__, *ptr__; \
198     - preempt_disable(); \
199     + preempt_disable_notrace(); \
200     ptr__ = raw_cpu_ptr(&(pcp)); \
201     if (__builtin_constant_p(val__) && \
202     ((szcast)val__ > -129) && ((szcast)val__ < 128)) { \
203     @@ -84,7 +84,7 @@
204     : [val__] "d" (val__) \
205     : "cc"); \
206     } \
207     - preempt_enable(); \
208     + preempt_enable_notrace(); \
209     }
210    
211     #define this_cpu_add_4(pcp, val) arch_this_cpu_add(pcp, val, "laa", "asi", int)
212     @@ -95,14 +95,14 @@
213     typedef typeof(pcp) pcp_op_T__; \
214     pcp_op_T__ val__ = (val); \
215     pcp_op_T__ old__, *ptr__; \
216     - preempt_disable(); \
217     + preempt_disable_notrace(); \
218     ptr__ = raw_cpu_ptr(&(pcp)); \
219     asm volatile( \
220     op " %[old__],%[val__],%[ptr__]\n" \
221     : [old__] "=d" (old__), [ptr__] "+Q" (*ptr__) \
222     : [val__] "d" (val__) \
223     : "cc"); \
224     - preempt_enable(); \
225     + preempt_enable_notrace(); \
226     old__ + val__; \
227     })
228    
229     @@ -114,14 +114,14 @@
230     typedef typeof(pcp) pcp_op_T__; \
231     pcp_op_T__ val__ = (val); \
232     pcp_op_T__ old__, *ptr__; \
233     - preempt_disable(); \
234     + preempt_disable_notrace(); \
235     ptr__ = raw_cpu_ptr(&(pcp)); \
236     asm volatile( \
237     op " %[old__],%[val__],%[ptr__]\n" \
238     : [old__] "=d" (old__), [ptr__] "+Q" (*ptr__) \
239     : [val__] "d" (val__) \
240     : "cc"); \
241     - preempt_enable(); \
242     + preempt_enable_notrace(); \
243     }
244    
245     #define this_cpu_and_4(pcp, val) arch_this_cpu_to_op(pcp, val, "lan")
246     @@ -136,10 +136,10 @@
247     typedef typeof(pcp) pcp_op_T__; \
248     pcp_op_T__ ret__; \
249     pcp_op_T__ *ptr__; \
250     - preempt_disable(); \
251     + preempt_disable_notrace(); \
252     ptr__ = raw_cpu_ptr(&(pcp)); \
253     ret__ = cmpxchg(ptr__, oval, nval); \
254     - preempt_enable(); \
255     + preempt_enable_notrace(); \
256     ret__; \
257     })
258    
259     @@ -152,10 +152,10 @@
260     ({ \
261     typeof(pcp) *ptr__; \
262     typeof(pcp) ret__; \
263     - preempt_disable(); \
264     + preempt_disable_notrace(); \
265     ptr__ = raw_cpu_ptr(&(pcp)); \
266     ret__ = xchg(ptr__, nval); \
267     - preempt_enable(); \
268     + preempt_enable_notrace(); \
269     ret__; \
270     })
271    
272     @@ -171,11 +171,11 @@
273     typeof(pcp1) *p1__; \
274     typeof(pcp2) *p2__; \
275     int ret__; \
276     - preempt_disable(); \
277     + preempt_disable_notrace(); \
278     p1__ = raw_cpu_ptr(&(pcp1)); \
279     p2__ = raw_cpu_ptr(&(pcp2)); \
280     ret__ = __cmpxchg_double(p1__, p2__, o1__, o2__, n1__, n2__); \
281     - preempt_enable(); \
282     + preempt_enable_notrace(); \
283     ret__; \
284     })
285    
286     diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h
287     index 332eb35258676..902be2e6e96cf 100644
288     --- a/arch/x86/include/asm/ptrace.h
289     +++ b/arch/x86/include/asm/ptrace.h
290     @@ -309,8 +309,8 @@ static inline unsigned long regs_get_kernel_argument(struct pt_regs *regs,
291     static const unsigned int argument_offs[] = {
292     #ifdef __i386__
293     offsetof(struct pt_regs, ax),
294     - offsetof(struct pt_regs, cx),
295     offsetof(struct pt_regs, dx),
296     + offsetof(struct pt_regs, cx),
297     #define NR_REG_ARGUMENTS 3
298     #else
299     offsetof(struct pt_regs, di),
300     diff --git a/arch/x86/mm/numa_emulation.c b/arch/x86/mm/numa_emulation.c
301     index abffa0be80da1..87282258d5bea 100644
302     --- a/arch/x86/mm/numa_emulation.c
303     +++ b/arch/x86/mm/numa_emulation.c
304     @@ -321,7 +321,7 @@ static int __init split_nodes_size_interleave(struct numa_meminfo *ei,
305     u64 addr, u64 max_addr, u64 size)
306     {
307     return split_nodes_size_interleave_uniform(ei, pi, addr, max_addr, size,
308     - 0, NULL, NUMA_NO_NODE);
309     + 0, NULL, 0);
310     }
311    
312     int __init setup_emu2phys_nid(int *dfl_phys_nid)
313     diff --git a/block/blk-core.c b/block/blk-core.c
314     index d5e668ec751b5..ca6b677356864 100644
315     --- a/block/blk-core.c
316     +++ b/block/blk-core.c
317     @@ -502,6 +502,7 @@ struct request_queue *blk_alloc_queue_node(gfp_t gfp_mask, int node_id)
318     goto fail_stats;
319    
320     q->backing_dev_info->ra_pages = VM_READAHEAD_PAGES;
321     + q->backing_dev_info->io_pages = VM_READAHEAD_PAGES;
322     q->backing_dev_info->capabilities = BDI_CAP_CGROUP_WRITEBACK;
323     q->backing_dev_info->name = "block";
324     q->node = node_id;
325     diff --git a/block/blk-iocost.c b/block/blk-iocost.c
326     index dcc6685d5becc..ef287c33d6d97 100644
327     --- a/block/blk-iocost.c
328     +++ b/block/blk-iocost.c
329     @@ -2074,14 +2074,15 @@ static void ioc_pd_free(struct blkg_policy_data *pd)
330     {
331     struct ioc_gq *iocg = pd_to_iocg(pd);
332     struct ioc *ioc = iocg->ioc;
333     + unsigned long flags;
334    
335     if (ioc) {
336     - spin_lock(&ioc->lock);
337     + spin_lock_irqsave(&ioc->lock, flags);
338     if (!list_empty(&iocg->active_list)) {
339     propagate_active_weight(iocg, 0, 0);
340     list_del_init(&iocg->active_list);
341     }
342     - spin_unlock(&ioc->lock);
343     + spin_unlock_irqrestore(&ioc->lock, flags);
344    
345     hrtimer_cancel(&iocg->waitq_timer);
346     hrtimer_cancel(&iocg->delay_timer);
347     diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
348     index 35f75c691d7cf..066b37963ad5f 100644
349     --- a/drivers/ata/libata-core.c
350     +++ b/drivers/ata/libata-core.c
351     @@ -4474,9 +4474,8 @@ static const struct ata_blacklist_entry ata_device_blacklist [] = {
352     /* https://bugzilla.kernel.org/show_bug.cgi?id=15573 */
353     { "C300-CTFDDAC128MAG", "0001", ATA_HORKAGE_NONCQ, },
354    
355     - /* Some Sandisk SSDs lock up hard with NCQ enabled. Reported on
356     - SD7SN6S256G and SD8SN8U256G */
357     - { "SanDisk SD[78]SN*G", NULL, ATA_HORKAGE_NONCQ, },
358     + /* Sandisk SD7/8/9s lock up hard on large trims */
359     + { "SanDisk SD[789]*", NULL, ATA_HORKAGE_MAX_TRIM_128M, },
360    
361     /* devices which puke on READ_NATIVE_MAX */
362     { "HDS724040KLSA80", "KFAOA20N", ATA_HORKAGE_BROKEN_HPA, },
363     diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
364     index 5596c9b6ebf23..464efedc778b0 100644
365     --- a/drivers/ata/libata-scsi.c
366     +++ b/drivers/ata/libata-scsi.c
367     @@ -2374,6 +2374,7 @@ static unsigned int ata_scsiop_inq_89(struct ata_scsi_args *args, u8 *rbuf)
368    
369     static unsigned int ata_scsiop_inq_b0(struct ata_scsi_args *args, u8 *rbuf)
370     {
371     + struct ata_device *dev = args->dev;
372     u16 min_io_sectors;
373    
374     rbuf[1] = 0xb0;
375     @@ -2399,7 +2400,12 @@ static unsigned int ata_scsiop_inq_b0(struct ata_scsi_args *args, u8 *rbuf)
376     * with the unmap bit set.
377     */
378     if (ata_id_has_trim(args->id)) {
379     - put_unaligned_be64(65535 * ATA_MAX_TRIM_RNUM, &rbuf[36]);
380     + u64 max_blocks = 65535 * ATA_MAX_TRIM_RNUM;
381     +
382     + if (dev->horkage & ATA_HORKAGE_MAX_TRIM_128M)
383     + max_blocks = 128 << (20 - SECTOR_SHIFT);
384     +
385     + put_unaligned_be64(max_blocks, &rbuf[36]);
386     put_unaligned_be32(1, &rbuf[28]);
387     }
388    
389     diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c
390     index 7b61d53ba050e..7c577cabb9c3b 100644
391     --- a/drivers/block/nbd.c
392     +++ b/drivers/block/nbd.c
393     @@ -1349,6 +1349,8 @@ static void nbd_set_cmd_timeout(struct nbd_device *nbd, u64 timeout)
394     nbd->tag_set.timeout = timeout * HZ;
395     if (timeout)
396     blk_queue_rq_timeout(nbd->disk->queue, timeout * HZ);
397     + else
398     + blk_queue_rq_timeout(nbd->disk->queue, 30 * HZ);
399     }
400    
401     /* Must be called with config_lock held */
402     diff --git a/drivers/cpuidle/cpuidle.c b/drivers/cpuidle/cpuidle.c
403     index 29d2d7a21bd7b..73f08cda21e0e 100644
404     --- a/drivers/cpuidle/cpuidle.c
405     +++ b/drivers/cpuidle/cpuidle.c
406     @@ -148,7 +148,8 @@ static void enter_s2idle_proper(struct cpuidle_driver *drv,
407     */
408     stop_critical_timings();
409     drv->states[index].enter_s2idle(dev, drv, index);
410     - WARN_ON(!irqs_disabled());
411     + if (WARN_ON_ONCE(!irqs_disabled()))
412     + local_irq_disable();
413     /*
414     * timekeeping_resume() that will be called by tick_unfreeze() for the
415     * first CPU executing it calls functions containing RCU read-side
416     diff --git a/drivers/dma/at_hdmac.c b/drivers/dma/at_hdmac.c
417     index 672c73b4a2d4f..ff366c2f58c18 100644
418     --- a/drivers/dma/at_hdmac.c
419     +++ b/drivers/dma/at_hdmac.c
420     @@ -1667,6 +1667,8 @@ static struct dma_chan *at_dma_xlate(struct of_phandle_args *dma_spec,
421     return NULL;
422    
423     dmac_pdev = of_find_device_by_node(dma_spec->np);
424     + if (!dmac_pdev)
425     + return NULL;
426    
427     dma_cap_zero(mask);
428     dma_cap_set(DMA_SLAVE, mask);
429     diff --git a/drivers/dma/dw-edma/dw-edma-core.c b/drivers/dma/dw-edma/dw-edma-core.c
430     index ff392c01bad1f..7f9a86c3c58ff 100644
431     --- a/drivers/dma/dw-edma/dw-edma-core.c
432     +++ b/drivers/dma/dw-edma/dw-edma-core.c
433     @@ -391,7 +391,7 @@ dw_edma_device_transfer(struct dw_edma_transfer *xfer)
434     if (xfer->cyclic) {
435     burst->dar = xfer->xfer.cyclic.paddr;
436     } else {
437     - burst->dar = sg_dma_address(sg);
438     + burst->dar = dst_addr;
439     /* Unlike the typical assumption by other
440     * drivers/IPs the peripheral memory isn't
441     * a FIFO memory, in this case, it's a
442     @@ -399,14 +399,13 @@ dw_edma_device_transfer(struct dw_edma_transfer *xfer)
443     * and destination addresses are increased
444     * by the same portion (data length)
445     */
446     - src_addr += sg_dma_len(sg);
447     }
448     } else {
449     burst->dar = dst_addr;
450     if (xfer->cyclic) {
451     burst->sar = xfer->xfer.cyclic.paddr;
452     } else {
453     - burst->sar = sg_dma_address(sg);
454     + burst->sar = src_addr;
455     /* Unlike the typical assumption by other
456     * drivers/IPs the peripheral memory isn't
457     * a FIFO memory, in this case, it's a
458     @@ -414,12 +413,14 @@ dw_edma_device_transfer(struct dw_edma_transfer *xfer)
459     * and destination addresses are increased
460     * by the same portion (data length)
461     */
462     - dst_addr += sg_dma_len(sg);
463     }
464     }
465    
466     - if (!xfer->cyclic)
467     + if (!xfer->cyclic) {
468     + src_addr += sg_dma_len(sg);
469     + dst_addr += sg_dma_len(sg);
470     sg = sg_next(sg);
471     + }
472     }
473    
474     return vchan_tx_prep(&chan->vc, &desc->vd, xfer->flags);
475     diff --git a/drivers/dma/fsldma.h b/drivers/dma/fsldma.h
476     index 56f18ae992332..308bed0a560ac 100644
477     --- a/drivers/dma/fsldma.h
478     +++ b/drivers/dma/fsldma.h
479     @@ -205,10 +205,10 @@ struct fsldma_chan {
480     #else
481     static u64 fsl_ioread64(const u64 __iomem *addr)
482     {
483     - u32 fsl_addr = lower_32_bits(addr);
484     - u64 fsl_addr_hi = (u64)in_le32((u32 *)(fsl_addr + 1)) << 32;
485     + u32 val_lo = in_le32((u32 __iomem *)addr);
486     + u32 val_hi = in_le32((u32 __iomem *)addr + 1);
487    
488     - return fsl_addr_hi | in_le32((u32 *)fsl_addr);
489     + return ((u64)val_hi << 32) + val_lo;
490     }
491    
492     static void fsl_iowrite64(u64 val, u64 __iomem *addr)
493     @@ -219,10 +219,10 @@ static void fsl_iowrite64(u64 val, u64 __iomem *addr)
494    
495     static u64 fsl_ioread64be(const u64 __iomem *addr)
496     {
497     - u32 fsl_addr = lower_32_bits(addr);
498     - u64 fsl_addr_hi = (u64)in_be32((u32 *)fsl_addr) << 32;
499     + u32 val_hi = in_be32((u32 __iomem *)addr);
500     + u32 val_lo = in_be32((u32 __iomem *)addr + 1);
501    
502     - return fsl_addr_hi | in_be32((u32 *)(fsl_addr + 1));
503     + return ((u64)val_hi << 32) + val_lo;
504     }
505    
506     static void fsl_iowrite64be(u64 val, u64 __iomem *addr)
507     diff --git a/drivers/dma/of-dma.c b/drivers/dma/of-dma.c
508     index c2d779daa4b51..4bbf4172b9bf9 100644
509     --- a/drivers/dma/of-dma.c
510     +++ b/drivers/dma/of-dma.c
511     @@ -69,12 +69,12 @@ static struct dma_chan *of_dma_router_xlate(struct of_phandle_args *dma_spec,
512     return NULL;
513    
514     chan = ofdma_target->of_dma_xlate(&dma_spec_target, ofdma_target);
515     - if (chan) {
516     - chan->router = ofdma->dma_router;
517     - chan->route_data = route_data;
518     - } else {
519     + if (IS_ERR_OR_NULL(chan)) {
520     ofdma->dma_router->route_free(ofdma->dma_router->dev,
521     route_data);
522     + } else {
523     + chan->router = ofdma->dma_router;
524     + chan->route_data = route_data;
525     }
526    
527     /*
528     diff --git a/drivers/dma/pl330.c b/drivers/dma/pl330.c
529     index 6cce9ef61b294..cd81d10974a29 100644
530     --- a/drivers/dma/pl330.c
531     +++ b/drivers/dma/pl330.c
532     @@ -2788,6 +2788,7 @@ pl330_prep_dma_memcpy(struct dma_chan *chan, dma_addr_t dst,
533     while (burst != (1 << desc->rqcfg.brst_size))
534     desc->rqcfg.brst_size++;
535    
536     + desc->rqcfg.brst_len = get_burst_len(desc, len);
537     /*
538     * If burst size is smaller than bus width then make sure we only
539     * transfer one at a time to avoid a burst stradling an MFIFO entry.
540     @@ -2795,7 +2796,6 @@ pl330_prep_dma_memcpy(struct dma_chan *chan, dma_addr_t dst,
541     if (desc->rqcfg.brst_size * 8 < pl330->pcfg.data_bus_width)
542     desc->rqcfg.brst_len = 1;
543    
544     - desc->rqcfg.brst_len = get_burst_len(desc, len);
545     desc->bytes_requested = len;
546    
547     desc->txd.flags = flags;
548     diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
549     index 247f53d41993d..60e50181f6d39 100644
550     --- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
551     +++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
552     @@ -2043,12 +2043,18 @@ static int amdgpu_dm_mode_config_init(struct amdgpu_device *adev)
553     &dm_atomic_state_funcs);
554    
555     r = amdgpu_display_modeset_create_props(adev);
556     - if (r)
557     + if (r) {
558     + dc_release_state(state->context);
559     + kfree(state);
560     return r;
561     + }
562    
563     r = amdgpu_dm_audio_init(adev);
564     - if (r)
565     + if (r) {
566     + dc_release_state(state->context);
567     + kfree(state);
568     return r;
569     + }
570    
571     return 0;
572     }
573     @@ -2064,6 +2070,8 @@ static void amdgpu_dm_update_backlight_caps(struct amdgpu_display_manager *dm)
574     #if defined(CONFIG_ACPI)
575     struct amdgpu_dm_backlight_caps caps;
576    
577     + memset(&caps, 0, sizeof(caps));
578     +
579     if (dm->backlight_caps.caps_valid)
580     return;
581    
582     diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_mst_types.c b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_mst_types.c
583     index 28a6c7b2ef4bb..2f858507ca702 100644
584     --- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_mst_types.c
585     +++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_mst_types.c
586     @@ -101,7 +101,7 @@ static ssize_t dm_dp_aux_transfer(struct drm_dp_aux *aux,
587     result = dc_link_aux_transfer_raw(TO_DM_AUX(aux)->ddc_service, &payload,
588     &operation_result);
589    
590     - if (payload.write)
591     + if (payload.write && result >= 0)
592     result = msg->size;
593    
594     if (result < 0)
595     diff --git a/drivers/gpu/drm/amd/display/dc/dcn10/dcn10_resource.c b/drivers/gpu/drm/amd/display/dc/dcn10/dcn10_resource.c
596     index 1599bb9711111..e860ae05feda1 100644
597     --- a/drivers/gpu/drm/amd/display/dc/dcn10/dcn10_resource.c
598     +++ b/drivers/gpu/drm/amd/display/dc/dcn10/dcn10_resource.c
599     @@ -1151,6 +1151,7 @@ static enum dc_status dcn10_validate_global(struct dc *dc, struct dc_state *cont
600     bool video_large = false;
601     bool desktop_large = false;
602     bool dcc_disabled = false;
603     + bool mpo_enabled = false;
604    
605     for (i = 0; i < context->stream_count; i++) {
606     if (context->stream_status[i].plane_count == 0)
607     @@ -1159,6 +1160,9 @@ static enum dc_status dcn10_validate_global(struct dc *dc, struct dc_state *cont
608     if (context->stream_status[i].plane_count > 2)
609     return DC_FAIL_UNSUPPORTED_1;
610    
611     + if (context->stream_status[i].plane_count > 1)
612     + mpo_enabled = true;
613     +
614     for (j = 0; j < context->stream_status[i].plane_count; j++) {
615     struct dc_plane_state *plane =
616     context->stream_status[i].plane_states[j];
617     @@ -1182,6 +1186,10 @@ static enum dc_status dcn10_validate_global(struct dc *dc, struct dc_state *cont
618     }
619     }
620    
621     + /* Disable MPO in multi-display configurations. */
622     + if (context->stream_count > 1 && mpo_enabled)
623     + return DC_FAIL_UNSUPPORTED_1;
624     +
625     /*
626     * Workaround: On DCN10 there is UMC issue that causes underflow when
627     * playing 4k video on 4k desktop with video downscaled and single channel
628     diff --git a/drivers/gpu/drm/amd/powerplay/hwmgr/vega10_thermal.c b/drivers/gpu/drm/amd/powerplay/hwmgr/vega10_thermal.c
629     index 36a17caa3761d..e8d01abf27fa8 100644
630     --- a/drivers/gpu/drm/amd/powerplay/hwmgr/vega10_thermal.c
631     +++ b/drivers/gpu/drm/amd/powerplay/hwmgr/vega10_thermal.c
632     @@ -375,8 +375,18 @@ static int vega10_thermal_set_temperature_range(struct pp_hwmgr *hwmgr,
633     /* compare them in unit celsius degree */
634     if (low < range->min / PP_TEMPERATURE_UNITS_PER_CENTIGRADES)
635     low = range->min / PP_TEMPERATURE_UNITS_PER_CENTIGRADES;
636     - if (high > tdp_table->usSoftwareShutdownTemp)
637     - high = tdp_table->usSoftwareShutdownTemp;
638     +
639     + /*
640     + * As a common sense, usSoftwareShutdownTemp should be bigger
641     + * than ThotspotLimit. For any invalid usSoftwareShutdownTemp,
642     + * we will just use the max possible setting VEGA10_THERMAL_MAXIMUM_ALERT_TEMP
643     + * to avoid false alarms.
644     + */
645     + if ((tdp_table->usSoftwareShutdownTemp >
646     + range->hotspot_crit_max / PP_TEMPERATURE_UNITS_PER_CENTIGRADES)) {
647     + if (high > tdp_table->usSoftwareShutdownTemp)
648     + high = tdp_table->usSoftwareShutdownTemp;
649     + }
650    
651     if (low > high)
652     return -EINVAL;
653     diff --git a/drivers/gpu/drm/msm/adreno/a6xx_gmu.c b/drivers/gpu/drm/msm/adreno/a6xx_gmu.c
654     index 9ea748667fab0..40431a09dc97c 100644
655     --- a/drivers/gpu/drm/msm/adreno/a6xx_gmu.c
656     +++ b/drivers/gpu/drm/msm/adreno/a6xx_gmu.c
657     @@ -199,12 +199,22 @@ static int a6xx_gmu_start(struct a6xx_gmu *gmu)
658     {
659     int ret;
660     u32 val;
661     + u32 mask, reset_val;
662     +
663     + val = gmu_read(gmu, REG_A6XX_GMU_CM3_DTCM_START + 0xff8);
664     + if (val <= 0x20010004) {
665     + mask = 0xffffffff;
666     + reset_val = 0xbabeface;
667     + } else {
668     + mask = 0x1ff;
669     + reset_val = 0x100;
670     + }
671    
672     gmu_write(gmu, REG_A6XX_GMU_CM3_SYSRESET, 1);
673     gmu_write(gmu, REG_A6XX_GMU_CM3_SYSRESET, 0);
674    
675     ret = gmu_poll_timeout(gmu, REG_A6XX_GMU_CM3_FW_INIT_RESULT, val,
676     - val == 0xbabeface, 100, 10000);
677     + (val & mask) == reset_val, 100, 10000);
678    
679     if (ret)
680     DRM_DEV_ERROR(gmu->dev, "GMU firmware initialization timed out\n");
681     diff --git a/drivers/gpu/drm/msm/disp/dpu1/dpu_plane.c b/drivers/gpu/drm/msm/disp/dpu1/dpu_plane.c
682     index 58d5acbcfc5c2..b984bafd27e25 100644
683     --- a/drivers/gpu/drm/msm/disp/dpu1/dpu_plane.c
684     +++ b/drivers/gpu/drm/msm/disp/dpu1/dpu_plane.c
685     @@ -853,9 +853,9 @@ static int dpu_plane_atomic_check(struct drm_plane *plane,
686     crtc_state = drm_atomic_get_new_crtc_state(state->state,
687     state->crtc);
688    
689     - min_scale = FRAC_16_16(1, pdpu->pipe_sblk->maxdwnscale);
690     + min_scale = FRAC_16_16(1, pdpu->pipe_sblk->maxupscale);
691     ret = drm_atomic_helper_check_plane_state(state, crtc_state, min_scale,
692     - pdpu->pipe_sblk->maxupscale << 16,
693     + pdpu->pipe_sblk->maxdwnscale << 16,
694     true, true);
695     if (ret) {
696     DPU_ERROR_PLANE(pdpu, "Check plane state failed (%d)\n", ret);
697     diff --git a/drivers/gpu/drm/msm/msm_atomic.c b/drivers/gpu/drm/msm/msm_atomic.c
698     index 5ccfad794c6a5..561bfa48841c3 100644
699     --- a/drivers/gpu/drm/msm/msm_atomic.c
700     +++ b/drivers/gpu/drm/msm/msm_atomic.c
701     @@ -27,6 +27,34 @@ int msm_atomic_prepare_fb(struct drm_plane *plane,
702     return msm_framebuffer_prepare(new_state->fb, kms->aspace);
703     }
704    
705     +/*
706     + * Helpers to control vblanks while we flush.. basically just to ensure
707     + * that vblank accounting is switched on, so we get valid seqn/timestamp
708     + * on pageflip events (if requested)
709     + */
710     +
711     +static void vblank_get(struct msm_kms *kms, unsigned crtc_mask)
712     +{
713     + struct drm_crtc *crtc;
714     +
715     + for_each_crtc_mask(kms->dev, crtc, crtc_mask) {
716     + if (!crtc->state->active)
717     + continue;
718     + drm_crtc_vblank_get(crtc);
719     + }
720     +}
721     +
722     +static void vblank_put(struct msm_kms *kms, unsigned crtc_mask)
723     +{
724     + struct drm_crtc *crtc;
725     +
726     + for_each_crtc_mask(kms->dev, crtc, crtc_mask) {
727     + if (!crtc->state->active)
728     + continue;
729     + drm_crtc_vblank_put(crtc);
730     + }
731     +}
732     +
733     static void msm_atomic_async_commit(struct msm_kms *kms, int crtc_idx)
734     {
735     unsigned crtc_mask = BIT(crtc_idx);
736     @@ -44,6 +72,8 @@ static void msm_atomic_async_commit(struct msm_kms *kms, int crtc_idx)
737    
738     kms->funcs->enable_commit(kms);
739    
740     + vblank_get(kms, crtc_mask);
741     +
742     /*
743     * Flush hardware updates:
744     */
745     @@ -58,6 +88,8 @@ static void msm_atomic_async_commit(struct msm_kms *kms, int crtc_idx)
746     kms->funcs->wait_flush(kms, crtc_mask);
747     trace_msm_atomic_wait_flush_finish(crtc_mask);
748    
749     + vblank_put(kms, crtc_mask);
750     +
751     mutex_lock(&kms->commit_lock);
752     kms->funcs->complete_commit(kms, crtc_mask);
753     mutex_unlock(&kms->commit_lock);
754     @@ -221,6 +253,8 @@ void msm_atomic_commit_tail(struct drm_atomic_state *state)
755     */
756     kms->pending_crtc_mask &= ~crtc_mask;
757    
758     + vblank_get(kms, crtc_mask);
759     +
760     /*
761     * Flush hardware updates:
762     */
763     @@ -235,6 +269,8 @@ void msm_atomic_commit_tail(struct drm_atomic_state *state)
764     kms->funcs->wait_flush(kms, crtc_mask);
765     trace_msm_atomic_wait_flush_finish(crtc_mask);
766    
767     + vblank_put(kms, crtc_mask);
768     +
769     mutex_lock(&kms->commit_lock);
770     kms->funcs->complete_commit(kms, crtc_mask);
771     mutex_unlock(&kms->commit_lock);
772     diff --git a/drivers/gpu/drm/msm/msm_drv.c b/drivers/gpu/drm/msm/msm_drv.c
773     index b73fbb65e14b2..4558d66761b3c 100644
774     --- a/drivers/gpu/drm/msm/msm_drv.c
775     +++ b/drivers/gpu/drm/msm/msm_drv.c
776     @@ -1321,6 +1321,13 @@ static int msm_pdev_remove(struct platform_device *pdev)
777     return 0;
778     }
779    
780     +static void msm_pdev_shutdown(struct platform_device *pdev)
781     +{
782     + struct drm_device *drm = platform_get_drvdata(pdev);
783     +
784     + drm_atomic_helper_shutdown(drm);
785     +}
786     +
787     static const struct of_device_id dt_match[] = {
788     { .compatible = "qcom,mdp4", .data = (void *)KMS_MDP4 },
789     { .compatible = "qcom,mdss", .data = (void *)KMS_MDP5 },
790     @@ -1332,6 +1339,7 @@ MODULE_DEVICE_TABLE(of, dt_match);
791     static struct platform_driver msm_platform_driver = {
792     .probe = msm_pdev_probe,
793     .remove = msm_pdev_remove,
794     + .shutdown = msm_pdev_shutdown,
795     .driver = {
796     .name = "msm",
797     .of_match_table = dt_match,
798     diff --git a/drivers/gpu/drm/omapdrm/omap_crtc.c b/drivers/gpu/drm/omapdrm/omap_crtc.c
799     index 3c5ddbf30e974..f5e18802e7bc6 100644
800     --- a/drivers/gpu/drm/omapdrm/omap_crtc.c
801     +++ b/drivers/gpu/drm/omapdrm/omap_crtc.c
802     @@ -451,11 +451,12 @@ static void omap_crtc_atomic_enable(struct drm_crtc *crtc,
803     if (omap_state->manually_updated)
804     return;
805    
806     - spin_lock_irq(&crtc->dev->event_lock);
807     drm_crtc_vblank_on(crtc);
808     +
809     ret = drm_crtc_vblank_get(crtc);
810     WARN_ON(ret != 0);
811    
812     + spin_lock_irq(&crtc->dev->event_lock);
813     omap_crtc_arm_event(crtc);
814     spin_unlock_irq(&crtc->dev->event_lock);
815     }
816     diff --git a/drivers/hid/hid-ids.h b/drivers/hid/hid-ids.h
817     index 09df5ecc2c79b..fbc93d8dda5ed 100644
818     --- a/drivers/hid/hid-ids.h
819     +++ b/drivers/hid/hid-ids.h
820     @@ -730,6 +730,9 @@
821     #define USB_DEVICE_ID_LENOVO_X1_TAB 0x60a3
822     #define USB_DEVICE_ID_LENOVO_X1_TAB3 0x60b5
823     #define USB_DEVICE_ID_LENOVO_PIXART_USB_MOUSE_608D 0x608d
824     +#define USB_DEVICE_ID_LENOVO_PIXART_USB_MOUSE_6019 0x6019
825     +#define USB_DEVICE_ID_LENOVO_PIXART_USB_MOUSE_602E 0x602e
826     +#define USB_DEVICE_ID_LENOVO_PIXART_USB_MOUSE_6093 0x6093
827    
828     #define USB_VENDOR_ID_LG 0x1fd2
829     #define USB_DEVICE_ID_LG_MULTITOUCH 0x0064
830     diff --git a/drivers/hid/hid-quirks.c b/drivers/hid/hid-quirks.c
831     index b3dd60897ffda..8a739ec50cc00 100644
832     --- a/drivers/hid/hid-quirks.c
833     +++ b/drivers/hid/hid-quirks.c
834     @@ -105,6 +105,9 @@ static const struct hid_device_id hid_quirks[] = {
835     { HID_USB_DEVICE(USB_VENDOR_ID_KYE, USB_DEVICE_ID_KYE_EASYPEN_M406XE), HID_QUIRK_MULTI_INPUT },
836     { HID_USB_DEVICE(USB_VENDOR_ID_KYE, USB_DEVICE_ID_PIXART_USB_OPTICAL_MOUSE_ID2), HID_QUIRK_ALWAYS_POLL },
837     { HID_USB_DEVICE(USB_VENDOR_ID_LENOVO, USB_DEVICE_ID_LENOVO_PIXART_USB_MOUSE_608D), HID_QUIRK_ALWAYS_POLL },
838     + { HID_USB_DEVICE(USB_VENDOR_ID_LENOVO, USB_DEVICE_ID_LENOVO_PIXART_USB_MOUSE_6019), HID_QUIRK_ALWAYS_POLL },
839     + { HID_USB_DEVICE(USB_VENDOR_ID_LENOVO, USB_DEVICE_ID_LENOVO_PIXART_USB_MOUSE_602E), HID_QUIRK_ALWAYS_POLL },
840     + { HID_USB_DEVICE(USB_VENDOR_ID_LENOVO, USB_DEVICE_ID_LENOVO_PIXART_USB_MOUSE_6093), HID_QUIRK_ALWAYS_POLL },
841     { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_C007), HID_QUIRK_ALWAYS_POLL },
842     { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_C077), HID_QUIRK_ALWAYS_POLL },
843     { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_KEYBOARD_G710_PLUS), HID_QUIRK_NOGET },
844     diff --git a/drivers/hwmon/applesmc.c b/drivers/hwmon/applesmc.c
845     index 183ff3d251299..006bc07bcd301 100644
846     --- a/drivers/hwmon/applesmc.c
847     +++ b/drivers/hwmon/applesmc.c
848     @@ -748,15 +748,18 @@ static ssize_t applesmc_light_show(struct device *dev,
849     }
850    
851     ret = applesmc_read_key(LIGHT_SENSOR_LEFT_KEY, buffer, data_length);
852     + if (ret)
853     + goto out;
854     /* newer macbooks report a single 10-bit bigendian value */
855     if (data_length == 10) {
856     left = be16_to_cpu(*(__be16 *)(buffer + 6)) >> 2;
857     goto out;
858     }
859     left = buffer[2];
860     +
861     + ret = applesmc_read_key(LIGHT_SENSOR_RIGHT_KEY, buffer, data_length);
862     if (ret)
863     goto out;
864     - ret = applesmc_read_key(LIGHT_SENSOR_RIGHT_KEY, buffer, data_length);
865     right = buffer[2];
866    
867     out:
868     @@ -805,12 +808,11 @@ static ssize_t applesmc_show_fan_speed(struct device *dev,
869     to_index(attr));
870    
871     ret = applesmc_read_key(newkey, buffer, 2);
872     - speed = ((buffer[0] << 8 | buffer[1]) >> 2);
873     -
874     if (ret)
875     return ret;
876     - else
877     - return snprintf(sysfsbuf, PAGE_SIZE, "%u\n", speed);
878     +
879     + speed = ((buffer[0] << 8 | buffer[1]) >> 2);
880     + return snprintf(sysfsbuf, PAGE_SIZE, "%u\n", speed);
881     }
882    
883     static ssize_t applesmc_store_fan_speed(struct device *dev,
884     @@ -846,12 +848,11 @@ static ssize_t applesmc_show_fan_manual(struct device *dev,
885     u8 buffer[2];
886    
887     ret = applesmc_read_key(FANS_MANUAL, buffer, 2);
888     - manual = ((buffer[0] << 8 | buffer[1]) >> to_index(attr)) & 0x01;
889     -
890     if (ret)
891     return ret;
892     - else
893     - return snprintf(sysfsbuf, PAGE_SIZE, "%d\n", manual);
894     +
895     + manual = ((buffer[0] << 8 | buffer[1]) >> to_index(attr)) & 0x01;
896     + return snprintf(sysfsbuf, PAGE_SIZE, "%d\n", manual);
897     }
898    
899     static ssize_t applesmc_store_fan_manual(struct device *dev,
900     @@ -867,10 +868,11 @@ static ssize_t applesmc_store_fan_manual(struct device *dev,
901     return -EINVAL;
902    
903     ret = applesmc_read_key(FANS_MANUAL, buffer, 2);
904     - val = (buffer[0] << 8 | buffer[1]);
905     if (ret)
906     goto out;
907    
908     + val = (buffer[0] << 8 | buffer[1]);
909     +
910     if (input)
911     val = val | (0x01 << to_index(attr));
912     else
913     @@ -946,13 +948,12 @@ static ssize_t applesmc_key_count_show(struct device *dev,
914     u32 count;
915    
916     ret = applesmc_read_key(KEY_COUNT_KEY, buffer, 4);
917     - count = ((u32)buffer[0]<<24) + ((u32)buffer[1]<<16) +
918     - ((u32)buffer[2]<<8) + buffer[3];
919     -
920     if (ret)
921     return ret;
922     - else
923     - return snprintf(sysfsbuf, PAGE_SIZE, "%d\n", count);
924     +
925     + count = ((u32)buffer[0]<<24) + ((u32)buffer[1]<<16) +
926     + ((u32)buffer[2]<<8) + buffer[3];
927     + return snprintf(sysfsbuf, PAGE_SIZE, "%d\n", count);
928     }
929    
930     static ssize_t applesmc_key_at_index_read_show(struct device *dev,
931     diff --git a/drivers/iommu/amd_iommu.c b/drivers/iommu/amd_iommu.c
932     index 3a7094f4813f2..cdafc652d9d1a 100644
933     --- a/drivers/iommu/amd_iommu.c
934     +++ b/drivers/iommu/amd_iommu.c
935     @@ -4431,6 +4431,7 @@ int amd_iommu_deactivate_guest_mode(void *data)
936     struct amd_ir_data *ir_data = (struct amd_ir_data *)data;
937     struct irte_ga *entry = (struct irte_ga *) ir_data->entry;
938     struct irq_cfg *cfg = ir_data->cfg;
939     + u64 valid = entry->lo.fields_remap.valid;
940    
941     if (!AMD_IOMMU_GUEST_IR_VAPIC(amd_iommu_guest_ir) ||
942     !entry || !entry->lo.fields_vapic.guest_mode)
943     @@ -4439,6 +4440,7 @@ int amd_iommu_deactivate_guest_mode(void *data)
944     entry->lo.val = 0;
945     entry->hi.val = 0;
946    
947     + entry->lo.fields_remap.valid = valid;
948     entry->lo.fields_remap.dm = apic->irq_dest_mode;
949     entry->lo.fields_remap.int_type = apic->irq_delivery_mode;
950     entry->hi.fields.vector = cfg->vector;
951     diff --git a/drivers/iommu/intel-iommu.c b/drivers/iommu/intel-iommu.c
952     index cdc1f4736a116..2ffec65df3889 100644
953     --- a/drivers/iommu/intel-iommu.c
954     +++ b/drivers/iommu/intel-iommu.c
955     @@ -123,29 +123,29 @@ static inline unsigned int level_to_offset_bits(int level)
956     return (level - 1) * LEVEL_STRIDE;
957     }
958    
959     -static inline int pfn_level_offset(unsigned long pfn, int level)
960     +static inline int pfn_level_offset(u64 pfn, int level)
961     {
962     return (pfn >> level_to_offset_bits(level)) & LEVEL_MASK;
963     }
964    
965     -static inline unsigned long level_mask(int level)
966     +static inline u64 level_mask(int level)
967     {
968     - return -1UL << level_to_offset_bits(level);
969     + return -1ULL << level_to_offset_bits(level);
970     }
971    
972     -static inline unsigned long level_size(int level)
973     +static inline u64 level_size(int level)
974     {
975     - return 1UL << level_to_offset_bits(level);
976     + return 1ULL << level_to_offset_bits(level);
977     }
978    
979     -static inline unsigned long align_to_level(unsigned long pfn, int level)
980     +static inline u64 align_to_level(u64 pfn, int level)
981     {
982     return (pfn + level_size(level) - 1) & level_mask(level);
983     }
984    
985     static inline unsigned long lvl_to_nr_pages(unsigned int lvl)
986     {
987     - return 1 << min_t(int, (lvl - 1) * LEVEL_STRIDE, MAX_AGAW_PFN_WIDTH);
988     + return 1UL << min_t(int, (lvl - 1) * LEVEL_STRIDE, MAX_AGAW_PFN_WIDTH);
989     }
990    
991     /* VT-d pages must always be _smaller_ than MM pages. Otherwise things
992     diff --git a/drivers/iommu/intel_irq_remapping.c b/drivers/iommu/intel_irq_remapping.c
993     index 6bfb283e6f287..f697f3a1d46bc 100644
994     --- a/drivers/iommu/intel_irq_remapping.c
995     +++ b/drivers/iommu/intel_irq_remapping.c
996     @@ -507,12 +507,18 @@ static void iommu_enable_irq_remapping(struct intel_iommu *iommu)
997    
998     /* Enable interrupt-remapping */
999     iommu->gcmd |= DMA_GCMD_IRE;
1000     - iommu->gcmd &= ~DMA_GCMD_CFI; /* Block compatibility-format MSIs */
1001     writel(iommu->gcmd, iommu->reg + DMAR_GCMD_REG);
1002     -
1003     IOMMU_WAIT_OP(iommu, DMAR_GSTS_REG,
1004     readl, (sts & DMA_GSTS_IRES), sts);
1005    
1006     + /* Block compatibility-format MSIs */
1007     + if (sts & DMA_GSTS_CFIS) {
1008     + iommu->gcmd &= ~DMA_GCMD_CFI;
1009     + writel(iommu->gcmd, iommu->reg + DMAR_GCMD_REG);
1010     + IOMMU_WAIT_OP(iommu, DMAR_GSTS_REG,
1011     + readl, !(sts & DMA_GSTS_CFIS), sts);
1012     + }
1013     +
1014     /*
1015     * With CFI clear in the Global Command register, we should be
1016     * protected from dangerous (i.e. compatibility) interrupts
1017     diff --git a/drivers/md/dm-cache-metadata.c b/drivers/md/dm-cache-metadata.c
1018     index 151aa95775be2..af6d4f898e4c1 100644
1019     --- a/drivers/md/dm-cache-metadata.c
1020     +++ b/drivers/md/dm-cache-metadata.c
1021     @@ -537,12 +537,16 @@ static int __create_persistent_data_objects(struct dm_cache_metadata *cmd,
1022     CACHE_MAX_CONCURRENT_LOCKS);
1023     if (IS_ERR(cmd->bm)) {
1024     DMERR("could not create block manager");
1025     - return PTR_ERR(cmd->bm);
1026     + r = PTR_ERR(cmd->bm);
1027     + cmd->bm = NULL;
1028     + return r;
1029     }
1030    
1031     r = __open_or_format_metadata(cmd, may_format_device);
1032     - if (r)
1033     + if (r) {
1034     dm_block_manager_destroy(cmd->bm);
1035     + cmd->bm = NULL;
1036     + }
1037    
1038     return r;
1039     }
1040     diff --git a/drivers/md/dm-crypt.c b/drivers/md/dm-crypt.c
1041     index ffbda729e26e9..1af82fbbac0c4 100644
1042     --- a/drivers/md/dm-crypt.c
1043     +++ b/drivers/md/dm-crypt.c
1044     @@ -720,7 +720,7 @@ static int crypt_iv_eboiv_gen(struct crypt_config *cc, u8 *iv,
1045     u8 buf[MAX_CIPHER_BLOCKSIZE] __aligned(__alignof__(__le64));
1046     struct skcipher_request *req;
1047     struct scatterlist src, dst;
1048     - struct crypto_wait wait;
1049     + DECLARE_CRYPTO_WAIT(wait);
1050     int err;
1051    
1052     req = skcipher_request_alloc(any_tfm(cc), GFP_NOIO);
1053     diff --git a/drivers/md/dm-integrity.c b/drivers/md/dm-integrity.c
1054     index 1f63084ef3291..d6edfe84e7490 100644
1055     --- a/drivers/md/dm-integrity.c
1056     +++ b/drivers/md/dm-integrity.c
1057     @@ -2365,6 +2365,7 @@ next_chunk:
1058     range.logical_sector = le64_to_cpu(ic->sb->recalc_sector);
1059     if (unlikely(range.logical_sector >= ic->provided_data_sectors)) {
1060     if (ic->mode == 'B') {
1061     + block_bitmap_op(ic, ic->recalc_bitmap, 0, ic->provided_data_sectors, BITMAP_OP_CLEAR);
1062     DEBUG_print("queue_delayed_work: bitmap_flush_work\n");
1063     queue_delayed_work(ic->commit_wq, &ic->bitmap_flush_work, 0);
1064     }
1065     @@ -2442,6 +2443,17 @@ next_chunk:
1066     goto err;
1067     }
1068    
1069     + if (ic->mode == 'B') {
1070     + sector_t start, end;
1071     + start = (range.logical_sector >>
1072     + (ic->sb->log2_sectors_per_block + ic->log2_blocks_per_bitmap_bit)) <<
1073     + (ic->sb->log2_sectors_per_block + ic->log2_blocks_per_bitmap_bit);
1074     + end = ((range.logical_sector + range.n_sectors) >>
1075     + (ic->sb->log2_sectors_per_block + ic->log2_blocks_per_bitmap_bit)) <<
1076     + (ic->sb->log2_sectors_per_block + ic->log2_blocks_per_bitmap_bit);
1077     + block_bitmap_op(ic, ic->recalc_bitmap, start, end - start, BITMAP_OP_CLEAR);
1078     + }
1079     +
1080     advance_and_next:
1081     cond_resched();
1082    
1083     diff --git a/drivers/md/dm-mpath.c b/drivers/md/dm-mpath.c
1084     index f2de4c73cc8fa..54ecfea2cf47b 100644
1085     --- a/drivers/md/dm-mpath.c
1086     +++ b/drivers/md/dm-mpath.c
1087     @@ -1190,17 +1190,25 @@ static void multipath_wait_for_pg_init_completion(struct multipath *m)
1088     static void flush_multipath_work(struct multipath *m)
1089     {
1090     if (m->hw_handler_name) {
1091     - set_bit(MPATHF_PG_INIT_DISABLED, &m->flags);
1092     - smp_mb__after_atomic();
1093     + unsigned long flags;
1094     +
1095     + if (!atomic_read(&m->pg_init_in_progress))
1096     + goto skip;
1097     +
1098     + spin_lock_irqsave(&m->lock, flags);
1099     + if (atomic_read(&m->pg_init_in_progress) &&
1100     + !test_and_set_bit(MPATHF_PG_INIT_DISABLED, &m->flags)) {
1101     + spin_unlock_irqrestore(&m->lock, flags);
1102    
1103     - if (atomic_read(&m->pg_init_in_progress))
1104     flush_workqueue(kmpath_handlerd);
1105     - multipath_wait_for_pg_init_completion(m);
1106     + multipath_wait_for_pg_init_completion(m);
1107    
1108     - clear_bit(MPATHF_PG_INIT_DISABLED, &m->flags);
1109     - smp_mb__after_atomic();
1110     + spin_lock_irqsave(&m->lock, flags);
1111     + clear_bit(MPATHF_PG_INIT_DISABLED, &m->flags);
1112     + }
1113     + spin_unlock_irqrestore(&m->lock, flags);
1114     }
1115     -
1116     +skip:
1117     if (m->queue_mode == DM_TYPE_BIO_BASED)
1118     flush_work(&m->process_queued_bios);
1119     flush_work(&m->trigger_event);
1120     diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
1121     index 4cd8868f80040..a5ed59eafdc51 100644
1122     --- a/drivers/md/dm-thin-metadata.c
1123     +++ b/drivers/md/dm-thin-metadata.c
1124     @@ -739,12 +739,16 @@ static int __create_persistent_data_objects(struct dm_pool_metadata *pmd, bool f
1125     THIN_MAX_CONCURRENT_LOCKS);
1126     if (IS_ERR(pmd->bm)) {
1127     DMERR("could not create block manager");
1128     - return PTR_ERR(pmd->bm);
1129     + r = PTR_ERR(pmd->bm);
1130     + pmd->bm = NULL;
1131     + return r;
1132     }
1133    
1134     r = __open_or_format_metadata(pmd, format_device);
1135     - if (r)
1136     + if (r) {
1137     dm_block_manager_destroy(pmd->bm);
1138     + pmd->bm = NULL;
1139     + }
1140    
1141     return r;
1142     }
1143     @@ -954,7 +958,7 @@ int dm_pool_metadata_close(struct dm_pool_metadata *pmd)
1144     }
1145    
1146     pmd_write_lock_in_core(pmd);
1147     - if (!dm_bm_is_read_only(pmd->bm) && !pmd->fail_io) {
1148     + if (!pmd->fail_io && !dm_bm_is_read_only(pmd->bm)) {
1149     r = __commit_transaction(pmd);
1150     if (r < 0)
1151     DMWARN("%s: __commit_transaction() failed, error = %d",
1152     diff --git a/drivers/md/dm-writecache.c b/drivers/md/dm-writecache.c
1153     index ed2f711c24c48..4e414b06192eb 100644
1154     --- a/drivers/md/dm-writecache.c
1155     +++ b/drivers/md/dm-writecache.c
1156     @@ -224,6 +224,7 @@ static int persistent_memory_claim(struct dm_writecache *wc)
1157     pfn_t pfn;
1158     int id;
1159     struct page **pages;
1160     + sector_t offset;
1161    
1162     wc->memory_vmapped = false;
1163    
1164     @@ -242,9 +243,16 @@ static int persistent_memory_claim(struct dm_writecache *wc)
1165     goto err1;
1166     }
1167    
1168     + offset = get_start_sect(wc->ssd_dev->bdev);
1169     + if (offset & (PAGE_SIZE / 512 - 1)) {
1170     + r = -EINVAL;
1171     + goto err1;
1172     + }
1173     + offset >>= PAGE_SHIFT - 9;
1174     +
1175     id = dax_read_lock();
1176    
1177     - da = dax_direct_access(wc->ssd_dev->dax_dev, 0, p, &wc->memory_map, &pfn);
1178     + da = dax_direct_access(wc->ssd_dev->dax_dev, offset, p, &wc->memory_map, &pfn);
1179     if (da < 0) {
1180     wc->memory_map = NULL;
1181     r = da;
1182     @@ -266,7 +274,7 @@ static int persistent_memory_claim(struct dm_writecache *wc)
1183     i = 0;
1184     do {
1185     long daa;
1186     - daa = dax_direct_access(wc->ssd_dev->dax_dev, i, p - i,
1187     + daa = dax_direct_access(wc->ssd_dev->dax_dev, offset + i, p - i,
1188     NULL, &pfn);
1189     if (daa <= 0) {
1190     r = daa ? daa : -EINVAL;
1191     diff --git a/drivers/md/persistent-data/dm-block-manager.c b/drivers/md/persistent-data/dm-block-manager.c
1192     index 749ec268d957d..54c089a50b152 100644
1193     --- a/drivers/md/persistent-data/dm-block-manager.c
1194     +++ b/drivers/md/persistent-data/dm-block-manager.c
1195     @@ -493,7 +493,7 @@ int dm_bm_write_lock(struct dm_block_manager *bm,
1196     void *p;
1197     int r;
1198    
1199     - if (bm->read_only)
1200     + if (dm_bm_is_read_only(bm))
1201     return -EPERM;
1202    
1203     p = dm_bufio_read(bm->bufio, b, (struct dm_buffer **) result);
1204     @@ -562,7 +562,7 @@ int dm_bm_write_lock_zero(struct dm_block_manager *bm,
1205     struct buffer_aux *aux;
1206     void *p;
1207    
1208     - if (bm->read_only)
1209     + if (dm_bm_is_read_only(bm))
1210     return -EPERM;
1211    
1212     p = dm_bufio_new(bm->bufio, b, (struct dm_buffer **) result);
1213     @@ -602,7 +602,7 @@ EXPORT_SYMBOL_GPL(dm_bm_unlock);
1214    
1215     int dm_bm_flush(struct dm_block_manager *bm)
1216     {
1217     - if (bm->read_only)
1218     + if (dm_bm_is_read_only(bm))
1219     return -EPERM;
1220    
1221     return dm_bufio_write_dirty_buffers(bm->bufio);
1222     @@ -616,19 +616,21 @@ void dm_bm_prefetch(struct dm_block_manager *bm, dm_block_t b)
1223    
1224     bool dm_bm_is_read_only(struct dm_block_manager *bm)
1225     {
1226     - return bm->read_only;
1227     + return (bm ? bm->read_only : true);
1228     }
1229     EXPORT_SYMBOL_GPL(dm_bm_is_read_only);
1230    
1231     void dm_bm_set_read_only(struct dm_block_manager *bm)
1232     {
1233     - bm->read_only = true;
1234     + if (bm)
1235     + bm->read_only = true;
1236     }
1237     EXPORT_SYMBOL_GPL(dm_bm_set_read_only);
1238    
1239     void dm_bm_set_read_write(struct dm_block_manager *bm)
1240     {
1241     - bm->read_only = false;
1242     + if (bm)
1243     + bm->read_only = false;
1244     }
1245     EXPORT_SYMBOL_GPL(dm_bm_set_read_write);
1246    
1247     diff --git a/drivers/media/platform/vicodec/vicodec-core.c b/drivers/media/platform/vicodec/vicodec-core.c
1248     index 84ec36156f73f..c77281d43f892 100644
1249     --- a/drivers/media/platform/vicodec/vicodec-core.c
1250     +++ b/drivers/media/platform/vicodec/vicodec-core.c
1251     @@ -2052,6 +2052,7 @@ static int vicodec_request_validate(struct media_request *req)
1252     }
1253     ctrl = v4l2_ctrl_request_hdl_ctrl_find(hdl,
1254     vicodec_ctrl_stateless_state.id);
1255     + v4l2_ctrl_request_hdl_put(hdl);
1256     if (!ctrl) {
1257     v4l2_info(&ctx->dev->v4l2_dev,
1258     "Missing required codec control\n");
1259     diff --git a/drivers/media/rc/rc-main.c b/drivers/media/rc/rc-main.c
1260     index 6f80c251f6413..e84f9dccf448a 100644
1261     --- a/drivers/media/rc/rc-main.c
1262     +++ b/drivers/media/rc/rc-main.c
1263     @@ -1256,6 +1256,10 @@ static ssize_t store_protocols(struct device *device,
1264     }
1265    
1266     mutex_lock(&dev->lock);
1267     + if (!dev->registered) {
1268     + mutex_unlock(&dev->lock);
1269     + return -ENODEV;
1270     + }
1271    
1272     old_protocols = *current_protocols;
1273     new_protocols = old_protocols;
1274     @@ -1394,6 +1398,10 @@ static ssize_t store_filter(struct device *device,
1275     return -EINVAL;
1276    
1277     mutex_lock(&dev->lock);
1278     + if (!dev->registered) {
1279     + mutex_unlock(&dev->lock);
1280     + return -ENODEV;
1281     + }
1282    
1283     new_filter = *filter;
1284     if (fattr->mask)
1285     @@ -1508,6 +1516,10 @@ static ssize_t store_wakeup_protocols(struct device *device,
1286     int i;
1287    
1288     mutex_lock(&dev->lock);
1289     + if (!dev->registered) {
1290     + mutex_unlock(&dev->lock);
1291     + return -ENODEV;
1292     + }
1293    
1294     allowed = dev->allowed_wakeup_protocols;
1295    
1296     @@ -1565,25 +1577,25 @@ static void rc_dev_release(struct device *device)
1297     kfree(dev);
1298     }
1299    
1300     -#define ADD_HOTPLUG_VAR(fmt, val...) \
1301     - do { \
1302     - int err = add_uevent_var(env, fmt, val); \
1303     - if (err) \
1304     - return err; \
1305     - } while (0)
1306     -
1307     static int rc_dev_uevent(struct device *device, struct kobj_uevent_env *env)
1308     {
1309     struct rc_dev *dev = to_rc_dev(device);
1310     + int ret = 0;
1311    
1312     - if (dev->rc_map.name)
1313     - ADD_HOTPLUG_VAR("NAME=%s", dev->rc_map.name);
1314     - if (dev->driver_name)
1315     - ADD_HOTPLUG_VAR("DRV_NAME=%s", dev->driver_name);
1316     - if (dev->device_name)
1317     - ADD_HOTPLUG_VAR("DEV_NAME=%s", dev->device_name);
1318     + mutex_lock(&dev->lock);
1319    
1320     - return 0;
1321     + if (!dev->registered)
1322     + ret = -ENODEV;
1323     + if (ret == 0 && dev->rc_map.name)
1324     + ret = add_uevent_var(env, "NAME=%s", dev->rc_map.name);
1325     + if (ret == 0 && dev->driver_name)
1326     + ret = add_uevent_var(env, "DRV_NAME=%s", dev->driver_name);
1327     + if (ret == 0 && dev->device_name)
1328     + ret = add_uevent_var(env, "DEV_NAME=%s", dev->device_name);
1329     +
1330     + mutex_unlock(&dev->lock);
1331     +
1332     + return ret;
1333     }
1334    
1335     /*
1336     @@ -1975,14 +1987,14 @@ void rc_unregister_device(struct rc_dev *dev)
1337     del_timer_sync(&dev->timer_keyup);
1338     del_timer_sync(&dev->timer_repeat);
1339    
1340     - rc_free_rx_device(dev);
1341     -
1342     mutex_lock(&dev->lock);
1343     if (dev->users && dev->close)
1344     dev->close(dev);
1345     dev->registered = false;
1346     mutex_unlock(&dev->lock);
1347    
1348     + rc_free_rx_device(dev);
1349     +
1350     /*
1351     * lirc device should be freed with dev->registered = false, so
1352     * that userspace polling will get notified.
1353     diff --git a/drivers/misc/habanalabs/firmware_if.c b/drivers/misc/habanalabs/firmware_if.c
1354     index ea2ca67fbfbfa..153858475abc1 100644
1355     --- a/drivers/misc/habanalabs/firmware_if.c
1356     +++ b/drivers/misc/habanalabs/firmware_if.c
1357     @@ -11,6 +11,7 @@
1358     #include <linux/genalloc.h>
1359     #include <linux/io-64-nonatomic-lo-hi.h>
1360    
1361     +#define FW_FILE_MAX_SIZE 0x1400000 /* maximum size of 20MB */
1362     /**
1363     * hl_fw_push_fw_to_device() - Push FW code to device.
1364     * @hdev: pointer to hl_device structure.
1365     @@ -43,6 +44,14 @@ int hl_fw_push_fw_to_device(struct hl_device *hdev, const char *fw_name,
1366    
1367     dev_dbg(hdev->dev, "%s firmware size == %zu\n", fw_name, fw_size);
1368    
1369     + if (fw_size > FW_FILE_MAX_SIZE) {
1370     + dev_err(hdev->dev,
1371     + "FW file size %zu exceeds maximum of %u bytes\n",
1372     + fw_size, FW_FILE_MAX_SIZE);
1373     + rc = -EINVAL;
1374     + goto out;
1375     + }
1376     +
1377     fw_data = (const u64 *) fw->data;
1378    
1379     memcpy_toio(dst, fw_data, fw_size);
1380     diff --git a/drivers/misc/habanalabs/memory.c b/drivers/misc/habanalabs/memory.c
1381     index 22566b75ca50c..acfccf32be6b9 100644
1382     --- a/drivers/misc/habanalabs/memory.c
1383     +++ b/drivers/misc/habanalabs/memory.c
1384     @@ -67,6 +67,11 @@ static int alloc_device_memory(struct hl_ctx *ctx, struct hl_mem_in *args,
1385     num_pgs = (args->alloc.mem_size + (page_size - 1)) >> page_shift;
1386     total_size = num_pgs << page_shift;
1387    
1388     + if (!total_size) {
1389     + dev_err(hdev->dev, "Cannot allocate 0 bytes\n");
1390     + return -EINVAL;
1391     + }
1392     +
1393     contiguous = args->flags & HL_MEM_CONTIGUOUS;
1394    
1395     if (contiguous) {
1396     @@ -94,7 +99,7 @@ static int alloc_device_memory(struct hl_ctx *ctx, struct hl_mem_in *args,
1397     phys_pg_pack->contiguous = contiguous;
1398    
1399     phys_pg_pack->pages = kvmalloc_array(num_pgs, sizeof(u64), GFP_KERNEL);
1400     - if (!phys_pg_pack->pages) {
1401     + if (ZERO_OR_NULL_PTR(phys_pg_pack->pages)) {
1402     rc = -ENOMEM;
1403     goto pages_arr_err;
1404     }
1405     @@ -689,7 +694,7 @@ static int init_phys_pg_pack_from_userptr(struct hl_ctx *ctx,
1406    
1407     phys_pg_pack->pages = kvmalloc_array(total_npages, sizeof(u64),
1408     GFP_KERNEL);
1409     - if (!phys_pg_pack->pages) {
1410     + if (ZERO_OR_NULL_PTR(phys_pg_pack->pages)) {
1411     rc = -ENOMEM;
1412     goto page_pack_arr_mem_err;
1413     }
1414     diff --git a/drivers/misc/habanalabs/mmu.c b/drivers/misc/habanalabs/mmu.c
1415     index 176c315836f12..d66e16de4cda3 100644
1416     --- a/drivers/misc/habanalabs/mmu.c
1417     +++ b/drivers/misc/habanalabs/mmu.c
1418     @@ -422,7 +422,7 @@ int hl_mmu_init(struct hl_device *hdev)
1419     hdev->mmu_shadow_hop0 = kvmalloc_array(prop->max_asid,
1420     prop->mmu_hop_table_size,
1421     GFP_KERNEL | __GFP_ZERO);
1422     - if (!hdev->mmu_shadow_hop0) {
1423     + if (ZERO_OR_NULL_PTR(hdev->mmu_shadow_hop0)) {
1424     rc = -ENOMEM;
1425     goto err_pool_add;
1426     }
1427     diff --git a/drivers/mmc/host/cqhci.c b/drivers/mmc/host/cqhci.c
1428     index c19f4c3f115a4..2d65b32d205a5 100644
1429     --- a/drivers/mmc/host/cqhci.c
1430     +++ b/drivers/mmc/host/cqhci.c
1431     @@ -299,16 +299,16 @@ static void __cqhci_disable(struct cqhci_host *cq_host)
1432     cq_host->activated = false;
1433     }
1434    
1435     -int cqhci_suspend(struct mmc_host *mmc)
1436     +int cqhci_deactivate(struct mmc_host *mmc)
1437     {
1438     struct cqhci_host *cq_host = mmc->cqe_private;
1439    
1440     - if (cq_host->enabled)
1441     + if (cq_host->enabled && cq_host->activated)
1442     __cqhci_disable(cq_host);
1443    
1444     return 0;
1445     }
1446     -EXPORT_SYMBOL(cqhci_suspend);
1447     +EXPORT_SYMBOL(cqhci_deactivate);
1448    
1449     int cqhci_resume(struct mmc_host *mmc)
1450     {
1451     diff --git a/drivers/mmc/host/cqhci.h b/drivers/mmc/host/cqhci.h
1452     index def76e9b5cacf..437700179de4d 100644
1453     --- a/drivers/mmc/host/cqhci.h
1454     +++ b/drivers/mmc/host/cqhci.h
1455     @@ -230,7 +230,11 @@ irqreturn_t cqhci_irq(struct mmc_host *mmc, u32 intmask, int cmd_error,
1456     int data_error);
1457     int cqhci_init(struct cqhci_host *cq_host, struct mmc_host *mmc, bool dma64);
1458     struct cqhci_host *cqhci_pltfm_init(struct platform_device *pdev);
1459     -int cqhci_suspend(struct mmc_host *mmc);
1460     +int cqhci_deactivate(struct mmc_host *mmc);
1461     +static inline int cqhci_suspend(struct mmc_host *mmc)
1462     +{
1463     + return cqhci_deactivate(mmc);
1464     +}
1465     int cqhci_resume(struct mmc_host *mmc);
1466    
1467     #endif
1468     diff --git a/drivers/mmc/host/mtk-sd.c b/drivers/mmc/host/mtk-sd.c
1469     index 010fe29a48883..9d47a2bd2546b 100644
1470     --- a/drivers/mmc/host/mtk-sd.c
1471     +++ b/drivers/mmc/host/mtk-sd.c
1472     @@ -22,6 +22,7 @@
1473     #include <linux/slab.h>
1474     #include <linux/spinlock.h>
1475     #include <linux/interrupt.h>
1476     +#include <linux/reset.h>
1477    
1478     #include <linux/mmc/card.h>
1479     #include <linux/mmc/core.h>
1480     @@ -412,6 +413,7 @@ struct msdc_host {
1481     struct pinctrl_state *pins_uhs;
1482     struct delayed_work req_timeout;
1483     int irq; /* host interrupt */
1484     + struct reset_control *reset;
1485    
1486     struct clk *src_clk; /* msdc source clock */
1487     struct clk *h_clk; /* msdc h_clk */
1488     @@ -1474,6 +1476,12 @@ static void msdc_init_hw(struct msdc_host *host)
1489     u32 val;
1490     u32 tune_reg = host->dev_comp->pad_tune_reg;
1491    
1492     + if (host->reset) {
1493     + reset_control_assert(host->reset);
1494     + usleep_range(10, 50);
1495     + reset_control_deassert(host->reset);
1496     + }
1497     +
1498     /* Configure to MMC/SD mode, clock free running */
1499     sdr_set_bits(host->base + MSDC_CFG, MSDC_CFG_MODE | MSDC_CFG_CKPDN);
1500    
1501     @@ -2232,6 +2240,11 @@ static int msdc_drv_probe(struct platform_device *pdev)
1502     if (IS_ERR(host->src_clk_cg))
1503     host->src_clk_cg = NULL;
1504    
1505     + host->reset = devm_reset_control_get_optional_exclusive(&pdev->dev,
1506     + "hrst");
1507     + if (IS_ERR(host->reset))
1508     + return PTR_ERR(host->reset);
1509     +
1510     host->irq = platform_get_irq(pdev, 0);
1511     if (host->irq < 0) {
1512     ret = -EINVAL;
1513     diff --git a/drivers/mmc/host/sdhci-acpi.c b/drivers/mmc/host/sdhci-acpi.c
1514     index 01fc437ed9659..5581a5c86fce3 100644
1515     --- a/drivers/mmc/host/sdhci-acpi.c
1516     +++ b/drivers/mmc/host/sdhci-acpi.c
1517     @@ -532,6 +532,11 @@ static const struct sdhci_acpi_slot sdhci_acpi_slot_qcom_sd = {
1518     .caps = MMC_CAP_NONREMOVABLE,
1519     };
1520    
1521     +struct amd_sdhci_host {
1522     + bool tuned_clock;
1523     + bool dll_enabled;
1524     +};
1525     +
1526     /* AMD sdhci reset dll register. */
1527     #define SDHCI_AMD_RESET_DLL_REGISTER 0x908
1528    
1529     @@ -551,26 +556,66 @@ static void sdhci_acpi_amd_hs400_dll(struct sdhci_host *host)
1530     }
1531    
1532     /*
1533     - * For AMD Platform it is required to disable the tuning
1534     - * bit first controller to bring to HS Mode from HS200
1535     - * mode, later enable to tune to HS400 mode.
1536     + * The initialization sequence for HS400 is:
1537     + * HS->HS200->Perform Tuning->HS->HS400
1538     + *
1539     + * The re-tuning sequence is:
1540     + * HS400->DDR52->HS->HS200->Perform Tuning->HS->HS400
1541     + *
1542     + * The AMD eMMC Controller can only use the tuned clock while in HS200 and HS400
1543     + * mode. If we switch to a different mode, we need to disable the tuned clock.
1544     + * If we have previously performed tuning and switch back to HS200 or
1545     + * HS400, we can re-enable the tuned clock.
1546     + *
1547     */
1548     static void amd_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
1549     {
1550     struct sdhci_host *host = mmc_priv(mmc);
1551     + struct sdhci_acpi_host *acpi_host = sdhci_priv(host);
1552     + struct amd_sdhci_host *amd_host = sdhci_acpi_priv(acpi_host);
1553     unsigned int old_timing = host->timing;
1554     + u16 val;
1555    
1556     sdhci_set_ios(mmc, ios);
1557     - if (old_timing == MMC_TIMING_MMC_HS200 &&
1558     - ios->timing == MMC_TIMING_MMC_HS)
1559     - sdhci_writew(host, 0x9, SDHCI_HOST_CONTROL2);
1560     - if (old_timing != MMC_TIMING_MMC_HS400 &&
1561     - ios->timing == MMC_TIMING_MMC_HS400) {
1562     - sdhci_writew(host, 0x80, SDHCI_HOST_CONTROL2);
1563     - sdhci_acpi_amd_hs400_dll(host);
1564     +
1565     + if (old_timing != host->timing && amd_host->tuned_clock) {
1566     + if (host->timing == MMC_TIMING_MMC_HS400 ||
1567     + host->timing == MMC_TIMING_MMC_HS200) {
1568     + val = sdhci_readw(host, SDHCI_HOST_CONTROL2);
1569     + val |= SDHCI_CTRL_TUNED_CLK;
1570     + sdhci_writew(host, val, SDHCI_HOST_CONTROL2);
1571     + } else {
1572     + val = sdhci_readw(host, SDHCI_HOST_CONTROL2);
1573     + val &= ~SDHCI_CTRL_TUNED_CLK;
1574     + sdhci_writew(host, val, SDHCI_HOST_CONTROL2);
1575     + }
1576     +
1577     + /* DLL is only required for HS400 */
1578     + if (host->timing == MMC_TIMING_MMC_HS400 &&
1579     + !amd_host->dll_enabled) {
1580     + sdhci_acpi_amd_hs400_dll(host);
1581     + amd_host->dll_enabled = true;
1582     + }
1583     }
1584     }
1585    
1586     +static int amd_sdhci_execute_tuning(struct mmc_host *mmc, u32 opcode)
1587     +{
1588     + int err;
1589     + struct sdhci_host *host = mmc_priv(mmc);
1590     + struct sdhci_acpi_host *acpi_host = sdhci_priv(host);
1591     + struct amd_sdhci_host *amd_host = sdhci_acpi_priv(acpi_host);
1592     +
1593     + amd_host->tuned_clock = false;
1594     +
1595     + err = sdhci_execute_tuning(mmc, opcode);
1596     +
1597     + if (!err && !host->tuning_err)
1598     + amd_host->tuned_clock = true;
1599     +
1600     + return err;
1601     +}
1602     +
1603     static const struct sdhci_ops sdhci_acpi_ops_amd = {
1604     .set_clock = sdhci_set_clock,
1605     .set_bus_width = sdhci_set_bus_width,
1606     @@ -598,6 +643,7 @@ static int sdhci_acpi_emmc_amd_probe_slot(struct platform_device *pdev,
1607    
1608     host->mmc_host_ops.select_drive_strength = amd_select_drive_strength;
1609     host->mmc_host_ops.set_ios = amd_set_ios;
1610     + host->mmc_host_ops.execute_tuning = amd_sdhci_execute_tuning;
1611     return 0;
1612     }
1613    
1614     @@ -609,6 +655,7 @@ static const struct sdhci_acpi_slot sdhci_acpi_slot_amd_emmc = {
1615     SDHCI_QUIRK_32BIT_ADMA_SIZE,
1616     .quirks2 = SDHCI_QUIRK2_BROKEN_64_BIT_DMA,
1617     .probe_slot = sdhci_acpi_emmc_amd_probe_slot,
1618     + .priv_size = sizeof(struct amd_sdhci_host),
1619     };
1620    
1621     struct sdhci_acpi_uid_slot {
1622     diff --git a/drivers/mmc/host/sdhci-pci-core.c b/drivers/mmc/host/sdhci-pci-core.c
1623     index 9b66e8b374ed7..425aa898e797a 100644
1624     --- a/drivers/mmc/host/sdhci-pci-core.c
1625     +++ b/drivers/mmc/host/sdhci-pci-core.c
1626     @@ -232,6 +232,14 @@ static void sdhci_pci_dumpregs(struct mmc_host *mmc)
1627     sdhci_dumpregs(mmc_priv(mmc));
1628     }
1629    
1630     +static void sdhci_cqhci_reset(struct sdhci_host *host, u8 mask)
1631     +{
1632     + if ((host->mmc->caps2 & MMC_CAP2_CQE) && (mask & SDHCI_RESET_ALL) &&
1633     + host->mmc->cqe_private)
1634     + cqhci_deactivate(host->mmc);
1635     + sdhci_reset(host, mask);
1636     +}
1637     +
1638     /*****************************************************************************\
1639     * *
1640     * Hardware specific quirk handling *
1641     @@ -722,7 +730,7 @@ static const struct sdhci_ops sdhci_intel_glk_ops = {
1642     .set_power = sdhci_intel_set_power,
1643     .enable_dma = sdhci_pci_enable_dma,
1644     .set_bus_width = sdhci_set_bus_width,
1645     - .reset = sdhci_reset,
1646     + .reset = sdhci_cqhci_reset,
1647     .set_uhs_signaling = sdhci_set_uhs_signaling,
1648     .hw_reset = sdhci_pci_hw_reset,
1649     .irq = sdhci_cqhci_irq,
1650     diff --git a/drivers/mmc/host/sdhci-tegra.c b/drivers/mmc/host/sdhci-tegra.c
1651     index e37d271ca9636..c105356ad4cb7 100644
1652     --- a/drivers/mmc/host/sdhci-tegra.c
1653     +++ b/drivers/mmc/host/sdhci-tegra.c
1654     @@ -100,6 +100,12 @@
1655     #define NVQUIRK_DIS_CARD_CLK_CONFIG_TAP BIT(8)
1656     #define NVQUIRK_CQHCI_DCMD_R1B_CMD_TIMING BIT(9)
1657    
1658     +/*
1659     + * NVQUIRK_HAS_TMCLK is for SoC's having separate timeout clock for Tegra
1660     + * SDMMC hardware data timeout.
1661     + */
1662     +#define NVQUIRK_HAS_TMCLK BIT(10)
1663     +
1664     /* SDMMC CQE Base Address for Tegra Host Ver 4.1 and Higher */
1665     #define SDHCI_TEGRA_CQE_BASE_ADDR 0xF000
1666    
1667     @@ -130,6 +136,7 @@ struct sdhci_tegra_autocal_offsets {
1668     struct sdhci_tegra {
1669     const struct sdhci_tegra_soc_data *soc_data;
1670     struct gpio_desc *power_gpio;
1671     + struct clk *tmclk;
1672     bool ddr_signaling;
1673     bool pad_calib_required;
1674     bool pad_control_available;
1675     @@ -1385,7 +1392,8 @@ static const struct sdhci_tegra_soc_data soc_data_tegra210 = {
1676     NVQUIRK_HAS_PADCALIB |
1677     NVQUIRK_DIS_CARD_CLK_CONFIG_TAP |
1678     NVQUIRK_ENABLE_SDR50 |
1679     - NVQUIRK_ENABLE_SDR104,
1680     + NVQUIRK_ENABLE_SDR104 |
1681     + NVQUIRK_HAS_TMCLK,
1682     .min_tap_delay = 106,
1683     .max_tap_delay = 185,
1684     };
1685     @@ -1422,6 +1430,7 @@ static const struct sdhci_tegra_soc_data soc_data_tegra186 = {
1686     NVQUIRK_DIS_CARD_CLK_CONFIG_TAP |
1687     NVQUIRK_ENABLE_SDR50 |
1688     NVQUIRK_ENABLE_SDR104 |
1689     + NVQUIRK_HAS_TMCLK |
1690     NVQUIRK_CQHCI_DCMD_R1B_CMD_TIMING,
1691     .min_tap_delay = 84,
1692     .max_tap_delay = 136,
1693     @@ -1434,7 +1443,8 @@ static const struct sdhci_tegra_soc_data soc_data_tegra194 = {
1694     NVQUIRK_HAS_PADCALIB |
1695     NVQUIRK_DIS_CARD_CLK_CONFIG_TAP |
1696     NVQUIRK_ENABLE_SDR50 |
1697     - NVQUIRK_ENABLE_SDR104,
1698     + NVQUIRK_ENABLE_SDR104 |
1699     + NVQUIRK_HAS_TMCLK,
1700     .min_tap_delay = 96,
1701     .max_tap_delay = 139,
1702     };
1703     @@ -1562,6 +1572,43 @@ static int sdhci_tegra_probe(struct platform_device *pdev)
1704     goto err_power_req;
1705     }
1706    
1707     + /*
1708     + * Tegra210 has a separate SDMMC_LEGACY_TM clock used for host
1709     + * timeout clock and SW can choose TMCLK or SDCLK for hardware
1710     + * data timeout through the bit USE_TMCLK_FOR_DATA_TIMEOUT of
1711     + * the register SDHCI_TEGRA_VENDOR_SYS_SW_CTRL.
1712     + *
1713     + * USE_TMCLK_FOR_DATA_TIMEOUT bit default is set to 1 and SDMMC uses
1714     + * 12Mhz TMCLK which is advertised in host capability register.
1715     + * With TMCLK of 12Mhz provides maximum data timeout period that can
1716     + * be achieved is 11s better than using SDCLK for data timeout.
1717     + *
1718     + * So, TMCLK is set to 12Mhz and kept enabled all the time on SoC's
1719     + * supporting separate TMCLK.
1720     + */
1721     +
1722     + if (soc_data->nvquirks & NVQUIRK_HAS_TMCLK) {
1723     + clk = devm_clk_get(&pdev->dev, "tmclk");
1724     + if (IS_ERR(clk)) {
1725     + rc = PTR_ERR(clk);
1726     + if (rc == -EPROBE_DEFER)
1727     + goto err_power_req;
1728     +
1729     + dev_warn(&pdev->dev, "failed to get tmclk: %d\n", rc);
1730     + clk = NULL;
1731     + }
1732     +
1733     + clk_set_rate(clk, 12000000);
1734     + rc = clk_prepare_enable(clk);
1735     + if (rc) {
1736     + dev_err(&pdev->dev,
1737     + "failed to enable tmclk: %d\n", rc);
1738     + goto err_power_req;
1739     + }
1740     +
1741     + tegra_host->tmclk = clk;
1742     + }
1743     +
1744     clk = devm_clk_get(mmc_dev(host->mmc), NULL);
1745     if (IS_ERR(clk)) {
1746     rc = PTR_ERR(clk);
1747     @@ -1605,6 +1652,7 @@ err_add_host:
1748     err_rst_get:
1749     clk_disable_unprepare(pltfm_host->clk);
1750     err_clk_get:
1751     + clk_disable_unprepare(tegra_host->tmclk);
1752     err_power_req:
1753     err_parse_dt:
1754     sdhci_pltfm_free(pdev);
1755     @@ -1622,6 +1670,7 @@ static int sdhci_tegra_remove(struct platform_device *pdev)
1756     reset_control_assert(tegra_host->rst);
1757     usleep_range(2000, 4000);
1758     clk_disable_unprepare(pltfm_host->clk);
1759     + clk_disable_unprepare(tegra_host->tmclk);
1760    
1761     sdhci_pltfm_free(pdev);
1762    
1763     diff --git a/drivers/net/dsa/microchip/ksz8795.c b/drivers/net/dsa/microchip/ksz8795.c
1764     index 8d50aacd19e51..84c4319e3b31f 100644
1765     --- a/drivers/net/dsa/microchip/ksz8795.c
1766     +++ b/drivers/net/dsa/microchip/ksz8795.c
1767     @@ -1270,9 +1270,6 @@ static int ksz8795_switch_init(struct ksz_device *dev)
1768     /* set the real number of ports */
1769     dev->ds->num_ports = dev->port_cnt;
1770    
1771     - /* set the real number of ports */
1772     - dev->ds->num_ports = dev->port_cnt;
1773     -
1774     return 0;
1775     }
1776    
1777     diff --git a/drivers/net/dsa/microchip/ksz9477.c b/drivers/net/dsa/microchip/ksz9477.c
1778     index b15da9a8e3bb9..49ab1346dc3f7 100644
1779     --- a/drivers/net/dsa/microchip/ksz9477.c
1780     +++ b/drivers/net/dsa/microchip/ksz9477.c
1781     @@ -515,9 +515,6 @@ static int ksz9477_port_vlan_filtering(struct dsa_switch *ds, int port,
1782     PORT_VLAN_LOOKUP_VID_0, false);
1783     }
1784    
1785     - /* set the real number of ports */
1786     - dev->ds->num_ports = dev->port_cnt;
1787     -
1788     return 0;
1789     }
1790    
1791     diff --git a/drivers/net/dsa/mt7530.c b/drivers/net/dsa/mt7530.c
1792     index dc9a3bb241149..00d680cb44418 100644
1793     --- a/drivers/net/dsa/mt7530.c
1794     +++ b/drivers/net/dsa/mt7530.c
1795     @@ -1456,7 +1456,7 @@ unsupported:
1796     phylink_set(mask, 100baseT_Full);
1797    
1798     if (state->interface != PHY_INTERFACE_MODE_MII) {
1799     - phylink_set(mask, 1000baseT_Half);
1800     + /* This switch only supports 1G full-duplex. */
1801     phylink_set(mask, 1000baseT_Full);
1802     if (port == 5)
1803     phylink_set(mask, 1000baseX_Full);
1804     diff --git a/drivers/net/ethernet/arc/emac_mdio.c b/drivers/net/ethernet/arc/emac_mdio.c
1805     index 0187dbf3b87df..54cdafdd067db 100644
1806     --- a/drivers/net/ethernet/arc/emac_mdio.c
1807     +++ b/drivers/net/ethernet/arc/emac_mdio.c
1808     @@ -153,6 +153,7 @@ int arc_mdio_probe(struct arc_emac_priv *priv)
1809     if (IS_ERR(data->reset_gpio)) {
1810     error = PTR_ERR(data->reset_gpio);
1811     dev_err(priv->dev, "Failed to request gpio: %d\n", error);
1812     + mdiobus_free(bus);
1813     return error;
1814     }
1815    
1816     diff --git a/drivers/net/ethernet/broadcom/bcmsysport.c b/drivers/net/ethernet/broadcom/bcmsysport.c
1817     index 4dfdb5a58025b..71eb8914e620b 100644
1818     --- a/drivers/net/ethernet/broadcom/bcmsysport.c
1819     +++ b/drivers/net/ethernet/broadcom/bcmsysport.c
1820     @@ -2453,8 +2453,10 @@ static int bcm_sysport_probe(struct platform_device *pdev)
1821     priv->tx_rings = devm_kcalloc(&pdev->dev, txq,
1822     sizeof(struct bcm_sysport_tx_ring),
1823     GFP_KERNEL);
1824     - if (!priv->tx_rings)
1825     - return -ENOMEM;
1826     + if (!priv->tx_rings) {
1827     + ret = -ENOMEM;
1828     + goto err_free_netdev;
1829     + }
1830    
1831     priv->is_lite = params->is_lite;
1832     priv->num_rx_desc_words = params->num_rx_desc_words;
1833     diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt.c b/drivers/net/ethernet/broadcom/bnxt/bnxt.c
1834     index 2cbfe0cd7eefa..4030020f92be5 100644
1835     --- a/drivers/net/ethernet/broadcom/bnxt/bnxt.c
1836     +++ b/drivers/net/ethernet/broadcom/bnxt/bnxt.c
1837     @@ -1143,6 +1143,9 @@ static int bnxt_discard_rx(struct bnxt *bp, struct bnxt_cp_ring_info *cpr,
1838    
1839     static void bnxt_queue_fw_reset_work(struct bnxt *bp, unsigned long delay)
1840     {
1841     + if (!(test_bit(BNXT_STATE_IN_FW_RESET, &bp->state)))
1842     + return;
1843     +
1844     if (BNXT_PF(bp))
1845     queue_delayed_work(bnxt_pf_wq, &bp->fw_reset_task, delay);
1846     else
1847     @@ -1159,10 +1162,12 @@ static void bnxt_queue_sp_work(struct bnxt *bp)
1848    
1849     static void bnxt_cancel_sp_work(struct bnxt *bp)
1850     {
1851     - if (BNXT_PF(bp))
1852     + if (BNXT_PF(bp)) {
1853     flush_workqueue(bnxt_pf_wq);
1854     - else
1855     + } else {
1856     cancel_work_sync(&bp->sp_task);
1857     + cancel_delayed_work_sync(&bp->fw_reset_task);
1858     + }
1859     }
1860    
1861     static void bnxt_sched_reset(struct bnxt *bp, struct bnxt_rx_ring_info *rxr)
1862     @@ -8933,16 +8938,19 @@ static ssize_t bnxt_show_temp(struct device *dev,
1863     struct hwrm_temp_monitor_query_input req = {0};
1864     struct hwrm_temp_monitor_query_output *resp;
1865     struct bnxt *bp = dev_get_drvdata(dev);
1866     - u32 temp = 0;
1867     + u32 len = 0;
1868    
1869     resp = bp->hwrm_cmd_resp_addr;
1870     bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_TEMP_MONITOR_QUERY, -1, -1);
1871     mutex_lock(&bp->hwrm_cmd_lock);
1872     - if (!_hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT))
1873     - temp = resp->temp * 1000; /* display millidegree */
1874     + if (!_hwrm_send_message_silent(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT))
1875     + len = sprintf(buf, "%u\n", resp->temp * 1000); /* display millidegree */
1876     mutex_unlock(&bp->hwrm_cmd_lock);
1877    
1878     - return sprintf(buf, "%u\n", temp);
1879     + if (len)
1880     + return len;
1881     +
1882     + return sprintf(buf, "unknown\n");
1883     }
1884     static SENSOR_DEVICE_ATTR(temp1_input, 0444, bnxt_show_temp, NULL, 0);
1885    
1886     @@ -9124,15 +9132,15 @@ static int __bnxt_open_nic(struct bnxt *bp, bool irq_re_init, bool link_re_init)
1887     }
1888     }
1889    
1890     - bnxt_enable_napi(bp);
1891     - bnxt_debug_dev_init(bp);
1892     -
1893     rc = bnxt_init_nic(bp, irq_re_init);
1894     if (rc) {
1895     netdev_err(bp->dev, "bnxt_init_nic err: %x\n", rc);
1896     - goto open_err;
1897     + goto open_err_irq;
1898     }
1899    
1900     + bnxt_enable_napi(bp);
1901     + bnxt_debug_dev_init(bp);
1902     +
1903     if (link_re_init) {
1904     mutex_lock(&bp->link_lock);
1905     rc = bnxt_update_phy_setting(bp);
1906     @@ -9163,10 +9171,6 @@ static int __bnxt_open_nic(struct bnxt *bp, bool irq_re_init, bool link_re_init)
1907     bnxt_vf_reps_open(bp);
1908     return 0;
1909    
1910     -open_err:
1911     - bnxt_debug_dev_exit(bp);
1912     - bnxt_disable_napi(bp);
1913     -
1914     open_err_irq:
1915     bnxt_del_napi(bp);
1916    
1917     @@ -11386,6 +11390,7 @@ static void bnxt_remove_one(struct pci_dev *pdev)
1918     unregister_netdev(dev);
1919     bnxt_dl_unregister(bp);
1920     bnxt_shutdown_tc(bp);
1921     + clear_bit(BNXT_STATE_IN_FW_RESET, &bp->state);
1922     bnxt_cancel_sp_work(bp);
1923     bp->sp_event = 0;
1924    
1925     @@ -11900,6 +11905,7 @@ static int bnxt_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
1926     (long)pci_resource_start(pdev, 0), dev->dev_addr);
1927     pcie_print_link_status(pdev);
1928    
1929     + pci_save_state(pdev);
1930     return 0;
1931    
1932     init_err_cleanup:
1933     @@ -12066,6 +12072,8 @@ static pci_ers_result_t bnxt_io_slot_reset(struct pci_dev *pdev)
1934     "Cannot re-enable PCI device after reset.\n");
1935     } else {
1936     pci_set_master(pdev);
1937     + pci_restore_state(pdev);
1938     + pci_save_state(pdev);
1939    
1940     err = bnxt_hwrm_func_reset(bp);
1941     if (!err && netif_running(netdev))
1942     diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt_ethtool.c b/drivers/net/ethernet/broadcom/bnxt/bnxt_ethtool.c
1943     index 1f512e7c3d434..fd01bcc8e28d4 100644
1944     --- a/drivers/net/ethernet/broadcom/bnxt/bnxt_ethtool.c
1945     +++ b/drivers/net/ethernet/broadcom/bnxt/bnxt_ethtool.c
1946     @@ -769,7 +769,7 @@ static void bnxt_get_channels(struct net_device *dev,
1947     int max_tx_sch_inputs;
1948    
1949     /* Get the most up-to-date max_tx_sch_inputs. */
1950     - if (BNXT_NEW_RM(bp))
1951     + if (netif_running(dev) && BNXT_NEW_RM(bp))
1952     bnxt_hwrm_func_resc_qcaps(bp, false);
1953     max_tx_sch_inputs = hw_resc->max_tx_sch_inputs;
1954    
1955     @@ -2161,6 +2161,9 @@ static int bnxt_get_nvram_directory(struct net_device *dev, u32 len, u8 *data)
1956     if (rc != 0)
1957     return rc;
1958    
1959     + if (!dir_entries || !entry_length)
1960     + return -EIO;
1961     +
1962     /* Insert 2 bytes of directory info (count and size of entries) */
1963     if (len < 2)
1964     return -EINVAL;
1965     diff --git a/drivers/net/ethernet/broadcom/tg3.c b/drivers/net/ethernet/broadcom/tg3.c
1966     index e12ba81288e64..70bd79dc43f2e 100644
1967     --- a/drivers/net/ethernet/broadcom/tg3.c
1968     +++ b/drivers/net/ethernet/broadcom/tg3.c
1969     @@ -7227,8 +7227,8 @@ static inline void tg3_reset_task_schedule(struct tg3 *tp)
1970    
1971     static inline void tg3_reset_task_cancel(struct tg3 *tp)
1972     {
1973     - cancel_work_sync(&tp->reset_task);
1974     - tg3_flag_clear(tp, RESET_TASK_PENDING);
1975     + if (test_and_clear_bit(TG3_FLAG_RESET_TASK_PENDING, tp->tg3_flags))
1976     + cancel_work_sync(&tp->reset_task);
1977     tg3_flag_clear(tp, TX_RECOVERY_PENDING);
1978     }
1979    
1980     @@ -11219,18 +11219,27 @@ static void tg3_reset_task(struct work_struct *work)
1981    
1982     tg3_halt(tp, RESET_KIND_SHUTDOWN, 0);
1983     err = tg3_init_hw(tp, true);
1984     - if (err)
1985     + if (err) {
1986     + tg3_full_unlock(tp);
1987     + tp->irq_sync = 0;
1988     + tg3_napi_enable(tp);
1989     + /* Clear this flag so that tg3_reset_task_cancel() will not
1990     + * call cancel_work_sync() and wait forever.
1991     + */
1992     + tg3_flag_clear(tp, RESET_TASK_PENDING);
1993     + dev_close(tp->dev);
1994     goto out;
1995     + }
1996    
1997     tg3_netif_start(tp);
1998    
1999     -out:
2000     tg3_full_unlock(tp);
2001    
2002     if (!err)
2003     tg3_phy_start(tp);
2004    
2005     tg3_flag_clear(tp, RESET_TASK_PENDING);
2006     +out:
2007     rtnl_unlock();
2008     }
2009    
2010     diff --git a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_thermal.c b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_thermal.c
2011     index 3de8a5e83b6c7..d7fefdbf3e575 100644
2012     --- a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_thermal.c
2013     +++ b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_thermal.c
2014     @@ -62,6 +62,7 @@ static struct thermal_zone_device_ops cxgb4_thermal_ops = {
2015     int cxgb4_thermal_init(struct adapter *adap)
2016     {
2017     struct ch_thermal *ch_thermal = &adap->ch_thermal;
2018     + char ch_tz_name[THERMAL_NAME_LENGTH];
2019     int num_trip = CXGB4_NUM_TRIPS;
2020     u32 param, val;
2021     int ret;
2022     @@ -82,7 +83,8 @@ int cxgb4_thermal_init(struct adapter *adap)
2023     ch_thermal->trip_type = THERMAL_TRIP_CRITICAL;
2024     }
2025    
2026     - ch_thermal->tzdev = thermal_zone_device_register("cxgb4", num_trip,
2027     + snprintf(ch_tz_name, sizeof(ch_tz_name), "cxgb4_%s", adap->name);
2028     + ch_thermal->tzdev = thermal_zone_device_register(ch_tz_name, num_trip,
2029     0, adap,
2030     &cxgb4_thermal_ops,
2031     NULL, 0, 0);
2032     @@ -97,7 +99,9 @@ int cxgb4_thermal_init(struct adapter *adap)
2033    
2034     int cxgb4_thermal_remove(struct adapter *adap)
2035     {
2036     - if (adap->ch_thermal.tzdev)
2037     + if (adap->ch_thermal.tzdev) {
2038     thermal_zone_device_unregister(adap->ch_thermal.tzdev);
2039     + adap->ch_thermal.tzdev = NULL;
2040     + }
2041     return 0;
2042     }
2043     diff --git a/drivers/net/ethernet/cortina/gemini.c b/drivers/net/ethernet/cortina/gemini.c
2044     index 28d4c54505f9a..c9fb1ec625d8b 100644
2045     --- a/drivers/net/ethernet/cortina/gemini.c
2046     +++ b/drivers/net/ethernet/cortina/gemini.c
2047     @@ -2445,8 +2445,8 @@ static int gemini_ethernet_port_probe(struct platform_device *pdev)
2048     port->reset = devm_reset_control_get_exclusive(dev, NULL);
2049     if (IS_ERR(port->reset)) {
2050     dev_err(dev, "no reset\n");
2051     - clk_disable_unprepare(port->pclk);
2052     - return PTR_ERR(port->reset);
2053     + ret = PTR_ERR(port->reset);
2054     + goto unprepare;
2055     }
2056     reset_control_reset(port->reset);
2057     usleep_range(100, 500);
2058     @@ -2501,25 +2501,25 @@ static int gemini_ethernet_port_probe(struct platform_device *pdev)
2059     IRQF_SHARED,
2060     port_names[port->id],
2061     port);
2062     - if (ret) {
2063     - clk_disable_unprepare(port->pclk);
2064     - return ret;
2065     - }
2066     + if (ret)
2067     + goto unprepare;
2068    
2069     ret = register_netdev(netdev);
2070     - if (!ret) {
2071     + if (ret)
2072     + goto unprepare;
2073     +
2074     + netdev_info(netdev,
2075     + "irq %d, DMA @ 0x%pap, GMAC @ 0x%pap\n",
2076     + port->irq, &dmares->start,
2077     + &gmacres->start);
2078     + ret = gmac_setup_phy(netdev);
2079     + if (ret)
2080     netdev_info(netdev,
2081     - "irq %d, DMA @ 0x%pap, GMAC @ 0x%pap\n",
2082     - port->irq, &dmares->start,
2083     - &gmacres->start);
2084     - ret = gmac_setup_phy(netdev);
2085     - if (ret)
2086     - netdev_info(netdev,
2087     - "PHY init failed, deferring to ifup time\n");
2088     - return 0;
2089     - }
2090     + "PHY init failed, deferring to ifup time\n");
2091     + return 0;
2092    
2093     - port->netdev = NULL;
2094     +unprepare:
2095     + clk_disable_unprepare(port->pclk);
2096     return ret;
2097     }
2098    
2099     diff --git a/drivers/net/ethernet/hisilicon/hns/hns_enet.c b/drivers/net/ethernet/hisilicon/hns/hns_enet.c
2100     index eb69e5c81a4d0..6d5d53cfc7ab4 100644
2101     --- a/drivers/net/ethernet/hisilicon/hns/hns_enet.c
2102     +++ b/drivers/net/ethernet/hisilicon/hns/hns_enet.c
2103     @@ -2296,8 +2296,10 @@ static int hns_nic_dev_probe(struct platform_device *pdev)
2104     priv->enet_ver = AE_VERSION_1;
2105     else if (acpi_dev_found(hns_enet_acpi_match[1].id))
2106     priv->enet_ver = AE_VERSION_2;
2107     - else
2108     - return -ENXIO;
2109     + else {
2110     + ret = -ENXIO;
2111     + goto out_read_prop_fail;
2112     + }
2113    
2114     /* try to find port-idx-in-ae first */
2115     ret = acpi_node_get_property_reference(dev->fwnode,
2116     @@ -2313,7 +2315,8 @@ static int hns_nic_dev_probe(struct platform_device *pdev)
2117     priv->fwnode = args.fwnode;
2118     } else {
2119     dev_err(dev, "cannot read cfg data from OF or acpi\n");
2120     - return -ENXIO;
2121     + ret = -ENXIO;
2122     + goto out_read_prop_fail;
2123     }
2124    
2125     ret = device_property_read_u32(dev, "port-idx-in-ae", &port_id);
2126     diff --git a/drivers/net/ethernet/mellanox/mlx4/mr.c b/drivers/net/ethernet/mellanox/mlx4/mr.c
2127     index 1a11bc0e16123..cfa0bba3940fb 100644
2128     --- a/drivers/net/ethernet/mellanox/mlx4/mr.c
2129     +++ b/drivers/net/ethernet/mellanox/mlx4/mr.c
2130     @@ -114,7 +114,7 @@ static int mlx4_buddy_init(struct mlx4_buddy *buddy, int max_order)
2131     goto err_out;
2132    
2133     for (i = 0; i <= buddy->max_order; ++i) {
2134     - s = BITS_TO_LONGS(1 << (buddy->max_order - i));
2135     + s = BITS_TO_LONGS(1UL << (buddy->max_order - i));
2136     buddy->bits[i] = kvmalloc_array(s, sizeof(long), GFP_KERNEL | __GFP_ZERO);
2137     if (!buddy->bits[i])
2138     goto err_out_free;
2139     diff --git a/drivers/net/ethernet/renesas/ravb_main.c b/drivers/net/ethernet/renesas/ravb_main.c
2140     index 30cdabf64ccc1..907ae1359a7c1 100644
2141     --- a/drivers/net/ethernet/renesas/ravb_main.c
2142     +++ b/drivers/net/ethernet/renesas/ravb_main.c
2143     @@ -1336,6 +1336,51 @@ static inline int ravb_hook_irq(unsigned int irq, irq_handler_t handler,
2144     return error;
2145     }
2146    
2147     +/* MDIO bus init function */
2148     +static int ravb_mdio_init(struct ravb_private *priv)
2149     +{
2150     + struct platform_device *pdev = priv->pdev;
2151     + struct device *dev = &pdev->dev;
2152     + int error;
2153     +
2154     + /* Bitbang init */
2155     + priv->mdiobb.ops = &bb_ops;
2156     +
2157     + /* MII controller setting */
2158     + priv->mii_bus = alloc_mdio_bitbang(&priv->mdiobb);
2159     + if (!priv->mii_bus)
2160     + return -ENOMEM;
2161     +
2162     + /* Hook up MII support for ethtool */
2163     + priv->mii_bus->name = "ravb_mii";
2164     + priv->mii_bus->parent = dev;
2165     + snprintf(priv->mii_bus->id, MII_BUS_ID_SIZE, "%s-%x",
2166     + pdev->name, pdev->id);
2167     +
2168     + /* Register MDIO bus */
2169     + error = of_mdiobus_register(priv->mii_bus, dev->of_node);
2170     + if (error)
2171     + goto out_free_bus;
2172     +
2173     + return 0;
2174     +
2175     +out_free_bus:
2176     + free_mdio_bitbang(priv->mii_bus);
2177     + return error;
2178     +}
2179     +
2180     +/* MDIO bus release function */
2181     +static int ravb_mdio_release(struct ravb_private *priv)
2182     +{
2183     + /* Unregister mdio bus */
2184     + mdiobus_unregister(priv->mii_bus);
2185     +
2186     + /* Free bitbang info */
2187     + free_mdio_bitbang(priv->mii_bus);
2188     +
2189     + return 0;
2190     +}
2191     +
2192     /* Network device open function for Ethernet AVB */
2193     static int ravb_open(struct net_device *ndev)
2194     {
2195     @@ -1344,6 +1389,13 @@ static int ravb_open(struct net_device *ndev)
2196     struct device *dev = &pdev->dev;
2197     int error;
2198    
2199     + /* MDIO bus init */
2200     + error = ravb_mdio_init(priv);
2201     + if (error) {
2202     + netdev_err(ndev, "failed to initialize MDIO\n");
2203     + return error;
2204     + }
2205     +
2206     napi_enable(&priv->napi[RAVB_BE]);
2207     napi_enable(&priv->napi[RAVB_NC]);
2208    
2209     @@ -1421,6 +1473,7 @@ out_free_irq:
2210     out_napi_off:
2211     napi_disable(&priv->napi[RAVB_NC]);
2212     napi_disable(&priv->napi[RAVB_BE]);
2213     + ravb_mdio_release(priv);
2214     return error;
2215     }
2216    
2217     @@ -1730,6 +1783,8 @@ static int ravb_close(struct net_device *ndev)
2218     ravb_ring_free(ndev, RAVB_BE);
2219     ravb_ring_free(ndev, RAVB_NC);
2220    
2221     + ravb_mdio_release(priv);
2222     +
2223     return 0;
2224     }
2225    
2226     @@ -1881,51 +1936,6 @@ static const struct net_device_ops ravb_netdev_ops = {
2227     .ndo_set_features = ravb_set_features,
2228     };
2229    
2230     -/* MDIO bus init function */
2231     -static int ravb_mdio_init(struct ravb_private *priv)
2232     -{
2233     - struct platform_device *pdev = priv->pdev;
2234     - struct device *dev = &pdev->dev;
2235     - int error;
2236     -
2237     - /* Bitbang init */
2238     - priv->mdiobb.ops = &bb_ops;
2239     -
2240     - /* MII controller setting */
2241     - priv->mii_bus = alloc_mdio_bitbang(&priv->mdiobb);
2242     - if (!priv->mii_bus)
2243     - return -ENOMEM;
2244     -
2245     - /* Hook up MII support for ethtool */
2246     - priv->mii_bus->name = "ravb_mii";
2247     - priv->mii_bus->parent = dev;
2248     - snprintf(priv->mii_bus->id, MII_BUS_ID_SIZE, "%s-%x",
2249     - pdev->name, pdev->id);
2250     -
2251     - /* Register MDIO bus */
2252     - error = of_mdiobus_register(priv->mii_bus, dev->of_node);
2253     - if (error)
2254     - goto out_free_bus;
2255     -
2256     - return 0;
2257     -
2258     -out_free_bus:
2259     - free_mdio_bitbang(priv->mii_bus);
2260     - return error;
2261     -}
2262     -
2263     -/* MDIO bus release function */
2264     -static int ravb_mdio_release(struct ravb_private *priv)
2265     -{
2266     - /* Unregister mdio bus */
2267     - mdiobus_unregister(priv->mii_bus);
2268     -
2269     - /* Free bitbang info */
2270     - free_mdio_bitbang(priv->mii_bus);
2271     -
2272     - return 0;
2273     -}
2274     -
2275     static const struct of_device_id ravb_match_table[] = {
2276     { .compatible = "renesas,etheravb-r8a7790", .data = (void *)RCAR_GEN2 },
2277     { .compatible = "renesas,etheravb-r8a7794", .data = (void *)RCAR_GEN2 },
2278     @@ -2166,13 +2176,6 @@ static int ravb_probe(struct platform_device *pdev)
2279     eth_hw_addr_random(ndev);
2280     }
2281    
2282     - /* MDIO bus init */
2283     - error = ravb_mdio_init(priv);
2284     - if (error) {
2285     - dev_err(&pdev->dev, "failed to initialize MDIO\n");
2286     - goto out_dma_free;
2287     - }
2288     -
2289     netif_napi_add(ndev, &priv->napi[RAVB_BE], ravb_poll, 64);
2290     netif_napi_add(ndev, &priv->napi[RAVB_NC], ravb_poll, 64);
2291    
2292     @@ -2194,8 +2197,6 @@ static int ravb_probe(struct platform_device *pdev)
2293     out_napi_del:
2294     netif_napi_del(&priv->napi[RAVB_NC]);
2295     netif_napi_del(&priv->napi[RAVB_BE]);
2296     - ravb_mdio_release(priv);
2297     -out_dma_free:
2298     dma_free_coherent(ndev->dev.parent, priv->desc_bat_size, priv->desc_bat,
2299     priv->desc_bat_dma);
2300    
2301     @@ -2227,7 +2228,6 @@ static int ravb_remove(struct platform_device *pdev)
2302     unregister_netdev(ndev);
2303     netif_napi_del(&priv->napi[RAVB_NC]);
2304     netif_napi_del(&priv->napi[RAVB_BE]);
2305     - ravb_mdio_release(priv);
2306     pm_runtime_disable(&pdev->dev);
2307     free_netdev(ndev);
2308     platform_set_drvdata(pdev, NULL);
2309     diff --git a/drivers/net/ethernet/ti/cpsw.c b/drivers/net/ethernet/ti/cpsw.c
2310     index 39df8c8feb6ce..e7b4d93e3f288 100644
2311     --- a/drivers/net/ethernet/ti/cpsw.c
2312     +++ b/drivers/net/ethernet/ti/cpsw.c
2313     @@ -2209,7 +2209,7 @@ static int cpsw_ndo_vlan_rx_kill_vid(struct net_device *ndev,
2314     HOST_PORT_NUM, ALE_VLAN, vid);
2315     ret |= cpsw_ale_del_mcast(cpsw->ale, priv->ndev->broadcast,
2316     0, ALE_VLAN, vid);
2317     - ret |= cpsw_ale_flush_multicast(cpsw->ale, 0, vid);
2318     + ret |= cpsw_ale_flush_multicast(cpsw->ale, ALE_PORT_HOST, vid);
2319     err:
2320     pm_runtime_put(cpsw->dev);
2321     return ret;
2322     diff --git a/drivers/net/gtp.c b/drivers/net/gtp.c
2323     index d89ec99abcd63..634bdea38ecb3 100644
2324     --- a/drivers/net/gtp.c
2325     +++ b/drivers/net/gtp.c
2326     @@ -1182,6 +1182,7 @@ static int gtp_genl_fill_info(struct sk_buff *skb, u32 snd_portid, u32 snd_seq,
2327     goto nlmsg_failure;
2328    
2329     if (nla_put_u32(skb, GTPA_VERSION, pctx->gtp_version) ||
2330     + nla_put_u32(skb, GTPA_LINK, pctx->dev->ifindex) ||
2331     nla_put_be32(skb, GTPA_PEER_ADDRESS, pctx->peer_addr_ip4.s_addr) ||
2332     nla_put_be32(skb, GTPA_MS_ADDRESS, pctx->ms_addr_ip4.s_addr))
2333     goto nla_put_failure;
2334     diff --git a/drivers/net/usb/asix_common.c b/drivers/net/usb/asix_common.c
2335     index e39f41efda3ec..7bc6e8f856fe0 100644
2336     --- a/drivers/net/usb/asix_common.c
2337     +++ b/drivers/net/usb/asix_common.c
2338     @@ -296,7 +296,7 @@ int asix_read_phy_addr(struct usbnet *dev, int internal)
2339    
2340     netdev_dbg(dev->net, "asix_get_phy_addr()\n");
2341    
2342     - if (ret < 0) {
2343     + if (ret < 2) {
2344     netdev_err(dev->net, "Error reading PHYID register: %02x\n", ret);
2345     goto out;
2346     }
2347     diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
2348     index ff5681da8780d..3cb017fa3a790 100644
2349     --- a/drivers/nvme/host/core.c
2350     +++ b/drivers/nvme/host/core.c
2351     @@ -4012,7 +4012,7 @@ static void nvme_free_ctrl(struct device *dev)
2352     container_of(dev, struct nvme_ctrl, ctrl_device);
2353     struct nvme_subsystem *subsys = ctrl->subsys;
2354    
2355     - if (subsys && ctrl->instance != subsys->instance)
2356     + if (!subsys || ctrl->instance != subsys->instance)
2357     ida_simple_remove(&nvme_instance_ida, ctrl->instance);
2358    
2359     kfree(ctrl->effects);
2360     diff --git a/drivers/nvme/target/core.c b/drivers/nvme/target/core.c
2361     index 57a4062cbb59e..7d7176369edf7 100644
2362     --- a/drivers/nvme/target/core.c
2363     +++ b/drivers/nvme/target/core.c
2364     @@ -369,6 +369,9 @@ static void nvmet_keep_alive_timer(struct work_struct *work)
2365    
2366     static void nvmet_start_keep_alive_timer(struct nvmet_ctrl *ctrl)
2367     {
2368     + if (unlikely(ctrl->kato == 0))
2369     + return;
2370     +
2371     pr_debug("ctrl %d start keep-alive timer for %d secs\n",
2372     ctrl->cntlid, ctrl->kato);
2373    
2374     @@ -378,6 +381,9 @@ static void nvmet_start_keep_alive_timer(struct nvmet_ctrl *ctrl)
2375    
2376     static void nvmet_stop_keep_alive_timer(struct nvmet_ctrl *ctrl)
2377     {
2378     + if (unlikely(ctrl->kato == 0))
2379     + return;
2380     +
2381     pr_debug("ctrl %d stop keep-alive\n", ctrl->cntlid);
2382    
2383     cancel_delayed_work_sync(&ctrl->ka_work);
2384     diff --git a/drivers/nvme/target/fc.c b/drivers/nvme/target/fc.c
2385     index ce8d819f86ccc..fc35f7ae67b0a 100644
2386     --- a/drivers/nvme/target/fc.c
2387     +++ b/drivers/nvme/target/fc.c
2388     @@ -1994,9 +1994,9 @@ nvmet_fc_fod_op_done(struct nvmet_fc_fcp_iod *fod)
2389     return;
2390     if (fcpreq->fcp_error ||
2391     fcpreq->transferred_length != fcpreq->transfer_length) {
2392     - spin_lock(&fod->flock);
2393     + spin_lock_irqsave(&fod->flock, flags);
2394     fod->abort = true;
2395     - spin_unlock(&fod->flock);
2396     + spin_unlock_irqrestore(&fod->flock, flags);
2397    
2398     nvmet_req_complete(&fod->req, NVME_SC_INTERNAL);
2399     return;
2400     diff --git a/drivers/staging/media/sunxi/cedrus/cedrus.c b/drivers/staging/media/sunxi/cedrus/cedrus.c
2401     index 3439f6ad63380..e80e82a276e93 100644
2402     --- a/drivers/staging/media/sunxi/cedrus/cedrus.c
2403     +++ b/drivers/staging/media/sunxi/cedrus/cedrus.c
2404     @@ -159,6 +159,7 @@ static int cedrus_request_validate(struct media_request *req)
2405     struct v4l2_ctrl *ctrl_test;
2406     unsigned int count;
2407     unsigned int i;
2408     + int ret = 0;
2409    
2410     list_for_each_entry(obj, &req->objects, list) {
2411     struct vb2_buffer *vb;
2412     @@ -203,12 +204,16 @@ static int cedrus_request_validate(struct media_request *req)
2413     if (!ctrl_test) {
2414     v4l2_info(&ctx->dev->v4l2_dev,
2415     "Missing required codec control\n");
2416     - return -ENOENT;
2417     + ret = -ENOENT;
2418     + break;
2419     }
2420     }
2421    
2422     v4l2_ctrl_request_hdl_put(hdl);
2423    
2424     + if (ret)
2425     + return ret;
2426     +
2427     return vb2_request_validate(req);
2428     }
2429    
2430     diff --git a/drivers/thermal/qcom/qcom-spmi-temp-alarm.c b/drivers/thermal/qcom/qcom-spmi-temp-alarm.c
2431     index bf7bae42c141c..6dc879fea9c8a 100644
2432     --- a/drivers/thermal/qcom/qcom-spmi-temp-alarm.c
2433     +++ b/drivers/thermal/qcom/qcom-spmi-temp-alarm.c
2434     @@ -1,6 +1,6 @@
2435     // SPDX-License-Identifier: GPL-2.0-only
2436     /*
2437     - * Copyright (c) 2011-2015, 2017, The Linux Foundation. All rights reserved.
2438     + * Copyright (c) 2011-2015, 2017, 2020, The Linux Foundation. All rights reserved.
2439     */
2440    
2441     #include <linux/bitops.h>
2442     @@ -191,7 +191,7 @@ static int qpnp_tm_get_temp(void *data, int *temp)
2443     chip->temp = mili_celsius;
2444     }
2445    
2446     - *temp = chip->temp < 0 ? 0 : chip->temp;
2447     + *temp = chip->temp;
2448    
2449     return 0;
2450     }
2451     diff --git a/drivers/thermal/ti-soc-thermal/omap4-thermal-data.c b/drivers/thermal/ti-soc-thermal/omap4-thermal-data.c
2452     index 63b02bfb2adf6..fdb8a495ab69a 100644
2453     --- a/drivers/thermal/ti-soc-thermal/omap4-thermal-data.c
2454     +++ b/drivers/thermal/ti-soc-thermal/omap4-thermal-data.c
2455     @@ -37,20 +37,21 @@ static struct temp_sensor_data omap4430_mpu_temp_sensor_data = {
2456    
2457     /*
2458     * Temperature values in milli degree celsius
2459     - * ADC code values from 530 to 923
2460     + * ADC code values from 13 to 107, see TRM
2461     + * "18.4.10.2.3 ADC Codes Versus Temperature".
2462     */
2463     static const int
2464     omap4430_adc_to_temp[OMAP4430_ADC_END_VALUE - OMAP4430_ADC_START_VALUE + 1] = {
2465     - -38000, -35000, -34000, -32000, -30000, -28000, -26000, -24000, -22000,
2466     - -20000, -18000, -17000, -15000, -13000, -12000, -10000, -8000, -6000,
2467     - -5000, -3000, -1000, 0, 2000, 3000, 5000, 6000, 8000, 10000, 12000,
2468     - 13000, 15000, 17000, 19000, 21000, 23000, 25000, 27000, 28000, 30000,
2469     - 32000, 33000, 35000, 37000, 38000, 40000, 42000, 43000, 45000, 47000,
2470     - 48000, 50000, 52000, 53000, 55000, 57000, 58000, 60000, 62000, 64000,
2471     - 66000, 68000, 70000, 71000, 73000, 75000, 77000, 78000, 80000, 82000,
2472     - 83000, 85000, 87000, 88000, 90000, 92000, 93000, 95000, 97000, 98000,
2473     - 100000, 102000, 103000, 105000, 107000, 109000, 111000, 113000, 115000,
2474     - 117000, 118000, 120000, 122000, 123000,
2475     + -40000, -38000, -35000, -34000, -32000, -30000, -28000, -26000, -24000,
2476     + -22000, -20000, -18500, -17000, -15000, -13500, -12000, -10000, -8000,
2477     + -6500, -5000, -3500, -1500, 0, 2000, 3500, 5000, 6500, 8500, 10000,
2478     + 12000, 13500, 15000, 17000, 19000, 21000, 23000, 25000, 27000, 28500,
2479     + 30000, 32000, 33500, 35000, 37000, 38500, 40000, 42000, 43500, 45000,
2480     + 47000, 48500, 50000, 52000, 53500, 55000, 57000, 58500, 60000, 62000,
2481     + 64000, 66000, 68000, 70000, 71500, 73500, 75000, 77000, 78500, 80000,
2482     + 82000, 83500, 85000, 87000, 88500, 90000, 92000, 93500, 95000, 97000,
2483     + 98500, 100000, 102000, 103500, 105000, 107000, 109000, 111000, 113000,
2484     + 115000, 117000, 118500, 120000, 122000, 123500, 125000,
2485     };
2486    
2487     /* OMAP4430 data */
2488     diff --git a/drivers/thermal/ti-soc-thermal/omap4xxx-bandgap.h b/drivers/thermal/ti-soc-thermal/omap4xxx-bandgap.h
2489     index a453ff8eb313e..9a3955c3853ba 100644
2490     --- a/drivers/thermal/ti-soc-thermal/omap4xxx-bandgap.h
2491     +++ b/drivers/thermal/ti-soc-thermal/omap4xxx-bandgap.h
2492     @@ -53,9 +53,13 @@
2493     * and thresholds for OMAP4430.
2494     */
2495    
2496     -/* ADC conversion table limits */
2497     -#define OMAP4430_ADC_START_VALUE 0
2498     -#define OMAP4430_ADC_END_VALUE 127
2499     +/*
2500     + * ADC conversion table limits. Ignore values outside the TRM listed
2501     + * range to avoid bogus thermal shutdowns. See omap4430 TRM chapter
2502     + * "18.4.10.2.3 ADC Codes Versus Temperature".
2503     + */
2504     +#define OMAP4430_ADC_START_VALUE 13
2505     +#define OMAP4430_ADC_END_VALUE 107
2506     /* bandgap clock limits (no control on 4430) */
2507     #define OMAP4430_MAX_FREQ 32768
2508     #define OMAP4430_MIN_FREQ 32768
2509     diff --git a/drivers/tty/serial/qcom_geni_serial.c b/drivers/tty/serial/qcom_geni_serial.c
2510     index f98a79172ad23..0b184256034fb 100644
2511     --- a/drivers/tty/serial/qcom_geni_serial.c
2512     +++ b/drivers/tty/serial/qcom_geni_serial.c
2513     @@ -1063,7 +1063,7 @@ static unsigned int qcom_geni_serial_tx_empty(struct uart_port *uport)
2514     }
2515    
2516     #ifdef CONFIG_SERIAL_QCOM_GENI_CONSOLE
2517     -static int __init qcom_geni_console_setup(struct console *co, char *options)
2518     +static int qcom_geni_console_setup(struct console *co, char *options)
2519     {
2520     struct uart_port *uport;
2521     struct qcom_geni_serial_port *port;
2522     diff --git a/drivers/vfio/pci/vfio_pci.c b/drivers/vfio/pci/vfio_pci.c
2523     index 02206162eaa9e..0d16f9806655f 100644
2524     --- a/drivers/vfio/pci/vfio_pci.c
2525     +++ b/drivers/vfio/pci/vfio_pci.c
2526     @@ -27,6 +27,7 @@
2527     #include <linux/vfio.h>
2528     #include <linux/vgaarb.h>
2529     #include <linux/nospec.h>
2530     +#include <linux/sched/mm.h>
2531    
2532     #include "vfio_pci_private.h"
2533    
2534     @@ -177,6 +178,7 @@ no_mmap:
2535    
2536     static void vfio_pci_try_bus_reset(struct vfio_pci_device *vdev);
2537     static void vfio_pci_disable(struct vfio_pci_device *vdev);
2538     +static int vfio_pci_try_zap_and_vma_lock_cb(struct pci_dev *pdev, void *data);
2539    
2540     /*
2541     * INTx masking requires the ability to disable INTx signaling via PCI_COMMAND
2542     @@ -688,6 +690,12 @@ int vfio_pci_register_dev_region(struct vfio_pci_device *vdev,
2543     return 0;
2544     }
2545    
2546     +struct vfio_devices {
2547     + struct vfio_device **devices;
2548     + int cur_index;
2549     + int max_index;
2550     +};
2551     +
2552     static long vfio_pci_ioctl(void *device_data,
2553     unsigned int cmd, unsigned long arg)
2554     {
2555     @@ -761,7 +769,7 @@ static long vfio_pci_ioctl(void *device_data,
2556     {
2557     void __iomem *io;
2558     size_t size;
2559     - u16 orig_cmd;
2560     + u16 cmd;
2561    
2562     info.offset = VFIO_PCI_INDEX_TO_OFFSET(info.index);
2563     info.flags = 0;
2564     @@ -781,10 +789,7 @@ static long vfio_pci_ioctl(void *device_data,
2565     * Is it really there? Enable memory decode for
2566     * implicit access in pci_map_rom().
2567     */
2568     - pci_read_config_word(pdev, PCI_COMMAND, &orig_cmd);
2569     - pci_write_config_word(pdev, PCI_COMMAND,
2570     - orig_cmd | PCI_COMMAND_MEMORY);
2571     -
2572     + cmd = vfio_pci_memory_lock_and_enable(vdev);
2573     io = pci_map_rom(pdev, &size);
2574     if (io) {
2575     info.flags = VFIO_REGION_INFO_FLAG_READ;
2576     @@ -792,8 +797,8 @@ static long vfio_pci_ioctl(void *device_data,
2577     } else {
2578     info.size = 0;
2579     }
2580     + vfio_pci_memory_unlock_and_restore(vdev, cmd);
2581    
2582     - pci_write_config_word(pdev, PCI_COMMAND, orig_cmd);
2583     break;
2584     }
2585     case VFIO_PCI_VGA_REGION_INDEX:
2586     @@ -936,8 +941,16 @@ static long vfio_pci_ioctl(void *device_data,
2587     return ret;
2588    
2589     } else if (cmd == VFIO_DEVICE_RESET) {
2590     - return vdev->reset_works ?
2591     - pci_try_reset_function(vdev->pdev) : -EINVAL;
2592     + int ret;
2593     +
2594     + if (!vdev->reset_works)
2595     + return -EINVAL;
2596     +
2597     + vfio_pci_zap_and_down_write_memory_lock(vdev);
2598     + ret = pci_try_reset_function(vdev->pdev);
2599     + up_write(&vdev->memory_lock);
2600     +
2601     + return ret;
2602    
2603     } else if (cmd == VFIO_DEVICE_GET_PCI_HOT_RESET_INFO) {
2604     struct vfio_pci_hot_reset_info hdr;
2605     @@ -1017,8 +1030,9 @@ reset_info_exit:
2606     int32_t *group_fds;
2607     struct vfio_pci_group_entry *groups;
2608     struct vfio_pci_group_info info;
2609     + struct vfio_devices devs = { .cur_index = 0 };
2610     bool slot = false;
2611     - int i, count = 0, ret = 0;
2612     + int i, group_idx, mem_idx = 0, count = 0, ret = 0;
2613    
2614     minsz = offsetofend(struct vfio_pci_hot_reset, count);
2615    
2616     @@ -1070,9 +1084,9 @@ reset_info_exit:
2617     * user interface and store the group and iommu ID. This
2618     * ensures the group is held across the reset.
2619     */
2620     - for (i = 0; i < hdr.count; i++) {
2621     + for (group_idx = 0; group_idx < hdr.count; group_idx++) {
2622     struct vfio_group *group;
2623     - struct fd f = fdget(group_fds[i]);
2624     + struct fd f = fdget(group_fds[group_idx]);
2625     if (!f.file) {
2626     ret = -EBADF;
2627     break;
2628     @@ -1085,8 +1099,9 @@ reset_info_exit:
2629     break;
2630     }
2631    
2632     - groups[i].group = group;
2633     - groups[i].id = vfio_external_user_iommu_id(group);
2634     + groups[group_idx].group = group;
2635     + groups[group_idx].id =
2636     + vfio_external_user_iommu_id(group);
2637     }
2638    
2639     kfree(group_fds);
2640     @@ -1105,13 +1120,63 @@ reset_info_exit:
2641     ret = vfio_pci_for_each_slot_or_bus(vdev->pdev,
2642     vfio_pci_validate_devs,
2643     &info, slot);
2644     - if (!ret)
2645     - /* User has access, do the reset */
2646     - ret = pci_reset_bus(vdev->pdev);
2647     + if (ret)
2648     + goto hot_reset_release;
2649     +
2650     + devs.max_index = count;
2651     + devs.devices = kcalloc(count, sizeof(struct vfio_device *),
2652     + GFP_KERNEL);
2653     + if (!devs.devices) {
2654     + ret = -ENOMEM;
2655     + goto hot_reset_release;
2656     + }
2657     +
2658     + /*
2659     + * We need to get memory_lock for each device, but devices
2660     + * can share mmap_sem, therefore we need to zap and hold
2661     + * the vma_lock for each device, and only then get each
2662     + * memory_lock.
2663     + */
2664     + ret = vfio_pci_for_each_slot_or_bus(vdev->pdev,
2665     + vfio_pci_try_zap_and_vma_lock_cb,
2666     + &devs, slot);
2667     + if (ret)
2668     + goto hot_reset_release;
2669     +
2670     + for (; mem_idx < devs.cur_index; mem_idx++) {
2671     + struct vfio_pci_device *tmp;
2672     +
2673     + tmp = vfio_device_data(devs.devices[mem_idx]);
2674     +
2675     + ret = down_write_trylock(&tmp->memory_lock);
2676     + if (!ret) {
2677     + ret = -EBUSY;
2678     + goto hot_reset_release;
2679     + }
2680     + mutex_unlock(&tmp->vma_lock);
2681     + }
2682     +
2683     + /* User has access, do the reset */
2684     + ret = pci_reset_bus(vdev->pdev);
2685    
2686     hot_reset_release:
2687     - for (i--; i >= 0; i--)
2688     - vfio_group_put_external_user(groups[i].group);
2689     + for (i = 0; i < devs.cur_index; i++) {
2690     + struct vfio_device *device;
2691     + struct vfio_pci_device *tmp;
2692     +
2693     + device = devs.devices[i];
2694     + tmp = vfio_device_data(device);
2695     +
2696     + if (i < mem_idx)
2697     + up_write(&tmp->memory_lock);
2698     + else
2699     + mutex_unlock(&tmp->vma_lock);
2700     + vfio_device_put(device);
2701     + }
2702     + kfree(devs.devices);
2703     +
2704     + for (group_idx--; group_idx >= 0; group_idx--)
2705     + vfio_group_put_external_user(groups[group_idx].group);
2706    
2707     kfree(groups);
2708     return ret;
2709     @@ -1192,6 +1257,202 @@ static ssize_t vfio_pci_write(void *device_data, const char __user *buf,
2710     return vfio_pci_rw(device_data, (char __user *)buf, count, ppos, true);
2711     }
2712    
2713     +/* Return 1 on zap and vma_lock acquired, 0 on contention (only with @try) */
2714     +static int vfio_pci_zap_and_vma_lock(struct vfio_pci_device *vdev, bool try)
2715     +{
2716     + struct vfio_pci_mmap_vma *mmap_vma, *tmp;
2717     +
2718     + /*
2719     + * Lock ordering:
2720     + * vma_lock is nested under mmap_sem for vm_ops callback paths.
2721     + * The memory_lock semaphore is used by both code paths calling
2722     + * into this function to zap vmas and the vm_ops.fault callback
2723     + * to protect the memory enable state of the device.
2724     + *
2725     + * When zapping vmas we need to maintain the mmap_sem => vma_lock
2726     + * ordering, which requires using vma_lock to walk vma_list to
2727     + * acquire an mm, then dropping vma_lock to get the mmap_sem and
2728     + * reacquiring vma_lock. This logic is derived from similar
2729     + * requirements in uverbs_user_mmap_disassociate().
2730     + *
2731     + * mmap_sem must always be the top-level lock when it is taken.
2732     + * Therefore we can only hold the memory_lock write lock when
2733     + * vma_list is empty, as we'd need to take mmap_sem to clear
2734     + * entries. vma_list can only be guaranteed empty when holding
2735     + * vma_lock, thus memory_lock is nested under vma_lock.
2736     + *
2737     + * This enables the vm_ops.fault callback to acquire vma_lock,
2738     + * followed by memory_lock read lock, while already holding
2739     + * mmap_sem without risk of deadlock.
2740     + */
2741     + while (1) {
2742     + struct mm_struct *mm = NULL;
2743     +
2744     + if (try) {
2745     + if (!mutex_trylock(&vdev->vma_lock))
2746     + return 0;
2747     + } else {
2748     + mutex_lock(&vdev->vma_lock);
2749     + }
2750     + while (!list_empty(&vdev->vma_list)) {
2751     + mmap_vma = list_first_entry(&vdev->vma_list,
2752     + struct vfio_pci_mmap_vma,
2753     + vma_next);
2754     + mm = mmap_vma->vma->vm_mm;
2755     + if (mmget_not_zero(mm))
2756     + break;
2757     +
2758     + list_del(&mmap_vma->vma_next);
2759     + kfree(mmap_vma);
2760     + mm = NULL;
2761     + }
2762     + if (!mm)
2763     + return 1;
2764     + mutex_unlock(&vdev->vma_lock);
2765     +
2766     + if (try) {
2767     + if (!down_read_trylock(&mm->mmap_sem)) {
2768     + mmput(mm);
2769     + return 0;
2770     + }
2771     + } else {
2772     + down_read(&mm->mmap_sem);
2773     + }
2774     + if (mmget_still_valid(mm)) {
2775     + if (try) {
2776     + if (!mutex_trylock(&vdev->vma_lock)) {
2777     + up_read(&mm->mmap_sem);
2778     + mmput(mm);
2779     + return 0;
2780     + }
2781     + } else {
2782     + mutex_lock(&vdev->vma_lock);
2783     + }
2784     + list_for_each_entry_safe(mmap_vma, tmp,
2785     + &vdev->vma_list, vma_next) {
2786     + struct vm_area_struct *vma = mmap_vma->vma;
2787     +
2788     + if (vma->vm_mm != mm)
2789     + continue;
2790     +
2791     + list_del(&mmap_vma->vma_next);
2792     + kfree(mmap_vma);
2793     +
2794     + zap_vma_ptes(vma, vma->vm_start,
2795     + vma->vm_end - vma->vm_start);
2796     + }
2797     + mutex_unlock(&vdev->vma_lock);
2798     + }
2799     + up_read(&mm->mmap_sem);
2800     + mmput(mm);
2801     + }
2802     +}
2803     +
2804     +void vfio_pci_zap_and_down_write_memory_lock(struct vfio_pci_device *vdev)
2805     +{
2806     + vfio_pci_zap_and_vma_lock(vdev, false);
2807     + down_write(&vdev->memory_lock);
2808     + mutex_unlock(&vdev->vma_lock);
2809     +}
2810     +
2811     +u16 vfio_pci_memory_lock_and_enable(struct vfio_pci_device *vdev)
2812     +{
2813     + u16 cmd;
2814     +
2815     + down_write(&vdev->memory_lock);
2816     + pci_read_config_word(vdev->pdev, PCI_COMMAND, &cmd);
2817     + if (!(cmd & PCI_COMMAND_MEMORY))
2818     + pci_write_config_word(vdev->pdev, PCI_COMMAND,
2819     + cmd | PCI_COMMAND_MEMORY);
2820     +
2821     + return cmd;
2822     +}
2823     +
2824     +void vfio_pci_memory_unlock_and_restore(struct vfio_pci_device *vdev, u16 cmd)
2825     +{
2826     + pci_write_config_word(vdev->pdev, PCI_COMMAND, cmd);
2827     + up_write(&vdev->memory_lock);
2828     +}
2829     +
2830     +/* Caller holds vma_lock */
2831     +static int __vfio_pci_add_vma(struct vfio_pci_device *vdev,
2832     + struct vm_area_struct *vma)
2833     +{
2834     + struct vfio_pci_mmap_vma *mmap_vma;
2835     +
2836     + mmap_vma = kmalloc(sizeof(*mmap_vma), GFP_KERNEL);
2837     + if (!mmap_vma)
2838     + return -ENOMEM;
2839     +
2840     + mmap_vma->vma = vma;
2841     + list_add(&mmap_vma->vma_next, &vdev->vma_list);
2842     +
2843     + return 0;
2844     +}
2845     +
2846     +/*
2847     + * Zap mmaps on open so that we can fault them in on access and therefore
2848     + * our vma_list only tracks mappings accessed since last zap.
2849     + */
2850     +static void vfio_pci_mmap_open(struct vm_area_struct *vma)
2851     +{
2852     + zap_vma_ptes(vma, vma->vm_start, vma->vm_end - vma->vm_start);
2853     +}
2854     +
2855     +static void vfio_pci_mmap_close(struct vm_area_struct *vma)
2856     +{
2857     + struct vfio_pci_device *vdev = vma->vm_private_data;
2858     + struct vfio_pci_mmap_vma *mmap_vma;
2859     +
2860     + mutex_lock(&vdev->vma_lock);
2861     + list_for_each_entry(mmap_vma, &vdev->vma_list, vma_next) {
2862     + if (mmap_vma->vma == vma) {
2863     + list_del(&mmap_vma->vma_next);
2864     + kfree(mmap_vma);
2865     + break;
2866     + }
2867     + }
2868     + mutex_unlock(&vdev->vma_lock);
2869     +}
2870     +
2871     +static vm_fault_t vfio_pci_mmap_fault(struct vm_fault *vmf)
2872     +{
2873     + struct vm_area_struct *vma = vmf->vma;
2874     + struct vfio_pci_device *vdev = vma->vm_private_data;
2875     + vm_fault_t ret = VM_FAULT_NOPAGE;
2876     +
2877     + mutex_lock(&vdev->vma_lock);
2878     + down_read(&vdev->memory_lock);
2879     +
2880     + if (!__vfio_pci_memory_enabled(vdev)) {
2881     + ret = VM_FAULT_SIGBUS;
2882     + mutex_unlock(&vdev->vma_lock);
2883     + goto up_out;
2884     + }
2885     +
2886     + if (__vfio_pci_add_vma(vdev, vma)) {
2887     + ret = VM_FAULT_OOM;
2888     + mutex_unlock(&vdev->vma_lock);
2889     + goto up_out;
2890     + }
2891     +
2892     + mutex_unlock(&vdev->vma_lock);
2893     +
2894     + if (remap_pfn_range(vma, vma->vm_start, vma->vm_pgoff,
2895     + vma->vm_end - vma->vm_start, vma->vm_page_prot))
2896     + ret = VM_FAULT_SIGBUS;
2897     +
2898     +up_out:
2899     + up_read(&vdev->memory_lock);
2900     + return ret;
2901     +}
2902     +
2903     +static const struct vm_operations_struct vfio_pci_mmap_ops = {
2904     + .open = vfio_pci_mmap_open,
2905     + .close = vfio_pci_mmap_close,
2906     + .fault = vfio_pci_mmap_fault,
2907     +};
2908     +
2909     static int vfio_pci_mmap(void *device_data, struct vm_area_struct *vma)
2910     {
2911     struct vfio_pci_device *vdev = device_data;
2912     @@ -1250,8 +1511,14 @@ static int vfio_pci_mmap(void *device_data, struct vm_area_struct *vma)
2913     vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
2914     vma->vm_pgoff = (pci_resource_start(pdev, index) >> PAGE_SHIFT) + pgoff;
2915    
2916     - return remap_pfn_range(vma, vma->vm_start, vma->vm_pgoff,
2917     - req_len, vma->vm_page_prot);
2918     + /*
2919     + * See remap_pfn_range(), called from vfio_pci_fault() but we can't
2920     + * change vm_flags within the fault handler. Set them now.
2921     + */
2922     + vma->vm_flags |= VM_IO | VM_PFNMAP | VM_DONTEXPAND | VM_DONTDUMP;
2923     + vma->vm_ops = &vfio_pci_mmap_ops;
2924     +
2925     + return 0;
2926     }
2927    
2928     static void vfio_pci_request(void *device_data, unsigned int count)
2929     @@ -1327,6 +1594,9 @@ static int vfio_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
2930     spin_lock_init(&vdev->irqlock);
2931     mutex_init(&vdev->ioeventfds_lock);
2932     INIT_LIST_HEAD(&vdev->ioeventfds_list);
2933     + mutex_init(&vdev->vma_lock);
2934     + INIT_LIST_HEAD(&vdev->vma_list);
2935     + init_rwsem(&vdev->memory_lock);
2936    
2937     ret = vfio_add_group_dev(&pdev->dev, &vfio_pci_ops, vdev);
2938     if (ret) {
2939     @@ -1516,12 +1786,6 @@ static void vfio_pci_reflck_put(struct vfio_pci_reflck *reflck)
2940     kref_put_mutex(&reflck->kref, vfio_pci_reflck_release, &reflck_lock);
2941     }
2942    
2943     -struct vfio_devices {
2944     - struct vfio_device **devices;
2945     - int cur_index;
2946     - int max_index;
2947     -};
2948     -
2949     static int vfio_pci_get_unused_devs(struct pci_dev *pdev, void *data)
2950     {
2951     struct vfio_devices *devs = data;
2952     @@ -1552,6 +1816,39 @@ static int vfio_pci_get_unused_devs(struct pci_dev *pdev, void *data)
2953     return 0;
2954     }
2955    
2956     +static int vfio_pci_try_zap_and_vma_lock_cb(struct pci_dev *pdev, void *data)
2957     +{
2958     + struct vfio_devices *devs = data;
2959     + struct vfio_device *device;
2960     + struct vfio_pci_device *vdev;
2961     +
2962     + if (devs->cur_index == devs->max_index)
2963     + return -ENOSPC;
2964     +
2965     + device = vfio_device_get_from_dev(&pdev->dev);
2966     + if (!device)
2967     + return -EINVAL;
2968     +
2969     + if (pci_dev_driver(pdev) != &vfio_pci_driver) {
2970     + vfio_device_put(device);
2971     + return -EBUSY;
2972     + }
2973     +
2974     + vdev = vfio_device_data(device);
2975     +
2976     + /*
2977     + * Locking multiple devices is prone to deadlock, runaway and
2978     + * unwind if we hit contention.
2979     + */
2980     + if (!vfio_pci_zap_and_vma_lock(vdev, true)) {
2981     + vfio_device_put(device);
2982     + return -EBUSY;
2983     + }
2984     +
2985     + devs->devices[devs->cur_index++] = device;
2986     + return 0;
2987     +}
2988     +
2989     /*
2990     * If a bus or slot reset is available for the provided device and:
2991     * - All of the devices affected by that bus or slot reset are unused
2992     diff --git a/drivers/vfio/pci/vfio_pci_config.c b/drivers/vfio/pci/vfio_pci_config.c
2993     index d6359c37c9e55..927b608461c82 100644
2994     --- a/drivers/vfio/pci/vfio_pci_config.c
2995     +++ b/drivers/vfio/pci/vfio_pci_config.c
2996     @@ -395,6 +395,20 @@ static inline void p_setd(struct perm_bits *p, int off, u32 virt, u32 write)
2997     *(__le32 *)(&p->write[off]) = cpu_to_le32(write);
2998     }
2999    
3000     +/* Caller should hold memory_lock semaphore */
3001     +bool __vfio_pci_memory_enabled(struct vfio_pci_device *vdev)
3002     +{
3003     + struct pci_dev *pdev = vdev->pdev;
3004     + u16 cmd = le16_to_cpu(*(__le16 *)&vdev->vconfig[PCI_COMMAND]);
3005     +
3006     + /*
3007     + * SR-IOV VF memory enable is handled by the MSE bit in the
3008     + * PF SR-IOV capability, there's therefore no need to trigger
3009     + * faults based on the virtual value.
3010     + */
3011     + return pdev->is_virtfn || (cmd & PCI_COMMAND_MEMORY);
3012     +}
3013     +
3014     /*
3015     * Restore the *real* BARs after we detect a FLR or backdoor reset.
3016     * (backdoor = some device specific technique that we didn't catch)
3017     @@ -554,13 +568,18 @@ static int vfio_basic_config_write(struct vfio_pci_device *vdev, int pos,
3018    
3019     new_cmd = le32_to_cpu(val);
3020    
3021     + phys_io = !!(phys_cmd & PCI_COMMAND_IO);
3022     + virt_io = !!(le16_to_cpu(*virt_cmd) & PCI_COMMAND_IO);
3023     + new_io = !!(new_cmd & PCI_COMMAND_IO);
3024     +
3025     phys_mem = !!(phys_cmd & PCI_COMMAND_MEMORY);
3026     virt_mem = !!(le16_to_cpu(*virt_cmd) & PCI_COMMAND_MEMORY);
3027     new_mem = !!(new_cmd & PCI_COMMAND_MEMORY);
3028    
3029     - phys_io = !!(phys_cmd & PCI_COMMAND_IO);
3030     - virt_io = !!(le16_to_cpu(*virt_cmd) & PCI_COMMAND_IO);
3031     - new_io = !!(new_cmd & PCI_COMMAND_IO);
3032     + if (!new_mem)
3033     + vfio_pci_zap_and_down_write_memory_lock(vdev);
3034     + else
3035     + down_write(&vdev->memory_lock);
3036    
3037     /*
3038     * If the user is writing mem/io enable (new_mem/io) and we
3039     @@ -577,8 +596,11 @@ static int vfio_basic_config_write(struct vfio_pci_device *vdev, int pos,
3040     }
3041    
3042     count = vfio_default_config_write(vdev, pos, count, perm, offset, val);
3043     - if (count < 0)
3044     + if (count < 0) {
3045     + if (offset == PCI_COMMAND)
3046     + up_write(&vdev->memory_lock);
3047     return count;
3048     + }
3049    
3050     /*
3051     * Save current memory/io enable bits in vconfig to allow for
3052     @@ -589,6 +611,8 @@ static int vfio_basic_config_write(struct vfio_pci_device *vdev, int pos,
3053    
3054     *virt_cmd &= cpu_to_le16(~mask);
3055     *virt_cmd |= cpu_to_le16(new_cmd & mask);
3056     +
3057     + up_write(&vdev->memory_lock);
3058     }
3059    
3060     /* Emulate INTx disable */
3061     @@ -826,8 +850,11 @@ static int vfio_exp_config_write(struct vfio_pci_device *vdev, int pos,
3062     pos - offset + PCI_EXP_DEVCAP,
3063     &cap);
3064    
3065     - if (!ret && (cap & PCI_EXP_DEVCAP_FLR))
3066     + if (!ret && (cap & PCI_EXP_DEVCAP_FLR)) {
3067     + vfio_pci_zap_and_down_write_memory_lock(vdev);
3068     pci_try_reset_function(vdev->pdev);
3069     + up_write(&vdev->memory_lock);
3070     + }
3071     }
3072    
3073     /*
3074     @@ -905,8 +932,11 @@ static int vfio_af_config_write(struct vfio_pci_device *vdev, int pos,
3075     pos - offset + PCI_AF_CAP,
3076     &cap);
3077    
3078     - if (!ret && (cap & PCI_AF_CAP_FLR) && (cap & PCI_AF_CAP_TP))
3079     + if (!ret && (cap & PCI_AF_CAP_FLR) && (cap & PCI_AF_CAP_TP)) {
3080     + vfio_pci_zap_and_down_write_memory_lock(vdev);
3081     pci_try_reset_function(vdev->pdev);
3082     + up_write(&vdev->memory_lock);
3083     + }
3084     }
3085    
3086     return count;
3087     @@ -1702,6 +1732,15 @@ int vfio_config_init(struct vfio_pci_device *vdev)
3088     vconfig[PCI_INTERRUPT_PIN]);
3089    
3090     vconfig[PCI_INTERRUPT_PIN] = 0; /* Gratuitous for good VFs */
3091     +
3092     + /*
3093     + * VFs do no implement the memory enable bit of the COMMAND
3094     + * register therefore we'll not have it set in our initial
3095     + * copy of config space after pci_enable_device(). For
3096     + * consistency with PFs, set the virtual enable bit here.
3097     + */
3098     + *(__le16 *)&vconfig[PCI_COMMAND] |=
3099     + cpu_to_le16(PCI_COMMAND_MEMORY);
3100     }
3101    
3102     if (!IS_ENABLED(CONFIG_VFIO_PCI_INTX) || vdev->nointx)
3103     diff --git a/drivers/vfio/pci/vfio_pci_intrs.c b/drivers/vfio/pci/vfio_pci_intrs.c
3104     index 2056f3f85f59b..1d9fb25929459 100644
3105     --- a/drivers/vfio/pci/vfio_pci_intrs.c
3106     +++ b/drivers/vfio/pci/vfio_pci_intrs.c
3107     @@ -249,6 +249,7 @@ static int vfio_msi_enable(struct vfio_pci_device *vdev, int nvec, bool msix)
3108     struct pci_dev *pdev = vdev->pdev;
3109     unsigned int flag = msix ? PCI_IRQ_MSIX : PCI_IRQ_MSI;
3110     int ret;
3111     + u16 cmd;
3112    
3113     if (!is_irq_none(vdev))
3114     return -EINVAL;
3115     @@ -258,13 +259,16 @@ static int vfio_msi_enable(struct vfio_pci_device *vdev, int nvec, bool msix)
3116     return -ENOMEM;
3117    
3118     /* return the number of supported vectors if we can't get all: */
3119     + cmd = vfio_pci_memory_lock_and_enable(vdev);
3120     ret = pci_alloc_irq_vectors(pdev, 1, nvec, flag);
3121     if (ret < nvec) {
3122     if (ret > 0)
3123     pci_free_irq_vectors(pdev);
3124     + vfio_pci_memory_unlock_and_restore(vdev, cmd);
3125     kfree(vdev->ctx);
3126     return ret;
3127     }
3128     + vfio_pci_memory_unlock_and_restore(vdev, cmd);
3129    
3130     vdev->num_ctx = nvec;
3131     vdev->irq_type = msix ? VFIO_PCI_MSIX_IRQ_INDEX :
3132     @@ -287,6 +291,7 @@ static int vfio_msi_set_vector_signal(struct vfio_pci_device *vdev,
3133     struct pci_dev *pdev = vdev->pdev;
3134     struct eventfd_ctx *trigger;
3135     int irq, ret;
3136     + u16 cmd;
3137    
3138     if (vector < 0 || vector >= vdev->num_ctx)
3139     return -EINVAL;
3140     @@ -295,7 +300,11 @@ static int vfio_msi_set_vector_signal(struct vfio_pci_device *vdev,
3141    
3142     if (vdev->ctx[vector].trigger) {
3143     irq_bypass_unregister_producer(&vdev->ctx[vector].producer);
3144     +
3145     + cmd = vfio_pci_memory_lock_and_enable(vdev);
3146     free_irq(irq, vdev->ctx[vector].trigger);
3147     + vfio_pci_memory_unlock_and_restore(vdev, cmd);
3148     +
3149     kfree(vdev->ctx[vector].name);
3150     eventfd_ctx_put(vdev->ctx[vector].trigger);
3151     vdev->ctx[vector].trigger = NULL;
3152     @@ -323,6 +332,7 @@ static int vfio_msi_set_vector_signal(struct vfio_pci_device *vdev,
3153     * such a reset it would be unsuccessful. To avoid this, restore the
3154     * cached value of the message prior to enabling.
3155     */
3156     + cmd = vfio_pci_memory_lock_and_enable(vdev);
3157     if (msix) {
3158     struct msi_msg msg;
3159    
3160     @@ -332,6 +342,7 @@ static int vfio_msi_set_vector_signal(struct vfio_pci_device *vdev,
3161    
3162     ret = request_irq(irq, vfio_msihandler, 0,
3163     vdev->ctx[vector].name, trigger);
3164     + vfio_pci_memory_unlock_and_restore(vdev, cmd);
3165     if (ret) {
3166     kfree(vdev->ctx[vector].name);
3167     eventfd_ctx_put(trigger);
3168     @@ -376,6 +387,7 @@ static void vfio_msi_disable(struct vfio_pci_device *vdev, bool msix)
3169     {
3170     struct pci_dev *pdev = vdev->pdev;
3171     int i;
3172     + u16 cmd;
3173    
3174     for (i = 0; i < vdev->num_ctx; i++) {
3175     vfio_virqfd_disable(&vdev->ctx[i].unmask);
3176     @@ -384,7 +396,9 @@ static void vfio_msi_disable(struct vfio_pci_device *vdev, bool msix)
3177    
3178     vfio_msi_set_block(vdev, 0, vdev->num_ctx, NULL, msix);
3179    
3180     + cmd = vfio_pci_memory_lock_and_enable(vdev);
3181     pci_free_irq_vectors(pdev);
3182     + vfio_pci_memory_unlock_and_restore(vdev, cmd);
3183    
3184     /*
3185     * Both disable paths above use pci_intx_for_msi() to clear DisINTx
3186     diff --git a/drivers/vfio/pci/vfio_pci_private.h b/drivers/vfio/pci/vfio_pci_private.h
3187     index ee6ee91718a4d..987b4d311fde9 100644
3188     --- a/drivers/vfio/pci/vfio_pci_private.h
3189     +++ b/drivers/vfio/pci/vfio_pci_private.h
3190     @@ -84,6 +84,11 @@ struct vfio_pci_reflck {
3191     struct mutex lock;
3192     };
3193    
3194     +struct vfio_pci_mmap_vma {
3195     + struct vm_area_struct *vma;
3196     + struct list_head vma_next;
3197     +};
3198     +
3199     struct vfio_pci_device {
3200     struct pci_dev *pdev;
3201     void __iomem *barmap[PCI_STD_RESOURCE_END + 1];
3202     @@ -122,6 +127,9 @@ struct vfio_pci_device {
3203     struct list_head dummy_resources_list;
3204     struct mutex ioeventfds_lock;
3205     struct list_head ioeventfds_list;
3206     + struct mutex vma_lock;
3207     + struct list_head vma_list;
3208     + struct rw_semaphore memory_lock;
3209     };
3210    
3211     #define is_intx(vdev) (vdev->irq_type == VFIO_PCI_INTX_IRQ_INDEX)
3212     @@ -164,6 +172,13 @@ extern int vfio_pci_register_dev_region(struct vfio_pci_device *vdev,
3213     extern int vfio_pci_set_power_state(struct vfio_pci_device *vdev,
3214     pci_power_t state);
3215    
3216     +extern bool __vfio_pci_memory_enabled(struct vfio_pci_device *vdev);
3217     +extern void vfio_pci_zap_and_down_write_memory_lock(struct vfio_pci_device
3218     + *vdev);
3219     +extern u16 vfio_pci_memory_lock_and_enable(struct vfio_pci_device *vdev);
3220     +extern void vfio_pci_memory_unlock_and_restore(struct vfio_pci_device *vdev,
3221     + u16 cmd);
3222     +
3223     #ifdef CONFIG_VFIO_PCI_IGD
3224     extern int vfio_pci_igd_init(struct vfio_pci_device *vdev);
3225     #else
3226     diff --git a/drivers/vfio/pci/vfio_pci_rdwr.c b/drivers/vfio/pci/vfio_pci_rdwr.c
3227     index 0120d8324a402..83f81d24df78e 100644
3228     --- a/drivers/vfio/pci/vfio_pci_rdwr.c
3229     +++ b/drivers/vfio/pci/vfio_pci_rdwr.c
3230     @@ -162,6 +162,7 @@ ssize_t vfio_pci_bar_rw(struct vfio_pci_device *vdev, char __user *buf,
3231     size_t x_start = 0, x_end = 0;
3232     resource_size_t end;
3233     void __iomem *io;
3234     + struct resource *res = &vdev->pdev->resource[bar];
3235     ssize_t done;
3236    
3237     if (pci_resource_start(pdev, bar))
3238     @@ -177,6 +178,14 @@ ssize_t vfio_pci_bar_rw(struct vfio_pci_device *vdev, char __user *buf,
3239    
3240     count = min(count, (size_t)(end - pos));
3241    
3242     + if (res->flags & IORESOURCE_MEM) {
3243     + down_read(&vdev->memory_lock);
3244     + if (!__vfio_pci_memory_enabled(vdev)) {
3245     + up_read(&vdev->memory_lock);
3246     + return -EIO;
3247     + }
3248     + }
3249     +
3250     if (bar == PCI_ROM_RESOURCE) {
3251     /*
3252     * The ROM can fill less space than the BAR, so we start the
3253     @@ -184,13 +193,17 @@ ssize_t vfio_pci_bar_rw(struct vfio_pci_device *vdev, char __user *buf,
3254     * filling large ROM BARs much faster.
3255     */
3256     io = pci_map_rom(pdev, &x_start);
3257     - if (!io)
3258     - return -ENOMEM;
3259     + if (!io) {
3260     + done = -ENOMEM;
3261     + goto out;
3262     + }
3263     x_end = end;
3264     } else {
3265     int ret = vfio_pci_setup_barmap(vdev, bar);
3266     - if (ret)
3267     - return ret;
3268     + if (ret) {
3269     + done = ret;
3270     + goto out;
3271     + }
3272    
3273     io = vdev->barmap[bar];
3274     }
3275     @@ -207,6 +220,9 @@ ssize_t vfio_pci_bar_rw(struct vfio_pci_device *vdev, char __user *buf,
3276    
3277     if (bar == PCI_ROM_RESOURCE)
3278     pci_unmap_rom(pdev, io);
3279     +out:
3280     + if (res->flags & IORESOURCE_MEM)
3281     + up_read(&vdev->memory_lock);
3282    
3283     return done;
3284     }
3285     diff --git a/drivers/vfio/vfio_iommu_type1.c b/drivers/vfio/vfio_iommu_type1.c
3286     index ca8c10aa4a4bc..c6220f57fdf3e 100644
3287     --- a/drivers/vfio/vfio_iommu_type1.c
3288     +++ b/drivers/vfio/vfio_iommu_type1.c
3289     @@ -335,6 +335,32 @@ static int put_pfn(unsigned long pfn, int prot)
3290     return 0;
3291     }
3292    
3293     +static int follow_fault_pfn(struct vm_area_struct *vma, struct mm_struct *mm,
3294     + unsigned long vaddr, unsigned long *pfn,
3295     + bool write_fault)
3296     +{
3297     + int ret;
3298     +
3299     + ret = follow_pfn(vma, vaddr, pfn);
3300     + if (ret) {
3301     + bool unlocked = false;
3302     +
3303     + ret = fixup_user_fault(NULL, mm, vaddr,
3304     + FAULT_FLAG_REMOTE |
3305     + (write_fault ? FAULT_FLAG_WRITE : 0),
3306     + &unlocked);
3307     + if (unlocked)
3308     + return -EAGAIN;
3309     +
3310     + if (ret)
3311     + return ret;
3312     +
3313     + ret = follow_pfn(vma, vaddr, pfn);
3314     + }
3315     +
3316     + return ret;
3317     +}
3318     +
3319     static int vaddr_get_pfn(struct mm_struct *mm, unsigned long vaddr,
3320     int prot, unsigned long *pfn)
3321     {
3322     @@ -377,12 +403,16 @@ static int vaddr_get_pfn(struct mm_struct *mm, unsigned long vaddr,
3323    
3324     vaddr = untagged_addr(vaddr);
3325    
3326     +retry:
3327     vma = find_vma_intersection(mm, vaddr, vaddr + 1);
3328    
3329     if (vma && vma->vm_flags & VM_PFNMAP) {
3330     - if (!follow_pfn(vma, vaddr, pfn) &&
3331     - is_invalid_reserved_pfn(*pfn))
3332     - ret = 0;
3333     + ret = follow_fault_pfn(vma, mm, vaddr, pfn, prot & IOMMU_WRITE);
3334     + if (ret == -EAGAIN)
3335     + goto retry;
3336     +
3337     + if (!ret && !is_invalid_reserved_pfn(*pfn))
3338     + ret = -EFAULT;
3339     }
3340    
3341     up_read(&mm->mmap_sem);
3342     diff --git a/drivers/xen/xenbus/xenbus_client.c b/drivers/xen/xenbus/xenbus_client.c
3343     index a38292ef79f6d..f38bdaea0ef11 100644
3344     --- a/drivers/xen/xenbus/xenbus_client.c
3345     +++ b/drivers/xen/xenbus/xenbus_client.c
3346     @@ -363,8 +363,14 @@ int xenbus_grant_ring(struct xenbus_device *dev, void *vaddr,
3347     int i, j;
3348    
3349     for (i = 0; i < nr_pages; i++) {
3350     - err = gnttab_grant_foreign_access(dev->otherend_id,
3351     - virt_to_gfn(vaddr), 0);
3352     + unsigned long gfn;
3353     +
3354     + if (is_vmalloc_addr(vaddr))
3355     + gfn = pfn_to_gfn(vmalloc_to_pfn(vaddr));
3356     + else
3357     + gfn = virt_to_gfn(vaddr);
3358     +
3359     + err = gnttab_grant_foreign_access(dev->otherend_id, gfn, 0);
3360     if (err < 0) {
3361     xenbus_dev_fatal(dev, err,
3362     "granting access to ring page");
3363     diff --git a/fs/affs/amigaffs.c b/fs/affs/amigaffs.c
3364     index f708c45d5f664..29f11e10a7c7d 100644
3365     --- a/fs/affs/amigaffs.c
3366     +++ b/fs/affs/amigaffs.c
3367     @@ -420,24 +420,51 @@ affs_mode_to_prot(struct inode *inode)
3368     u32 prot = AFFS_I(inode)->i_protect;
3369     umode_t mode = inode->i_mode;
3370    
3371     + /*
3372     + * First, clear all RWED bits for owner, group, other.
3373     + * Then, recalculate them afresh.
3374     + *
3375     + * We'll always clear the delete-inhibit bit for the owner, as that is
3376     + * the classic single-user mode AmigaOS protection bit and we need to
3377     + * stay compatible with all scenarios.
3378     + *
3379     + * Since multi-user AmigaOS is an extension, we'll only set the
3380     + * delete-allow bit if any of the other bits in the same user class
3381     + * (group/other) are used.
3382     + */
3383     + prot &= ~(FIBF_NOEXECUTE | FIBF_NOREAD
3384     + | FIBF_NOWRITE | FIBF_NODELETE
3385     + | FIBF_GRP_EXECUTE | FIBF_GRP_READ
3386     + | FIBF_GRP_WRITE | FIBF_GRP_DELETE
3387     + | FIBF_OTR_EXECUTE | FIBF_OTR_READ
3388     + | FIBF_OTR_WRITE | FIBF_OTR_DELETE);
3389     +
3390     + /* Classic single-user AmigaOS flags. These are inverted. */
3391     if (!(mode & 0100))
3392     prot |= FIBF_NOEXECUTE;
3393     if (!(mode & 0400))
3394     prot |= FIBF_NOREAD;
3395     if (!(mode & 0200))
3396     prot |= FIBF_NOWRITE;
3397     +
3398     + /* Multi-user extended flags. Not inverted. */
3399     if (mode & 0010)
3400     prot |= FIBF_GRP_EXECUTE;
3401     if (mode & 0040)
3402     prot |= FIBF_GRP_READ;
3403     if (mode & 0020)
3404     prot |= FIBF_GRP_WRITE;
3405     + if (mode & 0070)
3406     + prot |= FIBF_GRP_DELETE;
3407     +
3408     if (mode & 0001)
3409     prot |= FIBF_OTR_EXECUTE;
3410     if (mode & 0004)
3411     prot |= FIBF_OTR_READ;
3412     if (mode & 0002)
3413     prot |= FIBF_OTR_WRITE;
3414     + if (mode & 0007)
3415     + prot |= FIBF_OTR_DELETE;
3416    
3417     AFFS_I(inode)->i_protect = prot;
3418     }
3419     diff --git a/fs/affs/file.c b/fs/affs/file.c
3420     index a85817f54483f..ba084b0b214b9 100644
3421     --- a/fs/affs/file.c
3422     +++ b/fs/affs/file.c
3423     @@ -428,6 +428,24 @@ static int affs_write_begin(struct file *file, struct address_space *mapping,
3424     return ret;
3425     }
3426    
3427     +static int affs_write_end(struct file *file, struct address_space *mapping,
3428     + loff_t pos, unsigned int len, unsigned int copied,
3429     + struct page *page, void *fsdata)
3430     +{
3431     + struct inode *inode = mapping->host;
3432     + int ret;
3433     +
3434     + ret = generic_write_end(file, mapping, pos, len, copied, page, fsdata);
3435     +
3436     + /* Clear Archived bit on file writes, as AmigaOS would do */
3437     + if (AFFS_I(inode)->i_protect & FIBF_ARCHIVED) {
3438     + AFFS_I(inode)->i_protect &= ~FIBF_ARCHIVED;
3439     + mark_inode_dirty(inode);
3440     + }
3441     +
3442     + return ret;
3443     +}
3444     +
3445     static sector_t _affs_bmap(struct address_space *mapping, sector_t block)
3446     {
3447     return generic_block_bmap(mapping,block,affs_get_block);
3448     @@ -437,7 +455,7 @@ const struct address_space_operations affs_aops = {
3449     .readpage = affs_readpage,
3450     .writepage = affs_writepage,
3451     .write_begin = affs_write_begin,
3452     - .write_end = generic_write_end,
3453     + .write_end = affs_write_end,
3454     .direct_IO = affs_direct_IO,
3455     .bmap = _affs_bmap
3456     };
3457     @@ -794,6 +812,12 @@ done:
3458     if (tmp > inode->i_size)
3459     inode->i_size = AFFS_I(inode)->mmu_private = tmp;
3460    
3461     + /* Clear Archived bit on file writes, as AmigaOS would do */
3462     + if (AFFS_I(inode)->i_protect & FIBF_ARCHIVED) {
3463     + AFFS_I(inode)->i_protect &= ~FIBF_ARCHIVED;
3464     + mark_inode_dirty(inode);
3465     + }
3466     +
3467     err_first_bh:
3468     unlock_page(page);
3469     put_page(page);
3470     diff --git a/fs/afs/fs_probe.c b/fs/afs/fs_probe.c
3471     index 02e976ca5732f..51ee3dd79700f 100644
3472     --- a/fs/afs/fs_probe.c
3473     +++ b/fs/afs/fs_probe.c
3474     @@ -92,8 +92,8 @@ responded:
3475     }
3476     }
3477    
3478     - rtt_us = rxrpc_kernel_get_srtt(call->net->socket, call->rxcall);
3479     - if (rtt_us < server->probe.rtt) {
3480     + if (rxrpc_kernel_get_srtt(call->net->socket, call->rxcall, &rtt_us) &&
3481     + rtt_us < server->probe.rtt) {
3482     server->probe.rtt = rtt_us;
3483     alist->preferred = index;
3484     have_result = true;
3485     diff --git a/fs/afs/vl_probe.c b/fs/afs/vl_probe.c
3486     index e3aa013c21779..081b7e5b13f58 100644
3487     --- a/fs/afs/vl_probe.c
3488     +++ b/fs/afs/vl_probe.c
3489     @@ -92,8 +92,8 @@ responded:
3490     }
3491     }
3492    
3493     - rtt_us = rxrpc_kernel_get_srtt(call->net->socket, call->rxcall);
3494     - if (rtt_us < server->probe.rtt) {
3495     + if (rxrpc_kernel_get_srtt(call->net->socket, call->rxcall, &rtt_us) &&
3496     + rtt_us < server->probe.rtt) {
3497     server->probe.rtt = rtt_us;
3498     alist->preferred = index;
3499     have_result = true;
3500     diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
3501     index a989105d39c86..c05127f506373 100644
3502     --- a/fs/btrfs/ctree.c
3503     +++ b/fs/btrfs/ctree.c
3504     @@ -1339,6 +1339,8 @@ tree_mod_log_rewind(struct btrfs_fs_info *fs_info, struct btrfs_path *path,
3505     btrfs_tree_read_unlock_blocking(eb);
3506     free_extent_buffer(eb);
3507    
3508     + btrfs_set_buffer_lockdep_class(btrfs_header_owner(eb_rewin),
3509     + eb_rewin, btrfs_header_level(eb_rewin));
3510     btrfs_tree_read_lock(eb_rewin);
3511     __tree_mod_log_rewind(fs_info, eb_rewin, time_seq, tm);
3512     WARN_ON(btrfs_header_nritems(eb_rewin) >
3513     @@ -1412,7 +1414,6 @@ get_old_root(struct btrfs_root *root, u64 time_seq)
3514    
3515     if (!eb)
3516     return NULL;
3517     - btrfs_tree_read_lock(eb);
3518     if (old_root) {
3519     btrfs_set_header_bytenr(eb, eb->start);
3520     btrfs_set_header_backref_rev(eb, BTRFS_MIXED_BACKREF_REV);
3521     @@ -1420,6 +1421,9 @@ get_old_root(struct btrfs_root *root, u64 time_seq)
3522     btrfs_set_header_level(eb, old_root->level);
3523     btrfs_set_header_generation(eb, old_generation);
3524     }
3525     + btrfs_set_buffer_lockdep_class(btrfs_header_owner(eb), eb,
3526     + btrfs_header_level(eb));
3527     + btrfs_tree_read_lock(eb);
3528     if (tm)
3529     __tree_mod_log_rewind(fs_info, eb, time_seq, tm);
3530     else
3531     diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
3532     index ef05cbacef73f..541497036cc24 100644
3533     --- a/fs/btrfs/extent-tree.c
3534     +++ b/fs/btrfs/extent-tree.c
3535     @@ -4446,7 +4446,7 @@ btrfs_init_new_buffer(struct btrfs_trans_handle *trans, struct btrfs_root *root,
3536     return ERR_PTR(-EUCLEAN);
3537     }
3538    
3539     - btrfs_set_buffer_lockdep_class(root->root_key.objectid, buf, level);
3540     + btrfs_set_buffer_lockdep_class(owner, buf, level);
3541     btrfs_tree_lock(buf);
3542     btrfs_clean_tree_block(buf);
3543     clear_bit(EXTENT_BUFFER_STALE, &buf->bflags);
3544     diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c
3545     index 5707bf0575d43..60c21cfb19480 100644
3546     --- a/fs/btrfs/extent_io.c
3547     +++ b/fs/btrfs/extent_io.c
3548     @@ -5607,9 +5607,9 @@ void read_extent_buffer(const struct extent_buffer *eb, void *dstv,
3549     }
3550     }
3551    
3552     -int read_extent_buffer_to_user(const struct extent_buffer *eb,
3553     - void __user *dstv,
3554     - unsigned long start, unsigned long len)
3555     +int read_extent_buffer_to_user_nofault(const struct extent_buffer *eb,
3556     + void __user *dstv,
3557     + unsigned long start, unsigned long len)
3558     {
3559     size_t cur;
3560     size_t offset;
3561     @@ -5630,7 +5630,7 @@ int read_extent_buffer_to_user(const struct extent_buffer *eb,
3562    
3563     cur = min(len, (PAGE_SIZE - offset));
3564     kaddr = page_address(page);
3565     - if (copy_to_user(dst, kaddr + offset, cur)) {
3566     + if (probe_user_write(dst, kaddr + offset, cur)) {
3567     ret = -EFAULT;
3568     break;
3569     }
3570     diff --git a/fs/btrfs/extent_io.h b/fs/btrfs/extent_io.h
3571     index cf3424d58fec7..bc858c8cef0a6 100644
3572     --- a/fs/btrfs/extent_io.h
3573     +++ b/fs/btrfs/extent_io.h
3574     @@ -457,9 +457,9 @@ int memcmp_extent_buffer(const struct extent_buffer *eb, const void *ptrv,
3575     void read_extent_buffer(const struct extent_buffer *eb, void *dst,
3576     unsigned long start,
3577     unsigned long len);
3578     -int read_extent_buffer_to_user(const struct extent_buffer *eb,
3579     - void __user *dst, unsigned long start,
3580     - unsigned long len);
3581     +int read_extent_buffer_to_user_nofault(const struct extent_buffer *eb,
3582     + void __user *dst, unsigned long start,
3583     + unsigned long len);
3584     void write_extent_buffer_fsid(struct extent_buffer *eb, const void *src);
3585     void write_extent_buffer_chunk_tree_uuid(struct extent_buffer *eb,
3586     const void *src);
3587     diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
3588     index 88745b5182126..775fd5975191b 100644
3589     --- a/fs/btrfs/ioctl.c
3590     +++ b/fs/btrfs/ioctl.c
3591     @@ -2105,9 +2105,14 @@ static noinline int copy_to_sk(struct btrfs_path *path,
3592     sh.len = item_len;
3593     sh.transid = found_transid;
3594    
3595     - /* copy search result header */
3596     - if (copy_to_user(ubuf + *sk_offset, &sh, sizeof(sh))) {
3597     - ret = -EFAULT;
3598     + /*
3599     + * Copy search result header. If we fault then loop again so we
3600     + * can fault in the pages and -EFAULT there if there's a
3601     + * problem. Otherwise we'll fault and then copy the buffer in
3602     + * properly this next time through
3603     + */
3604     + if (probe_user_write(ubuf + *sk_offset, &sh, sizeof(sh))) {
3605     + ret = 0;
3606     goto out;
3607     }
3608    
3609     @@ -2115,10 +2120,14 @@ static noinline int copy_to_sk(struct btrfs_path *path,
3610    
3611     if (item_len) {
3612     char __user *up = ubuf + *sk_offset;
3613     - /* copy the item */
3614     - if (read_extent_buffer_to_user(leaf, up,
3615     - item_off, item_len)) {
3616     - ret = -EFAULT;
3617     + /*
3618     + * Copy the item, same behavior as above, but reset the
3619     + * * sk_offset so we copy the full thing again.
3620     + */
3621     + if (read_extent_buffer_to_user_nofault(leaf, up,
3622     + item_off, item_len)) {
3623     + ret = 0;
3624     + *sk_offset -= sizeof(sh);
3625     goto out;
3626     }
3627    
3628     @@ -2206,6 +2215,10 @@ static noinline int search_ioctl(struct inode *inode,
3629     key.offset = sk->min_offset;
3630    
3631     while (1) {
3632     + ret = fault_in_pages_writeable(ubuf, *buf_size - sk_offset);
3633     + if (ret)
3634     + break;
3635     +
3636     ret = btrfs_search_forward(root, &key, path, sk->min_transid);
3637     if (ret != 0) {
3638     if (ret > 0)
3639     diff --git a/fs/btrfs/scrub.c b/fs/btrfs/scrub.c
3640     index 498b824148187..93d7cb56e44b2 100644
3641     --- a/fs/btrfs/scrub.c
3642     +++ b/fs/btrfs/scrub.c
3643     @@ -3742,50 +3742,84 @@ static noinline_for_stack int scrub_supers(struct scrub_ctx *sctx,
3644     return 0;
3645     }
3646    
3647     +static void scrub_workers_put(struct btrfs_fs_info *fs_info)
3648     +{
3649     + if (refcount_dec_and_mutex_lock(&fs_info->scrub_workers_refcnt,
3650     + &fs_info->scrub_lock)) {
3651     + struct btrfs_workqueue *scrub_workers = NULL;
3652     + struct btrfs_workqueue *scrub_wr_comp = NULL;
3653     + struct btrfs_workqueue *scrub_parity = NULL;
3654     +
3655     + scrub_workers = fs_info->scrub_workers;
3656     + scrub_wr_comp = fs_info->scrub_wr_completion_workers;
3657     + scrub_parity = fs_info->scrub_parity_workers;
3658     +
3659     + fs_info->scrub_workers = NULL;
3660     + fs_info->scrub_wr_completion_workers = NULL;
3661     + fs_info->scrub_parity_workers = NULL;
3662     + mutex_unlock(&fs_info->scrub_lock);
3663     +
3664     + btrfs_destroy_workqueue(scrub_workers);
3665     + btrfs_destroy_workqueue(scrub_wr_comp);
3666     + btrfs_destroy_workqueue(scrub_parity);
3667     + }
3668     +}
3669     +
3670     /*
3671     * get a reference count on fs_info->scrub_workers. start worker if necessary
3672     */
3673     static noinline_for_stack int scrub_workers_get(struct btrfs_fs_info *fs_info,
3674     int is_dev_replace)
3675     {
3676     + struct btrfs_workqueue *scrub_workers = NULL;
3677     + struct btrfs_workqueue *scrub_wr_comp = NULL;
3678     + struct btrfs_workqueue *scrub_parity = NULL;
3679     unsigned int flags = WQ_FREEZABLE | WQ_UNBOUND;
3680     int max_active = fs_info->thread_pool_size;
3681     + int ret = -ENOMEM;
3682    
3683     - lockdep_assert_held(&fs_info->scrub_lock);
3684     + if (refcount_inc_not_zero(&fs_info->scrub_workers_refcnt))
3685     + return 0;
3686    
3687     - if (refcount_read(&fs_info->scrub_workers_refcnt) == 0) {
3688     - ASSERT(fs_info->scrub_workers == NULL);
3689     - fs_info->scrub_workers = btrfs_alloc_workqueue(fs_info, "scrub",
3690     - flags, is_dev_replace ? 1 : max_active, 4);
3691     - if (!fs_info->scrub_workers)
3692     - goto fail_scrub_workers;
3693     -
3694     - ASSERT(fs_info->scrub_wr_completion_workers == NULL);
3695     - fs_info->scrub_wr_completion_workers =
3696     - btrfs_alloc_workqueue(fs_info, "scrubwrc", flags,
3697     - max_active, 2);
3698     - if (!fs_info->scrub_wr_completion_workers)
3699     - goto fail_scrub_wr_completion_workers;
3700     + scrub_workers = btrfs_alloc_workqueue(fs_info, "scrub", flags,
3701     + is_dev_replace ? 1 : max_active, 4);
3702     + if (!scrub_workers)
3703     + goto fail_scrub_workers;
3704    
3705     - ASSERT(fs_info->scrub_parity_workers == NULL);
3706     - fs_info->scrub_parity_workers =
3707     - btrfs_alloc_workqueue(fs_info, "scrubparity", flags,
3708     + scrub_wr_comp = btrfs_alloc_workqueue(fs_info, "scrubwrc", flags,
3709     max_active, 2);
3710     - if (!fs_info->scrub_parity_workers)
3711     - goto fail_scrub_parity_workers;
3712     + if (!scrub_wr_comp)
3713     + goto fail_scrub_wr_completion_workers;
3714    
3715     + scrub_parity = btrfs_alloc_workqueue(fs_info, "scrubparity", flags,
3716     + max_active, 2);
3717     + if (!scrub_parity)
3718     + goto fail_scrub_parity_workers;
3719     +
3720     + mutex_lock(&fs_info->scrub_lock);
3721     + if (refcount_read(&fs_info->scrub_workers_refcnt) == 0) {
3722     + ASSERT(fs_info->scrub_workers == NULL &&
3723     + fs_info->scrub_wr_completion_workers == NULL &&
3724     + fs_info->scrub_parity_workers == NULL);
3725     + fs_info->scrub_workers = scrub_workers;
3726     + fs_info->scrub_wr_completion_workers = scrub_wr_comp;
3727     + fs_info->scrub_parity_workers = scrub_parity;
3728     refcount_set(&fs_info->scrub_workers_refcnt, 1);
3729     - } else {
3730     - refcount_inc(&fs_info->scrub_workers_refcnt);
3731     + mutex_unlock(&fs_info->scrub_lock);
3732     + return 0;
3733     }
3734     - return 0;
3735     + /* Other thread raced in and created the workers for us */
3736     + refcount_inc(&fs_info->scrub_workers_refcnt);
3737     + mutex_unlock(&fs_info->scrub_lock);
3738    
3739     + ret = 0;
3740     + btrfs_destroy_workqueue(scrub_parity);
3741     fail_scrub_parity_workers:
3742     - btrfs_destroy_workqueue(fs_info->scrub_wr_completion_workers);
3743     + btrfs_destroy_workqueue(scrub_wr_comp);
3744     fail_scrub_wr_completion_workers:
3745     - btrfs_destroy_workqueue(fs_info->scrub_workers);
3746     + btrfs_destroy_workqueue(scrub_workers);
3747     fail_scrub_workers:
3748     - return -ENOMEM;
3749     + return ret;
3750     }
3751    
3752     int btrfs_scrub_dev(struct btrfs_fs_info *fs_info, u64 devid, u64 start,
3753     @@ -3796,9 +3830,6 @@ int btrfs_scrub_dev(struct btrfs_fs_info *fs_info, u64 devid, u64 start,
3754     int ret;
3755     struct btrfs_device *dev;
3756     unsigned int nofs_flag;
3757     - struct btrfs_workqueue *scrub_workers = NULL;
3758     - struct btrfs_workqueue *scrub_wr_comp = NULL;
3759     - struct btrfs_workqueue *scrub_parity = NULL;
3760    
3761     if (btrfs_fs_closing(fs_info))
3762     return -EAGAIN;
3763     @@ -3845,13 +3876,17 @@ int btrfs_scrub_dev(struct btrfs_fs_info *fs_info, u64 devid, u64 start,
3764     if (IS_ERR(sctx))
3765     return PTR_ERR(sctx);
3766    
3767     + ret = scrub_workers_get(fs_info, is_dev_replace);
3768     + if (ret)
3769     + goto out_free_ctx;
3770     +
3771     mutex_lock(&fs_info->fs_devices->device_list_mutex);
3772     dev = btrfs_find_device(fs_info->fs_devices, devid, NULL, NULL, true);
3773     if (!dev || (test_bit(BTRFS_DEV_STATE_MISSING, &dev->dev_state) &&
3774     !is_dev_replace)) {
3775     mutex_unlock(&fs_info->fs_devices->device_list_mutex);
3776     ret = -ENODEV;
3777     - goto out_free_ctx;
3778     + goto out;
3779     }
3780    
3781     if (!is_dev_replace && !readonly &&
3782     @@ -3860,7 +3895,7 @@ int btrfs_scrub_dev(struct btrfs_fs_info *fs_info, u64 devid, u64 start,
3783     btrfs_err_in_rcu(fs_info, "scrub: device %s is not writable",
3784     rcu_str_deref(dev->name));
3785     ret = -EROFS;
3786     - goto out_free_ctx;
3787     + goto out;
3788     }
3789    
3790     mutex_lock(&fs_info->scrub_lock);
3791     @@ -3869,7 +3904,7 @@ int btrfs_scrub_dev(struct btrfs_fs_info *fs_info, u64 devid, u64 start,
3792     mutex_unlock(&fs_info->scrub_lock);
3793     mutex_unlock(&fs_info->fs_devices->device_list_mutex);
3794     ret = -EIO;
3795     - goto out_free_ctx;
3796     + goto out;
3797     }
3798    
3799     down_read(&fs_info->dev_replace.rwsem);
3800     @@ -3880,17 +3915,10 @@ int btrfs_scrub_dev(struct btrfs_fs_info *fs_info, u64 devid, u64 start,
3801     mutex_unlock(&fs_info->scrub_lock);
3802     mutex_unlock(&fs_info->fs_devices->device_list_mutex);
3803     ret = -EINPROGRESS;
3804     - goto out_free_ctx;
3805     + goto out;
3806     }
3807     up_read(&fs_info->dev_replace.rwsem);
3808    
3809     - ret = scrub_workers_get(fs_info, is_dev_replace);
3810     - if (ret) {
3811     - mutex_unlock(&fs_info->scrub_lock);
3812     - mutex_unlock(&fs_info->fs_devices->device_list_mutex);
3813     - goto out_free_ctx;
3814     - }
3815     -
3816     sctx->readonly = readonly;
3817     dev->scrub_ctx = sctx;
3818     mutex_unlock(&fs_info->fs_devices->device_list_mutex);
3819     @@ -3943,24 +3971,14 @@ int btrfs_scrub_dev(struct btrfs_fs_info *fs_info, u64 devid, u64 start,
3820    
3821     mutex_lock(&fs_info->scrub_lock);
3822     dev->scrub_ctx = NULL;
3823     - if (refcount_dec_and_test(&fs_info->scrub_workers_refcnt)) {
3824     - scrub_workers = fs_info->scrub_workers;
3825     - scrub_wr_comp = fs_info->scrub_wr_completion_workers;
3826     - scrub_parity = fs_info->scrub_parity_workers;
3827     -
3828     - fs_info->scrub_workers = NULL;
3829     - fs_info->scrub_wr_completion_workers = NULL;
3830     - fs_info->scrub_parity_workers = NULL;
3831     - }
3832     mutex_unlock(&fs_info->scrub_lock);
3833    
3834     - btrfs_destroy_workqueue(scrub_workers);
3835     - btrfs_destroy_workqueue(scrub_wr_comp);
3836     - btrfs_destroy_workqueue(scrub_parity);
3837     + scrub_workers_put(fs_info);
3838     scrub_put_ctx(sctx);
3839    
3840     return ret;
3841     -
3842     +out:
3843     + scrub_workers_put(fs_info);
3844     out_free_ctx:
3845     scrub_free_ctx(sctx);
3846    
3847     diff --git a/fs/btrfs/tree-checker.c b/fs/btrfs/tree-checker.c
3848     index 0e44db066641e..91ea38506fbb7 100644
3849     --- a/fs/btrfs/tree-checker.c
3850     +++ b/fs/btrfs/tree-checker.c
3851     @@ -772,7 +772,7 @@ static int check_inode_item(struct extent_buffer *leaf,
3852     /* Here we use super block generation + 1 to handle log tree */
3853     if (btrfs_inode_generation(leaf, iitem) > super_gen + 1) {
3854     inode_item_err(fs_info, leaf, slot,
3855     - "invalid inode generation: has %llu expect (0, %llu]",
3856     + "invalid inode transid: has %llu expect [0, %llu]",
3857     btrfs_inode_generation(leaf, iitem),
3858     super_gen + 1);
3859     return -EUCLEAN;
3860     diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
3861     index 196ddbcd29360..81be71fb569e1 100644
3862     --- a/fs/btrfs/volumes.c
3863     +++ b/fs/btrfs/volumes.c
3864     @@ -4568,6 +4568,7 @@ static int btrfs_uuid_scan_kthread(void *data)
3865     goto skip;
3866     }
3867     update_tree:
3868     + btrfs_release_path(path);
3869     if (!btrfs_is_empty_uuid(root_item.uuid)) {
3870     ret = btrfs_uuid_tree_add(trans, root_item.uuid,
3871     BTRFS_UUID_KEY_SUBVOL,
3872     @@ -4592,6 +4593,7 @@ update_tree:
3873     }
3874    
3875     skip:
3876     + btrfs_release_path(path);
3877     if (trans) {
3878     ret = btrfs_end_transaction(trans);
3879     trans = NULL;
3880     @@ -4599,7 +4601,6 @@ skip:
3881     break;
3882     }
3883    
3884     - btrfs_release_path(path);
3885     if (key.offset < (u64)-1) {
3886     key.offset++;
3887     } else if (key.type < BTRFS_ROOT_ITEM_KEY) {
3888     diff --git a/fs/ceph/file.c b/fs/ceph/file.c
3889     index 4a6b14a2bd7f9..a10711a6337af 100644
3890     --- a/fs/ceph/file.c
3891     +++ b/fs/ceph/file.c
3892     @@ -2198,6 +2198,7 @@ const struct file_operations ceph_file_fops = {
3893     .mmap = ceph_mmap,
3894     .fsync = ceph_fsync,
3895     .lock = ceph_lock,
3896     + .setlease = simple_nosetlease,
3897     .flock = ceph_flock,
3898     .splice_read = generic_file_splice_read,
3899     .splice_write = iter_file_splice_write,
3900     diff --git a/fs/eventpoll.c b/fs/eventpoll.c
3901     index 0d9b1e2b9da72..ae1d32344f7ac 100644
3902     --- a/fs/eventpoll.c
3903     +++ b/fs/eventpoll.c
3904     @@ -1992,9 +1992,9 @@ static int ep_loop_check_proc(void *priv, void *cookie, int call_nests)
3905     * during ep_insert().
3906     */
3907     if (list_empty(&epi->ffd.file->f_tfile_llink)) {
3908     - get_file(epi->ffd.file);
3909     - list_add(&epi->ffd.file->f_tfile_llink,
3910     - &tfile_check_list);
3911     + if (get_file_rcu(epi->ffd.file))
3912     + list_add(&epi->ffd.file->f_tfile_llink,
3913     + &tfile_check_list);
3914     }
3915     }
3916     }
3917     diff --git a/fs/ext2/file.c b/fs/ext2/file.c
3918     index 39c4772e96c9d..d73103cdda210 100644
3919     --- a/fs/ext2/file.c
3920     +++ b/fs/ext2/file.c
3921     @@ -93,8 +93,10 @@ static vm_fault_t ext2_dax_fault(struct vm_fault *vmf)
3922     struct inode *inode = file_inode(vmf->vma->vm_file);
3923     struct ext2_inode_info *ei = EXT2_I(inode);
3924     vm_fault_t ret;
3925     + bool write = (vmf->flags & FAULT_FLAG_WRITE) &&
3926     + (vmf->vma->vm_flags & VM_SHARED);
3927    
3928     - if (vmf->flags & FAULT_FLAG_WRITE) {
3929     + if (write) {
3930     sb_start_pagefault(inode->i_sb);
3931     file_update_time(vmf->vma->vm_file);
3932     }
3933     @@ -103,7 +105,7 @@ static vm_fault_t ext2_dax_fault(struct vm_fault *vmf)
3934     ret = dax_iomap_fault(vmf, PE_SIZE_PTE, NULL, NULL, &ext2_iomap_ops);
3935    
3936     up_read(&ei->dax_sem);
3937     - if (vmf->flags & FAULT_FLAG_WRITE)
3938     + if (write)
3939     sb_end_pagefault(inode->i_sb);
3940     return ret;
3941     }
3942     diff --git a/fs/xfs/libxfs/xfs_attr_leaf.c b/fs/xfs/libxfs/xfs_attr_leaf.c
3943     index f0089e862216c..fe277ee5ec7c4 100644
3944     --- a/fs/xfs/libxfs/xfs_attr_leaf.c
3945     +++ b/fs/xfs/libxfs/xfs_attr_leaf.c
3946     @@ -946,8 +946,10 @@ xfs_attr_shortform_verify(
3947     * struct xfs_attr_sf_entry has a variable length.
3948     * Check the fixed-offset parts of the structure are
3949     * within the data buffer.
3950     + * xfs_attr_sf_entry is defined with a 1-byte variable
3951     + * array at the end, so we must subtract that off.
3952     */
3953     - if (((char *)sfep + sizeof(*sfep)) >= endp)
3954     + if (((char *)sfep + sizeof(*sfep) - 1) >= endp)
3955     return __this_address;
3956    
3957     /* Don't allow names with known bad length. */
3958     diff --git a/fs/xfs/libxfs/xfs_bmap.c b/fs/xfs/libxfs/xfs_bmap.c
3959     index 3f76da11197c4..19a600443b9ee 100644
3960     --- a/fs/xfs/libxfs/xfs_bmap.c
3961     +++ b/fs/xfs/libxfs/xfs_bmap.c
3962     @@ -6179,7 +6179,7 @@ xfs_bmap_validate_extent(
3963    
3964     isrt = XFS_IS_REALTIME_INODE(ip);
3965     endfsb = irec->br_startblock + irec->br_blockcount - 1;
3966     - if (isrt) {
3967     + if (isrt && whichfork == XFS_DATA_FORK) {
3968     if (!xfs_verify_rtbno(mp, irec->br_startblock))
3969     return __this_address;
3970     if (!xfs_verify_rtbno(mp, endfsb))
3971     diff --git a/fs/xfs/xfs_file.c b/fs/xfs/xfs_file.c
3972     index 1ffb179f35d23..1e2176190c86f 100644
3973     --- a/fs/xfs/xfs_file.c
3974     +++ b/fs/xfs/xfs_file.c
3975     @@ -1172,6 +1172,14 @@ __xfs_filemap_fault(
3976     return ret;
3977     }
3978    
3979     +static inline bool
3980     +xfs_is_write_fault(
3981     + struct vm_fault *vmf)
3982     +{
3983     + return (vmf->flags & FAULT_FLAG_WRITE) &&
3984     + (vmf->vma->vm_flags & VM_SHARED);
3985     +}
3986     +
3987     static vm_fault_t
3988     xfs_filemap_fault(
3989     struct vm_fault *vmf)
3990     @@ -1179,7 +1187,7 @@ xfs_filemap_fault(
3991     /* DAX can shortcut the normal fault path on write faults! */
3992     return __xfs_filemap_fault(vmf, PE_SIZE_PTE,
3993     IS_DAX(file_inode(vmf->vma->vm_file)) &&
3994     - (vmf->flags & FAULT_FLAG_WRITE));
3995     + xfs_is_write_fault(vmf));
3996     }
3997    
3998     static vm_fault_t
3999     @@ -1192,7 +1200,7 @@ xfs_filemap_huge_fault(
4000    
4001     /* DAX can shortcut the normal fault path on write faults! */
4002     return __xfs_filemap_fault(vmf, pe_size,
4003     - (vmf->flags & FAULT_FLAG_WRITE));
4004     + xfs_is_write_fault(vmf));
4005     }
4006    
4007     static vm_fault_t
4008     diff --git a/include/linux/bvec.h b/include/linux/bvec.h
4009     index a032f01e928c5..d7a628e066ee8 100644
4010     --- a/include/linux/bvec.h
4011     +++ b/include/linux/bvec.h
4012     @@ -110,11 +110,18 @@ static inline bool bvec_iter_advance(const struct bio_vec *bv,
4013     return true;
4014     }
4015    
4016     +static inline void bvec_iter_skip_zero_bvec(struct bvec_iter *iter)
4017     +{
4018     + iter->bi_bvec_done = 0;
4019     + iter->bi_idx++;
4020     +}
4021     +
4022     #define for_each_bvec(bvl, bio_vec, iter, start) \
4023     for (iter = (start); \
4024     (iter).bi_size && \
4025     ((bvl = bvec_iter_bvec((bio_vec), (iter))), 1); \
4026     - bvec_iter_advance((bio_vec), &(iter), (bvl).bv_len))
4027     + (bvl).bv_len ? (void)bvec_iter_advance((bio_vec), &(iter), \
4028     + (bvl).bv_len) : bvec_iter_skip_zero_bvec(&(iter)))
4029    
4030     /* for iterating one bio from start to end */
4031     #define BVEC_ITER_ALL_INIT (struct bvec_iter) \
4032     diff --git a/include/linux/libata.h b/include/linux/libata.h
4033     index b9970f5bab67c..e752368ea3516 100644
4034     --- a/include/linux/libata.h
4035     +++ b/include/linux/libata.h
4036     @@ -422,6 +422,7 @@ enum {
4037     ATA_HORKAGE_NO_DMA_LOG = (1 << 23), /* don't use DMA for log read */
4038     ATA_HORKAGE_NOTRIM = (1 << 24), /* don't use TRIM */
4039     ATA_HORKAGE_MAX_SEC_1024 = (1 << 25), /* Limit max sects to 1024 */
4040     + ATA_HORKAGE_MAX_TRIM_128M = (1 << 26), /* Limit max trim size to 128M */
4041    
4042     /* DMA mask for user DMA control: User visible values; DO NOT
4043     renumber */
4044     diff --git a/include/linux/log2.h b/include/linux/log2.h
4045     index 83a4a3ca3e8a7..c619ec6eff4ae 100644
4046     --- a/include/linux/log2.h
4047     +++ b/include/linux/log2.h
4048     @@ -173,7 +173,7 @@ unsigned long __rounddown_pow_of_two(unsigned long n)
4049     #define roundup_pow_of_two(n) \
4050     ( \
4051     __builtin_constant_p(n) ? ( \
4052     - (n == 1) ? 1 : \
4053     + ((n) == 1) ? 1 : \
4054     (1UL << (ilog2((n) - 1) + 1)) \
4055     ) : \
4056     __roundup_pow_of_two(n) \
4057     diff --git a/include/linux/netfilter/nfnetlink.h b/include/linux/netfilter/nfnetlink.h
4058     index 851425c3178f1..89016d08f6a27 100644
4059     --- a/include/linux/netfilter/nfnetlink.h
4060     +++ b/include/linux/netfilter/nfnetlink.h
4061     @@ -43,8 +43,7 @@ int nfnetlink_has_listeners(struct net *net, unsigned int group);
4062     int nfnetlink_send(struct sk_buff *skb, struct net *net, u32 portid,
4063     unsigned int group, int echo, gfp_t flags);
4064     int nfnetlink_set_err(struct net *net, u32 portid, u32 group, int error);
4065     -int nfnetlink_unicast(struct sk_buff *skb, struct net *net, u32 portid,
4066     - int flags);
4067     +int nfnetlink_unicast(struct sk_buff *skb, struct net *net, u32 portid);
4068    
4069     static inline u16 nfnl_msg_type(u8 subsys, u8 msg_type)
4070     {
4071     diff --git a/include/net/af_rxrpc.h b/include/net/af_rxrpc.h
4072     index ab988940bf045..55b980b21f4b4 100644
4073     --- a/include/net/af_rxrpc.h
4074     +++ b/include/net/af_rxrpc.h
4075     @@ -59,7 +59,7 @@ bool rxrpc_kernel_abort_call(struct socket *, struct rxrpc_call *,
4076     void rxrpc_kernel_end_call(struct socket *, struct rxrpc_call *);
4077     void rxrpc_kernel_get_peer(struct socket *, struct rxrpc_call *,
4078     struct sockaddr_rxrpc *);
4079     -u32 rxrpc_kernel_get_srtt(struct socket *, struct rxrpc_call *);
4080     +bool rxrpc_kernel_get_srtt(struct socket *, struct rxrpc_call *, u32 *);
4081     int rxrpc_kernel_charge_accept(struct socket *, rxrpc_notify_rx_t,
4082     rxrpc_user_attach_call_t, unsigned long, gfp_t,
4083     unsigned int);
4084     diff --git a/include/net/netfilter/nf_tables.h b/include/net/netfilter/nf_tables.h
4085     index 2d0275f13bbfd..bc2c73f549622 100644
4086     --- a/include/net/netfilter/nf_tables.h
4087     +++ b/include/net/netfilter/nf_tables.h
4088     @@ -143,6 +143,8 @@ static inline u64 nft_reg_load64(u32 *sreg)
4089     static inline void nft_data_copy(u32 *dst, const struct nft_data *src,
4090     unsigned int len)
4091     {
4092     + if (len % NFT_REG32_SIZE)
4093     + dst[len / NFT_REG32_SIZE] = 0;
4094     memcpy(dst, src, len);
4095     }
4096    
4097     diff --git a/include/uapi/linux/netfilter/nf_tables.h b/include/uapi/linux/netfilter/nf_tables.h
4098     index ed8881ad18edd..0a995403172cc 100644
4099     --- a/include/uapi/linux/netfilter/nf_tables.h
4100     +++ b/include/uapi/linux/netfilter/nf_tables.h
4101     @@ -132,7 +132,7 @@ enum nf_tables_msg_types {
4102     * @NFTA_LIST_ELEM: list element (NLA_NESTED)
4103     */
4104     enum nft_list_attributes {
4105     - NFTA_LIST_UNPEC,
4106     + NFTA_LIST_UNSPEC,
4107     NFTA_LIST_ELEM,
4108     __NFTA_LIST_MAX
4109     };
4110     diff --git a/mm/hugetlb.c b/mm/hugetlb.c
4111     index 2a83b03c54a69..62ec514dae658 100644
4112     --- a/mm/hugetlb.c
4113     +++ b/mm/hugetlb.c
4114     @@ -3082,6 +3082,22 @@ static unsigned int cpuset_mems_nr(unsigned int *array)
4115     }
4116    
4117     #ifdef CONFIG_SYSCTL
4118     +static int proc_hugetlb_doulongvec_minmax(struct ctl_table *table, int write,
4119     + void *buffer, size_t *length,
4120     + loff_t *ppos, unsigned long *out)
4121     +{
4122     + struct ctl_table dup_table;
4123     +
4124     + /*
4125     + * In order to avoid races with __do_proc_doulongvec_minmax(), we
4126     + * can duplicate the @table and alter the duplicate of it.
4127     + */
4128     + dup_table = *table;
4129     + dup_table.data = out;
4130     +
4131     + return proc_doulongvec_minmax(&dup_table, write, buffer, length, ppos);
4132     +}
4133     +
4134     static int hugetlb_sysctl_handler_common(bool obey_mempolicy,
4135     struct ctl_table *table, int write,
4136     void __user *buffer, size_t *length, loff_t *ppos)
4137     @@ -3093,9 +3109,8 @@ static int hugetlb_sysctl_handler_common(bool obey_mempolicy,
4138     if (!hugepages_supported())
4139     return -EOPNOTSUPP;
4140    
4141     - table->data = &tmp;
4142     - table->maxlen = sizeof(unsigned long);
4143     - ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
4144     + ret = proc_hugetlb_doulongvec_minmax(table, write, buffer, length, ppos,
4145     + &tmp);
4146     if (ret)
4147     goto out;
4148    
4149     @@ -3139,9 +3154,8 @@ int hugetlb_overcommit_handler(struct ctl_table *table, int write,
4150     if (write && hstate_is_gigantic(h))
4151     return -EINVAL;
4152    
4153     - table->data = &tmp;
4154     - table->maxlen = sizeof(unsigned long);
4155     - ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
4156     + ret = proc_hugetlb_doulongvec_minmax(table, write, buffer, length, ppos,
4157     + &tmp);
4158     if (ret)
4159     goto out;
4160    
4161     diff --git a/mm/khugepaged.c b/mm/khugepaged.c
4162     index 3623d1c5343f2..9ec618d5ea557 100644
4163     --- a/mm/khugepaged.c
4164     +++ b/mm/khugepaged.c
4165     @@ -1592,7 +1592,7 @@ static void collapse_file(struct mm_struct *mm,
4166     xas_unlock_irq(&xas);
4167     page_cache_sync_readahead(mapping, &file->f_ra,
4168     file, index,
4169     - PAGE_SIZE);
4170     + end - index);
4171     /* drain pagevecs to help isolate_lru_page() */
4172     lru_add_drain();
4173     page = find_lock_page(mapping, index);
4174     diff --git a/mm/madvise.c b/mm/madvise.c
4175     index d8cfc3a0c1534..26f7954865ed9 100644
4176     --- a/mm/madvise.c
4177     +++ b/mm/madvise.c
4178     @@ -288,9 +288,9 @@ static long madvise_willneed(struct vm_area_struct *vma,
4179     */
4180     *prev = NULL; /* tell sys_madvise we drop mmap_sem */
4181     get_file(file);
4182     - up_read(&current->mm->mmap_sem);
4183     offset = (loff_t)(start - vma->vm_start)
4184     + ((loff_t)vma->vm_pgoff << PAGE_SHIFT);
4185     + up_read(&current->mm->mmap_sem);
4186     vfs_fadvise(file, offset, end - start, POSIX_FADV_WILLNEED);
4187     fput(file);
4188     down_read(&current->mm->mmap_sem);
4189     diff --git a/mm/slub.c b/mm/slub.c
4190     index 709e31002504c..822ba07245291 100644
4191     --- a/mm/slub.c
4192     +++ b/mm/slub.c
4193     @@ -645,12 +645,12 @@ static void slab_fix(struct kmem_cache *s, char *fmt, ...)
4194     }
4195    
4196     static bool freelist_corrupted(struct kmem_cache *s, struct page *page,
4197     - void *freelist, void *nextfree)
4198     + void **freelist, void *nextfree)
4199     {
4200     if ((s->flags & SLAB_CONSISTENCY_CHECKS) &&
4201     - !check_valid_pointer(s, page, nextfree)) {
4202     - object_err(s, page, freelist, "Freechain corrupt");
4203     - freelist = NULL;
4204     + !check_valid_pointer(s, page, nextfree) && freelist) {
4205     + object_err(s, page, *freelist, "Freechain corrupt");
4206     + *freelist = NULL;
4207     slab_fix(s, "Isolate corrupted freechain");
4208     return true;
4209     }
4210     @@ -1394,7 +1394,7 @@ static inline void dec_slabs_node(struct kmem_cache *s, int node,
4211     int objects) {}
4212    
4213     static bool freelist_corrupted(struct kmem_cache *s, struct page *page,
4214     - void *freelist, void *nextfree)
4215     + void **freelist, void *nextfree)
4216     {
4217     return false;
4218     }
4219     @@ -2086,7 +2086,7 @@ static void deactivate_slab(struct kmem_cache *s, struct page *page,
4220     * 'freelist' is already corrupted. So isolate all objects
4221     * starting at 'freelist'.
4222     */
4223     - if (freelist_corrupted(s, page, freelist, nextfree))
4224     + if (freelist_corrupted(s, page, &freelist, nextfree))
4225     break;
4226    
4227     do {
4228     diff --git a/net/batman-adv/bat_v_ogm.c b/net/batman-adv/bat_v_ogm.c
4229     index a9e7540c56918..3165f6ff8ee71 100644
4230     --- a/net/batman-adv/bat_v_ogm.c
4231     +++ b/net/batman-adv/bat_v_ogm.c
4232     @@ -878,6 +878,12 @@ static void batadv_v_ogm_process(const struct sk_buff *skb, int ogm_offset,
4233     ntohl(ogm_packet->seqno), ogm_throughput, ogm_packet->ttl,
4234     ogm_packet->version, ntohs(ogm_packet->tvlv_len));
4235    
4236     + if (batadv_is_my_mac(bat_priv, ogm_packet->orig)) {
4237     + batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
4238     + "Drop packet: originator packet from ourself\n");
4239     + return;
4240     + }
4241     +
4242     /* If the throughput metric is 0, immediately drop the packet. No need
4243     * to create orig_node / neigh_node for an unusable route.
4244     */
4245     @@ -1005,11 +1011,6 @@ int batadv_v_ogm_packet_recv(struct sk_buff *skb,
4246     if (batadv_is_my_mac(bat_priv, ethhdr->h_source))
4247     goto free_skb;
4248    
4249     - ogm_packet = (struct batadv_ogm2_packet *)skb->data;
4250     -
4251     - if (batadv_is_my_mac(bat_priv, ogm_packet->orig))
4252     - goto free_skb;
4253     -
4254     batadv_inc_counter(bat_priv, BATADV_CNT_MGMT_RX);
4255     batadv_add_counter(bat_priv, BATADV_CNT_MGMT_RX_BYTES,
4256     skb->len + ETH_HLEN);
4257     diff --git a/net/batman-adv/bridge_loop_avoidance.c b/net/batman-adv/bridge_loop_avoidance.c
4258     index 663a53b6d36e6..5f6309ade1ea1 100644
4259     --- a/net/batman-adv/bridge_loop_avoidance.c
4260     +++ b/net/batman-adv/bridge_loop_avoidance.c
4261     @@ -437,7 +437,10 @@ static void batadv_bla_send_claim(struct batadv_priv *bat_priv, u8 *mac,
4262     batadv_add_counter(bat_priv, BATADV_CNT_RX_BYTES,
4263     skb->len + ETH_HLEN);
4264    
4265     - netif_rx(skb);
4266     + if (in_interrupt())
4267     + netif_rx(skb);
4268     + else
4269     + netif_rx_ni(skb);
4270     out:
4271     if (primary_if)
4272     batadv_hardif_put(primary_if);
4273     diff --git a/net/batman-adv/gateway_client.c b/net/batman-adv/gateway_client.c
4274     index 47df4c6789886..89c9097007c3a 100644
4275     --- a/net/batman-adv/gateway_client.c
4276     +++ b/net/batman-adv/gateway_client.c
4277     @@ -703,8 +703,10 @@ batadv_gw_dhcp_recipient_get(struct sk_buff *skb, unsigned int *header_len,
4278    
4279     chaddr_offset = *header_len + BATADV_DHCP_CHADDR_OFFSET;
4280     /* store the client address if the message is going to a client */
4281     - if (ret == BATADV_DHCP_TO_CLIENT &&
4282     - pskb_may_pull(skb, chaddr_offset + ETH_ALEN)) {
4283     + if (ret == BATADV_DHCP_TO_CLIENT) {
4284     + if (!pskb_may_pull(skb, chaddr_offset + ETH_ALEN))
4285     + return BATADV_DHCP_NO;
4286     +
4287     /* check if the DHCP packet carries an Ethernet DHCP */
4288     p = skb->data + *header_len + BATADV_DHCP_HTYPE_OFFSET;
4289     if (*p != BATADV_DHCP_HTYPE_ETHERNET)
4290     diff --git a/net/core/dev.c b/net/core/dev.c
4291     index 25858f1f67cf7..56cd7b83a3829 100644
4292     --- a/net/core/dev.c
4293     +++ b/net/core/dev.c
4294     @@ -5602,12 +5602,13 @@ static void napi_skb_free_stolen_head(struct sk_buff *skb)
4295     kmem_cache_free(skbuff_head_cache, skb);
4296     }
4297    
4298     -static gro_result_t napi_skb_finish(gro_result_t ret, struct sk_buff *skb)
4299     +static gro_result_t napi_skb_finish(struct napi_struct *napi,
4300     + struct sk_buff *skb,
4301     + gro_result_t ret)
4302     {
4303     switch (ret) {
4304     case GRO_NORMAL:
4305     - if (netif_receive_skb_internal(skb))
4306     - ret = GRO_DROP;
4307     + gro_normal_one(napi, skb);
4308     break;
4309    
4310     case GRO_DROP:
4311     @@ -5639,7 +5640,7 @@ gro_result_t napi_gro_receive(struct napi_struct *napi, struct sk_buff *skb)
4312    
4313     skb_gro_reset_offset(skb);
4314    
4315     - ret = napi_skb_finish(dev_gro_receive(napi, skb), skb);
4316     + ret = napi_skb_finish(napi, skb, dev_gro_receive(napi, skb));
4317     trace_napi_gro_receive_exit(ret);
4318    
4319     return ret;
4320     diff --git a/net/netfilter/nf_tables_api.c b/net/netfilter/nf_tables_api.c
4321     index f7129232c8250..2023650c27249 100644
4322     --- a/net/netfilter/nf_tables_api.c
4323     +++ b/net/netfilter/nf_tables_api.c
4324     @@ -744,11 +744,11 @@ static int nf_tables_gettable(struct net *net, struct sock *nlsk,
4325     nlh->nlmsg_seq, NFT_MSG_NEWTABLE, 0,
4326     family, table);
4327     if (err < 0)
4328     - goto err;
4329     + goto err_fill_table_info;
4330    
4331     - return nlmsg_unicast(nlsk, skb2, NETLINK_CB(skb).portid);
4332     + return nfnetlink_unicast(skb2, net, NETLINK_CB(skb).portid);
4333    
4334     -err:
4335     +err_fill_table_info:
4336     kfree_skb(skb2);
4337     return err;
4338     }
4339     @@ -1443,11 +1443,11 @@ static int nf_tables_getchain(struct net *net, struct sock *nlsk,
4340     nlh->nlmsg_seq, NFT_MSG_NEWCHAIN, 0,
4341     family, table, chain);
4342     if (err < 0)
4343     - goto err;
4344     + goto err_fill_chain_info;
4345    
4346     - return nlmsg_unicast(nlsk, skb2, NETLINK_CB(skb).portid);
4347     + return nfnetlink_unicast(skb2, net, NETLINK_CB(skb).portid);
4348    
4349     -err:
4350     +err_fill_chain_info:
4351     kfree_skb(skb2);
4352     return err;
4353     }
4354     @@ -2622,11 +2622,11 @@ static int nf_tables_getrule(struct net *net, struct sock *nlsk,
4355     nlh->nlmsg_seq, NFT_MSG_NEWRULE, 0,
4356     family, table, chain, rule, NULL);
4357     if (err < 0)
4358     - goto err;
4359     + goto err_fill_rule_info;
4360    
4361     - return nlmsg_unicast(nlsk, skb2, NETLINK_CB(skb).portid);
4362     + return nfnetlink_unicast(skb2, net, NETLINK_CB(skb).portid);
4363    
4364     -err:
4365     +err_fill_rule_info:
4366     kfree_skb(skb2);
4367     return err;
4368     }
4369     @@ -3353,7 +3353,8 @@ static int nf_tables_fill_set(struct sk_buff *skb, const struct nft_ctx *ctx,
4370     goto nla_put_failure;
4371     }
4372    
4373     - if (nla_put(skb, NFTA_SET_USERDATA, set->udlen, set->udata))
4374     + if (set->udata &&
4375     + nla_put(skb, NFTA_SET_USERDATA, set->udlen, set->udata))
4376     goto nla_put_failure;
4377    
4378     desc = nla_nest_start_noflag(skb, NFTA_SET_DESC);
4379     @@ -3525,11 +3526,11 @@ static int nf_tables_getset(struct net *net, struct sock *nlsk,
4380    
4381     err = nf_tables_fill_set(skb2, &ctx, set, NFT_MSG_NEWSET, 0);
4382     if (err < 0)
4383     - goto err;
4384     + goto err_fill_set_info;
4385    
4386     - return nlmsg_unicast(nlsk, skb2, NETLINK_CB(skb).portid);
4387     + return nfnetlink_unicast(skb2, net, NETLINK_CB(skb).portid);
4388    
4389     -err:
4390     +err_fill_set_info:
4391     kfree_skb(skb2);
4392     return err;
4393     }
4394     @@ -4304,24 +4305,18 @@ static int nft_get_set_elem(struct nft_ctx *ctx, struct nft_set *set,
4395     err = -ENOMEM;
4396     skb = nlmsg_new(NLMSG_GOODSIZE, GFP_ATOMIC);
4397     if (skb == NULL)
4398     - goto err1;
4399     + return err;
4400    
4401     err = nf_tables_fill_setelem_info(skb, ctx, ctx->seq, ctx->portid,
4402     NFT_MSG_NEWSETELEM, 0, set, &elem);
4403     if (err < 0)
4404     - goto err2;
4405     + goto err_fill_setelem;
4406    
4407     - err = nfnetlink_unicast(skb, ctx->net, ctx->portid, MSG_DONTWAIT);
4408     - /* This avoids a loop in nfnetlink. */
4409     - if (err < 0)
4410     - goto err1;
4411     + return nfnetlink_unicast(skb, ctx->net, ctx->portid);
4412    
4413     - return 0;
4414     -err2:
4415     +err_fill_setelem:
4416     kfree_skb(skb);
4417     -err1:
4418     - /* this avoids a loop in nfnetlink. */
4419     - return err == -EAGAIN ? -ENOBUFS : err;
4420     + return err;
4421     }
4422    
4423     /* called with rcu_read_lock held */
4424     @@ -5498,10 +5493,11 @@ static int nf_tables_getobj(struct net *net, struct sock *nlsk,
4425     nlh->nlmsg_seq, NFT_MSG_NEWOBJ, 0,
4426     family, table, obj, reset);
4427     if (err < 0)
4428     - goto err;
4429     + goto err_fill_obj_info;
4430    
4431     - return nlmsg_unicast(nlsk, skb2, NETLINK_CB(skb).portid);
4432     -err:
4433     + return nfnetlink_unicast(skb2, net, NETLINK_CB(skb).portid);
4434     +
4435     +err_fill_obj_info:
4436     kfree_skb(skb2);
4437     return err;
4438     }
4439     @@ -6173,10 +6169,11 @@ static int nf_tables_getflowtable(struct net *net, struct sock *nlsk,
4440     NFT_MSG_NEWFLOWTABLE, 0, family,
4441     flowtable);
4442     if (err < 0)
4443     - goto err;
4444     + goto err_fill_flowtable_info;
4445    
4446     - return nlmsg_unicast(nlsk, skb2, NETLINK_CB(skb).portid);
4447     -err:
4448     + return nfnetlink_unicast(skb2, net, NETLINK_CB(skb).portid);
4449     +
4450     +err_fill_flowtable_info:
4451     kfree_skb(skb2);
4452     return err;
4453     }
4454     @@ -6337,10 +6334,11 @@ static int nf_tables_getgen(struct net *net, struct sock *nlsk,
4455     err = nf_tables_fill_gen_info(skb2, net, NETLINK_CB(skb).portid,
4456     nlh->nlmsg_seq);
4457     if (err < 0)
4458     - goto err;
4459     + goto err_fill_gen_info;
4460    
4461     - return nlmsg_unicast(nlsk, skb2, NETLINK_CB(skb).portid);
4462     -err:
4463     + return nfnetlink_unicast(skb2, net, NETLINK_CB(skb).portid);
4464     +
4465     +err_fill_gen_info:
4466     kfree_skb(skb2);
4467     return err;
4468     }
4469     diff --git a/net/netfilter/nfnetlink.c b/net/netfilter/nfnetlink.c
4470     index 99127e2d95a84..6d03b09096210 100644
4471     --- a/net/netfilter/nfnetlink.c
4472     +++ b/net/netfilter/nfnetlink.c
4473     @@ -148,10 +148,15 @@ int nfnetlink_set_err(struct net *net, u32 portid, u32 group, int error)
4474     }
4475     EXPORT_SYMBOL_GPL(nfnetlink_set_err);
4476    
4477     -int nfnetlink_unicast(struct sk_buff *skb, struct net *net, u32 portid,
4478     - int flags)
4479     +int nfnetlink_unicast(struct sk_buff *skb, struct net *net, u32 portid)
4480     {
4481     - return netlink_unicast(net->nfnl, skb, portid, flags);
4482     + int err;
4483     +
4484     + err = nlmsg_unicast(net->nfnl, skb, portid);
4485     + if (err == -EAGAIN)
4486     + err = -ENOBUFS;
4487     +
4488     + return err;
4489     }
4490     EXPORT_SYMBOL_GPL(nfnetlink_unicast);
4491    
4492     diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
4493     index 0ba020ca38e68..7ca2ca4bba055 100644
4494     --- a/net/netfilter/nfnetlink_log.c
4495     +++ b/net/netfilter/nfnetlink_log.c
4496     @@ -356,8 +356,7 @@ __nfulnl_send(struct nfulnl_instance *inst)
4497     goto out;
4498     }
4499     }
4500     - nfnetlink_unicast(inst->skb, inst->net, inst->peer_portid,
4501     - MSG_DONTWAIT);
4502     + nfnetlink_unicast(inst->skb, inst->net, inst->peer_portid);
4503     out:
4504     inst->qlen = 0;
4505     inst->skb = NULL;
4506     diff --git a/net/netfilter/nfnetlink_queue.c b/net/netfilter/nfnetlink_queue.c
4507     index feabdfb22920b..6f0a2bad8ad5e 100644
4508     --- a/net/netfilter/nfnetlink_queue.c
4509     +++ b/net/netfilter/nfnetlink_queue.c
4510     @@ -681,7 +681,7 @@ __nfqnl_enqueue_packet(struct net *net, struct nfqnl_instance *queue,
4511     *packet_id_ptr = htonl(entry->id);
4512    
4513     /* nfnetlink_unicast will either free the nskb or add it to a socket */
4514     - err = nfnetlink_unicast(nskb, net, queue->peer_portid, MSG_DONTWAIT);
4515     + err = nfnetlink_unicast(nskb, net, queue->peer_portid);
4516     if (err < 0) {
4517     if (queue->flags & NFQA_CFG_F_FAIL_OPEN) {
4518     failopen = 1;
4519     diff --git a/net/netfilter/nft_payload.c b/net/netfilter/nft_payload.c
4520     index 0e3bfbc26e790..62dc728bf93c9 100644
4521     --- a/net/netfilter/nft_payload.c
4522     +++ b/net/netfilter/nft_payload.c
4523     @@ -79,7 +79,9 @@ void nft_payload_eval(const struct nft_expr *expr,
4524     u32 *dest = &regs->data[priv->dreg];
4525     int offset;
4526    
4527     - dest[priv->len / NFT_REG32_SIZE] = 0;
4528     + if (priv->len % NFT_REG32_SIZE)
4529     + dest[priv->len / NFT_REG32_SIZE] = 0;
4530     +
4531     switch (priv->base) {
4532     case NFT_PAYLOAD_LL_HEADER:
4533     if (!skb_mac_header_was_set(skb))
4534     diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
4535     index 7735340c892eb..fbc2d4dfddf0e 100644
4536     --- a/net/packet/af_packet.c
4537     +++ b/net/packet/af_packet.c
4538     @@ -2169,7 +2169,8 @@ static int tpacket_rcv(struct sk_buff *skb, struct net_device *dev,
4539     int skb_len = skb->len;
4540     unsigned int snaplen, res;
4541     unsigned long status = TP_STATUS_USER;
4542     - unsigned short macoff, netoff, hdrlen;
4543     + unsigned short macoff, hdrlen;
4544     + unsigned int netoff;
4545     struct sk_buff *copy_skb = NULL;
4546     struct timespec ts;
4547     __u32 ts_status;
4548     @@ -2238,6 +2239,10 @@ static int tpacket_rcv(struct sk_buff *skb, struct net_device *dev,
4549     }
4550     macoff = netoff - maclen;
4551     }
4552     + if (netoff > USHRT_MAX) {
4553     + atomic_inc(&po->tp_drops);
4554     + goto drop_n_restore;
4555     + }
4556     if (po->tp_version <= TPACKET_V2) {
4557     if (macoff + snaplen > po->rx_ring.frame_size) {
4558     if (po->copy_thresh &&
4559     diff --git a/net/rxrpc/input.c b/net/rxrpc/input.c
4560     index 22dec6049e1bb..6cace43b217ee 100644
4561     --- a/net/rxrpc/input.c
4562     +++ b/net/rxrpc/input.c
4563     @@ -844,7 +844,7 @@ static void rxrpc_input_ack(struct rxrpc_call *call, struct sk_buff *skb)
4564     struct rxrpc_ackinfo info;
4565     u8 acks[RXRPC_MAXACKS];
4566     } buf;
4567     - rxrpc_serial_t acked_serial;
4568     + rxrpc_serial_t ack_serial, acked_serial;
4569     rxrpc_seq_t first_soft_ack, hard_ack, prev_pkt;
4570     int nr_acks, offset, ioffset;
4571    
4572     @@ -857,6 +857,7 @@ static void rxrpc_input_ack(struct rxrpc_call *call, struct sk_buff *skb)
4573     }
4574     offset += sizeof(buf.ack);
4575    
4576     + ack_serial = sp->hdr.serial;
4577     acked_serial = ntohl(buf.ack.serial);
4578     first_soft_ack = ntohl(buf.ack.firstPacket);
4579     prev_pkt = ntohl(buf.ack.previousPacket);
4580     @@ -865,31 +866,31 @@ static void rxrpc_input_ack(struct rxrpc_call *call, struct sk_buff *skb)
4581     summary.ack_reason = (buf.ack.reason < RXRPC_ACK__INVALID ?
4582     buf.ack.reason : RXRPC_ACK__INVALID);
4583    
4584     - trace_rxrpc_rx_ack(call, sp->hdr.serial, acked_serial,
4585     + trace_rxrpc_rx_ack(call, ack_serial, acked_serial,
4586     first_soft_ack, prev_pkt,
4587     summary.ack_reason, nr_acks);
4588    
4589     if (buf.ack.reason == RXRPC_ACK_PING_RESPONSE)
4590     rxrpc_input_ping_response(call, skb->tstamp, acked_serial,
4591     - sp->hdr.serial);
4592     + ack_serial);
4593     if (buf.ack.reason == RXRPC_ACK_REQUESTED)
4594     rxrpc_input_requested_ack(call, skb->tstamp, acked_serial,
4595     - sp->hdr.serial);
4596     + ack_serial);
4597    
4598     if (buf.ack.reason == RXRPC_ACK_PING) {
4599     - _proto("Rx ACK %%%u PING Request", sp->hdr.serial);
4600     + _proto("Rx ACK %%%u PING Request", ack_serial);
4601     rxrpc_propose_ACK(call, RXRPC_ACK_PING_RESPONSE,
4602     - sp->hdr.serial, true, true,
4603     + ack_serial, true, true,
4604     rxrpc_propose_ack_respond_to_ping);
4605     } else if (sp->hdr.flags & RXRPC_REQUEST_ACK) {
4606     rxrpc_propose_ACK(call, RXRPC_ACK_REQUESTED,
4607     - sp->hdr.serial, true, true,
4608     + ack_serial, true, true,
4609     rxrpc_propose_ack_respond_to_ack);
4610     }
4611    
4612     /* Discard any out-of-order or duplicate ACKs (outside lock). */
4613     if (!rxrpc_is_ack_valid(call, first_soft_ack, prev_pkt)) {
4614     - trace_rxrpc_rx_discard_ack(call->debug_id, sp->hdr.serial,
4615     + trace_rxrpc_rx_discard_ack(call->debug_id, ack_serial,
4616     first_soft_ack, call->ackr_first_seq,
4617     prev_pkt, call->ackr_prev_seq);
4618     return;
4619     @@ -905,7 +906,7 @@ static void rxrpc_input_ack(struct rxrpc_call *call, struct sk_buff *skb)
4620    
4621     /* Discard any out-of-order or duplicate ACKs (inside lock). */
4622     if (!rxrpc_is_ack_valid(call, first_soft_ack, prev_pkt)) {
4623     - trace_rxrpc_rx_discard_ack(call->debug_id, sp->hdr.serial,
4624     + trace_rxrpc_rx_discard_ack(call->debug_id, ack_serial,
4625     first_soft_ack, call->ackr_first_seq,
4626     prev_pkt, call->ackr_prev_seq);
4627     goto out;
4628     @@ -965,7 +966,7 @@ static void rxrpc_input_ack(struct rxrpc_call *call, struct sk_buff *skb)
4629     RXRPC_TX_ANNO_LAST &&
4630     summary.nr_acks == call->tx_top - hard_ack &&
4631     rxrpc_is_client_call(call))
4632     - rxrpc_propose_ACK(call, RXRPC_ACK_PING, sp->hdr.serial,
4633     + rxrpc_propose_ACK(call, RXRPC_ACK_PING, ack_serial,
4634     false, true,
4635     rxrpc_propose_ack_ping_for_lost_reply);
4636    
4637     diff --git a/net/rxrpc/peer_object.c b/net/rxrpc/peer_object.c
4638     index efce27802a74f..e011594adcd13 100644
4639     --- a/net/rxrpc/peer_object.c
4640     +++ b/net/rxrpc/peer_object.c
4641     @@ -500,11 +500,21 @@ EXPORT_SYMBOL(rxrpc_kernel_get_peer);
4642     * rxrpc_kernel_get_srtt - Get a call's peer smoothed RTT
4643     * @sock: The socket on which the call is in progress.
4644     * @call: The call to query
4645     + * @_srtt: Where to store the SRTT value.
4646     *
4647     - * Get the call's peer smoothed RTT.
4648     + * Get the call's peer smoothed RTT in uS.
4649     */
4650     -u32 rxrpc_kernel_get_srtt(struct socket *sock, struct rxrpc_call *call)
4651     +bool rxrpc_kernel_get_srtt(struct socket *sock, struct rxrpc_call *call,
4652     + u32 *_srtt)
4653     {
4654     - return call->peer->srtt_us >> 3;
4655     + struct rxrpc_peer *peer = call->peer;
4656     +
4657     + if (peer->rtt_count == 0) {
4658     + *_srtt = 1000000; /* 1S */
4659     + return false;
4660     + }
4661     +
4662     + *_srtt = call->peer->srtt_us >> 3;
4663     + return true;
4664     }
4665     EXPORT_SYMBOL(rxrpc_kernel_get_srtt);
4666     diff --git a/net/wireless/reg.c b/net/wireless/reg.c
4667     index 1a8218f1bbe07..20a8e6af88c45 100644
4668     --- a/net/wireless/reg.c
4669     +++ b/net/wireless/reg.c
4670     @@ -2941,6 +2941,9 @@ int regulatory_hint_user(const char *alpha2,
4671     if (WARN_ON(!alpha2))
4672     return -EINVAL;
4673    
4674     + if (!is_world_regdom(alpha2) && !is_an_alpha2(alpha2))
4675     + return -EINVAL;
4676     +
4677     request = kzalloc(sizeof(struct regulatory_request), GFP_KERNEL);
4678     if (!request)
4679     return -ENOMEM;
4680     diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
4681     index 6fcc66afb0880..0c9b114202796 100755
4682     --- a/scripts/checkpatch.pl
4683     +++ b/scripts/checkpatch.pl
4684     @@ -2576,8 +2576,8 @@ sub process {
4685    
4686     # Check if the commit log has what seems like a diff which can confuse patch
4687     if ($in_commit_log && !$commit_log_has_diff &&
4688     - (($line =~ m@^\s+diff\b.*a/[\w/]+@ &&
4689     - $line =~ m@^\s+diff\b.*a/([\w/]+)\s+b/$1\b@) ||
4690     + (($line =~ m@^\s+diff\b.*a/([\w/]+)@ &&
4691     + $line =~ m@^\s+diff\b.*a/[\w/]+\s+b/$1\b@) ||
4692     $line =~ m@^\s*(?:\-\-\-\s+a/|\+\+\+\s+b/)@ ||
4693     $line =~ m/^\s*\@\@ \-\d+,\d+ \+\d+,\d+ \@\@/)) {
4694     ERROR("DIFF_IN_COMMIT_MSG",
4695     diff --git a/sound/core/oss/mulaw.c b/sound/core/oss/mulaw.c
4696     index 3788906421a73..fe27034f28460 100644
4697     --- a/sound/core/oss/mulaw.c
4698     +++ b/sound/core/oss/mulaw.c
4699     @@ -329,8 +329,8 @@ int snd_pcm_plugin_build_mulaw(struct snd_pcm_substream *plug,
4700     snd_BUG();
4701     return -EINVAL;
4702     }
4703     - if (snd_BUG_ON(!snd_pcm_format_linear(format->format)))
4704     - return -ENXIO;
4705     + if (!snd_pcm_format_linear(format->format))
4706     + return -EINVAL;
4707    
4708     err = snd_pcm_plugin_build(plug, "Mu-Law<->linear conversion",
4709     src_format, dst_format,
4710     diff --git a/sound/firewire/digi00x/digi00x.c b/sound/firewire/digi00x/digi00x.c
4711     index 1f5fc0e7c0243..0e4b0eac30159 100644
4712     --- a/sound/firewire/digi00x/digi00x.c
4713     +++ b/sound/firewire/digi00x/digi00x.c
4714     @@ -14,6 +14,7 @@ MODULE_LICENSE("GPL v2");
4715     #define VENDOR_DIGIDESIGN 0x00a07e
4716     #define MODEL_CONSOLE 0x000001
4717     #define MODEL_RACK 0x000002
4718     +#define SPEC_VERSION 0x000001
4719    
4720     static int name_card(struct snd_dg00x *dg00x)
4721     {
4722     @@ -175,14 +176,18 @@ static const struct ieee1394_device_id snd_dg00x_id_table[] = {
4723     /* Both of 002/003 use the same ID. */
4724     {
4725     .match_flags = IEEE1394_MATCH_VENDOR_ID |
4726     + IEEE1394_MATCH_VERSION |
4727     IEEE1394_MATCH_MODEL_ID,
4728     .vendor_id = VENDOR_DIGIDESIGN,
4729     + .version = SPEC_VERSION,
4730     .model_id = MODEL_CONSOLE,
4731     },
4732     {
4733     .match_flags = IEEE1394_MATCH_VENDOR_ID |
4734     + IEEE1394_MATCH_VERSION |
4735     IEEE1394_MATCH_MODEL_ID,
4736     .vendor_id = VENDOR_DIGIDESIGN,
4737     + .version = SPEC_VERSION,
4738     .model_id = MODEL_RACK,
4739     },
4740     {}
4741     diff --git a/sound/firewire/tascam/tascam.c b/sound/firewire/tascam/tascam.c
4742     index addc464503bcf..0175e3e835ead 100644
4743     --- a/sound/firewire/tascam/tascam.c
4744     +++ b/sound/firewire/tascam/tascam.c
4745     @@ -39,9 +39,6 @@ static const struct snd_tscm_spec model_specs[] = {
4746     .midi_capture_ports = 2,
4747     .midi_playback_ports = 4,
4748     },
4749     - // This kernel module doesn't support FE-8 because the most of features
4750     - // can be implemented in userspace without any specific support of this
4751     - // module.
4752     };
4753    
4754     static int identify_model(struct snd_tscm *tscm)
4755     @@ -211,11 +208,39 @@ static void snd_tscm_remove(struct fw_unit *unit)
4756     }
4757    
4758     static const struct ieee1394_device_id snd_tscm_id_table[] = {
4759     + // Tascam, FW-1884.
4760     + {
4761     + .match_flags = IEEE1394_MATCH_VENDOR_ID |
4762     + IEEE1394_MATCH_SPECIFIER_ID |
4763     + IEEE1394_MATCH_VERSION,
4764     + .vendor_id = 0x00022e,
4765     + .specifier_id = 0x00022e,
4766     + .version = 0x800000,
4767     + },
4768     + // Tascam, FE-8 (.version = 0x800001)
4769     + // This kernel module doesn't support FE-8 because the most of features
4770     + // can be implemented in userspace without any specific support of this
4771     + // module.
4772     + //
4773     + // .version = 0x800002 is unknown.
4774     + //
4775     + // Tascam, FW-1082.
4776     + {
4777     + .match_flags = IEEE1394_MATCH_VENDOR_ID |
4778     + IEEE1394_MATCH_SPECIFIER_ID |
4779     + IEEE1394_MATCH_VERSION,
4780     + .vendor_id = 0x00022e,
4781     + .specifier_id = 0x00022e,
4782     + .version = 0x800003,
4783     + },
4784     + // Tascam, FW-1804.
4785     {
4786     .match_flags = IEEE1394_MATCH_VENDOR_ID |
4787     - IEEE1394_MATCH_SPECIFIER_ID,
4788     + IEEE1394_MATCH_SPECIFIER_ID |
4789     + IEEE1394_MATCH_VERSION,
4790     .vendor_id = 0x00022e,
4791     .specifier_id = 0x00022e,
4792     + .version = 0x800004,
4793     },
4794     {}
4795     };
4796     diff --git a/sound/pci/ca0106/ca0106_main.c b/sound/pci/ca0106/ca0106_main.c
4797     index 478412e0aa3c7..7aedaeb7a1968 100644
4798     --- a/sound/pci/ca0106/ca0106_main.c
4799     +++ b/sound/pci/ca0106/ca0106_main.c
4800     @@ -537,7 +537,8 @@ static int snd_ca0106_pcm_power_dac(struct snd_ca0106 *chip, int channel_id,
4801     else
4802     /* Power down */
4803     chip->spi_dac_reg[reg] |= bit;
4804     - return snd_ca0106_spi_write(chip, chip->spi_dac_reg[reg]);
4805     + if (snd_ca0106_spi_write(chip, chip->spi_dac_reg[reg]) != 0)
4806     + return -ENXIO;
4807     }
4808     return 0;
4809     }
4810     diff --git a/sound/pci/hda/hda_intel.c b/sound/pci/hda/hda_intel.c
4811     index 3a456410937b5..7353d2ec359ae 100644
4812     --- a/sound/pci/hda/hda_intel.c
4813     +++ b/sound/pci/hda/hda_intel.c
4814     @@ -2671,8 +2671,6 @@ static const struct pci_device_id azx_ids[] = {
4815     .driver_data = AZX_DRIVER_GENERIC | AZX_DCAPS_PRESET_ATI_HDMI },
4816     /* Zhaoxin */
4817     { PCI_DEVICE(0x1d17, 0x3288), .driver_data = AZX_DRIVER_ZHAOXIN },
4818     - /* Loongson */
4819     - { PCI_DEVICE(0x0014, 0x7a07), .driver_data = AZX_DRIVER_GENERIC },
4820     { 0, }
4821     };
4822     MODULE_DEVICE_TABLE(pci, azx_ids);
4823     diff --git a/sound/pci/hda/patch_hdmi.c b/sound/pci/hda/patch_hdmi.c
4824     index ec9460f3a288e..a13bad262598d 100644
4825     --- a/sound/pci/hda/patch_hdmi.c
4826     +++ b/sound/pci/hda/patch_hdmi.c
4827     @@ -2798,6 +2798,7 @@ static void i915_pin_cvt_fixup(struct hda_codec *codec,
4828     hda_nid_t cvt_nid)
4829     {
4830     if (per_pin) {
4831     + haswell_verify_D0(codec, per_pin->cvt_nid, per_pin->pin_nid);
4832     snd_hda_set_dev_select(codec, per_pin->pin_nid,
4833     per_pin->dev_id);
4834     intel_verify_pin_cvt_connect(codec, per_pin);
4835     diff --git a/sound/pci/hda/patch_realtek.c b/sound/pci/hda/patch_realtek.c
4836     index d1b74c7cacd76..d614090dae49d 100644
4837     --- a/sound/pci/hda/patch_realtek.c
4838     +++ b/sound/pci/hda/patch_realtek.c
4839     @@ -2466,6 +2466,7 @@ static const struct snd_pci_quirk alc882_fixup_tbl[] = {
4840     SND_PCI_QUIRK(0x1462, 0x1276, "MSI-GL73", ALC1220_FIXUP_CLEVO_P950),
4841     SND_PCI_QUIRK(0x1462, 0x1293, "MSI-GP65", ALC1220_FIXUP_CLEVO_P950),
4842     SND_PCI_QUIRK(0x1462, 0x7350, "MSI-7350", ALC889_FIXUP_CD),
4843     + SND_PCI_QUIRK(0x1462, 0x9c37, "MSI X570-A PRO", ALC1220_FIXUP_CLEVO_P950),
4844     SND_PCI_QUIRK(0x1462, 0xda57, "MSI Z270-Gaming", ALC1220_FIXUP_GB_DUAL_CODECS),
4845     SND_PCI_QUIRK_VENDOR(0x1462, "MSI", ALC882_FIXUP_GPIO3),
4846     SND_PCI_QUIRK(0x147b, 0x107a, "Abit AW9D-MAX", ALC882_FIXUP_ABIT_AW9D_MAX),
4847     @@ -5849,6 +5850,39 @@ static void alc275_fixup_gpio4_off(struct hda_codec *codec,
4848     }
4849     }
4850    
4851     +/* Quirk for Thinkpad X1 7th and 8th Gen
4852     + * The following fixed routing needed
4853     + * DAC1 (NID 0x02) -> Speaker (NID 0x14); some eq applied secretly
4854     + * DAC2 (NID 0x03) -> Bass (NID 0x17) & Headphone (NID 0x21); sharing a DAC
4855     + * DAC3 (NID 0x06) -> Unused, due to the lack of volume amp
4856     + */
4857     +static void alc285_fixup_thinkpad_x1_gen7(struct hda_codec *codec,
4858     + const struct hda_fixup *fix, int action)
4859     +{
4860     + static const hda_nid_t conn[] = { 0x02, 0x03 }; /* exclude 0x06 */
4861     + static const hda_nid_t preferred_pairs[] = {
4862     + 0x14, 0x02, 0x17, 0x03, 0x21, 0x03, 0
4863     + };
4864     + struct alc_spec *spec = codec->spec;
4865     +
4866     + switch (action) {
4867     + case HDA_FIXUP_ACT_PRE_PROBE:
4868     + snd_hda_override_conn_list(codec, 0x17, ARRAY_SIZE(conn), conn);
4869     + spec->gen.preferred_dacs = preferred_pairs;
4870     + break;
4871     + case HDA_FIXUP_ACT_BUILD:
4872     + /* The generic parser creates somewhat unintuitive volume ctls
4873     + * with the fixed routing above, and the shared DAC2 may be
4874     + * confusing for PA.
4875     + * Rename those to unique names so that PA doesn't touch them
4876     + * and use only Master volume.
4877     + */
4878     + rename_ctl(codec, "Front Playback Volume", "DAC1 Playback Volume");
4879     + rename_ctl(codec, "Bass Speaker Playback Volume", "DAC2 Playback Volume");
4880     + break;
4881     + }
4882     +}
4883     +
4884     static void alc233_alc662_fixup_lenovo_dual_codecs(struct hda_codec *codec,
4885     const struct hda_fixup *fix,
4886     int action)
4887     @@ -6117,6 +6151,7 @@ enum {
4888     ALC289_FIXUP_DUAL_SPK,
4889     ALC294_FIXUP_SPK2_TO_DAC1,
4890     ALC294_FIXUP_ASUS_DUAL_SPK,
4891     + ALC285_FIXUP_THINKPAD_X1_GEN7,
4892     ALC285_FIXUP_THINKPAD_HEADSET_JACK,
4893     ALC294_FIXUP_ASUS_HPE,
4894     ALC294_FIXUP_ASUS_COEF_1B,
4895     @@ -7262,11 +7297,17 @@ static const struct hda_fixup alc269_fixups[] = {
4896     .chained = true,
4897     .chain_id = ALC294_FIXUP_SPK2_TO_DAC1
4898     },
4899     + [ALC285_FIXUP_THINKPAD_X1_GEN7] = {
4900     + .type = HDA_FIXUP_FUNC,
4901     + .v.func = alc285_fixup_thinkpad_x1_gen7,
4902     + .chained = true,
4903     + .chain_id = ALC269_FIXUP_THINKPAD_ACPI
4904     + },
4905     [ALC285_FIXUP_THINKPAD_HEADSET_JACK] = {
4906     .type = HDA_FIXUP_FUNC,
4907     .v.func = alc_fixup_headset_jack,
4908     .chained = true,
4909     - .chain_id = ALC285_FIXUP_SPEAKER2_TO_DAC1
4910     + .chain_id = ALC285_FIXUP_THINKPAD_X1_GEN7
4911     },
4912     [ALC294_FIXUP_ASUS_HPE] = {
4913     .type = HDA_FIXUP_VERBS,
4914     @@ -7677,7 +7718,8 @@ static const struct snd_pci_quirk alc269_fixup_tbl[] = {
4915     SND_PCI_QUIRK(0x144d, 0xc169, "Samsung Notebook 9 Pen (NP930SBE-K01US)", ALC298_FIXUP_SAMSUNG_HEADPHONE_VERY_QUIET),
4916     SND_PCI_QUIRK(0x144d, 0xc176, "Samsung Notebook 9 Pro (NP930MBE-K04US)", ALC298_FIXUP_SAMSUNG_HEADPHONE_VERY_QUIET),
4917     SND_PCI_QUIRK(0x144d, 0xc189, "Samsung Galaxy Flex Book (NT950QCG-X716)", ALC298_FIXUP_SAMSUNG_HEADPHONE_VERY_QUIET),
4918     - SND_PCI_QUIRK(0x144d, 0xc18a, "Samsung Galaxy Book Ion (NT950XCJ-X716A)", ALC298_FIXUP_SAMSUNG_HEADPHONE_VERY_QUIET),
4919     + SND_PCI_QUIRK(0x144d, 0xc18a, "Samsung Galaxy Book Ion (NP930XCJ-K01US)", ALC298_FIXUP_SAMSUNG_HEADPHONE_VERY_QUIET),
4920     + SND_PCI_QUIRK(0x144d, 0xc830, "Samsung Galaxy Book Ion (NT950XCJ-X716A)", ALC298_FIXUP_SAMSUNG_HEADPHONE_VERY_QUIET),
4921     SND_PCI_QUIRK(0x144d, 0xc740, "Samsung Ativ book 8 (NP870Z5G)", ALC269_FIXUP_ATIV_BOOK_8),
4922     SND_PCI_QUIRK(0x144d, 0xc812, "Samsung Notebook Pen S (NT950SBE-X58)", ALC298_FIXUP_SAMSUNG_HEADPHONE_VERY_QUIET),
4923     SND_PCI_QUIRK(0x1458, 0xfa53, "Gigabyte BXBT-2807", ALC283_FIXUP_HEADSET_MIC),
4924     diff --git a/sound/usb/pcm.c b/sound/usb/pcm.c
4925     index 7b41f97489788..878f1201aad6e 100644
4926     --- a/sound/usb/pcm.c
4927     +++ b/sound/usb/pcm.c
4928     @@ -356,6 +356,7 @@ static int set_sync_ep_implicit_fb_quirk(struct snd_usb_substream *subs,
4929     case USB_ID(0x07fd, 0x0008): /* MOTU M Series */
4930     case USB_ID(0x31e9, 0x0001): /* Solid State Logic SSL2 */
4931     case USB_ID(0x31e9, 0x0002): /* Solid State Logic SSL2+ */
4932     + case USB_ID(0x0499, 0x172f): /* Steinberg UR22C */
4933     case USB_ID(0x0d9a, 0x00df): /* RTX6001 */
4934     ep = 0x81;
4935     ifnum = 2;
4936     diff --git a/tools/include/uapi/linux/perf_event.h b/tools/include/uapi/linux/perf_event.h
4937     index bb7b271397a66..fabe5aeaa351a 100644
4938     --- a/tools/include/uapi/linux/perf_event.h
4939     +++ b/tools/include/uapi/linux/perf_event.h
4940     @@ -1131,7 +1131,7 @@ union perf_mem_data_src {
4941    
4942     #define PERF_MEM_SNOOPX_FWD 0x01 /* forward */
4943     /* 1 free */
4944     -#define PERF_MEM_SNOOPX_SHIFT 37
4945     +#define PERF_MEM_SNOOPX_SHIFT 38
4946    
4947     /* locked instruction */
4948     #define PERF_MEM_LOCK_NA 0x01 /* not available */
4949     diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
4950     index 23332861de6e4..454e275cd5dff 100644
4951     --- a/tools/perf/builtin-record.c
4952     +++ b/tools/perf/builtin-record.c
4953     @@ -2137,7 +2137,7 @@ static struct option __record_options[] = {
4954     OPT_BOOLEAN(0, "tail-synthesize", &record.opts.tail_synthesize,
4955     "synthesize non-sample events at the end of output"),
4956     OPT_BOOLEAN(0, "overwrite", &record.opts.overwrite, "use overwrite mode"),
4957     - OPT_BOOLEAN(0, "no-bpf-event", &record.opts.no_bpf_event, "record bpf events"),
4958     + OPT_BOOLEAN(0, "no-bpf-event", &record.opts.no_bpf_event, "do not record bpf events"),
4959     OPT_BOOLEAN(0, "strict-freq", &record.opts.strict_freq,
4960     "Fail if the specified frequency can't be used"),
4961     OPT_CALLBACK('F', "freq", &record.opts, "freq or 'max'",
4962     diff --git a/tools/perf/pmu-events/jevents.c b/tools/perf/pmu-events/jevents.c
4963     index 99e3fd04a5cb3..d36ae65ae3330 100644
4964     --- a/tools/perf/pmu-events/jevents.c
4965     +++ b/tools/perf/pmu-events/jevents.c
4966     @@ -137,7 +137,7 @@ static char *fixregex(char *s)
4967     return s;
4968    
4969     /* allocate space for a new string */
4970     - fixed = (char *) malloc(len + 1);
4971     + fixed = (char *) malloc(len + esc_count + 1);
4972     if (!fixed)
4973     return NULL;
4974    
4975     diff --git a/tools/testing/selftests/bpf/test_maps.c b/tools/testing/selftests/bpf/test_maps.c
4976     index c812f0178b643..1c4219ceced2f 100644
4977     --- a/tools/testing/selftests/bpf/test_maps.c
4978     +++ b/tools/testing/selftests/bpf/test_maps.c
4979     @@ -1282,6 +1282,8 @@ static void __run_parallel(unsigned int tasks,
4980     pid_t pid[tasks];
4981     int i;
4982    
4983     + fflush(stdout);
4984     +
4985     for (i = 0; i < tasks; i++) {
4986     pid[i] = fork();
4987     if (pid[i] == 0) {