Gentoo Archives: gentoo-commits

From: Mike Pagano <mpagano@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/linux-patches:4.14 commit in: /
Date: Wed, 31 Jul 2019 10:23:28
Message-Id: 1564568588.7619187f72986c8c9bc60d3df750c0ae0dca67ea.mpagano@gentoo
1 commit: 7619187f72986c8c9bc60d3df750c0ae0dca67ea
2 Author: Mike Pagano <mpagano <AT> gentoo <DOT> org>
3 AuthorDate: Wed Jul 31 10:23:08 2019 +0000
4 Commit: Mike Pagano <mpagano <AT> gentoo <DOT> org>
5 CommitDate: Wed Jul 31 10:23:08 2019 +0000
6 URL: https://gitweb.gentoo.org/proj/linux-patches.git/commit/?id=7619187f
7
8 Linux patch 4.14.135
9
10 Signed-off-by: Mike Pagano <mpagano <AT> gentoo.org>
11
12 0000_README | 4 +
13 1134_linux-4.14.135.patch | 13831 ++++++++++++++++++++++++++++++++++++++++++++
14 2 files changed, 13835 insertions(+)
15
16 diff --git a/0000_README b/0000_README
17 index befc228..675e99c 100644
18 --- a/0000_README
19 +++ b/0000_README
20 @@ -579,6 +579,10 @@ Patch: 1133_linux-4.14.134.patch
21 From: https://www.kernel.org
22 Desc: Linux 4.14.134
23
24 +Patch: 1134_linux-4.14.135.patch
25 +From: https://www.kernel.org
26 +Desc: Linux 4.14.135
27 +
28 Patch: 1500_XATTR_USER_PREFIX.patch
29 From: https://bugs.gentoo.org/show_bug.cgi?id=470644
30 Desc: Support for namespace user.pax.* on tmpfs.
31
32 diff --git a/1134_linux-4.14.135.patch b/1134_linux-4.14.135.patch
33 new file mode 100644
34 index 0000000..74f80ff
35 --- /dev/null
36 +++ b/1134_linux-4.14.135.patch
37 @@ -0,0 +1,13831 @@
38 +diff --git a/Documentation/atomic_t.txt b/Documentation/atomic_t.txt
39 +index 913396ac5824..ed0d814df7e0 100644
40 +--- a/Documentation/atomic_t.txt
41 ++++ b/Documentation/atomic_t.txt
42 +@@ -177,6 +177,9 @@ These helper barriers exist because architectures have varying implicit
43 + ordering on their SMP atomic primitives. For example our TSO architectures
44 + provide full ordered atomics and these barriers are no-ops.
45 +
46 ++NOTE: when the atomic RmW ops are fully ordered, they should also imply a
47 ++compiler barrier.
48 ++
49 + Thus:
50 +
51 + atomic_fetch_add();
52 +diff --git a/Documentation/devicetree/bindings/net/marvell-orion-mdio.txt b/Documentation/devicetree/bindings/net/marvell-orion-mdio.txt
53 +index 42cd81090a2c..3f3cfc1d8d4d 100644
54 +--- a/Documentation/devicetree/bindings/net/marvell-orion-mdio.txt
55 ++++ b/Documentation/devicetree/bindings/net/marvell-orion-mdio.txt
56 +@@ -16,7 +16,7 @@ Required properties:
57 +
58 + Optional properties:
59 + - interrupts: interrupt line number for the SMI error/done interrupt
60 +-- clocks: phandle for up to three required clocks for the MDIO instance
61 ++- clocks: phandle for up to four required clocks for the MDIO instance
62 +
63 + The child nodes of the MDIO driver are the individual PHY devices
64 + connected to this MDIO bus. They must have a "reg" property given the
65 +diff --git a/Makefile b/Makefile
66 +index 97c744513af0..57825473c031 100644
67 +--- a/Makefile
68 ++++ b/Makefile
69 +@@ -1,7 +1,7 @@
70 + # SPDX-License-Identifier: GPL-2.0
71 + VERSION = 4
72 + PATCHLEVEL = 14
73 +-SUBLEVEL = 134
74 ++SUBLEVEL = 135
75 + EXTRAVERSION =
76 + NAME = Petit Gorille
77 +
78 +@@ -488,6 +488,7 @@ ifneq ($(GCC_TOOLCHAIN),)
79 + CLANG_FLAGS += --gcc-toolchain=$(GCC_TOOLCHAIN)
80 + endif
81 + CLANG_FLAGS += -no-integrated-as
82 ++CLANG_FLAGS += -Werror=unknown-warning-option
83 + KBUILD_CFLAGS += $(CLANG_FLAGS)
84 + KBUILD_AFLAGS += $(CLANG_FLAGS)
85 + export CLANG_FLAGS
86 +diff --git a/arch/arm64/boot/dts/nvidia/tegra210-p2180.dtsi b/arch/arm64/boot/dts/nvidia/tegra210-p2180.dtsi
87 +index d10d4430537a..f6e6f1e83ba8 100644
88 +--- a/arch/arm64/boot/dts/nvidia/tegra210-p2180.dtsi
89 ++++ b/arch/arm64/boot/dts/nvidia/tegra210-p2180.dtsi
90 +@@ -307,7 +307,8 @@
91 + regulator-max-microvolt = <1320000>;
92 + enable-gpios = <&pmic 6 GPIO_ACTIVE_HIGH>;
93 + regulator-ramp-delay = <80>;
94 +- regulator-enable-ramp-delay = <1000>;
95 ++ regulator-enable-ramp-delay = <2000>;
96 ++ regulator-settling-time-us = <160>;
97 + };
98 + };
99 + };
100 +diff --git a/arch/arm64/boot/dts/nvidia/tegra210.dtsi b/arch/arm64/boot/dts/nvidia/tegra210.dtsi
101 +index 9bdf19f2cca7..466199766848 100644
102 +--- a/arch/arm64/boot/dts/nvidia/tegra210.dtsi
103 ++++ b/arch/arm64/boot/dts/nvidia/tegra210.dtsi
104 +@@ -1103,7 +1103,7 @@
105 + compatible = "nvidia,tegra210-agic";
106 + #interrupt-cells = <3>;
107 + interrupt-controller;
108 +- reg = <0x702f9000 0x2000>,
109 ++ reg = <0x702f9000 0x1000>,
110 + <0x702fa000 0x2000>;
111 + interrupts = <GIC_SPI 102 (GIC_CPU_MASK_SIMPLE(4) | IRQ_TYPE_LEVEL_HIGH)>;
112 + clocks = <&tegra_car TEGRA210_CLK_APE>;
113 +diff --git a/arch/arm64/crypto/sha1-ce-glue.c b/arch/arm64/crypto/sha1-ce-glue.c
114 +index efbeb3e0dcfb..70568e6db77b 100644
115 +--- a/arch/arm64/crypto/sha1-ce-glue.c
116 ++++ b/arch/arm64/crypto/sha1-ce-glue.c
117 +@@ -54,7 +54,7 @@ static int sha1_ce_finup(struct shash_desc *desc, const u8 *data,
118 + unsigned int len, u8 *out)
119 + {
120 + struct sha1_ce_state *sctx = shash_desc_ctx(desc);
121 +- bool finalize = !sctx->sst.count && !(len % SHA1_BLOCK_SIZE);
122 ++ bool finalize = !sctx->sst.count && !(len % SHA1_BLOCK_SIZE) && len;
123 +
124 + if (!may_use_simd())
125 + return crypto_sha1_finup(desc, data, len, out);
126 +diff --git a/arch/arm64/crypto/sha2-ce-glue.c b/arch/arm64/crypto/sha2-ce-glue.c
127 +index fd1ff2b13dfa..af8472aded42 100644
128 +--- a/arch/arm64/crypto/sha2-ce-glue.c
129 ++++ b/arch/arm64/crypto/sha2-ce-glue.c
130 +@@ -59,7 +59,7 @@ static int sha256_ce_finup(struct shash_desc *desc, const u8 *data,
131 + unsigned int len, u8 *out)
132 + {
133 + struct sha256_ce_state *sctx = shash_desc_ctx(desc);
134 +- bool finalize = !sctx->sst.count && !(len % SHA256_BLOCK_SIZE);
135 ++ bool finalize = !sctx->sst.count && !(len % SHA256_BLOCK_SIZE) && len;
136 +
137 + if (!may_use_simd()) {
138 + if (len)
139 +diff --git a/arch/arm64/kernel/acpi.c b/arch/arm64/kernel/acpi.c
140 +index b3162715ed78..285f0b4851fc 100644
141 +--- a/arch/arm64/kernel/acpi.c
142 ++++ b/arch/arm64/kernel/acpi.c
143 +@@ -157,10 +157,14 @@ static int __init acpi_fadt_sanity_check(void)
144 + */
145 + if (table->revision < 5 ||
146 + (table->revision == 5 && fadt->minor_revision < 1)) {
147 +- pr_err("Unsupported FADT revision %d.%d, should be 5.1+\n",
148 ++ pr_err(FW_BUG "Unsupported FADT revision %d.%d, should be 5.1+\n",
149 + table->revision, fadt->minor_revision);
150 +- ret = -EINVAL;
151 +- goto out;
152 ++
153 ++ if (!fadt->arm_boot_flags) {
154 ++ ret = -EINVAL;
155 ++ goto out;
156 ++ }
157 ++ pr_err("FADT has ARM boot flags set, assuming 5.1\n");
158 + }
159 +
160 + if (!(fadt->flags & ACPI_FADT_HW_REDUCED)) {
161 +diff --git a/arch/arm64/kernel/image.h b/arch/arm64/kernel/image.h
162 +index 40f9f0b078a4..12af2ba8d558 100644
163 +--- a/arch/arm64/kernel/image.h
164 ++++ b/arch/arm64/kernel/image.h
165 +@@ -73,7 +73,11 @@
166 +
167 + #ifdef CONFIG_EFI
168 +
169 +-__efistub_stext_offset = stext - _text;
170 ++/*
171 ++ * Use ABSOLUTE() to avoid ld.lld treating this as a relative symbol:
172 ++ * https://github.com/ClangBuiltLinux/linux/issues/561
173 ++ */
174 ++__efistub_stext_offset = ABSOLUTE(stext - _text);
175 +
176 + /*
177 + * The EFI stub has its own symbol namespace prefixed by __efistub_, to
178 +diff --git a/arch/mips/boot/compressed/Makefile b/arch/mips/boot/compressed/Makefile
179 +index adce180f3ee4..331b9e0a8072 100644
180 +--- a/arch/mips/boot/compressed/Makefile
181 ++++ b/arch/mips/boot/compressed/Makefile
182 +@@ -75,6 +75,8 @@ OBJCOPYFLAGS_piggy.o := --add-section=.image=$(obj)/vmlinux.bin.z \
183 + $(obj)/piggy.o: $(obj)/dummy.o $(obj)/vmlinux.bin.z FORCE
184 + $(call if_changed,objcopy)
185 +
186 ++HOSTCFLAGS_calc_vmlinuz_load_addr.o += $(LINUXINCLUDE)
187 ++
188 + # Calculate the load address of the compressed kernel image
189 + hostprogs-y := calc_vmlinuz_load_addr
190 +
191 +diff --git a/arch/mips/boot/compressed/calc_vmlinuz_load_addr.c b/arch/mips/boot/compressed/calc_vmlinuz_load_addr.c
192 +index 542c3ede9722..d14f75ec8273 100644
193 +--- a/arch/mips/boot/compressed/calc_vmlinuz_load_addr.c
194 ++++ b/arch/mips/boot/compressed/calc_vmlinuz_load_addr.c
195 +@@ -13,7 +13,7 @@
196 + #include <stdint.h>
197 + #include <stdio.h>
198 + #include <stdlib.h>
199 +-#include "../../../../include/linux/sizes.h"
200 ++#include <linux/sizes.h>
201 +
202 + int main(int argc, char *argv[])
203 + {
204 +diff --git a/arch/mips/include/asm/mach-ath79/ar933x_uart.h b/arch/mips/include/asm/mach-ath79/ar933x_uart.h
205 +index c2917b39966b..bba2c8837951 100644
206 +--- a/arch/mips/include/asm/mach-ath79/ar933x_uart.h
207 ++++ b/arch/mips/include/asm/mach-ath79/ar933x_uart.h
208 +@@ -27,8 +27,8 @@
209 + #define AR933X_UART_CS_PARITY_S 0
210 + #define AR933X_UART_CS_PARITY_M 0x3
211 + #define AR933X_UART_CS_PARITY_NONE 0
212 +-#define AR933X_UART_CS_PARITY_ODD 1
213 +-#define AR933X_UART_CS_PARITY_EVEN 2
214 ++#define AR933X_UART_CS_PARITY_ODD 2
215 ++#define AR933X_UART_CS_PARITY_EVEN 3
216 + #define AR933X_UART_CS_IF_MODE_S 2
217 + #define AR933X_UART_CS_IF_MODE_M 0x3
218 + #define AR933X_UART_CS_IF_MODE_NONE 0
219 +diff --git a/arch/mips/jz4740/board-qi_lb60.c b/arch/mips/jz4740/board-qi_lb60.c
220 +index 6d7f97552200..e1a905515283 100644
221 +--- a/arch/mips/jz4740/board-qi_lb60.c
222 ++++ b/arch/mips/jz4740/board-qi_lb60.c
223 +@@ -456,27 +456,27 @@ static unsigned long pin_cfg_bias_disable[] = {
224 + static struct pinctrl_map pin_map[] __initdata = {
225 + /* NAND pin configuration */
226 + PIN_MAP_MUX_GROUP_DEFAULT("jz4740-nand",
227 +- "10010000.jz4740-pinctrl", "nand", "nand-cs1"),
228 ++ "10010000.pin-controller", "nand-cs1", "nand"),
229 +
230 + /* fbdev pin configuration */
231 + PIN_MAP_MUX_GROUP("jz4740-fb", PINCTRL_STATE_DEFAULT,
232 +- "10010000.jz4740-pinctrl", "lcd", "lcd-8bit"),
233 ++ "10010000.pin-controller", "lcd-8bit", "lcd"),
234 + PIN_MAP_MUX_GROUP("jz4740-fb", PINCTRL_STATE_SLEEP,
235 +- "10010000.jz4740-pinctrl", "lcd", "lcd-no-pins"),
236 ++ "10010000.pin-controller", "lcd-no-pins", "lcd"),
237 +
238 + /* MMC pin configuration */
239 + PIN_MAP_MUX_GROUP_DEFAULT("jz4740-mmc.0",
240 +- "10010000.jz4740-pinctrl", "mmc", "mmc-1bit"),
241 ++ "10010000.pin-controller", "mmc-1bit", "mmc"),
242 + PIN_MAP_MUX_GROUP_DEFAULT("jz4740-mmc.0",
243 +- "10010000.jz4740-pinctrl", "mmc", "mmc-4bit"),
244 ++ "10010000.pin-controller", "mmc-4bit", "mmc"),
245 + PIN_MAP_CONFIGS_PIN_DEFAULT("jz4740-mmc.0",
246 +- "10010000.jz4740-pinctrl", "PD0", pin_cfg_bias_disable),
247 ++ "10010000.pin-controller", "PD0", pin_cfg_bias_disable),
248 + PIN_MAP_CONFIGS_PIN_DEFAULT("jz4740-mmc.0",
249 +- "10010000.jz4740-pinctrl", "PD2", pin_cfg_bias_disable),
250 ++ "10010000.pin-controller", "PD2", pin_cfg_bias_disable),
251 +
252 + /* PWM pin configuration */
253 + PIN_MAP_MUX_GROUP_DEFAULT("jz4740-pwm",
254 +- "10010000.jz4740-pinctrl", "pwm4", "pwm4"),
255 ++ "10010000.pin-controller", "pwm4", "pwm4"),
256 + };
257 +
258 +
259 +diff --git a/arch/parisc/kernel/ptrace.c b/arch/parisc/kernel/ptrace.c
260 +index eca5b2a1c7e1..f468a5b44508 100644
261 +--- a/arch/parisc/kernel/ptrace.c
262 ++++ b/arch/parisc/kernel/ptrace.c
263 +@@ -171,6 +171,9 @@ long arch_ptrace(struct task_struct *child, long request,
264 + if ((addr & (sizeof(unsigned long)-1)) ||
265 + addr >= sizeof(struct pt_regs))
266 + break;
267 ++ if (addr == PT_IAOQ0 || addr == PT_IAOQ1) {
268 ++ data |= 3; /* ensure userspace privilege */
269 ++ }
270 + if ((addr >= PT_GR1 && addr <= PT_GR31) ||
271 + addr == PT_IAOQ0 || addr == PT_IAOQ1 ||
272 + (addr >= PT_FR0 && addr <= PT_FR31 + 4) ||
273 +@@ -232,16 +235,18 @@ long arch_ptrace(struct task_struct *child, long request,
274 +
275 + static compat_ulong_t translate_usr_offset(compat_ulong_t offset)
276 + {
277 +- if (offset < 0)
278 +- return sizeof(struct pt_regs);
279 +- else if (offset <= 32*4) /* gr[0..31] */
280 +- return offset * 2 + 4;
281 +- else if (offset <= 32*4+32*8) /* gr[0..31] + fr[0..31] */
282 +- return offset + 32*4;
283 +- else if (offset < sizeof(struct pt_regs)/2 + 32*4)
284 +- return offset * 2 + 4 - 32*8;
285 ++ compat_ulong_t pos;
286 ++
287 ++ if (offset < 32*4) /* gr[0..31] */
288 ++ pos = offset * 2 + 4;
289 ++ else if (offset < 32*4+32*8) /* fr[0] ... fr[31] */
290 ++ pos = (offset - 32*4) + PT_FR0;
291 ++ else if (offset < sizeof(struct pt_regs)/2 + 32*4) /* sr[0] ... ipsw */
292 ++ pos = (offset - 32*4 - 32*8) * 2 + PT_SR0 + 4;
293 + else
294 +- return sizeof(struct pt_regs);
295 ++ pos = sizeof(struct pt_regs);
296 ++
297 ++ return pos;
298 + }
299 +
300 + long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
301 +@@ -285,9 +290,12 @@ long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
302 + addr = translate_usr_offset(addr);
303 + if (addr >= sizeof(struct pt_regs))
304 + break;
305 ++ if (addr == PT_IAOQ0+4 || addr == PT_IAOQ1+4) {
306 ++ data |= 3; /* ensure userspace privilege */
307 ++ }
308 + if (addr >= PT_FR0 && addr <= PT_FR31 + 4) {
309 + /* Special case, fp regs are 64 bits anyway */
310 +- *(__u64 *) ((char *) task_regs(child) + addr) = data;
311 ++ *(__u32 *) ((char *) task_regs(child) + addr) = data;
312 + ret = 0;
313 + }
314 + else if ((addr >= PT_GR1+4 && addr <= PT_GR31+4) ||
315 +@@ -500,7 +508,8 @@ static void set_reg(struct pt_regs *regs, int num, unsigned long val)
316 + return;
317 + case RI(iaoq[0]):
318 + case RI(iaoq[1]):
319 +- regs->iaoq[num - RI(iaoq[0])] = val;
320 ++ /* set 2 lowest bits to ensure userspace privilege: */
321 ++ regs->iaoq[num - RI(iaoq[0])] = val | 3;
322 + return;
323 + case RI(sar): regs->sar = val;
324 + return;
325 +diff --git a/arch/powerpc/boot/xz_config.h b/arch/powerpc/boot/xz_config.h
326 +index e22e5b3770dd..ebfadd39e192 100644
327 +--- a/arch/powerpc/boot/xz_config.h
328 ++++ b/arch/powerpc/boot/xz_config.h
329 +@@ -20,10 +20,30 @@ static inline uint32_t swab32p(void *p)
330 +
331 + #ifdef __LITTLE_ENDIAN__
332 + #define get_le32(p) (*((uint32_t *) (p)))
333 ++#define cpu_to_be32(x) swab32(x)
334 ++static inline u32 be32_to_cpup(const u32 *p)
335 ++{
336 ++ return swab32p((u32 *)p);
337 ++}
338 + #else
339 + #define get_le32(p) swab32p(p)
340 ++#define cpu_to_be32(x) (x)
341 ++static inline u32 be32_to_cpup(const u32 *p)
342 ++{
343 ++ return *p;
344 ++}
345 + #endif
346 +
347 ++static inline uint32_t get_unaligned_be32(const void *p)
348 ++{
349 ++ return be32_to_cpup(p);
350 ++}
351 ++
352 ++static inline void put_unaligned_be32(u32 val, void *p)
353 ++{
354 ++ *((u32 *)p) = cpu_to_be32(val);
355 ++}
356 ++
357 + #define memeq(a, b, size) (memcmp(a, b, size) == 0)
358 + #define memzero(buf, size) memset(buf, 0, size)
359 +
360 +diff --git a/arch/powerpc/kernel/eeh.c b/arch/powerpc/kernel/eeh.c
361 +index 45322b37669a..d2ba7936d0d3 100644
362 +--- a/arch/powerpc/kernel/eeh.c
363 ++++ b/arch/powerpc/kernel/eeh.c
364 +@@ -361,10 +361,19 @@ static inline unsigned long eeh_token_to_phys(unsigned long token)
365 + ptep = find_init_mm_pte(token, &hugepage_shift);
366 + if (!ptep)
367 + return token;
368 +- WARN_ON(hugepage_shift);
369 +- pa = pte_pfn(*ptep) << PAGE_SHIFT;
370 +
371 +- return pa | (token & (PAGE_SIZE-1));
372 ++ pa = pte_pfn(*ptep);
373 ++
374 ++ /* On radix we can do hugepage mappings for io, so handle that */
375 ++ if (hugepage_shift) {
376 ++ pa <<= hugepage_shift;
377 ++ pa |= token & ((1ul << hugepage_shift) - 1);
378 ++ } else {
379 ++ pa <<= PAGE_SHIFT;
380 ++ pa |= token & (PAGE_SIZE - 1);
381 ++ }
382 ++
383 ++ return pa;
384 + }
385 +
386 + /*
387 +diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
388 +index f65bb53df43b..43cde6c60279 100644
389 +--- a/arch/powerpc/kernel/exceptions-64s.S
390 ++++ b/arch/powerpc/kernel/exceptions-64s.S
391 +@@ -1675,7 +1675,7 @@ handle_page_fault:
392 + addi r3,r1,STACK_FRAME_OVERHEAD
393 + bl do_page_fault
394 + cmpdi r3,0
395 +- beq+ 12f
396 ++ beq+ ret_from_except_lite
397 + bl save_nvgprs
398 + mr r5,r3
399 + addi r3,r1,STACK_FRAME_OVERHEAD
400 +@@ -1690,7 +1690,12 @@ handle_dabr_fault:
401 + ld r5,_DSISR(r1)
402 + addi r3,r1,STACK_FRAME_OVERHEAD
403 + bl do_break
404 +-12: b ret_from_except_lite
405 ++ /*
406 ++ * do_break() may have changed the NV GPRS while handling a breakpoint.
407 ++ * If so, we need to restore them with their updated values. Don't use
408 ++ * ret_from_except_lite here.
409 ++ */
410 ++ b ret_from_except
411 +
412 +
413 + #ifdef CONFIG_PPC_STD_MMU_64
414 +diff --git a/arch/powerpc/kernel/pci_of_scan.c b/arch/powerpc/kernel/pci_of_scan.c
415 +index 0d790f8432d2..6ca1b3a1e196 100644
416 +--- a/arch/powerpc/kernel/pci_of_scan.c
417 ++++ b/arch/powerpc/kernel/pci_of_scan.c
418 +@@ -45,6 +45,8 @@ static unsigned int pci_parse_of_flags(u32 addr0, int bridge)
419 + if (addr0 & 0x02000000) {
420 + flags = IORESOURCE_MEM | PCI_BASE_ADDRESS_SPACE_MEMORY;
421 + flags |= (addr0 >> 22) & PCI_BASE_ADDRESS_MEM_TYPE_64;
422 ++ if (flags & PCI_BASE_ADDRESS_MEM_TYPE_64)
423 ++ flags |= IORESOURCE_MEM_64;
424 + flags |= (addr0 >> 28) & PCI_BASE_ADDRESS_MEM_TYPE_1M;
425 + if (addr0 & 0x40000000)
426 + flags |= IORESOURCE_PREFETCH
427 +diff --git a/arch/powerpc/kernel/signal_32.c b/arch/powerpc/kernel/signal_32.c
428 +index 636ea854808e..a03fc3109fa5 100644
429 +--- a/arch/powerpc/kernel/signal_32.c
430 ++++ b/arch/powerpc/kernel/signal_32.c
431 +@@ -1279,6 +1279,9 @@ long sys_rt_sigreturn(int r3, int r4, int r5, int r6, int r7, int r8,
432 + goto bad;
433 +
434 + if (MSR_TM_ACTIVE(msr_hi<<32)) {
435 ++ /* Trying to start TM on non TM system */
436 ++ if (!cpu_has_feature(CPU_FTR_TM))
437 ++ goto bad;
438 + /* We only recheckpoint on return if we're
439 + * transaction.
440 + */
441 +diff --git a/arch/powerpc/kernel/signal_64.c b/arch/powerpc/kernel/signal_64.c
442 +index 927384d85faf..b75bf6e74209 100644
443 +--- a/arch/powerpc/kernel/signal_64.c
444 ++++ b/arch/powerpc/kernel/signal_64.c
445 +@@ -741,6 +741,11 @@ int sys_rt_sigreturn(unsigned long r3, unsigned long r4, unsigned long r5,
446 + if (MSR_TM_ACTIVE(msr)) {
447 + /* We recheckpoint on return. */
448 + struct ucontext __user *uc_transact;
449 ++
450 ++ /* Trying to start TM on non TM system */
451 ++ if (!cpu_has_feature(CPU_FTR_TM))
452 ++ goto badframe;
453 ++
454 + if (__get_user(uc_transact, &uc->uc_link))
455 + goto badframe;
456 + if (restore_tm_sigcontexts(current, &uc->uc_mcontext,
457 +diff --git a/arch/powerpc/kernel/swsusp_32.S b/arch/powerpc/kernel/swsusp_32.S
458 +index 34b73a262709..5307cb7e12de 100644
459 +--- a/arch/powerpc/kernel/swsusp_32.S
460 ++++ b/arch/powerpc/kernel/swsusp_32.S
461 +@@ -24,11 +24,19 @@
462 + #define SL_IBAT2 0x48
463 + #define SL_DBAT3 0x50
464 + #define SL_IBAT3 0x58
465 +-#define SL_TB 0x60
466 +-#define SL_R2 0x68
467 +-#define SL_CR 0x6c
468 +-#define SL_LR 0x70
469 +-#define SL_R12 0x74 /* r12 to r31 */
470 ++#define SL_DBAT4 0x60
471 ++#define SL_IBAT4 0x68
472 ++#define SL_DBAT5 0x70
473 ++#define SL_IBAT5 0x78
474 ++#define SL_DBAT6 0x80
475 ++#define SL_IBAT6 0x88
476 ++#define SL_DBAT7 0x90
477 ++#define SL_IBAT7 0x98
478 ++#define SL_TB 0xa0
479 ++#define SL_R2 0xa8
480 ++#define SL_CR 0xac
481 ++#define SL_LR 0xb0
482 ++#define SL_R12 0xb4 /* r12 to r31 */
483 + #define SL_SIZE (SL_R12 + 80)
484 +
485 + .section .data
486 +@@ -113,6 +121,41 @@ _GLOBAL(swsusp_arch_suspend)
487 + mfibatl r4,3
488 + stw r4,SL_IBAT3+4(r11)
489 +
490 ++BEGIN_MMU_FTR_SECTION
491 ++ mfspr r4,SPRN_DBAT4U
492 ++ stw r4,SL_DBAT4(r11)
493 ++ mfspr r4,SPRN_DBAT4L
494 ++ stw r4,SL_DBAT4+4(r11)
495 ++ mfspr r4,SPRN_DBAT5U
496 ++ stw r4,SL_DBAT5(r11)
497 ++ mfspr r4,SPRN_DBAT5L
498 ++ stw r4,SL_DBAT5+4(r11)
499 ++ mfspr r4,SPRN_DBAT6U
500 ++ stw r4,SL_DBAT6(r11)
501 ++ mfspr r4,SPRN_DBAT6L
502 ++ stw r4,SL_DBAT6+4(r11)
503 ++ mfspr r4,SPRN_DBAT7U
504 ++ stw r4,SL_DBAT7(r11)
505 ++ mfspr r4,SPRN_DBAT7L
506 ++ stw r4,SL_DBAT7+4(r11)
507 ++ mfspr r4,SPRN_IBAT4U
508 ++ stw r4,SL_IBAT4(r11)
509 ++ mfspr r4,SPRN_IBAT4L
510 ++ stw r4,SL_IBAT4+4(r11)
511 ++ mfspr r4,SPRN_IBAT5U
512 ++ stw r4,SL_IBAT5(r11)
513 ++ mfspr r4,SPRN_IBAT5L
514 ++ stw r4,SL_IBAT5+4(r11)
515 ++ mfspr r4,SPRN_IBAT6U
516 ++ stw r4,SL_IBAT6(r11)
517 ++ mfspr r4,SPRN_IBAT6L
518 ++ stw r4,SL_IBAT6+4(r11)
519 ++ mfspr r4,SPRN_IBAT7U
520 ++ stw r4,SL_IBAT7(r11)
521 ++ mfspr r4,SPRN_IBAT7L
522 ++ stw r4,SL_IBAT7+4(r11)
523 ++END_MMU_FTR_SECTION_IFSET(MMU_FTR_USE_HIGH_BATS)
524 ++
525 + #if 0
526 + /* Backup various CPU config stuffs */
527 + bl __save_cpu_setup
528 +@@ -278,27 +321,41 @@ END_FTR_SECTION_IFSET(CPU_FTR_ALTIVEC)
529 + mtibatu 3,r4
530 + lwz r4,SL_IBAT3+4(r11)
531 + mtibatl 3,r4
532 +-#endif
533 +-
534 + BEGIN_MMU_FTR_SECTION
535 +- li r4,0
536 ++ lwz r4,SL_DBAT4(r11)
537 + mtspr SPRN_DBAT4U,r4
538 ++ lwz r4,SL_DBAT4+4(r11)
539 + mtspr SPRN_DBAT4L,r4
540 ++ lwz r4,SL_DBAT5(r11)
541 + mtspr SPRN_DBAT5U,r4
542 ++ lwz r4,SL_DBAT5+4(r11)
543 + mtspr SPRN_DBAT5L,r4
544 ++ lwz r4,SL_DBAT6(r11)
545 + mtspr SPRN_DBAT6U,r4
546 ++ lwz r4,SL_DBAT6+4(r11)
547 + mtspr SPRN_DBAT6L,r4
548 ++ lwz r4,SL_DBAT7(r11)
549 + mtspr SPRN_DBAT7U,r4
550 ++ lwz r4,SL_DBAT7+4(r11)
551 + mtspr SPRN_DBAT7L,r4
552 ++ lwz r4,SL_IBAT4(r11)
553 + mtspr SPRN_IBAT4U,r4
554 ++ lwz r4,SL_IBAT4+4(r11)
555 + mtspr SPRN_IBAT4L,r4
556 ++ lwz r4,SL_IBAT5(r11)
557 + mtspr SPRN_IBAT5U,r4
558 ++ lwz r4,SL_IBAT5+4(r11)
559 + mtspr SPRN_IBAT5L,r4
560 ++ lwz r4,SL_IBAT6(r11)
561 + mtspr SPRN_IBAT6U,r4
562 ++ lwz r4,SL_IBAT6+4(r11)
563 + mtspr SPRN_IBAT6L,r4
564 ++ lwz r4,SL_IBAT7(r11)
565 + mtspr SPRN_IBAT7U,r4
566 ++ lwz r4,SL_IBAT7+4(r11)
567 + mtspr SPRN_IBAT7L,r4
568 + END_MMU_FTR_SECTION_IFSET(MMU_FTR_USE_HIGH_BATS)
569 ++#endif
570 +
571 + /* Flush all TLBs */
572 + lis r4,0x1000
573 +diff --git a/arch/powerpc/platforms/4xx/uic.c b/arch/powerpc/platforms/4xx/uic.c
574 +index 8b4dd0da0839..9e27cfe27026 100644
575 +--- a/arch/powerpc/platforms/4xx/uic.c
576 ++++ b/arch/powerpc/platforms/4xx/uic.c
577 +@@ -158,6 +158,7 @@ static int uic_set_irq_type(struct irq_data *d, unsigned int flow_type)
578 +
579 + mtdcr(uic->dcrbase + UIC_PR, pr);
580 + mtdcr(uic->dcrbase + UIC_TR, tr);
581 ++ mtdcr(uic->dcrbase + UIC_SR, ~mask);
582 +
583 + raw_spin_unlock_irqrestore(&uic->lock, flags);
584 +
585 +diff --git a/arch/powerpc/platforms/powermac/sleep.S b/arch/powerpc/platforms/powermac/sleep.S
586 +index 1c2802fabd57..c856cd7fcdc4 100644
587 +--- a/arch/powerpc/platforms/powermac/sleep.S
588 ++++ b/arch/powerpc/platforms/powermac/sleep.S
589 +@@ -37,10 +37,18 @@
590 + #define SL_IBAT2 0x48
591 + #define SL_DBAT3 0x50
592 + #define SL_IBAT3 0x58
593 +-#define SL_TB 0x60
594 +-#define SL_R2 0x68
595 +-#define SL_CR 0x6c
596 +-#define SL_R12 0x70 /* r12 to r31 */
597 ++#define SL_DBAT4 0x60
598 ++#define SL_IBAT4 0x68
599 ++#define SL_DBAT5 0x70
600 ++#define SL_IBAT5 0x78
601 ++#define SL_DBAT6 0x80
602 ++#define SL_IBAT6 0x88
603 ++#define SL_DBAT7 0x90
604 ++#define SL_IBAT7 0x98
605 ++#define SL_TB 0xa0
606 ++#define SL_R2 0xa8
607 ++#define SL_CR 0xac
608 ++#define SL_R12 0xb0 /* r12 to r31 */
609 + #define SL_SIZE (SL_R12 + 80)
610 +
611 + .section .text
612 +@@ -125,6 +133,41 @@ _GLOBAL(low_sleep_handler)
613 + mfibatl r4,3
614 + stw r4,SL_IBAT3+4(r1)
615 +
616 ++BEGIN_MMU_FTR_SECTION
617 ++ mfspr r4,SPRN_DBAT4U
618 ++ stw r4,SL_DBAT4(r1)
619 ++ mfspr r4,SPRN_DBAT4L
620 ++ stw r4,SL_DBAT4+4(r1)
621 ++ mfspr r4,SPRN_DBAT5U
622 ++ stw r4,SL_DBAT5(r1)
623 ++ mfspr r4,SPRN_DBAT5L
624 ++ stw r4,SL_DBAT5+4(r1)
625 ++ mfspr r4,SPRN_DBAT6U
626 ++ stw r4,SL_DBAT6(r1)
627 ++ mfspr r4,SPRN_DBAT6L
628 ++ stw r4,SL_DBAT6+4(r1)
629 ++ mfspr r4,SPRN_DBAT7U
630 ++ stw r4,SL_DBAT7(r1)
631 ++ mfspr r4,SPRN_DBAT7L
632 ++ stw r4,SL_DBAT7+4(r1)
633 ++ mfspr r4,SPRN_IBAT4U
634 ++ stw r4,SL_IBAT4(r1)
635 ++ mfspr r4,SPRN_IBAT4L
636 ++ stw r4,SL_IBAT4+4(r1)
637 ++ mfspr r4,SPRN_IBAT5U
638 ++ stw r4,SL_IBAT5(r1)
639 ++ mfspr r4,SPRN_IBAT5L
640 ++ stw r4,SL_IBAT5+4(r1)
641 ++ mfspr r4,SPRN_IBAT6U
642 ++ stw r4,SL_IBAT6(r1)
643 ++ mfspr r4,SPRN_IBAT6L
644 ++ stw r4,SL_IBAT6+4(r1)
645 ++ mfspr r4,SPRN_IBAT7U
646 ++ stw r4,SL_IBAT7(r1)
647 ++ mfspr r4,SPRN_IBAT7L
648 ++ stw r4,SL_IBAT7+4(r1)
649 ++END_MMU_FTR_SECTION_IFSET(MMU_FTR_USE_HIGH_BATS)
650 ++
651 + /* Backup various CPU config stuffs */
652 + bl __save_cpu_setup
653 +
654 +@@ -325,22 +368,37 @@ grackle_wake_up:
655 + mtibatl 3,r4
656 +
657 + BEGIN_MMU_FTR_SECTION
658 +- li r4,0
659 ++ lwz r4,SL_DBAT4(r1)
660 + mtspr SPRN_DBAT4U,r4
661 ++ lwz r4,SL_DBAT4+4(r1)
662 + mtspr SPRN_DBAT4L,r4
663 ++ lwz r4,SL_DBAT5(r1)
664 + mtspr SPRN_DBAT5U,r4
665 ++ lwz r4,SL_DBAT5+4(r1)
666 + mtspr SPRN_DBAT5L,r4
667 ++ lwz r4,SL_DBAT6(r1)
668 + mtspr SPRN_DBAT6U,r4
669 ++ lwz r4,SL_DBAT6+4(r1)
670 + mtspr SPRN_DBAT6L,r4
671 ++ lwz r4,SL_DBAT7(r1)
672 + mtspr SPRN_DBAT7U,r4
673 ++ lwz r4,SL_DBAT7+4(r1)
674 + mtspr SPRN_DBAT7L,r4
675 ++ lwz r4,SL_IBAT4(r1)
676 + mtspr SPRN_IBAT4U,r4
677 ++ lwz r4,SL_IBAT4+4(r1)
678 + mtspr SPRN_IBAT4L,r4
679 ++ lwz r4,SL_IBAT5(r1)
680 + mtspr SPRN_IBAT5U,r4
681 ++ lwz r4,SL_IBAT5+4(r1)
682 + mtspr SPRN_IBAT5L,r4
683 ++ lwz r4,SL_IBAT6(r1)
684 + mtspr SPRN_IBAT6U,r4
685 ++ lwz r4,SL_IBAT6+4(r1)
686 + mtspr SPRN_IBAT6L,r4
687 ++ lwz r4,SL_IBAT7(r1)
688 + mtspr SPRN_IBAT7U,r4
689 ++ lwz r4,SL_IBAT7+4(r1)
690 + mtspr SPRN_IBAT7L,r4
691 + END_MMU_FTR_SECTION_IFSET(MMU_FTR_USE_HIGH_BATS)
692 +
693 +diff --git a/arch/powerpc/platforms/pseries/mobility.c b/arch/powerpc/platforms/pseries/mobility.c
694 +index fbea7db043fa..4addc552eb33 100644
695 +--- a/arch/powerpc/platforms/pseries/mobility.c
696 ++++ b/arch/powerpc/platforms/pseries/mobility.c
697 +@@ -9,6 +9,7 @@
698 + * 2 as published by the Free Software Foundation.
699 + */
700 +
701 ++#include <linux/cpu.h>
702 + #include <linux/kernel.h>
703 + #include <linux/kobject.h>
704 + #include <linux/smp.h>
705 +@@ -343,11 +344,19 @@ void post_mobility_fixup(void)
706 + if (rc)
707 + printk(KERN_ERR "Post-mobility activate-fw failed: %d\n", rc);
708 +
709 ++ /*
710 ++ * We don't want CPUs to go online/offline while the device
711 ++ * tree is being updated.
712 ++ */
713 ++ cpus_read_lock();
714 ++
715 + rc = pseries_devicetree_update(MIGRATION_SCOPE);
716 + if (rc)
717 + printk(KERN_ERR "Post-mobility device tree update "
718 + "failed: %d\n", rc);
719 +
720 ++ cpus_read_unlock();
721 ++
722 + /* Possibly switch to a new RFI flush type */
723 + pseries_setup_rfi_flush();
724 +
725 +diff --git a/arch/powerpc/sysdev/xive/common.c b/arch/powerpc/sysdev/xive/common.c
726 +index a3b8d7d1316e..818fc5351591 100644
727 +--- a/arch/powerpc/sysdev/xive/common.c
728 ++++ b/arch/powerpc/sysdev/xive/common.c
729 +@@ -482,7 +482,7 @@ static int xive_find_target_in_mask(const struct cpumask *mask,
730 + * Now go through the entire mask until we find a valid
731 + * target.
732 + */
733 +- for (;;) {
734 ++ do {
735 + /*
736 + * We re-check online as the fallback case passes us
737 + * an untested affinity mask
738 +@@ -490,12 +490,11 @@ static int xive_find_target_in_mask(const struct cpumask *mask,
739 + if (cpu_online(cpu) && xive_try_pick_target(cpu))
740 + return cpu;
741 + cpu = cpumask_next(cpu, mask);
742 +- if (cpu == first)
743 +- break;
744 + /* Wrap around */
745 + if (cpu >= nr_cpu_ids)
746 + cpu = cpumask_first(mask);
747 +- }
748 ++ } while (cpu != first);
749 ++
750 + return -1;
751 + }
752 +
753 +diff --git a/arch/powerpc/xmon/xmon.c b/arch/powerpc/xmon/xmon.c
754 +index f752f771f29d..6b9038a3e79f 100644
755 +--- a/arch/powerpc/xmon/xmon.c
756 ++++ b/arch/powerpc/xmon/xmon.c
757 +@@ -465,8 +465,10 @@ static int xmon_core(struct pt_regs *regs, int fromipi)
758 + local_irq_save(flags);
759 + hard_irq_disable();
760 +
761 +- tracing_enabled = tracing_is_on();
762 +- tracing_off();
763 ++ if (!fromipi) {
764 ++ tracing_enabled = tracing_is_on();
765 ++ tracing_off();
766 ++ }
767 +
768 + bp = in_breakpoint_table(regs->nip, &offset);
769 + if (bp != NULL) {
770 +diff --git a/arch/sh/include/asm/io.h b/arch/sh/include/asm/io.h
771 +index 98cb8c802b1a..0ae60d680000 100644
772 +--- a/arch/sh/include/asm/io.h
773 ++++ b/arch/sh/include/asm/io.h
774 +@@ -371,7 +371,11 @@ static inline int iounmap_fixed(void __iomem *addr) { return -EINVAL; }
775 +
776 + #define ioremap_nocache ioremap
777 + #define ioremap_uc ioremap
778 +-#define iounmap __iounmap
779 ++
780 ++static inline void iounmap(void __iomem *addr)
781 ++{
782 ++ __iounmap(addr);
783 ++}
784 +
785 + /*
786 + * Convert a physical pointer to a virtual kernel pointer for /dev/mem
787 +diff --git a/arch/um/include/asm/mmu_context.h b/arch/um/include/asm/mmu_context.h
788 +index fca34b2177e2..129fb1d1f1c5 100644
789 +--- a/arch/um/include/asm/mmu_context.h
790 ++++ b/arch/um/include/asm/mmu_context.h
791 +@@ -53,7 +53,7 @@ static inline void activate_mm(struct mm_struct *old, struct mm_struct *new)
792 + * when the new ->mm is used for the first time.
793 + */
794 + __switch_mm(&new->context.id);
795 +- down_write(&new->mmap_sem);
796 ++ down_write_nested(&new->mmap_sem, 1);
797 + uml_setup_stubs(new);
798 + up_write(&new->mmap_sem);
799 + }
800 +diff --git a/arch/x86/events/amd/uncore.c b/arch/x86/events/amd/uncore.c
801 +index 4e1d7483b78c..baa7e36073f9 100644
802 +--- a/arch/x86/events/amd/uncore.c
803 ++++ b/arch/x86/events/amd/uncore.c
804 +@@ -19,6 +19,7 @@
805 + #include <asm/cpufeature.h>
806 + #include <asm/perf_event.h>
807 + #include <asm/msr.h>
808 ++#include <asm/smp.h>
809 +
810 + #define NUM_COUNTERS_NB 4
811 + #define NUM_COUNTERS_L2 4
812 +@@ -209,15 +210,22 @@ static int amd_uncore_event_init(struct perf_event *event)
813 + hwc->config = event->attr.config & AMD64_RAW_EVENT_MASK_NB;
814 + hwc->idx = -1;
815 +
816 ++ if (event->cpu < 0)
817 ++ return -EINVAL;
818 ++
819 + /*
820 + * SliceMask and ThreadMask need to be set for certain L3 events in
821 + * Family 17h. For other events, the two fields do not affect the count.
822 + */
823 +- if (l3_mask)
824 +- hwc->config |= (AMD64_L3_SLICE_MASK | AMD64_L3_THREAD_MASK);
825 ++ if (l3_mask && is_llc_event(event)) {
826 ++ int thread = 2 * (cpu_data(event->cpu).cpu_core_id % 4);
827 +
828 +- if (event->cpu < 0)
829 +- return -EINVAL;
830 ++ if (smp_num_siblings > 1)
831 ++ thread += cpu_data(event->cpu).apicid & 1;
832 ++
833 ++ hwc->config |= (1ULL << (AMD64_L3_THREAD_SHIFT + thread) &
834 ++ AMD64_L3_THREAD_MASK) | AMD64_L3_SLICE_MASK;
835 ++ }
836 +
837 + uncore = event_to_amd_uncore(event);
838 + if (!uncore)
839 +@@ -407,26 +415,8 @@ static int amd_uncore_cpu_starting(unsigned int cpu)
840 + }
841 +
842 + if (amd_uncore_llc) {
843 +- unsigned int apicid = cpu_data(cpu).apicid;
844 +- unsigned int nshared, subleaf, prev_eax = 0;
845 +-
846 + uncore = *per_cpu_ptr(amd_uncore_llc, cpu);
847 +- /*
848 +- * Iterate over Cache Topology Definition leaves until no
849 +- * more cache descriptions are available.
850 +- */
851 +- for (subleaf = 0; subleaf < 5; subleaf++) {
852 +- cpuid_count(0x8000001d, subleaf, &eax, &ebx, &ecx, &edx);
853 +-
854 +- /* EAX[0:4] gives type of cache */
855 +- if (!(eax & 0x1f))
856 +- break;
857 +-
858 +- prev_eax = eax;
859 +- }
860 +- nshared = ((prev_eax >> 14) & 0xfff) + 1;
861 +-
862 +- uncore->id = apicid - (apicid % nshared);
863 ++ uncore->id = per_cpu(cpu_llc_id, cpu);
864 +
865 + uncore = amd_uncore_find_online_sibling(uncore, amd_uncore_llc);
866 + *per_cpu_ptr(amd_uncore_llc, cpu) = uncore;
867 +diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h
868 +index 72759f131cc5..d09dd91dd0b6 100644
869 +--- a/arch/x86/include/asm/atomic.h
870 ++++ b/arch/x86/include/asm/atomic.h
871 +@@ -50,7 +50,7 @@ static __always_inline void atomic_add(int i, atomic_t *v)
872 + {
873 + asm volatile(LOCK_PREFIX "addl %1,%0"
874 + : "+m" (v->counter)
875 +- : "ir" (i));
876 ++ : "ir" (i) : "memory");
877 + }
878 +
879 + /**
880 +@@ -64,7 +64,7 @@ static __always_inline void atomic_sub(int i, atomic_t *v)
881 + {
882 + asm volatile(LOCK_PREFIX "subl %1,%0"
883 + : "+m" (v->counter)
884 +- : "ir" (i));
885 ++ : "ir" (i) : "memory");
886 + }
887 +
888 + /**
889 +@@ -90,7 +90,7 @@ static __always_inline bool atomic_sub_and_test(int i, atomic_t *v)
890 + static __always_inline void atomic_inc(atomic_t *v)
891 + {
892 + asm volatile(LOCK_PREFIX "incl %0"
893 +- : "+m" (v->counter));
894 ++ : "+m" (v->counter) :: "memory");
895 + }
896 +
897 + /**
898 +@@ -102,7 +102,7 @@ static __always_inline void atomic_inc(atomic_t *v)
899 + static __always_inline void atomic_dec(atomic_t *v)
900 + {
901 + asm volatile(LOCK_PREFIX "decl %0"
902 +- : "+m" (v->counter));
903 ++ : "+m" (v->counter) :: "memory");
904 + }
905 +
906 + /**
907 +diff --git a/arch/x86/include/asm/atomic64_64.h b/arch/x86/include/asm/atomic64_64.h
908 +index 738495caf05f..e6fad6bbb2ee 100644
909 +--- a/arch/x86/include/asm/atomic64_64.h
910 ++++ b/arch/x86/include/asm/atomic64_64.h
911 +@@ -45,7 +45,7 @@ static __always_inline void atomic64_add(long i, atomic64_t *v)
912 + {
913 + asm volatile(LOCK_PREFIX "addq %1,%0"
914 + : "=m" (v->counter)
915 +- : "er" (i), "m" (v->counter));
916 ++ : "er" (i), "m" (v->counter) : "memory");
917 + }
918 +
919 + /**
920 +@@ -59,7 +59,7 @@ static inline void atomic64_sub(long i, atomic64_t *v)
921 + {
922 + asm volatile(LOCK_PREFIX "subq %1,%0"
923 + : "=m" (v->counter)
924 +- : "er" (i), "m" (v->counter));
925 ++ : "er" (i), "m" (v->counter) : "memory");
926 + }
927 +
928 + /**
929 +@@ -86,7 +86,7 @@ static __always_inline void atomic64_inc(atomic64_t *v)
930 + {
931 + asm volatile(LOCK_PREFIX "incq %0"
932 + : "=m" (v->counter)
933 +- : "m" (v->counter));
934 ++ : "m" (v->counter) : "memory");
935 + }
936 +
937 + /**
938 +@@ -99,7 +99,7 @@ static __always_inline void atomic64_dec(atomic64_t *v)
939 + {
940 + asm volatile(LOCK_PREFIX "decq %0"
941 + : "=m" (v->counter)
942 +- : "m" (v->counter));
943 ++ : "m" (v->counter) : "memory");
944 + }
945 +
946 + /**
947 +diff --git a/arch/x86/include/asm/barrier.h b/arch/x86/include/asm/barrier.h
948 +index a04f0c242a28..bc88797cfa61 100644
949 +--- a/arch/x86/include/asm/barrier.h
950 ++++ b/arch/x86/include/asm/barrier.h
951 +@@ -106,8 +106,8 @@ do { \
952 + #endif
953 +
954 + /* Atomic operations are already serializing on x86 */
955 +-#define __smp_mb__before_atomic() barrier()
956 +-#define __smp_mb__after_atomic() barrier()
957 ++#define __smp_mb__before_atomic() do { } while (0)
958 ++#define __smp_mb__after_atomic() do { } while (0)
959 +
960 + #include <asm-generic/barrier.h>
961 +
962 +diff --git a/arch/x86/include/asm/cpufeatures.h b/arch/x86/include/asm/cpufeatures.h
963 +index 48ef9ed8226d..4cb8315c521f 100644
964 +--- a/arch/x86/include/asm/cpufeatures.h
965 ++++ b/arch/x86/include/asm/cpufeatures.h
966 +@@ -239,12 +239,14 @@
967 + #define X86_FEATURE_BMI1 ( 9*32+ 3) /* 1st group bit manipulation extensions */
968 + #define X86_FEATURE_HLE ( 9*32+ 4) /* Hardware Lock Elision */
969 + #define X86_FEATURE_AVX2 ( 9*32+ 5) /* AVX2 instructions */
970 ++#define X86_FEATURE_FDP_EXCPTN_ONLY ( 9*32+ 6) /* "" FPU data pointer updated only on x87 exceptions */
971 + #define X86_FEATURE_SMEP ( 9*32+ 7) /* Supervisor Mode Execution Protection */
972 + #define X86_FEATURE_BMI2 ( 9*32+ 8) /* 2nd group bit manipulation extensions */
973 + #define X86_FEATURE_ERMS ( 9*32+ 9) /* Enhanced REP MOVSB/STOSB instructions */
974 + #define X86_FEATURE_INVPCID ( 9*32+10) /* Invalidate Processor Context ID */
975 + #define X86_FEATURE_RTM ( 9*32+11) /* Restricted Transactional Memory */
976 + #define X86_FEATURE_CQM ( 9*32+12) /* Cache QoS Monitoring */
977 ++#define X86_FEATURE_ZERO_FCS_FDS ( 9*32+13) /* "" Zero out FPU CS and FPU DS */
978 + #define X86_FEATURE_MPX ( 9*32+14) /* Memory Protection Extension */
979 + #define X86_FEATURE_RDT_A ( 9*32+15) /* Resource Director Technology Allocation */
980 + #define X86_FEATURE_AVX512F ( 9*32+16) /* AVX-512 Foundation */
981 +diff --git a/arch/x86/kernel/cpu/bugs.c b/arch/x86/kernel/cpu/bugs.c
982 +index 3b44d39aca1d..64b6180ce162 100644
983 +--- a/arch/x86/kernel/cpu/bugs.c
984 ++++ b/arch/x86/kernel/cpu/bugs.c
985 +@@ -1196,7 +1196,7 @@ static ssize_t l1tf_show_state(char *buf)
986 +
987 + static ssize_t mds_show_state(char *buf)
988 + {
989 +- if (!hypervisor_is_type(X86_HYPER_NATIVE)) {
990 ++ if (boot_cpu_has(X86_FEATURE_HYPERVISOR)) {
991 + return sprintf(buf, "%s; SMT Host state unknown\n",
992 + mds_strings[mds_mitigation]);
993 + }
994 +diff --git a/arch/x86/kernel/cpu/mkcapflags.sh b/arch/x86/kernel/cpu/mkcapflags.sh
995 +index d0dfb892c72f..aed45b8895d5 100644
996 +--- a/arch/x86/kernel/cpu/mkcapflags.sh
997 ++++ b/arch/x86/kernel/cpu/mkcapflags.sh
998 +@@ -4,6 +4,8 @@
999 + # Generate the x86_cap/bug_flags[] arrays from include/asm/cpufeatures.h
1000 + #
1001 +
1002 ++set -e
1003 ++
1004 + IN=$1
1005 + OUT=$2
1006 +
1007 +diff --git a/arch/x86/kernel/mpparse.c b/arch/x86/kernel/mpparse.c
1008 +index 1c52acaa5bec..236abf77994b 100644
1009 +--- a/arch/x86/kernel/mpparse.c
1010 ++++ b/arch/x86/kernel/mpparse.c
1011 +@@ -544,17 +544,15 @@ void __init default_get_smp_config(unsigned int early)
1012 + * local APIC has default address
1013 + */
1014 + mp_lapic_addr = APIC_DEFAULT_PHYS_BASE;
1015 +- return;
1016 ++ goto out;
1017 + }
1018 +
1019 + pr_info("Default MP configuration #%d\n", mpf->feature1);
1020 + construct_default_ISA_mptable(mpf->feature1);
1021 +
1022 + } else if (mpf->physptr) {
1023 +- if (check_physptr(mpf, early)) {
1024 +- early_memunmap(mpf, sizeof(*mpf));
1025 +- return;
1026 +- }
1027 ++ if (check_physptr(mpf, early))
1028 ++ goto out;
1029 + } else
1030 + BUG();
1031 +
1032 +@@ -563,7 +561,7 @@ void __init default_get_smp_config(unsigned int early)
1033 + /*
1034 + * Only use the first configuration found.
1035 + */
1036 +-
1037 ++out:
1038 + early_memunmap(mpf, sizeof(*mpf));
1039 + }
1040 +
1041 +diff --git a/arch/x86/kernel/sysfb_efi.c b/arch/x86/kernel/sysfb_efi.c
1042 +index 623965e86b65..897da526e40e 100644
1043 +--- a/arch/x86/kernel/sysfb_efi.c
1044 ++++ b/arch/x86/kernel/sysfb_efi.c
1045 +@@ -231,9 +231,55 @@ static const struct dmi_system_id efifb_dmi_system_table[] __initconst = {
1046 + {},
1047 + };
1048 +
1049 ++/*
1050 ++ * Some devices have a portrait LCD but advertise a landscape resolution (and
1051 ++ * pitch). We simply swap width and height for these devices so that we can
1052 ++ * correctly deal with some of them coming with multiple resolutions.
1053 ++ */
1054 ++static const struct dmi_system_id efifb_dmi_swap_width_height[] __initconst = {
1055 ++ {
1056 ++ /*
1057 ++ * Lenovo MIIX310-10ICR, only some batches have the troublesome
1058 ++ * 800x1280 portrait screen. Luckily the portrait version has
1059 ++ * its own BIOS version, so we match on that.
1060 ++ */
1061 ++ .matches = {
1062 ++ DMI_EXACT_MATCH(DMI_SYS_VENDOR, "LENOVO"),
1063 ++ DMI_EXACT_MATCH(DMI_PRODUCT_VERSION, "MIIX 310-10ICR"),
1064 ++ DMI_EXACT_MATCH(DMI_BIOS_VERSION, "1HCN44WW"),
1065 ++ },
1066 ++ },
1067 ++ {
1068 ++ /* Lenovo MIIX 320-10ICR with 800x1280 portrait screen */
1069 ++ .matches = {
1070 ++ DMI_EXACT_MATCH(DMI_SYS_VENDOR, "LENOVO"),
1071 ++ DMI_EXACT_MATCH(DMI_PRODUCT_VERSION,
1072 ++ "Lenovo MIIX 320-10ICR"),
1073 ++ },
1074 ++ },
1075 ++ {
1076 ++ /* Lenovo D330 with 800x1280 or 1200x1920 portrait screen */
1077 ++ .matches = {
1078 ++ DMI_EXACT_MATCH(DMI_SYS_VENDOR, "LENOVO"),
1079 ++ DMI_EXACT_MATCH(DMI_PRODUCT_VERSION,
1080 ++ "Lenovo ideapad D330-10IGM"),
1081 ++ },
1082 ++ },
1083 ++ {},
1084 ++};
1085 ++
1086 + __init void sysfb_apply_efi_quirks(void)
1087 + {
1088 + if (screen_info.orig_video_isVGA != VIDEO_TYPE_EFI ||
1089 + !(screen_info.capabilities & VIDEO_CAPABILITY_SKIP_QUIRKS))
1090 + dmi_check_system(efifb_dmi_system_table);
1091 ++
1092 ++ if (screen_info.orig_video_isVGA == VIDEO_TYPE_EFI &&
1093 ++ dmi_check_system(efifb_dmi_swap_width_height)) {
1094 ++ u16 temp = screen_info.lfb_width;
1095 ++
1096 ++ screen_info.lfb_width = screen_info.lfb_height;
1097 ++ screen_info.lfb_height = temp;
1098 ++ screen_info.lfb_linelength = 4 * screen_info.lfb_width;
1099 ++ }
1100 + }
1101 +diff --git a/arch/x86/kvm/pmu.c b/arch/x86/kvm/pmu.c
1102 +index 026db42a86c3..1bca8016ee8a 100644
1103 +--- a/arch/x86/kvm/pmu.c
1104 ++++ b/arch/x86/kvm/pmu.c
1105 +@@ -131,8 +131,8 @@ static void pmc_reprogram_counter(struct kvm_pmc *pmc, u32 type,
1106 + intr ? kvm_perf_overflow_intr :
1107 + kvm_perf_overflow, pmc);
1108 + if (IS_ERR(event)) {
1109 +- printk_once("kvm_pmu: event creation failed %ld\n",
1110 +- PTR_ERR(event));
1111 ++ pr_debug_ratelimited("kvm_pmu: event creation failed %ld for pmc->idx = %d\n",
1112 ++ PTR_ERR(event), pmc->idx);
1113 + return;
1114 + }
1115 +
1116 +diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
1117 +index 9b2486e8ec00..ae484edcf7a3 100644
1118 +--- a/arch/x86/kvm/vmx.c
1119 ++++ b/arch/x86/kvm/vmx.c
1120 +@@ -7694,6 +7694,7 @@ static void vmx_disable_shadow_vmcs(struct vcpu_vmx *vmx)
1121 + {
1122 + vmcs_clear_bits(SECONDARY_VM_EXEC_CONTROL, SECONDARY_EXEC_SHADOW_VMCS);
1123 + vmcs_write64(VMCS_LINK_POINTER, -1ull);
1124 ++ vmx->nested.sync_shadow_vmcs = false;
1125 + }
1126 +
1127 + static inline void nested_release_vmcs12(struct vcpu_vmx *vmx)
1128 +@@ -7705,7 +7706,6 @@ static inline void nested_release_vmcs12(struct vcpu_vmx *vmx)
1129 + /* copy to memory all shadowed fields in case
1130 + they were modified */
1131 + copy_shadow_to_vmcs12(vmx);
1132 +- vmx->nested.sync_shadow_vmcs = false;
1133 + vmx_disable_shadow_vmcs(vmx);
1134 + }
1135 + vmx->nested.posted_intr_nv = -1;
1136 +@@ -7891,6 +7891,9 @@ static void copy_shadow_to_vmcs12(struct vcpu_vmx *vmx)
1137 + const unsigned long *fields = shadow_read_write_fields;
1138 + const int num_fields = max_shadow_read_write_fields;
1139 +
1140 ++ if (WARN_ON(!shadow_vmcs))
1141 ++ return;
1142 ++
1143 + preempt_disable();
1144 +
1145 + vmcs_load(shadow_vmcs);
1146 +@@ -7938,6 +7941,9 @@ static void copy_vmcs12_to_shadow(struct vcpu_vmx *vmx)
1147 + u64 field_value = 0;
1148 + struct vmcs *shadow_vmcs = vmx->vmcs01.shadow_vmcs;
1149 +
1150 ++ if (WARN_ON(!shadow_vmcs))
1151 ++ return;
1152 ++
1153 + vmcs_load(shadow_vmcs);
1154 +
1155 + for (q = 0; q < ARRAY_SIZE(fields); q++) {
1156 +diff --git a/block/bio-integrity.c b/block/bio-integrity.c
1157 +index 5df32907ff3b..7f8010662437 100644
1158 +--- a/block/bio-integrity.c
1159 ++++ b/block/bio-integrity.c
1160 +@@ -313,8 +313,12 @@ bool bio_integrity_prep(struct bio *bio)
1161 + ret = bio_integrity_add_page(bio, virt_to_page(buf),
1162 + bytes, offset);
1163 +
1164 +- if (ret == 0)
1165 +- return false;
1166 ++ if (ret == 0) {
1167 ++ printk(KERN_ERR "could not attach integrity payload\n");
1168 ++ kfree(buf);
1169 ++ status = BLK_STS_RESOURCE;
1170 ++ goto err_end_io;
1171 ++ }
1172 +
1173 + if (ret < bytes)
1174 + break;
1175 +diff --git a/crypto/asymmetric_keys/Kconfig b/crypto/asymmetric_keys/Kconfig
1176 +index f3702e533ff4..d8a73d94bb30 100644
1177 +--- a/crypto/asymmetric_keys/Kconfig
1178 ++++ b/crypto/asymmetric_keys/Kconfig
1179 +@@ -15,6 +15,7 @@ config ASYMMETRIC_PUBLIC_KEY_SUBTYPE
1180 + select MPILIB
1181 + select CRYPTO_HASH_INFO
1182 + select CRYPTO_AKCIPHER
1183 ++ select CRYPTO_HASH
1184 + help
1185 + This option provides support for asymmetric public key type handling.
1186 + If signature generation and/or verification are to be used,
1187 +@@ -34,6 +35,7 @@ config X509_CERTIFICATE_PARSER
1188 + config PKCS7_MESSAGE_PARSER
1189 + tristate "PKCS#7 message parser"
1190 + depends on X509_CERTIFICATE_PARSER
1191 ++ select CRYPTO_HASH
1192 + select ASN1
1193 + select OID_REGISTRY
1194 + help
1195 +@@ -56,6 +58,7 @@ config SIGNED_PE_FILE_VERIFICATION
1196 + bool "Support for PE file signature verification"
1197 + depends on PKCS7_MESSAGE_PARSER=y
1198 + depends on SYSTEM_DATA_VERIFICATION
1199 ++ select CRYPTO_HASH
1200 + select ASN1
1201 + select OID_REGISTRY
1202 + help
1203 +diff --git a/crypto/chacha20poly1305.c b/crypto/chacha20poly1305.c
1204 +index 4d6f51bcdfab..af8afe5c06ea 100644
1205 +--- a/crypto/chacha20poly1305.c
1206 ++++ b/crypto/chacha20poly1305.c
1207 +@@ -67,6 +67,8 @@ struct chachapoly_req_ctx {
1208 + unsigned int cryptlen;
1209 + /* Actual AD, excluding IV */
1210 + unsigned int assoclen;
1211 ++ /* request flags, with MAY_SLEEP cleared if needed */
1212 ++ u32 flags;
1213 + union {
1214 + struct poly_req poly;
1215 + struct chacha_req chacha;
1216 +@@ -76,8 +78,12 @@ struct chachapoly_req_ctx {
1217 + static inline void async_done_continue(struct aead_request *req, int err,
1218 + int (*cont)(struct aead_request *))
1219 + {
1220 +- if (!err)
1221 ++ if (!err) {
1222 ++ struct chachapoly_req_ctx *rctx = aead_request_ctx(req);
1223 ++
1224 ++ rctx->flags &= ~CRYPTO_TFM_REQ_MAY_SLEEP;
1225 + err = cont(req);
1226 ++ }
1227 +
1228 + if (err != -EINPROGRESS && err != -EBUSY)
1229 + aead_request_complete(req, err);
1230 +@@ -144,7 +150,7 @@ static int chacha_decrypt(struct aead_request *req)
1231 + dst = scatterwalk_ffwd(rctx->dst, req->dst, req->assoclen);
1232 + }
1233 +
1234 +- skcipher_request_set_callback(&creq->req, aead_request_flags(req),
1235 ++ skcipher_request_set_callback(&creq->req, rctx->flags,
1236 + chacha_decrypt_done, req);
1237 + skcipher_request_set_tfm(&creq->req, ctx->chacha);
1238 + skcipher_request_set_crypt(&creq->req, src, dst,
1239 +@@ -188,7 +194,7 @@ static int poly_tail(struct aead_request *req)
1240 + memcpy(&preq->tail.cryptlen, &len, sizeof(len));
1241 + sg_set_buf(preq->src, &preq->tail, sizeof(preq->tail));
1242 +
1243 +- ahash_request_set_callback(&preq->req, aead_request_flags(req),
1244 ++ ahash_request_set_callback(&preq->req, rctx->flags,
1245 + poly_tail_done, req);
1246 + ahash_request_set_tfm(&preq->req, ctx->poly);
1247 + ahash_request_set_crypt(&preq->req, preq->src,
1248 +@@ -219,7 +225,7 @@ static int poly_cipherpad(struct aead_request *req)
1249 + sg_init_table(preq->src, 1);
1250 + sg_set_buf(preq->src, &preq->pad, padlen);
1251 +
1252 +- ahash_request_set_callback(&preq->req, aead_request_flags(req),
1253 ++ ahash_request_set_callback(&preq->req, rctx->flags,
1254 + poly_cipherpad_done, req);
1255 + ahash_request_set_tfm(&preq->req, ctx->poly);
1256 + ahash_request_set_crypt(&preq->req, preq->src, NULL, padlen);
1257 +@@ -250,7 +256,7 @@ static int poly_cipher(struct aead_request *req)
1258 + sg_init_table(rctx->src, 2);
1259 + crypt = scatterwalk_ffwd(rctx->src, crypt, req->assoclen);
1260 +
1261 +- ahash_request_set_callback(&preq->req, aead_request_flags(req),
1262 ++ ahash_request_set_callback(&preq->req, rctx->flags,
1263 + poly_cipher_done, req);
1264 + ahash_request_set_tfm(&preq->req, ctx->poly);
1265 + ahash_request_set_crypt(&preq->req, crypt, NULL, rctx->cryptlen);
1266 +@@ -280,7 +286,7 @@ static int poly_adpad(struct aead_request *req)
1267 + sg_init_table(preq->src, 1);
1268 + sg_set_buf(preq->src, preq->pad, padlen);
1269 +
1270 +- ahash_request_set_callback(&preq->req, aead_request_flags(req),
1271 ++ ahash_request_set_callback(&preq->req, rctx->flags,
1272 + poly_adpad_done, req);
1273 + ahash_request_set_tfm(&preq->req, ctx->poly);
1274 + ahash_request_set_crypt(&preq->req, preq->src, NULL, padlen);
1275 +@@ -304,7 +310,7 @@ static int poly_ad(struct aead_request *req)
1276 + struct poly_req *preq = &rctx->u.poly;
1277 + int err;
1278 +
1279 +- ahash_request_set_callback(&preq->req, aead_request_flags(req),
1280 ++ ahash_request_set_callback(&preq->req, rctx->flags,
1281 + poly_ad_done, req);
1282 + ahash_request_set_tfm(&preq->req, ctx->poly);
1283 + ahash_request_set_crypt(&preq->req, req->src, NULL, rctx->assoclen);
1284 +@@ -331,7 +337,7 @@ static int poly_setkey(struct aead_request *req)
1285 + sg_init_table(preq->src, 1);
1286 + sg_set_buf(preq->src, rctx->key, sizeof(rctx->key));
1287 +
1288 +- ahash_request_set_callback(&preq->req, aead_request_flags(req),
1289 ++ ahash_request_set_callback(&preq->req, rctx->flags,
1290 + poly_setkey_done, req);
1291 + ahash_request_set_tfm(&preq->req, ctx->poly);
1292 + ahash_request_set_crypt(&preq->req, preq->src, NULL, sizeof(rctx->key));
1293 +@@ -355,7 +361,7 @@ static int poly_init(struct aead_request *req)
1294 + struct poly_req *preq = &rctx->u.poly;
1295 + int err;
1296 +
1297 +- ahash_request_set_callback(&preq->req, aead_request_flags(req),
1298 ++ ahash_request_set_callback(&preq->req, rctx->flags,
1299 + poly_init_done, req);
1300 + ahash_request_set_tfm(&preq->req, ctx->poly);
1301 +
1302 +@@ -393,7 +399,7 @@ static int poly_genkey(struct aead_request *req)
1303 +
1304 + chacha_iv(creq->iv, req, 0);
1305 +
1306 +- skcipher_request_set_callback(&creq->req, aead_request_flags(req),
1307 ++ skcipher_request_set_callback(&creq->req, rctx->flags,
1308 + poly_genkey_done, req);
1309 + skcipher_request_set_tfm(&creq->req, ctx->chacha);
1310 + skcipher_request_set_crypt(&creq->req, creq->src, creq->src,
1311 +@@ -433,7 +439,7 @@ static int chacha_encrypt(struct aead_request *req)
1312 + dst = scatterwalk_ffwd(rctx->dst, req->dst, req->assoclen);
1313 + }
1314 +
1315 +- skcipher_request_set_callback(&creq->req, aead_request_flags(req),
1316 ++ skcipher_request_set_callback(&creq->req, rctx->flags,
1317 + chacha_encrypt_done, req);
1318 + skcipher_request_set_tfm(&creq->req, ctx->chacha);
1319 + skcipher_request_set_crypt(&creq->req, src, dst,
1320 +@@ -451,6 +457,7 @@ static int chachapoly_encrypt(struct aead_request *req)
1321 + struct chachapoly_req_ctx *rctx = aead_request_ctx(req);
1322 +
1323 + rctx->cryptlen = req->cryptlen;
1324 ++ rctx->flags = aead_request_flags(req);
1325 +
1326 + /* encrypt call chain:
1327 + * - chacha_encrypt/done()
1328 +@@ -472,6 +479,7 @@ static int chachapoly_decrypt(struct aead_request *req)
1329 + struct chachapoly_req_ctx *rctx = aead_request_ctx(req);
1330 +
1331 + rctx->cryptlen = req->cryptlen - POLY1305_DIGEST_SIZE;
1332 ++ rctx->flags = aead_request_flags(req);
1333 +
1334 + /* decrypt call chain:
1335 + * - poly_genkey/done()
1336 +diff --git a/crypto/ghash-generic.c b/crypto/ghash-generic.c
1337 +index 12ad3e3a84e3..73b56f2f44f1 100644
1338 +--- a/crypto/ghash-generic.c
1339 ++++ b/crypto/ghash-generic.c
1340 +@@ -34,6 +34,7 @@ static int ghash_setkey(struct crypto_shash *tfm,
1341 + const u8 *key, unsigned int keylen)
1342 + {
1343 + struct ghash_ctx *ctx = crypto_shash_ctx(tfm);
1344 ++ be128 k;
1345 +
1346 + if (keylen != GHASH_BLOCK_SIZE) {
1347 + crypto_shash_set_flags(tfm, CRYPTO_TFM_RES_BAD_KEY_LEN);
1348 +@@ -42,7 +43,12 @@ static int ghash_setkey(struct crypto_shash *tfm,
1349 +
1350 + if (ctx->gf128)
1351 + gf128mul_free_4k(ctx->gf128);
1352 +- ctx->gf128 = gf128mul_init_4k_lle((be128 *)key);
1353 ++
1354 ++ BUILD_BUG_ON(sizeof(k) != GHASH_BLOCK_SIZE);
1355 ++ memcpy(&k, key, GHASH_BLOCK_SIZE); /* avoid violating alignment rules */
1356 ++ ctx->gf128 = gf128mul_init_4k_lle(&k);
1357 ++ memzero_explicit(&k, GHASH_BLOCK_SIZE);
1358 ++
1359 + if (!ctx->gf128)
1360 + return -ENOMEM;
1361 +
1362 +diff --git a/crypto/serpent_generic.c b/crypto/serpent_generic.c
1363 +index 7c3382facc82..600bd288881d 100644
1364 +--- a/crypto/serpent_generic.c
1365 ++++ b/crypto/serpent_generic.c
1366 +@@ -229,7 +229,13 @@
1367 + x4 ^= x2; \
1368 + })
1369 +
1370 +-static void __serpent_setkey_sbox(u32 r0, u32 r1, u32 r2, u32 r3, u32 r4, u32 *k)
1371 ++/*
1372 ++ * both gcc and clang have misoptimized this function in the past,
1373 ++ * producing horrible object code from spilling temporary variables
1374 ++ * on the stack. Forcing this part out of line avoids that.
1375 ++ */
1376 ++static noinline void __serpent_setkey_sbox(u32 r0, u32 r1, u32 r2,
1377 ++ u32 r3, u32 r4, u32 *k)
1378 + {
1379 + k += 100;
1380 + S3(r3, r4, r0, r1, r2); store_and_load_keys(r1, r2, r4, r3, 28, 24);
1381 +diff --git a/drivers/android/binder.c b/drivers/android/binder.c
1382 +index 1af9f36f89cf..e694fd2c4ed0 100644
1383 +--- a/drivers/android/binder.c
1384 ++++ b/drivers/android/binder.c
1385 +@@ -2785,7 +2785,7 @@ static void binder_transaction(struct binder_proc *proc,
1386 + else
1387 + return_error = BR_DEAD_REPLY;
1388 + mutex_unlock(&context->context_mgr_node_lock);
1389 +- if (target_node && target_proc == proc) {
1390 ++ if (target_node && target_proc->pid == proc->pid) {
1391 + binder_user_error("%d:%d got transaction to context manager from process owning it\n",
1392 + proc->pid, thread->pid);
1393 + return_error = BR_FAILED_REPLY;
1394 +diff --git a/drivers/ata/libata-eh.c b/drivers/ata/libata-eh.c
1395 +index 2651c81d1edf..c398be4b1797 100644
1396 +--- a/drivers/ata/libata-eh.c
1397 ++++ b/drivers/ata/libata-eh.c
1398 +@@ -1535,7 +1535,7 @@ static int ata_eh_read_log_10h(struct ata_device *dev,
1399 + tf->hob_lbah = buf[10];
1400 + tf->nsect = buf[12];
1401 + tf->hob_nsect = buf[13];
1402 +- if (ata_id_has_ncq_autosense(dev->id))
1403 ++ if (dev->class == ATA_DEV_ZAC && ata_id_has_ncq_autosense(dev->id))
1404 + tf->auxiliary = buf[14] << 16 | buf[15] << 8 | buf[16];
1405 +
1406 + return 0;
1407 +@@ -1784,7 +1784,8 @@ void ata_eh_analyze_ncq_error(struct ata_link *link)
1408 + memcpy(&qc->result_tf, &tf, sizeof(tf));
1409 + qc->result_tf.flags = ATA_TFLAG_ISADDR | ATA_TFLAG_LBA | ATA_TFLAG_LBA48;
1410 + qc->err_mask |= AC_ERR_DEV | AC_ERR_NCQ;
1411 +- if ((qc->result_tf.command & ATA_SENSE) || qc->result_tf.auxiliary) {
1412 ++ if (dev->class == ATA_DEV_ZAC &&
1413 ++ ((qc->result_tf.command & ATA_SENSE) || qc->result_tf.auxiliary)) {
1414 + char sense_key, asc, ascq;
1415 +
1416 + sense_key = (qc->result_tf.auxiliary >> 16) & 0xff;
1417 +@@ -1838,10 +1839,11 @@ static unsigned int ata_eh_analyze_tf(struct ata_queued_cmd *qc,
1418 + }
1419 +
1420 + switch (qc->dev->class) {
1421 +- case ATA_DEV_ATA:
1422 + case ATA_DEV_ZAC:
1423 + if (stat & ATA_SENSE)
1424 + ata_eh_request_sense(qc, qc->scsicmd);
1425 ++ /* fall through */
1426 ++ case ATA_DEV_ATA:
1427 + if (err & ATA_ICRC)
1428 + qc->err_mask |= AC_ERR_ATA_BUS;
1429 + if (err & (ATA_UNC | ATA_AMNF))
1430 +diff --git a/drivers/base/regmap/regmap.c b/drivers/base/regmap/regmap.c
1431 +index 8fd08023c0f5..013d0a2b3ba0 100644
1432 +--- a/drivers/base/regmap/regmap.c
1433 ++++ b/drivers/base/regmap/regmap.c
1434 +@@ -1509,6 +1509,8 @@ int _regmap_raw_write(struct regmap *map, unsigned int reg,
1435 + map->format.reg_bytes +
1436 + map->format.pad_bytes,
1437 + val, val_len);
1438 ++ else
1439 ++ ret = -ENOTSUPP;
1440 +
1441 + /* If that didn't work fall back on linearising by hand. */
1442 + if (ret == -ENOTSUPP) {
1443 +diff --git a/drivers/block/floppy.c b/drivers/block/floppy.c
1444 +index 3ea9c3e9acb3..a9d1430fc5ee 100644
1445 +--- a/drivers/block/floppy.c
1446 ++++ b/drivers/block/floppy.c
1447 +@@ -2114,6 +2114,9 @@ static void setup_format_params(int track)
1448 + raw_cmd->kernel_data = floppy_track_buffer;
1449 + raw_cmd->length = 4 * F_SECT_PER_TRACK;
1450 +
1451 ++ if (!F_SECT_PER_TRACK)
1452 ++ return;
1453 ++
1454 + /* allow for about 30ms for data transport per track */
1455 + head_shift = (F_SECT_PER_TRACK + 5) / 6;
1456 +
1457 +@@ -3236,8 +3239,12 @@ static int set_geometry(unsigned int cmd, struct floppy_struct *g,
1458 + int cnt;
1459 +
1460 + /* sanity checking for parameters. */
1461 +- if (g->sect <= 0 ||
1462 +- g->head <= 0 ||
1463 ++ if ((int)g->sect <= 0 ||
1464 ++ (int)g->head <= 0 ||
1465 ++ /* check for overflow in max_sector */
1466 ++ (int)(g->sect * g->head) <= 0 ||
1467 ++ /* check for zero in F_SECT_PER_TRACK */
1468 ++ (unsigned char)((g->sect << 2) >> FD_SIZECODE(g)) == 0 ||
1469 + g->track <= 0 || g->track > UDP->tracks >> STRETCH(g) ||
1470 + /* check if reserved bits are set */
1471 + (g->stretch & ~(FD_STRETCH | FD_SWAPSIDES | FD_SECTBASEMASK)) != 0)
1472 +@@ -3381,6 +3388,24 @@ static int fd_getgeo(struct block_device *bdev, struct hd_geometry *geo)
1473 + return 0;
1474 + }
1475 +
1476 ++static bool valid_floppy_drive_params(const short autodetect[8],
1477 ++ int native_format)
1478 ++{
1479 ++ size_t floppy_type_size = ARRAY_SIZE(floppy_type);
1480 ++ size_t i = 0;
1481 ++
1482 ++ for (i = 0; i < 8; ++i) {
1483 ++ if (autodetect[i] < 0 ||
1484 ++ autodetect[i] >= floppy_type_size)
1485 ++ return false;
1486 ++ }
1487 ++
1488 ++ if (native_format < 0 || native_format >= floppy_type_size)
1489 ++ return false;
1490 ++
1491 ++ return true;
1492 ++}
1493 ++
1494 + static int fd_locked_ioctl(struct block_device *bdev, fmode_t mode, unsigned int cmd,
1495 + unsigned long param)
1496 + {
1497 +@@ -3507,6 +3532,9 @@ static int fd_locked_ioctl(struct block_device *bdev, fmode_t mode, unsigned int
1498 + SUPBOUND(size, strlen((const char *)outparam) + 1);
1499 + break;
1500 + case FDSETDRVPRM:
1501 ++ if (!valid_floppy_drive_params(inparam.dp.autodetect,
1502 ++ inparam.dp.native_format))
1503 ++ return -EINVAL;
1504 + *UDP = inparam.dp;
1505 + break;
1506 + case FDGETDRVPRM:
1507 +@@ -3704,6 +3732,8 @@ static int compat_setdrvprm(int drive,
1508 + return -EPERM;
1509 + if (copy_from_user(&v, arg, sizeof(struct compat_floppy_drive_params)))
1510 + return -EFAULT;
1511 ++ if (!valid_floppy_drive_params(v.autodetect, v.native_format))
1512 ++ return -EINVAL;
1513 + mutex_lock(&floppy_mutex);
1514 + UDP->cmos = v.cmos;
1515 + UDP->max_dtr = v.max_dtr;
1516 +diff --git a/drivers/bluetooth/hci_bcsp.c b/drivers/bluetooth/hci_bcsp.c
1517 +index d880f4e33c75..57a7f4255ac0 100644
1518 +--- a/drivers/bluetooth/hci_bcsp.c
1519 ++++ b/drivers/bluetooth/hci_bcsp.c
1520 +@@ -757,6 +757,11 @@ static int bcsp_close(struct hci_uart *hu)
1521 + skb_queue_purge(&bcsp->rel);
1522 + skb_queue_purge(&bcsp->unrel);
1523 +
1524 ++ if (bcsp->rx_skb) {
1525 ++ kfree_skb(bcsp->rx_skb);
1526 ++ bcsp->rx_skb = NULL;
1527 ++ }
1528 ++
1529 + kfree(bcsp);
1530 + return 0;
1531 + }
1532 +diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
1533 +index 9dfb28b04559..05ca269ddd05 100644
1534 +--- a/drivers/char/hpet.c
1535 ++++ b/drivers/char/hpet.c
1536 +@@ -570,8 +570,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
1537 + unsigned long long m;
1538 +
1539 + m = hpets->hp_tick_freq + (dis >> 1);
1540 +- do_div(m, dis);
1541 +- return (unsigned long)m;
1542 ++ return div64_ul(m, dis);
1543 + }
1544 +
1545 + static int
1546 +diff --git a/drivers/clocksource/exynos_mct.c b/drivers/clocksource/exynos_mct.c
1547 +index d55c30f6981d..aaf5bfa9bd9c 100644
1548 +--- a/drivers/clocksource/exynos_mct.c
1549 ++++ b/drivers/clocksource/exynos_mct.c
1550 +@@ -211,7 +211,7 @@ static void exynos4_frc_resume(struct clocksource *cs)
1551 +
1552 + static struct clocksource mct_frc = {
1553 + .name = "mct-frc",
1554 +- .rating = 400,
1555 ++ .rating = 450, /* use value higher than ARM arch timer */
1556 + .read = exynos4_frc_read,
1557 + .mask = CLOCKSOURCE_MASK(32),
1558 + .flags = CLOCK_SOURCE_IS_CONTINUOUS,
1559 +@@ -466,7 +466,7 @@ static int exynos4_mct_starting_cpu(unsigned int cpu)
1560 + evt->set_state_oneshot_stopped = set_state_shutdown;
1561 + evt->tick_resume = set_state_shutdown;
1562 + evt->features = CLOCK_EVT_FEAT_PERIODIC | CLOCK_EVT_FEAT_ONESHOT;
1563 +- evt->rating = 450;
1564 ++ evt->rating = 500; /* use value higher than ARM arch timer */
1565 +
1566 + exynos4_mct_write(TICK_BASE_CNT, mevt->base + MCT_L_TCNTB_OFFSET);
1567 +
1568 +diff --git a/drivers/crypto/amcc/crypto4xx_trng.c b/drivers/crypto/amcc/crypto4xx_trng.c
1569 +index 368c5599515e..a194ee0ddbb6 100644
1570 +--- a/drivers/crypto/amcc/crypto4xx_trng.c
1571 ++++ b/drivers/crypto/amcc/crypto4xx_trng.c
1572 +@@ -111,7 +111,6 @@ void ppc4xx_trng_probe(struct crypto4xx_core_device *core_dev)
1573 + return;
1574 +
1575 + err_out:
1576 +- of_node_put(trng);
1577 + iounmap(dev->trng_base);
1578 + kfree(rng);
1579 + dev->trng_base = NULL;
1580 +diff --git a/drivers/crypto/caam/caamalg.c b/drivers/crypto/caam/caamalg.c
1581 +index 63a21a6fc6cf..78feafcb7083 100644
1582 +--- a/drivers/crypto/caam/caamalg.c
1583 ++++ b/drivers/crypto/caam/caamalg.c
1584 +@@ -853,6 +853,7 @@ static void ablkcipher_encrypt_done(struct device *jrdev, u32 *desc, u32 err,
1585 + struct ablkcipher_request *req = context;
1586 + struct ablkcipher_edesc *edesc;
1587 + struct crypto_ablkcipher *ablkcipher = crypto_ablkcipher_reqtfm(req);
1588 ++ struct caam_ctx *ctx = crypto_ablkcipher_ctx(ablkcipher);
1589 + int ivsize = crypto_ablkcipher_ivsize(ablkcipher);
1590 +
1591 + #ifdef DEBUG
1592 +@@ -877,10 +878,11 @@ static void ablkcipher_encrypt_done(struct device *jrdev, u32 *desc, u32 err,
1593 +
1594 + /*
1595 + * The crypto API expects us to set the IV (req->info) to the last
1596 +- * ciphertext block. This is used e.g. by the CTS mode.
1597 ++ * ciphertext block when running in CBC mode.
1598 + */
1599 +- scatterwalk_map_and_copy(req->info, req->dst, req->nbytes - ivsize,
1600 +- ivsize, 0);
1601 ++ if ((ctx->cdata.algtype & OP_ALG_AAI_MASK) == OP_ALG_AAI_CBC)
1602 ++ scatterwalk_map_and_copy(req->info, req->dst, req->nbytes -
1603 ++ ivsize, ivsize, 0);
1604 +
1605 + /* In case initial IV was generated, copy it in GIVCIPHER request */
1606 + if (edesc->iv_dir == DMA_FROM_DEVICE) {
1607 +@@ -1609,10 +1611,11 @@ static int ablkcipher_decrypt(struct ablkcipher_request *req)
1608 +
1609 + /*
1610 + * The crypto API expects us to set the IV (req->info) to the last
1611 +- * ciphertext block.
1612 ++ * ciphertext block when running in CBC mode.
1613 + */
1614 +- scatterwalk_map_and_copy(req->info, req->src, req->nbytes - ivsize,
1615 +- ivsize, 0);
1616 ++ if ((ctx->cdata.algtype & OP_ALG_AAI_MASK) == OP_ALG_AAI_CBC)
1617 ++ scatterwalk_map_and_copy(req->info, req->src, req->nbytes -
1618 ++ ivsize, ivsize, 0);
1619 +
1620 + /* Create and submit job descriptor*/
1621 + init_ablkcipher_job(ctx->sh_desc_dec, ctx->sh_desc_dec_dma, edesc, req);
1622 +diff --git a/drivers/crypto/ccp/ccp-dev.c b/drivers/crypto/ccp/ccp-dev.c
1623 +index 4e029b176641..18d10694dd2a 100644
1624 +--- a/drivers/crypto/ccp/ccp-dev.c
1625 ++++ b/drivers/crypto/ccp/ccp-dev.c
1626 +@@ -35,56 +35,62 @@ struct ccp_tasklet_data {
1627 + };
1628 +
1629 + /* Human-readable error strings */
1630 ++#define CCP_MAX_ERROR_CODE 64
1631 + static char *ccp_error_codes[] = {
1632 + "",
1633 +- "ERR 01: ILLEGAL_ENGINE",
1634 +- "ERR 02: ILLEGAL_KEY_ID",
1635 +- "ERR 03: ILLEGAL_FUNCTION_TYPE",
1636 +- "ERR 04: ILLEGAL_FUNCTION_MODE",
1637 +- "ERR 05: ILLEGAL_FUNCTION_ENCRYPT",
1638 +- "ERR 06: ILLEGAL_FUNCTION_SIZE",
1639 +- "ERR 07: Zlib_MISSING_INIT_EOM",
1640 +- "ERR 08: ILLEGAL_FUNCTION_RSVD",
1641 +- "ERR 09: ILLEGAL_BUFFER_LENGTH",
1642 +- "ERR 10: VLSB_FAULT",
1643 +- "ERR 11: ILLEGAL_MEM_ADDR",
1644 +- "ERR 12: ILLEGAL_MEM_SEL",
1645 +- "ERR 13: ILLEGAL_CONTEXT_ID",
1646 +- "ERR 14: ILLEGAL_KEY_ADDR",
1647 +- "ERR 15: 0xF Reserved",
1648 +- "ERR 16: Zlib_ILLEGAL_MULTI_QUEUE",
1649 +- "ERR 17: Zlib_ILLEGAL_JOBID_CHANGE",
1650 +- "ERR 18: CMD_TIMEOUT",
1651 +- "ERR 19: IDMA0_AXI_SLVERR",
1652 +- "ERR 20: IDMA0_AXI_DECERR",
1653 +- "ERR 21: 0x15 Reserved",
1654 +- "ERR 22: IDMA1_AXI_SLAVE_FAULT",
1655 +- "ERR 23: IDMA1_AIXI_DECERR",
1656 +- "ERR 24: 0x18 Reserved",
1657 +- "ERR 25: ZLIBVHB_AXI_SLVERR",
1658 +- "ERR 26: ZLIBVHB_AXI_DECERR",
1659 +- "ERR 27: 0x1B Reserved",
1660 +- "ERR 27: ZLIB_UNEXPECTED_EOM",
1661 +- "ERR 27: ZLIB_EXTRA_DATA",
1662 +- "ERR 30: ZLIB_BTYPE",
1663 +- "ERR 31: ZLIB_UNDEFINED_SYMBOL",
1664 +- "ERR 32: ZLIB_UNDEFINED_DISTANCE_S",
1665 +- "ERR 33: ZLIB_CODE_LENGTH_SYMBOL",
1666 +- "ERR 34: ZLIB _VHB_ILLEGAL_FETCH",
1667 +- "ERR 35: ZLIB_UNCOMPRESSED_LEN",
1668 +- "ERR 36: ZLIB_LIMIT_REACHED",
1669 +- "ERR 37: ZLIB_CHECKSUM_MISMATCH0",
1670 +- "ERR 38: ODMA0_AXI_SLVERR",
1671 +- "ERR 39: ODMA0_AXI_DECERR",
1672 +- "ERR 40: 0x28 Reserved",
1673 +- "ERR 41: ODMA1_AXI_SLVERR",
1674 +- "ERR 42: ODMA1_AXI_DECERR",
1675 +- "ERR 43: LSB_PARITY_ERR",
1676 ++ "ILLEGAL_ENGINE",
1677 ++ "ILLEGAL_KEY_ID",
1678 ++ "ILLEGAL_FUNCTION_TYPE",
1679 ++ "ILLEGAL_FUNCTION_MODE",
1680 ++ "ILLEGAL_FUNCTION_ENCRYPT",
1681 ++ "ILLEGAL_FUNCTION_SIZE",
1682 ++ "Zlib_MISSING_INIT_EOM",
1683 ++ "ILLEGAL_FUNCTION_RSVD",
1684 ++ "ILLEGAL_BUFFER_LENGTH",
1685 ++ "VLSB_FAULT",
1686 ++ "ILLEGAL_MEM_ADDR",
1687 ++ "ILLEGAL_MEM_SEL",
1688 ++ "ILLEGAL_CONTEXT_ID",
1689 ++ "ILLEGAL_KEY_ADDR",
1690 ++ "0xF Reserved",
1691 ++ "Zlib_ILLEGAL_MULTI_QUEUE",
1692 ++ "Zlib_ILLEGAL_JOBID_CHANGE",
1693 ++ "CMD_TIMEOUT",
1694 ++ "IDMA0_AXI_SLVERR",
1695 ++ "IDMA0_AXI_DECERR",
1696 ++ "0x15 Reserved",
1697 ++ "IDMA1_AXI_SLAVE_FAULT",
1698 ++ "IDMA1_AIXI_DECERR",
1699 ++ "0x18 Reserved",
1700 ++ "ZLIBVHB_AXI_SLVERR",
1701 ++ "ZLIBVHB_AXI_DECERR",
1702 ++ "0x1B Reserved",
1703 ++ "ZLIB_UNEXPECTED_EOM",
1704 ++ "ZLIB_EXTRA_DATA",
1705 ++ "ZLIB_BTYPE",
1706 ++ "ZLIB_UNDEFINED_SYMBOL",
1707 ++ "ZLIB_UNDEFINED_DISTANCE_S",
1708 ++ "ZLIB_CODE_LENGTH_SYMBOL",
1709 ++ "ZLIB _VHB_ILLEGAL_FETCH",
1710 ++ "ZLIB_UNCOMPRESSED_LEN",
1711 ++ "ZLIB_LIMIT_REACHED",
1712 ++ "ZLIB_CHECKSUM_MISMATCH0",
1713 ++ "ODMA0_AXI_SLVERR",
1714 ++ "ODMA0_AXI_DECERR",
1715 ++ "0x28 Reserved",
1716 ++ "ODMA1_AXI_SLVERR",
1717 ++ "ODMA1_AXI_DECERR",
1718 + };
1719 +
1720 +-void ccp_log_error(struct ccp_device *d, int e)
1721 ++void ccp_log_error(struct ccp_device *d, unsigned int e)
1722 + {
1723 +- dev_err(d->dev, "CCP error: %s (0x%x)\n", ccp_error_codes[e], e);
1724 ++ if (WARN_ON(e >= CCP_MAX_ERROR_CODE))
1725 ++ return;
1726 ++
1727 ++ if (e < ARRAY_SIZE(ccp_error_codes))
1728 ++ dev_err(d->dev, "CCP error %d: %s\n", e, ccp_error_codes[e]);
1729 ++ else
1730 ++ dev_err(d->dev, "CCP error %d: Unknown Error\n", e);
1731 + }
1732 +
1733 + /* List of CCPs, CCP count, read-write access lock, and access functions
1734 +diff --git a/drivers/crypto/ccp/ccp-dev.h b/drivers/crypto/ccp/ccp-dev.h
1735 +index 6810b65c1939..7442b0422f8a 100644
1736 +--- a/drivers/crypto/ccp/ccp-dev.h
1737 ++++ b/drivers/crypto/ccp/ccp-dev.h
1738 +@@ -632,7 +632,7 @@ struct ccp5_desc {
1739 + void ccp_add_device(struct ccp_device *ccp);
1740 + void ccp_del_device(struct ccp_device *ccp);
1741 +
1742 +-extern void ccp_log_error(struct ccp_device *, int);
1743 ++extern void ccp_log_error(struct ccp_device *, unsigned int);
1744 +
1745 + struct ccp_device *ccp_alloc_struct(struct sp_device *sp);
1746 + bool ccp_queues_suspended(struct ccp_device *ccp);
1747 +diff --git a/drivers/crypto/ccp/ccp-ops.c b/drivers/crypto/ccp/ccp-ops.c
1748 +index 406b95329b3d..73e49840305b 100644
1749 +--- a/drivers/crypto/ccp/ccp-ops.c
1750 ++++ b/drivers/crypto/ccp/ccp-ops.c
1751 +@@ -612,6 +612,7 @@ static int ccp_run_aes_gcm_cmd(struct ccp_cmd_queue *cmd_q,
1752 +
1753 + unsigned long long *final;
1754 + unsigned int dm_offset;
1755 ++ unsigned int jobid;
1756 + unsigned int ilen;
1757 + bool in_place = true; /* Default value */
1758 + int ret;
1759 +@@ -650,9 +651,11 @@ static int ccp_run_aes_gcm_cmd(struct ccp_cmd_queue *cmd_q,
1760 + p_tag = scatterwalk_ffwd(sg_tag, p_inp, ilen);
1761 + }
1762 +
1763 ++ jobid = CCP_NEW_JOBID(cmd_q->ccp);
1764 ++
1765 + memset(&op, 0, sizeof(op));
1766 + op.cmd_q = cmd_q;
1767 +- op.jobid = CCP_NEW_JOBID(cmd_q->ccp);
1768 ++ op.jobid = jobid;
1769 + op.sb_key = cmd_q->sb_key; /* Pre-allocated */
1770 + op.sb_ctx = cmd_q->sb_ctx; /* Pre-allocated */
1771 + op.init = 1;
1772 +@@ -797,6 +800,13 @@ static int ccp_run_aes_gcm_cmd(struct ccp_cmd_queue *cmd_q,
1773 + final[0] = cpu_to_be64(aes->aad_len * 8);
1774 + final[1] = cpu_to_be64(ilen * 8);
1775 +
1776 ++ memset(&op, 0, sizeof(op));
1777 ++ op.cmd_q = cmd_q;
1778 ++ op.jobid = jobid;
1779 ++ op.sb_key = cmd_q->sb_key; /* Pre-allocated */
1780 ++ op.sb_ctx = cmd_q->sb_ctx; /* Pre-allocated */
1781 ++ op.init = 1;
1782 ++ op.u.aes.type = aes->type;
1783 + op.u.aes.mode = CCP_AES_MODE_GHASH;
1784 + op.u.aes.action = CCP_AES_GHASHFINAL;
1785 + op.src.type = CCP_MEMTYPE_SYSTEM;
1786 +@@ -822,7 +832,8 @@ static int ccp_run_aes_gcm_cmd(struct ccp_cmd_queue *cmd_q,
1787 + goto e_tag;
1788 + ccp_set_dm_area(&tag, 0, p_tag, 0, AES_BLOCK_SIZE);
1789 +
1790 +- ret = memcmp(tag.address, final_wa.address, AES_BLOCK_SIZE);
1791 ++ ret = crypto_memneq(tag.address, final_wa.address,
1792 ++ AES_BLOCK_SIZE) ? -EBADMSG : 0;
1793 + ccp_dm_free(&tag);
1794 + }
1795 +
1796 +diff --git a/drivers/crypto/talitos.c b/drivers/crypto/talitos.c
1797 +index 1f8fe1795964..a0cd4f6085d0 100644
1798 +--- a/drivers/crypto/talitos.c
1799 ++++ b/drivers/crypto/talitos.c
1800 +@@ -984,7 +984,6 @@ static void ipsec_esp_encrypt_done(struct device *dev,
1801 + struct crypto_aead *authenc = crypto_aead_reqtfm(areq);
1802 + unsigned int authsize = crypto_aead_authsize(authenc);
1803 + struct talitos_edesc *edesc;
1804 +- struct scatterlist *sg;
1805 + void *icvdata;
1806 +
1807 + edesc = container_of(desc, struct talitos_edesc, desc);
1808 +@@ -998,9 +997,8 @@ static void ipsec_esp_encrypt_done(struct device *dev,
1809 + else
1810 + icvdata = &edesc->link_tbl[edesc->src_nents +
1811 + edesc->dst_nents + 2];
1812 +- sg = sg_last(areq->dst, edesc->dst_nents);
1813 +- memcpy((char *)sg_virt(sg) + sg->length - authsize,
1814 +- icvdata, authsize);
1815 ++ sg_pcopy_from_buffer(areq->dst, edesc->dst_nents ? : 1, icvdata,
1816 ++ authsize, areq->assoclen + areq->cryptlen);
1817 + }
1818 +
1819 + kfree(edesc);
1820 +@@ -1016,7 +1014,6 @@ static void ipsec_esp_decrypt_swauth_done(struct device *dev,
1821 + struct crypto_aead *authenc = crypto_aead_reqtfm(req);
1822 + unsigned int authsize = crypto_aead_authsize(authenc);
1823 + struct talitos_edesc *edesc;
1824 +- struct scatterlist *sg;
1825 + char *oicv, *icv;
1826 + struct talitos_private *priv = dev_get_drvdata(dev);
1827 + bool is_sec1 = has_ftr_sec1(priv);
1828 +@@ -1026,9 +1023,18 @@ static void ipsec_esp_decrypt_swauth_done(struct device *dev,
1829 + ipsec_esp_unmap(dev, edesc, req);
1830 +
1831 + if (!err) {
1832 ++ char icvdata[SHA512_DIGEST_SIZE];
1833 ++ int nents = edesc->dst_nents ? : 1;
1834 ++ unsigned int len = req->assoclen + req->cryptlen;
1835 ++
1836 + /* auth check */
1837 +- sg = sg_last(req->dst, edesc->dst_nents ? : 1);
1838 +- icv = (char *)sg_virt(sg) + sg->length - authsize;
1839 ++ if (nents > 1) {
1840 ++ sg_pcopy_to_buffer(req->dst, nents, icvdata, authsize,
1841 ++ len - authsize);
1842 ++ icv = icvdata;
1843 ++ } else {
1844 ++ icv = (char *)sg_virt(req->dst) + len - authsize;
1845 ++ }
1846 +
1847 + if (edesc->dma_len) {
1848 + if (is_sec1)
1849 +@@ -1458,7 +1464,6 @@ static int aead_decrypt(struct aead_request *req)
1850 + struct talitos_ctx *ctx = crypto_aead_ctx(authenc);
1851 + struct talitos_private *priv = dev_get_drvdata(ctx->dev);
1852 + struct talitos_edesc *edesc;
1853 +- struct scatterlist *sg;
1854 + void *icvdata;
1855 +
1856 + req->cryptlen -= authsize;
1857 +@@ -1493,9 +1498,8 @@ static int aead_decrypt(struct aead_request *req)
1858 + else
1859 + icvdata = &edesc->link_tbl[0];
1860 +
1861 +- sg = sg_last(req->src, edesc->src_nents ? : 1);
1862 +-
1863 +- memcpy(icvdata, (char *)sg_virt(sg) + sg->length - authsize, authsize);
1864 ++ sg_pcopy_to_buffer(req->src, edesc->src_nents ? : 1, icvdata, authsize,
1865 ++ req->assoclen + req->cryptlen - authsize);
1866 +
1867 + return ipsec_esp(edesc, req, ipsec_esp_decrypt_swauth_done);
1868 + }
1869 +@@ -1544,11 +1548,15 @@ static void ablkcipher_done(struct device *dev,
1870 + int err)
1871 + {
1872 + struct ablkcipher_request *areq = context;
1873 ++ struct crypto_ablkcipher *cipher = crypto_ablkcipher_reqtfm(areq);
1874 ++ struct talitos_ctx *ctx = crypto_ablkcipher_ctx(cipher);
1875 ++ unsigned int ivsize = crypto_ablkcipher_ivsize(cipher);
1876 + struct talitos_edesc *edesc;
1877 +
1878 + edesc = container_of(desc, struct talitos_edesc, desc);
1879 +
1880 + common_nonsnoop_unmap(dev, edesc, areq);
1881 ++ memcpy(areq->info, ctx->iv, ivsize);
1882 +
1883 + kfree(edesc);
1884 +
1885 +@@ -3111,7 +3119,10 @@ static struct talitos_crypto_alg *talitos_alg_alloc(struct device *dev,
1886 + alg->cra_priority = t_alg->algt.priority;
1887 + else
1888 + alg->cra_priority = TALITOS_CRA_PRIORITY;
1889 +- alg->cra_alignmask = 0;
1890 ++ if (has_ftr_sec1(priv))
1891 ++ alg->cra_alignmask = 3;
1892 ++ else
1893 ++ alg->cra_alignmask = 0;
1894 + alg->cra_ctxsize = sizeof(struct talitos_ctx);
1895 + alg->cra_flags |= CRYPTO_ALG_KERN_DRIVER_ONLY;
1896 +
1897 +diff --git a/drivers/dma-buf/dma-buf.c b/drivers/dma-buf/dma-buf.c
1898 +index bc1cb284111c..1195a3d2e67c 100644
1899 +--- a/drivers/dma-buf/dma-buf.c
1900 ++++ b/drivers/dma-buf/dma-buf.c
1901 +@@ -1115,6 +1115,7 @@ static int dma_buf_debug_show(struct seq_file *s, void *unused)
1902 + fence->ops->get_driver_name(fence),
1903 + fence->ops->get_timeline_name(fence),
1904 + dma_fence_is_signaled(fence) ? "" : "un");
1905 ++ dma_fence_put(fence);
1906 + }
1907 + rcu_read_unlock();
1908 +
1909 +diff --git a/drivers/dma-buf/reservation.c b/drivers/dma-buf/reservation.c
1910 +index 012fa3d1f407..afc66141066d 100644
1911 +--- a/drivers/dma-buf/reservation.c
1912 ++++ b/drivers/dma-buf/reservation.c
1913 +@@ -394,6 +394,10 @@ int reservation_object_get_fences_rcu(struct reservation_object *obj,
1914 + GFP_NOWAIT | __GFP_NOWARN);
1915 + if (!nshared) {
1916 + rcu_read_unlock();
1917 ++
1918 ++ dma_fence_put(fence_excl);
1919 ++ fence_excl = NULL;
1920 ++
1921 + nshared = krealloc(shared, sz, GFP_KERNEL);
1922 + if (nshared) {
1923 + shared = nshared;
1924 +diff --git a/drivers/dma/imx-sdma.c b/drivers/dma/imx-sdma.c
1925 +index b8e7c2d8915e..0fc12a8783e3 100644
1926 +--- a/drivers/dma/imx-sdma.c
1927 ++++ b/drivers/dma/imx-sdma.c
1928 +@@ -1821,27 +1821,6 @@ static int sdma_probe(struct platform_device *pdev)
1929 + if (pdata && pdata->script_addrs)
1930 + sdma_add_scripts(sdma, pdata->script_addrs);
1931 +
1932 +- if (pdata) {
1933 +- ret = sdma_get_firmware(sdma, pdata->fw_name);
1934 +- if (ret)
1935 +- dev_warn(&pdev->dev, "failed to get firmware from platform data\n");
1936 +- } else {
1937 +- /*
1938 +- * Because that device tree does not encode ROM script address,
1939 +- * the RAM script in firmware is mandatory for device tree
1940 +- * probe, otherwise it fails.
1941 +- */
1942 +- ret = of_property_read_string(np, "fsl,sdma-ram-script-name",
1943 +- &fw_name);
1944 +- if (ret)
1945 +- dev_warn(&pdev->dev, "failed to get firmware name\n");
1946 +- else {
1947 +- ret = sdma_get_firmware(sdma, fw_name);
1948 +- if (ret)
1949 +- dev_warn(&pdev->dev, "failed to get firmware from device tree\n");
1950 +- }
1951 +- }
1952 +-
1953 + sdma->dma_device.dev = &pdev->dev;
1954 +
1955 + sdma->dma_device.device_alloc_chan_resources = sdma_alloc_chan_resources;
1956 +@@ -1883,6 +1862,33 @@ static int sdma_probe(struct platform_device *pdev)
1957 + of_node_put(spba_bus);
1958 + }
1959 +
1960 ++ /*
1961 ++ * Kick off firmware loading as the very last step:
1962 ++ * attempt to load firmware only if we're not on the error path, because
1963 ++ * the firmware callback requires a fully functional and allocated sdma
1964 ++ * instance.
1965 ++ */
1966 ++ if (pdata) {
1967 ++ ret = sdma_get_firmware(sdma, pdata->fw_name);
1968 ++ if (ret)
1969 ++ dev_warn(&pdev->dev, "failed to get firmware from platform data\n");
1970 ++ } else {
1971 ++ /*
1972 ++ * Because that device tree does not encode ROM script address,
1973 ++ * the RAM script in firmware is mandatory for device tree
1974 ++ * probe, otherwise it fails.
1975 ++ */
1976 ++ ret = of_property_read_string(np, "fsl,sdma-ram-script-name",
1977 ++ &fw_name);
1978 ++ if (ret) {
1979 ++ dev_warn(&pdev->dev, "failed to get firmware name\n");
1980 ++ } else {
1981 ++ ret = sdma_get_firmware(sdma, fw_name);
1982 ++ if (ret)
1983 ++ dev_warn(&pdev->dev, "failed to get firmware from device tree\n");
1984 ++ }
1985 ++ }
1986 ++
1987 + return 0;
1988 +
1989 + err_register:
1990 +diff --git a/drivers/edac/edac_mc_sysfs.c b/drivers/edac/edac_mc_sysfs.c
1991 +index 79c13301bf41..a4acfa81dfe0 100644
1992 +--- a/drivers/edac/edac_mc_sysfs.c
1993 ++++ b/drivers/edac/edac_mc_sysfs.c
1994 +@@ -26,7 +26,7 @@
1995 + static int edac_mc_log_ue = 1;
1996 + static int edac_mc_log_ce = 1;
1997 + static int edac_mc_panic_on_ue;
1998 +-static int edac_mc_poll_msec = 1000;
1999 ++static unsigned int edac_mc_poll_msec = 1000;
2000 +
2001 + /* Getter functions for above */
2002 + int edac_mc_get_log_ue(void)
2003 +@@ -45,30 +45,30 @@ int edac_mc_get_panic_on_ue(void)
2004 + }
2005 +
2006 + /* this is temporary */
2007 +-int edac_mc_get_poll_msec(void)
2008 ++unsigned int edac_mc_get_poll_msec(void)
2009 + {
2010 + return edac_mc_poll_msec;
2011 + }
2012 +
2013 + static int edac_set_poll_msec(const char *val, struct kernel_param *kp)
2014 + {
2015 +- unsigned long l;
2016 ++ unsigned int i;
2017 + int ret;
2018 +
2019 + if (!val)
2020 + return -EINVAL;
2021 +
2022 +- ret = kstrtoul(val, 0, &l);
2023 ++ ret = kstrtouint(val, 0, &i);
2024 + if (ret)
2025 + return ret;
2026 +
2027 +- if (l < 1000)
2028 ++ if (i < 1000)
2029 + return -EINVAL;
2030 +
2031 +- *((unsigned long *)kp->arg) = l;
2032 ++ *((unsigned int *)kp->arg) = i;
2033 +
2034 + /* notify edac_mc engine to reset the poll period */
2035 +- edac_mc_reset_delay_period(l);
2036 ++ edac_mc_reset_delay_period(i);
2037 +
2038 + return 0;
2039 + }
2040 +@@ -82,7 +82,7 @@ MODULE_PARM_DESC(edac_mc_log_ue,
2041 + module_param(edac_mc_log_ce, int, 0644);
2042 + MODULE_PARM_DESC(edac_mc_log_ce,
2043 + "Log correctable error to console: 0=off 1=on");
2044 +-module_param_call(edac_mc_poll_msec, edac_set_poll_msec, param_get_int,
2045 ++module_param_call(edac_mc_poll_msec, edac_set_poll_msec, param_get_uint,
2046 + &edac_mc_poll_msec, 0644);
2047 + MODULE_PARM_DESC(edac_mc_poll_msec, "Polling period in milliseconds");
2048 +
2049 +@@ -426,6 +426,8 @@ static inline int nr_pages_per_csrow(struct csrow_info *csrow)
2050 + static int edac_create_csrow_object(struct mem_ctl_info *mci,
2051 + struct csrow_info *csrow, int index)
2052 + {
2053 ++ int err;
2054 ++
2055 + csrow->dev.type = &csrow_attr_type;
2056 + csrow->dev.bus = mci->bus;
2057 + csrow->dev.groups = csrow_dev_groups;
2058 +@@ -438,7 +440,11 @@ static int edac_create_csrow_object(struct mem_ctl_info *mci,
2059 + edac_dbg(0, "creating (virtual) csrow node %s\n",
2060 + dev_name(&csrow->dev));
2061 +
2062 +- return device_add(&csrow->dev);
2063 ++ err = device_add(&csrow->dev);
2064 ++ if (err)
2065 ++ put_device(&csrow->dev);
2066 ++
2067 ++ return err;
2068 + }
2069 +
2070 + /* Create a CSROW object under specifed edac_mc_device */
2071 +diff --git a/drivers/edac/edac_module.h b/drivers/edac/edac_module.h
2072 +index dec88dcea036..c9f0e73872a6 100644
2073 +--- a/drivers/edac/edac_module.h
2074 ++++ b/drivers/edac/edac_module.h
2075 +@@ -36,7 +36,7 @@ extern int edac_mc_get_log_ue(void);
2076 + extern int edac_mc_get_log_ce(void);
2077 + extern int edac_mc_get_panic_on_ue(void);
2078 + extern int edac_get_poll_msec(void);
2079 +-extern int edac_mc_get_poll_msec(void);
2080 ++extern unsigned int edac_mc_get_poll_msec(void);
2081 +
2082 + unsigned edac_dimm_info_location(struct dimm_info *dimm, char *buf,
2083 + unsigned len);
2084 +diff --git a/drivers/fpga/Kconfig b/drivers/fpga/Kconfig
2085 +index ad5448f718b3..57c41cefd454 100644
2086 +--- a/drivers/fpga/Kconfig
2087 ++++ b/drivers/fpga/Kconfig
2088 +@@ -34,6 +34,7 @@ config FPGA_MGR_ALTERA_CVP
2089 + config FPGA_MGR_ALTERA_PS_SPI
2090 + tristate "Altera FPGA Passive Serial over SPI"
2091 + depends on SPI
2092 ++ select BITREVERSE
2093 + help
2094 + FPGA manager driver support for Altera Arria/Cyclone/Stratix
2095 + using the passive serial interface over SPI.
2096 +diff --git a/drivers/gpio/gpio-omap.c b/drivers/gpio/gpio-omap.c
2097 +index 83c6843db50c..47e537a91dd8 100644
2098 +--- a/drivers/gpio/gpio-omap.c
2099 ++++ b/drivers/gpio/gpio-omap.c
2100 +@@ -790,9 +790,9 @@ static void omap_gpio_irq_shutdown(struct irq_data *d)
2101 +
2102 + raw_spin_lock_irqsave(&bank->lock, flags);
2103 + bank->irq_usage &= ~(BIT(offset));
2104 +- omap_set_gpio_irqenable(bank, offset, 0);
2105 +- omap_clear_gpio_irqstatus(bank, offset);
2106 + omap_set_gpio_triggering(bank, offset, IRQ_TYPE_NONE);
2107 ++ omap_clear_gpio_irqstatus(bank, offset);
2108 ++ omap_set_gpio_irqenable(bank, offset, 0);
2109 + if (!LINE_USED(bank->mod_usage, offset))
2110 + omap_clear_gpio_debounce(bank, offset);
2111 + omap_disable_gpio_module(bank, offset);
2112 +@@ -834,8 +834,8 @@ static void omap_gpio_mask_irq(struct irq_data *d)
2113 + unsigned long flags;
2114 +
2115 + raw_spin_lock_irqsave(&bank->lock, flags);
2116 +- omap_set_gpio_irqenable(bank, offset, 0);
2117 + omap_set_gpio_triggering(bank, offset, IRQ_TYPE_NONE);
2118 ++ omap_set_gpio_irqenable(bank, offset, 0);
2119 + raw_spin_unlock_irqrestore(&bank->lock, flags);
2120 + }
2121 +
2122 +@@ -847,9 +847,6 @@ static void omap_gpio_unmask_irq(struct irq_data *d)
2123 + unsigned long flags;
2124 +
2125 + raw_spin_lock_irqsave(&bank->lock, flags);
2126 +- if (trigger)
2127 +- omap_set_gpio_triggering(bank, offset, trigger);
2128 +-
2129 + omap_set_gpio_irqenable(bank, offset, 1);
2130 +
2131 + /*
2132 +@@ -857,9 +854,13 @@ static void omap_gpio_unmask_irq(struct irq_data *d)
2133 + * is cleared, thus after the handler has run. OMAP4 needs this done
2134 + * after enabing the interrupt to clear the wakeup status.
2135 + */
2136 +- if (bank->level_mask & BIT(offset))
2137 ++ if (bank->regs->leveldetect0 && bank->regs->wkup_en &&
2138 ++ trigger & (IRQ_TYPE_LEVEL_HIGH | IRQ_TYPE_LEVEL_LOW))
2139 + omap_clear_gpio_irqstatus(bank, offset);
2140 +
2141 ++ if (trigger)
2142 ++ omap_set_gpio_triggering(bank, offset, trigger);
2143 ++
2144 + raw_spin_unlock_irqrestore(&bank->lock, flags);
2145 + }
2146 +
2147 +@@ -1604,6 +1605,8 @@ static struct omap_gpio_reg_offs omap4_gpio_regs = {
2148 + .clr_dataout = OMAP4_GPIO_CLEARDATAOUT,
2149 + .irqstatus = OMAP4_GPIO_IRQSTATUS0,
2150 + .irqstatus2 = OMAP4_GPIO_IRQSTATUS1,
2151 ++ .irqstatus_raw0 = OMAP4_GPIO_IRQSTATUSRAW0,
2152 ++ .irqstatus_raw1 = OMAP4_GPIO_IRQSTATUSRAW1,
2153 + .irqenable = OMAP4_GPIO_IRQSTATUSSET0,
2154 + .irqenable2 = OMAP4_GPIO_IRQSTATUSSET1,
2155 + .set_irqenable = OMAP4_GPIO_IRQSTATUSSET0,
2156 +diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
2157 +index 21062cb6b85f..3db0a9b0d259 100644
2158 +--- a/drivers/gpio/gpiolib.c
2159 ++++ b/drivers/gpio/gpiolib.c
2160 +@@ -2480,7 +2480,7 @@ static int _gpiod_get_raw_value(const struct gpio_desc *desc)
2161 + int gpiod_get_raw_value(const struct gpio_desc *desc)
2162 + {
2163 + VALIDATE_DESC(desc);
2164 +- /* Should be using gpio_get_value_cansleep() */
2165 ++ /* Should be using gpiod_get_raw_value_cansleep() */
2166 + WARN_ON(desc->gdev->chip->can_sleep);
2167 + return _gpiod_get_raw_value(desc);
2168 + }
2169 +@@ -2501,7 +2501,7 @@ int gpiod_get_value(const struct gpio_desc *desc)
2170 + int value;
2171 +
2172 + VALIDATE_DESC(desc);
2173 +- /* Should be using gpio_get_value_cansleep() */
2174 ++ /* Should be using gpiod_get_value_cansleep() */
2175 + WARN_ON(desc->gdev->chip->can_sleep);
2176 +
2177 + value = _gpiod_get_raw_value(desc);
2178 +@@ -2670,7 +2670,7 @@ void gpiod_set_array_value_complex(bool raw, bool can_sleep,
2179 + void gpiod_set_raw_value(struct gpio_desc *desc, int value)
2180 + {
2181 + VALIDATE_DESC_VOID(desc);
2182 +- /* Should be using gpiod_set_value_cansleep() */
2183 ++ /* Should be using gpiod_set_raw_value_cansleep() */
2184 + WARN_ON(desc->gdev->chip->can_sleep);
2185 + _gpiod_set_raw_value(desc, value);
2186 + }
2187 +diff --git a/drivers/gpu/drm/bridge/sii902x.c b/drivers/gpu/drm/bridge/sii902x.c
2188 +index 60373d7eb220..109ab4c3df50 100644
2189 +--- a/drivers/gpu/drm/bridge/sii902x.c
2190 ++++ b/drivers/gpu/drm/bridge/sii902x.c
2191 +@@ -261,10 +261,11 @@ static void sii902x_bridge_mode_set(struct drm_bridge *bridge,
2192 + struct regmap *regmap = sii902x->regmap;
2193 + u8 buf[HDMI_INFOFRAME_SIZE(AVI)];
2194 + struct hdmi_avi_infoframe frame;
2195 ++ u16 pixel_clock_10kHz = adj->clock / 10;
2196 + int ret;
2197 +
2198 +- buf[0] = adj->clock;
2199 +- buf[1] = adj->clock >> 8;
2200 ++ buf[0] = pixel_clock_10kHz & 0xff;
2201 ++ buf[1] = pixel_clock_10kHz >> 8;
2202 + buf[2] = adj->vrefresh;
2203 + buf[3] = 0x00;
2204 + buf[4] = adj->hdisplay;
2205 +diff --git a/drivers/gpu/drm/bridge/tc358767.c b/drivers/gpu/drm/bridge/tc358767.c
2206 +index 6eebd8ad0c52..9705ca197b90 100644
2207 +--- a/drivers/gpu/drm/bridge/tc358767.c
2208 ++++ b/drivers/gpu/drm/bridge/tc358767.c
2209 +@@ -1147,6 +1147,13 @@ static int tc_connector_get_modes(struct drm_connector *connector)
2210 + struct tc_data *tc = connector_to_tc(connector);
2211 + struct edid *edid;
2212 + unsigned int count;
2213 ++ int ret;
2214 ++
2215 ++ ret = tc_get_display_props(tc);
2216 ++ if (ret < 0) {
2217 ++ dev_err(tc->dev, "failed to read display props: %d\n", ret);
2218 ++ return 0;
2219 ++ }
2220 +
2221 + if (tc->panel && tc->panel->funcs && tc->panel->funcs->get_modes) {
2222 + count = tc->panel->funcs->get_modes(tc->panel);
2223 +diff --git a/drivers/gpu/drm/drm_debugfs_crc.c b/drivers/gpu/drm/drm_debugfs_crc.c
2224 +index f9e26dda56d6..2901b7944068 100644
2225 +--- a/drivers/gpu/drm/drm_debugfs_crc.c
2226 ++++ b/drivers/gpu/drm/drm_debugfs_crc.c
2227 +@@ -139,6 +139,7 @@ static int crtc_crc_data_count(struct drm_crtc_crc *crc)
2228 + static void crtc_crc_cleanup(struct drm_crtc_crc *crc)
2229 + {
2230 + kfree(crc->entries);
2231 ++ crc->overflow = false;
2232 + crc->entries = NULL;
2233 + crc->head = 0;
2234 + crc->tail = 0;
2235 +@@ -359,12 +360,13 @@ int drm_crtc_add_crc_entry(struct drm_crtc *crtc, bool has_frame,
2236 + struct drm_crtc_crc *crc = &crtc->crc;
2237 + struct drm_crtc_crc_entry *entry;
2238 + int head, tail;
2239 ++ unsigned long flags;
2240 +
2241 +- spin_lock(&crc->lock);
2242 ++ spin_lock_irqsave(&crc->lock, flags);
2243 +
2244 + /* Caller may not have noticed yet that userspace has stopped reading */
2245 + if (!crc->entries) {
2246 +- spin_unlock(&crc->lock);
2247 ++ spin_unlock_irqrestore(&crc->lock, flags);
2248 + return -EINVAL;
2249 + }
2250 +
2251 +@@ -372,8 +374,14 @@ int drm_crtc_add_crc_entry(struct drm_crtc *crtc, bool has_frame,
2252 + tail = crc->tail;
2253 +
2254 + if (CIRC_SPACE(head, tail, DRM_CRC_ENTRIES_NR) < 1) {
2255 +- spin_unlock(&crc->lock);
2256 +- DRM_ERROR("Overflow of CRC buffer, userspace reads too slow.\n");
2257 ++ bool was_overflow = crc->overflow;
2258 ++
2259 ++ crc->overflow = true;
2260 ++ spin_unlock_irqrestore(&crc->lock, flags);
2261 ++
2262 ++ if (!was_overflow)
2263 ++ DRM_ERROR("Overflow of CRC buffer, userspace reads too slow.\n");
2264 ++
2265 + return -ENOBUFS;
2266 + }
2267 +
2268 +@@ -385,7 +393,7 @@ int drm_crtc_add_crc_entry(struct drm_crtc *crtc, bool has_frame,
2269 + head = (head + 1) & (DRM_CRC_ENTRIES_NR - 1);
2270 + crc->head = head;
2271 +
2272 +- spin_unlock(&crc->lock);
2273 ++ spin_unlock_irqrestore(&crc->lock, flags);
2274 +
2275 + wake_up_interruptible(&crc->wq);
2276 +
2277 +diff --git a/drivers/gpu/drm/drm_edid_load.c b/drivers/gpu/drm/drm_edid_load.c
2278 +index 1c0495acf341..06656acea420 100644
2279 +--- a/drivers/gpu/drm/drm_edid_load.c
2280 ++++ b/drivers/gpu/drm/drm_edid_load.c
2281 +@@ -274,6 +274,8 @@ struct edid *drm_load_edid_firmware(struct drm_connector *connector)
2282 + * the last one found one as a fallback.
2283 + */
2284 + fwstr = kstrdup(edid_firmware, GFP_KERNEL);
2285 ++ if (!fwstr)
2286 ++ return ERR_PTR(-ENOMEM);
2287 + edidstr = fwstr;
2288 +
2289 + while ((edidname = strsep(&edidstr, ","))) {
2290 +diff --git a/drivers/gpu/drm/msm/msm_drv.c b/drivers/gpu/drm/msm/msm_drv.c
2291 +index 606df7bea97b..b970427e53a7 100644
2292 +--- a/drivers/gpu/drm/msm/msm_drv.c
2293 ++++ b/drivers/gpu/drm/msm/msm_drv.c
2294 +@@ -1097,16 +1097,24 @@ static int msm_pdev_probe(struct platform_device *pdev)
2295 +
2296 + ret = add_gpu_components(&pdev->dev, &match);
2297 + if (ret)
2298 +- return ret;
2299 ++ goto fail;
2300 +
2301 + /* on all devices that I am aware of, iommu's which can map
2302 + * any address the cpu can see are used:
2303 + */
2304 + ret = dma_set_mask_and_coherent(&pdev->dev, ~0);
2305 + if (ret)
2306 +- return ret;
2307 ++ goto fail;
2308 ++
2309 ++ ret = component_master_add_with_match(&pdev->dev, &msm_drm_ops, match);
2310 ++ if (ret)
2311 ++ goto fail;
2312 ++
2313 ++ return 0;
2314 +
2315 +- return component_master_add_with_match(&pdev->dev, &msm_drm_ops, match);
2316 ++fail:
2317 ++ of_platform_depopulate(&pdev->dev);
2318 ++ return ret;
2319 + }
2320 +
2321 + static int msm_pdev_remove(struct platform_device *pdev)
2322 +diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/i2c/base.c b/drivers/gpu/drm/nouveau/nvkm/subdev/i2c/base.c
2323 +index ecacb22834d7..719345074711 100644
2324 +--- a/drivers/gpu/drm/nouveau/nvkm/subdev/i2c/base.c
2325 ++++ b/drivers/gpu/drm/nouveau/nvkm/subdev/i2c/base.c
2326 +@@ -184,6 +184,25 @@ nvkm_i2c_fini(struct nvkm_subdev *subdev, bool suspend)
2327 + return 0;
2328 + }
2329 +
2330 ++static int
2331 ++nvkm_i2c_preinit(struct nvkm_subdev *subdev)
2332 ++{
2333 ++ struct nvkm_i2c *i2c = nvkm_i2c(subdev);
2334 ++ struct nvkm_i2c_bus *bus;
2335 ++ struct nvkm_i2c_pad *pad;
2336 ++
2337 ++ /*
2338 ++ * We init our i2c busses as early as possible, since they may be
2339 ++ * needed by the vbios init scripts on some cards
2340 ++ */
2341 ++ list_for_each_entry(pad, &i2c->pad, head)
2342 ++ nvkm_i2c_pad_init(pad);
2343 ++ list_for_each_entry(bus, &i2c->bus, head)
2344 ++ nvkm_i2c_bus_init(bus);
2345 ++
2346 ++ return 0;
2347 ++}
2348 ++
2349 + static int
2350 + nvkm_i2c_init(struct nvkm_subdev *subdev)
2351 + {
2352 +@@ -238,6 +257,7 @@ nvkm_i2c_dtor(struct nvkm_subdev *subdev)
2353 + static const struct nvkm_subdev_func
2354 + nvkm_i2c = {
2355 + .dtor = nvkm_i2c_dtor,
2356 ++ .preinit = nvkm_i2c_preinit,
2357 + .init = nvkm_i2c_init,
2358 + .fini = nvkm_i2c_fini,
2359 + .intr = nvkm_i2c_intr,
2360 +diff --git a/drivers/gpu/drm/panel/panel-simple.c b/drivers/gpu/drm/panel/panel-simple.c
2361 +index fc56d033febe..7a0fd4e4e78d 100644
2362 +--- a/drivers/gpu/drm/panel/panel-simple.c
2363 ++++ b/drivers/gpu/drm/panel/panel-simple.c
2364 +@@ -2371,7 +2371,14 @@ static int panel_simple_dsi_probe(struct mipi_dsi_device *dsi)
2365 + dsi->format = desc->format;
2366 + dsi->lanes = desc->lanes;
2367 +
2368 +- return mipi_dsi_attach(dsi);
2369 ++ err = mipi_dsi_attach(dsi);
2370 ++ if (err) {
2371 ++ struct panel_simple *panel = dev_get_drvdata(&dsi->dev);
2372 ++
2373 ++ drm_panel_remove(&panel->base);
2374 ++ }
2375 ++
2376 ++ return err;
2377 + }
2378 +
2379 + static int panel_simple_dsi_remove(struct mipi_dsi_device *dsi)
2380 +diff --git a/drivers/gpu/drm/rockchip/rockchip_drm_vop.c b/drivers/gpu/drm/rockchip/rockchip_drm_vop.c
2381 +index f1fa8d5c9b52..7010424b2f89 100644
2382 +--- a/drivers/gpu/drm/rockchip/rockchip_drm_vop.c
2383 ++++ b/drivers/gpu/drm/rockchip/rockchip_drm_vop.c
2384 +@@ -861,7 +861,8 @@ static bool vop_crtc_mode_fixup(struct drm_crtc *crtc,
2385 + struct vop *vop = to_vop(crtc);
2386 +
2387 + adjusted_mode->clock =
2388 +- clk_round_rate(vop->dclk, mode->clock * 1000) / 1000;
2389 ++ DIV_ROUND_UP(clk_round_rate(vop->dclk, mode->clock * 1000),
2390 ++ 1000);
2391 +
2392 + return true;
2393 + }
2394 +diff --git a/drivers/gpu/drm/virtio/virtgpu_ioctl.c b/drivers/gpu/drm/virtio/virtgpu_ioctl.c
2395 +index ed9c443bb8a1..40cc2f6707cf 100644
2396 +--- a/drivers/gpu/drm/virtio/virtgpu_ioctl.c
2397 ++++ b/drivers/gpu/drm/virtio/virtgpu_ioctl.c
2398 +@@ -523,6 +523,9 @@ static int virtio_gpu_get_caps_ioctl(struct drm_device *dev,
2399 + ret = wait_event_timeout(vgdev->resp_wq,
2400 + atomic_read(&cache_ent->is_valid), 5 * HZ);
2401 +
2402 ++ /* is_valid check must proceed before copy of the cache entry. */
2403 ++ smp_rmb();
2404 ++
2405 + ptr = cache_ent->caps_cache;
2406 +
2407 + copy_exit:
2408 +diff --git a/drivers/gpu/drm/virtio/virtgpu_vq.c b/drivers/gpu/drm/virtio/virtgpu_vq.c
2409 +index 26a2da1f712d..21c2de81f3e3 100644
2410 +--- a/drivers/gpu/drm/virtio/virtgpu_vq.c
2411 ++++ b/drivers/gpu/drm/virtio/virtgpu_vq.c
2412 +@@ -585,6 +585,8 @@ static void virtio_gpu_cmd_capset_cb(struct virtio_gpu_device *vgdev,
2413 + cache_ent->id == le32_to_cpu(cmd->capset_id)) {
2414 + memcpy(cache_ent->caps_cache, resp->capset_data,
2415 + cache_ent->size);
2416 ++ /* Copy must occur before is_valid is signalled. */
2417 ++ smp_wmb();
2418 + atomic_set(&cache_ent->is_valid, 1);
2419 + break;
2420 + }
2421 +diff --git a/drivers/gpu/ipu-v3/ipu-ic.c b/drivers/gpu/ipu-v3/ipu-ic.c
2422 +index 321eb983c2f5..65d7daf944b0 100644
2423 +--- a/drivers/gpu/ipu-v3/ipu-ic.c
2424 ++++ b/drivers/gpu/ipu-v3/ipu-ic.c
2425 +@@ -256,7 +256,7 @@ static int init_csc(struct ipu_ic *ic,
2426 + writel(param, base++);
2427 +
2428 + param = ((a[0] & 0x1fe0) >> 5) | (params->scale << 8) |
2429 +- (params->sat << 9);
2430 ++ (params->sat << 10);
2431 + writel(param, base++);
2432 +
2433 + param = ((a[1] & 0x1f) << 27) | ((c[0][1] & 0x1ff) << 18) |
2434 +diff --git a/drivers/hid/wacom_sys.c b/drivers/hid/wacom_sys.c
2435 +index 18d5b99d13f1..ee87f11e8cd5 100644
2436 +--- a/drivers/hid/wacom_sys.c
2437 ++++ b/drivers/hid/wacom_sys.c
2438 +@@ -118,6 +118,9 @@ static void wacom_feature_mapping(struct hid_device *hdev,
2439 + u32 n;
2440 +
2441 + switch (equivalent_usage) {
2442 ++ case WACOM_HID_WD_TOUCH_RING_SETTING:
2443 ++ wacom->generic_has_leds = true;
2444 ++ break;
2445 + case HID_DG_CONTACTMAX:
2446 + /* leave touch_max as is if predefined */
2447 + if (!features->touch_max) {
2448 +diff --git a/drivers/hid/wacom_wac.c b/drivers/hid/wacom_wac.c
2449 +index b42bb955f22d..c2fb08bba296 100644
2450 +--- a/drivers/hid/wacom_wac.c
2451 ++++ b/drivers/hid/wacom_wac.c
2452 +@@ -1871,8 +1871,6 @@ static void wacom_wac_pad_usage_mapping(struct hid_device *hdev,
2453 + features->device_type |= WACOM_DEVICETYPE_PAD;
2454 + break;
2455 + case WACOM_HID_WD_BUTTONCENTER:
2456 +- wacom->generic_has_leds = true;
2457 +- /* fall through */
2458 + case WACOM_HID_WD_BUTTONHOME:
2459 + case WACOM_HID_WD_BUTTONUP:
2460 + case WACOM_HID_WD_BUTTONDOWN:
2461 +@@ -3552,7 +3550,7 @@ int wacom_setup_touch_input_capabilities(struct input_dev *input_dev,
2462 + 0, 5920, 4, 0);
2463 + }
2464 + input_abs_set_res(input_dev, ABS_MT_POSITION_X, 40);
2465 +- input_abs_set_res(input_dev, ABS_MT_POSITION_X, 40);
2466 ++ input_abs_set_res(input_dev, ABS_MT_POSITION_Y, 40);
2467 +
2468 + /* fall through */
2469 +
2470 +diff --git a/drivers/hid/wacom_wac.h b/drivers/hid/wacom_wac.h
2471 +index feb62fd4dfc3..d2fe7af2c152 100644
2472 +--- a/drivers/hid/wacom_wac.h
2473 ++++ b/drivers/hid/wacom_wac.h
2474 +@@ -140,6 +140,7 @@
2475 + #define WACOM_HID_WD_OFFSETBOTTOM (WACOM_HID_UP_WACOMDIGITIZER | 0x0d33)
2476 + #define WACOM_HID_WD_DATAMODE (WACOM_HID_UP_WACOMDIGITIZER | 0x1002)
2477 + #define WACOM_HID_WD_DIGITIZERINFO (WACOM_HID_UP_WACOMDIGITIZER | 0x1013)
2478 ++#define WACOM_HID_WD_TOUCH_RING_SETTING (WACOM_HID_UP_WACOMDIGITIZER | 0x1032)
2479 + #define WACOM_HID_UP_G9 0xff090000
2480 + #define WACOM_HID_G9_PEN (WACOM_HID_UP_G9 | 0x02)
2481 + #define WACOM_HID_G9_TOUCHSCREEN (WACOM_HID_UP_G9 | 0x11)
2482 +diff --git a/drivers/hwtracing/intel_th/msu.c b/drivers/hwtracing/intel_th/msu.c
2483 +index 36016c09dd96..6ebf6a2edb33 100644
2484 +--- a/drivers/hwtracing/intel_th/msu.c
2485 ++++ b/drivers/hwtracing/intel_th/msu.c
2486 +@@ -640,7 +640,7 @@ static int msc_buffer_contig_alloc(struct msc *msc, unsigned long size)
2487 + goto err_out;
2488 +
2489 + ret = -ENOMEM;
2490 +- page = alloc_pages(GFP_KERNEL | __GFP_ZERO, order);
2491 ++ page = alloc_pages(GFP_KERNEL | __GFP_ZERO | GFP_DMA32, order);
2492 + if (!page)
2493 + goto err_free_sgt;
2494 +
2495 +diff --git a/drivers/hwtracing/intel_th/pci.c b/drivers/hwtracing/intel_th/pci.c
2496 +index eb8444faa14e..c001a37b7055 100644
2497 +--- a/drivers/hwtracing/intel_th/pci.c
2498 ++++ b/drivers/hwtracing/intel_th/pci.c
2499 +@@ -178,6 +178,11 @@ static const struct pci_device_id intel_th_pci_id_table[] = {
2500 + PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x02a6),
2501 + .driver_data = (kernel_ulong_t)&intel_th_2x,
2502 + },
2503 ++ {
2504 ++ /* Ice Lake NNPI */
2505 ++ PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x45c5),
2506 ++ .driver_data = (kernel_ulong_t)&intel_th_2x,
2507 ++ },
2508 + { 0 },
2509 + };
2510 +
2511 +diff --git a/drivers/infiniband/hw/i40iw/i40iw_verbs.c b/drivers/infiniband/hw/i40iw/i40iw_verbs.c
2512 +index c1021b4afb41..57bfe4808247 100644
2513 +--- a/drivers/infiniband/hw/i40iw/i40iw_verbs.c
2514 ++++ b/drivers/infiniband/hw/i40iw/i40iw_verbs.c
2515 +@@ -821,6 +821,8 @@ static int i40iw_query_qp(struct ib_qp *ibqp,
2516 + struct i40iw_qp *iwqp = to_iwqp(ibqp);
2517 + struct i40iw_sc_qp *qp = &iwqp->sc_qp;
2518 +
2519 ++ attr->qp_state = iwqp->ibqp_state;
2520 ++ attr->cur_qp_state = attr->qp_state;
2521 + attr->qp_access_flags = 0;
2522 + attr->cap.max_send_wr = qp->qp_uk.sq_size;
2523 + attr->cap.max_recv_wr = qp->qp_uk.rq_size;
2524 +diff --git a/drivers/infiniband/sw/rxe/rxe_resp.c b/drivers/infiniband/sw/rxe/rxe_resp.c
2525 +index 74328561bee2..9207682b7a2e 100644
2526 +--- a/drivers/infiniband/sw/rxe/rxe_resp.c
2527 ++++ b/drivers/infiniband/sw/rxe/rxe_resp.c
2528 +@@ -435,6 +435,7 @@ static enum resp_states check_rkey(struct rxe_qp *qp,
2529 + qp->resp.va = reth_va(pkt);
2530 + qp->resp.rkey = reth_rkey(pkt);
2531 + qp->resp.resid = reth_len(pkt);
2532 ++ qp->resp.length = reth_len(pkt);
2533 + }
2534 + access = (pkt->mask & RXE_READ_MASK) ? IB_ACCESS_REMOTE_READ
2535 + : IB_ACCESS_REMOTE_WRITE;
2536 +@@ -860,7 +861,9 @@ static enum resp_states do_complete(struct rxe_qp *qp,
2537 + pkt->mask & RXE_WRITE_MASK) ?
2538 + IB_WC_RECV_RDMA_WITH_IMM : IB_WC_RECV;
2539 + wc->vendor_err = 0;
2540 +- wc->byte_len = wqe->dma.length - wqe->dma.resid;
2541 ++ wc->byte_len = (pkt->mask & RXE_IMMDT_MASK &&
2542 ++ pkt->mask & RXE_WRITE_MASK) ?
2543 ++ qp->resp.length : wqe->dma.length - wqe->dma.resid;
2544 +
2545 + /* fields after byte_len are different between kernel and user
2546 + * space
2547 +diff --git a/drivers/infiniband/sw/rxe/rxe_verbs.h b/drivers/infiniband/sw/rxe/rxe_verbs.h
2548 +index 59f6a24db064..b2b76a316eba 100644
2549 +--- a/drivers/infiniband/sw/rxe/rxe_verbs.h
2550 ++++ b/drivers/infiniband/sw/rxe/rxe_verbs.h
2551 +@@ -214,6 +214,7 @@ struct rxe_resp_info {
2552 + struct rxe_mem *mr;
2553 + u32 resid;
2554 + u32 rkey;
2555 ++ u32 length;
2556 + u64 atomic_orig;
2557 +
2558 + /* SRQ only */
2559 +diff --git a/drivers/infiniband/ulp/ipoib/ipoib_main.c b/drivers/infiniband/ulp/ipoib/ipoib_main.c
2560 +index e6ff16b27acd..1a93d3d58c8a 100644
2561 +--- a/drivers/infiniband/ulp/ipoib/ipoib_main.c
2562 ++++ b/drivers/infiniband/ulp/ipoib/ipoib_main.c
2563 +@@ -1833,6 +1833,7 @@ static int ipoib_get_vf_config(struct net_device *dev, int vf,
2564 + return err;
2565 +
2566 + ivf->vf = vf;
2567 ++ memcpy(ivf->mac, dev->dev_addr, dev->addr_len);
2568 +
2569 + return 0;
2570 + }
2571 +diff --git a/drivers/input/mouse/alps.c b/drivers/input/mouse/alps.c
2572 +index 9a234da8cac2..21bb1ed97f9f 100644
2573 +--- a/drivers/input/mouse/alps.c
2574 ++++ b/drivers/input/mouse/alps.c
2575 +@@ -24,6 +24,7 @@
2576 +
2577 + #include "psmouse.h"
2578 + #include "alps.h"
2579 ++#include "trackpoint.h"
2580 +
2581 + /*
2582 + * Definitions for ALPS version 3 and 4 command mode protocol
2583 +@@ -2860,6 +2861,23 @@ static const struct alps_protocol_info *alps_match_table(unsigned char *e7,
2584 + return NULL;
2585 + }
2586 +
2587 ++static bool alps_is_cs19_trackpoint(struct psmouse *psmouse)
2588 ++{
2589 ++ u8 param[2] = { 0 };
2590 ++
2591 ++ if (ps2_command(&psmouse->ps2dev,
2592 ++ param, MAKE_PS2_CMD(0, 2, TP_READ_ID)))
2593 ++ return false;
2594 ++
2595 ++ /*
2596 ++ * param[0] contains the trackpoint device variant_id while
2597 ++ * param[1] contains the firmware_id. So far all alps
2598 ++ * trackpoint-only devices have their variant_ids equal
2599 ++ * TP_VARIANT_ALPS and their firmware_ids are in 0x20~0x2f range.
2600 ++ */
2601 ++ return param[0] == TP_VARIANT_ALPS && ((param[1] & 0xf0) == 0x20);
2602 ++}
2603 ++
2604 + static int alps_identify(struct psmouse *psmouse, struct alps_data *priv)
2605 + {
2606 + const struct alps_protocol_info *protocol;
2607 +@@ -3160,6 +3178,20 @@ int alps_detect(struct psmouse *psmouse, bool set_properties)
2608 + if (error)
2609 + return error;
2610 +
2611 ++ /*
2612 ++ * ALPS cs19 is a trackpoint-only device, and uses different
2613 ++ * protocol than DualPoint ones, so we return -EINVAL here and let
2614 ++ * trackpoint.c drive this device. If the trackpoint driver is not
2615 ++ * enabled, the device will fall back to a bare PS/2 mouse.
2616 ++ * If ps2_command() fails here, we depend on the immediately
2617 ++ * followed psmouse_reset() to reset the device to normal state.
2618 ++ */
2619 ++ if (alps_is_cs19_trackpoint(psmouse)) {
2620 ++ psmouse_dbg(psmouse,
2621 ++ "ALPS CS19 trackpoint-only device detected, ignoring\n");
2622 ++ return -EINVAL;
2623 ++ }
2624 ++
2625 + /*
2626 + * Reset the device to make sure it is fully operational:
2627 + * on some laptops, like certain Dell Latitudes, we may
2628 +diff --git a/drivers/input/mouse/synaptics.c b/drivers/input/mouse/synaptics.c
2629 +index 1a6a05c45ee7..7c8d4baf647b 100644
2630 +--- a/drivers/input/mouse/synaptics.c
2631 ++++ b/drivers/input/mouse/synaptics.c
2632 +@@ -179,6 +179,7 @@ static const char * const smbus_pnp_ids[] = {
2633 + "LEN0093", /* T480 */
2634 + "LEN0096", /* X280 */
2635 + "LEN0097", /* X280 -> ALPS trackpoint */
2636 ++ "LEN009b", /* T580 */
2637 + "LEN200f", /* T450s */
2638 + "LEN2054", /* E480 */
2639 + "LEN2055", /* E580 */
2640 +diff --git a/drivers/input/tablet/gtco.c b/drivers/input/tablet/gtco.c
2641 +index 4b8b9d7aa75e..35031228a6d0 100644
2642 +--- a/drivers/input/tablet/gtco.c
2643 ++++ b/drivers/input/tablet/gtco.c
2644 +@@ -78,6 +78,7 @@ Scott Hill shill@×××××××××××.com
2645 +
2646 + /* Max size of a single report */
2647 + #define REPORT_MAX_SIZE 10
2648 ++#define MAX_COLLECTION_LEVELS 10
2649 +
2650 +
2651 + /* Bitmask whether pen is in range */
2652 +@@ -223,8 +224,7 @@ static void parse_hid_report_descriptor(struct gtco *device, char * report,
2653 + char maintype = 'x';
2654 + char globtype[12];
2655 + int indent = 0;
2656 +- char indentstr[10] = "";
2657 +-
2658 ++ char indentstr[MAX_COLLECTION_LEVELS + 1] = { 0 };
2659 +
2660 + dev_dbg(ddev, "======>>>>>>PARSE<<<<<<======\n");
2661 +
2662 +@@ -350,6 +350,13 @@ static void parse_hid_report_descriptor(struct gtco *device, char * report,
2663 + case TAG_MAIN_COL_START:
2664 + maintype = 'S';
2665 +
2666 ++ if (indent == MAX_COLLECTION_LEVELS) {
2667 ++ dev_err(ddev, "Collection level %d would exceed limit of %d\n",
2668 ++ indent + 1,
2669 ++ MAX_COLLECTION_LEVELS);
2670 ++ break;
2671 ++ }
2672 ++
2673 + if (data == 0) {
2674 + dev_dbg(ddev, "======>>>>>> Physical\n");
2675 + strcpy(globtype, "Physical");
2676 +@@ -369,8 +376,15 @@ static void parse_hid_report_descriptor(struct gtco *device, char * report,
2677 + break;
2678 +
2679 + case TAG_MAIN_COL_END:
2680 +- dev_dbg(ddev, "<<<<<<======\n");
2681 + maintype = 'E';
2682 ++
2683 ++ if (indent == 0) {
2684 ++ dev_err(ddev, "Collection level already at zero\n");
2685 ++ break;
2686 ++ }
2687 ++
2688 ++ dev_dbg(ddev, "<<<<<<======\n");
2689 ++
2690 + indent--;
2691 + for (x = 0; x < indent; x++)
2692 + indentstr[x] = '-';
2693 +diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
2694 +index 3de5c0bcb5cc..1620a6f49989 100644
2695 +--- a/drivers/iommu/iommu.c
2696 ++++ b/drivers/iommu/iommu.c
2697 +@@ -205,18 +205,21 @@ static int iommu_insert_resv_region(struct iommu_resv_region *new,
2698 + pos = pos->next;
2699 + } else if ((start >= a) && (end <= b)) {
2700 + if (new->type == type)
2701 +- goto done;
2702 ++ return 0;
2703 + else
2704 + pos = pos->next;
2705 + } else {
2706 + if (new->type == type) {
2707 + phys_addr_t new_start = min(a, start);
2708 + phys_addr_t new_end = max(b, end);
2709 ++ int ret;
2710 +
2711 + list_del(&entry->list);
2712 + entry->start = new_start;
2713 + entry->length = new_end - new_start + 1;
2714 +- iommu_insert_resv_region(entry, regions);
2715 ++ ret = iommu_insert_resv_region(entry, regions);
2716 ++ kfree(entry);
2717 ++ return ret;
2718 + } else {
2719 + pos = pos->next;
2720 + }
2721 +@@ -229,7 +232,6 @@ insert:
2722 + return -ENOMEM;
2723 +
2724 + list_add_tail(&region->list, pos);
2725 +-done:
2726 + return 0;
2727 + }
2728 +
2729 +diff --git a/drivers/mailbox/mailbox.c b/drivers/mailbox/mailbox.c
2730 +index 537f4f6d009b..44b49a2676f0 100644
2731 +--- a/drivers/mailbox/mailbox.c
2732 ++++ b/drivers/mailbox/mailbox.c
2733 +@@ -391,11 +391,13 @@ struct mbox_chan *mbox_request_channel_byname(struct mbox_client *cl,
2734 +
2735 + of_property_for_each_string(np, "mbox-names", prop, mbox_name) {
2736 + if (!strncmp(name, mbox_name, strlen(name)))
2737 +- break;
2738 ++ return mbox_request_channel(cl, index);
2739 + index++;
2740 + }
2741 +
2742 +- return mbox_request_channel(cl, index);
2743 ++ dev_err(cl->dev, "%s() could not locate channel named \"%s\"\n",
2744 ++ __func__, name);
2745 ++ return ERR_PTR(-EINVAL);
2746 + }
2747 + EXPORT_SYMBOL_GPL(mbox_request_channel_byname);
2748 +
2749 +diff --git a/drivers/md/bcache/super.c b/drivers/md/bcache/super.c
2750 +index 85a5afe01d39..1a270e2262f5 100644
2751 +--- a/drivers/md/bcache/super.c
2752 ++++ b/drivers/md/bcache/super.c
2753 +@@ -1402,7 +1402,7 @@ static void cache_set_flush(struct closure *cl)
2754 + kobject_put(&c->internal);
2755 + kobject_del(&c->kobj);
2756 +
2757 +- if (c->gc_thread)
2758 ++ if (!IS_ERR_OR_NULL(c->gc_thread))
2759 + kthread_stop(c->gc_thread);
2760 +
2761 + if (!IS_ERR_OR_NULL(c->root))
2762 +diff --git a/drivers/md/dm-bufio.c b/drivers/md/dm-bufio.c
2763 +index 1e17e6421da3..b7d3b62dae7f 100644
2764 +--- a/drivers/md/dm-bufio.c
2765 ++++ b/drivers/md/dm-bufio.c
2766 +@@ -1630,9 +1630,7 @@ dm_bufio_shrink_scan(struct shrinker *shrink, struct shrink_control *sc)
2767 + unsigned long freed;
2768 +
2769 + c = container_of(shrink, struct dm_bufio_client, shrinker);
2770 +- if (sc->gfp_mask & __GFP_FS)
2771 +- dm_bufio_lock(c);
2772 +- else if (!dm_bufio_trylock(c))
2773 ++ if (!dm_bufio_trylock(c))
2774 + return SHRINK_STOP;
2775 +
2776 + freed = __scan(c, sc->nr_to_scan, sc->gfp_mask);
2777 +diff --git a/drivers/md/dm-zoned-metadata.c b/drivers/md/dm-zoned-metadata.c
2778 +index 167686189fd2..597098a43aba 100644
2779 +--- a/drivers/md/dm-zoned-metadata.c
2780 ++++ b/drivers/md/dm-zoned-metadata.c
2781 +@@ -1593,30 +1593,6 @@ struct dm_zone *dmz_get_zone_for_reclaim(struct dmz_metadata *zmd)
2782 + return zone;
2783 + }
2784 +
2785 +-/*
2786 +- * Activate a zone (increment its reference count).
2787 +- */
2788 +-void dmz_activate_zone(struct dm_zone *zone)
2789 +-{
2790 +- set_bit(DMZ_ACTIVE, &zone->flags);
2791 +- atomic_inc(&zone->refcount);
2792 +-}
2793 +-
2794 +-/*
2795 +- * Deactivate a zone. This decrement the zone reference counter
2796 +- * and clears the active state of the zone once the count reaches 0,
2797 +- * indicating that all BIOs to the zone have completed. Returns
2798 +- * true if the zone was deactivated.
2799 +- */
2800 +-void dmz_deactivate_zone(struct dm_zone *zone)
2801 +-{
2802 +- if (atomic_dec_and_test(&zone->refcount)) {
2803 +- WARN_ON(!test_bit(DMZ_ACTIVE, &zone->flags));
2804 +- clear_bit_unlock(DMZ_ACTIVE, &zone->flags);
2805 +- smp_mb__after_atomic();
2806 +- }
2807 +-}
2808 +-
2809 + /*
2810 + * Get the zone mapping a chunk, if the chunk is mapped already.
2811 + * If no mapping exist and the operation is WRITE, a zone is
2812 +diff --git a/drivers/md/dm-zoned.h b/drivers/md/dm-zoned.h
2813 +index 12419f0bfe78..ed8de49c9a08 100644
2814 +--- a/drivers/md/dm-zoned.h
2815 ++++ b/drivers/md/dm-zoned.h
2816 +@@ -115,7 +115,6 @@ enum {
2817 + DMZ_BUF,
2818 +
2819 + /* Zone internal state */
2820 +- DMZ_ACTIVE,
2821 + DMZ_RECLAIM,
2822 + DMZ_SEQ_WRITE_ERR,
2823 + };
2824 +@@ -128,7 +127,6 @@ enum {
2825 + #define dmz_is_empty(z) ((z)->wp_block == 0)
2826 + #define dmz_is_offline(z) test_bit(DMZ_OFFLINE, &(z)->flags)
2827 + #define dmz_is_readonly(z) test_bit(DMZ_READ_ONLY, &(z)->flags)
2828 +-#define dmz_is_active(z) test_bit(DMZ_ACTIVE, &(z)->flags)
2829 + #define dmz_in_reclaim(z) test_bit(DMZ_RECLAIM, &(z)->flags)
2830 + #define dmz_seq_write_err(z) test_bit(DMZ_SEQ_WRITE_ERR, &(z)->flags)
2831 +
2832 +@@ -188,8 +186,30 @@ void dmz_unmap_zone(struct dmz_metadata *zmd, struct dm_zone *zone);
2833 + unsigned int dmz_nr_rnd_zones(struct dmz_metadata *zmd);
2834 + unsigned int dmz_nr_unmap_rnd_zones(struct dmz_metadata *zmd);
2835 +
2836 +-void dmz_activate_zone(struct dm_zone *zone);
2837 +-void dmz_deactivate_zone(struct dm_zone *zone);
2838 ++/*
2839 ++ * Activate a zone (increment its reference count).
2840 ++ */
2841 ++static inline void dmz_activate_zone(struct dm_zone *zone)
2842 ++{
2843 ++ atomic_inc(&zone->refcount);
2844 ++}
2845 ++
2846 ++/*
2847 ++ * Deactivate a zone. This decrement the zone reference counter
2848 ++ * indicating that all BIOs to the zone have completed when the count is 0.
2849 ++ */
2850 ++static inline void dmz_deactivate_zone(struct dm_zone *zone)
2851 ++{
2852 ++ atomic_dec(&zone->refcount);
2853 ++}
2854 ++
2855 ++/*
2856 ++ * Test if a zone is active, that is, has a refcount > 0.
2857 ++ */
2858 ++static inline bool dmz_is_active(struct dm_zone *zone)
2859 ++{
2860 ++ return atomic_read(&zone->refcount);
2861 ++}
2862 +
2863 + int dmz_lock_zone_reclaim(struct dm_zone *zone);
2864 + void dmz_unlock_zone_reclaim(struct dm_zone *zone);
2865 +diff --git a/drivers/media/dvb-frontends/tua6100.c b/drivers/media/dvb-frontends/tua6100.c
2866 +index 18e6d4c5be21..859fa14b319c 100644
2867 +--- a/drivers/media/dvb-frontends/tua6100.c
2868 ++++ b/drivers/media/dvb-frontends/tua6100.c
2869 +@@ -75,8 +75,8 @@ static int tua6100_set_params(struct dvb_frontend *fe)
2870 + struct i2c_msg msg1 = { .addr = priv->i2c_address, .flags = 0, .buf = reg1, .len = 4 };
2871 + struct i2c_msg msg2 = { .addr = priv->i2c_address, .flags = 0, .buf = reg2, .len = 3 };
2872 +
2873 +-#define _R 4
2874 +-#define _P 32
2875 ++#define _R_VAL 4
2876 ++#define _P_VAL 32
2877 + #define _ri 4000000
2878 +
2879 + // setup register 0
2880 +@@ -91,14 +91,14 @@ static int tua6100_set_params(struct dvb_frontend *fe)
2881 + else
2882 + reg1[1] = 0x0c;
2883 +
2884 +- if (_P == 64)
2885 ++ if (_P_VAL == 64)
2886 + reg1[1] |= 0x40;
2887 + if (c->frequency >= 1525000)
2888 + reg1[1] |= 0x80;
2889 +
2890 + // register 2
2891 +- reg2[1] = (_R >> 8) & 0x03;
2892 +- reg2[2] = _R;
2893 ++ reg2[1] = (_R_VAL >> 8) & 0x03;
2894 ++ reg2[2] = _R_VAL;
2895 + if (c->frequency < 1455000)
2896 + reg2[1] |= 0x1c;
2897 + else if (c->frequency < 1630000)
2898 +@@ -110,18 +110,18 @@ static int tua6100_set_params(struct dvb_frontend *fe)
2899 + * The N divisor ratio (note: c->frequency is in kHz, but we
2900 + * need it in Hz)
2901 + */
2902 +- prediv = (c->frequency * _R) / (_ri / 1000);
2903 +- div = prediv / _P;
2904 ++ prediv = (c->frequency * _R_VAL) / (_ri / 1000);
2905 ++ div = prediv / _P_VAL;
2906 + reg1[1] |= (div >> 9) & 0x03;
2907 + reg1[2] = div >> 1;
2908 + reg1[3] = (div << 7);
2909 +- priv->frequency = ((div * _P) * (_ri / 1000)) / _R;
2910 ++ priv->frequency = ((div * _P_VAL) * (_ri / 1000)) / _R_VAL;
2911 +
2912 + // Finally, calculate and store the value for A
2913 +- reg1[3] |= (prediv - (div*_P)) & 0x7f;
2914 ++ reg1[3] |= (prediv - (div*_P_VAL)) & 0x7f;
2915 +
2916 +-#undef _R
2917 +-#undef _P
2918 ++#undef _R_VAL
2919 ++#undef _P_VAL
2920 + #undef _ri
2921 +
2922 + if (fe->ops.i2c_gate_ctrl)
2923 +diff --git a/drivers/media/i2c/Makefile b/drivers/media/i2c/Makefile
2924 +index f104650d6000..0f5c5a3cdca3 100644
2925 +--- a/drivers/media/i2c/Makefile
2926 ++++ b/drivers/media/i2c/Makefile
2927 +@@ -33,7 +33,7 @@ obj-$(CONFIG_VIDEO_ADV748X) += adv748x/
2928 + obj-$(CONFIG_VIDEO_ADV7604) += adv7604.o
2929 + obj-$(CONFIG_VIDEO_ADV7842) += adv7842.o
2930 + obj-$(CONFIG_VIDEO_AD9389B) += ad9389b.o
2931 +-obj-$(CONFIG_VIDEO_ADV7511) += adv7511.o
2932 ++obj-$(CONFIG_VIDEO_ADV7511) += adv7511-v4l2.o
2933 + obj-$(CONFIG_VIDEO_VPX3220) += vpx3220.o
2934 + obj-$(CONFIG_VIDEO_VS6624) += vs6624.o
2935 + obj-$(CONFIG_VIDEO_BT819) += bt819.o
2936 +diff --git a/drivers/media/i2c/adv7511-v4l2.c b/drivers/media/i2c/adv7511-v4l2.c
2937 +new file mode 100644
2938 +index 000000000000..ef1144668809
2939 +--- /dev/null
2940 ++++ b/drivers/media/i2c/adv7511-v4l2.c
2941 +@@ -0,0 +1,2008 @@
2942 ++/*
2943 ++ * Analog Devices ADV7511 HDMI Transmitter Device Driver
2944 ++ *
2945 ++ * Copyright 2013 Cisco Systems, Inc. and/or its affiliates. All rights reserved.
2946 ++ *
2947 ++ * This program is free software; you may redistribute it and/or modify
2948 ++ * it under the terms of the GNU General Public License as published by
2949 ++ * the Free Software Foundation; version 2 of the License.
2950 ++ *
2951 ++ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
2952 ++ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
2953 ++ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
2954 ++ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
2955 ++ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
2956 ++ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
2957 ++ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2958 ++ * SOFTWARE.
2959 ++ */
2960 ++
2961 ++/*
2962 ++ * This file is named adv7511-v4l2.c so it doesn't conflict with the Analog
2963 ++ * Device ADV7511 (config fragment CONFIG_DRM_I2C_ADV7511).
2964 ++ */
2965 ++
2966 ++
2967 ++#include <linux/kernel.h>
2968 ++#include <linux/module.h>
2969 ++#include <linux/slab.h>
2970 ++#include <linux/i2c.h>
2971 ++#include <linux/delay.h>
2972 ++#include <linux/videodev2.h>
2973 ++#include <linux/gpio.h>
2974 ++#include <linux/workqueue.h>
2975 ++#include <linux/hdmi.h>
2976 ++#include <linux/v4l2-dv-timings.h>
2977 ++#include <media/v4l2-device.h>
2978 ++#include <media/v4l2-common.h>
2979 ++#include <media/v4l2-ctrls.h>
2980 ++#include <media/v4l2-dv-timings.h>
2981 ++#include <media/i2c/adv7511.h>
2982 ++#include <media/cec.h>
2983 ++
2984 ++static int debug;
2985 ++module_param(debug, int, 0644);
2986 ++MODULE_PARM_DESC(debug, "debug level (0-2)");
2987 ++
2988 ++MODULE_DESCRIPTION("Analog Devices ADV7511 HDMI Transmitter Device Driver");
2989 ++MODULE_AUTHOR("Hans Verkuil");
2990 ++MODULE_LICENSE("GPL v2");
2991 ++
2992 ++#define MASK_ADV7511_EDID_RDY_INT 0x04
2993 ++#define MASK_ADV7511_MSEN_INT 0x40
2994 ++#define MASK_ADV7511_HPD_INT 0x80
2995 ++
2996 ++#define MASK_ADV7511_HPD_DETECT 0x40
2997 ++#define MASK_ADV7511_MSEN_DETECT 0x20
2998 ++#define MASK_ADV7511_EDID_RDY 0x10
2999 ++
3000 ++#define EDID_MAX_RETRIES (8)
3001 ++#define EDID_DELAY 250
3002 ++#define EDID_MAX_SEGM 8
3003 ++
3004 ++#define ADV7511_MAX_WIDTH 1920
3005 ++#define ADV7511_MAX_HEIGHT 1200
3006 ++#define ADV7511_MIN_PIXELCLOCK 20000000
3007 ++#define ADV7511_MAX_PIXELCLOCK 225000000
3008 ++
3009 ++#define ADV7511_MAX_ADDRS (3)
3010 ++
3011 ++/*
3012 ++**********************************************************************
3013 ++*
3014 ++* Arrays with configuration parameters for the ADV7511
3015 ++*
3016 ++**********************************************************************
3017 ++*/
3018 ++
3019 ++struct i2c_reg_value {
3020 ++ unsigned char reg;
3021 ++ unsigned char value;
3022 ++};
3023 ++
3024 ++struct adv7511_state_edid {
3025 ++ /* total number of blocks */
3026 ++ u32 blocks;
3027 ++ /* Number of segments read */
3028 ++ u32 segments;
3029 ++ u8 data[EDID_MAX_SEGM * 256];
3030 ++ /* Number of EDID read retries left */
3031 ++ unsigned read_retries;
3032 ++ bool complete;
3033 ++};
3034 ++
3035 ++struct adv7511_state {
3036 ++ struct adv7511_platform_data pdata;
3037 ++ struct v4l2_subdev sd;
3038 ++ struct media_pad pad;
3039 ++ struct v4l2_ctrl_handler hdl;
3040 ++ int chip_revision;
3041 ++ u8 i2c_edid_addr;
3042 ++ u8 i2c_pktmem_addr;
3043 ++ u8 i2c_cec_addr;
3044 ++
3045 ++ struct i2c_client *i2c_cec;
3046 ++ struct cec_adapter *cec_adap;
3047 ++ u8 cec_addr[ADV7511_MAX_ADDRS];
3048 ++ u8 cec_valid_addrs;
3049 ++ bool cec_enabled_adap;
3050 ++
3051 ++ /* Is the adv7511 powered on? */
3052 ++ bool power_on;
3053 ++ /* Did we receive hotplug and rx-sense signals? */
3054 ++ bool have_monitor;
3055 ++ bool enabled_irq;
3056 ++ /* timings from s_dv_timings */
3057 ++ struct v4l2_dv_timings dv_timings;
3058 ++ u32 fmt_code;
3059 ++ u32 colorspace;
3060 ++ u32 ycbcr_enc;
3061 ++ u32 quantization;
3062 ++ u32 xfer_func;
3063 ++ u32 content_type;
3064 ++ /* controls */
3065 ++ struct v4l2_ctrl *hdmi_mode_ctrl;
3066 ++ struct v4l2_ctrl *hotplug_ctrl;
3067 ++ struct v4l2_ctrl *rx_sense_ctrl;
3068 ++ struct v4l2_ctrl *have_edid0_ctrl;
3069 ++ struct v4l2_ctrl *rgb_quantization_range_ctrl;
3070 ++ struct v4l2_ctrl *content_type_ctrl;
3071 ++ struct i2c_client *i2c_edid;
3072 ++ struct i2c_client *i2c_pktmem;
3073 ++ struct adv7511_state_edid edid;
3074 ++ /* Running counter of the number of detected EDIDs (for debugging) */
3075 ++ unsigned edid_detect_counter;
3076 ++ struct workqueue_struct *work_queue;
3077 ++ struct delayed_work edid_handler; /* work entry */
3078 ++};
3079 ++
3080 ++static void adv7511_check_monitor_present_status(struct v4l2_subdev *sd);
3081 ++static bool adv7511_check_edid_status(struct v4l2_subdev *sd);
3082 ++static void adv7511_setup(struct v4l2_subdev *sd);
3083 ++static int adv7511_s_i2s_clock_freq(struct v4l2_subdev *sd, u32 freq);
3084 ++static int adv7511_s_clock_freq(struct v4l2_subdev *sd, u32 freq);
3085 ++
3086 ++
3087 ++static const struct v4l2_dv_timings_cap adv7511_timings_cap = {
3088 ++ .type = V4L2_DV_BT_656_1120,
3089 ++ /* keep this initialization for compatibility with GCC < 4.4.6 */
3090 ++ .reserved = { 0 },
3091 ++ V4L2_INIT_BT_TIMINGS(640, ADV7511_MAX_WIDTH, 350, ADV7511_MAX_HEIGHT,
3092 ++ ADV7511_MIN_PIXELCLOCK, ADV7511_MAX_PIXELCLOCK,
3093 ++ V4L2_DV_BT_STD_CEA861 | V4L2_DV_BT_STD_DMT |
3094 ++ V4L2_DV_BT_STD_GTF | V4L2_DV_BT_STD_CVT,
3095 ++ V4L2_DV_BT_CAP_PROGRESSIVE | V4L2_DV_BT_CAP_REDUCED_BLANKING |
3096 ++ V4L2_DV_BT_CAP_CUSTOM)
3097 ++};
3098 ++
3099 ++static inline struct adv7511_state *get_adv7511_state(struct v4l2_subdev *sd)
3100 ++{
3101 ++ return container_of(sd, struct adv7511_state, sd);
3102 ++}
3103 ++
3104 ++static inline struct v4l2_subdev *to_sd(struct v4l2_ctrl *ctrl)
3105 ++{
3106 ++ return &container_of(ctrl->handler, struct adv7511_state, hdl)->sd;
3107 ++}
3108 ++
3109 ++/* ------------------------ I2C ----------------------------------------------- */
3110 ++
3111 ++static s32 adv_smbus_read_byte_data_check(struct i2c_client *client,
3112 ++ u8 command, bool check)
3113 ++{
3114 ++ union i2c_smbus_data data;
3115 ++
3116 ++ if (!i2c_smbus_xfer(client->adapter, client->addr, client->flags,
3117 ++ I2C_SMBUS_READ, command,
3118 ++ I2C_SMBUS_BYTE_DATA, &data))
3119 ++ return data.byte;
3120 ++ if (check)
3121 ++ v4l_err(client, "error reading %02x, %02x\n",
3122 ++ client->addr, command);
3123 ++ return -1;
3124 ++}
3125 ++
3126 ++static s32 adv_smbus_read_byte_data(struct i2c_client *client, u8 command)
3127 ++{
3128 ++ int i;
3129 ++ for (i = 0; i < 3; i++) {
3130 ++ int ret = adv_smbus_read_byte_data_check(client, command, true);
3131 ++ if (ret >= 0) {
3132 ++ if (i)
3133 ++ v4l_err(client, "read ok after %d retries\n", i);
3134 ++ return ret;
3135 ++ }
3136 ++ }
3137 ++ v4l_err(client, "read failed\n");
3138 ++ return -1;
3139 ++}
3140 ++
3141 ++static int adv7511_rd(struct v4l2_subdev *sd, u8 reg)
3142 ++{
3143 ++ struct i2c_client *client = v4l2_get_subdevdata(sd);
3144 ++
3145 ++ return adv_smbus_read_byte_data(client, reg);
3146 ++}
3147 ++
3148 ++static int adv7511_wr(struct v4l2_subdev *sd, u8 reg, u8 val)
3149 ++{
3150 ++ struct i2c_client *client = v4l2_get_subdevdata(sd);
3151 ++ int ret;
3152 ++ int i;
3153 ++
3154 ++ for (i = 0; i < 3; i++) {
3155 ++ ret = i2c_smbus_write_byte_data(client, reg, val);
3156 ++ if (ret == 0)
3157 ++ return 0;
3158 ++ }
3159 ++ v4l2_err(sd, "%s: i2c write error\n", __func__);
3160 ++ return ret;
3161 ++}
3162 ++
3163 ++/* To set specific bits in the register, a clear-mask is given (to be AND-ed),
3164 ++ and then the value-mask (to be OR-ed). */
3165 ++static inline void adv7511_wr_and_or(struct v4l2_subdev *sd, u8 reg, u8 clr_mask, u8 val_mask)
3166 ++{
3167 ++ adv7511_wr(sd, reg, (adv7511_rd(sd, reg) & clr_mask) | val_mask);
3168 ++}
3169 ++
3170 ++static int adv_smbus_read_i2c_block_data(struct i2c_client *client,
3171 ++ u8 command, unsigned length, u8 *values)
3172 ++{
3173 ++ union i2c_smbus_data data;
3174 ++ int ret;
3175 ++
3176 ++ if (length > I2C_SMBUS_BLOCK_MAX)
3177 ++ length = I2C_SMBUS_BLOCK_MAX;
3178 ++ data.block[0] = length;
3179 ++
3180 ++ ret = i2c_smbus_xfer(client->adapter, client->addr, client->flags,
3181 ++ I2C_SMBUS_READ, command,
3182 ++ I2C_SMBUS_I2C_BLOCK_DATA, &data);
3183 ++ memcpy(values, data.block + 1, length);
3184 ++ return ret;
3185 ++}
3186 ++
3187 ++static void adv7511_edid_rd(struct v4l2_subdev *sd, uint16_t len, uint8_t *buf)
3188 ++{
3189 ++ struct adv7511_state *state = get_adv7511_state(sd);
3190 ++ int i;
3191 ++ int err = 0;
3192 ++
3193 ++ v4l2_dbg(1, debug, sd, "%s:\n", __func__);
3194 ++
3195 ++ for (i = 0; !err && i < len; i += I2C_SMBUS_BLOCK_MAX)
3196 ++ err = adv_smbus_read_i2c_block_data(state->i2c_edid, i,
3197 ++ I2C_SMBUS_BLOCK_MAX, buf + i);
3198 ++ if (err)
3199 ++ v4l2_err(sd, "%s: i2c read error\n", __func__);
3200 ++}
3201 ++
3202 ++static inline int adv7511_cec_read(struct v4l2_subdev *sd, u8 reg)
3203 ++{
3204 ++ struct adv7511_state *state = get_adv7511_state(sd);
3205 ++
3206 ++ return i2c_smbus_read_byte_data(state->i2c_cec, reg);
3207 ++}
3208 ++
3209 ++static int adv7511_cec_write(struct v4l2_subdev *sd, u8 reg, u8 val)
3210 ++{
3211 ++ struct adv7511_state *state = get_adv7511_state(sd);
3212 ++ int ret;
3213 ++ int i;
3214 ++
3215 ++ for (i = 0; i < 3; i++) {
3216 ++ ret = i2c_smbus_write_byte_data(state->i2c_cec, reg, val);
3217 ++ if (ret == 0)
3218 ++ return 0;
3219 ++ }
3220 ++ v4l2_err(sd, "%s: I2C Write Problem\n", __func__);
3221 ++ return ret;
3222 ++}
3223 ++
3224 ++static inline int adv7511_cec_write_and_or(struct v4l2_subdev *sd, u8 reg, u8 mask,
3225 ++ u8 val)
3226 ++{
3227 ++ return adv7511_cec_write(sd, reg, (adv7511_cec_read(sd, reg) & mask) | val);
3228 ++}
3229 ++
3230 ++static int adv7511_pktmem_rd(struct v4l2_subdev *sd, u8 reg)
3231 ++{
3232 ++ struct adv7511_state *state = get_adv7511_state(sd);
3233 ++
3234 ++ return adv_smbus_read_byte_data(state->i2c_pktmem, reg);
3235 ++}
3236 ++
3237 ++static int adv7511_pktmem_wr(struct v4l2_subdev *sd, u8 reg, u8 val)
3238 ++{
3239 ++ struct adv7511_state *state = get_adv7511_state(sd);
3240 ++ int ret;
3241 ++ int i;
3242 ++
3243 ++ for (i = 0; i < 3; i++) {
3244 ++ ret = i2c_smbus_write_byte_data(state->i2c_pktmem, reg, val);
3245 ++ if (ret == 0)
3246 ++ return 0;
3247 ++ }
3248 ++ v4l2_err(sd, "%s: i2c write error\n", __func__);
3249 ++ return ret;
3250 ++}
3251 ++
3252 ++/* To set specific bits in the register, a clear-mask is given (to be AND-ed),
3253 ++ and then the value-mask (to be OR-ed). */
3254 ++static inline void adv7511_pktmem_wr_and_or(struct v4l2_subdev *sd, u8 reg, u8 clr_mask, u8 val_mask)
3255 ++{
3256 ++ adv7511_pktmem_wr(sd, reg, (adv7511_pktmem_rd(sd, reg) & clr_mask) | val_mask);
3257 ++}
3258 ++
3259 ++static inline bool adv7511_have_hotplug(struct v4l2_subdev *sd)
3260 ++{
3261 ++ return adv7511_rd(sd, 0x42) & MASK_ADV7511_HPD_DETECT;
3262 ++}
3263 ++
3264 ++static inline bool adv7511_have_rx_sense(struct v4l2_subdev *sd)
3265 ++{
3266 ++ return adv7511_rd(sd, 0x42) & MASK_ADV7511_MSEN_DETECT;
3267 ++}
3268 ++
3269 ++static void adv7511_csc_conversion_mode(struct v4l2_subdev *sd, u8 mode)
3270 ++{
3271 ++ adv7511_wr_and_or(sd, 0x18, 0x9f, (mode & 0x3)<<5);
3272 ++}
3273 ++
3274 ++static void adv7511_csc_coeff(struct v4l2_subdev *sd,
3275 ++ u16 A1, u16 A2, u16 A3, u16 A4,
3276 ++ u16 B1, u16 B2, u16 B3, u16 B4,
3277 ++ u16 C1, u16 C2, u16 C3, u16 C4)
3278 ++{
3279 ++ /* A */
3280 ++ adv7511_wr_and_or(sd, 0x18, 0xe0, A1>>8);
3281 ++ adv7511_wr(sd, 0x19, A1);
3282 ++ adv7511_wr_and_or(sd, 0x1A, 0xe0, A2>>8);
3283 ++ adv7511_wr(sd, 0x1B, A2);
3284 ++ adv7511_wr_and_or(sd, 0x1c, 0xe0, A3>>8);
3285 ++ adv7511_wr(sd, 0x1d, A3);
3286 ++ adv7511_wr_and_or(sd, 0x1e, 0xe0, A4>>8);
3287 ++ adv7511_wr(sd, 0x1f, A4);
3288 ++
3289 ++ /* B */
3290 ++ adv7511_wr_and_or(sd, 0x20, 0xe0, B1>>8);
3291 ++ adv7511_wr(sd, 0x21, B1);
3292 ++ adv7511_wr_and_or(sd, 0x22, 0xe0, B2>>8);
3293 ++ adv7511_wr(sd, 0x23, B2);
3294 ++ adv7511_wr_and_or(sd, 0x24, 0xe0, B3>>8);
3295 ++ adv7511_wr(sd, 0x25, B3);
3296 ++ adv7511_wr_and_or(sd, 0x26, 0xe0, B4>>8);
3297 ++ adv7511_wr(sd, 0x27, B4);
3298 ++
3299 ++ /* C */
3300 ++ adv7511_wr_and_or(sd, 0x28, 0xe0, C1>>8);
3301 ++ adv7511_wr(sd, 0x29, C1);
3302 ++ adv7511_wr_and_or(sd, 0x2A, 0xe0, C2>>8);
3303 ++ adv7511_wr(sd, 0x2B, C2);
3304 ++ adv7511_wr_and_or(sd, 0x2C, 0xe0, C3>>8);
3305 ++ adv7511_wr(sd, 0x2D, C3);
3306 ++ adv7511_wr_and_or(sd, 0x2E, 0xe0, C4>>8);
3307 ++ adv7511_wr(sd, 0x2F, C4);
3308 ++}
3309 ++
3310 ++static void adv7511_csc_rgb_full2limit(struct v4l2_subdev *sd, bool enable)
3311 ++{
3312 ++ if (enable) {
3313 ++ u8 csc_mode = 0;
3314 ++ adv7511_csc_conversion_mode(sd, csc_mode);
3315 ++ adv7511_csc_coeff(sd,
3316 ++ 4096-564, 0, 0, 256,
3317 ++ 0, 4096-564, 0, 256,
3318 ++ 0, 0, 4096-564, 256);
3319 ++ /* enable CSC */
3320 ++ adv7511_wr_and_or(sd, 0x18, 0x7f, 0x80);
3321 ++ /* AVI infoframe: Limited range RGB (16-235) */
3322 ++ adv7511_wr_and_or(sd, 0x57, 0xf3, 0x04);
3323 ++ } else {
3324 ++ /* disable CSC */
3325 ++ adv7511_wr_and_or(sd, 0x18, 0x7f, 0x0);
3326 ++ /* AVI infoframe: Full range RGB (0-255) */
3327 ++ adv7511_wr_and_or(sd, 0x57, 0xf3, 0x08);
3328 ++ }
3329 ++}
3330 ++
3331 ++static void adv7511_set_rgb_quantization_mode(struct v4l2_subdev *sd, struct v4l2_ctrl *ctrl)
3332 ++{
3333 ++ struct adv7511_state *state = get_adv7511_state(sd);
3334 ++
3335 ++ /* Only makes sense for RGB formats */
3336 ++ if (state->fmt_code != MEDIA_BUS_FMT_RGB888_1X24) {
3337 ++ /* so just keep quantization */
3338 ++ adv7511_csc_rgb_full2limit(sd, false);
3339 ++ return;
3340 ++ }
3341 ++
3342 ++ switch (ctrl->val) {
3343 ++ case V4L2_DV_RGB_RANGE_AUTO:
3344 ++ /* automatic */
3345 ++ if (state->dv_timings.bt.flags & V4L2_DV_FL_IS_CE_VIDEO) {
3346 ++ /* CE format, RGB limited range (16-235) */
3347 ++ adv7511_csc_rgb_full2limit(sd, true);
3348 ++ } else {
3349 ++ /* not CE format, RGB full range (0-255) */
3350 ++ adv7511_csc_rgb_full2limit(sd, false);
3351 ++ }
3352 ++ break;
3353 ++ case V4L2_DV_RGB_RANGE_LIMITED:
3354 ++ /* RGB limited range (16-235) */
3355 ++ adv7511_csc_rgb_full2limit(sd, true);
3356 ++ break;
3357 ++ case V4L2_DV_RGB_RANGE_FULL:
3358 ++ /* RGB full range (0-255) */
3359 ++ adv7511_csc_rgb_full2limit(sd, false);
3360 ++ break;
3361 ++ }
3362 ++}
3363 ++
3364 ++/* ------------------------------ CTRL OPS ------------------------------ */
3365 ++
3366 ++static int adv7511_s_ctrl(struct v4l2_ctrl *ctrl)
3367 ++{
3368 ++ struct v4l2_subdev *sd = to_sd(ctrl);
3369 ++ struct adv7511_state *state = get_adv7511_state(sd);
3370 ++
3371 ++ v4l2_dbg(1, debug, sd, "%s: ctrl id: %d, ctrl->val %d\n", __func__, ctrl->id, ctrl->val);
3372 ++
3373 ++ if (state->hdmi_mode_ctrl == ctrl) {
3374 ++ /* Set HDMI or DVI-D */
3375 ++ adv7511_wr_and_or(sd, 0xaf, 0xfd, ctrl->val == V4L2_DV_TX_MODE_HDMI ? 0x02 : 0x00);
3376 ++ return 0;
3377 ++ }
3378 ++ if (state->rgb_quantization_range_ctrl == ctrl) {
3379 ++ adv7511_set_rgb_quantization_mode(sd, ctrl);
3380 ++ return 0;
3381 ++ }
3382 ++ if (state->content_type_ctrl == ctrl) {
3383 ++ u8 itc, cn;
3384 ++
3385 ++ state->content_type = ctrl->val;
3386 ++ itc = state->content_type != V4L2_DV_IT_CONTENT_TYPE_NO_ITC;
3387 ++ cn = itc ? state->content_type : V4L2_DV_IT_CONTENT_TYPE_GRAPHICS;
3388 ++ adv7511_wr_and_or(sd, 0x57, 0x7f, itc << 7);
3389 ++ adv7511_wr_and_or(sd, 0x59, 0xcf, cn << 4);
3390 ++ return 0;
3391 ++ }
3392 ++
3393 ++ return -EINVAL;
3394 ++}
3395 ++
3396 ++static const struct v4l2_ctrl_ops adv7511_ctrl_ops = {
3397 ++ .s_ctrl = adv7511_s_ctrl,
3398 ++};
3399 ++
3400 ++/* ---------------------------- CORE OPS ------------------------------------------- */
3401 ++
3402 ++#ifdef CONFIG_VIDEO_ADV_DEBUG
3403 ++static void adv7511_inv_register(struct v4l2_subdev *sd)
3404 ++{
3405 ++ struct adv7511_state *state = get_adv7511_state(sd);
3406 ++
3407 ++ v4l2_info(sd, "0x000-0x0ff: Main Map\n");
3408 ++ if (state->i2c_cec)
3409 ++ v4l2_info(sd, "0x100-0x1ff: CEC Map\n");
3410 ++}
3411 ++
3412 ++static int adv7511_g_register(struct v4l2_subdev *sd, struct v4l2_dbg_register *reg)
3413 ++{
3414 ++ struct adv7511_state *state = get_adv7511_state(sd);
3415 ++
3416 ++ reg->size = 1;
3417 ++ switch (reg->reg >> 8) {
3418 ++ case 0:
3419 ++ reg->val = adv7511_rd(sd, reg->reg & 0xff);
3420 ++ break;
3421 ++ case 1:
3422 ++ if (state->i2c_cec) {
3423 ++ reg->val = adv7511_cec_read(sd, reg->reg & 0xff);
3424 ++ break;
3425 ++ }
3426 ++ /* fall through */
3427 ++ default:
3428 ++ v4l2_info(sd, "Register %03llx not supported\n", reg->reg);
3429 ++ adv7511_inv_register(sd);
3430 ++ break;
3431 ++ }
3432 ++ return 0;
3433 ++}
3434 ++
3435 ++static int adv7511_s_register(struct v4l2_subdev *sd, const struct v4l2_dbg_register *reg)
3436 ++{
3437 ++ struct adv7511_state *state = get_adv7511_state(sd);
3438 ++
3439 ++ switch (reg->reg >> 8) {
3440 ++ case 0:
3441 ++ adv7511_wr(sd, reg->reg & 0xff, reg->val & 0xff);
3442 ++ break;
3443 ++ case 1:
3444 ++ if (state->i2c_cec) {
3445 ++ adv7511_cec_write(sd, reg->reg & 0xff, reg->val & 0xff);
3446 ++ break;
3447 ++ }
3448 ++ /* fall through */
3449 ++ default:
3450 ++ v4l2_info(sd, "Register %03llx not supported\n", reg->reg);
3451 ++ adv7511_inv_register(sd);
3452 ++ break;
3453 ++ }
3454 ++ return 0;
3455 ++}
3456 ++#endif
3457 ++
3458 ++struct adv7511_cfg_read_infoframe {
3459 ++ const char *desc;
3460 ++ u8 present_reg;
3461 ++ u8 present_mask;
3462 ++ u8 header[3];
3463 ++ u16 payload_addr;
3464 ++};
3465 ++
3466 ++static u8 hdmi_infoframe_checksum(u8 *ptr, size_t size)
3467 ++{
3468 ++ u8 csum = 0;
3469 ++ size_t i;
3470 ++
3471 ++ /* compute checksum */
3472 ++ for (i = 0; i < size; i++)
3473 ++ csum += ptr[i];
3474 ++
3475 ++ return 256 - csum;
3476 ++}
3477 ++
3478 ++static void log_infoframe(struct v4l2_subdev *sd, const struct adv7511_cfg_read_infoframe *cri)
3479 ++{
3480 ++ struct i2c_client *client = v4l2_get_subdevdata(sd);
3481 ++ struct device *dev = &client->dev;
3482 ++ union hdmi_infoframe frame;
3483 ++ u8 buffer[32];
3484 ++ u8 len;
3485 ++ int i;
3486 ++
3487 ++ if (!(adv7511_rd(sd, cri->present_reg) & cri->present_mask)) {
3488 ++ v4l2_info(sd, "%s infoframe not transmitted\n", cri->desc);
3489 ++ return;
3490 ++ }
3491 ++
3492 ++ memcpy(buffer, cri->header, sizeof(cri->header));
3493 ++
3494 ++ len = buffer[2];
3495 ++
3496 ++ if (len + 4 > sizeof(buffer)) {
3497 ++ v4l2_err(sd, "%s: invalid %s infoframe length %d\n", __func__, cri->desc, len);
3498 ++ return;
3499 ++ }
3500 ++
3501 ++ if (cri->payload_addr >= 0x100) {
3502 ++ for (i = 0; i < len; i++)
3503 ++ buffer[i + 4] = adv7511_pktmem_rd(sd, cri->payload_addr + i - 0x100);
3504 ++ } else {
3505 ++ for (i = 0; i < len; i++)
3506 ++ buffer[i + 4] = adv7511_rd(sd, cri->payload_addr + i);
3507 ++ }
3508 ++ buffer[3] = 0;
3509 ++ buffer[3] = hdmi_infoframe_checksum(buffer, len + 4);
3510 ++
3511 ++ if (hdmi_infoframe_unpack(&frame, buffer) < 0) {
3512 ++ v4l2_err(sd, "%s: unpack of %s infoframe failed\n", __func__, cri->desc);
3513 ++ return;
3514 ++ }
3515 ++
3516 ++ hdmi_infoframe_log(KERN_INFO, dev, &frame);
3517 ++}
3518 ++
3519 ++static void adv7511_log_infoframes(struct v4l2_subdev *sd)
3520 ++{
3521 ++ static const struct adv7511_cfg_read_infoframe cri[] = {
3522 ++ { "AVI", 0x44, 0x10, { 0x82, 2, 13 }, 0x55 },
3523 ++ { "Audio", 0x44, 0x08, { 0x84, 1, 10 }, 0x73 },
3524 ++ { "SDP", 0x40, 0x40, { 0x83, 1, 25 }, 0x103 },
3525 ++ };
3526 ++ int i;
3527 ++
3528 ++ for (i = 0; i < ARRAY_SIZE(cri); i++)
3529 ++ log_infoframe(sd, &cri[i]);
3530 ++}
3531 ++
3532 ++static int adv7511_log_status(struct v4l2_subdev *sd)
3533 ++{
3534 ++ struct adv7511_state *state = get_adv7511_state(sd);
3535 ++ struct adv7511_state_edid *edid = &state->edid;
3536 ++ int i;
3537 ++
3538 ++ static const char * const states[] = {
3539 ++ "in reset",
3540 ++ "reading EDID",
3541 ++ "idle",
3542 ++ "initializing HDCP",
3543 ++ "HDCP enabled",
3544 ++ "initializing HDCP repeater",
3545 ++ "6", "7", "8", "9", "A", "B", "C", "D", "E", "F"
3546 ++ };
3547 ++ static const char * const errors[] = {
3548 ++ "no error",
3549 ++ "bad receiver BKSV",
3550 ++ "Ri mismatch",
3551 ++ "Pj mismatch",
3552 ++ "i2c error",
3553 ++ "timed out",
3554 ++ "max repeater cascade exceeded",
3555 ++ "hash check failed",
3556 ++ "too many devices",
3557 ++ "9", "A", "B", "C", "D", "E", "F"
3558 ++ };
3559 ++
3560 ++ v4l2_info(sd, "power %s\n", state->power_on ? "on" : "off");
3561 ++ v4l2_info(sd, "%s hotplug, %s Rx Sense, %s EDID (%d block(s))\n",
3562 ++ (adv7511_rd(sd, 0x42) & MASK_ADV7511_HPD_DETECT) ? "detected" : "no",
3563 ++ (adv7511_rd(sd, 0x42) & MASK_ADV7511_MSEN_DETECT) ? "detected" : "no",
3564 ++ edid->segments ? "found" : "no",
3565 ++ edid->blocks);
3566 ++ v4l2_info(sd, "%s output %s\n",
3567 ++ (adv7511_rd(sd, 0xaf) & 0x02) ?
3568 ++ "HDMI" : "DVI-D",
3569 ++ (adv7511_rd(sd, 0xa1) & 0x3c) ?
3570 ++ "disabled" : "enabled");
3571 ++ v4l2_info(sd, "state: %s, error: %s, detect count: %u, msk/irq: %02x/%02x\n",
3572 ++ states[adv7511_rd(sd, 0xc8) & 0xf],
3573 ++ errors[adv7511_rd(sd, 0xc8) >> 4], state->edid_detect_counter,
3574 ++ adv7511_rd(sd, 0x94), adv7511_rd(sd, 0x96));
3575 ++ v4l2_info(sd, "RGB quantization: %s range\n", adv7511_rd(sd, 0x18) & 0x80 ? "limited" : "full");
3576 ++ if (adv7511_rd(sd, 0xaf) & 0x02) {
3577 ++ /* HDMI only */
3578 ++ u8 manual_cts = adv7511_rd(sd, 0x0a) & 0x80;
3579 ++ u32 N = (adv7511_rd(sd, 0x01) & 0xf) << 16 |
3580 ++ adv7511_rd(sd, 0x02) << 8 |
3581 ++ adv7511_rd(sd, 0x03);
3582 ++ u8 vic_detect = adv7511_rd(sd, 0x3e) >> 2;
3583 ++ u8 vic_sent = adv7511_rd(sd, 0x3d) & 0x3f;
3584 ++ u32 CTS;
3585 ++
3586 ++ if (manual_cts)
3587 ++ CTS = (adv7511_rd(sd, 0x07) & 0xf) << 16 |
3588 ++ adv7511_rd(sd, 0x08) << 8 |
3589 ++ adv7511_rd(sd, 0x09);
3590 ++ else
3591 ++ CTS = (adv7511_rd(sd, 0x04) & 0xf) << 16 |
3592 ++ adv7511_rd(sd, 0x05) << 8 |
3593 ++ adv7511_rd(sd, 0x06);
3594 ++ v4l2_info(sd, "CTS %s mode: N %d, CTS %d\n",
3595 ++ manual_cts ? "manual" : "automatic", N, CTS);
3596 ++ v4l2_info(sd, "VIC: detected %d, sent %d\n",
3597 ++ vic_detect, vic_sent);
3598 ++ adv7511_log_infoframes(sd);
3599 ++ }
3600 ++ if (state->dv_timings.type == V4L2_DV_BT_656_1120)
3601 ++ v4l2_print_dv_timings(sd->name, "timings: ",
3602 ++ &state->dv_timings, false);
3603 ++ else
3604 ++ v4l2_info(sd, "no timings set\n");
3605 ++ v4l2_info(sd, "i2c edid addr: 0x%x\n", state->i2c_edid_addr);
3606 ++
3607 ++ if (state->i2c_cec == NULL)
3608 ++ return 0;
3609 ++
3610 ++ v4l2_info(sd, "i2c cec addr: 0x%x\n", state->i2c_cec_addr);
3611 ++
3612 ++ v4l2_info(sd, "CEC: %s\n", state->cec_enabled_adap ?
3613 ++ "enabled" : "disabled");
3614 ++ if (state->cec_enabled_adap) {
3615 ++ for (i = 0; i < ADV7511_MAX_ADDRS; i++) {
3616 ++ bool is_valid = state->cec_valid_addrs & (1 << i);
3617 ++
3618 ++ if (is_valid)
3619 ++ v4l2_info(sd, "CEC Logical Address: 0x%x\n",
3620 ++ state->cec_addr[i]);
3621 ++ }
3622 ++ }
3623 ++ v4l2_info(sd, "i2c pktmem addr: 0x%x\n", state->i2c_pktmem_addr);
3624 ++ return 0;
3625 ++}
3626 ++
3627 ++/* Power up/down adv7511 */
3628 ++static int adv7511_s_power(struct v4l2_subdev *sd, int on)
3629 ++{
3630 ++ struct adv7511_state *state = get_adv7511_state(sd);
3631 ++ const int retries = 20;
3632 ++ int i;
3633 ++
3634 ++ v4l2_dbg(1, debug, sd, "%s: power %s\n", __func__, on ? "on" : "off");
3635 ++
3636 ++ state->power_on = on;
3637 ++
3638 ++ if (!on) {
3639 ++ /* Power down */
3640 ++ adv7511_wr_and_or(sd, 0x41, 0xbf, 0x40);
3641 ++ return true;
3642 ++ }
3643 ++
3644 ++ /* Power up */
3645 ++ /* The adv7511 does not always come up immediately.
3646 ++ Retry multiple times. */
3647 ++ for (i = 0; i < retries; i++) {
3648 ++ adv7511_wr_and_or(sd, 0x41, 0xbf, 0x0);
3649 ++ if ((adv7511_rd(sd, 0x41) & 0x40) == 0)
3650 ++ break;
3651 ++ adv7511_wr_and_or(sd, 0x41, 0xbf, 0x40);
3652 ++ msleep(10);
3653 ++ }
3654 ++ if (i == retries) {
3655 ++ v4l2_dbg(1, debug, sd, "%s: failed to powerup the adv7511!\n", __func__);
3656 ++ adv7511_s_power(sd, 0);
3657 ++ return false;
3658 ++ }
3659 ++ if (i > 1)
3660 ++ v4l2_dbg(1, debug, sd, "%s: needed %d retries to powerup the adv7511\n", __func__, i);
3661 ++
3662 ++ /* Reserved registers that must be set */
3663 ++ adv7511_wr(sd, 0x98, 0x03);
3664 ++ adv7511_wr_and_or(sd, 0x9a, 0xfe, 0x70);
3665 ++ adv7511_wr(sd, 0x9c, 0x30);
3666 ++ adv7511_wr_and_or(sd, 0x9d, 0xfc, 0x01);
3667 ++ adv7511_wr(sd, 0xa2, 0xa4);
3668 ++ adv7511_wr(sd, 0xa3, 0xa4);
3669 ++ adv7511_wr(sd, 0xe0, 0xd0);
3670 ++ adv7511_wr(sd, 0xf9, 0x00);
3671 ++
3672 ++ adv7511_wr(sd, 0x43, state->i2c_edid_addr);
3673 ++ adv7511_wr(sd, 0x45, state->i2c_pktmem_addr);
3674 ++
3675 ++ /* Set number of attempts to read the EDID */
3676 ++ adv7511_wr(sd, 0xc9, 0xf);
3677 ++ return true;
3678 ++}
3679 ++
3680 ++#if IS_ENABLED(CONFIG_VIDEO_ADV7511_CEC)
3681 ++static int adv7511_cec_adap_enable(struct cec_adapter *adap, bool enable)
3682 ++{
3683 ++ struct adv7511_state *state = cec_get_drvdata(adap);
3684 ++ struct v4l2_subdev *sd = &state->sd;
3685 ++
3686 ++ if (state->i2c_cec == NULL)
3687 ++ return -EIO;
3688 ++
3689 ++ if (!state->cec_enabled_adap && enable) {
3690 ++ /* power up cec section */
3691 ++ adv7511_cec_write_and_or(sd, 0x4e, 0xfc, 0x01);
3692 ++ /* legacy mode and clear all rx buffers */
3693 ++ adv7511_cec_write(sd, 0x4a, 0x07);
3694 ++ adv7511_cec_write(sd, 0x4a, 0);
3695 ++ adv7511_cec_write_and_or(sd, 0x11, 0xfe, 0); /* initially disable tx */
3696 ++ /* enabled irqs: */
3697 ++ /* tx: ready */
3698 ++ /* tx: arbitration lost */
3699 ++ /* tx: retry timeout */
3700 ++ /* rx: ready 1 */
3701 ++ if (state->enabled_irq)
3702 ++ adv7511_wr_and_or(sd, 0x95, 0xc0, 0x39);
3703 ++ } else if (state->cec_enabled_adap && !enable) {
3704 ++ if (state->enabled_irq)
3705 ++ adv7511_wr_and_or(sd, 0x95, 0xc0, 0x00);
3706 ++ /* disable address mask 1-3 */
3707 ++ adv7511_cec_write_and_or(sd, 0x4b, 0x8f, 0x00);
3708 ++ /* power down cec section */
3709 ++ adv7511_cec_write_and_or(sd, 0x4e, 0xfc, 0x00);
3710 ++ state->cec_valid_addrs = 0;
3711 ++ }
3712 ++ state->cec_enabled_adap = enable;
3713 ++ return 0;
3714 ++}
3715 ++
3716 ++static int adv7511_cec_adap_log_addr(struct cec_adapter *adap, u8 addr)
3717 ++{
3718 ++ struct adv7511_state *state = cec_get_drvdata(adap);
3719 ++ struct v4l2_subdev *sd = &state->sd;
3720 ++ unsigned int i, free_idx = ADV7511_MAX_ADDRS;
3721 ++
3722 ++ if (!state->cec_enabled_adap)
3723 ++ return addr == CEC_LOG_ADDR_INVALID ? 0 : -EIO;
3724 ++
3725 ++ if (addr == CEC_LOG_ADDR_INVALID) {
3726 ++ adv7511_cec_write_and_or(sd, 0x4b, 0x8f, 0);
3727 ++ state->cec_valid_addrs = 0;
3728 ++ return 0;
3729 ++ }
3730 ++
3731 ++ for (i = 0; i < ADV7511_MAX_ADDRS; i++) {
3732 ++ bool is_valid = state->cec_valid_addrs & (1 << i);
3733 ++
3734 ++ if (free_idx == ADV7511_MAX_ADDRS && !is_valid)
3735 ++ free_idx = i;
3736 ++ if (is_valid && state->cec_addr[i] == addr)
3737 ++ return 0;
3738 ++ }
3739 ++ if (i == ADV7511_MAX_ADDRS) {
3740 ++ i = free_idx;
3741 ++ if (i == ADV7511_MAX_ADDRS)
3742 ++ return -ENXIO;
3743 ++ }
3744 ++ state->cec_addr[i] = addr;
3745 ++ state->cec_valid_addrs |= 1 << i;
3746 ++
3747 ++ switch (i) {
3748 ++ case 0:
3749 ++ /* enable address mask 0 */
3750 ++ adv7511_cec_write_and_or(sd, 0x4b, 0xef, 0x10);
3751 ++ /* set address for mask 0 */
3752 ++ adv7511_cec_write_and_or(sd, 0x4c, 0xf0, addr);
3753 ++ break;
3754 ++ case 1:
3755 ++ /* enable address mask 1 */
3756 ++ adv7511_cec_write_and_or(sd, 0x4b, 0xdf, 0x20);
3757 ++ /* set address for mask 1 */
3758 ++ adv7511_cec_write_and_or(sd, 0x4c, 0x0f, addr << 4);
3759 ++ break;
3760 ++ case 2:
3761 ++ /* enable address mask 2 */
3762 ++ adv7511_cec_write_and_or(sd, 0x4b, 0xbf, 0x40);
3763 ++ /* set address for mask 1 */
3764 ++ adv7511_cec_write_and_or(sd, 0x4d, 0xf0, addr);
3765 ++ break;
3766 ++ }
3767 ++ return 0;
3768 ++}
3769 ++
3770 ++static int adv7511_cec_adap_transmit(struct cec_adapter *adap, u8 attempts,
3771 ++ u32 signal_free_time, struct cec_msg *msg)
3772 ++{
3773 ++ struct adv7511_state *state = cec_get_drvdata(adap);
3774 ++ struct v4l2_subdev *sd = &state->sd;
3775 ++ u8 len = msg->len;
3776 ++ unsigned int i;
3777 ++
3778 ++ v4l2_dbg(1, debug, sd, "%s: len %d\n", __func__, len);
3779 ++
3780 ++ if (len > 16) {
3781 ++ v4l2_err(sd, "%s: len exceeded 16 (%d)\n", __func__, len);
3782 ++ return -EINVAL;
3783 ++ }
3784 ++
3785 ++ /*
3786 ++ * The number of retries is the number of attempts - 1, but retry
3787 ++ * at least once. It's not clear if a value of 0 is allowed, so
3788 ++ * let's do at least one retry.
3789 ++ */
3790 ++ adv7511_cec_write_and_or(sd, 0x12, ~0x70, max(1, attempts - 1) << 4);
3791 ++
3792 ++ /* blocking, clear cec tx irq status */
3793 ++ adv7511_wr_and_or(sd, 0x97, 0xc7, 0x38);
3794 ++
3795 ++ /* write data */
3796 ++ for (i = 0; i < len; i++)
3797 ++ adv7511_cec_write(sd, i, msg->msg[i]);
3798 ++
3799 ++ /* set length (data + header) */
3800 ++ adv7511_cec_write(sd, 0x10, len);
3801 ++ /* start transmit, enable tx */
3802 ++ adv7511_cec_write(sd, 0x11, 0x01);
3803 ++ return 0;
3804 ++}
3805 ++
3806 ++static void adv_cec_tx_raw_status(struct v4l2_subdev *sd, u8 tx_raw_status)
3807 ++{
3808 ++ struct adv7511_state *state = get_adv7511_state(sd);
3809 ++
3810 ++ if ((adv7511_cec_read(sd, 0x11) & 0x01) == 0) {
3811 ++ v4l2_dbg(1, debug, sd, "%s: tx raw: tx disabled\n", __func__);
3812 ++ return;
3813 ++ }
3814 ++
3815 ++ if (tx_raw_status & 0x10) {
3816 ++ v4l2_dbg(1, debug, sd,
3817 ++ "%s: tx raw: arbitration lost\n", __func__);
3818 ++ cec_transmit_done(state->cec_adap, CEC_TX_STATUS_ARB_LOST,
3819 ++ 1, 0, 0, 0);
3820 ++ return;
3821 ++ }
3822 ++ if (tx_raw_status & 0x08) {
3823 ++ u8 status;
3824 ++ u8 nack_cnt;
3825 ++ u8 low_drive_cnt;
3826 ++
3827 ++ v4l2_dbg(1, debug, sd, "%s: tx raw: retry failed\n", __func__);
3828 ++ /*
3829 ++ * We set this status bit since this hardware performs
3830 ++ * retransmissions.
3831 ++ */
3832 ++ status = CEC_TX_STATUS_MAX_RETRIES;
3833 ++ nack_cnt = adv7511_cec_read(sd, 0x14) & 0xf;
3834 ++ if (nack_cnt)
3835 ++ status |= CEC_TX_STATUS_NACK;
3836 ++ low_drive_cnt = adv7511_cec_read(sd, 0x14) >> 4;
3837 ++ if (low_drive_cnt)
3838 ++ status |= CEC_TX_STATUS_LOW_DRIVE;
3839 ++ cec_transmit_done(state->cec_adap, status,
3840 ++ 0, nack_cnt, low_drive_cnt, 0);
3841 ++ return;
3842 ++ }
3843 ++ if (tx_raw_status & 0x20) {
3844 ++ v4l2_dbg(1, debug, sd, "%s: tx raw: ready ok\n", __func__);
3845 ++ cec_transmit_done(state->cec_adap, CEC_TX_STATUS_OK, 0, 0, 0, 0);
3846 ++ return;
3847 ++ }
3848 ++}
3849 ++
3850 ++static const struct cec_adap_ops adv7511_cec_adap_ops = {
3851 ++ .adap_enable = adv7511_cec_adap_enable,
3852 ++ .adap_log_addr = adv7511_cec_adap_log_addr,
3853 ++ .adap_transmit = adv7511_cec_adap_transmit,
3854 ++};
3855 ++#endif
3856 ++
3857 ++/* Enable interrupts */
3858 ++static void adv7511_set_isr(struct v4l2_subdev *sd, bool enable)
3859 ++{
3860 ++ struct adv7511_state *state = get_adv7511_state(sd);
3861 ++ u8 irqs = MASK_ADV7511_HPD_INT | MASK_ADV7511_MSEN_INT;
3862 ++ u8 irqs_rd;
3863 ++ int retries = 100;
3864 ++
3865 ++ v4l2_dbg(2, debug, sd, "%s: %s\n", __func__, enable ? "enable" : "disable");
3866 ++
3867 ++ if (state->enabled_irq == enable)
3868 ++ return;
3869 ++ state->enabled_irq = enable;
3870 ++
3871 ++ /* The datasheet says that the EDID ready interrupt should be
3872 ++ disabled if there is no hotplug. */
3873 ++ if (!enable)
3874 ++ irqs = 0;
3875 ++ else if (adv7511_have_hotplug(sd))
3876 ++ irqs |= MASK_ADV7511_EDID_RDY_INT;
3877 ++
3878 ++ adv7511_wr_and_or(sd, 0x95, 0xc0,
3879 ++ (state->cec_enabled_adap && enable) ? 0x39 : 0x00);
3880 ++
3881 ++ /*
3882 ++ * This i2c write can fail (approx. 1 in 1000 writes). But it
3883 ++ * is essential that this register is correct, so retry it
3884 ++ * multiple times.
3885 ++ *
3886 ++ * Note that the i2c write does not report an error, but the readback
3887 ++ * clearly shows the wrong value.
3888 ++ */
3889 ++ do {
3890 ++ adv7511_wr(sd, 0x94, irqs);
3891 ++ irqs_rd = adv7511_rd(sd, 0x94);
3892 ++ } while (retries-- && irqs_rd != irqs);
3893 ++
3894 ++ if (irqs_rd == irqs)
3895 ++ return;
3896 ++ v4l2_err(sd, "Could not set interrupts: hw failure?\n");
3897 ++}
3898 ++
3899 ++/* Interrupt handler */
3900 ++static int adv7511_isr(struct v4l2_subdev *sd, u32 status, bool *handled)
3901 ++{
3902 ++ u8 irq_status;
3903 ++ u8 cec_irq;
3904 ++
3905 ++ /* disable interrupts to prevent a race condition */
3906 ++ adv7511_set_isr(sd, false);
3907 ++ irq_status = adv7511_rd(sd, 0x96);
3908 ++ cec_irq = adv7511_rd(sd, 0x97);
3909 ++ /* clear detected interrupts */
3910 ++ adv7511_wr(sd, 0x96, irq_status);
3911 ++ adv7511_wr(sd, 0x97, cec_irq);
3912 ++
3913 ++ v4l2_dbg(1, debug, sd, "%s: irq 0x%x, cec-irq 0x%x\n", __func__,
3914 ++ irq_status, cec_irq);
3915 ++
3916 ++ if (irq_status & (MASK_ADV7511_HPD_INT | MASK_ADV7511_MSEN_INT))
3917 ++ adv7511_check_monitor_present_status(sd);
3918 ++ if (irq_status & MASK_ADV7511_EDID_RDY_INT)
3919 ++ adv7511_check_edid_status(sd);
3920 ++
3921 ++#if IS_ENABLED(CONFIG_VIDEO_ADV7511_CEC)
3922 ++ if (cec_irq & 0x38)
3923 ++ adv_cec_tx_raw_status(sd, cec_irq);
3924 ++
3925 ++ if (cec_irq & 1) {
3926 ++ struct adv7511_state *state = get_adv7511_state(sd);
3927 ++ struct cec_msg msg;
3928 ++
3929 ++ msg.len = adv7511_cec_read(sd, 0x25) & 0x1f;
3930 ++
3931 ++ v4l2_dbg(1, debug, sd, "%s: cec msg len %d\n", __func__,
3932 ++ msg.len);
3933 ++
3934 ++ if (msg.len > 16)
3935 ++ msg.len = 16;
3936 ++
3937 ++ if (msg.len) {
3938 ++ u8 i;
3939 ++
3940 ++ for (i = 0; i < msg.len; i++)
3941 ++ msg.msg[i] = adv7511_cec_read(sd, i + 0x15);
3942 ++
3943 ++ adv7511_cec_write(sd, 0x4a, 1); /* toggle to re-enable rx 1 */
3944 ++ adv7511_cec_write(sd, 0x4a, 0);
3945 ++ cec_received_msg(state->cec_adap, &msg);
3946 ++ }
3947 ++ }
3948 ++#endif
3949 ++
3950 ++ /* enable interrupts */
3951 ++ adv7511_set_isr(sd, true);
3952 ++
3953 ++ if (handled)
3954 ++ *handled = true;
3955 ++ return 0;
3956 ++}
3957 ++
3958 ++static const struct v4l2_subdev_core_ops adv7511_core_ops = {
3959 ++ .log_status = adv7511_log_status,
3960 ++#ifdef CONFIG_VIDEO_ADV_DEBUG
3961 ++ .g_register = adv7511_g_register,
3962 ++ .s_register = adv7511_s_register,
3963 ++#endif
3964 ++ .s_power = adv7511_s_power,
3965 ++ .interrupt_service_routine = adv7511_isr,
3966 ++};
3967 ++
3968 ++/* ------------------------------ VIDEO OPS ------------------------------ */
3969 ++
3970 ++/* Enable/disable adv7511 output */
3971 ++static int adv7511_s_stream(struct v4l2_subdev *sd, int enable)
3972 ++{
3973 ++ struct adv7511_state *state = get_adv7511_state(sd);
3974 ++
3975 ++ v4l2_dbg(1, debug, sd, "%s: %sable\n", __func__, (enable ? "en" : "dis"));
3976 ++ adv7511_wr_and_or(sd, 0xa1, ~0x3c, (enable ? 0 : 0x3c));
3977 ++ if (enable) {
3978 ++ adv7511_check_monitor_present_status(sd);
3979 ++ } else {
3980 ++ adv7511_s_power(sd, 0);
3981 ++ state->have_monitor = false;
3982 ++ }
3983 ++ return 0;
3984 ++}
3985 ++
3986 ++static int adv7511_s_dv_timings(struct v4l2_subdev *sd,
3987 ++ struct v4l2_dv_timings *timings)
3988 ++{
3989 ++ struct adv7511_state *state = get_adv7511_state(sd);
3990 ++ struct v4l2_bt_timings *bt = &timings->bt;
3991 ++ u32 fps;
3992 ++
3993 ++ v4l2_dbg(1, debug, sd, "%s:\n", __func__);
3994 ++
3995 ++ /* quick sanity check */
3996 ++ if (!v4l2_valid_dv_timings(timings, &adv7511_timings_cap, NULL, NULL))
3997 ++ return -EINVAL;
3998 ++
3999 ++ /* Fill the optional fields .standards and .flags in struct v4l2_dv_timings
4000 ++ if the format is one of the CEA or DMT timings. */
4001 ++ v4l2_find_dv_timings_cap(timings, &adv7511_timings_cap, 0, NULL, NULL);
4002 ++
4003 ++ /* save timings */
4004 ++ state->dv_timings = *timings;
4005 ++
4006 ++ /* set h/vsync polarities */
4007 ++ adv7511_wr_and_or(sd, 0x17, 0x9f,
4008 ++ ((bt->polarities & V4L2_DV_VSYNC_POS_POL) ? 0 : 0x40) |
4009 ++ ((bt->polarities & V4L2_DV_HSYNC_POS_POL) ? 0 : 0x20));
4010 ++
4011 ++ fps = (u32)bt->pixelclock / (V4L2_DV_BT_FRAME_WIDTH(bt) * V4L2_DV_BT_FRAME_HEIGHT(bt));
4012 ++ switch (fps) {
4013 ++ case 24:
4014 ++ adv7511_wr_and_or(sd, 0xfb, 0xf9, 1 << 1);
4015 ++ break;
4016 ++ case 25:
4017 ++ adv7511_wr_and_or(sd, 0xfb, 0xf9, 2 << 1);
4018 ++ break;
4019 ++ case 30:
4020 ++ adv7511_wr_and_or(sd, 0xfb, 0xf9, 3 << 1);
4021 ++ break;
4022 ++ default:
4023 ++ adv7511_wr_and_or(sd, 0xfb, 0xf9, 0);
4024 ++ break;
4025 ++ }
4026 ++
4027 ++ /* update quantization range based on new dv_timings */
4028 ++ adv7511_set_rgb_quantization_mode(sd, state->rgb_quantization_range_ctrl);
4029 ++
4030 ++ return 0;
4031 ++}
4032 ++
4033 ++static int adv7511_g_dv_timings(struct v4l2_subdev *sd,
4034 ++ struct v4l2_dv_timings *timings)
4035 ++{
4036 ++ struct adv7511_state *state = get_adv7511_state(sd);
4037 ++
4038 ++ v4l2_dbg(1, debug, sd, "%s:\n", __func__);
4039 ++
4040 ++ if (!timings)
4041 ++ return -EINVAL;
4042 ++
4043 ++ *timings = state->dv_timings;
4044 ++
4045 ++ return 0;
4046 ++}
4047 ++
4048 ++static int adv7511_enum_dv_timings(struct v4l2_subdev *sd,
4049 ++ struct v4l2_enum_dv_timings *timings)
4050 ++{
4051 ++ if (timings->pad != 0)
4052 ++ return -EINVAL;
4053 ++
4054 ++ return v4l2_enum_dv_timings_cap(timings, &adv7511_timings_cap, NULL, NULL);
4055 ++}
4056 ++
4057 ++static int adv7511_dv_timings_cap(struct v4l2_subdev *sd,
4058 ++ struct v4l2_dv_timings_cap *cap)
4059 ++{
4060 ++ if (cap->pad != 0)
4061 ++ return -EINVAL;
4062 ++
4063 ++ *cap = adv7511_timings_cap;
4064 ++ return 0;
4065 ++}
4066 ++
4067 ++static const struct v4l2_subdev_video_ops adv7511_video_ops = {
4068 ++ .s_stream = adv7511_s_stream,
4069 ++ .s_dv_timings = adv7511_s_dv_timings,
4070 ++ .g_dv_timings = adv7511_g_dv_timings,
4071 ++};
4072 ++
4073 ++/* ------------------------------ AUDIO OPS ------------------------------ */
4074 ++static int adv7511_s_audio_stream(struct v4l2_subdev *sd, int enable)
4075 ++{
4076 ++ v4l2_dbg(1, debug, sd, "%s: %sable\n", __func__, (enable ? "en" : "dis"));
4077 ++
4078 ++ if (enable)
4079 ++ adv7511_wr_and_or(sd, 0x4b, 0x3f, 0x80);
4080 ++ else
4081 ++ adv7511_wr_and_or(sd, 0x4b, 0x3f, 0x40);
4082 ++
4083 ++ return 0;
4084 ++}
4085 ++
4086 ++static int adv7511_s_clock_freq(struct v4l2_subdev *sd, u32 freq)
4087 ++{
4088 ++ u32 N;
4089 ++
4090 ++ switch (freq) {
4091 ++ case 32000: N = 4096; break;
4092 ++ case 44100: N = 6272; break;
4093 ++ case 48000: N = 6144; break;
4094 ++ case 88200: N = 12544; break;
4095 ++ case 96000: N = 12288; break;
4096 ++ case 176400: N = 25088; break;
4097 ++ case 192000: N = 24576; break;
4098 ++ default:
4099 ++ return -EINVAL;
4100 ++ }
4101 ++
4102 ++ /* Set N (used with CTS to regenerate the audio clock) */
4103 ++ adv7511_wr(sd, 0x01, (N >> 16) & 0xf);
4104 ++ adv7511_wr(sd, 0x02, (N >> 8) & 0xff);
4105 ++ adv7511_wr(sd, 0x03, N & 0xff);
4106 ++
4107 ++ return 0;
4108 ++}
4109 ++
4110 ++static int adv7511_s_i2s_clock_freq(struct v4l2_subdev *sd, u32 freq)
4111 ++{
4112 ++ u32 i2s_sf;
4113 ++
4114 ++ switch (freq) {
4115 ++ case 32000: i2s_sf = 0x30; break;
4116 ++ case 44100: i2s_sf = 0x00; break;
4117 ++ case 48000: i2s_sf = 0x20; break;
4118 ++ case 88200: i2s_sf = 0x80; break;
4119 ++ case 96000: i2s_sf = 0xa0; break;
4120 ++ case 176400: i2s_sf = 0xc0; break;
4121 ++ case 192000: i2s_sf = 0xe0; break;
4122 ++ default:
4123 ++ return -EINVAL;
4124 ++ }
4125 ++
4126 ++ /* Set sampling frequency for I2S audio to 48 kHz */
4127 ++ adv7511_wr_and_or(sd, 0x15, 0xf, i2s_sf);
4128 ++
4129 ++ return 0;
4130 ++}
4131 ++
4132 ++static int adv7511_s_routing(struct v4l2_subdev *sd, u32 input, u32 output, u32 config)
4133 ++{
4134 ++ /* Only 2 channels in use for application */
4135 ++ adv7511_wr_and_or(sd, 0x73, 0xf8, 0x1);
4136 ++ /* Speaker mapping */
4137 ++ adv7511_wr(sd, 0x76, 0x00);
4138 ++
4139 ++ /* 16 bit audio word length */
4140 ++ adv7511_wr_and_or(sd, 0x14, 0xf0, 0x02);
4141 ++
4142 ++ return 0;
4143 ++}
4144 ++
4145 ++static const struct v4l2_subdev_audio_ops adv7511_audio_ops = {
4146 ++ .s_stream = adv7511_s_audio_stream,
4147 ++ .s_clock_freq = adv7511_s_clock_freq,
4148 ++ .s_i2s_clock_freq = adv7511_s_i2s_clock_freq,
4149 ++ .s_routing = adv7511_s_routing,
4150 ++};
4151 ++
4152 ++/* ---------------------------- PAD OPS ------------------------------------- */
4153 ++
4154 ++static int adv7511_get_edid(struct v4l2_subdev *sd, struct v4l2_edid *edid)
4155 ++{
4156 ++ struct adv7511_state *state = get_adv7511_state(sd);
4157 ++
4158 ++ memset(edid->reserved, 0, sizeof(edid->reserved));
4159 ++
4160 ++ if (edid->pad != 0)
4161 ++ return -EINVAL;
4162 ++
4163 ++ if (edid->start_block == 0 && edid->blocks == 0) {
4164 ++ edid->blocks = state->edid.segments * 2;
4165 ++ return 0;
4166 ++ }
4167 ++
4168 ++ if (state->edid.segments == 0)
4169 ++ return -ENODATA;
4170 ++
4171 ++ if (edid->start_block >= state->edid.segments * 2)
4172 ++ return -EINVAL;
4173 ++
4174 ++ if (edid->start_block + edid->blocks > state->edid.segments * 2)
4175 ++ edid->blocks = state->edid.segments * 2 - edid->start_block;
4176 ++
4177 ++ memcpy(edid->edid, &state->edid.data[edid->start_block * 128],
4178 ++ 128 * edid->blocks);
4179 ++
4180 ++ return 0;
4181 ++}
4182 ++
4183 ++static int adv7511_enum_mbus_code(struct v4l2_subdev *sd,
4184 ++ struct v4l2_subdev_pad_config *cfg,
4185 ++ struct v4l2_subdev_mbus_code_enum *code)
4186 ++{
4187 ++ if (code->pad != 0)
4188 ++ return -EINVAL;
4189 ++
4190 ++ switch (code->index) {
4191 ++ case 0:
4192 ++ code->code = MEDIA_BUS_FMT_RGB888_1X24;
4193 ++ break;
4194 ++ case 1:
4195 ++ code->code = MEDIA_BUS_FMT_YUYV8_1X16;
4196 ++ break;
4197 ++ case 2:
4198 ++ code->code = MEDIA_BUS_FMT_UYVY8_1X16;
4199 ++ break;
4200 ++ default:
4201 ++ return -EINVAL;
4202 ++ }
4203 ++ return 0;
4204 ++}
4205 ++
4206 ++static void adv7511_fill_format(struct adv7511_state *state,
4207 ++ struct v4l2_mbus_framefmt *format)
4208 ++{
4209 ++ format->width = state->dv_timings.bt.width;
4210 ++ format->height = state->dv_timings.bt.height;
4211 ++ format->field = V4L2_FIELD_NONE;
4212 ++}
4213 ++
4214 ++static int adv7511_get_fmt(struct v4l2_subdev *sd,
4215 ++ struct v4l2_subdev_pad_config *cfg,
4216 ++ struct v4l2_subdev_format *format)
4217 ++{
4218 ++ struct adv7511_state *state = get_adv7511_state(sd);
4219 ++
4220 ++ if (format->pad != 0)
4221 ++ return -EINVAL;
4222 ++
4223 ++ memset(&format->format, 0, sizeof(format->format));
4224 ++ adv7511_fill_format(state, &format->format);
4225 ++
4226 ++ if (format->which == V4L2_SUBDEV_FORMAT_TRY) {
4227 ++ struct v4l2_mbus_framefmt *fmt;
4228 ++
4229 ++ fmt = v4l2_subdev_get_try_format(sd, cfg, format->pad);
4230 ++ format->format.code = fmt->code;
4231 ++ format->format.colorspace = fmt->colorspace;
4232 ++ format->format.ycbcr_enc = fmt->ycbcr_enc;
4233 ++ format->format.quantization = fmt->quantization;
4234 ++ format->format.xfer_func = fmt->xfer_func;
4235 ++ } else {
4236 ++ format->format.code = state->fmt_code;
4237 ++ format->format.colorspace = state->colorspace;
4238 ++ format->format.ycbcr_enc = state->ycbcr_enc;
4239 ++ format->format.quantization = state->quantization;
4240 ++ format->format.xfer_func = state->xfer_func;
4241 ++ }
4242 ++
4243 ++ return 0;
4244 ++}
4245 ++
4246 ++static int adv7511_set_fmt(struct v4l2_subdev *sd,
4247 ++ struct v4l2_subdev_pad_config *cfg,
4248 ++ struct v4l2_subdev_format *format)
4249 ++{
4250 ++ struct adv7511_state *state = get_adv7511_state(sd);
4251 ++ /*
4252 ++ * Bitfield namings come the CEA-861-F standard, table 8 "Auxiliary
4253 ++ * Video Information (AVI) InfoFrame Format"
4254 ++ *
4255 ++ * c = Colorimetry
4256 ++ * ec = Extended Colorimetry
4257 ++ * y = RGB or YCbCr
4258 ++ * q = RGB Quantization Range
4259 ++ * yq = YCC Quantization Range
4260 ++ */
4261 ++ u8 c = HDMI_COLORIMETRY_NONE;
4262 ++ u8 ec = HDMI_EXTENDED_COLORIMETRY_XV_YCC_601;
4263 ++ u8 y = HDMI_COLORSPACE_RGB;
4264 ++ u8 q = HDMI_QUANTIZATION_RANGE_DEFAULT;
4265 ++ u8 yq = HDMI_YCC_QUANTIZATION_RANGE_LIMITED;
4266 ++ u8 itc = state->content_type != V4L2_DV_IT_CONTENT_TYPE_NO_ITC;
4267 ++ u8 cn = itc ? state->content_type : V4L2_DV_IT_CONTENT_TYPE_GRAPHICS;
4268 ++
4269 ++ if (format->pad != 0)
4270 ++ return -EINVAL;
4271 ++ switch (format->format.code) {
4272 ++ case MEDIA_BUS_FMT_UYVY8_1X16:
4273 ++ case MEDIA_BUS_FMT_YUYV8_1X16:
4274 ++ case MEDIA_BUS_FMT_RGB888_1X24:
4275 ++ break;
4276 ++ default:
4277 ++ return -EINVAL;
4278 ++ }
4279 ++
4280 ++ adv7511_fill_format(state, &format->format);
4281 ++ if (format->which == V4L2_SUBDEV_FORMAT_TRY) {
4282 ++ struct v4l2_mbus_framefmt *fmt;
4283 ++
4284 ++ fmt = v4l2_subdev_get_try_format(sd, cfg, format->pad);
4285 ++ fmt->code = format->format.code;
4286 ++ fmt->colorspace = format->format.colorspace;
4287 ++ fmt->ycbcr_enc = format->format.ycbcr_enc;
4288 ++ fmt->quantization = format->format.quantization;
4289 ++ fmt->xfer_func = format->format.xfer_func;
4290 ++ return 0;
4291 ++ }
4292 ++
4293 ++ switch (format->format.code) {
4294 ++ case MEDIA_BUS_FMT_UYVY8_1X16:
4295 ++ adv7511_wr_and_or(sd, 0x15, 0xf0, 0x01);
4296 ++ adv7511_wr_and_or(sd, 0x16, 0x03, 0xb8);
4297 ++ y = HDMI_COLORSPACE_YUV422;
4298 ++ break;
4299 ++ case MEDIA_BUS_FMT_YUYV8_1X16:
4300 ++ adv7511_wr_and_or(sd, 0x15, 0xf0, 0x01);
4301 ++ adv7511_wr_and_or(sd, 0x16, 0x03, 0xbc);
4302 ++ y = HDMI_COLORSPACE_YUV422;
4303 ++ break;
4304 ++ case MEDIA_BUS_FMT_RGB888_1X24:
4305 ++ default:
4306 ++ adv7511_wr_and_or(sd, 0x15, 0xf0, 0x00);
4307 ++ adv7511_wr_and_or(sd, 0x16, 0x03, 0x00);
4308 ++ break;
4309 ++ }
4310 ++ state->fmt_code = format->format.code;
4311 ++ state->colorspace = format->format.colorspace;
4312 ++ state->ycbcr_enc = format->format.ycbcr_enc;
4313 ++ state->quantization = format->format.quantization;
4314 ++ state->xfer_func = format->format.xfer_func;
4315 ++
4316 ++ switch (format->format.colorspace) {
4317 ++ case V4L2_COLORSPACE_ADOBERGB:
4318 ++ c = HDMI_COLORIMETRY_EXTENDED;
4319 ++ ec = y ? HDMI_EXTENDED_COLORIMETRY_ADOBE_YCC_601 :
4320 ++ HDMI_EXTENDED_COLORIMETRY_ADOBE_RGB;
4321 ++ break;
4322 ++ case V4L2_COLORSPACE_SMPTE170M:
4323 ++ c = y ? HDMI_COLORIMETRY_ITU_601 : HDMI_COLORIMETRY_NONE;
4324 ++ if (y && format->format.ycbcr_enc == V4L2_YCBCR_ENC_XV601) {
4325 ++ c = HDMI_COLORIMETRY_EXTENDED;
4326 ++ ec = HDMI_EXTENDED_COLORIMETRY_XV_YCC_601;
4327 ++ }
4328 ++ break;
4329 ++ case V4L2_COLORSPACE_REC709:
4330 ++ c = y ? HDMI_COLORIMETRY_ITU_709 : HDMI_COLORIMETRY_NONE;
4331 ++ if (y && format->format.ycbcr_enc == V4L2_YCBCR_ENC_XV709) {
4332 ++ c = HDMI_COLORIMETRY_EXTENDED;
4333 ++ ec = HDMI_EXTENDED_COLORIMETRY_XV_YCC_709;
4334 ++ }
4335 ++ break;
4336 ++ case V4L2_COLORSPACE_SRGB:
4337 ++ c = y ? HDMI_COLORIMETRY_EXTENDED : HDMI_COLORIMETRY_NONE;
4338 ++ ec = y ? HDMI_EXTENDED_COLORIMETRY_S_YCC_601 :
4339 ++ HDMI_EXTENDED_COLORIMETRY_XV_YCC_601;
4340 ++ break;
4341 ++ case V4L2_COLORSPACE_BT2020:
4342 ++ c = HDMI_COLORIMETRY_EXTENDED;
4343 ++ if (y && format->format.ycbcr_enc == V4L2_YCBCR_ENC_BT2020_CONST_LUM)
4344 ++ ec = 5; /* Not yet available in hdmi.h */
4345 ++ else
4346 ++ ec = 6; /* Not yet available in hdmi.h */
4347 ++ break;
4348 ++ default:
4349 ++ break;
4350 ++ }
4351 ++
4352 ++ /*
4353 ++ * CEA-861-F says that for RGB formats the YCC range must match the
4354 ++ * RGB range, although sources should ignore the YCC range.
4355 ++ *
4356 ++ * The RGB quantization range shouldn't be non-zero if the EDID doesn't
4357 ++ * have the Q bit set in the Video Capabilities Data Block, however this
4358 ++ * isn't checked at the moment. The assumption is that the application
4359 ++ * knows the EDID and can detect this.
4360 ++ *
4361 ++ * The same is true for the YCC quantization range: non-standard YCC
4362 ++ * quantization ranges should only be sent if the EDID has the YQ bit
4363 ++ * set in the Video Capabilities Data Block.
4364 ++ */
4365 ++ switch (format->format.quantization) {
4366 ++ case V4L2_QUANTIZATION_FULL_RANGE:
4367 ++ q = y ? HDMI_QUANTIZATION_RANGE_DEFAULT :
4368 ++ HDMI_QUANTIZATION_RANGE_FULL;
4369 ++ yq = q ? q - 1 : HDMI_YCC_QUANTIZATION_RANGE_FULL;
4370 ++ break;
4371 ++ case V4L2_QUANTIZATION_LIM_RANGE:
4372 ++ q = y ? HDMI_QUANTIZATION_RANGE_DEFAULT :
4373 ++ HDMI_QUANTIZATION_RANGE_LIMITED;
4374 ++ yq = q ? q - 1 : HDMI_YCC_QUANTIZATION_RANGE_LIMITED;
4375 ++ break;
4376 ++ }
4377 ++
4378 ++ adv7511_wr_and_or(sd, 0x4a, 0xbf, 0);
4379 ++ adv7511_wr_and_or(sd, 0x55, 0x9f, y << 5);
4380 ++ adv7511_wr_and_or(sd, 0x56, 0x3f, c << 6);
4381 ++ adv7511_wr_and_or(sd, 0x57, 0x83, (ec << 4) | (q << 2) | (itc << 7));
4382 ++ adv7511_wr_and_or(sd, 0x59, 0x0f, (yq << 6) | (cn << 4));
4383 ++ adv7511_wr_and_or(sd, 0x4a, 0xff, 1);
4384 ++ adv7511_set_rgb_quantization_mode(sd, state->rgb_quantization_range_ctrl);
4385 ++
4386 ++ return 0;
4387 ++}
4388 ++
4389 ++static const struct v4l2_subdev_pad_ops adv7511_pad_ops = {
4390 ++ .get_edid = adv7511_get_edid,
4391 ++ .enum_mbus_code = adv7511_enum_mbus_code,
4392 ++ .get_fmt = adv7511_get_fmt,
4393 ++ .set_fmt = adv7511_set_fmt,
4394 ++ .enum_dv_timings = adv7511_enum_dv_timings,
4395 ++ .dv_timings_cap = adv7511_dv_timings_cap,
4396 ++};
4397 ++
4398 ++/* --------------------- SUBDEV OPS --------------------------------------- */
4399 ++
4400 ++static const struct v4l2_subdev_ops adv7511_ops = {
4401 ++ .core = &adv7511_core_ops,
4402 ++ .pad = &adv7511_pad_ops,
4403 ++ .video = &adv7511_video_ops,
4404 ++ .audio = &adv7511_audio_ops,
4405 ++};
4406 ++
4407 ++/* ----------------------------------------------------------------------- */
4408 ++static void adv7511_dbg_dump_edid(int lvl, int debug, struct v4l2_subdev *sd, int segment, u8 *buf)
4409 ++{
4410 ++ if (debug >= lvl) {
4411 ++ int i, j;
4412 ++ v4l2_dbg(lvl, debug, sd, "edid segment %d\n", segment);
4413 ++ for (i = 0; i < 256; i += 16) {
4414 ++ u8 b[128];
4415 ++ u8 *bp = b;
4416 ++ if (i == 128)
4417 ++ v4l2_dbg(lvl, debug, sd, "\n");
4418 ++ for (j = i; j < i + 16; j++) {
4419 ++ sprintf(bp, "0x%02x, ", buf[j]);
4420 ++ bp += 6;
4421 ++ }
4422 ++ bp[0] = '\0';
4423 ++ v4l2_dbg(lvl, debug, sd, "%s\n", b);
4424 ++ }
4425 ++ }
4426 ++}
4427 ++
4428 ++static void adv7511_notify_no_edid(struct v4l2_subdev *sd)
4429 ++{
4430 ++ struct adv7511_state *state = get_adv7511_state(sd);
4431 ++ struct adv7511_edid_detect ed;
4432 ++
4433 ++ /* We failed to read the EDID, so send an event for this. */
4434 ++ ed.present = false;
4435 ++ ed.segment = adv7511_rd(sd, 0xc4);
4436 ++ ed.phys_addr = CEC_PHYS_ADDR_INVALID;
4437 ++ cec_s_phys_addr(state->cec_adap, ed.phys_addr, false);
4438 ++ v4l2_subdev_notify(sd, ADV7511_EDID_DETECT, (void *)&ed);
4439 ++ v4l2_ctrl_s_ctrl(state->have_edid0_ctrl, 0x0);
4440 ++}
4441 ++
4442 ++static void adv7511_edid_handler(struct work_struct *work)
4443 ++{
4444 ++ struct delayed_work *dwork = to_delayed_work(work);
4445 ++ struct adv7511_state *state = container_of(dwork, struct adv7511_state, edid_handler);
4446 ++ struct v4l2_subdev *sd = &state->sd;
4447 ++
4448 ++ v4l2_dbg(1, debug, sd, "%s:\n", __func__);
4449 ++
4450 ++ if (adv7511_check_edid_status(sd)) {
4451 ++ /* Return if we received the EDID. */
4452 ++ return;
4453 ++ }
4454 ++
4455 ++ if (adv7511_have_hotplug(sd)) {
4456 ++ /* We must retry reading the EDID several times, it is possible
4457 ++ * that initially the EDID couldn't be read due to i2c errors
4458 ++ * (DVI connectors are particularly prone to this problem). */
4459 ++ if (state->edid.read_retries) {
4460 ++ state->edid.read_retries--;
4461 ++ v4l2_dbg(1, debug, sd, "%s: edid read failed\n", __func__);
4462 ++ state->have_monitor = false;
4463 ++ adv7511_s_power(sd, false);
4464 ++ adv7511_s_power(sd, true);
4465 ++ queue_delayed_work(state->work_queue, &state->edid_handler, EDID_DELAY);
4466 ++ return;
4467 ++ }
4468 ++ }
4469 ++
4470 ++ /* We failed to read the EDID, so send an event for this. */
4471 ++ adv7511_notify_no_edid(sd);
4472 ++ v4l2_dbg(1, debug, sd, "%s: no edid found\n", __func__);
4473 ++}
4474 ++
4475 ++static void adv7511_audio_setup(struct v4l2_subdev *sd)
4476 ++{
4477 ++ v4l2_dbg(1, debug, sd, "%s\n", __func__);
4478 ++
4479 ++ adv7511_s_i2s_clock_freq(sd, 48000);
4480 ++ adv7511_s_clock_freq(sd, 48000);
4481 ++ adv7511_s_routing(sd, 0, 0, 0);
4482 ++}
4483 ++
4484 ++/* Configure hdmi transmitter. */
4485 ++static void adv7511_setup(struct v4l2_subdev *sd)
4486 ++{
4487 ++ struct adv7511_state *state = get_adv7511_state(sd);
4488 ++ v4l2_dbg(1, debug, sd, "%s\n", __func__);
4489 ++
4490 ++ /* Input format: RGB 4:4:4 */
4491 ++ adv7511_wr_and_or(sd, 0x15, 0xf0, 0x0);
4492 ++ /* Output format: RGB 4:4:4 */
4493 ++ adv7511_wr_and_or(sd, 0x16, 0x7f, 0x0);
4494 ++ /* 1st order interpolation 4:2:2 -> 4:4:4 up conversion, Aspect ratio: 16:9 */
4495 ++ adv7511_wr_and_or(sd, 0x17, 0xf9, 0x06);
4496 ++ /* Disable pixel repetition */
4497 ++ adv7511_wr_and_or(sd, 0x3b, 0x9f, 0x0);
4498 ++ /* Disable CSC */
4499 ++ adv7511_wr_and_or(sd, 0x18, 0x7f, 0x0);
4500 ++ /* Output format: RGB 4:4:4, Active Format Information is valid,
4501 ++ * underscanned */
4502 ++ adv7511_wr_and_or(sd, 0x55, 0x9c, 0x12);
4503 ++ /* AVI Info frame packet enable, Audio Info frame disable */
4504 ++ adv7511_wr_and_or(sd, 0x44, 0xe7, 0x10);
4505 ++ /* Colorimetry, Active format aspect ratio: same as picure. */
4506 ++ adv7511_wr(sd, 0x56, 0xa8);
4507 ++ /* No encryption */
4508 ++ adv7511_wr_and_or(sd, 0xaf, 0xed, 0x0);
4509 ++
4510 ++ /* Positive clk edge capture for input video clock */
4511 ++ adv7511_wr_and_or(sd, 0xba, 0x1f, 0x60);
4512 ++
4513 ++ adv7511_audio_setup(sd);
4514 ++
4515 ++ v4l2_ctrl_handler_setup(&state->hdl);
4516 ++}
4517 ++
4518 ++static void adv7511_notify_monitor_detect(struct v4l2_subdev *sd)
4519 ++{
4520 ++ struct adv7511_monitor_detect mdt;
4521 ++ struct adv7511_state *state = get_adv7511_state(sd);
4522 ++
4523 ++ mdt.present = state->have_monitor;
4524 ++ v4l2_subdev_notify(sd, ADV7511_MONITOR_DETECT, (void *)&mdt);
4525 ++}
4526 ++
4527 ++static void adv7511_check_monitor_present_status(struct v4l2_subdev *sd)
4528 ++{
4529 ++ struct adv7511_state *state = get_adv7511_state(sd);
4530 ++ /* read hotplug and rx-sense state */
4531 ++ u8 status = adv7511_rd(sd, 0x42);
4532 ++
4533 ++ v4l2_dbg(1, debug, sd, "%s: status: 0x%x%s%s\n",
4534 ++ __func__,
4535 ++ status,
4536 ++ status & MASK_ADV7511_HPD_DETECT ? ", hotplug" : "",
4537 ++ status & MASK_ADV7511_MSEN_DETECT ? ", rx-sense" : "");
4538 ++
4539 ++ /* update read only ctrls */
4540 ++ v4l2_ctrl_s_ctrl(state->hotplug_ctrl, adv7511_have_hotplug(sd) ? 0x1 : 0x0);
4541 ++ v4l2_ctrl_s_ctrl(state->rx_sense_ctrl, adv7511_have_rx_sense(sd) ? 0x1 : 0x0);
4542 ++
4543 ++ if ((status & MASK_ADV7511_HPD_DETECT) && ((status & MASK_ADV7511_MSEN_DETECT) || state->edid.segments)) {
4544 ++ v4l2_dbg(1, debug, sd, "%s: hotplug and (rx-sense or edid)\n", __func__);
4545 ++ if (!state->have_monitor) {
4546 ++ v4l2_dbg(1, debug, sd, "%s: monitor detected\n", __func__);
4547 ++ state->have_monitor = true;
4548 ++ adv7511_set_isr(sd, true);
4549 ++ if (!adv7511_s_power(sd, true)) {
4550 ++ v4l2_dbg(1, debug, sd, "%s: monitor detected, powerup failed\n", __func__);
4551 ++ return;
4552 ++ }
4553 ++ adv7511_setup(sd);
4554 ++ adv7511_notify_monitor_detect(sd);
4555 ++ state->edid.read_retries = EDID_MAX_RETRIES;
4556 ++ queue_delayed_work(state->work_queue, &state->edid_handler, EDID_DELAY);
4557 ++ }
4558 ++ } else if (status & MASK_ADV7511_HPD_DETECT) {
4559 ++ v4l2_dbg(1, debug, sd, "%s: hotplug detected\n", __func__);
4560 ++ state->edid.read_retries = EDID_MAX_RETRIES;
4561 ++ queue_delayed_work(state->work_queue, &state->edid_handler, EDID_DELAY);
4562 ++ } else if (!(status & MASK_ADV7511_HPD_DETECT)) {
4563 ++ v4l2_dbg(1, debug, sd, "%s: hotplug not detected\n", __func__);
4564 ++ if (state->have_monitor) {
4565 ++ v4l2_dbg(1, debug, sd, "%s: monitor not detected\n", __func__);
4566 ++ state->have_monitor = false;
4567 ++ adv7511_notify_monitor_detect(sd);
4568 ++ }
4569 ++ adv7511_s_power(sd, false);
4570 ++ memset(&state->edid, 0, sizeof(struct adv7511_state_edid));
4571 ++ adv7511_notify_no_edid(sd);
4572 ++ }
4573 ++}
4574 ++
4575 ++static bool edid_block_verify_crc(u8 *edid_block)
4576 ++{
4577 ++ u8 sum = 0;
4578 ++ int i;
4579 ++
4580 ++ for (i = 0; i < 128; i++)
4581 ++ sum += edid_block[i];
4582 ++ return sum == 0;
4583 ++}
4584 ++
4585 ++static bool edid_verify_crc(struct v4l2_subdev *sd, u32 segment)
4586 ++{
4587 ++ struct adv7511_state *state = get_adv7511_state(sd);
4588 ++ u32 blocks = state->edid.blocks;
4589 ++ u8 *data = state->edid.data;
4590 ++
4591 ++ if (!edid_block_verify_crc(&data[segment * 256]))
4592 ++ return false;
4593 ++ if ((segment + 1) * 2 <= blocks)
4594 ++ return edid_block_verify_crc(&data[segment * 256 + 128]);
4595 ++ return true;
4596 ++}
4597 ++
4598 ++static bool edid_verify_header(struct v4l2_subdev *sd, u32 segment)
4599 ++{
4600 ++ static const u8 hdmi_header[] = {
4601 ++ 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00
4602 ++ };
4603 ++ struct adv7511_state *state = get_adv7511_state(sd);
4604 ++ u8 *data = state->edid.data;
4605 ++
4606 ++ if (segment != 0)
4607 ++ return true;
4608 ++ return !memcmp(data, hdmi_header, sizeof(hdmi_header));
4609 ++}
4610 ++
4611 ++static bool adv7511_check_edid_status(struct v4l2_subdev *sd)
4612 ++{
4613 ++ struct adv7511_state *state = get_adv7511_state(sd);
4614 ++ u8 edidRdy = adv7511_rd(sd, 0xc5);
4615 ++
4616 ++ v4l2_dbg(1, debug, sd, "%s: edid ready (retries: %d)\n",
4617 ++ __func__, EDID_MAX_RETRIES - state->edid.read_retries);
4618 ++
4619 ++ if (state->edid.complete)
4620 ++ return true;
4621 ++
4622 ++ if (edidRdy & MASK_ADV7511_EDID_RDY) {
4623 ++ int segment = adv7511_rd(sd, 0xc4);
4624 ++ struct adv7511_edid_detect ed;
4625 ++
4626 ++ if (segment >= EDID_MAX_SEGM) {
4627 ++ v4l2_err(sd, "edid segment number too big\n");
4628 ++ return false;
4629 ++ }
4630 ++ v4l2_dbg(1, debug, sd, "%s: got segment %d\n", __func__, segment);
4631 ++ adv7511_edid_rd(sd, 256, &state->edid.data[segment * 256]);
4632 ++ adv7511_dbg_dump_edid(2, debug, sd, segment, &state->edid.data[segment * 256]);
4633 ++ if (segment == 0) {
4634 ++ state->edid.blocks = state->edid.data[0x7e] + 1;
4635 ++ v4l2_dbg(1, debug, sd, "%s: %d blocks in total\n", __func__, state->edid.blocks);
4636 ++ }
4637 ++ if (!edid_verify_crc(sd, segment) ||
4638 ++ !edid_verify_header(sd, segment)) {
4639 ++ /* edid crc error, force reread of edid segment */
4640 ++ v4l2_err(sd, "%s: edid crc or header error\n", __func__);
4641 ++ state->have_monitor = false;
4642 ++ adv7511_s_power(sd, false);
4643 ++ adv7511_s_power(sd, true);
4644 ++ return false;
4645 ++ }
4646 ++ /* one more segment read ok */
4647 ++ state->edid.segments = segment + 1;
4648 ++ v4l2_ctrl_s_ctrl(state->have_edid0_ctrl, 0x1);
4649 ++ if (((state->edid.data[0x7e] >> 1) + 1) > state->edid.segments) {
4650 ++ /* Request next EDID segment */
4651 ++ v4l2_dbg(1, debug, sd, "%s: request segment %d\n", __func__, state->edid.segments);
4652 ++ adv7511_wr(sd, 0xc9, 0xf);
4653 ++ adv7511_wr(sd, 0xc4, state->edid.segments);
4654 ++ state->edid.read_retries = EDID_MAX_RETRIES;
4655 ++ queue_delayed_work(state->work_queue, &state->edid_handler, EDID_DELAY);
4656 ++ return false;
4657 ++ }
4658 ++
4659 ++ v4l2_dbg(1, debug, sd, "%s: edid complete with %d segment(s)\n", __func__, state->edid.segments);
4660 ++ state->edid.complete = true;
4661 ++ ed.phys_addr = cec_get_edid_phys_addr(state->edid.data,
4662 ++ state->edid.segments * 256,
4663 ++ NULL);
4664 ++ /* report when we have all segments
4665 ++ but report only for segment 0
4666 ++ */
4667 ++ ed.present = true;
4668 ++ ed.segment = 0;
4669 ++ state->edid_detect_counter++;
4670 ++ cec_s_phys_addr(state->cec_adap, ed.phys_addr, false);
4671 ++ v4l2_subdev_notify(sd, ADV7511_EDID_DETECT, (void *)&ed);
4672 ++ return ed.present;
4673 ++ }
4674 ++
4675 ++ return false;
4676 ++}
4677 ++
4678 ++static int adv7511_registered(struct v4l2_subdev *sd)
4679 ++{
4680 ++ struct adv7511_state *state = get_adv7511_state(sd);
4681 ++ struct i2c_client *client = v4l2_get_subdevdata(sd);
4682 ++ int err;
4683 ++
4684 ++ err = cec_register_adapter(state->cec_adap, &client->dev);
4685 ++ if (err)
4686 ++ cec_delete_adapter(state->cec_adap);
4687 ++ return err;
4688 ++}
4689 ++
4690 ++static void adv7511_unregistered(struct v4l2_subdev *sd)
4691 ++{
4692 ++ struct adv7511_state *state = get_adv7511_state(sd);
4693 ++
4694 ++ cec_unregister_adapter(state->cec_adap);
4695 ++}
4696 ++
4697 ++static const struct v4l2_subdev_internal_ops adv7511_int_ops = {
4698 ++ .registered = adv7511_registered,
4699 ++ .unregistered = adv7511_unregistered,
4700 ++};
4701 ++
4702 ++/* ----------------------------------------------------------------------- */
4703 ++/* Setup ADV7511 */
4704 ++static void adv7511_init_setup(struct v4l2_subdev *sd)
4705 ++{
4706 ++ struct adv7511_state *state = get_adv7511_state(sd);
4707 ++ struct adv7511_state_edid *edid = &state->edid;
4708 ++ u32 cec_clk = state->pdata.cec_clk;
4709 ++ u8 ratio;
4710 ++
4711 ++ v4l2_dbg(1, debug, sd, "%s\n", __func__);
4712 ++
4713 ++ /* clear all interrupts */
4714 ++ adv7511_wr(sd, 0x96, 0xff);
4715 ++ adv7511_wr(sd, 0x97, 0xff);
4716 ++ /*
4717 ++ * Stop HPD from resetting a lot of registers.
4718 ++ * It might leave the chip in a partly un-initialized state,
4719 ++ * in particular with regards to hotplug bounces.
4720 ++ */
4721 ++ adv7511_wr_and_or(sd, 0xd6, 0x3f, 0xc0);
4722 ++ memset(edid, 0, sizeof(struct adv7511_state_edid));
4723 ++ state->have_monitor = false;
4724 ++ adv7511_set_isr(sd, false);
4725 ++ adv7511_s_stream(sd, false);
4726 ++ adv7511_s_audio_stream(sd, false);
4727 ++
4728 ++ if (state->i2c_cec == NULL)
4729 ++ return;
4730 ++
4731 ++ v4l2_dbg(1, debug, sd, "%s: cec_clk %d\n", __func__, cec_clk);
4732 ++
4733 ++ /* cec soft reset */
4734 ++ adv7511_cec_write(sd, 0x50, 0x01);
4735 ++ adv7511_cec_write(sd, 0x50, 0x00);
4736 ++
4737 ++ /* legacy mode */
4738 ++ adv7511_cec_write(sd, 0x4a, 0x00);
4739 ++
4740 ++ if (cec_clk % 750000 != 0)
4741 ++ v4l2_err(sd, "%s: cec_clk %d, not multiple of 750 Khz\n",
4742 ++ __func__, cec_clk);
4743 ++
4744 ++ ratio = (cec_clk / 750000) - 1;
4745 ++ adv7511_cec_write(sd, 0x4e, ratio << 2);
4746 ++}
4747 ++
4748 ++static int adv7511_probe(struct i2c_client *client, const struct i2c_device_id *id)
4749 ++{
4750 ++ struct adv7511_state *state;
4751 ++ struct adv7511_platform_data *pdata = client->dev.platform_data;
4752 ++ struct v4l2_ctrl_handler *hdl;
4753 ++ struct v4l2_subdev *sd;
4754 ++ u8 chip_id[2];
4755 ++ int err = -EIO;
4756 ++
4757 ++ /* Check if the adapter supports the needed features */
4758 ++ if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA))
4759 ++ return -EIO;
4760 ++
4761 ++ state = devm_kzalloc(&client->dev, sizeof(struct adv7511_state), GFP_KERNEL);
4762 ++ if (!state)
4763 ++ return -ENOMEM;
4764 ++
4765 ++ /* Platform data */
4766 ++ if (!pdata) {
4767 ++ v4l_err(client, "No platform data!\n");
4768 ++ return -ENODEV;
4769 ++ }
4770 ++ memcpy(&state->pdata, pdata, sizeof(state->pdata));
4771 ++ state->fmt_code = MEDIA_BUS_FMT_RGB888_1X24;
4772 ++ state->colorspace = V4L2_COLORSPACE_SRGB;
4773 ++
4774 ++ sd = &state->sd;
4775 ++
4776 ++ v4l2_dbg(1, debug, sd, "detecting adv7511 client on address 0x%x\n",
4777 ++ client->addr << 1);
4778 ++
4779 ++ v4l2_i2c_subdev_init(sd, client, &adv7511_ops);
4780 ++ sd->internal_ops = &adv7511_int_ops;
4781 ++
4782 ++ hdl = &state->hdl;
4783 ++ v4l2_ctrl_handler_init(hdl, 10);
4784 ++ /* add in ascending ID order */
4785 ++ state->hdmi_mode_ctrl = v4l2_ctrl_new_std_menu(hdl, &adv7511_ctrl_ops,
4786 ++ V4L2_CID_DV_TX_MODE, V4L2_DV_TX_MODE_HDMI,
4787 ++ 0, V4L2_DV_TX_MODE_DVI_D);
4788 ++ state->hotplug_ctrl = v4l2_ctrl_new_std(hdl, NULL,
4789 ++ V4L2_CID_DV_TX_HOTPLUG, 0, 1, 0, 0);
4790 ++ state->rx_sense_ctrl = v4l2_ctrl_new_std(hdl, NULL,
4791 ++ V4L2_CID_DV_TX_RXSENSE, 0, 1, 0, 0);
4792 ++ state->have_edid0_ctrl = v4l2_ctrl_new_std(hdl, NULL,
4793 ++ V4L2_CID_DV_TX_EDID_PRESENT, 0, 1, 0, 0);
4794 ++ state->rgb_quantization_range_ctrl =
4795 ++ v4l2_ctrl_new_std_menu(hdl, &adv7511_ctrl_ops,
4796 ++ V4L2_CID_DV_TX_RGB_RANGE, V4L2_DV_RGB_RANGE_FULL,
4797 ++ 0, V4L2_DV_RGB_RANGE_AUTO);
4798 ++ state->content_type_ctrl =
4799 ++ v4l2_ctrl_new_std_menu(hdl, &adv7511_ctrl_ops,
4800 ++ V4L2_CID_DV_TX_IT_CONTENT_TYPE, V4L2_DV_IT_CONTENT_TYPE_NO_ITC,
4801 ++ 0, V4L2_DV_IT_CONTENT_TYPE_NO_ITC);
4802 ++ sd->ctrl_handler = hdl;
4803 ++ if (hdl->error) {
4804 ++ err = hdl->error;
4805 ++ goto err_hdl;
4806 ++ }
4807 ++ state->pad.flags = MEDIA_PAD_FL_SINK;
4808 ++ err = media_entity_pads_init(&sd->entity, 1, &state->pad);
4809 ++ if (err)
4810 ++ goto err_hdl;
4811 ++
4812 ++ /* EDID and CEC i2c addr */
4813 ++ state->i2c_edid_addr = state->pdata.i2c_edid << 1;
4814 ++ state->i2c_cec_addr = state->pdata.i2c_cec << 1;
4815 ++ state->i2c_pktmem_addr = state->pdata.i2c_pktmem << 1;
4816 ++
4817 ++ state->chip_revision = adv7511_rd(sd, 0x0);
4818 ++ chip_id[0] = adv7511_rd(sd, 0xf5);
4819 ++ chip_id[1] = adv7511_rd(sd, 0xf6);
4820 ++ if (chip_id[0] != 0x75 || chip_id[1] != 0x11) {
4821 ++ v4l2_err(sd, "chip_id != 0x7511, read 0x%02x%02x\n", chip_id[0],
4822 ++ chip_id[1]);
4823 ++ err = -EIO;
4824 ++ goto err_entity;
4825 ++ }
4826 ++
4827 ++ state->i2c_edid = i2c_new_dummy(client->adapter,
4828 ++ state->i2c_edid_addr >> 1);
4829 ++ if (state->i2c_edid == NULL) {
4830 ++ v4l2_err(sd, "failed to register edid i2c client\n");
4831 ++ err = -ENOMEM;
4832 ++ goto err_entity;
4833 ++ }
4834 ++
4835 ++ adv7511_wr(sd, 0xe1, state->i2c_cec_addr);
4836 ++ if (state->pdata.cec_clk < 3000000 ||
4837 ++ state->pdata.cec_clk > 100000000) {
4838 ++ v4l2_err(sd, "%s: cec_clk %u outside range, disabling cec\n",
4839 ++ __func__, state->pdata.cec_clk);
4840 ++ state->pdata.cec_clk = 0;
4841 ++ }
4842 ++
4843 ++ if (state->pdata.cec_clk) {
4844 ++ state->i2c_cec = i2c_new_dummy(client->adapter,
4845 ++ state->i2c_cec_addr >> 1);
4846 ++ if (state->i2c_cec == NULL) {
4847 ++ v4l2_err(sd, "failed to register cec i2c client\n");
4848 ++ err = -ENOMEM;
4849 ++ goto err_unreg_edid;
4850 ++ }
4851 ++ adv7511_wr(sd, 0xe2, 0x00); /* power up cec section */
4852 ++ } else {
4853 ++ adv7511_wr(sd, 0xe2, 0x01); /* power down cec section */
4854 ++ }
4855 ++
4856 ++ state->i2c_pktmem = i2c_new_dummy(client->adapter, state->i2c_pktmem_addr >> 1);
4857 ++ if (state->i2c_pktmem == NULL) {
4858 ++ v4l2_err(sd, "failed to register pktmem i2c client\n");
4859 ++ err = -ENOMEM;
4860 ++ goto err_unreg_cec;
4861 ++ }
4862 ++
4863 ++ state->work_queue = create_singlethread_workqueue(sd->name);
4864 ++ if (state->work_queue == NULL) {
4865 ++ v4l2_err(sd, "could not create workqueue\n");
4866 ++ err = -ENOMEM;
4867 ++ goto err_unreg_pktmem;
4868 ++ }
4869 ++
4870 ++ INIT_DELAYED_WORK(&state->edid_handler, adv7511_edid_handler);
4871 ++
4872 ++ adv7511_init_setup(sd);
4873 ++
4874 ++#if IS_ENABLED(CONFIG_VIDEO_ADV7511_CEC)
4875 ++ state->cec_adap = cec_allocate_adapter(&adv7511_cec_adap_ops,
4876 ++ state, dev_name(&client->dev), CEC_CAP_DEFAULTS,
4877 ++ ADV7511_MAX_ADDRS);
4878 ++ err = PTR_ERR_OR_ZERO(state->cec_adap);
4879 ++ if (err) {
4880 ++ destroy_workqueue(state->work_queue);
4881 ++ goto err_unreg_pktmem;
4882 ++ }
4883 ++#endif
4884 ++
4885 ++ adv7511_set_isr(sd, true);
4886 ++ adv7511_check_monitor_present_status(sd);
4887 ++
4888 ++ v4l2_info(sd, "%s found @ 0x%x (%s)\n", client->name,
4889 ++ client->addr << 1, client->adapter->name);
4890 ++ return 0;
4891 ++
4892 ++err_unreg_pktmem:
4893 ++ i2c_unregister_device(state->i2c_pktmem);
4894 ++err_unreg_cec:
4895 ++ if (state->i2c_cec)
4896 ++ i2c_unregister_device(state->i2c_cec);
4897 ++err_unreg_edid:
4898 ++ i2c_unregister_device(state->i2c_edid);
4899 ++err_entity:
4900 ++ media_entity_cleanup(&sd->entity);
4901 ++err_hdl:
4902 ++ v4l2_ctrl_handler_free(&state->hdl);
4903 ++ return err;
4904 ++}
4905 ++
4906 ++/* ----------------------------------------------------------------------- */
4907 ++
4908 ++static int adv7511_remove(struct i2c_client *client)
4909 ++{
4910 ++ struct v4l2_subdev *sd = i2c_get_clientdata(client);
4911 ++ struct adv7511_state *state = get_adv7511_state(sd);
4912 ++
4913 ++ state->chip_revision = -1;
4914 ++
4915 ++ v4l2_dbg(1, debug, sd, "%s removed @ 0x%x (%s)\n", client->name,
4916 ++ client->addr << 1, client->adapter->name);
4917 ++
4918 ++ adv7511_set_isr(sd, false);
4919 ++ adv7511_init_setup(sd);
4920 ++ cancel_delayed_work(&state->edid_handler);
4921 ++ i2c_unregister_device(state->i2c_edid);
4922 ++ if (state->i2c_cec)
4923 ++ i2c_unregister_device(state->i2c_cec);
4924 ++ i2c_unregister_device(state->i2c_pktmem);
4925 ++ destroy_workqueue(state->work_queue);
4926 ++ v4l2_device_unregister_subdev(sd);
4927 ++ media_entity_cleanup(&sd->entity);
4928 ++ v4l2_ctrl_handler_free(sd->ctrl_handler);
4929 ++ return 0;
4930 ++}
4931 ++
4932 ++/* ----------------------------------------------------------------------- */
4933 ++
4934 ++static const struct i2c_device_id adv7511_id[] = {
4935 ++ { "adv7511", 0 },
4936 ++ { }
4937 ++};
4938 ++MODULE_DEVICE_TABLE(i2c, adv7511_id);
4939 ++
4940 ++static struct i2c_driver adv7511_driver = {
4941 ++ .driver = {
4942 ++ .name = "adv7511",
4943 ++ },
4944 ++ .probe = adv7511_probe,
4945 ++ .remove = adv7511_remove,
4946 ++ .id_table = adv7511_id,
4947 ++};
4948 ++
4949 ++module_i2c_driver(adv7511_driver);
4950 +diff --git a/drivers/media/i2c/adv7511.c b/drivers/media/i2c/adv7511.c
4951 +deleted file mode 100644
4952 +index 80c20404334a..000000000000
4953 +--- a/drivers/media/i2c/adv7511.c
4954 ++++ /dev/null
4955 +@@ -1,2003 +0,0 @@
4956 +-/*
4957 +- * Analog Devices ADV7511 HDMI Transmitter Device Driver
4958 +- *
4959 +- * Copyright 2013 Cisco Systems, Inc. and/or its affiliates. All rights reserved.
4960 +- *
4961 +- * This program is free software; you may redistribute it and/or modify
4962 +- * it under the terms of the GNU General Public License as published by
4963 +- * the Free Software Foundation; version 2 of the License.
4964 +- *
4965 +- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
4966 +- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
4967 +- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
4968 +- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
4969 +- * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
4970 +- * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
4971 +- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
4972 +- * SOFTWARE.
4973 +- */
4974 +-
4975 +-
4976 +-#include <linux/kernel.h>
4977 +-#include <linux/module.h>
4978 +-#include <linux/slab.h>
4979 +-#include <linux/i2c.h>
4980 +-#include <linux/delay.h>
4981 +-#include <linux/videodev2.h>
4982 +-#include <linux/gpio.h>
4983 +-#include <linux/workqueue.h>
4984 +-#include <linux/hdmi.h>
4985 +-#include <linux/v4l2-dv-timings.h>
4986 +-#include <media/v4l2-device.h>
4987 +-#include <media/v4l2-common.h>
4988 +-#include <media/v4l2-ctrls.h>
4989 +-#include <media/v4l2-dv-timings.h>
4990 +-#include <media/i2c/adv7511.h>
4991 +-#include <media/cec.h>
4992 +-
4993 +-static int debug;
4994 +-module_param(debug, int, 0644);
4995 +-MODULE_PARM_DESC(debug, "debug level (0-2)");
4996 +-
4997 +-MODULE_DESCRIPTION("Analog Devices ADV7511 HDMI Transmitter Device Driver");
4998 +-MODULE_AUTHOR("Hans Verkuil");
4999 +-MODULE_LICENSE("GPL v2");
5000 +-
5001 +-#define MASK_ADV7511_EDID_RDY_INT 0x04
5002 +-#define MASK_ADV7511_MSEN_INT 0x40
5003 +-#define MASK_ADV7511_HPD_INT 0x80
5004 +-
5005 +-#define MASK_ADV7511_HPD_DETECT 0x40
5006 +-#define MASK_ADV7511_MSEN_DETECT 0x20
5007 +-#define MASK_ADV7511_EDID_RDY 0x10
5008 +-
5009 +-#define EDID_MAX_RETRIES (8)
5010 +-#define EDID_DELAY 250
5011 +-#define EDID_MAX_SEGM 8
5012 +-
5013 +-#define ADV7511_MAX_WIDTH 1920
5014 +-#define ADV7511_MAX_HEIGHT 1200
5015 +-#define ADV7511_MIN_PIXELCLOCK 20000000
5016 +-#define ADV7511_MAX_PIXELCLOCK 225000000
5017 +-
5018 +-#define ADV7511_MAX_ADDRS (3)
5019 +-
5020 +-/*
5021 +-**********************************************************************
5022 +-*
5023 +-* Arrays with configuration parameters for the ADV7511
5024 +-*
5025 +-**********************************************************************
5026 +-*/
5027 +-
5028 +-struct i2c_reg_value {
5029 +- unsigned char reg;
5030 +- unsigned char value;
5031 +-};
5032 +-
5033 +-struct adv7511_state_edid {
5034 +- /* total number of blocks */
5035 +- u32 blocks;
5036 +- /* Number of segments read */
5037 +- u32 segments;
5038 +- u8 data[EDID_MAX_SEGM * 256];
5039 +- /* Number of EDID read retries left */
5040 +- unsigned read_retries;
5041 +- bool complete;
5042 +-};
5043 +-
5044 +-struct adv7511_state {
5045 +- struct adv7511_platform_data pdata;
5046 +- struct v4l2_subdev sd;
5047 +- struct media_pad pad;
5048 +- struct v4l2_ctrl_handler hdl;
5049 +- int chip_revision;
5050 +- u8 i2c_edid_addr;
5051 +- u8 i2c_pktmem_addr;
5052 +- u8 i2c_cec_addr;
5053 +-
5054 +- struct i2c_client *i2c_cec;
5055 +- struct cec_adapter *cec_adap;
5056 +- u8 cec_addr[ADV7511_MAX_ADDRS];
5057 +- u8 cec_valid_addrs;
5058 +- bool cec_enabled_adap;
5059 +-
5060 +- /* Is the adv7511 powered on? */
5061 +- bool power_on;
5062 +- /* Did we receive hotplug and rx-sense signals? */
5063 +- bool have_monitor;
5064 +- bool enabled_irq;
5065 +- /* timings from s_dv_timings */
5066 +- struct v4l2_dv_timings dv_timings;
5067 +- u32 fmt_code;
5068 +- u32 colorspace;
5069 +- u32 ycbcr_enc;
5070 +- u32 quantization;
5071 +- u32 xfer_func;
5072 +- u32 content_type;
5073 +- /* controls */
5074 +- struct v4l2_ctrl *hdmi_mode_ctrl;
5075 +- struct v4l2_ctrl *hotplug_ctrl;
5076 +- struct v4l2_ctrl *rx_sense_ctrl;
5077 +- struct v4l2_ctrl *have_edid0_ctrl;
5078 +- struct v4l2_ctrl *rgb_quantization_range_ctrl;
5079 +- struct v4l2_ctrl *content_type_ctrl;
5080 +- struct i2c_client *i2c_edid;
5081 +- struct i2c_client *i2c_pktmem;
5082 +- struct adv7511_state_edid edid;
5083 +- /* Running counter of the number of detected EDIDs (for debugging) */
5084 +- unsigned edid_detect_counter;
5085 +- struct workqueue_struct *work_queue;
5086 +- struct delayed_work edid_handler; /* work entry */
5087 +-};
5088 +-
5089 +-static void adv7511_check_monitor_present_status(struct v4l2_subdev *sd);
5090 +-static bool adv7511_check_edid_status(struct v4l2_subdev *sd);
5091 +-static void adv7511_setup(struct v4l2_subdev *sd);
5092 +-static int adv7511_s_i2s_clock_freq(struct v4l2_subdev *sd, u32 freq);
5093 +-static int adv7511_s_clock_freq(struct v4l2_subdev *sd, u32 freq);
5094 +-
5095 +-
5096 +-static const struct v4l2_dv_timings_cap adv7511_timings_cap = {
5097 +- .type = V4L2_DV_BT_656_1120,
5098 +- /* keep this initialization for compatibility with GCC < 4.4.6 */
5099 +- .reserved = { 0 },
5100 +- V4L2_INIT_BT_TIMINGS(640, ADV7511_MAX_WIDTH, 350, ADV7511_MAX_HEIGHT,
5101 +- ADV7511_MIN_PIXELCLOCK, ADV7511_MAX_PIXELCLOCK,
5102 +- V4L2_DV_BT_STD_CEA861 | V4L2_DV_BT_STD_DMT |
5103 +- V4L2_DV_BT_STD_GTF | V4L2_DV_BT_STD_CVT,
5104 +- V4L2_DV_BT_CAP_PROGRESSIVE | V4L2_DV_BT_CAP_REDUCED_BLANKING |
5105 +- V4L2_DV_BT_CAP_CUSTOM)
5106 +-};
5107 +-
5108 +-static inline struct adv7511_state *get_adv7511_state(struct v4l2_subdev *sd)
5109 +-{
5110 +- return container_of(sd, struct adv7511_state, sd);
5111 +-}
5112 +-
5113 +-static inline struct v4l2_subdev *to_sd(struct v4l2_ctrl *ctrl)
5114 +-{
5115 +- return &container_of(ctrl->handler, struct adv7511_state, hdl)->sd;
5116 +-}
5117 +-
5118 +-/* ------------------------ I2C ----------------------------------------------- */
5119 +-
5120 +-static s32 adv_smbus_read_byte_data_check(struct i2c_client *client,
5121 +- u8 command, bool check)
5122 +-{
5123 +- union i2c_smbus_data data;
5124 +-
5125 +- if (!i2c_smbus_xfer(client->adapter, client->addr, client->flags,
5126 +- I2C_SMBUS_READ, command,
5127 +- I2C_SMBUS_BYTE_DATA, &data))
5128 +- return data.byte;
5129 +- if (check)
5130 +- v4l_err(client, "error reading %02x, %02x\n",
5131 +- client->addr, command);
5132 +- return -1;
5133 +-}
5134 +-
5135 +-static s32 adv_smbus_read_byte_data(struct i2c_client *client, u8 command)
5136 +-{
5137 +- int i;
5138 +- for (i = 0; i < 3; i++) {
5139 +- int ret = adv_smbus_read_byte_data_check(client, command, true);
5140 +- if (ret >= 0) {
5141 +- if (i)
5142 +- v4l_err(client, "read ok after %d retries\n", i);
5143 +- return ret;
5144 +- }
5145 +- }
5146 +- v4l_err(client, "read failed\n");
5147 +- return -1;
5148 +-}
5149 +-
5150 +-static int adv7511_rd(struct v4l2_subdev *sd, u8 reg)
5151 +-{
5152 +- struct i2c_client *client = v4l2_get_subdevdata(sd);
5153 +-
5154 +- return adv_smbus_read_byte_data(client, reg);
5155 +-}
5156 +-
5157 +-static int adv7511_wr(struct v4l2_subdev *sd, u8 reg, u8 val)
5158 +-{
5159 +- struct i2c_client *client = v4l2_get_subdevdata(sd);
5160 +- int ret;
5161 +- int i;
5162 +-
5163 +- for (i = 0; i < 3; i++) {
5164 +- ret = i2c_smbus_write_byte_data(client, reg, val);
5165 +- if (ret == 0)
5166 +- return 0;
5167 +- }
5168 +- v4l2_err(sd, "%s: i2c write error\n", __func__);
5169 +- return ret;
5170 +-}
5171 +-
5172 +-/* To set specific bits in the register, a clear-mask is given (to be AND-ed),
5173 +- and then the value-mask (to be OR-ed). */
5174 +-static inline void adv7511_wr_and_or(struct v4l2_subdev *sd, u8 reg, u8 clr_mask, u8 val_mask)
5175 +-{
5176 +- adv7511_wr(sd, reg, (adv7511_rd(sd, reg) & clr_mask) | val_mask);
5177 +-}
5178 +-
5179 +-static int adv_smbus_read_i2c_block_data(struct i2c_client *client,
5180 +- u8 command, unsigned length, u8 *values)
5181 +-{
5182 +- union i2c_smbus_data data;
5183 +- int ret;
5184 +-
5185 +- if (length > I2C_SMBUS_BLOCK_MAX)
5186 +- length = I2C_SMBUS_BLOCK_MAX;
5187 +- data.block[0] = length;
5188 +-
5189 +- ret = i2c_smbus_xfer(client->adapter, client->addr, client->flags,
5190 +- I2C_SMBUS_READ, command,
5191 +- I2C_SMBUS_I2C_BLOCK_DATA, &data);
5192 +- memcpy(values, data.block + 1, length);
5193 +- return ret;
5194 +-}
5195 +-
5196 +-static void adv7511_edid_rd(struct v4l2_subdev *sd, uint16_t len, uint8_t *buf)
5197 +-{
5198 +- struct adv7511_state *state = get_adv7511_state(sd);
5199 +- int i;
5200 +- int err = 0;
5201 +-
5202 +- v4l2_dbg(1, debug, sd, "%s:\n", __func__);
5203 +-
5204 +- for (i = 0; !err && i < len; i += I2C_SMBUS_BLOCK_MAX)
5205 +- err = adv_smbus_read_i2c_block_data(state->i2c_edid, i,
5206 +- I2C_SMBUS_BLOCK_MAX, buf + i);
5207 +- if (err)
5208 +- v4l2_err(sd, "%s: i2c read error\n", __func__);
5209 +-}
5210 +-
5211 +-static inline int adv7511_cec_read(struct v4l2_subdev *sd, u8 reg)
5212 +-{
5213 +- struct adv7511_state *state = get_adv7511_state(sd);
5214 +-
5215 +- return i2c_smbus_read_byte_data(state->i2c_cec, reg);
5216 +-}
5217 +-
5218 +-static int adv7511_cec_write(struct v4l2_subdev *sd, u8 reg, u8 val)
5219 +-{
5220 +- struct adv7511_state *state = get_adv7511_state(sd);
5221 +- int ret;
5222 +- int i;
5223 +-
5224 +- for (i = 0; i < 3; i++) {
5225 +- ret = i2c_smbus_write_byte_data(state->i2c_cec, reg, val);
5226 +- if (ret == 0)
5227 +- return 0;
5228 +- }
5229 +- v4l2_err(sd, "%s: I2C Write Problem\n", __func__);
5230 +- return ret;
5231 +-}
5232 +-
5233 +-static inline int adv7511_cec_write_and_or(struct v4l2_subdev *sd, u8 reg, u8 mask,
5234 +- u8 val)
5235 +-{
5236 +- return adv7511_cec_write(sd, reg, (adv7511_cec_read(sd, reg) & mask) | val);
5237 +-}
5238 +-
5239 +-static int adv7511_pktmem_rd(struct v4l2_subdev *sd, u8 reg)
5240 +-{
5241 +- struct adv7511_state *state = get_adv7511_state(sd);
5242 +-
5243 +- return adv_smbus_read_byte_data(state->i2c_pktmem, reg);
5244 +-}
5245 +-
5246 +-static int adv7511_pktmem_wr(struct v4l2_subdev *sd, u8 reg, u8 val)
5247 +-{
5248 +- struct adv7511_state *state = get_adv7511_state(sd);
5249 +- int ret;
5250 +- int i;
5251 +-
5252 +- for (i = 0; i < 3; i++) {
5253 +- ret = i2c_smbus_write_byte_data(state->i2c_pktmem, reg, val);
5254 +- if (ret == 0)
5255 +- return 0;
5256 +- }
5257 +- v4l2_err(sd, "%s: i2c write error\n", __func__);
5258 +- return ret;
5259 +-}
5260 +-
5261 +-/* To set specific bits in the register, a clear-mask is given (to be AND-ed),
5262 +- and then the value-mask (to be OR-ed). */
5263 +-static inline void adv7511_pktmem_wr_and_or(struct v4l2_subdev *sd, u8 reg, u8 clr_mask, u8 val_mask)
5264 +-{
5265 +- adv7511_pktmem_wr(sd, reg, (adv7511_pktmem_rd(sd, reg) & clr_mask) | val_mask);
5266 +-}
5267 +-
5268 +-static inline bool adv7511_have_hotplug(struct v4l2_subdev *sd)
5269 +-{
5270 +- return adv7511_rd(sd, 0x42) & MASK_ADV7511_HPD_DETECT;
5271 +-}
5272 +-
5273 +-static inline bool adv7511_have_rx_sense(struct v4l2_subdev *sd)
5274 +-{
5275 +- return adv7511_rd(sd, 0x42) & MASK_ADV7511_MSEN_DETECT;
5276 +-}
5277 +-
5278 +-static void adv7511_csc_conversion_mode(struct v4l2_subdev *sd, u8 mode)
5279 +-{
5280 +- adv7511_wr_and_or(sd, 0x18, 0x9f, (mode & 0x3)<<5);
5281 +-}
5282 +-
5283 +-static void adv7511_csc_coeff(struct v4l2_subdev *sd,
5284 +- u16 A1, u16 A2, u16 A3, u16 A4,
5285 +- u16 B1, u16 B2, u16 B3, u16 B4,
5286 +- u16 C1, u16 C2, u16 C3, u16 C4)
5287 +-{
5288 +- /* A */
5289 +- adv7511_wr_and_or(sd, 0x18, 0xe0, A1>>8);
5290 +- adv7511_wr(sd, 0x19, A1);
5291 +- adv7511_wr_and_or(sd, 0x1A, 0xe0, A2>>8);
5292 +- adv7511_wr(sd, 0x1B, A2);
5293 +- adv7511_wr_and_or(sd, 0x1c, 0xe0, A3>>8);
5294 +- adv7511_wr(sd, 0x1d, A3);
5295 +- adv7511_wr_and_or(sd, 0x1e, 0xe0, A4>>8);
5296 +- adv7511_wr(sd, 0x1f, A4);
5297 +-
5298 +- /* B */
5299 +- adv7511_wr_and_or(sd, 0x20, 0xe0, B1>>8);
5300 +- adv7511_wr(sd, 0x21, B1);
5301 +- adv7511_wr_and_or(sd, 0x22, 0xe0, B2>>8);
5302 +- adv7511_wr(sd, 0x23, B2);
5303 +- adv7511_wr_and_or(sd, 0x24, 0xe0, B3>>8);
5304 +- adv7511_wr(sd, 0x25, B3);
5305 +- adv7511_wr_and_or(sd, 0x26, 0xe0, B4>>8);
5306 +- adv7511_wr(sd, 0x27, B4);
5307 +-
5308 +- /* C */
5309 +- adv7511_wr_and_or(sd, 0x28, 0xe0, C1>>8);
5310 +- adv7511_wr(sd, 0x29, C1);
5311 +- adv7511_wr_and_or(sd, 0x2A, 0xe0, C2>>8);
5312 +- adv7511_wr(sd, 0x2B, C2);
5313 +- adv7511_wr_and_or(sd, 0x2C, 0xe0, C3>>8);
5314 +- adv7511_wr(sd, 0x2D, C3);
5315 +- adv7511_wr_and_or(sd, 0x2E, 0xe0, C4>>8);
5316 +- adv7511_wr(sd, 0x2F, C4);
5317 +-}
5318 +-
5319 +-static void adv7511_csc_rgb_full2limit(struct v4l2_subdev *sd, bool enable)
5320 +-{
5321 +- if (enable) {
5322 +- u8 csc_mode = 0;
5323 +- adv7511_csc_conversion_mode(sd, csc_mode);
5324 +- adv7511_csc_coeff(sd,
5325 +- 4096-564, 0, 0, 256,
5326 +- 0, 4096-564, 0, 256,
5327 +- 0, 0, 4096-564, 256);
5328 +- /* enable CSC */
5329 +- adv7511_wr_and_or(sd, 0x18, 0x7f, 0x80);
5330 +- /* AVI infoframe: Limited range RGB (16-235) */
5331 +- adv7511_wr_and_or(sd, 0x57, 0xf3, 0x04);
5332 +- } else {
5333 +- /* disable CSC */
5334 +- adv7511_wr_and_or(sd, 0x18, 0x7f, 0x0);
5335 +- /* AVI infoframe: Full range RGB (0-255) */
5336 +- adv7511_wr_and_or(sd, 0x57, 0xf3, 0x08);
5337 +- }
5338 +-}
5339 +-
5340 +-static void adv7511_set_rgb_quantization_mode(struct v4l2_subdev *sd, struct v4l2_ctrl *ctrl)
5341 +-{
5342 +- struct adv7511_state *state = get_adv7511_state(sd);
5343 +-
5344 +- /* Only makes sense for RGB formats */
5345 +- if (state->fmt_code != MEDIA_BUS_FMT_RGB888_1X24) {
5346 +- /* so just keep quantization */
5347 +- adv7511_csc_rgb_full2limit(sd, false);
5348 +- return;
5349 +- }
5350 +-
5351 +- switch (ctrl->val) {
5352 +- case V4L2_DV_RGB_RANGE_AUTO:
5353 +- /* automatic */
5354 +- if (state->dv_timings.bt.flags & V4L2_DV_FL_IS_CE_VIDEO) {
5355 +- /* CE format, RGB limited range (16-235) */
5356 +- adv7511_csc_rgb_full2limit(sd, true);
5357 +- } else {
5358 +- /* not CE format, RGB full range (0-255) */
5359 +- adv7511_csc_rgb_full2limit(sd, false);
5360 +- }
5361 +- break;
5362 +- case V4L2_DV_RGB_RANGE_LIMITED:
5363 +- /* RGB limited range (16-235) */
5364 +- adv7511_csc_rgb_full2limit(sd, true);
5365 +- break;
5366 +- case V4L2_DV_RGB_RANGE_FULL:
5367 +- /* RGB full range (0-255) */
5368 +- adv7511_csc_rgb_full2limit(sd, false);
5369 +- break;
5370 +- }
5371 +-}
5372 +-
5373 +-/* ------------------------------ CTRL OPS ------------------------------ */
5374 +-
5375 +-static int adv7511_s_ctrl(struct v4l2_ctrl *ctrl)
5376 +-{
5377 +- struct v4l2_subdev *sd = to_sd(ctrl);
5378 +- struct adv7511_state *state = get_adv7511_state(sd);
5379 +-
5380 +- v4l2_dbg(1, debug, sd, "%s: ctrl id: %d, ctrl->val %d\n", __func__, ctrl->id, ctrl->val);
5381 +-
5382 +- if (state->hdmi_mode_ctrl == ctrl) {
5383 +- /* Set HDMI or DVI-D */
5384 +- adv7511_wr_and_or(sd, 0xaf, 0xfd, ctrl->val == V4L2_DV_TX_MODE_HDMI ? 0x02 : 0x00);
5385 +- return 0;
5386 +- }
5387 +- if (state->rgb_quantization_range_ctrl == ctrl) {
5388 +- adv7511_set_rgb_quantization_mode(sd, ctrl);
5389 +- return 0;
5390 +- }
5391 +- if (state->content_type_ctrl == ctrl) {
5392 +- u8 itc, cn;
5393 +-
5394 +- state->content_type = ctrl->val;
5395 +- itc = state->content_type != V4L2_DV_IT_CONTENT_TYPE_NO_ITC;
5396 +- cn = itc ? state->content_type : V4L2_DV_IT_CONTENT_TYPE_GRAPHICS;
5397 +- adv7511_wr_and_or(sd, 0x57, 0x7f, itc << 7);
5398 +- adv7511_wr_and_or(sd, 0x59, 0xcf, cn << 4);
5399 +- return 0;
5400 +- }
5401 +-
5402 +- return -EINVAL;
5403 +-}
5404 +-
5405 +-static const struct v4l2_ctrl_ops adv7511_ctrl_ops = {
5406 +- .s_ctrl = adv7511_s_ctrl,
5407 +-};
5408 +-
5409 +-/* ---------------------------- CORE OPS ------------------------------------------- */
5410 +-
5411 +-#ifdef CONFIG_VIDEO_ADV_DEBUG
5412 +-static void adv7511_inv_register(struct v4l2_subdev *sd)
5413 +-{
5414 +- struct adv7511_state *state = get_adv7511_state(sd);
5415 +-
5416 +- v4l2_info(sd, "0x000-0x0ff: Main Map\n");
5417 +- if (state->i2c_cec)
5418 +- v4l2_info(sd, "0x100-0x1ff: CEC Map\n");
5419 +-}
5420 +-
5421 +-static int adv7511_g_register(struct v4l2_subdev *sd, struct v4l2_dbg_register *reg)
5422 +-{
5423 +- struct adv7511_state *state = get_adv7511_state(sd);
5424 +-
5425 +- reg->size = 1;
5426 +- switch (reg->reg >> 8) {
5427 +- case 0:
5428 +- reg->val = adv7511_rd(sd, reg->reg & 0xff);
5429 +- break;
5430 +- case 1:
5431 +- if (state->i2c_cec) {
5432 +- reg->val = adv7511_cec_read(sd, reg->reg & 0xff);
5433 +- break;
5434 +- }
5435 +- /* fall through */
5436 +- default:
5437 +- v4l2_info(sd, "Register %03llx not supported\n", reg->reg);
5438 +- adv7511_inv_register(sd);
5439 +- break;
5440 +- }
5441 +- return 0;
5442 +-}
5443 +-
5444 +-static int adv7511_s_register(struct v4l2_subdev *sd, const struct v4l2_dbg_register *reg)
5445 +-{
5446 +- struct adv7511_state *state = get_adv7511_state(sd);
5447 +-
5448 +- switch (reg->reg >> 8) {
5449 +- case 0:
5450 +- adv7511_wr(sd, reg->reg & 0xff, reg->val & 0xff);
5451 +- break;
5452 +- case 1:
5453 +- if (state->i2c_cec) {
5454 +- adv7511_cec_write(sd, reg->reg & 0xff, reg->val & 0xff);
5455 +- break;
5456 +- }
5457 +- /* fall through */
5458 +- default:
5459 +- v4l2_info(sd, "Register %03llx not supported\n", reg->reg);
5460 +- adv7511_inv_register(sd);
5461 +- break;
5462 +- }
5463 +- return 0;
5464 +-}
5465 +-#endif
5466 +-
5467 +-struct adv7511_cfg_read_infoframe {
5468 +- const char *desc;
5469 +- u8 present_reg;
5470 +- u8 present_mask;
5471 +- u8 header[3];
5472 +- u16 payload_addr;
5473 +-};
5474 +-
5475 +-static u8 hdmi_infoframe_checksum(u8 *ptr, size_t size)
5476 +-{
5477 +- u8 csum = 0;
5478 +- size_t i;
5479 +-
5480 +- /* compute checksum */
5481 +- for (i = 0; i < size; i++)
5482 +- csum += ptr[i];
5483 +-
5484 +- return 256 - csum;
5485 +-}
5486 +-
5487 +-static void log_infoframe(struct v4l2_subdev *sd, const struct adv7511_cfg_read_infoframe *cri)
5488 +-{
5489 +- struct i2c_client *client = v4l2_get_subdevdata(sd);
5490 +- struct device *dev = &client->dev;
5491 +- union hdmi_infoframe frame;
5492 +- u8 buffer[32];
5493 +- u8 len;
5494 +- int i;
5495 +-
5496 +- if (!(adv7511_rd(sd, cri->present_reg) & cri->present_mask)) {
5497 +- v4l2_info(sd, "%s infoframe not transmitted\n", cri->desc);
5498 +- return;
5499 +- }
5500 +-
5501 +- memcpy(buffer, cri->header, sizeof(cri->header));
5502 +-
5503 +- len = buffer[2];
5504 +-
5505 +- if (len + 4 > sizeof(buffer)) {
5506 +- v4l2_err(sd, "%s: invalid %s infoframe length %d\n", __func__, cri->desc, len);
5507 +- return;
5508 +- }
5509 +-
5510 +- if (cri->payload_addr >= 0x100) {
5511 +- for (i = 0; i < len; i++)
5512 +- buffer[i + 4] = adv7511_pktmem_rd(sd, cri->payload_addr + i - 0x100);
5513 +- } else {
5514 +- for (i = 0; i < len; i++)
5515 +- buffer[i + 4] = adv7511_rd(sd, cri->payload_addr + i);
5516 +- }
5517 +- buffer[3] = 0;
5518 +- buffer[3] = hdmi_infoframe_checksum(buffer, len + 4);
5519 +-
5520 +- if (hdmi_infoframe_unpack(&frame, buffer) < 0) {
5521 +- v4l2_err(sd, "%s: unpack of %s infoframe failed\n", __func__, cri->desc);
5522 +- return;
5523 +- }
5524 +-
5525 +- hdmi_infoframe_log(KERN_INFO, dev, &frame);
5526 +-}
5527 +-
5528 +-static void adv7511_log_infoframes(struct v4l2_subdev *sd)
5529 +-{
5530 +- static const struct adv7511_cfg_read_infoframe cri[] = {
5531 +- { "AVI", 0x44, 0x10, { 0x82, 2, 13 }, 0x55 },
5532 +- { "Audio", 0x44, 0x08, { 0x84, 1, 10 }, 0x73 },
5533 +- { "SDP", 0x40, 0x40, { 0x83, 1, 25 }, 0x103 },
5534 +- };
5535 +- int i;
5536 +-
5537 +- for (i = 0; i < ARRAY_SIZE(cri); i++)
5538 +- log_infoframe(sd, &cri[i]);
5539 +-}
5540 +-
5541 +-static int adv7511_log_status(struct v4l2_subdev *sd)
5542 +-{
5543 +- struct adv7511_state *state = get_adv7511_state(sd);
5544 +- struct adv7511_state_edid *edid = &state->edid;
5545 +- int i;
5546 +-
5547 +- static const char * const states[] = {
5548 +- "in reset",
5549 +- "reading EDID",
5550 +- "idle",
5551 +- "initializing HDCP",
5552 +- "HDCP enabled",
5553 +- "initializing HDCP repeater",
5554 +- "6", "7", "8", "9", "A", "B", "C", "D", "E", "F"
5555 +- };
5556 +- static const char * const errors[] = {
5557 +- "no error",
5558 +- "bad receiver BKSV",
5559 +- "Ri mismatch",
5560 +- "Pj mismatch",
5561 +- "i2c error",
5562 +- "timed out",
5563 +- "max repeater cascade exceeded",
5564 +- "hash check failed",
5565 +- "too many devices",
5566 +- "9", "A", "B", "C", "D", "E", "F"
5567 +- };
5568 +-
5569 +- v4l2_info(sd, "power %s\n", state->power_on ? "on" : "off");
5570 +- v4l2_info(sd, "%s hotplug, %s Rx Sense, %s EDID (%d block(s))\n",
5571 +- (adv7511_rd(sd, 0x42) & MASK_ADV7511_HPD_DETECT) ? "detected" : "no",
5572 +- (adv7511_rd(sd, 0x42) & MASK_ADV7511_MSEN_DETECT) ? "detected" : "no",
5573 +- edid->segments ? "found" : "no",
5574 +- edid->blocks);
5575 +- v4l2_info(sd, "%s output %s\n",
5576 +- (adv7511_rd(sd, 0xaf) & 0x02) ?
5577 +- "HDMI" : "DVI-D",
5578 +- (adv7511_rd(sd, 0xa1) & 0x3c) ?
5579 +- "disabled" : "enabled");
5580 +- v4l2_info(sd, "state: %s, error: %s, detect count: %u, msk/irq: %02x/%02x\n",
5581 +- states[adv7511_rd(sd, 0xc8) & 0xf],
5582 +- errors[adv7511_rd(sd, 0xc8) >> 4], state->edid_detect_counter,
5583 +- adv7511_rd(sd, 0x94), adv7511_rd(sd, 0x96));
5584 +- v4l2_info(sd, "RGB quantization: %s range\n", adv7511_rd(sd, 0x18) & 0x80 ? "limited" : "full");
5585 +- if (adv7511_rd(sd, 0xaf) & 0x02) {
5586 +- /* HDMI only */
5587 +- u8 manual_cts = adv7511_rd(sd, 0x0a) & 0x80;
5588 +- u32 N = (adv7511_rd(sd, 0x01) & 0xf) << 16 |
5589 +- adv7511_rd(sd, 0x02) << 8 |
5590 +- adv7511_rd(sd, 0x03);
5591 +- u8 vic_detect = adv7511_rd(sd, 0x3e) >> 2;
5592 +- u8 vic_sent = adv7511_rd(sd, 0x3d) & 0x3f;
5593 +- u32 CTS;
5594 +-
5595 +- if (manual_cts)
5596 +- CTS = (adv7511_rd(sd, 0x07) & 0xf) << 16 |
5597 +- adv7511_rd(sd, 0x08) << 8 |
5598 +- adv7511_rd(sd, 0x09);
5599 +- else
5600 +- CTS = (adv7511_rd(sd, 0x04) & 0xf) << 16 |
5601 +- adv7511_rd(sd, 0x05) << 8 |
5602 +- adv7511_rd(sd, 0x06);
5603 +- v4l2_info(sd, "CTS %s mode: N %d, CTS %d\n",
5604 +- manual_cts ? "manual" : "automatic", N, CTS);
5605 +- v4l2_info(sd, "VIC: detected %d, sent %d\n",
5606 +- vic_detect, vic_sent);
5607 +- adv7511_log_infoframes(sd);
5608 +- }
5609 +- if (state->dv_timings.type == V4L2_DV_BT_656_1120)
5610 +- v4l2_print_dv_timings(sd->name, "timings: ",
5611 +- &state->dv_timings, false);
5612 +- else
5613 +- v4l2_info(sd, "no timings set\n");
5614 +- v4l2_info(sd, "i2c edid addr: 0x%x\n", state->i2c_edid_addr);
5615 +-
5616 +- if (state->i2c_cec == NULL)
5617 +- return 0;
5618 +-
5619 +- v4l2_info(sd, "i2c cec addr: 0x%x\n", state->i2c_cec_addr);
5620 +-
5621 +- v4l2_info(sd, "CEC: %s\n", state->cec_enabled_adap ?
5622 +- "enabled" : "disabled");
5623 +- if (state->cec_enabled_adap) {
5624 +- for (i = 0; i < ADV7511_MAX_ADDRS; i++) {
5625 +- bool is_valid = state->cec_valid_addrs & (1 << i);
5626 +-
5627 +- if (is_valid)
5628 +- v4l2_info(sd, "CEC Logical Address: 0x%x\n",
5629 +- state->cec_addr[i]);
5630 +- }
5631 +- }
5632 +- v4l2_info(sd, "i2c pktmem addr: 0x%x\n", state->i2c_pktmem_addr);
5633 +- return 0;
5634 +-}
5635 +-
5636 +-/* Power up/down adv7511 */
5637 +-static int adv7511_s_power(struct v4l2_subdev *sd, int on)
5638 +-{
5639 +- struct adv7511_state *state = get_adv7511_state(sd);
5640 +- const int retries = 20;
5641 +- int i;
5642 +-
5643 +- v4l2_dbg(1, debug, sd, "%s: power %s\n", __func__, on ? "on" : "off");
5644 +-
5645 +- state->power_on = on;
5646 +-
5647 +- if (!on) {
5648 +- /* Power down */
5649 +- adv7511_wr_and_or(sd, 0x41, 0xbf, 0x40);
5650 +- return true;
5651 +- }
5652 +-
5653 +- /* Power up */
5654 +- /* The adv7511 does not always come up immediately.
5655 +- Retry multiple times. */
5656 +- for (i = 0; i < retries; i++) {
5657 +- adv7511_wr_and_or(sd, 0x41, 0xbf, 0x0);
5658 +- if ((adv7511_rd(sd, 0x41) & 0x40) == 0)
5659 +- break;
5660 +- adv7511_wr_and_or(sd, 0x41, 0xbf, 0x40);
5661 +- msleep(10);
5662 +- }
5663 +- if (i == retries) {
5664 +- v4l2_dbg(1, debug, sd, "%s: failed to powerup the adv7511!\n", __func__);
5665 +- adv7511_s_power(sd, 0);
5666 +- return false;
5667 +- }
5668 +- if (i > 1)
5669 +- v4l2_dbg(1, debug, sd, "%s: needed %d retries to powerup the adv7511\n", __func__, i);
5670 +-
5671 +- /* Reserved registers that must be set */
5672 +- adv7511_wr(sd, 0x98, 0x03);
5673 +- adv7511_wr_and_or(sd, 0x9a, 0xfe, 0x70);
5674 +- adv7511_wr(sd, 0x9c, 0x30);
5675 +- adv7511_wr_and_or(sd, 0x9d, 0xfc, 0x01);
5676 +- adv7511_wr(sd, 0xa2, 0xa4);
5677 +- adv7511_wr(sd, 0xa3, 0xa4);
5678 +- adv7511_wr(sd, 0xe0, 0xd0);
5679 +- adv7511_wr(sd, 0xf9, 0x00);
5680 +-
5681 +- adv7511_wr(sd, 0x43, state->i2c_edid_addr);
5682 +- adv7511_wr(sd, 0x45, state->i2c_pktmem_addr);
5683 +-
5684 +- /* Set number of attempts to read the EDID */
5685 +- adv7511_wr(sd, 0xc9, 0xf);
5686 +- return true;
5687 +-}
5688 +-
5689 +-#if IS_ENABLED(CONFIG_VIDEO_ADV7511_CEC)
5690 +-static int adv7511_cec_adap_enable(struct cec_adapter *adap, bool enable)
5691 +-{
5692 +- struct adv7511_state *state = cec_get_drvdata(adap);
5693 +- struct v4l2_subdev *sd = &state->sd;
5694 +-
5695 +- if (state->i2c_cec == NULL)
5696 +- return -EIO;
5697 +-
5698 +- if (!state->cec_enabled_adap && enable) {
5699 +- /* power up cec section */
5700 +- adv7511_cec_write_and_or(sd, 0x4e, 0xfc, 0x01);
5701 +- /* legacy mode and clear all rx buffers */
5702 +- adv7511_cec_write(sd, 0x4a, 0x07);
5703 +- adv7511_cec_write(sd, 0x4a, 0);
5704 +- adv7511_cec_write_and_or(sd, 0x11, 0xfe, 0); /* initially disable tx */
5705 +- /* enabled irqs: */
5706 +- /* tx: ready */
5707 +- /* tx: arbitration lost */
5708 +- /* tx: retry timeout */
5709 +- /* rx: ready 1 */
5710 +- if (state->enabled_irq)
5711 +- adv7511_wr_and_or(sd, 0x95, 0xc0, 0x39);
5712 +- } else if (state->cec_enabled_adap && !enable) {
5713 +- if (state->enabled_irq)
5714 +- adv7511_wr_and_or(sd, 0x95, 0xc0, 0x00);
5715 +- /* disable address mask 1-3 */
5716 +- adv7511_cec_write_and_or(sd, 0x4b, 0x8f, 0x00);
5717 +- /* power down cec section */
5718 +- adv7511_cec_write_and_or(sd, 0x4e, 0xfc, 0x00);
5719 +- state->cec_valid_addrs = 0;
5720 +- }
5721 +- state->cec_enabled_adap = enable;
5722 +- return 0;
5723 +-}
5724 +-
5725 +-static int adv7511_cec_adap_log_addr(struct cec_adapter *adap, u8 addr)
5726 +-{
5727 +- struct adv7511_state *state = cec_get_drvdata(adap);
5728 +- struct v4l2_subdev *sd = &state->sd;
5729 +- unsigned int i, free_idx = ADV7511_MAX_ADDRS;
5730 +-
5731 +- if (!state->cec_enabled_adap)
5732 +- return addr == CEC_LOG_ADDR_INVALID ? 0 : -EIO;
5733 +-
5734 +- if (addr == CEC_LOG_ADDR_INVALID) {
5735 +- adv7511_cec_write_and_or(sd, 0x4b, 0x8f, 0);
5736 +- state->cec_valid_addrs = 0;
5737 +- return 0;
5738 +- }
5739 +-
5740 +- for (i = 0; i < ADV7511_MAX_ADDRS; i++) {
5741 +- bool is_valid = state->cec_valid_addrs & (1 << i);
5742 +-
5743 +- if (free_idx == ADV7511_MAX_ADDRS && !is_valid)
5744 +- free_idx = i;
5745 +- if (is_valid && state->cec_addr[i] == addr)
5746 +- return 0;
5747 +- }
5748 +- if (i == ADV7511_MAX_ADDRS) {
5749 +- i = free_idx;
5750 +- if (i == ADV7511_MAX_ADDRS)
5751 +- return -ENXIO;
5752 +- }
5753 +- state->cec_addr[i] = addr;
5754 +- state->cec_valid_addrs |= 1 << i;
5755 +-
5756 +- switch (i) {
5757 +- case 0:
5758 +- /* enable address mask 0 */
5759 +- adv7511_cec_write_and_or(sd, 0x4b, 0xef, 0x10);
5760 +- /* set address for mask 0 */
5761 +- adv7511_cec_write_and_or(sd, 0x4c, 0xf0, addr);
5762 +- break;
5763 +- case 1:
5764 +- /* enable address mask 1 */
5765 +- adv7511_cec_write_and_or(sd, 0x4b, 0xdf, 0x20);
5766 +- /* set address for mask 1 */
5767 +- adv7511_cec_write_and_or(sd, 0x4c, 0x0f, addr << 4);
5768 +- break;
5769 +- case 2:
5770 +- /* enable address mask 2 */
5771 +- adv7511_cec_write_and_or(sd, 0x4b, 0xbf, 0x40);
5772 +- /* set address for mask 1 */
5773 +- adv7511_cec_write_and_or(sd, 0x4d, 0xf0, addr);
5774 +- break;
5775 +- }
5776 +- return 0;
5777 +-}
5778 +-
5779 +-static int adv7511_cec_adap_transmit(struct cec_adapter *adap, u8 attempts,
5780 +- u32 signal_free_time, struct cec_msg *msg)
5781 +-{
5782 +- struct adv7511_state *state = cec_get_drvdata(adap);
5783 +- struct v4l2_subdev *sd = &state->sd;
5784 +- u8 len = msg->len;
5785 +- unsigned int i;
5786 +-
5787 +- v4l2_dbg(1, debug, sd, "%s: len %d\n", __func__, len);
5788 +-
5789 +- if (len > 16) {
5790 +- v4l2_err(sd, "%s: len exceeded 16 (%d)\n", __func__, len);
5791 +- return -EINVAL;
5792 +- }
5793 +-
5794 +- /*
5795 +- * The number of retries is the number of attempts - 1, but retry
5796 +- * at least once. It's not clear if a value of 0 is allowed, so
5797 +- * let's do at least one retry.
5798 +- */
5799 +- adv7511_cec_write_and_or(sd, 0x12, ~0x70, max(1, attempts - 1) << 4);
5800 +-
5801 +- /* blocking, clear cec tx irq status */
5802 +- adv7511_wr_and_or(sd, 0x97, 0xc7, 0x38);
5803 +-
5804 +- /* write data */
5805 +- for (i = 0; i < len; i++)
5806 +- adv7511_cec_write(sd, i, msg->msg[i]);
5807 +-
5808 +- /* set length (data + header) */
5809 +- adv7511_cec_write(sd, 0x10, len);
5810 +- /* start transmit, enable tx */
5811 +- adv7511_cec_write(sd, 0x11, 0x01);
5812 +- return 0;
5813 +-}
5814 +-
5815 +-static void adv_cec_tx_raw_status(struct v4l2_subdev *sd, u8 tx_raw_status)
5816 +-{
5817 +- struct adv7511_state *state = get_adv7511_state(sd);
5818 +-
5819 +- if ((adv7511_cec_read(sd, 0x11) & 0x01) == 0) {
5820 +- v4l2_dbg(1, debug, sd, "%s: tx raw: tx disabled\n", __func__);
5821 +- return;
5822 +- }
5823 +-
5824 +- if (tx_raw_status & 0x10) {
5825 +- v4l2_dbg(1, debug, sd,
5826 +- "%s: tx raw: arbitration lost\n", __func__);
5827 +- cec_transmit_done(state->cec_adap, CEC_TX_STATUS_ARB_LOST,
5828 +- 1, 0, 0, 0);
5829 +- return;
5830 +- }
5831 +- if (tx_raw_status & 0x08) {
5832 +- u8 status;
5833 +- u8 nack_cnt;
5834 +- u8 low_drive_cnt;
5835 +-
5836 +- v4l2_dbg(1, debug, sd, "%s: tx raw: retry failed\n", __func__);
5837 +- /*
5838 +- * We set this status bit since this hardware performs
5839 +- * retransmissions.
5840 +- */
5841 +- status = CEC_TX_STATUS_MAX_RETRIES;
5842 +- nack_cnt = adv7511_cec_read(sd, 0x14) & 0xf;
5843 +- if (nack_cnt)
5844 +- status |= CEC_TX_STATUS_NACK;
5845 +- low_drive_cnt = adv7511_cec_read(sd, 0x14) >> 4;
5846 +- if (low_drive_cnt)
5847 +- status |= CEC_TX_STATUS_LOW_DRIVE;
5848 +- cec_transmit_done(state->cec_adap, status,
5849 +- 0, nack_cnt, low_drive_cnt, 0);
5850 +- return;
5851 +- }
5852 +- if (tx_raw_status & 0x20) {
5853 +- v4l2_dbg(1, debug, sd, "%s: tx raw: ready ok\n", __func__);
5854 +- cec_transmit_done(state->cec_adap, CEC_TX_STATUS_OK, 0, 0, 0, 0);
5855 +- return;
5856 +- }
5857 +-}
5858 +-
5859 +-static const struct cec_adap_ops adv7511_cec_adap_ops = {
5860 +- .adap_enable = adv7511_cec_adap_enable,
5861 +- .adap_log_addr = adv7511_cec_adap_log_addr,
5862 +- .adap_transmit = adv7511_cec_adap_transmit,
5863 +-};
5864 +-#endif
5865 +-
5866 +-/* Enable interrupts */
5867 +-static void adv7511_set_isr(struct v4l2_subdev *sd, bool enable)
5868 +-{
5869 +- struct adv7511_state *state = get_adv7511_state(sd);
5870 +- u8 irqs = MASK_ADV7511_HPD_INT | MASK_ADV7511_MSEN_INT;
5871 +- u8 irqs_rd;
5872 +- int retries = 100;
5873 +-
5874 +- v4l2_dbg(2, debug, sd, "%s: %s\n", __func__, enable ? "enable" : "disable");
5875 +-
5876 +- if (state->enabled_irq == enable)
5877 +- return;
5878 +- state->enabled_irq = enable;
5879 +-
5880 +- /* The datasheet says that the EDID ready interrupt should be
5881 +- disabled if there is no hotplug. */
5882 +- if (!enable)
5883 +- irqs = 0;
5884 +- else if (adv7511_have_hotplug(sd))
5885 +- irqs |= MASK_ADV7511_EDID_RDY_INT;
5886 +-
5887 +- adv7511_wr_and_or(sd, 0x95, 0xc0,
5888 +- (state->cec_enabled_adap && enable) ? 0x39 : 0x00);
5889 +-
5890 +- /*
5891 +- * This i2c write can fail (approx. 1 in 1000 writes). But it
5892 +- * is essential that this register is correct, so retry it
5893 +- * multiple times.
5894 +- *
5895 +- * Note that the i2c write does not report an error, but the readback
5896 +- * clearly shows the wrong value.
5897 +- */
5898 +- do {
5899 +- adv7511_wr(sd, 0x94, irqs);
5900 +- irqs_rd = adv7511_rd(sd, 0x94);
5901 +- } while (retries-- && irqs_rd != irqs);
5902 +-
5903 +- if (irqs_rd == irqs)
5904 +- return;
5905 +- v4l2_err(sd, "Could not set interrupts: hw failure?\n");
5906 +-}
5907 +-
5908 +-/* Interrupt handler */
5909 +-static int adv7511_isr(struct v4l2_subdev *sd, u32 status, bool *handled)
5910 +-{
5911 +- u8 irq_status;
5912 +- u8 cec_irq;
5913 +-
5914 +- /* disable interrupts to prevent a race condition */
5915 +- adv7511_set_isr(sd, false);
5916 +- irq_status = adv7511_rd(sd, 0x96);
5917 +- cec_irq = adv7511_rd(sd, 0x97);
5918 +- /* clear detected interrupts */
5919 +- adv7511_wr(sd, 0x96, irq_status);
5920 +- adv7511_wr(sd, 0x97, cec_irq);
5921 +-
5922 +- v4l2_dbg(1, debug, sd, "%s: irq 0x%x, cec-irq 0x%x\n", __func__,
5923 +- irq_status, cec_irq);
5924 +-
5925 +- if (irq_status & (MASK_ADV7511_HPD_INT | MASK_ADV7511_MSEN_INT))
5926 +- adv7511_check_monitor_present_status(sd);
5927 +- if (irq_status & MASK_ADV7511_EDID_RDY_INT)
5928 +- adv7511_check_edid_status(sd);
5929 +-
5930 +-#if IS_ENABLED(CONFIG_VIDEO_ADV7511_CEC)
5931 +- if (cec_irq & 0x38)
5932 +- adv_cec_tx_raw_status(sd, cec_irq);
5933 +-
5934 +- if (cec_irq & 1) {
5935 +- struct adv7511_state *state = get_adv7511_state(sd);
5936 +- struct cec_msg msg;
5937 +-
5938 +- msg.len = adv7511_cec_read(sd, 0x25) & 0x1f;
5939 +-
5940 +- v4l2_dbg(1, debug, sd, "%s: cec msg len %d\n", __func__,
5941 +- msg.len);
5942 +-
5943 +- if (msg.len > 16)
5944 +- msg.len = 16;
5945 +-
5946 +- if (msg.len) {
5947 +- u8 i;
5948 +-
5949 +- for (i = 0; i < msg.len; i++)
5950 +- msg.msg[i] = adv7511_cec_read(sd, i + 0x15);
5951 +-
5952 +- adv7511_cec_write(sd, 0x4a, 1); /* toggle to re-enable rx 1 */
5953 +- adv7511_cec_write(sd, 0x4a, 0);
5954 +- cec_received_msg(state->cec_adap, &msg);
5955 +- }
5956 +- }
5957 +-#endif
5958 +-
5959 +- /* enable interrupts */
5960 +- adv7511_set_isr(sd, true);
5961 +-
5962 +- if (handled)
5963 +- *handled = true;
5964 +- return 0;
5965 +-}
5966 +-
5967 +-static const struct v4l2_subdev_core_ops adv7511_core_ops = {
5968 +- .log_status = adv7511_log_status,
5969 +-#ifdef CONFIG_VIDEO_ADV_DEBUG
5970 +- .g_register = adv7511_g_register,
5971 +- .s_register = adv7511_s_register,
5972 +-#endif
5973 +- .s_power = adv7511_s_power,
5974 +- .interrupt_service_routine = adv7511_isr,
5975 +-};
5976 +-
5977 +-/* ------------------------------ VIDEO OPS ------------------------------ */
5978 +-
5979 +-/* Enable/disable adv7511 output */
5980 +-static int adv7511_s_stream(struct v4l2_subdev *sd, int enable)
5981 +-{
5982 +- struct adv7511_state *state = get_adv7511_state(sd);
5983 +-
5984 +- v4l2_dbg(1, debug, sd, "%s: %sable\n", __func__, (enable ? "en" : "dis"));
5985 +- adv7511_wr_and_or(sd, 0xa1, ~0x3c, (enable ? 0 : 0x3c));
5986 +- if (enable) {
5987 +- adv7511_check_monitor_present_status(sd);
5988 +- } else {
5989 +- adv7511_s_power(sd, 0);
5990 +- state->have_monitor = false;
5991 +- }
5992 +- return 0;
5993 +-}
5994 +-
5995 +-static int adv7511_s_dv_timings(struct v4l2_subdev *sd,
5996 +- struct v4l2_dv_timings *timings)
5997 +-{
5998 +- struct adv7511_state *state = get_adv7511_state(sd);
5999 +- struct v4l2_bt_timings *bt = &timings->bt;
6000 +- u32 fps;
6001 +-
6002 +- v4l2_dbg(1, debug, sd, "%s:\n", __func__);
6003 +-
6004 +- /* quick sanity check */
6005 +- if (!v4l2_valid_dv_timings(timings, &adv7511_timings_cap, NULL, NULL))
6006 +- return -EINVAL;
6007 +-
6008 +- /* Fill the optional fields .standards and .flags in struct v4l2_dv_timings
6009 +- if the format is one of the CEA or DMT timings. */
6010 +- v4l2_find_dv_timings_cap(timings, &adv7511_timings_cap, 0, NULL, NULL);
6011 +-
6012 +- /* save timings */
6013 +- state->dv_timings = *timings;
6014 +-
6015 +- /* set h/vsync polarities */
6016 +- adv7511_wr_and_or(sd, 0x17, 0x9f,
6017 +- ((bt->polarities & V4L2_DV_VSYNC_POS_POL) ? 0 : 0x40) |
6018 +- ((bt->polarities & V4L2_DV_HSYNC_POS_POL) ? 0 : 0x20));
6019 +-
6020 +- fps = (u32)bt->pixelclock / (V4L2_DV_BT_FRAME_WIDTH(bt) * V4L2_DV_BT_FRAME_HEIGHT(bt));
6021 +- switch (fps) {
6022 +- case 24:
6023 +- adv7511_wr_and_or(sd, 0xfb, 0xf9, 1 << 1);
6024 +- break;
6025 +- case 25:
6026 +- adv7511_wr_and_or(sd, 0xfb, 0xf9, 2 << 1);
6027 +- break;
6028 +- case 30:
6029 +- adv7511_wr_and_or(sd, 0xfb, 0xf9, 3 << 1);
6030 +- break;
6031 +- default:
6032 +- adv7511_wr_and_or(sd, 0xfb, 0xf9, 0);
6033 +- break;
6034 +- }
6035 +-
6036 +- /* update quantization range based on new dv_timings */
6037 +- adv7511_set_rgb_quantization_mode(sd, state->rgb_quantization_range_ctrl);
6038 +-
6039 +- return 0;
6040 +-}
6041 +-
6042 +-static int adv7511_g_dv_timings(struct v4l2_subdev *sd,
6043 +- struct v4l2_dv_timings *timings)
6044 +-{
6045 +- struct adv7511_state *state = get_adv7511_state(sd);
6046 +-
6047 +- v4l2_dbg(1, debug, sd, "%s:\n", __func__);
6048 +-
6049 +- if (!timings)
6050 +- return -EINVAL;
6051 +-
6052 +- *timings = state->dv_timings;
6053 +-
6054 +- return 0;
6055 +-}
6056 +-
6057 +-static int adv7511_enum_dv_timings(struct v4l2_subdev *sd,
6058 +- struct v4l2_enum_dv_timings *timings)
6059 +-{
6060 +- if (timings->pad != 0)
6061 +- return -EINVAL;
6062 +-
6063 +- return v4l2_enum_dv_timings_cap(timings, &adv7511_timings_cap, NULL, NULL);
6064 +-}
6065 +-
6066 +-static int adv7511_dv_timings_cap(struct v4l2_subdev *sd,
6067 +- struct v4l2_dv_timings_cap *cap)
6068 +-{
6069 +- if (cap->pad != 0)
6070 +- return -EINVAL;
6071 +-
6072 +- *cap = adv7511_timings_cap;
6073 +- return 0;
6074 +-}
6075 +-
6076 +-static const struct v4l2_subdev_video_ops adv7511_video_ops = {
6077 +- .s_stream = adv7511_s_stream,
6078 +- .s_dv_timings = adv7511_s_dv_timings,
6079 +- .g_dv_timings = adv7511_g_dv_timings,
6080 +-};
6081 +-
6082 +-/* ------------------------------ AUDIO OPS ------------------------------ */
6083 +-static int adv7511_s_audio_stream(struct v4l2_subdev *sd, int enable)
6084 +-{
6085 +- v4l2_dbg(1, debug, sd, "%s: %sable\n", __func__, (enable ? "en" : "dis"));
6086 +-
6087 +- if (enable)
6088 +- adv7511_wr_and_or(sd, 0x4b, 0x3f, 0x80);
6089 +- else
6090 +- adv7511_wr_and_or(sd, 0x4b, 0x3f, 0x40);
6091 +-
6092 +- return 0;
6093 +-}
6094 +-
6095 +-static int adv7511_s_clock_freq(struct v4l2_subdev *sd, u32 freq)
6096 +-{
6097 +- u32 N;
6098 +-
6099 +- switch (freq) {
6100 +- case 32000: N = 4096; break;
6101 +- case 44100: N = 6272; break;
6102 +- case 48000: N = 6144; break;
6103 +- case 88200: N = 12544; break;
6104 +- case 96000: N = 12288; break;
6105 +- case 176400: N = 25088; break;
6106 +- case 192000: N = 24576; break;
6107 +- default:
6108 +- return -EINVAL;
6109 +- }
6110 +-
6111 +- /* Set N (used with CTS to regenerate the audio clock) */
6112 +- adv7511_wr(sd, 0x01, (N >> 16) & 0xf);
6113 +- adv7511_wr(sd, 0x02, (N >> 8) & 0xff);
6114 +- adv7511_wr(sd, 0x03, N & 0xff);
6115 +-
6116 +- return 0;
6117 +-}
6118 +-
6119 +-static int adv7511_s_i2s_clock_freq(struct v4l2_subdev *sd, u32 freq)
6120 +-{
6121 +- u32 i2s_sf;
6122 +-
6123 +- switch (freq) {
6124 +- case 32000: i2s_sf = 0x30; break;
6125 +- case 44100: i2s_sf = 0x00; break;
6126 +- case 48000: i2s_sf = 0x20; break;
6127 +- case 88200: i2s_sf = 0x80; break;
6128 +- case 96000: i2s_sf = 0xa0; break;
6129 +- case 176400: i2s_sf = 0xc0; break;
6130 +- case 192000: i2s_sf = 0xe0; break;
6131 +- default:
6132 +- return -EINVAL;
6133 +- }
6134 +-
6135 +- /* Set sampling frequency for I2S audio to 48 kHz */
6136 +- adv7511_wr_and_or(sd, 0x15, 0xf, i2s_sf);
6137 +-
6138 +- return 0;
6139 +-}
6140 +-
6141 +-static int adv7511_s_routing(struct v4l2_subdev *sd, u32 input, u32 output, u32 config)
6142 +-{
6143 +- /* Only 2 channels in use for application */
6144 +- adv7511_wr_and_or(sd, 0x73, 0xf8, 0x1);
6145 +- /* Speaker mapping */
6146 +- adv7511_wr(sd, 0x76, 0x00);
6147 +-
6148 +- /* 16 bit audio word length */
6149 +- adv7511_wr_and_or(sd, 0x14, 0xf0, 0x02);
6150 +-
6151 +- return 0;
6152 +-}
6153 +-
6154 +-static const struct v4l2_subdev_audio_ops adv7511_audio_ops = {
6155 +- .s_stream = adv7511_s_audio_stream,
6156 +- .s_clock_freq = adv7511_s_clock_freq,
6157 +- .s_i2s_clock_freq = adv7511_s_i2s_clock_freq,
6158 +- .s_routing = adv7511_s_routing,
6159 +-};
6160 +-
6161 +-/* ---------------------------- PAD OPS ------------------------------------- */
6162 +-
6163 +-static int adv7511_get_edid(struct v4l2_subdev *sd, struct v4l2_edid *edid)
6164 +-{
6165 +- struct adv7511_state *state = get_adv7511_state(sd);
6166 +-
6167 +- memset(edid->reserved, 0, sizeof(edid->reserved));
6168 +-
6169 +- if (edid->pad != 0)
6170 +- return -EINVAL;
6171 +-
6172 +- if (edid->start_block == 0 && edid->blocks == 0) {
6173 +- edid->blocks = state->edid.segments * 2;
6174 +- return 0;
6175 +- }
6176 +-
6177 +- if (state->edid.segments == 0)
6178 +- return -ENODATA;
6179 +-
6180 +- if (edid->start_block >= state->edid.segments * 2)
6181 +- return -EINVAL;
6182 +-
6183 +- if (edid->start_block + edid->blocks > state->edid.segments * 2)
6184 +- edid->blocks = state->edid.segments * 2 - edid->start_block;
6185 +-
6186 +- memcpy(edid->edid, &state->edid.data[edid->start_block * 128],
6187 +- 128 * edid->blocks);
6188 +-
6189 +- return 0;
6190 +-}
6191 +-
6192 +-static int adv7511_enum_mbus_code(struct v4l2_subdev *sd,
6193 +- struct v4l2_subdev_pad_config *cfg,
6194 +- struct v4l2_subdev_mbus_code_enum *code)
6195 +-{
6196 +- if (code->pad != 0)
6197 +- return -EINVAL;
6198 +-
6199 +- switch (code->index) {
6200 +- case 0:
6201 +- code->code = MEDIA_BUS_FMT_RGB888_1X24;
6202 +- break;
6203 +- case 1:
6204 +- code->code = MEDIA_BUS_FMT_YUYV8_1X16;
6205 +- break;
6206 +- case 2:
6207 +- code->code = MEDIA_BUS_FMT_UYVY8_1X16;
6208 +- break;
6209 +- default:
6210 +- return -EINVAL;
6211 +- }
6212 +- return 0;
6213 +-}
6214 +-
6215 +-static void adv7511_fill_format(struct adv7511_state *state,
6216 +- struct v4l2_mbus_framefmt *format)
6217 +-{
6218 +- format->width = state->dv_timings.bt.width;
6219 +- format->height = state->dv_timings.bt.height;
6220 +- format->field = V4L2_FIELD_NONE;
6221 +-}
6222 +-
6223 +-static int adv7511_get_fmt(struct v4l2_subdev *sd,
6224 +- struct v4l2_subdev_pad_config *cfg,
6225 +- struct v4l2_subdev_format *format)
6226 +-{
6227 +- struct adv7511_state *state = get_adv7511_state(sd);
6228 +-
6229 +- if (format->pad != 0)
6230 +- return -EINVAL;
6231 +-
6232 +- memset(&format->format, 0, sizeof(format->format));
6233 +- adv7511_fill_format(state, &format->format);
6234 +-
6235 +- if (format->which == V4L2_SUBDEV_FORMAT_TRY) {
6236 +- struct v4l2_mbus_framefmt *fmt;
6237 +-
6238 +- fmt = v4l2_subdev_get_try_format(sd, cfg, format->pad);
6239 +- format->format.code = fmt->code;
6240 +- format->format.colorspace = fmt->colorspace;
6241 +- format->format.ycbcr_enc = fmt->ycbcr_enc;
6242 +- format->format.quantization = fmt->quantization;
6243 +- format->format.xfer_func = fmt->xfer_func;
6244 +- } else {
6245 +- format->format.code = state->fmt_code;
6246 +- format->format.colorspace = state->colorspace;
6247 +- format->format.ycbcr_enc = state->ycbcr_enc;
6248 +- format->format.quantization = state->quantization;
6249 +- format->format.xfer_func = state->xfer_func;
6250 +- }
6251 +-
6252 +- return 0;
6253 +-}
6254 +-
6255 +-static int adv7511_set_fmt(struct v4l2_subdev *sd,
6256 +- struct v4l2_subdev_pad_config *cfg,
6257 +- struct v4l2_subdev_format *format)
6258 +-{
6259 +- struct adv7511_state *state = get_adv7511_state(sd);
6260 +- /*
6261 +- * Bitfield namings come the CEA-861-F standard, table 8 "Auxiliary
6262 +- * Video Information (AVI) InfoFrame Format"
6263 +- *
6264 +- * c = Colorimetry
6265 +- * ec = Extended Colorimetry
6266 +- * y = RGB or YCbCr
6267 +- * q = RGB Quantization Range
6268 +- * yq = YCC Quantization Range
6269 +- */
6270 +- u8 c = HDMI_COLORIMETRY_NONE;
6271 +- u8 ec = HDMI_EXTENDED_COLORIMETRY_XV_YCC_601;
6272 +- u8 y = HDMI_COLORSPACE_RGB;
6273 +- u8 q = HDMI_QUANTIZATION_RANGE_DEFAULT;
6274 +- u8 yq = HDMI_YCC_QUANTIZATION_RANGE_LIMITED;
6275 +- u8 itc = state->content_type != V4L2_DV_IT_CONTENT_TYPE_NO_ITC;
6276 +- u8 cn = itc ? state->content_type : V4L2_DV_IT_CONTENT_TYPE_GRAPHICS;
6277 +-
6278 +- if (format->pad != 0)
6279 +- return -EINVAL;
6280 +- switch (format->format.code) {
6281 +- case MEDIA_BUS_FMT_UYVY8_1X16:
6282 +- case MEDIA_BUS_FMT_YUYV8_1X16:
6283 +- case MEDIA_BUS_FMT_RGB888_1X24:
6284 +- break;
6285 +- default:
6286 +- return -EINVAL;
6287 +- }
6288 +-
6289 +- adv7511_fill_format(state, &format->format);
6290 +- if (format->which == V4L2_SUBDEV_FORMAT_TRY) {
6291 +- struct v4l2_mbus_framefmt *fmt;
6292 +-
6293 +- fmt = v4l2_subdev_get_try_format(sd, cfg, format->pad);
6294 +- fmt->code = format->format.code;
6295 +- fmt->colorspace = format->format.colorspace;
6296 +- fmt->ycbcr_enc = format->format.ycbcr_enc;
6297 +- fmt->quantization = format->format.quantization;
6298 +- fmt->xfer_func = format->format.xfer_func;
6299 +- return 0;
6300 +- }
6301 +-
6302 +- switch (format->format.code) {
6303 +- case MEDIA_BUS_FMT_UYVY8_1X16:
6304 +- adv7511_wr_and_or(sd, 0x15, 0xf0, 0x01);
6305 +- adv7511_wr_and_or(sd, 0x16, 0x03, 0xb8);
6306 +- y = HDMI_COLORSPACE_YUV422;
6307 +- break;
6308 +- case MEDIA_BUS_FMT_YUYV8_1X16:
6309 +- adv7511_wr_and_or(sd, 0x15, 0xf0, 0x01);
6310 +- adv7511_wr_and_or(sd, 0x16, 0x03, 0xbc);
6311 +- y = HDMI_COLORSPACE_YUV422;
6312 +- break;
6313 +- case MEDIA_BUS_FMT_RGB888_1X24:
6314 +- default:
6315 +- adv7511_wr_and_or(sd, 0x15, 0xf0, 0x00);
6316 +- adv7511_wr_and_or(sd, 0x16, 0x03, 0x00);
6317 +- break;
6318 +- }
6319 +- state->fmt_code = format->format.code;
6320 +- state->colorspace = format->format.colorspace;
6321 +- state->ycbcr_enc = format->format.ycbcr_enc;
6322 +- state->quantization = format->format.quantization;
6323 +- state->xfer_func = format->format.xfer_func;
6324 +-
6325 +- switch (format->format.colorspace) {
6326 +- case V4L2_COLORSPACE_ADOBERGB:
6327 +- c = HDMI_COLORIMETRY_EXTENDED;
6328 +- ec = y ? HDMI_EXTENDED_COLORIMETRY_ADOBE_YCC_601 :
6329 +- HDMI_EXTENDED_COLORIMETRY_ADOBE_RGB;
6330 +- break;
6331 +- case V4L2_COLORSPACE_SMPTE170M:
6332 +- c = y ? HDMI_COLORIMETRY_ITU_601 : HDMI_COLORIMETRY_NONE;
6333 +- if (y && format->format.ycbcr_enc == V4L2_YCBCR_ENC_XV601) {
6334 +- c = HDMI_COLORIMETRY_EXTENDED;
6335 +- ec = HDMI_EXTENDED_COLORIMETRY_XV_YCC_601;
6336 +- }
6337 +- break;
6338 +- case V4L2_COLORSPACE_REC709:
6339 +- c = y ? HDMI_COLORIMETRY_ITU_709 : HDMI_COLORIMETRY_NONE;
6340 +- if (y && format->format.ycbcr_enc == V4L2_YCBCR_ENC_XV709) {
6341 +- c = HDMI_COLORIMETRY_EXTENDED;
6342 +- ec = HDMI_EXTENDED_COLORIMETRY_XV_YCC_709;
6343 +- }
6344 +- break;
6345 +- case V4L2_COLORSPACE_SRGB:
6346 +- c = y ? HDMI_COLORIMETRY_EXTENDED : HDMI_COLORIMETRY_NONE;
6347 +- ec = y ? HDMI_EXTENDED_COLORIMETRY_S_YCC_601 :
6348 +- HDMI_EXTENDED_COLORIMETRY_XV_YCC_601;
6349 +- break;
6350 +- case V4L2_COLORSPACE_BT2020:
6351 +- c = HDMI_COLORIMETRY_EXTENDED;
6352 +- if (y && format->format.ycbcr_enc == V4L2_YCBCR_ENC_BT2020_CONST_LUM)
6353 +- ec = 5; /* Not yet available in hdmi.h */
6354 +- else
6355 +- ec = 6; /* Not yet available in hdmi.h */
6356 +- break;
6357 +- default:
6358 +- break;
6359 +- }
6360 +-
6361 +- /*
6362 +- * CEA-861-F says that for RGB formats the YCC range must match the
6363 +- * RGB range, although sources should ignore the YCC range.
6364 +- *
6365 +- * The RGB quantization range shouldn't be non-zero if the EDID doesn't
6366 +- * have the Q bit set in the Video Capabilities Data Block, however this
6367 +- * isn't checked at the moment. The assumption is that the application
6368 +- * knows the EDID and can detect this.
6369 +- *
6370 +- * The same is true for the YCC quantization range: non-standard YCC
6371 +- * quantization ranges should only be sent if the EDID has the YQ bit
6372 +- * set in the Video Capabilities Data Block.
6373 +- */
6374 +- switch (format->format.quantization) {
6375 +- case V4L2_QUANTIZATION_FULL_RANGE:
6376 +- q = y ? HDMI_QUANTIZATION_RANGE_DEFAULT :
6377 +- HDMI_QUANTIZATION_RANGE_FULL;
6378 +- yq = q ? q - 1 : HDMI_YCC_QUANTIZATION_RANGE_FULL;
6379 +- break;
6380 +- case V4L2_QUANTIZATION_LIM_RANGE:
6381 +- q = y ? HDMI_QUANTIZATION_RANGE_DEFAULT :
6382 +- HDMI_QUANTIZATION_RANGE_LIMITED;
6383 +- yq = q ? q - 1 : HDMI_YCC_QUANTIZATION_RANGE_LIMITED;
6384 +- break;
6385 +- }
6386 +-
6387 +- adv7511_wr_and_or(sd, 0x4a, 0xbf, 0);
6388 +- adv7511_wr_and_or(sd, 0x55, 0x9f, y << 5);
6389 +- adv7511_wr_and_or(sd, 0x56, 0x3f, c << 6);
6390 +- adv7511_wr_and_or(sd, 0x57, 0x83, (ec << 4) | (q << 2) | (itc << 7));
6391 +- adv7511_wr_and_or(sd, 0x59, 0x0f, (yq << 6) | (cn << 4));
6392 +- adv7511_wr_and_or(sd, 0x4a, 0xff, 1);
6393 +- adv7511_set_rgb_quantization_mode(sd, state->rgb_quantization_range_ctrl);
6394 +-
6395 +- return 0;
6396 +-}
6397 +-
6398 +-static const struct v4l2_subdev_pad_ops adv7511_pad_ops = {
6399 +- .get_edid = adv7511_get_edid,
6400 +- .enum_mbus_code = adv7511_enum_mbus_code,
6401 +- .get_fmt = adv7511_get_fmt,
6402 +- .set_fmt = adv7511_set_fmt,
6403 +- .enum_dv_timings = adv7511_enum_dv_timings,
6404 +- .dv_timings_cap = adv7511_dv_timings_cap,
6405 +-};
6406 +-
6407 +-/* --------------------- SUBDEV OPS --------------------------------------- */
6408 +-
6409 +-static const struct v4l2_subdev_ops adv7511_ops = {
6410 +- .core = &adv7511_core_ops,
6411 +- .pad = &adv7511_pad_ops,
6412 +- .video = &adv7511_video_ops,
6413 +- .audio = &adv7511_audio_ops,
6414 +-};
6415 +-
6416 +-/* ----------------------------------------------------------------------- */
6417 +-static void adv7511_dbg_dump_edid(int lvl, int debug, struct v4l2_subdev *sd, int segment, u8 *buf)
6418 +-{
6419 +- if (debug >= lvl) {
6420 +- int i, j;
6421 +- v4l2_dbg(lvl, debug, sd, "edid segment %d\n", segment);
6422 +- for (i = 0; i < 256; i += 16) {
6423 +- u8 b[128];
6424 +- u8 *bp = b;
6425 +- if (i == 128)
6426 +- v4l2_dbg(lvl, debug, sd, "\n");
6427 +- for (j = i; j < i + 16; j++) {
6428 +- sprintf(bp, "0x%02x, ", buf[j]);
6429 +- bp += 6;
6430 +- }
6431 +- bp[0] = '\0';
6432 +- v4l2_dbg(lvl, debug, sd, "%s\n", b);
6433 +- }
6434 +- }
6435 +-}
6436 +-
6437 +-static void adv7511_notify_no_edid(struct v4l2_subdev *sd)
6438 +-{
6439 +- struct adv7511_state *state = get_adv7511_state(sd);
6440 +- struct adv7511_edid_detect ed;
6441 +-
6442 +- /* We failed to read the EDID, so send an event for this. */
6443 +- ed.present = false;
6444 +- ed.segment = adv7511_rd(sd, 0xc4);
6445 +- ed.phys_addr = CEC_PHYS_ADDR_INVALID;
6446 +- cec_s_phys_addr(state->cec_adap, ed.phys_addr, false);
6447 +- v4l2_subdev_notify(sd, ADV7511_EDID_DETECT, (void *)&ed);
6448 +- v4l2_ctrl_s_ctrl(state->have_edid0_ctrl, 0x0);
6449 +-}
6450 +-
6451 +-static void adv7511_edid_handler(struct work_struct *work)
6452 +-{
6453 +- struct delayed_work *dwork = to_delayed_work(work);
6454 +- struct adv7511_state *state = container_of(dwork, struct adv7511_state, edid_handler);
6455 +- struct v4l2_subdev *sd = &state->sd;
6456 +-
6457 +- v4l2_dbg(1, debug, sd, "%s:\n", __func__);
6458 +-
6459 +- if (adv7511_check_edid_status(sd)) {
6460 +- /* Return if we received the EDID. */
6461 +- return;
6462 +- }
6463 +-
6464 +- if (adv7511_have_hotplug(sd)) {
6465 +- /* We must retry reading the EDID several times, it is possible
6466 +- * that initially the EDID couldn't be read due to i2c errors
6467 +- * (DVI connectors are particularly prone to this problem). */
6468 +- if (state->edid.read_retries) {
6469 +- state->edid.read_retries--;
6470 +- v4l2_dbg(1, debug, sd, "%s: edid read failed\n", __func__);
6471 +- state->have_monitor = false;
6472 +- adv7511_s_power(sd, false);
6473 +- adv7511_s_power(sd, true);
6474 +- queue_delayed_work(state->work_queue, &state->edid_handler, EDID_DELAY);
6475 +- return;
6476 +- }
6477 +- }
6478 +-
6479 +- /* We failed to read the EDID, so send an event for this. */
6480 +- adv7511_notify_no_edid(sd);
6481 +- v4l2_dbg(1, debug, sd, "%s: no edid found\n", __func__);
6482 +-}
6483 +-
6484 +-static void adv7511_audio_setup(struct v4l2_subdev *sd)
6485 +-{
6486 +- v4l2_dbg(1, debug, sd, "%s\n", __func__);
6487 +-
6488 +- adv7511_s_i2s_clock_freq(sd, 48000);
6489 +- adv7511_s_clock_freq(sd, 48000);
6490 +- adv7511_s_routing(sd, 0, 0, 0);
6491 +-}
6492 +-
6493 +-/* Configure hdmi transmitter. */
6494 +-static void adv7511_setup(struct v4l2_subdev *sd)
6495 +-{
6496 +- struct adv7511_state *state = get_adv7511_state(sd);
6497 +- v4l2_dbg(1, debug, sd, "%s\n", __func__);
6498 +-
6499 +- /* Input format: RGB 4:4:4 */
6500 +- adv7511_wr_and_or(sd, 0x15, 0xf0, 0x0);
6501 +- /* Output format: RGB 4:4:4 */
6502 +- adv7511_wr_and_or(sd, 0x16, 0x7f, 0x0);
6503 +- /* 1st order interpolation 4:2:2 -> 4:4:4 up conversion, Aspect ratio: 16:9 */
6504 +- adv7511_wr_and_or(sd, 0x17, 0xf9, 0x06);
6505 +- /* Disable pixel repetition */
6506 +- adv7511_wr_and_or(sd, 0x3b, 0x9f, 0x0);
6507 +- /* Disable CSC */
6508 +- adv7511_wr_and_or(sd, 0x18, 0x7f, 0x0);
6509 +- /* Output format: RGB 4:4:4, Active Format Information is valid,
6510 +- * underscanned */
6511 +- adv7511_wr_and_or(sd, 0x55, 0x9c, 0x12);
6512 +- /* AVI Info frame packet enable, Audio Info frame disable */
6513 +- adv7511_wr_and_or(sd, 0x44, 0xe7, 0x10);
6514 +- /* Colorimetry, Active format aspect ratio: same as picure. */
6515 +- adv7511_wr(sd, 0x56, 0xa8);
6516 +- /* No encryption */
6517 +- adv7511_wr_and_or(sd, 0xaf, 0xed, 0x0);
6518 +-
6519 +- /* Positive clk edge capture for input video clock */
6520 +- adv7511_wr_and_or(sd, 0xba, 0x1f, 0x60);
6521 +-
6522 +- adv7511_audio_setup(sd);
6523 +-
6524 +- v4l2_ctrl_handler_setup(&state->hdl);
6525 +-}
6526 +-
6527 +-static void adv7511_notify_monitor_detect(struct v4l2_subdev *sd)
6528 +-{
6529 +- struct adv7511_monitor_detect mdt;
6530 +- struct adv7511_state *state = get_adv7511_state(sd);
6531 +-
6532 +- mdt.present = state->have_monitor;
6533 +- v4l2_subdev_notify(sd, ADV7511_MONITOR_DETECT, (void *)&mdt);
6534 +-}
6535 +-
6536 +-static void adv7511_check_monitor_present_status(struct v4l2_subdev *sd)
6537 +-{
6538 +- struct adv7511_state *state = get_adv7511_state(sd);
6539 +- /* read hotplug and rx-sense state */
6540 +- u8 status = adv7511_rd(sd, 0x42);
6541 +-
6542 +- v4l2_dbg(1, debug, sd, "%s: status: 0x%x%s%s\n",
6543 +- __func__,
6544 +- status,
6545 +- status & MASK_ADV7511_HPD_DETECT ? ", hotplug" : "",
6546 +- status & MASK_ADV7511_MSEN_DETECT ? ", rx-sense" : "");
6547 +-
6548 +- /* update read only ctrls */
6549 +- v4l2_ctrl_s_ctrl(state->hotplug_ctrl, adv7511_have_hotplug(sd) ? 0x1 : 0x0);
6550 +- v4l2_ctrl_s_ctrl(state->rx_sense_ctrl, adv7511_have_rx_sense(sd) ? 0x1 : 0x0);
6551 +-
6552 +- if ((status & MASK_ADV7511_HPD_DETECT) && ((status & MASK_ADV7511_MSEN_DETECT) || state->edid.segments)) {
6553 +- v4l2_dbg(1, debug, sd, "%s: hotplug and (rx-sense or edid)\n", __func__);
6554 +- if (!state->have_monitor) {
6555 +- v4l2_dbg(1, debug, sd, "%s: monitor detected\n", __func__);
6556 +- state->have_monitor = true;
6557 +- adv7511_set_isr(sd, true);
6558 +- if (!adv7511_s_power(sd, true)) {
6559 +- v4l2_dbg(1, debug, sd, "%s: monitor detected, powerup failed\n", __func__);
6560 +- return;
6561 +- }
6562 +- adv7511_setup(sd);
6563 +- adv7511_notify_monitor_detect(sd);
6564 +- state->edid.read_retries = EDID_MAX_RETRIES;
6565 +- queue_delayed_work(state->work_queue, &state->edid_handler, EDID_DELAY);
6566 +- }
6567 +- } else if (status & MASK_ADV7511_HPD_DETECT) {
6568 +- v4l2_dbg(1, debug, sd, "%s: hotplug detected\n", __func__);
6569 +- state->edid.read_retries = EDID_MAX_RETRIES;
6570 +- queue_delayed_work(state->work_queue, &state->edid_handler, EDID_DELAY);
6571 +- } else if (!(status & MASK_ADV7511_HPD_DETECT)) {
6572 +- v4l2_dbg(1, debug, sd, "%s: hotplug not detected\n", __func__);
6573 +- if (state->have_monitor) {
6574 +- v4l2_dbg(1, debug, sd, "%s: monitor not detected\n", __func__);
6575 +- state->have_monitor = false;
6576 +- adv7511_notify_monitor_detect(sd);
6577 +- }
6578 +- adv7511_s_power(sd, false);
6579 +- memset(&state->edid, 0, sizeof(struct adv7511_state_edid));
6580 +- adv7511_notify_no_edid(sd);
6581 +- }
6582 +-}
6583 +-
6584 +-static bool edid_block_verify_crc(u8 *edid_block)
6585 +-{
6586 +- u8 sum = 0;
6587 +- int i;
6588 +-
6589 +- for (i = 0; i < 128; i++)
6590 +- sum += edid_block[i];
6591 +- return sum == 0;
6592 +-}
6593 +-
6594 +-static bool edid_verify_crc(struct v4l2_subdev *sd, u32 segment)
6595 +-{
6596 +- struct adv7511_state *state = get_adv7511_state(sd);
6597 +- u32 blocks = state->edid.blocks;
6598 +- u8 *data = state->edid.data;
6599 +-
6600 +- if (!edid_block_verify_crc(&data[segment * 256]))
6601 +- return false;
6602 +- if ((segment + 1) * 2 <= blocks)
6603 +- return edid_block_verify_crc(&data[segment * 256 + 128]);
6604 +- return true;
6605 +-}
6606 +-
6607 +-static bool edid_verify_header(struct v4l2_subdev *sd, u32 segment)
6608 +-{
6609 +- static const u8 hdmi_header[] = {
6610 +- 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00
6611 +- };
6612 +- struct adv7511_state *state = get_adv7511_state(sd);
6613 +- u8 *data = state->edid.data;
6614 +-
6615 +- if (segment != 0)
6616 +- return true;
6617 +- return !memcmp(data, hdmi_header, sizeof(hdmi_header));
6618 +-}
6619 +-
6620 +-static bool adv7511_check_edid_status(struct v4l2_subdev *sd)
6621 +-{
6622 +- struct adv7511_state *state = get_adv7511_state(sd);
6623 +- u8 edidRdy = adv7511_rd(sd, 0xc5);
6624 +-
6625 +- v4l2_dbg(1, debug, sd, "%s: edid ready (retries: %d)\n",
6626 +- __func__, EDID_MAX_RETRIES - state->edid.read_retries);
6627 +-
6628 +- if (state->edid.complete)
6629 +- return true;
6630 +-
6631 +- if (edidRdy & MASK_ADV7511_EDID_RDY) {
6632 +- int segment = adv7511_rd(sd, 0xc4);
6633 +- struct adv7511_edid_detect ed;
6634 +-
6635 +- if (segment >= EDID_MAX_SEGM) {
6636 +- v4l2_err(sd, "edid segment number too big\n");
6637 +- return false;
6638 +- }
6639 +- v4l2_dbg(1, debug, sd, "%s: got segment %d\n", __func__, segment);
6640 +- adv7511_edid_rd(sd, 256, &state->edid.data[segment * 256]);
6641 +- adv7511_dbg_dump_edid(2, debug, sd, segment, &state->edid.data[segment * 256]);
6642 +- if (segment == 0) {
6643 +- state->edid.blocks = state->edid.data[0x7e] + 1;
6644 +- v4l2_dbg(1, debug, sd, "%s: %d blocks in total\n", __func__, state->edid.blocks);
6645 +- }
6646 +- if (!edid_verify_crc(sd, segment) ||
6647 +- !edid_verify_header(sd, segment)) {
6648 +- /* edid crc error, force reread of edid segment */
6649 +- v4l2_err(sd, "%s: edid crc or header error\n", __func__);
6650 +- state->have_monitor = false;
6651 +- adv7511_s_power(sd, false);
6652 +- adv7511_s_power(sd, true);
6653 +- return false;
6654 +- }
6655 +- /* one more segment read ok */
6656 +- state->edid.segments = segment + 1;
6657 +- v4l2_ctrl_s_ctrl(state->have_edid0_ctrl, 0x1);
6658 +- if (((state->edid.data[0x7e] >> 1) + 1) > state->edid.segments) {
6659 +- /* Request next EDID segment */
6660 +- v4l2_dbg(1, debug, sd, "%s: request segment %d\n", __func__, state->edid.segments);
6661 +- adv7511_wr(sd, 0xc9, 0xf);
6662 +- adv7511_wr(sd, 0xc4, state->edid.segments);
6663 +- state->edid.read_retries = EDID_MAX_RETRIES;
6664 +- queue_delayed_work(state->work_queue, &state->edid_handler, EDID_DELAY);
6665 +- return false;
6666 +- }
6667 +-
6668 +- v4l2_dbg(1, debug, sd, "%s: edid complete with %d segment(s)\n", __func__, state->edid.segments);
6669 +- state->edid.complete = true;
6670 +- ed.phys_addr = cec_get_edid_phys_addr(state->edid.data,
6671 +- state->edid.segments * 256,
6672 +- NULL);
6673 +- /* report when we have all segments
6674 +- but report only for segment 0
6675 +- */
6676 +- ed.present = true;
6677 +- ed.segment = 0;
6678 +- state->edid_detect_counter++;
6679 +- cec_s_phys_addr(state->cec_adap, ed.phys_addr, false);
6680 +- v4l2_subdev_notify(sd, ADV7511_EDID_DETECT, (void *)&ed);
6681 +- return ed.present;
6682 +- }
6683 +-
6684 +- return false;
6685 +-}
6686 +-
6687 +-static int adv7511_registered(struct v4l2_subdev *sd)
6688 +-{
6689 +- struct adv7511_state *state = get_adv7511_state(sd);
6690 +- struct i2c_client *client = v4l2_get_subdevdata(sd);
6691 +- int err;
6692 +-
6693 +- err = cec_register_adapter(state->cec_adap, &client->dev);
6694 +- if (err)
6695 +- cec_delete_adapter(state->cec_adap);
6696 +- return err;
6697 +-}
6698 +-
6699 +-static void adv7511_unregistered(struct v4l2_subdev *sd)
6700 +-{
6701 +- struct adv7511_state *state = get_adv7511_state(sd);
6702 +-
6703 +- cec_unregister_adapter(state->cec_adap);
6704 +-}
6705 +-
6706 +-static const struct v4l2_subdev_internal_ops adv7511_int_ops = {
6707 +- .registered = adv7511_registered,
6708 +- .unregistered = adv7511_unregistered,
6709 +-};
6710 +-
6711 +-/* ----------------------------------------------------------------------- */
6712 +-/* Setup ADV7511 */
6713 +-static void adv7511_init_setup(struct v4l2_subdev *sd)
6714 +-{
6715 +- struct adv7511_state *state = get_adv7511_state(sd);
6716 +- struct adv7511_state_edid *edid = &state->edid;
6717 +- u32 cec_clk = state->pdata.cec_clk;
6718 +- u8 ratio;
6719 +-
6720 +- v4l2_dbg(1, debug, sd, "%s\n", __func__);
6721 +-
6722 +- /* clear all interrupts */
6723 +- adv7511_wr(sd, 0x96, 0xff);
6724 +- adv7511_wr(sd, 0x97, 0xff);
6725 +- /*
6726 +- * Stop HPD from resetting a lot of registers.
6727 +- * It might leave the chip in a partly un-initialized state,
6728 +- * in particular with regards to hotplug bounces.
6729 +- */
6730 +- adv7511_wr_and_or(sd, 0xd6, 0x3f, 0xc0);
6731 +- memset(edid, 0, sizeof(struct adv7511_state_edid));
6732 +- state->have_monitor = false;
6733 +- adv7511_set_isr(sd, false);
6734 +- adv7511_s_stream(sd, false);
6735 +- adv7511_s_audio_stream(sd, false);
6736 +-
6737 +- if (state->i2c_cec == NULL)
6738 +- return;
6739 +-
6740 +- v4l2_dbg(1, debug, sd, "%s: cec_clk %d\n", __func__, cec_clk);
6741 +-
6742 +- /* cec soft reset */
6743 +- adv7511_cec_write(sd, 0x50, 0x01);
6744 +- adv7511_cec_write(sd, 0x50, 0x00);
6745 +-
6746 +- /* legacy mode */
6747 +- adv7511_cec_write(sd, 0x4a, 0x00);
6748 +-
6749 +- if (cec_clk % 750000 != 0)
6750 +- v4l2_err(sd, "%s: cec_clk %d, not multiple of 750 Khz\n",
6751 +- __func__, cec_clk);
6752 +-
6753 +- ratio = (cec_clk / 750000) - 1;
6754 +- adv7511_cec_write(sd, 0x4e, ratio << 2);
6755 +-}
6756 +-
6757 +-static int adv7511_probe(struct i2c_client *client, const struct i2c_device_id *id)
6758 +-{
6759 +- struct adv7511_state *state;
6760 +- struct adv7511_platform_data *pdata = client->dev.platform_data;
6761 +- struct v4l2_ctrl_handler *hdl;
6762 +- struct v4l2_subdev *sd;
6763 +- u8 chip_id[2];
6764 +- int err = -EIO;
6765 +-
6766 +- /* Check if the adapter supports the needed features */
6767 +- if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA))
6768 +- return -EIO;
6769 +-
6770 +- state = devm_kzalloc(&client->dev, sizeof(struct adv7511_state), GFP_KERNEL);
6771 +- if (!state)
6772 +- return -ENOMEM;
6773 +-
6774 +- /* Platform data */
6775 +- if (!pdata) {
6776 +- v4l_err(client, "No platform data!\n");
6777 +- return -ENODEV;
6778 +- }
6779 +- memcpy(&state->pdata, pdata, sizeof(state->pdata));
6780 +- state->fmt_code = MEDIA_BUS_FMT_RGB888_1X24;
6781 +- state->colorspace = V4L2_COLORSPACE_SRGB;
6782 +-
6783 +- sd = &state->sd;
6784 +-
6785 +- v4l2_dbg(1, debug, sd, "detecting adv7511 client on address 0x%x\n",
6786 +- client->addr << 1);
6787 +-
6788 +- v4l2_i2c_subdev_init(sd, client, &adv7511_ops);
6789 +- sd->internal_ops = &adv7511_int_ops;
6790 +-
6791 +- hdl = &state->hdl;
6792 +- v4l2_ctrl_handler_init(hdl, 10);
6793 +- /* add in ascending ID order */
6794 +- state->hdmi_mode_ctrl = v4l2_ctrl_new_std_menu(hdl, &adv7511_ctrl_ops,
6795 +- V4L2_CID_DV_TX_MODE, V4L2_DV_TX_MODE_HDMI,
6796 +- 0, V4L2_DV_TX_MODE_DVI_D);
6797 +- state->hotplug_ctrl = v4l2_ctrl_new_std(hdl, NULL,
6798 +- V4L2_CID_DV_TX_HOTPLUG, 0, 1, 0, 0);
6799 +- state->rx_sense_ctrl = v4l2_ctrl_new_std(hdl, NULL,
6800 +- V4L2_CID_DV_TX_RXSENSE, 0, 1, 0, 0);
6801 +- state->have_edid0_ctrl = v4l2_ctrl_new_std(hdl, NULL,
6802 +- V4L2_CID_DV_TX_EDID_PRESENT, 0, 1, 0, 0);
6803 +- state->rgb_quantization_range_ctrl =
6804 +- v4l2_ctrl_new_std_menu(hdl, &adv7511_ctrl_ops,
6805 +- V4L2_CID_DV_TX_RGB_RANGE, V4L2_DV_RGB_RANGE_FULL,
6806 +- 0, V4L2_DV_RGB_RANGE_AUTO);
6807 +- state->content_type_ctrl =
6808 +- v4l2_ctrl_new_std_menu(hdl, &adv7511_ctrl_ops,
6809 +- V4L2_CID_DV_TX_IT_CONTENT_TYPE, V4L2_DV_IT_CONTENT_TYPE_NO_ITC,
6810 +- 0, V4L2_DV_IT_CONTENT_TYPE_NO_ITC);
6811 +- sd->ctrl_handler = hdl;
6812 +- if (hdl->error) {
6813 +- err = hdl->error;
6814 +- goto err_hdl;
6815 +- }
6816 +- state->pad.flags = MEDIA_PAD_FL_SINK;
6817 +- err = media_entity_pads_init(&sd->entity, 1, &state->pad);
6818 +- if (err)
6819 +- goto err_hdl;
6820 +-
6821 +- /* EDID and CEC i2c addr */
6822 +- state->i2c_edid_addr = state->pdata.i2c_edid << 1;
6823 +- state->i2c_cec_addr = state->pdata.i2c_cec << 1;
6824 +- state->i2c_pktmem_addr = state->pdata.i2c_pktmem << 1;
6825 +-
6826 +- state->chip_revision = adv7511_rd(sd, 0x0);
6827 +- chip_id[0] = adv7511_rd(sd, 0xf5);
6828 +- chip_id[1] = adv7511_rd(sd, 0xf6);
6829 +- if (chip_id[0] != 0x75 || chip_id[1] != 0x11) {
6830 +- v4l2_err(sd, "chip_id != 0x7511, read 0x%02x%02x\n", chip_id[0],
6831 +- chip_id[1]);
6832 +- err = -EIO;
6833 +- goto err_entity;
6834 +- }
6835 +-
6836 +- state->i2c_edid = i2c_new_dummy(client->adapter,
6837 +- state->i2c_edid_addr >> 1);
6838 +- if (state->i2c_edid == NULL) {
6839 +- v4l2_err(sd, "failed to register edid i2c client\n");
6840 +- err = -ENOMEM;
6841 +- goto err_entity;
6842 +- }
6843 +-
6844 +- adv7511_wr(sd, 0xe1, state->i2c_cec_addr);
6845 +- if (state->pdata.cec_clk < 3000000 ||
6846 +- state->pdata.cec_clk > 100000000) {
6847 +- v4l2_err(sd, "%s: cec_clk %u outside range, disabling cec\n",
6848 +- __func__, state->pdata.cec_clk);
6849 +- state->pdata.cec_clk = 0;
6850 +- }
6851 +-
6852 +- if (state->pdata.cec_clk) {
6853 +- state->i2c_cec = i2c_new_dummy(client->adapter,
6854 +- state->i2c_cec_addr >> 1);
6855 +- if (state->i2c_cec == NULL) {
6856 +- v4l2_err(sd, "failed to register cec i2c client\n");
6857 +- err = -ENOMEM;
6858 +- goto err_unreg_edid;
6859 +- }
6860 +- adv7511_wr(sd, 0xe2, 0x00); /* power up cec section */
6861 +- } else {
6862 +- adv7511_wr(sd, 0xe2, 0x01); /* power down cec section */
6863 +- }
6864 +-
6865 +- state->i2c_pktmem = i2c_new_dummy(client->adapter, state->i2c_pktmem_addr >> 1);
6866 +- if (state->i2c_pktmem == NULL) {
6867 +- v4l2_err(sd, "failed to register pktmem i2c client\n");
6868 +- err = -ENOMEM;
6869 +- goto err_unreg_cec;
6870 +- }
6871 +-
6872 +- state->work_queue = create_singlethread_workqueue(sd->name);
6873 +- if (state->work_queue == NULL) {
6874 +- v4l2_err(sd, "could not create workqueue\n");
6875 +- err = -ENOMEM;
6876 +- goto err_unreg_pktmem;
6877 +- }
6878 +-
6879 +- INIT_DELAYED_WORK(&state->edid_handler, adv7511_edid_handler);
6880 +-
6881 +- adv7511_init_setup(sd);
6882 +-
6883 +-#if IS_ENABLED(CONFIG_VIDEO_ADV7511_CEC)
6884 +- state->cec_adap = cec_allocate_adapter(&adv7511_cec_adap_ops,
6885 +- state, dev_name(&client->dev), CEC_CAP_DEFAULTS,
6886 +- ADV7511_MAX_ADDRS);
6887 +- err = PTR_ERR_OR_ZERO(state->cec_adap);
6888 +- if (err) {
6889 +- destroy_workqueue(state->work_queue);
6890 +- goto err_unreg_pktmem;
6891 +- }
6892 +-#endif
6893 +-
6894 +- adv7511_set_isr(sd, true);
6895 +- adv7511_check_monitor_present_status(sd);
6896 +-
6897 +- v4l2_info(sd, "%s found @ 0x%x (%s)\n", client->name,
6898 +- client->addr << 1, client->adapter->name);
6899 +- return 0;
6900 +-
6901 +-err_unreg_pktmem:
6902 +- i2c_unregister_device(state->i2c_pktmem);
6903 +-err_unreg_cec:
6904 +- if (state->i2c_cec)
6905 +- i2c_unregister_device(state->i2c_cec);
6906 +-err_unreg_edid:
6907 +- i2c_unregister_device(state->i2c_edid);
6908 +-err_entity:
6909 +- media_entity_cleanup(&sd->entity);
6910 +-err_hdl:
6911 +- v4l2_ctrl_handler_free(&state->hdl);
6912 +- return err;
6913 +-}
6914 +-
6915 +-/* ----------------------------------------------------------------------- */
6916 +-
6917 +-static int adv7511_remove(struct i2c_client *client)
6918 +-{
6919 +- struct v4l2_subdev *sd = i2c_get_clientdata(client);
6920 +- struct adv7511_state *state = get_adv7511_state(sd);
6921 +-
6922 +- state->chip_revision = -1;
6923 +-
6924 +- v4l2_dbg(1, debug, sd, "%s removed @ 0x%x (%s)\n", client->name,
6925 +- client->addr << 1, client->adapter->name);
6926 +-
6927 +- adv7511_set_isr(sd, false);
6928 +- adv7511_init_setup(sd);
6929 +- cancel_delayed_work(&state->edid_handler);
6930 +- i2c_unregister_device(state->i2c_edid);
6931 +- if (state->i2c_cec)
6932 +- i2c_unregister_device(state->i2c_cec);
6933 +- i2c_unregister_device(state->i2c_pktmem);
6934 +- destroy_workqueue(state->work_queue);
6935 +- v4l2_device_unregister_subdev(sd);
6936 +- media_entity_cleanup(&sd->entity);
6937 +- v4l2_ctrl_handler_free(sd->ctrl_handler);
6938 +- return 0;
6939 +-}
6940 +-
6941 +-/* ----------------------------------------------------------------------- */
6942 +-
6943 +-static const struct i2c_device_id adv7511_id[] = {
6944 +- { "adv7511", 0 },
6945 +- { }
6946 +-};
6947 +-MODULE_DEVICE_TABLE(i2c, adv7511_id);
6948 +-
6949 +-static struct i2c_driver adv7511_driver = {
6950 +- .driver = {
6951 +- .name = "adv7511",
6952 +- },
6953 +- .probe = adv7511_probe,
6954 +- .remove = adv7511_remove,
6955 +- .id_table = adv7511_id,
6956 +-};
6957 +-
6958 +-module_i2c_driver(adv7511_driver);
6959 +diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c
6960 +index 62b2c5d9bdfb..4eb51a618fe1 100644
6961 +--- a/drivers/media/media-device.c
6962 ++++ b/drivers/media/media-device.c
6963 +@@ -470,6 +470,7 @@ static long media_device_enum_links32(struct media_device *mdev,
6964 + {
6965 + struct media_links_enum links;
6966 + compat_uptr_t pads_ptr, links_ptr;
6967 ++ int ret;
6968 +
6969 + memset(&links, 0, sizeof(links));
6970 +
6971 +@@ -481,7 +482,14 @@ static long media_device_enum_links32(struct media_device *mdev,
6972 + links.pads = compat_ptr(pads_ptr);
6973 + links.links = compat_ptr(links_ptr);
6974 +
6975 +- return media_device_enum_links(mdev, &links);
6976 ++ ret = media_device_enum_links(mdev, &links);
6977 ++ if (ret)
6978 ++ return ret;
6979 ++
6980 ++ if (copy_to_user(ulinks->reserved, links.reserved,
6981 ++ sizeof(ulinks->reserved)))
6982 ++ return -EFAULT;
6983 ++ return 0;
6984 + }
6985 +
6986 + #define MEDIA_IOC_ENUM_LINKS32 _IOWR('|', 0x02, struct media_links_enum32)
6987 +diff --git a/drivers/media/platform/coda/coda-bit.c b/drivers/media/platform/coda/coda-bit.c
6988 +index 6eee55430d46..d538cd49a3ba 100644
6989 +--- a/drivers/media/platform/coda/coda-bit.c
6990 ++++ b/drivers/media/platform/coda/coda-bit.c
6991 +@@ -1679,6 +1679,7 @@ static int __coda_start_decoding(struct coda_ctx *ctx)
6992 + v4l2_err(&dev->v4l2_dev, "CODA_COMMAND_SEQ_INIT timeout\n");
6993 + return ret;
6994 + }
6995 ++ ctx->sequence_offset = ~0U;
6996 + ctx->initialized = 1;
6997 +
6998 + /* Update kfifo out pointer from coda bitstream read pointer */
6999 +@@ -2090,12 +2091,17 @@ static void coda_finish_decode(struct coda_ctx *ctx)
7000 + else if (ctx->display_idx < 0)
7001 + ctx->hold = true;
7002 + } else if (decoded_idx == -2) {
7003 ++ if (ctx->display_idx >= 0 &&
7004 ++ ctx->display_idx < ctx->num_internal_frames)
7005 ++ ctx->sequence_offset++;
7006 + /* no frame was decoded, we still return remaining buffers */
7007 + } else if (decoded_idx < 0 || decoded_idx >= ctx->num_internal_frames) {
7008 + v4l2_err(&dev->v4l2_dev,
7009 + "decoded frame index out of range: %d\n", decoded_idx);
7010 + } else {
7011 +- val = coda_read(dev, CODA_RET_DEC_PIC_FRAME_NUM) - 1;
7012 ++ val = coda_read(dev, CODA_RET_DEC_PIC_FRAME_NUM);
7013 ++ if (ctx->sequence_offset == -1)
7014 ++ ctx->sequence_offset = val;
7015 + val -= ctx->sequence_offset;
7016 + spin_lock_irqsave(&ctx->buffer_meta_lock, flags);
7017 + if (!list_empty(&ctx->buffer_meta_list)) {
7018 +@@ -2251,7 +2257,6 @@ irqreturn_t coda_irq_handler(int irq, void *data)
7019 + if (ctx == NULL) {
7020 + v4l2_err(&dev->v4l2_dev,
7021 + "Instance released before the end of transaction\n");
7022 +- mutex_unlock(&dev->coda_mutex);
7023 + return IRQ_HANDLED;
7024 + }
7025 +
7026 +diff --git a/drivers/media/platform/coda/coda-common.c b/drivers/media/platform/coda/coda-common.c
7027 +index 2e1472fadc2c..5b87c488ee11 100644
7028 +--- a/drivers/media/platform/coda/coda-common.c
7029 ++++ b/drivers/media/platform/coda/coda-common.c
7030 +@@ -932,6 +932,8 @@ static int coda_encoder_cmd(struct file *file, void *fh,
7031 + /* Set the stream-end flag on this context */
7032 + ctx->bit_stream_param |= CODA_BIT_STREAM_END_FLAG;
7033 +
7034 ++ flush_work(&ctx->pic_run_work);
7035 ++
7036 + /* If there is no buffer in flight, wake up */
7037 + if (!ctx->streamon_out || ctx->qsequence == ctx->osequence) {
7038 + dst_vq = v4l2_m2m_get_vq(ctx->fh.m2m_ctx,
7039 +diff --git a/drivers/media/platform/davinci/vpss.c b/drivers/media/platform/davinci/vpss.c
7040 +index f2d27b932999..2ee4cd9e6d80 100644
7041 +--- a/drivers/media/platform/davinci/vpss.c
7042 ++++ b/drivers/media/platform/davinci/vpss.c
7043 +@@ -518,6 +518,11 @@ static int __init vpss_init(void)
7044 + return -EBUSY;
7045 +
7046 + oper_cfg.vpss_regs_base2 = ioremap(VPSS_CLK_CTRL, 4);
7047 ++ if (unlikely(!oper_cfg.vpss_regs_base2)) {
7048 ++ release_mem_region(VPSS_CLK_CTRL, 4);
7049 ++ return -ENOMEM;
7050 ++ }
7051 ++
7052 + writel(VPSS_CLK_CTRL_VENCCLKEN |
7053 + VPSS_CLK_CTRL_DACCLKEN, oper_cfg.vpss_regs_base2);
7054 +
7055 +diff --git a/drivers/media/platform/marvell-ccic/mcam-core.c b/drivers/media/platform/marvell-ccic/mcam-core.c
7056 +index 7b7250b1cff8..4ecb94860aa4 100644
7057 +--- a/drivers/media/platform/marvell-ccic/mcam-core.c
7058 ++++ b/drivers/media/platform/marvell-ccic/mcam-core.c
7059 +@@ -200,7 +200,6 @@ struct mcam_vb_buffer {
7060 + struct list_head queue;
7061 + struct mcam_dma_desc *dma_desc; /* Descriptor virtual address */
7062 + dma_addr_t dma_desc_pa; /* Descriptor physical address */
7063 +- int dma_desc_nent; /* Number of mapped descriptors */
7064 + };
7065 +
7066 + static inline struct mcam_vb_buffer *vb_to_mvb(struct vb2_v4l2_buffer *vb)
7067 +@@ -608,9 +607,11 @@ static void mcam_dma_contig_done(struct mcam_camera *cam, int frame)
7068 + static void mcam_sg_next_buffer(struct mcam_camera *cam)
7069 + {
7070 + struct mcam_vb_buffer *buf;
7071 ++ struct sg_table *sg_table;
7072 +
7073 + buf = list_first_entry(&cam->buffers, struct mcam_vb_buffer, queue);
7074 + list_del_init(&buf->queue);
7075 ++ sg_table = vb2_dma_sg_plane_desc(&buf->vb_buf.vb2_buf, 0);
7076 + /*
7077 + * Very Bad Not Good Things happen if you don't clear
7078 + * C1_DESC_ENA before making any descriptor changes.
7079 +@@ -618,7 +619,7 @@ static void mcam_sg_next_buffer(struct mcam_camera *cam)
7080 + mcam_reg_clear_bit(cam, REG_CTRL1, C1_DESC_ENA);
7081 + mcam_reg_write(cam, REG_DMA_DESC_Y, buf->dma_desc_pa);
7082 + mcam_reg_write(cam, REG_DESC_LEN_Y,
7083 +- buf->dma_desc_nent*sizeof(struct mcam_dma_desc));
7084 ++ sg_table->nents * sizeof(struct mcam_dma_desc));
7085 + mcam_reg_write(cam, REG_DESC_LEN_U, 0);
7086 + mcam_reg_write(cam, REG_DESC_LEN_V, 0);
7087 + mcam_reg_set_bit(cam, REG_CTRL1, C1_DESC_ENA);
7088 +diff --git a/drivers/media/platform/rcar_fdp1.c b/drivers/media/platform/rcar_fdp1.c
7089 +index 3245bc45f4a0..a889332d5d30 100644
7090 +--- a/drivers/media/platform/rcar_fdp1.c
7091 ++++ b/drivers/media/platform/rcar_fdp1.c
7092 +@@ -261,6 +261,8 @@ MODULE_PARM_DESC(debug, "activate debug info");
7093 + #define FD1_IP_H3_ES1 0x02010101
7094 + #define FD1_IP_M3W 0x02010202
7095 + #define FD1_IP_H3 0x02010203
7096 ++#define FD1_IP_M3N 0x02010204
7097 ++#define FD1_IP_E3 0x02010205
7098 +
7099 + /* LUTs */
7100 + #define FD1_LUT_DIF_ADJ 0x1000
7101 +@@ -2369,6 +2371,12 @@ static int fdp1_probe(struct platform_device *pdev)
7102 + case FD1_IP_H3:
7103 + dprintk(fdp1, "FDP1 Version R-Car H3\n");
7104 + break;
7105 ++ case FD1_IP_M3N:
7106 ++ dprintk(fdp1, "FDP1 Version R-Car M3N\n");
7107 ++ break;
7108 ++ case FD1_IP_E3:
7109 ++ dprintk(fdp1, "FDP1 Version R-Car E3\n");
7110 ++ break;
7111 + default:
7112 + dev_err(fdp1->dev, "FDP1 Unidentifiable (0x%08x)\n",
7113 + hw_version);
7114 +diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc_pm.c b/drivers/media/platform/s5p-mfc/s5p_mfc_pm.c
7115 +index eb85cedc5ef3..5e080f32b0e8 100644
7116 +--- a/drivers/media/platform/s5p-mfc/s5p_mfc_pm.c
7117 ++++ b/drivers/media/platform/s5p-mfc/s5p_mfc_pm.c
7118 +@@ -38,6 +38,11 @@ int s5p_mfc_init_pm(struct s5p_mfc_dev *dev)
7119 + for (i = 0; i < pm->num_clocks; i++) {
7120 + pm->clocks[i] = devm_clk_get(pm->device, pm->clk_names[i]);
7121 + if (IS_ERR(pm->clocks[i])) {
7122 ++ /* additional clocks are optional */
7123 ++ if (i && PTR_ERR(pm->clocks[i]) == -ENOENT) {
7124 ++ pm->clocks[i] = NULL;
7125 ++ continue;
7126 ++ }
7127 + mfc_err("Failed to get clock: %s\n",
7128 + pm->clk_names[i]);
7129 + return PTR_ERR(pm->clocks[i]);
7130 +diff --git a/drivers/media/platform/vimc/vimc-capture.c b/drivers/media/platform/vimc/vimc-capture.c
7131 +index a078ad18909a..091921ed09dd 100644
7132 +--- a/drivers/media/platform/vimc/vimc-capture.c
7133 ++++ b/drivers/media/platform/vimc/vimc-capture.c
7134 +@@ -131,12 +131,15 @@ static int vimc_cap_s_fmt_vid_cap(struct file *file, void *priv,
7135 + struct v4l2_format *f)
7136 + {
7137 + struct vimc_cap_device *vcap = video_drvdata(file);
7138 ++ int ret;
7139 +
7140 + /* Do not change the format while stream is on */
7141 + if (vb2_is_busy(&vcap->queue))
7142 + return -EBUSY;
7143 +
7144 +- vimc_cap_try_fmt_vid_cap(file, priv, f);
7145 ++ ret = vimc_cap_try_fmt_vid_cap(file, priv, f);
7146 ++ if (ret)
7147 ++ return ret;
7148 +
7149 + dev_dbg(vcap->dev, "%s: format update: "
7150 + "old:%dx%d (0x%x, %d, %d, %d, %d) "
7151 +diff --git a/drivers/media/radio/wl128x/fmdrv_v4l2.c b/drivers/media/radio/wl128x/fmdrv_v4l2.c
7152 +index fc5a7abc83d2..77778c86e04d 100644
7153 +--- a/drivers/media/radio/wl128x/fmdrv_v4l2.c
7154 ++++ b/drivers/media/radio/wl128x/fmdrv_v4l2.c
7155 +@@ -549,6 +549,7 @@ int fm_v4l2_init_video_device(struct fmdev *fmdev, int radio_nr)
7156 +
7157 + /* Register with V4L2 subsystem as RADIO device */
7158 + if (video_register_device(&gradio_dev, VFL_TYPE_RADIO, radio_nr)) {
7159 ++ v4l2_device_unregister(&fmdev->v4l2_dev);
7160 + fmerr("Could not register video device\n");
7161 + return -ENOMEM;
7162 + }
7163 +@@ -562,6 +563,8 @@ int fm_v4l2_init_video_device(struct fmdev *fmdev, int radio_nr)
7164 + if (ret < 0) {
7165 + fmerr("(fmdev): Can't init ctrl handler\n");
7166 + v4l2_ctrl_handler_free(&fmdev->ctrl_handler);
7167 ++ video_unregister_device(fmdev->radio_dev);
7168 ++ v4l2_device_unregister(&fmdev->v4l2_dev);
7169 + return -EBUSY;
7170 + }
7171 +
7172 +diff --git a/drivers/media/rc/ir-spi.c b/drivers/media/rc/ir-spi.c
7173 +index 29ed0638cb74..cbe585f95715 100644
7174 +--- a/drivers/media/rc/ir-spi.c
7175 ++++ b/drivers/media/rc/ir-spi.c
7176 +@@ -186,6 +186,7 @@ static const struct of_device_id ir_spi_of_match[] = {
7177 + { .compatible = "ir-spi-led" },
7178 + {},
7179 + };
7180 ++MODULE_DEVICE_TABLE(of, ir_spi_of_match);
7181 +
7182 + static struct spi_driver ir_spi_driver = {
7183 + .probe = ir_spi_probe,
7184 +diff --git a/drivers/media/usb/dvb-usb/dvb-usb-init.c b/drivers/media/usb/dvb-usb/dvb-usb-init.c
7185 +index 84308569e7dc..b3413404f91a 100644
7186 +--- a/drivers/media/usb/dvb-usb/dvb-usb-init.c
7187 ++++ b/drivers/media/usb/dvb-usb/dvb-usb-init.c
7188 +@@ -287,12 +287,15 @@ EXPORT_SYMBOL(dvb_usb_device_init);
7189 + void dvb_usb_device_exit(struct usb_interface *intf)
7190 + {
7191 + struct dvb_usb_device *d = usb_get_intfdata(intf);
7192 +- const char *name = "generic DVB-USB module";
7193 ++ const char *default_name = "generic DVB-USB module";
7194 ++ char name[40];
7195 +
7196 + usb_set_intfdata(intf, NULL);
7197 + if (d != NULL && d->desc != NULL) {
7198 +- name = d->desc->name;
7199 ++ strscpy(name, d->desc->name, sizeof(name));
7200 + dvb_usb_exit(d);
7201 ++ } else {
7202 ++ strscpy(name, default_name, sizeof(name));
7203 + }
7204 + info("%s successfully deinitialized and disconnected.", name);
7205 +
7206 +diff --git a/drivers/media/usb/hdpvr/hdpvr-video.c b/drivers/media/usb/hdpvr/hdpvr-video.c
7207 +index 7fb036d6a86e..991f820a4530 100644
7208 +--- a/drivers/media/usb/hdpvr/hdpvr-video.c
7209 ++++ b/drivers/media/usb/hdpvr/hdpvr-video.c
7210 +@@ -439,7 +439,7 @@ static ssize_t hdpvr_read(struct file *file, char __user *buffer, size_t count,
7211 + /* wait for the first buffer */
7212 + if (!(file->f_flags & O_NONBLOCK)) {
7213 + if (wait_event_interruptible(dev->wait_data,
7214 +- hdpvr_get_next_buffer(dev)))
7215 ++ !list_empty_careful(&dev->rec_buff_list)))
7216 + return -ERESTARTSYS;
7217 + }
7218 +
7219 +@@ -465,10 +465,17 @@ static ssize_t hdpvr_read(struct file *file, char __user *buffer, size_t count,
7220 + goto err;
7221 + }
7222 + if (!err) {
7223 +- v4l2_dbg(MSG_INFO, hdpvr_debug, &dev->v4l2_dev,
7224 +- "timeout: restart streaming\n");
7225 ++ v4l2_info(&dev->v4l2_dev,
7226 ++ "timeout: restart streaming\n");
7227 ++ mutex_lock(&dev->io_mutex);
7228 + hdpvr_stop_streaming(dev);
7229 +- msecs_to_jiffies(4000);
7230 ++ mutex_unlock(&dev->io_mutex);
7231 ++ /*
7232 ++ * The FW needs about 4 seconds after streaming
7233 ++ * stopped before it is ready to restart
7234 ++ * streaming.
7235 ++ */
7236 ++ msleep(4000);
7237 + err = hdpvr_start_streaming(dev);
7238 + if (err) {
7239 + ret = err;
7240 +@@ -1133,9 +1140,7 @@ static void hdpvr_device_release(struct video_device *vdev)
7241 + struct hdpvr_device *dev = video_get_drvdata(vdev);
7242 +
7243 + hdpvr_delete(dev);
7244 +- mutex_lock(&dev->io_mutex);
7245 + flush_work(&dev->worker);
7246 +- mutex_unlock(&dev->io_mutex);
7247 +
7248 + v4l2_device_unregister(&dev->v4l2_dev);
7249 + v4l2_ctrl_handler_free(&dev->hdl);
7250 +diff --git a/drivers/media/v4l2-core/v4l2-ctrls.c b/drivers/media/v4l2-core/v4l2-ctrls.c
7251 +index 07bd2008ae4b..1ee072e939e4 100644
7252 +--- a/drivers/media/v4l2-core/v4l2-ctrls.c
7253 ++++ b/drivers/media/v4l2-core/v4l2-ctrls.c
7254 +@@ -2113,16 +2113,15 @@ struct v4l2_ctrl *v4l2_ctrl_new_custom(struct v4l2_ctrl_handler *hdl,
7255 + v4l2_ctrl_fill(cfg->id, &name, &type, &min, &max, &step,
7256 + &def, &flags);
7257 +
7258 +- is_menu = (cfg->type == V4L2_CTRL_TYPE_MENU ||
7259 +- cfg->type == V4L2_CTRL_TYPE_INTEGER_MENU);
7260 ++ is_menu = (type == V4L2_CTRL_TYPE_MENU ||
7261 ++ type == V4L2_CTRL_TYPE_INTEGER_MENU);
7262 + if (is_menu)
7263 + WARN_ON(step);
7264 + else
7265 + WARN_ON(cfg->menu_skip_mask);
7266 +- if (cfg->type == V4L2_CTRL_TYPE_MENU && qmenu == NULL)
7267 ++ if (type == V4L2_CTRL_TYPE_MENU && !qmenu) {
7268 + qmenu = v4l2_ctrl_get_menu(cfg->id);
7269 +- else if (cfg->type == V4L2_CTRL_TYPE_INTEGER_MENU &&
7270 +- qmenu_int == NULL) {
7271 ++ } else if (type == V4L2_CTRL_TYPE_INTEGER_MENU && !qmenu_int) {
7272 + handler_set_err(hdl, -EINVAL);
7273 + return NULL;
7274 + }
7275 +diff --git a/drivers/memstick/core/memstick.c b/drivers/memstick/core/memstick.c
7276 +index 1246d69ba187..b1564cacd19e 100644
7277 +--- a/drivers/memstick/core/memstick.c
7278 ++++ b/drivers/memstick/core/memstick.c
7279 +@@ -629,13 +629,18 @@ static int __init memstick_init(void)
7280 + return -ENOMEM;
7281 +
7282 + rc = bus_register(&memstick_bus_type);
7283 +- if (!rc)
7284 +- rc = class_register(&memstick_host_class);
7285 ++ if (rc)
7286 ++ goto error_destroy_workqueue;
7287 +
7288 +- if (!rc)
7289 +- return 0;
7290 ++ rc = class_register(&memstick_host_class);
7291 ++ if (rc)
7292 ++ goto error_bus_unregister;
7293 ++
7294 ++ return 0;
7295 +
7296 ++error_bus_unregister:
7297 + bus_unregister(&memstick_bus_type);
7298 ++error_destroy_workqueue:
7299 + destroy_workqueue(workqueue);
7300 +
7301 + return rc;
7302 +diff --git a/drivers/mfd/arizona-core.c b/drivers/mfd/arizona-core.c
7303 +index 8d46e3ad9529..d8e3184bd27c 100644
7304 +--- a/drivers/mfd/arizona-core.c
7305 ++++ b/drivers/mfd/arizona-core.c
7306 +@@ -1029,7 +1029,7 @@ int arizona_dev_init(struct arizona *arizona)
7307 + unsigned int reg, val, mask;
7308 + int (*apply_patch)(struct arizona *) = NULL;
7309 + const struct mfd_cell *subdevs = NULL;
7310 +- int n_subdevs, ret, i;
7311 ++ int n_subdevs = 0, ret, i;
7312 +
7313 + dev_set_drvdata(arizona->dev, arizona);
7314 + mutex_init(&arizona->clk_lock);
7315 +diff --git a/drivers/mfd/hi655x-pmic.c b/drivers/mfd/hi655x-pmic.c
7316 +index 96c07fa1802a..6693f74aa6ab 100644
7317 +--- a/drivers/mfd/hi655x-pmic.c
7318 ++++ b/drivers/mfd/hi655x-pmic.c
7319 +@@ -112,6 +112,8 @@ static int hi655x_pmic_probe(struct platform_device *pdev)
7320 +
7321 + pmic->regmap = devm_regmap_init_mmio_clk(dev, NULL, base,
7322 + &hi655x_regmap_config);
7323 ++ if (IS_ERR(pmic->regmap))
7324 ++ return PTR_ERR(pmic->regmap);
7325 +
7326 + regmap_read(pmic->regmap, HI655X_BUS_ADDR(HI655X_VER_REG), &pmic->ver);
7327 + if ((pmic->ver < PMU_VER_START) || (pmic->ver > PMU_VER_END)) {
7328 +diff --git a/drivers/mfd/mfd-core.c b/drivers/mfd/mfd-core.c
7329 +index c57e407020f1..5c8ed2150c8b 100644
7330 +--- a/drivers/mfd/mfd-core.c
7331 ++++ b/drivers/mfd/mfd-core.c
7332 +@@ -179,6 +179,7 @@ static int mfd_add_device(struct device *parent, int id,
7333 + for_each_child_of_node(parent->of_node, np) {
7334 + if (of_device_is_compatible(np, cell->of_compatible)) {
7335 + pdev->dev.of_node = np;
7336 ++ pdev->dev.fwnode = &np->fwnode;
7337 + break;
7338 + }
7339 + }
7340 +diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
7341 +index 8536a75f32e3..11a0e84d3d7c 100644
7342 +--- a/drivers/net/bonding/bond_main.c
7343 ++++ b/drivers/net/bonding/bond_main.c
7344 +@@ -3817,8 +3817,8 @@ static u32 bond_rr_gen_slave_id(struct bonding *bond)
7345 + static int bond_xmit_roundrobin(struct sk_buff *skb, struct net_device *bond_dev)
7346 + {
7347 + struct bonding *bond = netdev_priv(bond_dev);
7348 +- struct iphdr *iph = ip_hdr(skb);
7349 + struct slave *slave;
7350 ++ int slave_cnt;
7351 + u32 slave_id;
7352 +
7353 + /* Start with the curr_active_slave that joined the bond as the
7354 +@@ -3827,23 +3827,32 @@ static int bond_xmit_roundrobin(struct sk_buff *skb, struct net_device *bond_dev
7355 + * send the join/membership reports. The curr_active_slave found
7356 + * will send all of this type of traffic.
7357 + */
7358 +- if (iph->protocol == IPPROTO_IGMP && skb->protocol == htons(ETH_P_IP)) {
7359 +- slave = rcu_dereference(bond->curr_active_slave);
7360 +- if (slave)
7361 +- bond_dev_queue_xmit(bond, skb, slave->dev);
7362 +- else
7363 +- bond_xmit_slave_id(bond, skb, 0);
7364 +- } else {
7365 +- int slave_cnt = ACCESS_ONCE(bond->slave_cnt);
7366 ++ if (skb->protocol == htons(ETH_P_IP)) {
7367 ++ int noff = skb_network_offset(skb);
7368 ++ struct iphdr *iph;
7369 +
7370 +- if (likely(slave_cnt)) {
7371 +- slave_id = bond_rr_gen_slave_id(bond);
7372 +- bond_xmit_slave_id(bond, skb, slave_id % slave_cnt);
7373 +- } else {
7374 +- bond_tx_drop(bond_dev, skb);
7375 ++ if (unlikely(!pskb_may_pull(skb, noff + sizeof(*iph))))
7376 ++ goto non_igmp;
7377 ++
7378 ++ iph = ip_hdr(skb);
7379 ++ if (iph->protocol == IPPROTO_IGMP) {
7380 ++ slave = rcu_dereference(bond->curr_active_slave);
7381 ++ if (slave)
7382 ++ bond_dev_queue_xmit(bond, skb, slave->dev);
7383 ++ else
7384 ++ bond_xmit_slave_id(bond, skb, 0);
7385 ++ return NETDEV_TX_OK;
7386 + }
7387 + }
7388 +
7389 ++non_igmp:
7390 ++ slave_cnt = ACCESS_ONCE(bond->slave_cnt);
7391 ++ if (likely(slave_cnt)) {
7392 ++ slave_id = bond_rr_gen_slave_id(bond);
7393 ++ bond_xmit_slave_id(bond, skb, slave_id % slave_cnt);
7394 ++ } else {
7395 ++ bond_tx_drop(bond_dev, skb);
7396 ++ }
7397 + return NETDEV_TX_OK;
7398 + }
7399 +
7400 +diff --git a/drivers/net/caif/caif_hsi.c b/drivers/net/caif/caif_hsi.c
7401 +index 438966bf51c2..60c6a60da7c4 100644
7402 +--- a/drivers/net/caif/caif_hsi.c
7403 ++++ b/drivers/net/caif/caif_hsi.c
7404 +@@ -1462,7 +1462,7 @@ static void __exit cfhsi_exit_module(void)
7405 + rtnl_lock();
7406 + list_for_each_safe(list_node, n, &cfhsi_list) {
7407 + cfhsi = list_entry(list_node, struct cfhsi, list);
7408 +- unregister_netdev(cfhsi->ndev);
7409 ++ unregister_netdevice(cfhsi->ndev);
7410 + }
7411 + rtnl_unlock();
7412 + }
7413 +diff --git a/drivers/net/dsa/mv88e6xxx/chip.c b/drivers/net/dsa/mv88e6xxx/chip.c
7414 +index 086603de1859..0fff1502267a 100644
7415 +--- a/drivers/net/dsa/mv88e6xxx/chip.c
7416 ++++ b/drivers/net/dsa/mv88e6xxx/chip.c
7417 +@@ -4044,6 +4044,8 @@ static int mv88e6xxx_probe(struct mdio_device *mdiodev)
7418 + goto out_g1_irq;
7419 + }
7420 + }
7421 ++ if (chip->reset)
7422 ++ usleep_range(1000, 2000);
7423 +
7424 + err = mv88e6xxx_mdios_register(chip, np);
7425 + if (err)
7426 +diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c
7427 +index 8498a357d389..64828d1438ab 100644
7428 +--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c
7429 ++++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c
7430 +@@ -286,6 +286,9 @@ int bnx2x_tx_int(struct bnx2x *bp, struct bnx2x_fp_txdata *txdata)
7431 + hw_cons = le16_to_cpu(*txdata->tx_cons_sb);
7432 + sw_cons = txdata->tx_pkt_cons;
7433 +
7434 ++ /* Ensure subsequent loads occur after hw_cons */
7435 ++ smp_rmb();
7436 ++
7437 + while (sw_cons != hw_cons) {
7438 + u16 pkt_cons;
7439 +
7440 +@@ -3856,9 +3859,12 @@ netdev_tx_t bnx2x_start_xmit(struct sk_buff *skb, struct net_device *dev)
7441 +
7442 + if (unlikely(skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP)) {
7443 + if (!(bp->flags & TX_TIMESTAMPING_EN)) {
7444 ++ bp->eth_stats.ptp_skip_tx_ts++;
7445 + BNX2X_ERR("Tx timestamping was not enabled, this packet will not be timestamped\n");
7446 + } else if (bp->ptp_tx_skb) {
7447 +- BNX2X_ERR("The device supports only a single outstanding packet to timestamp, this packet will not be timestamped\n");
7448 ++ bp->eth_stats.ptp_skip_tx_ts++;
7449 ++ dev_err_once(&bp->dev->dev,
7450 ++ "Device supports only a single outstanding packet to timestamp, this packet won't be timestamped\n");
7451 + } else {
7452 + skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS;
7453 + /* schedule check for Tx timestamp */
7454 +diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_ethtool.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_ethtool.c
7455 +index 65bc1929d1a8..8edac67130ff 100644
7456 +--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_ethtool.c
7457 ++++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_ethtool.c
7458 +@@ -182,7 +182,9 @@ static const struct {
7459 + { STATS_OFFSET32(driver_filtered_tx_pkt),
7460 + 4, false, "driver_filtered_tx_pkt" },
7461 + { STATS_OFFSET32(eee_tx_lpi),
7462 +- 4, true, "Tx LPI entry count"}
7463 ++ 4, true, "Tx LPI entry count"},
7464 ++ { STATS_OFFSET32(ptp_skip_tx_ts),
7465 ++ 4, false, "ptp_skipped_tx_tstamp" },
7466 + };
7467 +
7468 + #define BNX2X_NUM_STATS ARRAY_SIZE(bnx2x_stats_arr)
7469 +diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
7470 +index 41ac9a2bc153..53fa4f88ed4d 100644
7471 +--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
7472 ++++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
7473 +@@ -15264,11 +15264,24 @@ static void bnx2x_ptp_task(struct work_struct *work)
7474 + u32 val_seq;
7475 + u64 timestamp, ns;
7476 + struct skb_shared_hwtstamps shhwtstamps;
7477 ++ bool bail = true;
7478 ++ int i;
7479 ++
7480 ++ /* FW may take a while to complete timestamping; try a bit and if it's
7481 ++ * still not complete, may indicate an error state - bail out then.
7482 ++ */
7483 ++ for (i = 0; i < 10; i++) {
7484 ++ /* Read Tx timestamp registers */
7485 ++ val_seq = REG_RD(bp, port ? NIG_REG_P1_TLLH_PTP_BUF_SEQID :
7486 ++ NIG_REG_P0_TLLH_PTP_BUF_SEQID);
7487 ++ if (val_seq & 0x10000) {
7488 ++ bail = false;
7489 ++ break;
7490 ++ }
7491 ++ msleep(1 << i);
7492 ++ }
7493 +
7494 +- /* Read Tx timestamp registers */
7495 +- val_seq = REG_RD(bp, port ? NIG_REG_P1_TLLH_PTP_BUF_SEQID :
7496 +- NIG_REG_P0_TLLH_PTP_BUF_SEQID);
7497 +- if (val_seq & 0x10000) {
7498 ++ if (!bail) {
7499 + /* There is a valid timestamp value */
7500 + timestamp = REG_RD(bp, port ? NIG_REG_P1_TLLH_PTP_BUF_TS_MSB :
7501 + NIG_REG_P0_TLLH_PTP_BUF_TS_MSB);
7502 +@@ -15283,16 +15296,18 @@ static void bnx2x_ptp_task(struct work_struct *work)
7503 + memset(&shhwtstamps, 0, sizeof(shhwtstamps));
7504 + shhwtstamps.hwtstamp = ns_to_ktime(ns);
7505 + skb_tstamp_tx(bp->ptp_tx_skb, &shhwtstamps);
7506 +- dev_kfree_skb_any(bp->ptp_tx_skb);
7507 +- bp->ptp_tx_skb = NULL;
7508 +
7509 + DP(BNX2X_MSG_PTP, "Tx timestamp, timestamp cycles = %llu, ns = %llu\n",
7510 + timestamp, ns);
7511 + } else {
7512 +- DP(BNX2X_MSG_PTP, "There is no valid Tx timestamp yet\n");
7513 +- /* Reschedule to keep checking for a valid timestamp value */
7514 +- schedule_work(&bp->ptp_task);
7515 ++ DP(BNX2X_MSG_PTP,
7516 ++ "Tx timestamp is not recorded (register read=%u)\n",
7517 ++ val_seq);
7518 ++ bp->eth_stats.ptp_skip_tx_ts++;
7519 + }
7520 ++
7521 ++ dev_kfree_skb_any(bp->ptp_tx_skb);
7522 ++ bp->ptp_tx_skb = NULL;
7523 + }
7524 +
7525 + void bnx2x_set_rx_ts(struct bnx2x *bp, struct sk_buff *skb)
7526 +diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_stats.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_stats.h
7527 +index b2644ed13d06..d55e63692cf3 100644
7528 +--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_stats.h
7529 ++++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_stats.h
7530 +@@ -207,6 +207,9 @@ struct bnx2x_eth_stats {
7531 + u32 driver_filtered_tx_pkt;
7532 + /* src: Clear-on-Read register; Will not survive PMF Migration */
7533 + u32 eee_tx_lpi;
7534 ++
7535 ++ /* PTP */
7536 ++ u32 ptp_skip_tx_ts;
7537 + };
7538 +
7539 + struct bnx2x_eth_q_stats {
7540 +diff --git a/drivers/net/ethernet/broadcom/genet/bcmgenet.c b/drivers/net/ethernet/broadcom/genet/bcmgenet.c
7541 +index 9cebca896913..d857df8ebdb4 100644
7542 +--- a/drivers/net/ethernet/broadcom/genet/bcmgenet.c
7543 ++++ b/drivers/net/ethernet/broadcom/genet/bcmgenet.c
7544 +@@ -3088,39 +3088,42 @@ static void bcmgenet_timeout(struct net_device *dev)
7545 + netif_tx_wake_all_queues(dev);
7546 + }
7547 +
7548 +-#define MAX_MC_COUNT 16
7549 ++#define MAX_MDF_FILTER 17
7550 +
7551 + static inline void bcmgenet_set_mdf_addr(struct bcmgenet_priv *priv,
7552 + unsigned char *addr,
7553 +- int *i,
7554 +- int *mc)
7555 ++ int *i)
7556 + {
7557 +- u32 reg;
7558 +-
7559 + bcmgenet_umac_writel(priv, addr[0] << 8 | addr[1],
7560 + UMAC_MDF_ADDR + (*i * 4));
7561 + bcmgenet_umac_writel(priv, addr[2] << 24 | addr[3] << 16 |
7562 + addr[4] << 8 | addr[5],
7563 + UMAC_MDF_ADDR + ((*i + 1) * 4));
7564 +- reg = bcmgenet_umac_readl(priv, UMAC_MDF_CTRL);
7565 +- reg |= (1 << (MAX_MC_COUNT - *mc));
7566 +- bcmgenet_umac_writel(priv, reg, UMAC_MDF_CTRL);
7567 + *i += 2;
7568 +- (*mc)++;
7569 + }
7570 +
7571 + static void bcmgenet_set_rx_mode(struct net_device *dev)
7572 + {
7573 + struct bcmgenet_priv *priv = netdev_priv(dev);
7574 + struct netdev_hw_addr *ha;
7575 +- int i, mc;
7576 ++ int i, nfilter;
7577 + u32 reg;
7578 +
7579 + netif_dbg(priv, hw, dev, "%s: %08X\n", __func__, dev->flags);
7580 +
7581 +- /* Promiscuous mode */
7582 ++ /* Number of filters needed */
7583 ++ nfilter = netdev_uc_count(dev) + netdev_mc_count(dev) + 2;
7584 ++
7585 ++ /*
7586 ++ * Turn on promicuous mode for three scenarios
7587 ++ * 1. IFF_PROMISC flag is set
7588 ++ * 2. IFF_ALLMULTI flag is set
7589 ++ * 3. The number of filters needed exceeds the number filters
7590 ++ * supported by the hardware.
7591 ++ */
7592 + reg = bcmgenet_umac_readl(priv, UMAC_CMD);
7593 +- if (dev->flags & IFF_PROMISC) {
7594 ++ if ((dev->flags & (IFF_PROMISC | IFF_ALLMULTI)) ||
7595 ++ (nfilter > MAX_MDF_FILTER)) {
7596 + reg |= CMD_PROMISC;
7597 + bcmgenet_umac_writel(priv, reg, UMAC_CMD);
7598 + bcmgenet_umac_writel(priv, 0, UMAC_MDF_CTRL);
7599 +@@ -3130,32 +3133,24 @@ static void bcmgenet_set_rx_mode(struct net_device *dev)
7600 + bcmgenet_umac_writel(priv, reg, UMAC_CMD);
7601 + }
7602 +
7603 +- /* UniMac doesn't support ALLMULTI */
7604 +- if (dev->flags & IFF_ALLMULTI) {
7605 +- netdev_warn(dev, "ALLMULTI is not supported\n");
7606 +- return;
7607 +- }
7608 +-
7609 + /* update MDF filter */
7610 + i = 0;
7611 +- mc = 0;
7612 + /* Broadcast */
7613 +- bcmgenet_set_mdf_addr(priv, dev->broadcast, &i, &mc);
7614 ++ bcmgenet_set_mdf_addr(priv, dev->broadcast, &i);
7615 + /* my own address.*/
7616 +- bcmgenet_set_mdf_addr(priv, dev->dev_addr, &i, &mc);
7617 +- /* Unicast list*/
7618 +- if (netdev_uc_count(dev) > (MAX_MC_COUNT - mc))
7619 +- return;
7620 ++ bcmgenet_set_mdf_addr(priv, dev->dev_addr, &i);
7621 +
7622 +- if (!netdev_uc_empty(dev))
7623 +- netdev_for_each_uc_addr(ha, dev)
7624 +- bcmgenet_set_mdf_addr(priv, ha->addr, &i, &mc);
7625 +- /* Multicast */
7626 +- if (netdev_mc_empty(dev) || netdev_mc_count(dev) >= (MAX_MC_COUNT - mc))
7627 +- return;
7628 ++ /* Unicast */
7629 ++ netdev_for_each_uc_addr(ha, dev)
7630 ++ bcmgenet_set_mdf_addr(priv, ha->addr, &i);
7631 +
7632 ++ /* Multicast */
7633 + netdev_for_each_mc_addr(ha, dev)
7634 +- bcmgenet_set_mdf_addr(priv, ha->addr, &i, &mc);
7635 ++ bcmgenet_set_mdf_addr(priv, ha->addr, &i);
7636 ++
7637 ++ /* Enable filters */
7638 ++ reg = GENMASK(MAX_MDF_FILTER - 1, MAX_MDF_FILTER - nfilter);
7639 ++ bcmgenet_umac_writel(priv, reg, UMAC_MDF_CTRL);
7640 + }
7641 +
7642 + /* Set the hardware MAC address. */
7643 +diff --git a/drivers/net/ethernet/freescale/fec_main.c b/drivers/net/ethernet/freescale/fec_main.c
7644 +index 98cd53d380f7..0ae6532b02e0 100644
7645 +--- a/drivers/net/ethernet/freescale/fec_main.c
7646 ++++ b/drivers/net/ethernet/freescale/fec_main.c
7647 +@@ -1690,10 +1690,10 @@ static void fec_get_mac(struct net_device *ndev)
7648 + */
7649 + if (!is_valid_ether_addr(iap)) {
7650 + /* Report it and use a random ethernet address instead */
7651 +- netdev_err(ndev, "Invalid MAC address: %pM\n", iap);
7652 ++ dev_err(&fep->pdev->dev, "Invalid MAC address: %pM\n", iap);
7653 + eth_hw_addr_random(ndev);
7654 +- netdev_info(ndev, "Using random MAC address: %pM\n",
7655 +- ndev->dev_addr);
7656 ++ dev_info(&fep->pdev->dev, "Using random MAC address: %pM\n",
7657 ++ ndev->dev_addr);
7658 + return;
7659 + }
7660 +
7661 +diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
7662 +index 654aad6e748b..86523e8993cb 100644
7663 +--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
7664 ++++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
7665 +@@ -619,8 +619,7 @@ static u8 *hclge_comm_get_strings(u32 stringset,
7666 + return buff;
7667 +
7668 + for (i = 0; i < size; i++) {
7669 +- snprintf(buff, ETH_GSTRING_LEN,
7670 +- strs[i].desc);
7671 ++ snprintf(buff, ETH_GSTRING_LEN, "%s", strs[i].desc);
7672 + buff = buff + ETH_GSTRING_LEN;
7673 + }
7674 +
7675 +diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_tm.c b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_tm.c
7676 +index 73a75d7cc551..55228b91d80b 100644
7677 +--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_tm.c
7678 ++++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_tm.c
7679 +@@ -57,7 +57,8 @@ static int hclge_shaper_para_calc(u32 ir, u8 shaper_level,
7680 + u32 tick;
7681 +
7682 + /* Calc tick */
7683 +- if (shaper_level >= HCLGE_SHAPER_LVL_CNT)
7684 ++ if (shaper_level >= HCLGE_SHAPER_LVL_CNT ||
7685 ++ ir > HCLGE_ETHER_MAX_RATE)
7686 + return -EINVAL;
7687 +
7688 + tick = tick_array[shaper_level];
7689 +@@ -893,6 +894,9 @@ static int hclge_tm_schd_mode_vnet_base_cfg(struct hclge_vport *vport)
7690 + int ret;
7691 + u8 i;
7692 +
7693 ++ if (vport->vport_id >= HNAE3_MAX_TC)
7694 ++ return -EINVAL;
7695 ++
7696 + ret = hclge_tm_pri_schd_mode_cfg(hdev, vport->vport_id);
7697 + if (ret)
7698 + return ret;
7699 +diff --git a/drivers/net/ethernet/intel/i40evf/i40e_txrx.c b/drivers/net/ethernet/intel/i40evf/i40e_txrx.c
7700 +index 7368b0dc3af8..4afdabbe95e8 100644
7701 +--- a/drivers/net/ethernet/intel/i40evf/i40e_txrx.c
7702 ++++ b/drivers/net/ethernet/intel/i40evf/i40e_txrx.c
7703 +@@ -1117,7 +1117,7 @@ static struct sk_buff *i40e_construct_skb(struct i40e_ring *rx_ring,
7704 + struct i40e_rx_buffer *rx_buffer,
7705 + unsigned int size)
7706 + {
7707 +- void *va = page_address(rx_buffer->page) + rx_buffer->page_offset;
7708 ++ void *va;
7709 + #if (PAGE_SIZE < 8192)
7710 + unsigned int truesize = i40e_rx_pg_size(rx_ring) / 2;
7711 + #else
7712 +@@ -1127,6 +1127,7 @@ static struct sk_buff *i40e_construct_skb(struct i40e_ring *rx_ring,
7713 + struct sk_buff *skb;
7714 +
7715 + /* prefetch first cache line of first page */
7716 ++ va = page_address(rx_buffer->page) + rx_buffer->page_offset;
7717 + prefetch(va);
7718 + #if L1_CACHE_BYTES < 128
7719 + prefetch(va + L1_CACHE_BYTES);
7720 +@@ -1181,7 +1182,7 @@ static struct sk_buff *i40e_build_skb(struct i40e_ring *rx_ring,
7721 + struct i40e_rx_buffer *rx_buffer,
7722 + unsigned int size)
7723 + {
7724 +- void *va = page_address(rx_buffer->page) + rx_buffer->page_offset;
7725 ++ void *va;
7726 + #if (PAGE_SIZE < 8192)
7727 + unsigned int truesize = i40e_rx_pg_size(rx_ring) / 2;
7728 + #else
7729 +@@ -1191,6 +1192,7 @@ static struct sk_buff *i40e_build_skb(struct i40e_ring *rx_ring,
7730 + struct sk_buff *skb;
7731 +
7732 + /* prefetch first cache line of first page */
7733 ++ va = page_address(rx_buffer->page) + rx_buffer->page_offset;
7734 + prefetch(va);
7735 + #if L1_CACHE_BYTES < 128
7736 + prefetch(va + L1_CACHE_BYTES);
7737 +diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ethtool.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ethtool.c
7738 +index c3e7a8191128..f7e68083200c 100644
7739 +--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ethtool.c
7740 ++++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ethtool.c
7741 +@@ -3237,7 +3237,8 @@ static int ixgbe_get_module_info(struct net_device *dev,
7742 + page_swap = true;
7743 + }
7744 +
7745 +- if (sff8472_rev == IXGBE_SFF_SFF_8472_UNSUP || page_swap) {
7746 ++ if (sff8472_rev == IXGBE_SFF_SFF_8472_UNSUP || page_swap ||
7747 ++ !(addr_mode & IXGBE_SFF_DDM_IMPLEMENTED)) {
7748 + /* We have a SFP, but it does not support SFF-8472 */
7749 + modinfo->type = ETH_MODULE_SFF_8079;
7750 + modinfo->eeprom_len = ETH_MODULE_SFF_8079_LEN;
7751 +diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_phy.h b/drivers/net/ethernet/intel/ixgbe/ixgbe_phy.h
7752 +index b0cac961df3b..94df1d99be95 100644
7753 +--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_phy.h
7754 ++++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_phy.h
7755 +@@ -70,6 +70,7 @@
7756 + #define IXGBE_SFF_SOFT_RS_SELECT_10G 0x8
7757 + #define IXGBE_SFF_SOFT_RS_SELECT_1G 0x0
7758 + #define IXGBE_SFF_ADDRESSING_MODE 0x4
7759 ++#define IXGBE_SFF_DDM_IMPLEMENTED 0x40
7760 + #define IXGBE_SFF_QSFP_DA_ACTIVE_CABLE 0x1
7761 + #define IXGBE_SFF_QSFP_DA_PASSIVE_CABLE 0x8
7762 + #define IXGBE_SFF_QSFP_CONNECTOR_NOT_SEPARABLE 0x23
7763 +diff --git a/drivers/net/ethernet/marvell/mvmdio.c b/drivers/net/ethernet/marvell/mvmdio.c
7764 +index 0495487f7b42..b6ff143c9cff 100644
7765 +--- a/drivers/net/ethernet/marvell/mvmdio.c
7766 ++++ b/drivers/net/ethernet/marvell/mvmdio.c
7767 +@@ -64,7 +64,7 @@
7768 +
7769 + struct orion_mdio_dev {
7770 + void __iomem *regs;
7771 +- struct clk *clk[3];
7772 ++ struct clk *clk[4];
7773 + /*
7774 + * If we have access to the error interrupt pin (which is
7775 + * somewhat misnamed as it not only reflects internal errors
7776 +@@ -321,6 +321,10 @@ static int orion_mdio_probe(struct platform_device *pdev)
7777 +
7778 + for (i = 0; i < ARRAY_SIZE(dev->clk); i++) {
7779 + dev->clk[i] = of_clk_get(pdev->dev.of_node, i);
7780 ++ if (PTR_ERR(dev->clk[i]) == -EPROBE_DEFER) {
7781 ++ ret = -EPROBE_DEFER;
7782 ++ goto out_clk;
7783 ++ }
7784 + if (IS_ERR(dev->clk[i]))
7785 + break;
7786 + clk_prepare_enable(dev->clk[i]);
7787 +@@ -365,6 +369,7 @@ out_mdio:
7788 + if (dev->err_interrupt > 0)
7789 + writel(0, dev->regs + MVMDIO_ERR_INT_MASK);
7790 +
7791 ++out_clk:
7792 + for (i = 0; i < ARRAY_SIZE(dev->clk); i++) {
7793 + if (IS_ERR(dev->clk[i]))
7794 + break;
7795 +diff --git a/drivers/net/ethernet/marvell/sky2.c b/drivers/net/ethernet/marvell/sky2.c
7796 +index cf6f58889038..7b239af6cc04 100644
7797 +--- a/drivers/net/ethernet/marvell/sky2.c
7798 ++++ b/drivers/net/ethernet/marvell/sky2.c
7799 +@@ -4947,6 +4947,13 @@ static const struct dmi_system_id msi_blacklist[] = {
7800 + DMI_MATCH(DMI_PRODUCT_NAME, "P-79"),
7801 + },
7802 + },
7803 ++ {
7804 ++ .ident = "ASUS P6T",
7805 ++ .matches = {
7806 ++ DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."),
7807 ++ DMI_MATCH(DMI_BOARD_NAME, "P6T"),
7808 ++ },
7809 ++ },
7810 + {}
7811 + };
7812 +
7813 +diff --git a/drivers/net/ethernet/qlogic/qed/qed_dev.c b/drivers/net/ethernet/qlogic/qed/qed_dev.c
7814 +index 410528e7d927..c4e8bf0773fe 100644
7815 +--- a/drivers/net/ethernet/qlogic/qed/qed_dev.c
7816 ++++ b/drivers/net/ethernet/qlogic/qed/qed_dev.c
7817 +@@ -2947,6 +2947,7 @@ static int qed_get_dev_info(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt)
7818 + static int qed_hw_prepare_single(struct qed_hwfn *p_hwfn,
7819 + void __iomem *p_regview,
7820 + void __iomem *p_doorbells,
7821 ++ u64 db_phys_addr,
7822 + enum qed_pci_personality personality)
7823 + {
7824 + int rc = 0;
7825 +@@ -2954,6 +2955,7 @@ static int qed_hw_prepare_single(struct qed_hwfn *p_hwfn,
7826 + /* Split PCI bars evenly between hwfns */
7827 + p_hwfn->regview = p_regview;
7828 + p_hwfn->doorbells = p_doorbells;
7829 ++ p_hwfn->db_phys_addr = db_phys_addr;
7830 +
7831 + if (IS_VF(p_hwfn->cdev))
7832 + return qed_vf_hw_prepare(p_hwfn);
7833 +@@ -3036,7 +3038,9 @@ int qed_hw_prepare(struct qed_dev *cdev,
7834 + /* Initialize the first hwfn - will learn number of hwfns */
7835 + rc = qed_hw_prepare_single(p_hwfn,
7836 + cdev->regview,
7837 +- cdev->doorbells, personality);
7838 ++ cdev->doorbells,
7839 ++ cdev->db_phys_addr,
7840 ++ personality);
7841 + if (rc)
7842 + return rc;
7843 +
7844 +@@ -3045,22 +3049,25 @@ int qed_hw_prepare(struct qed_dev *cdev,
7845 + /* Initialize the rest of the hwfns */
7846 + if (cdev->num_hwfns > 1) {
7847 + void __iomem *p_regview, *p_doorbell;
7848 +- u8 __iomem *addr;
7849 ++ u64 db_phys_addr;
7850 ++ u32 offset;
7851 +
7852 + /* adjust bar offset for second engine */
7853 +- addr = cdev->regview +
7854 +- qed_hw_bar_size(p_hwfn, p_hwfn->p_main_ptt,
7855 +- BAR_ID_0) / 2;
7856 +- p_regview = addr;
7857 ++ offset = qed_hw_bar_size(p_hwfn, p_hwfn->p_main_ptt,
7858 ++ BAR_ID_0) / 2;
7859 ++ p_regview = cdev->regview + offset;
7860 +
7861 +- addr = cdev->doorbells +
7862 +- qed_hw_bar_size(p_hwfn, p_hwfn->p_main_ptt,
7863 +- BAR_ID_1) / 2;
7864 +- p_doorbell = addr;
7865 ++ offset = qed_hw_bar_size(p_hwfn, p_hwfn->p_main_ptt,
7866 ++ BAR_ID_1) / 2;
7867 ++
7868 ++ p_doorbell = cdev->doorbells + offset;
7869 ++
7870 ++ db_phys_addr = cdev->db_phys_addr + offset;
7871 +
7872 + /* prepare second hw function */
7873 + rc = qed_hw_prepare_single(&cdev->hwfns[1], p_regview,
7874 +- p_doorbell, personality);
7875 ++ p_doorbell, db_phys_addr,
7876 ++ personality);
7877 +
7878 + /* in case of error, need to free the previously
7879 + * initiliazed hwfn 0.
7880 +diff --git a/drivers/net/ethernet/qlogic/qed/qed_rdma.c b/drivers/net/ethernet/qlogic/qed/qed_rdma.c
7881 +index 1b6554866138..1e13dea66989 100644
7882 +--- a/drivers/net/ethernet/qlogic/qed/qed_rdma.c
7883 ++++ b/drivers/net/ethernet/qlogic/qed/qed_rdma.c
7884 +@@ -753,7 +753,7 @@ static int qed_rdma_add_user(void *rdma_cxt,
7885 + dpi_start_offset +
7886 + ((out_params->dpi) * p_hwfn->dpi_size));
7887 +
7888 +- out_params->dpi_phys_addr = p_hwfn->cdev->db_phys_addr +
7889 ++ out_params->dpi_phys_addr = p_hwfn->db_phys_addr +
7890 + dpi_start_offset +
7891 + ((out_params->dpi) * p_hwfn->dpi_size);
7892 +
7893 +diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac1000_core.c b/drivers/net/ethernet/stmicro/stmmac/dwmac1000_core.c
7894 +index 540d21786a43..08dd6a06ac58 100644
7895 +--- a/drivers/net/ethernet/stmicro/stmmac/dwmac1000_core.c
7896 ++++ b/drivers/net/ethernet/stmicro/stmmac/dwmac1000_core.c
7897 +@@ -217,6 +217,12 @@ static void dwmac1000_set_filter(struct mac_device_info *hw,
7898 + GMAC_ADDR_LOW(reg));
7899 + reg++;
7900 + }
7901 ++
7902 ++ while (reg <= perfect_addr_number) {
7903 ++ writel(0, ioaddr + GMAC_ADDR_HIGH(reg));
7904 ++ writel(0, ioaddr + GMAC_ADDR_LOW(reg));
7905 ++ reg++;
7906 ++ }
7907 + }
7908 +
7909 + #ifdef FRAME_FILTER_DEBUG
7910 +diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c b/drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c
7911 +index 55ae14a6bb8c..8445af580cb6 100644
7912 +--- a/drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c
7913 ++++ b/drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c
7914 +@@ -443,14 +443,20 @@ static void dwmac4_set_filter(struct mac_device_info *hw,
7915 + * are required
7916 + */
7917 + value |= GMAC_PACKET_FILTER_PR;
7918 +- } else if (!netdev_uc_empty(dev)) {
7919 +- int reg = 1;
7920 ++ } else {
7921 + struct netdev_hw_addr *ha;
7922 ++ int reg = 1;
7923 +
7924 + netdev_for_each_uc_addr(ha, dev) {
7925 + dwmac4_set_umac_addr(hw, ha->addr, reg);
7926 + reg++;
7927 + }
7928 ++
7929 ++ while (reg <= GMAC_MAX_PERFECT_ADDRESSES) {
7930 ++ writel(0, ioaddr + GMAC_ADDR_HIGH(reg));
7931 ++ writel(0, ioaddr + GMAC_ADDR_LOW(reg));
7932 ++ reg++;
7933 ++ }
7934 + }
7935 +
7936 + writel(value, ioaddr + GMAC_PACKET_FILTER);
7937 +@@ -468,8 +474,9 @@ static void dwmac4_flow_ctrl(struct mac_device_info *hw, unsigned int duplex,
7938 + if (fc & FLOW_RX) {
7939 + pr_debug("\tReceive Flow-Control ON\n");
7940 + flow |= GMAC_RX_FLOW_CTRL_RFE;
7941 +- writel(flow, ioaddr + GMAC_RX_FLOW_CTRL);
7942 + }
7943 ++ writel(flow, ioaddr + GMAC_RX_FLOW_CTRL);
7944 ++
7945 + if (fc & FLOW_TX) {
7946 + pr_debug("\tTransmit Flow-Control ON\n");
7947 +
7948 +@@ -477,7 +484,7 @@ static void dwmac4_flow_ctrl(struct mac_device_info *hw, unsigned int duplex,
7949 + pr_debug("\tduplex mode: PAUSE %d\n", pause_time);
7950 +
7951 + for (queue = 0; queue < tx_cnt; queue++) {
7952 +- flow |= GMAC_TX_FLOW_CTRL_TFE;
7953 ++ flow = GMAC_TX_FLOW_CTRL_TFE;
7954 +
7955 + if (duplex)
7956 + flow |=
7957 +@@ -485,6 +492,9 @@ static void dwmac4_flow_ctrl(struct mac_device_info *hw, unsigned int duplex,
7958 +
7959 + writel(flow, ioaddr + GMAC_QX_TX_FLOW_CTRL(queue));
7960 + }
7961 ++ } else {
7962 ++ for (queue = 0; queue < tx_cnt; queue++)
7963 ++ writel(0, ioaddr + GMAC_QX_TX_FLOW_CTRL(queue));
7964 + }
7965 + }
7966 +
7967 +diff --git a/drivers/net/ethernet/xilinx/xilinx_axienet_main.c b/drivers/net/ethernet/xilinx/xilinx_axienet_main.c
7968 +index d46dc8cd1670..b481cb174b23 100644
7969 +--- a/drivers/net/ethernet/xilinx/xilinx_axienet_main.c
7970 ++++ b/drivers/net/ethernet/xilinx/xilinx_axienet_main.c
7971 +@@ -614,6 +614,10 @@ static void axienet_start_xmit_done(struct net_device *ndev)
7972 +
7973 + ndev->stats.tx_packets += packets;
7974 + ndev->stats.tx_bytes += size;
7975 ++
7976 ++ /* Matches barrier in axienet_start_xmit */
7977 ++ smp_mb();
7978 ++
7979 + netif_wake_queue(ndev);
7980 + }
7981 +
7982 +@@ -668,9 +672,19 @@ static int axienet_start_xmit(struct sk_buff *skb, struct net_device *ndev)
7983 + cur_p = &lp->tx_bd_v[lp->tx_bd_tail];
7984 +
7985 + if (axienet_check_tx_bd_space(lp, num_frag)) {
7986 +- if (!netif_queue_stopped(ndev))
7987 +- netif_stop_queue(ndev);
7988 +- return NETDEV_TX_BUSY;
7989 ++ if (netif_queue_stopped(ndev))
7990 ++ return NETDEV_TX_BUSY;
7991 ++
7992 ++ netif_stop_queue(ndev);
7993 ++
7994 ++ /* Matches barrier in axienet_start_xmit_done */
7995 ++ smp_mb();
7996 ++
7997 ++ /* Space might have just been freed - check again */
7998 ++ if (axienet_check_tx_bd_space(lp, num_frag))
7999 ++ return NETDEV_TX_BUSY;
8000 ++
8001 ++ netif_wake_queue(ndev);
8002 + }
8003 +
8004 + if (skb->ip_summed == CHECKSUM_PARTIAL) {
8005 +diff --git a/drivers/net/gtp.c b/drivers/net/gtp.c
8006 +index f38e32a7ec9c..5de4053774b8 100644
8007 +--- a/drivers/net/gtp.c
8008 ++++ b/drivers/net/gtp.c
8009 +@@ -289,16 +289,29 @@ static int gtp1u_udp_encap_recv(struct gtp_dev *gtp, struct sk_buff *skb)
8010 + return gtp_rx(pctx, skb, hdrlen, gtp->role);
8011 + }
8012 +
8013 +-static void gtp_encap_destroy(struct sock *sk)
8014 ++static void __gtp_encap_destroy(struct sock *sk)
8015 + {
8016 + struct gtp_dev *gtp;
8017 +
8018 +- gtp = rcu_dereference_sk_user_data(sk);
8019 ++ lock_sock(sk);
8020 ++ gtp = sk->sk_user_data;
8021 + if (gtp) {
8022 ++ if (gtp->sk0 == sk)
8023 ++ gtp->sk0 = NULL;
8024 ++ else
8025 ++ gtp->sk1u = NULL;
8026 + udp_sk(sk)->encap_type = 0;
8027 + rcu_assign_sk_user_data(sk, NULL);
8028 + sock_put(sk);
8029 + }
8030 ++ release_sock(sk);
8031 ++}
8032 ++
8033 ++static void gtp_encap_destroy(struct sock *sk)
8034 ++{
8035 ++ rtnl_lock();
8036 ++ __gtp_encap_destroy(sk);
8037 ++ rtnl_unlock();
8038 + }
8039 +
8040 + static void gtp_encap_disable_sock(struct sock *sk)
8041 +@@ -306,7 +319,7 @@ static void gtp_encap_disable_sock(struct sock *sk)
8042 + if (!sk)
8043 + return;
8044 +
8045 +- gtp_encap_destroy(sk);
8046 ++ __gtp_encap_destroy(sk);
8047 + }
8048 +
8049 + static void gtp_encap_disable(struct gtp_dev *gtp)
8050 +@@ -798,7 +811,8 @@ static struct sock *gtp_encap_enable_socket(int fd, int type,
8051 + goto out_sock;
8052 + }
8053 +
8054 +- if (rcu_dereference_sk_user_data(sock->sk)) {
8055 ++ lock_sock(sock->sk);
8056 ++ if (sock->sk->sk_user_data) {
8057 + sk = ERR_PTR(-EBUSY);
8058 + goto out_sock;
8059 + }
8060 +@@ -814,6 +828,7 @@ static struct sock *gtp_encap_enable_socket(int fd, int type,
8061 + setup_udp_tunnel_sock(sock_net(sock->sk), sock, &tuncfg);
8062 +
8063 + out_sock:
8064 ++ release_sock(sock->sk);
8065 + sockfd_put(sock);
8066 + return sk;
8067 + }
8068 +@@ -845,8 +860,13 @@ static int gtp_encap_enable(struct gtp_dev *gtp, struct nlattr *data[])
8069 +
8070 + if (data[IFLA_GTP_ROLE]) {
8071 + role = nla_get_u32(data[IFLA_GTP_ROLE]);
8072 +- if (role > GTP_ROLE_SGSN)
8073 ++ if (role > GTP_ROLE_SGSN) {
8074 ++ if (sk0)
8075 ++ gtp_encap_disable_sock(sk0);
8076 ++ if (sk1u)
8077 ++ gtp_encap_disable_sock(sk1u);
8078 + return -EINVAL;
8079 ++ }
8080 + }
8081 +
8082 + gtp->sk0 = sk0;
8083 +@@ -947,7 +967,7 @@ static int ipv4_pdp_add(struct gtp_dev *gtp, struct sock *sk,
8084 +
8085 + }
8086 +
8087 +- pctx = kmalloc(sizeof(struct pdp_ctx), GFP_KERNEL);
8088 ++ pctx = kmalloc(sizeof(*pctx), GFP_ATOMIC);
8089 + if (pctx == NULL)
8090 + return -ENOMEM;
8091 +
8092 +@@ -1036,6 +1056,7 @@ static int gtp_genl_new_pdp(struct sk_buff *skb, struct genl_info *info)
8093 + return -EINVAL;
8094 + }
8095 +
8096 ++ rtnl_lock();
8097 + rcu_read_lock();
8098 +
8099 + gtp = gtp_find_dev(sock_net(skb->sk), info->attrs);
8100 +@@ -1060,6 +1081,7 @@ static int gtp_genl_new_pdp(struct sk_buff *skb, struct genl_info *info)
8101 +
8102 + out_unlock:
8103 + rcu_read_unlock();
8104 ++ rtnl_unlock();
8105 + return err;
8106 + }
8107 +
8108 +@@ -1361,9 +1383,9 @@ late_initcall(gtp_init);
8109 +
8110 + static void __exit gtp_fini(void)
8111 + {
8112 +- unregister_pernet_subsys(&gtp_net_ops);
8113 + genl_unregister_family(&gtp_genl_family);
8114 + rtnl_link_unregister(&gtp_link_ops);
8115 ++ unregister_pernet_subsys(&gtp_net_ops);
8116 +
8117 + pr_info("GTP module unloaded\n");
8118 + }
8119 +diff --git a/drivers/net/macsec.c b/drivers/net/macsec.c
8120 +index 5ab1b8849c30..0c69dfbd28ef 100644
8121 +--- a/drivers/net/macsec.c
8122 ++++ b/drivers/net/macsec.c
8123 +@@ -865,6 +865,7 @@ static void macsec_reset_skb(struct sk_buff *skb, struct net_device *dev)
8124 +
8125 + static void macsec_finalize_skb(struct sk_buff *skb, u8 icv_len, u8 hdr_len)
8126 + {
8127 ++ skb->ip_summed = CHECKSUM_NONE;
8128 + memmove(skb->data + hdr_len, skb->data, 2 * ETH_ALEN);
8129 + skb_pull(skb, hdr_len);
8130 + pskb_trim_unique(skb, skb->len - icv_len);
8131 +@@ -1099,10 +1100,9 @@ static rx_handler_result_t macsec_handle_frame(struct sk_buff **pskb)
8132 + }
8133 +
8134 + skb = skb_unshare(skb, GFP_ATOMIC);
8135 +- if (!skb) {
8136 +- *pskb = NULL;
8137 ++ *pskb = skb;
8138 ++ if (!skb)
8139 + return RX_HANDLER_CONSUMED;
8140 +- }
8141 +
8142 + pulled_sci = pskb_may_pull(skb, macsec_extra_len(true));
8143 + if (!pulled_sci) {
8144 +diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c
8145 +index c433be573e0d..ed7e3c70b511 100644
8146 +--- a/drivers/net/phy/phy_device.c
8147 ++++ b/drivers/net/phy/phy_device.c
8148 +@@ -729,6 +729,9 @@ int phy_connect_direct(struct net_device *dev, struct phy_device *phydev,
8149 + {
8150 + int rc;
8151 +
8152 ++ if (!dev)
8153 ++ return -EINVAL;
8154 ++
8155 + rc = phy_attach_direct(dev, phydev, phydev->dev_flags, interface);
8156 + if (rc)
8157 + return rc;
8158 +@@ -1067,6 +1070,9 @@ struct phy_device *phy_attach(struct net_device *dev, const char *bus_id,
8159 + struct device *d;
8160 + int rc;
8161 +
8162 ++ if (!dev)
8163 ++ return ERR_PTR(-EINVAL);
8164 ++
8165 + /* Search the list of PHY devices on the mdio bus for the
8166 + * PHY with the requested name
8167 + */
8168 +diff --git a/drivers/net/phy/sfp.c b/drivers/net/phy/sfp.c
8169 +index 2dcb25aa0452..9cef89fe410d 100644
8170 +--- a/drivers/net/phy/sfp.c
8171 ++++ b/drivers/net/phy/sfp.c
8172 +@@ -115,10 +115,11 @@ struct sfp {
8173 + struct gpio_desc *gpio[GPIO_MAX];
8174 +
8175 + bool attached;
8176 ++ struct mutex st_mutex; /* Protects state */
8177 + unsigned int state;
8178 + struct delayed_work poll;
8179 + struct delayed_work timeout;
8180 +- struct mutex sm_mutex;
8181 ++ struct mutex sm_mutex; /* Protects state machine */
8182 + unsigned char sm_mod_state;
8183 + unsigned char sm_dev_state;
8184 + unsigned short sm_state;
8185 +@@ -738,6 +739,7 @@ static void sfp_check_state(struct sfp *sfp)
8186 + {
8187 + unsigned int state, i, changed;
8188 +
8189 ++ mutex_lock(&sfp->st_mutex);
8190 + state = sfp_get_state(sfp);
8191 + changed = state ^ sfp->state;
8192 + changed &= SFP_F_PRESENT | SFP_F_LOS | SFP_F_TX_FAULT;
8193 +@@ -763,6 +765,7 @@ static void sfp_check_state(struct sfp *sfp)
8194 + sfp_sm_event(sfp, state & SFP_F_LOS ?
8195 + SFP_E_LOS_HIGH : SFP_E_LOS_LOW);
8196 + rtnl_unlock();
8197 ++ mutex_unlock(&sfp->st_mutex);
8198 + }
8199 +
8200 + static irqreturn_t sfp_irq(int irq, void *data)
8201 +@@ -793,6 +796,7 @@ static struct sfp *sfp_alloc(struct device *dev)
8202 + sfp->dev = dev;
8203 +
8204 + mutex_init(&sfp->sm_mutex);
8205 ++ mutex_init(&sfp->st_mutex);
8206 + INIT_DELAYED_WORK(&sfp->poll, sfp_poll);
8207 + INIT_DELAYED_WORK(&sfp->timeout, sfp_timeout);
8208 +
8209 +diff --git a/drivers/net/usb/asix_devices.c b/drivers/net/usb/asix_devices.c
8210 +index d0c0ac0c3519..9b751d4bd327 100644
8211 +--- a/drivers/net/usb/asix_devices.c
8212 ++++ b/drivers/net/usb/asix_devices.c
8213 +@@ -238,7 +238,7 @@ static void asix_phy_reset(struct usbnet *dev, unsigned int reset_bits)
8214 + static int ax88172_bind(struct usbnet *dev, struct usb_interface *intf)
8215 + {
8216 + int ret = 0;
8217 +- u8 buf[ETH_ALEN];
8218 ++ u8 buf[ETH_ALEN] = {0};
8219 + int i;
8220 + unsigned long gpio_bits = dev->driver_info->data;
8221 +
8222 +@@ -689,7 +689,7 @@ static int asix_resume(struct usb_interface *intf)
8223 + static int ax88772_bind(struct usbnet *dev, struct usb_interface *intf)
8224 + {
8225 + int ret, i;
8226 +- u8 buf[ETH_ALEN], chipcode = 0;
8227 ++ u8 buf[ETH_ALEN] = {0}, chipcode = 0;
8228 + u32 phyid;
8229 + struct asix_common_private *priv;
8230 +
8231 +@@ -1065,7 +1065,7 @@ static const struct net_device_ops ax88178_netdev_ops = {
8232 + static int ax88178_bind(struct usbnet *dev, struct usb_interface *intf)
8233 + {
8234 + int ret;
8235 +- u8 buf[ETH_ALEN];
8236 ++ u8 buf[ETH_ALEN] = {0};
8237 +
8238 + usbnet_get_endpoints(dev,intf);
8239 +
8240 +diff --git a/drivers/net/vrf.c b/drivers/net/vrf.c
8241 +index 5c6a8ef54aec..03e4fcdfeab7 100644
8242 +--- a/drivers/net/vrf.c
8243 ++++ b/drivers/net/vrf.c
8244 +@@ -167,23 +167,29 @@ static int vrf_ip6_local_out(struct net *net, struct sock *sk,
8245 + static netdev_tx_t vrf_process_v6_outbound(struct sk_buff *skb,
8246 + struct net_device *dev)
8247 + {
8248 +- const struct ipv6hdr *iph = ipv6_hdr(skb);
8249 ++ const struct ipv6hdr *iph;
8250 + struct net *net = dev_net(skb->dev);
8251 +- struct flowi6 fl6 = {
8252 +- /* needed to match OIF rule */
8253 +- .flowi6_oif = dev->ifindex,
8254 +- .flowi6_iif = LOOPBACK_IFINDEX,
8255 +- .daddr = iph->daddr,
8256 +- .saddr = iph->saddr,
8257 +- .flowlabel = ip6_flowinfo(iph),
8258 +- .flowi6_mark = skb->mark,
8259 +- .flowi6_proto = iph->nexthdr,
8260 +- .flowi6_flags = FLOWI_FLAG_SKIP_NH_OIF,
8261 +- };
8262 ++ struct flowi6 fl6;
8263 + int ret = NET_XMIT_DROP;
8264 + struct dst_entry *dst;
8265 + struct dst_entry *dst_null = &net->ipv6.ip6_null_entry->dst;
8266 +
8267 ++ if (!pskb_may_pull(skb, ETH_HLEN + sizeof(struct ipv6hdr)))
8268 ++ goto err;
8269 ++
8270 ++ iph = ipv6_hdr(skb);
8271 ++
8272 ++ memset(&fl6, 0, sizeof(fl6));
8273 ++ /* needed to match OIF rule */
8274 ++ fl6.flowi6_oif = dev->ifindex;
8275 ++ fl6.flowi6_iif = LOOPBACK_IFINDEX;
8276 ++ fl6.daddr = iph->daddr;
8277 ++ fl6.saddr = iph->saddr;
8278 ++ fl6.flowlabel = ip6_flowinfo(iph);
8279 ++ fl6.flowi6_mark = skb->mark;
8280 ++ fl6.flowi6_proto = iph->nexthdr;
8281 ++ fl6.flowi6_flags = FLOWI_FLAG_SKIP_NH_OIF;
8282 ++
8283 + dst = ip6_route_output(net, NULL, &fl6);
8284 + if (dst == dst_null)
8285 + goto err;
8286 +@@ -239,21 +245,27 @@ static int vrf_ip_local_out(struct net *net, struct sock *sk,
8287 + static netdev_tx_t vrf_process_v4_outbound(struct sk_buff *skb,
8288 + struct net_device *vrf_dev)
8289 + {
8290 +- struct iphdr *ip4h = ip_hdr(skb);
8291 ++ struct iphdr *ip4h;
8292 + int ret = NET_XMIT_DROP;
8293 +- struct flowi4 fl4 = {
8294 +- /* needed to match OIF rule */
8295 +- .flowi4_oif = vrf_dev->ifindex,
8296 +- .flowi4_iif = LOOPBACK_IFINDEX,
8297 +- .flowi4_tos = RT_TOS(ip4h->tos),
8298 +- .flowi4_flags = FLOWI_FLAG_ANYSRC | FLOWI_FLAG_SKIP_NH_OIF,
8299 +- .flowi4_proto = ip4h->protocol,
8300 +- .daddr = ip4h->daddr,
8301 +- .saddr = ip4h->saddr,
8302 +- };
8303 ++ struct flowi4 fl4;
8304 + struct net *net = dev_net(vrf_dev);
8305 + struct rtable *rt;
8306 +
8307 ++ if (!pskb_may_pull(skb, ETH_HLEN + sizeof(struct iphdr)))
8308 ++ goto err;
8309 ++
8310 ++ ip4h = ip_hdr(skb);
8311 ++
8312 ++ memset(&fl4, 0, sizeof(fl4));
8313 ++ /* needed to match OIF rule */
8314 ++ fl4.flowi4_oif = vrf_dev->ifindex;
8315 ++ fl4.flowi4_iif = LOOPBACK_IFINDEX;
8316 ++ fl4.flowi4_tos = RT_TOS(ip4h->tos);
8317 ++ fl4.flowi4_flags = FLOWI_FLAG_ANYSRC | FLOWI_FLAG_SKIP_NH_OIF;
8318 ++ fl4.flowi4_proto = ip4h->protocol;
8319 ++ fl4.daddr = ip4h->daddr;
8320 ++ fl4.saddr = ip4h->saddr;
8321 ++
8322 + rt = ip_route_output_flow(net, &fl4, NULL);
8323 + if (IS_ERR(rt))
8324 + goto err;
8325 +diff --git a/drivers/net/wireless/ath/ath10k/hw.c b/drivers/net/wireless/ath/ath10k/hw.c
8326 +index a860691d635d..e96534cd3d8b 100644
8327 +--- a/drivers/net/wireless/ath/ath10k/hw.c
8328 ++++ b/drivers/net/wireless/ath/ath10k/hw.c
8329 +@@ -168,7 +168,7 @@ const struct ath10k_hw_values qca6174_values = {
8330 + };
8331 +
8332 + const struct ath10k_hw_values qca99x0_values = {
8333 +- .rtc_state_val_on = 5,
8334 ++ .rtc_state_val_on = 7,
8335 + .ce_count = 12,
8336 + .msi_assign_ce_max = 12,
8337 + .num_target_ce_config_wlan = 10,
8338 +diff --git a/drivers/net/wireless/ath/ath10k/mac.c b/drivers/net/wireless/ath/ath10k/mac.c
8339 +index cdcfb175ad9b..58a3c42c4aed 100644
8340 +--- a/drivers/net/wireless/ath/ath10k/mac.c
8341 ++++ b/drivers/net/wireless/ath/ath10k/mac.c
8342 +@@ -1611,6 +1611,10 @@ static int ath10k_mac_setup_prb_tmpl(struct ath10k_vif *arvif)
8343 + if (arvif->vdev_type != WMI_VDEV_TYPE_AP)
8344 + return 0;
8345 +
8346 ++ /* For mesh, probe response and beacon share the same template */
8347 ++ if (ieee80211_vif_is_mesh(vif))
8348 ++ return 0;
8349 ++
8350 + prb = ieee80211_proberesp_get(hw, vif);
8351 + if (!prb) {
8352 + ath10k_warn(ar, "failed to get probe resp template from mac80211\n");
8353 +diff --git a/drivers/net/wireless/ath/ath10k/sdio.c b/drivers/net/wireless/ath/ath10k/sdio.c
8354 +index da9dbf3ddaa5..0a1248ebccf5 100644
8355 +--- a/drivers/net/wireless/ath/ath10k/sdio.c
8356 ++++ b/drivers/net/wireless/ath/ath10k/sdio.c
8357 +@@ -610,6 +610,10 @@ static int ath10k_sdio_mbox_rx_alloc(struct ath10k *ar,
8358 + full_len,
8359 + last_in_bundle,
8360 + last_in_bundle);
8361 ++ if (ret) {
8362 ++ ath10k_warn(ar, "alloc_rx_pkt error %d\n", ret);
8363 ++ goto err;
8364 ++ }
8365 + }
8366 +
8367 + ar_sdio->n_rx_pkts = i;
8368 +@@ -2072,6 +2076,9 @@ static void ath10k_sdio_remove(struct sdio_func *func)
8369 + cancel_work_sync(&ar_sdio->wr_async_work);
8370 + ath10k_core_unregister(ar);
8371 + ath10k_core_destroy(ar);
8372 ++
8373 ++ flush_workqueue(ar_sdio->workqueue);
8374 ++ destroy_workqueue(ar_sdio->workqueue);
8375 + }
8376 +
8377 + static const struct sdio_device_id ath10k_sdio_devices[] = {
8378 +diff --git a/drivers/net/wireless/ath/ath6kl/wmi.c b/drivers/net/wireless/ath/ath6kl/wmi.c
8379 +index bfc20b45b806..d79c2bccf582 100644
8380 +--- a/drivers/net/wireless/ath/ath6kl/wmi.c
8381 ++++ b/drivers/net/wireless/ath/ath6kl/wmi.c
8382 +@@ -1178,6 +1178,10 @@ static int ath6kl_wmi_pstream_timeout_event_rx(struct wmi *wmi, u8 *datap,
8383 + return -EINVAL;
8384 +
8385 + ev = (struct wmi_pstream_timeout_event *) datap;
8386 ++ if (ev->traffic_class >= WMM_NUM_AC) {
8387 ++ ath6kl_err("invalid traffic class: %d\n", ev->traffic_class);
8388 ++ return -EINVAL;
8389 ++ }
8390 +
8391 + /*
8392 + * When the pstream (fat pipe == AC) timesout, it means there were
8393 +@@ -1519,6 +1523,10 @@ static int ath6kl_wmi_cac_event_rx(struct wmi *wmi, u8 *datap, int len,
8394 + return -EINVAL;
8395 +
8396 + reply = (struct wmi_cac_event *) datap;
8397 ++ if (reply->ac >= WMM_NUM_AC) {
8398 ++ ath6kl_err("invalid AC: %d\n", reply->ac);
8399 ++ return -EINVAL;
8400 ++ }
8401 +
8402 + if ((reply->cac_indication == CAC_INDICATION_ADMISSION_RESP) &&
8403 + (reply->status_code != IEEE80211_TSPEC_STATUS_ADMISS_ACCEPTED)) {
8404 +@@ -2635,7 +2643,7 @@ int ath6kl_wmi_delete_pstream_cmd(struct wmi *wmi, u8 if_idx, u8 traffic_class,
8405 + u16 active_tsids = 0;
8406 + int ret;
8407 +
8408 +- if (traffic_class > 3) {
8409 ++ if (traffic_class >= WMM_NUM_AC) {
8410 + ath6kl_err("invalid traffic class: %d\n", traffic_class);
8411 + return -EINVAL;
8412 + }
8413 +diff --git a/drivers/net/wireless/ath/ath9k/hw.c b/drivers/net/wireless/ath/ath9k/hw.c
8414 +index a7f506eb7b36..406b52f114f0 100644
8415 +--- a/drivers/net/wireless/ath/ath9k/hw.c
8416 ++++ b/drivers/net/wireless/ath/ath9k/hw.c
8417 +@@ -250,8 +250,9 @@ void ath9k_hw_get_channel_centers(struct ath_hw *ah,
8418 + /* Chip Revisions */
8419 + /******************/
8420 +
8421 +-static void ath9k_hw_read_revisions(struct ath_hw *ah)
8422 ++static bool ath9k_hw_read_revisions(struct ath_hw *ah)
8423 + {
8424 ++ u32 srev;
8425 + u32 val;
8426 +
8427 + if (ah->get_mac_revision)
8428 +@@ -267,25 +268,33 @@ static void ath9k_hw_read_revisions(struct ath_hw *ah)
8429 + val = REG_READ(ah, AR_SREV);
8430 + ah->hw_version.macRev = MS(val, AR_SREV_REVISION2);
8431 + }
8432 +- return;
8433 ++ return true;
8434 + case AR9300_DEVID_AR9340:
8435 + ah->hw_version.macVersion = AR_SREV_VERSION_9340;
8436 +- return;
8437 ++ return true;
8438 + case AR9300_DEVID_QCA955X:
8439 + ah->hw_version.macVersion = AR_SREV_VERSION_9550;
8440 +- return;
8441 ++ return true;
8442 + case AR9300_DEVID_AR953X:
8443 + ah->hw_version.macVersion = AR_SREV_VERSION_9531;
8444 +- return;
8445 ++ return true;
8446 + case AR9300_DEVID_QCA956X:
8447 + ah->hw_version.macVersion = AR_SREV_VERSION_9561;
8448 +- return;
8449 ++ return true;
8450 + }
8451 +
8452 +- val = REG_READ(ah, AR_SREV) & AR_SREV_ID;
8453 ++ srev = REG_READ(ah, AR_SREV);
8454 ++
8455 ++ if (srev == -EIO) {
8456 ++ ath_err(ath9k_hw_common(ah),
8457 ++ "Failed to read SREV register");
8458 ++ return false;
8459 ++ }
8460 ++
8461 ++ val = srev & AR_SREV_ID;
8462 +
8463 + if (val == 0xFF) {
8464 +- val = REG_READ(ah, AR_SREV);
8465 ++ val = srev;
8466 + ah->hw_version.macVersion =
8467 + (val & AR_SREV_VERSION2) >> AR_SREV_TYPE2_S;
8468 + ah->hw_version.macRev = MS(val, AR_SREV_REVISION2);
8469 +@@ -304,6 +313,8 @@ static void ath9k_hw_read_revisions(struct ath_hw *ah)
8470 + if (ah->hw_version.macVersion == AR_SREV_VERSION_5416_PCIE)
8471 + ah->is_pciexpress = true;
8472 + }
8473 ++
8474 ++ return true;
8475 + }
8476 +
8477 + /************************************/
8478 +@@ -557,7 +568,10 @@ static int __ath9k_hw_init(struct ath_hw *ah)
8479 + struct ath_common *common = ath9k_hw_common(ah);
8480 + int r = 0;
8481 +
8482 +- ath9k_hw_read_revisions(ah);
8483 ++ if (!ath9k_hw_read_revisions(ah)) {
8484 ++ ath_err(common, "Could not read hardware revisions");
8485 ++ return -EOPNOTSUPP;
8486 ++ }
8487 +
8488 + switch (ah->hw_version.macVersion) {
8489 + case AR_SREV_VERSION_5416_PCI:
8490 +diff --git a/drivers/net/wireless/ath/dfs_pattern_detector.c b/drivers/net/wireless/ath/dfs_pattern_detector.c
8491 +index 4100ffd42a43..78146607f16e 100644
8492 +--- a/drivers/net/wireless/ath/dfs_pattern_detector.c
8493 ++++ b/drivers/net/wireless/ath/dfs_pattern_detector.c
8494 +@@ -111,7 +111,7 @@ static const struct radar_detector_specs jp_radar_ref_types[] = {
8495 + JP_PATTERN(0, 0, 1, 1428, 1428, 1, 18, 29, false),
8496 + JP_PATTERN(1, 2, 3, 3846, 3846, 1, 18, 29, false),
8497 + JP_PATTERN(2, 0, 1, 1388, 1388, 1, 18, 50, false),
8498 +- JP_PATTERN(3, 1, 2, 4000, 4000, 1, 18, 50, false),
8499 ++ JP_PATTERN(3, 0, 4, 4000, 4000, 1, 18, 50, false),
8500 + JP_PATTERN(4, 0, 5, 150, 230, 1, 23, 50, false),
8501 + JP_PATTERN(5, 6, 10, 200, 500, 1, 16, 50, false),
8502 + JP_PATTERN(6, 11, 20, 200, 500, 1, 12, 50, false),
8503 +diff --git a/drivers/net/wireless/ath/wil6210/txrx.c b/drivers/net/wireless/ath/wil6210/txrx.c
8504 +index 389c718cd257..16750056b8b5 100644
8505 +--- a/drivers/net/wireless/ath/wil6210/txrx.c
8506 ++++ b/drivers/net/wireless/ath/wil6210/txrx.c
8507 +@@ -732,6 +732,7 @@ void wil_netif_rx_any(struct sk_buff *skb, struct net_device *ndev)
8508 + [GRO_HELD] = "GRO_HELD",
8509 + [GRO_NORMAL] = "GRO_NORMAL",
8510 + [GRO_DROP] = "GRO_DROP",
8511 ++ [GRO_CONSUMED] = "GRO_CONSUMED",
8512 + };
8513 +
8514 + if (ndev->features & NETIF_F_RXHASH)
8515 +diff --git a/drivers/net/wireless/intel/iwlwifi/mvm/tx.c b/drivers/net/wireless/intel/iwlwifi/mvm/tx.c
8516 +index 62a6e293cf12..f0f2be432d20 100644
8517 +--- a/drivers/net/wireless/intel/iwlwifi/mvm/tx.c
8518 ++++ b/drivers/net/wireless/intel/iwlwifi/mvm/tx.c
8519 +@@ -621,6 +621,9 @@ int iwl_mvm_tx_skb_non_sta(struct iwl_mvm *mvm, struct sk_buff *skb)
8520 +
8521 + memcpy(&info, skb->cb, sizeof(info));
8522 +
8523 ++ if (WARN_ON_ONCE(skb->len > IEEE80211_MAX_DATA_LEN + hdrlen))
8524 ++ return -1;
8525 ++
8526 + if (WARN_ON_ONCE(info.flags & IEEE80211_TX_CTL_AMPDU))
8527 + return -1;
8528 +
8529 +diff --git a/drivers/net/wireless/intel/iwlwifi/pcie/rx.c b/drivers/net/wireless/intel/iwlwifi/pcie/rx.c
8530 +index 953e0254a94c..3ebab48f6980 100644
8531 +--- a/drivers/net/wireless/intel/iwlwifi/pcie/rx.c
8532 ++++ b/drivers/net/wireless/intel/iwlwifi/pcie/rx.c
8533 +@@ -1674,25 +1674,23 @@ irqreturn_t iwl_pcie_irq_handler(int irq, void *dev_id)
8534 + goto out;
8535 + }
8536 +
8537 +- if (iwl_have_debug_level(IWL_DL_ISR)) {
8538 +- /* NIC fires this, but we don't use it, redundant with WAKEUP */
8539 +- if (inta & CSR_INT_BIT_SCD) {
8540 +- IWL_DEBUG_ISR(trans,
8541 +- "Scheduler finished to transmit the frame/frames.\n");
8542 +- isr_stats->sch++;
8543 +- }
8544 ++ /* NIC fires this, but we don't use it, redundant with WAKEUP */
8545 ++ if (inta & CSR_INT_BIT_SCD) {
8546 ++ IWL_DEBUG_ISR(trans,
8547 ++ "Scheduler finished to transmit the frame/frames.\n");
8548 ++ isr_stats->sch++;
8549 ++ }
8550 +
8551 +- /* Alive notification via Rx interrupt will do the real work */
8552 +- if (inta & CSR_INT_BIT_ALIVE) {
8553 +- IWL_DEBUG_ISR(trans, "Alive interrupt\n");
8554 +- isr_stats->alive++;
8555 +- if (trans->cfg->gen2) {
8556 +- /*
8557 +- * We can restock, since firmware configured
8558 +- * the RFH
8559 +- */
8560 +- iwl_pcie_rxmq_restock(trans, trans_pcie->rxq);
8561 +- }
8562 ++ /* Alive notification via Rx interrupt will do the real work */
8563 ++ if (inta & CSR_INT_BIT_ALIVE) {
8564 ++ IWL_DEBUG_ISR(trans, "Alive interrupt\n");
8565 ++ isr_stats->alive++;
8566 ++ if (trans->cfg->gen2) {
8567 ++ /*
8568 ++ * We can restock, since firmware configured
8569 ++ * the RFH
8570 ++ */
8571 ++ iwl_pcie_rxmq_restock(trans, trans_pcie->rxq);
8572 + }
8573 + }
8574 +
8575 +@@ -1956,10 +1954,18 @@ irqreturn_t iwl_pcie_irq_msix_handler(int irq, void *dev_id)
8576 + return IRQ_NONE;
8577 + }
8578 +
8579 +- if (iwl_have_debug_level(IWL_DL_ISR))
8580 +- IWL_DEBUG_ISR(trans, "ISR inta_fh 0x%08x, enabled 0x%08x\n",
8581 +- inta_fh,
8582 ++ if (iwl_have_debug_level(IWL_DL_ISR)) {
8583 ++ IWL_DEBUG_ISR(trans,
8584 ++ "ISR inta_fh 0x%08x, enabled (sw) 0x%08x (hw) 0x%08x\n",
8585 ++ inta_fh, trans_pcie->fh_mask,
8586 + iwl_read32(trans, CSR_MSIX_FH_INT_MASK_AD));
8587 ++ if (inta_fh & ~trans_pcie->fh_mask)
8588 ++ IWL_DEBUG_ISR(trans,
8589 ++ "We got a masked interrupt (0x%08x)\n",
8590 ++ inta_fh & ~trans_pcie->fh_mask);
8591 ++ }
8592 ++
8593 ++ inta_fh &= trans_pcie->fh_mask;
8594 +
8595 + if ((trans_pcie->shared_vec_mask & IWL_SHARED_IRQ_NON_RX) &&
8596 + inta_fh & MSIX_FH_INT_CAUSES_Q0) {
8597 +@@ -1998,11 +2004,18 @@ irqreturn_t iwl_pcie_irq_msix_handler(int irq, void *dev_id)
8598 + }
8599 +
8600 + /* After checking FH register check HW register */
8601 +- if (iwl_have_debug_level(IWL_DL_ISR))
8602 ++ if (iwl_have_debug_level(IWL_DL_ISR)) {
8603 + IWL_DEBUG_ISR(trans,
8604 +- "ISR inta_hw 0x%08x, enabled 0x%08x\n",
8605 +- inta_hw,
8606 ++ "ISR inta_hw 0x%08x, enabled (sw) 0x%08x (hw) 0x%08x\n",
8607 ++ inta_hw, trans_pcie->hw_mask,
8608 + iwl_read32(trans, CSR_MSIX_HW_INT_MASK_AD));
8609 ++ if (inta_hw & ~trans_pcie->hw_mask)
8610 ++ IWL_DEBUG_ISR(trans,
8611 ++ "We got a masked interrupt 0x%08x\n",
8612 ++ inta_hw & ~trans_pcie->hw_mask);
8613 ++ }
8614 ++
8615 ++ inta_hw &= trans_pcie->hw_mask;
8616 +
8617 + /* Alive notification via Rx interrupt will do the real work */
8618 + if (inta_hw & MSIX_HW_INT_CAUSES_REG_ALIVE) {
8619 +diff --git a/drivers/net/wireless/mediatek/mt7601u/dma.c b/drivers/net/wireless/mediatek/mt7601u/dma.c
8620 +index 7f3e3983b781..47cebb2ec05c 100644
8621 +--- a/drivers/net/wireless/mediatek/mt7601u/dma.c
8622 ++++ b/drivers/net/wireless/mediatek/mt7601u/dma.c
8623 +@@ -193,10 +193,23 @@ static void mt7601u_complete_rx(struct urb *urb)
8624 + struct mt7601u_rx_queue *q = &dev->rx_q;
8625 + unsigned long flags;
8626 +
8627 +- spin_lock_irqsave(&dev->rx_lock, flags);
8628 ++ /* do no schedule rx tasklet if urb has been unlinked
8629 ++ * or the device has been removed
8630 ++ */
8631 ++ switch (urb->status) {
8632 ++ case -ECONNRESET:
8633 ++ case -ESHUTDOWN:
8634 ++ case -ENOENT:
8635 ++ return;
8636 ++ default:
8637 ++ dev_err_ratelimited(dev->dev, "rx urb failed: %d\n",
8638 ++ urb->status);
8639 ++ /* fall through */
8640 ++ case 0:
8641 ++ break;
8642 ++ }
8643 +
8644 +- if (mt7601u_urb_has_error(urb))
8645 +- dev_err(dev->dev, "Error: RX urb failed:%d\n", urb->status);
8646 ++ spin_lock_irqsave(&dev->rx_lock, flags);
8647 + if (WARN_ONCE(q->e[q->end].urb != urb, "RX urb mismatch"))
8648 + goto out;
8649 +
8650 +@@ -228,14 +241,25 @@ static void mt7601u_complete_tx(struct urb *urb)
8651 + struct sk_buff *skb;
8652 + unsigned long flags;
8653 +
8654 +- spin_lock_irqsave(&dev->tx_lock, flags);
8655 ++ switch (urb->status) {
8656 ++ case -ECONNRESET:
8657 ++ case -ESHUTDOWN:
8658 ++ case -ENOENT:
8659 ++ return;
8660 ++ default:
8661 ++ dev_err_ratelimited(dev->dev, "tx urb failed: %d\n",
8662 ++ urb->status);
8663 ++ /* fall through */
8664 ++ case 0:
8665 ++ break;
8666 ++ }
8667 +
8668 +- if (mt7601u_urb_has_error(urb))
8669 +- dev_err(dev->dev, "Error: TX urb failed:%d\n", urb->status);
8670 ++ spin_lock_irqsave(&dev->tx_lock, flags);
8671 + if (WARN_ONCE(q->e[q->start].urb != urb, "TX urb mismatch"))
8672 + goto out;
8673 +
8674 + skb = q->e[q->start].skb;
8675 ++ q->e[q->start].skb = NULL;
8676 + trace_mt_tx_dma_done(dev, skb);
8677 +
8678 + __skb_queue_tail(&dev->tx_skb_done, skb);
8679 +@@ -363,19 +387,9 @@ int mt7601u_dma_enqueue_tx(struct mt7601u_dev *dev, struct sk_buff *skb,
8680 + static void mt7601u_kill_rx(struct mt7601u_dev *dev)
8681 + {
8682 + int i;
8683 +- unsigned long flags;
8684 +-
8685 +- spin_lock_irqsave(&dev->rx_lock, flags);
8686 +-
8687 +- for (i = 0; i < dev->rx_q.entries; i++) {
8688 +- int next = dev->rx_q.end;
8689 +
8690 +- spin_unlock_irqrestore(&dev->rx_lock, flags);
8691 +- usb_poison_urb(dev->rx_q.e[next].urb);
8692 +- spin_lock_irqsave(&dev->rx_lock, flags);
8693 +- }
8694 +-
8695 +- spin_unlock_irqrestore(&dev->rx_lock, flags);
8696 ++ for (i = 0; i < dev->rx_q.entries; i++)
8697 ++ usb_poison_urb(dev->rx_q.e[i].urb);
8698 + }
8699 +
8700 + static int mt7601u_submit_rx_buf(struct mt7601u_dev *dev,
8701 +@@ -445,10 +459,10 @@ static void mt7601u_free_tx_queue(struct mt7601u_tx_queue *q)
8702 + {
8703 + int i;
8704 +
8705 +- WARN_ON(q->used);
8706 +-
8707 + for (i = 0; i < q->entries; i++) {
8708 + usb_poison_urb(q->e[i].urb);
8709 ++ if (q->e[i].skb)
8710 ++ mt7601u_tx_status(q->dev, q->e[i].skb);
8711 + usb_free_urb(q->e[i].urb);
8712 + }
8713 + }
8714 +diff --git a/drivers/net/wireless/mediatek/mt7601u/tx.c b/drivers/net/wireless/mediatek/mt7601u/tx.c
8715 +index 3600e911a63e..4d81c45722fb 100644
8716 +--- a/drivers/net/wireless/mediatek/mt7601u/tx.c
8717 ++++ b/drivers/net/wireless/mediatek/mt7601u/tx.c
8718 +@@ -117,9 +117,9 @@ void mt7601u_tx_status(struct mt7601u_dev *dev, struct sk_buff *skb)
8719 + info->status.rates[0].idx = -1;
8720 + info->flags |= IEEE80211_TX_STAT_ACK;
8721 +
8722 +- spin_lock(&dev->mac_lock);
8723 ++ spin_lock_bh(&dev->mac_lock);
8724 + ieee80211_tx_status(dev->hw, skb);
8725 +- spin_unlock(&dev->mac_lock);
8726 ++ spin_unlock_bh(&dev->mac_lock);
8727 + }
8728 +
8729 + static int mt7601u_skb_rooms(struct mt7601u_dev *dev, struct sk_buff *skb)
8730 +diff --git a/drivers/net/wireless/realtek/rtlwifi/usb.c b/drivers/net/wireless/realtek/rtlwifi/usb.c
8731 +index 820c42ff5384..2401c8bdb211 100644
8732 +--- a/drivers/net/wireless/realtek/rtlwifi/usb.c
8733 ++++ b/drivers/net/wireless/realtek/rtlwifi/usb.c
8734 +@@ -1099,13 +1099,13 @@ int rtl_usb_probe(struct usb_interface *intf,
8735 + rtlpriv->cfg->ops->read_eeprom_info(hw);
8736 + err = _rtl_usb_init(hw);
8737 + if (err)
8738 +- goto error_out;
8739 ++ goto error_out2;
8740 + rtl_usb_init_sw(hw);
8741 + /* Init mac80211 sw */
8742 + err = rtl_init_core(hw);
8743 + if (err) {
8744 + pr_err("Can't allocate sw for mac80211\n");
8745 +- goto error_out;
8746 ++ goto error_out2;
8747 + }
8748 + if (rtlpriv->cfg->ops->init_sw_vars(hw)) {
8749 + pr_err("Can't init_sw_vars\n");
8750 +@@ -1126,6 +1126,7 @@ int rtl_usb_probe(struct usb_interface *intf,
8751 +
8752 + error_out:
8753 + rtl_deinit_core(hw);
8754 ++error_out2:
8755 + _rtl_usb_io_handler_release(hw);
8756 + usb_put_dev(udev);
8757 + complete(&rtlpriv->firmware_loading_complete);
8758 +diff --git a/drivers/nvdimm/dax_devs.c b/drivers/nvdimm/dax_devs.c
8759 +index 1bf2bd318371..0e9e37410c58 100644
8760 +--- a/drivers/nvdimm/dax_devs.c
8761 ++++ b/drivers/nvdimm/dax_devs.c
8762 +@@ -126,7 +126,7 @@ int nd_dax_probe(struct device *dev, struct nd_namespace_common *ndns)
8763 + nvdimm_bus_unlock(&ndns->dev);
8764 + if (!dax_dev)
8765 + return -ENOMEM;
8766 +- pfn_sb = devm_kzalloc(dev, sizeof(*pfn_sb), GFP_KERNEL);
8767 ++ pfn_sb = devm_kmalloc(dev, sizeof(*pfn_sb), GFP_KERNEL);
8768 + nd_pfn->pfn_sb = pfn_sb;
8769 + rc = nd_pfn_validate(nd_pfn, DAX_SIG);
8770 + dev_dbg(dev, "%s: dax: %s\n", __func__,
8771 +diff --git a/drivers/nvdimm/pfn.h b/drivers/nvdimm/pfn.h
8772 +index dde9853453d3..e901e3a3b04c 100644
8773 +--- a/drivers/nvdimm/pfn.h
8774 ++++ b/drivers/nvdimm/pfn.h
8775 +@@ -36,6 +36,7 @@ struct nd_pfn_sb {
8776 + __le32 end_trunc;
8777 + /* minor-version-2 record the base alignment of the mapping */
8778 + __le32 align;
8779 ++ /* minor-version-3 guarantee the padding and flags are zero */
8780 + u8 padding[4000];
8781 + __le64 checksum;
8782 + };
8783 +diff --git a/drivers/nvdimm/pfn_devs.c b/drivers/nvdimm/pfn_devs.c
8784 +index b9dad88b8ea3..e2af91a91c22 100644
8785 +--- a/drivers/nvdimm/pfn_devs.c
8786 ++++ b/drivers/nvdimm/pfn_devs.c
8787 +@@ -361,6 +361,15 @@ struct device *nd_pfn_create(struct nd_region *nd_region)
8788 + return dev;
8789 + }
8790 +
8791 ++/**
8792 ++ * nd_pfn_validate - read and validate info-block
8793 ++ * @nd_pfn: fsdax namespace runtime state / properties
8794 ++ * @sig: 'devdax' or 'fsdax' signature
8795 ++ *
8796 ++ * Upon return the info-block buffer contents (->pfn_sb) are
8797 ++ * indeterminate when validation fails, and a coherent info-block
8798 ++ * otherwise.
8799 ++ */
8800 + int nd_pfn_validate(struct nd_pfn *nd_pfn, const char *sig)
8801 + {
8802 + u64 checksum, offset;
8803 +@@ -506,7 +515,7 @@ int nd_pfn_probe(struct device *dev, struct nd_namespace_common *ndns)
8804 + nvdimm_bus_unlock(&ndns->dev);
8805 + if (!pfn_dev)
8806 + return -ENOMEM;
8807 +- pfn_sb = devm_kzalloc(dev, sizeof(*pfn_sb), GFP_KERNEL);
8808 ++ pfn_sb = devm_kmalloc(dev, sizeof(*pfn_sb), GFP_KERNEL);
8809 + nd_pfn = to_nd_pfn(pfn_dev);
8810 + nd_pfn->pfn_sb = pfn_sb;
8811 + rc = nd_pfn_validate(nd_pfn, PFN_SIG);
8812 +@@ -637,7 +646,7 @@ static int nd_pfn_init(struct nd_pfn *nd_pfn)
8813 + u64 checksum;
8814 + int rc;
8815 +
8816 +- pfn_sb = devm_kzalloc(&nd_pfn->dev, sizeof(*pfn_sb), GFP_KERNEL);
8817 ++ pfn_sb = devm_kmalloc(&nd_pfn->dev, sizeof(*pfn_sb), GFP_KERNEL);
8818 + if (!pfn_sb)
8819 + return -ENOMEM;
8820 +
8821 +@@ -646,11 +655,14 @@ static int nd_pfn_init(struct nd_pfn *nd_pfn)
8822 + sig = DAX_SIG;
8823 + else
8824 + sig = PFN_SIG;
8825 ++
8826 + rc = nd_pfn_validate(nd_pfn, sig);
8827 + if (rc != -ENODEV)
8828 + return rc;
8829 +
8830 + /* no info block, do init */;
8831 ++ memset(pfn_sb, 0, sizeof(*pfn_sb));
8832 ++
8833 + nd_region = to_nd_region(nd_pfn->dev.parent);
8834 + if (nd_region->ro) {
8835 + dev_info(&nd_pfn->dev,
8836 +@@ -704,7 +716,7 @@ static int nd_pfn_init(struct nd_pfn *nd_pfn)
8837 + memcpy(pfn_sb->uuid, nd_pfn->uuid, 16);
8838 + memcpy(pfn_sb->parent_uuid, nd_dev_to_uuid(&ndns->dev), 16);
8839 + pfn_sb->version_major = cpu_to_le16(1);
8840 +- pfn_sb->version_minor = cpu_to_le16(2);
8841 ++ pfn_sb->version_minor = cpu_to_le16(3);
8842 + pfn_sb->start_pad = cpu_to_le32(start_pad);
8843 + pfn_sb->end_trunc = cpu_to_le32(end_trunc);
8844 + pfn_sb->align = cpu_to_le32(nd_pfn->align);
8845 +diff --git a/drivers/pci/dwc/pci-dra7xx.c b/drivers/pci/dwc/pci-dra7xx.c
8846 +index 06eae132aff7..63052c5e5f82 100644
8847 +--- a/drivers/pci/dwc/pci-dra7xx.c
8848 ++++ b/drivers/pci/dwc/pci-dra7xx.c
8849 +@@ -29,6 +29,7 @@
8850 + #include <linux/types.h>
8851 + #include <linux/mfd/syscon.h>
8852 + #include <linux/regmap.h>
8853 ++#include <linux/gpio/consumer.h>
8854 +
8855 + #include "pcie-designware.h"
8856 +
8857 +diff --git a/drivers/pci/host/pci-hyperv.c b/drivers/pci/host/pci-hyperv.c
8858 +index f591de23f3d3..5a9d94512232 100644
8859 +--- a/drivers/pci/host/pci-hyperv.c
8860 ++++ b/drivers/pci/host/pci-hyperv.c
8861 +@@ -1912,6 +1912,7 @@ static void hv_pci_devices_present(struct hv_pcibus_device *hbus,
8862 + static void hv_eject_device_work(struct work_struct *work)
8863 + {
8864 + struct pci_eject_response *ejct_pkt;
8865 ++ struct hv_pcibus_device *hbus;
8866 + struct hv_pci_dev *hpdev;
8867 + struct pci_dev *pdev;
8868 + unsigned long flags;
8869 +@@ -1922,6 +1923,7 @@ static void hv_eject_device_work(struct work_struct *work)
8870 + } ctxt;
8871 +
8872 + hpdev = container_of(work, struct hv_pci_dev, wrk);
8873 ++ hbus = hpdev->hbus;
8874 +
8875 + if (hpdev->state != hv_pcichild_ejecting) {
8876 + put_pcichild(hpdev, hv_pcidev_ref_pnp);
8877 +@@ -1935,8 +1937,7 @@ static void hv_eject_device_work(struct work_struct *work)
8878 + * because hbus->pci_bus may not exist yet.
8879 + */
8880 + wslot = wslot_to_devfn(hpdev->desc.win_slot.slot);
8881 +- pdev = pci_get_domain_bus_and_slot(hpdev->hbus->sysdata.domain, 0,
8882 +- wslot);
8883 ++ pdev = pci_get_domain_bus_and_slot(hbus->sysdata.domain, 0, wslot);
8884 + if (pdev) {
8885 + pci_lock_rescan_remove();
8886 + pci_stop_and_remove_bus_device(pdev);
8887 +@@ -1944,9 +1945,9 @@ static void hv_eject_device_work(struct work_struct *work)
8888 + pci_unlock_rescan_remove();
8889 + }
8890 +
8891 +- spin_lock_irqsave(&hpdev->hbus->device_list_lock, flags);
8892 ++ spin_lock_irqsave(&hbus->device_list_lock, flags);
8893 + list_del(&hpdev->list_entry);
8894 +- spin_unlock_irqrestore(&hpdev->hbus->device_list_lock, flags);
8895 ++ spin_unlock_irqrestore(&hbus->device_list_lock, flags);
8896 +
8897 + if (hpdev->pci_slot)
8898 + pci_destroy_slot(hpdev->pci_slot);
8899 +@@ -1955,14 +1956,16 @@ static void hv_eject_device_work(struct work_struct *work)
8900 + ejct_pkt = (struct pci_eject_response *)&ctxt.pkt.message;
8901 + ejct_pkt->message_type.type = PCI_EJECTION_COMPLETE;
8902 + ejct_pkt->wslot.slot = hpdev->desc.win_slot.slot;
8903 +- vmbus_sendpacket(hpdev->hbus->hdev->channel, ejct_pkt,
8904 ++ vmbus_sendpacket(hbus->hdev->channel, ejct_pkt,
8905 + sizeof(*ejct_pkt), (unsigned long)&ctxt.pkt,
8906 + VM_PKT_DATA_INBAND, 0);
8907 +
8908 + put_pcichild(hpdev, hv_pcidev_ref_childlist);
8909 + put_pcichild(hpdev, hv_pcidev_ref_initial);
8910 + put_pcichild(hpdev, hv_pcidev_ref_pnp);
8911 +- put_hvpcibus(hpdev->hbus);
8912 ++
8913 ++ /* hpdev has been freed. Do not use it any more. */
8914 ++ put_hvpcibus(hbus);
8915 + }
8916 +
8917 + /**
8918 +diff --git a/drivers/pci/host/pcie-xilinx-nwl.c b/drivers/pci/host/pcie-xilinx-nwl.c
8919 +index dd527ea558d7..981a5195686f 100644
8920 +--- a/drivers/pci/host/pcie-xilinx-nwl.c
8921 ++++ b/drivers/pci/host/pcie-xilinx-nwl.c
8922 +@@ -485,15 +485,13 @@ static int nwl_irq_domain_alloc(struct irq_domain *domain, unsigned int virq,
8923 + int i;
8924 +
8925 + mutex_lock(&msi->lock);
8926 +- bit = bitmap_find_next_zero_area(msi->bitmap, INT_PCI_MSI_NR, 0,
8927 +- nr_irqs, 0);
8928 +- if (bit >= INT_PCI_MSI_NR) {
8929 ++ bit = bitmap_find_free_region(msi->bitmap, INT_PCI_MSI_NR,
8930 ++ get_count_order(nr_irqs));
8931 ++ if (bit < 0) {
8932 + mutex_unlock(&msi->lock);
8933 + return -ENOSPC;
8934 + }
8935 +
8936 +- bitmap_set(msi->bitmap, bit, nr_irqs);
8937 +-
8938 + for (i = 0; i < nr_irqs; i++) {
8939 + irq_domain_set_info(domain, virq + i, bit + i, &nwl_irq_chip,
8940 + domain->host_data, handle_simple_irq,
8941 +@@ -511,7 +509,8 @@ static void nwl_irq_domain_free(struct irq_domain *domain, unsigned int virq,
8942 + struct nwl_msi *msi = &pcie->msi;
8943 +
8944 + mutex_lock(&msi->lock);
8945 +- bitmap_clear(msi->bitmap, data->hwirq, nr_irqs);
8946 ++ bitmap_release_region(msi->bitmap, data->hwirq,
8947 ++ get_count_order(nr_irqs));
8948 + mutex_unlock(&msi->lock);
8949 + }
8950 +
8951 +diff --git a/drivers/pci/pci-driver.c b/drivers/pci/pci-driver.c
8952 +index ea69b4dbab66..e5a8bf2c9b37 100644
8953 +--- a/drivers/pci/pci-driver.c
8954 ++++ b/drivers/pci/pci-driver.c
8955 +@@ -415,6 +415,9 @@ static int pci_device_probe(struct device *dev)
8956 + struct pci_dev *pci_dev = to_pci_dev(dev);
8957 + struct pci_driver *drv = to_pci_driver(dev->driver);
8958 +
8959 ++ if (!pci_device_can_probe(pci_dev))
8960 ++ return -ENODEV;
8961 ++
8962 + pci_assign_irq(pci_dev);
8963 +
8964 + error = pcibios_alloc_irq(pci_dev);
8965 +@@ -422,12 +425,10 @@ static int pci_device_probe(struct device *dev)
8966 + return error;
8967 +
8968 + pci_dev_get(pci_dev);
8969 +- if (pci_device_can_probe(pci_dev)) {
8970 +- error = __pci_device_probe(drv, pci_dev);
8971 +- if (error) {
8972 +- pcibios_free_irq(pci_dev);
8973 +- pci_dev_put(pci_dev);
8974 +- }
8975 ++ error = __pci_device_probe(drv, pci_dev);
8976 ++ if (error) {
8977 ++ pcibios_free_irq(pci_dev);
8978 ++ pci_dev_put(pci_dev);
8979 + }
8980 +
8981 + return error;
8982 +diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
8983 +index c3f0473d1afa..ee7dccab771d 100644
8984 +--- a/drivers/pci/pci-sysfs.c
8985 ++++ b/drivers/pci/pci-sysfs.c
8986 +@@ -496,7 +496,7 @@ static ssize_t remove_store(struct device *dev, struct device_attribute *attr,
8987 + pci_stop_and_remove_bus_device_locked(to_pci_dev(dev));
8988 + return count;
8989 + }
8990 +-static struct device_attribute dev_remove_attr = __ATTR(remove,
8991 ++static struct device_attribute dev_remove_attr = __ATTR_IGNORE_LOCKDEP(remove,
8992 + (S_IWUSR|S_IWGRP),
8993 + NULL, remove_store);
8994 +
8995 +diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
8996 +index 1af30c881566..044b208f7f6a 100644
8997 +--- a/drivers/pci/pci.c
8998 ++++ b/drivers/pci/pci.c
8999 +@@ -1786,6 +1786,13 @@ static void pci_pme_list_scan(struct work_struct *work)
9000 + */
9001 + if (bridge && bridge->current_state != PCI_D0)
9002 + continue;
9003 ++ /*
9004 ++ * If the device is in D3cold it should not be
9005 ++ * polled either.
9006 ++ */
9007 ++ if (pme_dev->dev->current_state == PCI_D3cold)
9008 ++ continue;
9009 ++
9010 + pci_pme_wakeup(pme_dev->dev, NULL);
9011 + } else {
9012 + list_del(&pme_dev->list);
9013 +diff --git a/drivers/phy/renesas/phy-rcar-gen2.c b/drivers/phy/renesas/phy-rcar-gen2.c
9014 +index 97d4dd6ea924..aa02b19b7e0e 100644
9015 +--- a/drivers/phy/renesas/phy-rcar-gen2.c
9016 ++++ b/drivers/phy/renesas/phy-rcar-gen2.c
9017 +@@ -288,6 +288,7 @@ static int rcar_gen2_phy_probe(struct platform_device *pdev)
9018 + error = of_property_read_u32(np, "reg", &channel_num);
9019 + if (error || channel_num > 2) {
9020 + dev_err(dev, "Invalid \"reg\" property\n");
9021 ++ of_node_put(np);
9022 + return error;
9023 + }
9024 + channel->select_mask = select_mask[channel_num];
9025 +@@ -303,6 +304,7 @@ static int rcar_gen2_phy_probe(struct platform_device *pdev)
9026 + &rcar_gen2_phy_ops);
9027 + if (IS_ERR(phy->phy)) {
9028 + dev_err(dev, "Failed to create PHY\n");
9029 ++ of_node_put(np);
9030 + return PTR_ERR(phy->phy);
9031 + }
9032 + phy_set_drvdata(phy->phy, phy);
9033 +diff --git a/drivers/pinctrl/pinctrl-rockchip.c b/drivers/pinctrl/pinctrl-rockchip.c
9034 +index a9bc1e01f982..5d6cf024ee9c 100644
9035 +--- a/drivers/pinctrl/pinctrl-rockchip.c
9036 ++++ b/drivers/pinctrl/pinctrl-rockchip.c
9037 +@@ -2941,6 +2941,7 @@ static int rockchip_get_bank_data(struct rockchip_pin_bank *bank,
9038 + base,
9039 + &rockchip_regmap_config);
9040 + }
9041 ++ of_node_put(node);
9042 + }
9043 +
9044 + bank->irq = irq_of_parse_and_map(bank->of_node, 0);
9045 +diff --git a/drivers/ras/cec.c b/drivers/ras/cec.c
9046 +index c7205cdcc11a..97cf40a522be 100644
9047 +--- a/drivers/ras/cec.c
9048 ++++ b/drivers/ras/cec.c
9049 +@@ -373,7 +373,9 @@ static int pfn_set(void *data, u64 val)
9050 + {
9051 + *(u64 *)data = val;
9052 +
9053 +- return cec_add_elem(val);
9054 ++ cec_add_elem(val);
9055 ++
9056 ++ return 0;
9057 + }
9058 +
9059 + DEFINE_DEBUGFS_ATTRIBUTE(pfn_ops, u64_get, pfn_set, "0x%llx\n");
9060 +diff --git a/drivers/regulator/s2mps11.c b/drivers/regulator/s2mps11.c
9061 +index 17a816656b92..8f7c19901339 100644
9062 +--- a/drivers/regulator/s2mps11.c
9063 ++++ b/drivers/regulator/s2mps11.c
9064 +@@ -386,8 +386,8 @@ static const struct regulator_desc s2mps11_regulators[] = {
9065 + regulator_desc_s2mps11_buck1_4(4),
9066 + regulator_desc_s2mps11_buck5,
9067 + regulator_desc_s2mps11_buck67810(6, MIN_600_MV, STEP_6_25_MV),
9068 +- regulator_desc_s2mps11_buck67810(7, MIN_600_MV, STEP_12_5_MV),
9069 +- regulator_desc_s2mps11_buck67810(8, MIN_600_MV, STEP_12_5_MV),
9070 ++ regulator_desc_s2mps11_buck67810(7, MIN_750_MV, STEP_12_5_MV),
9071 ++ regulator_desc_s2mps11_buck67810(8, MIN_750_MV, STEP_12_5_MV),
9072 + regulator_desc_s2mps11_buck9,
9073 + regulator_desc_s2mps11_buck67810(10, MIN_750_MV, STEP_12_5_MV),
9074 + };
9075 +diff --git a/drivers/s390/cio/qdio_main.c b/drivers/s390/cio/qdio_main.c
9076 +index c7afdbded26b..ab8dd81fbc2b 100644
9077 +--- a/drivers/s390/cio/qdio_main.c
9078 ++++ b/drivers/s390/cio/qdio_main.c
9079 +@@ -759,6 +759,7 @@ static int get_outbound_buffer_frontier(struct qdio_q *q)
9080 +
9081 + switch (state) {
9082 + case SLSB_P_OUTPUT_EMPTY:
9083 ++ case SLSB_P_OUTPUT_PENDING:
9084 + /* the adapter got it */
9085 + DBF_DEV_EVENT(DBF_INFO, q->irq_ptr,
9086 + "out empty:%1d %02x", q->nr, count);
9087 +diff --git a/drivers/scsi/NCR5380.c b/drivers/scsi/NCR5380.c
9088 +index 777b0222d021..8caa51797511 100644
9089 +--- a/drivers/scsi/NCR5380.c
9090 ++++ b/drivers/scsi/NCR5380.c
9091 +@@ -710,6 +710,8 @@ static void NCR5380_main(struct work_struct *work)
9092 + NCR5380_information_transfer(instance);
9093 + done = 0;
9094 + }
9095 ++ if (!hostdata->connected)
9096 ++ NCR5380_write(SELECT_ENABLE_REG, hostdata->id_mask);
9097 + spin_unlock_irq(&hostdata->lock);
9098 + if (!done)
9099 + cond_resched();
9100 +@@ -984,7 +986,7 @@ static struct scsi_cmnd *NCR5380_select(struct Scsi_Host *instance,
9101 + if (!hostdata->selecting) {
9102 + /* Command was aborted */
9103 + NCR5380_write(MODE_REG, MR_BASE);
9104 +- goto out;
9105 ++ return NULL;
9106 + }
9107 + if (err < 0) {
9108 + NCR5380_write(MODE_REG, MR_BASE);
9109 +@@ -1033,7 +1035,7 @@ static struct scsi_cmnd *NCR5380_select(struct Scsi_Host *instance,
9110 + if (!hostdata->selecting) {
9111 + NCR5380_write(MODE_REG, MR_BASE);
9112 + NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
9113 +- goto out;
9114 ++ return NULL;
9115 + }
9116 +
9117 + dsprintk(NDEBUG_ARBITRATION, instance, "won arbitration\n");
9118 +@@ -1106,8 +1108,6 @@ static struct scsi_cmnd *NCR5380_select(struct Scsi_Host *instance,
9119 + spin_lock_irq(&hostdata->lock);
9120 + NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
9121 + NCR5380_reselect(instance);
9122 +- if (!hostdata->connected)
9123 +- NCR5380_write(SELECT_ENABLE_REG, hostdata->id_mask);
9124 + shost_printk(KERN_ERR, instance, "reselection after won arbitration?\n");
9125 + goto out;
9126 + }
9127 +@@ -1115,14 +1115,16 @@ static struct scsi_cmnd *NCR5380_select(struct Scsi_Host *instance,
9128 + if (err < 0) {
9129 + spin_lock_irq(&hostdata->lock);
9130 + NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
9131 +- NCR5380_write(SELECT_ENABLE_REG, hostdata->id_mask);
9132 ++
9133 + /* Can't touch cmd if it has been reclaimed by the scsi ML */
9134 +- if (hostdata->selecting) {
9135 +- cmd->result = DID_BAD_TARGET << 16;
9136 +- complete_cmd(instance, cmd);
9137 +- dsprintk(NDEBUG_SELECTION, instance, "target did not respond within 250ms\n");
9138 +- cmd = NULL;
9139 +- }
9140 ++ if (!hostdata->selecting)
9141 ++ return NULL;
9142 ++
9143 ++ cmd->result = DID_BAD_TARGET << 16;
9144 ++ complete_cmd(instance, cmd);
9145 ++ dsprintk(NDEBUG_SELECTION, instance,
9146 ++ "target did not respond within 250ms\n");
9147 ++ cmd = NULL;
9148 + goto out;
9149 + }
9150 +
9151 +@@ -1150,12 +1152,11 @@ static struct scsi_cmnd *NCR5380_select(struct Scsi_Host *instance,
9152 + if (err < 0) {
9153 + shost_printk(KERN_ERR, instance, "select: REQ timeout\n");
9154 + NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
9155 +- NCR5380_write(SELECT_ENABLE_REG, hostdata->id_mask);
9156 + goto out;
9157 + }
9158 + if (!hostdata->selecting) {
9159 + do_abort(instance);
9160 +- goto out;
9161 ++ return NULL;
9162 + }
9163 +
9164 + dsprintk(NDEBUG_SELECTION, instance, "target %d selected, going into MESSAGE OUT phase.\n",
9165 +@@ -1817,9 +1818,6 @@ static void NCR5380_information_transfer(struct Scsi_Host *instance)
9166 + */
9167 + NCR5380_write(TARGET_COMMAND_REG, 0);
9168 +
9169 +- /* Enable reselect interrupts */
9170 +- NCR5380_write(SELECT_ENABLE_REG, hostdata->id_mask);
9171 +-
9172 + maybe_release_dma_irq(instance);
9173 + return;
9174 + case MESSAGE_REJECT:
9175 +@@ -1851,8 +1849,6 @@ static void NCR5380_information_transfer(struct Scsi_Host *instance)
9176 + */
9177 + NCR5380_write(TARGET_COMMAND_REG, 0);
9178 +
9179 +- /* Enable reselect interrupts */
9180 +- NCR5380_write(SELECT_ENABLE_REG, hostdata->id_mask);
9181 + #ifdef SUN3_SCSI_VME
9182 + dregs->csr |= CSR_DMA_ENABLE;
9183 + #endif
9184 +@@ -1960,7 +1956,6 @@ static void NCR5380_information_transfer(struct Scsi_Host *instance)
9185 + cmd->result = DID_ERROR << 16;
9186 + complete_cmd(instance, cmd);
9187 + maybe_release_dma_irq(instance);
9188 +- NCR5380_write(SELECT_ENABLE_REG, hostdata->id_mask);
9189 + return;
9190 + }
9191 + msgout = NOP;
9192 +diff --git a/drivers/scsi/NCR5380.h b/drivers/scsi/NCR5380.h
9193 +index 31096a0b0fdd..8a6d002e6789 100644
9194 +--- a/drivers/scsi/NCR5380.h
9195 ++++ b/drivers/scsi/NCR5380.h
9196 +@@ -235,7 +235,7 @@ struct NCR5380_cmd {
9197 + #define NCR5380_PIO_CHUNK_SIZE 256
9198 +
9199 + /* Time limit (ms) to poll registers when IRQs are disabled, e.g. during PDMA */
9200 +-#define NCR5380_REG_POLL_TIME 15
9201 ++#define NCR5380_REG_POLL_TIME 10
9202 +
9203 + static inline struct scsi_cmnd *NCR5380_to_scmd(struct NCR5380_cmd *ncmd_ptr)
9204 + {
9205 +diff --git a/drivers/scsi/mac_scsi.c b/drivers/scsi/mac_scsi.c
9206 +index dd6057359d7c..643321fc152d 100644
9207 +--- a/drivers/scsi/mac_scsi.c
9208 ++++ b/drivers/scsi/mac_scsi.c
9209 +@@ -3,6 +3,8 @@
9210 + *
9211 + * Copyright 1998, Michael Schmitz <mschmitz@×××.gov>
9212 + *
9213 ++ * Copyright 2019 Finn Thain
9214 ++ *
9215 + * derived in part from:
9216 + */
9217 + /*
9218 +@@ -11,6 +13,7 @@
9219 + * Copyright 1995, Russell King
9220 + */
9221 +
9222 ++#include <linux/delay.h>
9223 + #include <linux/types.h>
9224 + #include <linux/module.h>
9225 + #include <linux/ioport.h>
9226 +@@ -52,7 +55,7 @@ static int setup_cmd_per_lun = -1;
9227 + module_param(setup_cmd_per_lun, int, 0);
9228 + static int setup_sg_tablesize = -1;
9229 + module_param(setup_sg_tablesize, int, 0);
9230 +-static int setup_use_pdma = -1;
9231 ++static int setup_use_pdma = 512;
9232 + module_param(setup_use_pdma, int, 0);
9233 + static int setup_hostid = -1;
9234 + module_param(setup_hostid, int, 0);
9235 +@@ -89,101 +92,217 @@ static int __init mac_scsi_setup(char *str)
9236 + __setup("mac5380=", mac_scsi_setup);
9237 + #endif /* !MODULE */
9238 +
9239 +-/* Pseudo DMA asm originally by Ove Edlund */
9240 +-
9241 +-#define CP_IO_TO_MEM(s,d,n) \
9242 +-__asm__ __volatile__ \
9243 +- (" cmp.w #4,%2\n" \
9244 +- " bls 8f\n" \
9245 +- " move.w %1,%%d0\n" \
9246 +- " neg.b %%d0\n" \
9247 +- " and.w #3,%%d0\n" \
9248 +- " sub.w %%d0,%2\n" \
9249 +- " bra 2f\n" \
9250 +- " 1: move.b (%0),(%1)+\n" \
9251 +- " 2: dbf %%d0,1b\n" \
9252 +- " move.w %2,%%d0\n" \
9253 +- " lsr.w #5,%%d0\n" \
9254 +- " bra 4f\n" \
9255 +- " 3: move.l (%0),(%1)+\n" \
9256 +- "31: move.l (%0),(%1)+\n" \
9257 +- "32: move.l (%0),(%1)+\n" \
9258 +- "33: move.l (%0),(%1)+\n" \
9259 +- "34: move.l (%0),(%1)+\n" \
9260 +- "35: move.l (%0),(%1)+\n" \
9261 +- "36: move.l (%0),(%1)+\n" \
9262 +- "37: move.l (%0),(%1)+\n" \
9263 +- " 4: dbf %%d0,3b\n" \
9264 +- " move.w %2,%%d0\n" \
9265 +- " lsr.w #2,%%d0\n" \
9266 +- " and.w #7,%%d0\n" \
9267 +- " bra 6f\n" \
9268 +- " 5: move.l (%0),(%1)+\n" \
9269 +- " 6: dbf %%d0,5b\n" \
9270 +- " and.w #3,%2\n" \
9271 +- " bra 8f\n" \
9272 +- " 7: move.b (%0),(%1)+\n" \
9273 +- " 8: dbf %2,7b\n" \
9274 +- " moveq.l #0, %2\n" \
9275 +- " 9: \n" \
9276 +- ".section .fixup,\"ax\"\n" \
9277 +- " .even\n" \
9278 +- "91: moveq.l #1, %2\n" \
9279 +- " jra 9b\n" \
9280 +- "94: moveq.l #4, %2\n" \
9281 +- " jra 9b\n" \
9282 +- ".previous\n" \
9283 +- ".section __ex_table,\"a\"\n" \
9284 +- " .align 4\n" \
9285 +- " .long 1b,91b\n" \
9286 +- " .long 3b,94b\n" \
9287 +- " .long 31b,94b\n" \
9288 +- " .long 32b,94b\n" \
9289 +- " .long 33b,94b\n" \
9290 +- " .long 34b,94b\n" \
9291 +- " .long 35b,94b\n" \
9292 +- " .long 36b,94b\n" \
9293 +- " .long 37b,94b\n" \
9294 +- " .long 5b,94b\n" \
9295 +- " .long 7b,91b\n" \
9296 +- ".previous" \
9297 +- : "=a"(s), "=a"(d), "=d"(n) \
9298 +- : "0"(s), "1"(d), "2"(n) \
9299 +- : "d0")
9300 ++/*
9301 ++ * According to "Inside Macintosh: Devices", Mac OS requires disk drivers to
9302 ++ * specify the number of bytes between the delays expected from a SCSI target.
9303 ++ * This allows the operating system to "prevent bus errors when a target fails
9304 ++ * to deliver the next byte within the processor bus error timeout period."
9305 ++ * Linux SCSI drivers lack knowledge of the timing behaviour of SCSI targets
9306 ++ * so bus errors are unavoidable.
9307 ++ *
9308 ++ * If a MOVE.B instruction faults, we assume that zero bytes were transferred
9309 ++ * and simply retry. That assumption probably depends on target behaviour but
9310 ++ * seems to hold up okay. The NOP provides synchronization: without it the
9311 ++ * fault can sometimes occur after the program counter has moved past the
9312 ++ * offending instruction. Post-increment addressing can't be used.
9313 ++ */
9314 ++
9315 ++#define MOVE_BYTE(operands) \
9316 ++ asm volatile ( \
9317 ++ "1: moveb " operands " \n" \
9318 ++ "11: nop \n" \
9319 ++ " addq #1,%0 \n" \
9320 ++ " subq #1,%1 \n" \
9321 ++ "40: \n" \
9322 ++ " \n" \
9323 ++ ".section .fixup,\"ax\" \n" \
9324 ++ ".even \n" \
9325 ++ "90: movel #1, %2 \n" \
9326 ++ " jra 40b \n" \
9327 ++ ".previous \n" \
9328 ++ " \n" \
9329 ++ ".section __ex_table,\"a\" \n" \
9330 ++ ".align 4 \n" \
9331 ++ ".long 1b,90b \n" \
9332 ++ ".long 11b,90b \n" \
9333 ++ ".previous \n" \
9334 ++ : "+a" (addr), "+r" (n), "+r" (result) : "a" (io))
9335 ++
9336 ++/*
9337 ++ * If a MOVE.W (or MOVE.L) instruction faults, it cannot be retried because
9338 ++ * the residual byte count would be uncertain. In that situation the MOVE_WORD
9339 ++ * macro clears n in the fixup section to abort the transfer.
9340 ++ */
9341 ++
9342 ++#define MOVE_WORD(operands) \
9343 ++ asm volatile ( \
9344 ++ "1: movew " operands " \n" \
9345 ++ "11: nop \n" \
9346 ++ " subq #2,%1 \n" \
9347 ++ "40: \n" \
9348 ++ " \n" \
9349 ++ ".section .fixup,\"ax\" \n" \
9350 ++ ".even \n" \
9351 ++ "90: movel #0, %1 \n" \
9352 ++ " movel #2, %2 \n" \
9353 ++ " jra 40b \n" \
9354 ++ ".previous \n" \
9355 ++ " \n" \
9356 ++ ".section __ex_table,\"a\" \n" \
9357 ++ ".align 4 \n" \
9358 ++ ".long 1b,90b \n" \
9359 ++ ".long 11b,90b \n" \
9360 ++ ".previous \n" \
9361 ++ : "+a" (addr), "+r" (n), "+r" (result) : "a" (io))
9362 ++
9363 ++#define MOVE_16_WORDS(operands) \
9364 ++ asm volatile ( \
9365 ++ "1: movew " operands " \n" \
9366 ++ "2: movew " operands " \n" \
9367 ++ "3: movew " operands " \n" \
9368 ++ "4: movew " operands " \n" \
9369 ++ "5: movew " operands " \n" \
9370 ++ "6: movew " operands " \n" \
9371 ++ "7: movew " operands " \n" \
9372 ++ "8: movew " operands " \n" \
9373 ++ "9: movew " operands " \n" \
9374 ++ "10: movew " operands " \n" \
9375 ++ "11: movew " operands " \n" \
9376 ++ "12: movew " operands " \n" \
9377 ++ "13: movew " operands " \n" \
9378 ++ "14: movew " operands " \n" \
9379 ++ "15: movew " operands " \n" \
9380 ++ "16: movew " operands " \n" \
9381 ++ "17: nop \n" \
9382 ++ " subl #32,%1 \n" \
9383 ++ "40: \n" \
9384 ++ " \n" \
9385 ++ ".section .fixup,\"ax\" \n" \
9386 ++ ".even \n" \
9387 ++ "90: movel #0, %1 \n" \
9388 ++ " movel #2, %2 \n" \
9389 ++ " jra 40b \n" \
9390 ++ ".previous \n" \
9391 ++ " \n" \
9392 ++ ".section __ex_table,\"a\" \n" \
9393 ++ ".align 4 \n" \
9394 ++ ".long 1b,90b \n" \
9395 ++ ".long 2b,90b \n" \
9396 ++ ".long 3b,90b \n" \
9397 ++ ".long 4b,90b \n" \
9398 ++ ".long 5b,90b \n" \
9399 ++ ".long 6b,90b \n" \
9400 ++ ".long 7b,90b \n" \
9401 ++ ".long 8b,90b \n" \
9402 ++ ".long 9b,90b \n" \
9403 ++ ".long 10b,90b \n" \
9404 ++ ".long 11b,90b \n" \
9405 ++ ".long 12b,90b \n" \
9406 ++ ".long 13b,90b \n" \
9407 ++ ".long 14b,90b \n" \
9408 ++ ".long 15b,90b \n" \
9409 ++ ".long 16b,90b \n" \
9410 ++ ".long 17b,90b \n" \
9411 ++ ".previous \n" \
9412 ++ : "+a" (addr), "+r" (n), "+r" (result) : "a" (io))
9413 ++
9414 ++#define MAC_PDMA_DELAY 32
9415 ++
9416 ++static inline int mac_pdma_recv(void __iomem *io, unsigned char *start, int n)
9417 ++{
9418 ++ unsigned char *addr = start;
9419 ++ int result = 0;
9420 ++
9421 ++ if (n >= 1) {
9422 ++ MOVE_BYTE("%3@,%0@");
9423 ++ if (result)
9424 ++ goto out;
9425 ++ }
9426 ++ if (n >= 1 && ((unsigned long)addr & 1)) {
9427 ++ MOVE_BYTE("%3@,%0@");
9428 ++ if (result)
9429 ++ goto out;
9430 ++ }
9431 ++ while (n >= 32)
9432 ++ MOVE_16_WORDS("%3@,%0@+");
9433 ++ while (n >= 2)
9434 ++ MOVE_WORD("%3@,%0@+");
9435 ++ if (result)
9436 ++ return start - addr; /* Negated to indicate uncertain length */
9437 ++ if (n == 1)
9438 ++ MOVE_BYTE("%3@,%0@");
9439 ++out:
9440 ++ return addr - start;
9441 ++}
9442 ++
9443 ++static inline int mac_pdma_send(unsigned char *start, void __iomem *io, int n)
9444 ++{
9445 ++ unsigned char *addr = start;
9446 ++ int result = 0;
9447 ++
9448 ++ if (n >= 1) {
9449 ++ MOVE_BYTE("%0@,%3@");
9450 ++ if (result)
9451 ++ goto out;
9452 ++ }
9453 ++ if (n >= 1 && ((unsigned long)addr & 1)) {
9454 ++ MOVE_BYTE("%0@,%3@");
9455 ++ if (result)
9456 ++ goto out;
9457 ++ }
9458 ++ while (n >= 32)
9459 ++ MOVE_16_WORDS("%0@+,%3@");
9460 ++ while (n >= 2)
9461 ++ MOVE_WORD("%0@+,%3@");
9462 ++ if (result)
9463 ++ return start - addr; /* Negated to indicate uncertain length */
9464 ++ if (n == 1)
9465 ++ MOVE_BYTE("%0@,%3@");
9466 ++out:
9467 ++ return addr - start;
9468 ++}
9469 +
9470 + static inline int macscsi_pread(struct NCR5380_hostdata *hostdata,
9471 + unsigned char *dst, int len)
9472 + {
9473 + u8 __iomem *s = hostdata->pdma_io + (INPUT_DATA_REG << 4);
9474 + unsigned char *d = dst;
9475 +- int n = len;
9476 +- int transferred;
9477 ++
9478 ++ hostdata->pdma_residual = len;
9479 +
9480 + while (!NCR5380_poll_politely(hostdata, BUS_AND_STATUS_REG,
9481 + BASR_DRQ | BASR_PHASE_MATCH,
9482 + BASR_DRQ | BASR_PHASE_MATCH, HZ / 64)) {
9483 +- CP_IO_TO_MEM(s, d, n);
9484 ++ int bytes;
9485 +
9486 +- transferred = d - dst - n;
9487 +- hostdata->pdma_residual = len - transferred;
9488 ++ bytes = mac_pdma_recv(s, d, min(hostdata->pdma_residual, 512));
9489 +
9490 +- /* No bus error. */
9491 +- if (n == 0)
9492 ++ if (bytes > 0) {
9493 ++ d += bytes;
9494 ++ hostdata->pdma_residual -= bytes;
9495 ++ }
9496 ++
9497 ++ if (hostdata->pdma_residual == 0)
9498 + return 0;
9499 +
9500 +- /* Target changed phase early? */
9501 + if (NCR5380_poll_politely2(hostdata, STATUS_REG, SR_REQ, SR_REQ,
9502 +- BUS_AND_STATUS_REG, BASR_ACK, BASR_ACK, HZ / 64) < 0)
9503 +- scmd_printk(KERN_ERR, hostdata->connected,
9504 ++ BUS_AND_STATUS_REG, BASR_ACK,
9505 ++ BASR_ACK, HZ / 64) < 0)
9506 ++ scmd_printk(KERN_DEBUG, hostdata->connected,
9507 + "%s: !REQ and !ACK\n", __func__);
9508 + if (!(NCR5380_read(BUS_AND_STATUS_REG) & BASR_PHASE_MATCH))
9509 + return 0;
9510 +
9511 ++ if (bytes == 0)
9512 ++ udelay(MAC_PDMA_DELAY);
9513 ++
9514 ++ if (bytes >= 0)
9515 ++ continue;
9516 ++
9517 + dsprintk(NDEBUG_PSEUDO_DMA, hostdata->host,
9518 +- "%s: bus error (%d/%d)\n", __func__, transferred, len);
9519 ++ "%s: bus error (%d/%d)\n", __func__, d - dst, len);
9520 + NCR5380_dprint(NDEBUG_PSEUDO_DMA, hostdata->host);
9521 +- d = dst + transferred;
9522 +- n = len - transferred;
9523 ++ return -1;
9524 + }
9525 +
9526 + scmd_printk(KERN_ERR, hostdata->connected,
9527 +@@ -192,93 +311,27 @@ static inline int macscsi_pread(struct NCR5380_hostdata *hostdata,
9528 + return -1;
9529 + }
9530 +
9531 +-
9532 +-#define CP_MEM_TO_IO(s,d,n) \
9533 +-__asm__ __volatile__ \
9534 +- (" cmp.w #4,%2\n" \
9535 +- " bls 8f\n" \
9536 +- " move.w %0,%%d0\n" \
9537 +- " neg.b %%d0\n" \
9538 +- " and.w #3,%%d0\n" \
9539 +- " sub.w %%d0,%2\n" \
9540 +- " bra 2f\n" \
9541 +- " 1: move.b (%0)+,(%1)\n" \
9542 +- " 2: dbf %%d0,1b\n" \
9543 +- " move.w %2,%%d0\n" \
9544 +- " lsr.w #5,%%d0\n" \
9545 +- " bra 4f\n" \
9546 +- " 3: move.l (%0)+,(%1)\n" \
9547 +- "31: move.l (%0)+,(%1)\n" \
9548 +- "32: move.l (%0)+,(%1)\n" \
9549 +- "33: move.l (%0)+,(%1)\n" \
9550 +- "34: move.l (%0)+,(%1)\n" \
9551 +- "35: move.l (%0)+,(%1)\n" \
9552 +- "36: move.l (%0)+,(%1)\n" \
9553 +- "37: move.l (%0)+,(%1)\n" \
9554 +- " 4: dbf %%d0,3b\n" \
9555 +- " move.w %2,%%d0\n" \
9556 +- " lsr.w #2,%%d0\n" \
9557 +- " and.w #7,%%d0\n" \
9558 +- " bra 6f\n" \
9559 +- " 5: move.l (%0)+,(%1)\n" \
9560 +- " 6: dbf %%d0,5b\n" \
9561 +- " and.w #3,%2\n" \
9562 +- " bra 8f\n" \
9563 +- " 7: move.b (%0)+,(%1)\n" \
9564 +- " 8: dbf %2,7b\n" \
9565 +- " moveq.l #0, %2\n" \
9566 +- " 9: \n" \
9567 +- ".section .fixup,\"ax\"\n" \
9568 +- " .even\n" \
9569 +- "91: moveq.l #1, %2\n" \
9570 +- " jra 9b\n" \
9571 +- "94: moveq.l #4, %2\n" \
9572 +- " jra 9b\n" \
9573 +- ".previous\n" \
9574 +- ".section __ex_table,\"a\"\n" \
9575 +- " .align 4\n" \
9576 +- " .long 1b,91b\n" \
9577 +- " .long 3b,94b\n" \
9578 +- " .long 31b,94b\n" \
9579 +- " .long 32b,94b\n" \
9580 +- " .long 33b,94b\n" \
9581 +- " .long 34b,94b\n" \
9582 +- " .long 35b,94b\n" \
9583 +- " .long 36b,94b\n" \
9584 +- " .long 37b,94b\n" \
9585 +- " .long 5b,94b\n" \
9586 +- " .long 7b,91b\n" \
9587 +- ".previous" \
9588 +- : "=a"(s), "=a"(d), "=d"(n) \
9589 +- : "0"(s), "1"(d), "2"(n) \
9590 +- : "d0")
9591 +-
9592 + static inline int macscsi_pwrite(struct NCR5380_hostdata *hostdata,
9593 + unsigned char *src, int len)
9594 + {
9595 + unsigned char *s = src;
9596 + u8 __iomem *d = hostdata->pdma_io + (OUTPUT_DATA_REG << 4);
9597 +- int n = len;
9598 +- int transferred;
9599 ++
9600 ++ hostdata->pdma_residual = len;
9601 +
9602 + while (!NCR5380_poll_politely(hostdata, BUS_AND_STATUS_REG,
9603 + BASR_DRQ | BASR_PHASE_MATCH,
9604 + BASR_DRQ | BASR_PHASE_MATCH, HZ / 64)) {
9605 +- CP_MEM_TO_IO(s, d, n);
9606 ++ int bytes;
9607 +
9608 +- transferred = s - src - n;
9609 +- hostdata->pdma_residual = len - transferred;
9610 ++ bytes = mac_pdma_send(s, d, min(hostdata->pdma_residual, 512));
9611 +
9612 +- /* Target changed phase early? */
9613 +- if (NCR5380_poll_politely2(hostdata, STATUS_REG, SR_REQ, SR_REQ,
9614 +- BUS_AND_STATUS_REG, BASR_ACK, BASR_ACK, HZ / 64) < 0)
9615 +- scmd_printk(KERN_ERR, hostdata->connected,
9616 +- "%s: !REQ and !ACK\n", __func__);
9617 +- if (!(NCR5380_read(BUS_AND_STATUS_REG) & BASR_PHASE_MATCH))
9618 +- return 0;
9619 ++ if (bytes > 0) {
9620 ++ s += bytes;
9621 ++ hostdata->pdma_residual -= bytes;
9622 ++ }
9623 +
9624 +- /* No bus error. */
9625 +- if (n == 0) {
9626 ++ if (hostdata->pdma_residual == 0) {
9627 + if (NCR5380_poll_politely(hostdata, TARGET_COMMAND_REG,
9628 + TCR_LAST_BYTE_SENT,
9629 + TCR_LAST_BYTE_SENT, HZ / 64) < 0)
9630 +@@ -287,17 +340,29 @@ static inline int macscsi_pwrite(struct NCR5380_hostdata *hostdata,
9631 + return 0;
9632 + }
9633 +
9634 ++ if (NCR5380_poll_politely2(hostdata, STATUS_REG, SR_REQ, SR_REQ,
9635 ++ BUS_AND_STATUS_REG, BASR_ACK,
9636 ++ BASR_ACK, HZ / 64) < 0)
9637 ++ scmd_printk(KERN_DEBUG, hostdata->connected,
9638 ++ "%s: !REQ and !ACK\n", __func__);
9639 ++ if (!(NCR5380_read(BUS_AND_STATUS_REG) & BASR_PHASE_MATCH))
9640 ++ return 0;
9641 ++
9642 ++ if (bytes == 0)
9643 ++ udelay(MAC_PDMA_DELAY);
9644 ++
9645 ++ if (bytes >= 0)
9646 ++ continue;
9647 ++
9648 + dsprintk(NDEBUG_PSEUDO_DMA, hostdata->host,
9649 +- "%s: bus error (%d/%d)\n", __func__, transferred, len);
9650 ++ "%s: bus error (%d/%d)\n", __func__, s - src, len);
9651 + NCR5380_dprint(NDEBUG_PSEUDO_DMA, hostdata->host);
9652 +- s = src + transferred;
9653 +- n = len - transferred;
9654 ++ return -1;
9655 + }
9656 +
9657 + scmd_printk(KERN_ERR, hostdata->connected,
9658 + "%s: phase mismatch or !DRQ\n", __func__);
9659 + NCR5380_dprint(NDEBUG_PSEUDO_DMA, hostdata->host);
9660 +-
9661 + return -1;
9662 + }
9663 +
9664 +@@ -305,7 +370,7 @@ static int macscsi_dma_xfer_len(struct NCR5380_hostdata *hostdata,
9665 + struct scsi_cmnd *cmd)
9666 + {
9667 + if (hostdata->flags & FLAG_NO_PSEUDO_DMA ||
9668 +- cmd->SCp.this_residual < 16)
9669 ++ cmd->SCp.this_residual < setup_use_pdma)
9670 + return 0;
9671 +
9672 + return cmd->SCp.this_residual;
9673 +diff --git a/drivers/scsi/megaraid/megaraid_sas_base.c b/drivers/scsi/megaraid/megaraid_sas_base.c
9674 +index 7f1ecd264652..73acd3e9ded7 100644
9675 +--- a/drivers/scsi/megaraid/megaraid_sas_base.c
9676 ++++ b/drivers/scsi/megaraid/megaraid_sas_base.c
9677 +@@ -5806,7 +5806,8 @@ megasas_get_target_prop(struct megasas_instance *instance,
9678 + int ret;
9679 + struct megasas_cmd *cmd;
9680 + struct megasas_dcmd_frame *dcmd;
9681 +- u16 targetId = (sdev->channel % 2) + sdev->id;
9682 ++ u16 targetId = ((sdev->channel % 2) * MEGASAS_MAX_DEV_PER_CHANNEL) +
9683 ++ sdev->id;
9684 +
9685 + cmd = megasas_get_cmd(instance);
9686 +
9687 +diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
9688 +index c89f0e129f58..efb8af57dd9c 100644
9689 +--- a/drivers/scsi/scsi_lib.c
9690 ++++ b/drivers/scsi/scsi_lib.c
9691 +@@ -71,11 +71,11 @@ int scsi_init_sense_cache(struct Scsi_Host *shost)
9692 + struct kmem_cache *cache;
9693 + int ret = 0;
9694 +
9695 ++ mutex_lock(&scsi_sense_cache_mutex);
9696 + cache = scsi_select_sense_cache(shost->unchecked_isa_dma);
9697 + if (cache)
9698 +- return 0;
9699 ++ goto exit;
9700 +
9701 +- mutex_lock(&scsi_sense_cache_mutex);
9702 + if (shost->unchecked_isa_dma) {
9703 + scsi_sense_isadma_cache =
9704 + kmem_cache_create("scsi_sense_cache(DMA)",
9705 +@@ -90,7 +90,7 @@ int scsi_init_sense_cache(struct Scsi_Host *shost)
9706 + if (!scsi_sense_cache)
9707 + ret = -ENOMEM;
9708 + }
9709 +-
9710 ++ exit:
9711 + mutex_unlock(&scsi_sense_cache_mutex);
9712 + return ret;
9713 + }
9714 +diff --git a/drivers/staging/media/davinci_vpfe/vpfe_video.c b/drivers/staging/media/davinci_vpfe/vpfe_video.c
9715 +index 155e8c758e4b..346e60d230f3 100644
9716 +--- a/drivers/staging/media/davinci_vpfe/vpfe_video.c
9717 ++++ b/drivers/staging/media/davinci_vpfe/vpfe_video.c
9718 +@@ -422,6 +422,9 @@ static int vpfe_open(struct file *file)
9719 + /* If decoder is not initialized. initialize it */
9720 + if (!video->initialized && vpfe_update_pipe_state(video)) {
9721 + mutex_unlock(&video->lock);
9722 ++ v4l2_fh_del(&handle->vfh);
9723 ++ v4l2_fh_exit(&handle->vfh);
9724 ++ kfree(handle);
9725 + return -ENODEV;
9726 + }
9727 + /* Increment device users counter */
9728 +diff --git a/drivers/target/iscsi/iscsi_target_auth.c b/drivers/target/iscsi/iscsi_target_auth.c
9729 +index 4e680d753941..e2fa3a3bc81d 100644
9730 +--- a/drivers/target/iscsi/iscsi_target_auth.c
9731 ++++ b/drivers/target/iscsi/iscsi_target_auth.c
9732 +@@ -89,6 +89,12 @@ out:
9733 + return CHAP_DIGEST_UNKNOWN;
9734 + }
9735 +
9736 ++static void chap_close(struct iscsi_conn *conn)
9737 ++{
9738 ++ kfree(conn->auth_protocol);
9739 ++ conn->auth_protocol = NULL;
9740 ++}
9741 ++
9742 + static struct iscsi_chap *chap_server_open(
9743 + struct iscsi_conn *conn,
9744 + struct iscsi_node_auth *auth,
9745 +@@ -126,7 +132,7 @@ static struct iscsi_chap *chap_server_open(
9746 + case CHAP_DIGEST_UNKNOWN:
9747 + default:
9748 + pr_err("Unsupported CHAP_A value\n");
9749 +- kfree(conn->auth_protocol);
9750 ++ chap_close(conn);
9751 + return NULL;
9752 + }
9753 +
9754 +@@ -141,19 +147,13 @@ static struct iscsi_chap *chap_server_open(
9755 + * Generate Challenge.
9756 + */
9757 + if (chap_gen_challenge(conn, 1, aic_str, aic_len) < 0) {
9758 +- kfree(conn->auth_protocol);
9759 ++ chap_close(conn);
9760 + return NULL;
9761 + }
9762 +
9763 + return chap;
9764 + }
9765 +
9766 +-static void chap_close(struct iscsi_conn *conn)
9767 +-{
9768 +- kfree(conn->auth_protocol);
9769 +- conn->auth_protocol = NULL;
9770 +-}
9771 +-
9772 + static int chap_server_compute_md5(
9773 + struct iscsi_conn *conn,
9774 + struct iscsi_node_auth *auth,
9775 +diff --git a/drivers/tty/serial/8250/8250_port.c b/drivers/tty/serial/8250/8250_port.c
9776 +index ab0796d14ac1..a73d2bc4b685 100644
9777 +--- a/drivers/tty/serial/8250/8250_port.c
9778 ++++ b/drivers/tty/serial/8250/8250_port.c
9779 +@@ -1878,7 +1878,8 @@ int serial8250_handle_irq(struct uart_port *port, unsigned int iir)
9780 + status = serial8250_rx_chars(up, status);
9781 + }
9782 + serial8250_modem_status(up);
9783 +- if ((!up->dma || up->dma->tx_err) && (status & UART_LSR_THRE))
9784 ++ if ((!up->dma || up->dma->tx_err) && (status & UART_LSR_THRE) &&
9785 ++ (up->ier & UART_IER_THRI))
9786 + serial8250_tx_chars(up);
9787 +
9788 + spin_unlock_irqrestore(&port->lock, flags);
9789 +diff --git a/drivers/tty/serial/cpm_uart/cpm_uart_core.c b/drivers/tty/serial/cpm_uart/cpm_uart_core.c
9790 +index 8b2b694334ec..8f5a5a16cb3b 100644
9791 +--- a/drivers/tty/serial/cpm_uart/cpm_uart_core.c
9792 ++++ b/drivers/tty/serial/cpm_uart/cpm_uart_core.c
9793 +@@ -421,7 +421,16 @@ static int cpm_uart_startup(struct uart_port *port)
9794 + clrbits16(&pinfo->sccp->scc_sccm, UART_SCCM_RX);
9795 + }
9796 + cpm_uart_initbd(pinfo);
9797 +- cpm_line_cr_cmd(pinfo, CPM_CR_INIT_TRX);
9798 ++ if (IS_SMC(pinfo)) {
9799 ++ out_be32(&pinfo->smcup->smc_rstate, 0);
9800 ++ out_be32(&pinfo->smcup->smc_tstate, 0);
9801 ++ out_be16(&pinfo->smcup->smc_rbptr,
9802 ++ in_be16(&pinfo->smcup->smc_rbase));
9803 ++ out_be16(&pinfo->smcup->smc_tbptr,
9804 ++ in_be16(&pinfo->smcup->smc_tbase));
9805 ++ } else {
9806 ++ cpm_line_cr_cmd(pinfo, CPM_CR_INIT_TRX);
9807 ++ }
9808 + }
9809 + /* Install interrupt handler. */
9810 + retval = request_irq(port->irq, cpm_uart_int, 0, "cpm_uart", port);
9811 +@@ -875,16 +884,14 @@ static void cpm_uart_init_smc(struct uart_cpm_port *pinfo)
9812 + (u8 __iomem *)pinfo->tx_bd_base - DPRAM_BASE);
9813 +
9814 + /*
9815 +- * In case SMC1 is being relocated...
9816 ++ * In case SMC is being relocated...
9817 + */
9818 +-#if defined (CONFIG_I2C_SPI_SMC1_UCODE_PATCH)
9819 + out_be16(&up->smc_rbptr, in_be16(&pinfo->smcup->smc_rbase));
9820 + out_be16(&up->smc_tbptr, in_be16(&pinfo->smcup->smc_tbase));
9821 + out_be32(&up->smc_rstate, 0);
9822 + out_be32(&up->smc_tstate, 0);
9823 + out_be16(&up->smc_brkcr, 1); /* number of break chars */
9824 + out_be16(&up->smc_brkec, 0);
9825 +-#endif
9826 +
9827 + /* Set up the uart parameters in the
9828 + * parameter ram.
9829 +@@ -898,8 +905,6 @@ static void cpm_uart_init_smc(struct uart_cpm_port *pinfo)
9830 + out_be16(&up->smc_brkec, 0);
9831 + out_be16(&up->smc_brkcr, 1);
9832 +
9833 +- cpm_line_cr_cmd(pinfo, CPM_CR_INIT_TRX);
9834 +-
9835 + /* Set UART mode, 8 bit, no parity, one stop.
9836 + * Enable receive and transmit.
9837 + */
9838 +diff --git a/drivers/tty/serial/digicolor-usart.c b/drivers/tty/serial/digicolor-usart.c
9839 +index 02ad6953b167..50ec5f1ac77f 100644
9840 +--- a/drivers/tty/serial/digicolor-usart.c
9841 ++++ b/drivers/tty/serial/digicolor-usart.c
9842 +@@ -545,7 +545,11 @@ static int __init digicolor_uart_init(void)
9843 + if (ret)
9844 + return ret;
9845 +
9846 +- return platform_driver_register(&digicolor_uart_platform);
9847 ++ ret = platform_driver_register(&digicolor_uart_platform);
9848 ++ if (ret)
9849 ++ uart_unregister_driver(&digicolor_uart);
9850 ++
9851 ++ return ret;
9852 + }
9853 + module_init(digicolor_uart_init);
9854 +
9855 +diff --git a/drivers/tty/serial/max310x.c b/drivers/tty/serial/max310x.c
9856 +index 1a98b6631e90..0969a0d97b2b 100644
9857 +--- a/drivers/tty/serial/max310x.c
9858 ++++ b/drivers/tty/serial/max310x.c
9859 +@@ -494,37 +494,48 @@ static bool max310x_reg_precious(struct device *dev, unsigned int reg)
9860 +
9861 + static int max310x_set_baud(struct uart_port *port, int baud)
9862 + {
9863 +- unsigned int mode = 0, clk = port->uartclk, div = clk / baud;
9864 ++ unsigned int mode = 0, div = 0, frac = 0, c = 0, F = 0;
9865 +
9866 +- /* Check for minimal value for divider */
9867 +- if (div < 16)
9868 +- div = 16;
9869 +-
9870 +- if (clk % baud && (div / 16) < 0x8000) {
9871 ++ /*
9872 ++ * Calculate the integer divisor first. Select a proper mode
9873 ++ * in case if the requested baud is too high for the pre-defined
9874 ++ * clocks frequency.
9875 ++ */
9876 ++ div = port->uartclk / baud;
9877 ++ if (div < 8) {
9878 ++ /* Mode x4 */
9879 ++ c = 4;
9880 ++ mode = MAX310X_BRGCFG_4XMODE_BIT;
9881 ++ } else if (div < 16) {
9882 + /* Mode x2 */
9883 ++ c = 8;
9884 + mode = MAX310X_BRGCFG_2XMODE_BIT;
9885 +- clk = port->uartclk * 2;
9886 +- div = clk / baud;
9887 +-
9888 +- if (clk % baud && (div / 16) < 0x8000) {
9889 +- /* Mode x4 */
9890 +- mode = MAX310X_BRGCFG_4XMODE_BIT;
9891 +- clk = port->uartclk * 4;
9892 +- div = clk / baud;
9893 +- }
9894 ++ } else {
9895 ++ c = 16;
9896 + }
9897 +
9898 +- max310x_port_write(port, MAX310X_BRGDIVMSB_REG, (div / 16) >> 8);
9899 +- max310x_port_write(port, MAX310X_BRGDIVLSB_REG, div / 16);
9900 +- max310x_port_write(port, MAX310X_BRGCFG_REG, (div % 16) | mode);
9901 ++ /* Calculate the divisor in accordance with the fraction coefficient */
9902 ++ div /= c;
9903 ++ F = c*baud;
9904 ++
9905 ++ /* Calculate the baud rate fraction */
9906 ++ if (div > 0)
9907 ++ frac = (16*(port->uartclk % F)) / F;
9908 ++ else
9909 ++ div = 1;
9910 ++
9911 ++ max310x_port_write(port, MAX310X_BRGDIVMSB_REG, div >> 8);
9912 ++ max310x_port_write(port, MAX310X_BRGDIVLSB_REG, div);
9913 ++ max310x_port_write(port, MAX310X_BRGCFG_REG, frac | mode);
9914 +
9915 +- return DIV_ROUND_CLOSEST(clk, div);
9916 ++ /* Return the actual baud rate we just programmed */
9917 ++ return (16*port->uartclk) / (c*(16*div + frac));
9918 + }
9919 +
9920 + static int max310x_update_best_err(unsigned long f, long *besterr)
9921 + {
9922 + /* Use baudrate 115200 for calculate error */
9923 +- long err = f % (115200 * 16);
9924 ++ long err = f % (460800 * 16);
9925 +
9926 + if ((*besterr < 0) || (*besterr > err)) {
9927 + *besterr = err;
9928 +diff --git a/drivers/tty/serial/msm_serial.c b/drivers/tty/serial/msm_serial.c
9929 +index 716aa76abdf9..0e0ccc132ab0 100644
9930 +--- a/drivers/tty/serial/msm_serial.c
9931 ++++ b/drivers/tty/serial/msm_serial.c
9932 +@@ -391,10 +391,14 @@ no_rx:
9933 +
9934 + static inline void msm_wait_for_xmitr(struct uart_port *port)
9935 + {
9936 ++ unsigned int timeout = 500000;
9937 ++
9938 + while (!(msm_read(port, UART_SR) & UART_SR_TX_EMPTY)) {
9939 + if (msm_read(port, UART_ISR) & UART_ISR_TX_READY)
9940 + break;
9941 + udelay(1);
9942 ++ if (!timeout--)
9943 ++ break;
9944 + }
9945 + msm_write(port, UART_CR_CMD_RESET_TX_READY, UART_CR);
9946 + }
9947 +diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
9948 +index c39246b916af..17e2311f7b00 100644
9949 +--- a/drivers/tty/serial/serial_core.c
9950 ++++ b/drivers/tty/serial/serial_core.c
9951 +@@ -1742,6 +1742,7 @@ static int uart_port_activate(struct tty_port *port, struct tty_struct *tty)
9952 + {
9953 + struct uart_state *state = container_of(port, struct uart_state, port);
9954 + struct uart_port *uport;
9955 ++ int ret;
9956 +
9957 + uport = uart_port_check(state);
9958 + if (!uport || uport->flags & UPF_DEAD)
9959 +@@ -1752,7 +1753,11 @@ static int uart_port_activate(struct tty_port *port, struct tty_struct *tty)
9960 + /*
9961 + * Start up the serial port.
9962 + */
9963 +- return uart_startup(tty, state, 0);
9964 ++ ret = uart_startup(tty, state, 0);
9965 ++ if (ret > 0)
9966 ++ tty_port_set_active(port, 1);
9967 ++
9968 ++ return ret;
9969 + }
9970 +
9971 + static const char *uart_type(struct uart_port *port)
9972 +diff --git a/drivers/tty/serial/serial_mctrl_gpio.c b/drivers/tty/serial/serial_mctrl_gpio.c
9973 +index d2da6aa7f27d..42e42e3e7a6e 100644
9974 +--- a/drivers/tty/serial/serial_mctrl_gpio.c
9975 ++++ b/drivers/tty/serial/serial_mctrl_gpio.c
9976 +@@ -21,6 +21,7 @@
9977 + #include <linux/termios.h>
9978 + #include <linux/serial_core.h>
9979 + #include <linux/module.h>
9980 ++#include <linux/property.h>
9981 +
9982 + #include "serial_mctrl_gpio.h"
9983 +
9984 +@@ -124,6 +125,19 @@ struct mctrl_gpios *mctrl_gpio_init_noauto(struct device *dev, unsigned int idx)
9985 +
9986 + for (i = 0; i < UART_GPIO_MAX; i++) {
9987 + enum gpiod_flags flags;
9988 ++ char *gpio_str;
9989 ++ bool present;
9990 ++
9991 ++ /* Check if GPIO property exists and continue if not */
9992 ++ gpio_str = kasprintf(GFP_KERNEL, "%s-gpios",
9993 ++ mctrl_gpios_desc[i].name);
9994 ++ if (!gpio_str)
9995 ++ continue;
9996 ++
9997 ++ present = device_property_present(dev, gpio_str);
9998 ++ kfree(gpio_str);
9999 ++ if (!present)
10000 ++ continue;
10001 +
10002 + if (mctrl_gpios_desc[i].dir_out)
10003 + flags = GPIOD_OUT_LOW;
10004 +diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c
10005 +index 66c8bbea06c4..333de7d3fe86 100644
10006 +--- a/drivers/tty/serial/sh-sci.c
10007 ++++ b/drivers/tty/serial/sh-sci.c
10008 +@@ -1319,6 +1319,7 @@ static void work_fn_tx(struct work_struct *work)
10009 + struct uart_port *port = &s->port;
10010 + struct circ_buf *xmit = &port->state->xmit;
10011 + dma_addr_t buf;
10012 ++ int head, tail;
10013 +
10014 + /*
10015 + * DMA is idle now.
10016 +@@ -1328,16 +1329,23 @@ static void work_fn_tx(struct work_struct *work)
10017 + * consistent xmit buffer state.
10018 + */
10019 + spin_lock_irq(&port->lock);
10020 +- buf = s->tx_dma_addr + (xmit->tail & (UART_XMIT_SIZE - 1));
10021 ++ head = xmit->head;
10022 ++ tail = xmit->tail;
10023 ++ buf = s->tx_dma_addr + (tail & (UART_XMIT_SIZE - 1));
10024 + s->tx_dma_len = min_t(unsigned int,
10025 +- CIRC_CNT(xmit->head, xmit->tail, UART_XMIT_SIZE),
10026 +- CIRC_CNT_TO_END(xmit->head, xmit->tail, UART_XMIT_SIZE));
10027 +- spin_unlock_irq(&port->lock);
10028 ++ CIRC_CNT(head, tail, UART_XMIT_SIZE),
10029 ++ CIRC_CNT_TO_END(head, tail, UART_XMIT_SIZE));
10030 ++ if (!s->tx_dma_len) {
10031 ++ /* Transmit buffer has been flushed */
10032 ++ spin_unlock_irq(&port->lock);
10033 ++ return;
10034 ++ }
10035 +
10036 + desc = dmaengine_prep_slave_single(chan, buf, s->tx_dma_len,
10037 + DMA_MEM_TO_DEV,
10038 + DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
10039 + if (!desc) {
10040 ++ spin_unlock_irq(&port->lock);
10041 + dev_warn(port->dev, "Failed preparing Tx DMA descriptor\n");
10042 + /* switch to PIO */
10043 + sci_tx_dma_release(s, true);
10044 +@@ -1347,20 +1355,20 @@ static void work_fn_tx(struct work_struct *work)
10045 + dma_sync_single_for_device(chan->device->dev, buf, s->tx_dma_len,
10046 + DMA_TO_DEVICE);
10047 +
10048 +- spin_lock_irq(&port->lock);
10049 + desc->callback = sci_dma_tx_complete;
10050 + desc->callback_param = s;
10051 +- spin_unlock_irq(&port->lock);
10052 + s->cookie_tx = dmaengine_submit(desc);
10053 + if (dma_submit_error(s->cookie_tx)) {
10054 ++ spin_unlock_irq(&port->lock);
10055 + dev_warn(port->dev, "Failed submitting Tx DMA descriptor\n");
10056 + /* switch to PIO */
10057 + sci_tx_dma_release(s, true);
10058 + return;
10059 + }
10060 +
10061 ++ spin_unlock_irq(&port->lock);
10062 + dev_dbg(port->dev, "%s: %p: %d...%d, cookie %d\n",
10063 +- __func__, xmit->buf, xmit->tail, xmit->head, s->cookie_tx);
10064 ++ __func__, xmit->buf, tail, head, s->cookie_tx);
10065 +
10066 + dma_async_issue_pending(chan);
10067 + }
10068 +@@ -1571,11 +1579,18 @@ static void sci_free_dma(struct uart_port *port)
10069 +
10070 + static void sci_flush_buffer(struct uart_port *port)
10071 + {
10072 ++ struct sci_port *s = to_sci_port(port);
10073 ++
10074 + /*
10075 + * In uart_flush_buffer(), the xmit circular buffer has just been
10076 +- * cleared, so we have to reset tx_dma_len accordingly.
10077 ++ * cleared, so we have to reset tx_dma_len accordingly, and stop any
10078 ++ * pending transfers
10079 + */
10080 +- to_sci_port(port)->tx_dma_len = 0;
10081 ++ s->tx_dma_len = 0;
10082 ++ if (s->chan_tx) {
10083 ++ dmaengine_terminate_async(s->chan_tx);
10084 ++ s->cookie_tx = -EINVAL;
10085 ++ }
10086 + }
10087 + #else /* !CONFIG_SERIAL_SH_SCI_DMA */
10088 + static inline void sci_request_dma(struct uart_port *port)
10089 +diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
10090 +index eddecaf1f0b2..b543a4730ef2 100644
10091 +--- a/drivers/usb/core/hub.c
10092 ++++ b/drivers/usb/core/hub.c
10093 +@@ -3532,6 +3532,7 @@ static int hub_handle_remote_wakeup(struct usb_hub *hub, unsigned int port,
10094 + struct usb_device *hdev;
10095 + struct usb_device *udev;
10096 + int connect_change = 0;
10097 ++ u16 link_state;
10098 + int ret;
10099 +
10100 + hdev = hub->hdev;
10101 +@@ -3541,9 +3542,11 @@ static int hub_handle_remote_wakeup(struct usb_hub *hub, unsigned int port,
10102 + return 0;
10103 + usb_clear_port_feature(hdev, port, USB_PORT_FEAT_C_SUSPEND);
10104 + } else {
10105 ++ link_state = portstatus & USB_PORT_STAT_LINK_STATE;
10106 + if (!udev || udev->state != USB_STATE_SUSPENDED ||
10107 +- (portstatus & USB_PORT_STAT_LINK_STATE) !=
10108 +- USB_SS_PORT_LS_U0)
10109 ++ (link_state != USB_SS_PORT_LS_U0 &&
10110 ++ link_state != USB_SS_PORT_LS_U1 &&
10111 ++ link_state != USB_SS_PORT_LS_U2))
10112 + return 0;
10113 + }
10114 +
10115 +@@ -3873,6 +3876,9 @@ static int usb_set_lpm_timeout(struct usb_device *udev,
10116 + * control transfers to set the hub timeout or enable device-initiated U1/U2
10117 + * will be successful.
10118 + *
10119 ++ * If the control transfer to enable device-initiated U1/U2 entry fails, then
10120 ++ * hub-initiated U1/U2 will be disabled.
10121 ++ *
10122 + * If we cannot set the parent hub U1/U2 timeout, we attempt to let the xHCI
10123 + * driver know about it. If that call fails, it should be harmless, and just
10124 + * take up more slightly more bus bandwidth for unnecessary U1/U2 exit latency.
10125 +@@ -3927,23 +3933,24 @@ static void usb_enable_link_state(struct usb_hcd *hcd, struct usb_device *udev,
10126 + * host know that this link state won't be enabled.
10127 + */
10128 + hcd->driver->disable_usb3_lpm_timeout(hcd, udev, state);
10129 +- } else {
10130 +- /* Only a configured device will accept the Set Feature
10131 +- * U1/U2_ENABLE
10132 +- */
10133 +- if (udev->actconfig)
10134 +- usb_set_device_initiated_lpm(udev, state, true);
10135 ++ return;
10136 ++ }
10137 +
10138 +- /* As soon as usb_set_lpm_timeout(timeout) returns 0, the
10139 +- * hub-initiated LPM is enabled. Thus, LPM is enabled no
10140 +- * matter the result of usb_set_device_initiated_lpm().
10141 +- * The only difference is whether device is able to initiate
10142 +- * LPM.
10143 +- */
10144 ++ /* Only a configured device will accept the Set Feature
10145 ++ * U1/U2_ENABLE
10146 ++ */
10147 ++ if (udev->actconfig &&
10148 ++ usb_set_device_initiated_lpm(udev, state, true) == 0) {
10149 + if (state == USB3_LPM_U1)
10150 + udev->usb3_lpm_u1_enabled = 1;
10151 + else if (state == USB3_LPM_U2)
10152 + udev->usb3_lpm_u2_enabled = 1;
10153 ++ } else {
10154 ++ /* Don't request U1/U2 entry if the device
10155 ++ * cannot transition to U1/U2.
10156 ++ */
10157 ++ usb_set_lpm_timeout(udev, state, 0);
10158 ++ hcd->driver->disable_usb3_lpm_timeout(hcd, udev, state);
10159 + }
10160 + }
10161 +
10162 +diff --git a/drivers/usb/gadget/function/f_fs.c b/drivers/usb/gadget/function/f_fs.c
10163 +index 79900c0b4f3a..cdffbe999500 100644
10164 +--- a/drivers/usb/gadget/function/f_fs.c
10165 ++++ b/drivers/usb/gadget/function/f_fs.c
10166 +@@ -1102,11 +1102,12 @@ static ssize_t ffs_epfile_write_iter(struct kiocb *kiocb, struct iov_iter *from)
10167 + ENTER();
10168 +
10169 + if (!is_sync_kiocb(kiocb)) {
10170 +- p = kmalloc(sizeof(io_data), GFP_KERNEL);
10171 ++ p = kzalloc(sizeof(io_data), GFP_KERNEL);
10172 + if (unlikely(!p))
10173 + return -ENOMEM;
10174 + p->aio = true;
10175 + } else {
10176 ++ memset(p, 0, sizeof(*p));
10177 + p->aio = false;
10178 + }
10179 +
10180 +@@ -1138,11 +1139,12 @@ static ssize_t ffs_epfile_read_iter(struct kiocb *kiocb, struct iov_iter *to)
10181 + ENTER();
10182 +
10183 + if (!is_sync_kiocb(kiocb)) {
10184 +- p = kmalloc(sizeof(io_data), GFP_KERNEL);
10185 ++ p = kzalloc(sizeof(io_data), GFP_KERNEL);
10186 + if (unlikely(!p))
10187 + return -ENOMEM;
10188 + p->aio = true;
10189 + } else {
10190 ++ memset(p, 0, sizeof(*p));
10191 + p->aio = false;
10192 + }
10193 +
10194 +diff --git a/drivers/usb/host/hwa-hc.c b/drivers/usb/host/hwa-hc.c
10195 +index 216069c396a0..aa654b86993d 100644
10196 +--- a/drivers/usb/host/hwa-hc.c
10197 ++++ b/drivers/usb/host/hwa-hc.c
10198 +@@ -173,7 +173,7 @@ out:
10199 + return result;
10200 +
10201 + error_set_cluster_id:
10202 +- wusb_cluster_id_put(wusbhc->cluster_id);
10203 ++ wusb_cluster_id_put(addr);
10204 + error_cluster_id_get:
10205 + goto out;
10206 +
10207 +diff --git a/drivers/usb/host/pci-quirks.c b/drivers/usb/host/pci-quirks.c
10208 +index e1faee1f8602..f5f2c83a2c66 100644
10209 +--- a/drivers/usb/host/pci-quirks.c
10210 ++++ b/drivers/usb/host/pci-quirks.c
10211 +@@ -204,7 +204,7 @@ int usb_amd_find_chipset_info(void)
10212 + {
10213 + unsigned long flags;
10214 + struct amd_chipset_info info;
10215 +- int ret;
10216 ++ int need_pll_quirk = 0;
10217 +
10218 + spin_lock_irqsave(&amd_lock, flags);
10219 +
10220 +@@ -218,21 +218,28 @@ int usb_amd_find_chipset_info(void)
10221 + spin_unlock_irqrestore(&amd_lock, flags);
10222 +
10223 + if (!amd_chipset_sb_type_init(&info)) {
10224 +- ret = 0;
10225 + goto commit;
10226 + }
10227 +
10228 +- /* Below chipset generations needn't enable AMD PLL quirk */
10229 +- if (info.sb_type.gen == AMD_CHIPSET_UNKNOWN ||
10230 +- info.sb_type.gen == AMD_CHIPSET_SB600 ||
10231 +- info.sb_type.gen == AMD_CHIPSET_YANGTZE ||
10232 +- (info.sb_type.gen == AMD_CHIPSET_SB700 &&
10233 +- info.sb_type.rev > 0x3b)) {
10234 ++ switch (info.sb_type.gen) {
10235 ++ case AMD_CHIPSET_SB700:
10236 ++ need_pll_quirk = info.sb_type.rev <= 0x3B;
10237 ++ break;
10238 ++ case AMD_CHIPSET_SB800:
10239 ++ case AMD_CHIPSET_HUDSON2:
10240 ++ case AMD_CHIPSET_BOLTON:
10241 ++ need_pll_quirk = 1;
10242 ++ break;
10243 ++ default:
10244 ++ need_pll_quirk = 0;
10245 ++ break;
10246 ++ }
10247 ++
10248 ++ if (!need_pll_quirk) {
10249 + if (info.smbus_dev) {
10250 + pci_dev_put(info.smbus_dev);
10251 + info.smbus_dev = NULL;
10252 + }
10253 +- ret = 0;
10254 + goto commit;
10255 + }
10256 +
10257 +@@ -251,7 +258,7 @@ int usb_amd_find_chipset_info(void)
10258 + }
10259 + }
10260 +
10261 +- ret = info.probe_result = 1;
10262 ++ need_pll_quirk = info.probe_result = 1;
10263 + printk(KERN_DEBUG "QUIRK: Enable AMD PLL fix\n");
10264 +
10265 + commit:
10266 +@@ -262,7 +269,7 @@ commit:
10267 +
10268 + /* Mark that we where here */
10269 + amd_chipset.probe_count++;
10270 +- ret = amd_chipset.probe_result;
10271 ++ need_pll_quirk = amd_chipset.probe_result;
10272 +
10273 + spin_unlock_irqrestore(&amd_lock, flags);
10274 +
10275 +@@ -276,7 +283,7 @@ commit:
10276 + spin_unlock_irqrestore(&amd_lock, flags);
10277 + }
10278 +
10279 +- return ret;
10280 ++ return need_pll_quirk;
10281 + }
10282 + EXPORT_SYMBOL_GPL(usb_amd_find_chipset_info);
10283 +
10284 +diff --git a/drivers/vhost/net.c b/drivers/vhost/net.c
10285 +index b40e8ded49c6..4d11152e60c1 100644
10286 +--- a/drivers/vhost/net.c
10287 ++++ b/drivers/vhost/net.c
10288 +@@ -35,7 +35,7 @@
10289 +
10290 + #include "vhost.h"
10291 +
10292 +-static int experimental_zcopytx = 1;
10293 ++static int experimental_zcopytx = 0;
10294 + module_param(experimental_zcopytx, int, 0444);
10295 + MODULE_PARM_DESC(experimental_zcopytx, "Enable Zero Copy TX;"
10296 + " 1 -Enable; 0 - Disable");
10297 +diff --git a/drivers/xen/balloon.c b/drivers/xen/balloon.c
10298 +index f77e499afddd..7d521babc020 100644
10299 +--- a/drivers/xen/balloon.c
10300 ++++ b/drivers/xen/balloon.c
10301 +@@ -590,8 +590,15 @@ static void balloon_process(struct work_struct *work)
10302 + state = reserve_additional_memory();
10303 + }
10304 +
10305 +- if (credit < 0)
10306 +- state = decrease_reservation(-credit, GFP_BALLOON);
10307 ++ if (credit < 0) {
10308 ++ long n_pages;
10309 ++
10310 ++ n_pages = min(-credit, si_mem_available());
10311 ++ state = decrease_reservation(n_pages, GFP_BALLOON);
10312 ++ if (state == BP_DONE && n_pages != -credit &&
10313 ++ n_pages < totalreserve_pages)
10314 ++ state = BP_EAGAIN;
10315 ++ }
10316 +
10317 + state = update_schedule(state);
10318 +
10319 +@@ -630,6 +637,9 @@ static int add_ballooned_pages(int nr_pages)
10320 + }
10321 + }
10322 +
10323 ++ if (si_mem_available() < nr_pages)
10324 ++ return -ENOMEM;
10325 ++
10326 + st = decrease_reservation(nr_pages, GFP_USER);
10327 + if (st != BP_DONE)
10328 + return -ENOMEM;
10329 +@@ -759,7 +769,7 @@ static int __init balloon_init(void)
10330 + balloon_stats.schedule_delay = 1;
10331 + balloon_stats.max_schedule_delay = 32;
10332 + balloon_stats.retry_count = 1;
10333 +- balloon_stats.max_retry_count = RETRY_UNLIMITED;
10334 ++ balloon_stats.max_retry_count = 4;
10335 +
10336 + #ifdef CONFIG_XEN_BALLOON_MEMORY_HOTPLUG
10337 + set_online_page_callback(&xen_online_page);
10338 +diff --git a/drivers/xen/events/events_base.c b/drivers/xen/events/events_base.c
10339 +index fe1f16351f94..8d49b91d92cd 100644
10340 +--- a/drivers/xen/events/events_base.c
10341 ++++ b/drivers/xen/events/events_base.c
10342 +@@ -1293,7 +1293,7 @@ void rebind_evtchn_irq(int evtchn, int irq)
10343 + }
10344 +
10345 + /* Rebind an evtchn so that it gets delivered to a specific cpu */
10346 +-int xen_rebind_evtchn_to_cpu(int evtchn, unsigned tcpu)
10347 ++static int xen_rebind_evtchn_to_cpu(int evtchn, unsigned int tcpu)
10348 + {
10349 + struct evtchn_bind_vcpu bind_vcpu;
10350 + int masked;
10351 +@@ -1327,7 +1327,6 @@ int xen_rebind_evtchn_to_cpu(int evtchn, unsigned tcpu)
10352 +
10353 + return 0;
10354 + }
10355 +-EXPORT_SYMBOL_GPL(xen_rebind_evtchn_to_cpu);
10356 +
10357 + static int set_affinity_irq(struct irq_data *data, const struct cpumask *dest,
10358 + bool force)
10359 +@@ -1341,6 +1340,15 @@ static int set_affinity_irq(struct irq_data *data, const struct cpumask *dest,
10360 + return ret;
10361 + }
10362 +
10363 ++/* To be called with desc->lock held. */
10364 ++int xen_set_affinity_evtchn(struct irq_desc *desc, unsigned int tcpu)
10365 ++{
10366 ++ struct irq_data *d = irq_desc_get_irq_data(desc);
10367 ++
10368 ++ return set_affinity_irq(d, cpumask_of(tcpu), false);
10369 ++}
10370 ++EXPORT_SYMBOL_GPL(xen_set_affinity_evtchn);
10371 ++
10372 + static void enable_dynirq(struct irq_data *data)
10373 + {
10374 + int evtchn = evtchn_from_irq(data->irq);
10375 +diff --git a/drivers/xen/evtchn.c b/drivers/xen/evtchn.c
10376 +index 9729a64ea1a9..055123f48039 100644
10377 +--- a/drivers/xen/evtchn.c
10378 ++++ b/drivers/xen/evtchn.c
10379 +@@ -447,7 +447,7 @@ static void evtchn_bind_interdom_next_vcpu(int evtchn)
10380 + this_cpu_write(bind_last_selected_cpu, selected_cpu);
10381 +
10382 + /* unmask expects irqs to be disabled */
10383 +- xen_rebind_evtchn_to_cpu(evtchn, selected_cpu);
10384 ++ xen_set_affinity_evtchn(desc, selected_cpu);
10385 + raw_spin_unlock_irqrestore(&desc->lock, flags);
10386 + }
10387 +
10388 +diff --git a/fs/9p/vfs_addr.c b/fs/9p/vfs_addr.c
10389 +index e1cbdfdb7c68..197069303510 100644
10390 +--- a/fs/9p/vfs_addr.c
10391 ++++ b/fs/9p/vfs_addr.c
10392 +@@ -50,8 +50,9 @@
10393 + * @page: structure to page
10394 + *
10395 + */
10396 +-static int v9fs_fid_readpage(struct p9_fid *fid, struct page *page)
10397 ++static int v9fs_fid_readpage(void *data, struct page *page)
10398 + {
10399 ++ struct p9_fid *fid = data;
10400 + struct inode *inode = page->mapping->host;
10401 + struct bio_vec bvec = {.bv_page = page, .bv_len = PAGE_SIZE};
10402 + struct iov_iter to;
10403 +@@ -122,7 +123,8 @@ static int v9fs_vfs_readpages(struct file *filp, struct address_space *mapping,
10404 + if (ret == 0)
10405 + return ret;
10406 +
10407 +- ret = read_cache_pages(mapping, pages, (void *)v9fs_vfs_readpage, filp);
10408 ++ ret = read_cache_pages(mapping, pages, v9fs_fid_readpage,
10409 ++ filp->private_data);
10410 + p9_debug(P9_DEBUG_VFS, " = %d\n", ret);
10411 + return ret;
10412 + }
10413 +diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c
10414 +index 97958ecaeed9..6fbae1357644 100644
10415 +--- a/fs/btrfs/file.c
10416 ++++ b/fs/btrfs/file.c
10417 +@@ -2784,6 +2784,11 @@ out_only_mutex:
10418 + * for detecting, at fsync time, if the inode isn't yet in the
10419 + * log tree or it's there but not up to date.
10420 + */
10421 ++ struct timespec now = current_time(inode);
10422 ++
10423 ++ inode_inc_iversion(inode);
10424 ++ inode->i_mtime = now;
10425 ++ inode->i_ctime = now;
10426 + trans = btrfs_start_transaction(root, 1);
10427 + if (IS_ERR(trans)) {
10428 + err = PTR_ERR(trans);
10429 +diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
10430 +index ea7b65c025c2..ddc1d1d1a29f 100644
10431 +--- a/fs/btrfs/inode.c
10432 ++++ b/fs/btrfs/inode.c
10433 +@@ -405,10 +405,31 @@ static noinline int add_async_extent(struct async_cow *cow,
10434 + return 0;
10435 + }
10436 +
10437 ++/*
10438 ++ * Check if the inode has flags compatible with compression
10439 ++ */
10440 ++static inline bool inode_can_compress(struct inode *inode)
10441 ++{
10442 ++ if (BTRFS_I(inode)->flags & BTRFS_INODE_NODATACOW ||
10443 ++ BTRFS_I(inode)->flags & BTRFS_INODE_NODATASUM)
10444 ++ return false;
10445 ++ return true;
10446 ++}
10447 ++
10448 ++/*
10449 ++ * Check if the inode needs to be submitted to compression, based on mount
10450 ++ * options, defragmentation, properties or heuristics.
10451 ++ */
10452 + static inline int inode_need_compress(struct inode *inode, u64 start, u64 end)
10453 + {
10454 + struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb);
10455 +
10456 ++ if (!inode_can_compress(inode)) {
10457 ++ WARN(IS_ENABLED(CONFIG_BTRFS_DEBUG),
10458 ++ KERN_ERR "BTRFS: unexpected compression for ino %llu\n",
10459 ++ btrfs_ino(BTRFS_I(inode)));
10460 ++ return 0;
10461 ++ }
10462 + /* force compress */
10463 + if (btrfs_test_opt(fs_info, FORCE_COMPRESS))
10464 + return 1;
10465 +@@ -1626,7 +1647,8 @@ static int run_delalloc_range(void *private_data, struct page *locked_page,
10466 + } else if (BTRFS_I(inode)->flags & BTRFS_INODE_PREALLOC && !force_cow) {
10467 + ret = run_delalloc_nocow(inode, locked_page, start, end,
10468 + page_started, 0, nr_written);
10469 +- } else if (!inode_need_compress(inode, start, end)) {
10470 ++ } else if (!inode_can_compress(inode) ||
10471 ++ !inode_need_compress(inode, start, end)) {
10472 + ret = cow_file_range(inode, locked_page, start, end, end,
10473 + page_started, nr_written, 1, NULL);
10474 + } else {
10475 +diff --git a/fs/btrfs/tree-log.c b/fs/btrfs/tree-log.c
10476 +index 8ac6a64d0422..bfd7c89c8d92 100644
10477 +--- a/fs/btrfs/tree-log.c
10478 ++++ b/fs/btrfs/tree-log.c
10479 +@@ -3152,6 +3152,30 @@ int btrfs_free_log_root_tree(struct btrfs_trans_handle *trans,
10480 + return 0;
10481 + }
10482 +
10483 ++/*
10484 ++ * Check if an inode was logged in the current transaction. We can't always rely
10485 ++ * on an inode's logged_trans value, because it's an in-memory only field and
10486 ++ * therefore not persisted. This means that its value is lost if the inode gets
10487 ++ * evicted and loaded again from disk (in which case it has a value of 0, and
10488 ++ * certainly it is smaller then any possible transaction ID), when that happens
10489 ++ * the full_sync flag is set in the inode's runtime flags, so on that case we
10490 ++ * assume eviction happened and ignore the logged_trans value, assuming the
10491 ++ * worst case, that the inode was logged before in the current transaction.
10492 ++ */
10493 ++static bool inode_logged(struct btrfs_trans_handle *trans,
10494 ++ struct btrfs_inode *inode)
10495 ++{
10496 ++ if (inode->logged_trans == trans->transid)
10497 ++ return true;
10498 ++
10499 ++ if (inode->last_trans == trans->transid &&
10500 ++ test_bit(BTRFS_INODE_NEEDS_FULL_SYNC, &inode->runtime_flags) &&
10501 ++ !test_bit(BTRFS_FS_LOG_RECOVERING, &trans->fs_info->flags))
10502 ++ return true;
10503 ++
10504 ++ return false;
10505 ++}
10506 ++
10507 + /*
10508 + * If both a file and directory are logged, and unlinks or renames are
10509 + * mixed in, we have a few interesting corners:
10510 +@@ -3186,7 +3210,7 @@ int btrfs_del_dir_entries_in_log(struct btrfs_trans_handle *trans,
10511 + int bytes_del = 0;
10512 + u64 dir_ino = btrfs_ino(dir);
10513 +
10514 +- if (dir->logged_trans < trans->transid)
10515 ++ if (!inode_logged(trans, dir))
10516 + return 0;
10517 +
10518 + ret = join_running_log_trans(root);
10519 +@@ -3291,7 +3315,7 @@ int btrfs_del_inode_ref_in_log(struct btrfs_trans_handle *trans,
10520 + u64 index;
10521 + int ret;
10522 +
10523 +- if (inode->logged_trans < trans->transid)
10524 ++ if (!inode_logged(trans, inode))
10525 + return 0;
10526 +
10527 + ret = join_running_log_trans(root);
10528 +@@ -5266,9 +5290,19 @@ log_extents:
10529 + }
10530 + }
10531 +
10532 ++ /*
10533 ++ * Don't update last_log_commit if we logged that an inode exists after
10534 ++ * it was loaded to memory (full_sync bit set).
10535 ++ * This is to prevent data loss when we do a write to the inode, then
10536 ++ * the inode gets evicted after all delalloc was flushed, then we log
10537 ++ * it exists (due to a rename for example) and then fsync it. This last
10538 ++ * fsync would do nothing (not logging the extents previously written).
10539 ++ */
10540 + spin_lock(&inode->lock);
10541 + inode->logged_trans = trans->transid;
10542 +- inode->last_log_commit = inode->last_sub_trans;
10543 ++ if (inode_only != LOG_INODE_EXISTS ||
10544 ++ !test_bit(BTRFS_INODE_NEEDS_FULL_SYNC, &inode->runtime_flags))
10545 ++ inode->last_log_commit = inode->last_sub_trans;
10546 + spin_unlock(&inode->lock);
10547 + out_unlock:
10548 + if (unlikely(err))
10549 +diff --git a/fs/coda/file.c b/fs/coda/file.c
10550 +index 1cbc1f2298ee..43d371551d2b 100644
10551 +--- a/fs/coda/file.c
10552 ++++ b/fs/coda/file.c
10553 +@@ -27,6 +27,13 @@
10554 + #include "coda_linux.h"
10555 + #include "coda_int.h"
10556 +
10557 ++struct coda_vm_ops {
10558 ++ atomic_t refcnt;
10559 ++ struct file *coda_file;
10560 ++ const struct vm_operations_struct *host_vm_ops;
10561 ++ struct vm_operations_struct vm_ops;
10562 ++};
10563 ++
10564 + static ssize_t
10565 + coda_file_read_iter(struct kiocb *iocb, struct iov_iter *to)
10566 + {
10567 +@@ -61,6 +68,34 @@ coda_file_write_iter(struct kiocb *iocb, struct iov_iter *to)
10568 + return ret;
10569 + }
10570 +
10571 ++static void
10572 ++coda_vm_open(struct vm_area_struct *vma)
10573 ++{
10574 ++ struct coda_vm_ops *cvm_ops =
10575 ++ container_of(vma->vm_ops, struct coda_vm_ops, vm_ops);
10576 ++
10577 ++ atomic_inc(&cvm_ops->refcnt);
10578 ++
10579 ++ if (cvm_ops->host_vm_ops && cvm_ops->host_vm_ops->open)
10580 ++ cvm_ops->host_vm_ops->open(vma);
10581 ++}
10582 ++
10583 ++static void
10584 ++coda_vm_close(struct vm_area_struct *vma)
10585 ++{
10586 ++ struct coda_vm_ops *cvm_ops =
10587 ++ container_of(vma->vm_ops, struct coda_vm_ops, vm_ops);
10588 ++
10589 ++ if (cvm_ops->host_vm_ops && cvm_ops->host_vm_ops->close)
10590 ++ cvm_ops->host_vm_ops->close(vma);
10591 ++
10592 ++ if (atomic_dec_and_test(&cvm_ops->refcnt)) {
10593 ++ vma->vm_ops = cvm_ops->host_vm_ops;
10594 ++ fput(cvm_ops->coda_file);
10595 ++ kfree(cvm_ops);
10596 ++ }
10597 ++}
10598 ++
10599 + static int
10600 + coda_file_mmap(struct file *coda_file, struct vm_area_struct *vma)
10601 + {
10602 +@@ -68,6 +103,8 @@ coda_file_mmap(struct file *coda_file, struct vm_area_struct *vma)
10603 + struct coda_inode_info *cii;
10604 + struct file *host_file;
10605 + struct inode *coda_inode, *host_inode;
10606 ++ struct coda_vm_ops *cvm_ops;
10607 ++ int ret;
10608 +
10609 + cfi = CODA_FTOC(coda_file);
10610 + BUG_ON(!cfi || cfi->cfi_magic != CODA_MAGIC);
10611 +@@ -76,6 +113,13 @@ coda_file_mmap(struct file *coda_file, struct vm_area_struct *vma)
10612 + if (!host_file->f_op->mmap)
10613 + return -ENODEV;
10614 +
10615 ++ if (WARN_ON(coda_file != vma->vm_file))
10616 ++ return -EIO;
10617 ++
10618 ++ cvm_ops = kmalloc(sizeof(struct coda_vm_ops), GFP_KERNEL);
10619 ++ if (!cvm_ops)
10620 ++ return -ENOMEM;
10621 ++
10622 + coda_inode = file_inode(coda_file);
10623 + host_inode = file_inode(host_file);
10624 +
10625 +@@ -89,6 +133,7 @@ coda_file_mmap(struct file *coda_file, struct vm_area_struct *vma)
10626 + * the container file on us! */
10627 + else if (coda_inode->i_mapping != host_inode->i_mapping) {
10628 + spin_unlock(&cii->c_lock);
10629 ++ kfree(cvm_ops);
10630 + return -EBUSY;
10631 + }
10632 +
10633 +@@ -97,7 +142,29 @@ coda_file_mmap(struct file *coda_file, struct vm_area_struct *vma)
10634 + cfi->cfi_mapcount++;
10635 + spin_unlock(&cii->c_lock);
10636 +
10637 +- return call_mmap(host_file, vma);
10638 ++ vma->vm_file = get_file(host_file);
10639 ++ ret = call_mmap(vma->vm_file, vma);
10640 ++
10641 ++ if (ret) {
10642 ++ /* if call_mmap fails, our caller will put coda_file so we
10643 ++ * should drop the reference to the host_file that we got.
10644 ++ */
10645 ++ fput(host_file);
10646 ++ kfree(cvm_ops);
10647 ++ } else {
10648 ++ /* here we add redirects for the open/close vm_operations */
10649 ++ cvm_ops->host_vm_ops = vma->vm_ops;
10650 ++ if (vma->vm_ops)
10651 ++ cvm_ops->vm_ops = *vma->vm_ops;
10652 ++
10653 ++ cvm_ops->vm_ops.open = coda_vm_open;
10654 ++ cvm_ops->vm_ops.close = coda_vm_close;
10655 ++ cvm_ops->coda_file = coda_file;
10656 ++ atomic_set(&cvm_ops->refcnt, 1);
10657 ++
10658 ++ vma->vm_ops = &cvm_ops->vm_ops;
10659 ++ }
10660 ++ return ret;
10661 + }
10662 +
10663 + int coda_open(struct inode *coda_inode, struct file *coda_file)
10664 +@@ -207,4 +274,3 @@ const struct file_operations coda_file_operations = {
10665 + .fsync = coda_fsync,
10666 + .splice_read = generic_file_splice_read,
10667 + };
10668 +-
10669 +diff --git a/fs/crypto/crypto.c b/fs/crypto/crypto.c
10670 +index daf2683f0655..f862ad19c714 100644
10671 +--- a/fs/crypto/crypto.c
10672 ++++ b/fs/crypto/crypto.c
10673 +@@ -157,7 +157,10 @@ int fscrypt_do_page_crypto(const struct inode *inode, fscrypt_direction_t rw,
10674 + struct crypto_skcipher *tfm = ci->ci_ctfm;
10675 + int res = 0;
10676 +
10677 +- BUG_ON(len == 0);
10678 ++ if (WARN_ON_ONCE(len <= 0))
10679 ++ return -EINVAL;
10680 ++ if (WARN_ON_ONCE(len % FS_CRYPTO_BLOCK_SIZE != 0))
10681 ++ return -EINVAL;
10682 +
10683 + BUILD_BUG_ON(sizeof(iv) != FS_IV_SIZE);
10684 + BUILD_BUG_ON(AES_BLOCK_SIZE != FS_IV_SIZE);
10685 +@@ -257,8 +260,6 @@ struct page *fscrypt_encrypt_page(const struct inode *inode,
10686 + struct page *ciphertext_page = page;
10687 + int err;
10688 +
10689 +- BUG_ON(len % FS_CRYPTO_BLOCK_SIZE != 0);
10690 +-
10691 + if (inode->i_sb->s_cop->flags & FS_CFLG_OWN_PAGES) {
10692 + /* with inplace-encryption we just encrypt the page */
10693 + err = fscrypt_do_page_crypto(inode, FS_ENCRYPT, lblk_num, page,
10694 +@@ -270,7 +271,8 @@ struct page *fscrypt_encrypt_page(const struct inode *inode,
10695 + return ciphertext_page;
10696 + }
10697 +
10698 +- BUG_ON(!PageLocked(page));
10699 ++ if (WARN_ON_ONCE(!PageLocked(page)))
10700 ++ return ERR_PTR(-EINVAL);
10701 +
10702 + ctx = fscrypt_get_ctx(inode, gfp_flags);
10703 + if (IS_ERR(ctx))
10704 +@@ -318,8 +320,9 @@ EXPORT_SYMBOL(fscrypt_encrypt_page);
10705 + int fscrypt_decrypt_page(const struct inode *inode, struct page *page,
10706 + unsigned int len, unsigned int offs, u64 lblk_num)
10707 + {
10708 +- if (!(inode->i_sb->s_cop->flags & FS_CFLG_OWN_PAGES))
10709 +- BUG_ON(!PageLocked(page));
10710 ++ if (WARN_ON_ONCE(!PageLocked(page) &&
10711 ++ !(inode->i_sb->s_cop->flags & FS_CFLG_OWN_PAGES)))
10712 ++ return -EINVAL;
10713 +
10714 + return fscrypt_do_page_crypto(inode, FS_DECRYPT, lblk_num, page, page,
10715 + len, offs, GFP_NOFS);
10716 +diff --git a/fs/ecryptfs/crypto.c b/fs/ecryptfs/crypto.c
10717 +index 9d1823efff34..bd25ab837011 100644
10718 +--- a/fs/ecryptfs/crypto.c
10719 ++++ b/fs/ecryptfs/crypto.c
10720 +@@ -1034,8 +1034,10 @@ int ecryptfs_read_and_validate_header_region(struct inode *inode)
10721 +
10722 + rc = ecryptfs_read_lower(file_size, 0, ECRYPTFS_SIZE_AND_MARKER_BYTES,
10723 + inode);
10724 +- if (rc < ECRYPTFS_SIZE_AND_MARKER_BYTES)
10725 +- return rc >= 0 ? -EINVAL : rc;
10726 ++ if (rc < 0)
10727 ++ return rc;
10728 ++ else if (rc < ECRYPTFS_SIZE_AND_MARKER_BYTES)
10729 ++ return -EINVAL;
10730 + rc = ecryptfs_validate_marker(marker);
10731 + if (!rc)
10732 + ecryptfs_i_size_init(file_size, inode);
10733 +@@ -1397,8 +1399,10 @@ int ecryptfs_read_and_validate_xattr_region(struct dentry *dentry,
10734 + ecryptfs_inode_to_lower(inode),
10735 + ECRYPTFS_XATTR_NAME, file_size,
10736 + ECRYPTFS_SIZE_AND_MARKER_BYTES);
10737 +- if (rc < ECRYPTFS_SIZE_AND_MARKER_BYTES)
10738 +- return rc >= 0 ? -EINVAL : rc;
10739 ++ if (rc < 0)
10740 ++ return rc;
10741 ++ else if (rc < ECRYPTFS_SIZE_AND_MARKER_BYTES)
10742 ++ return -EINVAL;
10743 + rc = ecryptfs_validate_marker(marker);
10744 + if (!rc)
10745 + ecryptfs_i_size_init(file_size, inode);
10746 +diff --git a/fs/ext4/dir.c b/fs/ext4/dir.c
10747 +index dc676714454a..446b6c375b6f 100644
10748 +--- a/fs/ext4/dir.c
10749 ++++ b/fs/ext4/dir.c
10750 +@@ -107,7 +107,6 @@ static int ext4_readdir(struct file *file, struct dir_context *ctx)
10751 + struct inode *inode = file_inode(file);
10752 + struct super_block *sb = inode->i_sb;
10753 + struct buffer_head *bh = NULL;
10754 +- int dir_has_error = 0;
10755 + struct fscrypt_str fstr = FSTR_INIT(NULL, 0);
10756 +
10757 + if (ext4_encrypted_inode(inode)) {
10758 +@@ -143,8 +142,6 @@ static int ext4_readdir(struct file *file, struct dir_context *ctx)
10759 + return err;
10760 + }
10761 +
10762 +- offset = ctx->pos & (sb->s_blocksize - 1);
10763 +-
10764 + while (ctx->pos < inode->i_size) {
10765 + struct ext4_map_blocks map;
10766 +
10767 +@@ -153,9 +150,18 @@ static int ext4_readdir(struct file *file, struct dir_context *ctx)
10768 + goto errout;
10769 + }
10770 + cond_resched();
10771 ++ offset = ctx->pos & (sb->s_blocksize - 1);
10772 + map.m_lblk = ctx->pos >> EXT4_BLOCK_SIZE_BITS(sb);
10773 + map.m_len = 1;
10774 + err = ext4_map_blocks(NULL, inode, &map, 0);
10775 ++ if (err == 0) {
10776 ++ /* m_len should never be zero but let's avoid
10777 ++ * an infinite loop if it somehow is */
10778 ++ if (map.m_len == 0)
10779 ++ map.m_len = 1;
10780 ++ ctx->pos += map.m_len * sb->s_blocksize;
10781 ++ continue;
10782 ++ }
10783 + if (err > 0) {
10784 + pgoff_t index = map.m_pblk >>
10785 + (PAGE_SHIFT - inode->i_blkbits);
10786 +@@ -174,13 +180,6 @@ static int ext4_readdir(struct file *file, struct dir_context *ctx)
10787 + }
10788 +
10789 + if (!bh) {
10790 +- if (!dir_has_error) {
10791 +- EXT4_ERROR_FILE(file, 0,
10792 +- "directory contains a "
10793 +- "hole at offset %llu",
10794 +- (unsigned long long) ctx->pos);
10795 +- dir_has_error = 1;
10796 +- }
10797 + /* corrupt size? Maybe no more blocks to read */
10798 + if (ctx->pos > inode->i_blocks << 9)
10799 + break;
10800 +diff --git a/fs/ext4/ext4_jbd2.h b/fs/ext4/ext4_jbd2.h
10801 +index 1437f62d068c..116401578401 100644
10802 +--- a/fs/ext4/ext4_jbd2.h
10803 ++++ b/fs/ext4/ext4_jbd2.h
10804 +@@ -364,20 +364,20 @@ static inline int ext4_journal_force_commit(journal_t *journal)
10805 + }
10806 +
10807 + static inline int ext4_jbd2_inode_add_write(handle_t *handle,
10808 +- struct inode *inode)
10809 ++ struct inode *inode, loff_t start_byte, loff_t length)
10810 + {
10811 + if (ext4_handle_valid(handle))
10812 +- return jbd2_journal_inode_add_write(handle,
10813 +- EXT4_I(inode)->jinode);
10814 ++ return jbd2_journal_inode_ranged_write(handle,
10815 ++ EXT4_I(inode)->jinode, start_byte, length);
10816 + return 0;
10817 + }
10818 +
10819 + static inline int ext4_jbd2_inode_add_wait(handle_t *handle,
10820 +- struct inode *inode)
10821 ++ struct inode *inode, loff_t start_byte, loff_t length)
10822 + {
10823 + if (ext4_handle_valid(handle))
10824 +- return jbd2_journal_inode_add_wait(handle,
10825 +- EXT4_I(inode)->jinode);
10826 ++ return jbd2_journal_inode_ranged_wait(handle,
10827 ++ EXT4_I(inode)->jinode, start_byte, length);
10828 + return 0;
10829 + }
10830 +
10831 +diff --git a/fs/ext4/file.c b/fs/ext4/file.c
10832 +index 44966b272216..4ede0af9d6fe 100644
10833 +--- a/fs/ext4/file.c
10834 ++++ b/fs/ext4/file.c
10835 +@@ -163,6 +163,10 @@ static ssize_t ext4_write_checks(struct kiocb *iocb, struct iov_iter *from)
10836 + ret = generic_write_checks(iocb, from);
10837 + if (ret <= 0)
10838 + return ret;
10839 ++
10840 ++ if (unlikely(IS_IMMUTABLE(inode)))
10841 ++ return -EPERM;
10842 ++
10843 + /*
10844 + * If we have encountered a bitmap-format file, the size limit
10845 + * is smaller than s_maxbytes, which is for extent-mapped files.
10846 +diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
10847 +index 862766a1b080..ea85063e5dc2 100644
10848 +--- a/fs/ext4/inode.c
10849 ++++ b/fs/ext4/inode.c
10850 +@@ -728,10 +728,16 @@ out_sem:
10851 + !(flags & EXT4_GET_BLOCKS_ZERO) &&
10852 + !ext4_is_quota_file(inode) &&
10853 + ext4_should_order_data(inode)) {
10854 ++ loff_t start_byte =
10855 ++ (loff_t)map->m_lblk << inode->i_blkbits;
10856 ++ loff_t length = (loff_t)map->m_len << inode->i_blkbits;
10857 ++
10858 + if (flags & EXT4_GET_BLOCKS_IO_SUBMIT)
10859 +- ret = ext4_jbd2_inode_add_wait(handle, inode);
10860 ++ ret = ext4_jbd2_inode_add_wait(handle, inode,
10861 ++ start_byte, length);
10862 + else
10863 +- ret = ext4_jbd2_inode_add_write(handle, inode);
10864 ++ ret = ext4_jbd2_inode_add_write(handle, inode,
10865 ++ start_byte, length);
10866 + if (ret)
10867 + return ret;
10868 + }
10869 +@@ -4004,7 +4010,8 @@ static int __ext4_block_zero_page_range(handle_t *handle,
10870 + err = 0;
10871 + mark_buffer_dirty(bh);
10872 + if (ext4_should_order_data(inode))
10873 +- err = ext4_jbd2_inode_add_write(handle, inode);
10874 ++ err = ext4_jbd2_inode_add_write(handle, inode, from,
10875 ++ length);
10876 + }
10877 +
10878 + unlock:
10879 +@@ -5341,6 +5348,14 @@ int ext4_setattr(struct dentry *dentry, struct iattr *attr)
10880 + if (unlikely(ext4_forced_shutdown(EXT4_SB(inode->i_sb))))
10881 + return -EIO;
10882 +
10883 ++ if (unlikely(IS_IMMUTABLE(inode)))
10884 ++ return -EPERM;
10885 ++
10886 ++ if (unlikely(IS_APPEND(inode) &&
10887 ++ (ia_valid & (ATTR_MODE | ATTR_UID |
10888 ++ ATTR_GID | ATTR_TIMES_SET))))
10889 ++ return -EPERM;
10890 ++
10891 + error = setattr_prepare(dentry, attr);
10892 + if (error)
10893 + return error;
10894 +@@ -6045,6 +6060,9 @@ int ext4_page_mkwrite(struct vm_fault *vmf)
10895 + get_block_t *get_block;
10896 + int retries = 0;
10897 +
10898 ++ if (unlikely(IS_IMMUTABLE(inode)))
10899 ++ return VM_FAULT_SIGBUS;
10900 ++
10901 + sb_start_pagefault(inode->i_sb);
10902 + file_update_time(vma->vm_file);
10903 +
10904 +diff --git a/fs/ext4/ioctl.c b/fs/ext4/ioctl.c
10905 +index d2efc0cb8f31..82e118e9e50b 100644
10906 +--- a/fs/ext4/ioctl.c
10907 ++++ b/fs/ext4/ioctl.c
10908 +@@ -210,6 +210,29 @@ static int uuid_is_zero(__u8 u[16])
10909 + }
10910 + #endif
10911 +
10912 ++/*
10913 ++ * If immutable is set and we are not clearing it, we're not allowed to change
10914 ++ * anything else in the inode. Don't error out if we're only trying to set
10915 ++ * immutable on an immutable file.
10916 ++ */
10917 ++static int ext4_ioctl_check_immutable(struct inode *inode, __u32 new_projid,
10918 ++ unsigned int flags)
10919 ++{
10920 ++ struct ext4_inode_info *ei = EXT4_I(inode);
10921 ++ unsigned int oldflags = ei->i_flags;
10922 ++
10923 ++ if (!(oldflags & EXT4_IMMUTABLE_FL) || !(flags & EXT4_IMMUTABLE_FL))
10924 ++ return 0;
10925 ++
10926 ++ if ((oldflags & ~EXT4_IMMUTABLE_FL) != (flags & ~EXT4_IMMUTABLE_FL))
10927 ++ return -EPERM;
10928 ++ if (ext4_has_feature_project(inode->i_sb) &&
10929 ++ __kprojid_val(ei->i_projid) != new_projid)
10930 ++ return -EPERM;
10931 ++
10932 ++ return 0;
10933 ++}
10934 ++
10935 + static int ext4_ioctl_setflags(struct inode *inode,
10936 + unsigned int flags)
10937 + {
10938 +@@ -263,6 +286,20 @@ static int ext4_ioctl_setflags(struct inode *inode,
10939 + goto flags_out;
10940 + }
10941 +
10942 ++ /*
10943 ++ * Wait for all pending directio and then flush all the dirty pages
10944 ++ * for this file. The flush marks all the pages readonly, so any
10945 ++ * subsequent attempt to write to the file (particularly mmap pages)
10946 ++ * will come through the filesystem and fail.
10947 ++ */
10948 ++ if (S_ISREG(inode->i_mode) && !IS_IMMUTABLE(inode) &&
10949 ++ (flags & EXT4_IMMUTABLE_FL)) {
10950 ++ inode_dio_wait(inode);
10951 ++ err = filemap_write_and_wait(inode->i_mapping);
10952 ++ if (err)
10953 ++ goto flags_out;
10954 ++ }
10955 ++
10956 + handle = ext4_journal_start(inode, EXT4_HT_INODE, 1);
10957 + if (IS_ERR(handle)) {
10958 + err = PTR_ERR(handle);
10959 +@@ -653,7 +690,11 @@ long ext4_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
10960 + return err;
10961 +
10962 + inode_lock(inode);
10963 +- err = ext4_ioctl_setflags(inode, flags);
10964 ++ err = ext4_ioctl_check_immutable(inode,
10965 ++ from_kprojid(&init_user_ns, ei->i_projid),
10966 ++ flags);
10967 ++ if (!err)
10968 ++ err = ext4_ioctl_setflags(inode, flags);
10969 + inode_unlock(inode);
10970 + mnt_drop_write_file(filp);
10971 + return err;
10972 +@@ -1061,6 +1102,9 @@ resizefs_out:
10973 + goto out;
10974 + flags = (ei->i_flags & ~EXT4_FL_XFLAG_VISIBLE) |
10975 + (flags & EXT4_FL_XFLAG_VISIBLE);
10976 ++ err = ext4_ioctl_check_immutable(inode, fa.fsx_projid, flags);
10977 ++ if (err)
10978 ++ goto out;
10979 + err = ext4_ioctl_setflags(inode, flags);
10980 + if (err)
10981 + goto out;
10982 +diff --git a/fs/ext4/move_extent.c b/fs/ext4/move_extent.c
10983 +index cd8d481e0c48..ef60f2e92da6 100644
10984 +--- a/fs/ext4/move_extent.c
10985 ++++ b/fs/ext4/move_extent.c
10986 +@@ -400,7 +400,8 @@ data_copy:
10987 +
10988 + /* Even in case of data=writeback it is reasonable to pin
10989 + * inode to transaction, to prevent unexpected data loss */
10990 +- *err = ext4_jbd2_inode_add_write(handle, orig_inode);
10991 ++ *err = ext4_jbd2_inode_add_write(handle, orig_inode,
10992 ++ (loff_t)orig_page_offset << PAGE_SHIFT, replaced_size);
10993 +
10994 + unlock_pages:
10995 + unlock_page(pagep[0]);
10996 +diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c
10997 +index 070660cb5b91..162e853dc5d6 100644
10998 +--- a/fs/ext4/namei.c
10999 ++++ b/fs/ext4/namei.c
11000 +@@ -80,8 +80,18 @@ static struct buffer_head *ext4_append(handle_t *handle,
11001 + static int ext4_dx_csum_verify(struct inode *inode,
11002 + struct ext4_dir_entry *dirent);
11003 +
11004 ++/*
11005 ++ * Hints to ext4_read_dirblock regarding whether we expect a directory
11006 ++ * block being read to be an index block, or a block containing
11007 ++ * directory entries (and if the latter, whether it was found via a
11008 ++ * logical block in an htree index block). This is used to control
11009 ++ * what sort of sanity checkinig ext4_read_dirblock() will do on the
11010 ++ * directory block read from the storage device. EITHER will means
11011 ++ * the caller doesn't know what kind of directory block will be read,
11012 ++ * so no specific verification will be done.
11013 ++ */
11014 + typedef enum {
11015 +- EITHER, INDEX, DIRENT
11016 ++ EITHER, INDEX, DIRENT, DIRENT_HTREE
11017 + } dirblock_type_t;
11018 +
11019 + #define ext4_read_dirblock(inode, block, type) \
11020 +@@ -107,11 +117,14 @@ static struct buffer_head *__ext4_read_dirblock(struct inode *inode,
11021 +
11022 + return bh;
11023 + }
11024 +- if (!bh) {
11025 ++ if (!bh && (type == INDEX || type == DIRENT_HTREE)) {
11026 + ext4_error_inode(inode, func, line, block,
11027 +- "Directory hole found");
11028 ++ "Directory hole found for htree %s block",
11029 ++ (type == INDEX) ? "index" : "leaf");
11030 + return ERR_PTR(-EFSCORRUPTED);
11031 + }
11032 ++ if (!bh)
11033 ++ return NULL;
11034 + dirent = (struct ext4_dir_entry *) bh->b_data;
11035 + /* Determine whether or not we have an index block */
11036 + if (is_dx(inode)) {
11037 +@@ -978,7 +991,7 @@ static int htree_dirblock_to_tree(struct file *dir_file,
11038 +
11039 + dxtrace(printk(KERN_INFO "In htree dirblock_to_tree: block %lu\n",
11040 + (unsigned long)block));
11041 +- bh = ext4_read_dirblock(dir, block, DIRENT);
11042 ++ bh = ext4_read_dirblock(dir, block, DIRENT_HTREE);
11043 + if (IS_ERR(bh))
11044 + return PTR_ERR(bh);
11045 +
11046 +@@ -1508,7 +1521,7 @@ static struct buffer_head * ext4_dx_find_entry(struct inode *dir,
11047 + return (struct buffer_head *) frame;
11048 + do {
11049 + block = dx_get_block(frame->at);
11050 +- bh = ext4_read_dirblock(dir, block, DIRENT);
11051 ++ bh = ext4_read_dirblock(dir, block, DIRENT_HTREE);
11052 + if (IS_ERR(bh))
11053 + goto errout;
11054 +
11055 +@@ -2088,6 +2101,11 @@ static int ext4_add_entry(handle_t *handle, struct dentry *dentry,
11056 + blocks = dir->i_size >> sb->s_blocksize_bits;
11057 + for (block = 0; block < blocks; block++) {
11058 + bh = ext4_read_dirblock(dir, block, DIRENT);
11059 ++ if (bh == NULL) {
11060 ++ bh = ext4_bread(handle, dir, block,
11061 ++ EXT4_GET_BLOCKS_CREATE);
11062 ++ goto add_to_new_block;
11063 ++ }
11064 + if (IS_ERR(bh)) {
11065 + retval = PTR_ERR(bh);
11066 + bh = NULL;
11067 +@@ -2108,6 +2126,7 @@ static int ext4_add_entry(handle_t *handle, struct dentry *dentry,
11068 + brelse(bh);
11069 + }
11070 + bh = ext4_append(handle, dir, &block);
11071 ++add_to_new_block:
11072 + if (IS_ERR(bh)) {
11073 + retval = PTR_ERR(bh);
11074 + bh = NULL;
11075 +@@ -2152,7 +2171,7 @@ again:
11076 + return PTR_ERR(frame);
11077 + entries = frame->entries;
11078 + at = frame->at;
11079 +- bh = ext4_read_dirblock(dir, dx_get_block(frame->at), DIRENT);
11080 ++ bh = ext4_read_dirblock(dir, dx_get_block(frame->at), DIRENT_HTREE);
11081 + if (IS_ERR(bh)) {
11082 + err = PTR_ERR(bh);
11083 + bh = NULL;
11084 +@@ -2700,7 +2719,10 @@ bool ext4_empty_dir(struct inode *inode)
11085 + EXT4_ERROR_INODE(inode, "invalid size");
11086 + return true;
11087 + }
11088 +- bh = ext4_read_dirblock(inode, 0, EITHER);
11089 ++ /* The first directory block must not be a hole,
11090 ++ * so treat it as DIRENT_HTREE
11091 ++ */
11092 ++ bh = ext4_read_dirblock(inode, 0, DIRENT_HTREE);
11093 + if (IS_ERR(bh))
11094 + return true;
11095 +
11096 +@@ -2722,6 +2744,10 @@ bool ext4_empty_dir(struct inode *inode)
11097 + brelse(bh);
11098 + lblock = offset >> EXT4_BLOCK_SIZE_BITS(sb);
11099 + bh = ext4_read_dirblock(inode, lblock, EITHER);
11100 ++ if (bh == NULL) {
11101 ++ offset += sb->s_blocksize;
11102 ++ continue;
11103 ++ }
11104 + if (IS_ERR(bh))
11105 + return true;
11106 + de = (struct ext4_dir_entry_2 *) bh->b_data;
11107 +@@ -3292,7 +3318,10 @@ static struct buffer_head *ext4_get_first_dir_block(handle_t *handle,
11108 + struct buffer_head *bh;
11109 +
11110 + if (!ext4_has_inline_data(inode)) {
11111 +- bh = ext4_read_dirblock(inode, 0, EITHER);
11112 ++ /* The first directory block must not be a hole, so
11113 ++ * treat it as DIRENT_HTREE
11114 ++ */
11115 ++ bh = ext4_read_dirblock(inode, 0, DIRENT_HTREE);
11116 + if (IS_ERR(bh)) {
11117 + *retval = PTR_ERR(bh);
11118 + return NULL;
11119 +diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c
11120 +index 70bd15cadb44..18d51c36a5e3 100644
11121 +--- a/fs/f2fs/segment.c
11122 ++++ b/fs/f2fs/segment.c
11123 +@@ -2612,6 +2612,11 @@ static int read_compacted_summaries(struct f2fs_sb_info *sbi)
11124 + seg_i = CURSEG_I(sbi, i);
11125 + segno = le32_to_cpu(ckpt->cur_data_segno[i]);
11126 + blk_off = le16_to_cpu(ckpt->cur_data_blkoff[i]);
11127 ++ if (blk_off > ENTRIES_IN_SUM) {
11128 ++ f2fs_bug_on(sbi, 1);
11129 ++ f2fs_put_page(page, 1);
11130 ++ return -EFAULT;
11131 ++ }
11132 + seg_i->next_segno = segno;
11133 + reset_curseg(sbi, i, 0);
11134 + seg_i->alloc_type = ckpt->alloc_type[i];
11135 +diff --git a/fs/fs-writeback.c b/fs/fs-writeback.c
11136 +index 4d561ee08d05..9e8fde348d61 100644
11137 +--- a/fs/fs-writeback.c
11138 ++++ b/fs/fs-writeback.c
11139 +@@ -721,6 +721,7 @@ void wbc_detach_inode(struct writeback_control *wbc)
11140 + void wbc_account_io(struct writeback_control *wbc, struct page *page,
11141 + size_t bytes)
11142 + {
11143 ++ struct cgroup_subsys_state *css;
11144 + int id;
11145 +
11146 + /*
11147 +@@ -732,7 +733,12 @@ void wbc_account_io(struct writeback_control *wbc, struct page *page,
11148 + if (!wbc->wb)
11149 + return;
11150 +
11151 +- id = mem_cgroup_css_from_page(page)->id;
11152 ++ css = mem_cgroup_css_from_page(page);
11153 ++ /* dead cgroups shouldn't contribute to inode ownership arbitration */
11154 ++ if (!(css->flags & CSS_ONLINE))
11155 ++ return;
11156 ++
11157 ++ id = css->id;
11158 +
11159 + if (id == wbc->wb_id) {
11160 + wbc->wb_bytes += bytes;
11161 +diff --git a/fs/jbd2/commit.c b/fs/jbd2/commit.c
11162 +index d11401afd52f..0567b17a970c 100644
11163 +--- a/fs/jbd2/commit.c
11164 ++++ b/fs/jbd2/commit.c
11165 +@@ -189,14 +189,15 @@ static int journal_wait_on_commit_record(journal_t *journal,
11166 + * use writepages() because with dealyed allocation we may be doing
11167 + * block allocation in writepages().
11168 + */
11169 +-static int journal_submit_inode_data_buffers(struct address_space *mapping)
11170 ++static int journal_submit_inode_data_buffers(struct address_space *mapping,
11171 ++ loff_t dirty_start, loff_t dirty_end)
11172 + {
11173 + int ret;
11174 + struct writeback_control wbc = {
11175 + .sync_mode = WB_SYNC_ALL,
11176 + .nr_to_write = mapping->nrpages * 2,
11177 +- .range_start = 0,
11178 +- .range_end = i_size_read(mapping->host),
11179 ++ .range_start = dirty_start,
11180 ++ .range_end = dirty_end,
11181 + };
11182 +
11183 + ret = generic_writepages(mapping, &wbc);
11184 +@@ -220,6 +221,9 @@ static int journal_submit_data_buffers(journal_t *journal,
11185 +
11186 + spin_lock(&journal->j_list_lock);
11187 + list_for_each_entry(jinode, &commit_transaction->t_inode_list, i_list) {
11188 ++ loff_t dirty_start = jinode->i_dirty_start;
11189 ++ loff_t dirty_end = jinode->i_dirty_end;
11190 ++
11191 + if (!(jinode->i_flags & JI_WRITE_DATA))
11192 + continue;
11193 + mapping = jinode->i_vfs_inode->i_mapping;
11194 +@@ -232,7 +236,8 @@ static int journal_submit_data_buffers(journal_t *journal,
11195 + * only allocated blocks here.
11196 + */
11197 + trace_jbd2_submit_inode_data(jinode->i_vfs_inode);
11198 +- err = journal_submit_inode_data_buffers(mapping);
11199 ++ err = journal_submit_inode_data_buffers(mapping, dirty_start,
11200 ++ dirty_end);
11201 + if (!ret)
11202 + ret = err;
11203 + spin_lock(&journal->j_list_lock);
11204 +@@ -259,12 +264,16 @@ static int journal_finish_inode_data_buffers(journal_t *journal,
11205 + /* For locking, see the comment in journal_submit_data_buffers() */
11206 + spin_lock(&journal->j_list_lock);
11207 + list_for_each_entry(jinode, &commit_transaction->t_inode_list, i_list) {
11208 ++ loff_t dirty_start = jinode->i_dirty_start;
11209 ++ loff_t dirty_end = jinode->i_dirty_end;
11210 ++
11211 + if (!(jinode->i_flags & JI_WAIT_DATA))
11212 + continue;
11213 + jinode->i_flags |= JI_COMMIT_RUNNING;
11214 + spin_unlock(&journal->j_list_lock);
11215 +- err = filemap_fdatawait_keep_errors(
11216 +- jinode->i_vfs_inode->i_mapping);
11217 ++ err = filemap_fdatawait_range_keep_errors(
11218 ++ jinode->i_vfs_inode->i_mapping, dirty_start,
11219 ++ dirty_end);
11220 + if (!ret)
11221 + ret = err;
11222 + spin_lock(&journal->j_list_lock);
11223 +@@ -284,6 +293,8 @@ static int journal_finish_inode_data_buffers(journal_t *journal,
11224 + &jinode->i_transaction->t_inode_list);
11225 + } else {
11226 + jinode->i_transaction = NULL;
11227 ++ jinode->i_dirty_start = 0;
11228 ++ jinode->i_dirty_end = 0;
11229 + }
11230 + }
11231 + spin_unlock(&journal->j_list_lock);
11232 +diff --git a/fs/jbd2/journal.c b/fs/jbd2/journal.c
11233 +index 593f3e31fb21..d3cce5c86fd9 100644
11234 +--- a/fs/jbd2/journal.c
11235 ++++ b/fs/jbd2/journal.c
11236 +@@ -97,6 +97,8 @@ EXPORT_SYMBOL(jbd2_journal_try_to_free_buffers);
11237 + EXPORT_SYMBOL(jbd2_journal_force_commit);
11238 + EXPORT_SYMBOL(jbd2_journal_inode_add_write);
11239 + EXPORT_SYMBOL(jbd2_journal_inode_add_wait);
11240 ++EXPORT_SYMBOL(jbd2_journal_inode_ranged_write);
11241 ++EXPORT_SYMBOL(jbd2_journal_inode_ranged_wait);
11242 + EXPORT_SYMBOL(jbd2_journal_init_jbd_inode);
11243 + EXPORT_SYMBOL(jbd2_journal_release_jbd_inode);
11244 + EXPORT_SYMBOL(jbd2_journal_begin_ordered_truncate);
11245 +@@ -2581,6 +2583,8 @@ void jbd2_journal_init_jbd_inode(struct jbd2_inode *jinode, struct inode *inode)
11246 + jinode->i_next_transaction = NULL;
11247 + jinode->i_vfs_inode = inode;
11248 + jinode->i_flags = 0;
11249 ++ jinode->i_dirty_start = 0;
11250 ++ jinode->i_dirty_end = 0;
11251 + INIT_LIST_HEAD(&jinode->i_list);
11252 + }
11253 +
11254 +diff --git a/fs/jbd2/transaction.c b/fs/jbd2/transaction.c
11255 +index 650927f0a2dc..7fe422eced89 100644
11256 +--- a/fs/jbd2/transaction.c
11257 ++++ b/fs/jbd2/transaction.c
11258 +@@ -2503,7 +2503,7 @@ void jbd2_journal_refile_buffer(journal_t *journal, struct journal_head *jh)
11259 + * File inode in the inode list of the handle's transaction
11260 + */
11261 + static int jbd2_journal_file_inode(handle_t *handle, struct jbd2_inode *jinode,
11262 +- unsigned long flags)
11263 ++ unsigned long flags, loff_t start_byte, loff_t end_byte)
11264 + {
11265 + transaction_t *transaction = handle->h_transaction;
11266 + journal_t *journal;
11267 +@@ -2515,26 +2515,17 @@ static int jbd2_journal_file_inode(handle_t *handle, struct jbd2_inode *jinode,
11268 + jbd_debug(4, "Adding inode %lu, tid:%d\n", jinode->i_vfs_inode->i_ino,
11269 + transaction->t_tid);
11270 +
11271 +- /*
11272 +- * First check whether inode isn't already on the transaction's
11273 +- * lists without taking the lock. Note that this check is safe
11274 +- * without the lock as we cannot race with somebody removing inode
11275 +- * from the transaction. The reason is that we remove inode from the
11276 +- * transaction only in journal_release_jbd_inode() and when we commit
11277 +- * the transaction. We are guarded from the first case by holding
11278 +- * a reference to the inode. We are safe against the second case
11279 +- * because if jinode->i_transaction == transaction, commit code
11280 +- * cannot touch the transaction because we hold reference to it,
11281 +- * and if jinode->i_next_transaction == transaction, commit code
11282 +- * will only file the inode where we want it.
11283 +- */
11284 +- if ((jinode->i_transaction == transaction ||
11285 +- jinode->i_next_transaction == transaction) &&
11286 +- (jinode->i_flags & flags) == flags)
11287 +- return 0;
11288 +-
11289 + spin_lock(&journal->j_list_lock);
11290 + jinode->i_flags |= flags;
11291 ++
11292 ++ if (jinode->i_dirty_end) {
11293 ++ jinode->i_dirty_start = min(jinode->i_dirty_start, start_byte);
11294 ++ jinode->i_dirty_end = max(jinode->i_dirty_end, end_byte);
11295 ++ } else {
11296 ++ jinode->i_dirty_start = start_byte;
11297 ++ jinode->i_dirty_end = end_byte;
11298 ++ }
11299 ++
11300 + /* Is inode already attached where we need it? */
11301 + if (jinode->i_transaction == transaction ||
11302 + jinode->i_next_transaction == transaction)
11303 +@@ -2569,12 +2560,28 @@ done:
11304 + int jbd2_journal_inode_add_write(handle_t *handle, struct jbd2_inode *jinode)
11305 + {
11306 + return jbd2_journal_file_inode(handle, jinode,
11307 +- JI_WRITE_DATA | JI_WAIT_DATA);
11308 ++ JI_WRITE_DATA | JI_WAIT_DATA, 0, LLONG_MAX);
11309 + }
11310 +
11311 + int jbd2_journal_inode_add_wait(handle_t *handle, struct jbd2_inode *jinode)
11312 + {
11313 +- return jbd2_journal_file_inode(handle, jinode, JI_WAIT_DATA);
11314 ++ return jbd2_journal_file_inode(handle, jinode, JI_WAIT_DATA, 0,
11315 ++ LLONG_MAX);
11316 ++}
11317 ++
11318 ++int jbd2_journal_inode_ranged_write(handle_t *handle,
11319 ++ struct jbd2_inode *jinode, loff_t start_byte, loff_t length)
11320 ++{
11321 ++ return jbd2_journal_file_inode(handle, jinode,
11322 ++ JI_WRITE_DATA | JI_WAIT_DATA, start_byte,
11323 ++ start_byte + length - 1);
11324 ++}
11325 ++
11326 ++int jbd2_journal_inode_ranged_wait(handle_t *handle, struct jbd2_inode *jinode,
11327 ++ loff_t start_byte, loff_t length)
11328 ++{
11329 ++ return jbd2_journal_file_inode(handle, jinode, JI_WAIT_DATA,
11330 ++ start_byte, start_byte + length - 1);
11331 + }
11332 +
11333 + /*
11334 +diff --git a/fs/nfs/flexfilelayout/flexfilelayoutdev.c b/fs/nfs/flexfilelayout/flexfilelayoutdev.c
11335 +index 2de6e87e5ee5..2464b9b80698 100644
11336 +--- a/fs/nfs/flexfilelayout/flexfilelayoutdev.c
11337 ++++ b/fs/nfs/flexfilelayout/flexfilelayoutdev.c
11338 +@@ -306,7 +306,7 @@ int ff_layout_track_ds_error(struct nfs4_flexfile_layout *flo,
11339 + if (status == 0)
11340 + return 0;
11341 +
11342 +- if (mirror->mirror_ds == NULL)
11343 ++ if (IS_ERR_OR_NULL(mirror->mirror_ds))
11344 + return -EINVAL;
11345 +
11346 + dserr = kmalloc(sizeof(*dserr), gfp_flags);
11347 +diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
11348 +index 134d9f560240..71a399f6805a 100644
11349 +--- a/fs/nfs/inode.c
11350 ++++ b/fs/nfs/inode.c
11351 +@@ -1034,6 +1034,7 @@ int nfs_open(struct inode *inode, struct file *filp)
11352 + nfs_fscache_open_file(inode, filp);
11353 + return 0;
11354 + }
11355 ++EXPORT_SYMBOL_GPL(nfs_open);
11356 +
11357 + /*
11358 + * This function is called whenever some part of NFS notices that
11359 +diff --git a/fs/nfs/nfs4file.c b/fs/nfs/nfs4file.c
11360 +index 626d1382002e..2b3e0f1ca572 100644
11361 +--- a/fs/nfs/nfs4file.c
11362 ++++ b/fs/nfs/nfs4file.c
11363 +@@ -50,7 +50,7 @@ nfs4_file_open(struct inode *inode, struct file *filp)
11364 + return err;
11365 +
11366 + if ((openflags & O_ACCMODE) == 3)
11367 +- openflags--;
11368 ++ return nfs_open(inode, filp);
11369 +
11370 + /* We can't create new files here */
11371 + openflags &= ~(O_CREAT|O_EXCL);
11372 +diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c
11373 +index a225f98c9903..209a21ed5f97 100644
11374 +--- a/fs/nfs/nfs4proc.c
11375 ++++ b/fs/nfs/nfs4proc.c
11376 +@@ -1099,6 +1099,12 @@ struct nfs4_opendata {
11377 + int rpc_status;
11378 + };
11379 +
11380 ++struct nfs4_open_createattrs {
11381 ++ struct nfs4_label *label;
11382 ++ struct iattr *sattr;
11383 ++ const __u32 verf[2];
11384 ++};
11385 ++
11386 + static bool nfs4_clear_cap_atomic_open_v1(struct nfs_server *server,
11387 + int err, struct nfs4_exception *exception)
11388 + {
11389 +@@ -1168,8 +1174,7 @@ static void nfs4_init_opendata_res(struct nfs4_opendata *p)
11390 +
11391 + static struct nfs4_opendata *nfs4_opendata_alloc(struct dentry *dentry,
11392 + struct nfs4_state_owner *sp, fmode_t fmode, int flags,
11393 +- const struct iattr *attrs,
11394 +- struct nfs4_label *label,
11395 ++ const struct nfs4_open_createattrs *c,
11396 + enum open_claim_type4 claim,
11397 + gfp_t gfp_mask)
11398 + {
11399 +@@ -1177,6 +1182,7 @@ static struct nfs4_opendata *nfs4_opendata_alloc(struct dentry *dentry,
11400 + struct inode *dir = d_inode(parent);
11401 + struct nfs_server *server = NFS_SERVER(dir);
11402 + struct nfs_seqid *(*alloc_seqid)(struct nfs_seqid_counter *, gfp_t);
11403 ++ struct nfs4_label *label = (c != NULL) ? c->label : NULL;
11404 + struct nfs4_opendata *p;
11405 +
11406 + p = kzalloc(sizeof(*p), gfp_mask);
11407 +@@ -1242,15 +1248,11 @@ static struct nfs4_opendata *nfs4_opendata_alloc(struct dentry *dentry,
11408 + case NFS4_OPEN_CLAIM_DELEG_PREV_FH:
11409 + p->o_arg.fh = NFS_FH(d_inode(dentry));
11410 + }
11411 +- if (attrs != NULL && attrs->ia_valid != 0) {
11412 +- __u32 verf[2];
11413 +-
11414 ++ if (c != NULL && c->sattr != NULL && c->sattr->ia_valid != 0) {
11415 + p->o_arg.u.attrs = &p->attrs;
11416 +- memcpy(&p->attrs, attrs, sizeof(p->attrs));
11417 ++ memcpy(&p->attrs, c->sattr, sizeof(p->attrs));
11418 +
11419 +- verf[0] = jiffies;
11420 +- verf[1] = current->pid;
11421 +- memcpy(p->o_arg.u.verifier.data, verf,
11422 ++ memcpy(p->o_arg.u.verifier.data, c->verf,
11423 + sizeof(p->o_arg.u.verifier.data));
11424 + }
11425 + p->c_arg.fh = &p->o_res.fh;
11426 +@@ -1816,7 +1818,7 @@ static struct nfs4_opendata *nfs4_open_recoverdata_alloc(struct nfs_open_context
11427 + struct nfs4_opendata *opendata;
11428 +
11429 + opendata = nfs4_opendata_alloc(ctx->dentry, state->owner, 0, 0,
11430 +- NULL, NULL, claim, GFP_NOFS);
11431 ++ NULL, claim, GFP_NOFS);
11432 + if (opendata == NULL)
11433 + return ERR_PTR(-ENOMEM);
11434 + opendata->state = state;
11435 +@@ -2757,8 +2759,7 @@ out:
11436 + static int _nfs4_do_open(struct inode *dir,
11437 + struct nfs_open_context *ctx,
11438 + int flags,
11439 +- struct iattr *sattr,
11440 +- struct nfs4_label *label,
11441 ++ const struct nfs4_open_createattrs *c,
11442 + int *opened)
11443 + {
11444 + struct nfs4_state_owner *sp;
11445 +@@ -2770,6 +2771,8 @@ static int _nfs4_do_open(struct inode *dir,
11446 + struct nfs4_threshold **ctx_th = &ctx->mdsthreshold;
11447 + fmode_t fmode = ctx->mode & (FMODE_READ|FMODE_WRITE|FMODE_EXEC);
11448 + enum open_claim_type4 claim = NFS4_OPEN_CLAIM_NULL;
11449 ++ struct iattr *sattr = c->sattr;
11450 ++ struct nfs4_label *label = c->label;
11451 + struct nfs4_label *olabel = NULL;
11452 + int status;
11453 +
11454 +@@ -2788,8 +2791,8 @@ static int _nfs4_do_open(struct inode *dir,
11455 + status = -ENOMEM;
11456 + if (d_really_is_positive(dentry))
11457 + claim = NFS4_OPEN_CLAIM_FH;
11458 +- opendata = nfs4_opendata_alloc(dentry, sp, fmode, flags, sattr,
11459 +- label, claim, GFP_KERNEL);
11460 ++ opendata = nfs4_opendata_alloc(dentry, sp, fmode, flags,
11461 ++ c, claim, GFP_KERNEL);
11462 + if (opendata == NULL)
11463 + goto err_put_state_owner;
11464 +
11465 +@@ -2870,10 +2873,18 @@ static struct nfs4_state *nfs4_do_open(struct inode *dir,
11466 + struct nfs_server *server = NFS_SERVER(dir);
11467 + struct nfs4_exception exception = { };
11468 + struct nfs4_state *res;
11469 ++ struct nfs4_open_createattrs c = {
11470 ++ .label = label,
11471 ++ .sattr = sattr,
11472 ++ .verf = {
11473 ++ [0] = (__u32)jiffies,
11474 ++ [1] = (__u32)current->pid,
11475 ++ },
11476 ++ };
11477 + int status;
11478 +
11479 + do {
11480 +- status = _nfs4_do_open(dir, ctx, flags, sattr, label, opened);
11481 ++ status = _nfs4_do_open(dir, ctx, flags, &c, opened);
11482 + res = ctx->state;
11483 + trace_nfs4_open_file(ctx, flags, status);
11484 + if (status == 0)
11485 +diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c
11486 +index 94128643ec1a..87ee9cbf7dcb 100644
11487 +--- a/fs/nfsd/nfs4state.c
11488 ++++ b/fs/nfsd/nfs4state.c
11489 +@@ -1502,11 +1502,16 @@ static u32 nfsd4_get_drc_mem(struct nfsd4_channel_attrs *ca)
11490 + {
11491 + u32 slotsize = slot_bytes(ca);
11492 + u32 num = ca->maxreqs;
11493 +- int avail;
11494 ++ unsigned long avail, total_avail;
11495 +
11496 + spin_lock(&nfsd_drc_lock);
11497 +- avail = min((unsigned long)NFSD_MAX_MEM_PER_SESSION,
11498 +- nfsd_drc_max_mem - nfsd_drc_mem_used);
11499 ++ total_avail = nfsd_drc_max_mem - nfsd_drc_mem_used;
11500 ++ avail = min((unsigned long)NFSD_MAX_MEM_PER_SESSION, total_avail);
11501 ++ /*
11502 ++ * Never use more than a third of the remaining memory,
11503 ++ * unless it's the only way to give this client a slot:
11504 ++ */
11505 ++ avail = clamp_t(unsigned long, avail, slotsize, total_avail/3);
11506 + num = min_t(int, num, avail / slotsize);
11507 + nfsd_drc_mem_used += num * slotsize;
11508 + spin_unlock(&nfsd_drc_lock);
11509 +diff --git a/fs/nfsd/nfssvc.c b/fs/nfsd/nfssvc.c
11510 +index e02bd2783124..4a9e0fb634b6 100644
11511 +--- a/fs/nfsd/nfssvc.c
11512 ++++ b/fs/nfsd/nfssvc.c
11513 +@@ -447,7 +447,7 @@ void nfsd_reset_versions(void)
11514 + */
11515 + static void set_max_drc(void)
11516 + {
11517 +- #define NFSD_DRC_SIZE_SHIFT 10
11518 ++ #define NFSD_DRC_SIZE_SHIFT 7
11519 + nfsd_drc_max_mem = (nr_free_buffer_pages()
11520 + >> NFSD_DRC_SIZE_SHIFT) * PAGE_SIZE;
11521 + nfsd_drc_mem_used = 0;
11522 +diff --git a/fs/open.c b/fs/open.c
11523 +index f4ea0dc88823..29a2cdcbcb17 100644
11524 +--- a/fs/open.c
11525 ++++ b/fs/open.c
11526 +@@ -379,6 +379,25 @@ SYSCALL_DEFINE3(faccessat, int, dfd, const char __user *, filename, int, mode)
11527 + override_cred->cap_permitted;
11528 + }
11529 +
11530 ++ /*
11531 ++ * The new set of credentials can *only* be used in
11532 ++ * task-synchronous circumstances, and does not need
11533 ++ * RCU freeing, unless somebody then takes a separate
11534 ++ * reference to it.
11535 ++ *
11536 ++ * NOTE! This is _only_ true because this credential
11537 ++ * is used purely for override_creds() that installs
11538 ++ * it as the subjective cred. Other threads will be
11539 ++ * accessing ->real_cred, not the subjective cred.
11540 ++ *
11541 ++ * If somebody _does_ make a copy of this (using the
11542 ++ * 'get_current_cred()' function), that will clear the
11543 ++ * non_rcu field, because now that other user may be
11544 ++ * expecting RCU freeing. But normal thread-synchronous
11545 ++ * cred accesses will keep things non-RCY.
11546 ++ */
11547 ++ override_cred->non_rcu = 1;
11548 ++
11549 + old_cred = override_creds(override_cred);
11550 + retry:
11551 + res = user_path_at(dfd, filename, lookup_flags, &path);
11552 +diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
11553 +index 555698ddb943..12bac452738d 100644
11554 +--- a/fs/proc/proc_sysctl.c
11555 ++++ b/fs/proc/proc_sysctl.c
11556 +@@ -498,6 +498,10 @@ static struct inode *proc_sys_make_inode(struct super_block *sb,
11557 +
11558 + if (root->set_ownership)
11559 + root->set_ownership(head, table, &inode->i_uid, &inode->i_gid);
11560 ++ else {
11561 ++ inode->i_uid = GLOBAL_ROOT_UID;
11562 ++ inode->i_gid = GLOBAL_ROOT_GID;
11563 ++ }
11564 +
11565 + return inode;
11566 + }
11567 +diff --git a/include/drm/drm_debugfs_crc.h b/include/drm/drm_debugfs_crc.h
11568 +index 7d63b1d4adb9..b225eeb30d05 100644
11569 +--- a/include/drm/drm_debugfs_crc.h
11570 ++++ b/include/drm/drm_debugfs_crc.h
11571 +@@ -43,6 +43,7 @@ struct drm_crtc_crc_entry {
11572 + * @lock: protects the fields in this struct
11573 + * @source: name of the currently configured source of CRCs
11574 + * @opened: whether userspace has opened the data file for reading
11575 ++ * @overflow: whether an overflow occured.
11576 + * @entries: array of entries, with size of %DRM_CRC_ENTRIES_NR
11577 + * @head: head of circular queue
11578 + * @tail: tail of circular queue
11579 +@@ -52,7 +53,7 @@ struct drm_crtc_crc_entry {
11580 + struct drm_crtc_crc {
11581 + spinlock_t lock;
11582 + const char *source;
11583 +- bool opened;
11584 ++ bool opened, overflow;
11585 + struct drm_crtc_crc_entry *entries;
11586 + int head, tail;
11587 + size_t values_cnt;
11588 +diff --git a/include/linux/compiler.h b/include/linux/compiler.h
11589 +index a704d032713b..f84d332085c3 100644
11590 +--- a/include/linux/compiler.h
11591 ++++ b/include/linux/compiler.h
11592 +@@ -185,23 +185,21 @@ void __read_once_size(const volatile void *p, void *res, int size)
11593 +
11594 + #ifdef CONFIG_KASAN
11595 + /*
11596 +- * This function is not 'inline' because __no_sanitize_address confilcts
11597 ++ * We can't declare function 'inline' because __no_sanitize_address confilcts
11598 + * with inlining. Attempt to inline it may cause a build failure.
11599 + * https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67368
11600 + * '__maybe_unused' allows us to avoid defined-but-not-used warnings.
11601 + */
11602 +-static __no_sanitize_address __maybe_unused
11603 +-void __read_once_size_nocheck(const volatile void *p, void *res, int size)
11604 +-{
11605 +- __READ_ONCE_SIZE;
11606 +-}
11607 ++# define __no_kasan_or_inline __no_sanitize_address __maybe_unused
11608 + #else
11609 +-static __always_inline
11610 ++# define __no_kasan_or_inline __always_inline
11611 ++#endif
11612 ++
11613 ++static __no_kasan_or_inline
11614 + void __read_once_size_nocheck(const volatile void *p, void *res, int size)
11615 + {
11616 + __READ_ONCE_SIZE;
11617 + }
11618 +-#endif
11619 +
11620 + static __always_inline void __write_once_size(volatile void *p, void *res, int size)
11621 + {
11622 +@@ -240,6 +238,7 @@ static __always_inline void __write_once_size(volatile void *p, void *res, int s
11623 + * required ordering.
11624 + */
11625 + #include <asm/barrier.h>
11626 ++#include <linux/kasan-checks.h>
11627 +
11628 + #define __READ_ONCE(x, check) \
11629 + ({ \
11630 +@@ -259,6 +258,13 @@ static __always_inline void __write_once_size(volatile void *p, void *res, int s
11631 + */
11632 + #define READ_ONCE_NOCHECK(x) __READ_ONCE(x, 0)
11633 +
11634 ++static __no_kasan_or_inline
11635 ++unsigned long read_word_at_a_time(const void *addr)
11636 ++{
11637 ++ kasan_check_read(addr, 1);
11638 ++ return *(unsigned long *)addr;
11639 ++}
11640 ++
11641 + #define WRITE_ONCE(x, val) \
11642 + ({ \
11643 + union { typeof(x) __val; char __c[1]; } __u = \
11644 +diff --git a/include/linux/cpuhotplug.h b/include/linux/cpuhotplug.h
11645 +index 0c78ad0cc515..0834eb5ea9e6 100644
11646 +--- a/include/linux/cpuhotplug.h
11647 ++++ b/include/linux/cpuhotplug.h
11648 +@@ -115,10 +115,10 @@ enum cpuhp_state {
11649 + CPUHP_AP_PERF_ARM_ACPI_STARTING,
11650 + CPUHP_AP_PERF_ARM_STARTING,
11651 + CPUHP_AP_ARM_L2X0_STARTING,
11652 ++ CPUHP_AP_EXYNOS4_MCT_TIMER_STARTING,
11653 + CPUHP_AP_ARM_ARCH_TIMER_STARTING,
11654 + CPUHP_AP_ARM_GLOBAL_TIMER_STARTING,
11655 + CPUHP_AP_JCORE_TIMER_STARTING,
11656 +- CPUHP_AP_EXYNOS4_MCT_TIMER_STARTING,
11657 + CPUHP_AP_ARM_TWD_STARTING,
11658 + CPUHP_AP_METAG_TIMER_STARTING,
11659 + CPUHP_AP_QCOM_TIMER_STARTING,
11660 +diff --git a/include/linux/cred.h b/include/linux/cred.h
11661 +index 631286535d0f..2a0d4674294e 100644
11662 +--- a/include/linux/cred.h
11663 ++++ b/include/linux/cred.h
11664 +@@ -145,7 +145,11 @@ struct cred {
11665 + struct user_struct *user; /* real user ID subscription */
11666 + struct user_namespace *user_ns; /* user_ns the caps and keyrings are relative to. */
11667 + struct group_info *group_info; /* supplementary groups for euid/fsgid */
11668 +- struct rcu_head rcu; /* RCU deletion hook */
11669 ++ /* RCU deletion */
11670 ++ union {
11671 ++ int non_rcu; /* Can we skip RCU deletion? */
11672 ++ struct rcu_head rcu; /* RCU deletion hook */
11673 ++ };
11674 + } __randomize_layout;
11675 +
11676 + extern void __put_cred(struct cred *);
11677 +@@ -243,6 +247,7 @@ static inline const struct cred *get_cred(const struct cred *cred)
11678 + {
11679 + struct cred *nonconst_cred = (struct cred *) cred;
11680 + validate_creds(cred);
11681 ++ nonconst_cred->non_rcu = 0;
11682 + return get_new_cred(nonconst_cred);
11683 + }
11684 +
11685 +diff --git a/include/linux/fs.h b/include/linux/fs.h
11686 +index da56c796c5d8..f0fddf4ea828 100644
11687 +--- a/include/linux/fs.h
11688 ++++ b/include/linux/fs.h
11689 +@@ -2580,6 +2580,8 @@ extern int filemap_flush(struct address_space *);
11690 + extern int filemap_fdatawait_keep_errors(struct address_space *mapping);
11691 + extern int filemap_fdatawait_range(struct address_space *, loff_t lstart,
11692 + loff_t lend);
11693 ++extern int filemap_fdatawait_range_keep_errors(struct address_space *mapping,
11694 ++ loff_t start_byte, loff_t end_byte);
11695 +
11696 + static inline int filemap_fdatawait(struct address_space *mapping)
11697 + {
11698 +diff --git a/include/linux/jbd2.h b/include/linux/jbd2.h
11699 +index 29290bfb94a8..11b3ab68f6a7 100644
11700 +--- a/include/linux/jbd2.h
11701 ++++ b/include/linux/jbd2.h
11702 +@@ -454,6 +454,22 @@ struct jbd2_inode {
11703 + * @i_flags: Flags of inode [j_list_lock]
11704 + */
11705 + unsigned long i_flags;
11706 ++
11707 ++ /**
11708 ++ * @i_dirty_start:
11709 ++ *
11710 ++ * Offset in bytes where the dirty range for this inode starts.
11711 ++ * [j_list_lock]
11712 ++ */
11713 ++ loff_t i_dirty_start;
11714 ++
11715 ++ /**
11716 ++ * @i_dirty_end:
11717 ++ *
11718 ++ * Inclusive offset in bytes where the dirty range for this inode
11719 ++ * ends. [j_list_lock]
11720 ++ */
11721 ++ loff_t i_dirty_end;
11722 + };
11723 +
11724 + struct jbd2_revoke_table_s;
11725 +@@ -1399,6 +1415,12 @@ extern int jbd2_journal_force_commit(journal_t *);
11726 + extern int jbd2_journal_force_commit_nested(journal_t *);
11727 + extern int jbd2_journal_inode_add_write(handle_t *handle, struct jbd2_inode *inode);
11728 + extern int jbd2_journal_inode_add_wait(handle_t *handle, struct jbd2_inode *inode);
11729 ++extern int jbd2_journal_inode_ranged_write(handle_t *handle,
11730 ++ struct jbd2_inode *inode, loff_t start_byte,
11731 ++ loff_t length);
11732 ++extern int jbd2_journal_inode_ranged_wait(handle_t *handle,
11733 ++ struct jbd2_inode *inode, loff_t start_byte,
11734 ++ loff_t length);
11735 + extern int jbd2_journal_begin_ordered_truncate(journal_t *journal,
11736 + struct jbd2_inode *inode, loff_t new_size);
11737 + extern void jbd2_journal_init_jbd_inode(struct jbd2_inode *jinode, struct inode *inode);
11738 +diff --git a/include/linux/rcupdate.h b/include/linux/rcupdate.h
11739 +index f960c85cd9ec..8d570190e9b4 100644
11740 +--- a/include/linux/rcupdate.h
11741 ++++ b/include/linux/rcupdate.h
11742 +@@ -622,7 +622,7 @@ static inline void rcu_preempt_sleep_check(void) { }
11743 + * read-side critical sections may be preempted and they may also block, but
11744 + * only when acquiring spinlocks that are subject to priority inheritance.
11745 + */
11746 +-static inline void rcu_read_lock(void)
11747 ++static __always_inline void rcu_read_lock(void)
11748 + {
11749 + __rcu_read_lock();
11750 + __acquire(RCU);
11751 +diff --git a/include/net/dst.h b/include/net/dst.h
11752 +index ebfb4328fdb1..2acd670fc86b 100644
11753 +--- a/include/net/dst.h
11754 ++++ b/include/net/dst.h
11755 +@@ -329,8 +329,9 @@ static inline bool dst_hold_safe(struct dst_entry *dst)
11756 + * @skb: buffer
11757 + *
11758 + * If dst is not yet refcounted and not destroyed, grab a ref on it.
11759 ++ * Returns true if dst is refcounted.
11760 + */
11761 +-static inline void skb_dst_force(struct sk_buff *skb)
11762 ++static inline bool skb_dst_force(struct sk_buff *skb)
11763 + {
11764 + if (skb_dst_is_noref(skb)) {
11765 + struct dst_entry *dst = skb_dst(skb);
11766 +@@ -341,6 +342,8 @@ static inline void skb_dst_force(struct sk_buff *skb)
11767 +
11768 + skb->_skb_refdst = (unsigned long)dst;
11769 + }
11770 ++
11771 ++ return skb->_skb_refdst != 0UL;
11772 + }
11773 +
11774 +
11775 +diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
11776 +index 5d08c1950e7d..82bc9f0e8a76 100644
11777 +--- a/include/net/ip_vs.h
11778 ++++ b/include/net/ip_vs.h
11779 +@@ -812,11 +812,12 @@ struct ipvs_master_sync_state {
11780 + struct ip_vs_sync_buff *sync_buff;
11781 + unsigned long sync_queue_len;
11782 + unsigned int sync_queue_delay;
11783 +- struct task_struct *master_thread;
11784 + struct delayed_work master_wakeup_work;
11785 + struct netns_ipvs *ipvs;
11786 + };
11787 +
11788 ++struct ip_vs_sync_thread_data;
11789 ++
11790 + /* How much time to keep dests in trash */
11791 + #define IP_VS_DEST_TRASH_PERIOD (120 * HZ)
11792 +
11793 +@@ -947,7 +948,8 @@ struct netns_ipvs {
11794 + spinlock_t sync_lock;
11795 + struct ipvs_master_sync_state *ms;
11796 + spinlock_t sync_buff_lock;
11797 +- struct task_struct **backup_threads;
11798 ++ struct ip_vs_sync_thread_data *master_tinfo;
11799 ++ struct ip_vs_sync_thread_data *backup_tinfo;
11800 + int threads_mask;
11801 + volatile int sync_state;
11802 + struct mutex sync_mutex;
11803 +diff --git a/include/net/tcp.h b/include/net/tcp.h
11804 +index 1179ef4f0768..0b477a1e1177 100644
11805 +--- a/include/net/tcp.h
11806 ++++ b/include/net/tcp.h
11807 +@@ -1043,7 +1043,8 @@ void tcp_get_default_congestion_control(char *name);
11808 + void tcp_get_available_congestion_control(char *buf, size_t len);
11809 + void tcp_get_allowed_congestion_control(char *buf, size_t len);
11810 + int tcp_set_allowed_congestion_control(char *allowed);
11811 +-int tcp_set_congestion_control(struct sock *sk, const char *name, bool load, bool reinit);
11812 ++int tcp_set_congestion_control(struct sock *sk, const char *name, bool load,
11813 ++ bool reinit, bool cap_net_admin);
11814 + u32 tcp_slow_start(struct tcp_sock *tp, u32 acked);
11815 + void tcp_cong_avoid_ai(struct tcp_sock *tp, u32 w, u32 acked);
11816 +
11817 +diff --git a/include/xen/events.h b/include/xen/events.h
11818 +index c3e6bc643a7b..1650d39decae 100644
11819 +--- a/include/xen/events.h
11820 ++++ b/include/xen/events.h
11821 +@@ -3,6 +3,7 @@
11822 + #define _XEN_EVENTS_H
11823 +
11824 + #include <linux/interrupt.h>
11825 ++#include <linux/irq.h>
11826 + #ifdef CONFIG_PCI_MSI
11827 + #include <linux/msi.h>
11828 + #endif
11829 +@@ -59,7 +60,7 @@ void evtchn_put(unsigned int evtchn);
11830 +
11831 + void xen_send_IPI_one(unsigned int cpu, enum ipi_vector vector);
11832 + void rebind_evtchn_irq(int evtchn, int irq);
11833 +-int xen_rebind_evtchn_to_cpu(int evtchn, unsigned tcpu);
11834 ++int xen_set_affinity_evtchn(struct irq_desc *desc, unsigned int tcpu);
11835 +
11836 + static inline void notify_remote_via_evtchn(int port)
11837 + {
11838 +diff --git a/kernel/bpf/Makefile b/kernel/bpf/Makefile
11839 +index af3ab6164ff5..be282c135a66 100644
11840 +--- a/kernel/bpf/Makefile
11841 ++++ b/kernel/bpf/Makefile
11842 +@@ -1,5 +1,6 @@
11843 + # SPDX-License-Identifier: GPL-2.0
11844 + obj-y := core.o
11845 ++CFLAGS_core.o += $(call cc-disable-warning, override-init)
11846 +
11847 + obj-$(CONFIG_BPF_SYSCALL) += syscall.o verifier.o inode.o helpers.o tnum.o
11848 + obj-$(CONFIG_BPF_SYSCALL) += hashtab.o arraymap.o percpu_freelist.o bpf_lru_list.o lpm_trie.o map_in_map.o
11849 +diff --git a/kernel/cred.c b/kernel/cred.c
11850 +index efd04b2ec84c..5ab1f7ec946e 100644
11851 +--- a/kernel/cred.c
11852 ++++ b/kernel/cred.c
11853 +@@ -147,7 +147,10 @@ void __put_cred(struct cred *cred)
11854 + BUG_ON(cred == current->cred);
11855 + BUG_ON(cred == current->real_cred);
11856 +
11857 +- call_rcu(&cred->rcu, put_cred_rcu);
11858 ++ if (cred->non_rcu)
11859 ++ put_cred_rcu(&cred->rcu);
11860 ++ else
11861 ++ call_rcu(&cred->rcu, put_cred_rcu);
11862 + }
11863 + EXPORT_SYMBOL(__put_cred);
11864 +
11865 +@@ -258,6 +261,7 @@ struct cred *prepare_creds(void)
11866 + old = task->cred;
11867 + memcpy(new, old, sizeof(struct cred));
11868 +
11869 ++ new->non_rcu = 0;
11870 + atomic_set(&new->usage, 1);
11871 + set_cred_subscribers(new, 0);
11872 + get_group_info(new->group_info);
11873 +@@ -537,7 +541,19 @@ const struct cred *override_creds(const struct cred *new)
11874 +
11875 + validate_creds(old);
11876 + validate_creds(new);
11877 +- get_cred(new);
11878 ++
11879 ++ /*
11880 ++ * NOTE! This uses 'get_new_cred()' rather than 'get_cred()'.
11881 ++ *
11882 ++ * That means that we do not clear the 'non_rcu' flag, since
11883 ++ * we are only installing the cred into the thread-synchronous
11884 ++ * '->cred' pointer, not the '->real_cred' pointer that is
11885 ++ * visible to other threads under RCU.
11886 ++ *
11887 ++ * Also note that we did validate_creds() manually, not depending
11888 ++ * on the validation in 'get_cred()'.
11889 ++ */
11890 ++ get_new_cred((struct cred *)new);
11891 + alter_cred_subscribers(new, 1);
11892 + rcu_assign_pointer(current->cred, new);
11893 + alter_cred_subscribers(old, -1);
11894 +@@ -620,6 +636,7 @@ struct cred *prepare_kernel_cred(struct task_struct *daemon)
11895 + validate_creds(old);
11896 +
11897 + *new = *old;
11898 ++ new->non_rcu = 0;
11899 + atomic_set(&new->usage, 1);
11900 + set_cred_subscribers(new, 0);
11901 + get_uid(new->user);
11902 +diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
11903 +index bf694c709b96..565005a3b8f0 100644
11904 +--- a/kernel/locking/lockdep.c
11905 ++++ b/kernel/locking/lockdep.c
11906 +@@ -3402,17 +3402,17 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
11907 + if (depth && !cross_lock(lock)) {
11908 + hlock = curr->held_locks + depth - 1;
11909 + if (hlock->class_idx == class_idx && nest_lock) {
11910 +- if (hlock->references) {
11911 +- /*
11912 +- * Check: unsigned int references:12, overflow.
11913 +- */
11914 +- if (DEBUG_LOCKS_WARN_ON(hlock->references == (1 << 12)-1))
11915 +- return 0;
11916 ++ if (!references)
11917 ++ references++;
11918 +
11919 ++ if (!hlock->references)
11920 + hlock->references++;
11921 +- } else {
11922 +- hlock->references = 2;
11923 +- }
11924 ++
11925 ++ hlock->references += references;
11926 ++
11927 ++ /* Overflow */
11928 ++ if (DEBUG_LOCKS_WARN_ON(hlock->references < references))
11929 ++ return 0;
11930 +
11931 + return 1;
11932 + }
11933 +diff --git a/kernel/locking/lockdep_proc.c b/kernel/locking/lockdep_proc.c
11934 +index ad69bbc9bd28..8b2ef15e3552 100644
11935 +--- a/kernel/locking/lockdep_proc.c
11936 ++++ b/kernel/locking/lockdep_proc.c
11937 +@@ -224,7 +224,6 @@ static void lockdep_stats_debug_show(struct seq_file *m)
11938 +
11939 + static int lockdep_stats_show(struct seq_file *m, void *v)
11940 + {
11941 +- struct lock_class *class;
11942 + unsigned long nr_unused = 0, nr_uncategorized = 0,
11943 + nr_irq_safe = 0, nr_irq_unsafe = 0,
11944 + nr_softirq_safe = 0, nr_softirq_unsafe = 0,
11945 +@@ -234,6 +233,9 @@ static int lockdep_stats_show(struct seq_file *m, void *v)
11946 + nr_hardirq_read_safe = 0, nr_hardirq_read_unsafe = 0,
11947 + sum_forward_deps = 0;
11948 +
11949 ++#ifdef CONFIG_PROVE_LOCKING
11950 ++ struct lock_class *class;
11951 ++
11952 + list_for_each_entry(class, &all_lock_classes, lock_entry) {
11953 +
11954 + if (class->usage_mask == 0)
11955 +@@ -265,12 +267,12 @@ static int lockdep_stats_show(struct seq_file *m, void *v)
11956 + if (class->usage_mask & LOCKF_ENABLED_HARDIRQ_READ)
11957 + nr_hardirq_read_unsafe++;
11958 +
11959 +-#ifdef CONFIG_PROVE_LOCKING
11960 + sum_forward_deps += lockdep_count_forward_deps(class);
11961 +-#endif
11962 + }
11963 + #ifdef CONFIG_DEBUG_LOCKDEP
11964 + DEBUG_LOCKS_WARN_ON(debug_atomic_read(nr_unused_locks) != nr_unused);
11965 ++#endif
11966 ++
11967 + #endif
11968 + seq_printf(m, " lock-classes: %11lu [max: %lu]\n",
11969 + nr_lock_classes, MAX_LOCKDEP_KEYS);
11970 +diff --git a/kernel/padata.c b/kernel/padata.c
11971 +index 868f947166d7..87540ce72aea 100644
11972 +--- a/kernel/padata.c
11973 ++++ b/kernel/padata.c
11974 +@@ -265,7 +265,12 @@ static void padata_reorder(struct parallel_data *pd)
11975 + * The next object that needs serialization might have arrived to
11976 + * the reorder queues in the meantime, we will be called again
11977 + * from the timer function if no one else cares for it.
11978 ++ *
11979 ++ * Ensure reorder_objects is read after pd->lock is dropped so we see
11980 ++ * an increment from another task in padata_do_serial. Pairs with
11981 ++ * smp_mb__after_atomic in padata_do_serial.
11982 + */
11983 ++ smp_mb();
11984 + if (atomic_read(&pd->reorder_objects)
11985 + && !(pinst->flags & PADATA_RESET))
11986 + mod_timer(&pd->timer, jiffies + HZ);
11987 +@@ -334,6 +339,13 @@ void padata_do_serial(struct padata_priv *padata)
11988 + list_add_tail(&padata->list, &pqueue->reorder.list);
11989 + spin_unlock(&pqueue->reorder.lock);
11990 +
11991 ++ /*
11992 ++ * Ensure the atomic_inc of reorder_objects above is ordered correctly
11993 ++ * with the trylock of pd->lock in padata_reorder. Pairs with smp_mb
11994 ++ * in padata_reorder.
11995 ++ */
11996 ++ smp_mb__after_atomic();
11997 ++
11998 + put_cpu();
11999 +
12000 + padata_reorder(pd);
12001 +diff --git a/kernel/pid_namespace.c b/kernel/pid_namespace.c
12002 +index 4918314893bc..22091c88b3bb 100644
12003 +--- a/kernel/pid_namespace.c
12004 ++++ b/kernel/pid_namespace.c
12005 +@@ -351,7 +351,7 @@ int reboot_pid_ns(struct pid_namespace *pid_ns, int cmd)
12006 + }
12007 +
12008 + read_lock(&tasklist_lock);
12009 +- force_sig(SIGKILL, pid_ns->child_reaper);
12010 ++ send_sig(SIGKILL, pid_ns->child_reaper, 1);
12011 + read_unlock(&tasklist_lock);
12012 +
12013 + do_exit(0);
12014 +diff --git a/kernel/sched/core.c b/kernel/sched/core.c
12015 +index b3ff73d6a4c2..ff128e281d1c 100644
12016 +--- a/kernel/sched/core.c
12017 ++++ b/kernel/sched/core.c
12018 +@@ -5026,7 +5026,7 @@ long __sched io_schedule_timeout(long timeout)
12019 + }
12020 + EXPORT_SYMBOL(io_schedule_timeout);
12021 +
12022 +-void io_schedule(void)
12023 ++void __sched io_schedule(void)
12024 + {
12025 + int token;
12026 +
12027 +diff --git a/kernel/time/ntp.c b/kernel/time/ntp.c
12028 +index 4bb9b66338be..9288532f73c8 100644
12029 +--- a/kernel/time/ntp.c
12030 ++++ b/kernel/time/ntp.c
12031 +@@ -43,6 +43,7 @@ static u64 tick_length_base;
12032 + #define MAX_TICKADJ 500LL /* usecs */
12033 + #define MAX_TICKADJ_SCALED \
12034 + (((MAX_TICKADJ * NSEC_PER_USEC) << NTP_SCALE_SHIFT) / NTP_INTERVAL_FREQ)
12035 ++#define MAX_TAI_OFFSET 100000
12036 +
12037 + /*
12038 + * phase-lock loop variables
12039 +@@ -640,7 +641,8 @@ static inline void process_adjtimex_modes(struct timex *txc,
12040 + time_constant = max(time_constant, 0l);
12041 + }
12042 +
12043 +- if (txc->modes & ADJ_TAI && txc->constant >= 0)
12044 ++ if (txc->modes & ADJ_TAI &&
12045 ++ txc->constant >= 0 && txc->constant <= MAX_TAI_OFFSET)
12046 + *time_tai = txc->constant;
12047 +
12048 + if (txc->modes & ADJ_OFFSET)
12049 +diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
12050 +index 0ed768b56c60..7e9f149d34ea 100644
12051 +--- a/kernel/time/timer_list.c
12052 ++++ b/kernel/time/timer_list.c
12053 +@@ -289,23 +289,6 @@ static inline void timer_list_header(struct seq_file *m, u64 now)
12054 + SEQ_printf(m, "\n");
12055 + }
12056 +
12057 +-static int timer_list_show(struct seq_file *m, void *v)
12058 +-{
12059 +- struct timer_list_iter *iter = v;
12060 +-
12061 +- if (iter->cpu == -1 && !iter->second_pass)
12062 +- timer_list_header(m, iter->now);
12063 +- else if (!iter->second_pass)
12064 +- print_cpu(m, iter->cpu, iter->now);
12065 +-#ifdef CONFIG_GENERIC_CLOCKEVENTS
12066 +- else if (iter->cpu == -1 && iter->second_pass)
12067 +- timer_list_show_tickdevices_header(m);
12068 +- else
12069 +- print_tickdevice(m, tick_get_device(iter->cpu), iter->cpu);
12070 +-#endif
12071 +- return 0;
12072 +-}
12073 +-
12074 + void sysrq_timer_list_show(void)
12075 + {
12076 + u64 now = ktime_to_ns(ktime_get());
12077 +@@ -324,6 +307,24 @@ void sysrq_timer_list_show(void)
12078 + return;
12079 + }
12080 +
12081 ++#ifdef CONFIG_PROC_FS
12082 ++static int timer_list_show(struct seq_file *m, void *v)
12083 ++{
12084 ++ struct timer_list_iter *iter = v;
12085 ++
12086 ++ if (iter->cpu == -1 && !iter->second_pass)
12087 ++ timer_list_header(m, iter->now);
12088 ++ else if (!iter->second_pass)
12089 ++ print_cpu(m, iter->cpu, iter->now);
12090 ++#ifdef CONFIG_GENERIC_CLOCKEVENTS
12091 ++ else if (iter->cpu == -1 && iter->second_pass)
12092 ++ timer_list_show_tickdevices_header(m);
12093 ++ else
12094 ++ print_tickdevice(m, tick_get_device(iter->cpu), iter->cpu);
12095 ++#endif
12096 ++ return 0;
12097 ++}
12098 ++
12099 + static void *move_iter(struct timer_list_iter *iter, loff_t offset)
12100 + {
12101 + for (; offset; offset--) {
12102 +@@ -395,3 +396,4 @@ static int __init init_timer_list_procfs(void)
12103 + return 0;
12104 + }
12105 + __initcall(init_timer_list_procfs);
12106 ++#endif
12107 +diff --git a/lib/reed_solomon/decode_rs.c b/lib/reed_solomon/decode_rs.c
12108 +index 0ec3f257ffdf..a5d313381539 100644
12109 +--- a/lib/reed_solomon/decode_rs.c
12110 ++++ b/lib/reed_solomon/decode_rs.c
12111 +@@ -42,8 +42,18 @@
12112 + BUG_ON(pad < 0 || pad >= nn);
12113 +
12114 + /* Does the caller provide the syndrome ? */
12115 +- if (s != NULL)
12116 +- goto decode;
12117 ++ if (s != NULL) {
12118 ++ for (i = 0; i < nroots; i++) {
12119 ++ /* The syndrome is in index form,
12120 ++ * so nn represents zero
12121 ++ */
12122 ++ if (s[i] != nn)
12123 ++ goto decode;
12124 ++ }
12125 ++
12126 ++ /* syndrome is zero, no errors to correct */
12127 ++ return 0;
12128 ++ }
12129 +
12130 + /* form the syndromes; i.e., evaluate data(x) at roots of
12131 + * g(x) */
12132 +@@ -99,9 +109,9 @@
12133 + if (no_eras > 0) {
12134 + /* Init lambda to be the erasure locator polynomial */
12135 + lambda[1] = alpha_to[rs_modnn(rs,
12136 +- prim * (nn - 1 - eras_pos[0]))];
12137 ++ prim * (nn - 1 - (eras_pos[0] + pad)))];
12138 + for (i = 1; i < no_eras; i++) {
12139 +- u = rs_modnn(rs, prim * (nn - 1 - eras_pos[i]));
12140 ++ u = rs_modnn(rs, prim * (nn - 1 - (eras_pos[i] + pad)));
12141 + for (j = i + 1; j > 0; j--) {
12142 + tmp = index_of[lambda[j - 1]];
12143 + if (tmp != nn) {
12144 +diff --git a/lib/scatterlist.c b/lib/scatterlist.c
12145 +index be7b4dd6b68d..355f2e90b72c 100644
12146 +--- a/lib/scatterlist.c
12147 ++++ b/lib/scatterlist.c
12148 +@@ -496,17 +496,18 @@ static bool sg_miter_get_next_page(struct sg_mapping_iter *miter)
12149 + {
12150 + if (!miter->__remaining) {
12151 + struct scatterlist *sg;
12152 +- unsigned long pgoffset;
12153 +
12154 + if (!__sg_page_iter_next(&miter->piter))
12155 + return false;
12156 +
12157 + sg = miter->piter.sg;
12158 +- pgoffset = miter->piter.sg_pgoffset;
12159 +
12160 +- miter->__offset = pgoffset ? 0 : sg->offset;
12161 ++ miter->__offset = miter->piter.sg_pgoffset ? 0 : sg->offset;
12162 ++ miter->piter.sg_pgoffset += miter->__offset >> PAGE_SHIFT;
12163 ++ miter->__offset &= PAGE_SIZE - 1;
12164 + miter->__remaining = sg->offset + sg->length -
12165 +- (pgoffset << PAGE_SHIFT) - miter->__offset;
12166 ++ (miter->piter.sg_pgoffset << PAGE_SHIFT) -
12167 ++ miter->__offset;
12168 + miter->__remaining = min_t(unsigned long, miter->__remaining,
12169 + PAGE_SIZE - miter->__offset);
12170 + }
12171 +diff --git a/lib/string.c b/lib/string.c
12172 +index 1530643edf00..33befc6ba3fa 100644
12173 +--- a/lib/string.c
12174 ++++ b/lib/string.c
12175 +@@ -203,7 +203,7 @@ ssize_t strscpy(char *dest, const char *src, size_t count)
12176 + while (max >= sizeof(unsigned long)) {
12177 + unsigned long c, data;
12178 +
12179 +- c = *(unsigned long *)(src+res);
12180 ++ c = read_word_at_a_time(src+res);
12181 + if (has_zero(c, &data, &constants)) {
12182 + data = prep_zero_mask(c, data, &constants);
12183 + data = create_zero_mask(data);
12184 +diff --git a/mm/filemap.c b/mm/filemap.c
12185 +index e2e738cc08b1..938365ad7e99 100644
12186 +--- a/mm/filemap.c
12187 ++++ b/mm/filemap.c
12188 +@@ -463,6 +463,28 @@ int filemap_fdatawait_range(struct address_space *mapping, loff_t start_byte,
12189 + }
12190 + EXPORT_SYMBOL(filemap_fdatawait_range);
12191 +
12192 ++/**
12193 ++ * filemap_fdatawait_range_keep_errors - wait for writeback to complete
12194 ++ * @mapping: address space structure to wait for
12195 ++ * @start_byte: offset in bytes where the range starts
12196 ++ * @end_byte: offset in bytes where the range ends (inclusive)
12197 ++ *
12198 ++ * Walk the list of under-writeback pages of the given address space in the
12199 ++ * given range and wait for all of them. Unlike filemap_fdatawait_range(),
12200 ++ * this function does not clear error status of the address space.
12201 ++ *
12202 ++ * Use this function if callers don't handle errors themselves. Expected
12203 ++ * call sites are system-wide / filesystem-wide data flushers: e.g. sync(2),
12204 ++ * fsfreeze(8)
12205 ++ */
12206 ++int filemap_fdatawait_range_keep_errors(struct address_space *mapping,
12207 ++ loff_t start_byte, loff_t end_byte)
12208 ++{
12209 ++ __filemap_fdatawait_range(mapping, start_byte, end_byte);
12210 ++ return filemap_check_and_keep_errors(mapping);
12211 ++}
12212 ++EXPORT_SYMBOL(filemap_fdatawait_range_keep_errors);
12213 ++
12214 + /**
12215 + * file_fdatawait_range - wait for writeback to complete
12216 + * @file: file pointing to address space structure to wait for
12217 +diff --git a/mm/gup.c b/mm/gup.c
12218 +index babcbd6d99c3..12b9626b1a9e 100644
12219 +--- a/mm/gup.c
12220 ++++ b/mm/gup.c
12221 +@@ -442,11 +442,14 @@ static int get_gate_page(struct mm_struct *mm, unsigned long address,
12222 + pgd = pgd_offset_k(address);
12223 + else
12224 + pgd = pgd_offset_gate(mm, address);
12225 +- BUG_ON(pgd_none(*pgd));
12226 ++ if (pgd_none(*pgd))
12227 ++ return -EFAULT;
12228 + p4d = p4d_offset(pgd, address);
12229 +- BUG_ON(p4d_none(*p4d));
12230 ++ if (p4d_none(*p4d))
12231 ++ return -EFAULT;
12232 + pud = pud_offset(p4d, address);
12233 +- BUG_ON(pud_none(*pud));
12234 ++ if (pud_none(*pud))
12235 ++ return -EFAULT;
12236 + pmd = pmd_offset(pud, address);
12237 + if (!pmd_present(*pmd))
12238 + return -EFAULT;
12239 +@@ -1364,7 +1367,8 @@ static inline pte_t gup_get_pte(pte_t *ptep)
12240 + }
12241 + #endif
12242 +
12243 +-static void undo_dev_pagemap(int *nr, int nr_start, struct page **pages)
12244 ++static void __maybe_unused undo_dev_pagemap(int *nr, int nr_start,
12245 ++ struct page **pages)
12246 + {
12247 + while ((*nr) - nr_start) {
12248 + struct page *page = pages[--(*nr)];
12249 +diff --git a/mm/kmemleak.c b/mm/kmemleak.c
12250 +index 71ba1c7f8892..d779181bed4d 100644
12251 +--- a/mm/kmemleak.c
12252 ++++ b/mm/kmemleak.c
12253 +@@ -577,7 +577,7 @@ static struct kmemleak_object *create_object(unsigned long ptr, size_t size,
12254 + if (in_irq()) {
12255 + object->pid = 0;
12256 + strncpy(object->comm, "hardirq", sizeof(object->comm));
12257 +- } else if (in_softirq()) {
12258 ++ } else if (in_serving_softirq()) {
12259 + object->pid = 0;
12260 + strncpy(object->comm, "softirq", sizeof(object->comm));
12261 + } else {
12262 +diff --git a/mm/mmu_notifier.c b/mm/mmu_notifier.c
12263 +index 314285284e6e..70d0efb06374 100644
12264 +--- a/mm/mmu_notifier.c
12265 ++++ b/mm/mmu_notifier.c
12266 +@@ -267,7 +267,7 @@ static int do_mmu_notifier_register(struct mmu_notifier *mn,
12267 + * thanks to mm_take_all_locks().
12268 + */
12269 + spin_lock(&mm->mmu_notifier_mm->lock);
12270 +- hlist_add_head(&mn->hlist, &mm->mmu_notifier_mm->list);
12271 ++ hlist_add_head_rcu(&mn->hlist, &mm->mmu_notifier_mm->list);
12272 + spin_unlock(&mm->mmu_notifier_mm->lock);
12273 +
12274 + mm_drop_all_locks(mm);
12275 +diff --git a/mm/vmscan.c b/mm/vmscan.c
12276 +index 290078e8d4b1..0cc3c1eb15f5 100644
12277 +--- a/mm/vmscan.c
12278 ++++ b/mm/vmscan.c
12279 +@@ -2120,7 +2120,7 @@ static void shrink_active_list(unsigned long nr_to_scan,
12280 + * 10TB 320 32GB
12281 + */
12282 + static bool inactive_list_is_low(struct lruvec *lruvec, bool file,
12283 +- struct scan_control *sc, bool actual_reclaim)
12284 ++ struct scan_control *sc, bool trace)
12285 + {
12286 + enum lru_list active_lru = file * LRU_FILE + LRU_ACTIVE;
12287 + struct pglist_data *pgdat = lruvec_pgdat(lruvec);
12288 +@@ -2146,7 +2146,7 @@ static bool inactive_list_is_low(struct lruvec *lruvec, bool file,
12289 + * rid of the stale workingset quickly.
12290 + */
12291 + refaults = lruvec_page_state(lruvec, WORKINGSET_ACTIVATE);
12292 +- if (file && actual_reclaim && lruvec->refaults != refaults) {
12293 ++ if (file && lruvec->refaults != refaults) {
12294 + inactive_ratio = 0;
12295 + } else {
12296 + gb = (inactive + active) >> (30 - PAGE_SHIFT);
12297 +@@ -2156,7 +2156,7 @@ static bool inactive_list_is_low(struct lruvec *lruvec, bool file,
12298 + inactive_ratio = 1;
12299 + }
12300 +
12301 +- if (actual_reclaim)
12302 ++ if (trace)
12303 + trace_mm_vmscan_inactive_list_is_low(pgdat->node_id, sc->reclaim_idx,
12304 + lruvec_lru_size(lruvec, inactive_lru, MAX_NR_ZONES), inactive,
12305 + lruvec_lru_size(lruvec, active_lru, MAX_NR_ZONES), active,
12306 +diff --git a/net/9p/trans_virtio.c b/net/9p/trans_virtio.c
12307 +index e73fd647065a..f88911cffa1a 100644
12308 +--- a/net/9p/trans_virtio.c
12309 ++++ b/net/9p/trans_virtio.c
12310 +@@ -764,10 +764,16 @@ static struct p9_trans_module p9_virtio_trans = {
12311 + /* The standard init function */
12312 + static int __init p9_virtio_init(void)
12313 + {
12314 ++ int rc;
12315 ++
12316 + INIT_LIST_HEAD(&virtio_chan_list);
12317 +
12318 + v9fs_register_trans(&p9_virtio_trans);
12319 +- return register_virtio_driver(&p9_virtio_drv);
12320 ++ rc = register_virtio_driver(&p9_virtio_drv);
12321 ++ if (rc)
12322 ++ v9fs_unregister_trans(&p9_virtio_trans);
12323 ++
12324 ++ return rc;
12325 + }
12326 +
12327 + static void __exit p9_virtio_cleanup(void)
12328 +diff --git a/net/9p/trans_xen.c b/net/9p/trans_xen.c
12329 +index 389eb635ec2c..ea9f1773abc8 100644
12330 +--- a/net/9p/trans_xen.c
12331 ++++ b/net/9p/trans_xen.c
12332 +@@ -530,13 +530,19 @@ static struct xenbus_driver xen_9pfs_front_driver = {
12333 +
12334 + static int p9_trans_xen_init(void)
12335 + {
12336 ++ int rc;
12337 ++
12338 + if (!xen_domain())
12339 + return -ENODEV;
12340 +
12341 + pr_info("Initialising Xen transport for 9pfs\n");
12342 +
12343 + v9fs_register_trans(&p9_xen_trans);
12344 +- return xenbus_register_frontend(&xen_9pfs_front_driver);
12345 ++ rc = xenbus_register_frontend(&xen_9pfs_front_driver);
12346 ++ if (rc)
12347 ++ v9fs_unregister_trans(&p9_xen_trans);
12348 ++
12349 ++ return rc;
12350 + }
12351 + module_init(p9_trans_xen_init);
12352 +
12353 +diff --git a/net/batman-adv/translation-table.c b/net/batman-adv/translation-table.c
12354 +index 020a8adc4cce..2c2670b85fa9 100644
12355 +--- a/net/batman-adv/translation-table.c
12356 ++++ b/net/batman-adv/translation-table.c
12357 +@@ -3750,6 +3750,8 @@ static void batadv_tt_purge(struct work_struct *work)
12358 +
12359 + void batadv_tt_free(struct batadv_priv *bat_priv)
12360 + {
12361 ++ batadv_tvlv_handler_unregister(bat_priv, BATADV_TVLV_ROAM, 1);
12362 ++
12363 + batadv_tvlv_container_unregister(bat_priv, BATADV_TVLV_TT, 1);
12364 + batadv_tvlv_handler_unregister(bat_priv, BATADV_TVLV_TT, 1);
12365 +
12366 +diff --git a/net/bluetooth/6lowpan.c b/net/bluetooth/6lowpan.c
12367 +index 4e2576fc0c59..357475cceec6 100644
12368 +--- a/net/bluetooth/6lowpan.c
12369 ++++ b/net/bluetooth/6lowpan.c
12370 +@@ -187,10 +187,16 @@ static inline struct lowpan_peer *peer_lookup_dst(struct lowpan_btle_dev *dev,
12371 + }
12372 +
12373 + if (!rt) {
12374 +- nexthop = &lowpan_cb(skb)->gw;
12375 +-
12376 +- if (ipv6_addr_any(nexthop))
12377 +- return NULL;
12378 ++ if (ipv6_addr_any(&lowpan_cb(skb)->gw)) {
12379 ++ /* There is neither route nor gateway,
12380 ++ * probably the destination is a direct peer.
12381 ++ */
12382 ++ nexthop = daddr;
12383 ++ } else {
12384 ++ /* There is a known gateway
12385 ++ */
12386 ++ nexthop = &lowpan_cb(skb)->gw;
12387 ++ }
12388 + } else {
12389 + nexthop = rt6_nexthop(rt, daddr);
12390 +
12391 +diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c
12392 +index 363dc85bbc5c..3d2f64a6d623 100644
12393 +--- a/net/bluetooth/hci_event.c
12394 ++++ b/net/bluetooth/hci_event.c
12395 +@@ -5089,6 +5089,11 @@ static void hci_le_remote_conn_param_req_evt(struct hci_dev *hdev,
12396 + return send_conn_param_neg_reply(hdev, handle,
12397 + HCI_ERROR_UNKNOWN_CONN_ID);
12398 +
12399 ++ if (min < hcon->le_conn_min_interval ||
12400 ++ max > hcon->le_conn_max_interval)
12401 ++ return send_conn_param_neg_reply(hdev, handle,
12402 ++ HCI_ERROR_INVALID_LL_PARAMS);
12403 ++
12404 + if (hci_check_conn_params(min, max, latency, timeout))
12405 + return send_conn_param_neg_reply(hdev, handle,
12406 + HCI_ERROR_INVALID_LL_PARAMS);
12407 +diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
12408 +index 0ee64f67300a..4dc1db85a9c2 100644
12409 +--- a/net/bluetooth/l2cap_core.c
12410 ++++ b/net/bluetooth/l2cap_core.c
12411 +@@ -4384,6 +4384,12 @@ static inline int l2cap_disconnect_rsp(struct l2cap_conn *conn,
12412 +
12413 + l2cap_chan_lock(chan);
12414 +
12415 ++ if (chan->state != BT_DISCONN) {
12416 ++ l2cap_chan_unlock(chan);
12417 ++ mutex_unlock(&conn->chan_lock);
12418 ++ return 0;
12419 ++ }
12420 ++
12421 + l2cap_chan_hold(chan);
12422 + l2cap_chan_del(chan, 0);
12423 +
12424 +@@ -5281,7 +5287,14 @@ static inline int l2cap_conn_param_update_req(struct l2cap_conn *conn,
12425 +
12426 + memset(&rsp, 0, sizeof(rsp));
12427 +
12428 +- err = hci_check_conn_params(min, max, latency, to_multiplier);
12429 ++ if (min < hcon->le_conn_min_interval ||
12430 ++ max > hcon->le_conn_max_interval) {
12431 ++ BT_DBG("requested connection interval exceeds current bounds.");
12432 ++ err = -EINVAL;
12433 ++ } else {
12434 ++ err = hci_check_conn_params(min, max, latency, to_multiplier);
12435 ++ }
12436 ++
12437 + if (err)
12438 + rsp.result = cpu_to_le16(L2CAP_CONN_PARAM_REJECTED);
12439 + else
12440 +diff --git a/net/bluetooth/smp.c b/net/bluetooth/smp.c
12441 +index dbcc439fc78b..6e9a247b15d7 100644
12442 +--- a/net/bluetooth/smp.c
12443 ++++ b/net/bluetooth/smp.c
12444 +@@ -2571,6 +2571,19 @@ static int smp_cmd_ident_addr_info(struct l2cap_conn *conn,
12445 + goto distribute;
12446 + }
12447 +
12448 ++ /* Drop IRK if peer is using identity address during pairing but is
12449 ++ * providing different address as identity information.
12450 ++ *
12451 ++ * Microsoft Surface Precision Mouse is known to have this bug.
12452 ++ */
12453 ++ if (hci_is_identity_address(&hcon->dst, hcon->dst_type) &&
12454 ++ (bacmp(&info->bdaddr, &hcon->dst) ||
12455 ++ info->addr_type != hcon->dst_type)) {
12456 ++ bt_dev_err(hcon->hdev,
12457 ++ "ignoring IRK with invalid identity address");
12458 ++ goto distribute;
12459 ++ }
12460 ++
12461 + bacpy(&smp->id_addr, &info->bdaddr);
12462 + smp->id_addr_type = info->addr_type;
12463 +
12464 +diff --git a/net/bridge/br_multicast.c b/net/bridge/br_multicast.c
12465 +index e83048cb53ce..5cd83145c7d8 100644
12466 +--- a/net/bridge/br_multicast.c
12467 ++++ b/net/bridge/br_multicast.c
12468 +@@ -1120,6 +1120,7 @@ static int br_ip4_multicast_igmp3_report(struct net_bridge *br,
12469 + int type;
12470 + int err = 0;
12471 + __be32 group;
12472 ++ u16 nsrcs;
12473 +
12474 + ih = igmpv3_report_hdr(skb);
12475 + num = ntohs(ih->ngrec);
12476 +@@ -1133,8 +1134,9 @@ static int br_ip4_multicast_igmp3_report(struct net_bridge *br,
12477 + grec = (void *)(skb->data + len - sizeof(*grec));
12478 + group = grec->grec_mca;
12479 + type = grec->grec_type;
12480 ++ nsrcs = ntohs(grec->grec_nsrcs);
12481 +
12482 +- len += ntohs(grec->grec_nsrcs) * 4;
12483 ++ len += nsrcs * 4;
12484 + if (!pskb_may_pull(skb, len))
12485 + return -EINVAL;
12486 +
12487 +@@ -1155,7 +1157,7 @@ static int br_ip4_multicast_igmp3_report(struct net_bridge *br,
12488 + src = eth_hdr(skb)->h_source;
12489 + if ((type == IGMPV3_CHANGE_TO_INCLUDE ||
12490 + type == IGMPV3_MODE_IS_INCLUDE) &&
12491 +- ntohs(grec->grec_nsrcs) == 0) {
12492 ++ nsrcs == 0) {
12493 + br_ip4_multicast_leave_group(br, port, group, vid, src);
12494 + } else {
12495 + err = br_ip4_multicast_add_group(br, port, group, vid,
12496 +@@ -1190,23 +1192,26 @@ static int br_ip6_multicast_mld2_report(struct net_bridge *br,
12497 + len = skb_transport_offset(skb) + sizeof(*icmp6h);
12498 +
12499 + for (i = 0; i < num; i++) {
12500 +- __be16 *nsrcs, _nsrcs;
12501 +-
12502 +- nsrcs = skb_header_pointer(skb,
12503 +- len + offsetof(struct mld2_grec,
12504 +- grec_nsrcs),
12505 +- sizeof(_nsrcs), &_nsrcs);
12506 +- if (!nsrcs)
12507 ++ __be16 *_nsrcs, __nsrcs;
12508 ++ u16 nsrcs;
12509 ++
12510 ++ _nsrcs = skb_header_pointer(skb,
12511 ++ len + offsetof(struct mld2_grec,
12512 ++ grec_nsrcs),
12513 ++ sizeof(__nsrcs), &__nsrcs);
12514 ++ if (!_nsrcs)
12515 + return -EINVAL;
12516 +
12517 ++ nsrcs = ntohs(*_nsrcs);
12518 ++
12519 + if (!pskb_may_pull(skb,
12520 + len + sizeof(*grec) +
12521 +- sizeof(struct in6_addr) * ntohs(*nsrcs)))
12522 ++ sizeof(struct in6_addr) * nsrcs))
12523 + return -EINVAL;
12524 +
12525 + grec = (struct mld2_grec *)(skb->data + len);
12526 + len += sizeof(*grec) +
12527 +- sizeof(struct in6_addr) * ntohs(*nsrcs);
12528 ++ sizeof(struct in6_addr) * nsrcs;
12529 +
12530 + /* We treat these as MLDv1 reports for now. */
12531 + switch (grec->grec_type) {
12532 +@@ -1225,7 +1230,7 @@ static int br_ip6_multicast_mld2_report(struct net_bridge *br,
12533 + src = eth_hdr(skb)->h_source;
12534 + if ((grec->grec_type == MLD2_CHANGE_TO_INCLUDE ||
12535 + grec->grec_type == MLD2_MODE_IS_INCLUDE) &&
12536 +- ntohs(*nsrcs) == 0) {
12537 ++ nsrcs == 0) {
12538 + br_ip6_multicast_leave_group(br, port, &grec->grec_mca,
12539 + vid, src);
12540 + } else {
12541 +@@ -1477,7 +1482,6 @@ static int br_ip6_multicast_query(struct net_bridge *br,
12542 + struct sk_buff *skb,
12543 + u16 vid)
12544 + {
12545 +- const struct ipv6hdr *ip6h = ipv6_hdr(skb);
12546 + struct mld_msg *mld;
12547 + struct net_bridge_mdb_entry *mp;
12548 + struct mld2_query *mld2q;
12549 +@@ -1521,7 +1525,7 @@ static int br_ip6_multicast_query(struct net_bridge *br,
12550 +
12551 + if (is_general_query) {
12552 + saddr.proto = htons(ETH_P_IPV6);
12553 +- saddr.u.ip6 = ip6h->saddr;
12554 ++ saddr.u.ip6 = ipv6_hdr(skb)->saddr;
12555 +
12556 + br_multicast_query_received(br, port, &br->ip6_other_query,
12557 + &saddr, max_delay);
12558 +diff --git a/net/bridge/br_stp_bpdu.c b/net/bridge/br_stp_bpdu.c
12559 +index 1b75d6bf12bd..37ddcea3fc96 100644
12560 +--- a/net/bridge/br_stp_bpdu.c
12561 ++++ b/net/bridge/br_stp_bpdu.c
12562 +@@ -147,7 +147,6 @@ void br_send_tcn_bpdu(struct net_bridge_port *p)
12563 + void br_stp_rcv(const struct stp_proto *proto, struct sk_buff *skb,
12564 + struct net_device *dev)
12565 + {
12566 +- const unsigned char *dest = eth_hdr(skb)->h_dest;
12567 + struct net_bridge_port *p;
12568 + struct net_bridge *br;
12569 + const unsigned char *buf;
12570 +@@ -176,7 +175,7 @@ void br_stp_rcv(const struct stp_proto *proto, struct sk_buff *skb,
12571 + if (p->state == BR_STATE_DISABLED)
12572 + goto out;
12573 +
12574 +- if (!ether_addr_equal(dest, br->group_addr))
12575 ++ if (!ether_addr_equal(eth_hdr(skb)->h_dest, br->group_addr))
12576 + goto out;
12577 +
12578 + if (p->flags & BR_BPDU_GUARD) {
12579 +diff --git a/net/core/filter.c b/net/core/filter.c
12580 +index 61396648381e..a3646230fbee 100644
12581 +--- a/net/core/filter.c
12582 ++++ b/net/core/filter.c
12583 +@@ -3122,7 +3122,8 @@ BPF_CALL_5(bpf_setsockopt, struct bpf_sock_ops_kern *, bpf_sock,
12584 + strncpy(name, optval, min_t(long, optlen,
12585 + TCP_CA_NAME_MAX-1));
12586 + name[TCP_CA_NAME_MAX-1] = 0;
12587 +- ret = tcp_set_congestion_control(sk, name, false, reinit);
12588 ++ ret = tcp_set_congestion_control(sk, name, false,
12589 ++ reinit, true);
12590 + } else {
12591 + struct tcp_sock *tp = tcp_sk(sk);
12592 +
12593 +diff --git a/net/core/neighbour.c b/net/core/neighbour.c
12594 +index 04b0e399361a..eb3efeabac91 100644
12595 +--- a/net/core/neighbour.c
12596 ++++ b/net/core/neighbour.c
12597 +@@ -1018,6 +1018,7 @@ int __neigh_event_send(struct neighbour *neigh, struct sk_buff *skb)
12598 +
12599 + atomic_set(&neigh->probes,
12600 + NEIGH_VAR(neigh->parms, UCAST_PROBES));
12601 ++ neigh_del_timer(neigh);
12602 + neigh->nud_state = NUD_INCOMPLETE;
12603 + neigh->updated = now;
12604 + next = now + max(NEIGH_VAR(neigh->parms, RETRANS_TIME),
12605 +@@ -1034,6 +1035,7 @@ int __neigh_event_send(struct neighbour *neigh, struct sk_buff *skb)
12606 + }
12607 + } else if (neigh->nud_state & NUD_STALE) {
12608 + neigh_dbg(2, "neigh %p is delayed\n", neigh);
12609 ++ neigh_del_timer(neigh);
12610 + neigh->nud_state = NUD_DELAY;
12611 + neigh->updated = jiffies;
12612 + neigh_add_timer(neigh, jiffies +
12613 +diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
12614 +index bffa88ecc534..5264510c9983 100644
12615 +--- a/net/ipv4/devinet.c
12616 ++++ b/net/ipv4/devinet.c
12617 +@@ -66,6 +66,11 @@
12618 + #include <net/net_namespace.h>
12619 + #include <net/addrconf.h>
12620 +
12621 ++#define IPV6ONLY_FLAGS \
12622 ++ (IFA_F_NODAD | IFA_F_OPTIMISTIC | IFA_F_DADFAILED | \
12623 ++ IFA_F_HOMEADDRESS | IFA_F_TENTATIVE | \
12624 ++ IFA_F_MANAGETEMPADDR | IFA_F_STABLE_PRIVACY)
12625 ++
12626 + static struct ipv4_devconf ipv4_devconf = {
12627 + .data = {
12628 + [IPV4_DEVCONF_ACCEPT_REDIRECTS - 1] = 1,
12629 +@@ -455,6 +460,9 @@ static int __inet_insert_ifa(struct in_ifaddr *ifa, struct nlmsghdr *nlh,
12630 + ifa->ifa_flags &= ~IFA_F_SECONDARY;
12631 + last_primary = &in_dev->ifa_list;
12632 +
12633 ++ /* Don't set IPv6 only flags to IPv4 addresses */
12634 ++ ifa->ifa_flags &= ~IPV6ONLY_FLAGS;
12635 ++
12636 + for (ifap = &in_dev->ifa_list; (ifa1 = *ifap) != NULL;
12637 + ifap = &ifa1->ifa_next) {
12638 + if (!(ifa1->ifa_flags & IFA_F_SECONDARY) &&
12639 +diff --git a/net/ipv4/igmp.c b/net/ipv4/igmp.c
12640 +index 94604f9bd0d7..b6f0ee01f2e0 100644
12641 +--- a/net/ipv4/igmp.c
12642 ++++ b/net/ipv4/igmp.c
12643 +@@ -1220,12 +1220,8 @@ static void igmpv3_del_delrec(struct in_device *in_dev, struct ip_mc_list *im)
12644 + im->interface = pmc->interface;
12645 + im->crcount = in_dev->mr_qrv ?: net->ipv4.sysctl_igmp_qrv;
12646 + if (im->sfmode == MCAST_INCLUDE) {
12647 +- im->tomb = pmc->tomb;
12648 +- pmc->tomb = NULL;
12649 +-
12650 +- im->sources = pmc->sources;
12651 +- pmc->sources = NULL;
12652 +-
12653 ++ swap(im->tomb, pmc->tomb);
12654 ++ swap(im->sources, pmc->sources);
12655 + for (psf = im->sources; psf; psf = psf->sf_next)
12656 + psf->sf_crcount = im->crcount;
12657 + }
12658 +diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
12659 +index d51571be9eac..541686f3f835 100644
12660 +--- a/net/ipv4/tcp.c
12661 ++++ b/net/ipv4/tcp.c
12662 +@@ -2366,6 +2366,8 @@ int tcp_disconnect(struct sock *sk, int flags)
12663 + dst_release(sk->sk_rx_dst);
12664 + sk->sk_rx_dst = NULL;
12665 + tcp_saved_syn_free(tp);
12666 ++ tp->bytes_acked = 0;
12667 ++ tp->bytes_received = 0;
12668 +
12669 + /* Clean up fastopen related fields */
12670 + tcp_free_fastopen_req(tp);
12671 +@@ -2500,7 +2502,9 @@ static int do_tcp_setsockopt(struct sock *sk, int level,
12672 + name[val] = 0;
12673 +
12674 + lock_sock(sk);
12675 +- err = tcp_set_congestion_control(sk, name, true, true);
12676 ++ err = tcp_set_congestion_control(sk, name, true, true,
12677 ++ ns_capable(sock_net(sk)->user_ns,
12678 ++ CAP_NET_ADMIN));
12679 + release_sock(sk);
12680 + return err;
12681 + }
12682 +diff --git a/net/ipv4/tcp_cong.c b/net/ipv4/tcp_cong.c
12683 +index 2f26124fd160..494e3c3a21a1 100644
12684 +--- a/net/ipv4/tcp_cong.c
12685 ++++ b/net/ipv4/tcp_cong.c
12686 +@@ -338,7 +338,8 @@ out:
12687 + * tcp_reinit_congestion_control (if the current congestion control was
12688 + * already initialized.
12689 + */
12690 +-int tcp_set_congestion_control(struct sock *sk, const char *name, bool load, bool reinit)
12691 ++int tcp_set_congestion_control(struct sock *sk, const char *name, bool load,
12692 ++ bool reinit, bool cap_net_admin)
12693 + {
12694 + struct inet_connection_sock *icsk = inet_csk(sk);
12695 + const struct tcp_congestion_ops *ca;
12696 +@@ -372,8 +373,7 @@ int tcp_set_congestion_control(struct sock *sk, const char *name, bool load, boo
12697 + } else {
12698 + err = -EBUSY;
12699 + }
12700 +- } else if (!((ca->flags & TCP_CONG_NON_RESTRICTED) ||
12701 +- ns_capable(sock_net(sk)->user_ns, CAP_NET_ADMIN))) {
12702 ++ } else if (!((ca->flags & TCP_CONG_NON_RESTRICTED) || cap_net_admin)) {
12703 + err = -EPERM;
12704 + } else if (!try_module_get(ca->owner)) {
12705 + err = -EBUSY;
12706 +diff --git a/net/key/af_key.c b/net/key/af_key.c
12707 +index b095551a5773..ac38b47e9f86 100644
12708 +--- a/net/key/af_key.c
12709 ++++ b/net/key/af_key.c
12710 +@@ -2438,8 +2438,10 @@ static int key_pol_get_resp(struct sock *sk, struct xfrm_policy *xp, const struc
12711 + goto out;
12712 + }
12713 + err = pfkey_xfrm_policy2msg(out_skb, xp, dir);
12714 +- if (err < 0)
12715 ++ if (err < 0) {
12716 ++ kfree_skb(out_skb);
12717 + goto out;
12718 ++ }
12719 +
12720 + out_hdr = (struct sadb_msg *) out_skb->data;
12721 + out_hdr->sadb_msg_version = hdr->sadb_msg_version;
12722 +@@ -2690,8 +2692,10 @@ static int dump_sp(struct xfrm_policy *xp, int dir, int count, void *ptr)
12723 + return PTR_ERR(out_skb);
12724 +
12725 + err = pfkey_xfrm_policy2msg(out_skb, xp, dir);
12726 +- if (err < 0)
12727 ++ if (err < 0) {
12728 ++ kfree_skb(out_skb);
12729 + return err;
12730 ++ }
12731 +
12732 + out_hdr = (struct sadb_msg *) out_skb->data;
12733 + out_hdr->sadb_msg_version = pfk->dump.msg_version;
12734 +diff --git a/net/netfilter/ipset/ip_set_hash_gen.h b/net/netfilter/ipset/ip_set_hash_gen.h
12735 +index dfd268166e42..42d9cd22447e 100644
12736 +--- a/net/netfilter/ipset/ip_set_hash_gen.h
12737 ++++ b/net/netfilter/ipset/ip_set_hash_gen.h
12738 +@@ -624,7 +624,7 @@ retry:
12739 + goto cleanup;
12740 + }
12741 + m->size = AHASH_INIT_SIZE;
12742 +- extsize = ext_size(AHASH_INIT_SIZE, dsize);
12743 ++ extsize += ext_size(AHASH_INIT_SIZE, dsize);
12744 + RCU_INIT_POINTER(hbucket(t, key), m);
12745 + } else if (m->pos >= m->size) {
12746 + struct hbucket *ht;
12747 +diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
12748 +index ee97ce176b9a..2156571455db 100644
12749 +--- a/net/netfilter/ipvs/ip_vs_core.c
12750 ++++ b/net/netfilter/ipvs/ip_vs_core.c
12751 +@@ -2206,7 +2206,6 @@ static const struct nf_hook_ops ip_vs_ops[] = {
12752 + static int __net_init __ip_vs_init(struct net *net)
12753 + {
12754 + struct netns_ipvs *ipvs;
12755 +- int ret;
12756 +
12757 + ipvs = net_generic(net, ip_vs_net_id);
12758 + if (ipvs == NULL)
12759 +@@ -2238,17 +2237,11 @@ static int __net_init __ip_vs_init(struct net *net)
12760 + if (ip_vs_sync_net_init(ipvs) < 0)
12761 + goto sync_fail;
12762 +
12763 +- ret = nf_register_net_hooks(net, ip_vs_ops, ARRAY_SIZE(ip_vs_ops));
12764 +- if (ret < 0)
12765 +- goto hook_fail;
12766 +-
12767 + return 0;
12768 + /*
12769 + * Error handling
12770 + */
12771 +
12772 +-hook_fail:
12773 +- ip_vs_sync_net_cleanup(ipvs);
12774 + sync_fail:
12775 + ip_vs_conn_net_cleanup(ipvs);
12776 + conn_fail:
12777 +@@ -2278,6 +2271,19 @@ static void __net_exit __ip_vs_cleanup(struct net *net)
12778 + net->ipvs = NULL;
12779 + }
12780 +
12781 ++static int __net_init __ip_vs_dev_init(struct net *net)
12782 ++{
12783 ++ int ret;
12784 ++
12785 ++ ret = nf_register_net_hooks(net, ip_vs_ops, ARRAY_SIZE(ip_vs_ops));
12786 ++ if (ret < 0)
12787 ++ goto hook_fail;
12788 ++ return 0;
12789 ++
12790 ++hook_fail:
12791 ++ return ret;
12792 ++}
12793 ++
12794 + static void __net_exit __ip_vs_dev_cleanup(struct net *net)
12795 + {
12796 + struct netns_ipvs *ipvs = net_ipvs(net);
12797 +@@ -2297,6 +2303,7 @@ static struct pernet_operations ipvs_core_ops = {
12798 + };
12799 +
12800 + static struct pernet_operations ipvs_core_dev_ops = {
12801 ++ .init = __ip_vs_dev_init,
12802 + .exit = __ip_vs_dev_cleanup,
12803 + };
12804 +
12805 +diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
12806 +index 6d7608b88f66..4648dccebf59 100644
12807 +--- a/net/netfilter/ipvs/ip_vs_ctl.c
12808 ++++ b/net/netfilter/ipvs/ip_vs_ctl.c
12809 +@@ -2414,9 +2414,7 @@ do_ip_vs_set_ctl(struct sock *sk, int cmd, void __user *user, unsigned int len)
12810 + cfg.syncid = dm->syncid;
12811 + ret = start_sync_thread(ipvs, &cfg, dm->state);
12812 + } else {
12813 +- mutex_lock(&ipvs->sync_mutex);
12814 + ret = stop_sync_thread(ipvs, dm->state);
12815 +- mutex_unlock(&ipvs->sync_mutex);
12816 + }
12817 + goto out_dec;
12818 + }
12819 +@@ -3524,10 +3522,8 @@ static int ip_vs_genl_del_daemon(struct netns_ipvs *ipvs, struct nlattr **attrs)
12820 + if (!attrs[IPVS_DAEMON_ATTR_STATE])
12821 + return -EINVAL;
12822 +
12823 +- mutex_lock(&ipvs->sync_mutex);
12824 + ret = stop_sync_thread(ipvs,
12825 + nla_get_u32(attrs[IPVS_DAEMON_ATTR_STATE]));
12826 +- mutex_unlock(&ipvs->sync_mutex);
12827 + return ret;
12828 + }
12829 +
12830 +diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
12831 +index 5e07f7a6794e..b578ebb3d7ef 100644
12832 +--- a/net/netfilter/ipvs/ip_vs_sync.c
12833 ++++ b/net/netfilter/ipvs/ip_vs_sync.c
12834 +@@ -195,6 +195,7 @@ union ip_vs_sync_conn {
12835 + #define IPVS_OPT_F_PARAM (1 << (IPVS_OPT_PARAM-1))
12836 +
12837 + struct ip_vs_sync_thread_data {
12838 ++ struct task_struct *task;
12839 + struct netns_ipvs *ipvs;
12840 + struct socket *sock;
12841 + char *buf;
12842 +@@ -374,8 +375,11 @@ static inline void sb_queue_tail(struct netns_ipvs *ipvs,
12843 + max(IPVS_SYNC_SEND_DELAY, 1));
12844 + ms->sync_queue_len++;
12845 + list_add_tail(&sb->list, &ms->sync_queue);
12846 +- if ((++ms->sync_queue_delay) == IPVS_SYNC_WAKEUP_RATE)
12847 +- wake_up_process(ms->master_thread);
12848 ++ if ((++ms->sync_queue_delay) == IPVS_SYNC_WAKEUP_RATE) {
12849 ++ int id = (int)(ms - ipvs->ms);
12850 ++
12851 ++ wake_up_process(ipvs->master_tinfo[id].task);
12852 ++ }
12853 + } else
12854 + ip_vs_sync_buff_release(sb);
12855 + spin_unlock(&ipvs->sync_lock);
12856 +@@ -1645,8 +1649,10 @@ static void master_wakeup_work_handler(struct work_struct *work)
12857 + spin_lock_bh(&ipvs->sync_lock);
12858 + if (ms->sync_queue_len &&
12859 + ms->sync_queue_delay < IPVS_SYNC_WAKEUP_RATE) {
12860 ++ int id = (int)(ms - ipvs->ms);
12861 ++
12862 + ms->sync_queue_delay = IPVS_SYNC_WAKEUP_RATE;
12863 +- wake_up_process(ms->master_thread);
12864 ++ wake_up_process(ipvs->master_tinfo[id].task);
12865 + }
12866 + spin_unlock_bh(&ipvs->sync_lock);
12867 + }
12868 +@@ -1712,10 +1718,6 @@ done:
12869 + if (sb)
12870 + ip_vs_sync_buff_release(sb);
12871 +
12872 +- /* release the sending multicast socket */
12873 +- sock_release(tinfo->sock);
12874 +- kfree(tinfo);
12875 +-
12876 + return 0;
12877 + }
12878 +
12879 +@@ -1749,11 +1751,6 @@ static int sync_thread_backup(void *data)
12880 + }
12881 + }
12882 +
12883 +- /* release the sending multicast socket */
12884 +- sock_release(tinfo->sock);
12885 +- kfree(tinfo->buf);
12886 +- kfree(tinfo);
12887 +-
12888 + return 0;
12889 + }
12890 +
12891 +@@ -1761,8 +1758,8 @@ static int sync_thread_backup(void *data)
12892 + int start_sync_thread(struct netns_ipvs *ipvs, struct ipvs_sync_daemon_cfg *c,
12893 + int state)
12894 + {
12895 +- struct ip_vs_sync_thread_data *tinfo = NULL;
12896 +- struct task_struct **array = NULL, *task;
12897 ++ struct ip_vs_sync_thread_data *ti = NULL, *tinfo;
12898 ++ struct task_struct *task;
12899 + struct net_device *dev;
12900 + char *name;
12901 + int (*threadfn)(void *data);
12902 +@@ -1831,7 +1828,7 @@ int start_sync_thread(struct netns_ipvs *ipvs, struct ipvs_sync_daemon_cfg *c,
12903 + threadfn = sync_thread_master;
12904 + } else if (state == IP_VS_STATE_BACKUP) {
12905 + result = -EEXIST;
12906 +- if (ipvs->backup_threads)
12907 ++ if (ipvs->backup_tinfo)
12908 + goto out_early;
12909 +
12910 + ipvs->bcfg = *c;
12911 +@@ -1858,28 +1855,22 @@ int start_sync_thread(struct netns_ipvs *ipvs, struct ipvs_sync_daemon_cfg *c,
12912 + master_wakeup_work_handler);
12913 + ms->ipvs = ipvs;
12914 + }
12915 +- } else {
12916 +- array = kcalloc(count, sizeof(struct task_struct *),
12917 +- GFP_KERNEL);
12918 +- result = -ENOMEM;
12919 +- if (!array)
12920 +- goto out;
12921 + }
12922 ++ result = -ENOMEM;
12923 ++ ti = kcalloc(count, sizeof(struct ip_vs_sync_thread_data),
12924 ++ GFP_KERNEL);
12925 ++ if (!ti)
12926 ++ goto out;
12927 +
12928 + for (id = 0; id < count; id++) {
12929 +- result = -ENOMEM;
12930 +- tinfo = kmalloc(sizeof(*tinfo), GFP_KERNEL);
12931 +- if (!tinfo)
12932 +- goto out;
12933 ++ tinfo = &ti[id];
12934 + tinfo->ipvs = ipvs;
12935 +- tinfo->sock = NULL;
12936 + if (state == IP_VS_STATE_BACKUP) {
12937 ++ result = -ENOMEM;
12938 + tinfo->buf = kmalloc(ipvs->bcfg.sync_maxlen,
12939 + GFP_KERNEL);
12940 + if (!tinfo->buf)
12941 + goto out;
12942 +- } else {
12943 +- tinfo->buf = NULL;
12944 + }
12945 + tinfo->id = id;
12946 + if (state == IP_VS_STATE_MASTER)
12947 +@@ -1894,17 +1885,15 @@ int start_sync_thread(struct netns_ipvs *ipvs, struct ipvs_sync_daemon_cfg *c,
12948 + result = PTR_ERR(task);
12949 + goto out;
12950 + }
12951 +- tinfo = NULL;
12952 +- if (state == IP_VS_STATE_MASTER)
12953 +- ipvs->ms[id].master_thread = task;
12954 +- else
12955 +- array[id] = task;
12956 ++ tinfo->task = task;
12957 + }
12958 +
12959 + /* mark as active */
12960 +
12961 +- if (state == IP_VS_STATE_BACKUP)
12962 +- ipvs->backup_threads = array;
12963 ++ if (state == IP_VS_STATE_MASTER)
12964 ++ ipvs->master_tinfo = ti;
12965 ++ else
12966 ++ ipvs->backup_tinfo = ti;
12967 + spin_lock_bh(&ipvs->sync_buff_lock);
12968 + ipvs->sync_state |= state;
12969 + spin_unlock_bh(&ipvs->sync_buff_lock);
12970 +@@ -1919,29 +1908,31 @@ int start_sync_thread(struct netns_ipvs *ipvs, struct ipvs_sync_daemon_cfg *c,
12971 +
12972 + out:
12973 + /* We do not need RTNL lock anymore, release it here so that
12974 +- * sock_release below and in the kthreads can use rtnl_lock
12975 +- * to leave the mcast group.
12976 ++ * sock_release below can use rtnl_lock to leave the mcast group.
12977 + */
12978 + rtnl_unlock();
12979 +- count = id;
12980 +- while (count-- > 0) {
12981 +- if (state == IP_VS_STATE_MASTER)
12982 +- kthread_stop(ipvs->ms[count].master_thread);
12983 +- else
12984 +- kthread_stop(array[count]);
12985 ++ id = min(id, count - 1);
12986 ++ if (ti) {
12987 ++ for (tinfo = ti + id; tinfo >= ti; tinfo--) {
12988 ++ if (tinfo->task)
12989 ++ kthread_stop(tinfo->task);
12990 ++ }
12991 + }
12992 + if (!(ipvs->sync_state & IP_VS_STATE_MASTER)) {
12993 + kfree(ipvs->ms);
12994 + ipvs->ms = NULL;
12995 + }
12996 + mutex_unlock(&ipvs->sync_mutex);
12997 +- if (tinfo) {
12998 +- if (tinfo->sock)
12999 +- sock_release(tinfo->sock);
13000 +- kfree(tinfo->buf);
13001 +- kfree(tinfo);
13002 ++
13003 ++ /* No more mutexes, release socks */
13004 ++ if (ti) {
13005 ++ for (tinfo = ti + id; tinfo >= ti; tinfo--) {
13006 ++ if (tinfo->sock)
13007 ++ sock_release(tinfo->sock);
13008 ++ kfree(tinfo->buf);
13009 ++ }
13010 ++ kfree(ti);
13011 + }
13012 +- kfree(array);
13013 + return result;
13014 +
13015 + out_early:
13016 +@@ -1953,15 +1944,18 @@ out_early:
13017 +
13018 + int stop_sync_thread(struct netns_ipvs *ipvs, int state)
13019 + {
13020 +- struct task_struct **array;
13021 ++ struct ip_vs_sync_thread_data *ti, *tinfo;
13022 + int id;
13023 + int retc = -EINVAL;
13024 +
13025 + IP_VS_DBG(7, "%s(): pid %d\n", __func__, task_pid_nr(current));
13026 +
13027 ++ mutex_lock(&ipvs->sync_mutex);
13028 + if (state == IP_VS_STATE_MASTER) {
13029 ++ retc = -ESRCH;
13030 + if (!ipvs->ms)
13031 +- return -ESRCH;
13032 ++ goto err;
13033 ++ ti = ipvs->master_tinfo;
13034 +
13035 + /*
13036 + * The lock synchronizes with sb_queue_tail(), so that we don't
13037 +@@ -1980,38 +1974,56 @@ int stop_sync_thread(struct netns_ipvs *ipvs, int state)
13038 + struct ipvs_master_sync_state *ms = &ipvs->ms[id];
13039 + int ret;
13040 +
13041 ++ tinfo = &ti[id];
13042 + pr_info("stopping master sync thread %d ...\n",
13043 +- task_pid_nr(ms->master_thread));
13044 ++ task_pid_nr(tinfo->task));
13045 + cancel_delayed_work_sync(&ms->master_wakeup_work);
13046 +- ret = kthread_stop(ms->master_thread);
13047 ++ ret = kthread_stop(tinfo->task);
13048 + if (retc >= 0)
13049 + retc = ret;
13050 + }
13051 + kfree(ipvs->ms);
13052 + ipvs->ms = NULL;
13053 ++ ipvs->master_tinfo = NULL;
13054 + } else if (state == IP_VS_STATE_BACKUP) {
13055 +- if (!ipvs->backup_threads)
13056 +- return -ESRCH;
13057 ++ retc = -ESRCH;
13058 ++ if (!ipvs->backup_tinfo)
13059 ++ goto err;
13060 ++ ti = ipvs->backup_tinfo;
13061 +
13062 + ipvs->sync_state &= ~IP_VS_STATE_BACKUP;
13063 +- array = ipvs->backup_threads;
13064 + retc = 0;
13065 + for (id = ipvs->threads_mask; id >= 0; id--) {
13066 + int ret;
13067 +
13068 ++ tinfo = &ti[id];
13069 + pr_info("stopping backup sync thread %d ...\n",
13070 +- task_pid_nr(array[id]));
13071 +- ret = kthread_stop(array[id]);
13072 ++ task_pid_nr(tinfo->task));
13073 ++ ret = kthread_stop(tinfo->task);
13074 + if (retc >= 0)
13075 + retc = ret;
13076 + }
13077 +- kfree(array);
13078 +- ipvs->backup_threads = NULL;
13079 ++ ipvs->backup_tinfo = NULL;
13080 ++ } else {
13081 ++ goto err;
13082 + }
13083 ++ id = ipvs->threads_mask;
13084 ++ mutex_unlock(&ipvs->sync_mutex);
13085 ++
13086 ++ /* No more mutexes, release socks */
13087 ++ for (tinfo = ti + id; tinfo >= ti; tinfo--) {
13088 ++ if (tinfo->sock)
13089 ++ sock_release(tinfo->sock);
13090 ++ kfree(tinfo->buf);
13091 ++ }
13092 ++ kfree(ti);
13093 +
13094 + /* decrease the module use count */
13095 + ip_vs_use_count_dec();
13096 ++ return retc;
13097 +
13098 ++err:
13099 ++ mutex_unlock(&ipvs->sync_mutex);
13100 + return retc;
13101 + }
13102 +
13103 +@@ -2030,7 +2042,6 @@ void ip_vs_sync_net_cleanup(struct netns_ipvs *ipvs)
13104 + {
13105 + int retc;
13106 +
13107 +- mutex_lock(&ipvs->sync_mutex);
13108 + retc = stop_sync_thread(ipvs, IP_VS_STATE_MASTER);
13109 + if (retc && retc != -ESRCH)
13110 + pr_err("Failed to stop Master Daemon\n");
13111 +@@ -2038,5 +2049,4 @@ void ip_vs_sync_net_cleanup(struct netns_ipvs *ipvs)
13112 + retc = stop_sync_thread(ipvs, IP_VS_STATE_BACKUP);
13113 + if (retc && retc != -ESRCH)
13114 + pr_err("Failed to stop Backup Daemon\n");
13115 +- mutex_unlock(&ipvs->sync_mutex);
13116 + }
13117 +diff --git a/net/netfilter/nf_queue.c b/net/netfilter/nf_queue.c
13118 +index 8260b1e73bbd..37efcc1c8887 100644
13119 +--- a/net/netfilter/nf_queue.c
13120 ++++ b/net/netfilter/nf_queue.c
13121 +@@ -138,6 +138,11 @@ static int __nf_queue(struct sk_buff *skb, const struct nf_hook_state *state,
13122 + goto err;
13123 + }
13124 +
13125 ++ if (!skb_dst_force(skb) && state->hook != NF_INET_PRE_ROUTING) {
13126 ++ status = -ENETDOWN;
13127 ++ goto err;
13128 ++ }
13129 ++
13130 + *entry = (struct nf_queue_entry) {
13131 + .skb = skb,
13132 + .state = *state,
13133 +@@ -146,7 +151,6 @@ static int __nf_queue(struct sk_buff *skb, const struct nf_hook_state *state,
13134 + };
13135 +
13136 + nf_queue_entry_get_refs(entry);
13137 +- skb_dst_force(skb);
13138 + afinfo->saveroute(skb, entry);
13139 + status = qh->outfn(entry, queuenum);
13140 +
13141 +diff --git a/net/netrom/af_netrom.c b/net/netrom/af_netrom.c
13142 +index fc876b0c3e06..aebc804c10aa 100644
13143 +--- a/net/netrom/af_netrom.c
13144 ++++ b/net/netrom/af_netrom.c
13145 +@@ -871,7 +871,7 @@ int nr_rx_frame(struct sk_buff *skb, struct net_device *dev)
13146 + unsigned short frametype, flags, window, timeout;
13147 + int ret;
13148 +
13149 +- skb->sk = NULL; /* Initially we don't know who it's for */
13150 ++ skb_orphan(skb);
13151 +
13152 + /*
13153 + * skb->data points to the netrom frame start
13154 +@@ -969,7 +969,9 @@ int nr_rx_frame(struct sk_buff *skb, struct net_device *dev)
13155 +
13156 + window = skb->data[20];
13157 +
13158 ++ sock_hold(make);
13159 + skb->sk = make;
13160 ++ skb->destructor = sock_efree;
13161 + make->sk_state = TCP_ESTABLISHED;
13162 +
13163 + /* Fill in his circuit details */
13164 +diff --git a/net/nfc/nci/data.c b/net/nfc/nci/data.c
13165 +index 908f25e3773e..5405d073804c 100644
13166 +--- a/net/nfc/nci/data.c
13167 ++++ b/net/nfc/nci/data.c
13168 +@@ -119,7 +119,7 @@ static int nci_queue_tx_data_frags(struct nci_dev *ndev,
13169 + conn_info = nci_get_conn_info_by_conn_id(ndev, conn_id);
13170 + if (!conn_info) {
13171 + rc = -EPROTO;
13172 +- goto free_exit;
13173 ++ goto exit;
13174 + }
13175 +
13176 + __skb_queue_head_init(&frags_q);
13177 +diff --git a/net/openvswitch/actions.c b/net/openvswitch/actions.c
13178 +index a54a556fcdb5..5601e2c6ac05 100644
13179 +--- a/net/openvswitch/actions.c
13180 ++++ b/net/openvswitch/actions.c
13181 +@@ -174,8 +174,7 @@ static void update_ethertype(struct sk_buff *skb, struct ethhdr *hdr,
13182 + if (skb->ip_summed == CHECKSUM_COMPLETE) {
13183 + __be16 diff[] = { ~(hdr->h_proto), ethertype };
13184 +
13185 +- skb->csum = ~csum_partial((char *)diff, sizeof(diff),
13186 +- ~skb->csum);
13187 ++ skb->csum = csum_partial((char *)diff, sizeof(diff), skb->csum);
13188 + }
13189 +
13190 + hdr->h_proto = ethertype;
13191 +@@ -267,8 +266,7 @@ static int set_mpls(struct sk_buff *skb, struct sw_flow_key *flow_key,
13192 + if (skb->ip_summed == CHECKSUM_COMPLETE) {
13193 + __be32 diff[] = { ~(stack->label_stack_entry), lse };
13194 +
13195 +- skb->csum = ~csum_partial((char *)diff, sizeof(diff),
13196 +- ~skb->csum);
13197 ++ skb->csum = csum_partial((char *)diff, sizeof(diff), skb->csum);
13198 + }
13199 +
13200 + stack->label_stack_entry = lse;
13201 +diff --git a/net/rxrpc/af_rxrpc.c b/net/rxrpc/af_rxrpc.c
13202 +index 2a32f60652d8..296b9efe6641 100644
13203 +--- a/net/rxrpc/af_rxrpc.c
13204 ++++ b/net/rxrpc/af_rxrpc.c
13205 +@@ -504,6 +504,7 @@ static int rxrpc_sendmsg(struct socket *sock, struct msghdr *m, size_t len)
13206 +
13207 + switch (rx->sk.sk_state) {
13208 + case RXRPC_UNBOUND:
13209 ++ case RXRPC_CLIENT_UNBOUND:
13210 + rx->srx.srx_family = AF_RXRPC;
13211 + rx->srx.srx_service = 0;
13212 + rx->srx.transport_type = SOCK_DGRAM;
13213 +@@ -528,10 +529,9 @@ static int rxrpc_sendmsg(struct socket *sock, struct msghdr *m, size_t len)
13214 + }
13215 +
13216 + rx->local = local;
13217 +- rx->sk.sk_state = RXRPC_CLIENT_UNBOUND;
13218 ++ rx->sk.sk_state = RXRPC_CLIENT_BOUND;
13219 + /* Fall through */
13220 +
13221 +- case RXRPC_CLIENT_UNBOUND:
13222 + case RXRPC_CLIENT_BOUND:
13223 + if (!m->msg_name &&
13224 + test_bit(RXRPC_SOCK_CONNECTED, &rx->flags)) {
13225 +diff --git a/net/vmw_vsock/hyperv_transport.c b/net/vmw_vsock/hyperv_transport.c
13226 +index 2c63f7b169b5..3bee93bc5d11 100644
13227 +--- a/net/vmw_vsock/hyperv_transport.c
13228 ++++ b/net/vmw_vsock/hyperv_transport.c
13229 +@@ -217,18 +217,6 @@ static void hvs_set_channel_pending_send_size(struct vmbus_channel *chan)
13230 + set_channel_pending_send_size(chan,
13231 + HVS_PKT_LEN(HVS_SEND_BUF_SIZE));
13232 +
13233 +- /* See hvs_stream_has_space(): we must make sure the host has seen
13234 +- * the new pending send size, before we can re-check the writable
13235 +- * bytes.
13236 +- */
13237 +- virt_mb();
13238 +-}
13239 +-
13240 +-static void hvs_clear_channel_pending_send_size(struct vmbus_channel *chan)
13241 +-{
13242 +- set_channel_pending_send_size(chan, 0);
13243 +-
13244 +- /* Ditto */
13245 + virt_mb();
13246 + }
13247 +
13248 +@@ -298,9 +286,6 @@ static void hvs_channel_cb(void *ctx)
13249 + if (hvs_channel_readable(chan))
13250 + sk->sk_data_ready(sk);
13251 +
13252 +- /* See hvs_stream_has_space(): when we reach here, the writable bytes
13253 +- * may be already less than HVS_PKT_LEN(HVS_SEND_BUF_SIZE).
13254 +- */
13255 + if (hv_get_bytes_to_write(&chan->outbound) > 0)
13256 + sk->sk_write_space(sk);
13257 + }
13258 +@@ -328,8 +313,9 @@ static void hvs_open_connection(struct vmbus_channel *chan)
13259 +
13260 + struct sockaddr_vm addr;
13261 + struct sock *sk, *new = NULL;
13262 +- struct vsock_sock *vnew;
13263 +- struct hvsock *hvs, *hvs_new;
13264 ++ struct vsock_sock *vnew = NULL;
13265 ++ struct hvsock *hvs = NULL;
13266 ++ struct hvsock *hvs_new = NULL;
13267 + int ret;
13268 +
13269 + if_type = &chan->offermsg.offer.if_type;
13270 +@@ -389,6 +375,13 @@ static void hvs_open_connection(struct vmbus_channel *chan)
13271 + set_per_channel_state(chan, conn_from_host ? new : sk);
13272 + vmbus_set_chn_rescind_callback(chan, hvs_close_connection);
13273 +
13274 ++ /* Set the pending send size to max packet size to always get
13275 ++ * notifications from the host when there is enough writable space.
13276 ++ * The host is optimized to send notifications only when the pending
13277 ++ * size boundary is crossed, and not always.
13278 ++ */
13279 ++ hvs_set_channel_pending_send_size(chan);
13280 ++
13281 + if (conn_from_host) {
13282 + new->sk_state = SS_CONNECTED;
13283 + sk->sk_ack_backlog++;
13284 +@@ -652,23 +645,8 @@ static s64 hvs_stream_has_data(struct vsock_sock *vsk)
13285 + static s64 hvs_stream_has_space(struct vsock_sock *vsk)
13286 + {
13287 + struct hvsock *hvs = vsk->trans;
13288 +- struct vmbus_channel *chan = hvs->chan;
13289 +- s64 ret;
13290 +-
13291 +- ret = hvs_channel_writable_bytes(chan);
13292 +- if (ret > 0) {
13293 +- hvs_clear_channel_pending_send_size(chan);
13294 +- } else {
13295 +- /* See hvs_channel_cb() */
13296 +- hvs_set_channel_pending_send_size(chan);
13297 +-
13298 +- /* Re-check the writable bytes to avoid race */
13299 +- ret = hvs_channel_writable_bytes(chan);
13300 +- if (ret > 0)
13301 +- hvs_clear_channel_pending_send_size(chan);
13302 +- }
13303 +
13304 +- return ret;
13305 ++ return hvs_channel_writable_bytes(hvs->chan);
13306 + }
13307 +
13308 + static u64 hvs_stream_rcvhiwat(struct vsock_sock *vsk)
13309 +diff --git a/net/xfrm/Kconfig b/net/xfrm/Kconfig
13310 +index 286ed25c1a69..2e747ae7dc89 100644
13311 +--- a/net/xfrm/Kconfig
13312 ++++ b/net/xfrm/Kconfig
13313 +@@ -14,6 +14,8 @@ config XFRM_ALGO
13314 + tristate
13315 + select XFRM
13316 + select CRYPTO
13317 ++ select CRYPTO_HASH
13318 ++ select CRYPTO_BLKCIPHER
13319 +
13320 + config XFRM_USER
13321 + tristate "Transformation user configuration interface"
13322 +diff --git a/net/xfrm/xfrm_user.c b/net/xfrm/xfrm_user.c
13323 +index 919b8406028c..150c58dc8a7b 100644
13324 +--- a/net/xfrm/xfrm_user.c
13325 ++++ b/net/xfrm/xfrm_user.c
13326 +@@ -150,6 +150,25 @@ static int verify_newsa_info(struct xfrm_usersa_info *p,
13327 +
13328 + err = -EINVAL;
13329 + switch (p->family) {
13330 ++ case AF_INET:
13331 ++ break;
13332 ++
13333 ++ case AF_INET6:
13334 ++#if IS_ENABLED(CONFIG_IPV6)
13335 ++ break;
13336 ++#else
13337 ++ err = -EAFNOSUPPORT;
13338 ++ goto out;
13339 ++#endif
13340 ++
13341 ++ default:
13342 ++ goto out;
13343 ++ }
13344 ++
13345 ++ switch (p->sel.family) {
13346 ++ case AF_UNSPEC:
13347 ++ break;
13348 ++
13349 + case AF_INET:
13350 + if (p->sel.prefixlen_d > 32 || p->sel.prefixlen_s > 32)
13351 + goto out;
13352 +diff --git a/scripts/kallsyms.c b/scripts/kallsyms.c
13353 +index 1dd24c5b9b47..b471022c8162 100644
13354 +--- a/scripts/kallsyms.c
13355 ++++ b/scripts/kallsyms.c
13356 +@@ -160,6 +160,9 @@ static int read_symbol(FILE *in, struct sym_entry *s)
13357 + /* exclude debugging symbols */
13358 + else if (stype == 'N' || stype == 'n')
13359 + return -1;
13360 ++ /* exclude s390 kasan local symbols */
13361 ++ else if (!strncmp(sym, ".LASANPC", 8))
13362 ++ return -1;
13363 +
13364 + /* include the type field in the symbol name, so that it gets
13365 + * compressed together */
13366 +diff --git a/scripts/recordmcount.h b/scripts/recordmcount.h
13367 +index b9897e2be404..04151ede8043 100644
13368 +--- a/scripts/recordmcount.h
13369 ++++ b/scripts/recordmcount.h
13370 +@@ -326,7 +326,8 @@ static uint_t *sift_rel_mcount(uint_t *mlocp,
13371 + if (!mcountsym)
13372 + mcountsym = get_mcountsym(sym0, relp, str0);
13373 +
13374 +- if (mcountsym == Elf_r_sym(relp) && !is_fake_mcount(relp)) {
13375 ++ if (mcountsym && mcountsym == Elf_r_sym(relp) &&
13376 ++ !is_fake_mcount(relp)) {
13377 + uint_t const addend =
13378 + _w(_w(relp->r_offset) - recval + mcount_adjust);
13379 + mrelp->r_offset = _w(offbase
13380 +diff --git a/sound/core/seq/seq_clientmgr.c b/sound/core/seq/seq_clientmgr.c
13381 +index 7d2c07c1237c..cc5b4c25d6f1 100644
13382 +--- a/sound/core/seq/seq_clientmgr.c
13383 ++++ b/sound/core/seq/seq_clientmgr.c
13384 +@@ -1001,7 +1001,7 @@ static ssize_t snd_seq_write(struct file *file, const char __user *buf,
13385 + {
13386 + struct snd_seq_client *client = file->private_data;
13387 + int written = 0, len;
13388 +- int err;
13389 ++ int err, handled;
13390 + struct snd_seq_event event;
13391 +
13392 + if (!(snd_seq_file_flags(file) & SNDRV_SEQ_LFLG_OUTPUT))
13393 +@@ -1014,6 +1014,8 @@ static ssize_t snd_seq_write(struct file *file, const char __user *buf,
13394 + if (!client->accept_output || client->pool == NULL)
13395 + return -ENXIO;
13396 +
13397 ++ repeat:
13398 ++ handled = 0;
13399 + /* allocate the pool now if the pool is not allocated yet */
13400 + mutex_lock(&client->ioctl_mutex);
13401 + if (client->pool->size > 0 && !snd_seq_write_pool_allocated(client)) {
13402 +@@ -1073,12 +1075,19 @@ static ssize_t snd_seq_write(struct file *file, const char __user *buf,
13403 + 0, 0, &client->ioctl_mutex);
13404 + if (err < 0)
13405 + break;
13406 ++ handled++;
13407 +
13408 + __skip_event:
13409 + /* Update pointers and counts */
13410 + count -= len;
13411 + buf += len;
13412 + written += len;
13413 ++
13414 ++ /* let's have a coffee break if too many events are queued */
13415 ++ if (++handled >= 200) {
13416 ++ mutex_unlock(&client->ioctl_mutex);
13417 ++ goto repeat;
13418 ++ }
13419 + }
13420 +
13421 + out:
13422 +diff --git a/sound/pci/hda/patch_conexant.c b/sound/pci/hda/patch_conexant.c
13423 +index d14516f31679..7bdf10e754f5 100644
13424 +--- a/sound/pci/hda/patch_conexant.c
13425 ++++ b/sound/pci/hda/patch_conexant.c
13426 +@@ -1127,6 +1127,7 @@ static int patch_conexant_auto(struct hda_codec *codec)
13427 + */
13428 +
13429 + static const struct hda_device_id snd_hda_id_conexant[] = {
13430 ++ HDA_CODEC_ENTRY(0x14f11f86, "CX8070", patch_conexant_auto),
13431 + HDA_CODEC_ENTRY(0x14f12008, "CX8200", patch_conexant_auto),
13432 + HDA_CODEC_ENTRY(0x14f15045, "CX20549 (Venice)", patch_conexant_auto),
13433 + HDA_CODEC_ENTRY(0x14f15047, "CX20551 (Waikiki)", patch_conexant_auto),
13434 +diff --git a/sound/pci/hda/patch_realtek.c b/sound/pci/hda/patch_realtek.c
13435 +index 20914a33ca5d..6d32c44cd0c8 100644
13436 +--- a/sound/pci/hda/patch_realtek.c
13437 ++++ b/sound/pci/hda/patch_realtek.c
13438 +@@ -8149,6 +8149,11 @@ static const struct snd_hda_pin_quirk alc662_pin_fixup_tbl[] = {
13439 + {0x18, 0x01a19030},
13440 + {0x1a, 0x01813040},
13441 + {0x21, 0x01014020}),
13442 ++ SND_HDA_PIN_QUIRK(0x10ec0867, 0x1028, "Dell", ALC891_FIXUP_DELL_MIC_NO_PRESENCE,
13443 ++ {0x16, 0x01813030},
13444 ++ {0x17, 0x02211010},
13445 ++ {0x18, 0x01a19040},
13446 ++ {0x21, 0x01014020}),
13447 + SND_HDA_PIN_QUIRK(0x10ec0662, 0x1028, "Dell", ALC662_FIXUP_DELL_MIC_NO_PRESENCE,
13448 + {0x14, 0x01014010},
13449 + {0x18, 0x01a19020},
13450 +diff --git a/sound/soc/soc-dapm.c b/sound/soc/soc-dapm.c
13451 +index e9f7c6287376..b4c8ba412a5c 100644
13452 +--- a/sound/soc/soc-dapm.c
13453 ++++ b/sound/soc/soc-dapm.c
13454 +@@ -2120,23 +2120,25 @@ void snd_soc_dapm_debugfs_init(struct snd_soc_dapm_context *dapm,
13455 + {
13456 + struct dentry *d;
13457 +
13458 +- if (!parent)
13459 ++ if (!parent || IS_ERR(parent))
13460 + return;
13461 +
13462 + dapm->debugfs_dapm = debugfs_create_dir("dapm", parent);
13463 +
13464 +- if (!dapm->debugfs_dapm) {
13465 ++ if (IS_ERR(dapm->debugfs_dapm)) {
13466 + dev_warn(dapm->dev,
13467 +- "ASoC: Failed to create DAPM debugfs directory\n");
13468 ++ "ASoC: Failed to create DAPM debugfs directory %ld\n",
13469 ++ PTR_ERR(dapm->debugfs_dapm));
13470 + return;
13471 + }
13472 +
13473 + d = debugfs_create_file("bias_level", 0444,
13474 + dapm->debugfs_dapm, dapm,
13475 + &dapm_bias_fops);
13476 +- if (!d)
13477 ++ if (IS_ERR(d))
13478 + dev_warn(dapm->dev,
13479 +- "ASoC: Failed to create bias level debugfs file\n");
13480 ++ "ASoC: Failed to create bias level debugfs file: %ld\n",
13481 ++ PTR_ERR(d));
13482 + }
13483 +
13484 + static void dapm_debugfs_add_widget(struct snd_soc_dapm_widget *w)
13485 +@@ -2150,10 +2152,10 @@ static void dapm_debugfs_add_widget(struct snd_soc_dapm_widget *w)
13486 + d = debugfs_create_file(w->name, 0444,
13487 + dapm->debugfs_dapm, w,
13488 + &dapm_widget_power_fops);
13489 +- if (!d)
13490 ++ if (IS_ERR(d))
13491 + dev_warn(w->dapm->dev,
13492 +- "ASoC: Failed to create %s debugfs file\n",
13493 +- w->name);
13494 ++ "ASoC: Failed to create %s debugfs file: %ld\n",
13495 ++ w->name, PTR_ERR(d));
13496 + }
13497 +
13498 + static void dapm_debugfs_cleanup(struct snd_soc_dapm_context *dapm)
13499 +diff --git a/sound/usb/line6/podhd.c b/sound/usb/line6/podhd.c
13500 +index ee6a68c6e1c1..1513fbaf70c2 100644
13501 +--- a/sound/usb/line6/podhd.c
13502 ++++ b/sound/usb/line6/podhd.c
13503 +@@ -415,7 +415,7 @@ static const struct line6_properties podhd_properties_table[] = {
13504 + .name = "POD HD500",
13505 + .capabilities = LINE6_CAP_PCM
13506 + | LINE6_CAP_HWMON,
13507 +- .altsetting = 1,
13508 ++ .altsetting = 0,
13509 + .ep_ctrl_r = 0x81,
13510 + .ep_ctrl_w = 0x01,
13511 + .ep_audio_r = 0x86,
13512 +diff --git a/tools/iio/iio_utils.c b/tools/iio/iio_utils.c
13513 +index 7a6d61c6c012..55272fef3b50 100644
13514 +--- a/tools/iio/iio_utils.c
13515 ++++ b/tools/iio/iio_utils.c
13516 +@@ -159,9 +159,9 @@ int iioutils_get_type(unsigned *is_signed, unsigned *bytes, unsigned *bits_used,
13517 + *be = (endianchar == 'b');
13518 + *bytes = padint / 8;
13519 + if (*bits_used == 64)
13520 +- *mask = ~0;
13521 ++ *mask = ~(0ULL);
13522 + else
13523 +- *mask = (1ULL << *bits_used) - 1;
13524 ++ *mask = (1ULL << *bits_used) - 1ULL;
13525 +
13526 + *is_signed = (signchar == 's');
13527 + if (fclose(sysfsfp)) {
13528 +diff --git a/tools/perf/arch/arm/util/cs-etm.c b/tools/perf/arch/arm/util/cs-etm.c
13529 +index fbfc055d3f4d..aec62e822bab 100644
13530 +--- a/tools/perf/arch/arm/util/cs-etm.c
13531 ++++ b/tools/perf/arch/arm/util/cs-etm.c
13532 +@@ -43,6 +43,8 @@ struct cs_etm_recording {
13533 + struct auxtrace_record itr;
13534 + struct perf_pmu *cs_etm_pmu;
13535 + struct perf_evlist *evlist;
13536 ++ int wrapped_cnt;
13537 ++ bool *wrapped;
13538 + bool snapshot_mode;
13539 + size_t snapshot_size;
13540 + };
13541 +@@ -485,16 +487,131 @@ static int cs_etm_info_fill(struct auxtrace_record *itr,
13542 + return 0;
13543 + }
13544 +
13545 +-static int cs_etm_find_snapshot(struct auxtrace_record *itr __maybe_unused,
13546 ++static int cs_etm_alloc_wrapped_array(struct cs_etm_recording *ptr, int idx)
13547 ++{
13548 ++ bool *wrapped;
13549 ++ int cnt = ptr->wrapped_cnt;
13550 ++
13551 ++ /* Make @ptr->wrapped as big as @idx */
13552 ++ while (cnt <= idx)
13553 ++ cnt++;
13554 ++
13555 ++ /*
13556 ++ * Free'ed in cs_etm_recording_free(). Using realloc() to avoid
13557 ++ * cross compilation problems where the host's system supports
13558 ++ * reallocarray() but not the target.
13559 ++ */
13560 ++ wrapped = realloc(ptr->wrapped, cnt * sizeof(bool));
13561 ++ if (!wrapped)
13562 ++ return -ENOMEM;
13563 ++
13564 ++ wrapped[cnt - 1] = false;
13565 ++ ptr->wrapped_cnt = cnt;
13566 ++ ptr->wrapped = wrapped;
13567 ++
13568 ++ return 0;
13569 ++}
13570 ++
13571 ++static bool cs_etm_buffer_has_wrapped(unsigned char *buffer,
13572 ++ size_t buffer_size, u64 head)
13573 ++{
13574 ++ u64 i, watermark;
13575 ++ u64 *buf = (u64 *)buffer;
13576 ++ size_t buf_size = buffer_size;
13577 ++
13578 ++ /*
13579 ++ * We want to look the very last 512 byte (chosen arbitrarily) in
13580 ++ * the ring buffer.
13581 ++ */
13582 ++ watermark = buf_size - 512;
13583 ++
13584 ++ /*
13585 ++ * @head is continuously increasing - if its value is equal or greater
13586 ++ * than the size of the ring buffer, it has wrapped around.
13587 ++ */
13588 ++ if (head >= buffer_size)
13589 ++ return true;
13590 ++
13591 ++ /*
13592 ++ * The value of @head is somewhere within the size of the ring buffer.
13593 ++ * This can be that there hasn't been enough data to fill the ring
13594 ++ * buffer yet or the trace time was so long that @head has numerically
13595 ++ * wrapped around. To find we need to check if we have data at the very
13596 ++ * end of the ring buffer. We can reliably do this because mmap'ed
13597 ++ * pages are zeroed out and there is a fresh mapping with every new
13598 ++ * session.
13599 ++ */
13600 ++
13601 ++ /* @head is less than 512 byte from the end of the ring buffer */
13602 ++ if (head > watermark)
13603 ++ watermark = head;
13604 ++
13605 ++ /*
13606 ++ * Speed things up by using 64 bit transactions (see "u64 *buf" above)
13607 ++ */
13608 ++ watermark >>= 3;
13609 ++ buf_size >>= 3;
13610 ++
13611 ++ /*
13612 ++ * If we find trace data at the end of the ring buffer, @head has
13613 ++ * been there and has numerically wrapped around at least once.
13614 ++ */
13615 ++ for (i = watermark; i < buf_size; i++)
13616 ++ if (buf[i])
13617 ++ return true;
13618 ++
13619 ++ return false;
13620 ++}
13621 ++
13622 ++static int cs_etm_find_snapshot(struct auxtrace_record *itr,
13623 + int idx, struct auxtrace_mmap *mm,
13624 +- unsigned char *data __maybe_unused,
13625 ++ unsigned char *data,
13626 + u64 *head, u64 *old)
13627 + {
13628 ++ int err;
13629 ++ bool wrapped;
13630 ++ struct cs_etm_recording *ptr =
13631 ++ container_of(itr, struct cs_etm_recording, itr);
13632 ++
13633 ++ /*
13634 ++ * Allocate memory to keep track of wrapping if this is the first
13635 ++ * time we deal with this *mm.
13636 ++ */
13637 ++ if (idx >= ptr->wrapped_cnt) {
13638 ++ err = cs_etm_alloc_wrapped_array(ptr, idx);
13639 ++ if (err)
13640 ++ return err;
13641 ++ }
13642 ++
13643 ++ /*
13644 ++ * Check to see if *head has wrapped around. If it hasn't only the
13645 ++ * amount of data between *head and *old is snapshot'ed to avoid
13646 ++ * bloating the perf.data file with zeros. But as soon as *head has
13647 ++ * wrapped around the entire size of the AUX ring buffer it taken.
13648 ++ */
13649 ++ wrapped = ptr->wrapped[idx];
13650 ++ if (!wrapped && cs_etm_buffer_has_wrapped(data, mm->len, *head)) {
13651 ++ wrapped = true;
13652 ++ ptr->wrapped[idx] = true;
13653 ++ }
13654 ++
13655 + pr_debug3("%s: mmap index %d old head %zu new head %zu size %zu\n",
13656 + __func__, idx, (size_t)*old, (size_t)*head, mm->len);
13657 +
13658 +- *old = *head;
13659 +- *head += mm->len;
13660 ++ /* No wrap has occurred, we can just use *head and *old. */
13661 ++ if (!wrapped)
13662 ++ return 0;
13663 ++
13664 ++ /*
13665 ++ * *head has wrapped around - adjust *head and *old to pickup the
13666 ++ * entire content of the AUX buffer.
13667 ++ */
13668 ++ if (*head >= mm->len) {
13669 ++ *old = *head - mm->len;
13670 ++ } else {
13671 ++ *head += mm->len;
13672 ++ *old = *head - mm->len;
13673 ++ }
13674 +
13675 + return 0;
13676 + }
13677 +@@ -535,6 +652,8 @@ static void cs_etm_recording_free(struct auxtrace_record *itr)
13678 + {
13679 + struct cs_etm_recording *ptr =
13680 + container_of(itr, struct cs_etm_recording, itr);
13681 ++
13682 ++ zfree(&ptr->wrapped);
13683 + free(ptr);
13684 + }
13685 +
13686 +diff --git a/tools/perf/perf.h b/tools/perf/perf.h
13687 +index 96f62dd7e3ed..d4ebd0956114 100644
13688 +--- a/tools/perf/perf.h
13689 ++++ b/tools/perf/perf.h
13690 +@@ -25,7 +25,7 @@ static inline unsigned long long rdclock(void)
13691 + }
13692 +
13693 + #ifndef MAX_NR_CPUS
13694 +-#define MAX_NR_CPUS 1024
13695 ++#define MAX_NR_CPUS 2048
13696 + #endif
13697 +
13698 + extern const char *input_name;
13699 +diff --git a/tools/perf/tests/mmap-thread-lookup.c b/tools/perf/tests/mmap-thread-lookup.c
13700 +index 3c3f3e029e33..2ecb86876f10 100644
13701 +--- a/tools/perf/tests/mmap-thread-lookup.c
13702 ++++ b/tools/perf/tests/mmap-thread-lookup.c
13703 +@@ -52,7 +52,7 @@ static void *thread_fn(void *arg)
13704 + {
13705 + struct thread_data *td = arg;
13706 + ssize_t ret;
13707 +- int go;
13708 ++ int go = 0;
13709 +
13710 + if (thread_init(td))
13711 + return NULL;
13712 +diff --git a/tools/perf/tests/parse-events.c b/tools/perf/tests/parse-events.c
13713 +index f0679613bd18..424b82a7d078 100644
13714 +--- a/tools/perf/tests/parse-events.c
13715 ++++ b/tools/perf/tests/parse-events.c
13716 +@@ -19,6 +19,32 @@
13717 + #define PERF_TP_SAMPLE_TYPE (PERF_SAMPLE_RAW | PERF_SAMPLE_TIME | \
13718 + PERF_SAMPLE_CPU | PERF_SAMPLE_PERIOD)
13719 +
13720 ++#if defined(__s390x__)
13721 ++/* Return true if kvm module is available and loaded. Test this
13722 ++ * and retun success when trace point kvm_s390_create_vm
13723 ++ * exists. Otherwise this test always fails.
13724 ++ */
13725 ++static bool kvm_s390_create_vm_valid(void)
13726 ++{
13727 ++ char *eventfile;
13728 ++ bool rc = false;
13729 ++
13730 ++ eventfile = get_events_file("kvm-s390");
13731 ++
13732 ++ if (eventfile) {
13733 ++ DIR *mydir = opendir(eventfile);
13734 ++
13735 ++ if (mydir) {
13736 ++ rc = true;
13737 ++ closedir(mydir);
13738 ++ }
13739 ++ put_events_file(eventfile);
13740 ++ }
13741 ++
13742 ++ return rc;
13743 ++}
13744 ++#endif
13745 ++
13746 + static int test__checkevent_tracepoint(struct perf_evlist *evlist)
13747 + {
13748 + struct perf_evsel *evsel = perf_evlist__first(evlist);
13749 +@@ -1600,6 +1626,7 @@ static struct evlist_test test__events[] = {
13750 + {
13751 + .name = "kvm-s390:kvm_s390_create_vm",
13752 + .check = test__checkevent_tracepoint,
13753 ++ .valid = kvm_s390_create_vm_valid,
13754 + .id = 100,
13755 + },
13756 + #endif
13757 +diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c
13758 +index 398d4cc2f0e4..2a8d2a6723f6 100644
13759 +--- a/tools/perf/util/annotate.c
13760 ++++ b/tools/perf/util/annotate.c
13761 +@@ -868,16 +868,14 @@ static int disasm_line__parse(char *line, const char **namep, char **rawp)
13762 + *namep = strdup(name);
13763 +
13764 + if (*namep == NULL)
13765 +- goto out_free_name;
13766 ++ goto out;
13767 +
13768 + (*rawp)[0] = tmp;
13769 + *rawp = ltrim(*rawp);
13770 +
13771 + return 0;
13772 +
13773 +-out_free_name:
13774 +- free((void *)namep);
13775 +- *namep = NULL;
13776 ++out:
13777 + return -1;
13778 + }
13779 +
13780 +diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
13781 +index 0cf6f537f980..3ab81e8e079e 100644
13782 +--- a/tools/perf/util/evsel.c
13783 ++++ b/tools/perf/util/evsel.c
13784 +@@ -587,6 +587,9 @@ const char *perf_evsel__name(struct perf_evsel *evsel)
13785 + {
13786 + char bf[128];
13787 +
13788 ++ if (!evsel)
13789 ++ goto out_unknown;
13790 ++
13791 + if (evsel->name)
13792 + return evsel->name;
13793 +
13794 +@@ -623,7 +626,10 @@ const char *perf_evsel__name(struct perf_evsel *evsel)
13795 +
13796 + evsel->name = strdup(bf);
13797 +
13798 +- return evsel->name ?: "unknown";
13799 ++ if (evsel->name)
13800 ++ return evsel->name;
13801 ++out_unknown:
13802 ++ return "unknown";
13803 + }
13804 +
13805 + const char *perf_evsel__group_name(struct perf_evsel *evsel)
13806 +diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
13807 +index f11cead6a151..26437143c940 100644
13808 +--- a/tools/perf/util/header.c
13809 ++++ b/tools/perf/util/header.c
13810 +@@ -1122,7 +1122,7 @@ static int build_caches(struct cpu_cache_level caches[], u32 size, u32 *cntp)
13811 + return 0;
13812 + }
13813 +
13814 +-#define MAX_CACHES 2000
13815 ++#define MAX_CACHES (MAX_NR_CPUS * 4)
13816 +
13817 + static int write_cache(struct feat_fd *ff,
13818 + struct perf_evlist *evlist __maybe_unused)
13819 +diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c
13820 +index da55081aefc6..c49e8ea1a42c 100644
13821 +--- a/tools/perf/util/session.c
13822 ++++ b/tools/perf/util/session.c
13823 +@@ -1145,6 +1145,9 @@ static void dump_read(struct perf_evsel *evsel, union perf_event *event)
13824 + evsel ? perf_evsel__name(evsel) : "FAIL",
13825 + event->read.value);
13826 +
13827 ++ if (!evsel)
13828 ++ return;
13829 ++
13830 + read_format = evsel->attr.read_format;
13831 +
13832 + if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED)
13833 +diff --git a/tools/perf/util/stat-shadow.c b/tools/perf/util/stat-shadow.c
13834 +index 37363869c9a1..eadc9a2aef16 100644
13835 +--- a/tools/perf/util/stat-shadow.c
13836 ++++ b/tools/perf/util/stat-shadow.c
13837 +@@ -271,7 +271,7 @@ static struct perf_evsel *perf_stat__find_event(struct perf_evlist *evsel_list,
13838 + struct perf_evsel *c2;
13839 +
13840 + evlist__for_each_entry (evsel_list, c2) {
13841 +- if (!strcasecmp(c2->name, name))
13842 ++ if (!strcasecmp(c2->name, name) && !c2->collect_stat)
13843 + return c2;
13844 + }
13845 + return NULL;
13846 +@@ -310,7 +310,8 @@ void perf_stat__collect_metric_expr(struct perf_evlist *evsel_list)
13847 + if (leader) {
13848 + /* Search in group */
13849 + for_each_group_member (oc, leader) {
13850 +- if (!strcasecmp(oc->name, metric_names[i])) {
13851 ++ if (!strcasecmp(oc->name, metric_names[i]) &&
13852 ++ !oc->collect_stat) {
13853 + found = true;
13854 + break;
13855 + }
13856 +diff --git a/tools/power/cpupower/utils/cpufreq-set.c b/tools/power/cpupower/utils/cpufreq-set.c
13857 +index 1eef0aed6423..08a405593a79 100644
13858 +--- a/tools/power/cpupower/utils/cpufreq-set.c
13859 ++++ b/tools/power/cpupower/utils/cpufreq-set.c
13860 +@@ -306,6 +306,8 @@ int cmd_freq_set(int argc, char **argv)
13861 + bitmask_setbit(cpus_chosen, cpus->cpu);
13862 + cpus = cpus->next;
13863 + }
13864 ++ /* Set the last cpu in related cpus list */
13865 ++ bitmask_setbit(cpus_chosen, cpus->cpu);
13866 + cpufreq_put_related_cpus(cpus);
13867 + }
13868 + }