Gentoo Archives: gentoo-commits

From: Mike Pagano <mpagano@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/linux-patches:6.0 commit in: /
Date: Sat, 31 Dec 2022 15:29:34
Message-Id: 1672500556.47bebee42dd8af1585608157960c0bcf25816035.mpagano@gentoo
1 commit: 47bebee42dd8af1585608157960c0bcf25816035
2 Author: Mike Pagano <mpagano <AT> gentoo <DOT> org>
3 AuthorDate: Sat Dec 31 15:29:16 2022 +0000
4 Commit: Mike Pagano <mpagano <AT> gentoo <DOT> org>
5 CommitDate: Sat Dec 31 15:29:16 2022 +0000
6 URL: https://gitweb.gentoo.org/proj/linux-patches.git/commit/?id=47bebee4
7
8 Linux patch 6.0.16
9
10 Signed-off-by: Mike Pagano <mpagano <AT> gentoo.org>
11
12 0000_README | 4 +
13 1015_linux-6.0.16.patch | 45617 ++++++++++++++++++++++++++++++++++++++++++++++
14 2 files changed, 45621 insertions(+)
15
16 diff --git a/0000_README b/0000_README
17 index 302d8339..44fc4c7e 100644
18 --- a/0000_README
19 +++ b/0000_README
20 @@ -103,6 +103,10 @@ Patch: 1014_linux-6.0.15.patch
21 From: http://www.kernel.org
22 Desc: Linux 6.0.15
23
24 +Patch: 1015_linux-6.0.16.patch
25 +From: http://www.kernel.org
26 +Desc: Linux 6.0.16
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/1015_linux-6.0.16.patch b/1015_linux-6.0.16.patch
33 new file mode 100644
34 index 00000000..e72ee462
35 --- /dev/null
36 +++ b/1015_linux-6.0.16.patch
37 @@ -0,0 +1,45617 @@
38 +diff --git a/Documentation/ABI/testing/sysfs-bus-spi-devices-spi-nor b/Documentation/ABI/testing/sysfs-bus-spi-devices-spi-nor
39 +index d76cd3946434d..e9ef69aef20b1 100644
40 +--- a/Documentation/ABI/testing/sysfs-bus-spi-devices-spi-nor
41 ++++ b/Documentation/ABI/testing/sysfs-bus-spi-devices-spi-nor
42 +@@ -5,6 +5,9 @@ Contact: linux-mtd@×××××××××××××××.org
43 + Description: (RO) The JEDEC ID of the SPI NOR flash as reported by the
44 + flash device.
45 +
46 ++ The attribute is not present if the flash doesn't support
47 ++ the "Read JEDEC ID" command (9Fh). This is the case for
48 ++ non-JEDEC compliant flashes.
49 +
50 + What: /sys/bus/spi/devices/.../spi-nor/manufacturer
51 + Date: April 2021
52 +diff --git a/Documentation/admin-guide/sysctl/kernel.rst b/Documentation/admin-guide/sysctl/kernel.rst
53 +index ee6572b1edada..66d1b23ca64fe 100644
54 +--- a/Documentation/admin-guide/sysctl/kernel.rst
55 ++++ b/Documentation/admin-guide/sysctl/kernel.rst
56 +@@ -1298,6 +1298,29 @@ watchdog work to be queued by the watchdog timer function, otherwise the NMI
57 + watchdog — if enabled — can detect a hard lockup condition.
58 +
59 +
60 ++split_lock_mitigate (x86 only)
61 ++==============================
62 ++
63 ++On x86, each "split lock" imposes a system-wide performance penalty. On larger
64 ++systems, large numbers of split locks from unprivileged users can result in
65 ++denials of service to well-behaved and potentially more important users.
66 ++
67 ++The kernel mitigates these bad users by detecting split locks and imposing
68 ++penalties: forcing them to wait and only allowing one core to execute split
69 ++locks at a time.
70 ++
71 ++These mitigations can make those bad applications unbearably slow. Setting
72 ++split_lock_mitigate=0 may restore some application performance, but will also
73 ++increase system exposure to denial of service attacks from split lock users.
74 ++
75 ++= ===================================================================
76 ++0 Disable the mitigation mode - just warns the split lock on kernel log
77 ++ and exposes the system to denials of service from the split lockers.
78 ++1 Enable the mitigation mode (this is the default) - penalizes the split
79 ++ lockers with intentional performance degradation.
80 ++= ===================================================================
81 ++
82 ++
83 + stack_erasing
84 + =============
85 +
86 +diff --git a/Documentation/devicetree/bindings/clock/qcom,sc7280-lpasscorecc.yaml b/Documentation/devicetree/bindings/clock/qcom,sc7280-lpasscorecc.yaml
87 +index bad9135489de5..1d20cdcc69ff8 100644
88 +--- a/Documentation/devicetree/bindings/clock/qcom,sc7280-lpasscorecc.yaml
89 ++++ b/Documentation/devicetree/bindings/clock/qcom,sc7280-lpasscorecc.yaml
90 +@@ -22,6 +22,8 @@ properties:
91 +
92 + clock-names: true
93 +
94 ++ reg: true
95 ++
96 + compatible:
97 + enum:
98 + - qcom,sc7280-lpassaoncc
99 +@@ -38,8 +40,8 @@ properties:
100 + '#power-domain-cells':
101 + const: 1
102 +
103 +- reg:
104 +- maxItems: 1
105 ++ '#reset-cells':
106 ++ const: 1
107 +
108 + required:
109 + - compatible
110 +@@ -69,6 +71,11 @@ allOf:
111 + items:
112 + - const: bi_tcxo
113 + - const: lpass_aon_cc_main_rcg_clk_src
114 ++
115 ++ reg:
116 ++ items:
117 ++ - description: lpass core cc register
118 ++ - description: lpass audio csr register
119 + - if:
120 + properties:
121 + compatible:
122 +@@ -90,6 +97,8 @@ allOf:
123 + - const: bi_tcxo_ao
124 + - const: iface
125 +
126 ++ reg:
127 ++ maxItems: 1
128 + - if:
129 + properties:
130 + compatible:
131 +@@ -108,6 +117,8 @@ allOf:
132 + items:
133 + - const: bi_tcxo
134 +
135 ++ reg:
136 ++ maxItems: 1
137 + examples:
138 + - |
139 + #include <dt-bindings/clock/qcom,rpmh.h>
140 +@@ -116,13 +127,15 @@ examples:
141 + #include <dt-bindings/clock/qcom,lpasscorecc-sc7280.h>
142 + lpass_audiocc: clock-controller@3300000 {
143 + compatible = "qcom,sc7280-lpassaudiocc";
144 +- reg = <0x3300000 0x30000>;
145 ++ reg = <0x3300000 0x30000>,
146 ++ <0x32a9000 0x1000>;
147 + clocks = <&rpmhcc RPMH_CXO_CLK>,
148 + <&lpass_aon LPASS_AON_CC_MAIN_RCG_CLK_SRC>;
149 + clock-names = "bi_tcxo", "lpass_aon_cc_main_rcg_clk_src";
150 + power-domains = <&lpass_aon LPASS_AON_CC_LPASS_AUDIO_HM_GDSC>;
151 + #clock-cells = <1>;
152 + #power-domain-cells = <1>;
153 ++ #reset-cells = <1>;
154 + };
155 +
156 + - |
157 +diff --git a/Documentation/devicetree/bindings/input/azoteq,iqs7222.yaml b/Documentation/devicetree/bindings/input/azoteq,iqs7222.yaml
158 +index 02e605fac408d..9ddba7f2e7aa6 100644
159 +--- a/Documentation/devicetree/bindings/input/azoteq,iqs7222.yaml
160 ++++ b/Documentation/devicetree/bindings/input/azoteq,iqs7222.yaml
161 +@@ -473,9 +473,6 @@ patternProperties:
162 + Specifies whether the event is to be interpreted as a key (1)
163 + or a switch (5).
164 +
165 +- required:
166 +- - linux,code
167 +-
168 + additionalProperties: false
169 +
170 + dependencies:
171 +@@ -501,7 +498,7 @@ patternProperties:
172 +
173 + azoteq,slider-size:
174 + $ref: /schemas/types.yaml#/definitions/uint32
175 +- minimum: 0
176 ++ minimum: 1
177 + maximum: 65535
178 + description:
179 + Specifies the slider's one-dimensional resolution, equal to the
180 +@@ -575,9 +572,9 @@ patternProperties:
181 + linux,code: true
182 +
183 + azoteq,gesture-max-ms:
184 +- multipleOf: 4
185 ++ multipleOf: 16
186 + minimum: 0
187 +- maximum: 1020
188 ++ maximum: 4080
189 + description:
190 + Specifies the length of time (in ms) within which a tap, swipe
191 + or flick gesture must be completed in order to be acknowledged
192 +@@ -585,9 +582,9 @@ patternProperties:
193 + gesture applies to all remaining swipe or flick gestures.
194 +
195 + azoteq,gesture-min-ms:
196 +- multipleOf: 4
197 ++ multipleOf: 16
198 + minimum: 0
199 +- maximum: 124
200 ++ maximum: 496
201 + description:
202 + Specifies the length of time (in ms) for which a tap gesture must
203 + be held in order to be acknowledged by the device.
204 +@@ -620,9 +617,6 @@ patternProperties:
205 + GPIO, they must all be of the same type (proximity, touch or
206 + slider gesture).
207 +
208 +- required:
209 +- - linux,code
210 +-
211 + additionalProperties: false
212 +
213 + required:
214 +@@ -693,6 +687,7 @@ allOf:
215 + properties:
216 + azoteq,slider-size:
217 + multipleOf: 16
218 ++ minimum: 16
219 + maximum: 4080
220 +
221 + azoteq,top-speed:
222 +@@ -935,14 +930,14 @@ examples:
223 +
224 + event-tap {
225 + linux,code = <KEY_PLAYPAUSE>;
226 +- azoteq,gesture-max-ms = <600>;
227 +- azoteq,gesture-min-ms = <24>;
228 ++ azoteq,gesture-max-ms = <400>;
229 ++ azoteq,gesture-min-ms = <32>;
230 + };
231 +
232 + event-flick-pos {
233 + linux,code = <KEY_NEXTSONG>;
234 +- azoteq,gesture-max-ms = <600>;
235 +- azoteq,gesture-dist = <816>;
236 ++ azoteq,gesture-max-ms = <800>;
237 ++ azoteq,gesture-dist = <800>;
238 + };
239 +
240 + event-flick-neg {
241 +diff --git a/Documentation/devicetree/bindings/mfd/qcom,spmi-pmic.yaml b/Documentation/devicetree/bindings/mfd/qcom,spmi-pmic.yaml
242 +index 65cbc6dee545e..2a5bafe0660a0 100644
243 +--- a/Documentation/devicetree/bindings/mfd/qcom,spmi-pmic.yaml
244 ++++ b/Documentation/devicetree/bindings/mfd/qcom,spmi-pmic.yaml
245 +@@ -92,6 +92,10 @@ properties:
246 + type: object
247 + $ref: /schemas/regulator/regulator.yaml#
248 +
249 ++ pwm:
250 ++ type: object
251 ++ $ref: /schemas/leds/leds-qcom-lpg.yaml#
252 ++
253 + patternProperties:
254 + "^adc@[0-9a-f]+$":
255 + type: object
256 +@@ -117,10 +121,6 @@ patternProperties:
257 + type: object
258 + $ref: /schemas/power/reset/qcom,pon.yaml#
259 +
260 +- "pwm@[0-9a-f]+$":
261 +- type: object
262 +- $ref: /schemas/leds/leds-qcom-lpg.yaml#
263 +-
264 + "^rtc@[0-9a-f]+$":
265 + type: object
266 + $ref: /schemas/rtc/qcom-pm8xxx-rtc.yaml#
267 +diff --git a/Documentation/devicetree/bindings/pci/fsl,imx6q-pcie.yaml b/Documentation/devicetree/bindings/pci/fsl,imx6q-pcie.yaml
268 +index 376e739bcad40..49b4f7a32e71e 100644
269 +--- a/Documentation/devicetree/bindings/pci/fsl,imx6q-pcie.yaml
270 ++++ b/Documentation/devicetree/bindings/pci/fsl,imx6q-pcie.yaml
271 +@@ -14,9 +14,6 @@ description: |+
272 + This PCIe host controller is based on the Synopsys DesignWare PCIe IP
273 + and thus inherits all the common properties defined in snps,dw-pcie.yaml.
274 +
275 +-allOf:
276 +- - $ref: /schemas/pci/snps,dw-pcie.yaml#
277 +-
278 + properties:
279 + compatible:
280 + enum:
281 +@@ -61,7 +58,7 @@ properties:
282 + - const: pcie
283 + - const: pcie_bus
284 + - const: pcie_phy
285 +- - const: pcie_inbound_axi for imx6sx-pcie, pcie_aux for imx8mq-pcie
286 ++ - enum: [ pcie_inbound_axi, pcie_aux ]
287 +
288 + num-lanes:
289 + const: 1
290 +@@ -175,6 +172,47 @@ required:
291 + - clocks
292 + - clock-names
293 +
294 ++allOf:
295 ++ - $ref: /schemas/pci/snps,dw-pcie.yaml#
296 ++ - if:
297 ++ properties:
298 ++ compatible:
299 ++ contains:
300 ++ const: fsl,imx6sx-pcie
301 ++ then:
302 ++ properties:
303 ++ clock-names:
304 ++ items:
305 ++ - {}
306 ++ - {}
307 ++ - {}
308 ++ - const: pcie_inbound_axi
309 ++ - if:
310 ++ properties:
311 ++ compatible:
312 ++ contains:
313 ++ const: fsl,imx8mq-pcie
314 ++ then:
315 ++ properties:
316 ++ clock-names:
317 ++ items:
318 ++ - {}
319 ++ - {}
320 ++ - {}
321 ++ - const: pcie_aux
322 ++ - if:
323 ++ properties:
324 ++ compatible:
325 ++ not:
326 ++ contains:
327 ++ enum:
328 ++ - fsl,imx6sx-pcie
329 ++ - fsl,imx8mq-pcie
330 ++ then:
331 ++ properties:
332 ++ clock-names:
333 ++ maxItems: 3
334 ++
335 + unevaluatedProperties: false
336 +
337 + examples:
338 +diff --git a/Documentation/devicetree/bindings/pci/toshiba,visconti-pcie.yaml b/Documentation/devicetree/bindings/pci/toshiba,visconti-pcie.yaml
339 +index 30b6396d83c83..aea0e2bcdd778 100644
340 +--- a/Documentation/devicetree/bindings/pci/toshiba,visconti-pcie.yaml
341 ++++ b/Documentation/devicetree/bindings/pci/toshiba,visconti-pcie.yaml
342 +@@ -36,7 +36,7 @@ properties:
343 + - const: mpu
344 +
345 + interrupts:
346 +- maxItems: 1
347 ++ maxItems: 2
348 +
349 + clocks:
350 + items:
351 +@@ -94,8 +94,9 @@ examples:
352 + #interrupt-cells = <1>;
353 + ranges = <0x81000000 0 0x40000000 0 0x40000000 0 0x00010000>,
354 + <0x82000000 0 0x50000000 0 0x50000000 0 0x20000000>;
355 +- interrupts = <GIC_SPI 215 IRQ_TYPE_LEVEL_HIGH>;
356 +- interrupt-names = "intr";
357 ++ interrupts = <GIC_SPI 211 IRQ_TYPE_LEVEL_HIGH>,
358 ++ <GIC_SPI 215 IRQ_TYPE_LEVEL_HIGH>;
359 ++ interrupt-names = "msi", "intr";
360 + interrupt-map-mask = <0 0 0 7>;
361 + interrupt-map =
362 + <0 0 0 1 &gic GIC_SPI 215 IRQ_TYPE_LEVEL_HIGH
363 +diff --git a/Documentation/devicetree/bindings/pinctrl/mediatek,mt7986-pinctrl.yaml b/Documentation/devicetree/bindings/pinctrl/mediatek,mt7986-pinctrl.yaml
364 +index 4eadea55df10f..41abfa94877fb 100644
365 +--- a/Documentation/devicetree/bindings/pinctrl/mediatek,mt7986-pinctrl.yaml
366 ++++ b/Documentation/devicetree/bindings/pinctrl/mediatek,mt7986-pinctrl.yaml
367 +@@ -87,6 +87,8 @@ patternProperties:
368 + "wifi_led" "led" 1, 2
369 + "i2c" "i2c" 3, 4
370 + "uart1_0" "uart" 7, 8, 9, 10
371 ++ "uart1_rx_tx" "uart" 42, 43
372 ++ "uart1_cts_rts" "uart" 44, 45
373 + "pcie_clk" "pcie" 9
374 + "pcie_wake" "pcie" 10
375 + "spi1_0" "spi" 11, 12, 13, 14
376 +@@ -98,9 +100,11 @@ patternProperties:
377 + "emmc_45" "emmc" 22, 23, 24, 25, 26, 27, 28, 29, 30,
378 + 31, 32
379 + "spi1_1" "spi" 23, 24, 25, 26
380 +- "uart1_2" "uart" 29, 30, 31, 32
381 ++ "uart1_2_rx_tx" "uart" 29, 30
382 ++ "uart1_2_cts_rts" "uart" 31, 32
383 + "uart1_1" "uart" 23, 24, 25, 26
384 +- "uart2_0" "uart" 29, 30, 31, 32
385 ++ "uart2_0_rx_tx" "uart" 29, 30
386 ++ "uart2_0_cts_rts" "uart" 31, 32
387 + "spi0" "spi" 33, 34, 35, 36
388 + "spi0_wp_hold" "spi" 37, 38
389 + "uart1_3_rx_tx" "uart" 35, 36
390 +@@ -153,7 +157,7 @@ patternProperties:
391 + then:
392 + properties:
393 + groups:
394 +- enum: [emmc, emmc_rst]
395 ++ enum: [emmc_45, emmc_51]
396 + - if:
397 + properties:
398 + function:
399 +@@ -217,8 +221,12 @@ patternProperties:
400 + then:
401 + properties:
402 + groups:
403 +- enum: [uart1_0, uart1_1, uart1_2, uart1_3_rx_tx,
404 +- uart1_3_cts_rts, uart2_0, uart2_1, uart0, uart1, uart2]
405 ++ items:
406 ++ enum: [uart1_0, uart1_rx_tx, uart1_cts_rts, uart1_1,
407 ++ uart1_2_rx_tx, uart1_2_cts_rts, uart1_3_rx_tx,
408 ++ uart1_3_cts_rts, uart2_0_rx_tx, uart2_0_cts_rts,
409 ++ uart2_1, uart0, uart1, uart2]
410 ++ maxItems: 2
411 + - if:
412 + properties:
413 + function:
414 +@@ -348,6 +356,27 @@ examples:
415 + interrupt-parent = <&gic>;
416 + #interrupt-cells = <2>;
417 +
418 ++ pcie_pins: pcie-pins {
419 ++ mux {
420 ++ function = "pcie";
421 ++ groups = "pcie_clk", "pcie_wake", "pcie_pereset";
422 ++ };
423 ++ };
424 ++
425 ++ pwm_pins: pwm-pins {
426 ++ mux {
427 ++ function = "pwm";
428 ++ groups = "pwm0", "pwm1_0";
429 ++ };
430 ++ };
431 ++
432 ++ spi0_pins: spi0-pins {
433 ++ mux {
434 ++ function = "spi";
435 ++ groups = "spi0", "spi0_wp_hold";
436 ++ };
437 ++ };
438 ++
439 + uart1_pins: uart1-pins {
440 + mux {
441 + function = "uart";
442 +@@ -355,6 +384,13 @@ examples:
443 + };
444 + };
445 +
446 ++ uart1_3_pins: uart1-3-pins {
447 ++ mux {
448 ++ function = "uart";
449 ++ groups = "uart1_3_rx_tx", "uart1_3_cts_rts";
450 ++ };
451 ++ };
452 ++
453 + uart2_pins: uart2-pins {
454 + mux {
455 + function = "uart";
456 +diff --git a/Documentation/devicetree/bindings/pwm/microchip,corepwm.yaml b/Documentation/devicetree/bindings/pwm/microchip,corepwm.yaml
457 +index a7fae1772a81b..cd8e9a8907f84 100644
458 +--- a/Documentation/devicetree/bindings/pwm/microchip,corepwm.yaml
459 ++++ b/Documentation/devicetree/bindings/pwm/microchip,corepwm.yaml
460 +@@ -30,7 +30,9 @@ properties:
461 + maxItems: 1
462 +
463 + "#pwm-cells":
464 +- const: 2
465 ++ enum: [2, 3]
466 ++ description:
467 ++ The only flag supported by the controller is PWM_POLARITY_INVERTED.
468 +
469 + microchip,sync-update-mask:
470 + description: |
471 +diff --git a/Documentation/devicetree/bindings/sound/qcom,wcd9335.txt b/Documentation/devicetree/bindings/sound/qcom,wcd9335.txt
472 +index 5d6ea66a863fe..1f75feec3dec6 100644
473 +--- a/Documentation/devicetree/bindings/sound/qcom,wcd9335.txt
474 ++++ b/Documentation/devicetree/bindings/sound/qcom,wcd9335.txt
475 +@@ -109,7 +109,7 @@ audio-codec@1{
476 + reg = <1 0>;
477 + interrupts = <&msmgpio 54 IRQ_TYPE_LEVEL_HIGH>;
478 + interrupt-names = "intr2"
479 +- reset-gpios = <&msmgpio 64 0>;
480 ++ reset-gpios = <&msmgpio 64 GPIO_ACTIVE_LOW>;
481 + slim-ifc-dev = <&wc9335_ifd>;
482 + clock-names = "mclk", "native";
483 + clocks = <&rpmcc RPM_SMD_DIV_CLK1>,
484 +diff --git a/Documentation/devicetree/bindings/sound/rt5682.txt b/Documentation/devicetree/bindings/sound/rt5682.txt
485 +index c5f2b8febceec..6b87db68337c2 100644
486 +--- a/Documentation/devicetree/bindings/sound/rt5682.txt
487 ++++ b/Documentation/devicetree/bindings/sound/rt5682.txt
488 +@@ -46,7 +46,7 @@ Optional properties:
489 +
490 + - realtek,dmic-clk-driving-high : Set the high driving of the DMIC clock out.
491 +
492 +-- #sound-dai-cells: Should be set to '<0>'.
493 ++- #sound-dai-cells: Should be set to '<1>'.
494 +
495 + Pins on the device (for linking into audio routes) for RT5682:
496 +
497 +diff --git a/Documentation/driver-api/spi.rst b/Documentation/driver-api/spi.rst
498 +index f64cb666498aa..f28887045049d 100644
499 +--- a/Documentation/driver-api/spi.rst
500 ++++ b/Documentation/driver-api/spi.rst
501 +@@ -25,8 +25,8 @@ hardware, which may be as simple as a set of GPIO pins or as complex as
502 + a pair of FIFOs connected to dual DMA engines on the other side of the
503 + SPI shift register (maximizing throughput). Such drivers bridge between
504 + whatever bus they sit on (often the platform bus) and SPI, and expose
505 +-the SPI side of their device as a :c:type:`struct spi_master
506 +-<spi_master>`. SPI devices are children of that master,
507 ++the SPI side of their device as a :c:type:`struct spi_controller
508 ++<spi_controller>`. SPI devices are children of that master,
509 + represented as a :c:type:`struct spi_device <spi_device>` and
510 + manufactured from :c:type:`struct spi_board_info
511 + <spi_board_info>` descriptors which are usually provided by
512 +diff --git a/Documentation/fault-injection/fault-injection.rst b/Documentation/fault-injection/fault-injection.rst
513 +index 17779a2772e51..5f6454b9dbd4d 100644
514 +--- a/Documentation/fault-injection/fault-injection.rst
515 ++++ b/Documentation/fault-injection/fault-injection.rst
516 +@@ -83,9 +83,7 @@ configuration of fault-injection capabilities.
517 + - /sys/kernel/debug/fail*/times:
518 +
519 + specifies how many times failures may happen at most. A value of -1
520 +- means "no limit". Note, though, that this file only accepts unsigned
521 +- values. So, if you want to specify -1, you better use 'printf' instead
522 +- of 'echo', e.g.: $ printf %#x -1 > times
523 ++ means "no limit".
524 +
525 + - /sys/kernel/debug/fail*/space:
526 +
527 +@@ -284,7 +282,7 @@ Application Examples
528 + echo Y > /sys/kernel/debug/$FAILTYPE/task-filter
529 + echo 10 > /sys/kernel/debug/$FAILTYPE/probability
530 + echo 100 > /sys/kernel/debug/$FAILTYPE/interval
531 +- printf %#x -1 > /sys/kernel/debug/$FAILTYPE/times
532 ++ echo -1 > /sys/kernel/debug/$FAILTYPE/times
533 + echo 0 > /sys/kernel/debug/$FAILTYPE/space
534 + echo 2 > /sys/kernel/debug/$FAILTYPE/verbose
535 + echo Y > /sys/kernel/debug/$FAILTYPE/ignore-gfp-wait
536 +@@ -338,7 +336,7 @@ Application Examples
537 + echo N > /sys/kernel/debug/$FAILTYPE/task-filter
538 + echo 10 > /sys/kernel/debug/$FAILTYPE/probability
539 + echo 100 > /sys/kernel/debug/$FAILTYPE/interval
540 +- printf %#x -1 > /sys/kernel/debug/$FAILTYPE/times
541 ++ echo -1 > /sys/kernel/debug/$FAILTYPE/times
542 + echo 0 > /sys/kernel/debug/$FAILTYPE/space
543 + echo 2 > /sys/kernel/debug/$FAILTYPE/verbose
544 + echo Y > /sys/kernel/debug/$FAILTYPE/ignore-gfp-wait
545 +@@ -369,7 +367,7 @@ Application Examples
546 + echo N > /sys/kernel/debug/$FAILTYPE/task-filter
547 + echo 100 > /sys/kernel/debug/$FAILTYPE/probability
548 + echo 0 > /sys/kernel/debug/$FAILTYPE/interval
549 +- printf %#x -1 > /sys/kernel/debug/$FAILTYPE/times
550 ++ echo -1 > /sys/kernel/debug/$FAILTYPE/times
551 + echo 0 > /sys/kernel/debug/$FAILTYPE/space
552 + echo 1 > /sys/kernel/debug/$FAILTYPE/verbose
553 +
554 +diff --git a/Makefile b/Makefile
555 +index 0c7ae314ad3d5..ff8d88b113919 100644
556 +--- a/Makefile
557 ++++ b/Makefile
558 +@@ -1,7 +1,7 @@
559 + # SPDX-License-Identifier: GPL-2.0
560 + VERSION = 6
561 + PATCHLEVEL = 0
562 +-SUBLEVEL = 15
563 ++SUBLEVEL = 16
564 + EXTRAVERSION =
565 + NAME = Hurr durr I'ma ninja sloth
566 +
567 +diff --git a/arch/Kconfig b/arch/Kconfig
568 +index 8b311e400ec14..732a4680e733e 100644
569 +--- a/arch/Kconfig
570 ++++ b/arch/Kconfig
571 +@@ -629,7 +629,7 @@ config ARCH_SUPPORTS_SHADOW_CALL_STACK
572 + config SHADOW_CALL_STACK
573 + bool "Shadow Call Stack"
574 + depends on ARCH_SUPPORTS_SHADOW_CALL_STACK
575 +- depends on DYNAMIC_FTRACE_WITH_REGS || !FUNCTION_GRAPH_TRACER
576 ++ depends on DYNAMIC_FTRACE_WITH_ARGS || DYNAMIC_FTRACE_WITH_REGS || !FUNCTION_GRAPH_TRACER
577 + help
578 + This option enables the compiler's Shadow Call Stack, which
579 + uses a shadow stack to protect function return addresses from
580 +diff --git a/arch/alpha/include/asm/thread_info.h b/arch/alpha/include/asm/thread_info.h
581 +index fdc485d7787a6..084c27cb0c707 100644
582 +--- a/arch/alpha/include/asm/thread_info.h
583 ++++ b/arch/alpha/include/asm/thread_info.h
584 +@@ -75,7 +75,7 @@ register struct thread_info *__current_thread_info __asm__("$8");
585 +
586 + /* Work to do on interrupt/exception return. */
587 + #define _TIF_WORK_MASK (_TIF_SIGPENDING | _TIF_NEED_RESCHED | \
588 +- _TIF_NOTIFY_RESUME)
589 ++ _TIF_NOTIFY_RESUME | _TIF_NOTIFY_SIGNAL)
590 +
591 + /* Work to do on any return to userspace. */
592 + #define _TIF_ALLWORK_MASK (_TIF_WORK_MASK \
593 +diff --git a/arch/alpha/kernel/entry.S b/arch/alpha/kernel/entry.S
594 +index e227f3a29a43c..c41a5a9c3b9f2 100644
595 +--- a/arch/alpha/kernel/entry.S
596 ++++ b/arch/alpha/kernel/entry.S
597 +@@ -469,8 +469,10 @@ entSys:
598 + #ifdef CONFIG_AUDITSYSCALL
599 + lda $6, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
600 + and $3, $6, $3
601 +-#endif
602 + bne $3, strace
603 ++#else
604 ++ blbs $3, strace /* check for SYSCALL_TRACE in disguise */
605 ++#endif
606 + beq $4, 1f
607 + ldq $27, 0($5)
608 + 1: jsr $26, ($27), sys_ni_syscall
609 +diff --git a/arch/arm/boot/dts/armada-370.dtsi b/arch/arm/boot/dts/armada-370.dtsi
610 +index 46e6d3ed8f35a..c042c416a94a3 100644
611 +--- a/arch/arm/boot/dts/armada-370.dtsi
612 ++++ b/arch/arm/boot/dts/armada-370.dtsi
613 +@@ -74,7 +74,7 @@
614 +
615 + pcie2: pcie@2,0 {
616 + device_type = "pci";
617 +- assigned-addresses = <0x82002800 0 0x80000 0 0x2000>;
618 ++ assigned-addresses = <0x82001000 0 0x80000 0 0x2000>;
619 + reg = <0x1000 0 0 0 0>;
620 + #address-cells = <3>;
621 + #size-cells = <2>;
622 +diff --git a/arch/arm/boot/dts/armada-375.dtsi b/arch/arm/boot/dts/armada-375.dtsi
623 +index 7f2f24a29e6c1..352a2f7ba3114 100644
624 +--- a/arch/arm/boot/dts/armada-375.dtsi
625 ++++ b/arch/arm/boot/dts/armada-375.dtsi
626 +@@ -582,7 +582,7 @@
627 +
628 + pcie1: pcie@2,0 {
629 + device_type = "pci";
630 +- assigned-addresses = <0x82000800 0 0x44000 0 0x2000>;
631 ++ assigned-addresses = <0x82001000 0 0x44000 0 0x2000>;
632 + reg = <0x1000 0 0 0 0>;
633 + #address-cells = <3>;
634 + #size-cells = <2>;
635 +diff --git a/arch/arm/boot/dts/armada-380.dtsi b/arch/arm/boot/dts/armada-380.dtsi
636 +index cff1269f3fbfd..7146cc8f082af 100644
637 +--- a/arch/arm/boot/dts/armada-380.dtsi
638 ++++ b/arch/arm/boot/dts/armada-380.dtsi
639 +@@ -79,7 +79,7 @@
640 + /* x1 port */
641 + pcie@2,0 {
642 + device_type = "pci";
643 +- assigned-addresses = <0x82000800 0 0x40000 0 0x2000>;
644 ++ assigned-addresses = <0x82001000 0 0x40000 0 0x2000>;
645 + reg = <0x1000 0 0 0 0>;
646 + #address-cells = <3>;
647 + #size-cells = <2>;
648 +@@ -98,7 +98,7 @@
649 + /* x1 port */
650 + pcie@3,0 {
651 + device_type = "pci";
652 +- assigned-addresses = <0x82000800 0 0x44000 0 0x2000>;
653 ++ assigned-addresses = <0x82001800 0 0x44000 0 0x2000>;
654 + reg = <0x1800 0 0 0 0>;
655 + #address-cells = <3>;
656 + #size-cells = <2>;
657 +diff --git a/arch/arm/boot/dts/armada-385-turris-omnia.dts b/arch/arm/boot/dts/armada-385-turris-omnia.dts
658 +index a41902e3815cd..0b64d7505dca0 100644
659 +--- a/arch/arm/boot/dts/armada-385-turris-omnia.dts
660 ++++ b/arch/arm/boot/dts/armada-385-turris-omnia.dts
661 +@@ -23,6 +23,12 @@
662 + stdout-path = &uart0;
663 + };
664 +
665 ++ aliases {
666 ++ ethernet0 = &eth0;
667 ++ ethernet1 = &eth1;
668 ++ ethernet2 = &eth2;
669 ++ };
670 ++
671 + memory {
672 + device_type = "memory";
673 + reg = <0x00000000 0x40000000>; /* 1024 MB */
674 +@@ -455,7 +461,17 @@
675 + };
676 + };
677 +
678 +- /* port 6 is connected to eth0 */
679 ++ ports@6 {
680 ++ reg = <6>;
681 ++ label = "cpu";
682 ++ ethernet = <&eth0>;
683 ++ phy-mode = "rgmii-id";
684 ++
685 ++ fixed-link {
686 ++ speed = <1000>;
687 ++ full-duplex;
688 ++ };
689 ++ };
690 + };
691 + };
692 + };
693 +diff --git a/arch/arm/boot/dts/armada-385.dtsi b/arch/arm/boot/dts/armada-385.dtsi
694 +index 83392b92dae28..be8d607c59b21 100644
695 +--- a/arch/arm/boot/dts/armada-385.dtsi
696 ++++ b/arch/arm/boot/dts/armada-385.dtsi
697 +@@ -93,7 +93,7 @@
698 + /* x1 port */
699 + pcie2: pcie@2,0 {
700 + device_type = "pci";
701 +- assigned-addresses = <0x82000800 0 0x40000 0 0x2000>;
702 ++ assigned-addresses = <0x82001000 0 0x40000 0 0x2000>;
703 + reg = <0x1000 0 0 0 0>;
704 + #address-cells = <3>;
705 + #size-cells = <2>;
706 +@@ -121,7 +121,7 @@
707 + /* x1 port */
708 + pcie3: pcie@3,0 {
709 + device_type = "pci";
710 +- assigned-addresses = <0x82000800 0 0x44000 0 0x2000>;
711 ++ assigned-addresses = <0x82001800 0 0x44000 0 0x2000>;
712 + reg = <0x1800 0 0 0 0>;
713 + #address-cells = <3>;
714 + #size-cells = <2>;
715 +@@ -152,7 +152,7 @@
716 + */
717 + pcie4: pcie@4,0 {
718 + device_type = "pci";
719 +- assigned-addresses = <0x82000800 0 0x48000 0 0x2000>;
720 ++ assigned-addresses = <0x82002000 0 0x48000 0 0x2000>;
721 + reg = <0x2000 0 0 0 0>;
722 + #address-cells = <3>;
723 + #size-cells = <2>;
724 +diff --git a/arch/arm/boot/dts/armada-39x.dtsi b/arch/arm/boot/dts/armada-39x.dtsi
725 +index e0b7c20998312..9525e7b7f4360 100644
726 +--- a/arch/arm/boot/dts/armada-39x.dtsi
727 ++++ b/arch/arm/boot/dts/armada-39x.dtsi
728 +@@ -453,7 +453,7 @@
729 + /* x1 port */
730 + pcie@2,0 {
731 + device_type = "pci";
732 +- assigned-addresses = <0x82000800 0 0x40000 0 0x2000>;
733 ++ assigned-addresses = <0x82001000 0 0x40000 0 0x2000>;
734 + reg = <0x1000 0 0 0 0>;
735 + #address-cells = <3>;
736 + #size-cells = <2>;
737 +@@ -472,7 +472,7 @@
738 + /* x1 port */
739 + pcie@3,0 {
740 + device_type = "pci";
741 +- assigned-addresses = <0x82000800 0 0x44000 0 0x2000>;
742 ++ assigned-addresses = <0x82001800 0 0x44000 0 0x2000>;
743 + reg = <0x1800 0 0 0 0>;
744 + #address-cells = <3>;
745 + #size-cells = <2>;
746 +@@ -494,7 +494,7 @@
747 + */
748 + pcie@4,0 {
749 + device_type = "pci";
750 +- assigned-addresses = <0x82000800 0 0x48000 0 0x2000>;
751 ++ assigned-addresses = <0x82002000 0 0x48000 0 0x2000>;
752 + reg = <0x2000 0 0 0 0>;
753 + #address-cells = <3>;
754 + #size-cells = <2>;
755 +diff --git a/arch/arm/boot/dts/armada-xp-mv78230.dtsi b/arch/arm/boot/dts/armada-xp-mv78230.dtsi
756 +index 8558bf6bb54c6..d55fe162fc7f0 100644
757 +--- a/arch/arm/boot/dts/armada-xp-mv78230.dtsi
758 ++++ b/arch/arm/boot/dts/armada-xp-mv78230.dtsi
759 +@@ -97,7 +97,7 @@
760 +
761 + pcie2: pcie@2,0 {
762 + device_type = "pci";
763 +- assigned-addresses = <0x82000800 0 0x44000 0 0x2000>;
764 ++ assigned-addresses = <0x82001000 0 0x44000 0 0x2000>;
765 + reg = <0x1000 0 0 0 0>;
766 + #address-cells = <3>;
767 + #size-cells = <2>;
768 +@@ -115,7 +115,7 @@
769 +
770 + pcie3: pcie@3,0 {
771 + device_type = "pci";
772 +- assigned-addresses = <0x82000800 0 0x48000 0 0x2000>;
773 ++ assigned-addresses = <0x82001800 0 0x48000 0 0x2000>;
774 + reg = <0x1800 0 0 0 0>;
775 + #address-cells = <3>;
776 + #size-cells = <2>;
777 +@@ -133,7 +133,7 @@
778 +
779 + pcie4: pcie@4,0 {
780 + device_type = "pci";
781 +- assigned-addresses = <0x82000800 0 0x4c000 0 0x2000>;
782 ++ assigned-addresses = <0x82002000 0 0x4c000 0 0x2000>;
783 + reg = <0x2000 0 0 0 0>;
784 + #address-cells = <3>;
785 + #size-cells = <2>;
786 +@@ -151,7 +151,7 @@
787 +
788 + pcie5: pcie@5,0 {
789 + device_type = "pci";
790 +- assigned-addresses = <0x82000800 0 0x80000 0 0x2000>;
791 ++ assigned-addresses = <0x82002800 0 0x80000 0 0x2000>;
792 + reg = <0x2800 0 0 0 0>;
793 + #address-cells = <3>;
794 + #size-cells = <2>;
795 +diff --git a/arch/arm/boot/dts/armada-xp-mv78260.dtsi b/arch/arm/boot/dts/armada-xp-mv78260.dtsi
796 +index 2d85fe8ac3272..fdcc818199401 100644
797 +--- a/arch/arm/boot/dts/armada-xp-mv78260.dtsi
798 ++++ b/arch/arm/boot/dts/armada-xp-mv78260.dtsi
799 +@@ -112,7 +112,7 @@
800 +
801 + pcie2: pcie@2,0 {
802 + device_type = "pci";
803 +- assigned-addresses = <0x82000800 0 0x44000 0 0x2000>;
804 ++ assigned-addresses = <0x82001000 0 0x44000 0 0x2000>;
805 + reg = <0x1000 0 0 0 0>;
806 + #address-cells = <3>;
807 + #size-cells = <2>;
808 +@@ -130,7 +130,7 @@
809 +
810 + pcie3: pcie@3,0 {
811 + device_type = "pci";
812 +- assigned-addresses = <0x82000800 0 0x48000 0 0x2000>;
813 ++ assigned-addresses = <0x82001800 0 0x48000 0 0x2000>;
814 + reg = <0x1800 0 0 0 0>;
815 + #address-cells = <3>;
816 + #size-cells = <2>;
817 +@@ -148,7 +148,7 @@
818 +
819 + pcie4: pcie@4,0 {
820 + device_type = "pci";
821 +- assigned-addresses = <0x82000800 0 0x4c000 0 0x2000>;
822 ++ assigned-addresses = <0x82002000 0 0x4c000 0 0x2000>;
823 + reg = <0x2000 0 0 0 0>;
824 + #address-cells = <3>;
825 + #size-cells = <2>;
826 +@@ -166,7 +166,7 @@
827 +
828 + pcie5: pcie@5,0 {
829 + device_type = "pci";
830 +- assigned-addresses = <0x82000800 0 0x80000 0 0x2000>;
831 ++ assigned-addresses = <0x82002800 0 0x80000 0 0x2000>;
832 + reg = <0x2800 0 0 0 0>;
833 + #address-cells = <3>;
834 + #size-cells = <2>;
835 +@@ -184,7 +184,7 @@
836 +
837 + pcie6: pcie@6,0 {
838 + device_type = "pci";
839 +- assigned-addresses = <0x82000800 0 0x84000 0 0x2000>;
840 ++ assigned-addresses = <0x82003000 0 0x84000 0 0x2000>;
841 + reg = <0x3000 0 0 0 0>;
842 + #address-cells = <3>;
843 + #size-cells = <2>;
844 +@@ -202,7 +202,7 @@
845 +
846 + pcie7: pcie@7,0 {
847 + device_type = "pci";
848 +- assigned-addresses = <0x82000800 0 0x88000 0 0x2000>;
849 ++ assigned-addresses = <0x82003800 0 0x88000 0 0x2000>;
850 + reg = <0x3800 0 0 0 0>;
851 + #address-cells = <3>;
852 + #size-cells = <2>;
853 +@@ -220,7 +220,7 @@
854 +
855 + pcie8: pcie@8,0 {
856 + device_type = "pci";
857 +- assigned-addresses = <0x82000800 0 0x8c000 0 0x2000>;
858 ++ assigned-addresses = <0x82004000 0 0x8c000 0 0x2000>;
859 + reg = <0x4000 0 0 0 0>;
860 + #address-cells = <3>;
861 + #size-cells = <2>;
862 +@@ -238,7 +238,7 @@
863 +
864 + pcie9: pcie@9,0 {
865 + device_type = "pci";
866 +- assigned-addresses = <0x82000800 0 0x42000 0 0x2000>;
867 ++ assigned-addresses = <0x82004800 0 0x42000 0 0x2000>;
868 + reg = <0x4800 0 0 0 0>;
869 + #address-cells = <3>;
870 + #size-cells = <2>;
871 +diff --git a/arch/arm/boot/dts/aspeed-bmc-ibm-everest.dts b/arch/arm/boot/dts/aspeed-bmc-ibm-everest.dts
872 +index a6a2bc3b855c2..fcc890e3ad735 100644
873 +--- a/arch/arm/boot/dts/aspeed-bmc-ibm-everest.dts
874 ++++ b/arch/arm/boot/dts/aspeed-bmc-ibm-everest.dts
875 +@@ -162,16 +162,9 @@
876 + #size-cells = <1>;
877 + ranges;
878 +
879 +- /* LPC FW cycle bridge region requires natural alignment */
880 +- flash_memory: region@b8000000 {
881 +- no-map;
882 +- reg = <0xb8000000 0x04000000>; /* 64M */
883 +- };
884 +-
885 +- /* 48MB region from the end of flash to start of vga memory */
886 +- ramoops@bc000000 {
887 ++ ramoops@b3e00000 {
888 + compatible = "ramoops";
889 +- reg = <0xbc000000 0x200000>; /* 16 * (4 * 0x8000) */
890 ++ reg = <0xb3e00000 0x200000>; /* 16 * (4 * 0x8000) */
891 + record-size = <0x8000>;
892 + console-size = <0x8000>;
893 + ftrace-size = <0x8000>;
894 +@@ -179,6 +172,12 @@
895 + max-reason = <3>; /* KMSG_DUMP_EMERG */
896 + };
897 +
898 ++ /* LPC FW cycle bridge region requires natural alignment */
899 ++ flash_memory: region@b4000000 {
900 ++ no-map;
901 ++ reg = <0xb4000000 0x04000000>; /* 64M */
902 ++ };
903 ++
904 + /* VGA region is dictated by hardware strapping */
905 + vga_memory: region@bf000000 {
906 + no-map;
907 +diff --git a/arch/arm/boot/dts/aspeed-bmc-ibm-rainier.dts b/arch/arm/boot/dts/aspeed-bmc-ibm-rainier.dts
908 +index bf59a9962379d..4879da4cdbd25 100644
909 +--- a/arch/arm/boot/dts/aspeed-bmc-ibm-rainier.dts
910 ++++ b/arch/arm/boot/dts/aspeed-bmc-ibm-rainier.dts
911 +@@ -95,14 +95,9 @@
912 + #size-cells = <1>;
913 + ranges;
914 +
915 +- flash_memory: region@b8000000 {
916 +- no-map;
917 +- reg = <0xb8000000 0x04000000>; /* 64M */
918 +- };
919 +-
920 +- ramoops@bc000000 {
921 ++ ramoops@b3e00000 {
922 + compatible = "ramoops";
923 +- reg = <0xbc000000 0x200000>; /* 16 * (4 * 0x8000) */
924 ++ reg = <0xb3e00000 0x200000>; /* 16 * (4 * 0x8000) */
925 + record-size = <0x8000>;
926 + console-size = <0x8000>;
927 + ftrace-size = <0x8000>;
928 +@@ -110,6 +105,13 @@
929 + max-reason = <3>; /* KMSG_DUMP_EMERG */
930 + };
931 +
932 ++ /* LPC FW cycle bridge region requires natural alignment */
933 ++ flash_memory: region@b4000000 {
934 ++ no-map;
935 ++ reg = <0xb4000000 0x04000000>; /* 64M */
936 ++ };
937 ++
938 ++ /* VGA region is dictated by hardware strapping */
939 + vga_memory: region@bf000000 {
940 + no-map;
941 + compatible = "shared-dma-pool";
942 +diff --git a/arch/arm/boot/dts/dove.dtsi b/arch/arm/boot/dts/dove.dtsi
943 +index 89e0bdaf3a85f..726d353eda686 100644
944 +--- a/arch/arm/boot/dts/dove.dtsi
945 ++++ b/arch/arm/boot/dts/dove.dtsi
946 +@@ -129,7 +129,7 @@
947 + pcie1: pcie@2 {
948 + device_type = "pci";
949 + status = "disabled";
950 +- assigned-addresses = <0x82002800 0 0x80000 0 0x2000>;
951 ++ assigned-addresses = <0x82001000 0 0x80000 0 0x2000>;
952 + reg = <0x1000 0 0 0 0>;
953 + clocks = <&gate_clk 5>;
954 + marvell,pcie-port = <1>;
955 +diff --git a/arch/arm/boot/dts/nuvoton-npcm730-gbs.dts b/arch/arm/boot/dts/nuvoton-npcm730-gbs.dts
956 +index d10669fcd527d..9e9eba8bad5e4 100644
957 +--- a/arch/arm/boot/dts/nuvoton-npcm730-gbs.dts
958 ++++ b/arch/arm/boot/dts/nuvoton-npcm730-gbs.dts
959 +@@ -366,7 +366,7 @@
960 + spi-max-frequency = <20000000>;
961 + spi-rx-bus-width = <2>;
962 + label = "bmc";
963 +- partitions@80000000 {
964 ++ partitions {
965 + compatible = "fixed-partitions";
966 + #address-cells = <1>;
967 + #size-cells = <1>;
968 +diff --git a/arch/arm/boot/dts/nuvoton-npcm730-gsj.dts b/arch/arm/boot/dts/nuvoton-npcm730-gsj.dts
969 +index 491606c4f044d..2a394cc15284c 100644
970 +--- a/arch/arm/boot/dts/nuvoton-npcm730-gsj.dts
971 ++++ b/arch/arm/boot/dts/nuvoton-npcm730-gsj.dts
972 +@@ -142,7 +142,7 @@
973 + reg = <0>;
974 + spi-rx-bus-width = <2>;
975 +
976 +- partitions@80000000 {
977 ++ partitions {
978 + compatible = "fixed-partitions";
979 + #address-cells = <1>;
980 + #size-cells = <1>;
981 +diff --git a/arch/arm/boot/dts/nuvoton-npcm730-kudo.dts b/arch/arm/boot/dts/nuvoton-npcm730-kudo.dts
982 +index a0c2d76526258..f7b38bee039bc 100644
983 +--- a/arch/arm/boot/dts/nuvoton-npcm730-kudo.dts
984 ++++ b/arch/arm/boot/dts/nuvoton-npcm730-kudo.dts
985 +@@ -388,7 +388,7 @@
986 + spi-max-frequency = <5000000>;
987 + spi-rx-bus-width = <2>;
988 + label = "bmc";
989 +- partitions@80000000 {
990 ++ partitions {
991 + compatible = "fixed-partitions";
992 + #address-cells = <1>;
993 + #size-cells = <1>;
994 +@@ -422,7 +422,7 @@
995 + reg = <1>;
996 + spi-max-frequency = <5000000>;
997 + spi-rx-bus-width = <2>;
998 +- partitions@88000000 {
999 ++ partitions {
1000 + compatible = "fixed-partitions";
1001 + #address-cells = <1>;
1002 + #size-cells = <1>;
1003 +@@ -447,7 +447,7 @@
1004 + reg = <0>;
1005 + spi-max-frequency = <5000000>;
1006 + spi-rx-bus-width = <2>;
1007 +- partitions@A0000000 {
1008 ++ partitions {
1009 + compatible = "fixed-partitions";
1010 + #address-cells = <1>;
1011 + #size-cells = <1>;
1012 +diff --git a/arch/arm/boot/dts/nuvoton-npcm750-evb.dts b/arch/arm/boot/dts/nuvoton-npcm750-evb.dts
1013 +index 3dad32834e5ea..f53d45fa1de87 100644
1014 +--- a/arch/arm/boot/dts/nuvoton-npcm750-evb.dts
1015 ++++ b/arch/arm/boot/dts/nuvoton-npcm750-evb.dts
1016 +@@ -74,7 +74,7 @@
1017 + spi-rx-bus-width = <2>;
1018 + reg = <0>;
1019 + spi-max-frequency = <5000000>;
1020 +- partitions@80000000 {
1021 ++ partitions {
1022 + compatible = "fixed-partitions";
1023 + #address-cells = <1>;
1024 + #size-cells = <1>;
1025 +@@ -135,7 +135,7 @@
1026 + spi-rx-bus-width = <2>;
1027 + reg = <0>;
1028 + spi-max-frequency = <5000000>;
1029 +- partitions@A0000000 {
1030 ++ partitions {
1031 + compatible = "fixed-partitions";
1032 + #address-cells = <1>;
1033 + #size-cells = <1>;
1034 +diff --git a/arch/arm/boot/dts/nuvoton-npcm750-runbmc-olympus.dts b/arch/arm/boot/dts/nuvoton-npcm750-runbmc-olympus.dts
1035 +index 132e702281fc5..87359ab05db3e 100644
1036 +--- a/arch/arm/boot/dts/nuvoton-npcm750-runbmc-olympus.dts
1037 ++++ b/arch/arm/boot/dts/nuvoton-npcm750-runbmc-olympus.dts
1038 +@@ -107,7 +107,7 @@
1039 + reg = <0>;
1040 + spi-rx-bus-width = <2>;
1041 +
1042 +- partitions@80000000 {
1043 ++ partitions {
1044 + compatible = "fixed-partitions";
1045 + #address-cells = <1>;
1046 + #size-cells = <1>;
1047 +@@ -146,7 +146,7 @@
1048 + reg = <1>;
1049 + npcm,fiu-rx-bus-width = <2>;
1050 +
1051 +- partitions@88000000 {
1052 ++ partitions {
1053 + compatible = "fixed-partitions";
1054 + #address-cells = <1>;
1055 + #size-cells = <1>;
1056 +@@ -173,7 +173,7 @@
1057 + reg = <0>;
1058 + spi-rx-bus-width = <2>;
1059 +
1060 +- partitions@A0000000 {
1061 ++ partitions {
1062 + compatible = "fixed-partitions";
1063 + #address-cells = <1>;
1064 + #size-cells = <1>;
1065 +diff --git a/arch/arm/boot/dts/qcom-apq8064.dtsi b/arch/arm/boot/dts/qcom-apq8064.dtsi
1066 +index ada4c828bf2f4..095849423de1d 100644
1067 +--- a/arch/arm/boot/dts/qcom-apq8064.dtsi
1068 ++++ b/arch/arm/boot/dts/qcom-apq8064.dtsi
1069 +@@ -1580,7 +1580,7 @@
1070 + };
1071 +
1072 + etb@1a01000 {
1073 +- compatible = "coresight-etb10", "arm,primecell";
1074 ++ compatible = "arm,coresight-etb10", "arm,primecell";
1075 + reg = <0x1a01000 0x1000>;
1076 +
1077 + clocks = <&rpmcc RPM_QDSS_CLK>;
1078 +diff --git a/arch/arm/boot/dts/spear600.dtsi b/arch/arm/boot/dts/spear600.dtsi
1079 +index fd41243a0b2c0..9d5a04a46b14e 100644
1080 +--- a/arch/arm/boot/dts/spear600.dtsi
1081 ++++ b/arch/arm/boot/dts/spear600.dtsi
1082 +@@ -47,7 +47,7 @@
1083 + compatible = "arm,pl110", "arm,primecell";
1084 + reg = <0xfc200000 0x1000>;
1085 + interrupt-parent = <&vic1>;
1086 +- interrupts = <12>;
1087 ++ interrupts = <13>;
1088 + status = "disabled";
1089 + };
1090 +
1091 +diff --git a/arch/arm/boot/dts/stm32mp157a-dhcor-avenger96.dts b/arch/arm/boot/dts/stm32mp157a-dhcor-avenger96.dts
1092 +index 2e3c9fbb4eb36..275167f26fd9d 100644
1093 +--- a/arch/arm/boot/dts/stm32mp157a-dhcor-avenger96.dts
1094 ++++ b/arch/arm/boot/dts/stm32mp157a-dhcor-avenger96.dts
1095 +@@ -13,7 +13,6 @@
1096 + /dts-v1/;
1097 +
1098 + #include "stm32mp157.dtsi"
1099 +-#include "stm32mp15xc.dtsi"
1100 + #include "stm32mp15xx-dhcor-som.dtsi"
1101 + #include "stm32mp15xx-dhcor-avenger96.dtsi"
1102 +
1103 +diff --git a/arch/arm/boot/dts/stm32mp15xx-dhcor-avenger96.dtsi b/arch/arm/boot/dts/stm32mp15xx-dhcor-avenger96.dtsi
1104 +index 90933077d66de..b6957cbdeff5f 100644
1105 +--- a/arch/arm/boot/dts/stm32mp15xx-dhcor-avenger96.dtsi
1106 ++++ b/arch/arm/boot/dts/stm32mp15xx-dhcor-avenger96.dtsi
1107 +@@ -100,7 +100,7 @@
1108 + regulator-min-microvolt = <3300000>;
1109 + regulator-max-microvolt = <3300000>;
1110 +
1111 +- gpios = <&gpioz 3 GPIO_ACTIVE_HIGH>;
1112 ++ gpio = <&gpioz 3 GPIO_ACTIVE_HIGH>;
1113 + enable-active-high;
1114 + };
1115 + };
1116 +diff --git a/arch/arm/mach-mmp/time.c b/arch/arm/mach-mmp/time.c
1117 +index 41b2e8abc9e69..708816caf859c 100644
1118 +--- a/arch/arm/mach-mmp/time.c
1119 ++++ b/arch/arm/mach-mmp/time.c
1120 +@@ -43,18 +43,21 @@
1121 + static void __iomem *mmp_timer_base = TIMERS_VIRT_BASE;
1122 +
1123 + /*
1124 +- * FIXME: the timer needs some delay to stablize the counter capture
1125 ++ * Read the timer through the CVWR register. Delay is required after requesting
1126 ++ * a read. The CR register cannot be directly read due to metastability issues
1127 ++ * documented in the PXA168 software manual.
1128 + */
1129 + static inline uint32_t timer_read(void)
1130 + {
1131 +- int delay = 100;
1132 ++ uint32_t val;
1133 ++ int delay = 3;
1134 +
1135 + __raw_writel(1, mmp_timer_base + TMR_CVWR(1));
1136 +
1137 + while (delay--)
1138 +- cpu_relax();
1139 ++ val = __raw_readl(mmp_timer_base + TMR_CVWR(1));
1140 +
1141 +- return __raw_readl(mmp_timer_base + TMR_CVWR(1));
1142 ++ return val;
1143 + }
1144 +
1145 + static u64 notrace mmp_read_sched_clock(void)
1146 +diff --git a/arch/arm64/boot/dts/apple/t8103.dtsi b/arch/arm64/boot/dts/apple/t8103.dtsi
1147 +index 51a63b29d4045..a4d195e9eb8c8 100644
1148 +--- a/arch/arm64/boot/dts/apple/t8103.dtsi
1149 ++++ b/arch/arm64/boot/dts/apple/t8103.dtsi
1150 +@@ -412,7 +412,7 @@
1151 + resets = <&ps_ans2>;
1152 + };
1153 +
1154 +- pcie0_dart_0: dart@681008000 {
1155 ++ pcie0_dart_0: iommu@681008000 {
1156 + compatible = "apple,t8103-dart";
1157 + reg = <0x6 0x81008000 0x0 0x4000>;
1158 + #iommu-cells = <1>;
1159 +@@ -421,7 +421,7 @@
1160 + power-domains = <&ps_apcie_gp>;
1161 + };
1162 +
1163 +- pcie0_dart_1: dart@682008000 {
1164 ++ pcie0_dart_1: iommu@682008000 {
1165 + compatible = "apple,t8103-dart";
1166 + reg = <0x6 0x82008000 0x0 0x4000>;
1167 + #iommu-cells = <1>;
1168 +@@ -430,7 +430,7 @@
1169 + power-domains = <&ps_apcie_gp>;
1170 + };
1171 +
1172 +- pcie0_dart_2: dart@683008000 {
1173 ++ pcie0_dart_2: iommu@683008000 {
1174 + compatible = "apple,t8103-dart";
1175 + reg = <0x6 0x83008000 0x0 0x4000>;
1176 + #iommu-cells = <1>;
1177 +diff --git a/arch/arm64/boot/dts/marvell/armada-3720-turris-mox.dts b/arch/arm64/boot/dts/marvell/armada-3720-turris-mox.dts
1178 +index ada164d423f3d..200f97e1c4c9c 100644
1179 +--- a/arch/arm64/boot/dts/marvell/armada-3720-turris-mox.dts
1180 ++++ b/arch/arm64/boot/dts/marvell/armada-3720-turris-mox.dts
1181 +@@ -125,9 +125,12 @@
1182 + /delete-property/ mrvl,i2c-fast-mode;
1183 + status = "okay";
1184 +
1185 ++ /* MCP7940MT-I/MNY RTC */
1186 + rtc@6f {
1187 + compatible = "microchip,mcp7940x";
1188 + reg = <0x6f>;
1189 ++ interrupt-parent = <&gpiosb>;
1190 ++ interrupts = <5 0>; /* GPIO2_5 */
1191 + };
1192 + };
1193 +
1194 +diff --git a/arch/arm64/boot/dts/mediatek/mt2712-evb.dts b/arch/arm64/boot/dts/mediatek/mt2712-evb.dts
1195 +index 9b1af9c801308..d31a194124c91 100644
1196 +--- a/arch/arm64/boot/dts/mediatek/mt2712-evb.dts
1197 ++++ b/arch/arm64/boot/dts/mediatek/mt2712-evb.dts
1198 +@@ -26,14 +26,14 @@
1199 + stdout-path = "serial0:921600n8";
1200 + };
1201 +
1202 +- cpus_fixed_vproc0: fixedregulator@0 {
1203 ++ cpus_fixed_vproc0: regulator-vproc-buck0 {
1204 + compatible = "regulator-fixed";
1205 + regulator-name = "vproc_buck0";
1206 + regulator-min-microvolt = <1000000>;
1207 + regulator-max-microvolt = <1000000>;
1208 + };
1209 +
1210 +- cpus_fixed_vproc1: fixedregulator@1 {
1211 ++ cpus_fixed_vproc1: regulator-vproc-buck1 {
1212 + compatible = "regulator-fixed";
1213 + regulator-name = "vproc_buck1";
1214 + regulator-min-microvolt = <1000000>;
1215 +@@ -50,7 +50,7 @@
1216 + id-gpio = <&pio 14 GPIO_ACTIVE_HIGH>;
1217 + };
1218 +
1219 +- usb_p0_vbus: regulator@2 {
1220 ++ usb_p0_vbus: regulator-usb-p0-vbus {
1221 + compatible = "regulator-fixed";
1222 + regulator-name = "p0_vbus";
1223 + regulator-min-microvolt = <5000000>;
1224 +@@ -59,7 +59,7 @@
1225 + enable-active-high;
1226 + };
1227 +
1228 +- usb_p1_vbus: regulator@3 {
1229 ++ usb_p1_vbus: regulator-usb-p1-vbus {
1230 + compatible = "regulator-fixed";
1231 + regulator-name = "p1_vbus";
1232 + regulator-min-microvolt = <5000000>;
1233 +@@ -68,7 +68,7 @@
1234 + enable-active-high;
1235 + };
1236 +
1237 +- usb_p2_vbus: regulator@4 {
1238 ++ usb_p2_vbus: regulator-usb-p2-vbus {
1239 + compatible = "regulator-fixed";
1240 + regulator-name = "p2_vbus";
1241 + regulator-min-microvolt = <5000000>;
1242 +@@ -77,7 +77,7 @@
1243 + enable-active-high;
1244 + };
1245 +
1246 +- usb_p3_vbus: regulator@5 {
1247 ++ usb_p3_vbus: regulator-usb-p3-vbus {
1248 + compatible = "regulator-fixed";
1249 + regulator-name = "p3_vbus";
1250 + regulator-min-microvolt = <5000000>;
1251 +diff --git a/arch/arm64/boot/dts/mediatek/mt2712e.dtsi b/arch/arm64/boot/dts/mediatek/mt2712e.dtsi
1252 +index 4797537cb3683..2ebefd144d6f5 100644
1253 +--- a/arch/arm64/boot/dts/mediatek/mt2712e.dtsi
1254 ++++ b/arch/arm64/boot/dts/mediatek/mt2712e.dtsi
1255 +@@ -160,70 +160,70 @@
1256 + #clock-cells = <0>;
1257 + };
1258 +
1259 +- clk26m: oscillator@0 {
1260 ++ clk26m: oscillator-26m {
1261 + compatible = "fixed-clock";
1262 + #clock-cells = <0>;
1263 + clock-frequency = <26000000>;
1264 + clock-output-names = "clk26m";
1265 + };
1266 +
1267 +- clk32k: oscillator@1 {
1268 ++ clk32k: oscillator-32k {
1269 + compatible = "fixed-clock";
1270 + #clock-cells = <0>;
1271 + clock-frequency = <32768>;
1272 + clock-output-names = "clk32k";
1273 + };
1274 +
1275 +- clkfpc: oscillator@2 {
1276 ++ clkfpc: oscillator-50m {
1277 + compatible = "fixed-clock";
1278 + #clock-cells = <0>;
1279 + clock-frequency = <50000000>;
1280 + clock-output-names = "clkfpc";
1281 + };
1282 +
1283 +- clkaud_ext_i_0: oscillator@3 {
1284 ++ clkaud_ext_i_0: oscillator-aud0 {
1285 + compatible = "fixed-clock";
1286 + #clock-cells = <0>;
1287 + clock-frequency = <6500000>;
1288 + clock-output-names = "clkaud_ext_i_0";
1289 + };
1290 +
1291 +- clkaud_ext_i_1: oscillator@4 {
1292 ++ clkaud_ext_i_1: oscillator-aud1 {
1293 + compatible = "fixed-clock";
1294 + #clock-cells = <0>;
1295 + clock-frequency = <196608000>;
1296 + clock-output-names = "clkaud_ext_i_1";
1297 + };
1298 +
1299 +- clkaud_ext_i_2: oscillator@5 {
1300 ++ clkaud_ext_i_2: oscillator-aud2 {
1301 + compatible = "fixed-clock";
1302 + #clock-cells = <0>;
1303 + clock-frequency = <180633600>;
1304 + clock-output-names = "clkaud_ext_i_2";
1305 + };
1306 +
1307 +- clki2si0_mck_i: oscillator@6 {
1308 ++ clki2si0_mck_i: oscillator-i2s0 {
1309 + compatible = "fixed-clock";
1310 + #clock-cells = <0>;
1311 + clock-frequency = <30000000>;
1312 + clock-output-names = "clki2si0_mck_i";
1313 + };
1314 +
1315 +- clki2si1_mck_i: oscillator@7 {
1316 ++ clki2si1_mck_i: oscillator-i2s1 {
1317 + compatible = "fixed-clock";
1318 + #clock-cells = <0>;
1319 + clock-frequency = <30000000>;
1320 + clock-output-names = "clki2si1_mck_i";
1321 + };
1322 +
1323 +- clki2si2_mck_i: oscillator@8 {
1324 ++ clki2si2_mck_i: oscillator-i2s2 {
1325 + compatible = "fixed-clock";
1326 + #clock-cells = <0>;
1327 + clock-frequency = <30000000>;
1328 + clock-output-names = "clki2si2_mck_i";
1329 + };
1330 +
1331 +- clktdmin_mclk_i: oscillator@9 {
1332 ++ clktdmin_mclk_i: oscillator-mclk {
1333 + compatible = "fixed-clock";
1334 + #clock-cells = <0>;
1335 + clock-frequency = <30000000>;
1336 +@@ -266,7 +266,7 @@
1337 + reg = <0 0x10005000 0 0x1000>;
1338 + };
1339 +
1340 +- pio: pinctrl@10005000 {
1341 ++ pio: pinctrl@1000b000 {
1342 + compatible = "mediatek,mt2712-pinctrl";
1343 + reg = <0 0x1000b000 0 0x1000>;
1344 + mediatek,pctl-regmap = <&syscfg_pctl_a>;
1345 +diff --git a/arch/arm64/boot/dts/mediatek/mt6779.dtsi b/arch/arm64/boot/dts/mediatek/mt6779.dtsi
1346 +index 9bdf5145966c5..dde9ce137b4f1 100644
1347 +--- a/arch/arm64/boot/dts/mediatek/mt6779.dtsi
1348 ++++ b/arch/arm64/boot/dts/mediatek/mt6779.dtsi
1349 +@@ -88,14 +88,14 @@
1350 + interrupts = <GIC_PPI 7 IRQ_TYPE_LEVEL_LOW 0>;
1351 + };
1352 +
1353 +- clk26m: oscillator@0 {
1354 ++ clk26m: oscillator-26m {
1355 + compatible = "fixed-clock";
1356 + #clock-cells = <0>;
1357 + clock-frequency = <26000000>;
1358 + clock-output-names = "clk26m";
1359 + };
1360 +
1361 +- clk32k: oscillator@1 {
1362 ++ clk32k: oscillator-32k {
1363 + compatible = "fixed-clock";
1364 + #clock-cells = <0>;
1365 + clock-frequency = <32768>;
1366 +@@ -117,7 +117,7 @@
1367 + compatible = "simple-bus";
1368 + ranges;
1369 +
1370 +- gic: interrupt-controller@0c000000 {
1371 ++ gic: interrupt-controller@c000000 {
1372 + compatible = "arm,gic-v3";
1373 + #interrupt-cells = <4>;
1374 + interrupt-parent = <&gic>;
1375 +@@ -138,7 +138,7 @@
1376 +
1377 + };
1378 +
1379 +- sysirq: intpol-controller@0c53a650 {
1380 ++ sysirq: intpol-controller@c53a650 {
1381 + compatible = "mediatek,mt6779-sysirq",
1382 + "mediatek,mt6577-sysirq";
1383 + interrupt-controller;
1384 +diff --git a/arch/arm64/boot/dts/mediatek/mt6797.dtsi b/arch/arm64/boot/dts/mediatek/mt6797.dtsi
1385 +index 15616231022a2..c3677d77e0a45 100644
1386 +--- a/arch/arm64/boot/dts/mediatek/mt6797.dtsi
1387 ++++ b/arch/arm64/boot/dts/mediatek/mt6797.dtsi
1388 +@@ -95,7 +95,7 @@
1389 + };
1390 + };
1391 +
1392 +- clk26m: oscillator@0 {
1393 ++ clk26m: oscillator-26m {
1394 + compatible = "fixed-clock";
1395 + #clock-cells = <0>;
1396 + clock-frequency = <26000000>;
1397 +diff --git a/arch/arm64/boot/dts/mediatek/mt7986a.dtsi b/arch/arm64/boot/dts/mediatek/mt7986a.dtsi
1398 +index e3a407d03551f..25b297bbb1b02 100644
1399 +--- a/arch/arm64/boot/dts/mediatek/mt7986a.dtsi
1400 ++++ b/arch/arm64/boot/dts/mediatek/mt7986a.dtsi
1401 +@@ -13,7 +13,7 @@
1402 + #address-cells = <2>;
1403 + #size-cells = <2>;
1404 +
1405 +- clk40m: oscillator@0 {
1406 ++ clk40m: oscillator-40m {
1407 + compatible = "fixed-clock";
1408 + clock-frequency = <40000000>;
1409 + #clock-cells = <0>;
1410 +@@ -162,7 +162,7 @@
1411 + #clock-cells = <1>;
1412 + };
1413 +
1414 +- trng: trng@1020f000 {
1415 ++ trng: rng@1020f000 {
1416 + compatible = "mediatek,mt7986-rng",
1417 + "mediatek,mt7623-rng";
1418 + reg = <0 0x1020f000 0 0x100>;
1419 +diff --git a/arch/arm64/boot/dts/mediatek/mt8183.dtsi b/arch/arm64/boot/dts/mediatek/mt8183.dtsi
1420 +index 9d32871973a29..85fb61324be8d 100644
1421 +--- a/arch/arm64/boot/dts/mediatek/mt8183.dtsi
1422 ++++ b/arch/arm64/boot/dts/mediatek/mt8183.dtsi
1423 +@@ -1670,7 +1670,7 @@
1424 + <GIC_SPI 278 IRQ_TYPE_LEVEL_LOW>;
1425 + interrupt-names = "job", "mmu", "gpu";
1426 +
1427 +- clocks = <&topckgen CLK_TOP_MFGPLL_CK>;
1428 ++ clocks = <&mfgcfg CLK_MFG_BG3D>;
1429 +
1430 + power-domains =
1431 + <&spm MT8183_POWER_DOMAIN_MFG_CORE0>,
1432 +diff --git a/arch/arm64/boot/dts/mediatek/mt8195.dtsi b/arch/arm64/boot/dts/mediatek/mt8195.dtsi
1433 +index 066c14989708a..e694ddb74f7d5 100644
1434 +--- a/arch/arm64/boot/dts/mediatek/mt8195.dtsi
1435 ++++ b/arch/arm64/boot/dts/mediatek/mt8195.dtsi
1436 +@@ -27,7 +27,7 @@
1437 + reg = <0x000>;
1438 + enable-method = "psci";
1439 + clock-frequency = <1701000000>;
1440 +- capacity-dmips-mhz = <578>;
1441 ++ capacity-dmips-mhz = <308>;
1442 + cpu-idle-states = <&cpu_off_l &cluster_off_l>;
1443 + next-level-cache = <&l2_0>;
1444 + #cooling-cells = <2>;
1445 +@@ -39,7 +39,7 @@
1446 + reg = <0x100>;
1447 + enable-method = "psci";
1448 + clock-frequency = <1701000000>;
1449 +- capacity-dmips-mhz = <578>;
1450 ++ capacity-dmips-mhz = <308>;
1451 + cpu-idle-states = <&cpu_off_l &cluster_off_l>;
1452 + next-level-cache = <&l2_0>;
1453 + #cooling-cells = <2>;
1454 +@@ -51,7 +51,7 @@
1455 + reg = <0x200>;
1456 + enable-method = "psci";
1457 + clock-frequency = <1701000000>;
1458 +- capacity-dmips-mhz = <578>;
1459 ++ capacity-dmips-mhz = <308>;
1460 + cpu-idle-states = <&cpu_off_l &cluster_off_l>;
1461 + next-level-cache = <&l2_0>;
1462 + #cooling-cells = <2>;
1463 +@@ -63,7 +63,7 @@
1464 + reg = <0x300>;
1465 + enable-method = "psci";
1466 + clock-frequency = <1701000000>;
1467 +- capacity-dmips-mhz = <578>;
1468 ++ capacity-dmips-mhz = <308>;
1469 + cpu-idle-states = <&cpu_off_l &cluster_off_l>;
1470 + next-level-cache = <&l2_0>;
1471 + #cooling-cells = <2>;
1472 +diff --git a/arch/arm64/boot/dts/mediatek/pumpkin-common.dtsi b/arch/arm64/boot/dts/mediatek/pumpkin-common.dtsi
1473 +index 8ee1529683a34..ec8dfb3d1c6d6 100644
1474 +--- a/arch/arm64/boot/dts/mediatek/pumpkin-common.dtsi
1475 ++++ b/arch/arm64/boot/dts/mediatek/pumpkin-common.dtsi
1476 +@@ -17,7 +17,7 @@
1477 + };
1478 +
1479 + firmware {
1480 +- optee: optee@4fd00000 {
1481 ++ optee: optee {
1482 + compatible = "linaro,optee-tz";
1483 + method = "smc";
1484 + };
1485 +@@ -209,7 +209,7 @@
1486 + };
1487 + };
1488 +
1489 +- i2c0_pins_a: i2c0@0 {
1490 ++ i2c0_pins_a: i2c0 {
1491 + pins1 {
1492 + pinmux = <MT8516_PIN_58_SDA0__FUNC_SDA0_0>,
1493 + <MT8516_PIN_59_SCL0__FUNC_SCL0_0>;
1494 +@@ -217,7 +217,7 @@
1495 + };
1496 + };
1497 +
1498 +- i2c2_pins_a: i2c2@0 {
1499 ++ i2c2_pins_a: i2c2 {
1500 + pins1 {
1501 + pinmux = <MT8516_PIN_60_SDA2__FUNC_SDA2_0>,
1502 + <MT8516_PIN_61_SCL2__FUNC_SCL2_0>;
1503 +diff --git a/arch/arm64/boot/dts/qcom/apq8096-ifc6640.dts b/arch/arm64/boot/dts/qcom/apq8096-ifc6640.dts
1504 +index 567b331065560..92f264891d84b 100644
1505 +--- a/arch/arm64/boot/dts/qcom/apq8096-ifc6640.dts
1506 ++++ b/arch/arm64/boot/dts/qcom/apq8096-ifc6640.dts
1507 +@@ -368,7 +368,7 @@
1508 +
1509 + bus-width = <4>;
1510 +
1511 +- cd-gpios = <&tlmm 38 0x1>;
1512 ++ cd-gpios = <&tlmm 38 GPIO_ACTIVE_LOW>;
1513 +
1514 + vmmc-supply = <&vreg_l21a_2p95>;
1515 + vqmmc-supply = <&vreg_l13a_2p95>;
1516 +diff --git a/arch/arm64/boot/dts/qcom/ipq6018-cp01-c1.dts b/arch/arm64/boot/dts/qcom/ipq6018-cp01-c1.dts
1517 +index 1ba2eca33c7b6..6a716c83e5f1d 100644
1518 +--- a/arch/arm64/boot/dts/qcom/ipq6018-cp01-c1.dts
1519 ++++ b/arch/arm64/boot/dts/qcom/ipq6018-cp01-c1.dts
1520 +@@ -37,6 +37,8 @@
1521 +
1522 + &blsp1_spi1 {
1523 + cs-select = <0>;
1524 ++ pinctrl-0 = <&spi_0_pins>;
1525 ++ pinctrl-names = "default";
1526 + status = "okay";
1527 +
1528 + flash@0 {
1529 +diff --git a/arch/arm64/boot/dts/qcom/msm8916.dtsi b/arch/arm64/boot/dts/qcom/msm8916.dtsi
1530 +index 48bc2e09128d9..863a60b636416 100644
1531 +--- a/arch/arm64/boot/dts/qcom/msm8916.dtsi
1532 ++++ b/arch/arm64/boot/dts/qcom/msm8916.dtsi
1533 +@@ -1331,7 +1331,7 @@
1534 + };
1535 +
1536 + mpss: remoteproc@4080000 {
1537 +- compatible = "qcom,msm8916-mss-pil", "qcom,q6v5-pil";
1538 ++ compatible = "qcom,msm8916-mss-pil";
1539 + reg = <0x04080000 0x100>,
1540 + <0x04020000 0x040>;
1541 +
1542 +diff --git a/arch/arm64/boot/dts/qcom/msm8994-sony-xperia-kitakami.dtsi b/arch/arm64/boot/dts/qcom/msm8994-sony-xperia-kitakami.dtsi
1543 +index f430d797196f5..ff60b7004d260 100644
1544 +--- a/arch/arm64/boot/dts/qcom/msm8994-sony-xperia-kitakami.dtsi
1545 ++++ b/arch/arm64/boot/dts/qcom/msm8994-sony-xperia-kitakami.dtsi
1546 +@@ -471,7 +471,7 @@
1547 + &sdhc2 {
1548 + status = "okay";
1549 +
1550 +- cd-gpios = <&tlmm 100 0>;
1551 ++ cd-gpios = <&tlmm 100 GPIO_ACTIVE_HIGH>;
1552 + vmmc-supply = <&pm8994_l21>;
1553 + vqmmc-supply = <&pm8994_l13>;
1554 + };
1555 +diff --git a/arch/arm64/boot/dts/qcom/msm8994.dtsi b/arch/arm64/boot/dts/qcom/msm8994.dtsi
1556 +index 8bc6c070e3066..86ef0091cafff 100644
1557 +--- a/arch/arm64/boot/dts/qcom/msm8994.dtsi
1558 ++++ b/arch/arm64/boot/dts/qcom/msm8994.dtsi
1559 +@@ -6,6 +6,7 @@
1560 + #include <dt-bindings/clock/qcom,gcc-msm8994.h>
1561 + #include <dt-bindings/clock/qcom,mmcc-msm8994.h>
1562 + #include <dt-bindings/clock/qcom,rpmcc.h>
1563 ++#include <dt-bindings/gpio/gpio.h>
1564 + #include <dt-bindings/power/qcom-rpmpd.h>
1565 +
1566 + / {
1567 +@@ -502,7 +503,7 @@
1568 + pinctrl-0 = <&sdc2_clk_on &sdc2_cmd_on &sdc2_data_on>;
1569 + pinctrl-1 = <&sdc2_clk_off &sdc2_cmd_off &sdc2_data_off>;
1570 +
1571 +- cd-gpios = <&tlmm 100 0>;
1572 ++ cd-gpios = <&tlmm 100 GPIO_ACTIVE_HIGH>;
1573 + bus-width = <4>;
1574 + status = "disabled";
1575 + };
1576 +diff --git a/arch/arm64/boot/dts/qcom/msm8996.dtsi b/arch/arm64/boot/dts/qcom/msm8996.dtsi
1577 +index 742eac4ce9b35..5cf04c350a62c 100644
1578 +--- a/arch/arm64/boot/dts/qcom/msm8996.dtsi
1579 ++++ b/arch/arm64/boot/dts/qcom/msm8996.dtsi
1580 +@@ -7,6 +7,7 @@
1581 + #include <dt-bindings/clock/qcom,mmcc-msm8996.h>
1582 + #include <dt-bindings/clock/qcom,rpmcc.h>
1583 + #include <dt-bindings/interconnect/qcom,msm8996.h>
1584 ++#include <dt-bindings/gpio/gpio.h>
1585 + #include <dt-bindings/power/qcom-rpmpd.h>
1586 + #include <dt-bindings/soc/qcom,apr.h>
1587 + #include <dt-bindings/thermal/thermal.h>
1588 +@@ -143,82 +144,92 @@
1589 + /* Nominal fmax for now */
1590 + opp-307200000 {
1591 + opp-hz = /bits/ 64 <307200000>;
1592 +- opp-supported-hw = <0x77>;
1593 ++ opp-supported-hw = <0x7>;
1594 + clock-latency-ns = <200000>;
1595 + };
1596 + opp-422400000 {
1597 + opp-hz = /bits/ 64 <422400000>;
1598 +- opp-supported-hw = <0x77>;
1599 ++ opp-supported-hw = <0x7>;
1600 + clock-latency-ns = <200000>;
1601 + };
1602 + opp-480000000 {
1603 + opp-hz = /bits/ 64 <480000000>;
1604 +- opp-supported-hw = <0x77>;
1605 ++ opp-supported-hw = <0x7>;
1606 + clock-latency-ns = <200000>;
1607 + };
1608 + opp-556800000 {
1609 + opp-hz = /bits/ 64 <556800000>;
1610 +- opp-supported-hw = <0x77>;
1611 ++ opp-supported-hw = <0x7>;
1612 + clock-latency-ns = <200000>;
1613 + };
1614 + opp-652800000 {
1615 + opp-hz = /bits/ 64 <652800000>;
1616 +- opp-supported-hw = <0x77>;
1617 ++ opp-supported-hw = <0x7>;
1618 + clock-latency-ns = <200000>;
1619 + };
1620 + opp-729600000 {
1621 + opp-hz = /bits/ 64 <729600000>;
1622 +- opp-supported-hw = <0x77>;
1623 ++ opp-supported-hw = <0x7>;
1624 + clock-latency-ns = <200000>;
1625 + };
1626 + opp-844800000 {
1627 + opp-hz = /bits/ 64 <844800000>;
1628 +- opp-supported-hw = <0x77>;
1629 ++ opp-supported-hw = <0x7>;
1630 + clock-latency-ns = <200000>;
1631 + };
1632 + opp-960000000 {
1633 + opp-hz = /bits/ 64 <960000000>;
1634 +- opp-supported-hw = <0x77>;
1635 ++ opp-supported-hw = <0x7>;
1636 + clock-latency-ns = <200000>;
1637 + };
1638 + opp-1036800000 {
1639 + opp-hz = /bits/ 64 <1036800000>;
1640 +- opp-supported-hw = <0x77>;
1641 ++ opp-supported-hw = <0x7>;
1642 + clock-latency-ns = <200000>;
1643 + };
1644 + opp-1113600000 {
1645 + opp-hz = /bits/ 64 <1113600000>;
1646 +- opp-supported-hw = <0x77>;
1647 ++ opp-supported-hw = <0x7>;
1648 + clock-latency-ns = <200000>;
1649 + };
1650 + opp-1190400000 {
1651 + opp-hz = /bits/ 64 <1190400000>;
1652 +- opp-supported-hw = <0x77>;
1653 ++ opp-supported-hw = <0x7>;
1654 + clock-latency-ns = <200000>;
1655 + };
1656 + opp-1228800000 {
1657 + opp-hz = /bits/ 64 <1228800000>;
1658 +- opp-supported-hw = <0x77>;
1659 ++ opp-supported-hw = <0x7>;
1660 + clock-latency-ns = <200000>;
1661 + };
1662 + opp-1324800000 {
1663 + opp-hz = /bits/ 64 <1324800000>;
1664 +- opp-supported-hw = <0x77>;
1665 ++ opp-supported-hw = <0x5>;
1666 ++ clock-latency-ns = <200000>;
1667 ++ };
1668 ++ opp-1363200000 {
1669 ++ opp-hz = /bits/ 64 <1363200000>;
1670 ++ opp-supported-hw = <0x2>;
1671 + clock-latency-ns = <200000>;
1672 + };
1673 + opp-1401600000 {
1674 + opp-hz = /bits/ 64 <1401600000>;
1675 +- opp-supported-hw = <0x77>;
1676 ++ opp-supported-hw = <0x5>;
1677 + clock-latency-ns = <200000>;
1678 + };
1679 + opp-1478400000 {
1680 + opp-hz = /bits/ 64 <1478400000>;
1681 +- opp-supported-hw = <0x77>;
1682 ++ opp-supported-hw = <0x1>;
1683 ++ clock-latency-ns = <200000>;
1684 ++ };
1685 ++ opp-1497600000 {
1686 ++ opp-hz = /bits/ 64 <1497600000>;
1687 ++ opp-supported-hw = <0x04>;
1688 + clock-latency-ns = <200000>;
1689 + };
1690 + opp-1593600000 {
1691 + opp-hz = /bits/ 64 <1593600000>;
1692 +- opp-supported-hw = <0x77>;
1693 ++ opp-supported-hw = <0x1>;
1694 + clock-latency-ns = <200000>;
1695 + };
1696 + };
1697 +@@ -231,127 +242,137 @@
1698 + /* Nominal fmax for now */
1699 + opp-307200000 {
1700 + opp-hz = /bits/ 64 <307200000>;
1701 +- opp-supported-hw = <0x77>;
1702 ++ opp-supported-hw = <0x7>;
1703 + clock-latency-ns = <200000>;
1704 + };
1705 + opp-403200000 {
1706 + opp-hz = /bits/ 64 <403200000>;
1707 +- opp-supported-hw = <0x77>;
1708 ++ opp-supported-hw = <0x7>;
1709 + clock-latency-ns = <200000>;
1710 + };
1711 + opp-480000000 {
1712 + opp-hz = /bits/ 64 <480000000>;
1713 +- opp-supported-hw = <0x77>;
1714 ++ opp-supported-hw = <0x7>;
1715 + clock-latency-ns = <200000>;
1716 + };
1717 + opp-556800000 {
1718 + opp-hz = /bits/ 64 <556800000>;
1719 +- opp-supported-hw = <0x77>;
1720 ++ opp-supported-hw = <0x7>;
1721 + clock-latency-ns = <200000>;
1722 + };
1723 + opp-652800000 {
1724 + opp-hz = /bits/ 64 <652800000>;
1725 +- opp-supported-hw = <0x77>;
1726 ++ opp-supported-hw = <0x7>;
1727 + clock-latency-ns = <200000>;
1728 + };
1729 + opp-729600000 {
1730 + opp-hz = /bits/ 64 <729600000>;
1731 +- opp-supported-hw = <0x77>;
1732 ++ opp-supported-hw = <0x7>;
1733 + clock-latency-ns = <200000>;
1734 + };
1735 + opp-806400000 {
1736 + opp-hz = /bits/ 64 <806400000>;
1737 +- opp-supported-hw = <0x77>;
1738 ++ opp-supported-hw = <0x7>;
1739 + clock-latency-ns = <200000>;
1740 + };
1741 + opp-883200000 {
1742 + opp-hz = /bits/ 64 <883200000>;
1743 +- opp-supported-hw = <0x77>;
1744 ++ opp-supported-hw = <0x7>;
1745 + clock-latency-ns = <200000>;
1746 + };
1747 + opp-940800000 {
1748 + opp-hz = /bits/ 64 <940800000>;
1749 +- opp-supported-hw = <0x77>;
1750 ++ opp-supported-hw = <0x7>;
1751 + clock-latency-ns = <200000>;
1752 + };
1753 + opp-1036800000 {
1754 + opp-hz = /bits/ 64 <1036800000>;
1755 +- opp-supported-hw = <0x77>;
1756 ++ opp-supported-hw = <0x7>;
1757 + clock-latency-ns = <200000>;
1758 + };
1759 + opp-1113600000 {
1760 + opp-hz = /bits/ 64 <1113600000>;
1761 +- opp-supported-hw = <0x77>;
1762 ++ opp-supported-hw = <0x7>;
1763 + clock-latency-ns = <200000>;
1764 + };
1765 + opp-1190400000 {
1766 + opp-hz = /bits/ 64 <1190400000>;
1767 +- opp-supported-hw = <0x77>;
1768 ++ opp-supported-hw = <0x7>;
1769 + clock-latency-ns = <200000>;
1770 + };
1771 + opp-1248000000 {
1772 + opp-hz = /bits/ 64 <1248000000>;
1773 +- opp-supported-hw = <0x77>;
1774 ++ opp-supported-hw = <0x7>;
1775 + clock-latency-ns = <200000>;
1776 + };
1777 + opp-1324800000 {
1778 + opp-hz = /bits/ 64 <1324800000>;
1779 +- opp-supported-hw = <0x77>;
1780 ++ opp-supported-hw = <0x7>;
1781 + clock-latency-ns = <200000>;
1782 + };
1783 + opp-1401600000 {
1784 + opp-hz = /bits/ 64 <1401600000>;
1785 +- opp-supported-hw = <0x77>;
1786 ++ opp-supported-hw = <0x7>;
1787 + clock-latency-ns = <200000>;
1788 + };
1789 + opp-1478400000 {
1790 + opp-hz = /bits/ 64 <1478400000>;
1791 +- opp-supported-hw = <0x77>;
1792 ++ opp-supported-hw = <0x7>;
1793 + clock-latency-ns = <200000>;
1794 + };
1795 + opp-1555200000 {
1796 + opp-hz = /bits/ 64 <1555200000>;
1797 +- opp-supported-hw = <0x77>;
1798 ++ opp-supported-hw = <0x7>;
1799 + clock-latency-ns = <200000>;
1800 + };
1801 + opp-1632000000 {
1802 + opp-hz = /bits/ 64 <1632000000>;
1803 +- opp-supported-hw = <0x77>;
1804 ++ opp-supported-hw = <0x7>;
1805 + clock-latency-ns = <200000>;
1806 + };
1807 + opp-1708800000 {
1808 + opp-hz = /bits/ 64 <1708800000>;
1809 +- opp-supported-hw = <0x77>;
1810 ++ opp-supported-hw = <0x7>;
1811 + clock-latency-ns = <200000>;
1812 + };
1813 + opp-1785600000 {
1814 + opp-hz = /bits/ 64 <1785600000>;
1815 +- opp-supported-hw = <0x77>;
1816 ++ opp-supported-hw = <0x7>;
1817 ++ clock-latency-ns = <200000>;
1818 ++ };
1819 ++ opp-1804800000 {
1820 ++ opp-hz = /bits/ 64 <1804800000>;
1821 ++ opp-supported-hw = <0x6>;
1822 + clock-latency-ns = <200000>;
1823 + };
1824 + opp-1824000000 {
1825 + opp-hz = /bits/ 64 <1824000000>;
1826 +- opp-supported-hw = <0x77>;
1827 ++ opp-supported-hw = <0x1>;
1828 ++ clock-latency-ns = <200000>;
1829 ++ };
1830 ++ opp-1900800000 {
1831 ++ opp-hz = /bits/ 64 <1900800000>;
1832 ++ opp-supported-hw = <0x4>;
1833 + clock-latency-ns = <200000>;
1834 + };
1835 + opp-1920000000 {
1836 + opp-hz = /bits/ 64 <1920000000>;
1837 +- opp-supported-hw = <0x77>;
1838 ++ opp-supported-hw = <0x1>;
1839 + clock-latency-ns = <200000>;
1840 + };
1841 + opp-1996800000 {
1842 + opp-hz = /bits/ 64 <1996800000>;
1843 +- opp-supported-hw = <0x77>;
1844 ++ opp-supported-hw = <0x1>;
1845 + clock-latency-ns = <200000>;
1846 + };
1847 + opp-2073600000 {
1848 + opp-hz = /bits/ 64 <2073600000>;
1849 +- opp-supported-hw = <0x77>;
1850 ++ opp-supported-hw = <0x1>;
1851 + clock-latency-ns = <200000>;
1852 + };
1853 + opp-2150400000 {
1854 + opp-hz = /bits/ 64 <2150400000>;
1855 +- opp-supported-hw = <0x77>;
1856 ++ opp-supported-hw = <0x1>;
1857 + clock-latency-ns = <200000>;
1858 + };
1859 + };
1860 +@@ -1208,17 +1229,17 @@
1861 + compatible = "operating-points-v2";
1862 +
1863 + /*
1864 +- * 624Mhz and 560Mhz are only available on speed
1865 +- * bin (1 << 0). All the rest are available on
1866 +- * all bins of the hardware
1867 ++ * 624Mhz is only available on speed bins 0 and 3.
1868 ++ * 560Mhz is only available on speed bins 0, 2 and 3.
1869 ++ * All the rest are available on all bins of the hardware.
1870 + */
1871 + opp-624000000 {
1872 + opp-hz = /bits/ 64 <624000000>;
1873 +- opp-supported-hw = <0x01>;
1874 ++ opp-supported-hw = <0x09>;
1875 + };
1876 + opp-560000000 {
1877 + opp-hz = /bits/ 64 <560000000>;
1878 +- opp-supported-hw = <0x01>;
1879 ++ opp-supported-hw = <0x0d>;
1880 + };
1881 + opp-510000000 {
1882 + opp-hz = /bits/ 64 <510000000>;
1883 +@@ -3337,7 +3358,7 @@
1884 + interrupt-names = "intr1", "intr2";
1885 + interrupt-controller;
1886 + #interrupt-cells = <1>;
1887 +- reset-gpios = <&tlmm 64 0>;
1888 ++ reset-gpios = <&tlmm 64 GPIO_ACTIVE_LOW>;
1889 +
1890 + slim-ifc-dev = <&tasha_ifd>;
1891 +
1892 +diff --git a/arch/arm64/boot/dts/qcom/msm8996pro.dtsi b/arch/arm64/boot/dts/qcom/msm8996pro.dtsi
1893 +new file mode 100644
1894 +index 0000000000000..63e1b4ec7a360
1895 +--- /dev/null
1896 ++++ b/arch/arm64/boot/dts/qcom/msm8996pro.dtsi
1897 +@@ -0,0 +1,266 @@
1898 ++// SPDX-License-Identifier: BSD-3-Clause
1899 ++/*
1900 ++ * Copyright (c) 2022, Linaro Limited
1901 ++ */
1902 ++
1903 ++#include "msm8996.dtsi"
1904 ++
1905 ++/ {
1906 ++ /delete-node/ opp-table-cluster0;
1907 ++ /delete-node/ opp-table-cluster1;
1908 ++
1909 ++ /*
1910 ++ * On MSM8996 Pro the cpufreq driver shifts speed bins into the high
1911 ++ * nibble of supported hw, so speed bin 0 becomes 0x10, speed bin 1
1912 ++ * becomes 0x20, speed 2 becomes 0x40.
1913 ++ */
1914 ++
1915 ++ cluster0_opp: opp-table-cluster0 {
1916 ++ compatible = "operating-points-v2-kryo-cpu";
1917 ++ nvmem-cells = <&speedbin_efuse>;
1918 ++ opp-shared;
1919 ++
1920 ++ opp-307200000 {
1921 ++ opp-hz = /bits/ 64 <307200000>;
1922 ++ opp-supported-hw = <0x70>;
1923 ++ clock-latency-ns = <200000>;
1924 ++ };
1925 ++ opp-384000000 {
1926 ++ opp-hz = /bits/ 64 <384000000>;
1927 ++ opp-supported-hw = <0x70>;
1928 ++ clock-latency-ns = <200000>;
1929 ++ };
1930 ++ opp-460800000 {
1931 ++ opp-hz = /bits/ 64 <460800000>;
1932 ++ opp-supported-hw = <0x70>;
1933 ++ clock-latency-ns = <200000>;
1934 ++ };
1935 ++ opp-537600000 {
1936 ++ opp-hz = /bits/ 64 <537600000>;
1937 ++ opp-supported-hw = <0x70>;
1938 ++ clock-latency-ns = <200000>;
1939 ++ };
1940 ++ opp-614400000 {
1941 ++ opp-hz = /bits/ 64 <614400000>;
1942 ++ opp-supported-hw = <0x70>;
1943 ++ clock-latency-ns = <200000>;
1944 ++ };
1945 ++ opp-691200000 {
1946 ++ opp-hz = /bits/ 64 <691200000>;
1947 ++ opp-supported-hw = <0x70>;
1948 ++ clock-latency-ns = <200000>;
1949 ++ };
1950 ++ opp-768000000 {
1951 ++ opp-hz = /bits/ 64 <768000000>;
1952 ++ opp-supported-hw = <0x70>;
1953 ++ clock-latency-ns = <200000>;
1954 ++ };
1955 ++ opp-844800000 {
1956 ++ opp-hz = /bits/ 64 <844800000>;
1957 ++ opp-supported-hw = <0x70>;
1958 ++ clock-latency-ns = <200000>;
1959 ++ };
1960 ++ opp-902400000 {
1961 ++ opp-hz = /bits/ 64 <902400000>;
1962 ++ opp-supported-hw = <0x70>;
1963 ++ clock-latency-ns = <200000>;
1964 ++ };
1965 ++ opp-979200000 {
1966 ++ opp-hz = /bits/ 64 <979200000>;
1967 ++ opp-supported-hw = <0x70>;
1968 ++ clock-latency-ns = <200000>;
1969 ++ };
1970 ++ opp-1056000000 {
1971 ++ opp-hz = /bits/ 64 <1056000000>;
1972 ++ opp-supported-hw = <0x70>;
1973 ++ clock-latency-ns = <200000>;
1974 ++ };
1975 ++ opp-1132800000 {
1976 ++ opp-hz = /bits/ 64 <1132800000>;
1977 ++ opp-supported-hw = <0x70>;
1978 ++ clock-latency-ns = <200000>;
1979 ++ };
1980 ++ opp-1209600000 {
1981 ++ opp-hz = /bits/ 64 <1209600000>;
1982 ++ opp-supported-hw = <0x70>;
1983 ++ clock-latency-ns = <200000>;
1984 ++ };
1985 ++ opp-1286400000 {
1986 ++ opp-hz = /bits/ 64 <1286400000>;
1987 ++ opp-supported-hw = <0x70>;
1988 ++ clock-latency-ns = <200000>;
1989 ++ };
1990 ++ opp-1363200000 {
1991 ++ opp-hz = /bits/ 64 <1363200000>;
1992 ++ opp-supported-hw = <0x70>;
1993 ++ clock-latency-ns = <200000>;
1994 ++ };
1995 ++ opp-1440000000 {
1996 ++ opp-hz = /bits/ 64 <1440000000>;
1997 ++ opp-supported-hw = <0x70>;
1998 ++ clock-latency-ns = <200000>;
1999 ++ };
2000 ++ opp-1516800000 {
2001 ++ opp-hz = /bits/ 64 <1516800000>;
2002 ++ opp-supported-hw = <0x70>;
2003 ++ clock-latency-ns = <200000>;
2004 ++ };
2005 ++ opp-1593600000 {
2006 ++ opp-hz = /bits/ 64 <1593600000>;
2007 ++ opp-supported-hw = <0x70>;
2008 ++ clock-latency-ns = <200000>;
2009 ++ };
2010 ++ opp-1996800000 {
2011 ++ opp-hz = /bits/ 64 <1996800000>;
2012 ++ opp-supported-hw = <0x20>;
2013 ++ clock-latency-ns = <200000>;
2014 ++ };
2015 ++ opp-2188800000 {
2016 ++ opp-hz = /bits/ 64 <2188800000>;
2017 ++ opp-supported-hw = <0x10>;
2018 ++ clock-latency-ns = <200000>;
2019 ++ };
2020 ++ };
2021 ++
2022 ++ cluster1_opp: opp-table-cluster1 {
2023 ++ compatible = "operating-points-v2-kryo-cpu";
2024 ++ nvmem-cells = <&speedbin_efuse>;
2025 ++ opp-shared;
2026 ++
2027 ++ opp-307200000 {
2028 ++ opp-hz = /bits/ 64 <307200000>;
2029 ++ opp-supported-hw = <0x70>;
2030 ++ clock-latency-ns = <200000>;
2031 ++ };
2032 ++ opp-384000000 {
2033 ++ opp-hz = /bits/ 64 <384000000>;
2034 ++ opp-supported-hw = <0x70>;
2035 ++ clock-latency-ns = <200000>;
2036 ++ };
2037 ++ opp-460800000 {
2038 ++ opp-hz = /bits/ 64 <460800000>;
2039 ++ opp-supported-hw = <0x70>;
2040 ++ clock-latency-ns = <200000>;
2041 ++ };
2042 ++ opp-537600000 {
2043 ++ opp-hz = /bits/ 64 <537600000>;
2044 ++ opp-supported-hw = <0x70>;
2045 ++ clock-latency-ns = <200000>;
2046 ++ };
2047 ++ opp-614400000 {
2048 ++ opp-hz = /bits/ 64 <614400000>;
2049 ++ opp-supported-hw = <0x70>;
2050 ++ clock-latency-ns = <200000>;
2051 ++ };
2052 ++ opp-691200000 {
2053 ++ opp-hz = /bits/ 64 <691200000>;
2054 ++ opp-supported-hw = <0x70>;
2055 ++ clock-latency-ns = <200000>;
2056 ++ };
2057 ++ opp-748800000 {
2058 ++ opp-hz = /bits/ 64 <748800000>;
2059 ++ opp-supported-hw = <0x70>;
2060 ++ clock-latency-ns = <200000>;
2061 ++ };
2062 ++ opp-825600000 {
2063 ++ opp-hz = /bits/ 64 <825600000>;
2064 ++ opp-supported-hw = <0x70>;
2065 ++ clock-latency-ns = <200000>;
2066 ++ };
2067 ++ opp-902400000 {
2068 ++ opp-hz = /bits/ 64 <902400000>;
2069 ++ opp-supported-hw = <0x70>;
2070 ++ clock-latency-ns = <200000>;
2071 ++ };
2072 ++ opp-979200000 {
2073 ++ opp-hz = /bits/ 64 <979200000>;
2074 ++ opp-supported-hw = <0x70>;
2075 ++ clock-latency-ns = <200000>;
2076 ++ };
2077 ++ opp-1056000000 {
2078 ++ opp-hz = /bits/ 64 <1056000000>;
2079 ++ opp-supported-hw = <0x70>;
2080 ++ clock-latency-ns = <200000>;
2081 ++ };
2082 ++ opp-1132800000 {
2083 ++ opp-hz = /bits/ 64 <1132800000>;
2084 ++ opp-supported-hw = <0x70>;
2085 ++ clock-latency-ns = <200000>;
2086 ++ };
2087 ++ opp-1209600000 {
2088 ++ opp-hz = /bits/ 64 <1209600000>;
2089 ++ opp-supported-hw = <0x70>;
2090 ++ clock-latency-ns = <200000>;
2091 ++ };
2092 ++ opp-1286400000 {
2093 ++ opp-hz = /bits/ 64 <1286400000>;
2094 ++ opp-supported-hw = <0x70>;
2095 ++ clock-latency-ns = <200000>;
2096 ++ };
2097 ++ opp-1363200000 {
2098 ++ opp-hz = /bits/ 64 <1363200000>;
2099 ++ opp-supported-hw = <0x70>;
2100 ++ clock-latency-ns = <200000>;
2101 ++ };
2102 ++ opp-1440000000 {
2103 ++ opp-hz = /bits/ 64 <1440000000>;
2104 ++ opp-supported-hw = <0x70>;
2105 ++ clock-latency-ns = <200000>;
2106 ++ };
2107 ++ opp-1516800000 {
2108 ++ opp-hz = /bits/ 64 <1516800000>;
2109 ++ opp-supported-hw = <0x70>;
2110 ++ clock-latency-ns = <200000>;
2111 ++ };
2112 ++ opp-1593600000 {
2113 ++ opp-hz = /bits/ 64 <1593600000>;
2114 ++ opp-supported-hw = <0x70>;
2115 ++ clock-latency-ns = <200000>;
2116 ++ };
2117 ++ opp-1670400000 {
2118 ++ opp-hz = /bits/ 64 <1670400000>;
2119 ++ opp-supported-hw = <0x70>;
2120 ++ clock-latency-ns = <200000>;
2121 ++ };
2122 ++ opp-1747200000 {
2123 ++ opp-hz = /bits/ 64 <1747200000>;
2124 ++ opp-supported-hw = <0x70>;
2125 ++ clock-latency-ns = <200000>;
2126 ++ };
2127 ++ opp-1824000000 {
2128 ++ opp-hz = /bits/ 64 <1824000000>;
2129 ++ opp-supported-hw = <0x70>;
2130 ++ clock-latency-ns = <200000>;
2131 ++ };
2132 ++ opp-1900800000 {
2133 ++ opp-hz = /bits/ 64 <1900800000>;
2134 ++ opp-supported-hw = <0x70>;
2135 ++ clock-latency-ns = <200000>;
2136 ++ };
2137 ++ opp-1977600000 {
2138 ++ opp-hz = /bits/ 64 <1977600000>;
2139 ++ opp-supported-hw = <0x30>;
2140 ++ clock-latency-ns = <200000>;
2141 ++ };
2142 ++ opp-2054400000 {
2143 ++ opp-hz = /bits/ 64 <2054400000>;
2144 ++ opp-supported-hw = <0x30>;
2145 ++ clock-latency-ns = <200000>;
2146 ++ };
2147 ++ opp-2150400000 {
2148 ++ opp-hz = /bits/ 64 <2150400000>;
2149 ++ opp-supported-hw = <0x30>;
2150 ++ clock-latency-ns = <200000>;
2151 ++ };
2152 ++ opp-2246400000 {
2153 ++ opp-hz = /bits/ 64 <2246400000>;
2154 ++ opp-supported-hw = <0x10>;
2155 ++ clock-latency-ns = <200000>;
2156 ++ };
2157 ++ opp-2342400000 {
2158 ++ opp-hz = /bits/ 64 <2342400000>;
2159 ++ opp-supported-hw = <0x10>;
2160 ++ clock-latency-ns = <200000>;
2161 ++ };
2162 ++ };
2163 ++};
2164 +diff --git a/arch/arm64/boot/dts/qcom/pm6350.dtsi b/arch/arm64/boot/dts/qcom/pm6350.dtsi
2165 +index ecf9b99191828..68245d78d2b93 100644
2166 +--- a/arch/arm64/boot/dts/qcom/pm6350.dtsi
2167 ++++ b/arch/arm64/boot/dts/qcom/pm6350.dtsi
2168 +@@ -3,6 +3,7 @@
2169 + * Copyright (c) 2021, Luca Weiss <luca@×××××.xyz>
2170 + */
2171 +
2172 ++#include <dt-bindings/input/input.h>
2173 + #include <dt-bindings/spmi/spmi.h>
2174 +
2175 + &spmi_bus {
2176 +diff --git a/arch/arm64/boot/dts/qcom/pm660.dtsi b/arch/arm64/boot/dts/qcom/pm660.dtsi
2177 +index d0eefbb516634..d8c9ece20cd9a 100644
2178 +--- a/arch/arm64/boot/dts/qcom/pm660.dtsi
2179 ++++ b/arch/arm64/boot/dts/qcom/pm660.dtsi
2180 +@@ -163,7 +163,7 @@
2181 + qcom,pre-scaling = <1 3>;
2182 + };
2183 +
2184 +- vcoin: vcoin@83 {
2185 ++ vcoin: vcoin@85 {
2186 + reg = <ADC5_VCOIN>;
2187 + qcom,decimation = <1024>;
2188 + qcom,pre-scaling = <1 3>;
2189 +diff --git a/arch/arm64/boot/dts/qcom/sc7180-trogdor-homestar.dtsi b/arch/arm64/boot/dts/qcom/sc7180-trogdor-homestar.dtsi
2190 +index 1bd6c7dcd9e91..bfab67f4a7c9c 100644
2191 +--- a/arch/arm64/boot/dts/qcom/sc7180-trogdor-homestar.dtsi
2192 ++++ b/arch/arm64/boot/dts/qcom/sc7180-trogdor-homestar.dtsi
2193 +@@ -194,6 +194,12 @@ ap_ts_pen_1v8: &i2c4 {
2194 + pins = "gpio49", "gpio50", "gpio51", "gpio52";
2195 + function = "mi2s_1";
2196 + };
2197 ++
2198 ++ pinconf {
2199 ++ pins = "gpio49", "gpio50", "gpio51", "gpio52";
2200 ++ drive-strength = <2>;
2201 ++ bias-pull-down;
2202 ++ };
2203 + };
2204 +
2205 + &ts_reset_l {
2206 +diff --git a/arch/arm64/boot/dts/qcom/sdm630.dtsi b/arch/arm64/boot/dts/qcom/sdm630.dtsi
2207 +index 1bc9091cad2a8..12f01815230bc 100644
2208 +--- a/arch/arm64/boot/dts/qcom/sdm630.dtsi
2209 ++++ b/arch/arm64/boot/dts/qcom/sdm630.dtsi
2210 +@@ -773,7 +773,7 @@
2211 + pins = "gpio17", "gpio18", "gpio19";
2212 + function = "gpio";
2213 + drive-strength = <2>;
2214 +- bias-no-pull;
2215 ++ bias-disable;
2216 + };
2217 + };
2218 +
2219 +diff --git a/arch/arm64/boot/dts/qcom/sdm845-cheza.dtsi b/arch/arm64/boot/dts/qcom/sdm845-cheza.dtsi
2220 +index b5eb8f7eca1d5..b5f11fbcc3004 100644
2221 +--- a/arch/arm64/boot/dts/qcom/sdm845-cheza.dtsi
2222 ++++ b/arch/arm64/boot/dts/qcom/sdm845-cheza.dtsi
2223 +@@ -1436,7 +1436,7 @@ ap_ts_i2c: &i2c14 {
2224 + config {
2225 + pins = "gpio126";
2226 + function = "gpio";
2227 +- bias-no-pull;
2228 ++ bias-disable;
2229 + drive-strength = <2>;
2230 + output-low;
2231 + };
2232 +@@ -1446,7 +1446,7 @@ ap_ts_i2c: &i2c14 {
2233 + config {
2234 + pins = "gpio126";
2235 + function = "gpio";
2236 +- bias-no-pull;
2237 ++ bias-disable;
2238 + drive-strength = <2>;
2239 + output-high;
2240 + };
2241 +diff --git a/arch/arm64/boot/dts/qcom/sdm845-db845c.dts b/arch/arm64/boot/dts/qcom/sdm845-db845c.dts
2242 +index c6e2c571b4527..b2eddcd875069 100644
2243 +--- a/arch/arm64/boot/dts/qcom/sdm845-db845c.dts
2244 ++++ b/arch/arm64/boot/dts/qcom/sdm845-db845c.dts
2245 +@@ -1081,7 +1081,7 @@
2246 + pinctrl-names = "default";
2247 + clock-names = "extclk";
2248 + clocks = <&rpmhcc RPMH_LN_BB_CLK2>;
2249 +- reset-gpios = <&tlmm 64 0>;
2250 ++ reset-gpios = <&tlmm 64 GPIO_ACTIVE_HIGH>;
2251 + vdd-buck-supply = <&vreg_s4a_1p8>;
2252 + vdd-buck-sido-supply = <&vreg_s4a_1p8>;
2253 + vdd-tx-supply = <&vreg_s4a_1p8>;
2254 +@@ -1255,7 +1255,7 @@
2255 + reg = <0x60>;
2256 +
2257 + // CAM3_RST_N
2258 +- enable-gpios = <&tlmm 21 0>;
2259 ++ enable-gpios = <&tlmm 21 GPIO_ACTIVE_HIGH>;
2260 + pinctrl-names = "default";
2261 + pinctrl-0 = <&cam3_default>;
2262 + gpios = <&tlmm 16 0>,
2263 +diff --git a/arch/arm64/boot/dts/qcom/sdm845-xiaomi-beryllium.dts b/arch/arm64/boot/dts/qcom/sdm845-xiaomi-beryllium.dts
2264 +index 82c27f90d300d..0f470cf1ed1c1 100644
2265 +--- a/arch/arm64/boot/dts/qcom/sdm845-xiaomi-beryllium.dts
2266 ++++ b/arch/arm64/boot/dts/qcom/sdm845-xiaomi-beryllium.dts
2267 +@@ -546,7 +546,7 @@
2268 + pinctrl-names = "default";
2269 + clock-names = "extclk";
2270 + clocks = <&rpmhcc RPMH_LN_BB_CLK2>;
2271 +- reset-gpios = <&tlmm 64 0>;
2272 ++ reset-gpios = <&tlmm 64 GPIO_ACTIVE_HIGH>;
2273 + vdd-buck-supply = <&vreg_s4a_1p8>;
2274 + vdd-buck-sido-supply = <&vreg_s4a_1p8>;
2275 + vdd-tx-supply = <&vreg_s4a_1p8>;
2276 +diff --git a/arch/arm64/boot/dts/qcom/sdm845-xiaomi-polaris.dts b/arch/arm64/boot/dts/qcom/sdm845-xiaomi-polaris.dts
2277 +index dba7c2693ff50..1cc477c309451 100644
2278 +--- a/arch/arm64/boot/dts/qcom/sdm845-xiaomi-polaris.dts
2279 ++++ b/arch/arm64/boot/dts/qcom/sdm845-xiaomi-polaris.dts
2280 +@@ -126,7 +126,7 @@
2281 + regulator-min-microvolt = <1800000>;
2282 + regulator-max-microvolt = <1800000>;
2283 +
2284 +- gpio = <&tlmm 23 0>;
2285 ++ gpio = <&tlmm 23 GPIO_ACTIVE_HIGH>;
2286 + regulator-always-on;
2287 + regulator-boot-on;
2288 + enable-active-high;
2289 +@@ -628,7 +628,7 @@
2290 + };
2291 +
2292 + wcd_intr_default: wcd-intr-default {
2293 +- pins = "goui54";
2294 ++ pins = "gpio54";
2295 + function = "gpio";
2296 + input-enable;
2297 + bias-pull-down;
2298 +@@ -712,7 +712,7 @@
2299 + pinctrl-names = "default";
2300 + clock-names = "extclk";
2301 + clocks = <&rpmhcc RPMH_LN_BB_CLK2>;
2302 +- reset-gpios = <&tlmm 64 0>;
2303 ++ reset-gpios = <&tlmm 64 GPIO_ACTIVE_HIGH>;
2304 + vdd-buck-sido-supply = <&vreg_s4a_1p8>;
2305 + vdd-buck-supply = <&vreg_s4a_1p8>;
2306 + vdd-tx-supply = <&vreg_s4a_1p8>;
2307 +diff --git a/arch/arm64/boot/dts/qcom/sdm850-lenovo-yoga-c630.dts b/arch/arm64/boot/dts/qcom/sdm850-lenovo-yoga-c630.dts
2308 +index a7af1bed43129..be59a8ba9c1fe 100644
2309 +--- a/arch/arm64/boot/dts/qcom/sdm850-lenovo-yoga-c630.dts
2310 ++++ b/arch/arm64/boot/dts/qcom/sdm850-lenovo-yoga-c630.dts
2311 +@@ -772,7 +772,7 @@
2312 + pinctrl-names = "default";
2313 + clock-names = "extclk";
2314 + clocks = <&rpmhcc RPMH_LN_BB_CLK2>;
2315 +- reset-gpios = <&tlmm 64 0>;
2316 ++ reset-gpios = <&tlmm 64 GPIO_ACTIVE_HIGH>;
2317 + vdd-buck-supply = <&vreg_s4a_1p8>;
2318 + vdd-buck-sido-supply = <&vreg_s4a_1p8>;
2319 + vdd-tx-supply = <&vreg_s4a_1p8>;
2320 +diff --git a/arch/arm64/boot/dts/qcom/sdm850-samsung-w737.dts b/arch/arm64/boot/dts/qcom/sdm850-samsung-w737.dts
2321 +index b0315eeb13205..f954fe5cb61ab 100644
2322 +--- a/arch/arm64/boot/dts/qcom/sdm850-samsung-w737.dts
2323 ++++ b/arch/arm64/boot/dts/qcom/sdm850-samsung-w737.dts
2324 +@@ -704,7 +704,7 @@
2325 + pinctrl-names = "default";
2326 + clock-names = "extclk";
2327 + clocks = <&rpmhcc RPMH_LN_BB_CLK2>;
2328 +- reset-gpios = <&tlmm 64 0>;
2329 ++ reset-gpios = <&tlmm 64 GPIO_ACTIVE_HIGH>;
2330 + vdd-buck-supply = <&vreg_s4a_1p8>;
2331 + vdd-buck-sido-supply = <&vreg_s4a_1p8>;
2332 + vdd-tx-supply = <&vreg_s4a_1p8>;
2333 +diff --git a/arch/arm64/boot/dts/qcom/sm6125.dtsi b/arch/arm64/boot/dts/qcom/sm6125.dtsi
2334 +index 8c582a9e4ada4..0127224086823 100644
2335 +--- a/arch/arm64/boot/dts/qcom/sm6125.dtsi
2336 ++++ b/arch/arm64/boot/dts/qcom/sm6125.dtsi
2337 +@@ -458,7 +458,7 @@
2338 + sdhc_1: mmc@4744000 {
2339 + compatible = "qcom,sm6125-sdhci", "qcom,sdhci-msm-v5";
2340 + reg = <0x04744000 0x1000>, <0x04745000 0x1000>;
2341 +- reg-names = "hc", "core";
2342 ++ reg-names = "hc", "cqhci";
2343 +
2344 + interrupts = <GIC_SPI 348 IRQ_TYPE_LEVEL_HIGH>,
2345 + <GIC_SPI 352 IRQ_TYPE_LEVEL_HIGH>;
2346 +diff --git a/arch/arm64/boot/dts/qcom/sm6350.dtsi b/arch/arm64/boot/dts/qcom/sm6350.dtsi
2347 +index d06aefdf3d9ed..76608c1d7f0c4 100644
2348 +--- a/arch/arm64/boot/dts/qcom/sm6350.dtsi
2349 ++++ b/arch/arm64/boot/dts/qcom/sm6350.dtsi
2350 +@@ -482,6 +482,7 @@
2351 + interrupts = <GIC_SPI 641 IRQ_TYPE_LEVEL_HIGH>,
2352 + <GIC_SPI 644 IRQ_TYPE_LEVEL_HIGH>;
2353 + interrupt-names = "hc_irq", "pwr_irq";
2354 ++ iommus = <&apps_smmu 0x60 0x0>;
2355 +
2356 + clocks = <&gcc GCC_SDCC1_AHB_CLK>,
2357 + <&gcc GCC_SDCC1_APPS_CLK>,
2358 +@@ -928,6 +929,7 @@
2359 + interrupts = <GIC_SPI 204 IRQ_TYPE_LEVEL_HIGH>,
2360 + <GIC_SPI 222 IRQ_TYPE_LEVEL_HIGH>;
2361 + interrupt-names = "hc_irq", "pwr_irq";
2362 ++ iommus = <&apps_smmu 0x560 0x0>;
2363 +
2364 + clocks = <&gcc GCC_SDCC2_AHB_CLK>,
2365 + <&gcc GCC_SDCC2_APPS_CLK>,
2366 +@@ -1005,15 +1007,11 @@
2367 + dp_phy: dp-phy@88ea200 {
2368 + reg = <0 0x088ea200 0 0x200>,
2369 + <0 0x088ea400 0 0x200>,
2370 +- <0 0x088eac00 0 0x400>,
2371 ++ <0 0x088eaa00 0 0x200>,
2372 + <0 0x088ea600 0 0x200>,
2373 +- <0 0x088ea800 0 0x200>,
2374 +- <0 0x088eaa00 0 0x100>;
2375 ++ <0 0x088ea800 0 0x200>;
2376 + #phy-cells = <0>;
2377 + #clock-cells = <1>;
2378 +- clocks = <&gcc GCC_USB3_PRIM_PHY_PIPE_CLK>;
2379 +- clock-names = "pipe0";
2380 +- clock-output-names = "usb3_phy_pipe_clk_src";
2381 + };
2382 + };
2383 +
2384 +diff --git a/arch/arm64/boot/dts/qcom/sm8150.dtsi b/arch/arm64/boot/dts/qcom/sm8150.dtsi
2385 +index 916f12b799b79..3df80dde92496 100644
2386 +--- a/arch/arm64/boot/dts/qcom/sm8150.dtsi
2387 ++++ b/arch/arm64/boot/dts/qcom/sm8150.dtsi
2388 +@@ -2038,11 +2038,11 @@
2389 + status = "disabled";
2390 +
2391 + ufs_mem_phy_lanes: phy@1d87400 {
2392 +- reg = <0 0x01d87400 0 0x108>,
2393 +- <0 0x01d87600 0 0x1e0>,
2394 +- <0 0x01d87c00 0 0x1dc>,
2395 +- <0 0x01d87800 0 0x108>,
2396 +- <0 0x01d87a00 0 0x1e0>;
2397 ++ reg = <0 0x01d87400 0 0x16c>,
2398 ++ <0 0x01d87600 0 0x200>,
2399 ++ <0 0x01d87c00 0 0x200>,
2400 ++ <0 0x01d87800 0 0x16c>,
2401 ++ <0 0x01d87a00 0 0x200>;
2402 + #phy-cells = <0>;
2403 + };
2404 + };
2405 +diff --git a/arch/arm64/boot/dts/qcom/sm8250-mtp.dts b/arch/arm64/boot/dts/qcom/sm8250-mtp.dts
2406 +index 7ab3627cc347d..a05fe468e0b41 100644
2407 +--- a/arch/arm64/boot/dts/qcom/sm8250-mtp.dts
2408 ++++ b/arch/arm64/boot/dts/qcom/sm8250-mtp.dts
2409 +@@ -635,7 +635,7 @@
2410 + wcd938x: codec {
2411 + compatible = "qcom,wcd9380-codec";
2412 + #sound-dai-cells = <1>;
2413 +- reset-gpios = <&tlmm 32 0>;
2414 ++ reset-gpios = <&tlmm 32 GPIO_ACTIVE_LOW>;
2415 + vdd-buck-supply = <&vreg_s4a_1p8>;
2416 + vdd-rxtx-supply = <&vreg_s4a_1p8>;
2417 + vdd-io-supply = <&vreg_s4a_1p8>;
2418 +diff --git a/arch/arm64/boot/dts/qcom/sm8250-sony-xperia-edo.dtsi b/arch/arm64/boot/dts/qcom/sm8250-sony-xperia-edo.dtsi
2419 +index 5428aab3058dd..e4769dcfaad7b 100644
2420 +--- a/arch/arm64/boot/dts/qcom/sm8250-sony-xperia-edo.dtsi
2421 ++++ b/arch/arm64/boot/dts/qcom/sm8250-sony-xperia-edo.dtsi
2422 +@@ -619,7 +619,7 @@
2423 + pins = "gpio39";
2424 + function = "gpio";
2425 + drive-strength = <2>;
2426 +- bias-disabled;
2427 ++ bias-disable;
2428 + input-enable;
2429 + };
2430 +
2431 +diff --git a/arch/arm64/boot/dts/qcom/sm8250.dtsi b/arch/arm64/boot/dts/qcom/sm8250.dtsi
2432 +index 052b4dbc1ee44..652fb0231da0e 100644
2433 +--- a/arch/arm64/boot/dts/qcom/sm8250.dtsi
2434 ++++ b/arch/arm64/boot/dts/qcom/sm8250.dtsi
2435 +@@ -2172,11 +2172,11 @@
2436 + status = "disabled";
2437 +
2438 + ufs_mem_phy_lanes: phy@1d87400 {
2439 +- reg = <0 0x01d87400 0 0x108>,
2440 +- <0 0x01d87600 0 0x1e0>,
2441 +- <0 0x01d87c00 0 0x1dc>,
2442 +- <0 0x01d87800 0 0x108>,
2443 +- <0 0x01d87a00 0 0x1e0>;
2444 ++ reg = <0 0x01d87400 0 0x16c>,
2445 ++ <0 0x01d87600 0 0x200>,
2446 ++ <0 0x01d87c00 0 0x200>,
2447 ++ <0 0x01d87800 0 0x16c>,
2448 ++ <0 0x01d87a00 0 0x200>;
2449 + #phy-cells = <0>;
2450 + };
2451 + };
2452 +@@ -2447,7 +2447,7 @@
2453 + pins = "gpio7";
2454 + function = "dmic1_data";
2455 + drive-strength = <2>;
2456 +- pull-down;
2457 ++ bias-pull-down;
2458 + input-enable;
2459 + };
2460 + };
2461 +@@ -2884,15 +2884,11 @@
2462 + dp_phy: dp-phy@88ea200 {
2463 + reg = <0 0x088ea200 0 0x200>,
2464 + <0 0x088ea400 0 0x200>,
2465 +- <0 0x088eac00 0 0x400>,
2466 ++ <0 0x088eaa00 0 0x200>,
2467 + <0 0x088ea600 0 0x200>,
2468 +- <0 0x088ea800 0 0x200>,
2469 +- <0 0x088eaa00 0 0x100>;
2470 ++ <0 0x088ea800 0 0x200>;
2471 + #phy-cells = <0>;
2472 + #clock-cells = <1>;
2473 +- clocks = <&gcc GCC_USB3_PRIM_PHY_PIPE_CLK>;
2474 +- clock-names = "pipe0";
2475 +- clock-output-names = "usb3_phy_pipe_clk_src";
2476 + };
2477 + };
2478 +
2479 +diff --git a/arch/arm64/boot/dts/qcom/sm8350.dtsi b/arch/arm64/boot/dts/qcom/sm8350.dtsi
2480 +index d9b08dfc2980d..eace5b2ee3812 100644
2481 +--- a/arch/arm64/boot/dts/qcom/sm8350.dtsi
2482 ++++ b/arch/arm64/boot/dts/qcom/sm8350.dtsi
2483 +@@ -2142,11 +2142,11 @@
2484 + status = "disabled";
2485 +
2486 + ufs_mem_phy_lanes: phy@1d87400 {
2487 +- reg = <0 0x01d87400 0 0x108>,
2488 +- <0 0x01d87600 0 0x1e0>,
2489 +- <0 0x01d87c00 0 0x1dc>,
2490 +- <0 0x01d87800 0 0x108>,
2491 +- <0 0x01d87a00 0 0x1e0>;
2492 ++ reg = <0 0x01d87400 0 0x188>,
2493 ++ <0 0x01d87600 0 0x200>,
2494 ++ <0 0x01d87c00 0 0x200>,
2495 ++ <0 0x01d87800 0 0x188>,
2496 ++ <0 0x01d87a00 0 0x200>;
2497 + #phy-cells = <0>;
2498 + };
2499 + };
2500 +diff --git a/arch/arm64/boot/dts/qcom/sm8450.dtsi b/arch/arm64/boot/dts/qcom/sm8450.dtsi
2501 +index 8a6c0f3e7bb70..ed3e1eff4f58f 100644
2502 +--- a/arch/arm64/boot/dts/qcom/sm8450.dtsi
2503 ++++ b/arch/arm64/boot/dts/qcom/sm8450.dtsi
2504 +@@ -3131,11 +3131,11 @@
2505 + status = "disabled";
2506 +
2507 + ufs_mem_phy_lanes: phy@1d87400 {
2508 +- reg = <0 0x01d87400 0 0x108>,
2509 +- <0 0x01d87600 0 0x1e0>,
2510 +- <0 0x01d87c00 0 0x1dc>,
2511 +- <0 0x01d87800 0 0x108>,
2512 +- <0 0x01d87a00 0 0x1e0>;
2513 ++ reg = <0 0x01d87400 0 0x188>,
2514 ++ <0 0x01d87600 0 0x200>,
2515 ++ <0 0x01d87c00 0 0x200>,
2516 ++ <0 0x01d87800 0 0x188>,
2517 ++ <0 0x01d87a00 0 0x200>;
2518 + #phy-cells = <0>;
2519 + };
2520 + };
2521 +diff --git a/arch/arm64/boot/dts/renesas/r8a779f0.dtsi b/arch/arm64/boot/dts/renesas/r8a779f0.dtsi
2522 +index 384817ffa4deb..d4f3ebfe841ab 100644
2523 +--- a/arch/arm64/boot/dts/renesas/r8a779f0.dtsi
2524 ++++ b/arch/arm64/boot/dts/renesas/r8a779f0.dtsi
2525 +@@ -442,7 +442,7 @@
2526 + reg = <0 0xe6540000 0 0x60>;
2527 + interrupts = <GIC_SPI 245 IRQ_TYPE_LEVEL_HIGH>;
2528 + clocks = <&cpg CPG_MOD 514>,
2529 +- <&cpg CPG_CORE R8A779F0_CLK_S0D3>,
2530 ++ <&cpg CPG_CORE R8A779F0_CLK_SASYNCPERD1>,
2531 + <&scif_clk>;
2532 + clock-names = "fck", "brg_int", "scif_clk";
2533 + dmas = <&dmac0 0x31>, <&dmac0 0x30>,
2534 +@@ -459,7 +459,7 @@
2535 + reg = <0 0xe6550000 0 0x60>;
2536 + interrupts = <GIC_SPI 246 IRQ_TYPE_LEVEL_HIGH>;
2537 + clocks = <&cpg CPG_MOD 515>,
2538 +- <&cpg CPG_CORE R8A779F0_CLK_S0D3>,
2539 ++ <&cpg CPG_CORE R8A779F0_CLK_SASYNCPERD1>,
2540 + <&scif_clk>;
2541 + clock-names = "fck", "brg_int", "scif_clk";
2542 + dmas = <&dmac0 0x33>, <&dmac0 0x32>,
2543 +@@ -476,7 +476,7 @@
2544 + reg = <0 0xe6560000 0 0x60>;
2545 + interrupts = <GIC_SPI 247 IRQ_TYPE_LEVEL_HIGH>;
2546 + clocks = <&cpg CPG_MOD 516>,
2547 +- <&cpg CPG_CORE R8A779F0_CLK_S0D3>,
2548 ++ <&cpg CPG_CORE R8A779F0_CLK_SASYNCPERD1>,
2549 + <&scif_clk>;
2550 + clock-names = "fck", "brg_int", "scif_clk";
2551 + dmas = <&dmac0 0x35>, <&dmac0 0x34>,
2552 +@@ -493,7 +493,7 @@
2553 + reg = <0 0xe66a0000 0 0x60>;
2554 + interrupts = <GIC_SPI 248 IRQ_TYPE_LEVEL_HIGH>;
2555 + clocks = <&cpg CPG_MOD 517>,
2556 +- <&cpg CPG_CORE R8A779F0_CLK_S0D3>,
2557 ++ <&cpg CPG_CORE R8A779F0_CLK_SASYNCPERD1>,
2558 + <&scif_clk>;
2559 + clock-names = "fck", "brg_int", "scif_clk";
2560 + dmas = <&dmac0 0x37>, <&dmac0 0x36>,
2561 +@@ -522,7 +522,7 @@
2562 + reg = <0 0xe6e60000 0 64>;
2563 + interrupts = <GIC_SPI 249 IRQ_TYPE_LEVEL_HIGH>;
2564 + clocks = <&cpg CPG_MOD 702>,
2565 +- <&cpg CPG_CORE R8A779F0_CLK_S0D3_PER>,
2566 ++ <&cpg CPG_CORE R8A779F0_CLK_SASYNCPERD1>,
2567 + <&scif_clk>;
2568 + clock-names = "fck", "brg_int", "scif_clk";
2569 + dmas = <&dmac0 0x51>, <&dmac0 0x50>,
2570 +@@ -539,7 +539,7 @@
2571 + reg = <0 0xe6e68000 0 64>;
2572 + interrupts = <GIC_SPI 250 IRQ_TYPE_LEVEL_HIGH>;
2573 + clocks = <&cpg CPG_MOD 703>,
2574 +- <&cpg CPG_CORE R8A779F0_CLK_S0D3_PER>,
2575 ++ <&cpg CPG_CORE R8A779F0_CLK_SASYNCPERD1>,
2576 + <&scif_clk>;
2577 + clock-names = "fck", "brg_int", "scif_clk";
2578 + dmas = <&dmac0 0x53>, <&dmac0 0x52>,
2579 +@@ -556,7 +556,7 @@
2580 + reg = <0 0xe6c50000 0 64>;
2581 + interrupts = <GIC_SPI 252 IRQ_TYPE_LEVEL_HIGH>;
2582 + clocks = <&cpg CPG_MOD 704>,
2583 +- <&cpg CPG_CORE R8A779F0_CLK_S0D3_PER>,
2584 ++ <&cpg CPG_CORE R8A779F0_CLK_SASYNCPERD1>,
2585 + <&scif_clk>;
2586 + clock-names = "fck", "brg_int", "scif_clk";
2587 + dmas = <&dmac0 0x57>, <&dmac0 0x56>,
2588 +@@ -573,7 +573,7 @@
2589 + reg = <0 0xe6c40000 0 64>;
2590 + interrupts = <GIC_SPI 253 IRQ_TYPE_LEVEL_HIGH>;
2591 + clocks = <&cpg CPG_MOD 705>,
2592 +- <&cpg CPG_CORE R8A779F0_CLK_S0D3_PER>,
2593 ++ <&cpg CPG_CORE R8A779F0_CLK_SASYNCPERD1>,
2594 + <&scif_clk>;
2595 + clock-names = "fck", "brg_int", "scif_clk";
2596 + dmas = <&dmac0 0x59>, <&dmac0 0x58>,
2597 +diff --git a/arch/arm64/boot/dts/renesas/r8a779g0.dtsi b/arch/arm64/boot/dts/renesas/r8a779g0.dtsi
2598 +index 1c15726cff8bf..4bd3cb107b38b 100644
2599 +--- a/arch/arm64/boot/dts/renesas/r8a779g0.dtsi
2600 ++++ b/arch/arm64/boot/dts/renesas/r8a779g0.dtsi
2601 +@@ -87,7 +87,7 @@
2602 + reg = <0 0xe6540000 0 96>;
2603 + interrupts = <GIC_SPI 246 IRQ_TYPE_LEVEL_HIGH>;
2604 + clocks = <&cpg CPG_MOD 514>,
2605 +- <&cpg CPG_CORE R8A779G0_CLK_S0D3_PER>,
2606 ++ <&cpg CPG_CORE R8A779G0_CLK_SASYNCPERD1>,
2607 + <&scif_clk>;
2608 + clock-names = "fck", "brg_int", "scif_clk";
2609 + power-domains = <&sysc R8A779G0_PD_ALWAYS_ON>;
2610 +diff --git a/arch/arm64/boot/dts/renesas/r9a09g011.dtsi b/arch/arm64/boot/dts/renesas/r9a09g011.dtsi
2611 +index d4cc5459fbb76..4ce0f39446492 100644
2612 +--- a/arch/arm64/boot/dts/renesas/r9a09g011.dtsi
2613 ++++ b/arch/arm64/boot/dts/renesas/r9a09g011.dtsi
2614 +@@ -48,7 +48,7 @@
2615 + #size-cells = <2>;
2616 + ranges;
2617 +
2618 +- gic: interrupt-controller@82000000 {
2619 ++ gic: interrupt-controller@82010000 {
2620 + compatible = "arm,gic-400";
2621 + #interrupt-cells = <3>;
2622 + #address-cells = <0>;
2623 +diff --git a/arch/arm64/boot/dts/tesla/fsd-pinctrl.dtsi b/arch/arm64/boot/dts/tesla/fsd-pinctrl.dtsi
2624 +index d0abb9aa0e9ed..e3852c9463528 100644
2625 +--- a/arch/arm64/boot/dts/tesla/fsd-pinctrl.dtsi
2626 ++++ b/arch/arm64/boot/dts/tesla/fsd-pinctrl.dtsi
2627 +@@ -55,14 +55,14 @@
2628 + samsung,pins = "gpf5-0";
2629 + samsung,pin-function = <FSD_PIN_FUNC_2>;
2630 + samsung,pin-pud = <FSD_PIN_PULL_NONE>;
2631 +- samsung,pin-drv = <FSD_PIN_DRV_LV2>;
2632 ++ samsung,pin-drv = <FSD_PIN_DRV_LV4>;
2633 + };
2634 +
2635 + ufs_refclk_out: ufs-refclk-out-pins {
2636 + samsung,pins = "gpf5-1";
2637 + samsung,pin-function = <FSD_PIN_FUNC_2>;
2638 + samsung,pin-pud = <FSD_PIN_PULL_NONE>;
2639 +- samsung,pin-drv = <FSD_PIN_DRV_LV2>;
2640 ++ samsung,pin-drv = <FSD_PIN_DRV_LV4>;
2641 + };
2642 + };
2643 +
2644 +@@ -239,105 +239,105 @@
2645 + samsung,pins = "gpb6-1";
2646 + samsung,pin-function = <FSD_PIN_FUNC_2>;
2647 + samsung,pin-pud = <FSD_PIN_PULL_UP>;
2648 +- samsung,pin-drv = <FSD_PIN_DRV_LV2>;
2649 ++ samsung,pin-drv = <FSD_PIN_DRV_LV4>;
2650 + };
2651 +
2652 + pwm1_out: pwm1-out-pins {
2653 + samsung,pins = "gpb6-5";
2654 + samsung,pin-function = <FSD_PIN_FUNC_2>;
2655 + samsung,pin-pud = <FSD_PIN_PULL_UP>;
2656 +- samsung,pin-drv = <FSD_PIN_DRV_LV2>;
2657 ++ samsung,pin-drv = <FSD_PIN_DRV_LV4>;
2658 + };
2659 +
2660 + hs_i2c0_bus: hs-i2c0-bus-pins {
2661 + samsung,pins = "gpb0-0", "gpb0-1";
2662 + samsung,pin-function = <FSD_PIN_FUNC_2>;
2663 + samsung,pin-pud = <FSD_PIN_PULL_UP>;
2664 +- samsung,pin-drv = <FSD_PIN_DRV_LV1>;
2665 ++ samsung,pin-drv = <FSD_PIN_DRV_LV4>;
2666 + };
2667 +
2668 + hs_i2c1_bus: hs-i2c1-bus-pins {
2669 + samsung,pins = "gpb0-2", "gpb0-3";
2670 + samsung,pin-function = <FSD_PIN_FUNC_2>;
2671 + samsung,pin-pud = <FSD_PIN_PULL_UP>;
2672 +- samsung,pin-drv = <FSD_PIN_DRV_LV1>;
2673 ++ samsung,pin-drv = <FSD_PIN_DRV_LV4>;
2674 + };
2675 +
2676 + hs_i2c2_bus: hs-i2c2-bus-pins {
2677 + samsung,pins = "gpb0-4", "gpb0-5";
2678 + samsung,pin-function = <FSD_PIN_FUNC_2>;
2679 + samsung,pin-pud = <FSD_PIN_PULL_UP>;
2680 +- samsung,pin-drv = <FSD_PIN_DRV_LV1>;
2681 ++ samsung,pin-drv = <FSD_PIN_DRV_LV4>;
2682 + };
2683 +
2684 + hs_i2c3_bus: hs-i2c3-bus-pins {
2685 + samsung,pins = "gpb0-6", "gpb0-7";
2686 + samsung,pin-function = <FSD_PIN_FUNC_2>;
2687 + samsung,pin-pud = <FSD_PIN_PULL_UP>;
2688 +- samsung,pin-drv = <FSD_PIN_DRV_LV1>;
2689 ++ samsung,pin-drv = <FSD_PIN_DRV_LV4>;
2690 + };
2691 +
2692 + hs_i2c4_bus: hs-i2c4-bus-pins {
2693 + samsung,pins = "gpb1-0", "gpb1-1";
2694 + samsung,pin-function = <FSD_PIN_FUNC_2>;
2695 + samsung,pin-pud = <FSD_PIN_PULL_UP>;
2696 +- samsung,pin-drv = <FSD_PIN_DRV_LV1>;
2697 ++ samsung,pin-drv = <FSD_PIN_DRV_LV4>;
2698 + };
2699 +
2700 + hs_i2c5_bus: hs-i2c5-bus-pins {
2701 + samsung,pins = "gpb1-2", "gpb1-3";
2702 + samsung,pin-function = <FSD_PIN_FUNC_2>;
2703 + samsung,pin-pud = <FSD_PIN_PULL_UP>;
2704 +- samsung,pin-drv = <FSD_PIN_DRV_LV1>;
2705 ++ samsung,pin-drv = <FSD_PIN_DRV_LV4>;
2706 + };
2707 +
2708 + hs_i2c6_bus: hs-i2c6-bus-pins {
2709 + samsung,pins = "gpb1-4", "gpb1-5";
2710 + samsung,pin-function = <FSD_PIN_FUNC_2>;
2711 + samsung,pin-pud = <FSD_PIN_PULL_UP>;
2712 +- samsung,pin-drv = <FSD_PIN_DRV_LV1>;
2713 ++ samsung,pin-drv = <FSD_PIN_DRV_LV4>;
2714 + };
2715 +
2716 + hs_i2c7_bus: hs-i2c7-bus-pins {
2717 + samsung,pins = "gpb1-6", "gpb1-7";
2718 + samsung,pin-function = <FSD_PIN_FUNC_2>;
2719 + samsung,pin-pud = <FSD_PIN_PULL_UP>;
2720 +- samsung,pin-drv = <FSD_PIN_DRV_LV1>;
2721 ++ samsung,pin-drv = <FSD_PIN_DRV_LV4>;
2722 + };
2723 +
2724 + uart0_data: uart0-data-pins {
2725 + samsung,pins = "gpb7-0", "gpb7-1";
2726 + samsung,pin-function = <FSD_PIN_FUNC_2>;
2727 + samsung,pin-pud = <FSD_PIN_PULL_NONE>;
2728 +- samsung,pin-drv = <FSD_PIN_DRV_LV1>;
2729 ++ samsung,pin-drv = <FSD_PIN_DRV_LV4>;
2730 + };
2731 +
2732 + uart1_data: uart1-data-pins {
2733 + samsung,pins = "gpb7-4", "gpb7-5";
2734 + samsung,pin-function = <FSD_PIN_FUNC_2>;
2735 + samsung,pin-pud = <FSD_PIN_PULL_NONE>;
2736 +- samsung,pin-drv = <FSD_PIN_DRV_LV1>;
2737 ++ samsung,pin-drv = <FSD_PIN_DRV_LV4>;
2738 + };
2739 +
2740 + spi0_bus: spi0-bus-pins {
2741 + samsung,pins = "gpb4-0", "gpb4-2", "gpb4-3";
2742 + samsung,pin-function = <FSD_PIN_FUNC_2>;
2743 + samsung,pin-pud = <FSD_PIN_PULL_UP>;
2744 +- samsung,pin-drv = <FSD_PIN_DRV_LV1>;
2745 ++ samsung,pin-drv = <FSD_PIN_DRV_LV4>;
2746 + };
2747 +
2748 + spi1_bus: spi1-bus-pins {
2749 + samsung,pins = "gpb4-4", "gpb4-6", "gpb4-7";
2750 + samsung,pin-function = <FSD_PIN_FUNC_2>;
2751 + samsung,pin-pud = <FSD_PIN_PULL_UP>;
2752 +- samsung,pin-drv = <FSD_PIN_DRV_LV1>;
2753 ++ samsung,pin-drv = <FSD_PIN_DRV_LV4>;
2754 + };
2755 +
2756 + spi2_bus: spi2-bus-pins {
2757 + samsung,pins = "gpb5-0", "gpb5-2", "gpb5-3";
2758 + samsung,pin-function = <FSD_PIN_FUNC_2>;
2759 + samsung,pin-pud = <FSD_PIN_PULL_UP>;
2760 +- samsung,pin-drv = <FSD_PIN_DRV_LV1>;
2761 ++ samsung,pin-drv = <FSD_PIN_DRV_LV4>;
2762 + };
2763 + };
2764 +
2765 +diff --git a/arch/arm64/boot/dts/tesla/fsd-pinctrl.h b/arch/arm64/boot/dts/tesla/fsd-pinctrl.h
2766 +index 6ffbda3624930..c397d02208a08 100644
2767 +--- a/arch/arm64/boot/dts/tesla/fsd-pinctrl.h
2768 ++++ b/arch/arm64/boot/dts/tesla/fsd-pinctrl.h
2769 +@@ -16,9 +16,9 @@
2770 + #define FSD_PIN_PULL_UP 3
2771 +
2772 + #define FSD_PIN_DRV_LV1 0
2773 +-#define FSD_PIN_DRV_LV2 2
2774 +-#define FSD_PIN_DRV_LV3 1
2775 +-#define FSD_PIN_DRV_LV4 3
2776 ++#define FSD_PIN_DRV_LV2 1
2777 ++#define FSD_PIN_DRV_LV4 2
2778 ++#define FSD_PIN_DRV_LV6 3
2779 +
2780 + #define FSD_PIN_FUNC_INPUT 0
2781 + #define FSD_PIN_FUNC_OUTPUT 1
2782 +diff --git a/arch/arm64/boot/dts/ti/k3-am65-main.dtsi b/arch/arm64/boot/dts/ti/k3-am65-main.dtsi
2783 +index 8919fede3cd76..ef960386c62cb 100644
2784 +--- a/arch/arm64/boot/dts/ti/k3-am65-main.dtsi
2785 ++++ b/arch/arm64/boot/dts/ti/k3-am65-main.dtsi
2786 +@@ -120,7 +120,6 @@
2787 + dmas = <&main_udmap 0xc000>, <&main_udmap 0x4000>,
2788 + <&main_udmap 0x4001>;
2789 + dma-names = "tx", "rx1", "rx2";
2790 +- dma-coherent;
2791 +
2792 + rng: rng@4e10000 {
2793 + compatible = "inside-secure,safexcel-eip76";
2794 +diff --git a/arch/arm64/boot/dts/ti/k3-j721e-main.dtsi b/arch/arm64/boot/dts/ti/k3-j721e-main.dtsi
2795 +index 43b6cf5791eee..75789c0f82bd3 100644
2796 +--- a/arch/arm64/boot/dts/ti/k3-j721e-main.dtsi
2797 ++++ b/arch/arm64/boot/dts/ti/k3-j721e-main.dtsi
2798 +@@ -337,7 +337,6 @@
2799 + dmas = <&main_udmap 0xc000>, <&main_udmap 0x4000>,
2800 + <&main_udmap 0x4001>;
2801 + dma-names = "tx", "rx1", "rx2";
2802 +- dma-coherent;
2803 +
2804 + rng: rng@4e10000 {
2805 + compatible = "inside-secure,safexcel-eip76";
2806 +diff --git a/arch/arm64/boot/dts/ti/k3-j721s2-main.dtsi b/arch/arm64/boot/dts/ti/k3-j721s2-main.dtsi
2807 +index 34e7d577ae13b..c89f28235812a 100644
2808 +--- a/arch/arm64/boot/dts/ti/k3-j721s2-main.dtsi
2809 ++++ b/arch/arm64/boot/dts/ti/k3-j721s2-main.dtsi
2810 +@@ -60,7 +60,7 @@
2811 + #interrupt-cells = <1>;
2812 + ti,sci = <&sms>;
2813 + ti,sci-dev-id = <148>;
2814 +- ti,interrupt-ranges = <8 360 56>;
2815 ++ ti,interrupt-ranges = <8 392 56>;
2816 + };
2817 +
2818 + main_pmx0: pinctrl@11c000 {
2819 +diff --git a/arch/arm64/boot/dts/ti/k3-j721s2-mcu-wakeup.dtsi b/arch/arm64/boot/dts/ti/k3-j721s2-mcu-wakeup.dtsi
2820 +index 4d1bfabd1313a..f0644851602cd 100644
2821 +--- a/arch/arm64/boot/dts/ti/k3-j721s2-mcu-wakeup.dtsi
2822 ++++ b/arch/arm64/boot/dts/ti/k3-j721s2-mcu-wakeup.dtsi
2823 +@@ -65,7 +65,7 @@
2824 + #interrupt-cells = <1>;
2825 + ti,sci = <&sms>;
2826 + ti,sci-dev-id = <125>;
2827 +- ti,interrupt-ranges = <16 928 16>;
2828 ++ ti,interrupt-ranges = <16 960 16>;
2829 + };
2830 +
2831 + mcu_conf: syscon@40f00000 {
2832 +diff --git a/arch/arm64/include/asm/processor.h b/arch/arm64/include/asm/processor.h
2833 +index 86eb0bfe3b380..d9144b6e078c8 100644
2834 +--- a/arch/arm64/include/asm/processor.h
2835 ++++ b/arch/arm64/include/asm/processor.h
2836 +@@ -308,13 +308,13 @@ static inline void compat_start_thread(struct pt_regs *regs, unsigned long pc,
2837 + }
2838 + #endif
2839 +
2840 +-static inline bool is_ttbr0_addr(unsigned long addr)
2841 ++static __always_inline bool is_ttbr0_addr(unsigned long addr)
2842 + {
2843 + /* entry assembly clears tags for TTBR0 addrs */
2844 + return addr < TASK_SIZE;
2845 + }
2846 +
2847 +-static inline bool is_ttbr1_addr(unsigned long addr)
2848 ++static __always_inline bool is_ttbr1_addr(unsigned long addr)
2849 + {
2850 + /* TTBR1 addresses may have a tag if KASAN_SW_TAGS is in use */
2851 + return arch_kasan_reset_tag(addr) >= PAGE_OFFSET;
2852 +diff --git a/arch/arm64/mm/fault.c b/arch/arm64/mm/fault.c
2853 +index c33f1fad27450..89628bd370d91 100644
2854 +--- a/arch/arm64/mm/fault.c
2855 ++++ b/arch/arm64/mm/fault.c
2856 +@@ -353,6 +353,11 @@ static bool is_el1_mte_sync_tag_check_fault(unsigned long esr)
2857 + return false;
2858 + }
2859 +
2860 ++static bool is_translation_fault(unsigned long esr)
2861 ++{
2862 ++ return (esr & ESR_ELx_FSC_TYPE) == ESR_ELx_FSC_FAULT;
2863 ++}
2864 ++
2865 + static void __do_kernel_fault(unsigned long addr, unsigned long esr,
2866 + struct pt_regs *regs)
2867 + {
2868 +@@ -385,7 +390,8 @@ static void __do_kernel_fault(unsigned long addr, unsigned long esr,
2869 + } else if (addr < PAGE_SIZE) {
2870 + msg = "NULL pointer dereference";
2871 + } else {
2872 +- if (kfence_handle_page_fault(addr, esr & ESR_ELx_WNR, regs))
2873 ++ if (is_translation_fault(esr) &&
2874 ++ kfence_handle_page_fault(addr, esr & ESR_ELx_WNR, regs))
2875 + return;
2876 +
2877 + msg = "paging request";
2878 +diff --git a/arch/mips/bcm63xx/clk.c b/arch/mips/bcm63xx/clk.c
2879 +index 6e6756e8fa0a9..86a6e25908664 100644
2880 +--- a/arch/mips/bcm63xx/clk.c
2881 ++++ b/arch/mips/bcm63xx/clk.c
2882 +@@ -361,6 +361,8 @@ static struct clk clk_periph = {
2883 + */
2884 + int clk_enable(struct clk *clk)
2885 + {
2886 ++ if (!clk)
2887 ++ return 0;
2888 + mutex_lock(&clocks_mutex);
2889 + clk_enable_unlocked(clk);
2890 + mutex_unlock(&clocks_mutex);
2891 +diff --git a/arch/mips/cavium-octeon/executive/cvmx-helper-board.c b/arch/mips/cavium-octeon/executive/cvmx-helper-board.c
2892 +index d09d0769f5496..0fd9ac76eb742 100644
2893 +--- a/arch/mips/cavium-octeon/executive/cvmx-helper-board.c
2894 ++++ b/arch/mips/cavium-octeon/executive/cvmx-helper-board.c
2895 +@@ -211,7 +211,7 @@ union cvmx_helper_link_info __cvmx_helper_board_link_get(int ipd_port)
2896 + {
2897 + union cvmx_helper_link_info result;
2898 +
2899 +- WARN(!octeon_is_simulation(),
2900 ++ WARN_ONCE(!octeon_is_simulation(),
2901 + "Using deprecated link status - please update your DT");
2902 +
2903 + /* Unless we fix it later, all links are defaulted to down */
2904 +diff --git a/arch/mips/cavium-octeon/executive/cvmx-helper.c b/arch/mips/cavium-octeon/executive/cvmx-helper.c
2905 +index 6f49fd9be1f3c..9abfc4bf9bd83 100644
2906 +--- a/arch/mips/cavium-octeon/executive/cvmx-helper.c
2907 ++++ b/arch/mips/cavium-octeon/executive/cvmx-helper.c
2908 +@@ -1096,7 +1096,7 @@ union cvmx_helper_link_info cvmx_helper_link_get(int ipd_port)
2909 + if (index == 0)
2910 + result = __cvmx_helper_rgmii_link_get(ipd_port);
2911 + else {
2912 +- WARN(1, "Using deprecated link status - please update your DT");
2913 ++ WARN_ONCE(1, "Using deprecated link status - please update your DT");
2914 + result.s.full_duplex = 1;
2915 + result.s.link_up = 1;
2916 + result.s.speed = 1000;
2917 +diff --git a/arch/mips/include/asm/mach-ralink/mt7621.h b/arch/mips/include/asm/mach-ralink/mt7621.h
2918 +index 6bbf082dd149e..79d5bb0e06d63 100644
2919 +--- a/arch/mips/include/asm/mach-ralink/mt7621.h
2920 ++++ b/arch/mips/include/asm/mach-ralink/mt7621.h
2921 +@@ -7,10 +7,12 @@
2922 + #ifndef _MT7621_REGS_H_
2923 + #define _MT7621_REGS_H_
2924 +
2925 ++#define IOMEM(x) ((void __iomem *)(KSEG1ADDR(x)))
2926 ++
2927 + #define MT7621_PALMBUS_BASE 0x1C000000
2928 + #define MT7621_PALMBUS_SIZE 0x03FFFFFF
2929 +
2930 +-#define MT7621_SYSC_BASE 0x1E000000
2931 ++#define MT7621_SYSC_BASE IOMEM(0x1E000000)
2932 +
2933 + #define SYSC_REG_CHIP_NAME0 0x00
2934 + #define SYSC_REG_CHIP_NAME1 0x04
2935 +diff --git a/arch/mips/kernel/vpe-cmp.c b/arch/mips/kernel/vpe-cmp.c
2936 +index e673603e11e5d..92140edb3ce3e 100644
2937 +--- a/arch/mips/kernel/vpe-cmp.c
2938 ++++ b/arch/mips/kernel/vpe-cmp.c
2939 +@@ -75,7 +75,6 @@ ATTRIBUTE_GROUPS(vpe);
2940 +
2941 + static void vpe_device_release(struct device *cd)
2942 + {
2943 +- kfree(cd);
2944 + }
2945 +
2946 + static struct class vpe_class = {
2947 +@@ -157,6 +156,7 @@ out_dev:
2948 + device_del(&vpe_device);
2949 +
2950 + out_class:
2951 ++ put_device(&vpe_device);
2952 + class_unregister(&vpe_class);
2953 +
2954 + out_chrdev:
2955 +@@ -169,7 +169,7 @@ void __exit vpe_module_exit(void)
2956 + {
2957 + struct vpe *v, *n;
2958 +
2959 +- device_del(&vpe_device);
2960 ++ device_unregister(&vpe_device);
2961 + class_unregister(&vpe_class);
2962 + unregister_chrdev(major, VPE_MODULE_NAME);
2963 +
2964 +diff --git a/arch/mips/kernel/vpe-mt.c b/arch/mips/kernel/vpe-mt.c
2965 +index bad6b0891b2b5..84a82b551ec35 100644
2966 +--- a/arch/mips/kernel/vpe-mt.c
2967 ++++ b/arch/mips/kernel/vpe-mt.c
2968 +@@ -313,7 +313,6 @@ ATTRIBUTE_GROUPS(vpe);
2969 +
2970 + static void vpe_device_release(struct device *cd)
2971 + {
2972 +- kfree(cd);
2973 + }
2974 +
2975 + static struct class vpe_class = {
2976 +@@ -497,6 +496,7 @@ out_dev:
2977 + device_del(&vpe_device);
2978 +
2979 + out_class:
2980 ++ put_device(&vpe_device);
2981 + class_unregister(&vpe_class);
2982 +
2983 + out_chrdev:
2984 +@@ -509,7 +509,7 @@ void __exit vpe_module_exit(void)
2985 + {
2986 + struct vpe *v, *n;
2987 +
2988 +- device_del(&vpe_device);
2989 ++ device_unregister(&vpe_device);
2990 + class_unregister(&vpe_class);
2991 + unregister_chrdev(major, VPE_MODULE_NAME);
2992 +
2993 +diff --git a/arch/mips/ralink/mt7621.c b/arch/mips/ralink/mt7621.c
2994 +index fb0565bc34fda..bbf5811afbf2c 100644
2995 +--- a/arch/mips/ralink/mt7621.c
2996 ++++ b/arch/mips/ralink/mt7621.c
2997 +@@ -25,6 +25,7 @@
2998 + #define MT7621_MEM_TEST_PATTERN 0xaa5555aa
2999 +
3000 + static u32 detect_magic __initdata;
3001 ++static struct ralink_soc_info *soc_info_ptr;
3002 +
3003 + int pcibios_root_bridge_prepare(struct pci_host_bridge *bridge)
3004 + {
3005 +@@ -97,41 +98,83 @@ void __init ralink_of_remap(void)
3006 + panic("Failed to remap core resources");
3007 + }
3008 +
3009 +-static void soc_dev_init(struct ralink_soc_info *soc_info, u32 rev)
3010 ++static unsigned int __init mt7621_get_soc_name0(void)
3011 ++{
3012 ++ return __raw_readl(MT7621_SYSC_BASE + SYSC_REG_CHIP_NAME0);
3013 ++}
3014 ++
3015 ++static unsigned int __init mt7621_get_soc_name1(void)
3016 ++{
3017 ++ return __raw_readl(MT7621_SYSC_BASE + SYSC_REG_CHIP_NAME1);
3018 ++}
3019 ++
3020 ++static bool __init mt7621_soc_valid(void)
3021 ++{
3022 ++ if (mt7621_get_soc_name0() == MT7621_CHIP_NAME0 &&
3023 ++ mt7621_get_soc_name1() == MT7621_CHIP_NAME1)
3024 ++ return true;
3025 ++ else
3026 ++ return false;
3027 ++}
3028 ++
3029 ++static const char __init *mt7621_get_soc_id(void)
3030 ++{
3031 ++ if (mt7621_soc_valid())
3032 ++ return "MT7621";
3033 ++ else
3034 ++ return "invalid";
3035 ++}
3036 ++
3037 ++static unsigned int __init mt7621_get_soc_rev(void)
3038 ++{
3039 ++ return __raw_readl(MT7621_SYSC_BASE + SYSC_REG_CHIP_REV);
3040 ++}
3041 ++
3042 ++static unsigned int __init mt7621_get_soc_ver(void)
3043 ++{
3044 ++ return (mt7621_get_soc_rev() >> CHIP_REV_VER_SHIFT) & CHIP_REV_VER_MASK;
3045 ++}
3046 ++
3047 ++static unsigned int __init mt7621_get_soc_eco(void)
3048 ++{
3049 ++ return (mt7621_get_soc_rev() & CHIP_REV_ECO_MASK);
3050 ++}
3051 ++
3052 ++static const char __init *mt7621_get_soc_revision(void)
3053 ++{
3054 ++ if (mt7621_get_soc_rev() == 1 && mt7621_get_soc_eco() == 1)
3055 ++ return "E2";
3056 ++ else
3057 ++ return "E1";
3058 ++}
3059 ++
3060 ++static int __init mt7621_soc_dev_init(void)
3061 + {
3062 + struct soc_device *soc_dev;
3063 + struct soc_device_attribute *soc_dev_attr;
3064 +
3065 + soc_dev_attr = kzalloc(sizeof(*soc_dev_attr), GFP_KERNEL);
3066 + if (!soc_dev_attr)
3067 +- return;
3068 ++ return -ENOMEM;
3069 +
3070 + soc_dev_attr->soc_id = "mt7621";
3071 + soc_dev_attr->family = "Ralink";
3072 ++ soc_dev_attr->revision = mt7621_get_soc_revision();
3073 +
3074 +- if (((rev >> CHIP_REV_VER_SHIFT) & CHIP_REV_VER_MASK) == 1 &&
3075 +- (rev & CHIP_REV_ECO_MASK) == 1)
3076 +- soc_dev_attr->revision = "E2";
3077 +- else
3078 +- soc_dev_attr->revision = "E1";
3079 +-
3080 +- soc_dev_attr->data = soc_info;
3081 ++ soc_dev_attr->data = soc_info_ptr;
3082 +
3083 + soc_dev = soc_device_register(soc_dev_attr);
3084 + if (IS_ERR(soc_dev)) {
3085 + kfree(soc_dev_attr);
3086 +- return;
3087 ++ return PTR_ERR(soc_dev);
3088 + }
3089 ++
3090 ++ return 0;
3091 + }
3092 ++device_initcall(mt7621_soc_dev_init);
3093 +
3094 + void __init prom_soc_init(struct ralink_soc_info *soc_info)
3095 + {
3096 +- void __iomem *sysc = (void __iomem *) KSEG1ADDR(MT7621_SYSC_BASE);
3097 +- unsigned char *name = NULL;
3098 +- u32 n0;
3099 +- u32 n1;
3100 +- u32 rev;
3101 +-
3102 + /* Early detection of CMP support */
3103 + mips_cm_probe();
3104 + mips_cpc_probe();
3105 +@@ -154,27 +197,23 @@ void __init prom_soc_init(struct ralink_soc_info *soc_info)
3106 + __sync();
3107 + }
3108 +
3109 +- n0 = __raw_readl(sysc + SYSC_REG_CHIP_NAME0);
3110 +- n1 = __raw_readl(sysc + SYSC_REG_CHIP_NAME1);
3111 +-
3112 +- if (n0 == MT7621_CHIP_NAME0 && n1 == MT7621_CHIP_NAME1) {
3113 +- name = "MT7621";
3114 ++ if (mt7621_soc_valid())
3115 + soc_info->compatible = "mediatek,mt7621-soc";
3116 +- } else {
3117 +- panic("mt7621: unknown SoC, n0:%08x n1:%08x\n", n0, n1);
3118 +- }
3119 ++ else
3120 ++ panic("mt7621: unknown SoC, n0:%08x n1:%08x\n",
3121 ++ mt7621_get_soc_name0(),
3122 ++ mt7621_get_soc_name1());
3123 + ralink_soc = MT762X_SOC_MT7621AT;
3124 +- rev = __raw_readl(sysc + SYSC_REG_CHIP_REV);
3125 +
3126 + snprintf(soc_info->sys_type, RAMIPS_SYS_TYPE_LEN,
3127 + "MediaTek %s ver:%u eco:%u",
3128 +- name,
3129 +- (rev >> CHIP_REV_VER_SHIFT) & CHIP_REV_VER_MASK,
3130 +- (rev & CHIP_REV_ECO_MASK));
3131 ++ mt7621_get_soc_id(),
3132 ++ mt7621_get_soc_ver(),
3133 ++ mt7621_get_soc_eco());
3134 +
3135 + soc_info->mem_detect = mt7621_memory_detect;
3136 +
3137 +- soc_dev_init(soc_info, rev);
3138 ++ soc_info_ptr = soc_info;
3139 +
3140 + if (!register_cps_smp_ops())
3141 + return;
3142 +diff --git a/arch/mips/ralink/of.c b/arch/mips/ralink/of.c
3143 +index ea8072acf8d94..01c132bc33d54 100644
3144 +--- a/arch/mips/ralink/of.c
3145 ++++ b/arch/mips/ralink/of.c
3146 +@@ -21,6 +21,7 @@
3147 + #include <asm/bootinfo.h>
3148 + #include <asm/addrspace.h>
3149 + #include <asm/prom.h>
3150 ++#include <asm/mach-ralink/ralink_regs.h>
3151 +
3152 + #include "common.h"
3153 +
3154 +@@ -81,7 +82,8 @@ static int __init plat_of_setup(void)
3155 + __dt_register_buses(soc_info.compatible, "palmbus");
3156 +
3157 + /* make sure that the reset controller is setup early */
3158 +- ralink_rst_init();
3159 ++ if (ralink_soc != MT762X_SOC_MT7621AT)
3160 ++ ralink_rst_init();
3161 +
3162 + return 0;
3163 + }
3164 +diff --git a/arch/powerpc/boot/dts/turris1x.dts b/arch/powerpc/boot/dts/turris1x.dts
3165 +index 045af668e9284..e9cda34a140e0 100644
3166 +--- a/arch/powerpc/boot/dts/turris1x.dts
3167 ++++ b/arch/powerpc/boot/dts/turris1x.dts
3168 +@@ -69,6 +69,20 @@
3169 + interrupt-parent = <&gpio>;
3170 + interrupts = <12 IRQ_TYPE_LEVEL_LOW>, /* GPIO12 - ALERT pin */
3171 + <13 IRQ_TYPE_LEVEL_LOW>; /* GPIO13 - CRIT pin */
3172 ++ #address-cells = <1>;
3173 ++ #size-cells = <0>;
3174 ++
3175 ++ /* Local temperature sensor (SA56004ED internal) */
3176 ++ channel@0 {
3177 ++ reg = <0>;
3178 ++ label = "board";
3179 ++ };
3180 ++
3181 ++ /* Remote temperature sensor (D+/D- connected to P2020 CPU Temperature Diode) */
3182 ++ channel@1 {
3183 ++ reg = <1>;
3184 ++ label = "cpu";
3185 ++ };
3186 + };
3187 +
3188 + /* DDR3 SPD/EEPROM */
3189 +diff --git a/arch/powerpc/include/asm/hvcall.h b/arch/powerpc/include/asm/hvcall.h
3190 +index 8abae463f6c12..95fd7f9485d55 100644
3191 +--- a/arch/powerpc/include/asm/hvcall.h
3192 ++++ b/arch/powerpc/include/asm/hvcall.h
3193 +@@ -79,7 +79,7 @@
3194 + #define H_NOT_ENOUGH_RESOURCES -44
3195 + #define H_R_STATE -45
3196 + #define H_RESCINDED -46
3197 +-#define H_P1 -54
3198 ++#define H_ABORTED -54
3199 + #define H_P2 -55
3200 + #define H_P3 -56
3201 + #define H_P4 -57
3202 +@@ -100,7 +100,6 @@
3203 + #define H_COP_HW -74
3204 + #define H_STATE -75
3205 + #define H_IN_USE -77
3206 +-#define H_ABORTED -78
3207 + #define H_UNSUPPORTED_FLAG_START -256
3208 + #define H_UNSUPPORTED_FLAG_END -511
3209 + #define H_MULTI_THREADS_ACTIVE -9005
3210 +diff --git a/arch/powerpc/perf/callchain.c b/arch/powerpc/perf/callchain.c
3211 +index 082f6d0308a47..8718289c051dd 100644
3212 +--- a/arch/powerpc/perf/callchain.c
3213 ++++ b/arch/powerpc/perf/callchain.c
3214 +@@ -61,6 +61,7 @@ perf_callchain_kernel(struct perf_callchain_entry_ctx *entry, struct pt_regs *re
3215 + next_sp = fp[0];
3216 +
3217 + if (next_sp == sp + STACK_INT_FRAME_SIZE &&
3218 ++ validate_sp(sp, current, STACK_INT_FRAME_SIZE) &&
3219 + fp[STACK_FRAME_MARKER] == STACK_FRAME_REGS_MARKER) {
3220 + /*
3221 + * This looks like an interrupt frame for an
3222 +diff --git a/arch/powerpc/perf/hv-gpci-requests.h b/arch/powerpc/perf/hv-gpci-requests.h
3223 +index 8965b4463d433..5e86371a20c78 100644
3224 +--- a/arch/powerpc/perf/hv-gpci-requests.h
3225 ++++ b/arch/powerpc/perf/hv-gpci-requests.h
3226 +@@ -79,6 +79,7 @@ REQUEST(__field(0, 8, partition_id)
3227 + )
3228 + #include I(REQUEST_END)
3229 +
3230 ++#ifdef ENABLE_EVENTS_COUNTERINFO_V6
3231 + /*
3232 + * Not available for counter_info_version >= 0x8, use
3233 + * run_instruction_cycles_by_partition(0x100) instead.
3234 +@@ -92,6 +93,7 @@ REQUEST(__field(0, 8, partition_id)
3235 + __count(0x10, 8, cycles)
3236 + )
3237 + #include I(REQUEST_END)
3238 ++#endif
3239 +
3240 + #define REQUEST_NAME system_performance_capabilities
3241 + #define REQUEST_NUM 0x40
3242 +@@ -103,6 +105,7 @@ REQUEST(__field(0, 1, perf_collect_privileged)
3243 + )
3244 + #include I(REQUEST_END)
3245 +
3246 ++#ifdef ENABLE_EVENTS_COUNTERINFO_V6
3247 + #define REQUEST_NAME processor_bus_utilization_abc_links
3248 + #define REQUEST_NUM 0x50
3249 + #define REQUEST_IDX_KIND "hw_chip_id=?"
3250 +@@ -194,6 +197,7 @@ REQUEST(__field(0, 4, phys_processor_idx)
3251 + __count(0x28, 8, instructions_completed)
3252 + )
3253 + #include I(REQUEST_END)
3254 ++#endif
3255 +
3256 + /* Processor_core_power_mode (0x95) skipped, no counters */
3257 + /* Affinity_domain_information_by_virtual_processor (0xA0) skipped,
3258 +diff --git a/arch/powerpc/perf/hv-gpci.c b/arch/powerpc/perf/hv-gpci.c
3259 +index 5eb60ed5b5e8a..7ff8ff3509f5f 100644
3260 +--- a/arch/powerpc/perf/hv-gpci.c
3261 ++++ b/arch/powerpc/perf/hv-gpci.c
3262 +@@ -70,9 +70,9 @@ static const struct attribute_group format_group = {
3263 + .attrs = format_attrs,
3264 + };
3265 +
3266 +-static const struct attribute_group event_group = {
3267 ++static struct attribute_group event_group = {
3268 + .name = "events",
3269 +- .attrs = hv_gpci_event_attrs,
3270 ++ /* .attrs is set in init */
3271 + };
3272 +
3273 + #define HV_CAPS_ATTR(_name, _format) \
3274 +@@ -330,6 +330,7 @@ static int hv_gpci_init(void)
3275 + int r;
3276 + unsigned long hret;
3277 + struct hv_perf_caps caps;
3278 ++ struct hv_gpci_request_buffer *arg;
3279 +
3280 + hv_gpci_assert_offsets_correct();
3281 +
3282 +@@ -353,6 +354,36 @@ static int hv_gpci_init(void)
3283 + /* sampling not supported */
3284 + h_gpci_pmu.capabilities |= PERF_PMU_CAP_NO_INTERRUPT;
3285 +
3286 ++ arg = (void *)get_cpu_var(hv_gpci_reqb);
3287 ++ memset(arg, 0, HGPCI_REQ_BUFFER_SIZE);
3288 ++
3289 ++ /*
3290 ++ * hcall H_GET_PERF_COUNTER_INFO populates the output
3291 ++ * counter_info_version value based on the system hypervisor.
3292 ++ * Pass the counter request 0x10 corresponds to request type
3293 ++ * 'Dispatch_timebase_by_processor', to get the supported
3294 ++ * counter_info_version.
3295 ++ */
3296 ++ arg->params.counter_request = cpu_to_be32(0x10);
3297 ++
3298 ++ r = plpar_hcall_norets(H_GET_PERF_COUNTER_INFO,
3299 ++ virt_to_phys(arg), HGPCI_REQ_BUFFER_SIZE);
3300 ++ if (r) {
3301 ++ pr_devel("hcall failed, can't get supported counter_info_version: 0x%x\n", r);
3302 ++ arg->params.counter_info_version_out = 0x8;
3303 ++ }
3304 ++
3305 ++ /*
3306 ++ * Use counter_info_version_out value to assign
3307 ++ * required hv-gpci event list.
3308 ++ */
3309 ++ if (arg->params.counter_info_version_out >= 0x8)
3310 ++ event_group.attrs = hv_gpci_event_attrs;
3311 ++ else
3312 ++ event_group.attrs = hv_gpci_event_attrs_v6;
3313 ++
3314 ++ put_cpu_var(hv_gpci_reqb);
3315 ++
3316 + r = perf_pmu_register(&h_gpci_pmu, h_gpci_pmu.name, -1);
3317 + if (r)
3318 + return r;
3319 +diff --git a/arch/powerpc/perf/hv-gpci.h b/arch/powerpc/perf/hv-gpci.h
3320 +index 4d108262bed79..c72020912dea5 100644
3321 +--- a/arch/powerpc/perf/hv-gpci.h
3322 ++++ b/arch/powerpc/perf/hv-gpci.h
3323 +@@ -26,6 +26,7 @@ enum {
3324 + #define REQUEST_FILE "../hv-gpci-requests.h"
3325 + #define NAME_LOWER hv_gpci
3326 + #define NAME_UPPER HV_GPCI
3327 ++#define ENABLE_EVENTS_COUNTERINFO_V6
3328 + #include "req-gen/perf.h"
3329 + #undef REQUEST_FILE
3330 + #undef NAME_LOWER
3331 +diff --git a/arch/powerpc/perf/req-gen/perf.h b/arch/powerpc/perf/req-gen/perf.h
3332 +index fa9bc804e67af..6b2a59fefffa7 100644
3333 +--- a/arch/powerpc/perf/req-gen/perf.h
3334 ++++ b/arch/powerpc/perf/req-gen/perf.h
3335 +@@ -139,6 +139,26 @@ PMU_EVENT_ATTR_STRING( \
3336 + #define REQUEST_(r_name, r_value, r_idx_1, r_fields) \
3337 + r_fields
3338 +
3339 ++/* Generate event list for platforms with counter_info_version 0x6 or below */
3340 ++static __maybe_unused struct attribute *hv_gpci_event_attrs_v6[] = {
3341 ++#include REQUEST_FILE
3342 ++ NULL
3343 ++};
3344 ++
3345 ++/*
3346 ++ * Based on getPerfCountInfo v1.018 documentation, some of the hv-gpci
3347 ++ * events were deprecated for platform firmware that supports
3348 ++ * counter_info_version 0x8 or above.
3349 ++ * Those deprecated events are still part of platform firmware that
3350 ++ * support counter_info_version 0x6 and below. As per the getPerfCountInfo
3351 ++ * v1.018 documentation there is no counter_info_version 0x7.
3352 ++ * Undefining macro ENABLE_EVENTS_COUNTERINFO_V6, to disable the addition of
3353 ++ * deprecated events in "hv_gpci_event_attrs" attribute group, for platforms
3354 ++ * that supports counter_info_version 0x8 or above.
3355 ++ */
3356 ++#undef ENABLE_EVENTS_COUNTERINFO_V6
3357 ++
3358 ++/* Generate event list for platforms with counter_info_version 0x8 or above*/
3359 + static __maybe_unused struct attribute *hv_gpci_event_attrs[] = {
3360 + #include REQUEST_FILE
3361 + NULL
3362 +diff --git a/arch/powerpc/platforms/52xx/mpc52xx_lpbfifo.c b/arch/powerpc/platforms/52xx/mpc52xx_lpbfifo.c
3363 +index 48038aaedbd36..2875c206ac0f8 100644
3364 +--- a/arch/powerpc/platforms/52xx/mpc52xx_lpbfifo.c
3365 ++++ b/arch/powerpc/platforms/52xx/mpc52xx_lpbfifo.c
3366 +@@ -531,6 +531,7 @@ static int mpc52xx_lpbfifo_probe(struct platform_device *op)
3367 + err_bcom_rx_irq:
3368 + bcom_gen_bd_rx_release(lpbfifo.bcom_rx_task);
3369 + err_bcom_rx:
3370 ++ free_irq(lpbfifo.irq, &lpbfifo);
3371 + err_irq:
3372 + iounmap(lpbfifo.regs);
3373 + lpbfifo.regs = NULL;
3374 +diff --git a/arch/powerpc/platforms/83xx/mpc832x_rdb.c b/arch/powerpc/platforms/83xx/mpc832x_rdb.c
3375 +index bb8caa5071f8c..dddb5c6f81209 100644
3376 +--- a/arch/powerpc/platforms/83xx/mpc832x_rdb.c
3377 ++++ b/arch/powerpc/platforms/83xx/mpc832x_rdb.c
3378 +@@ -107,7 +107,7 @@ static int __init of_fsl_spi_probe(char *type, char *compatible, u32 sysclk,
3379 +
3380 + goto next;
3381 + unreg:
3382 +- platform_device_del(pdev);
3383 ++ platform_device_put(pdev);
3384 + err:
3385 + pr_err("%pOF: registration failed\n", np);
3386 + next:
3387 +diff --git a/arch/powerpc/platforms/pseries/eeh_pseries.c b/arch/powerpc/platforms/pseries/eeh_pseries.c
3388 +index 8e40ccac0f44e..e5a58a9b2fe9f 100644
3389 +--- a/arch/powerpc/platforms/pseries/eeh_pseries.c
3390 ++++ b/arch/powerpc/platforms/pseries/eeh_pseries.c
3391 +@@ -848,16 +848,7 @@ static int __init eeh_pseries_init(void)
3392 + }
3393 +
3394 + /* Initialize error log size */
3395 +- eeh_error_buf_size = rtas_token("rtas-error-log-max");
3396 +- if (eeh_error_buf_size == RTAS_UNKNOWN_SERVICE) {
3397 +- pr_info("%s: unknown EEH error log size\n",
3398 +- __func__);
3399 +- eeh_error_buf_size = 1024;
3400 +- } else if (eeh_error_buf_size > RTAS_ERROR_LOG_MAX) {
3401 +- pr_info("%s: EEH error log size %d exceeds the maximal %d\n",
3402 +- __func__, eeh_error_buf_size, RTAS_ERROR_LOG_MAX);
3403 +- eeh_error_buf_size = RTAS_ERROR_LOG_MAX;
3404 +- }
3405 ++ eeh_error_buf_size = rtas_get_error_log_max();
3406 +
3407 + /* Set EEH probe mode */
3408 + eeh_add_flag(EEH_PROBE_MODE_DEVTREE | EEH_ENABLE_IO_FOR_LOG);
3409 +diff --git a/arch/powerpc/platforms/pseries/plpks.c b/arch/powerpc/platforms/pseries/plpks.c
3410 +index f4b5b5a64db3d..63a1e1fe01851 100644
3411 +--- a/arch/powerpc/platforms/pseries/plpks.c
3412 ++++ b/arch/powerpc/platforms/pseries/plpks.c
3413 +@@ -75,7 +75,7 @@ static int pseries_status_to_err(int rc)
3414 + case H_FUNCTION:
3415 + err = -ENXIO;
3416 + break;
3417 +- case H_P1:
3418 ++ case H_PARAMETER:
3419 + case H_P2:
3420 + case H_P3:
3421 + case H_P4:
3422 +@@ -111,7 +111,7 @@ static int pseries_status_to_err(int rc)
3423 + err = -EEXIST;
3424 + break;
3425 + case H_ABORTED:
3426 +- err = -EINTR;
3427 ++ err = -EIO;
3428 + break;
3429 + default:
3430 + err = -EINVAL;
3431 +@@ -366,22 +366,24 @@ static int plpks_read_var(u8 consumer, struct plpks_var *var)
3432 + {
3433 + unsigned long retbuf[PLPAR_HCALL_BUFSIZE] = { 0 };
3434 + struct plpks_auth *auth;
3435 +- struct label *label;
3436 ++ struct label *label = NULL;
3437 + u8 *output;
3438 + int rc;
3439 +
3440 + if (var->namelen > MAX_NAME_SIZE)
3441 + return -EINVAL;
3442 +
3443 +- auth = construct_auth(PKS_OS_OWNER);
3444 ++ auth = construct_auth(consumer);
3445 + if (IS_ERR(auth))
3446 + return PTR_ERR(auth);
3447 +
3448 +- label = construct_label(var->component, var->os, var->name,
3449 +- var->namelen);
3450 +- if (IS_ERR(label)) {
3451 +- rc = PTR_ERR(label);
3452 +- goto out_free_auth;
3453 ++ if (consumer == PKS_OS_OWNER) {
3454 ++ label = construct_label(var->component, var->os, var->name,
3455 ++ var->namelen);
3456 ++ if (IS_ERR(label)) {
3457 ++ rc = PTR_ERR(label);
3458 ++ goto out_free_auth;
3459 ++ }
3460 + }
3461 +
3462 + output = kzalloc(maxobjsize, GFP_KERNEL);
3463 +@@ -390,9 +392,15 @@ static int plpks_read_var(u8 consumer, struct plpks_var *var)
3464 + goto out_free_label;
3465 + }
3466 +
3467 +- rc = plpar_hcall(H_PKS_READ_OBJECT, retbuf, virt_to_phys(auth),
3468 +- virt_to_phys(label), label->size, virt_to_phys(output),
3469 +- maxobjsize);
3470 ++ if (consumer == PKS_OS_OWNER)
3471 ++ rc = plpar_hcall(H_PKS_READ_OBJECT, retbuf, virt_to_phys(auth),
3472 ++ virt_to_phys(label), label->size, virt_to_phys(output),
3473 ++ maxobjsize);
3474 ++ else
3475 ++ rc = plpar_hcall(H_PKS_READ_OBJECT, retbuf, virt_to_phys(auth),
3476 ++ virt_to_phys(var->name), var->namelen, virt_to_phys(output),
3477 ++ maxobjsize);
3478 ++
3479 +
3480 + if (rc != H_SUCCESS) {
3481 + pr_err("Failed to read variable %s for component %s with error %d\n",
3482 +diff --git a/arch/powerpc/platforms/pseries/plpks.h b/arch/powerpc/platforms/pseries/plpks.h
3483 +index c6a291367bb13..275ccd86bfb5e 100644
3484 +--- a/arch/powerpc/platforms/pseries/plpks.h
3485 ++++ b/arch/powerpc/platforms/pseries/plpks.h
3486 +@@ -17,7 +17,7 @@
3487 + #define WORLDREADABLE 0x08000000
3488 + #define SIGNEDUPDATE 0x01000000
3489 +
3490 +-#define PLPKS_VAR_LINUX 0x01
3491 ++#define PLPKS_VAR_LINUX 0x02
3492 + #define PLPKS_VAR_COMMON 0x04
3493 +
3494 + struct plpks_var {
3495 +diff --git a/arch/powerpc/sysdev/xive/spapr.c b/arch/powerpc/sysdev/xive/spapr.c
3496 +index e2c8f93b535ba..e454192643910 100644
3497 +--- a/arch/powerpc/sysdev/xive/spapr.c
3498 ++++ b/arch/powerpc/sysdev/xive/spapr.c
3499 +@@ -439,6 +439,7 @@ static int xive_spapr_populate_irq_data(u32 hw_irq, struct xive_irq_data *data)
3500 +
3501 + data->trig_mmio = ioremap(data->trig_page, 1u << data->esb_shift);
3502 + if (!data->trig_mmio) {
3503 ++ iounmap(data->eoi_mmio);
3504 + pr_err("Failed to map trigger page for irq 0x%x\n", hw_irq);
3505 + return -ENOMEM;
3506 + }
3507 +diff --git a/arch/powerpc/xmon/xmon.c b/arch/powerpc/xmon/xmon.c
3508 +index 26ef3388c24c4..df91dfc7ff727 100644
3509 +--- a/arch/powerpc/xmon/xmon.c
3510 ++++ b/arch/powerpc/xmon/xmon.c
3511 +@@ -1525,9 +1525,9 @@ bpt_cmds(void)
3512 + cmd = inchar();
3513 +
3514 + switch (cmd) {
3515 +- static const char badaddr[] = "Only kernel addresses are permitted for breakpoints\n";
3516 +- int mode;
3517 +- case 'd': /* bd - hardware data breakpoint */
3518 ++ case 'd': { /* bd - hardware data breakpoint */
3519 ++ static const char badaddr[] = "Only kernel addresses are permitted for breakpoints\n";
3520 ++ int mode;
3521 + if (xmon_is_ro) {
3522 + printf(xmon_ro_msg);
3523 + break;
3524 +@@ -1560,6 +1560,7 @@ bpt_cmds(void)
3525 +
3526 + force_enable_xmon();
3527 + break;
3528 ++ }
3529 +
3530 + case 'i': /* bi - hardware instr breakpoint */
3531 + if (xmon_is_ro) {
3532 +diff --git a/arch/riscv/include/asm/hugetlb.h b/arch/riscv/include/asm/hugetlb.h
3533 +index a5c2ca1d1cd8b..ec19d6afc8965 100644
3534 +--- a/arch/riscv/include/asm/hugetlb.h
3535 ++++ b/arch/riscv/include/asm/hugetlb.h
3536 +@@ -5,4 +5,10 @@
3537 + #include <asm-generic/hugetlb.h>
3538 + #include <asm/page.h>
3539 +
3540 ++static inline void arch_clear_hugepage_flags(struct page *page)
3541 ++{
3542 ++ clear_bit(PG_dcache_clean, &page->flags);
3543 ++}
3544 ++#define arch_clear_hugepage_flags arch_clear_hugepage_flags
3545 ++
3546 + #endif /* _ASM_RISCV_HUGETLB_H */
3547 +diff --git a/arch/riscv/include/asm/io.h b/arch/riscv/include/asm/io.h
3548 +index 92080a2279372..42497d487a174 100644
3549 +--- a/arch/riscv/include/asm/io.h
3550 ++++ b/arch/riscv/include/asm/io.h
3551 +@@ -135,4 +135,9 @@ __io_writes_outs(outs, u64, q, __io_pbr(), __io_paw())
3552 +
3553 + #include <asm-generic/io.h>
3554 +
3555 ++#ifdef CONFIG_MMU
3556 ++#define arch_memremap_wb(addr, size) \
3557 ++ ((__force void *)ioremap_prot((addr), (size), _PAGE_KERNEL))
3558 ++#endif
3559 ++
3560 + #endif /* _ASM_RISCV_IO_H */
3561 +diff --git a/arch/riscv/include/asm/pgtable-64.h b/arch/riscv/include/asm/pgtable-64.h
3562 +index dc42375c23571..42a042c0e13ed 100644
3563 +--- a/arch/riscv/include/asm/pgtable-64.h
3564 ++++ b/arch/riscv/include/asm/pgtable-64.h
3565 +@@ -25,7 +25,11 @@ extern bool pgtable_l5_enabled;
3566 + #define PGDIR_MASK (~(PGDIR_SIZE - 1))
3567 +
3568 + /* p4d is folded into pgd in case of 4-level page table */
3569 +-#define P4D_SHIFT 39
3570 ++#define P4D_SHIFT_L3 30
3571 ++#define P4D_SHIFT_L4 39
3572 ++#define P4D_SHIFT_L5 39
3573 ++#define P4D_SHIFT (pgtable_l5_enabled ? P4D_SHIFT_L5 : \
3574 ++ (pgtable_l4_enabled ? P4D_SHIFT_L4 : P4D_SHIFT_L3))
3575 + #define P4D_SIZE (_AC(1, UL) << P4D_SHIFT)
3576 + #define P4D_MASK (~(P4D_SIZE - 1))
3577 +
3578 +diff --git a/arch/riscv/kernel/entry.S b/arch/riscv/kernel/entry.S
3579 +index 186abd146eaff..3221a9e5f3724 100644
3580 +--- a/arch/riscv/kernel/entry.S
3581 ++++ b/arch/riscv/kernel/entry.S
3582 +@@ -263,12 +263,11 @@ ret_from_exception:
3583 + #endif
3584 + bnez s0, resume_kernel
3585 +
3586 +-resume_userspace:
3587 + /* Interrupts must be disabled here so flags are checked atomically */
3588 + REG_L s0, TASK_TI_FLAGS(tp) /* current_thread_info->flags */
3589 + andi s1, s0, _TIF_WORK_MASK
3590 +- bnez s1, work_pending
3591 +-
3592 ++ bnez s1, resume_userspace_slow
3593 ++resume_userspace:
3594 + #ifdef CONFIG_CONTEXT_TRACKING_USER
3595 + call user_enter_callable
3596 + #endif
3597 +@@ -368,19 +367,12 @@ resume_kernel:
3598 + j restore_all
3599 + #endif
3600 +
3601 +-work_pending:
3602 ++resume_userspace_slow:
3603 + /* Enter slow path for supplementary processing */
3604 +- la ra, ret_from_exception
3605 +- andi s1, s0, _TIF_NEED_RESCHED
3606 +- bnez s1, work_resched
3607 +-work_notifysig:
3608 +- /* Handle pending signals and notify-resume requests */
3609 +- csrs CSR_STATUS, SR_IE /* Enable interrupts for do_notify_resume() */
3610 + move a0, sp /* pt_regs */
3611 + move a1, s0 /* current_thread_info->flags */
3612 +- tail do_notify_resume
3613 +-work_resched:
3614 +- tail schedule
3615 ++ call do_work_pending
3616 ++ j resume_userspace
3617 +
3618 + /* Slow paths for ptrace. */
3619 + handle_syscall_trace_enter:
3620 +diff --git a/arch/riscv/kernel/signal.c b/arch/riscv/kernel/signal.c
3621 +index 5c591123c4409..bfb2afa4135f8 100644
3622 +--- a/arch/riscv/kernel/signal.c
3623 ++++ b/arch/riscv/kernel/signal.c
3624 +@@ -313,19 +313,27 @@ static void do_signal(struct pt_regs *regs)
3625 + }
3626 +
3627 + /*
3628 +- * notification of userspace execution resumption
3629 +- * - triggered by the _TIF_WORK_MASK flags
3630 ++ * Handle any pending work on the resume-to-userspace path, as indicated by
3631 ++ * _TIF_WORK_MASK. Entered from assembly with IRQs off.
3632 + */
3633 +-asmlinkage __visible void do_notify_resume(struct pt_regs *regs,
3634 +- unsigned long thread_info_flags)
3635 ++asmlinkage __visible void do_work_pending(struct pt_regs *regs,
3636 ++ unsigned long thread_info_flags)
3637 + {
3638 +- if (thread_info_flags & _TIF_UPROBE)
3639 +- uprobe_notify_resume(regs);
3640 +-
3641 +- /* Handle pending signal delivery */
3642 +- if (thread_info_flags & (_TIF_SIGPENDING | _TIF_NOTIFY_SIGNAL))
3643 +- do_signal(regs);
3644 +-
3645 +- if (thread_info_flags & _TIF_NOTIFY_RESUME)
3646 +- resume_user_mode_work(regs);
3647 ++ do {
3648 ++ if (thread_info_flags & _TIF_NEED_RESCHED) {
3649 ++ schedule();
3650 ++ } else {
3651 ++ local_irq_enable();
3652 ++ if (thread_info_flags & _TIF_UPROBE)
3653 ++ uprobe_notify_resume(regs);
3654 ++ /* Handle pending signal delivery */
3655 ++ if (thread_info_flags & (_TIF_SIGPENDING |
3656 ++ _TIF_NOTIFY_SIGNAL))
3657 ++ do_signal(regs);
3658 ++ if (thread_info_flags & _TIF_NOTIFY_RESUME)
3659 ++ resume_user_mode_work(regs);
3660 ++ }
3661 ++ local_irq_disable();
3662 ++ thread_info_flags = read_thread_flags();
3663 ++ } while (thread_info_flags & _TIF_WORK_MASK);
3664 + }
3665 +diff --git a/arch/riscv/kernel/traps.c b/arch/riscv/kernel/traps.c
3666 +index 6e8822446069e..026b458331582 100644
3667 +--- a/arch/riscv/kernel/traps.c
3668 ++++ b/arch/riscv/kernel/traps.c
3669 +@@ -211,7 +211,7 @@ static DEFINE_PER_CPU(unsigned long [OVERFLOW_STACK_SIZE/sizeof(long)],
3670 + * shadow stack, handled_ kernel_ stack_ overflow(in kernel/entry.S) is used
3671 + * to get per-cpu overflow stack(get_overflow_stack).
3672 + */
3673 +-long shadow_stack[SHADOW_OVERFLOW_STACK_SIZE/sizeof(long)];
3674 ++long shadow_stack[SHADOW_OVERFLOW_STACK_SIZE/sizeof(long)] __aligned(16);
3675 + asmlinkage unsigned long get_overflow_stack(void)
3676 + {
3677 + return (unsigned long)this_cpu_ptr(overflow_stack) +
3678 +diff --git a/arch/riscv/kvm/vcpu.c b/arch/riscv/kvm/vcpu.c
3679 +index f692c0716aa7a..aa7ae63270449 100644
3680 +--- a/arch/riscv/kvm/vcpu.c
3681 ++++ b/arch/riscv/kvm/vcpu.c
3682 +@@ -286,12 +286,15 @@ static int kvm_riscv_vcpu_set_reg_config(struct kvm_vcpu *vcpu,
3683 + if (copy_from_user(&reg_val, uaddr, KVM_REG_SIZE(reg->id)))
3684 + return -EFAULT;
3685 +
3686 +- /* This ONE REG interface is only defined for single letter extensions */
3687 +- if (fls(reg_val) >= RISCV_ISA_EXT_BASE)
3688 +- return -EINVAL;
3689 +-
3690 + switch (reg_num) {
3691 + case KVM_REG_RISCV_CONFIG_REG(isa):
3692 ++ /*
3693 ++ * This ONE REG interface is only defined for
3694 ++ * single letter extensions.
3695 ++ */
3696 ++ if (fls(reg_val) >= RISCV_ISA_EXT_BASE)
3697 ++ return -EINVAL;
3698 ++
3699 + if (!vcpu->arch.ran_atleast_once) {
3700 + /* Ignore the enable/disable request for certain extensions */
3701 + for (i = 0; i < RISCV_ISA_EXT_BASE; i++) {
3702 +diff --git a/arch/riscv/mm/physaddr.c b/arch/riscv/mm/physaddr.c
3703 +index 19cf25a74ee29..9b18bda74154e 100644
3704 +--- a/arch/riscv/mm/physaddr.c
3705 ++++ b/arch/riscv/mm/physaddr.c
3706 +@@ -22,7 +22,7 @@ EXPORT_SYMBOL(__virt_to_phys);
3707 + phys_addr_t __phys_addr_symbol(unsigned long x)
3708 + {
3709 + unsigned long kernel_start = kernel_map.virt_addr;
3710 +- unsigned long kernel_end = (unsigned long)_end;
3711 ++ unsigned long kernel_end = kernel_start + kernel_map.size;
3712 +
3713 + /*
3714 + * Boundary checking aginst the kernel image mapping.
3715 +diff --git a/arch/riscv/net/bpf_jit_comp64.c b/arch/riscv/net/bpf_jit_comp64.c
3716 +index 00df3a8f92acd..f2417ac54edd6 100644
3717 +--- a/arch/riscv/net/bpf_jit_comp64.c
3718 ++++ b/arch/riscv/net/bpf_jit_comp64.c
3719 +@@ -136,6 +136,25 @@ static bool in_auipc_jalr_range(s64 val)
3720 + val < ((1L << 31) - (1L << 11));
3721 + }
3722 +
3723 ++/* Emit fixed-length instructions for address */
3724 ++static int emit_addr(u8 rd, u64 addr, bool extra_pass, struct rv_jit_context *ctx)
3725 ++{
3726 ++ u64 ip = (u64)(ctx->insns + ctx->ninsns);
3727 ++ s64 off = addr - ip;
3728 ++ s64 upper = (off + (1 << 11)) >> 12;
3729 ++ s64 lower = off & 0xfff;
3730 ++
3731 ++ if (extra_pass && !in_auipc_jalr_range(off)) {
3732 ++ pr_err("bpf-jit: target offset 0x%llx is out of range\n", off);
3733 ++ return -ERANGE;
3734 ++ }
3735 ++
3736 ++ emit(rv_auipc(rd, upper), ctx);
3737 ++ emit(rv_addi(rd, rd, lower), ctx);
3738 ++ return 0;
3739 ++}
3740 ++
3741 ++/* Emit variable-length instructions for 32-bit and 64-bit imm */
3742 + static void emit_imm(u8 rd, s64 val, struct rv_jit_context *ctx)
3743 + {
3744 + /* Note that the immediate from the add is sign-extended,
3745 +@@ -1050,7 +1069,15 @@ out_be:
3746 + u64 imm64;
3747 +
3748 + imm64 = (u64)insn1.imm << 32 | (u32)imm;
3749 +- emit_imm(rd, imm64, ctx);
3750 ++ if (bpf_pseudo_func(insn)) {
3751 ++ /* fixed-length insns for extra jit pass */
3752 ++ ret = emit_addr(rd, imm64, extra_pass, ctx);
3753 ++ if (ret)
3754 ++ return ret;
3755 ++ } else {
3756 ++ emit_imm(rd, imm64, ctx);
3757 ++ }
3758 ++
3759 + return 1;
3760 + }
3761 +
3762 +diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
3763 +index 4728d3f5d5c40..3fec0e9d92410 100644
3764 +--- a/arch/x86/Kconfig
3765 ++++ b/arch/x86/Kconfig
3766 +@@ -450,8 +450,8 @@ config X86_X2APIC
3767 +
3768 + Some Intel systems circa 2022 and later are locked into x2APIC mode
3769 + and can not fall back to the legacy APIC modes if SGX or TDX are
3770 +- enabled in the BIOS. They will be unable to boot without enabling
3771 +- this option.
3772 ++ enabled in the BIOS. They will boot with very reduced functionality
3773 ++ without enabling this option.
3774 +
3775 + If you don't know what to do here, say N.
3776 +
3777 +diff --git a/arch/x86/events/intel/uncore_snb.c b/arch/x86/events/intel/uncore_snb.c
3778 +index 1ef4f7861e2ec..1f4869227efb9 100644
3779 +--- a/arch/x86/events/intel/uncore_snb.c
3780 ++++ b/arch/x86/events/intel/uncore_snb.c
3781 +@@ -1338,6 +1338,7 @@ static void __uncore_imc_init_box(struct intel_uncore_box *box,
3782 + /* MCHBAR is disabled */
3783 + if (!(mch_bar & BIT(0))) {
3784 + pr_warn("perf uncore: MCHBAR is disabled. Failed to map IMC free-running counters.\n");
3785 ++ pci_dev_put(pdev);
3786 + return;
3787 + }
3788 + mch_bar &= ~BIT(0);
3789 +@@ -1352,6 +1353,8 @@ static void __uncore_imc_init_box(struct intel_uncore_box *box,
3790 + box->io_addr = ioremap(addr, type->mmio_map_size);
3791 + if (!box->io_addr)
3792 + pr_warn("perf uncore: Failed to ioremap for %s.\n", type->name);
3793 ++
3794 ++ pci_dev_put(pdev);
3795 + }
3796 +
3797 + static void tgl_uncore_imc_freerunning_init_box(struct intel_uncore_box *box)
3798 +diff --git a/arch/x86/events/intel/uncore_snbep.c b/arch/x86/events/intel/uncore_snbep.c
3799 +index ed869443efb21..fcd95e93f479a 100644
3800 +--- a/arch/x86/events/intel/uncore_snbep.c
3801 ++++ b/arch/x86/events/intel/uncore_snbep.c
3802 +@@ -2891,6 +2891,7 @@ static bool hswep_has_limit_sbox(unsigned int device)
3803 + return false;
3804 +
3805 + pci_read_config_dword(dev, HSWEP_PCU_CAPID4_OFFET, &capid4);
3806 ++ pci_dev_put(dev);
3807 + if (!hswep_get_chop(capid4))
3808 + return true;
3809 +
3810 +@@ -4492,6 +4493,8 @@ static int sad_cfg_iio_topology(struct intel_uncore_type *type, u8 *sad_pmon_map
3811 + type->topology = NULL;
3812 + }
3813 +
3814 ++ pci_dev_put(dev);
3815 ++
3816 + return ret;
3817 + }
3818 +
3819 +@@ -4857,6 +4860,8 @@ static int snr_uncore_mmio_map(struct intel_uncore_box *box,
3820 +
3821 + addr += box_ctl;
3822 +
3823 ++ pci_dev_put(pdev);
3824 ++
3825 + box->io_addr = ioremap(addr, type->mmio_map_size);
3826 + if (!box->io_addr) {
3827 + pr_warn("perf uncore: Failed to ioremap for %s.\n", type->name);
3828 +diff --git a/arch/x86/hyperv/hv_init.c b/arch/x86/hyperv/hv_init.c
3829 +index a0165df3c4d8c..d03561b2fffe6 100644
3830 +--- a/arch/x86/hyperv/hv_init.c
3831 ++++ b/arch/x86/hyperv/hv_init.c
3832 +@@ -536,8 +536,6 @@ void hyperv_cleanup(void)
3833 + {
3834 + union hv_x64_msr_hypercall_contents hypercall_msr;
3835 +
3836 +- unregister_syscore_ops(&hv_syscore_ops);
3837 +-
3838 + /* Reset our OS id */
3839 + wrmsrl(HV_X64_MSR_GUEST_OS_ID, 0);
3840 + hv_ghcb_msr_write(HV_X64_MSR_GUEST_OS_ID, 0);
3841 +diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
3842 +index 3415321c8240c..3216da7074bad 100644
3843 +--- a/arch/x86/include/asm/apic.h
3844 ++++ b/arch/x86/include/asm/apic.h
3845 +@@ -249,7 +249,6 @@ static inline u64 native_x2apic_icr_read(void)
3846 + extern int x2apic_mode;
3847 + extern int x2apic_phys;
3848 + extern void __init x2apic_set_max_apicid(u32 apicid);
3849 +-extern void __init check_x2apic(void);
3850 + extern void x2apic_setup(void);
3851 + static inline int x2apic_enabled(void)
3852 + {
3853 +@@ -258,13 +257,13 @@ static inline int x2apic_enabled(void)
3854 +
3855 + #define x2apic_supported() (boot_cpu_has(X86_FEATURE_X2APIC))
3856 + #else /* !CONFIG_X86_X2APIC */
3857 +-static inline void check_x2apic(void) { }
3858 + static inline void x2apic_setup(void) { }
3859 + static inline int x2apic_enabled(void) { return 0; }
3860 +
3861 + #define x2apic_mode (0)
3862 + #define x2apic_supported() (0)
3863 + #endif /* !CONFIG_X86_X2APIC */
3864 ++extern void __init check_x2apic(void);
3865 +
3866 + struct irq_data;
3867 +
3868 +diff --git a/arch/x86/include/asm/realmode.h b/arch/x86/include/asm/realmode.h
3869 +index fd6f6e5b755a7..a336feef0af14 100644
3870 +--- a/arch/x86/include/asm/realmode.h
3871 ++++ b/arch/x86/include/asm/realmode.h
3872 +@@ -91,6 +91,7 @@ static inline void set_real_mode_mem(phys_addr_t mem)
3873 +
3874 + void reserve_real_mode(void);
3875 + void load_trampoline_pgtable(void);
3876 ++void init_real_mode(void);
3877 +
3878 + #endif /* __ASSEMBLY__ */
3879 +
3880 +diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_init.h
3881 +index e9170457697e4..c1c8c581759d6 100644
3882 +--- a/arch/x86/include/asm/x86_init.h
3883 ++++ b/arch/x86/include/asm/x86_init.h
3884 +@@ -285,6 +285,8 @@ struct x86_hyper_runtime {
3885 + * possible in x86_early_init_platform_quirks() by
3886 + * only using the current x86_hardware_subarch
3887 + * semantics.
3888 ++ * @realmode_reserve: reserve memory for realmode trampoline
3889 ++ * @realmode_init: initialize realmode trampoline
3890 + * @hyper: x86 hypervisor specific runtime callbacks
3891 + */
3892 + struct x86_platform_ops {
3893 +@@ -301,6 +303,8 @@ struct x86_platform_ops {
3894 + void (*apic_post_init)(void);
3895 + struct x86_legacy_features legacy;
3896 + void (*set_legacy_features)(void);
3897 ++ void (*realmode_reserve)(void);
3898 ++ void (*realmode_init)(void);
3899 + struct x86_hyper_runtime hyper;
3900 + struct x86_guest guest;
3901 + };
3902 +diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
3903 +index c6876d3ea4b17..20d9a604da7c4 100644
3904 +--- a/arch/x86/kernel/apic/apic.c
3905 ++++ b/arch/x86/kernel/apic/apic.c
3906 +@@ -1931,16 +1931,19 @@ void __init check_x2apic(void)
3907 + }
3908 + }
3909 + #else /* CONFIG_X86_X2APIC */
3910 +-static int __init validate_x2apic(void)
3911 ++void __init check_x2apic(void)
3912 + {
3913 + if (!apic_is_x2apic_enabled())
3914 +- return 0;
3915 ++ return;
3916 + /*
3917 +- * Checkme: Can we simply turn off x2apic here instead of panic?
3918 ++ * Checkme: Can we simply turn off x2APIC here instead of disabling the APIC?
3919 + */
3920 +- panic("BIOS has enabled x2apic but kernel doesn't support x2apic, please disable x2apic in BIOS.\n");
3921 ++ pr_err("Kernel does not support x2APIC, please recompile with CONFIG_X86_X2APIC.\n");
3922 ++ pr_err("Disabling APIC, expect reduced performance and functionality.\n");
3923 ++
3924 ++ disable_apic = 1;
3925 ++ setup_clear_cpu_cap(X86_FEATURE_APIC);
3926 + }
3927 +-early_initcall(validate_x2apic);
3928 +
3929 + static inline void try_to_enable_x2apic(int remap_mode) { }
3930 + static inline void __x2apic_enable(void) { }
3931 +diff --git a/arch/x86/kernel/cpu/intel.c b/arch/x86/kernel/cpu/intel.c
3932 +index 2d7ea5480ec33..4278996504833 100644
3933 +--- a/arch/x86/kernel/cpu/intel.c
3934 ++++ b/arch/x86/kernel/cpu/intel.c
3935 +@@ -1034,8 +1034,32 @@ static const struct {
3936 +
3937 + static struct ratelimit_state bld_ratelimit;
3938 +
3939 ++static unsigned int sysctl_sld_mitigate = 1;
3940 + static DEFINE_SEMAPHORE(buslock_sem);
3941 +
3942 ++#ifdef CONFIG_PROC_SYSCTL
3943 ++static struct ctl_table sld_sysctls[] = {
3944 ++ {
3945 ++ .procname = "split_lock_mitigate",
3946 ++ .data = &sysctl_sld_mitigate,
3947 ++ .maxlen = sizeof(unsigned int),
3948 ++ .mode = 0644,
3949 ++ .proc_handler = proc_douintvec_minmax,
3950 ++ .extra1 = SYSCTL_ZERO,
3951 ++ .extra2 = SYSCTL_ONE,
3952 ++ },
3953 ++ {}
3954 ++};
3955 ++
3956 ++static int __init sld_mitigate_sysctl_init(void)
3957 ++{
3958 ++ register_sysctl_init("kernel", sld_sysctls);
3959 ++ return 0;
3960 ++}
3961 ++
3962 ++late_initcall(sld_mitigate_sysctl_init);
3963 ++#endif
3964 ++
3965 + static inline bool match_option(const char *arg, int arglen, const char *opt)
3966 + {
3967 + int len = strlen(opt), ratelimit;
3968 +@@ -1146,12 +1170,20 @@ static void split_lock_init(void)
3969 + split_lock_verify_msr(sld_state != sld_off);
3970 + }
3971 +
3972 +-static void __split_lock_reenable(struct work_struct *work)
3973 ++static void __split_lock_reenable_unlock(struct work_struct *work)
3974 + {
3975 + sld_update_msr(true);
3976 + up(&buslock_sem);
3977 + }
3978 +
3979 ++static DECLARE_DELAYED_WORK(sl_reenable_unlock, __split_lock_reenable_unlock);
3980 ++
3981 ++static void __split_lock_reenable(struct work_struct *work)
3982 ++{
3983 ++ sld_update_msr(true);
3984 ++}
3985 ++static DECLARE_DELAYED_WORK(sl_reenable, __split_lock_reenable);
3986 ++
3987 + /*
3988 + * If a CPU goes offline with pending delayed work to re-enable split lock
3989 + * detection then the delayed work will be executed on some other CPU. That
3990 +@@ -1169,10 +1201,9 @@ static int splitlock_cpu_offline(unsigned int cpu)
3991 + return 0;
3992 + }
3993 +
3994 +-static DECLARE_DELAYED_WORK(split_lock_reenable, __split_lock_reenable);
3995 +-
3996 + static void split_lock_warn(unsigned long ip)
3997 + {
3998 ++ struct delayed_work *work;
3999 + int cpu;
4000 +
4001 + if (!current->reported_split_lock)
4002 +@@ -1180,14 +1211,26 @@ static void split_lock_warn(unsigned long ip)
4003 + current->comm, current->pid, ip);
4004 + current->reported_split_lock = 1;
4005 +
4006 +- /* misery factor #1, sleep 10ms before trying to execute split lock */
4007 +- if (msleep_interruptible(10) > 0)
4008 +- return;
4009 +- /* Misery factor #2, only allow one buslocked disabled core at a time */
4010 +- if (down_interruptible(&buslock_sem) == -EINTR)
4011 +- return;
4012 ++ if (sysctl_sld_mitigate) {
4013 ++ /*
4014 ++ * misery factor #1:
4015 ++ * sleep 10ms before trying to execute split lock.
4016 ++ */
4017 ++ if (msleep_interruptible(10) > 0)
4018 ++ return;
4019 ++ /*
4020 ++ * Misery factor #2:
4021 ++ * only allow one buslocked disabled core at a time.
4022 ++ */
4023 ++ if (down_interruptible(&buslock_sem) == -EINTR)
4024 ++ return;
4025 ++ work = &sl_reenable_unlock;
4026 ++ } else {
4027 ++ work = &sl_reenable;
4028 ++ }
4029 ++
4030 + cpu = get_cpu();
4031 +- schedule_delayed_work_on(cpu, &split_lock_reenable, 2);
4032 ++ schedule_delayed_work_on(cpu, work, 2);
4033 +
4034 + /* Disable split lock detection on this CPU to make progress */
4035 + sld_update_msr(false);
4036 +diff --git a/arch/x86/kernel/cpu/sgx/encl.c b/arch/x86/kernel/cpu/sgx/encl.c
4037 +index 8bdeae2fc3091..6942a3d8b578c 100644
4038 +--- a/arch/x86/kernel/cpu/sgx/encl.c
4039 ++++ b/arch/x86/kernel/cpu/sgx/encl.c
4040 +@@ -677,11 +677,15 @@ const struct vm_operations_struct sgx_vm_ops = {
4041 + void sgx_encl_release(struct kref *ref)
4042 + {
4043 + struct sgx_encl *encl = container_of(ref, struct sgx_encl, refcount);
4044 ++ unsigned long max_page_index = PFN_DOWN(encl->base + encl->size - 1);
4045 + struct sgx_va_page *va_page;
4046 + struct sgx_encl_page *entry;
4047 +- unsigned long index;
4048 ++ unsigned long count = 0;
4049 ++
4050 ++ XA_STATE(xas, &encl->page_array, PFN_DOWN(encl->base));
4051 +
4052 +- xa_for_each(&encl->page_array, index, entry) {
4053 ++ xas_lock(&xas);
4054 ++ xas_for_each(&xas, entry, max_page_index) {
4055 + if (entry->epc_page) {
4056 + /*
4057 + * The page and its radix tree entry cannot be freed
4058 +@@ -696,9 +700,20 @@ void sgx_encl_release(struct kref *ref)
4059 + }
4060 +
4061 + kfree(entry);
4062 +- /* Invoke scheduler to prevent soft lockups. */
4063 +- cond_resched();
4064 ++ /*
4065 ++ * Invoke scheduler on every XA_CHECK_SCHED iteration
4066 ++ * to prevent soft lockups.
4067 ++ */
4068 ++ if (!(++count % XA_CHECK_SCHED)) {
4069 ++ xas_pause(&xas);
4070 ++ xas_unlock(&xas);
4071 ++
4072 ++ cond_resched();
4073 ++
4074 ++ xas_lock(&xas);
4075 ++ }
4076 + }
4077 ++ xas_unlock(&xas);
4078 +
4079 + xa_destroy(&encl->page_array);
4080 +
4081 +diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
4082 +index 216fee7144eef..892609cde4a20 100644
4083 +--- a/arch/x86/kernel/setup.c
4084 ++++ b/arch/x86/kernel/setup.c
4085 +@@ -1175,7 +1175,7 @@ void __init setup_arch(char **cmdline_p)
4086 + * Moreover, on machines with SandyBridge graphics or in setups that use
4087 + * crashkernel the entire 1M is reserved anyway.
4088 + */
4089 +- reserve_real_mode();
4090 ++ x86_platform.realmode_reserve();
4091 +
4092 + init_mem_mapping();
4093 +
4094 +diff --git a/arch/x86/kernel/uprobes.c b/arch/x86/kernel/uprobes.c
4095 +index b63cf8f7745ee..6c07f6daaa227 100644
4096 +--- a/arch/x86/kernel/uprobes.c
4097 ++++ b/arch/x86/kernel/uprobes.c
4098 +@@ -722,8 +722,9 @@ static int branch_setup_xol_ops(struct arch_uprobe *auprobe, struct insn *insn)
4099 + switch (opc1) {
4100 + case 0xeb: /* jmp 8 */
4101 + case 0xe9: /* jmp 32 */
4102 +- case 0x90: /* prefix* + nop; same as jmp with .offs = 0 */
4103 + break;
4104 ++ case 0x90: /* prefix* + nop; same as jmp with .offs = 0 */
4105 ++ goto setup;
4106 +
4107 + case 0xe8: /* call relative */
4108 + branch_clear_offset(auprobe, insn);
4109 +@@ -753,6 +754,7 @@ static int branch_setup_xol_ops(struct arch_uprobe *auprobe, struct insn *insn)
4110 + return -ENOTSUPP;
4111 + }
4112 +
4113 ++setup:
4114 + auprobe->branch.opc1 = opc1;
4115 + auprobe->branch.ilen = insn->length;
4116 + auprobe->branch.offs = insn->immediate.value;
4117 +diff --git a/arch/x86/kernel/x86_init.c b/arch/x86/kernel/x86_init.c
4118 +index e84ee5cdbd8c6..3a164fb0d4c3e 100644
4119 +--- a/arch/x86/kernel/x86_init.c
4120 ++++ b/arch/x86/kernel/x86_init.c
4121 +@@ -25,6 +25,7 @@
4122 + #include <asm/iommu.h>
4123 + #include <asm/mach_traps.h>
4124 + #include <asm/irqdomain.h>
4125 ++#include <asm/realmode.h>
4126 +
4127 + void x86_init_noop(void) { }
4128 + void __init x86_init_uint_noop(unsigned int unused) { }
4129 +@@ -145,6 +146,8 @@ struct x86_platform_ops x86_platform __ro_after_init = {
4130 + .get_nmi_reason = default_get_nmi_reason,
4131 + .save_sched_clock_state = tsc_save_sched_clock_state,
4132 + .restore_sched_clock_state = tsc_restore_sched_clock_state,
4133 ++ .realmode_reserve = reserve_real_mode,
4134 ++ .realmode_init = init_real_mode,
4135 + .hyper.pin_vcpu = x86_op_int_noop,
4136 +
4137 + .guest = {
4138 +diff --git a/arch/x86/realmode/init.c b/arch/x86/realmode/init.c
4139 +index 41d7669a97ad1..af565816d2ba6 100644
4140 +--- a/arch/x86/realmode/init.c
4141 ++++ b/arch/x86/realmode/init.c
4142 +@@ -200,14 +200,18 @@ static void __init set_real_mode_permissions(void)
4143 + set_memory_x((unsigned long) text_start, text_size >> PAGE_SHIFT);
4144 + }
4145 +
4146 +-static int __init init_real_mode(void)
4147 ++void __init init_real_mode(void)
4148 + {
4149 + if (!real_mode_header)
4150 + panic("Real mode trampoline was not allocated");
4151 +
4152 + setup_real_mode();
4153 + set_real_mode_permissions();
4154 ++}
4155 +
4156 ++static int __init do_init_real_mode(void)
4157 ++{
4158 ++ x86_platform.realmode_init();
4159 + return 0;
4160 + }
4161 +-early_initcall(init_real_mode);
4162 ++early_initcall(do_init_real_mode);
4163 +diff --git a/arch/x86/xen/enlighten_pv.c b/arch/x86/xen/enlighten_pv.c
4164 +index 9b1a58dda935b..807ab4fbe2c42 100644
4165 +--- a/arch/x86/xen/enlighten_pv.c
4166 ++++ b/arch/x86/xen/enlighten_pv.c
4167 +@@ -1224,6 +1224,8 @@ asmlinkage __visible void __init xen_start_kernel(struct start_info *si)
4168 + xen_vcpu_info_reset(0);
4169 +
4170 + x86_platform.get_nmi_reason = xen_get_nmi_reason;
4171 ++ x86_platform.realmode_reserve = x86_init_noop;
4172 ++ x86_platform.realmode_init = x86_init_noop;
4173 +
4174 + x86_init.resources.memory_setup = xen_memory_setup;
4175 + x86_init.irqs.intr_mode_select = x86_init_noop;
4176 +diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
4177 +index c3e1f9a7d43aa..4b0d6fff88de5 100644
4178 +--- a/arch/x86/xen/smp.c
4179 ++++ b/arch/x86/xen/smp.c
4180 +@@ -32,30 +32,30 @@ static irqreturn_t xen_reschedule_interrupt(int irq, void *dev_id)
4181 +
4182 + void xen_smp_intr_free(unsigned int cpu)
4183 + {
4184 ++ kfree(per_cpu(xen_resched_irq, cpu).name);
4185 ++ per_cpu(xen_resched_irq, cpu).name = NULL;
4186 + if (per_cpu(xen_resched_irq, cpu).irq >= 0) {
4187 + unbind_from_irqhandler(per_cpu(xen_resched_irq, cpu).irq, NULL);
4188 + per_cpu(xen_resched_irq, cpu).irq = -1;
4189 +- kfree(per_cpu(xen_resched_irq, cpu).name);
4190 +- per_cpu(xen_resched_irq, cpu).name = NULL;
4191 + }
4192 ++ kfree(per_cpu(xen_callfunc_irq, cpu).name);
4193 ++ per_cpu(xen_callfunc_irq, cpu).name = NULL;
4194 + if (per_cpu(xen_callfunc_irq, cpu).irq >= 0) {
4195 + unbind_from_irqhandler(per_cpu(xen_callfunc_irq, cpu).irq, NULL);
4196 + per_cpu(xen_callfunc_irq, cpu).irq = -1;
4197 +- kfree(per_cpu(xen_callfunc_irq, cpu).name);
4198 +- per_cpu(xen_callfunc_irq, cpu).name = NULL;
4199 + }
4200 ++ kfree(per_cpu(xen_debug_irq, cpu).name);
4201 ++ per_cpu(xen_debug_irq, cpu).name = NULL;
4202 + if (per_cpu(xen_debug_irq, cpu).irq >= 0) {
4203 + unbind_from_irqhandler(per_cpu(xen_debug_irq, cpu).irq, NULL);
4204 + per_cpu(xen_debug_irq, cpu).irq = -1;
4205 +- kfree(per_cpu(xen_debug_irq, cpu).name);
4206 +- per_cpu(xen_debug_irq, cpu).name = NULL;
4207 + }
4208 ++ kfree(per_cpu(xen_callfuncsingle_irq, cpu).name);
4209 ++ per_cpu(xen_callfuncsingle_irq, cpu).name = NULL;
4210 + if (per_cpu(xen_callfuncsingle_irq, cpu).irq >= 0) {
4211 + unbind_from_irqhandler(per_cpu(xen_callfuncsingle_irq, cpu).irq,
4212 + NULL);
4213 + per_cpu(xen_callfuncsingle_irq, cpu).irq = -1;
4214 +- kfree(per_cpu(xen_callfuncsingle_irq, cpu).name);
4215 +- per_cpu(xen_callfuncsingle_irq, cpu).name = NULL;
4216 + }
4217 + }
4218 +
4219 +@@ -65,6 +65,7 @@ int xen_smp_intr_init(unsigned int cpu)
4220 + char *resched_name, *callfunc_name, *debug_name;
4221 +
4222 + resched_name = kasprintf(GFP_KERNEL, "resched%d", cpu);
4223 ++ per_cpu(xen_resched_irq, cpu).name = resched_name;
4224 + rc = bind_ipi_to_irqhandler(XEN_RESCHEDULE_VECTOR,
4225 + cpu,
4226 + xen_reschedule_interrupt,
4227 +@@ -74,9 +75,9 @@ int xen_smp_intr_init(unsigned int cpu)
4228 + if (rc < 0)
4229 + goto fail;
4230 + per_cpu(xen_resched_irq, cpu).irq = rc;
4231 +- per_cpu(xen_resched_irq, cpu).name = resched_name;
4232 +
4233 + callfunc_name = kasprintf(GFP_KERNEL, "callfunc%d", cpu);
4234 ++ per_cpu(xen_callfunc_irq, cpu).name = callfunc_name;
4235 + rc = bind_ipi_to_irqhandler(XEN_CALL_FUNCTION_VECTOR,
4236 + cpu,
4237 + xen_call_function_interrupt,
4238 +@@ -86,10 +87,10 @@ int xen_smp_intr_init(unsigned int cpu)
4239 + if (rc < 0)
4240 + goto fail;
4241 + per_cpu(xen_callfunc_irq, cpu).irq = rc;
4242 +- per_cpu(xen_callfunc_irq, cpu).name = callfunc_name;
4243 +
4244 + if (!xen_fifo_events) {
4245 + debug_name = kasprintf(GFP_KERNEL, "debug%d", cpu);
4246 ++ per_cpu(xen_debug_irq, cpu).name = debug_name;
4247 + rc = bind_virq_to_irqhandler(VIRQ_DEBUG, cpu,
4248 + xen_debug_interrupt,
4249 + IRQF_PERCPU | IRQF_NOBALANCING,
4250 +@@ -97,10 +98,10 @@ int xen_smp_intr_init(unsigned int cpu)
4251 + if (rc < 0)
4252 + goto fail;
4253 + per_cpu(xen_debug_irq, cpu).irq = rc;
4254 +- per_cpu(xen_debug_irq, cpu).name = debug_name;
4255 + }
4256 +
4257 + callfunc_name = kasprintf(GFP_KERNEL, "callfuncsingle%d", cpu);
4258 ++ per_cpu(xen_callfuncsingle_irq, cpu).name = callfunc_name;
4259 + rc = bind_ipi_to_irqhandler(XEN_CALL_FUNCTION_SINGLE_VECTOR,
4260 + cpu,
4261 + xen_call_function_single_interrupt,
4262 +@@ -110,7 +111,6 @@ int xen_smp_intr_init(unsigned int cpu)
4263 + if (rc < 0)
4264 + goto fail;
4265 + per_cpu(xen_callfuncsingle_irq, cpu).irq = rc;
4266 +- per_cpu(xen_callfuncsingle_irq, cpu).name = callfunc_name;
4267 +
4268 + return 0;
4269 +
4270 +diff --git a/arch/x86/xen/smp_pv.c b/arch/x86/xen/smp_pv.c
4271 +index ba7af2eca755b..cd80f8422e173 100644
4272 +--- a/arch/x86/xen/smp_pv.c
4273 ++++ b/arch/x86/xen/smp_pv.c
4274 +@@ -97,18 +97,18 @@ asmlinkage __visible void cpu_bringup_and_idle(void)
4275 +
4276 + void xen_smp_intr_free_pv(unsigned int cpu)
4277 + {
4278 ++ kfree(per_cpu(xen_irq_work, cpu).name);
4279 ++ per_cpu(xen_irq_work, cpu).name = NULL;
4280 + if (per_cpu(xen_irq_work, cpu).irq >= 0) {
4281 + unbind_from_irqhandler(per_cpu(xen_irq_work, cpu).irq, NULL);
4282 + per_cpu(xen_irq_work, cpu).irq = -1;
4283 +- kfree(per_cpu(xen_irq_work, cpu).name);
4284 +- per_cpu(xen_irq_work, cpu).name = NULL;
4285 + }
4286 +
4287 ++ kfree(per_cpu(xen_pmu_irq, cpu).name);
4288 ++ per_cpu(xen_pmu_irq, cpu).name = NULL;
4289 + if (per_cpu(xen_pmu_irq, cpu).irq >= 0) {
4290 + unbind_from_irqhandler(per_cpu(xen_pmu_irq, cpu).irq, NULL);
4291 + per_cpu(xen_pmu_irq, cpu).irq = -1;
4292 +- kfree(per_cpu(xen_pmu_irq, cpu).name);
4293 +- per_cpu(xen_pmu_irq, cpu).name = NULL;
4294 + }
4295 + }
4296 +
4297 +@@ -118,6 +118,7 @@ int xen_smp_intr_init_pv(unsigned int cpu)
4298 + char *callfunc_name, *pmu_name;
4299 +
4300 + callfunc_name = kasprintf(GFP_KERNEL, "irqwork%d", cpu);
4301 ++ per_cpu(xen_irq_work, cpu).name = callfunc_name;
4302 + rc = bind_ipi_to_irqhandler(XEN_IRQ_WORK_VECTOR,
4303 + cpu,
4304 + xen_irq_work_interrupt,
4305 +@@ -127,10 +128,10 @@ int xen_smp_intr_init_pv(unsigned int cpu)
4306 + if (rc < 0)
4307 + goto fail;
4308 + per_cpu(xen_irq_work, cpu).irq = rc;
4309 +- per_cpu(xen_irq_work, cpu).name = callfunc_name;
4310 +
4311 + if (is_xen_pmu) {
4312 + pmu_name = kasprintf(GFP_KERNEL, "pmu%d", cpu);
4313 ++ per_cpu(xen_pmu_irq, cpu).name = pmu_name;
4314 + rc = bind_virq_to_irqhandler(VIRQ_XENPMU, cpu,
4315 + xen_pmu_irq_handler,
4316 + IRQF_PERCPU|IRQF_NOBALANCING,
4317 +@@ -138,7 +139,6 @@ int xen_smp_intr_init_pv(unsigned int cpu)
4318 + if (rc < 0)
4319 + goto fail;
4320 + per_cpu(xen_pmu_irq, cpu).irq = rc;
4321 +- per_cpu(xen_pmu_irq, cpu).name = pmu_name;
4322 + }
4323 +
4324 + return 0;
4325 +diff --git a/arch/x86/xen/spinlock.c b/arch/x86/xen/spinlock.c
4326 +index 043c73dfd2c98..5c6fc16e4b925 100644
4327 +--- a/arch/x86/xen/spinlock.c
4328 ++++ b/arch/x86/xen/spinlock.c
4329 +@@ -75,6 +75,7 @@ void xen_init_lock_cpu(int cpu)
4330 + cpu, per_cpu(lock_kicker_irq, cpu));
4331 +
4332 + name = kasprintf(GFP_KERNEL, "spinlock%d", cpu);
4333 ++ per_cpu(irq_name, cpu) = name;
4334 + irq = bind_ipi_to_irqhandler(XEN_SPIN_UNLOCK_VECTOR,
4335 + cpu,
4336 + dummy_handler,
4337 +@@ -85,7 +86,6 @@ void xen_init_lock_cpu(int cpu)
4338 + if (irq >= 0) {
4339 + disable_irq(irq); /* make sure it's never delivered */
4340 + per_cpu(lock_kicker_irq, cpu) = irq;
4341 +- per_cpu(irq_name, cpu) = name;
4342 + }
4343 +
4344 + printk("cpu %d spinlock event irq %d\n", cpu, irq);
4345 +@@ -98,6 +98,8 @@ void xen_uninit_lock_cpu(int cpu)
4346 + if (!xen_pvspin)
4347 + return;
4348 +
4349 ++ kfree(per_cpu(irq_name, cpu));
4350 ++ per_cpu(irq_name, cpu) = NULL;
4351 + /*
4352 + * When booting the kernel with 'mitigations=auto,nosmt', the secondary
4353 + * CPUs are not activated, and lock_kicker_irq is not initialized.
4354 +@@ -108,8 +110,6 @@ void xen_uninit_lock_cpu(int cpu)
4355 +
4356 + unbind_from_irqhandler(irq, NULL);
4357 + per_cpu(lock_kicker_irq, cpu) = -1;
4358 +- kfree(per_cpu(irq_name, cpu));
4359 +- per_cpu(irq_name, cpu) = NULL;
4360 + }
4361 +
4362 + PV_CALLEE_SAVE_REGS_THUNK(xen_vcpu_stolen);
4363 +diff --git a/block/bfq-iosched.c b/block/bfq-iosched.c
4364 +index c740b41fe0a49..528ca21044a57 100644
4365 +--- a/block/bfq-iosched.c
4366 ++++ b/block/bfq-iosched.c
4367 +@@ -386,6 +386,12 @@ static void bfq_put_stable_ref(struct bfq_queue *bfqq);
4368 +
4369 + void bic_set_bfqq(struct bfq_io_cq *bic, struct bfq_queue *bfqq, bool is_sync)
4370 + {
4371 ++ struct bfq_queue *old_bfqq = bic->bfqq[is_sync];
4372 ++
4373 ++ /* Clear bic pointer if bfqq is detached from this bic */
4374 ++ if (old_bfqq && old_bfqq->bic == bic)
4375 ++ old_bfqq->bic = NULL;
4376 ++
4377 + /*
4378 + * If bfqq != NULL, then a non-stable queue merge between
4379 + * bic->bfqq and bfqq is happening here. This causes troubles
4380 +@@ -5379,7 +5385,6 @@ static void bfq_exit_icq_bfqq(struct bfq_io_cq *bic, bool is_sync)
4381 + unsigned long flags;
4382 +
4383 + spin_lock_irqsave(&bfqd->lock, flags);
4384 +- bfqq->bic = NULL;
4385 + bfq_exit_bfqq(bfqd, bfqq);
4386 + bic_set_bfqq(bic, NULL, is_sync);
4387 + spin_unlock_irqrestore(&bfqd->lock, flags);
4388 +@@ -6786,6 +6791,12 @@ static struct bfq_queue *bfq_init_rq(struct request *rq)
4389 + bfqq = bfq_get_bfqq_handle_split(bfqd, bic, bio,
4390 + true, is_sync,
4391 + NULL);
4392 ++ if (unlikely(bfqq == &bfqd->oom_bfqq))
4393 ++ bfqq_already_existing = true;
4394 ++ } else
4395 ++ bfqq_already_existing = true;
4396 ++
4397 ++ if (!bfqq_already_existing) {
4398 + bfqq->waker_bfqq = old_bfqq->waker_bfqq;
4399 + bfqq->tentative_waker_bfqq = NULL;
4400 +
4401 +@@ -6799,8 +6810,7 @@ static struct bfq_queue *bfq_init_rq(struct request *rq)
4402 + if (bfqq->waker_bfqq)
4403 + hlist_add_head(&bfqq->woken_list_node,
4404 + &bfqq->waker_bfqq->woken_list);
4405 +- } else
4406 +- bfqq_already_existing = true;
4407 ++ }
4408 + }
4409 + }
4410 +
4411 +diff --git a/block/blk-mq-sysfs.c b/block/blk-mq-sysfs.c
4412 +index 93997d297d427..4515288fbe351 100644
4413 +--- a/block/blk-mq-sysfs.c
4414 ++++ b/block/blk-mq-sysfs.c
4415 +@@ -185,7 +185,7 @@ static int blk_mq_register_hctx(struct blk_mq_hw_ctx *hctx)
4416 + {
4417 + struct request_queue *q = hctx->queue;
4418 + struct blk_mq_ctx *ctx;
4419 +- int i, ret;
4420 ++ int i, j, ret;
4421 +
4422 + if (!hctx->nr_ctx)
4423 + return 0;
4424 +@@ -197,9 +197,16 @@ static int blk_mq_register_hctx(struct blk_mq_hw_ctx *hctx)
4425 + hctx_for_each_ctx(hctx, ctx, i) {
4426 + ret = kobject_add(&ctx->kobj, &hctx->kobj, "cpu%u", ctx->cpu);
4427 + if (ret)
4428 +- break;
4429 ++ goto out;
4430 + }
4431 +
4432 ++ return 0;
4433 ++out:
4434 ++ hctx_for_each_ctx(hctx, ctx, j) {
4435 ++ if (j < i)
4436 ++ kobject_del(&ctx->kobj);
4437 ++ }
4438 ++ kobject_del(&hctx->kobj);
4439 + return ret;
4440 + }
4441 +
4442 +diff --git a/block/blk-mq.c b/block/blk-mq.c
4443 +index 3f1f5e3e0951d..1a30f65802749 100644
4444 +--- a/block/blk-mq.c
4445 ++++ b/block/blk-mq.c
4446 +@@ -1442,7 +1442,13 @@ static void blk_mq_rq_timed_out(struct request *req)
4447 + blk_add_timer(req);
4448 + }
4449 +
4450 +-static bool blk_mq_req_expired(struct request *rq, unsigned long *next)
4451 ++struct blk_expired_data {
4452 ++ bool has_timedout_rq;
4453 ++ unsigned long next;
4454 ++ unsigned long timeout_start;
4455 ++};
4456 ++
4457 ++static bool blk_mq_req_expired(struct request *rq, struct blk_expired_data *expired)
4458 + {
4459 + unsigned long deadline;
4460 +
4461 +@@ -1452,13 +1458,13 @@ static bool blk_mq_req_expired(struct request *rq, unsigned long *next)
4462 + return false;
4463 +
4464 + deadline = READ_ONCE(rq->deadline);
4465 +- if (time_after_eq(jiffies, deadline))
4466 ++ if (time_after_eq(expired->timeout_start, deadline))
4467 + return true;
4468 +
4469 +- if (*next == 0)
4470 +- *next = deadline;
4471 +- else if (time_after(*next, deadline))
4472 +- *next = deadline;
4473 ++ if (expired->next == 0)
4474 ++ expired->next = deadline;
4475 ++ else if (time_after(expired->next, deadline))
4476 ++ expired->next = deadline;
4477 + return false;
4478 + }
4479 +
4480 +@@ -1472,7 +1478,7 @@ void blk_mq_put_rq_ref(struct request *rq)
4481 +
4482 + static bool blk_mq_check_expired(struct request *rq, void *priv)
4483 + {
4484 +- unsigned long *next = priv;
4485 ++ struct blk_expired_data *expired = priv;
4486 +
4487 + /*
4488 + * blk_mq_queue_tag_busy_iter() has locked the request, so it cannot
4489 +@@ -1481,7 +1487,18 @@ static bool blk_mq_check_expired(struct request *rq, void *priv)
4490 + * it was completed and reallocated as a new request after returning
4491 + * from blk_mq_check_expired().
4492 + */
4493 +- if (blk_mq_req_expired(rq, next))
4494 ++ if (blk_mq_req_expired(rq, expired)) {
4495 ++ expired->has_timedout_rq = true;
4496 ++ return false;
4497 ++ }
4498 ++ return true;
4499 ++}
4500 ++
4501 ++static bool blk_mq_handle_expired(struct request *rq, void *priv)
4502 ++{
4503 ++ struct blk_expired_data *expired = priv;
4504 ++
4505 ++ if (blk_mq_req_expired(rq, expired))
4506 + blk_mq_rq_timed_out(rq);
4507 + return true;
4508 + }
4509 +@@ -1490,7 +1507,9 @@ static void blk_mq_timeout_work(struct work_struct *work)
4510 + {
4511 + struct request_queue *q =
4512 + container_of(work, struct request_queue, timeout_work);
4513 +- unsigned long next = 0;
4514 ++ struct blk_expired_data expired = {
4515 ++ .timeout_start = jiffies,
4516 ++ };
4517 + struct blk_mq_hw_ctx *hctx;
4518 + unsigned long i;
4519 +
4520 +@@ -1510,10 +1529,23 @@ static void blk_mq_timeout_work(struct work_struct *work)
4521 + if (!percpu_ref_tryget(&q->q_usage_counter))
4522 + return;
4523 +
4524 +- blk_mq_queue_tag_busy_iter(q, blk_mq_check_expired, &next);
4525 ++ /* check if there is any timed-out request */
4526 ++ blk_mq_queue_tag_busy_iter(q, blk_mq_check_expired, &expired);
4527 ++ if (expired.has_timedout_rq) {
4528 ++ /*
4529 ++ * Before walking tags, we must ensure any submit started
4530 ++ * before the current time has finished. Since the submit
4531 ++ * uses srcu or rcu, wait for a synchronization point to
4532 ++ * ensure all running submits have finished
4533 ++ */
4534 ++ blk_mq_wait_quiesce_done(q);
4535 ++
4536 ++ expired.next = 0;
4537 ++ blk_mq_queue_tag_busy_iter(q, blk_mq_handle_expired, &expired);
4538 ++ }
4539 +
4540 +- if (next != 0) {
4541 +- mod_timer(&q->timeout, next);
4542 ++ if (expired.next != 0) {
4543 ++ mod_timer(&q->timeout, expired.next);
4544 + } else {
4545 + /*
4546 + * Request timeouts are handled as a forward rolling timer. If
4547 +diff --git a/block/genhd.c b/block/genhd.c
4548 +index 044ff97381e33..28654723bc2b2 100644
4549 +--- a/block/genhd.c
4550 ++++ b/block/genhd.c
4551 +@@ -522,6 +522,7 @@ out_unregister_queue:
4552 + rq_qos_exit(disk->queue);
4553 + out_put_slave_dir:
4554 + kobject_put(disk->slave_dir);
4555 ++ disk->slave_dir = NULL;
4556 + out_put_holder_dir:
4557 + kobject_put(disk->part0->bd_holder_dir);
4558 + out_del_integrity:
4559 +@@ -618,6 +619,7 @@ void del_gendisk(struct gendisk *disk)
4560 +
4561 + kobject_put(disk->part0->bd_holder_dir);
4562 + kobject_put(disk->slave_dir);
4563 ++ disk->slave_dir = NULL;
4564 +
4565 + part_stat_set_all(disk->part0, 0);
4566 + disk->part0->bd_stamp = 0;
4567 +diff --git a/crypto/cryptd.c b/crypto/cryptd.c
4568 +index 668095eca0faf..ca3a40fc7da91 100644
4569 +--- a/crypto/cryptd.c
4570 ++++ b/crypto/cryptd.c
4571 +@@ -68,11 +68,12 @@ struct aead_instance_ctx {
4572 +
4573 + struct cryptd_skcipher_ctx {
4574 + refcount_t refcnt;
4575 +- struct crypto_sync_skcipher *child;
4576 ++ struct crypto_skcipher *child;
4577 + };
4578 +
4579 + struct cryptd_skcipher_request_ctx {
4580 + crypto_completion_t complete;
4581 ++ struct skcipher_request req;
4582 + };
4583 +
4584 + struct cryptd_hash_ctx {
4585 +@@ -227,13 +228,13 @@ static int cryptd_skcipher_setkey(struct crypto_skcipher *parent,
4586 + const u8 *key, unsigned int keylen)
4587 + {
4588 + struct cryptd_skcipher_ctx *ctx = crypto_skcipher_ctx(parent);
4589 +- struct crypto_sync_skcipher *child = ctx->child;
4590 ++ struct crypto_skcipher *child = ctx->child;
4591 +
4592 +- crypto_sync_skcipher_clear_flags(child, CRYPTO_TFM_REQ_MASK);
4593 +- crypto_sync_skcipher_set_flags(child,
4594 +- crypto_skcipher_get_flags(parent) &
4595 +- CRYPTO_TFM_REQ_MASK);
4596 +- return crypto_sync_skcipher_setkey(child, key, keylen);
4597 ++ crypto_skcipher_clear_flags(child, CRYPTO_TFM_REQ_MASK);
4598 ++ crypto_skcipher_set_flags(child,
4599 ++ crypto_skcipher_get_flags(parent) &
4600 ++ CRYPTO_TFM_REQ_MASK);
4601 ++ return crypto_skcipher_setkey(child, key, keylen);
4602 + }
4603 +
4604 + static void cryptd_skcipher_complete(struct skcipher_request *req, int err)
4605 +@@ -258,13 +259,13 @@ static void cryptd_skcipher_encrypt(struct crypto_async_request *base,
4606 + struct cryptd_skcipher_request_ctx *rctx = skcipher_request_ctx(req);
4607 + struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
4608 + struct cryptd_skcipher_ctx *ctx = crypto_skcipher_ctx(tfm);
4609 +- struct crypto_sync_skcipher *child = ctx->child;
4610 +- SYNC_SKCIPHER_REQUEST_ON_STACK(subreq, child);
4611 ++ struct skcipher_request *subreq = &rctx->req;
4612 ++ struct crypto_skcipher *child = ctx->child;
4613 +
4614 + if (unlikely(err == -EINPROGRESS))
4615 + goto out;
4616 +
4617 +- skcipher_request_set_sync_tfm(subreq, child);
4618 ++ skcipher_request_set_tfm(subreq, child);
4619 + skcipher_request_set_callback(subreq, CRYPTO_TFM_REQ_MAY_SLEEP,
4620 + NULL, NULL);
4621 + skcipher_request_set_crypt(subreq, req->src, req->dst, req->cryptlen,
4622 +@@ -286,13 +287,13 @@ static void cryptd_skcipher_decrypt(struct crypto_async_request *base,
4623 + struct cryptd_skcipher_request_ctx *rctx = skcipher_request_ctx(req);
4624 + struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
4625 + struct cryptd_skcipher_ctx *ctx = crypto_skcipher_ctx(tfm);
4626 +- struct crypto_sync_skcipher *child = ctx->child;
4627 +- SYNC_SKCIPHER_REQUEST_ON_STACK(subreq, child);
4628 ++ struct skcipher_request *subreq = &rctx->req;
4629 ++ struct crypto_skcipher *child = ctx->child;
4630 +
4631 + if (unlikely(err == -EINPROGRESS))
4632 + goto out;
4633 +
4634 +- skcipher_request_set_sync_tfm(subreq, child);
4635 ++ skcipher_request_set_tfm(subreq, child);
4636 + skcipher_request_set_callback(subreq, CRYPTO_TFM_REQ_MAY_SLEEP,
4637 + NULL, NULL);
4638 + skcipher_request_set_crypt(subreq, req->src, req->dst, req->cryptlen,
4639 +@@ -343,9 +344,10 @@ static int cryptd_skcipher_init_tfm(struct crypto_skcipher *tfm)
4640 + if (IS_ERR(cipher))
4641 + return PTR_ERR(cipher);
4642 +
4643 +- ctx->child = (struct crypto_sync_skcipher *)cipher;
4644 ++ ctx->child = cipher;
4645 + crypto_skcipher_set_reqsize(
4646 +- tfm, sizeof(struct cryptd_skcipher_request_ctx));
4647 ++ tfm, sizeof(struct cryptd_skcipher_request_ctx) +
4648 ++ crypto_skcipher_reqsize(cipher));
4649 + return 0;
4650 + }
4651 +
4652 +@@ -353,7 +355,7 @@ static void cryptd_skcipher_exit_tfm(struct crypto_skcipher *tfm)
4653 + {
4654 + struct cryptd_skcipher_ctx *ctx = crypto_skcipher_ctx(tfm);
4655 +
4656 +- crypto_free_sync_skcipher(ctx->child);
4657 ++ crypto_free_skcipher(ctx->child);
4658 + }
4659 +
4660 + static void cryptd_skcipher_free(struct skcipher_instance *inst)
4661 +@@ -931,7 +933,7 @@ struct crypto_skcipher *cryptd_skcipher_child(struct cryptd_skcipher *tfm)
4662 + {
4663 + struct cryptd_skcipher_ctx *ctx = crypto_skcipher_ctx(&tfm->base);
4664 +
4665 +- return &ctx->child->base;
4666 ++ return ctx->child;
4667 + }
4668 + EXPORT_SYMBOL_GPL(cryptd_skcipher_child);
4669 +
4670 +diff --git a/crypto/tcrypt.c b/crypto/tcrypt.c
4671 +index 59eb8ec366643..bc57b182f3047 100644
4672 +--- a/crypto/tcrypt.c
4673 ++++ b/crypto/tcrypt.c
4674 +@@ -1101,15 +1101,6 @@ static void test_mb_skcipher_speed(const char *algo, int enc, int secs,
4675 + goto out_free_tfm;
4676 + }
4677 +
4678 +-
4679 +- for (i = 0; i < num_mb; ++i)
4680 +- if (testmgr_alloc_buf(data[i].xbuf)) {
4681 +- while (i--)
4682 +- testmgr_free_buf(data[i].xbuf);
4683 +- goto out_free_tfm;
4684 +- }
4685 +-
4686 +-
4687 + for (i = 0; i < num_mb; ++i) {
4688 + data[i].req = skcipher_request_alloc(tfm, GFP_KERNEL);
4689 + if (!data[i].req) {
4690 +@@ -1494,387 +1485,387 @@ static int do_test(const char *alg, u32 type, u32 mask, int m, u32 num_mb)
4691 + }
4692 +
4693 + for (i = 1; i < 200; i++)
4694 +- ret += do_test(NULL, 0, 0, i, num_mb);
4695 ++ ret = min(ret, do_test(NULL, 0, 0, i, num_mb));
4696 + break;
4697 +
4698 + case 1:
4699 +- ret += tcrypt_test("md5");
4700 ++ ret = min(ret, tcrypt_test("md5"));
4701 + break;
4702 +
4703 + case 2:
4704 +- ret += tcrypt_test("sha1");
4705 ++ ret = min(ret, tcrypt_test("sha1"));
4706 + break;
4707 +
4708 + case 3:
4709 +- ret += tcrypt_test("ecb(des)");
4710 +- ret += tcrypt_test("cbc(des)");
4711 +- ret += tcrypt_test("ctr(des)");
4712 ++ ret = min(ret, tcrypt_test("ecb(des)"));
4713 ++ ret = min(ret, tcrypt_test("cbc(des)"));
4714 ++ ret = min(ret, tcrypt_test("ctr(des)"));
4715 + break;
4716 +
4717 + case 4:
4718 +- ret += tcrypt_test("ecb(des3_ede)");
4719 +- ret += tcrypt_test("cbc(des3_ede)");
4720 +- ret += tcrypt_test("ctr(des3_ede)");
4721 ++ ret = min(ret, tcrypt_test("ecb(des3_ede)"));
4722 ++ ret = min(ret, tcrypt_test("cbc(des3_ede)"));
4723 ++ ret = min(ret, tcrypt_test("ctr(des3_ede)"));
4724 + break;
4725 +
4726 + case 5:
4727 +- ret += tcrypt_test("md4");
4728 ++ ret = min(ret, tcrypt_test("md4"));
4729 + break;
4730 +
4731 + case 6:
4732 +- ret += tcrypt_test("sha256");
4733 ++ ret = min(ret, tcrypt_test("sha256"));
4734 + break;
4735 +
4736 + case 7:
4737 +- ret += tcrypt_test("ecb(blowfish)");
4738 +- ret += tcrypt_test("cbc(blowfish)");
4739 +- ret += tcrypt_test("ctr(blowfish)");
4740 ++ ret = min(ret, tcrypt_test("ecb(blowfish)"));
4741 ++ ret = min(ret, tcrypt_test("cbc(blowfish)"));
4742 ++ ret = min(ret, tcrypt_test("ctr(blowfish)"));
4743 + break;
4744 +
4745 + case 8:
4746 +- ret += tcrypt_test("ecb(twofish)");
4747 +- ret += tcrypt_test("cbc(twofish)");
4748 +- ret += tcrypt_test("ctr(twofish)");
4749 +- ret += tcrypt_test("lrw(twofish)");
4750 +- ret += tcrypt_test("xts(twofish)");
4751 ++ ret = min(ret, tcrypt_test("ecb(twofish)"));
4752 ++ ret = min(ret, tcrypt_test("cbc(twofish)"));
4753 ++ ret = min(ret, tcrypt_test("ctr(twofish)"));
4754 ++ ret = min(ret, tcrypt_test("lrw(twofish)"));
4755 ++ ret = min(ret, tcrypt_test("xts(twofish)"));
4756 + break;
4757 +
4758 + case 9:
4759 +- ret += tcrypt_test("ecb(serpent)");
4760 +- ret += tcrypt_test("cbc(serpent)");
4761 +- ret += tcrypt_test("ctr(serpent)");
4762 +- ret += tcrypt_test("lrw(serpent)");
4763 +- ret += tcrypt_test("xts(serpent)");
4764 ++ ret = min(ret, tcrypt_test("ecb(serpent)"));
4765 ++ ret = min(ret, tcrypt_test("cbc(serpent)"));
4766 ++ ret = min(ret, tcrypt_test("ctr(serpent)"));
4767 ++ ret = min(ret, tcrypt_test("lrw(serpent)"));
4768 ++ ret = min(ret, tcrypt_test("xts(serpent)"));
4769 + break;
4770 +
4771 + case 10:
4772 +- ret += tcrypt_test("ecb(aes)");
4773 +- ret += tcrypt_test("cbc(aes)");
4774 +- ret += tcrypt_test("lrw(aes)");
4775 +- ret += tcrypt_test("xts(aes)");
4776 +- ret += tcrypt_test("ctr(aes)");
4777 +- ret += tcrypt_test("rfc3686(ctr(aes))");
4778 +- ret += tcrypt_test("ofb(aes)");
4779 +- ret += tcrypt_test("cfb(aes)");
4780 +- ret += tcrypt_test("xctr(aes)");
4781 ++ ret = min(ret, tcrypt_test("ecb(aes)"));
4782 ++ ret = min(ret, tcrypt_test("cbc(aes)"));
4783 ++ ret = min(ret, tcrypt_test("lrw(aes)"));
4784 ++ ret = min(ret, tcrypt_test("xts(aes)"));
4785 ++ ret = min(ret, tcrypt_test("ctr(aes)"));
4786 ++ ret = min(ret, tcrypt_test("rfc3686(ctr(aes))"));
4787 ++ ret = min(ret, tcrypt_test("ofb(aes)"));
4788 ++ ret = min(ret, tcrypt_test("cfb(aes)"));
4789 ++ ret = min(ret, tcrypt_test("xctr(aes)"));
4790 + break;
4791 +
4792 + case 11:
4793 +- ret += tcrypt_test("sha384");
4794 ++ ret = min(ret, tcrypt_test("sha384"));
4795 + break;
4796 +
4797 + case 12:
4798 +- ret += tcrypt_test("sha512");
4799 ++ ret = min(ret, tcrypt_test("sha512"));
4800 + break;
4801 +
4802 + case 13:
4803 +- ret += tcrypt_test("deflate");
4804 ++ ret = min(ret, tcrypt_test("deflate"));
4805 + break;
4806 +
4807 + case 14:
4808 +- ret += tcrypt_test("ecb(cast5)");
4809 +- ret += tcrypt_test("cbc(cast5)");
4810 +- ret += tcrypt_test("ctr(cast5)");
4811 ++ ret = min(ret, tcrypt_test("ecb(cast5)"));
4812 ++ ret = min(ret, tcrypt_test("cbc(cast5)"));
4813 ++ ret = min(ret, tcrypt_test("ctr(cast5)"));
4814 + break;
4815 +
4816 + case 15:
4817 +- ret += tcrypt_test("ecb(cast6)");
4818 +- ret += tcrypt_test("cbc(cast6)");
4819 +- ret += tcrypt_test("ctr(cast6)");
4820 +- ret += tcrypt_test("lrw(cast6)");
4821 +- ret += tcrypt_test("xts(cast6)");
4822 ++ ret = min(ret, tcrypt_test("ecb(cast6)"));
4823 ++ ret = min(ret, tcrypt_test("cbc(cast6)"));
4824 ++ ret = min(ret, tcrypt_test("ctr(cast6)"));
4825 ++ ret = min(ret, tcrypt_test("lrw(cast6)"));
4826 ++ ret = min(ret, tcrypt_test("xts(cast6)"));
4827 + break;
4828 +
4829 + case 16:
4830 +- ret += tcrypt_test("ecb(arc4)");
4831 ++ ret = min(ret, tcrypt_test("ecb(arc4)"));
4832 + break;
4833 +
4834 + case 17:
4835 +- ret += tcrypt_test("michael_mic");
4836 ++ ret = min(ret, tcrypt_test("michael_mic"));
4837 + break;
4838 +
4839 + case 18:
4840 +- ret += tcrypt_test("crc32c");
4841 ++ ret = min(ret, tcrypt_test("crc32c"));
4842 + break;
4843 +
4844 + case 19:
4845 +- ret += tcrypt_test("ecb(tea)");
4846 ++ ret = min(ret, tcrypt_test("ecb(tea)"));
4847 + break;
4848 +
4849 + case 20:
4850 +- ret += tcrypt_test("ecb(xtea)");
4851 ++ ret = min(ret, tcrypt_test("ecb(xtea)"));
4852 + break;
4853 +
4854 + case 21:
4855 +- ret += tcrypt_test("ecb(khazad)");
4856 ++ ret = min(ret, tcrypt_test("ecb(khazad)"));
4857 + break;
4858 +
4859 + case 22:
4860 +- ret += tcrypt_test("wp512");
4861 ++ ret = min(ret, tcrypt_test("wp512"));
4862 + break;
4863 +
4864 + case 23:
4865 +- ret += tcrypt_test("wp384");
4866 ++ ret = min(ret, tcrypt_test("wp384"));
4867 + break;
4868 +
4869 + case 24:
4870 +- ret += tcrypt_test("wp256");
4871 ++ ret = min(ret, tcrypt_test("wp256"));
4872 + break;
4873 +
4874 + case 26:
4875 +- ret += tcrypt_test("ecb(anubis)");
4876 +- ret += tcrypt_test("cbc(anubis)");
4877 ++ ret = min(ret, tcrypt_test("ecb(anubis)"));
4878 ++ ret = min(ret, tcrypt_test("cbc(anubis)"));
4879 + break;
4880 +
4881 + case 30:
4882 +- ret += tcrypt_test("ecb(xeta)");
4883 ++ ret = min(ret, tcrypt_test("ecb(xeta)"));
4884 + break;
4885 +
4886 + case 31:
4887 +- ret += tcrypt_test("pcbc(fcrypt)");
4888 ++ ret = min(ret, tcrypt_test("pcbc(fcrypt)"));
4889 + break;
4890 +
4891 + case 32:
4892 +- ret += tcrypt_test("ecb(camellia)");
4893 +- ret += tcrypt_test("cbc(camellia)");
4894 +- ret += tcrypt_test("ctr(camellia)");
4895 +- ret += tcrypt_test("lrw(camellia)");
4896 +- ret += tcrypt_test("xts(camellia)");
4897 ++ ret = min(ret, tcrypt_test("ecb(camellia)"));
4898 ++ ret = min(ret, tcrypt_test("cbc(camellia)"));
4899 ++ ret = min(ret, tcrypt_test("ctr(camellia)"));
4900 ++ ret = min(ret, tcrypt_test("lrw(camellia)"));
4901 ++ ret = min(ret, tcrypt_test("xts(camellia)"));
4902 + break;
4903 +
4904 + case 33:
4905 +- ret += tcrypt_test("sha224");
4906 ++ ret = min(ret, tcrypt_test("sha224"));
4907 + break;
4908 +
4909 + case 35:
4910 +- ret += tcrypt_test("gcm(aes)");
4911 ++ ret = min(ret, tcrypt_test("gcm(aes)"));
4912 + break;
4913 +
4914 + case 36:
4915 +- ret += tcrypt_test("lzo");
4916 ++ ret = min(ret, tcrypt_test("lzo"));
4917 + break;
4918 +
4919 + case 37:
4920 +- ret += tcrypt_test("ccm(aes)");
4921 ++ ret = min(ret, tcrypt_test("ccm(aes)"));
4922 + break;
4923 +
4924 + case 38:
4925 +- ret += tcrypt_test("cts(cbc(aes))");
4926 ++ ret = min(ret, tcrypt_test("cts(cbc(aes))"));
4927 + break;
4928 +
4929 + case 39:
4930 +- ret += tcrypt_test("xxhash64");
4931 ++ ret = min(ret, tcrypt_test("xxhash64"));
4932 + break;
4933 +
4934 + case 40:
4935 +- ret += tcrypt_test("rmd160");
4936 ++ ret = min(ret, tcrypt_test("rmd160"));
4937 + break;
4938 +
4939 + case 42:
4940 +- ret += tcrypt_test("blake2b-512");
4941 ++ ret = min(ret, tcrypt_test("blake2b-512"));
4942 + break;
4943 +
4944 + case 43:
4945 +- ret += tcrypt_test("ecb(seed)");
4946 ++ ret = min(ret, tcrypt_test("ecb(seed)"));
4947 + break;
4948 +
4949 + case 45:
4950 +- ret += tcrypt_test("rfc4309(ccm(aes))");
4951 ++ ret = min(ret, tcrypt_test("rfc4309(ccm(aes))"));
4952 + break;
4953 +
4954 + case 46:
4955 +- ret += tcrypt_test("ghash");
4956 ++ ret = min(ret, tcrypt_test("ghash"));
4957 + break;
4958 +
4959 + case 47:
4960 +- ret += tcrypt_test("crct10dif");
4961 ++ ret = min(ret, tcrypt_test("crct10dif"));
4962 + break;
4963 +
4964 + case 48:
4965 +- ret += tcrypt_test("sha3-224");
4966 ++ ret = min(ret, tcrypt_test("sha3-224"));
4967 + break;
4968 +
4969 + case 49:
4970 +- ret += tcrypt_test("sha3-256");
4971 ++ ret = min(ret, tcrypt_test("sha3-256"));
4972 + break;
4973 +
4974 + case 50:
4975 +- ret += tcrypt_test("sha3-384");
4976 ++ ret = min(ret, tcrypt_test("sha3-384"));
4977 + break;
4978 +
4979 + case 51:
4980 +- ret += tcrypt_test("sha3-512");
4981 ++ ret = min(ret, tcrypt_test("sha3-512"));
4982 + break;
4983 +
4984 + case 52:
4985 +- ret += tcrypt_test("sm3");
4986 ++ ret = min(ret, tcrypt_test("sm3"));
4987 + break;
4988 +
4989 + case 53:
4990 +- ret += tcrypt_test("streebog256");
4991 ++ ret = min(ret, tcrypt_test("streebog256"));
4992 + break;
4993 +
4994 + case 54:
4995 +- ret += tcrypt_test("streebog512");
4996 ++ ret = min(ret, tcrypt_test("streebog512"));
4997 + break;
4998 +
4999 + case 55:
5000 +- ret += tcrypt_test("gcm(sm4)");
5001 ++ ret = min(ret, tcrypt_test("gcm(sm4)"));
5002 + break;
5003 +
5004 + case 56:
5005 +- ret += tcrypt_test("ccm(sm4)");
5006 ++ ret = min(ret, tcrypt_test("ccm(sm4)"));
5007 + break;
5008 +
5009 + case 57:
5010 +- ret += tcrypt_test("polyval");
5011 ++ ret = min(ret, tcrypt_test("polyval"));
5012 + break;
5013 +
5014 + case 58:
5015 +- ret += tcrypt_test("gcm(aria)");
5016 ++ ret = min(ret, tcrypt_test("gcm(aria)"));
5017 + break;
5018 +
5019 + case 100:
5020 +- ret += tcrypt_test("hmac(md5)");
5021 ++ ret = min(ret, tcrypt_test("hmac(md5)"));
5022 + break;
5023 +
5024 + case 101:
5025 +- ret += tcrypt_test("hmac(sha1)");
5026 ++ ret = min(ret, tcrypt_test("hmac(sha1)"));
5027 + break;
5028 +
5029 + case 102:
5030 +- ret += tcrypt_test("hmac(sha256)");
5031 ++ ret = min(ret, tcrypt_test("hmac(sha256)"));
5032 + break;
5033 +
5034 + case 103:
5035 +- ret += tcrypt_test("hmac(sha384)");
5036 ++ ret = min(ret, tcrypt_test("hmac(sha384)"));
5037 + break;
5038 +
5039 + case 104:
5040 +- ret += tcrypt_test("hmac(sha512)");
5041 ++ ret = min(ret, tcrypt_test("hmac(sha512)"));
5042 + break;
5043 +
5044 + case 105:
5045 +- ret += tcrypt_test("hmac(sha224)");
5046 ++ ret = min(ret, tcrypt_test("hmac(sha224)"));
5047 + break;
5048 +
5049 + case 106:
5050 +- ret += tcrypt_test("xcbc(aes)");
5051 ++ ret = min(ret, tcrypt_test("xcbc(aes)"));
5052 + break;
5053 +
5054 + case 108:
5055 +- ret += tcrypt_test("hmac(rmd160)");
5056 ++ ret = min(ret, tcrypt_test("hmac(rmd160)"));
5057 + break;
5058 +
5059 + case 109:
5060 +- ret += tcrypt_test("vmac64(aes)");
5061 ++ ret = min(ret, tcrypt_test("vmac64(aes)"));
5062 + break;
5063 +
5064 + case 111:
5065 +- ret += tcrypt_test("hmac(sha3-224)");
5066 ++ ret = min(ret, tcrypt_test("hmac(sha3-224)"));
5067 + break;
5068 +
5069 + case 112:
5070 +- ret += tcrypt_test("hmac(sha3-256)");
5071 ++ ret = min(ret, tcrypt_test("hmac(sha3-256)"));
5072 + break;
5073 +
5074 + case 113:
5075 +- ret += tcrypt_test("hmac(sha3-384)");
5076 ++ ret = min(ret, tcrypt_test("hmac(sha3-384)"));
5077 + break;
5078 +
5079 + case 114:
5080 +- ret += tcrypt_test("hmac(sha3-512)");
5081 ++ ret = min(ret, tcrypt_test("hmac(sha3-512)"));
5082 + break;
5083 +
5084 + case 115:
5085 +- ret += tcrypt_test("hmac(streebog256)");
5086 ++ ret = min(ret, tcrypt_test("hmac(streebog256)"));
5087 + break;
5088 +
5089 + case 116:
5090 +- ret += tcrypt_test("hmac(streebog512)");
5091 ++ ret = min(ret, tcrypt_test("hmac(streebog512)"));
5092 + break;
5093 +
5094 + case 150:
5095 +- ret += tcrypt_test("ansi_cprng");
5096 ++ ret = min(ret, tcrypt_test("ansi_cprng"));
5097 + break;
5098 +
5099 + case 151:
5100 +- ret += tcrypt_test("rfc4106(gcm(aes))");
5101 ++ ret = min(ret, tcrypt_test("rfc4106(gcm(aes))"));
5102 + break;
5103 +
5104 + case 152:
5105 +- ret += tcrypt_test("rfc4543(gcm(aes))");
5106 ++ ret = min(ret, tcrypt_test("rfc4543(gcm(aes))"));
5107 + break;
5108 +
5109 + case 153:
5110 +- ret += tcrypt_test("cmac(aes)");
5111 ++ ret = min(ret, tcrypt_test("cmac(aes)"));
5112 + break;
5113 +
5114 + case 154:
5115 +- ret += tcrypt_test("cmac(des3_ede)");
5116 ++ ret = min(ret, tcrypt_test("cmac(des3_ede)"));
5117 + break;
5118 +
5119 + case 155:
5120 +- ret += tcrypt_test("authenc(hmac(sha1),cbc(aes))");
5121 ++ ret = min(ret, tcrypt_test("authenc(hmac(sha1),cbc(aes))"));
5122 + break;
5123 +
5124 + case 156:
5125 +- ret += tcrypt_test("authenc(hmac(md5),ecb(cipher_null))");
5126 ++ ret = min(ret, tcrypt_test("authenc(hmac(md5),ecb(cipher_null))"));
5127 + break;
5128 +
5129 + case 157:
5130 +- ret += tcrypt_test("authenc(hmac(sha1),ecb(cipher_null))");
5131 ++ ret = min(ret, tcrypt_test("authenc(hmac(sha1),ecb(cipher_null))"));
5132 + break;
5133 +
5134 + case 158:
5135 +- ret += tcrypt_test("cbcmac(sm4)");
5136 ++ ret = min(ret, tcrypt_test("cbcmac(sm4)"));
5137 + break;
5138 +
5139 + case 159:
5140 +- ret += tcrypt_test("cmac(sm4)");
5141 ++ ret = min(ret, tcrypt_test("cmac(sm4)"));
5142 + break;
5143 +
5144 + case 181:
5145 +- ret += tcrypt_test("authenc(hmac(sha1),cbc(des))");
5146 ++ ret = min(ret, tcrypt_test("authenc(hmac(sha1),cbc(des))"));
5147 + break;
5148 + case 182:
5149 +- ret += tcrypt_test("authenc(hmac(sha1),cbc(des3_ede))");
5150 ++ ret = min(ret, tcrypt_test("authenc(hmac(sha1),cbc(des3_ede))"));
5151 + break;
5152 + case 183:
5153 +- ret += tcrypt_test("authenc(hmac(sha224),cbc(des))");
5154 ++ ret = min(ret, tcrypt_test("authenc(hmac(sha224),cbc(des))"));
5155 + break;
5156 + case 184:
5157 +- ret += tcrypt_test("authenc(hmac(sha224),cbc(des3_ede))");
5158 ++ ret = min(ret, tcrypt_test("authenc(hmac(sha224),cbc(des3_ede))"));
5159 + break;
5160 + case 185:
5161 +- ret += tcrypt_test("authenc(hmac(sha256),cbc(des))");
5162 ++ ret = min(ret, tcrypt_test("authenc(hmac(sha256),cbc(des))"));
5163 + break;
5164 + case 186:
5165 +- ret += tcrypt_test("authenc(hmac(sha256),cbc(des3_ede))");
5166 ++ ret = min(ret, tcrypt_test("authenc(hmac(sha256),cbc(des3_ede))"));
5167 + break;
5168 + case 187:
5169 +- ret += tcrypt_test("authenc(hmac(sha384),cbc(des))");
5170 ++ ret = min(ret, tcrypt_test("authenc(hmac(sha384),cbc(des))"));
5171 + break;
5172 + case 188:
5173 +- ret += tcrypt_test("authenc(hmac(sha384),cbc(des3_ede))");
5174 ++ ret = min(ret, tcrypt_test("authenc(hmac(sha384),cbc(des3_ede))"));
5175 + break;
5176 + case 189:
5177 +- ret += tcrypt_test("authenc(hmac(sha512),cbc(des))");
5178 ++ ret = min(ret, tcrypt_test("authenc(hmac(sha512),cbc(des))"));
5179 + break;
5180 + case 190:
5181 +- ret += tcrypt_test("authenc(hmac(sha512),cbc(des3_ede))");
5182 ++ ret = min(ret, tcrypt_test("authenc(hmac(sha512),cbc(des3_ede))"));
5183 + break;
5184 + case 191:
5185 +- ret += tcrypt_test("ecb(sm4)");
5186 +- ret += tcrypt_test("cbc(sm4)");
5187 +- ret += tcrypt_test("cfb(sm4)");
5188 +- ret += tcrypt_test("ctr(sm4)");
5189 ++ ret = min(ret, tcrypt_test("ecb(sm4)"));
5190 ++ ret = min(ret, tcrypt_test("cbc(sm4)"));
5191 ++ ret = min(ret, tcrypt_test("cfb(sm4)"));
5192 ++ ret = min(ret, tcrypt_test("ctr(sm4)"));
5193 + break;
5194 + case 192:
5195 +- ret += tcrypt_test("ecb(aria)");
5196 +- ret += tcrypt_test("cbc(aria)");
5197 +- ret += tcrypt_test("cfb(aria)");
5198 +- ret += tcrypt_test("ctr(aria)");
5199 ++ ret = min(ret, tcrypt_test("ecb(aria)"));
5200 ++ ret = min(ret, tcrypt_test("cbc(aria)"));
5201 ++ ret = min(ret, tcrypt_test("cfb(aria)"));
5202 ++ ret = min(ret, tcrypt_test("ctr(aria)"));
5203 + break;
5204 + case 200:
5205 + test_cipher_speed("ecb(aes)", ENCRYPT, sec, NULL, 0,
5206 +diff --git a/drivers/acpi/acpica/dsmethod.c b/drivers/acpi/acpica/dsmethod.c
5207 +index ae2e768830bfc..9332bc688713c 100644
5208 +--- a/drivers/acpi/acpica/dsmethod.c
5209 ++++ b/drivers/acpi/acpica/dsmethod.c
5210 +@@ -517,7 +517,7 @@ acpi_ds_call_control_method(struct acpi_thread_state *thread,
5211 + info = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_evaluate_info));
5212 + if (!info) {
5213 + status = AE_NO_MEMORY;
5214 +- goto cleanup;
5215 ++ goto pop_walk_state;
5216 + }
5217 +
5218 + info->parameters = &this_walk_state->operands[0];
5219 +@@ -529,7 +529,7 @@ acpi_ds_call_control_method(struct acpi_thread_state *thread,
5220 +
5221 + ACPI_FREE(info);
5222 + if (ACPI_FAILURE(status)) {
5223 +- goto cleanup;
5224 ++ goto pop_walk_state;
5225 + }
5226 +
5227 + next_walk_state->method_nesting_depth =
5228 +@@ -575,6 +575,12 @@ acpi_ds_call_control_method(struct acpi_thread_state *thread,
5229 +
5230 + return_ACPI_STATUS(status);
5231 +
5232 ++pop_walk_state:
5233 ++
5234 ++ /* On error, pop the walk state to be deleted from thread */
5235 ++
5236 ++ acpi_ds_pop_walk_state(thread);
5237 ++
5238 + cleanup:
5239 +
5240 + /* On error, we must terminate the method properly */
5241 +diff --git a/drivers/acpi/acpica/utcopy.c b/drivers/acpi/acpica/utcopy.c
5242 +index 400b9e15a709c..63c17f420fb86 100644
5243 +--- a/drivers/acpi/acpica/utcopy.c
5244 ++++ b/drivers/acpi/acpica/utcopy.c
5245 +@@ -916,13 +916,6 @@ acpi_ut_copy_ipackage_to_ipackage(union acpi_operand_object *source_obj,
5246 + status = acpi_ut_walk_package_tree(source_obj, dest_obj,
5247 + acpi_ut_copy_ielement_to_ielement,
5248 + walk_state);
5249 +- if (ACPI_FAILURE(status)) {
5250 +-
5251 +- /* On failure, delete the destination package object */
5252 +-
5253 +- acpi_ut_remove_reference(dest_obj);
5254 +- }
5255 +-
5256 + return_ACPI_STATUS(status);
5257 + }
5258 +
5259 +diff --git a/drivers/acpi/ec.c b/drivers/acpi/ec.c
5260 +index c95e535035a04..fdc760e1e09ef 100644
5261 +--- a/drivers/acpi/ec.c
5262 ++++ b/drivers/acpi/ec.c
5263 +@@ -1879,6 +1879,16 @@ static const struct dmi_system_id ec_dmi_table[] __initconst = {
5264 + DMI_MATCH(DMI_PRODUCT_NAME, "HP Pavilion Gaming Laptop 15-cx0xxx"),
5265 + },
5266 + },
5267 ++ {
5268 ++ /*
5269 ++ * HP Pavilion Gaming Laptop 15-cx0041ur
5270 ++ */
5271 ++ .callback = ec_honor_dsdt_gpe,
5272 ++ .matches = {
5273 ++ DMI_MATCH(DMI_SYS_VENDOR, "HP"),
5274 ++ DMI_MATCH(DMI_PRODUCT_NAME, "HP 15-cx0041ur"),
5275 ++ },
5276 ++ },
5277 + {
5278 + /*
5279 + * Samsung hardware
5280 +diff --git a/drivers/acpi/irq.c b/drivers/acpi/irq.c
5281 +index dabe45eba055d..0d9a17fdd83eb 100644
5282 +--- a/drivers/acpi/irq.c
5283 ++++ b/drivers/acpi/irq.c
5284 +@@ -94,6 +94,7 @@ EXPORT_SYMBOL_GPL(acpi_unregister_gsi);
5285 + /**
5286 + * acpi_get_irq_source_fwhandle() - Retrieve fwhandle from IRQ resource source.
5287 + * @source: acpi_resource_source to use for the lookup.
5288 ++ * @gsi: GSI IRQ number
5289 + *
5290 + * Description:
5291 + * Retrieve the fwhandle of the device referenced by the given IRQ resource
5292 +@@ -295,8 +296,8 @@ EXPORT_SYMBOL_GPL(acpi_irq_get);
5293 + /**
5294 + * acpi_set_irq_model - Setup the GSI irqdomain information
5295 + * @model: the value assigned to acpi_irq_model
5296 +- * @fwnode: the irq_domain identifier for mapping and looking up
5297 +- * GSI interrupts
5298 ++ * @fn: a dispatcher function that will return the domain fwnode
5299 ++ * for a given GSI
5300 + */
5301 + void __init acpi_set_irq_model(enum acpi_irq_model_id model,
5302 + struct fwnode_handle *(*fn)(u32))
5303 +diff --git a/drivers/acpi/pfr_telemetry.c b/drivers/acpi/pfr_telemetry.c
5304 +index 9abf350bd7a5a..27fb6cdad75f9 100644
5305 +--- a/drivers/acpi/pfr_telemetry.c
5306 ++++ b/drivers/acpi/pfr_telemetry.c
5307 +@@ -144,7 +144,7 @@ static int get_pfrt_log_data_info(struct pfrt_log_data_info *data_info,
5308 + ret = 0;
5309 +
5310 + free_acpi_buffer:
5311 +- kfree(out_obj);
5312 ++ ACPI_FREE(out_obj);
5313 +
5314 + return ret;
5315 + }
5316 +@@ -180,7 +180,7 @@ static int set_pfrt_log_level(int level, struct pfrt_log_device *pfrt_log_dev)
5317 + ret = -EBUSY;
5318 + }
5319 +
5320 +- kfree(out_obj);
5321 ++ ACPI_FREE(out_obj);
5322 +
5323 + return ret;
5324 + }
5325 +@@ -218,7 +218,7 @@ static int get_pfrt_log_level(struct pfrt_log_device *pfrt_log_dev)
5326 + ret = obj->integer.value;
5327 +
5328 + free_acpi_buffer:
5329 +- kfree(out_obj);
5330 ++ ACPI_FREE(out_obj);
5331 +
5332 + return ret;
5333 + }
5334 +diff --git a/drivers/acpi/pfr_update.c b/drivers/acpi/pfr_update.c
5335 +index 6bb0b778b5da5..9d2bdc13253a5 100644
5336 +--- a/drivers/acpi/pfr_update.c
5337 ++++ b/drivers/acpi/pfr_update.c
5338 +@@ -178,7 +178,7 @@ static int query_capability(struct pfru_update_cap_info *cap_hdr,
5339 + ret = 0;
5340 +
5341 + free_acpi_buffer:
5342 +- kfree(out_obj);
5343 ++ ACPI_FREE(out_obj);
5344 +
5345 + return ret;
5346 + }
5347 +@@ -224,7 +224,7 @@ static int query_buffer(struct pfru_com_buf_info *info,
5348 + ret = 0;
5349 +
5350 + free_acpi_buffer:
5351 +- kfree(out_obj);
5352 ++ ACPI_FREE(out_obj);
5353 +
5354 + return ret;
5355 + }
5356 +@@ -385,7 +385,7 @@ static int start_update(int action, struct pfru_device *pfru_dev)
5357 + ret = 0;
5358 +
5359 + free_acpi_buffer:
5360 +- kfree(out_obj);
5361 ++ ACPI_FREE(out_obj);
5362 +
5363 + return ret;
5364 + }
5365 +diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c
5366 +index 9f40917c49efb..4d1dd255c1228 100644
5367 +--- a/drivers/acpi/processor_idle.c
5368 ++++ b/drivers/acpi/processor_idle.c
5369 +@@ -1134,6 +1134,9 @@ static int acpi_processor_get_lpi_info(struct acpi_processor *pr)
5370 + status = acpi_get_parent(handle, &pr_ahandle);
5371 + while (ACPI_SUCCESS(status)) {
5372 + d = acpi_fetch_acpi_dev(pr_ahandle);
5373 ++ if (!d)
5374 ++ break;
5375 ++
5376 + handle = pr_ahandle;
5377 +
5378 + if (strcmp(acpi_device_hid(d), ACPI_PROCESSOR_CONTAINER_HID))
5379 +diff --git a/drivers/acpi/x86/utils.c b/drivers/acpi/x86/utils.c
5380 +index 950a93922ca8f..ae60e4aae0eec 100644
5381 +--- a/drivers/acpi/x86/utils.c
5382 ++++ b/drivers/acpi/x86/utils.c
5383 +@@ -308,7 +308,7 @@ static const struct dmi_system_id acpi_quirk_skip_dmi_ids[] = {
5384 + ACPI_QUIRK_SKIP_ACPI_AC_AND_BATTERY),
5385 + },
5386 + {
5387 +- /* Lenovo Yoga Tablet 1050F/L */
5388 ++ /* Lenovo Yoga Tablet 2 1050F/L */
5389 + .matches = {
5390 + DMI_MATCH(DMI_SYS_VENDOR, "Intel Corp."),
5391 + DMI_MATCH(DMI_PRODUCT_NAME, "VALLEYVIEW C0 PLATFORM"),
5392 +@@ -319,6 +319,27 @@ static const struct dmi_system_id acpi_quirk_skip_dmi_ids[] = {
5393 + .driver_data = (void *)(ACPI_QUIRK_SKIP_I2C_CLIENTS |
5394 + ACPI_QUIRK_SKIP_ACPI_AC_AND_BATTERY),
5395 + },
5396 ++ {
5397 ++ /* Lenovo Yoga Tab 3 Pro X90F */
5398 ++ .matches = {
5399 ++ DMI_MATCH(DMI_SYS_VENDOR, "Intel Corporation"),
5400 ++ DMI_MATCH(DMI_PRODUCT_NAME, "CHERRYVIEW D1 PLATFORM"),
5401 ++ DMI_MATCH(DMI_PRODUCT_VERSION, "Blade3-10A-001"),
5402 ++ },
5403 ++ .driver_data = (void *)(ACPI_QUIRK_SKIP_I2C_CLIENTS |
5404 ++ ACPI_QUIRK_SKIP_ACPI_AC_AND_BATTERY),
5405 ++ },
5406 ++ {
5407 ++ /* Medion Lifetab S10346 */
5408 ++ .matches = {
5409 ++ DMI_MATCH(DMI_BOARD_VENDOR, "AMI Corporation"),
5410 ++ DMI_MATCH(DMI_BOARD_NAME, "Aptio CRB"),
5411 ++ /* Way too generic, also match on BIOS data */
5412 ++ DMI_MATCH(DMI_BIOS_DATE, "10/22/2015"),
5413 ++ },
5414 ++ .driver_data = (void *)(ACPI_QUIRK_SKIP_I2C_CLIENTS |
5415 ++ ACPI_QUIRK_SKIP_ACPI_AC_AND_BATTERY),
5416 ++ },
5417 + {
5418 + /* Nextbook Ares 8 */
5419 + .matches = {
5420 +@@ -348,6 +369,7 @@ static const struct acpi_device_id i2c_acpi_known_good_ids[] = {
5421 + { "10EC5640", 0 }, /* RealTek ALC5640 audio codec */
5422 + { "INT33F4", 0 }, /* X-Powers AXP288 PMIC */
5423 + { "INT33FD", 0 }, /* Intel Crystal Cove PMIC */
5424 ++ { "INT34D3", 0 }, /* Intel Whiskey Cove PMIC */
5425 + { "NPCE69A", 0 }, /* Asus Transformer keyboard dock */
5426 + {}
5427 + };
5428 +diff --git a/drivers/ata/libata-sata.c b/drivers/ata/libata-sata.c
5429 +index 13b9d0fdd42c8..8e292e2abb046 100644
5430 +--- a/drivers/ata/libata-sata.c
5431 ++++ b/drivers/ata/libata-sata.c
5432 +@@ -1392,7 +1392,8 @@ static int ata_eh_read_log_10h(struct ata_device *dev,
5433 + tf->hob_lbah = buf[10];
5434 + tf->nsect = buf[12];
5435 + tf->hob_nsect = buf[13];
5436 +- if (dev->class == ATA_DEV_ZAC && ata_id_has_ncq_autosense(dev->id))
5437 ++ if (dev->class == ATA_DEV_ZAC && ata_id_has_ncq_autosense(dev->id) &&
5438 ++ (tf->status & ATA_SENSE))
5439 + tf->auxiliary = buf[14] << 16 | buf[15] << 8 | buf[16];
5440 +
5441 + return 0;
5442 +@@ -1456,8 +1457,12 @@ void ata_eh_analyze_ncq_error(struct ata_link *link)
5443 + memcpy(&qc->result_tf, &tf, sizeof(tf));
5444 + qc->result_tf.flags = ATA_TFLAG_ISADDR | ATA_TFLAG_LBA | ATA_TFLAG_LBA48;
5445 + qc->err_mask |= AC_ERR_DEV | AC_ERR_NCQ;
5446 +- if (dev->class == ATA_DEV_ZAC &&
5447 +- ((qc->result_tf.status & ATA_SENSE) || qc->result_tf.auxiliary)) {
5448 ++
5449 ++ /*
5450 ++ * If the device supports NCQ autosense, ata_eh_read_log_10h() will have
5451 ++ * stored the sense data in qc->result_tf.auxiliary.
5452 ++ */
5453 ++ if (qc->result_tf.auxiliary) {
5454 + char sense_key, asc, ascq;
5455 +
5456 + sense_key = (qc->result_tf.auxiliary >> 16) & 0xff;
5457 +diff --git a/drivers/base/class.c b/drivers/base/class.c
5458 +index 8feb85e186e3b..e394e3e473b5d 100644
5459 +--- a/drivers/base/class.c
5460 ++++ b/drivers/base/class.c
5461 +@@ -192,6 +192,11 @@ int __class_register(struct class *cls, struct lock_class_key *key)
5462 + }
5463 + error = class_add_groups(class_get(cls), cls->class_groups);
5464 + class_put(cls);
5465 ++ if (error) {
5466 ++ kobject_del(&cp->subsys.kobj);
5467 ++ kfree_const(cp->subsys.kobj.name);
5468 ++ kfree(cp);
5469 ++ }
5470 + return error;
5471 + }
5472 + EXPORT_SYMBOL_GPL(__class_register);
5473 +diff --git a/drivers/base/power/runtime.c b/drivers/base/power/runtime.c
5474 +index 997be3ac20a79..d36fb07190bf5 100644
5475 +--- a/drivers/base/power/runtime.c
5476 ++++ b/drivers/base/power/runtime.c
5477 +@@ -484,7 +484,17 @@ static int rpm_idle(struct device *dev, int rpmflags)
5478 +
5479 + dev->power.idle_notification = true;
5480 +
5481 +- retval = __rpm_callback(callback, dev);
5482 ++ if (dev->power.irq_safe)
5483 ++ spin_unlock(&dev->power.lock);
5484 ++ else
5485 ++ spin_unlock_irq(&dev->power.lock);
5486 ++
5487 ++ retval = callback(dev);
5488 ++
5489 ++ if (dev->power.irq_safe)
5490 ++ spin_lock(&dev->power.lock);
5491 ++ else
5492 ++ spin_lock_irq(&dev->power.lock);
5493 +
5494 + dev->power.idle_notification = false;
5495 + wake_up_all(&dev->power.wait_queue);
5496 +diff --git a/drivers/base/regmap/regmap-irq.c b/drivers/base/regmap/regmap-irq.c
5497 +index 4ef9488d05cde..3de89795f5843 100644
5498 +--- a/drivers/base/regmap/regmap-irq.c
5499 ++++ b/drivers/base/regmap/regmap-irq.c
5500 +@@ -722,6 +722,7 @@ int regmap_add_irq_chip_fwnode(struct fwnode_handle *fwnode,
5501 + int i;
5502 + int ret = -ENOMEM;
5503 + int num_type_reg;
5504 ++ int num_regs;
5505 + u32 reg;
5506 +
5507 + if (chip->num_regs <= 0)
5508 +@@ -796,14 +797,20 @@ int regmap_add_irq_chip_fwnode(struct fwnode_handle *fwnode,
5509 + goto err_alloc;
5510 + }
5511 +
5512 +- num_type_reg = chip->type_in_mask ? chip->num_regs : chip->num_type_reg;
5513 +- if (num_type_reg) {
5514 +- d->type_buf_def = kcalloc(num_type_reg,
5515 ++ /*
5516 ++ * Use num_config_regs if defined, otherwise fall back to num_type_reg
5517 ++ * to maintain backward compatibility.
5518 ++ */
5519 ++ num_type_reg = chip->num_config_regs ? chip->num_config_regs
5520 ++ : chip->num_type_reg;
5521 ++ num_regs = chip->type_in_mask ? chip->num_regs : num_type_reg;
5522 ++ if (num_regs) {
5523 ++ d->type_buf_def = kcalloc(num_regs,
5524 + sizeof(*d->type_buf_def), GFP_KERNEL);
5525 + if (!d->type_buf_def)
5526 + goto err_alloc;
5527 +
5528 +- d->type_buf = kcalloc(num_type_reg, sizeof(*d->type_buf),
5529 ++ d->type_buf = kcalloc(num_regs, sizeof(*d->type_buf),
5530 + GFP_KERNEL);
5531 + if (!d->type_buf)
5532 + goto err_alloc;
5533 +diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
5534 +index 8532b839a3435..6772402326842 100644
5535 +--- a/drivers/block/drbd/drbd_main.c
5536 ++++ b/drivers/block/drbd/drbd_main.c
5537 +@@ -2217,7 +2217,8 @@ void drbd_destroy_device(struct kref *kref)
5538 + kref_put(&peer_device->connection->kref, drbd_destroy_connection);
5539 + kfree(peer_device);
5540 + }
5541 +- memset(device, 0xfd, sizeof(*device));
5542 ++ if (device->submit.wq)
5543 ++ destroy_workqueue(device->submit.wq);
5544 + kfree(device);
5545 + kref_put(&resource->kref, drbd_destroy_resource);
5546 + }
5547 +@@ -2309,7 +2310,6 @@ void drbd_destroy_resource(struct kref *kref)
5548 + idr_destroy(&resource->devices);
5549 + free_cpumask_var(resource->cpu_mask);
5550 + kfree(resource->name);
5551 +- memset(resource, 0xf2, sizeof(*resource));
5552 + kfree(resource);
5553 + }
5554 +
5555 +@@ -2650,7 +2650,6 @@ void drbd_destroy_connection(struct kref *kref)
5556 + drbd_free_socket(&connection->data);
5557 + kfree(connection->int_dig_in);
5558 + kfree(connection->int_dig_vv);
5559 +- memset(connection, 0xfc, sizeof(*connection));
5560 + kfree(connection);
5561 + kref_put(&resource->kref, drbd_destroy_resource);
5562 + }
5563 +@@ -2774,7 +2773,7 @@ enum drbd_ret_code drbd_create_device(struct drbd_config_context *adm_ctx, unsig
5564 +
5565 + err = add_disk(disk);
5566 + if (err)
5567 +- goto out_idr_remove_from_resource;
5568 ++ goto out_destroy_workqueue;
5569 +
5570 + /* inherit the connection state */
5571 + device->state.conn = first_connection(resource)->cstate;
5572 +@@ -2788,6 +2787,8 @@ enum drbd_ret_code drbd_create_device(struct drbd_config_context *adm_ctx, unsig
5573 + drbd_debugfs_device_add(device);
5574 + return NO_ERROR;
5575 +
5576 ++out_destroy_workqueue:
5577 ++ destroy_workqueue(device->submit.wq);
5578 + out_idr_remove_from_resource:
5579 + for_each_connection_safe(connection, n, resource) {
5580 + peer_device = idr_remove(&connection->peer_devices, vnr);
5581 +diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c
5582 +index 013d355a2033b..921c303a7b5c4 100644
5583 +--- a/drivers/block/drbd/drbd_nl.c
5584 ++++ b/drivers/block/drbd/drbd_nl.c
5585 +@@ -1210,6 +1210,7 @@ static void decide_on_discard_support(struct drbd_device *device,
5586 + struct drbd_connection *connection =
5587 + first_peer_device(device)->connection;
5588 + struct request_queue *q = device->rq_queue;
5589 ++ unsigned int max_discard_sectors;
5590 +
5591 + if (bdev && !bdev_max_discard_sectors(bdev->backing_bdev))
5592 + goto not_supported;
5593 +@@ -1230,15 +1231,14 @@ static void decide_on_discard_support(struct drbd_device *device,
5594 + * topology on all peers.
5595 + */
5596 + blk_queue_discard_granularity(q, 512);
5597 +- q->limits.max_discard_sectors = drbd_max_discard_sectors(connection);
5598 +- q->limits.max_write_zeroes_sectors =
5599 +- drbd_max_discard_sectors(connection);
5600 ++ max_discard_sectors = drbd_max_discard_sectors(connection);
5601 ++ blk_queue_max_discard_sectors(q, max_discard_sectors);
5602 ++ blk_queue_max_write_zeroes_sectors(q, max_discard_sectors);
5603 + return;
5604 +
5605 + not_supported:
5606 + blk_queue_discard_granularity(q, 0);
5607 +- q->limits.max_discard_sectors = 0;
5608 +- q->limits.max_write_zeroes_sectors = 0;
5609 ++ blk_queue_max_discard_sectors(q, 0);
5610 + }
5611 +
5612 + static void fixup_write_zeroes(struct drbd_device *device, struct request_queue *q)
5613 +diff --git a/drivers/block/floppy.c b/drivers/block/floppy.c
5614 +index ccad3d7b3ddd9..487840e3564df 100644
5615 +--- a/drivers/block/floppy.c
5616 ++++ b/drivers/block/floppy.c
5617 +@@ -4593,8 +4593,10 @@ static int __init do_floppy_init(void)
5618 + goto out_put_disk;
5619 +
5620 + err = floppy_alloc_disk(drive, 0);
5621 +- if (err)
5622 ++ if (err) {
5623 ++ blk_mq_free_tag_set(&tag_sets[drive]);
5624 + goto out_put_disk;
5625 ++ }
5626 +
5627 + timer_setup(&motor_off_timer[drive], motor_off_callback, 0);
5628 + }
5629 +diff --git a/drivers/block/loop.c b/drivers/block/loop.c
5630 +index ad92192c7d617..d12d3d171ec4c 100644
5631 +--- a/drivers/block/loop.c
5632 ++++ b/drivers/block/loop.c
5633 +@@ -1773,7 +1773,16 @@ static const struct block_device_operations lo_fops = {
5634 + /*
5635 + * And now the modules code and kernel interface.
5636 + */
5637 +-static int max_loop;
5638 ++
5639 ++/*
5640 ++ * If max_loop is specified, create that many devices upfront.
5641 ++ * This also becomes a hard limit. If max_loop is not specified,
5642 ++ * create CONFIG_BLK_DEV_LOOP_MIN_COUNT loop devices at module
5643 ++ * init time. Loop devices can be requested on-demand with the
5644 ++ * /dev/loop-control interface, or be instantiated by accessing
5645 ++ * a 'dead' device node.
5646 ++ */
5647 ++static int max_loop = CONFIG_BLK_DEV_LOOP_MIN_COUNT;
5648 + module_param(max_loop, int, 0444);
5649 + MODULE_PARM_DESC(max_loop, "Maximum number of loop devices");
5650 + module_param(max_part, int, 0444);
5651 +@@ -2181,7 +2190,7 @@ MODULE_ALIAS("devname:loop-control");
5652 +
5653 + static int __init loop_init(void)
5654 + {
5655 +- int i, nr;
5656 ++ int i;
5657 + int err;
5658 +
5659 + part_shift = 0;
5660 +@@ -2209,19 +2218,6 @@ static int __init loop_init(void)
5661 + goto err_out;
5662 + }
5663 +
5664 +- /*
5665 +- * If max_loop is specified, create that many devices upfront.
5666 +- * This also becomes a hard limit. If max_loop is not specified,
5667 +- * create CONFIG_BLK_DEV_LOOP_MIN_COUNT loop devices at module
5668 +- * init time. Loop devices can be requested on-demand with the
5669 +- * /dev/loop-control interface, or be instantiated by accessing
5670 +- * a 'dead' device node.
5671 +- */
5672 +- if (max_loop)
5673 +- nr = max_loop;
5674 +- else
5675 +- nr = CONFIG_BLK_DEV_LOOP_MIN_COUNT;
5676 +-
5677 + err = misc_register(&loop_misc);
5678 + if (err < 0)
5679 + goto err_out;
5680 +@@ -2233,7 +2229,7 @@ static int __init loop_init(void)
5681 + }
5682 +
5683 + /* pre-create number of devices given by config or max_loop */
5684 +- for (i = 0; i < nr; i++)
5685 ++ for (i = 0; i < max_loop; i++)
5686 + loop_add(i);
5687 +
5688 + printk(KERN_INFO "loop: module loaded\n");
5689 +diff --git a/drivers/bluetooth/btintel.c b/drivers/bluetooth/btintel.c
5690 +index d44a966675179..0c2542cee294b 100644
5691 +--- a/drivers/bluetooth/btintel.c
5692 ++++ b/drivers/bluetooth/btintel.c
5693 +@@ -2522,7 +2522,7 @@ static int btintel_setup_combined(struct hci_dev *hdev)
5694 + */
5695 + err = btintel_read_version(hdev, &ver);
5696 + if (err)
5697 +- return err;
5698 ++ break;
5699 +
5700 + /* Apply the device specific HCI quirks
5701 + *
5702 +@@ -2563,7 +2563,8 @@ static int btintel_setup_combined(struct hci_dev *hdev)
5703 + default:
5704 + bt_dev_err(hdev, "Unsupported Intel hw variant (%u)",
5705 + INTEL_HW_VARIANT(ver_tlv.cnvi_bt));
5706 +- return -EINVAL;
5707 ++ err = -EINVAL;
5708 ++ break;
5709 + }
5710 +
5711 + exit_error:
5712 +diff --git a/drivers/bluetooth/btusb.c b/drivers/bluetooth/btusb.c
5713 +index 882b5893f9108..a132e7aba6054 100644
5714 +--- a/drivers/bluetooth/btusb.c
5715 ++++ b/drivers/bluetooth/btusb.c
5716 +@@ -788,13 +788,13 @@ static inline void btusb_free_frags(struct btusb_data *data)
5717 +
5718 + spin_lock_irqsave(&data->rxlock, flags);
5719 +
5720 +- kfree_skb(data->evt_skb);
5721 ++ dev_kfree_skb_irq(data->evt_skb);
5722 + data->evt_skb = NULL;
5723 +
5724 +- kfree_skb(data->acl_skb);
5725 ++ dev_kfree_skb_irq(data->acl_skb);
5726 + data->acl_skb = NULL;
5727 +
5728 +- kfree_skb(data->sco_skb);
5729 ++ dev_kfree_skb_irq(data->sco_skb);
5730 + data->sco_skb = NULL;
5731 +
5732 + spin_unlock_irqrestore(&data->rxlock, flags);
5733 +diff --git a/drivers/bluetooth/hci_bcm.c b/drivers/bluetooth/hci_bcm.c
5734 +index d7e0b75db8a60..2b6c0e1922cb3 100644
5735 +--- a/drivers/bluetooth/hci_bcm.c
5736 ++++ b/drivers/bluetooth/hci_bcm.c
5737 +@@ -53,11 +53,13 @@
5738 + * struct bcm_device_data - device specific data
5739 + * @no_early_set_baudrate: Disallow set baudrate before driver setup()
5740 + * @drive_rts_on_open: drive RTS signal on ->open() when platform requires it
5741 ++ * @no_uart_clock_set: UART clock set command for >3Mbps mode is unavailable
5742 + * @max_autobaud_speed: max baudrate supported by device in autobaud mode
5743 + */
5744 + struct bcm_device_data {
5745 + bool no_early_set_baudrate;
5746 + bool drive_rts_on_open;
5747 ++ bool no_uart_clock_set;
5748 + u32 max_autobaud_speed;
5749 + };
5750 +
5751 +@@ -100,6 +102,7 @@ struct bcm_device_data {
5752 + * @is_suspended: whether flow control is currently disabled
5753 + * @no_early_set_baudrate: don't set_baudrate before setup()
5754 + * @drive_rts_on_open: drive RTS signal on ->open() when platform requires it
5755 ++ * @no_uart_clock_set: UART clock set command for >3Mbps mode is unavailable
5756 + * @pcm_int_params: keep the initial PCM configuration
5757 + * @use_autobaud_mode: start Bluetooth device in autobaud mode
5758 + * @max_autobaud_speed: max baudrate supported by device in autobaud mode
5759 +@@ -140,6 +143,7 @@ struct bcm_device {
5760 + #endif
5761 + bool no_early_set_baudrate;
5762 + bool drive_rts_on_open;
5763 ++ bool no_uart_clock_set;
5764 + bool use_autobaud_mode;
5765 + u8 pcm_int_params[5];
5766 + u32 max_autobaud_speed;
5767 +@@ -172,10 +176,11 @@ static inline void host_set_baudrate(struct hci_uart *hu, unsigned int speed)
5768 + static int bcm_set_baudrate(struct hci_uart *hu, unsigned int speed)
5769 + {
5770 + struct hci_dev *hdev = hu->hdev;
5771 ++ struct bcm_data *bcm = hu->priv;
5772 + struct sk_buff *skb;
5773 + struct bcm_update_uart_baud_rate param;
5774 +
5775 +- if (speed > 3000000) {
5776 ++ if (speed > 3000000 && !bcm->dev->no_uart_clock_set) {
5777 + struct bcm_write_uart_clock_setting clock;
5778 +
5779 + clock.type = BCM_UART_CLOCK_48MHZ;
5780 +@@ -1529,6 +1534,7 @@ static int bcm_serdev_probe(struct serdev_device *serdev)
5781 + bcmdev->max_autobaud_speed = data->max_autobaud_speed;
5782 + bcmdev->no_early_set_baudrate = data->no_early_set_baudrate;
5783 + bcmdev->drive_rts_on_open = data->drive_rts_on_open;
5784 ++ bcmdev->no_uart_clock_set = data->no_uart_clock_set;
5785 + }
5786 +
5787 + return hci_uart_register_device(&bcmdev->serdev_hu, &bcm_proto);
5788 +@@ -1550,6 +1556,10 @@ static struct bcm_device_data bcm43438_device_data = {
5789 + .drive_rts_on_open = true,
5790 + };
5791 +
5792 ++static struct bcm_device_data cyw4373a0_device_data = {
5793 ++ .no_uart_clock_set = true,
5794 ++};
5795 ++
5796 + static struct bcm_device_data cyw55572_device_data = {
5797 + .max_autobaud_speed = 921600,
5798 + };
5799 +@@ -1566,6 +1576,7 @@ static const struct of_device_id bcm_bluetooth_of_match[] = {
5800 + { .compatible = "brcm,bcm4349-bt", .data = &bcm43438_device_data },
5801 + { .compatible = "brcm,bcm43540-bt", .data = &bcm4354_device_data },
5802 + { .compatible = "brcm,bcm4335a0" },
5803 ++ { .compatible = "cypress,cyw4373a0-bt", .data = &cyw4373a0_device_data },
5804 + { .compatible = "infineon,cyw55572-bt", .data = &cyw55572_device_data },
5805 + { },
5806 + };
5807 +diff --git a/drivers/bluetooth/hci_bcsp.c b/drivers/bluetooth/hci_bcsp.c
5808 +index cf4a560958173..8055f63603f45 100644
5809 +--- a/drivers/bluetooth/hci_bcsp.c
5810 ++++ b/drivers/bluetooth/hci_bcsp.c
5811 +@@ -378,7 +378,7 @@ static void bcsp_pkt_cull(struct bcsp_struct *bcsp)
5812 + i++;
5813 +
5814 + __skb_unlink(skb, &bcsp->unack);
5815 +- kfree_skb(skb);
5816 ++ dev_kfree_skb_irq(skb);
5817 + }
5818 +
5819 + if (skb_queue_empty(&bcsp->unack))
5820 +diff --git a/drivers/bluetooth/hci_h5.c b/drivers/bluetooth/hci_h5.c
5821 +index c5a0409ef84fd..6455bc4fb5bb3 100644
5822 +--- a/drivers/bluetooth/hci_h5.c
5823 ++++ b/drivers/bluetooth/hci_h5.c
5824 +@@ -313,7 +313,7 @@ static void h5_pkt_cull(struct h5 *h5)
5825 + break;
5826 +
5827 + __skb_unlink(skb, &h5->unack);
5828 +- kfree_skb(skb);
5829 ++ dev_kfree_skb_irq(skb);
5830 + }
5831 +
5832 + if (skb_queue_empty(&h5->unack))
5833 +diff --git a/drivers/bluetooth/hci_ll.c b/drivers/bluetooth/hci_ll.c
5834 +index 4eb420a9ed04e..5abc01a2acf72 100644
5835 +--- a/drivers/bluetooth/hci_ll.c
5836 ++++ b/drivers/bluetooth/hci_ll.c
5837 +@@ -345,7 +345,7 @@ static int ll_enqueue(struct hci_uart *hu, struct sk_buff *skb)
5838 + default:
5839 + BT_ERR("illegal hcill state: %ld (losing packet)",
5840 + ll->hcill_state);
5841 +- kfree_skb(skb);
5842 ++ dev_kfree_skb_irq(skb);
5843 + break;
5844 + }
5845 +
5846 +diff --git a/drivers/bluetooth/hci_qca.c b/drivers/bluetooth/hci_qca.c
5847 +index 8df11016fd51b..bae9b2a408d95 100644
5848 +--- a/drivers/bluetooth/hci_qca.c
5849 ++++ b/drivers/bluetooth/hci_qca.c
5850 +@@ -912,7 +912,7 @@ static int qca_enqueue(struct hci_uart *hu, struct sk_buff *skb)
5851 + default:
5852 + BT_ERR("Illegal tx state: %d (losing packet)",
5853 + qca->tx_ibs_state);
5854 +- kfree_skb(skb);
5855 ++ dev_kfree_skb_irq(skb);
5856 + break;
5857 + }
5858 +
5859 +diff --git a/drivers/char/hw_random/amd-rng.c b/drivers/char/hw_random/amd-rng.c
5860 +index c22d4184bb612..0555e3838bce1 100644
5861 +--- a/drivers/char/hw_random/amd-rng.c
5862 ++++ b/drivers/char/hw_random/amd-rng.c
5863 +@@ -143,15 +143,19 @@ static int __init amd_rng_mod_init(void)
5864 + found:
5865 + err = pci_read_config_dword(pdev, 0x58, &pmbase);
5866 + if (err)
5867 +- return err;
5868 ++ goto put_dev;
5869 +
5870 + pmbase &= 0x0000FF00;
5871 +- if (pmbase == 0)
5872 +- return -EIO;
5873 ++ if (pmbase == 0) {
5874 ++ err = -EIO;
5875 ++ goto put_dev;
5876 ++ }
5877 +
5878 + priv = kzalloc(sizeof(*priv), GFP_KERNEL);
5879 +- if (!priv)
5880 +- return -ENOMEM;
5881 ++ if (!priv) {
5882 ++ err = -ENOMEM;
5883 ++ goto put_dev;
5884 ++ }
5885 +
5886 + if (!request_region(pmbase + PMBASE_OFFSET, PMBASE_SIZE, DRV_NAME)) {
5887 + dev_err(&pdev->dev, DRV_NAME " region 0x%x already in use!\n",
5888 +@@ -185,6 +189,8 @@ err_iomap:
5889 + release_region(pmbase + PMBASE_OFFSET, PMBASE_SIZE);
5890 + out:
5891 + kfree(priv);
5892 ++put_dev:
5893 ++ pci_dev_put(pdev);
5894 + return err;
5895 + }
5896 +
5897 +@@ -200,6 +206,8 @@ static void __exit amd_rng_mod_exit(void)
5898 +
5899 + release_region(priv->pmbase + PMBASE_OFFSET, PMBASE_SIZE);
5900 +
5901 ++ pci_dev_put(priv->pcidev);
5902 ++
5903 + kfree(priv);
5904 + }
5905 +
5906 +diff --git a/drivers/char/hw_random/geode-rng.c b/drivers/char/hw_random/geode-rng.c
5907 +index 138ce434f86b2..12fbe80918319 100644
5908 +--- a/drivers/char/hw_random/geode-rng.c
5909 ++++ b/drivers/char/hw_random/geode-rng.c
5910 +@@ -51,6 +51,10 @@ static const struct pci_device_id pci_tbl[] = {
5911 + };
5912 + MODULE_DEVICE_TABLE(pci, pci_tbl);
5913 +
5914 ++struct amd_geode_priv {
5915 ++ struct pci_dev *pcidev;
5916 ++ void __iomem *membase;
5917 ++};
5918 +
5919 + static int geode_rng_data_read(struct hwrng *rng, u32 *data)
5920 + {
5921 +@@ -90,6 +94,7 @@ static int __init geode_rng_init(void)
5922 + const struct pci_device_id *ent;
5923 + void __iomem *mem;
5924 + unsigned long rng_base;
5925 ++ struct amd_geode_priv *priv;
5926 +
5927 + for_each_pci_dev(pdev) {
5928 + ent = pci_match_id(pci_tbl, pdev);
5929 +@@ -97,17 +102,26 @@ static int __init geode_rng_init(void)
5930 + goto found;
5931 + }
5932 + /* Device not found. */
5933 +- goto out;
5934 ++ return err;
5935 +
5936 + found:
5937 ++ priv = kzalloc(sizeof(*priv), GFP_KERNEL);
5938 ++ if (!priv) {
5939 ++ err = -ENOMEM;
5940 ++ goto put_dev;
5941 ++ }
5942 ++
5943 + rng_base = pci_resource_start(pdev, 0);
5944 + if (rng_base == 0)
5945 +- goto out;
5946 ++ goto free_priv;
5947 + err = -ENOMEM;
5948 + mem = ioremap(rng_base, 0x58);
5949 + if (!mem)
5950 +- goto out;
5951 +- geode_rng.priv = (unsigned long)mem;
5952 ++ goto free_priv;
5953 ++
5954 ++ geode_rng.priv = (unsigned long)priv;
5955 ++ priv->membase = mem;
5956 ++ priv->pcidev = pdev;
5957 +
5958 + pr_info("AMD Geode RNG detected\n");
5959 + err = hwrng_register(&geode_rng);
5960 +@@ -116,20 +130,26 @@ found:
5961 + err);
5962 + goto err_unmap;
5963 + }
5964 +-out:
5965 + return err;
5966 +
5967 + err_unmap:
5968 + iounmap(mem);
5969 +- goto out;
5970 ++free_priv:
5971 ++ kfree(priv);
5972 ++put_dev:
5973 ++ pci_dev_put(pdev);
5974 ++ return err;
5975 + }
5976 +
5977 + static void __exit geode_rng_exit(void)
5978 + {
5979 +- void __iomem *mem = (void __iomem *)geode_rng.priv;
5980 ++ struct amd_geode_priv *priv;
5981 +
5982 ++ priv = (struct amd_geode_priv *)geode_rng.priv;
5983 + hwrng_unregister(&geode_rng);
5984 +- iounmap(mem);
5985 ++ iounmap(priv->membase);
5986 ++ pci_dev_put(priv->pcidev);
5987 ++ kfree(priv);
5988 + }
5989 +
5990 + module_init(geode_rng_init);
5991 +diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
5992 +index 703433493c852..c9e32d100b7eb 100644
5993 +--- a/drivers/char/ipmi/ipmi_msghandler.c
5994 ++++ b/drivers/char/ipmi/ipmi_msghandler.c
5995 +@@ -3710,12 +3710,16 @@ static void deliver_smi_err_response(struct ipmi_smi *intf,
5996 + struct ipmi_smi_msg *msg,
5997 + unsigned char err)
5998 + {
5999 ++ int rv;
6000 + msg->rsp[0] = msg->data[0] | 4;
6001 + msg->rsp[1] = msg->data[1];
6002 + msg->rsp[2] = err;
6003 + msg->rsp_size = 3;
6004 +- /* It's an error, so it will never requeue, no need to check return. */
6005 +- handle_one_recv_msg(intf, msg);
6006 ++
6007 ++ /* This will never requeue, but it may ask us to free the message. */
6008 ++ rv = handle_one_recv_msg(intf, msg);
6009 ++ if (rv == 0)
6010 ++ ipmi_free_smi_msg(msg);
6011 + }
6012 +
6013 + static void cleanup_smi_msgs(struct ipmi_smi *intf)
6014 +diff --git a/drivers/char/ipmi/kcs_bmc_aspeed.c b/drivers/char/ipmi/kcs_bmc_aspeed.c
6015 +index cdc88cde1e9aa..417e5a3ccfaeb 100644
6016 +--- a/drivers/char/ipmi/kcs_bmc_aspeed.c
6017 ++++ b/drivers/char/ipmi/kcs_bmc_aspeed.c
6018 +@@ -399,13 +399,31 @@ static void aspeed_kcs_check_obe(struct timer_list *timer)
6019 + static void aspeed_kcs_irq_mask_update(struct kcs_bmc_device *kcs_bmc, u8 mask, u8 state)
6020 + {
6021 + struct aspeed_kcs_bmc *priv = to_aspeed_kcs_bmc(kcs_bmc);
6022 ++ int rc;
6023 ++ u8 str;
6024 +
6025 + /* We don't have an OBE IRQ, emulate it */
6026 + if (mask & KCS_BMC_EVENT_TYPE_OBE) {
6027 +- if (KCS_BMC_EVENT_TYPE_OBE & state)
6028 +- mod_timer(&priv->obe.timer, jiffies + OBE_POLL_PERIOD);
6029 +- else
6030 ++ if (KCS_BMC_EVENT_TYPE_OBE & state) {
6031 ++ /*
6032 ++ * Given we don't have an OBE IRQ, delay by polling briefly to see if we can
6033 ++ * observe such an event before returning to the caller. This is not
6034 ++ * incorrect because OBF may have already become clear before enabling the
6035 ++ * IRQ if we had one, under which circumstance no event will be propagated
6036 ++ * anyway.
6037 ++ *
6038 ++ * The onus is on the client to perform a race-free check that it hasn't
6039 ++ * missed the event.
6040 ++ */
6041 ++ rc = read_poll_timeout_atomic(aspeed_kcs_inb, str,
6042 ++ !(str & KCS_BMC_STR_OBF), 1, 100, false,
6043 ++ &priv->kcs_bmc, priv->kcs_bmc.ioreg.str);
6044 ++ /* Time for the slow path? */
6045 ++ if (rc == -ETIMEDOUT)
6046 ++ mod_timer(&priv->obe.timer, jiffies + OBE_POLL_PERIOD);
6047 ++ } else {
6048 + del_timer(&priv->obe.timer);
6049 ++ }
6050 + }
6051 +
6052 + if (mask & KCS_BMC_EVENT_TYPE_IBF) {
6053 +diff --git a/drivers/char/tpm/tpm_crb.c b/drivers/char/tpm/tpm_crb.c
6054 +index 18606651d1aa4..65f8f179a27f0 100644
6055 +--- a/drivers/char/tpm/tpm_crb.c
6056 ++++ b/drivers/char/tpm/tpm_crb.c
6057 +@@ -252,7 +252,7 @@ static int __crb_relinquish_locality(struct device *dev,
6058 + iowrite32(CRB_LOC_CTRL_RELINQUISH, &priv->regs_h->loc_ctrl);
6059 + if (!crb_wait_for_reg_32(&priv->regs_h->loc_state, mask, value,
6060 + TPM2_TIMEOUT_C)) {
6061 +- dev_warn(dev, "TPM_LOC_STATE_x.requestAccess timed out\n");
6062 ++ dev_warn(dev, "TPM_LOC_STATE_x.Relinquish timed out\n");
6063 + return -ETIME;
6064 + }
6065 +
6066 +diff --git a/drivers/char/tpm/tpm_ftpm_tee.c b/drivers/char/tpm/tpm_ftpm_tee.c
6067 +index 5c233423c56fa..deff23bb54bf1 100644
6068 +--- a/drivers/char/tpm/tpm_ftpm_tee.c
6069 ++++ b/drivers/char/tpm/tpm_ftpm_tee.c
6070 +@@ -397,7 +397,13 @@ static int __init ftpm_mod_init(void)
6071 + if (rc)
6072 + return rc;
6073 +
6074 +- return driver_register(&ftpm_tee_driver.driver);
6075 ++ rc = driver_register(&ftpm_tee_driver.driver);
6076 ++ if (rc) {
6077 ++ platform_driver_unregister(&ftpm_tee_plat_driver);
6078 ++ return rc;
6079 ++ }
6080 ++
6081 ++ return 0;
6082 + }
6083 +
6084 + static void __exit ftpm_mod_exit(void)
6085 +diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c
6086 +index 757623bacfd50..3f98e587b3e84 100644
6087 +--- a/drivers/char/tpm/tpm_tis_core.c
6088 ++++ b/drivers/char/tpm/tpm_tis_core.c
6089 +@@ -682,15 +682,19 @@ static bool tpm_tis_req_canceled(struct tpm_chip *chip, u8 status)
6090 + {
6091 + struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev);
6092 +
6093 +- switch (priv->manufacturer_id) {
6094 +- case TPM_VID_WINBOND:
6095 +- return ((status == TPM_STS_VALID) ||
6096 +- (status == (TPM_STS_VALID | TPM_STS_COMMAND_READY)));
6097 +- case TPM_VID_STM:
6098 +- return (status == (TPM_STS_VALID | TPM_STS_COMMAND_READY));
6099 +- default:
6100 +- return (status == TPM_STS_COMMAND_READY);
6101 ++ if (!test_bit(TPM_TIS_DEFAULT_CANCELLATION, &priv->flags)) {
6102 ++ switch (priv->manufacturer_id) {
6103 ++ case TPM_VID_WINBOND:
6104 ++ return ((status == TPM_STS_VALID) ||
6105 ++ (status == (TPM_STS_VALID | TPM_STS_COMMAND_READY)));
6106 ++ case TPM_VID_STM:
6107 ++ return (status == (TPM_STS_VALID | TPM_STS_COMMAND_READY));
6108 ++ default:
6109 ++ break;
6110 ++ }
6111 + }
6112 ++
6113 ++ return status == TPM_STS_COMMAND_READY;
6114 + }
6115 +
6116 + static irqreturn_t tis_int_handler(int dummy, void *dev_id)
6117 +diff --git a/drivers/char/tpm/tpm_tis_core.h b/drivers/char/tpm/tpm_tis_core.h
6118 +index 66a5a13cd1df2..b68479e0de10f 100644
6119 +--- a/drivers/char/tpm/tpm_tis_core.h
6120 ++++ b/drivers/char/tpm/tpm_tis_core.h
6121 +@@ -86,6 +86,7 @@ enum tis_defaults {
6122 + enum tpm_tis_flags {
6123 + TPM_TIS_ITPM_WORKAROUND = BIT(0),
6124 + TPM_TIS_INVALID_STATUS = BIT(1),
6125 ++ TPM_TIS_DEFAULT_CANCELLATION = BIT(2),
6126 + };
6127 +
6128 + struct tpm_tis_data {
6129 +diff --git a/drivers/char/tpm/tpm_tis_i2c.c b/drivers/char/tpm/tpm_tis_i2c.c
6130 +index ba0911b1d1ff3..e728a61659f86 100644
6131 +--- a/drivers/char/tpm/tpm_tis_i2c.c
6132 ++++ b/drivers/char/tpm/tpm_tis_i2c.c
6133 +@@ -49,7 +49,7 @@
6134 +
6135 + /* Masks with bits that must be read zero */
6136 + #define TPM_ACCESS_READ_ZERO 0x48
6137 +-#define TPM_INT_ENABLE_ZERO 0x7FFFFF6
6138 ++#define TPM_INT_ENABLE_ZERO 0x7FFFFF60
6139 + #define TPM_STS_READ_ZERO 0x23
6140 + #define TPM_INTF_CAPABILITY_ZERO 0x0FFFF000
6141 + #define TPM_I2C_INTERFACE_CAPABILITY_ZERO 0x80000000
6142 +@@ -329,6 +329,7 @@ static int tpm_tis_i2c_probe(struct i2c_client *dev,
6143 + if (!phy->io_buf)
6144 + return -ENOMEM;
6145 +
6146 ++ set_bit(TPM_TIS_DEFAULT_CANCELLATION, &phy->priv.flags);
6147 + phy->i2c_client = dev;
6148 +
6149 + /* must precede all communication with the tpm */
6150 +diff --git a/drivers/clk/imx/clk-imx8mn.c b/drivers/clk/imx/clk-imx8mn.c
6151 +index d37c45b676abe..2afea905f7f3c 100644
6152 +--- a/drivers/clk/imx/clk-imx8mn.c
6153 ++++ b/drivers/clk/imx/clk-imx8mn.c
6154 +@@ -27,10 +27,10 @@ static u32 share_count_nand;
6155 + static const char * const pll_ref_sels[] = { "osc_24m", "dummy", "dummy", "dummy", };
6156 + static const char * const audio_pll1_bypass_sels[] = {"audio_pll1", "audio_pll1_ref_sel", };
6157 + static const char * const audio_pll2_bypass_sels[] = {"audio_pll2", "audio_pll2_ref_sel", };
6158 +-static const char * const video_pll1_bypass_sels[] = {"video_pll1", "video_pll1_ref_sel", };
6159 ++static const char * const video_pll_bypass_sels[] = {"video_pll", "video_pll_ref_sel", };
6160 + static const char * const dram_pll_bypass_sels[] = {"dram_pll", "dram_pll_ref_sel", };
6161 + static const char * const gpu_pll_bypass_sels[] = {"gpu_pll", "gpu_pll_ref_sel", };
6162 +-static const char * const vpu_pll_bypass_sels[] = {"vpu_pll", "vpu_pll_ref_sel", };
6163 ++static const char * const m7_alt_pll_bypass_sels[] = {"m7_alt_pll", "m7_alt_pll_ref_sel", };
6164 + static const char * const arm_pll_bypass_sels[] = {"arm_pll", "arm_pll_ref_sel", };
6165 + static const char * const sys_pll3_bypass_sels[] = {"sys_pll3", "sys_pll3_ref_sel", };
6166 +
6167 +@@ -40,24 +40,24 @@ static const char * const imx8mn_a53_sels[] = {"osc_24m", "arm_pll_out", "sys_pl
6168 +
6169 + static const char * const imx8mn_a53_core_sels[] = {"arm_a53_div", "arm_pll_out", };
6170 +
6171 +-static const char * const imx8mn_m7_sels[] = {"osc_24m", "sys_pll2_200m", "sys_pll2_250m", "vpu_pll_out",
6172 +- "sys_pll1_800m", "audio_pll1_out", "video_pll1_out", "sys_pll3_out", };
6173 ++static const char * const imx8mn_m7_sels[] = {"osc_24m", "sys_pll2_200m", "sys_pll2_250m", "m7_alt_pll_out",
6174 ++ "sys_pll1_800m", "audio_pll1_out", "video_pll_out", "sys_pll3_out", };
6175 +
6176 + static const char * const imx8mn_gpu_core_sels[] = {"osc_24m", "gpu_pll_out", "sys_pll1_800m",
6177 + "sys_pll3_out", "sys_pll2_1000m", "audio_pll1_out",
6178 +- "video_pll1_out", "audio_pll2_out", };
6179 ++ "video_pll_out", "audio_pll2_out", };
6180 +
6181 + static const char * const imx8mn_gpu_shader_sels[] = {"osc_24m", "gpu_pll_out", "sys_pll1_800m",
6182 + "sys_pll3_out", "sys_pll2_1000m", "audio_pll1_out",
6183 +- "video_pll1_out", "audio_pll2_out", };
6184 ++ "video_pll_out", "audio_pll2_out", };
6185 +
6186 + static const char * const imx8mn_main_axi_sels[] = {"osc_24m", "sys_pll2_333m", "sys_pll1_800m",
6187 + "sys_pll2_250m", "sys_pll2_1000m", "audio_pll1_out",
6188 +- "video_pll1_out", "sys_pll1_100m",};
6189 ++ "video_pll_out", "sys_pll1_100m",};
6190 +
6191 + static const char * const imx8mn_enet_axi_sels[] = {"osc_24m", "sys_pll1_266m", "sys_pll1_800m",
6192 + "sys_pll2_250m", "sys_pll2_200m", "audio_pll1_out",
6193 +- "video_pll1_out", "sys_pll3_out", };
6194 ++ "video_pll_out", "sys_pll3_out", };
6195 +
6196 + static const char * const imx8mn_nand_usdhc_sels[] = {"osc_24m", "sys_pll1_266m", "sys_pll1_800m",
6197 + "sys_pll2_200m", "sys_pll1_133m", "sys_pll3_out",
6198 +@@ -77,23 +77,23 @@ static const char * const imx8mn_usb_bus_sels[] = {"osc_24m", "sys_pll2_500m", "
6199 +
6200 + static const char * const imx8mn_gpu_axi_sels[] = {"osc_24m", "sys_pll1_800m", "gpu_pll_out",
6201 + "sys_pll3_out", "sys_pll2_1000m", "audio_pll1_out",
6202 +- "video_pll1_out", "audio_pll2_out", };
6203 ++ "video_pll_out", "audio_pll2_out", };
6204 +
6205 + static const char * const imx8mn_gpu_ahb_sels[] = {"osc_24m", "sys_pll1_800m", "gpu_pll_out",
6206 + "sys_pll3_out", "sys_pll2_1000m", "audio_pll1_out",
6207 +- "video_pll1_out", "audio_pll2_out", };
6208 ++ "video_pll_out", "audio_pll2_out", };
6209 +
6210 + static const char * const imx8mn_noc_sels[] = {"osc_24m", "sys_pll1_800m", "sys_pll3_out",
6211 + "sys_pll2_1000m", "sys_pll2_500m", "audio_pll1_out",
6212 +- "video_pll1_out", "audio_pll2_out", };
6213 ++ "video_pll_out", "audio_pll2_out", };
6214 +
6215 + static const char * const imx8mn_ahb_sels[] = {"osc_24m", "sys_pll1_133m", "sys_pll1_800m",
6216 + "sys_pll1_400m", "sys_pll2_125m", "sys_pll3_out",
6217 +- "audio_pll1_out", "video_pll1_out", };
6218 ++ "audio_pll1_out", "video_pll_out", };
6219 +
6220 + static const char * const imx8mn_audio_ahb_sels[] = {"osc_24m", "sys_pll2_500m", "sys_pll1_800m",
6221 + "sys_pll2_1000m", "sys_pll2_166m", "sys_pll3_out",
6222 +- "audio_pll1_out", "video_pll1_out", };
6223 ++ "audio_pll1_out", "video_pll_out", };
6224 +
6225 + static const char * const imx8mn_dram_alt_sels[] = {"osc_24m", "sys_pll1_800m", "sys_pll1_100m",
6226 + "sys_pll2_500m", "sys_pll2_1000m", "sys_pll3_out",
6227 +@@ -103,49 +103,49 @@ static const char * const imx8mn_dram_apb_sels[] = {"osc_24m", "sys_pll2_200m",
6228 + "sys_pll1_160m", "sys_pll1_800m", "sys_pll3_out",
6229 + "sys_pll2_250m", "audio_pll2_out", };
6230 +
6231 +-static const char * const imx8mn_disp_pixel_sels[] = {"osc_24m", "video_pll1_out", "audio_pll2_out",
6232 ++static const char * const imx8mn_disp_pixel_sels[] = {"osc_24m", "video_pll_out", "audio_pll2_out",
6233 + "audio_pll1_out", "sys_pll1_800m", "sys_pll2_1000m",
6234 + "sys_pll3_out", "clk_ext4", };
6235 +
6236 + static const char * const imx8mn_sai2_sels[] = {"osc_24m", "audio_pll1_out", "audio_pll2_out",
6237 +- "video_pll1_out", "sys_pll1_133m", "osc_hdmi",
6238 +- "clk_ext3", "clk_ext4", };
6239 ++ "video_pll_out", "sys_pll1_133m", "dummy",
6240 ++ "clk_ext2", "clk_ext3", };
6241 +
6242 + static const char * const imx8mn_sai3_sels[] = {"osc_24m", "audio_pll1_out", "audio_pll2_out",
6243 +- "video_pll1_out", "sys_pll1_133m", "osc_hdmi",
6244 ++ "video_pll_out", "sys_pll1_133m", "dummy",
6245 + "clk_ext3", "clk_ext4", };
6246 +
6247 + static const char * const imx8mn_sai5_sels[] = {"osc_24m", "audio_pll1_out", "audio_pll2_out",
6248 +- "video_pll1_out", "sys_pll1_133m", "osc_hdmi",
6249 ++ "video_pll_out", "sys_pll1_133m", "dummy",
6250 + "clk_ext2", "clk_ext3", };
6251 +
6252 + static const char * const imx8mn_sai6_sels[] = {"osc_24m", "audio_pll1_out", "audio_pll2_out",
6253 +- "video_pll1_out", "sys_pll1_133m", "osc_hdmi",
6254 ++ "video_pll_out", "sys_pll1_133m", "dummy",
6255 + "clk_ext3", "clk_ext4", };
6256 +
6257 + static const char * const imx8mn_sai7_sels[] = {"osc_24m", "audio_pll1_out", "audio_pll2_out",
6258 +- "video_pll1_out", "sys_pll1_133m", "osc_hdmi",
6259 ++ "video_pll_out", "sys_pll1_133m", "dummy",
6260 + "clk_ext3", "clk_ext4", };
6261 +
6262 + static const char * const imx8mn_spdif1_sels[] = {"osc_24m", "audio_pll1_out", "audio_pll2_out",
6263 +- "video_pll1_out", "sys_pll1_133m", "osc_hdmi",
6264 ++ "video_pll_out", "sys_pll1_133m", "dummy",
6265 + "clk_ext2", "clk_ext3", };
6266 +
6267 + static const char * const imx8mn_enet_ref_sels[] = {"osc_24m", "sys_pll2_125m", "sys_pll2_50m",
6268 + "sys_pll2_100m", "sys_pll1_160m", "audio_pll1_out",
6269 +- "video_pll1_out", "clk_ext4", };
6270 ++ "video_pll_out", "clk_ext4", };
6271 +
6272 + static const char * const imx8mn_enet_timer_sels[] = {"osc_24m", "sys_pll2_100m", "audio_pll1_out",
6273 + "clk_ext1", "clk_ext2", "clk_ext3",
6274 +- "clk_ext4", "video_pll1_out", };
6275 ++ "clk_ext4", "video_pll_out", };
6276 +
6277 + static const char * const imx8mn_enet_phy_sels[] = {"osc_24m", "sys_pll2_50m", "sys_pll2_125m",
6278 +- "sys_pll2_200m", "sys_pll2_500m", "video_pll1_out",
6279 +- "audio_pll2_out", };
6280 ++ "sys_pll2_200m", "sys_pll2_500m", "audio_pll1_out",
6281 ++ "video_pll_out", "audio_pll2_out", };
6282 +
6283 + static const char * const imx8mn_nand_sels[] = {"osc_24m", "sys_pll2_500m", "audio_pll1_out",
6284 + "sys_pll1_400m", "audio_pll2_out", "sys_pll3_out",
6285 +- "sys_pll2_250m", "video_pll1_out", };
6286 ++ "sys_pll2_250m", "video_pll_out", };
6287 +
6288 + static const char * const imx8mn_qspi_sels[] = {"osc_24m", "sys_pll1_400m", "sys_pll2_333m",
6289 + "sys_pll2_500m", "audio_pll2_out", "sys_pll1_266m",
6290 +@@ -160,19 +160,19 @@ static const char * const imx8mn_usdhc2_sels[] = {"osc_24m", "sys_pll1_400m", "s
6291 + "audio_pll2_out", "sys_pll1_100m", };
6292 +
6293 + static const char * const imx8mn_i2c1_sels[] = {"osc_24m", "sys_pll1_160m", "sys_pll2_50m",
6294 +- "sys_pll3_out", "audio_pll1_out", "video_pll1_out",
6295 ++ "sys_pll3_out", "audio_pll1_out", "video_pll_out",
6296 + "audio_pll2_out", "sys_pll1_133m", };
6297 +
6298 + static const char * const imx8mn_i2c2_sels[] = {"osc_24m", "sys_pll1_160m", "sys_pll2_50m",
6299 +- "sys_pll3_out", "audio_pll1_out", "video_pll1_out",
6300 ++ "sys_pll3_out", "audio_pll1_out", "video_pll_out",
6301 + "audio_pll2_out", "sys_pll1_133m", };
6302 +
6303 + static const char * const imx8mn_i2c3_sels[] = {"osc_24m", "sys_pll1_160m", "sys_pll2_50m",
6304 +- "sys_pll3_out", "audio_pll1_out", "video_pll1_out",
6305 ++ "sys_pll3_out", "audio_pll1_out", "video_pll_out",
6306 + "audio_pll2_out", "sys_pll1_133m", };
6307 +
6308 + static const char * const imx8mn_i2c4_sels[] = {"osc_24m", "sys_pll1_160m", "sys_pll2_50m",
6309 +- "sys_pll3_out", "audio_pll1_out", "video_pll1_out",
6310 ++ "sys_pll3_out", "audio_pll1_out", "video_pll_out",
6311 + "audio_pll2_out", "sys_pll1_133m", };
6312 +
6313 + static const char * const imx8mn_uart1_sels[] = {"osc_24m", "sys_pll1_80m", "sys_pll2_200m",
6314 +@@ -213,63 +213,63 @@ static const char * const imx8mn_ecspi2_sels[] = {"osc_24m", "sys_pll2_200m", "s
6315 +
6316 + static const char * const imx8mn_pwm1_sels[] = {"osc_24m", "sys_pll2_100m", "sys_pll1_160m",
6317 + "sys_pll1_40m", "sys_pll3_out", "clk_ext1",
6318 +- "sys_pll1_80m", "video_pll1_out", };
6319 ++ "sys_pll1_80m", "video_pll_out", };
6320 +
6321 + static const char * const imx8mn_pwm2_sels[] = {"osc_24m", "sys_pll2_100m", "sys_pll1_160m",
6322 + "sys_pll1_40m", "sys_pll3_out", "clk_ext1",
6323 +- "sys_pll1_80m", "video_pll1_out", };
6324 ++ "sys_pll1_80m", "video_pll_out", };
6325 +
6326 + static const char * const imx8mn_pwm3_sels[] = {"osc_24m", "sys_pll2_100m", "sys_pll1_160m",
6327 + "sys_pll1_40m", "sys_pll3_out", "clk_ext2",
6328 +- "sys_pll1_80m", "video_pll1_out", };
6329 ++ "sys_pll1_80m", "video_pll_out", };
6330 +
6331 + static const char * const imx8mn_pwm4_sels[] = {"osc_24m", "sys_pll2_100m", "sys_pll1_160m",
6332 + "sys_pll1_40m", "sys_pll3_out", "clk_ext2",
6333 +- "sys_pll1_80m", "video_pll1_out", };
6334 ++ "sys_pll1_80m", "video_pll_out", };
6335 +
6336 + static const char * const imx8mn_gpt1_sels[] = {"osc_24m", "sys_pll2_100m", "sys_pll1_400m",
6337 +- "sys_pll1_40m", "video_pll1_out", "sys_pll1_80m",
6338 ++ "sys_pll1_40m", "video_pll_out", "sys_pll1_80m",
6339 + "audio_pll1_out", "clk_ext1", };
6340 +
6341 + static const char * const imx8mn_gpt2_sels[] = {"osc_24m", "sys_pll2_100m", "sys_pll1_400m",
6342 +- "sys_pll1_40m", "video_pll1_out", "sys_pll1_80m",
6343 ++ "sys_pll1_40m", "video_pll_out", "sys_pll1_80m",
6344 + "audio_pll1_out", "clk_ext1", };
6345 +
6346 + static const char * const imx8mn_gpt3_sels[] = {"osc_24m", "sys_pll2_100m", "sys_pll1_400m",
6347 +- "sys_pll1_40m", "video_pll1_out", "sys_pll1_80m",
6348 ++ "sys_pll1_40m", "video_pll_out", "sys_pll1_80m",
6349 + "audio_pll1_out", "clk_ext1", };
6350 +
6351 + static const char * const imx8mn_gpt4_sels[] = {"osc_24m", "sys_pll2_100m", "sys_pll1_400m",
6352 +- "sys_pll1_40m", "video_pll1_out", "sys_pll1_80m",
6353 ++ "sys_pll1_40m", "video_pll_out", "sys_pll1_80m",
6354 + "audio_pll1_out", "clk_ext1", };
6355 +
6356 + static const char * const imx8mn_gpt5_sels[] = {"osc_24m", "sys_pll2_100m", "sys_pll1_400m",
6357 +- "sys_pll1_40m", "video_pll1_out", "sys_pll1_80m",
6358 ++ "sys_pll1_40m", "video_pll_out", "sys_pll1_80m",
6359 + "audio_pll1_out", "clk_ext1", };
6360 +
6361 + static const char * const imx8mn_gpt6_sels[] = {"osc_24m", "sys_pll2_100m", "sys_pll1_400m",
6362 +- "sys_pll1_40m", "video_pll1_out", "sys_pll1_80m",
6363 ++ "sys_pll1_40m", "video_pll_out", "sys_pll1_80m",
6364 + "audio_pll1_out", "clk_ext1", };
6365 +
6366 + static const char * const imx8mn_wdog_sels[] = {"osc_24m", "sys_pll1_133m", "sys_pll1_160m",
6367 +- "vpu_pll_out", "sys_pll2_125m", "sys_pll3_out",
6368 ++ "m7_alt_pll_out", "sys_pll2_125m", "sys_pll3_out",
6369 + "sys_pll1_80m", "sys_pll2_166m", };
6370 +
6371 +-static const char * const imx8mn_wrclk_sels[] = {"osc_24m", "sys_pll1_40m", "vpu_pll_out",
6372 ++static const char * const imx8mn_wrclk_sels[] = {"osc_24m", "sys_pll1_40m", "m7_alt_pll_out",
6373 + "sys_pll3_out", "sys_pll2_200m", "sys_pll1_266m",
6374 + "sys_pll2_500m", "sys_pll1_100m", };
6375 +
6376 + static const char * const imx8mn_dsi_core_sels[] = {"osc_24m", "sys_pll1_266m", "sys_pll2_250m",
6377 + "sys_pll1_800m", "sys_pll2_1000m", "sys_pll3_out",
6378 +- "audio_pll2_out", "video_pll1_out", };
6379 ++ "audio_pll2_out", "video_pll_out", };
6380 +
6381 + static const char * const imx8mn_dsi_phy_sels[] = {"osc_24m", "sys_pll2_125m", "sys_pll2_100m",
6382 + "sys_pll1_800m", "sys_pll2_1000m", "clk_ext2",
6383 +- "audio_pll2_out", "video_pll1_out", };
6384 ++ "audio_pll2_out", "video_pll_out", };
6385 +
6386 + static const char * const imx8mn_dsi_dbi_sels[] = {"osc_24m", "sys_pll1_266m", "sys_pll2_100m",
6387 + "sys_pll1_800m", "sys_pll2_1000m", "sys_pll3_out",
6388 +- "audio_pll2_out", "video_pll1_out", };
6389 ++ "audio_pll2_out", "video_pll_out", };
6390 +
6391 + static const char * const imx8mn_usdhc3_sels[] = {"osc_24m", "sys_pll1_400m", "sys_pll1_800m",
6392 + "sys_pll2_500m", "sys_pll3_out", "sys_pll1_266m",
6393 +@@ -277,15 +277,15 @@ static const char * const imx8mn_usdhc3_sels[] = {"osc_24m", "sys_pll1_400m", "s
6394 +
6395 + static const char * const imx8mn_camera_pixel_sels[] = {"osc_24m", "sys_pll1_266m", "sys_pll2_250m",
6396 + "sys_pll1_800m", "sys_pll2_1000m", "sys_pll3_out",
6397 +- "audio_pll2_out", "video_pll1_out", };
6398 ++ "audio_pll2_out", "video_pll_out", };
6399 +
6400 + static const char * const imx8mn_csi1_phy_sels[] = {"osc_24m", "sys_pll2_333m", "sys_pll2_100m",
6401 + "sys_pll1_800m", "sys_pll2_1000m", "clk_ext2",
6402 +- "audio_pll2_out", "video_pll1_out", };
6403 ++ "audio_pll2_out", "video_pll_out", };
6404 +
6405 + static const char * const imx8mn_csi2_phy_sels[] = {"osc_24m", "sys_pll2_333m", "sys_pll2_100m",
6406 + "sys_pll1_800m", "sys_pll2_1000m", "clk_ext2",
6407 +- "audio_pll2_out", "video_pll1_out", };
6408 ++ "audio_pll2_out", "video_pll_out", };
6409 +
6410 + static const char * const imx8mn_csi2_esc_sels[] = {"osc_24m", "sys_pll2_100m", "sys_pll1_80m",
6411 + "sys_pll1_800m", "sys_pll2_1000m", "sys_pll3_out",
6412 +@@ -306,9 +306,9 @@ static const char * const imx8mn_clko1_sels[] = {"osc_24m", "sys_pll1_800m", "du
6413 + "dummy", "sys_pll1_80m", };
6414 + static const char * const imx8mn_clko2_sels[] = {"osc_24m", "sys_pll2_200m", "sys_pll1_400m",
6415 + "sys_pll2_166m", "sys_pll3_out", "audio_pll1_out",
6416 +- "video_pll1_out", "osc_32k", };
6417 ++ "video_pll_out", "osc_32k", };
6418 +
6419 +-static const char * const clkout_sels[] = {"audio_pll1_out", "audio_pll2_out", "video_pll1_out",
6420 ++static const char * const clkout_sels[] = {"audio_pll1_out", "audio_pll2_out", "video_pll_out",
6421 + "dummy", "dummy", "gpu_pll_out", "dummy",
6422 + "arm_pll_out", "sys_pll1", "sys_pll2", "sys_pll3",
6423 + "dummy", "dummy", "osc_24m", "dummy", "osc_32k"};
6424 +@@ -349,19 +349,19 @@ static int imx8mn_clocks_probe(struct platform_device *pdev)
6425 +
6426 + hws[IMX8MN_AUDIO_PLL1_REF_SEL] = imx_clk_hw_mux("audio_pll1_ref_sel", base + 0x0, 0, 2, pll_ref_sels, ARRAY_SIZE(pll_ref_sels));
6427 + hws[IMX8MN_AUDIO_PLL2_REF_SEL] = imx_clk_hw_mux("audio_pll2_ref_sel", base + 0x14, 0, 2, pll_ref_sels, ARRAY_SIZE(pll_ref_sels));
6428 +- hws[IMX8MN_VIDEO_PLL1_REF_SEL] = imx_clk_hw_mux("video_pll1_ref_sel", base + 0x28, 0, 2, pll_ref_sels, ARRAY_SIZE(pll_ref_sels));
6429 ++ hws[IMX8MN_VIDEO_PLL_REF_SEL] = imx_clk_hw_mux("video_pll_ref_sel", base + 0x28, 0, 2, pll_ref_sels, ARRAY_SIZE(pll_ref_sels));
6430 + hws[IMX8MN_DRAM_PLL_REF_SEL] = imx_clk_hw_mux("dram_pll_ref_sel", base + 0x50, 0, 2, pll_ref_sels, ARRAY_SIZE(pll_ref_sels));
6431 + hws[IMX8MN_GPU_PLL_REF_SEL] = imx_clk_hw_mux("gpu_pll_ref_sel", base + 0x64, 0, 2, pll_ref_sels, ARRAY_SIZE(pll_ref_sels));
6432 +- hws[IMX8MN_VPU_PLL_REF_SEL] = imx_clk_hw_mux("vpu_pll_ref_sel", base + 0x74, 0, 2, pll_ref_sels, ARRAY_SIZE(pll_ref_sels));
6433 ++ hws[IMX8MN_M7_ALT_PLL_REF_SEL] = imx_clk_hw_mux("m7_alt_pll_ref_sel", base + 0x74, 0, 2, pll_ref_sels, ARRAY_SIZE(pll_ref_sels));
6434 + hws[IMX8MN_ARM_PLL_REF_SEL] = imx_clk_hw_mux("arm_pll_ref_sel", base + 0x84, 0, 2, pll_ref_sels, ARRAY_SIZE(pll_ref_sels));
6435 + hws[IMX8MN_SYS_PLL3_REF_SEL] = imx_clk_hw_mux("sys_pll3_ref_sel", base + 0x114, 0, 2, pll_ref_sels, ARRAY_SIZE(pll_ref_sels));
6436 +
6437 + hws[IMX8MN_AUDIO_PLL1] = imx_clk_hw_pll14xx("audio_pll1", "audio_pll1_ref_sel", base, &imx_1443x_pll);
6438 + hws[IMX8MN_AUDIO_PLL2] = imx_clk_hw_pll14xx("audio_pll2", "audio_pll2_ref_sel", base + 0x14, &imx_1443x_pll);
6439 +- hws[IMX8MN_VIDEO_PLL1] = imx_clk_hw_pll14xx("video_pll1", "video_pll1_ref_sel", base + 0x28, &imx_1443x_pll);
6440 ++ hws[IMX8MN_VIDEO_PLL] = imx_clk_hw_pll14xx("video_pll", "video_pll_ref_sel", base + 0x28, &imx_1443x_pll);
6441 + hws[IMX8MN_DRAM_PLL] = imx_clk_hw_pll14xx("dram_pll", "dram_pll_ref_sel", base + 0x50, &imx_1443x_dram_pll);
6442 + hws[IMX8MN_GPU_PLL] = imx_clk_hw_pll14xx("gpu_pll", "gpu_pll_ref_sel", base + 0x64, &imx_1416x_pll);
6443 +- hws[IMX8MN_VPU_PLL] = imx_clk_hw_pll14xx("vpu_pll", "vpu_pll_ref_sel", base + 0x74, &imx_1416x_pll);
6444 ++ hws[IMX8MN_M7_ALT_PLL] = imx_clk_hw_pll14xx("m7_alt_pll", "m7_alt_pll_ref_sel", base + 0x74, &imx_1416x_pll);
6445 + hws[IMX8MN_ARM_PLL] = imx_clk_hw_pll14xx("arm_pll", "arm_pll_ref_sel", base + 0x84, &imx_1416x_pll);
6446 + hws[IMX8MN_SYS_PLL1] = imx_clk_hw_fixed("sys_pll1", 800000000);
6447 + hws[IMX8MN_SYS_PLL2] = imx_clk_hw_fixed("sys_pll2", 1000000000);
6448 +@@ -370,20 +370,20 @@ static int imx8mn_clocks_probe(struct platform_device *pdev)
6449 + /* PLL bypass out */
6450 + hws[IMX8MN_AUDIO_PLL1_BYPASS] = imx_clk_hw_mux_flags("audio_pll1_bypass", base, 16, 1, audio_pll1_bypass_sels, ARRAY_SIZE(audio_pll1_bypass_sels), CLK_SET_RATE_PARENT);
6451 + hws[IMX8MN_AUDIO_PLL2_BYPASS] = imx_clk_hw_mux_flags("audio_pll2_bypass", base + 0x14, 16, 1, audio_pll2_bypass_sels, ARRAY_SIZE(audio_pll2_bypass_sels), CLK_SET_RATE_PARENT);
6452 +- hws[IMX8MN_VIDEO_PLL1_BYPASS] = imx_clk_hw_mux_flags("video_pll1_bypass", base + 0x28, 16, 1, video_pll1_bypass_sels, ARRAY_SIZE(video_pll1_bypass_sels), CLK_SET_RATE_PARENT);
6453 ++ hws[IMX8MN_VIDEO_PLL_BYPASS] = imx_clk_hw_mux_flags("video_pll_bypass", base + 0x28, 16, 1, video_pll_bypass_sels, ARRAY_SIZE(video_pll_bypass_sels), CLK_SET_RATE_PARENT);
6454 + hws[IMX8MN_DRAM_PLL_BYPASS] = imx_clk_hw_mux_flags("dram_pll_bypass", base + 0x50, 16, 1, dram_pll_bypass_sels, ARRAY_SIZE(dram_pll_bypass_sels), CLK_SET_RATE_PARENT);
6455 + hws[IMX8MN_GPU_PLL_BYPASS] = imx_clk_hw_mux_flags("gpu_pll_bypass", base + 0x64, 28, 1, gpu_pll_bypass_sels, ARRAY_SIZE(gpu_pll_bypass_sels), CLK_SET_RATE_PARENT);
6456 +- hws[IMX8MN_VPU_PLL_BYPASS] = imx_clk_hw_mux_flags("vpu_pll_bypass", base + 0x74, 28, 1, vpu_pll_bypass_sels, ARRAY_SIZE(vpu_pll_bypass_sels), CLK_SET_RATE_PARENT);
6457 ++ hws[IMX8MN_M7_ALT_PLL_BYPASS] = imx_clk_hw_mux_flags("m7_alt_pll_bypass", base + 0x74, 28, 1, m7_alt_pll_bypass_sels, ARRAY_SIZE(m7_alt_pll_bypass_sels), CLK_SET_RATE_PARENT);
6458 + hws[IMX8MN_ARM_PLL_BYPASS] = imx_clk_hw_mux_flags("arm_pll_bypass", base + 0x84, 28, 1, arm_pll_bypass_sels, ARRAY_SIZE(arm_pll_bypass_sels), CLK_SET_RATE_PARENT);
6459 + hws[IMX8MN_SYS_PLL3_BYPASS] = imx_clk_hw_mux_flags("sys_pll3_bypass", base + 0x114, 28, 1, sys_pll3_bypass_sels, ARRAY_SIZE(sys_pll3_bypass_sels), CLK_SET_RATE_PARENT);
6460 +
6461 + /* PLL out gate */
6462 + hws[IMX8MN_AUDIO_PLL1_OUT] = imx_clk_hw_gate("audio_pll1_out", "audio_pll1_bypass", base, 13);
6463 + hws[IMX8MN_AUDIO_PLL2_OUT] = imx_clk_hw_gate("audio_pll2_out", "audio_pll2_bypass", base + 0x14, 13);
6464 +- hws[IMX8MN_VIDEO_PLL1_OUT] = imx_clk_hw_gate("video_pll1_out", "video_pll1_bypass", base + 0x28, 13);
6465 ++ hws[IMX8MN_VIDEO_PLL_OUT] = imx_clk_hw_gate("video_pll_out", "video_pll_bypass", base + 0x28, 13);
6466 + hws[IMX8MN_DRAM_PLL_OUT] = imx_clk_hw_gate("dram_pll_out", "dram_pll_bypass", base + 0x50, 13);
6467 + hws[IMX8MN_GPU_PLL_OUT] = imx_clk_hw_gate("gpu_pll_out", "gpu_pll_bypass", base + 0x64, 11);
6468 +- hws[IMX8MN_VPU_PLL_OUT] = imx_clk_hw_gate("vpu_pll_out", "vpu_pll_bypass", base + 0x74, 11);
6469 ++ hws[IMX8MN_M7_ALT_PLL_OUT] = imx_clk_hw_gate("m7_alt_pll_out", "m7_alt_pll_bypass", base + 0x74, 11);
6470 + hws[IMX8MN_ARM_PLL_OUT] = imx_clk_hw_gate("arm_pll_out", "arm_pll_bypass", base + 0x84, 11);
6471 + hws[IMX8MN_SYS_PLL3_OUT] = imx_clk_hw_gate("sys_pll3_out", "sys_pll3_bypass", base + 0x114, 11);
6472 +
6473 +diff --git a/drivers/clk/imx/clk-imx8mp.c b/drivers/clk/imx/clk-imx8mp.c
6474 +index 652ae58c2735f..5d68d975b4eb1 100644
6475 +--- a/drivers/clk/imx/clk-imx8mp.c
6476 ++++ b/drivers/clk/imx/clk-imx8mp.c
6477 +@@ -17,6 +17,7 @@
6478 +
6479 + static u32 share_count_nand;
6480 + static u32 share_count_media;
6481 ++static u32 share_count_usb;
6482 +
6483 + static const char * const pll_ref_sels[] = { "osc_24m", "dummy", "dummy", "dummy", };
6484 + static const char * const audio_pll1_bypass_sels[] = {"audio_pll1", "audio_pll1_ref_sel", };
6485 +@@ -673,7 +674,8 @@ static int imx8mp_clocks_probe(struct platform_device *pdev)
6486 + hws[IMX8MP_CLK_UART2_ROOT] = imx_clk_hw_gate4("uart2_root_clk", "uart2", ccm_base + 0x44a0, 0);
6487 + hws[IMX8MP_CLK_UART3_ROOT] = imx_clk_hw_gate4("uart3_root_clk", "uart3", ccm_base + 0x44b0, 0);
6488 + hws[IMX8MP_CLK_UART4_ROOT] = imx_clk_hw_gate4("uart4_root_clk", "uart4", ccm_base + 0x44c0, 0);
6489 +- hws[IMX8MP_CLK_USB_ROOT] = imx_clk_hw_gate4("usb_root_clk", "hsio_axi", ccm_base + 0x44d0, 0);
6490 ++ hws[IMX8MP_CLK_USB_ROOT] = imx_clk_hw_gate2_shared2("usb_root_clk", "hsio_axi", ccm_base + 0x44d0, 0, &share_count_usb);
6491 ++ hws[IMX8MP_CLK_USB_SUSP] = imx_clk_hw_gate2_shared2("usb_suspend_clk", "osc_32k", ccm_base + 0x44d0, 0, &share_count_usb);
6492 + hws[IMX8MP_CLK_USB_PHY_ROOT] = imx_clk_hw_gate4("usb_phy_root_clk", "usb_phy_ref", ccm_base + 0x44f0, 0);
6493 + hws[IMX8MP_CLK_USDHC1_ROOT] = imx_clk_hw_gate4("usdhc1_root_clk", "usdhc1", ccm_base + 0x4510, 0);
6494 + hws[IMX8MP_CLK_USDHC2_ROOT] = imx_clk_hw_gate4("usdhc2_root_clk", "usdhc2", ccm_base + 0x4520, 0);
6495 +diff --git a/drivers/clk/imx/clk-imx93.c b/drivers/clk/imx/clk-imx93.c
6496 +index dcc41d178238e..2e99c3443d3c3 100644
6497 +--- a/drivers/clk/imx/clk-imx93.c
6498 ++++ b/drivers/clk/imx/clk-imx93.c
6499 +@@ -162,7 +162,7 @@ static const struct imx93_clk_ccgr {
6500 + { IMX93_CLK_MU_B_GATE, "mu_b", "bus_aon_root", 0x8500, },
6501 + { IMX93_CLK_EDMA1_GATE, "edma1", "m33_root", 0x8540, },
6502 + { IMX93_CLK_EDMA2_GATE, "edma2", "wakeup_axi_root", 0x8580, },
6503 +- { IMX93_CLK_FLEXSPI1_GATE, "flexspi", "flexspi_root", 0x8640, },
6504 ++ { IMX93_CLK_FLEXSPI1_GATE, "flexspi1", "flexspi1_root", 0x8640, },
6505 + { IMX93_CLK_GPIO1_GATE, "gpio1", "m33_root", 0x8880, },
6506 + { IMX93_CLK_GPIO2_GATE, "gpio2", "bus_wakeup_root", 0x88c0, },
6507 + { IMX93_CLK_GPIO3_GATE, "gpio3", "bus_wakeup_root", 0x8900, },
6508 +@@ -229,7 +229,7 @@ static const struct imx93_clk_ccgr {
6509 + { IMX93_CLK_AUD_XCVR_GATE, "aud_xcvr", "audio_xcvr_root", 0x9b80, },
6510 + { IMX93_CLK_SPDIF_GATE, "spdif", "spdif_root", 0x9c00, },
6511 + { IMX93_CLK_HSIO_32K_GATE, "hsio_32k", "osc_32k", 0x9dc0, },
6512 +- { IMX93_CLK_ENET1_GATE, "enet1", "enet_root", 0x9e00, },
6513 ++ { IMX93_CLK_ENET1_GATE, "enet1", "wakeup_axi_root", 0x9e00, },
6514 + { IMX93_CLK_ENET_QOS_GATE, "enet_qos", "wakeup_axi_root", 0x9e40, },
6515 + { IMX93_CLK_SYS_CNT_GATE, "sys_cnt", "osc_24m", 0x9e80, },
6516 + { IMX93_CLK_TSTMR1_GATE, "tstmr1", "bus_aon_root", 0x9ec0, },
6517 +@@ -247,7 +247,7 @@ static int imx93_clocks_probe(struct platform_device *pdev)
6518 + struct device_node *np = dev->of_node;
6519 + const struct imx93_clk_root *root;
6520 + const struct imx93_clk_ccgr *ccgr;
6521 +- void __iomem *base = NULL;
6522 ++ void __iomem *base, *anatop_base;
6523 + int i, ret;
6524 +
6525 + clk_hw_data = kzalloc(struct_size(clk_hw_data, hws,
6526 +@@ -274,20 +274,22 @@ static int imx93_clocks_probe(struct platform_device *pdev)
6527 + "sys_pll_pfd2", 1, 2);
6528 +
6529 + np = of_find_compatible_node(NULL, NULL, "fsl,imx93-anatop");
6530 +- base = of_iomap(np, 0);
6531 ++ anatop_base = of_iomap(np, 0);
6532 + of_node_put(np);
6533 +- if (WARN_ON(!base))
6534 ++ if (WARN_ON(!anatop_base))
6535 + return -ENOMEM;
6536 +
6537 +- clks[IMX93_CLK_AUDIO_PLL] = imx_clk_fracn_gppll("audio_pll", "osc_24m", base + 0x1200,
6538 ++ clks[IMX93_CLK_AUDIO_PLL] = imx_clk_fracn_gppll("audio_pll", "osc_24m", anatop_base + 0x1200,
6539 + &imx_fracn_gppll);
6540 +- clks[IMX93_CLK_VIDEO_PLL] = imx_clk_fracn_gppll("video_pll", "osc_24m", base + 0x1400,
6541 ++ clks[IMX93_CLK_VIDEO_PLL] = imx_clk_fracn_gppll("video_pll", "osc_24m", anatop_base + 0x1400,
6542 + &imx_fracn_gppll);
6543 +
6544 + np = dev->of_node;
6545 + base = devm_platform_ioremap_resource(pdev, 0);
6546 +- if (WARN_ON(IS_ERR(base)))
6547 ++ if (WARN_ON(IS_ERR(base))) {
6548 ++ iounmap(anatop_base);
6549 + return PTR_ERR(base);
6550 ++ }
6551 +
6552 + for (i = 0; i < ARRAY_SIZE(root_array); i++) {
6553 + root = &root_array[i];
6554 +@@ -317,6 +319,7 @@ static int imx93_clocks_probe(struct platform_device *pdev)
6555 +
6556 + unregister_hws:
6557 + imx_unregister_hw_clocks(clks, IMX93_CLK_END);
6558 ++ iounmap(anatop_base);
6559 +
6560 + return ret;
6561 + }
6562 +diff --git a/drivers/clk/imx/clk-imxrt1050.c b/drivers/clk/imx/clk-imxrt1050.c
6563 +index 9539d35588ee9..26108e9f7e67a 100644
6564 +--- a/drivers/clk/imx/clk-imxrt1050.c
6565 ++++ b/drivers/clk/imx/clk-imxrt1050.c
6566 +@@ -140,7 +140,7 @@ static int imxrt1050_clocks_probe(struct platform_device *pdev)
6567 + hws[IMXRT1050_CLK_USDHC1] = imx_clk_hw_gate2("usdhc1", "usdhc1_podf", ccm_base + 0x80, 2);
6568 + hws[IMXRT1050_CLK_USDHC2] = imx_clk_hw_gate2("usdhc2", "usdhc2_podf", ccm_base + 0x80, 4);
6569 + hws[IMXRT1050_CLK_LPUART1] = imx_clk_hw_gate2("lpuart1", "lpuart_podf", ccm_base + 0x7c, 24);
6570 +- hws[IMXRT1050_CLK_LCDIF_APB] = imx_clk_hw_gate2("lcdif", "lcdif_podf", ccm_base + 0x74, 10);
6571 ++ hws[IMXRT1050_CLK_LCDIF_APB] = imx_clk_hw_gate2("lcdif", "lcdif_podf", ccm_base + 0x70, 28);
6572 + hws[IMXRT1050_CLK_DMA] = imx_clk_hw_gate("dma", "ipg", ccm_base + 0x7C, 6);
6573 + hws[IMXRT1050_CLK_DMA_MUX] = imx_clk_hw_gate("dmamux0", "ipg", ccm_base + 0x7C, 7);
6574 + imx_check_clk_hws(hws, IMXRT1050_CLK_END);
6575 +diff --git a/drivers/clk/mediatek/clk-mt7986-infracfg.c b/drivers/clk/mediatek/clk-mt7986-infracfg.c
6576 +index d90727a53283c..49666047bf0ed 100644
6577 +--- a/drivers/clk/mediatek/clk-mt7986-infracfg.c
6578 ++++ b/drivers/clk/mediatek/clk-mt7986-infracfg.c
6579 +@@ -153,7 +153,7 @@ static const struct mtk_gate infra_clks[] = {
6580 + 18),
6581 + GATE_INFRA1(CLK_INFRA_MSDC_66M_CK, "infra_msdc_66m", "infra_sysaxi_d2",
6582 + 19),
6583 +- GATE_INFRA1(CLK_INFRA_ADC_26M_CK, "infra_adc_26m", "csw_f26m_sel", 20),
6584 ++ GATE_INFRA1(CLK_INFRA_ADC_26M_CK, "infra_adc_26m", "infra_adc_frc", 20),
6585 + GATE_INFRA1(CLK_INFRA_ADC_FRC_CK, "infra_adc_frc", "csw_f26m_sel", 21),
6586 + GATE_INFRA1(CLK_INFRA_FBIST2FPC_CK, "infra_fbist2fpc", "nfi1x_sel", 23),
6587 + /* INFRA2 */
6588 +diff --git a/drivers/clk/qcom/clk-krait.c b/drivers/clk/qcom/clk-krait.c
6589 +index 45da736bd5f4c..293a9dfa7151a 100644
6590 +--- a/drivers/clk/qcom/clk-krait.c
6591 ++++ b/drivers/clk/qcom/clk-krait.c
6592 +@@ -114,6 +114,8 @@ static int krait_div2_set_rate(struct clk_hw *hw, unsigned long rate,
6593 +
6594 + if (d->lpl)
6595 + mask = mask << (d->shift + LPL_SHIFT) | mask << d->shift;
6596 ++ else
6597 ++ mask <<= d->shift;
6598 +
6599 + spin_lock_irqsave(&krait_clock_reg_lock, flags);
6600 + val = krait_get_l2_indirect_reg(d->offset);
6601 +diff --git a/drivers/clk/qcom/dispcc-sm6350.c b/drivers/clk/qcom/dispcc-sm6350.c
6602 +index 0c3c2e26ede90..ea6f54ed846ec 100644
6603 +--- a/drivers/clk/qcom/dispcc-sm6350.c
6604 ++++ b/drivers/clk/qcom/dispcc-sm6350.c
6605 +@@ -306,7 +306,7 @@ static struct clk_rcg2 disp_cc_mdss_pclk0_clk_src = {
6606 + .name = "disp_cc_mdss_pclk0_clk_src",
6607 + .parent_data = disp_cc_parent_data_5,
6608 + .num_parents = ARRAY_SIZE(disp_cc_parent_data_5),
6609 +- .flags = CLK_SET_RATE_PARENT | CLK_GET_RATE_NOCACHE,
6610 ++ .flags = CLK_SET_RATE_PARENT | CLK_GET_RATE_NOCACHE | CLK_OPS_PARENT_ENABLE,
6611 + .ops = &clk_pixel_ops,
6612 + },
6613 + };
6614 +@@ -385,7 +385,7 @@ static struct clk_branch disp_cc_mdss_byte0_clk = {
6615 + &disp_cc_mdss_byte0_clk_src.clkr.hw,
6616 + },
6617 + .num_parents = 1,
6618 +- .flags = CLK_SET_RATE_PARENT | CLK_GET_RATE_NOCACHE,
6619 ++ .flags = CLK_SET_RATE_PARENT | CLK_GET_RATE_NOCACHE | CLK_OPS_PARENT_ENABLE,
6620 + .ops = &clk_branch2_ops,
6621 + },
6622 + },
6623 +diff --git a/drivers/clk/qcom/gcc-ipq806x.c b/drivers/clk/qcom/gcc-ipq806x.c
6624 +index 718de17a1e600..6447f3e81b555 100644
6625 +--- a/drivers/clk/qcom/gcc-ipq806x.c
6626 ++++ b/drivers/clk/qcom/gcc-ipq806x.c
6627 +@@ -79,7 +79,9 @@ static struct clk_regmap pll4_vote = {
6628 + .enable_mask = BIT(4),
6629 + .hw.init = &(struct clk_init_data){
6630 + .name = "pll4_vote",
6631 +- .parent_names = (const char *[]){ "pll4" },
6632 ++ .parent_data = &(const struct clk_parent_data){
6633 ++ .fw_name = "pll4", .name = "pll4",
6634 ++ },
6635 + .num_parents = 1,
6636 + .ops = &clk_pll_vote_ops,
6637 + },
6638 +diff --git a/drivers/clk/qcom/gcc-sm8250.c b/drivers/clk/qcom/gcc-sm8250.c
6639 +index 9755ef4888c19..a0ba37656b07b 100644
6640 +--- a/drivers/clk/qcom/gcc-sm8250.c
6641 ++++ b/drivers/clk/qcom/gcc-sm8250.c
6642 +@@ -3267,7 +3267,7 @@ static struct gdsc usb30_prim_gdsc = {
6643 + .pd = {
6644 + .name = "usb30_prim_gdsc",
6645 + },
6646 +- .pwrsts = PWRSTS_OFF_ON,
6647 ++ .pwrsts = PWRSTS_RET_ON,
6648 + };
6649 +
6650 + static struct gdsc usb30_sec_gdsc = {
6651 +@@ -3275,7 +3275,7 @@ static struct gdsc usb30_sec_gdsc = {
6652 + .pd = {
6653 + .name = "usb30_sec_gdsc",
6654 + },
6655 +- .pwrsts = PWRSTS_OFF_ON,
6656 ++ .pwrsts = PWRSTS_RET_ON,
6657 + };
6658 +
6659 + static struct gdsc hlos1_vote_mmnoc_mmu_tbu_hf0_gdsc = {
6660 +diff --git a/drivers/clk/qcom/lpassaudiocc-sc7280.c b/drivers/clk/qcom/lpassaudiocc-sc7280.c
6661 +index 6ab6e5a34c724..b2646b7e13c9f 100644
6662 +--- a/drivers/clk/qcom/lpassaudiocc-sc7280.c
6663 ++++ b/drivers/clk/qcom/lpassaudiocc-sc7280.c
6664 +@@ -12,6 +12,7 @@
6665 + #include <linux/pm_runtime.h>
6666 + #include <linux/regmap.h>
6667 +
6668 ++#include <dt-bindings/clock/qcom,lpass-sc7280.h>
6669 + #include <dt-bindings/clock/qcom,lpassaudiocc-sc7280.h>
6670 +
6671 + #include "clk-alpha-pll.h"
6672 +@@ -22,6 +23,7 @@
6673 + #include "clk-regmap-mux.h"
6674 + #include "common.h"
6675 + #include "gdsc.h"
6676 ++#include "reset.h"
6677 +
6678 + enum {
6679 + P_BI_TCXO,
6680 +@@ -38,6 +40,32 @@ static const struct pll_vco zonda_vco[] = {
6681 + { 595200000UL, 3600000000UL, 0 },
6682 + };
6683 +
6684 ++static struct clk_branch lpass_q6ss_ahbm_clk = {
6685 ++ .halt_reg = 0x901c,
6686 ++ .halt_check = BRANCH_HALT,
6687 ++ .clkr = {
6688 ++ .enable_reg = 0x901c,
6689 ++ .enable_mask = BIT(0),
6690 ++ .hw.init = &(struct clk_init_data){
6691 ++ .name = "lpass_q6ss_ahbm_clk",
6692 ++ .ops = &clk_branch2_ops,
6693 ++ },
6694 ++ },
6695 ++};
6696 ++
6697 ++static struct clk_branch lpass_q6ss_ahbs_clk = {
6698 ++ .halt_reg = 0x9020,
6699 ++ .halt_check = BRANCH_HALT_VOTED,
6700 ++ .clkr = {
6701 ++ .enable_reg = 0x9020,
6702 ++ .enable_mask = BIT(0),
6703 ++ .hw.init = &(struct clk_init_data){
6704 ++ .name = "lpass_q6ss_ahbs_clk",
6705 ++ .ops = &clk_branch2_ops,
6706 ++ },
6707 ++ },
6708 ++};
6709 ++
6710 + /* 1128.96MHz configuration */
6711 + static const struct alpha_pll_config lpass_audio_cc_pll_config = {
6712 + .l = 0x3a,
6713 +@@ -221,7 +249,7 @@ static struct clk_rcg2 lpass_aon_cc_main_rcg_clk_src = {
6714 + .parent_data = lpass_aon_cc_parent_data_0,
6715 + .num_parents = ARRAY_SIZE(lpass_aon_cc_parent_data_0),
6716 + .flags = CLK_OPS_PARENT_ENABLE,
6717 +- .ops = &clk_rcg2_ops,
6718 ++ .ops = &clk_rcg2_shared_ops,
6719 + },
6720 + };
6721 +
6722 +@@ -614,6 +642,11 @@ static struct gdsc lpass_aon_cc_lpass_audio_hm_gdsc = {
6723 + .flags = RETAIN_FF_ENABLE,
6724 + };
6725 +
6726 ++static struct clk_regmap *lpass_cc_sc7280_clocks[] = {
6727 ++ [LPASS_Q6SS_AHBM_CLK] = &lpass_q6ss_ahbm_clk.clkr,
6728 ++ [LPASS_Q6SS_AHBS_CLK] = &lpass_q6ss_ahbs_clk.clkr,
6729 ++};
6730 ++
6731 + static struct clk_regmap *lpass_aon_cc_sc7280_clocks[] = {
6732 + [LPASS_AON_CC_AUDIO_HM_H_CLK] = &lpass_aon_cc_audio_hm_h_clk.clkr,
6733 + [LPASS_AON_CC_VA_MEM0_CLK] = &lpass_aon_cc_va_mem0_clk.clkr,
6734 +@@ -659,45 +692,47 @@ static struct regmap_config lpass_audio_cc_sc7280_regmap_config = {
6735 + .fast_io = true,
6736 + };
6737 +
6738 ++static const struct qcom_cc_desc lpass_cc_sc7280_desc = {
6739 ++ .config = &lpass_audio_cc_sc7280_regmap_config,
6740 ++ .clks = lpass_cc_sc7280_clocks,
6741 ++ .num_clks = ARRAY_SIZE(lpass_cc_sc7280_clocks),
6742 ++};
6743 ++
6744 + static const struct qcom_cc_desc lpass_audio_cc_sc7280_desc = {
6745 + .config = &lpass_audio_cc_sc7280_regmap_config,
6746 + .clks = lpass_audio_cc_sc7280_clocks,
6747 + .num_clks = ARRAY_SIZE(lpass_audio_cc_sc7280_clocks),
6748 + };
6749 +
6750 ++static const struct qcom_reset_map lpass_audio_cc_sc7280_resets[] = {
6751 ++ [LPASS_AUDIO_SWR_RX_CGCR] = { 0xa0, 1 },
6752 ++ [LPASS_AUDIO_SWR_TX_CGCR] = { 0xa8, 1 },
6753 ++ [LPASS_AUDIO_SWR_WSA_CGCR] = { 0xb0, 1 },
6754 ++};
6755 ++
6756 ++static const struct qcom_cc_desc lpass_audio_cc_reset_sc7280_desc = {
6757 ++ .config = &lpass_audio_cc_sc7280_regmap_config,
6758 ++ .resets = lpass_audio_cc_sc7280_resets,
6759 ++ .num_resets = ARRAY_SIZE(lpass_audio_cc_sc7280_resets),
6760 ++};
6761 ++
6762 + static const struct of_device_id lpass_audio_cc_sc7280_match_table[] = {
6763 + { .compatible = "qcom,sc7280-lpassaudiocc" },
6764 + { }
6765 + };
6766 + MODULE_DEVICE_TABLE(of, lpass_audio_cc_sc7280_match_table);
6767 +
6768 +-static void lpassaudio_pm_runtime_disable(void *data)
6769 +-{
6770 +- pm_runtime_disable(data);
6771 +-}
6772 +-
6773 +-static void lpassaudio_pm_clk_destroy(void *data)
6774 +-{
6775 +- pm_clk_destroy(data);
6776 +-}
6777 +-
6778 +-static int lpassaudio_create_pm_clks(struct platform_device *pdev)
6779 ++static int lpass_audio_setup_runtime_pm(struct platform_device *pdev)
6780 + {
6781 + int ret;
6782 +
6783 + pm_runtime_use_autosuspend(&pdev->dev);
6784 + pm_runtime_set_autosuspend_delay(&pdev->dev, 50);
6785 +- pm_runtime_enable(&pdev->dev);
6786 +-
6787 +- ret = devm_add_action_or_reset(&pdev->dev, lpassaudio_pm_runtime_disable, &pdev->dev);
6788 +- if (ret)
6789 +- return ret;
6790 +-
6791 +- ret = pm_clk_create(&pdev->dev);
6792 ++ ret = devm_pm_runtime_enable(&pdev->dev);
6793 + if (ret)
6794 + return ret;
6795 +
6796 +- ret = devm_add_action_or_reset(&pdev->dev, lpassaudio_pm_clk_destroy, &pdev->dev);
6797 ++ ret = devm_pm_clk_create(&pdev->dev);
6798 + if (ret)
6799 + return ret;
6800 +
6801 +@@ -705,7 +740,7 @@ static int lpassaudio_create_pm_clks(struct platform_device *pdev)
6802 + if (ret < 0)
6803 + dev_err(&pdev->dev, "failed to acquire iface clock\n");
6804 +
6805 +- return ret;
6806 ++ return pm_runtime_resume_and_get(&pdev->dev);
6807 + }
6808 +
6809 + static int lpass_audio_cc_sc7280_probe(struct platform_device *pdev)
6810 +@@ -714,7 +749,7 @@ static int lpass_audio_cc_sc7280_probe(struct platform_device *pdev)
6811 + struct regmap *regmap;
6812 + int ret;
6813 +
6814 +- ret = lpassaudio_create_pm_clks(pdev);
6815 ++ ret = lpass_audio_setup_runtime_pm(pdev);
6816 + if (ret)
6817 + return ret;
6818 +
6819 +@@ -724,8 +759,8 @@ static int lpass_audio_cc_sc7280_probe(struct platform_device *pdev)
6820 +
6821 + regmap = qcom_cc_map(pdev, desc);
6822 + if (IS_ERR(regmap)) {
6823 +- pm_runtime_disable(&pdev->dev);
6824 +- return PTR_ERR(regmap);
6825 ++ ret = PTR_ERR(regmap);
6826 ++ goto exit;
6827 + }
6828 +
6829 + clk_zonda_pll_configure(&lpass_audio_cc_pll, regmap, &lpass_audio_cc_pll_config);
6830 +@@ -734,16 +769,21 @@ static int lpass_audio_cc_sc7280_probe(struct platform_device *pdev)
6831 + regmap_write(regmap, 0x4, 0x3b);
6832 + regmap_write(regmap, 0x8, 0xff05);
6833 +
6834 +- ret = qcom_cc_really_probe(pdev, &lpass_audio_cc_sc7280_desc, regmap);
6835 ++ ret = qcom_cc_probe_by_index(pdev, 0, &lpass_audio_cc_sc7280_desc);
6836 + if (ret) {
6837 + dev_err(&pdev->dev, "Failed to register LPASS AUDIO CC clocks\n");
6838 +- pm_runtime_disable(&pdev->dev);
6839 +- return ret;
6840 ++ goto exit;
6841 ++ }
6842 ++
6843 ++ ret = qcom_cc_probe_by_index(pdev, 1, &lpass_audio_cc_reset_sc7280_desc);
6844 ++ if (ret) {
6845 ++ dev_err(&pdev->dev, "Failed to register LPASS AUDIO CC Resets\n");
6846 ++ goto exit;
6847 + }
6848 +
6849 + pm_runtime_mark_last_busy(&pdev->dev);
6850 ++exit:
6851 + pm_runtime_put_autosuspend(&pdev->dev);
6852 +- pm_runtime_put_sync(&pdev->dev);
6853 +
6854 + return ret;
6855 + }
6856 +@@ -781,27 +821,38 @@ static int lpass_aon_cc_sc7280_probe(struct platform_device *pdev)
6857 + struct regmap *regmap;
6858 + int ret;
6859 +
6860 +- ret = lpassaudio_create_pm_clks(pdev);
6861 ++ ret = lpass_audio_setup_runtime_pm(pdev);
6862 + if (ret)
6863 + return ret;
6864 +
6865 ++ if (of_property_read_bool(pdev->dev.of_node, "qcom,adsp-pil-mode")) {
6866 ++ lpass_audio_cc_sc7280_regmap_config.name = "cc";
6867 ++ desc = &lpass_cc_sc7280_desc;
6868 ++ ret = qcom_cc_probe(pdev, desc);
6869 ++ goto exit;
6870 ++ }
6871 ++
6872 + lpass_audio_cc_sc7280_regmap_config.name = "lpasscc_aon";
6873 + lpass_audio_cc_sc7280_regmap_config.max_register = 0xa0008;
6874 + desc = &lpass_aon_cc_sc7280_desc;
6875 +
6876 + regmap = qcom_cc_map(pdev, desc);
6877 +- if (IS_ERR(regmap))
6878 +- return PTR_ERR(regmap);
6879 ++ if (IS_ERR(regmap)) {
6880 ++ ret = PTR_ERR(regmap);
6881 ++ goto exit;
6882 ++ }
6883 +
6884 + clk_lucid_pll_configure(&lpass_aon_cc_pll, regmap, &lpass_aon_cc_pll_config);
6885 +
6886 + ret = qcom_cc_really_probe(pdev, &lpass_aon_cc_sc7280_desc, regmap);
6887 +- if (ret)
6888 ++ if (ret) {
6889 + dev_err(&pdev->dev, "Failed to register LPASS AON CC clocks\n");
6890 ++ goto exit;
6891 ++ }
6892 +
6893 + pm_runtime_mark_last_busy(&pdev->dev);
6894 ++exit:
6895 + pm_runtime_put_autosuspend(&pdev->dev);
6896 +- pm_runtime_put_sync(&pdev->dev);
6897 +
6898 + return ret;
6899 + }
6900 +diff --git a/drivers/clk/qcom/lpasscc-sc7280.c b/drivers/clk/qcom/lpasscc-sc7280.c
6901 +index b39ee1c9647bc..5c1e17bd0d763 100644
6902 +--- a/drivers/clk/qcom/lpasscc-sc7280.c
6903 ++++ b/drivers/clk/qcom/lpasscc-sc7280.c
6904 +@@ -17,32 +17,6 @@
6905 + #include "clk-branch.h"
6906 + #include "common.h"
6907 +
6908 +-static struct clk_branch lpass_q6ss_ahbm_clk = {
6909 +- .halt_reg = 0x1c,
6910 +- .halt_check = BRANCH_HALT,
6911 +- .clkr = {
6912 +- .enable_reg = 0x1c,
6913 +- .enable_mask = BIT(0),
6914 +- .hw.init = &(struct clk_init_data){
6915 +- .name = "lpass_q6ss_ahbm_clk",
6916 +- .ops = &clk_branch2_ops,
6917 +- },
6918 +- },
6919 +-};
6920 +-
6921 +-static struct clk_branch lpass_q6ss_ahbs_clk = {
6922 +- .halt_reg = 0x20,
6923 +- .halt_check = BRANCH_HALT_VOTED,
6924 +- .clkr = {
6925 +- .enable_reg = 0x20,
6926 +- .enable_mask = BIT(0),
6927 +- .hw.init = &(struct clk_init_data){
6928 +- .name = "lpass_q6ss_ahbs_clk",
6929 +- .ops = &clk_branch2_ops,
6930 +- },
6931 +- },
6932 +-};
6933 +-
6934 + static struct clk_branch lpass_top_cc_lpi_q6_axim_hs_clk = {
6935 + .halt_reg = 0x0,
6936 + .halt_check = BRANCH_HALT,
6937 +@@ -105,17 +79,6 @@ static struct regmap_config lpass_regmap_config = {
6938 + .fast_io = true,
6939 + };
6940 +
6941 +-static struct clk_regmap *lpass_cc_sc7280_clocks[] = {
6942 +- [LPASS_Q6SS_AHBM_CLK] = &lpass_q6ss_ahbm_clk.clkr,
6943 +- [LPASS_Q6SS_AHBS_CLK] = &lpass_q6ss_ahbs_clk.clkr,
6944 +-};
6945 +-
6946 +-static const struct qcom_cc_desc lpass_cc_sc7280_desc = {
6947 +- .config = &lpass_regmap_config,
6948 +- .clks = lpass_cc_sc7280_clocks,
6949 +- .num_clks = ARRAY_SIZE(lpass_cc_sc7280_clocks),
6950 +-};
6951 +-
6952 + static struct clk_regmap *lpass_cc_top_sc7280_clocks[] = {
6953 + [LPASS_TOP_CC_LPI_Q6_AXIM_HS_CLK] =
6954 + &lpass_top_cc_lpi_q6_axim_hs_clk.clkr,
6955 +@@ -169,13 +132,6 @@ static int lpass_cc_sc7280_probe(struct platform_device *pdev)
6956 + if (ret)
6957 + goto destroy_pm_clk;
6958 +
6959 +- lpass_regmap_config.name = "cc";
6960 +- desc = &lpass_cc_sc7280_desc;
6961 +-
6962 +- ret = qcom_cc_probe_by_index(pdev, 2, desc);
6963 +- if (ret)
6964 +- goto destroy_pm_clk;
6965 +-
6966 + return 0;
6967 +
6968 + destroy_pm_clk:
6969 +diff --git a/drivers/clk/qcom/lpasscorecc-sc7180.c b/drivers/clk/qcom/lpasscorecc-sc7180.c
6970 +index ac09b7b840aba..a5731994cbed1 100644
6971 +--- a/drivers/clk/qcom/lpasscorecc-sc7180.c
6972 ++++ b/drivers/clk/qcom/lpasscorecc-sc7180.c
6973 +@@ -356,7 +356,7 @@ static const struct qcom_cc_desc lpass_audio_hm_sc7180_desc = {
6974 + .num_gdscs = ARRAY_SIZE(lpass_audio_hm_sc7180_gdscs),
6975 + };
6976 +
6977 +-static int lpass_create_pm_clks(struct platform_device *pdev)
6978 ++static int lpass_setup_runtime_pm(struct platform_device *pdev)
6979 + {
6980 + int ret;
6981 +
6982 +@@ -375,7 +375,7 @@ static int lpass_create_pm_clks(struct platform_device *pdev)
6983 + if (ret < 0)
6984 + dev_err(&pdev->dev, "failed to acquire iface clock\n");
6985 +
6986 +- return ret;
6987 ++ return pm_runtime_resume_and_get(&pdev->dev);
6988 + }
6989 +
6990 + static int lpass_core_cc_sc7180_probe(struct platform_device *pdev)
6991 +@@ -384,7 +384,7 @@ static int lpass_core_cc_sc7180_probe(struct platform_device *pdev)
6992 + struct regmap *regmap;
6993 + int ret;
6994 +
6995 +- ret = lpass_create_pm_clks(pdev);
6996 ++ ret = lpass_setup_runtime_pm(pdev);
6997 + if (ret)
6998 + return ret;
6999 +
7000 +@@ -392,12 +392,14 @@ static int lpass_core_cc_sc7180_probe(struct platform_device *pdev)
7001 + desc = &lpass_audio_hm_sc7180_desc;
7002 + ret = qcom_cc_probe_by_index(pdev, 1, desc);
7003 + if (ret)
7004 +- return ret;
7005 ++ goto exit;
7006 +
7007 + lpass_core_cc_sc7180_regmap_config.name = "lpass_core_cc";
7008 + regmap = qcom_cc_map(pdev, &lpass_core_cc_sc7180_desc);
7009 +- if (IS_ERR(regmap))
7010 +- return PTR_ERR(regmap);
7011 ++ if (IS_ERR(regmap)) {
7012 ++ ret = PTR_ERR(regmap);
7013 ++ goto exit;
7014 ++ }
7015 +
7016 + /*
7017 + * Keep the CLK always-ON
7018 +@@ -415,6 +417,7 @@ static int lpass_core_cc_sc7180_probe(struct platform_device *pdev)
7019 + ret = qcom_cc_really_probe(pdev, &lpass_core_cc_sc7180_desc, regmap);
7020 +
7021 + pm_runtime_mark_last_busy(&pdev->dev);
7022 ++exit:
7023 + pm_runtime_put_autosuspend(&pdev->dev);
7024 +
7025 + return ret;
7026 +@@ -425,14 +428,19 @@ static int lpass_hm_core_probe(struct platform_device *pdev)
7027 + const struct qcom_cc_desc *desc;
7028 + int ret;
7029 +
7030 +- ret = lpass_create_pm_clks(pdev);
7031 ++ ret = lpass_setup_runtime_pm(pdev);
7032 + if (ret)
7033 + return ret;
7034 +
7035 + lpass_core_cc_sc7180_regmap_config.name = "lpass_hm_core";
7036 + desc = &lpass_core_hm_sc7180_desc;
7037 +
7038 +- return qcom_cc_probe_by_index(pdev, 0, desc);
7039 ++ ret = qcom_cc_probe_by_index(pdev, 0, desc);
7040 ++
7041 ++ pm_runtime_mark_last_busy(&pdev->dev);
7042 ++ pm_runtime_put_autosuspend(&pdev->dev);
7043 ++
7044 ++ return ret;
7045 + }
7046 +
7047 + static const struct of_device_id lpass_hm_sc7180_match_table[] = {
7048 +diff --git a/drivers/clk/qcom/lpasscorecc-sc7280.c b/drivers/clk/qcom/lpasscorecc-sc7280.c
7049 +index 1f1f1bd1b68ef..6ad19b06b1ce3 100644
7050 +--- a/drivers/clk/qcom/lpasscorecc-sc7280.c
7051 ++++ b/drivers/clk/qcom/lpasscorecc-sc7280.c
7052 +@@ -190,6 +190,19 @@ static struct clk_rcg2 lpass_core_cc_ext_if1_clk_src = {
7053 + },
7054 + };
7055 +
7056 ++static struct clk_rcg2 lpass_core_cc_ext_mclk0_clk_src = {
7057 ++ .cmd_rcgr = 0x20000,
7058 ++ .mnd_width = 8,
7059 ++ .hid_width = 5,
7060 ++ .parent_map = lpass_core_cc_parent_map_0,
7061 ++ .freq_tbl = ftbl_lpass_core_cc_ext_if0_clk_src,
7062 ++ .clkr.hw.init = &(const struct clk_init_data){
7063 ++ .name = "lpass_core_cc_ext_mclk0_clk_src",
7064 ++ .parent_data = lpass_core_cc_parent_data_0,
7065 ++ .num_parents = ARRAY_SIZE(lpass_core_cc_parent_data_0),
7066 ++ .ops = &clk_rcg2_ops,
7067 ++ },
7068 ++};
7069 +
7070 + static struct clk_branch lpass_core_cc_core_clk = {
7071 + .halt_reg = 0x1f000,
7072 +@@ -283,6 +296,24 @@ static struct clk_branch lpass_core_cc_lpm_mem0_core_clk = {
7073 + },
7074 + };
7075 +
7076 ++static struct clk_branch lpass_core_cc_ext_mclk0_clk = {
7077 ++ .halt_reg = 0x20014,
7078 ++ .halt_check = BRANCH_HALT,
7079 ++ .clkr = {
7080 ++ .enable_reg = 0x20014,
7081 ++ .enable_mask = BIT(0),
7082 ++ .hw.init = &(const struct clk_init_data){
7083 ++ .name = "lpass_core_cc_ext_mclk0_clk",
7084 ++ .parent_hws = (const struct clk_hw*[]){
7085 ++ &lpass_core_cc_ext_mclk0_clk_src.clkr.hw,
7086 ++ },
7087 ++ .num_parents = 1,
7088 ++ .flags = CLK_SET_RATE_PARENT,
7089 ++ .ops = &clk_branch2_ops,
7090 ++ },
7091 ++ },
7092 ++};
7093 ++
7094 + static struct clk_branch lpass_core_cc_sysnoc_mport_core_clk = {
7095 + .halt_reg = 0x23000,
7096 + .halt_check = BRANCH_HALT_VOTED,
7097 +@@ -326,6 +357,8 @@ static struct clk_regmap *lpass_core_cc_sc7280_clocks[] = {
7098 + [LPASS_CORE_CC_LPM_CORE_CLK] = &lpass_core_cc_lpm_core_clk.clkr,
7099 + [LPASS_CORE_CC_LPM_MEM0_CORE_CLK] = &lpass_core_cc_lpm_mem0_core_clk.clkr,
7100 + [LPASS_CORE_CC_SYSNOC_MPORT_CORE_CLK] = &lpass_core_cc_sysnoc_mport_core_clk.clkr,
7101 ++ [LPASS_CORE_CC_EXT_MCLK0_CLK] = &lpass_core_cc_ext_mclk0_clk.clkr,
7102 ++ [LPASS_CORE_CC_EXT_MCLK0_CLK_SRC] = &lpass_core_cc_ext_mclk0_clk_src.clkr,
7103 + };
7104 +
7105 + static struct regmap_config lpass_core_cc_sc7280_regmap_config = {
7106 +diff --git a/drivers/clk/renesas/r8a779a0-cpg-mssr.c b/drivers/clk/renesas/r8a779a0-cpg-mssr.c
7107 +index d74d46833012f..e02542ca24a06 100644
7108 +--- a/drivers/clk/renesas/r8a779a0-cpg-mssr.c
7109 ++++ b/drivers/clk/renesas/r8a779a0-cpg-mssr.c
7110 +@@ -116,7 +116,7 @@ static const struct cpg_core_clk r8a779a0_core_clks[] __initconst = {
7111 + DEF_FIXED("cp", R8A779A0_CLK_CP, CLK_EXTAL, 2, 1),
7112 + DEF_FIXED("cl16mck", R8A779A0_CLK_CL16MCK, CLK_PLL1_DIV2, 64, 1),
7113 +
7114 +- DEF_GEN4_SDH("sdh0", R8A779A0_CLK_SD0H, CLK_SDSRC, 0x870),
7115 ++ DEF_GEN4_SDH("sd0h", R8A779A0_CLK_SD0H, CLK_SDSRC, 0x870),
7116 + DEF_GEN4_SD("sd0", R8A779A0_CLK_SD0, R8A779A0_CLK_SD0H, 0x870),
7117 +
7118 + DEF_BASE("rpc", R8A779A0_CLK_RPC, CLK_TYPE_GEN4_RPC, CLK_RPCSRC),
7119 +diff --git a/drivers/clk/renesas/r8a779f0-cpg-mssr.c b/drivers/clk/renesas/r8a779f0-cpg-mssr.c
7120 +index cd80b6084eceb..ab104a25a6019 100644
7121 +--- a/drivers/clk/renesas/r8a779f0-cpg-mssr.c
7122 ++++ b/drivers/clk/renesas/r8a779f0-cpg-mssr.c
7123 +@@ -108,7 +108,13 @@ static const struct cpg_core_clk r8a779f0_core_clks[] __initconst = {
7124 + DEF_FIXED("cbfusa", R8A779F0_CLK_CBFUSA, CLK_EXTAL, 2, 1),
7125 + DEF_FIXED("cpex", R8A779F0_CLK_CPEX, CLK_EXTAL, 2, 1),
7126 +
7127 +- DEF_GEN4_SD("sd0", R8A779F0_CLK_SD0, CLK_SDSRC, 0x870),
7128 ++ DEF_FIXED("sasyncrt", R8A779F0_CLK_SASYNCRT, CLK_PLL5_DIV4, 48, 1),
7129 ++ DEF_FIXED("sasyncperd1", R8A779F0_CLK_SASYNCPERD1, CLK_PLL5_DIV4, 3, 1),
7130 ++ DEF_FIXED("sasyncperd2", R8A779F0_CLK_SASYNCPERD2, R8A779F0_CLK_SASYNCPERD1, 2, 1),
7131 ++ DEF_FIXED("sasyncperd4", R8A779F0_CLK_SASYNCPERD4, R8A779F0_CLK_SASYNCPERD1, 4, 1),
7132 ++
7133 ++ DEF_GEN4_SDH("sd0h", R8A779F0_CLK_SD0H, CLK_SDSRC, 0x870),
7134 ++ DEF_GEN4_SD("sd0", R8A779F0_CLK_SD0, R8A779F0_CLK_SD0H, 0x870),
7135 +
7136 + DEF_BASE("rpc", R8A779F0_CLK_RPC, CLK_TYPE_GEN4_RPC, CLK_RPCSRC),
7137 + DEF_BASE("rpcd2", R8A779F0_CLK_RPCD2, CLK_TYPE_GEN4_RPCD2, R8A779F0_CLK_RPC),
7138 +@@ -120,10 +126,10 @@ static const struct cpg_core_clk r8a779f0_core_clks[] __initconst = {
7139 + };
7140 +
7141 + static const struct mssr_mod_clk r8a779f0_mod_clks[] __initconst = {
7142 +- DEF_MOD("hscif0", 514, R8A779F0_CLK_S0D3),
7143 +- DEF_MOD("hscif1", 515, R8A779F0_CLK_S0D3),
7144 +- DEF_MOD("hscif2", 516, R8A779F0_CLK_S0D3),
7145 +- DEF_MOD("hscif3", 517, R8A779F0_CLK_S0D3),
7146 ++ DEF_MOD("hscif0", 514, R8A779F0_CLK_SASYNCPERD1),
7147 ++ DEF_MOD("hscif1", 515, R8A779F0_CLK_SASYNCPERD1),
7148 ++ DEF_MOD("hscif2", 516, R8A779F0_CLK_SASYNCPERD1),
7149 ++ DEF_MOD("hscif3", 517, R8A779F0_CLK_SASYNCPERD1),
7150 + DEF_MOD("i2c0", 518, R8A779F0_CLK_S0D6_PER),
7151 + DEF_MOD("i2c1", 519, R8A779F0_CLK_S0D6_PER),
7152 + DEF_MOD("i2c2", 520, R8A779F0_CLK_S0D6_PER),
7153 +@@ -132,13 +138,18 @@ static const struct mssr_mod_clk r8a779f0_mod_clks[] __initconst = {
7154 + DEF_MOD("i2c5", 523, R8A779F0_CLK_S0D6_PER),
7155 + DEF_MOD("pcie0", 624, R8A779F0_CLK_S0D2),
7156 + DEF_MOD("pcie1", 625, R8A779F0_CLK_S0D2),
7157 +- DEF_MOD("scif0", 702, R8A779F0_CLK_S0D12_PER),
7158 +- DEF_MOD("scif1", 703, R8A779F0_CLK_S0D12_PER),
7159 +- DEF_MOD("scif3", 704, R8A779F0_CLK_S0D12_PER),
7160 +- DEF_MOD("scif4", 705, R8A779F0_CLK_S0D12_PER),
7161 ++ DEF_MOD("scif0", 702, R8A779F0_CLK_SASYNCPERD4),
7162 ++ DEF_MOD("scif1", 703, R8A779F0_CLK_SASYNCPERD4),
7163 ++ DEF_MOD("scif3", 704, R8A779F0_CLK_SASYNCPERD4),
7164 ++ DEF_MOD("scif4", 705, R8A779F0_CLK_SASYNCPERD4),
7165 + DEF_MOD("sdhi0", 706, R8A779F0_CLK_SD0),
7166 + DEF_MOD("sys-dmac0", 709, R8A779F0_CLK_S0D3_PER),
7167 + DEF_MOD("sys-dmac1", 710, R8A779F0_CLK_S0D3_PER),
7168 ++ DEF_MOD("tmu0", 713, R8A779F0_CLK_SASYNCRT),
7169 ++ DEF_MOD("tmu1", 714, R8A779F0_CLK_SASYNCPERD2),
7170 ++ DEF_MOD("tmu2", 715, R8A779F0_CLK_SASYNCPERD2),
7171 ++ DEF_MOD("tmu3", 716, R8A779F0_CLK_SASYNCPERD2),
7172 ++ DEF_MOD("tmu4", 717, R8A779F0_CLK_SASYNCPERD2),
7173 + DEF_MOD("wdt", 907, R8A779F0_CLK_R),
7174 + DEF_MOD("pfc0", 915, R8A779F0_CLK_CL16M),
7175 + DEF_MOD("tsc", 919, R8A779F0_CLK_CL16M),
7176 +diff --git a/drivers/clk/renesas/r9a06g032-clocks.c b/drivers/clk/renesas/r9a06g032-clocks.c
7177 +index 1488c9d6e6394..983faa5707b9c 100644
7178 +--- a/drivers/clk/renesas/r9a06g032-clocks.c
7179 ++++ b/drivers/clk/renesas/r9a06g032-clocks.c
7180 +@@ -412,7 +412,7 @@ static int r9a06g032_attach_dev(struct generic_pm_domain *pd,
7181 + int error;
7182 + int index;
7183 +
7184 +- while (!of_parse_phandle_with_args(np, "clocks", "#clock-cells", i,
7185 ++ while (!of_parse_phandle_with_args(np, "clocks", "#clock-cells", i++,
7186 + &clkspec)) {
7187 + if (clkspec.np != pd->dev.of_node)
7188 + continue;
7189 +@@ -425,7 +425,6 @@ static int r9a06g032_attach_dev(struct generic_pm_domain *pd,
7190 + if (error)
7191 + return error;
7192 + }
7193 +- i++;
7194 + }
7195 +
7196 + return 0;
7197 +diff --git a/drivers/clk/rockchip/clk-pll.c b/drivers/clk/rockchip/clk-pll.c
7198 +index f7827b3b7fc1c..6e5e502be44a6 100644
7199 +--- a/drivers/clk/rockchip/clk-pll.c
7200 ++++ b/drivers/clk/rockchip/clk-pll.c
7201 +@@ -981,6 +981,7 @@ struct clk *rockchip_clk_register_pll(struct rockchip_clk_provider *ctx,
7202 + return mux_clk;
7203 +
7204 + err_pll:
7205 ++ kfree(pll->rate_table);
7206 + clk_unregister(mux_clk);
7207 + mux_clk = pll_clk;
7208 + err_mux:
7209 +diff --git a/drivers/clk/samsung/clk-pll.c b/drivers/clk/samsung/clk-pll.c
7210 +index fe383471c5f0a..0ff28938943f0 100644
7211 +--- a/drivers/clk/samsung/clk-pll.c
7212 ++++ b/drivers/clk/samsung/clk-pll.c
7213 +@@ -1583,6 +1583,7 @@ static void __init _samsung_clk_register_pll(struct samsung_clk_provider *ctx,
7214 + if (ret) {
7215 + pr_err("%s: failed to register pll clock %s : %d\n",
7216 + __func__, pll_clk->name, ret);
7217 ++ kfree(pll->rate_table);
7218 + kfree(pll);
7219 + return;
7220 + }
7221 +diff --git a/drivers/clk/socfpga/clk-gate.c b/drivers/clk/socfpga/clk-gate.c
7222 +index 53d6e3ec4309f..c94b59b80dd43 100644
7223 +--- a/drivers/clk/socfpga/clk-gate.c
7224 ++++ b/drivers/clk/socfpga/clk-gate.c
7225 +@@ -188,8 +188,10 @@ void __init socfpga_gate_init(struct device_node *node)
7226 + return;
7227 +
7228 + ops = kmemdup(&gateclk_ops, sizeof(gateclk_ops), GFP_KERNEL);
7229 +- if (WARN_ON(!ops))
7230 ++ if (WARN_ON(!ops)) {
7231 ++ kfree(socfpga_clk);
7232 + return;
7233 ++ }
7234 +
7235 + rc = of_property_read_u32_array(node, "clk-gate", clk_gate, 2);
7236 + if (rc)
7237 +@@ -243,6 +245,7 @@ void __init socfpga_gate_init(struct device_node *node)
7238 +
7239 + err = clk_hw_register(NULL, hw_clk);
7240 + if (err) {
7241 ++ kfree(ops);
7242 + kfree(socfpga_clk);
7243 + return;
7244 + }
7245 +diff --git a/drivers/clk/st/clkgen-fsyn.c b/drivers/clk/st/clkgen-fsyn.c
7246 +index d820292a381d0..40df1db102a77 100644
7247 +--- a/drivers/clk/st/clkgen-fsyn.c
7248 ++++ b/drivers/clk/st/clkgen-fsyn.c
7249 +@@ -1020,9 +1020,10 @@ static void __init st_of_quadfs_setup(struct device_node *np,
7250 +
7251 + clk = st_clk_register_quadfs_pll(pll_name, clk_parent_name, datac->data,
7252 + reg, lock);
7253 +- if (IS_ERR(clk))
7254 ++ if (IS_ERR(clk)) {
7255 ++ kfree(lock);
7256 + goto err_exit;
7257 +- else
7258 ++ } else
7259 + pr_debug("%s: parent %s rate %u\n",
7260 + __clk_get_name(clk),
7261 + __clk_get_name(clk_get_parent(clk)),
7262 +diff --git a/drivers/clk/visconti/pll.c b/drivers/clk/visconti/pll.c
7263 +index a484cb945d67b..1f3234f226674 100644
7264 +--- a/drivers/clk/visconti/pll.c
7265 ++++ b/drivers/clk/visconti/pll.c
7266 +@@ -277,6 +277,7 @@ static struct clk_hw *visconti_register_pll(struct visconti_pll_provider *ctx,
7267 + ret = clk_hw_register(NULL, &pll->hw);
7268 + if (ret) {
7269 + pr_err("failed to register pll clock %s : %d\n", name, ret);
7270 ++ kfree(pll->rate_table);
7271 + kfree(pll);
7272 + pll_hw_clk = ERR_PTR(ret);
7273 + }
7274 +diff --git a/drivers/clocksource/sh_cmt.c b/drivers/clocksource/sh_cmt.c
7275 +index 64dcb082d4cf6..7b952aa52c0b9 100644
7276 +--- a/drivers/clocksource/sh_cmt.c
7277 ++++ b/drivers/clocksource/sh_cmt.c
7278 +@@ -13,6 +13,7 @@
7279 + #include <linux/init.h>
7280 + #include <linux/interrupt.h>
7281 + #include <linux/io.h>
7282 ++#include <linux/iopoll.h>
7283 + #include <linux/ioport.h>
7284 + #include <linux/irq.h>
7285 + #include <linux/module.h>
7286 +@@ -116,6 +117,7 @@ struct sh_cmt_device {
7287 + void __iomem *mapbase;
7288 + struct clk *clk;
7289 + unsigned long rate;
7290 ++ unsigned int reg_delay;
7291 +
7292 + raw_spinlock_t lock; /* Protect the shared start/stop register */
7293 +
7294 +@@ -247,10 +249,17 @@ static inline u32 sh_cmt_read_cmstr(struct sh_cmt_channel *ch)
7295 +
7296 + static inline void sh_cmt_write_cmstr(struct sh_cmt_channel *ch, u32 value)
7297 + {
7298 +- if (ch->iostart)
7299 +- ch->cmt->info->write_control(ch->iostart, 0, value);
7300 +- else
7301 +- ch->cmt->info->write_control(ch->cmt->mapbase, 0, value);
7302 ++ u32 old_value = sh_cmt_read_cmstr(ch);
7303 ++
7304 ++ if (value != old_value) {
7305 ++ if (ch->iostart) {
7306 ++ ch->cmt->info->write_control(ch->iostart, 0, value);
7307 ++ udelay(ch->cmt->reg_delay);
7308 ++ } else {
7309 ++ ch->cmt->info->write_control(ch->cmt->mapbase, 0, value);
7310 ++ udelay(ch->cmt->reg_delay);
7311 ++ }
7312 ++ }
7313 + }
7314 +
7315 + static inline u32 sh_cmt_read_cmcsr(struct sh_cmt_channel *ch)
7316 +@@ -260,7 +269,12 @@ static inline u32 sh_cmt_read_cmcsr(struct sh_cmt_channel *ch)
7317 +
7318 + static inline void sh_cmt_write_cmcsr(struct sh_cmt_channel *ch, u32 value)
7319 + {
7320 +- ch->cmt->info->write_control(ch->ioctrl, CMCSR, value);
7321 ++ u32 old_value = sh_cmt_read_cmcsr(ch);
7322 ++
7323 ++ if (value != old_value) {
7324 ++ ch->cmt->info->write_control(ch->ioctrl, CMCSR, value);
7325 ++ udelay(ch->cmt->reg_delay);
7326 ++ }
7327 + }
7328 +
7329 + static inline u32 sh_cmt_read_cmcnt(struct sh_cmt_channel *ch)
7330 +@@ -268,14 +282,33 @@ static inline u32 sh_cmt_read_cmcnt(struct sh_cmt_channel *ch)
7331 + return ch->cmt->info->read_count(ch->ioctrl, CMCNT);
7332 + }
7333 +
7334 +-static inline void sh_cmt_write_cmcnt(struct sh_cmt_channel *ch, u32 value)
7335 ++static inline int sh_cmt_write_cmcnt(struct sh_cmt_channel *ch, u32 value)
7336 + {
7337 ++ /* Tests showed that we need to wait 3 clocks here */
7338 ++ unsigned int cmcnt_delay = DIV_ROUND_UP(3 * ch->cmt->reg_delay, 2);
7339 ++ u32 reg;
7340 ++
7341 ++ if (ch->cmt->info->model > SH_CMT_16BIT) {
7342 ++ int ret = read_poll_timeout_atomic(sh_cmt_read_cmcsr, reg,
7343 ++ !(reg & SH_CMT32_CMCSR_WRFLG),
7344 ++ 1, cmcnt_delay, false, ch);
7345 ++ if (ret < 0)
7346 ++ return ret;
7347 ++ }
7348 ++
7349 + ch->cmt->info->write_count(ch->ioctrl, CMCNT, value);
7350 ++ udelay(cmcnt_delay);
7351 ++ return 0;
7352 + }
7353 +
7354 + static inline void sh_cmt_write_cmcor(struct sh_cmt_channel *ch, u32 value)
7355 + {
7356 +- ch->cmt->info->write_count(ch->ioctrl, CMCOR, value);
7357 ++ u32 old_value = ch->cmt->info->read_count(ch->ioctrl, CMCOR);
7358 ++
7359 ++ if (value != old_value) {
7360 ++ ch->cmt->info->write_count(ch->ioctrl, CMCOR, value);
7361 ++ udelay(ch->cmt->reg_delay);
7362 ++ }
7363 + }
7364 +
7365 + static u32 sh_cmt_get_counter(struct sh_cmt_channel *ch, u32 *has_wrapped)
7366 +@@ -319,7 +352,7 @@ static void sh_cmt_start_stop_ch(struct sh_cmt_channel *ch, int start)
7367 +
7368 + static int sh_cmt_enable(struct sh_cmt_channel *ch)
7369 + {
7370 +- int k, ret;
7371 ++ int ret;
7372 +
7373 + dev_pm_syscore_device(&ch->cmt->pdev->dev, true);
7374 +
7375 +@@ -347,26 +380,9 @@ static int sh_cmt_enable(struct sh_cmt_channel *ch)
7376 + }
7377 +
7378 + sh_cmt_write_cmcor(ch, 0xffffffff);
7379 +- sh_cmt_write_cmcnt(ch, 0);
7380 +-
7381 +- /*
7382 +- * According to the sh73a0 user's manual, as CMCNT can be operated
7383 +- * only by the RCLK (Pseudo 32 kHz), there's one restriction on
7384 +- * modifying CMCNT register; two RCLK cycles are necessary before
7385 +- * this register is either read or any modification of the value
7386 +- * it holds is reflected in the LSI's actual operation.
7387 +- *
7388 +- * While at it, we're supposed to clear out the CMCNT as of this
7389 +- * moment, so make sure it's processed properly here. This will
7390 +- * take RCLKx2 at maximum.
7391 +- */
7392 +- for (k = 0; k < 100; k++) {
7393 +- if (!sh_cmt_read_cmcnt(ch))
7394 +- break;
7395 +- udelay(1);
7396 +- }
7397 ++ ret = sh_cmt_write_cmcnt(ch, 0);
7398 +
7399 +- if (sh_cmt_read_cmcnt(ch)) {
7400 ++ if (ret || sh_cmt_read_cmcnt(ch)) {
7401 + dev_err(&ch->cmt->pdev->dev, "ch%u: cannot clear CMCNT\n",
7402 + ch->index);
7403 + ret = -ETIMEDOUT;
7404 +@@ -995,8 +1011,8 @@ MODULE_DEVICE_TABLE(of, sh_cmt_of_table);
7405 +
7406 + static int sh_cmt_setup(struct sh_cmt_device *cmt, struct platform_device *pdev)
7407 + {
7408 +- unsigned int mask;
7409 +- unsigned int i;
7410 ++ unsigned int mask, i;
7411 ++ unsigned long rate;
7412 + int ret;
7413 +
7414 + cmt->pdev = pdev;
7415 +@@ -1032,10 +1048,16 @@ static int sh_cmt_setup(struct sh_cmt_device *cmt, struct platform_device *pdev)
7416 + if (ret < 0)
7417 + goto err_clk_unprepare;
7418 +
7419 +- if (cmt->info->width == 16)
7420 +- cmt->rate = clk_get_rate(cmt->clk) / 512;
7421 +- else
7422 +- cmt->rate = clk_get_rate(cmt->clk) / 8;
7423 ++ rate = clk_get_rate(cmt->clk);
7424 ++ if (!rate) {
7425 ++ ret = -EINVAL;
7426 ++ goto err_clk_disable;
7427 ++ }
7428 ++
7429 ++ /* We shall wait 2 input clks after register writes */
7430 ++ if (cmt->info->model >= SH_CMT_48BIT)
7431 ++ cmt->reg_delay = DIV_ROUND_UP(2UL * USEC_PER_SEC, rate);
7432 ++ cmt->rate = rate / (cmt->info->width == 16 ? 512 : 8);
7433 +
7434 + /* Map the memory resource(s). */
7435 + ret = sh_cmt_map_memory(cmt);
7436 +diff --git a/drivers/clocksource/timer-ti-dm-systimer.c b/drivers/clocksource/timer-ti-dm-systimer.c
7437 +index 2737407ff0698..632523c1232f6 100644
7438 +--- a/drivers/clocksource/timer-ti-dm-systimer.c
7439 ++++ b/drivers/clocksource/timer-ti-dm-systimer.c
7440 +@@ -345,8 +345,10 @@ static int __init dmtimer_systimer_init_clock(struct dmtimer_systimer *t,
7441 + return error;
7442 +
7443 + r = clk_get_rate(clock);
7444 +- if (!r)
7445 ++ if (!r) {
7446 ++ clk_disable_unprepare(clock);
7447 + return -ENODEV;
7448 ++ }
7449 +
7450 + if (is_ick)
7451 + t->ick = clock;
7452 +diff --git a/drivers/clocksource/timer-ti-dm.c b/drivers/clocksource/timer-ti-dm.c
7453 +index 469f7c91564b6..78c2c038d3ae4 100644
7454 +--- a/drivers/clocksource/timer-ti-dm.c
7455 ++++ b/drivers/clocksource/timer-ti-dm.c
7456 +@@ -1081,7 +1081,7 @@ static struct platform_driver omap_dm_timer_driver = {
7457 + .remove = omap_dm_timer_remove,
7458 + .driver = {
7459 + .name = "omap_timer",
7460 +- .of_match_table = of_match_ptr(omap_timer_match),
7461 ++ .of_match_table = omap_timer_match,
7462 + .pm = &omap_dm_timer_pm_ops,
7463 + },
7464 + };
7465 +diff --git a/drivers/counter/stm32-lptimer-cnt.c b/drivers/counter/stm32-lptimer-cnt.c
7466 +index 68031d93ce895..aee3b1a8aaa77 100644
7467 +--- a/drivers/counter/stm32-lptimer-cnt.c
7468 ++++ b/drivers/counter/stm32-lptimer-cnt.c
7469 +@@ -69,7 +69,7 @@ static int stm32_lptim_set_enable_state(struct stm32_lptim_cnt *priv,
7470 +
7471 + /* ensure CMP & ARR registers are properly written */
7472 + ret = regmap_read_poll_timeout(priv->regmap, STM32_LPTIM_ISR, val,
7473 +- (val & STM32_LPTIM_CMPOK_ARROK),
7474 ++ (val & STM32_LPTIM_CMPOK_ARROK) == STM32_LPTIM_CMPOK_ARROK,
7475 + 100, 1000);
7476 + if (ret)
7477 + return ret;
7478 +diff --git a/drivers/cpufreq/amd_freq_sensitivity.c b/drivers/cpufreq/amd_freq_sensitivity.c
7479 +index 6448e03bcf488..59b19b9975e8c 100644
7480 +--- a/drivers/cpufreq/amd_freq_sensitivity.c
7481 ++++ b/drivers/cpufreq/amd_freq_sensitivity.c
7482 +@@ -125,6 +125,8 @@ static int __init amd_freq_sensitivity_init(void)
7483 + if (!pcidev) {
7484 + if (!boot_cpu_has(X86_FEATURE_PROC_FEEDBACK))
7485 + return -ENODEV;
7486 ++ } else {
7487 ++ pci_dev_put(pcidev);
7488 + }
7489 +
7490 + if (rdmsrl_safe(MSR_AMD64_FREQ_SENSITIVITY_ACTUAL, &val))
7491 +diff --git a/drivers/cpufreq/qcom-cpufreq-hw.c b/drivers/cpufreq/qcom-cpufreq-hw.c
7492 +index bb32659820ceb..823b069203e1b 100644
7493 +--- a/drivers/cpufreq/qcom-cpufreq-hw.c
7494 ++++ b/drivers/cpufreq/qcom-cpufreq-hw.c
7495 +@@ -122,7 +122,35 @@ static int qcom_cpufreq_hw_target_index(struct cpufreq_policy *policy,
7496 + return 0;
7497 + }
7498 +
7499 ++static unsigned long qcom_lmh_get_throttle_freq(struct qcom_cpufreq_data *data)
7500 ++{
7501 ++ unsigned int lval;
7502 ++
7503 ++ if (data->soc_data->reg_current_vote)
7504 ++ lval = readl_relaxed(data->base + data->soc_data->reg_current_vote) & 0x3ff;
7505 ++ else
7506 ++ lval = readl_relaxed(data->base + data->soc_data->reg_domain_state) & 0xff;
7507 ++
7508 ++ return lval * xo_rate;
7509 ++}
7510 ++
7511 ++/* Get the current frequency of the CPU (after throttling) */
7512 + static unsigned int qcom_cpufreq_hw_get(unsigned int cpu)
7513 ++{
7514 ++ struct qcom_cpufreq_data *data;
7515 ++ struct cpufreq_policy *policy;
7516 ++
7517 ++ policy = cpufreq_cpu_get_raw(cpu);
7518 ++ if (!policy)
7519 ++ return 0;
7520 ++
7521 ++ data = policy->driver_data;
7522 ++
7523 ++ return qcom_lmh_get_throttle_freq(data) / HZ_PER_KHZ;
7524 ++}
7525 ++
7526 ++/* Get the frequency requested by the cpufreq core for the CPU */
7527 ++static unsigned int qcom_cpufreq_get_freq(unsigned int cpu)
7528 + {
7529 + struct qcom_cpufreq_data *data;
7530 + const struct qcom_cpufreq_soc_data *soc_data;
7531 +@@ -190,6 +218,7 @@ static int qcom_cpufreq_hw_read_lut(struct device *cpu_dev,
7532 + }
7533 + } else if (ret != -ENODEV) {
7534 + dev_err(cpu_dev, "Invalid opp table in device tree\n");
7535 ++ kfree(table);
7536 + return ret;
7537 + } else {
7538 + policy->fast_switch_possible = true;
7539 +@@ -283,18 +312,6 @@ static void qcom_get_related_cpus(int index, struct cpumask *m)
7540 + }
7541 + }
7542 +
7543 +-static unsigned long qcom_lmh_get_throttle_freq(struct qcom_cpufreq_data *data)
7544 +-{
7545 +- unsigned int lval;
7546 +-
7547 +- if (data->soc_data->reg_current_vote)
7548 +- lval = readl_relaxed(data->base + data->soc_data->reg_current_vote) & 0x3ff;
7549 +- else
7550 +- lval = readl_relaxed(data->base + data->soc_data->reg_domain_state) & 0xff;
7551 +-
7552 +- return lval * xo_rate;
7553 +-}
7554 +-
7555 + static void qcom_lmh_dcvs_notify(struct qcom_cpufreq_data *data)
7556 + {
7557 + struct cpufreq_policy *policy = data->policy;
7558 +@@ -336,7 +353,7 @@ static void qcom_lmh_dcvs_notify(struct qcom_cpufreq_data *data)
7559 + * If h/w throttled frequency is higher than what cpufreq has requested
7560 + * for, then stop polling and switch back to interrupt mechanism.
7561 + */
7562 +- if (throttled_freq >= qcom_cpufreq_hw_get(cpu))
7563 ++ if (throttled_freq >= qcom_cpufreq_get_freq(cpu))
7564 + enable_irq(data->throttle_irq);
7565 + else
7566 + mod_delayed_work(system_highpri_wq, &data->throttle_work,
7567 +diff --git a/drivers/cpuidle/dt_idle_states.c b/drivers/cpuidle/dt_idle_states.c
7568 +index 252f2a9686a62..448bc796b0b40 100644
7569 +--- a/drivers/cpuidle/dt_idle_states.c
7570 ++++ b/drivers/cpuidle/dt_idle_states.c
7571 +@@ -223,6 +223,6 @@ int dt_init_idle_driver(struct cpuidle_driver *drv,
7572 + * also be 0 on platforms with missing DT idle states or legacy DT
7573 + * configuration predating the DT idle states bindings.
7574 + */
7575 +- return i;
7576 ++ return state_idx - start_idx;
7577 + }
7578 + EXPORT_SYMBOL_GPL(dt_init_idle_driver);
7579 +diff --git a/drivers/crypto/Kconfig b/drivers/crypto/Kconfig
7580 +index 3e6aa319920b7..79d9e14b70c87 100644
7581 +--- a/drivers/crypto/Kconfig
7582 ++++ b/drivers/crypto/Kconfig
7583 +@@ -669,7 +669,12 @@ config CRYPTO_DEV_IMGTEC_HASH
7584 + config CRYPTO_DEV_ROCKCHIP
7585 + tristate "Rockchip's Cryptographic Engine driver"
7586 + depends on OF && ARCH_ROCKCHIP
7587 ++ depends on PM
7588 ++ select CRYPTO_ECB
7589 ++ select CRYPTO_CBC
7590 ++ select CRYPTO_DES
7591 + select CRYPTO_AES
7592 ++ select CRYPTO_ENGINE
7593 + select CRYPTO_LIB_DES
7594 + select CRYPTO_MD5
7595 + select CRYPTO_SHA1
7596 +diff --git a/drivers/crypto/allwinner/sun8i-ss/sun8i-ss-cipher.c b/drivers/crypto/allwinner/sun8i-ss/sun8i-ss-cipher.c
7597 +index 910d6751644cf..902f6be057ec6 100644
7598 +--- a/drivers/crypto/allwinner/sun8i-ss/sun8i-ss-cipher.c
7599 ++++ b/drivers/crypto/allwinner/sun8i-ss/sun8i-ss-cipher.c
7600 +@@ -124,7 +124,7 @@ static int sun8i_ss_setup_ivs(struct skcipher_request *areq)
7601 + unsigned int ivsize = crypto_skcipher_ivsize(tfm);
7602 + struct sun8i_ss_flow *sf = &ss->flows[rctx->flow];
7603 + int i = 0;
7604 +- u32 a;
7605 ++ dma_addr_t a;
7606 + int err;
7607 +
7608 + rctx->ivlen = ivsize;
7609 +diff --git a/drivers/crypto/amlogic/amlogic-gxl-core.c b/drivers/crypto/amlogic/amlogic-gxl-core.c
7610 +index 6e7ae896717cd..937187027ad57 100644
7611 +--- a/drivers/crypto/amlogic/amlogic-gxl-core.c
7612 ++++ b/drivers/crypto/amlogic/amlogic-gxl-core.c
7613 +@@ -237,7 +237,6 @@ static int meson_crypto_probe(struct platform_device *pdev)
7614 + return err;
7615 + }
7616 +
7617 +- mc->irqs = devm_kcalloc(mc->dev, MAXFLOW, sizeof(int), GFP_KERNEL);
7618 + for (i = 0; i < MAXFLOW; i++) {
7619 + mc->irqs[i] = platform_get_irq(pdev, i);
7620 + if (mc->irqs[i] < 0)
7621 +diff --git a/drivers/crypto/amlogic/amlogic-gxl.h b/drivers/crypto/amlogic/amlogic-gxl.h
7622 +index dc0f142324a3c..8c0746a1d6d43 100644
7623 +--- a/drivers/crypto/amlogic/amlogic-gxl.h
7624 ++++ b/drivers/crypto/amlogic/amlogic-gxl.h
7625 +@@ -95,7 +95,7 @@ struct meson_dev {
7626 + struct device *dev;
7627 + struct meson_flow *chanlist;
7628 + atomic_t flow;
7629 +- int *irqs;
7630 ++ int irqs[MAXFLOW];
7631 + #ifdef CONFIG_CRYPTO_DEV_AMLOGIC_GXL_DEBUG
7632 + struct dentry *dbgfs_dir;
7633 + #endif
7634 +diff --git a/drivers/crypto/cavium/nitrox/nitrox_mbx.c b/drivers/crypto/cavium/nitrox/nitrox_mbx.c
7635 +index 9e7308e39b304..d4e06999af9b7 100644
7636 +--- a/drivers/crypto/cavium/nitrox/nitrox_mbx.c
7637 ++++ b/drivers/crypto/cavium/nitrox/nitrox_mbx.c
7638 +@@ -195,6 +195,7 @@ int nitrox_mbox_init(struct nitrox_device *ndev)
7639 + ndev->iov.pf2vf_wq = alloc_workqueue("nitrox_pf2vf", 0, 0);
7640 + if (!ndev->iov.pf2vf_wq) {
7641 + kfree(ndev->iov.vfdev);
7642 ++ ndev->iov.vfdev = NULL;
7643 + return -ENOMEM;
7644 + }
7645 + /* enable pf2vf mailbox interrupts */
7646 +diff --git a/drivers/crypto/ccree/cc_debugfs.c b/drivers/crypto/ccree/cc_debugfs.c
7647 +index 7083767602fcf..8f008f024f8f1 100644
7648 +--- a/drivers/crypto/ccree/cc_debugfs.c
7649 ++++ b/drivers/crypto/ccree/cc_debugfs.c
7650 +@@ -55,7 +55,7 @@ void __init cc_debugfs_global_init(void)
7651 + cc_debugfs_dir = debugfs_create_dir("ccree", NULL);
7652 + }
7653 +
7654 +-void __exit cc_debugfs_global_fini(void)
7655 ++void cc_debugfs_global_fini(void)
7656 + {
7657 + debugfs_remove(cc_debugfs_dir);
7658 + }
7659 +diff --git a/drivers/crypto/ccree/cc_driver.c b/drivers/crypto/ccree/cc_driver.c
7660 +index cadead18b59e8..d489c6f808925 100644
7661 +--- a/drivers/crypto/ccree/cc_driver.c
7662 ++++ b/drivers/crypto/ccree/cc_driver.c
7663 +@@ -651,9 +651,17 @@ static struct platform_driver ccree_driver = {
7664 +
7665 + static int __init ccree_init(void)
7666 + {
7667 ++ int rc;
7668 ++
7669 + cc_debugfs_global_init();
7670 +
7671 +- return platform_driver_register(&ccree_driver);
7672 ++ rc = platform_driver_register(&ccree_driver);
7673 ++ if (rc) {
7674 ++ cc_debugfs_global_fini();
7675 ++ return rc;
7676 ++ }
7677 ++
7678 ++ return 0;
7679 + }
7680 + module_init(ccree_init);
7681 +
7682 +diff --git a/drivers/crypto/hisilicon/hpre/hpre_main.c b/drivers/crypto/hisilicon/hpre/hpre_main.c
7683 +index 9d529df0eab9b..7a50ca664ada1 100644
7684 +--- a/drivers/crypto/hisilicon/hpre/hpre_main.c
7685 ++++ b/drivers/crypto/hisilicon/hpre/hpre_main.c
7686 +@@ -457,7 +457,7 @@ static void hpre_open_sva_prefetch(struct hisi_qm *qm)
7687 + u32 val;
7688 + int ret;
7689 +
7690 +- if (qm->ver < QM_HW_V3)
7691 ++ if (!test_bit(QM_SUPPORT_SVA_PREFETCH, &qm->caps))
7692 + return;
7693 +
7694 + /* Enable prefetch */
7695 +@@ -478,7 +478,7 @@ static void hpre_close_sva_prefetch(struct hisi_qm *qm)
7696 + u32 val;
7697 + int ret;
7698 +
7699 +- if (qm->ver < QM_HW_V3)
7700 ++ if (!test_bit(QM_SUPPORT_SVA_PREFETCH, &qm->caps))
7701 + return;
7702 +
7703 + val = readl_relaxed(qm->io_base + HPRE_PREFETCH_CFG);
7704 +@@ -1287,18 +1287,12 @@ err_with_qm_init:
7705 + static void hpre_remove(struct pci_dev *pdev)
7706 + {
7707 + struct hisi_qm *qm = pci_get_drvdata(pdev);
7708 +- int ret;
7709 +
7710 + hisi_qm_pm_uninit(qm);
7711 + hisi_qm_wait_task_finish(qm, &hpre_devices);
7712 + hisi_qm_alg_unregister(qm, &hpre_devices);
7713 +- if (qm->fun_type == QM_HW_PF && qm->vfs_num) {
7714 +- ret = hisi_qm_sriov_disable(pdev, true);
7715 +- if (ret) {
7716 +- pci_err(pdev, "Disable SRIOV fail!\n");
7717 +- return;
7718 +- }
7719 +- }
7720 ++ if (qm->fun_type == QM_HW_PF && qm->vfs_num)
7721 ++ hisi_qm_sriov_disable(pdev, true);
7722 +
7723 + hpre_debugfs_exit(qm);
7724 + hisi_qm_stop(qm, QM_NORMAL);
7725 +diff --git a/drivers/crypto/hisilicon/qm.c b/drivers/crypto/hisilicon/qm.c
7726 +index 9fa2efe601537..959f4846aa233 100644
7727 +--- a/drivers/crypto/hisilicon/qm.c
7728 ++++ b/drivers/crypto/hisilicon/qm.c
7729 +@@ -86,9 +86,7 @@
7730 + #define QM_DB_CMD_SHIFT_V1 16
7731 + #define QM_DB_INDEX_SHIFT_V1 32
7732 + #define QM_DB_PRIORITY_SHIFT_V1 48
7733 +-#define QM_QUE_ISO_CFG_V 0x0030
7734 + #define QM_PAGE_SIZE 0x0034
7735 +-#define QM_QUE_ISO_EN 0x100154
7736 + #define QM_CAPBILITY 0x100158
7737 + #define QM_QP_NUN_MASK GENMASK(10, 0)
7738 + #define QM_QP_DB_INTERVAL 0x10000
7739 +@@ -205,6 +203,8 @@
7740 + #define MAX_WAIT_COUNTS 1000
7741 + #define QM_CACHE_WB_START 0x204
7742 + #define QM_CACHE_WB_DONE 0x208
7743 ++#define QM_FUNC_CAPS_REG 0x3100
7744 ++#define QM_CAPBILITY_VERSION GENMASK(7, 0)
7745 +
7746 + #define PCI_BAR_2 2
7747 + #define PCI_BAR_4 4
7748 +@@ -252,7 +252,6 @@
7749 + #define QM_QOS_MIN_CIR_B 100
7750 + #define QM_QOS_MAX_CIR_U 6
7751 + #define QM_QOS_MAX_CIR_S 11
7752 +-#define QM_QOS_VAL_MAX_LEN 32
7753 + #define QM_DFX_BASE 0x0100000
7754 + #define QM_DFX_STATE1 0x0104000
7755 + #define QM_DFX_STATE2 0x01040C8
7756 +@@ -329,6 +328,22 @@ enum qm_mb_cmd {
7757 + QM_VF_GET_QOS,
7758 + };
7759 +
7760 ++static const struct hisi_qm_cap_info qm_cap_info_comm[] = {
7761 ++ {QM_SUPPORT_DB_ISOLATION, 0x30, 0, BIT(0), 0x0, 0x0, 0x0},
7762 ++ {QM_SUPPORT_FUNC_QOS, 0x3100, 0, BIT(8), 0x0, 0x0, 0x1},
7763 ++ {QM_SUPPORT_STOP_QP, 0x3100, 0, BIT(9), 0x0, 0x0, 0x1},
7764 ++ {QM_SUPPORT_MB_COMMAND, 0x3100, 0, BIT(11), 0x0, 0x0, 0x1},
7765 ++ {QM_SUPPORT_SVA_PREFETCH, 0x3100, 0, BIT(14), 0x0, 0x0, 0x1},
7766 ++};
7767 ++
7768 ++static const struct hisi_qm_cap_info qm_cap_info_pf[] = {
7769 ++ {QM_SUPPORT_RPM, 0x3100, 0, BIT(13), 0x0, 0x0, 0x1},
7770 ++};
7771 ++
7772 ++static const struct hisi_qm_cap_info qm_cap_info_vf[] = {
7773 ++ {QM_SUPPORT_RPM, 0x3100, 0, BIT(12), 0x0, 0x0, 0x0},
7774 ++};
7775 ++
7776 + struct qm_cqe {
7777 + __le32 rsvd0;
7778 + __le16 cmd_id;
7779 +@@ -426,10 +441,7 @@ struct hisi_qm_hw_ops {
7780 + void (*hw_error_init)(struct hisi_qm *qm, u32 ce, u32 nfe, u32 fe);
7781 + void (*hw_error_uninit)(struct hisi_qm *qm);
7782 + enum acc_err_result (*hw_error_handle)(struct hisi_qm *qm);
7783 +- int (*stop_qp)(struct hisi_qp *qp);
7784 + int (*set_msi)(struct hisi_qm *qm, bool set);
7785 +- int (*ping_all_vfs)(struct hisi_qm *qm, u64 cmd);
7786 +- int (*ping_pf)(struct hisi_qm *qm, u64 cmd);
7787 + };
7788 +
7789 + struct qm_dfx_item {
7790 +@@ -828,6 +840,36 @@ static int qm_dev_mem_reset(struct hisi_qm *qm)
7791 + POLL_TIMEOUT);
7792 + }
7793 +
7794 ++/**
7795 ++ * hisi_qm_get_hw_info() - Get device information.
7796 ++ * @qm: The qm which want to get information.
7797 ++ * @info_table: Array for storing device information.
7798 ++ * @index: Index in info_table.
7799 ++ * @is_read: Whether read from reg, 0: not support read from reg.
7800 ++ *
7801 ++ * This function returns device information the caller needs.
7802 ++ */
7803 ++u32 hisi_qm_get_hw_info(struct hisi_qm *qm,
7804 ++ const struct hisi_qm_cap_info *info_table,
7805 ++ u32 index, bool is_read)
7806 ++{
7807 ++ u32 val;
7808 ++
7809 ++ switch (qm->ver) {
7810 ++ case QM_HW_V1:
7811 ++ return info_table[index].v1_val;
7812 ++ case QM_HW_V2:
7813 ++ return info_table[index].v2_val;
7814 ++ default:
7815 ++ if (!is_read)
7816 ++ return info_table[index].v3_val;
7817 ++
7818 ++ val = readl(qm->io_base + info_table[index].offset);
7819 ++ return (val >> info_table[index].shift) & info_table[index].mask;
7820 ++ }
7821 ++}
7822 ++EXPORT_SYMBOL_GPL(hisi_qm_get_hw_info);
7823 ++
7824 + static u32 qm_get_irq_num_v1(struct hisi_qm *qm)
7825 + {
7826 + return QM_IRQ_NUM_V1;
7827 +@@ -854,7 +896,7 @@ static int qm_pm_get_sync(struct hisi_qm *qm)
7828 + struct device *dev = &qm->pdev->dev;
7829 + int ret;
7830 +
7831 +- if (qm->fun_type == QM_HW_VF || qm->ver < QM_HW_V3)
7832 ++ if (!test_bit(QM_SUPPORT_RPM, &qm->caps))
7833 + return 0;
7834 +
7835 + ret = pm_runtime_resume_and_get(dev);
7836 +@@ -870,7 +912,7 @@ static void qm_pm_put_sync(struct hisi_qm *qm)
7837 + {
7838 + struct device *dev = &qm->pdev->dev;
7839 +
7840 +- if (qm->fun_type == QM_HW_VF || qm->ver < QM_HW_V3)
7841 ++ if (!test_bit(QM_SUPPORT_RPM, &qm->caps))
7842 + return;
7843 +
7844 + pm_runtime_mark_last_busy(dev);
7845 +@@ -1151,7 +1193,7 @@ static void qm_init_prefetch(struct hisi_qm *qm)
7846 + struct device *dev = &qm->pdev->dev;
7847 + u32 page_type = 0x0;
7848 +
7849 +- if (qm->ver < QM_HW_V3)
7850 ++ if (!test_bit(QM_SUPPORT_SVA_PREFETCH, &qm->caps))
7851 + return;
7852 +
7853 + switch (PAGE_SIZE) {
7854 +@@ -1270,7 +1312,7 @@ static void qm_vft_data_cfg(struct hisi_qm *qm, enum vft_type type, u32 base,
7855 + }
7856 + break;
7857 + case SHAPER_VFT:
7858 +- if (qm->ver >= QM_HW_V3) {
7859 ++ if (factor) {
7860 + tmp = factor->cir_b |
7861 + (factor->cir_u << QM_SHAPER_FACTOR_CIR_U_SHIFT) |
7862 + (factor->cir_s << QM_SHAPER_FACTOR_CIR_S_SHIFT) |
7863 +@@ -1288,10 +1330,13 @@ static void qm_vft_data_cfg(struct hisi_qm *qm, enum vft_type type, u32 base,
7864 + static int qm_set_vft_common(struct hisi_qm *qm, enum vft_type type,
7865 + u32 fun_num, u32 base, u32 number)
7866 + {
7867 +- struct qm_shaper_factor *factor = &qm->factor[fun_num];
7868 ++ struct qm_shaper_factor *factor = NULL;
7869 + unsigned int val;
7870 + int ret;
7871 +
7872 ++ if (type == SHAPER_VFT && test_bit(QM_SUPPORT_FUNC_QOS, &qm->caps))
7873 ++ factor = &qm->factor[fun_num];
7874 ++
7875 + ret = readl_relaxed_poll_timeout(qm->io_base + QM_VFT_CFG_RDY, val,
7876 + val & BIT(0), POLL_PERIOD,
7877 + POLL_TIMEOUT);
7878 +@@ -1349,7 +1394,7 @@ static int qm_set_sqc_cqc_vft(struct hisi_qm *qm, u32 fun_num, u32 base,
7879 + }
7880 +
7881 + /* init default shaper qos val */
7882 +- if (qm->ver >= QM_HW_V3) {
7883 ++ if (test_bit(QM_SUPPORT_FUNC_QOS, &qm->caps)) {
7884 + ret = qm_shaper_init_vft(qm, fun_num);
7885 + if (ret)
7886 + goto back_sqc_cqc;
7887 +@@ -2495,7 +2540,7 @@ static int qm_wait_vf_prepare_finish(struct hisi_qm *qm)
7888 + u64 val;
7889 + u32 i;
7890 +
7891 +- if (!qm->vfs_num || qm->ver < QM_HW_V3)
7892 ++ if (!qm->vfs_num || !test_bit(QM_SUPPORT_MB_COMMAND, &qm->caps))
7893 + return 0;
7894 +
7895 + while (true) {
7896 +@@ -2780,10 +2825,7 @@ static const struct hisi_qm_hw_ops qm_hw_ops_v3 = {
7897 + .hw_error_init = qm_hw_error_init_v3,
7898 + .hw_error_uninit = qm_hw_error_uninit_v3,
7899 + .hw_error_handle = qm_hw_error_handle_v2,
7900 +- .stop_qp = qm_stop_qp,
7901 + .set_msi = qm_set_msi_v3,
7902 +- .ping_all_vfs = qm_ping_all_vfs,
7903 +- .ping_pf = qm_ping_pf,
7904 + };
7905 +
7906 + static void *qm_get_avail_sqe(struct hisi_qp *qp)
7907 +@@ -3080,8 +3122,8 @@ static int qm_drain_qp(struct hisi_qp *qp)
7908 + return 0;
7909 +
7910 + /* Kunpeng930 supports drain qp by device */
7911 +- if (qm->ops->stop_qp) {
7912 +- ret = qm->ops->stop_qp(qp);
7913 ++ if (test_bit(QM_SUPPORT_STOP_QP, &qm->caps)) {
7914 ++ ret = qm_stop_qp(qp);
7915 + if (ret)
7916 + dev_err(dev, "Failed to stop qp(%u)!\n", qp->qp_id);
7917 + return ret;
7918 +@@ -3312,7 +3354,7 @@ static int hisi_qm_uacce_mmap(struct uacce_queue *q,
7919 + if (qm->ver == QM_HW_V1) {
7920 + if (sz > PAGE_SIZE * QM_DOORBELL_PAGE_NR)
7921 + return -EINVAL;
7922 +- } else if (qm->ver == QM_HW_V2 || !qm->use_db_isolation) {
7923 ++ } else if (!test_bit(QM_SUPPORT_DB_ISOLATION, &qm->caps)) {
7924 + if (sz > PAGE_SIZE * (QM_DOORBELL_PAGE_NR +
7925 + QM_DOORBELL_SQ_CQ_BASE_V2 / PAGE_SIZE))
7926 + return -EINVAL;
7927 +@@ -3466,7 +3508,7 @@ static int qm_alloc_uacce(struct hisi_qm *qm)
7928 +
7929 + if (qm->ver == QM_HW_V1)
7930 + mmio_page_nr = QM_DOORBELL_PAGE_NR;
7931 +- else if (qm->ver == QM_HW_V2 || !qm->use_db_isolation)
7932 ++ else if (!test_bit(QM_SUPPORT_DB_ISOLATION, &qm->caps))
7933 + mmio_page_nr = QM_DOORBELL_PAGE_NR +
7934 + QM_DOORBELL_SQ_CQ_BASE_V2 / PAGE_SIZE;
7935 + else
7936 +@@ -3628,7 +3670,7 @@ static void hisi_qm_pre_init(struct hisi_qm *qm)
7937 + init_rwsem(&qm->qps_lock);
7938 + qm->qp_in_used = 0;
7939 + qm->misc_ctl = false;
7940 +- if (qm->fun_type == QM_HW_PF && qm->ver > QM_HW_V2) {
7941 ++ if (test_bit(QM_SUPPORT_RPM, &qm->caps)) {
7942 + if (!acpi_device_power_manageable(ACPI_COMPANION(&pdev->dev)))
7943 + dev_info(&pdev->dev, "_PS0 and _PR0 are not defined");
7944 + }
7945 +@@ -3638,7 +3680,7 @@ static void qm_cmd_uninit(struct hisi_qm *qm)
7946 + {
7947 + u32 val;
7948 +
7949 +- if (qm->ver < QM_HW_V3)
7950 ++ if (!test_bit(QM_SUPPORT_MB_COMMAND, &qm->caps))
7951 + return;
7952 +
7953 + val = readl(qm->io_base + QM_IFC_INT_MASK);
7954 +@@ -3650,7 +3692,7 @@ static void qm_cmd_init(struct hisi_qm *qm)
7955 + {
7956 + u32 val;
7957 +
7958 +- if (qm->ver < QM_HW_V3)
7959 ++ if (!test_bit(QM_SUPPORT_MB_COMMAND, &qm->caps))
7960 + return;
7961 +
7962 + /* Clear communication interrupt source */
7963 +@@ -3666,7 +3708,7 @@ static void qm_put_pci_res(struct hisi_qm *qm)
7964 + {
7965 + struct pci_dev *pdev = qm->pdev;
7966 +
7967 +- if (qm->use_db_isolation)
7968 ++ if (test_bit(QM_SUPPORT_DB_ISOLATION, &qm->caps))
7969 + iounmap(qm->db_io_base);
7970 +
7971 + iounmap(qm->io_base);
7972 +@@ -3716,7 +3758,9 @@ static void hisi_qm_memory_uninit(struct hisi_qm *qm)
7973 + }
7974 +
7975 + idr_destroy(&qm->qp_idr);
7976 +- kfree(qm->factor);
7977 ++
7978 ++ if (test_bit(QM_SUPPORT_FUNC_QOS, &qm->caps))
7979 ++ kfree(qm->factor);
7980 + }
7981 +
7982 + /**
7983 +@@ -4499,12 +4543,10 @@ static int qm_vf_read_qos(struct hisi_qm *qm)
7984 + qm->mb_qos = 0;
7985 +
7986 + /* vf ping pf to get function qos */
7987 +- if (qm->ops->ping_pf) {
7988 +- ret = qm->ops->ping_pf(qm, QM_VF_GET_QOS);
7989 +- if (ret) {
7990 +- pci_err(qm->pdev, "failed to send cmd to PF to get qos!\n");
7991 +- return ret;
7992 +- }
7993 ++ ret = qm_ping_pf(qm, QM_VF_GET_QOS);
7994 ++ if (ret) {
7995 ++ pci_err(qm->pdev, "failed to send cmd to PF to get qos!\n");
7996 ++ return ret;
7997 + }
7998 +
7999 + while (true) {
8000 +@@ -4583,7 +4625,7 @@ static ssize_t qm_get_qos_value(struct hisi_qm *qm, const char *buf,
8001 + unsigned int *fun_index)
8002 + {
8003 + char tbuf_bdf[QM_DBG_READ_LEN] = {0};
8004 +- char val_buf[QM_QOS_VAL_MAX_LEN] = {0};
8005 ++ char val_buf[QM_DBG_READ_LEN] = {0};
8006 + u32 tmp1, device, function;
8007 + int ret, bus;
8008 +
8009 +@@ -4676,14 +4718,14 @@ static const struct file_operations qm_algqos_fops = {
8010 + * hisi_qm_set_algqos_init() - Initialize function qos debugfs files.
8011 + * @qm: The qm for which we want to add debugfs files.
8012 + *
8013 +- * Create function qos debugfs files.
8014 ++ * Create function qos debugfs files, VF ping PF to get function qos.
8015 + */
8016 + static void hisi_qm_set_algqos_init(struct hisi_qm *qm)
8017 + {
8018 + if (qm->fun_type == QM_HW_PF)
8019 + debugfs_create_file("alg_qos", 0644, qm->debug.debug_root,
8020 + qm, &qm_algqos_fops);
8021 +- else
8022 ++ else if (test_bit(QM_SUPPORT_MB_COMMAND, &qm->caps))
8023 + debugfs_create_file("alg_qos", 0444, qm->debug.debug_root,
8024 + qm, &qm_algqos_fops);
8025 + }
8026 +@@ -4731,7 +4773,7 @@ void hisi_qm_debug_init(struct hisi_qm *qm)
8027 + &qm_atomic64_ops);
8028 + }
8029 +
8030 +- if (qm->ver >= QM_HW_V3)
8031 ++ if (test_bit(QM_SUPPORT_FUNC_QOS, &qm->caps))
8032 + hisi_qm_set_algqos_init(qm);
8033 + }
8034 + EXPORT_SYMBOL_GPL(hisi_qm_debug_init);
8035 +@@ -4848,7 +4890,9 @@ int hisi_qm_sriov_disable(struct pci_dev *pdev, bool is_frozen)
8036 +
8037 + pci_disable_sriov(pdev);
8038 + /* clear vf function shaper configure array */
8039 +- memset(qm->factor + 1, 0, sizeof(struct qm_shaper_factor) * total_vfs);
8040 ++ if (test_bit(QM_SUPPORT_FUNC_QOS, &qm->caps))
8041 ++ memset(qm->factor + 1, 0, sizeof(struct qm_shaper_factor) * total_vfs);
8042 ++
8043 + ret = qm_clear_vft_config(qm);
8044 + if (ret)
8045 + return ret;
8046 +@@ -5072,8 +5116,8 @@ static int qm_try_stop_vfs(struct hisi_qm *qm, u64 cmd,
8047 + return 0;
8048 +
8049 + /* Kunpeng930 supports to notify VFs to stop before PF reset */
8050 +- if (qm->ops->ping_all_vfs) {
8051 +- ret = qm->ops->ping_all_vfs(qm, cmd);
8052 ++ if (test_bit(QM_SUPPORT_MB_COMMAND, &qm->caps)) {
8053 ++ ret = qm_ping_all_vfs(qm, cmd);
8054 + if (ret)
8055 + pci_err(pdev, "failed to send cmd to all VFs before PF reset!\n");
8056 + } else {
8057 +@@ -5264,8 +5308,8 @@ static int qm_try_start_vfs(struct hisi_qm *qm, enum qm_mb_cmd cmd)
8058 + }
8059 +
8060 + /* Kunpeng930 supports to notify VFs to start after PF reset. */
8061 +- if (qm->ops->ping_all_vfs) {
8062 +- ret = qm->ops->ping_all_vfs(qm, cmd);
8063 ++ if (test_bit(QM_SUPPORT_MB_COMMAND, &qm->caps)) {
8064 ++ ret = qm_ping_all_vfs(qm, cmd);
8065 + if (ret)
8066 + pci_warn(pdev, "failed to send cmd to all VFs after PF reset!\n");
8067 + } else {
8068 +@@ -5713,7 +5757,7 @@ err_prepare:
8069 + hisi_qm_set_hw_reset(qm, QM_RESET_STOP_RX_OFFSET);
8070 + out:
8071 + pci_save_state(pdev);
8072 +- ret = qm->ops->ping_pf(qm, cmd);
8073 ++ ret = qm_ping_pf(qm, cmd);
8074 + if (ret)
8075 + dev_warn(&pdev->dev, "PF responds timeout in reset prepare!\n");
8076 + }
8077 +@@ -5731,7 +5775,8 @@ static void qm_pf_reset_vf_done(struct hisi_qm *qm)
8078 + cmd = QM_VF_START_FAIL;
8079 + }
8080 +
8081 +- ret = qm->ops->ping_pf(qm, cmd);
8082 ++ qm_cmd_init(qm);
8083 ++ ret = qm_ping_pf(qm, cmd);
8084 + if (ret)
8085 + dev_warn(&pdev->dev, "PF responds timeout in reset done!\n");
8086 +
8087 +@@ -5792,7 +5837,6 @@ static void qm_pf_reset_vf_process(struct hisi_qm *qm,
8088 + goto err_get_status;
8089 +
8090 + qm_pf_reset_vf_done(qm);
8091 +- qm_cmd_init(qm);
8092 +
8093 + dev_info(dev, "device reset done.\n");
8094 +
8095 +@@ -5936,7 +5980,7 @@ static int qm_get_qp_num(struct hisi_qm *qm)
8096 + qm->ctrl_qp_num = readl(qm->io_base + QM_CAPBILITY) &
8097 + QM_QP_NUN_MASK;
8098 +
8099 +- if (qm->use_db_isolation)
8100 ++ if (test_bit(QM_SUPPORT_DB_ISOLATION, &qm->caps))
8101 + qm->max_qp_num = (readl(qm->io_base + QM_CAPBILITY) >>
8102 + QM_QP_MAX_NUM_SHIFT) & QM_QP_NUN_MASK;
8103 + else
8104 +@@ -5952,6 +5996,39 @@ static int qm_get_qp_num(struct hisi_qm *qm)
8105 + return 0;
8106 + }
8107 +
8108 ++static void qm_get_hw_caps(struct hisi_qm *qm)
8109 ++{
8110 ++ const struct hisi_qm_cap_info *cap_info = qm->fun_type == QM_HW_PF ?
8111 ++ qm_cap_info_pf : qm_cap_info_vf;
8112 ++ u32 size = qm->fun_type == QM_HW_PF ? ARRAY_SIZE(qm_cap_info_pf) :
8113 ++ ARRAY_SIZE(qm_cap_info_vf);
8114 ++ u32 val, i;
8115 ++
8116 ++ /* Doorbell isolate register is a independent register. */
8117 ++ val = hisi_qm_get_hw_info(qm, qm_cap_info_comm, QM_SUPPORT_DB_ISOLATION, true);
8118 ++ if (val)
8119 ++ set_bit(QM_SUPPORT_DB_ISOLATION, &qm->caps);
8120 ++
8121 ++ if (qm->ver >= QM_HW_V3) {
8122 ++ val = readl(qm->io_base + QM_FUNC_CAPS_REG);
8123 ++ qm->cap_ver = val & QM_CAPBILITY_VERSION;
8124 ++ }
8125 ++
8126 ++ /* Get PF/VF common capbility */
8127 ++ for (i = 1; i < ARRAY_SIZE(qm_cap_info_comm); i++) {
8128 ++ val = hisi_qm_get_hw_info(qm, qm_cap_info_comm, i, qm->cap_ver);
8129 ++ if (val)
8130 ++ set_bit(qm_cap_info_comm[i].type, &qm->caps);
8131 ++ }
8132 ++
8133 ++ /* Get PF/VF different capbility */
8134 ++ for (i = 0; i < size; i++) {
8135 ++ val = hisi_qm_get_hw_info(qm, cap_info, i, qm->cap_ver);
8136 ++ if (val)
8137 ++ set_bit(cap_info[i].type, &qm->caps);
8138 ++ }
8139 ++}
8140 ++
8141 + static int qm_get_pci_res(struct hisi_qm *qm)
8142 + {
8143 + struct pci_dev *pdev = qm->pdev;
8144 +@@ -5971,16 +6048,8 @@ static int qm_get_pci_res(struct hisi_qm *qm)
8145 + goto err_request_mem_regions;
8146 + }
8147 +
8148 +- if (qm->ver > QM_HW_V2) {
8149 +- if (qm->fun_type == QM_HW_PF)
8150 +- qm->use_db_isolation = readl(qm->io_base +
8151 +- QM_QUE_ISO_EN) & BIT(0);
8152 +- else
8153 +- qm->use_db_isolation = readl(qm->io_base +
8154 +- QM_QUE_ISO_CFG_V) & BIT(0);
8155 +- }
8156 +-
8157 +- if (qm->use_db_isolation) {
8158 ++ qm_get_hw_caps(qm);
8159 ++ if (test_bit(QM_SUPPORT_DB_ISOLATION, &qm->caps)) {
8160 + qm->db_interval = QM_QP_DB_INTERVAL;
8161 + qm->db_phys_base = pci_resource_start(pdev, PCI_BAR_4);
8162 + qm->db_io_base = ioremap(qm->db_phys_base,
8163 +@@ -6004,7 +6073,7 @@ static int qm_get_pci_res(struct hisi_qm *qm)
8164 + return 0;
8165 +
8166 + err_db_ioremap:
8167 +- if (qm->use_db_isolation)
8168 ++ if (test_bit(QM_SUPPORT_DB_ISOLATION, &qm->caps))
8169 + iounmap(qm->db_io_base);
8170 + err_ioremap:
8171 + iounmap(qm->io_base);
8172 +@@ -6121,12 +6190,15 @@ static int hisi_qm_memory_init(struct hisi_qm *qm)
8173 + int ret, total_func, i;
8174 + size_t off = 0;
8175 +
8176 +- total_func = pci_sriov_get_totalvfs(qm->pdev) + 1;
8177 +- qm->factor = kcalloc(total_func, sizeof(struct qm_shaper_factor), GFP_KERNEL);
8178 +- if (!qm->factor)
8179 +- return -ENOMEM;
8180 +- for (i = 0; i < total_func; i++)
8181 +- qm->factor[i].func_qos = QM_QOS_MAX_VAL;
8182 ++ if (test_bit(QM_SUPPORT_FUNC_QOS, &qm->caps)) {
8183 ++ total_func = pci_sriov_get_totalvfs(qm->pdev) + 1;
8184 ++ qm->factor = kcalloc(total_func, sizeof(struct qm_shaper_factor), GFP_KERNEL);
8185 ++ if (!qm->factor)
8186 ++ return -ENOMEM;
8187 ++
8188 ++ for (i = 0; i < total_func; i++)
8189 ++ qm->factor[i].func_qos = QM_QOS_MAX_VAL;
8190 ++ }
8191 +
8192 + #define QM_INIT_BUF(qm, type, num) do { \
8193 + (qm)->type = ((qm)->qdma.va + (off)); \
8194 +@@ -6143,8 +6215,8 @@ static int hisi_qm_memory_init(struct hisi_qm *qm)
8195 + GFP_ATOMIC);
8196 + dev_dbg(dev, "allocate qm dma buf size=%zx)\n", qm->qdma.size);
8197 + if (!qm->qdma.va) {
8198 +- ret = -ENOMEM;
8199 +- goto err_alloc_qdma;
8200 ++ ret = -ENOMEM;
8201 ++ goto err_destroy_idr;
8202 + }
8203 +
8204 + QM_INIT_BUF(qm, eqe, QM_EQ_DEPTH);
8205 +@@ -6160,8 +6232,10 @@ static int hisi_qm_memory_init(struct hisi_qm *qm)
8206 +
8207 + err_alloc_qp_array:
8208 + dma_free_coherent(dev, qm->qdma.size, qm->qdma.va, qm->qdma.dma);
8209 +-err_alloc_qdma:
8210 +- kfree(qm->factor);
8211 ++err_destroy_idr:
8212 ++ idr_destroy(&qm->qp_idr);
8213 ++ if (test_bit(QM_SUPPORT_FUNC_QOS, &qm->caps))
8214 ++ kfree(qm->factor);
8215 +
8216 + return ret;
8217 + }
8218 +@@ -6304,7 +6378,7 @@ void hisi_qm_pm_init(struct hisi_qm *qm)
8219 + {
8220 + struct device *dev = &qm->pdev->dev;
8221 +
8222 +- if (qm->fun_type == QM_HW_VF || qm->ver < QM_HW_V3)
8223 ++ if (!test_bit(QM_SUPPORT_RPM, &qm->caps))
8224 + return;
8225 +
8226 + pm_runtime_set_autosuspend_delay(dev, QM_AUTOSUSPEND_DELAY);
8227 +@@ -6323,7 +6397,7 @@ void hisi_qm_pm_uninit(struct hisi_qm *qm)
8228 + {
8229 + struct device *dev = &qm->pdev->dev;
8230 +
8231 +- if (qm->fun_type == QM_HW_VF || qm->ver < QM_HW_V3)
8232 ++ if (!test_bit(QM_SUPPORT_RPM, &qm->caps))
8233 + return;
8234 +
8235 + pm_runtime_get_noresume(dev);
8236 +diff --git a/drivers/crypto/hisilicon/sec2/sec_main.c b/drivers/crypto/hisilicon/sec2/sec_main.c
8237 +index 2c0be91c0b094..1ec3b06345fd4 100644
8238 +--- a/drivers/crypto/hisilicon/sec2/sec_main.c
8239 ++++ b/drivers/crypto/hisilicon/sec2/sec_main.c
8240 +@@ -415,7 +415,7 @@ static void sec_open_sva_prefetch(struct hisi_qm *qm)
8241 + u32 val;
8242 + int ret;
8243 +
8244 +- if (qm->ver < QM_HW_V3)
8245 ++ if (!test_bit(QM_SUPPORT_SVA_PREFETCH, &qm->caps))
8246 + return;
8247 +
8248 + /* Enable prefetch */
8249 +@@ -435,7 +435,7 @@ static void sec_close_sva_prefetch(struct hisi_qm *qm)
8250 + u32 val;
8251 + int ret;
8252 +
8253 +- if (qm->ver < QM_HW_V3)
8254 ++ if (!test_bit(QM_SUPPORT_SVA_PREFETCH, &qm->caps))
8255 + return;
8256 +
8257 + val = readl_relaxed(qm->io_base + SEC_PREFETCH_CFG);
8258 +diff --git a/drivers/crypto/hisilicon/zip/zip_main.c b/drivers/crypto/hisilicon/zip/zip_main.c
8259 +index c3303d99acac7..65ed2ae8e1319 100644
8260 +--- a/drivers/crypto/hisilicon/zip/zip_main.c
8261 ++++ b/drivers/crypto/hisilicon/zip/zip_main.c
8262 +@@ -348,7 +348,7 @@ static void hisi_zip_open_sva_prefetch(struct hisi_qm *qm)
8263 + u32 val;
8264 + int ret;
8265 +
8266 +- if (qm->ver < QM_HW_V3)
8267 ++ if (!test_bit(QM_SUPPORT_SVA_PREFETCH, &qm->caps))
8268 + return;
8269 +
8270 + /* Enable prefetch */
8271 +@@ -368,7 +368,7 @@ static void hisi_zip_close_sva_prefetch(struct hisi_qm *qm)
8272 + u32 val;
8273 + int ret;
8274 +
8275 +- if (qm->ver < QM_HW_V3)
8276 ++ if (!test_bit(QM_SUPPORT_SVA_PREFETCH, &qm->caps))
8277 + return;
8278 +
8279 + val = readl_relaxed(qm->io_base + HZIP_PREFETCH_CFG);
8280 +diff --git a/drivers/crypto/img-hash.c b/drivers/crypto/img-hash.c
8281 +index d8e82d69745d8..9629e98bd68b7 100644
8282 +--- a/drivers/crypto/img-hash.c
8283 ++++ b/drivers/crypto/img-hash.c
8284 +@@ -358,12 +358,16 @@ static int img_hash_dma_init(struct img_hash_dev *hdev)
8285 + static void img_hash_dma_task(unsigned long d)
8286 + {
8287 + struct img_hash_dev *hdev = (struct img_hash_dev *)d;
8288 +- struct img_hash_request_ctx *ctx = ahash_request_ctx(hdev->req);
8289 ++ struct img_hash_request_ctx *ctx;
8290 + u8 *addr;
8291 + size_t nbytes, bleft, wsend, len, tbc;
8292 + struct scatterlist tsg;
8293 +
8294 +- if (!hdev->req || !ctx->sg)
8295 ++ if (!hdev->req)
8296 ++ return;
8297 ++
8298 ++ ctx = ahash_request_ctx(hdev->req);
8299 ++ if (!ctx->sg)
8300 + return;
8301 +
8302 + addr = sg_virt(ctx->sg);
8303 +diff --git a/drivers/crypto/omap-sham.c b/drivers/crypto/omap-sham.c
8304 +index 655a7f5a406a1..cbeda59c6b191 100644
8305 +--- a/drivers/crypto/omap-sham.c
8306 ++++ b/drivers/crypto/omap-sham.c
8307 +@@ -2114,7 +2114,7 @@ static int omap_sham_probe(struct platform_device *pdev)
8308 +
8309 + pm_runtime_enable(dev);
8310 +
8311 +- err = pm_runtime_get_sync(dev);
8312 ++ err = pm_runtime_resume_and_get(dev);
8313 + if (err < 0) {
8314 + dev_err(dev, "failed to get sync: %d\n", err);
8315 + goto err_pm;
8316 +diff --git a/drivers/crypto/qat/qat_4xxx/adf_drv.c b/drivers/crypto/qat/qat_4xxx/adf_drv.c
8317 +index 2f212561acc47..670a58b25cb16 100644
8318 +--- a/drivers/crypto/qat/qat_4xxx/adf_drv.c
8319 ++++ b/drivers/crypto/qat/qat_4xxx/adf_drv.c
8320 +@@ -261,6 +261,7 @@ static int adf_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
8321 + hw_data->accel_capabilities_mask = hw_data->get_accel_cap(accel_dev);
8322 + if (!hw_data->accel_capabilities_mask) {
8323 + dev_err(&pdev->dev, "Failed to get capabilities mask.\n");
8324 ++ ret = -EINVAL;
8325 + goto out_err;
8326 + }
8327 +
8328 +diff --git a/drivers/crypto/rockchip/rk3288_crypto.c b/drivers/crypto/rockchip/rk3288_crypto.c
8329 +index 35d73061d1569..14a0aef18ab13 100644
8330 +--- a/drivers/crypto/rockchip/rk3288_crypto.c
8331 ++++ b/drivers/crypto/rockchip/rk3288_crypto.c
8332 +@@ -65,186 +65,24 @@ static void rk_crypto_disable_clk(struct rk_crypto_info *dev)
8333 + clk_disable_unprepare(dev->sclk);
8334 + }
8335 +
8336 +-static int check_alignment(struct scatterlist *sg_src,
8337 +- struct scatterlist *sg_dst,
8338 +- int align_mask)
8339 +-{
8340 +- int in, out, align;
8341 +-
8342 +- in = IS_ALIGNED((uint32_t)sg_src->offset, 4) &&
8343 +- IS_ALIGNED((uint32_t)sg_src->length, align_mask);
8344 +- if (!sg_dst)
8345 +- return in;
8346 +- out = IS_ALIGNED((uint32_t)sg_dst->offset, 4) &&
8347 +- IS_ALIGNED((uint32_t)sg_dst->length, align_mask);
8348 +- align = in && out;
8349 +-
8350 +- return (align && (sg_src->length == sg_dst->length));
8351 +-}
8352 +-
8353 +-static int rk_load_data(struct rk_crypto_info *dev,
8354 +- struct scatterlist *sg_src,
8355 +- struct scatterlist *sg_dst)
8356 +-{
8357 +- unsigned int count;
8358 +-
8359 +- dev->aligned = dev->aligned ?
8360 +- check_alignment(sg_src, sg_dst, dev->align_size) :
8361 +- dev->aligned;
8362 +- if (dev->aligned) {
8363 +- count = min(dev->left_bytes, sg_src->length);
8364 +- dev->left_bytes -= count;
8365 +-
8366 +- if (!dma_map_sg(dev->dev, sg_src, 1, DMA_TO_DEVICE)) {
8367 +- dev_err(dev->dev, "[%s:%d] dma_map_sg(src) error\n",
8368 +- __func__, __LINE__);
8369 +- return -EINVAL;
8370 +- }
8371 +- dev->addr_in = sg_dma_address(sg_src);
8372 +-
8373 +- if (sg_dst) {
8374 +- if (!dma_map_sg(dev->dev, sg_dst, 1, DMA_FROM_DEVICE)) {
8375 +- dev_err(dev->dev,
8376 +- "[%s:%d] dma_map_sg(dst) error\n",
8377 +- __func__, __LINE__);
8378 +- dma_unmap_sg(dev->dev, sg_src, 1,
8379 +- DMA_TO_DEVICE);
8380 +- return -EINVAL;
8381 +- }
8382 +- dev->addr_out = sg_dma_address(sg_dst);
8383 +- }
8384 +- } else {
8385 +- count = (dev->left_bytes > PAGE_SIZE) ?
8386 +- PAGE_SIZE : dev->left_bytes;
8387 +-
8388 +- if (!sg_pcopy_to_buffer(dev->first, dev->src_nents,
8389 +- dev->addr_vir, count,
8390 +- dev->total - dev->left_bytes)) {
8391 +- dev_err(dev->dev, "[%s:%d] pcopy err\n",
8392 +- __func__, __LINE__);
8393 +- return -EINVAL;
8394 +- }
8395 +- dev->left_bytes -= count;
8396 +- sg_init_one(&dev->sg_tmp, dev->addr_vir, count);
8397 +- if (!dma_map_sg(dev->dev, &dev->sg_tmp, 1, DMA_TO_DEVICE)) {
8398 +- dev_err(dev->dev, "[%s:%d] dma_map_sg(sg_tmp) error\n",
8399 +- __func__, __LINE__);
8400 +- return -ENOMEM;
8401 +- }
8402 +- dev->addr_in = sg_dma_address(&dev->sg_tmp);
8403 +-
8404 +- if (sg_dst) {
8405 +- if (!dma_map_sg(dev->dev, &dev->sg_tmp, 1,
8406 +- DMA_FROM_DEVICE)) {
8407 +- dev_err(dev->dev,
8408 +- "[%s:%d] dma_map_sg(sg_tmp) error\n",
8409 +- __func__, __LINE__);
8410 +- dma_unmap_sg(dev->dev, &dev->sg_tmp, 1,
8411 +- DMA_TO_DEVICE);
8412 +- return -ENOMEM;
8413 +- }
8414 +- dev->addr_out = sg_dma_address(&dev->sg_tmp);
8415 +- }
8416 +- }
8417 +- dev->count = count;
8418 +- return 0;
8419 +-}
8420 +-
8421 +-static void rk_unload_data(struct rk_crypto_info *dev)
8422 +-{
8423 +- struct scatterlist *sg_in, *sg_out;
8424 +-
8425 +- sg_in = dev->aligned ? dev->sg_src : &dev->sg_tmp;
8426 +- dma_unmap_sg(dev->dev, sg_in, 1, DMA_TO_DEVICE);
8427 +-
8428 +- if (dev->sg_dst) {
8429 +- sg_out = dev->aligned ? dev->sg_dst : &dev->sg_tmp;
8430 +- dma_unmap_sg(dev->dev, sg_out, 1, DMA_FROM_DEVICE);
8431 +- }
8432 +-}
8433 +-
8434 + static irqreturn_t rk_crypto_irq_handle(int irq, void *dev_id)
8435 + {
8436 + struct rk_crypto_info *dev = platform_get_drvdata(dev_id);
8437 + u32 interrupt_status;
8438 +
8439 +- spin_lock(&dev->lock);
8440 + interrupt_status = CRYPTO_READ(dev, RK_CRYPTO_INTSTS);
8441 + CRYPTO_WRITE(dev, RK_CRYPTO_INTSTS, interrupt_status);
8442 +
8443 ++ dev->status = 1;
8444 + if (interrupt_status & 0x0a) {
8445 + dev_warn(dev->dev, "DMA Error\n");
8446 +- dev->err = -EFAULT;
8447 ++ dev->status = 0;
8448 + }
8449 +- tasklet_schedule(&dev->done_task);
8450 ++ complete(&dev->complete);
8451 +
8452 +- spin_unlock(&dev->lock);
8453 + return IRQ_HANDLED;
8454 + }
8455 +
8456 +-static int rk_crypto_enqueue(struct rk_crypto_info *dev,
8457 +- struct crypto_async_request *async_req)
8458 +-{
8459 +- unsigned long flags;
8460 +- int ret;
8461 +-
8462 +- spin_lock_irqsave(&dev->lock, flags);
8463 +- ret = crypto_enqueue_request(&dev->queue, async_req);
8464 +- if (dev->busy) {
8465 +- spin_unlock_irqrestore(&dev->lock, flags);
8466 +- return ret;
8467 +- }
8468 +- dev->busy = true;
8469 +- spin_unlock_irqrestore(&dev->lock, flags);
8470 +- tasklet_schedule(&dev->queue_task);
8471 +-
8472 +- return ret;
8473 +-}
8474 +-
8475 +-static void rk_crypto_queue_task_cb(unsigned long data)
8476 +-{
8477 +- struct rk_crypto_info *dev = (struct rk_crypto_info *)data;
8478 +- struct crypto_async_request *async_req, *backlog;
8479 +- unsigned long flags;
8480 +- int err = 0;
8481 +-
8482 +- dev->err = 0;
8483 +- spin_lock_irqsave(&dev->lock, flags);
8484 +- backlog = crypto_get_backlog(&dev->queue);
8485 +- async_req = crypto_dequeue_request(&dev->queue);
8486 +-
8487 +- if (!async_req) {
8488 +- dev->busy = false;
8489 +- spin_unlock_irqrestore(&dev->lock, flags);
8490 +- return;
8491 +- }
8492 +- spin_unlock_irqrestore(&dev->lock, flags);
8493 +-
8494 +- if (backlog) {
8495 +- backlog->complete(backlog, -EINPROGRESS);
8496 +- backlog = NULL;
8497 +- }
8498 +-
8499 +- dev->async_req = async_req;
8500 +- err = dev->start(dev);
8501 +- if (err)
8502 +- dev->complete(dev->async_req, err);
8503 +-}
8504 +-
8505 +-static void rk_crypto_done_task_cb(unsigned long data)
8506 +-{
8507 +- struct rk_crypto_info *dev = (struct rk_crypto_info *)data;
8508 +-
8509 +- if (dev->err) {
8510 +- dev->complete(dev->async_req, dev->err);
8511 +- return;
8512 +- }
8513 +-
8514 +- dev->err = dev->update(dev);
8515 +- if (dev->err)
8516 +- dev->complete(dev->async_req, dev->err);
8517 +-}
8518 +-
8519 + static struct rk_crypto_tmp *rk_cipher_algs[] = {
8520 + &rk_ecb_aes_alg,
8521 + &rk_cbc_aes_alg,
8522 +@@ -337,8 +175,6 @@ static int rk_crypto_probe(struct platform_device *pdev)
8523 + if (err)
8524 + goto err_crypto;
8525 +
8526 +- spin_lock_init(&crypto_info->lock);
8527 +-
8528 + crypto_info->reg = devm_platform_ioremap_resource(pdev, 0);
8529 + if (IS_ERR(crypto_info->reg)) {
8530 + err = PTR_ERR(crypto_info->reg);
8531 +@@ -389,18 +225,11 @@ static int rk_crypto_probe(struct platform_device *pdev)
8532 + crypto_info->dev = &pdev->dev;
8533 + platform_set_drvdata(pdev, crypto_info);
8534 +
8535 +- tasklet_init(&crypto_info->queue_task,
8536 +- rk_crypto_queue_task_cb, (unsigned long)crypto_info);
8537 +- tasklet_init(&crypto_info->done_task,
8538 +- rk_crypto_done_task_cb, (unsigned long)crypto_info);
8539 +- crypto_init_queue(&crypto_info->queue, 50);
8540 ++ crypto_info->engine = crypto_engine_alloc_init(&pdev->dev, true);
8541 ++ crypto_engine_start(crypto_info->engine);
8542 ++ init_completion(&crypto_info->complete);
8543 +
8544 +- crypto_info->enable_clk = rk_crypto_enable_clk;
8545 +- crypto_info->disable_clk = rk_crypto_disable_clk;
8546 +- crypto_info->load_data = rk_load_data;
8547 +- crypto_info->unload_data = rk_unload_data;
8548 +- crypto_info->enqueue = rk_crypto_enqueue;
8549 +- crypto_info->busy = false;
8550 ++ rk_crypto_enable_clk(crypto_info);
8551 +
8552 + err = rk_crypto_register(crypto_info);
8553 + if (err) {
8554 +@@ -412,9 +241,9 @@ static int rk_crypto_probe(struct platform_device *pdev)
8555 + return 0;
8556 +
8557 + err_register_alg:
8558 +- tasklet_kill(&crypto_info->queue_task);
8559 +- tasklet_kill(&crypto_info->done_task);
8560 ++ crypto_engine_exit(crypto_info->engine);
8561 + err_crypto:
8562 ++ dev_err(dev, "Crypto Accelerator not successfully registered\n");
8563 + return err;
8564 + }
8565 +
8566 +@@ -423,8 +252,8 @@ static int rk_crypto_remove(struct platform_device *pdev)
8567 + struct rk_crypto_info *crypto_tmp = platform_get_drvdata(pdev);
8568 +
8569 + rk_crypto_unregister();
8570 +- tasklet_kill(&crypto_tmp->done_task);
8571 +- tasklet_kill(&crypto_tmp->queue_task);
8572 ++ rk_crypto_disable_clk(crypto_tmp);
8573 ++ crypto_engine_exit(crypto_tmp->engine);
8574 + return 0;
8575 + }
8576 +
8577 +diff --git a/drivers/crypto/rockchip/rk3288_crypto.h b/drivers/crypto/rockchip/rk3288_crypto.h
8578 +index 97278c2574ff9..045e811b4af84 100644
8579 +--- a/drivers/crypto/rockchip/rk3288_crypto.h
8580 ++++ b/drivers/crypto/rockchip/rk3288_crypto.h
8581 +@@ -5,9 +5,11 @@
8582 + #include <crypto/aes.h>
8583 + #include <crypto/internal/des.h>
8584 + #include <crypto/algapi.h>
8585 ++#include <linux/dma-mapping.h>
8586 + #include <linux/interrupt.h>
8587 + #include <linux/delay.h>
8588 + #include <linux/scatterlist.h>
8589 ++#include <crypto/engine.h>
8590 + #include <crypto/internal/hash.h>
8591 + #include <crypto/internal/skcipher.h>
8592 +
8593 +@@ -193,45 +195,15 @@ struct rk_crypto_info {
8594 + struct reset_control *rst;
8595 + void __iomem *reg;
8596 + int irq;
8597 +- struct crypto_queue queue;
8598 +- struct tasklet_struct queue_task;
8599 +- struct tasklet_struct done_task;
8600 +- struct crypto_async_request *async_req;
8601 +- int err;
8602 +- /* device lock */
8603 +- spinlock_t lock;
8604 +-
8605 +- /* the public variable */
8606 +- struct scatterlist *sg_src;
8607 +- struct scatterlist *sg_dst;
8608 +- struct scatterlist sg_tmp;
8609 +- struct scatterlist *first;
8610 +- unsigned int left_bytes;
8611 +- void *addr_vir;
8612 +- int aligned;
8613 +- int align_size;
8614 +- size_t src_nents;
8615 +- size_t dst_nents;
8616 +- unsigned int total;
8617 +- unsigned int count;
8618 +- dma_addr_t addr_in;
8619 +- dma_addr_t addr_out;
8620 +- bool busy;
8621 +- int (*start)(struct rk_crypto_info *dev);
8622 +- int (*update)(struct rk_crypto_info *dev);
8623 +- void (*complete)(struct crypto_async_request *base, int err);
8624 +- int (*enable_clk)(struct rk_crypto_info *dev);
8625 +- void (*disable_clk)(struct rk_crypto_info *dev);
8626 +- int (*load_data)(struct rk_crypto_info *dev,
8627 +- struct scatterlist *sg_src,
8628 +- struct scatterlist *sg_dst);
8629 +- void (*unload_data)(struct rk_crypto_info *dev);
8630 +- int (*enqueue)(struct rk_crypto_info *dev,
8631 +- struct crypto_async_request *async_req);
8632 ++
8633 ++ struct crypto_engine *engine;
8634 ++ struct completion complete;
8635 ++ int status;
8636 + };
8637 +
8638 + /* the private variable of hash */
8639 + struct rk_ahash_ctx {
8640 ++ struct crypto_engine_ctx enginectx;
8641 + struct rk_crypto_info *dev;
8642 + /* for fallback */
8643 + struct crypto_ahash *fallback_tfm;
8644 +@@ -241,14 +213,23 @@ struct rk_ahash_ctx {
8645 + struct rk_ahash_rctx {
8646 + struct ahash_request fallback_req;
8647 + u32 mode;
8648 ++ int nrsg;
8649 + };
8650 +
8651 + /* the private variable of cipher */
8652 + struct rk_cipher_ctx {
8653 ++ struct crypto_engine_ctx enginectx;
8654 + struct rk_crypto_info *dev;
8655 + unsigned int keylen;
8656 +- u32 mode;
8657 ++ u8 key[AES_MAX_KEY_SIZE];
8658 + u8 iv[AES_BLOCK_SIZE];
8659 ++ struct crypto_skcipher *fallback_tfm;
8660 ++};
8661 ++
8662 ++struct rk_cipher_rctx {
8663 ++ u8 backup_iv[AES_BLOCK_SIZE];
8664 ++ u32 mode;
8665 ++ struct skcipher_request fallback_req; // keep at the end
8666 + };
8667 +
8668 + enum alg_type {
8669 +diff --git a/drivers/crypto/rockchip/rk3288_crypto_ahash.c b/drivers/crypto/rockchip/rk3288_crypto_ahash.c
8670 +index ed03058497bc2..edd40e16a3f0a 100644
8671 +--- a/drivers/crypto/rockchip/rk3288_crypto_ahash.c
8672 ++++ b/drivers/crypto/rockchip/rk3288_crypto_ahash.c
8673 +@@ -9,6 +9,7 @@
8674 + * Some ideas are from marvell/cesa.c and s5p-sss.c driver.
8675 + */
8676 + #include <linux/device.h>
8677 ++#include <asm/unaligned.h>
8678 + #include "rk3288_crypto.h"
8679 +
8680 + /*
8681 +@@ -16,6 +17,40 @@
8682 + * so we put the fixed hash out when met zero message.
8683 + */
8684 +
8685 ++static bool rk_ahash_need_fallback(struct ahash_request *req)
8686 ++{
8687 ++ struct scatterlist *sg;
8688 ++
8689 ++ sg = req->src;
8690 ++ while (sg) {
8691 ++ if (!IS_ALIGNED(sg->offset, sizeof(u32))) {
8692 ++ return true;
8693 ++ }
8694 ++ if (sg->length % 4) {
8695 ++ return true;
8696 ++ }
8697 ++ sg = sg_next(sg);
8698 ++ }
8699 ++ return false;
8700 ++}
8701 ++
8702 ++static int rk_ahash_digest_fb(struct ahash_request *areq)
8703 ++{
8704 ++ struct rk_ahash_rctx *rctx = ahash_request_ctx(areq);
8705 ++ struct crypto_ahash *tfm = crypto_ahash_reqtfm(areq);
8706 ++ struct rk_ahash_ctx *tfmctx = crypto_ahash_ctx(tfm);
8707 ++
8708 ++ ahash_request_set_tfm(&rctx->fallback_req, tfmctx->fallback_tfm);
8709 ++ rctx->fallback_req.base.flags = areq->base.flags &
8710 ++ CRYPTO_TFM_REQ_MAY_SLEEP;
8711 ++
8712 ++ rctx->fallback_req.nbytes = areq->nbytes;
8713 ++ rctx->fallback_req.src = areq->src;
8714 ++ rctx->fallback_req.result = areq->result;
8715 ++
8716 ++ return crypto_ahash_digest(&rctx->fallback_req);
8717 ++}
8718 ++
8719 + static int zero_message_process(struct ahash_request *req)
8720 + {
8721 + struct crypto_ahash *tfm = crypto_ahash_reqtfm(req);
8722 +@@ -38,16 +73,12 @@ static int zero_message_process(struct ahash_request *req)
8723 + return 0;
8724 + }
8725 +
8726 +-static void rk_ahash_crypto_complete(struct crypto_async_request *base, int err)
8727 +-{
8728 +- if (base->complete)
8729 +- base->complete(base, err);
8730 +-}
8731 +-
8732 +-static void rk_ahash_reg_init(struct rk_crypto_info *dev)
8733 ++static void rk_ahash_reg_init(struct ahash_request *req)
8734 + {
8735 +- struct ahash_request *req = ahash_request_cast(dev->async_req);
8736 + struct rk_ahash_rctx *rctx = ahash_request_ctx(req);
8737 ++ struct crypto_ahash *tfm = crypto_ahash_reqtfm(req);
8738 ++ struct rk_ahash_ctx *tctx = crypto_ahash_ctx(tfm);
8739 ++ struct rk_crypto_info *dev = tctx->dev;
8740 + int reg_status;
8741 +
8742 + reg_status = CRYPTO_READ(dev, RK_CRYPTO_CTRL) |
8743 +@@ -74,7 +105,7 @@ static void rk_ahash_reg_init(struct rk_crypto_info *dev)
8744 + RK_CRYPTO_BYTESWAP_BRFIFO |
8745 + RK_CRYPTO_BYTESWAP_BTFIFO);
8746 +
8747 +- CRYPTO_WRITE(dev, RK_CRYPTO_HASH_MSG_LEN, dev->total);
8748 ++ CRYPTO_WRITE(dev, RK_CRYPTO_HASH_MSG_LEN, req->nbytes);
8749 + }
8750 +
8751 + static int rk_ahash_init(struct ahash_request *req)
8752 +@@ -167,48 +198,64 @@ static int rk_ahash_digest(struct ahash_request *req)
8753 + struct rk_ahash_ctx *tctx = crypto_tfm_ctx(req->base.tfm);
8754 + struct rk_crypto_info *dev = tctx->dev;
8755 +
8756 ++ if (rk_ahash_need_fallback(req))
8757 ++ return rk_ahash_digest_fb(req);
8758 ++
8759 + if (!req->nbytes)
8760 + return zero_message_process(req);
8761 +- else
8762 +- return dev->enqueue(dev, &req->base);
8763 ++
8764 ++ return crypto_transfer_hash_request_to_engine(dev->engine, req);
8765 + }
8766 +
8767 +-static void crypto_ahash_dma_start(struct rk_crypto_info *dev)
8768 ++static void crypto_ahash_dma_start(struct rk_crypto_info *dev, struct scatterlist *sg)
8769 + {
8770 +- CRYPTO_WRITE(dev, RK_CRYPTO_HRDMAS, dev->addr_in);
8771 +- CRYPTO_WRITE(dev, RK_CRYPTO_HRDMAL, (dev->count + 3) / 4);
8772 ++ CRYPTO_WRITE(dev, RK_CRYPTO_HRDMAS, sg_dma_address(sg));
8773 ++ CRYPTO_WRITE(dev, RK_CRYPTO_HRDMAL, sg_dma_len(sg) / 4);
8774 + CRYPTO_WRITE(dev, RK_CRYPTO_CTRL, RK_CRYPTO_HASH_START |
8775 + (RK_CRYPTO_HASH_START << 16));
8776 + }
8777 +
8778 +-static int rk_ahash_set_data_start(struct rk_crypto_info *dev)
8779 ++static int rk_hash_prepare(struct crypto_engine *engine, void *breq)
8780 ++{
8781 ++ struct ahash_request *areq = container_of(breq, struct ahash_request, base);
8782 ++ struct crypto_ahash *tfm = crypto_ahash_reqtfm(areq);
8783 ++ struct rk_ahash_rctx *rctx = ahash_request_ctx(areq);
8784 ++ struct rk_ahash_ctx *tctx = crypto_ahash_ctx(tfm);
8785 ++ int ret;
8786 ++
8787 ++ ret = dma_map_sg(tctx->dev->dev, areq->src, sg_nents(areq->src), DMA_TO_DEVICE);
8788 ++ if (ret <= 0)
8789 ++ return -EINVAL;
8790 ++
8791 ++ rctx->nrsg = ret;
8792 ++
8793 ++ return 0;
8794 ++}
8795 ++
8796 ++static int rk_hash_unprepare(struct crypto_engine *engine, void *breq)
8797 + {
8798 +- int err;
8799 ++ struct ahash_request *areq = container_of(breq, struct ahash_request, base);
8800 ++ struct crypto_ahash *tfm = crypto_ahash_reqtfm(areq);
8801 ++ struct rk_ahash_rctx *rctx = ahash_request_ctx(areq);
8802 ++ struct rk_ahash_ctx *tctx = crypto_ahash_ctx(tfm);
8803 +
8804 +- err = dev->load_data(dev, dev->sg_src, NULL);
8805 +- if (!err)
8806 +- crypto_ahash_dma_start(dev);
8807 +- return err;
8808 ++ dma_unmap_sg(tctx->dev->dev, areq->src, rctx->nrsg, DMA_TO_DEVICE);
8809 ++ return 0;
8810 + }
8811 +
8812 +-static int rk_ahash_start(struct rk_crypto_info *dev)
8813 ++static int rk_hash_run(struct crypto_engine *engine, void *breq)
8814 + {
8815 +- struct ahash_request *req = ahash_request_cast(dev->async_req);
8816 +- struct crypto_ahash *tfm;
8817 +- struct rk_ahash_rctx *rctx;
8818 +-
8819 +- dev->total = req->nbytes;
8820 +- dev->left_bytes = req->nbytes;
8821 +- dev->aligned = 0;
8822 +- dev->align_size = 4;
8823 +- dev->sg_dst = NULL;
8824 +- dev->sg_src = req->src;
8825 +- dev->first = req->src;
8826 +- dev->src_nents = sg_nents(req->src);
8827 +- rctx = ahash_request_ctx(req);
8828 ++ struct ahash_request *areq = container_of(breq, struct ahash_request, base);
8829 ++ struct crypto_ahash *tfm = crypto_ahash_reqtfm(areq);
8830 ++ struct rk_ahash_rctx *rctx = ahash_request_ctx(areq);
8831 ++ struct rk_ahash_ctx *tctx = crypto_ahash_ctx(tfm);
8832 ++ struct scatterlist *sg = areq->src;
8833 ++ int err = 0;
8834 ++ int i;
8835 ++ u32 v;
8836 ++
8837 + rctx->mode = 0;
8838 +
8839 +- tfm = crypto_ahash_reqtfm(req);
8840 + switch (crypto_ahash_digestsize(tfm)) {
8841 + case SHA1_DIGEST_SIZE:
8842 + rctx->mode = RK_CRYPTO_HASH_SHA1;
8843 +@@ -220,32 +267,26 @@ static int rk_ahash_start(struct rk_crypto_info *dev)
8844 + rctx->mode = RK_CRYPTO_HASH_MD5;
8845 + break;
8846 + default:
8847 +- return -EINVAL;
8848 ++ err = -EINVAL;
8849 ++ goto theend;
8850 + }
8851 +
8852 +- rk_ahash_reg_init(dev);
8853 +- return rk_ahash_set_data_start(dev);
8854 +-}
8855 +-
8856 +-static int rk_ahash_crypto_rx(struct rk_crypto_info *dev)
8857 +-{
8858 +- int err = 0;
8859 +- struct ahash_request *req = ahash_request_cast(dev->async_req);
8860 +- struct crypto_ahash *tfm;
8861 +-
8862 +- dev->unload_data(dev);
8863 +- if (dev->left_bytes) {
8864 +- if (dev->aligned) {
8865 +- if (sg_is_last(dev->sg_src)) {
8866 +- dev_warn(dev->dev, "[%s:%d], Lack of data\n",
8867 +- __func__, __LINE__);
8868 +- err = -ENOMEM;
8869 +- goto out_rx;
8870 +- }
8871 +- dev->sg_src = sg_next(dev->sg_src);
8872 ++ rk_ahash_reg_init(areq);
8873 ++
8874 ++ while (sg) {
8875 ++ reinit_completion(&tctx->dev->complete);
8876 ++ tctx->dev->status = 0;
8877 ++ crypto_ahash_dma_start(tctx->dev, sg);
8878 ++ wait_for_completion_interruptible_timeout(&tctx->dev->complete,
8879 ++ msecs_to_jiffies(2000));
8880 ++ if (!tctx->dev->status) {
8881 ++ dev_err(tctx->dev->dev, "DMA timeout\n");
8882 ++ err = -EFAULT;
8883 ++ goto theend;
8884 + }
8885 +- err = rk_ahash_set_data_start(dev);
8886 +- } else {
8887 ++ sg = sg_next(sg);
8888 ++ }
8889 ++
8890 + /*
8891 + * it will take some time to process date after last dma
8892 + * transmission.
8893 +@@ -256,18 +297,20 @@ static int rk_ahash_crypto_rx(struct rk_crypto_info *dev)
8894 + * efficiency, and make it response quickly when dma
8895 + * complete.
8896 + */
8897 +- while (!CRYPTO_READ(dev, RK_CRYPTO_HASH_STS))
8898 +- udelay(10);
8899 +-
8900 +- tfm = crypto_ahash_reqtfm(req);
8901 +- memcpy_fromio(req->result, dev->reg + RK_CRYPTO_HASH_DOUT_0,
8902 +- crypto_ahash_digestsize(tfm));
8903 +- dev->complete(dev->async_req, 0);
8904 +- tasklet_schedule(&dev->queue_task);
8905 ++ while (!CRYPTO_READ(tctx->dev, RK_CRYPTO_HASH_STS))
8906 ++ udelay(10);
8907 ++
8908 ++ for (i = 0; i < crypto_ahash_digestsize(tfm) / 4; i++) {
8909 ++ v = readl(tctx->dev->reg + RK_CRYPTO_HASH_DOUT_0 + i * 4);
8910 ++ put_unaligned_le32(v, areq->result + i * 4);
8911 + }
8912 +
8913 +-out_rx:
8914 +- return err;
8915 ++theend:
8916 ++ local_bh_disable();
8917 ++ crypto_finalize_hash_request(engine, breq, err);
8918 ++ local_bh_enable();
8919 ++
8920 ++ return 0;
8921 + }
8922 +
8923 + static int rk_cra_hash_init(struct crypto_tfm *tfm)
8924 +@@ -281,14 +324,6 @@ static int rk_cra_hash_init(struct crypto_tfm *tfm)
8925 + algt = container_of(alg, struct rk_crypto_tmp, alg.hash);
8926 +
8927 + tctx->dev = algt->dev;
8928 +- tctx->dev->addr_vir = (void *)__get_free_page(GFP_KERNEL);
8929 +- if (!tctx->dev->addr_vir) {
8930 +- dev_err(tctx->dev->dev, "failed to kmalloc for addr_vir\n");
8931 +- return -ENOMEM;
8932 +- }
8933 +- tctx->dev->start = rk_ahash_start;
8934 +- tctx->dev->update = rk_ahash_crypto_rx;
8935 +- tctx->dev->complete = rk_ahash_crypto_complete;
8936 +
8937 + /* for fallback */
8938 + tctx->fallback_tfm = crypto_alloc_ahash(alg_name, 0,
8939 +@@ -297,19 +332,23 @@ static int rk_cra_hash_init(struct crypto_tfm *tfm)
8940 + dev_err(tctx->dev->dev, "Could not load fallback driver.\n");
8941 + return PTR_ERR(tctx->fallback_tfm);
8942 + }
8943 ++
8944 + crypto_ahash_set_reqsize(__crypto_ahash_cast(tfm),
8945 + sizeof(struct rk_ahash_rctx) +
8946 + crypto_ahash_reqsize(tctx->fallback_tfm));
8947 +
8948 +- return tctx->dev->enable_clk(tctx->dev);
8949 ++ tctx->enginectx.op.do_one_request = rk_hash_run;
8950 ++ tctx->enginectx.op.prepare_request = rk_hash_prepare;
8951 ++ tctx->enginectx.op.unprepare_request = rk_hash_unprepare;
8952 ++
8953 ++ return 0;
8954 + }
8955 +
8956 + static void rk_cra_hash_exit(struct crypto_tfm *tfm)
8957 + {
8958 + struct rk_ahash_ctx *tctx = crypto_tfm_ctx(tfm);
8959 +
8960 +- free_page((unsigned long)tctx->dev->addr_vir);
8961 +- return tctx->dev->disable_clk(tctx->dev);
8962 ++ crypto_free_ahash(tctx->fallback_tfm);
8963 + }
8964 +
8965 + struct rk_crypto_tmp rk_ahash_sha1 = {
8966 +diff --git a/drivers/crypto/rockchip/rk3288_crypto_skcipher.c b/drivers/crypto/rockchip/rk3288_crypto_skcipher.c
8967 +index 5bbf0d2722e11..67a7e05d5ae31 100644
8968 +--- a/drivers/crypto/rockchip/rk3288_crypto_skcipher.c
8969 ++++ b/drivers/crypto/rockchip/rk3288_crypto_skcipher.c
8970 +@@ -9,23 +9,77 @@
8971 + * Some ideas are from marvell-cesa.c and s5p-sss.c driver.
8972 + */
8973 + #include <linux/device.h>
8974 ++#include <crypto/scatterwalk.h>
8975 + #include "rk3288_crypto.h"
8976 +
8977 + #define RK_CRYPTO_DEC BIT(0)
8978 +
8979 +-static void rk_crypto_complete(struct crypto_async_request *base, int err)
8980 ++static int rk_cipher_need_fallback(struct skcipher_request *req)
8981 + {
8982 +- if (base->complete)
8983 +- base->complete(base, err);
8984 ++ struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
8985 ++ unsigned int bs = crypto_skcipher_blocksize(tfm);
8986 ++ struct scatterlist *sgs, *sgd;
8987 ++ unsigned int stodo, dtodo, len;
8988 ++
8989 ++ if (!req->cryptlen)
8990 ++ return true;
8991 ++
8992 ++ len = req->cryptlen;
8993 ++ sgs = req->src;
8994 ++ sgd = req->dst;
8995 ++ while (sgs && sgd) {
8996 ++ if (!IS_ALIGNED(sgs->offset, sizeof(u32))) {
8997 ++ return true;
8998 ++ }
8999 ++ if (!IS_ALIGNED(sgd->offset, sizeof(u32))) {
9000 ++ return true;
9001 ++ }
9002 ++ stodo = min(len, sgs->length);
9003 ++ if (stodo % bs) {
9004 ++ return true;
9005 ++ }
9006 ++ dtodo = min(len, sgd->length);
9007 ++ if (dtodo % bs) {
9008 ++ return true;
9009 ++ }
9010 ++ if (stodo != dtodo) {
9011 ++ return true;
9012 ++ }
9013 ++ len -= stodo;
9014 ++ sgs = sg_next(sgs);
9015 ++ sgd = sg_next(sgd);
9016 ++ }
9017 ++ return false;
9018 ++}
9019 ++
9020 ++static int rk_cipher_fallback(struct skcipher_request *areq)
9021 ++{
9022 ++ struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(areq);
9023 ++ struct rk_cipher_ctx *op = crypto_skcipher_ctx(tfm);
9024 ++ struct rk_cipher_rctx *rctx = skcipher_request_ctx(areq);
9025 ++ int err;
9026 ++
9027 ++ skcipher_request_set_tfm(&rctx->fallback_req, op->fallback_tfm);
9028 ++ skcipher_request_set_callback(&rctx->fallback_req, areq->base.flags,
9029 ++ areq->base.complete, areq->base.data);
9030 ++ skcipher_request_set_crypt(&rctx->fallback_req, areq->src, areq->dst,
9031 ++ areq->cryptlen, areq->iv);
9032 ++ if (rctx->mode & RK_CRYPTO_DEC)
9033 ++ err = crypto_skcipher_decrypt(&rctx->fallback_req);
9034 ++ else
9035 ++ err = crypto_skcipher_encrypt(&rctx->fallback_req);
9036 ++ return err;
9037 + }
9038 +
9039 + static int rk_handle_req(struct rk_crypto_info *dev,
9040 + struct skcipher_request *req)
9041 + {
9042 +- if (!IS_ALIGNED(req->cryptlen, dev->align_size))
9043 +- return -EINVAL;
9044 +- else
9045 +- return dev->enqueue(dev, &req->base);
9046 ++ struct crypto_engine *engine = dev->engine;
9047 ++
9048 ++ if (rk_cipher_need_fallback(req))
9049 ++ return rk_cipher_fallback(req);
9050 ++
9051 ++ return crypto_transfer_skcipher_request_to_engine(engine, req);
9052 + }
9053 +
9054 + static int rk_aes_setkey(struct crypto_skcipher *cipher,
9055 +@@ -38,8 +92,9 @@ static int rk_aes_setkey(struct crypto_skcipher *cipher,
9056 + keylen != AES_KEYSIZE_256)
9057 + return -EINVAL;
9058 + ctx->keylen = keylen;
9059 +- memcpy_toio(ctx->dev->reg + RK_CRYPTO_AES_KEY_0, key, keylen);
9060 +- return 0;
9061 ++ memcpy(ctx->key, key, keylen);
9062 ++
9063 ++ return crypto_skcipher_setkey(ctx->fallback_tfm, key, keylen);
9064 + }
9065 +
9066 + static int rk_des_setkey(struct crypto_skcipher *cipher,
9067 +@@ -53,8 +108,9 @@ static int rk_des_setkey(struct crypto_skcipher *cipher,
9068 + return err;
9069 +
9070 + ctx->keylen = keylen;
9071 +- memcpy_toio(ctx->dev->reg + RK_CRYPTO_TDES_KEY1_0, key, keylen);
9072 +- return 0;
9073 ++ memcpy(ctx->key, key, keylen);
9074 ++
9075 ++ return crypto_skcipher_setkey(ctx->fallback_tfm, key, keylen);
9076 + }
9077 +
9078 + static int rk_tdes_setkey(struct crypto_skcipher *cipher,
9079 +@@ -68,17 +124,19 @@ static int rk_tdes_setkey(struct crypto_skcipher *cipher,
9080 + return err;
9081 +
9082 + ctx->keylen = keylen;
9083 +- memcpy_toio(ctx->dev->reg + RK_CRYPTO_TDES_KEY1_0, key, keylen);
9084 +- return 0;
9085 ++ memcpy(ctx->key, key, keylen);
9086 ++
9087 ++ return crypto_skcipher_setkey(ctx->fallback_tfm, key, keylen);
9088 + }
9089 +
9090 + static int rk_aes_ecb_encrypt(struct skcipher_request *req)
9091 + {
9092 + struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
9093 + struct rk_cipher_ctx *ctx = crypto_skcipher_ctx(tfm);
9094 ++ struct rk_cipher_rctx *rctx = skcipher_request_ctx(req);
9095 + struct rk_crypto_info *dev = ctx->dev;
9096 +
9097 +- ctx->mode = RK_CRYPTO_AES_ECB_MODE;
9098 ++ rctx->mode = RK_CRYPTO_AES_ECB_MODE;
9099 + return rk_handle_req(dev, req);
9100 + }
9101 +
9102 +@@ -86,9 +144,10 @@ static int rk_aes_ecb_decrypt(struct skcipher_request *req)
9103 + {
9104 + struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
9105 + struct rk_cipher_ctx *ctx = crypto_skcipher_ctx(tfm);
9106 ++ struct rk_cipher_rctx *rctx = skcipher_request_ctx(req);
9107 + struct rk_crypto_info *dev = ctx->dev;
9108 +
9109 +- ctx->mode = RK_CRYPTO_AES_ECB_MODE | RK_CRYPTO_DEC;
9110 ++ rctx->mode = RK_CRYPTO_AES_ECB_MODE | RK_CRYPTO_DEC;
9111 + return rk_handle_req(dev, req);
9112 + }
9113 +
9114 +@@ -96,9 +155,10 @@ static int rk_aes_cbc_encrypt(struct skcipher_request *req)
9115 + {
9116 + struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
9117 + struct rk_cipher_ctx *ctx = crypto_skcipher_ctx(tfm);
9118 ++ struct rk_cipher_rctx *rctx = skcipher_request_ctx(req);
9119 + struct rk_crypto_info *dev = ctx->dev;
9120 +
9121 +- ctx->mode = RK_CRYPTO_AES_CBC_MODE;
9122 ++ rctx->mode = RK_CRYPTO_AES_CBC_MODE;
9123 + return rk_handle_req(dev, req);
9124 + }
9125 +
9126 +@@ -106,9 +166,10 @@ static int rk_aes_cbc_decrypt(struct skcipher_request *req)
9127 + {
9128 + struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
9129 + struct rk_cipher_ctx *ctx = crypto_skcipher_ctx(tfm);
9130 ++ struct rk_cipher_rctx *rctx = skcipher_request_ctx(req);
9131 + struct rk_crypto_info *dev = ctx->dev;
9132 +
9133 +- ctx->mode = RK_CRYPTO_AES_CBC_MODE | RK_CRYPTO_DEC;
9134 ++ rctx->mode = RK_CRYPTO_AES_CBC_MODE | RK_CRYPTO_DEC;
9135 + return rk_handle_req(dev, req);
9136 + }
9137 +
9138 +@@ -116,9 +177,10 @@ static int rk_des_ecb_encrypt(struct skcipher_request *req)
9139 + {
9140 + struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
9141 + struct rk_cipher_ctx *ctx = crypto_skcipher_ctx(tfm);
9142 ++ struct rk_cipher_rctx *rctx = skcipher_request_ctx(req);
9143 + struct rk_crypto_info *dev = ctx->dev;
9144 +
9145 +- ctx->mode = 0;
9146 ++ rctx->mode = 0;
9147 + return rk_handle_req(dev, req);
9148 + }
9149 +
9150 +@@ -126,9 +188,10 @@ static int rk_des_ecb_decrypt(struct skcipher_request *req)
9151 + {
9152 + struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
9153 + struct rk_cipher_ctx *ctx = crypto_skcipher_ctx(tfm);
9154 ++ struct rk_cipher_rctx *rctx = skcipher_request_ctx(req);
9155 + struct rk_crypto_info *dev = ctx->dev;
9156 +
9157 +- ctx->mode = RK_CRYPTO_DEC;
9158 ++ rctx->mode = RK_CRYPTO_DEC;
9159 + return rk_handle_req(dev, req);
9160 + }
9161 +
9162 +@@ -136,9 +199,10 @@ static int rk_des_cbc_encrypt(struct skcipher_request *req)
9163 + {
9164 + struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
9165 + struct rk_cipher_ctx *ctx = crypto_skcipher_ctx(tfm);
9166 ++ struct rk_cipher_rctx *rctx = skcipher_request_ctx(req);
9167 + struct rk_crypto_info *dev = ctx->dev;
9168 +
9169 +- ctx->mode = RK_CRYPTO_TDES_CHAINMODE_CBC;
9170 ++ rctx->mode = RK_CRYPTO_TDES_CHAINMODE_CBC;
9171 + return rk_handle_req(dev, req);
9172 + }
9173 +
9174 +@@ -146,9 +210,10 @@ static int rk_des_cbc_decrypt(struct skcipher_request *req)
9175 + {
9176 + struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
9177 + struct rk_cipher_ctx *ctx = crypto_skcipher_ctx(tfm);
9178 ++ struct rk_cipher_rctx *rctx = skcipher_request_ctx(req);
9179 + struct rk_crypto_info *dev = ctx->dev;
9180 +
9181 +- ctx->mode = RK_CRYPTO_TDES_CHAINMODE_CBC | RK_CRYPTO_DEC;
9182 ++ rctx->mode = RK_CRYPTO_TDES_CHAINMODE_CBC | RK_CRYPTO_DEC;
9183 + return rk_handle_req(dev, req);
9184 + }
9185 +
9186 +@@ -156,9 +221,10 @@ static int rk_des3_ede_ecb_encrypt(struct skcipher_request *req)
9187 + {
9188 + struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
9189 + struct rk_cipher_ctx *ctx = crypto_skcipher_ctx(tfm);
9190 ++ struct rk_cipher_rctx *rctx = skcipher_request_ctx(req);
9191 + struct rk_crypto_info *dev = ctx->dev;
9192 +
9193 +- ctx->mode = RK_CRYPTO_TDES_SELECT;
9194 ++ rctx->mode = RK_CRYPTO_TDES_SELECT;
9195 + return rk_handle_req(dev, req);
9196 + }
9197 +
9198 +@@ -166,9 +232,10 @@ static int rk_des3_ede_ecb_decrypt(struct skcipher_request *req)
9199 + {
9200 + struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
9201 + struct rk_cipher_ctx *ctx = crypto_skcipher_ctx(tfm);
9202 ++ struct rk_cipher_rctx *rctx = skcipher_request_ctx(req);
9203 + struct rk_crypto_info *dev = ctx->dev;
9204 +
9205 +- ctx->mode = RK_CRYPTO_TDES_SELECT | RK_CRYPTO_DEC;
9206 ++ rctx->mode = RK_CRYPTO_TDES_SELECT | RK_CRYPTO_DEC;
9207 + return rk_handle_req(dev, req);
9208 + }
9209 +
9210 +@@ -176,9 +243,10 @@ static int rk_des3_ede_cbc_encrypt(struct skcipher_request *req)
9211 + {
9212 + struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
9213 + struct rk_cipher_ctx *ctx = crypto_skcipher_ctx(tfm);
9214 ++ struct rk_cipher_rctx *rctx = skcipher_request_ctx(req);
9215 + struct rk_crypto_info *dev = ctx->dev;
9216 +
9217 +- ctx->mode = RK_CRYPTO_TDES_SELECT | RK_CRYPTO_TDES_CHAINMODE_CBC;
9218 ++ rctx->mode = RK_CRYPTO_TDES_SELECT | RK_CRYPTO_TDES_CHAINMODE_CBC;
9219 + return rk_handle_req(dev, req);
9220 + }
9221 +
9222 +@@ -186,43 +254,42 @@ static int rk_des3_ede_cbc_decrypt(struct skcipher_request *req)
9223 + {
9224 + struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
9225 + struct rk_cipher_ctx *ctx = crypto_skcipher_ctx(tfm);
9226 ++ struct rk_cipher_rctx *rctx = skcipher_request_ctx(req);
9227 + struct rk_crypto_info *dev = ctx->dev;
9228 +
9229 +- ctx->mode = RK_CRYPTO_TDES_SELECT | RK_CRYPTO_TDES_CHAINMODE_CBC |
9230 ++ rctx->mode = RK_CRYPTO_TDES_SELECT | RK_CRYPTO_TDES_CHAINMODE_CBC |
9231 + RK_CRYPTO_DEC;
9232 + return rk_handle_req(dev, req);
9233 + }
9234 +
9235 +-static void rk_ablk_hw_init(struct rk_crypto_info *dev)
9236 ++static void rk_ablk_hw_init(struct rk_crypto_info *dev, struct skcipher_request *req)
9237 + {
9238 +- struct skcipher_request *req =
9239 +- skcipher_request_cast(dev->async_req);
9240 + struct crypto_skcipher *cipher = crypto_skcipher_reqtfm(req);
9241 + struct crypto_tfm *tfm = crypto_skcipher_tfm(cipher);
9242 ++ struct rk_cipher_rctx *rctx = skcipher_request_ctx(req);
9243 + struct rk_cipher_ctx *ctx = crypto_skcipher_ctx(cipher);
9244 +- u32 ivsize, block, conf_reg = 0;
9245 ++ u32 block, conf_reg = 0;
9246 +
9247 + block = crypto_tfm_alg_blocksize(tfm);
9248 +- ivsize = crypto_skcipher_ivsize(cipher);
9249 +
9250 + if (block == DES_BLOCK_SIZE) {
9251 +- ctx->mode |= RK_CRYPTO_TDES_FIFO_MODE |
9252 ++ rctx->mode |= RK_CRYPTO_TDES_FIFO_MODE |
9253 + RK_CRYPTO_TDES_BYTESWAP_KEY |
9254 + RK_CRYPTO_TDES_BYTESWAP_IV;
9255 +- CRYPTO_WRITE(dev, RK_CRYPTO_TDES_CTRL, ctx->mode);
9256 +- memcpy_toio(dev->reg + RK_CRYPTO_TDES_IV_0, req->iv, ivsize);
9257 ++ CRYPTO_WRITE(dev, RK_CRYPTO_TDES_CTRL, rctx->mode);
9258 ++ memcpy_toio(ctx->dev->reg + RK_CRYPTO_TDES_KEY1_0, ctx->key, ctx->keylen);
9259 + conf_reg = RK_CRYPTO_DESSEL;
9260 + } else {
9261 +- ctx->mode |= RK_CRYPTO_AES_FIFO_MODE |
9262 ++ rctx->mode |= RK_CRYPTO_AES_FIFO_MODE |
9263 + RK_CRYPTO_AES_KEY_CHANGE |
9264 + RK_CRYPTO_AES_BYTESWAP_KEY |
9265 + RK_CRYPTO_AES_BYTESWAP_IV;
9266 + if (ctx->keylen == AES_KEYSIZE_192)
9267 +- ctx->mode |= RK_CRYPTO_AES_192BIT_key;
9268 ++ rctx->mode |= RK_CRYPTO_AES_192BIT_key;
9269 + else if (ctx->keylen == AES_KEYSIZE_256)
9270 +- ctx->mode |= RK_CRYPTO_AES_256BIT_key;
9271 +- CRYPTO_WRITE(dev, RK_CRYPTO_AES_CTRL, ctx->mode);
9272 +- memcpy_toio(dev->reg + RK_CRYPTO_AES_IV_0, req->iv, ivsize);
9273 ++ rctx->mode |= RK_CRYPTO_AES_256BIT_key;
9274 ++ CRYPTO_WRITE(dev, RK_CRYPTO_AES_CTRL, rctx->mode);
9275 ++ memcpy_toio(ctx->dev->reg + RK_CRYPTO_AES_KEY_0, ctx->key, ctx->keylen);
9276 + }
9277 + conf_reg |= RK_CRYPTO_BYTESWAP_BTFIFO |
9278 + RK_CRYPTO_BYTESWAP_BRFIFO;
9279 +@@ -231,146 +298,138 @@ static void rk_ablk_hw_init(struct rk_crypto_info *dev)
9280 + RK_CRYPTO_BCDMA_ERR_ENA | RK_CRYPTO_BCDMA_DONE_ENA);
9281 + }
9282 +
9283 +-static void crypto_dma_start(struct rk_crypto_info *dev)
9284 ++static void crypto_dma_start(struct rk_crypto_info *dev,
9285 ++ struct scatterlist *sgs,
9286 ++ struct scatterlist *sgd, unsigned int todo)
9287 + {
9288 +- CRYPTO_WRITE(dev, RK_CRYPTO_BRDMAS, dev->addr_in);
9289 +- CRYPTO_WRITE(dev, RK_CRYPTO_BRDMAL, dev->count / 4);
9290 +- CRYPTO_WRITE(dev, RK_CRYPTO_BTDMAS, dev->addr_out);
9291 ++ CRYPTO_WRITE(dev, RK_CRYPTO_BRDMAS, sg_dma_address(sgs));
9292 ++ CRYPTO_WRITE(dev, RK_CRYPTO_BRDMAL, todo);
9293 ++ CRYPTO_WRITE(dev, RK_CRYPTO_BTDMAS, sg_dma_address(sgd));
9294 + CRYPTO_WRITE(dev, RK_CRYPTO_CTRL, RK_CRYPTO_BLOCK_START |
9295 + _SBF(RK_CRYPTO_BLOCK_START, 16));
9296 + }
9297 +
9298 +-static int rk_set_data_start(struct rk_crypto_info *dev)
9299 ++static int rk_cipher_run(struct crypto_engine *engine, void *async_req)
9300 + {
9301 +- int err;
9302 +- struct skcipher_request *req =
9303 +- skcipher_request_cast(dev->async_req);
9304 +- struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
9305 ++ struct skcipher_request *areq = container_of(async_req, struct skcipher_request, base);
9306 ++ struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(areq);
9307 + struct rk_cipher_ctx *ctx = crypto_skcipher_ctx(tfm);
9308 +- u32 ivsize = crypto_skcipher_ivsize(tfm);
9309 +- u8 *src_last_blk = page_address(sg_page(dev->sg_src)) +
9310 +- dev->sg_src->offset + dev->sg_src->length - ivsize;
9311 +-
9312 +- /* Store the iv that need to be updated in chain mode.
9313 +- * And update the IV buffer to contain the next IV for decryption mode.
9314 +- */
9315 +- if (ctx->mode & RK_CRYPTO_DEC) {
9316 +- memcpy(ctx->iv, src_last_blk, ivsize);
9317 +- sg_pcopy_to_buffer(dev->first, dev->src_nents, req->iv,
9318 +- ivsize, dev->total - ivsize);
9319 +- }
9320 +-
9321 +- err = dev->load_data(dev, dev->sg_src, dev->sg_dst);
9322 +- if (!err)
9323 +- crypto_dma_start(dev);
9324 +- return err;
9325 +-}
9326 +-
9327 +-static int rk_ablk_start(struct rk_crypto_info *dev)
9328 +-{
9329 +- struct skcipher_request *req =
9330 +- skcipher_request_cast(dev->async_req);
9331 +- unsigned long flags;
9332 ++ struct rk_cipher_rctx *rctx = skcipher_request_ctx(areq);
9333 ++ struct scatterlist *sgs, *sgd;
9334 + int err = 0;
9335 ++ int ivsize = crypto_skcipher_ivsize(tfm);
9336 ++ int offset;
9337 ++ u8 iv[AES_BLOCK_SIZE];
9338 ++ u8 biv[AES_BLOCK_SIZE];
9339 ++ u8 *ivtouse = areq->iv;
9340 ++ unsigned int len = areq->cryptlen;
9341 ++ unsigned int todo;
9342 ++
9343 ++ ivsize = crypto_skcipher_ivsize(tfm);
9344 ++ if (areq->iv && crypto_skcipher_ivsize(tfm) > 0) {
9345 ++ if (rctx->mode & RK_CRYPTO_DEC) {
9346 ++ offset = areq->cryptlen - ivsize;
9347 ++ scatterwalk_map_and_copy(rctx->backup_iv, areq->src,
9348 ++ offset, ivsize, 0);
9349 ++ }
9350 ++ }
9351 +
9352 +- dev->left_bytes = req->cryptlen;
9353 +- dev->total = req->cryptlen;
9354 +- dev->sg_src = req->src;
9355 +- dev->first = req->src;
9356 +- dev->src_nents = sg_nents(req->src);
9357 +- dev->sg_dst = req->dst;
9358 +- dev->dst_nents = sg_nents(req->dst);
9359 +- dev->aligned = 1;
9360 +-
9361 +- spin_lock_irqsave(&dev->lock, flags);
9362 +- rk_ablk_hw_init(dev);
9363 +- err = rk_set_data_start(dev);
9364 +- spin_unlock_irqrestore(&dev->lock, flags);
9365 +- return err;
9366 +-}
9367 ++ sgs = areq->src;
9368 ++ sgd = areq->dst;
9369 +
9370 +-static void rk_iv_copyback(struct rk_crypto_info *dev)
9371 +-{
9372 +- struct skcipher_request *req =
9373 +- skcipher_request_cast(dev->async_req);
9374 +- struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
9375 +- struct rk_cipher_ctx *ctx = crypto_skcipher_ctx(tfm);
9376 +- u32 ivsize = crypto_skcipher_ivsize(tfm);
9377 +-
9378 +- /* Update the IV buffer to contain the next IV for encryption mode. */
9379 +- if (!(ctx->mode & RK_CRYPTO_DEC)) {
9380 +- if (dev->aligned) {
9381 +- memcpy(req->iv, sg_virt(dev->sg_dst) +
9382 +- dev->sg_dst->length - ivsize, ivsize);
9383 ++ while (sgs && sgd && len) {
9384 ++ if (!sgs->length) {
9385 ++ sgs = sg_next(sgs);
9386 ++ sgd = sg_next(sgd);
9387 ++ continue;
9388 ++ }
9389 ++ if (rctx->mode & RK_CRYPTO_DEC) {
9390 ++ /* we backup last block of source to be used as IV at next step */
9391 ++ offset = sgs->length - ivsize;
9392 ++ scatterwalk_map_and_copy(biv, sgs, offset, ivsize, 0);
9393 ++ }
9394 ++ if (sgs == sgd) {
9395 ++ err = dma_map_sg(ctx->dev->dev, sgs, 1, DMA_BIDIRECTIONAL);
9396 ++ if (err <= 0) {
9397 ++ err = -EINVAL;
9398 ++ goto theend_iv;
9399 ++ }
9400 ++ } else {
9401 ++ err = dma_map_sg(ctx->dev->dev, sgs, 1, DMA_TO_DEVICE);
9402 ++ if (err <= 0) {
9403 ++ err = -EINVAL;
9404 ++ goto theend_iv;
9405 ++ }
9406 ++ err = dma_map_sg(ctx->dev->dev, sgd, 1, DMA_FROM_DEVICE);
9407 ++ if (err <= 0) {
9408 ++ err = -EINVAL;
9409 ++ goto theend_sgs;
9410 ++ }
9411 ++ }
9412 ++ err = 0;
9413 ++ rk_ablk_hw_init(ctx->dev, areq);
9414 ++ if (ivsize) {
9415 ++ if (ivsize == DES_BLOCK_SIZE)
9416 ++ memcpy_toio(ctx->dev->reg + RK_CRYPTO_TDES_IV_0, ivtouse, ivsize);
9417 ++ else
9418 ++ memcpy_toio(ctx->dev->reg + RK_CRYPTO_AES_IV_0, ivtouse, ivsize);
9419 ++ }
9420 ++ reinit_completion(&ctx->dev->complete);
9421 ++ ctx->dev->status = 0;
9422 ++
9423 ++ todo = min(sg_dma_len(sgs), len);
9424 ++ len -= todo;
9425 ++ crypto_dma_start(ctx->dev, sgs, sgd, todo / 4);
9426 ++ wait_for_completion_interruptible_timeout(&ctx->dev->complete,
9427 ++ msecs_to_jiffies(2000));
9428 ++ if (!ctx->dev->status) {
9429 ++ dev_err(ctx->dev->dev, "DMA timeout\n");
9430 ++ err = -EFAULT;
9431 ++ goto theend;
9432 ++ }
9433 ++ if (sgs == sgd) {
9434 ++ dma_unmap_sg(ctx->dev->dev, sgs, 1, DMA_BIDIRECTIONAL);
9435 ++ } else {
9436 ++ dma_unmap_sg(ctx->dev->dev, sgs, 1, DMA_TO_DEVICE);
9437 ++ dma_unmap_sg(ctx->dev->dev, sgd, 1, DMA_FROM_DEVICE);
9438 ++ }
9439 ++ if (rctx->mode & RK_CRYPTO_DEC) {
9440 ++ memcpy(iv, biv, ivsize);
9441 ++ ivtouse = iv;
9442 + } else {
9443 +- memcpy(req->iv, dev->addr_vir +
9444 +- dev->count - ivsize, ivsize);
9445 ++ offset = sgd->length - ivsize;
9446 ++ scatterwalk_map_and_copy(iv, sgd, offset, ivsize, 0);
9447 ++ ivtouse = iv;
9448 + }
9449 ++ sgs = sg_next(sgs);
9450 ++ sgd = sg_next(sgd);
9451 + }
9452 +-}
9453 +-
9454 +-static void rk_update_iv(struct rk_crypto_info *dev)
9455 +-{
9456 +- struct skcipher_request *req =
9457 +- skcipher_request_cast(dev->async_req);
9458 +- struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
9459 +- struct rk_cipher_ctx *ctx = crypto_skcipher_ctx(tfm);
9460 +- u32 ivsize = crypto_skcipher_ivsize(tfm);
9461 +- u8 *new_iv = NULL;
9462 +
9463 +- if (ctx->mode & RK_CRYPTO_DEC) {
9464 +- new_iv = ctx->iv;
9465 +- } else {
9466 +- new_iv = page_address(sg_page(dev->sg_dst)) +
9467 +- dev->sg_dst->offset + dev->sg_dst->length - ivsize;
9468 ++ if (areq->iv && ivsize > 0) {
9469 ++ offset = areq->cryptlen - ivsize;
9470 ++ if (rctx->mode & RK_CRYPTO_DEC) {
9471 ++ memcpy(areq->iv, rctx->backup_iv, ivsize);
9472 ++ memzero_explicit(rctx->backup_iv, ivsize);
9473 ++ } else {
9474 ++ scatterwalk_map_and_copy(areq->iv, areq->dst, offset,
9475 ++ ivsize, 0);
9476 ++ }
9477 + }
9478 +
9479 +- if (ivsize == DES_BLOCK_SIZE)
9480 +- memcpy_toio(dev->reg + RK_CRYPTO_TDES_IV_0, new_iv, ivsize);
9481 +- else if (ivsize == AES_BLOCK_SIZE)
9482 +- memcpy_toio(dev->reg + RK_CRYPTO_AES_IV_0, new_iv, ivsize);
9483 +-}
9484 ++theend:
9485 ++ local_bh_disable();
9486 ++ crypto_finalize_skcipher_request(engine, areq, err);
9487 ++ local_bh_enable();
9488 ++ return 0;
9489 +
9490 +-/* return:
9491 +- * true some err was occurred
9492 +- * fault no err, continue
9493 +- */
9494 +-static int rk_ablk_rx(struct rk_crypto_info *dev)
9495 +-{
9496 +- int err = 0;
9497 +- struct skcipher_request *req =
9498 +- skcipher_request_cast(dev->async_req);
9499 +-
9500 +- dev->unload_data(dev);
9501 +- if (!dev->aligned) {
9502 +- if (!sg_pcopy_from_buffer(req->dst, dev->dst_nents,
9503 +- dev->addr_vir, dev->count,
9504 +- dev->total - dev->left_bytes -
9505 +- dev->count)) {
9506 +- err = -EINVAL;
9507 +- goto out_rx;
9508 +- }
9509 +- }
9510 +- if (dev->left_bytes) {
9511 +- rk_update_iv(dev);
9512 +- if (dev->aligned) {
9513 +- if (sg_is_last(dev->sg_src)) {
9514 +- dev_err(dev->dev, "[%s:%d] Lack of data\n",
9515 +- __func__, __LINE__);
9516 +- err = -ENOMEM;
9517 +- goto out_rx;
9518 +- }
9519 +- dev->sg_src = sg_next(dev->sg_src);
9520 +- dev->sg_dst = sg_next(dev->sg_dst);
9521 +- }
9522 +- err = rk_set_data_start(dev);
9523 ++theend_sgs:
9524 ++ if (sgs == sgd) {
9525 ++ dma_unmap_sg(ctx->dev->dev, sgs, 1, DMA_BIDIRECTIONAL);
9526 + } else {
9527 +- rk_iv_copyback(dev);
9528 +- /* here show the calculation is over without any err */
9529 +- dev->complete(dev->async_req, 0);
9530 +- tasklet_schedule(&dev->queue_task);
9531 ++ dma_unmap_sg(ctx->dev->dev, sgs, 1, DMA_TO_DEVICE);
9532 ++ dma_unmap_sg(ctx->dev->dev, sgd, 1, DMA_FROM_DEVICE);
9533 + }
9534 +-out_rx:
9535 ++theend_iv:
9536 + return err;
9537 + }
9538 +
9539 +@@ -378,26 +437,34 @@ static int rk_ablk_init_tfm(struct crypto_skcipher *tfm)
9540 + {
9541 + struct rk_cipher_ctx *ctx = crypto_skcipher_ctx(tfm);
9542 + struct skcipher_alg *alg = crypto_skcipher_alg(tfm);
9543 ++ const char *name = crypto_tfm_alg_name(&tfm->base);
9544 + struct rk_crypto_tmp *algt;
9545 +
9546 + algt = container_of(alg, struct rk_crypto_tmp, alg.skcipher);
9547 +
9548 + ctx->dev = algt->dev;
9549 +- ctx->dev->align_size = crypto_tfm_alg_alignmask(crypto_skcipher_tfm(tfm)) + 1;
9550 +- ctx->dev->start = rk_ablk_start;
9551 +- ctx->dev->update = rk_ablk_rx;
9552 +- ctx->dev->complete = rk_crypto_complete;
9553 +- ctx->dev->addr_vir = (char *)__get_free_page(GFP_KERNEL);
9554 +
9555 +- return ctx->dev->addr_vir ? ctx->dev->enable_clk(ctx->dev) : -ENOMEM;
9556 ++ ctx->fallback_tfm = crypto_alloc_skcipher(name, 0, CRYPTO_ALG_NEED_FALLBACK);
9557 ++ if (IS_ERR(ctx->fallback_tfm)) {
9558 ++ dev_err(ctx->dev->dev, "ERROR: Cannot allocate fallback for %s %ld\n",
9559 ++ name, PTR_ERR(ctx->fallback_tfm));
9560 ++ return PTR_ERR(ctx->fallback_tfm);
9561 ++ }
9562 ++
9563 ++ tfm->reqsize = sizeof(struct rk_cipher_rctx) +
9564 ++ crypto_skcipher_reqsize(ctx->fallback_tfm);
9565 ++
9566 ++ ctx->enginectx.op.do_one_request = rk_cipher_run;
9567 ++
9568 ++ return 0;
9569 + }
9570 +
9571 + static void rk_ablk_exit_tfm(struct crypto_skcipher *tfm)
9572 + {
9573 + struct rk_cipher_ctx *ctx = crypto_skcipher_ctx(tfm);
9574 +
9575 +- free_page((unsigned long)ctx->dev->addr_vir);
9576 +- ctx->dev->disable_clk(ctx->dev);
9577 ++ memzero_explicit(ctx->key, ctx->keylen);
9578 ++ crypto_free_skcipher(ctx->fallback_tfm);
9579 + }
9580 +
9581 + struct rk_crypto_tmp rk_ecb_aes_alg = {
9582 +@@ -406,7 +473,7 @@ struct rk_crypto_tmp rk_ecb_aes_alg = {
9583 + .base.cra_name = "ecb(aes)",
9584 + .base.cra_driver_name = "ecb-aes-rk",
9585 + .base.cra_priority = 300,
9586 +- .base.cra_flags = CRYPTO_ALG_ASYNC,
9587 ++ .base.cra_flags = CRYPTO_ALG_ASYNC | CRYPTO_ALG_NEED_FALLBACK,
9588 + .base.cra_blocksize = AES_BLOCK_SIZE,
9589 + .base.cra_ctxsize = sizeof(struct rk_cipher_ctx),
9590 + .base.cra_alignmask = 0x0f,
9591 +@@ -428,7 +495,7 @@ struct rk_crypto_tmp rk_cbc_aes_alg = {
9592 + .base.cra_name = "cbc(aes)",
9593 + .base.cra_driver_name = "cbc-aes-rk",
9594 + .base.cra_priority = 300,
9595 +- .base.cra_flags = CRYPTO_ALG_ASYNC,
9596 ++ .base.cra_flags = CRYPTO_ALG_ASYNC | CRYPTO_ALG_NEED_FALLBACK,
9597 + .base.cra_blocksize = AES_BLOCK_SIZE,
9598 + .base.cra_ctxsize = sizeof(struct rk_cipher_ctx),
9599 + .base.cra_alignmask = 0x0f,
9600 +@@ -451,7 +518,7 @@ struct rk_crypto_tmp rk_ecb_des_alg = {
9601 + .base.cra_name = "ecb(des)",
9602 + .base.cra_driver_name = "ecb-des-rk",
9603 + .base.cra_priority = 300,
9604 +- .base.cra_flags = CRYPTO_ALG_ASYNC,
9605 ++ .base.cra_flags = CRYPTO_ALG_ASYNC | CRYPTO_ALG_NEED_FALLBACK,
9606 + .base.cra_blocksize = DES_BLOCK_SIZE,
9607 + .base.cra_ctxsize = sizeof(struct rk_cipher_ctx),
9608 + .base.cra_alignmask = 0x07,
9609 +@@ -473,7 +540,7 @@ struct rk_crypto_tmp rk_cbc_des_alg = {
9610 + .base.cra_name = "cbc(des)",
9611 + .base.cra_driver_name = "cbc-des-rk",
9612 + .base.cra_priority = 300,
9613 +- .base.cra_flags = CRYPTO_ALG_ASYNC,
9614 ++ .base.cra_flags = CRYPTO_ALG_ASYNC | CRYPTO_ALG_NEED_FALLBACK,
9615 + .base.cra_blocksize = DES_BLOCK_SIZE,
9616 + .base.cra_ctxsize = sizeof(struct rk_cipher_ctx),
9617 + .base.cra_alignmask = 0x07,
9618 +@@ -496,7 +563,7 @@ struct rk_crypto_tmp rk_ecb_des3_ede_alg = {
9619 + .base.cra_name = "ecb(des3_ede)",
9620 + .base.cra_driver_name = "ecb-des3-ede-rk",
9621 + .base.cra_priority = 300,
9622 +- .base.cra_flags = CRYPTO_ALG_ASYNC,
9623 ++ .base.cra_flags = CRYPTO_ALG_ASYNC | CRYPTO_ALG_NEED_FALLBACK,
9624 + .base.cra_blocksize = DES_BLOCK_SIZE,
9625 + .base.cra_ctxsize = sizeof(struct rk_cipher_ctx),
9626 + .base.cra_alignmask = 0x07,
9627 +@@ -518,7 +585,7 @@ struct rk_crypto_tmp rk_cbc_des3_ede_alg = {
9628 + .base.cra_name = "cbc(des3_ede)",
9629 + .base.cra_driver_name = "cbc-des3-ede-rk",
9630 + .base.cra_priority = 300,
9631 +- .base.cra_flags = CRYPTO_ALG_ASYNC,
9632 ++ .base.cra_flags = CRYPTO_ALG_ASYNC | CRYPTO_ALG_NEED_FALLBACK,
9633 + .base.cra_blocksize = DES_BLOCK_SIZE,
9634 + .base.cra_ctxsize = sizeof(struct rk_cipher_ctx),
9635 + .base.cra_alignmask = 0x07,
9636 +diff --git a/drivers/dio/dio.c b/drivers/dio/dio.c
9637 +index 0e5a5662d5a40..0a051d6568800 100644
9638 +--- a/drivers/dio/dio.c
9639 ++++ b/drivers/dio/dio.c
9640 +@@ -109,6 +109,12 @@ static char dio_no_name[] = { 0 };
9641 +
9642 + #endif /* CONFIG_DIO_CONSTANTS */
9643 +
9644 ++static void dio_dev_release(struct device *dev)
9645 ++{
9646 ++ struct dio_dev *ddev = container_of(dev, typeof(struct dio_dev), dev);
9647 ++ kfree(ddev);
9648 ++}
9649 ++
9650 + int __init dio_find(int deviceid)
9651 + {
9652 + /* Called to find a DIO device before the full bus scan has run.
9653 +@@ -225,6 +231,7 @@ static int __init dio_init(void)
9654 + dev->bus = &dio_bus;
9655 + dev->dev.parent = &dio_bus.dev;
9656 + dev->dev.bus = &dio_bus_type;
9657 ++ dev->dev.release = dio_dev_release;
9658 + dev->scode = scode;
9659 + dev->resource.start = pa;
9660 + dev->resource.end = pa + DIO_SIZE(scode, va);
9661 +@@ -252,6 +259,7 @@ static int __init dio_init(void)
9662 + if (error) {
9663 + pr_err("DIO: Error registering device %s\n",
9664 + dev->name);
9665 ++ put_device(&dev->dev);
9666 + continue;
9667 + }
9668 + error = dio_create_sysfs_dev_files(dev);
9669 +diff --git a/drivers/dma/apple-admac.c b/drivers/dma/apple-admac.c
9670 +index 6780761a16403..e3334762be853 100644
9671 +--- a/drivers/dma/apple-admac.c
9672 ++++ b/drivers/dma/apple-admac.c
9673 +@@ -20,6 +20,12 @@
9674 + #define NCHANNELS_MAX 64
9675 + #define IRQ_NOUTPUTS 4
9676 +
9677 ++/*
9678 ++ * For allocation purposes we split the cache
9679 ++ * memory into blocks of fixed size (given in bytes).
9680 ++ */
9681 ++#define SRAM_BLOCK 2048
9682 ++
9683 + #define RING_WRITE_SLOT GENMASK(1, 0)
9684 + #define RING_READ_SLOT GENMASK(5, 4)
9685 + #define RING_FULL BIT(9)
9686 +@@ -35,6 +41,9 @@
9687 + #define REG_TX_STOP 0x0004
9688 + #define REG_RX_START 0x0008
9689 + #define REG_RX_STOP 0x000c
9690 ++#define REG_IMPRINT 0x0090
9691 ++#define REG_TX_SRAM_SIZE 0x0094
9692 ++#define REG_RX_SRAM_SIZE 0x0098
9693 +
9694 + #define REG_CHAN_CTL(ch) (0x8000 + (ch) * 0x200)
9695 + #define REG_CHAN_CTL_RST_RINGS BIT(0)
9696 +@@ -52,7 +61,9 @@
9697 + #define BUS_WIDTH_FRAME_2_WORDS 0x10
9698 + #define BUS_WIDTH_FRAME_4_WORDS 0x20
9699 +
9700 +-#define CHAN_BUFSIZE 0x8000
9701 ++#define REG_CHAN_SRAM_CARVEOUT(ch) (0x8050 + (ch) * 0x200)
9702 ++#define CHAN_SRAM_CARVEOUT_SIZE GENMASK(31, 16)
9703 ++#define CHAN_SRAM_CARVEOUT_BASE GENMASK(15, 0)
9704 +
9705 + #define REG_CHAN_FIFOCTL(ch) (0x8054 + (ch) * 0x200)
9706 + #define CHAN_FIFOCTL_LIMIT GENMASK(31, 16)
9707 +@@ -75,6 +86,8 @@ struct admac_chan {
9708 + struct dma_chan chan;
9709 + struct tasklet_struct tasklet;
9710 +
9711 ++ u32 carveout;
9712 ++
9713 + spinlock_t lock;
9714 + struct admac_tx *current_tx;
9715 + int nperiod_acks;
9716 +@@ -91,11 +104,24 @@ struct admac_chan {
9717 + struct list_head to_free;
9718 + };
9719 +
9720 ++struct admac_sram {
9721 ++ u32 size;
9722 ++ /*
9723 ++ * SRAM_CARVEOUT has 16-bit fields, so the SRAM cannot be larger than
9724 ++ * 64K and a 32-bit bitfield over 2K blocks covers it.
9725 ++ */
9726 ++ u32 allocated;
9727 ++};
9728 ++
9729 + struct admac_data {
9730 + struct dma_device dma;
9731 + struct device *dev;
9732 + __iomem void *base;
9733 +
9734 ++ struct mutex cache_alloc_lock;
9735 ++ struct admac_sram txcache, rxcache;
9736 ++
9737 ++ int irq;
9738 + int irq_index;
9739 + int nchannels;
9740 + struct admac_chan channels[];
9741 +@@ -115,6 +141,60 @@ struct admac_tx {
9742 + struct list_head node;
9743 + };
9744 +
9745 ++static int admac_alloc_sram_carveout(struct admac_data *ad,
9746 ++ enum dma_transfer_direction dir,
9747 ++ u32 *out)
9748 ++{
9749 ++ struct admac_sram *sram;
9750 ++ int i, ret = 0, nblocks;
9751 ++
9752 ++ if (dir == DMA_MEM_TO_DEV)
9753 ++ sram = &ad->txcache;
9754 ++ else
9755 ++ sram = &ad->rxcache;
9756 ++
9757 ++ mutex_lock(&ad->cache_alloc_lock);
9758 ++
9759 ++ nblocks = sram->size / SRAM_BLOCK;
9760 ++ for (i = 0; i < nblocks; i++)
9761 ++ if (!(sram->allocated & BIT(i)))
9762 ++ break;
9763 ++
9764 ++ if (i < nblocks) {
9765 ++ *out = FIELD_PREP(CHAN_SRAM_CARVEOUT_BASE, i * SRAM_BLOCK) |
9766 ++ FIELD_PREP(CHAN_SRAM_CARVEOUT_SIZE, SRAM_BLOCK);
9767 ++ sram->allocated |= BIT(i);
9768 ++ } else {
9769 ++ ret = -EBUSY;
9770 ++ }
9771 ++
9772 ++ mutex_unlock(&ad->cache_alloc_lock);
9773 ++
9774 ++ return ret;
9775 ++}
9776 ++
9777 ++static void admac_free_sram_carveout(struct admac_data *ad,
9778 ++ enum dma_transfer_direction dir,
9779 ++ u32 carveout)
9780 ++{
9781 ++ struct admac_sram *sram;
9782 ++ u32 base = FIELD_GET(CHAN_SRAM_CARVEOUT_BASE, carveout);
9783 ++ int i;
9784 ++
9785 ++ if (dir == DMA_MEM_TO_DEV)
9786 ++ sram = &ad->txcache;
9787 ++ else
9788 ++ sram = &ad->rxcache;
9789 ++
9790 ++ if (WARN_ON(base >= sram->size))
9791 ++ return;
9792 ++
9793 ++ mutex_lock(&ad->cache_alloc_lock);
9794 ++ i = base / SRAM_BLOCK;
9795 ++ sram->allocated &= ~BIT(i);
9796 ++ mutex_unlock(&ad->cache_alloc_lock);
9797 ++}
9798 ++
9799 + static void admac_modify(struct admac_data *ad, int reg, u32 mask, u32 val)
9800 + {
9801 + void __iomem *addr = ad->base + reg;
9802 +@@ -463,15 +543,28 @@ static void admac_synchronize(struct dma_chan *chan)
9803 + static int admac_alloc_chan_resources(struct dma_chan *chan)
9804 + {
9805 + struct admac_chan *adchan = to_admac_chan(chan);
9806 ++ struct admac_data *ad = adchan->host;
9807 ++ int ret;
9808 +
9809 + dma_cookie_init(&adchan->chan);
9810 ++ ret = admac_alloc_sram_carveout(ad, admac_chan_direction(adchan->no),
9811 ++ &adchan->carveout);
9812 ++ if (ret < 0)
9813 ++ return ret;
9814 ++
9815 ++ writel_relaxed(adchan->carveout,
9816 ++ ad->base + REG_CHAN_SRAM_CARVEOUT(adchan->no));
9817 + return 0;
9818 + }
9819 +
9820 + static void admac_free_chan_resources(struct dma_chan *chan)
9821 + {
9822 ++ struct admac_chan *adchan = to_admac_chan(chan);
9823 ++
9824 + admac_terminate_all(chan);
9825 + admac_synchronize(chan);
9826 ++ admac_free_sram_carveout(adchan->host, admac_chan_direction(adchan->no),
9827 ++ adchan->carveout);
9828 + }
9829 +
9830 + static struct dma_chan *admac_dma_of_xlate(struct of_phandle_args *dma_spec,
9831 +@@ -709,6 +802,7 @@ static int admac_probe(struct platform_device *pdev)
9832 + platform_set_drvdata(pdev, ad);
9833 + ad->dev = &pdev->dev;
9834 + ad->nchannels = nchannels;
9835 ++ mutex_init(&ad->cache_alloc_lock);
9836 +
9837 + /*
9838 + * The controller has 4 IRQ outputs. Try them all until
9839 +@@ -724,12 +818,7 @@ static int admac_probe(struct platform_device *pdev)
9840 +
9841 + if (irq < 0)
9842 + return dev_err_probe(&pdev->dev, irq, "no usable interrupt\n");
9843 +-
9844 +- err = devm_request_irq(&pdev->dev, irq, admac_interrupt,
9845 +- 0, dev_name(&pdev->dev), ad);
9846 +- if (err)
9847 +- return dev_err_probe(&pdev->dev, err,
9848 +- "unable to register interrupt\n");
9849 ++ ad->irq = irq;
9850 +
9851 + ad->base = devm_platform_ioremap_resource(pdev, 0);
9852 + if (IS_ERR(ad->base))
9853 +@@ -774,17 +863,36 @@ static int admac_probe(struct platform_device *pdev)
9854 + tasklet_setup(&adchan->tasklet, admac_chan_tasklet);
9855 + }
9856 +
9857 +- err = dma_async_device_register(&ad->dma);
9858 ++ err = request_irq(irq, admac_interrupt, 0, dev_name(&pdev->dev), ad);
9859 + if (err)
9860 +- return dev_err_probe(&pdev->dev, err, "failed to register DMA device\n");
9861 ++ return dev_err_probe(&pdev->dev, err,
9862 ++ "unable to register interrupt\n");
9863 ++
9864 ++ err = dma_async_device_register(&ad->dma);
9865 ++ if (err) {
9866 ++ dev_err_probe(&pdev->dev, err, "failed to register DMA device\n");
9867 ++ goto free_irq;
9868 ++ }
9869 +
9870 + err = of_dma_controller_register(pdev->dev.of_node, admac_dma_of_xlate, ad);
9871 + if (err) {
9872 + dma_async_device_unregister(&ad->dma);
9873 +- return dev_err_probe(&pdev->dev, err, "failed to register with OF\n");
9874 ++ dev_err_probe(&pdev->dev, err, "failed to register with OF\n");
9875 ++ goto free_irq;
9876 + }
9877 +
9878 ++ ad->txcache.size = readl_relaxed(ad->base + REG_TX_SRAM_SIZE);
9879 ++ ad->rxcache.size = readl_relaxed(ad->base + REG_RX_SRAM_SIZE);
9880 ++
9881 ++ dev_info(&pdev->dev, "Audio DMA Controller\n");
9882 ++ dev_info(&pdev->dev, "imprint %x TX cache %u RX cache %u\n",
9883 ++ readl_relaxed(ad->base + REG_IMPRINT), ad->txcache.size, ad->rxcache.size);
9884 ++
9885 + return 0;
9886 ++
9887 ++free_irq:
9888 ++ free_irq(ad->irq, ad);
9889 ++ return err;
9890 + }
9891 +
9892 + static int admac_remove(struct platform_device *pdev)
9893 +@@ -793,6 +901,7 @@ static int admac_remove(struct platform_device *pdev)
9894 +
9895 + of_dma_controller_free(pdev->dev.of_node);
9896 + dma_async_device_unregister(&ad->dma);
9897 ++ free_irq(ad->irq, ad);
9898 +
9899 + return 0;
9900 + }
9901 +diff --git a/drivers/edac/i10nm_base.c b/drivers/edac/i10nm_base.c
9902 +index 6cf50ee0b77c5..e0af60833d28c 100644
9903 +--- a/drivers/edac/i10nm_base.c
9904 ++++ b/drivers/edac/i10nm_base.c
9905 +@@ -198,11 +198,10 @@ static struct pci_dev *pci_get_dev_wrapper(int dom, unsigned int bus,
9906 + if (unlikely(pci_enable_device(pdev) < 0)) {
9907 + edac_dbg(2, "Failed to enable device %02x:%02x.%x\n",
9908 + bus, dev, fun);
9909 ++ pci_dev_put(pdev);
9910 + return NULL;
9911 + }
9912 +
9913 +- pci_dev_get(pdev);
9914 +-
9915 + return pdev;
9916 + }
9917 +
9918 +diff --git a/drivers/extcon/Kconfig b/drivers/extcon/Kconfig
9919 +index dca7cecb37e34..290186e44e6bd 100644
9920 +--- a/drivers/extcon/Kconfig
9921 ++++ b/drivers/extcon/Kconfig
9922 +@@ -183,7 +183,7 @@ config EXTCON_USBC_CROS_EC
9923 +
9924 + config EXTCON_USBC_TUSB320
9925 + tristate "TI TUSB320 USB-C extcon support"
9926 +- depends on I2C
9927 ++ depends on I2C && TYPEC
9928 + select REGMAP_I2C
9929 + help
9930 + Say Y here to enable support for USB Type C cable detection extcon
9931 +diff --git a/drivers/extcon/extcon-usbc-tusb320.c b/drivers/extcon/extcon-usbc-tusb320.c
9932 +index 6ba3d89b106d0..7223c4b9dc707 100644
9933 +--- a/drivers/extcon/extcon-usbc-tusb320.c
9934 ++++ b/drivers/extcon/extcon-usbc-tusb320.c
9935 +@@ -6,6 +6,7 @@
9936 + * Author: Michael Auchter <michael.auchter@××.com>
9937 + */
9938 +
9939 ++#include <linux/bitfield.h>
9940 + #include <linux/extcon-provider.h>
9941 + #include <linux/i2c.h>
9942 + #include <linux/init.h>
9943 +@@ -13,6 +14,24 @@
9944 + #include <linux/kernel.h>
9945 + #include <linux/module.h>
9946 + #include <linux/regmap.h>
9947 ++#include <linux/usb/typec.h>
9948 ++
9949 ++#define TUSB320_REG8 0x8
9950 ++#define TUSB320_REG8_CURRENT_MODE_ADVERTISE GENMASK(7, 6)
9951 ++#define TUSB320_REG8_CURRENT_MODE_ADVERTISE_USB 0x0
9952 ++#define TUSB320_REG8_CURRENT_MODE_ADVERTISE_15A 0x1
9953 ++#define TUSB320_REG8_CURRENT_MODE_ADVERTISE_30A 0x2
9954 ++#define TUSB320_REG8_CURRENT_MODE_DETECT GENMASK(5, 4)
9955 ++#define TUSB320_REG8_CURRENT_MODE_DETECT_DEF 0x0
9956 ++#define TUSB320_REG8_CURRENT_MODE_DETECT_MED 0x1
9957 ++#define TUSB320_REG8_CURRENT_MODE_DETECT_ACC 0x2
9958 ++#define TUSB320_REG8_CURRENT_MODE_DETECT_HI 0x3
9959 ++#define TUSB320_REG8_ACCESSORY_CONNECTED GENMASK(3, 2)
9960 ++#define TUSB320_REG8_ACCESSORY_CONNECTED_NONE 0x0
9961 ++#define TUSB320_REG8_ACCESSORY_CONNECTED_AUDIO 0x4
9962 ++#define TUSB320_REG8_ACCESSORY_CONNECTED_ACC 0x5
9963 ++#define TUSB320_REG8_ACCESSORY_CONNECTED_DEBUG 0x6
9964 ++#define TUSB320_REG8_ACTIVE_CABLE_DETECTION BIT(0)
9965 +
9966 + #define TUSB320_REG9 0x9
9967 + #define TUSB320_REG9_ATTACHED_STATE_SHIFT 6
9968 +@@ -55,6 +74,10 @@ struct tusb320_priv {
9969 + struct extcon_dev *edev;
9970 + struct tusb320_ops *ops;
9971 + enum tusb320_attached_state state;
9972 ++ struct typec_port *port;
9973 ++ struct typec_capability cap;
9974 ++ enum typec_port_type port_type;
9975 ++ enum typec_pwr_opmode pwr_opmode;
9976 + };
9977 +
9978 + static const char * const tusb_attached_states[] = {
9979 +@@ -184,19 +207,47 @@ static struct tusb320_ops tusb320l_ops = {
9980 + .get_revision = tusb320l_get_revision,
9981 + };
9982 +
9983 +-static irqreturn_t tusb320_irq_handler(int irq, void *dev_id)
9984 ++static int tusb320_set_adv_pwr_mode(struct tusb320_priv *priv)
9985 + {
9986 +- struct tusb320_priv *priv = dev_id;
9987 +- int state, polarity;
9988 +- unsigned reg;
9989 ++ u8 mode;
9990 ++
9991 ++ if (priv->pwr_opmode == TYPEC_PWR_MODE_USB)
9992 ++ mode = TUSB320_REG8_CURRENT_MODE_ADVERTISE_USB;
9993 ++ else if (priv->pwr_opmode == TYPEC_PWR_MODE_1_5A)
9994 ++ mode = TUSB320_REG8_CURRENT_MODE_ADVERTISE_15A;
9995 ++ else if (priv->pwr_opmode == TYPEC_PWR_MODE_3_0A)
9996 ++ mode = TUSB320_REG8_CURRENT_MODE_ADVERTISE_30A;
9997 ++ else /* No other mode is supported. */
9998 ++ return -EINVAL;
9999 +
10000 +- if (regmap_read(priv->regmap, TUSB320_REG9, &reg)) {
10001 +- dev_err(priv->dev, "error during i2c read!\n");
10002 +- return IRQ_NONE;
10003 +- }
10004 ++ return regmap_write_bits(priv->regmap, TUSB320_REG8,
10005 ++ TUSB320_REG8_CURRENT_MODE_ADVERTISE,
10006 ++ FIELD_PREP(TUSB320_REG8_CURRENT_MODE_ADVERTISE,
10007 ++ mode));
10008 ++}
10009 +
10010 +- if (!(reg & TUSB320_REG9_INTERRUPT_STATUS))
10011 +- return IRQ_NONE;
10012 ++static int tusb320_port_type_set(struct typec_port *port,
10013 ++ enum typec_port_type type)
10014 ++{
10015 ++ struct tusb320_priv *priv = typec_get_drvdata(port);
10016 ++
10017 ++ if (type == TYPEC_PORT_SRC)
10018 ++ return priv->ops->set_mode(priv, TUSB320_MODE_DFP);
10019 ++ else if (type == TYPEC_PORT_SNK)
10020 ++ return priv->ops->set_mode(priv, TUSB320_MODE_UFP);
10021 ++ else if (type == TYPEC_PORT_DRP)
10022 ++ return priv->ops->set_mode(priv, TUSB320_MODE_DRP);
10023 ++ else
10024 ++ return priv->ops->set_mode(priv, TUSB320_MODE_PORT);
10025 ++}
10026 ++
10027 ++static const struct typec_operations tusb320_typec_ops = {
10028 ++ .port_type_set = tusb320_port_type_set,
10029 ++};
10030 ++
10031 ++static void tusb320_extcon_irq_handler(struct tusb320_priv *priv, u8 reg)
10032 ++{
10033 ++ int state, polarity;
10034 +
10035 + state = (reg >> TUSB320_REG9_ATTACHED_STATE_SHIFT) &
10036 + TUSB320_REG9_ATTACHED_STATE_MASK;
10037 +@@ -219,19 +270,166 @@ static irqreturn_t tusb320_irq_handler(int irq, void *dev_id)
10038 + extcon_sync(priv->edev, EXTCON_USB_HOST);
10039 +
10040 + priv->state = state;
10041 ++}
10042 ++
10043 ++static void tusb320_typec_irq_handler(struct tusb320_priv *priv, u8 reg9)
10044 ++{
10045 ++ struct typec_port *port = priv->port;
10046 ++ struct device *dev = priv->dev;
10047 ++ u8 mode, role, state;
10048 ++ int ret, reg8;
10049 ++ bool ori;
10050 ++
10051 ++ ori = reg9 & TUSB320_REG9_CABLE_DIRECTION;
10052 ++ typec_set_orientation(port, ori ? TYPEC_ORIENTATION_REVERSE :
10053 ++ TYPEC_ORIENTATION_NORMAL);
10054 ++
10055 ++ state = (reg9 >> TUSB320_REG9_ATTACHED_STATE_SHIFT) &
10056 ++ TUSB320_REG9_ATTACHED_STATE_MASK;
10057 ++ if (state == TUSB320_ATTACHED_STATE_DFP)
10058 ++ role = TYPEC_SOURCE;
10059 ++ else
10060 ++ role = TYPEC_SINK;
10061 ++
10062 ++ typec_set_vconn_role(port, role);
10063 ++ typec_set_pwr_role(port, role);
10064 ++ typec_set_data_role(port, role == TYPEC_SOURCE ?
10065 ++ TYPEC_HOST : TYPEC_DEVICE);
10066 ++
10067 ++ ret = regmap_read(priv->regmap, TUSB320_REG8, &reg8);
10068 ++ if (ret) {
10069 ++ dev_err(dev, "error during reg8 i2c read, ret=%d!\n", ret);
10070 ++ return;
10071 ++ }
10072 ++
10073 ++ mode = FIELD_GET(TUSB320_REG8_CURRENT_MODE_DETECT, reg8);
10074 ++ if (mode == TUSB320_REG8_CURRENT_MODE_DETECT_DEF)
10075 ++ typec_set_pwr_opmode(port, TYPEC_PWR_MODE_USB);
10076 ++ else if (mode == TUSB320_REG8_CURRENT_MODE_DETECT_MED)
10077 ++ typec_set_pwr_opmode(port, TYPEC_PWR_MODE_1_5A);
10078 ++ else if (mode == TUSB320_REG8_CURRENT_MODE_DETECT_HI)
10079 ++ typec_set_pwr_opmode(port, TYPEC_PWR_MODE_3_0A);
10080 ++ else /* Charge through accessory */
10081 ++ typec_set_pwr_opmode(port, TYPEC_PWR_MODE_USB);
10082 ++}
10083 ++
10084 ++static irqreturn_t tusb320_state_update_handler(struct tusb320_priv *priv,
10085 ++ bool force_update)
10086 ++{
10087 ++ unsigned int reg;
10088 ++
10089 ++ if (regmap_read(priv->regmap, TUSB320_REG9, &reg)) {
10090 ++ dev_err(priv->dev, "error during i2c read!\n");
10091 ++ return IRQ_NONE;
10092 ++ }
10093 ++
10094 ++ if (!force_update && !(reg & TUSB320_REG9_INTERRUPT_STATUS))
10095 ++ return IRQ_NONE;
10096 ++
10097 ++ tusb320_extcon_irq_handler(priv, reg);
10098 ++
10099 ++ /*
10100 ++ * Type-C support is optional. Only call the Type-C handler if a
10101 ++ * port had been registered previously.
10102 ++ */
10103 ++ if (priv->port)
10104 ++ tusb320_typec_irq_handler(priv, reg);
10105 +
10106 + regmap_write(priv->regmap, TUSB320_REG9, reg);
10107 +
10108 + return IRQ_HANDLED;
10109 + }
10110 +
10111 ++static irqreturn_t tusb320_irq_handler(int irq, void *dev_id)
10112 ++{
10113 ++ struct tusb320_priv *priv = dev_id;
10114 ++
10115 ++ return tusb320_state_update_handler(priv, false);
10116 ++}
10117 ++
10118 + static const struct regmap_config tusb320_regmap_config = {
10119 + .reg_bits = 8,
10120 + .val_bits = 8,
10121 + };
10122 +
10123 +-static int tusb320_extcon_probe(struct i2c_client *client,
10124 +- const struct i2c_device_id *id)
10125 ++static int tusb320_extcon_probe(struct tusb320_priv *priv)
10126 ++{
10127 ++ int ret;
10128 ++
10129 ++ priv->edev = devm_extcon_dev_allocate(priv->dev, tusb320_extcon_cable);
10130 ++ if (IS_ERR(priv->edev)) {
10131 ++ dev_err(priv->dev, "failed to allocate extcon device\n");
10132 ++ return PTR_ERR(priv->edev);
10133 ++ }
10134 ++
10135 ++ ret = devm_extcon_dev_register(priv->dev, priv->edev);
10136 ++ if (ret < 0) {
10137 ++ dev_err(priv->dev, "failed to register extcon device\n");
10138 ++ return ret;
10139 ++ }
10140 ++
10141 ++ extcon_set_property_capability(priv->edev, EXTCON_USB,
10142 ++ EXTCON_PROP_USB_TYPEC_POLARITY);
10143 ++ extcon_set_property_capability(priv->edev, EXTCON_USB_HOST,
10144 ++ EXTCON_PROP_USB_TYPEC_POLARITY);
10145 ++
10146 ++ return 0;
10147 ++}
10148 ++
10149 ++static int tusb320_typec_probe(struct i2c_client *client,
10150 ++ struct tusb320_priv *priv)
10151 ++{
10152 ++ struct fwnode_handle *connector;
10153 ++ const char *cap_str;
10154 ++ int ret;
10155 ++
10156 ++ /* The Type-C connector is optional, for backward compatibility. */
10157 ++ connector = device_get_named_child_node(&client->dev, "connector");
10158 ++ if (!connector)
10159 ++ return 0;
10160 ++
10161 ++ /* Type-C connector found. */
10162 ++ ret = typec_get_fw_cap(&priv->cap, connector);
10163 ++ if (ret)
10164 ++ return ret;
10165 ++
10166 ++ priv->port_type = priv->cap.type;
10167 ++
10168 ++ /* This goes into register 0x8 field CURRENT_MODE_ADVERTISE */
10169 ++ ret = fwnode_property_read_string(connector, "typec-power-opmode", &cap_str);
10170 ++ if (ret)
10171 ++ return ret;
10172 ++
10173 ++ ret = typec_find_pwr_opmode(cap_str);
10174 ++ if (ret < 0)
10175 ++ return ret;
10176 ++ if (ret == TYPEC_PWR_MODE_PD)
10177 ++ return -EINVAL;
10178 ++
10179 ++ priv->pwr_opmode = ret;
10180 ++
10181 ++ /* Initialize the hardware with the devicetree settings. */
10182 ++ ret = tusb320_set_adv_pwr_mode(priv);
10183 ++ if (ret)
10184 ++ return ret;
10185 ++
10186 ++ priv->cap.revision = USB_TYPEC_REV_1_1;
10187 ++ priv->cap.accessory[0] = TYPEC_ACCESSORY_AUDIO;
10188 ++ priv->cap.accessory[1] = TYPEC_ACCESSORY_DEBUG;
10189 ++ priv->cap.orientation_aware = true;
10190 ++ priv->cap.driver_data = priv;
10191 ++ priv->cap.ops = &tusb320_typec_ops;
10192 ++ priv->cap.fwnode = connector;
10193 ++
10194 ++ priv->port = typec_register_port(&client->dev, &priv->cap);
10195 ++ if (IS_ERR(priv->port))
10196 ++ return PTR_ERR(priv->port);
10197 ++
10198 ++ return 0;
10199 ++}
10200 ++
10201 ++static int tusb320_probe(struct i2c_client *client,
10202 ++ const struct i2c_device_id *id)
10203 + {
10204 + struct tusb320_priv *priv;
10205 + const void *match_data;
10206 +@@ -257,12 +455,6 @@ static int tusb320_extcon_probe(struct i2c_client *client,
10207 +
10208 + priv->ops = (struct tusb320_ops*)match_data;
10209 +
10210 +- priv->edev = devm_extcon_dev_allocate(priv->dev, tusb320_extcon_cable);
10211 +- if (IS_ERR(priv->edev)) {
10212 +- dev_err(priv->dev, "failed to allocate extcon device\n");
10213 +- return PTR_ERR(priv->edev);
10214 +- }
10215 +-
10216 + if (priv->ops->get_revision) {
10217 + ret = priv->ops->get_revision(priv, &revision);
10218 + if (ret)
10219 +@@ -272,19 +464,16 @@ static int tusb320_extcon_probe(struct i2c_client *client,
10220 + dev_info(priv->dev, "chip revision %d\n", revision);
10221 + }
10222 +
10223 +- ret = devm_extcon_dev_register(priv->dev, priv->edev);
10224 +- if (ret < 0) {
10225 +- dev_err(priv->dev, "failed to register extcon device\n");
10226 ++ ret = tusb320_extcon_probe(priv);
10227 ++ if (ret)
10228 + return ret;
10229 +- }
10230 +
10231 +- extcon_set_property_capability(priv->edev, EXTCON_USB,
10232 +- EXTCON_PROP_USB_TYPEC_POLARITY);
10233 +- extcon_set_property_capability(priv->edev, EXTCON_USB_HOST,
10234 +- EXTCON_PROP_USB_TYPEC_POLARITY);
10235 ++ ret = tusb320_typec_probe(client, priv);
10236 ++ if (ret)
10237 ++ return ret;
10238 +
10239 + /* update initial state */
10240 +- tusb320_irq_handler(client->irq, priv);
10241 ++ tusb320_state_update_handler(priv, true);
10242 +
10243 + /* Reset chip to its default state */
10244 + ret = tusb320_reset(priv);
10245 +@@ -295,7 +484,7 @@ static int tusb320_extcon_probe(struct i2c_client *client,
10246 + * State and polarity might change after a reset, so update
10247 + * them again and make sure the interrupt status bit is cleared.
10248 + */
10249 +- tusb320_irq_handler(client->irq, priv);
10250 ++ tusb320_state_update_handler(priv, true);
10251 +
10252 + ret = devm_request_threaded_irq(priv->dev, client->irq, NULL,
10253 + tusb320_irq_handler,
10254 +@@ -313,7 +502,7 @@ static const struct of_device_id tusb320_extcon_dt_match[] = {
10255 + MODULE_DEVICE_TABLE(of, tusb320_extcon_dt_match);
10256 +
10257 + static struct i2c_driver tusb320_extcon_driver = {
10258 +- .probe = tusb320_extcon_probe,
10259 ++ .probe = tusb320_probe,
10260 + .driver = {
10261 + .name = "extcon-tusb320",
10262 + .of_match_table = tusb320_extcon_dt_match,
10263 +diff --git a/drivers/firmware/raspberrypi.c b/drivers/firmware/raspberrypi.c
10264 +index 4b8978b254f9a..dba315f675bc7 100644
10265 +--- a/drivers/firmware/raspberrypi.c
10266 ++++ b/drivers/firmware/raspberrypi.c
10267 +@@ -272,6 +272,7 @@ static int rpi_firmware_probe(struct platform_device *pdev)
10268 + int ret = PTR_ERR(fw->chan);
10269 + if (ret != -EPROBE_DEFER)
10270 + dev_err(dev, "Failed to get mbox channel: %d\n", ret);
10271 ++ kfree(fw);
10272 + return ret;
10273 + }
10274 +
10275 +diff --git a/drivers/firmware/ti_sci.c b/drivers/firmware/ti_sci.c
10276 +index ebc32bbd9b833..6281e7153b475 100644
10277 +--- a/drivers/firmware/ti_sci.c
10278 ++++ b/drivers/firmware/ti_sci.c
10279 +@@ -429,15 +429,14 @@ static inline int ti_sci_do_xfer(struct ti_sci_info *info,
10280 + * during noirq phase, so we must manually poll the completion.
10281 + */
10282 + ret = read_poll_timeout_atomic(try_wait_for_completion, done_state,
10283 +- true, 1,
10284 ++ done_state, 1,
10285 + info->desc->max_rx_timeout_ms * 1000,
10286 + false, &xfer->done);
10287 + }
10288 +
10289 +- if (ret == -ETIMEDOUT || !done_state) {
10290 ++ if (ret == -ETIMEDOUT)
10291 + dev_err(dev, "Mbox timedout in resp(caller: %pS)\n",
10292 + (void *)_RET_IP_);
10293 +- }
10294 +
10295 + /*
10296 + * NOTE: we might prefer not to need the mailbox ticker to manage the
10297 +diff --git a/drivers/gpio/gpiolib-cdev.c b/drivers/gpio/gpiolib-cdev.c
10298 +index 92f185575e941..12e068dc60bc2 100644
10299 +--- a/drivers/gpio/gpiolib-cdev.c
10300 ++++ b/drivers/gpio/gpiolib-cdev.c
10301 +@@ -55,6 +55,50 @@ static_assert(IS_ALIGNED(sizeof(struct gpio_v2_line_values), 8));
10302 + * interface to gpiolib GPIOs via ioctl()s.
10303 + */
10304 +
10305 ++typedef __poll_t (*poll_fn)(struct file *, struct poll_table_struct *);
10306 ++typedef long (*ioctl_fn)(struct file *, unsigned int, unsigned long);
10307 ++typedef ssize_t (*read_fn)(struct file *, char __user *,
10308 ++ size_t count, loff_t *);
10309 ++
10310 ++static __poll_t call_poll_locked(struct file *file,
10311 ++ struct poll_table_struct *wait,
10312 ++ struct gpio_device *gdev, poll_fn func)
10313 ++{
10314 ++ __poll_t ret;
10315 ++
10316 ++ down_read(&gdev->sem);
10317 ++ ret = func(file, wait);
10318 ++ up_read(&gdev->sem);
10319 ++
10320 ++ return ret;
10321 ++}
10322 ++
10323 ++static long call_ioctl_locked(struct file *file, unsigned int cmd,
10324 ++ unsigned long arg, struct gpio_device *gdev,
10325 ++ ioctl_fn func)
10326 ++{
10327 ++ long ret;
10328 ++
10329 ++ down_read(&gdev->sem);
10330 ++ ret = func(file, cmd, arg);
10331 ++ up_read(&gdev->sem);
10332 ++
10333 ++ return ret;
10334 ++}
10335 ++
10336 ++static ssize_t call_read_locked(struct file *file, char __user *buf,
10337 ++ size_t count, loff_t *f_ps,
10338 ++ struct gpio_device *gdev, read_fn func)
10339 ++{
10340 ++ ssize_t ret;
10341 ++
10342 ++ down_read(&gdev->sem);
10343 ++ ret = func(file, buf, count, f_ps);
10344 ++ up_read(&gdev->sem);
10345 ++
10346 ++ return ret;
10347 ++}
10348 ++
10349 + /*
10350 + * GPIO line handle management
10351 + */
10352 +@@ -191,8 +235,8 @@ static long linehandle_set_config(struct linehandle_state *lh,
10353 + return 0;
10354 + }
10355 +
10356 +-static long linehandle_ioctl(struct file *file, unsigned int cmd,
10357 +- unsigned long arg)
10358 ++static long linehandle_ioctl_unlocked(struct file *file, unsigned int cmd,
10359 ++ unsigned long arg)
10360 + {
10361 + struct linehandle_state *lh = file->private_data;
10362 + void __user *ip = (void __user *)arg;
10363 +@@ -201,6 +245,9 @@ static long linehandle_ioctl(struct file *file, unsigned int cmd,
10364 + unsigned int i;
10365 + int ret;
10366 +
10367 ++ if (!lh->gdev->chip)
10368 ++ return -ENODEV;
10369 ++
10370 + switch (cmd) {
10371 + case GPIOHANDLE_GET_LINE_VALUES_IOCTL:
10372 + /* NOTE: It's okay to read values of output lines */
10373 +@@ -247,6 +294,15 @@ static long linehandle_ioctl(struct file *file, unsigned int cmd,
10374 + }
10375 + }
10376 +
10377 ++static long linehandle_ioctl(struct file *file, unsigned int cmd,
10378 ++ unsigned long arg)
10379 ++{
10380 ++ struct linehandle_state *lh = file->private_data;
10381 ++
10382 ++ return call_ioctl_locked(file, cmd, arg, lh->gdev,
10383 ++ linehandle_ioctl_unlocked);
10384 ++}
10385 ++
10386 + #ifdef CONFIG_COMPAT
10387 + static long linehandle_ioctl_compat(struct file *file, unsigned int cmd,
10388 + unsigned long arg)
10389 +@@ -1378,12 +1434,15 @@ static long linereq_set_config(struct linereq *lr, void __user *ip)
10390 + return ret;
10391 + }
10392 +
10393 +-static long linereq_ioctl(struct file *file, unsigned int cmd,
10394 +- unsigned long arg)
10395 ++static long linereq_ioctl_unlocked(struct file *file, unsigned int cmd,
10396 ++ unsigned long arg)
10397 + {
10398 + struct linereq *lr = file->private_data;
10399 + void __user *ip = (void __user *)arg;
10400 +
10401 ++ if (!lr->gdev->chip)
10402 ++ return -ENODEV;
10403 ++
10404 + switch (cmd) {
10405 + case GPIO_V2_LINE_GET_VALUES_IOCTL:
10406 + return linereq_get_values(lr, ip);
10407 +@@ -1396,6 +1455,15 @@ static long linereq_ioctl(struct file *file, unsigned int cmd,
10408 + }
10409 + }
10410 +
10411 ++static long linereq_ioctl(struct file *file, unsigned int cmd,
10412 ++ unsigned long arg)
10413 ++{
10414 ++ struct linereq *lr = file->private_data;
10415 ++
10416 ++ return call_ioctl_locked(file, cmd, arg, lr->gdev,
10417 ++ linereq_ioctl_unlocked);
10418 ++}
10419 ++
10420 + #ifdef CONFIG_COMPAT
10421 + static long linereq_ioctl_compat(struct file *file, unsigned int cmd,
10422 + unsigned long arg)
10423 +@@ -1404,12 +1472,15 @@ static long linereq_ioctl_compat(struct file *file, unsigned int cmd,
10424 + }
10425 + #endif
10426 +
10427 +-static __poll_t linereq_poll(struct file *file,
10428 +- struct poll_table_struct *wait)
10429 ++static __poll_t linereq_poll_unlocked(struct file *file,
10430 ++ struct poll_table_struct *wait)
10431 + {
10432 + struct linereq *lr = file->private_data;
10433 + __poll_t events = 0;
10434 +
10435 ++ if (!lr->gdev->chip)
10436 ++ return EPOLLHUP | EPOLLERR;
10437 ++
10438 + poll_wait(file, &lr->wait, wait);
10439 +
10440 + if (!kfifo_is_empty_spinlocked_noirqsave(&lr->events,
10441 +@@ -1419,16 +1490,25 @@ static __poll_t linereq_poll(struct file *file,
10442 + return events;
10443 + }
10444 +
10445 +-static ssize_t linereq_read(struct file *file,
10446 +- char __user *buf,
10447 +- size_t count,
10448 +- loff_t *f_ps)
10449 ++static __poll_t linereq_poll(struct file *file,
10450 ++ struct poll_table_struct *wait)
10451 ++{
10452 ++ struct linereq *lr = file->private_data;
10453 ++
10454 ++ return call_poll_locked(file, wait, lr->gdev, linereq_poll_unlocked);
10455 ++}
10456 ++
10457 ++static ssize_t linereq_read_unlocked(struct file *file, char __user *buf,
10458 ++ size_t count, loff_t *f_ps)
10459 + {
10460 + struct linereq *lr = file->private_data;
10461 + struct gpio_v2_line_event le;
10462 + ssize_t bytes_read = 0;
10463 + int ret;
10464 +
10465 ++ if (!lr->gdev->chip)
10466 ++ return -ENODEV;
10467 ++
10468 + if (count < sizeof(le))
10469 + return -EINVAL;
10470 +
10471 +@@ -1473,6 +1553,15 @@ static ssize_t linereq_read(struct file *file,
10472 + return bytes_read;
10473 + }
10474 +
10475 ++static ssize_t linereq_read(struct file *file, char __user *buf,
10476 ++ size_t count, loff_t *f_ps)
10477 ++{
10478 ++ struct linereq *lr = file->private_data;
10479 ++
10480 ++ return call_read_locked(file, buf, count, f_ps, lr->gdev,
10481 ++ linereq_read_unlocked);
10482 ++}
10483 ++
10484 + static void linereq_free(struct linereq *lr)
10485 + {
10486 + unsigned int i;
10487 +@@ -1692,12 +1781,15 @@ struct lineevent_state {
10488 + (GPIOEVENT_REQUEST_RISING_EDGE | \
10489 + GPIOEVENT_REQUEST_FALLING_EDGE)
10490 +
10491 +-static __poll_t lineevent_poll(struct file *file,
10492 +- struct poll_table_struct *wait)
10493 ++static __poll_t lineevent_poll_unlocked(struct file *file,
10494 ++ struct poll_table_struct *wait)
10495 + {
10496 + struct lineevent_state *le = file->private_data;
10497 + __poll_t events = 0;
10498 +
10499 ++ if (!le->gdev->chip)
10500 ++ return EPOLLHUP | EPOLLERR;
10501 ++
10502 + poll_wait(file, &le->wait, wait);
10503 +
10504 + if (!kfifo_is_empty_spinlocked_noirqsave(&le->events, &le->wait.lock))
10505 +@@ -1706,15 +1798,21 @@ static __poll_t lineevent_poll(struct file *file,
10506 + return events;
10507 + }
10508 +
10509 ++static __poll_t lineevent_poll(struct file *file,
10510 ++ struct poll_table_struct *wait)
10511 ++{
10512 ++ struct lineevent_state *le = file->private_data;
10513 ++
10514 ++ return call_poll_locked(file, wait, le->gdev, lineevent_poll_unlocked);
10515 ++}
10516 ++
10517 + struct compat_gpioeevent_data {
10518 + compat_u64 timestamp;
10519 + u32 id;
10520 + };
10521 +
10522 +-static ssize_t lineevent_read(struct file *file,
10523 +- char __user *buf,
10524 +- size_t count,
10525 +- loff_t *f_ps)
10526 ++static ssize_t lineevent_read_unlocked(struct file *file, char __user *buf,
10527 ++ size_t count, loff_t *f_ps)
10528 + {
10529 + struct lineevent_state *le = file->private_data;
10530 + struct gpioevent_data ge;
10531 +@@ -1722,6 +1820,9 @@ static ssize_t lineevent_read(struct file *file,
10532 + ssize_t ge_size;
10533 + int ret;
10534 +
10535 ++ if (!le->gdev->chip)
10536 ++ return -ENODEV;
10537 ++
10538 + /*
10539 + * When compatible system call is being used the struct gpioevent_data,
10540 + * in case of at least ia32, has different size due to the alignment
10541 +@@ -1779,6 +1880,15 @@ static ssize_t lineevent_read(struct file *file,
10542 + return bytes_read;
10543 + }
10544 +
10545 ++static ssize_t lineevent_read(struct file *file, char __user *buf,
10546 ++ size_t count, loff_t *f_ps)
10547 ++{
10548 ++ struct lineevent_state *le = file->private_data;
10549 ++
10550 ++ return call_read_locked(file, buf, count, f_ps, le->gdev,
10551 ++ lineevent_read_unlocked);
10552 ++}
10553 ++
10554 + static void lineevent_free(struct lineevent_state *le)
10555 + {
10556 + if (le->irq)
10557 +@@ -1796,13 +1906,16 @@ static int lineevent_release(struct inode *inode, struct file *file)
10558 + return 0;
10559 + }
10560 +
10561 +-static long lineevent_ioctl(struct file *file, unsigned int cmd,
10562 +- unsigned long arg)
10563 ++static long lineevent_ioctl_unlocked(struct file *file, unsigned int cmd,
10564 ++ unsigned long arg)
10565 + {
10566 + struct lineevent_state *le = file->private_data;
10567 + void __user *ip = (void __user *)arg;
10568 + struct gpiohandle_data ghd;
10569 +
10570 ++ if (!le->gdev->chip)
10571 ++ return -ENODEV;
10572 ++
10573 + /*
10574 + * We can get the value for an event line but not set it,
10575 + * because it is input by definition.
10576 +@@ -1825,6 +1938,15 @@ static long lineevent_ioctl(struct file *file, unsigned int cmd,
10577 + return -EINVAL;
10578 + }
10579 +
10580 ++static long lineevent_ioctl(struct file *file, unsigned int cmd,
10581 ++ unsigned long arg)
10582 ++{
10583 ++ struct lineevent_state *le = file->private_data;
10584 ++
10585 ++ return call_ioctl_locked(file, cmd, arg, le->gdev,
10586 ++ lineevent_ioctl_unlocked);
10587 ++}
10588 ++
10589 + #ifdef CONFIG_COMPAT
10590 + static long lineevent_ioctl_compat(struct file *file, unsigned int cmd,
10591 + unsigned long arg)
10592 +@@ -2383,12 +2505,15 @@ static int lineinfo_changed_notify(struct notifier_block *nb,
10593 + return NOTIFY_OK;
10594 + }
10595 +
10596 +-static __poll_t lineinfo_watch_poll(struct file *file,
10597 +- struct poll_table_struct *pollt)
10598 ++static __poll_t lineinfo_watch_poll_unlocked(struct file *file,
10599 ++ struct poll_table_struct *pollt)
10600 + {
10601 + struct gpio_chardev_data *cdev = file->private_data;
10602 + __poll_t events = 0;
10603 +
10604 ++ if (!cdev->gdev->chip)
10605 ++ return EPOLLHUP | EPOLLERR;
10606 ++
10607 + poll_wait(file, &cdev->wait, pollt);
10608 +
10609 + if (!kfifo_is_empty_spinlocked_noirqsave(&cdev->events,
10610 +@@ -2398,8 +2523,17 @@ static __poll_t lineinfo_watch_poll(struct file *file,
10611 + return events;
10612 + }
10613 +
10614 +-static ssize_t lineinfo_watch_read(struct file *file, char __user *buf,
10615 +- size_t count, loff_t *off)
10616 ++static __poll_t lineinfo_watch_poll(struct file *file,
10617 ++ struct poll_table_struct *pollt)
10618 ++{
10619 ++ struct gpio_chardev_data *cdev = file->private_data;
10620 ++
10621 ++ return call_poll_locked(file, pollt, cdev->gdev,
10622 ++ lineinfo_watch_poll_unlocked);
10623 ++}
10624 ++
10625 ++static ssize_t lineinfo_watch_read_unlocked(struct file *file, char __user *buf,
10626 ++ size_t count, loff_t *off)
10627 + {
10628 + struct gpio_chardev_data *cdev = file->private_data;
10629 + struct gpio_v2_line_info_changed event;
10630 +@@ -2407,6 +2541,9 @@ static ssize_t lineinfo_watch_read(struct file *file, char __user *buf,
10631 + int ret;
10632 + size_t event_size;
10633 +
10634 ++ if (!cdev->gdev->chip)
10635 ++ return -ENODEV;
10636 ++
10637 + #ifndef CONFIG_GPIO_CDEV_V1
10638 + event_size = sizeof(struct gpio_v2_line_info_changed);
10639 + if (count < event_size)
10640 +@@ -2474,6 +2611,15 @@ static ssize_t lineinfo_watch_read(struct file *file, char __user *buf,
10641 + return bytes_read;
10642 + }
10643 +
10644 ++static ssize_t lineinfo_watch_read(struct file *file, char __user *buf,
10645 ++ size_t count, loff_t *off)
10646 ++{
10647 ++ struct gpio_chardev_data *cdev = file->private_data;
10648 ++
10649 ++ return call_read_locked(file, buf, count, off, cdev->gdev,
10650 ++ lineinfo_watch_read_unlocked);
10651 ++}
10652 ++
10653 + /**
10654 + * gpio_chrdev_open() - open the chardev for ioctl operations
10655 + * @inode: inode for this chardev
10656 +@@ -2487,13 +2633,17 @@ static int gpio_chrdev_open(struct inode *inode, struct file *file)
10657 + struct gpio_chardev_data *cdev;
10658 + int ret = -ENOMEM;
10659 +
10660 ++ down_read(&gdev->sem);
10661 ++
10662 + /* Fail on open if the backing gpiochip is gone */
10663 +- if (!gdev->chip)
10664 +- return -ENODEV;
10665 ++ if (!gdev->chip) {
10666 ++ ret = -ENODEV;
10667 ++ goto out_unlock;
10668 ++ }
10669 +
10670 + cdev = kzalloc(sizeof(*cdev), GFP_KERNEL);
10671 + if (!cdev)
10672 +- return -ENOMEM;
10673 ++ goto out_unlock;
10674 +
10675 + cdev->watched_lines = bitmap_zalloc(gdev->chip->ngpio, GFP_KERNEL);
10676 + if (!cdev->watched_lines)
10677 +@@ -2516,6 +2666,8 @@ static int gpio_chrdev_open(struct inode *inode, struct file *file)
10678 + if (ret)
10679 + goto out_unregister_notifier;
10680 +
10681 ++ up_read(&gdev->sem);
10682 ++
10683 + return ret;
10684 +
10685 + out_unregister_notifier:
10686 +@@ -2525,6 +2677,8 @@ out_free_bitmap:
10687 + bitmap_free(cdev->watched_lines);
10688 + out_free_cdev:
10689 + kfree(cdev);
10690 ++out_unlock:
10691 ++ up_read(&gdev->sem);
10692 + return ret;
10693 + }
10694 +
10695 +diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
10696 +index eb7d00608c7fb..2adca7c2dd5c8 100644
10697 +--- a/drivers/gpio/gpiolib.c
10698 ++++ b/drivers/gpio/gpiolib.c
10699 +@@ -735,6 +735,7 @@ int gpiochip_add_data_with_key(struct gpio_chip *gc, void *data,
10700 + spin_unlock_irqrestore(&gpio_lock, flags);
10701 +
10702 + BLOCKING_INIT_NOTIFIER_HEAD(&gdev->notifier);
10703 ++ init_rwsem(&gdev->sem);
10704 +
10705 + #ifdef CONFIG_PINCTRL
10706 + INIT_LIST_HEAD(&gdev->pin_ranges);
10707 +@@ -875,6 +876,8 @@ void gpiochip_remove(struct gpio_chip *gc)
10708 + unsigned long flags;
10709 + unsigned int i;
10710 +
10711 ++ down_write(&gdev->sem);
10712 ++
10713 + /* FIXME: should the legacy sysfs handling be moved to gpio_device? */
10714 + gpiochip_sysfs_unregister(gdev);
10715 + gpiochip_free_hogs(gc);
10716 +@@ -909,6 +912,7 @@ void gpiochip_remove(struct gpio_chip *gc)
10717 + * gone.
10718 + */
10719 + gcdev_unregister(gdev);
10720 ++ up_write(&gdev->sem);
10721 + put_device(&gdev->dev);
10722 + }
10723 + EXPORT_SYMBOL_GPL(gpiochip_remove);
10724 +diff --git a/drivers/gpio/gpiolib.h b/drivers/gpio/gpiolib.h
10725 +index d900ecdbac46d..9ad68a0adf4a8 100644
10726 +--- a/drivers/gpio/gpiolib.h
10727 ++++ b/drivers/gpio/gpiolib.h
10728 +@@ -15,6 +15,7 @@
10729 + #include <linux/device.h>
10730 + #include <linux/module.h>
10731 + #include <linux/cdev.h>
10732 ++#include <linux/rwsem.h>
10733 +
10734 + #define GPIOCHIP_NAME "gpiochip"
10735 +
10736 +@@ -39,6 +40,9 @@
10737 + * @list: links gpio_device:s together for traversal
10738 + * @notifier: used to notify subscribers about lines being requested, released
10739 + * or reconfigured
10740 ++ * @sem: protects the structure from a NULL-pointer dereference of @chip by
10741 ++ * user-space operations when the device gets unregistered during
10742 ++ * a hot-unplug event
10743 + * @pin_ranges: range of pins served by the GPIO driver
10744 + *
10745 + * This state container holds most of the runtime variable data
10746 +@@ -60,6 +64,7 @@ struct gpio_device {
10747 + void *data;
10748 + struct list_head list;
10749 + struct blocking_notifier_head notifier;
10750 ++ struct rw_semaphore sem;
10751 +
10752 + #ifdef CONFIG_PINCTRL
10753 + /*
10754 +diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
10755 +index 5e184952ec988..6659630303a38 100644
10756 +--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
10757 ++++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
10758 +@@ -2253,7 +2253,7 @@ int amdgpu_amdkfd_gpuvm_import_dmabuf(struct amdgpu_device *adev,
10759 +
10760 + ret = drm_vma_node_allow(&obj->vma_node, drm_priv);
10761 + if (ret) {
10762 +- kfree(mem);
10763 ++ kfree(*mem);
10764 + return ret;
10765 + }
10766 +
10767 +diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_bios.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_bios.c
10768 +index e363f56c72af1..30c28a69e847d 100644
10769 +--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_bios.c
10770 ++++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_bios.c
10771 +@@ -317,6 +317,7 @@ static bool amdgpu_atrm_get_bios(struct amdgpu_device *adev)
10772 +
10773 + if (!found)
10774 + return false;
10775 ++ pci_dev_put(pdev);
10776 +
10777 + adev->bios = kmalloc(size, GFP_KERNEL);
10778 + if (!adev->bios) {
10779 +diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
10780 +index e0c960cc1d2e1..f04e698e631c5 100644
10781 +--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
10782 ++++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
10783 +@@ -5004,6 +5004,8 @@ static void amdgpu_device_resume_display_audio(struct amdgpu_device *adev)
10784 + pm_runtime_enable(&(p->dev));
10785 + pm_runtime_resume(&(p->dev));
10786 + }
10787 ++
10788 ++ pci_dev_put(p);
10789 + }
10790 +
10791 + static int amdgpu_device_suspend_display_audio(struct amdgpu_device *adev)
10792 +@@ -5042,6 +5044,7 @@ static int amdgpu_device_suspend_display_audio(struct amdgpu_device *adev)
10793 +
10794 + if (expires < ktime_get_mono_fast_ns()) {
10795 + dev_warn(adev->dev, "failed to suspend display audio\n");
10796 ++ pci_dev_put(p);
10797 + /* TODO: abort the succeeding gpu reset? */
10798 + return -ETIMEDOUT;
10799 + }
10800 +@@ -5049,6 +5052,7 @@ static int amdgpu_device_suspend_display_audio(struct amdgpu_device *adev)
10801 +
10802 + pm_runtime_disable(&(p->dev));
10803 +
10804 ++ pci_dev_put(p);
10805 + return 0;
10806 + }
10807 +
10808 +diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.h
10809 +index 617d072275ebe..77210fd64a2bc 100644
10810 +--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.h
10811 ++++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.h
10812 +@@ -75,6 +75,8 @@ struct amdgpu_vf_error_buffer {
10813 + uint64_t data[AMDGPU_VF_ERROR_ENTRY_SIZE];
10814 + };
10815 +
10816 ++enum idh_request;
10817 ++
10818 + /**
10819 + * struct amdgpu_virt_ops - amdgpu device virt operations
10820 + */
10821 +@@ -84,7 +86,8 @@ struct amdgpu_virt_ops {
10822 + int (*req_init_data)(struct amdgpu_device *adev);
10823 + int (*reset_gpu)(struct amdgpu_device *adev);
10824 + int (*wait_reset)(struct amdgpu_device *adev);
10825 +- void (*trans_msg)(struct amdgpu_device *adev, u32 req, u32 data1, u32 data2, u32 data3);
10826 ++ void (*trans_msg)(struct amdgpu_device *adev, enum idh_request req,
10827 ++ u32 data1, u32 data2, u32 data3);
10828 + };
10829 +
10830 + /*
10831 +diff --git a/drivers/gpu/drm/amd/amdgpu/nv.c b/drivers/gpu/drm/amd/amdgpu/nv.c
10832 +index b3fba8dea63ca..6853b93ac82e7 100644
10833 +--- a/drivers/gpu/drm/amd/amdgpu/nv.c
10834 ++++ b/drivers/gpu/drm/amd/amdgpu/nv.c
10835 +@@ -82,10 +82,10 @@ static const struct amdgpu_video_codecs nv_video_codecs_encode =
10836 + /* Navi1x */
10837 + static const struct amdgpu_video_codec_info nv_video_codecs_decode_array[] =
10838 + {
10839 +- {codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_MPEG2, 4096, 4906, 3)},
10840 +- {codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_MPEG4, 4096, 4906, 5)},
10841 +- {codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_MPEG4_AVC, 4096, 4906, 52)},
10842 +- {codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_VC1, 4096, 4906, 4)},
10843 ++ {codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_MPEG2, 4096, 4096, 3)},
10844 ++ {codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_MPEG4, 4096, 4096, 5)},
10845 ++ {codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_MPEG4_AVC, 4096, 4096, 52)},
10846 ++ {codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_VC1, 4096, 4096, 4)},
10847 + {codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_HEVC, 8192, 4352, 186)},
10848 + {codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_JPEG, 4096, 4096, 0)},
10849 + {codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_VP9, 8192, 4352, 0)},
10850 +@@ -100,10 +100,10 @@ static const struct amdgpu_video_codecs nv_video_codecs_decode =
10851 + /* Sienna Cichlid */
10852 + static const struct amdgpu_video_codec_info sc_video_codecs_decode_array[] =
10853 + {
10854 +- {codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_MPEG2, 4096, 4906, 3)},
10855 +- {codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_MPEG4, 4096, 4906, 5)},
10856 +- {codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_MPEG4_AVC, 4096, 4906, 52)},
10857 +- {codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_VC1, 4096, 4906, 4)},
10858 ++ {codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_MPEG2, 4096, 4096, 3)},
10859 ++ {codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_MPEG4, 4096, 4096, 5)},
10860 ++ {codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_MPEG4_AVC, 4096, 4096, 52)},
10861 ++ {codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_VC1, 4096, 4096, 4)},
10862 + {codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_HEVC, 8192, 4352, 186)},
10863 + {codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_JPEG, 4096, 4096, 0)},
10864 + {codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_VP9, 8192, 4352, 0)},
10865 +@@ -125,10 +125,10 @@ static struct amdgpu_video_codec_info sriov_sc_video_codecs_encode_array[] =
10866 +
10867 + static struct amdgpu_video_codec_info sriov_sc_video_codecs_decode_array[] =
10868 + {
10869 +- {codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_MPEG2, 4096, 4906, 3)},
10870 +- {codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_MPEG4, 4096, 4906, 5)},
10871 +- {codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_MPEG4_AVC, 4096, 4906, 52)},
10872 +- {codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_VC1, 4096, 4906, 4)},
10873 ++ {codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_MPEG2, 4096, 4096, 3)},
10874 ++ {codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_MPEG4, 4096, 4096, 5)},
10875 ++ {codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_MPEG4_AVC, 4096, 4096, 52)},
10876 ++ {codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_VC1, 4096, 4096, 4)},
10877 + {codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_HEVC, 8192, 4352, 186)},
10878 + {codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_JPEG, 4096, 4096, 0)},
10879 + {codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_VP9, 8192, 4352, 0)},
10880 +@@ -149,7 +149,7 @@ static struct amdgpu_video_codecs sriov_sc_video_codecs_decode =
10881 +
10882 + /* Beige Goby*/
10883 + static const struct amdgpu_video_codec_info bg_video_codecs_decode_array[] = {
10884 +- {codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_MPEG4_AVC, 4096, 4906, 52)},
10885 ++ {codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_MPEG4_AVC, 4096, 4096, 52)},
10886 + {codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_HEVC, 8192, 4352, 186)},
10887 + {codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_VP9, 8192, 4352, 0)},
10888 + };
10889 +@@ -166,7 +166,7 @@ static const struct amdgpu_video_codecs bg_video_codecs_encode = {
10890 +
10891 + /* Yellow Carp*/
10892 + static const struct amdgpu_video_codec_info yc_video_codecs_decode_array[] = {
10893 +- {codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_MPEG4_AVC, 4096, 4906, 52)},
10894 ++ {codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_MPEG4_AVC, 4096, 4096, 52)},
10895 + {codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_HEVC, 8192, 4352, 186)},
10896 + {codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_VP9, 8192, 4352, 0)},
10897 + {codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_JPEG, 4096, 4096, 0)},
10898 +diff --git a/drivers/gpu/drm/amd/amdgpu/soc15.c b/drivers/gpu/drm/amd/amdgpu/soc15.c
10899 +index e3b2b6b4f1a66..7cd17dda32ceb 100644
10900 +--- a/drivers/gpu/drm/amd/amdgpu/soc15.c
10901 ++++ b/drivers/gpu/drm/amd/amdgpu/soc15.c
10902 +@@ -103,10 +103,10 @@ static const struct amdgpu_video_codecs vega_video_codecs_encode =
10903 + /* Vega */
10904 + static const struct amdgpu_video_codec_info vega_video_codecs_decode_array[] =
10905 + {
10906 +- {codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_MPEG2, 4096, 4906, 3)},
10907 +- {codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_MPEG4, 4096, 4906, 5)},
10908 +- {codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_MPEG4_AVC, 4096, 4906, 52)},
10909 +- {codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_VC1, 4096, 4906, 4)},
10910 ++ {codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_MPEG2, 4096, 4096, 3)},
10911 ++ {codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_MPEG4, 4096, 4096, 5)},
10912 ++ {codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_MPEG4_AVC, 4096, 4096, 52)},
10913 ++ {codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_VC1, 4096, 4096, 4)},
10914 + {codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_HEVC, 4096, 4096, 186)},
10915 + {codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_JPEG, 4096, 4096, 0)},
10916 + };
10917 +@@ -120,10 +120,10 @@ static const struct amdgpu_video_codecs vega_video_codecs_decode =
10918 + /* Raven */
10919 + static const struct amdgpu_video_codec_info rv_video_codecs_decode_array[] =
10920 + {
10921 +- {codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_MPEG2, 4096, 4906, 3)},
10922 +- {codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_MPEG4, 4096, 4906, 5)},
10923 +- {codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_MPEG4_AVC, 4096, 4906, 52)},
10924 +- {codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_VC1, 4096, 4906, 4)},
10925 ++ {codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_MPEG2, 4096, 4096, 3)},
10926 ++ {codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_MPEG4, 4096, 4096, 5)},
10927 ++ {codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_MPEG4_AVC, 4096, 4096, 52)},
10928 ++ {codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_VC1, 4096, 4096, 4)},
10929 + {codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_HEVC, 4096, 4096, 186)},
10930 + {codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_JPEG, 4096, 4096, 0)},
10931 + {codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_VP9, 4096, 4096, 0)},
10932 +@@ -138,10 +138,10 @@ static const struct amdgpu_video_codecs rv_video_codecs_decode =
10933 + /* Renoir, Arcturus */
10934 + static const struct amdgpu_video_codec_info rn_video_codecs_decode_array[] =
10935 + {
10936 +- {codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_MPEG2, 4096, 4906, 3)},
10937 +- {codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_MPEG4, 4096, 4906, 5)},
10938 +- {codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_MPEG4_AVC, 4096, 4906, 52)},
10939 +- {codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_VC1, 4096, 4906, 4)},
10940 ++ {codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_MPEG2, 4096, 4096, 3)},
10941 ++ {codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_MPEG4, 4096, 4096, 5)},
10942 ++ {codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_MPEG4_AVC, 4096, 4096, 52)},
10943 ++ {codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_VC1, 4096, 4096, 4)},
10944 + {codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_HEVC, 8192, 4352, 186)},
10945 + {codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_JPEG, 4096, 4096, 0)},
10946 + {codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_VP9, 8192, 4352, 0)},
10947 +diff --git a/drivers/gpu/drm/amd/amdgpu/soc21.c b/drivers/gpu/drm/amd/amdgpu/soc21.c
10948 +index 9c3463b481396..6d21c975b73d1 100644
10949 +--- a/drivers/gpu/drm/amd/amdgpu/soc21.c
10950 ++++ b/drivers/gpu/drm/amd/amdgpu/soc21.c
10951 +@@ -61,7 +61,7 @@ static const struct amdgpu_video_codecs vcn_4_0_0_video_codecs_encode =
10952 +
10953 + static const struct amdgpu_video_codec_info vcn_4_0_0_video_codecs_decode_array[] =
10954 + {
10955 +- {codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_MPEG4_AVC, 4096, 4906, 52)},
10956 ++ {codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_MPEG4_AVC, 4096, 4096, 52)},
10957 + {codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_HEVC, 8192, 4352, 186)},
10958 + {codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_JPEG, 4096, 4096, 0)},
10959 + {codec_info_build(AMDGPU_INFO_VIDEO_CAPS_CODEC_IDX_VP9, 8192, 4352, 0)},
10960 +diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_helpers.c b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_helpers.c
10961 +index a0154a5f71832..e2d3027c39936 100644
10962 +--- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_helpers.c
10963 ++++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_helpers.c
10964 +@@ -41,39 +41,6 @@
10965 + #include "dm_helpers.h"
10966 + #include "ddc_service_types.h"
10967 +
10968 +-struct monitor_patch_info {
10969 +- unsigned int manufacturer_id;
10970 +- unsigned int product_id;
10971 +- void (*patch_func)(struct dc_edid_caps *edid_caps, unsigned int param);
10972 +- unsigned int patch_param;
10973 +-};
10974 +-static void set_max_dsc_bpp_limit(struct dc_edid_caps *edid_caps, unsigned int param);
10975 +-
10976 +-static const struct monitor_patch_info monitor_patch_table[] = {
10977 +-{0x6D1E, 0x5BBF, set_max_dsc_bpp_limit, 15},
10978 +-{0x6D1E, 0x5B9A, set_max_dsc_bpp_limit, 15},
10979 +-};
10980 +-
10981 +-static void set_max_dsc_bpp_limit(struct dc_edid_caps *edid_caps, unsigned int param)
10982 +-{
10983 +- if (edid_caps)
10984 +- edid_caps->panel_patch.max_dsc_target_bpp_limit = param;
10985 +-}
10986 +-
10987 +-static int amdgpu_dm_patch_edid_caps(struct dc_edid_caps *edid_caps)
10988 +-{
10989 +- int i, ret = 0;
10990 +-
10991 +- for (i = 0; i < ARRAY_SIZE(monitor_patch_table); i++)
10992 +- if ((edid_caps->manufacturer_id == monitor_patch_table[i].manufacturer_id)
10993 +- && (edid_caps->product_id == monitor_patch_table[i].product_id)) {
10994 +- monitor_patch_table[i].patch_func(edid_caps, monitor_patch_table[i].patch_param);
10995 +- ret++;
10996 +- }
10997 +-
10998 +- return ret;
10999 +-}
11000 +-
11001 + /* dm_helpers_parse_edid_caps
11002 + *
11003 + * Parse edid caps
11004 +@@ -148,8 +115,6 @@ enum dc_edid_status dm_helpers_parse_edid_caps(
11005 + kfree(sads);
11006 + kfree(sadb);
11007 +
11008 +- amdgpu_dm_patch_edid_caps(edid_caps);
11009 +-
11010 + return result;
11011 + }
11012 +
11013 +diff --git a/drivers/gpu/drm/amd/display/dc/bios/bios_parser2.c b/drivers/gpu/drm/amd/display/dc/bios/bios_parser2.c
11014 +index de3a1f3fd4f1a..c98cd7c5b9f7a 100644
11015 +--- a/drivers/gpu/drm/amd/display/dc/bios/bios_parser2.c
11016 ++++ b/drivers/gpu/drm/amd/display/dc/bios/bios_parser2.c
11017 +@@ -487,6 +487,7 @@ static enum bp_result get_gpio_i2c_info(
11018 + uint32_t count = 0;
11019 + unsigned int table_index = 0;
11020 + bool find_valid = false;
11021 ++ struct atom_gpio_pin_assignment *pin;
11022 +
11023 + if (!info)
11024 + return BP_RESULT_BADINPUT;
11025 +@@ -514,20 +515,17 @@ static enum bp_result get_gpio_i2c_info(
11026 + - sizeof(struct atom_common_table_header))
11027 + / sizeof(struct atom_gpio_pin_assignment);
11028 +
11029 ++ pin = (struct atom_gpio_pin_assignment *) header->gpio_pin;
11030 ++
11031 + for (table_index = 0; table_index < count; table_index++) {
11032 +- if (((record->i2c_id & I2C_HW_CAP) == (
11033 +- header->gpio_pin[table_index].gpio_id &
11034 +- I2C_HW_CAP)) &&
11035 +- ((record->i2c_id & I2C_HW_ENGINE_ID_MASK) ==
11036 +- (header->gpio_pin[table_index].gpio_id &
11037 +- I2C_HW_ENGINE_ID_MASK)) &&
11038 +- ((record->i2c_id & I2C_HW_LANE_MUX) ==
11039 +- (header->gpio_pin[table_index].gpio_id &
11040 +- I2C_HW_LANE_MUX))) {
11041 ++ if (((record->i2c_id & I2C_HW_CAP) == (pin->gpio_id & I2C_HW_CAP)) &&
11042 ++ ((record->i2c_id & I2C_HW_ENGINE_ID_MASK) == (pin->gpio_id & I2C_HW_ENGINE_ID_MASK)) &&
11043 ++ ((record->i2c_id & I2C_HW_LANE_MUX) == (pin->gpio_id & I2C_HW_LANE_MUX))) {
11044 + /* still valid */
11045 + find_valid = true;
11046 + break;
11047 + }
11048 ++ pin = (struct atom_gpio_pin_assignment *)((uint8_t *)pin + sizeof(struct atom_gpio_pin_assignment));
11049 + }
11050 +
11051 + /* If we don't find the entry that we are looking for then
11052 +diff --git a/drivers/gpu/drm/amd/display/dc/clk_mgr/dcn32/dcn32_clk_mgr.c b/drivers/gpu/drm/amd/display/dc/clk_mgr/dcn32/dcn32_clk_mgr.c
11053 +index e7f1d5f8166f9..59a29c32f66a8 100644
11054 +--- a/drivers/gpu/drm/amd/display/dc/clk_mgr/dcn32/dcn32_clk_mgr.c
11055 ++++ b/drivers/gpu/drm/amd/display/dc/clk_mgr/dcn32/dcn32_clk_mgr.c
11056 +@@ -436,7 +436,7 @@ static void dcn32_update_clocks(struct clk_mgr *clk_mgr_base,
11057 + }
11058 +
11059 + if (!new_clocks->dtbclk_en) {
11060 +- new_clocks->ref_dtbclk_khz = 0;
11061 ++ new_clocks->ref_dtbclk_khz = clk_mgr_base->bw_params->clk_table.entries[0].dtbclk_mhz * 1000;
11062 + }
11063 +
11064 + /* clock limits are received with MHz precision, divide by 1000 to prevent setting clocks at every call */
11065 +diff --git a/drivers/gpu/drm/amd/display/dc/dce60/dce60_resource.c b/drivers/gpu/drm/amd/display/dc/dce60/dce60_resource.c
11066 +index fc6aa098bda06..8db9f75144662 100644
11067 +--- a/drivers/gpu/drm/amd/display/dc/dce60/dce60_resource.c
11068 ++++ b/drivers/gpu/drm/amd/display/dc/dce60/dce60_resource.c
11069 +@@ -1128,6 +1128,7 @@ struct resource_pool *dce60_create_resource_pool(
11070 + if (dce60_construct(num_virtual_links, dc, pool))
11071 + return &pool->base;
11072 +
11073 ++ kfree(pool);
11074 + BREAK_TO_DEBUGGER();
11075 + return NULL;
11076 + }
11077 +@@ -1325,6 +1326,7 @@ struct resource_pool *dce61_create_resource_pool(
11078 + if (dce61_construct(num_virtual_links, dc, pool))
11079 + return &pool->base;
11080 +
11081 ++ kfree(pool);
11082 + BREAK_TO_DEBUGGER();
11083 + return NULL;
11084 + }
11085 +@@ -1518,6 +1520,7 @@ struct resource_pool *dce64_create_resource_pool(
11086 + if (dce64_construct(num_virtual_links, dc, pool))
11087 + return &pool->base;
11088 +
11089 ++ kfree(pool);
11090 + BREAK_TO_DEBUGGER();
11091 + return NULL;
11092 + }
11093 +diff --git a/drivers/gpu/drm/amd/display/dc/dce80/dce80_resource.c b/drivers/gpu/drm/amd/display/dc/dce80/dce80_resource.c
11094 +index b28025960050c..5825e6f412bd7 100644
11095 +--- a/drivers/gpu/drm/amd/display/dc/dce80/dce80_resource.c
11096 ++++ b/drivers/gpu/drm/amd/display/dc/dce80/dce80_resource.c
11097 +@@ -1137,6 +1137,7 @@ struct resource_pool *dce80_create_resource_pool(
11098 + if (dce80_construct(num_virtual_links, dc, pool))
11099 + return &pool->base;
11100 +
11101 ++ kfree(pool);
11102 + BREAK_TO_DEBUGGER();
11103 + return NULL;
11104 + }
11105 +@@ -1336,6 +1337,7 @@ struct resource_pool *dce81_create_resource_pool(
11106 + if (dce81_construct(num_virtual_links, dc, pool))
11107 + return &pool->base;
11108 +
11109 ++ kfree(pool);
11110 + BREAK_TO_DEBUGGER();
11111 + return NULL;
11112 + }
11113 +diff --git a/drivers/gpu/drm/amd/display/dc/dcn10/dcn10_hw_sequencer.c b/drivers/gpu/drm/amd/display/dc/dcn10/dcn10_hw_sequencer.c
11114 +index bc9b92838ea9f..d7757e7900ba7 100644
11115 +--- a/drivers/gpu/drm/amd/display/dc/dcn10/dcn10_hw_sequencer.c
11116 ++++ b/drivers/gpu/drm/amd/display/dc/dcn10/dcn10_hw_sequencer.c
11117 +@@ -867,6 +867,32 @@ static void false_optc_underflow_wa(
11118 + tg->funcs->clear_optc_underflow(tg);
11119 + }
11120 +
11121 ++static int calculate_vready_offset_for_group(struct pipe_ctx *pipe)
11122 ++{
11123 ++ struct pipe_ctx *other_pipe;
11124 ++ int vready_offset = pipe->pipe_dlg_param.vready_offset;
11125 ++
11126 ++ /* Always use the largest vready_offset of all connected pipes */
11127 ++ for (other_pipe = pipe->bottom_pipe; other_pipe != NULL; other_pipe = other_pipe->bottom_pipe) {
11128 ++ if (other_pipe->pipe_dlg_param.vready_offset > vready_offset)
11129 ++ vready_offset = other_pipe->pipe_dlg_param.vready_offset;
11130 ++ }
11131 ++ for (other_pipe = pipe->top_pipe; other_pipe != NULL; other_pipe = other_pipe->top_pipe) {
11132 ++ if (other_pipe->pipe_dlg_param.vready_offset > vready_offset)
11133 ++ vready_offset = other_pipe->pipe_dlg_param.vready_offset;
11134 ++ }
11135 ++ for (other_pipe = pipe->next_odm_pipe; other_pipe != NULL; other_pipe = other_pipe->next_odm_pipe) {
11136 ++ if (other_pipe->pipe_dlg_param.vready_offset > vready_offset)
11137 ++ vready_offset = other_pipe->pipe_dlg_param.vready_offset;
11138 ++ }
11139 ++ for (other_pipe = pipe->prev_odm_pipe; other_pipe != NULL; other_pipe = other_pipe->prev_odm_pipe) {
11140 ++ if (other_pipe->pipe_dlg_param.vready_offset > vready_offset)
11141 ++ vready_offset = other_pipe->pipe_dlg_param.vready_offset;
11142 ++ }
11143 ++
11144 ++ return vready_offset;
11145 ++}
11146 ++
11147 + enum dc_status dcn10_enable_stream_timing(
11148 + struct pipe_ctx *pipe_ctx,
11149 + struct dc_state *context,
11150 +@@ -902,7 +928,7 @@ enum dc_status dcn10_enable_stream_timing(
11151 + pipe_ctx->stream_res.tg->funcs->program_timing(
11152 + pipe_ctx->stream_res.tg,
11153 + &stream->timing,
11154 +- pipe_ctx->pipe_dlg_param.vready_offset,
11155 ++ calculate_vready_offset_for_group(pipe_ctx),
11156 + pipe_ctx->pipe_dlg_param.vstartup_start,
11157 + pipe_ctx->pipe_dlg_param.vupdate_offset,
11158 + pipe_ctx->pipe_dlg_param.vupdate_width,
11159 +@@ -2869,7 +2895,7 @@ void dcn10_program_pipe(
11160 +
11161 + pipe_ctx->stream_res.tg->funcs->program_global_sync(
11162 + pipe_ctx->stream_res.tg,
11163 +- pipe_ctx->pipe_dlg_param.vready_offset,
11164 ++ calculate_vready_offset_for_group(pipe_ctx),
11165 + pipe_ctx->pipe_dlg_param.vstartup_start,
11166 + pipe_ctx->pipe_dlg_param.vupdate_offset,
11167 + pipe_ctx->pipe_dlg_param.vupdate_width);
11168 +diff --git a/drivers/gpu/drm/amd/display/dc/dcn20/dcn20_hwseq.c b/drivers/gpu/drm/amd/display/dc/dcn20/dcn20_hwseq.c
11169 +index 0f30df523fdf5..cd799ce6e48b8 100644
11170 +--- a/drivers/gpu/drm/amd/display/dc/dcn20/dcn20_hwseq.c
11171 ++++ b/drivers/gpu/drm/amd/display/dc/dcn20/dcn20_hwseq.c
11172 +@@ -1608,6 +1608,31 @@ static void dcn20_update_dchubp_dpp(
11173 + hubp->funcs->phantom_hubp_post_enable(hubp);
11174 + }
11175 +
11176 ++static int calculate_vready_offset_for_group(struct pipe_ctx *pipe)
11177 ++{
11178 ++ struct pipe_ctx *other_pipe;
11179 ++ int vready_offset = pipe->pipe_dlg_param.vready_offset;
11180 ++
11181 ++ /* Always use the largest vready_offset of all connected pipes */
11182 ++ for (other_pipe = pipe->bottom_pipe; other_pipe != NULL; other_pipe = other_pipe->bottom_pipe) {
11183 ++ if (other_pipe->pipe_dlg_param.vready_offset > vready_offset)
11184 ++ vready_offset = other_pipe->pipe_dlg_param.vready_offset;
11185 ++ }
11186 ++ for (other_pipe = pipe->top_pipe; other_pipe != NULL; other_pipe = other_pipe->top_pipe) {
11187 ++ if (other_pipe->pipe_dlg_param.vready_offset > vready_offset)
11188 ++ vready_offset = other_pipe->pipe_dlg_param.vready_offset;
11189 ++ }
11190 ++ for (other_pipe = pipe->next_odm_pipe; other_pipe != NULL; other_pipe = other_pipe->next_odm_pipe) {
11191 ++ if (other_pipe->pipe_dlg_param.vready_offset > vready_offset)
11192 ++ vready_offset = other_pipe->pipe_dlg_param.vready_offset;
11193 ++ }
11194 ++ for (other_pipe = pipe->prev_odm_pipe; other_pipe != NULL; other_pipe = other_pipe->prev_odm_pipe) {
11195 ++ if (other_pipe->pipe_dlg_param.vready_offset > vready_offset)
11196 ++ vready_offset = other_pipe->pipe_dlg_param.vready_offset;
11197 ++ }
11198 ++
11199 ++ return vready_offset;
11200 ++}
11201 +
11202 + static void dcn20_program_pipe(
11203 + struct dc *dc,
11204 +@@ -1626,16 +1651,14 @@ static void dcn20_program_pipe(
11205 + && !pipe_ctx->prev_odm_pipe) {
11206 + pipe_ctx->stream_res.tg->funcs->program_global_sync(
11207 + pipe_ctx->stream_res.tg,
11208 +- pipe_ctx->pipe_dlg_param.vready_offset,
11209 ++ calculate_vready_offset_for_group(pipe_ctx),
11210 + pipe_ctx->pipe_dlg_param.vstartup_start,
11211 + pipe_ctx->pipe_dlg_param.vupdate_offset,
11212 + pipe_ctx->pipe_dlg_param.vupdate_width);
11213 +
11214 + if (pipe_ctx->stream->mall_stream_config.type != SUBVP_PHANTOM) {
11215 +- pipe_ctx->stream_res.tg->funcs->wait_for_state(
11216 +- pipe_ctx->stream_res.tg, CRTC_STATE_VBLANK);
11217 +- pipe_ctx->stream_res.tg->funcs->wait_for_state(
11218 +- pipe_ctx->stream_res.tg, CRTC_STATE_VACTIVE);
11219 ++ pipe_ctx->stream_res.tg->funcs->wait_for_state(pipe_ctx->stream_res.tg, CRTC_STATE_VBLANK);
11220 ++ pipe_ctx->stream_res.tg->funcs->wait_for_state(pipe_ctx->stream_res.tg, CRTC_STATE_VACTIVE);
11221 + }
11222 +
11223 + pipe_ctx->stream_res.tg->funcs->set_vtg_params(
11224 +@@ -2040,7 +2063,7 @@ bool dcn20_update_bandwidth(
11225 +
11226 + pipe_ctx->stream_res.tg->funcs->program_global_sync(
11227 + pipe_ctx->stream_res.tg,
11228 +- pipe_ctx->pipe_dlg_param.vready_offset,
11229 ++ calculate_vready_offset_for_group(pipe_ctx),
11230 + pipe_ctx->pipe_dlg_param.vstartup_start,
11231 + pipe_ctx->pipe_dlg_param.vupdate_offset,
11232 + pipe_ctx->pipe_dlg_param.vupdate_width);
11233 +diff --git a/drivers/gpu/drm/amd/display/dc/dcn32/dcn32_dccg.c b/drivers/gpu/drm/amd/display/dc/dcn32/dcn32_dccg.c
11234 +index 6dd8dadd68a5d..6f160f65c8fa9 100644
11235 +--- a/drivers/gpu/drm/amd/display/dc/dcn32/dcn32_dccg.c
11236 ++++ b/drivers/gpu/drm/amd/display/dc/dcn32/dcn32_dccg.c
11237 +@@ -225,11 +225,7 @@ void dccg32_set_dtbclk_dto(
11238 + } else {
11239 + REG_UPDATE_2(OTG_PIXEL_RATE_CNTL[params->otg_inst],
11240 + DTBCLK_DTO_ENABLE[params->otg_inst], 0,
11241 +- PIPE_DTO_SRC_SEL[params->otg_inst], 1);
11242 +- if (params->is_hdmi)
11243 +- REG_UPDATE(OTG_PIXEL_RATE_CNTL[params->otg_inst],
11244 +- PIPE_DTO_SRC_SEL[params->otg_inst], 0);
11245 +-
11246 ++ PIPE_DTO_SRC_SEL[params->otg_inst], params->is_hdmi ? 0 : 1);
11247 + REG_WRITE(DTBCLK_DTO_MODULO[params->otg_inst], 0);
11248 + REG_WRITE(DTBCLK_DTO_PHASE[params->otg_inst], 0);
11249 + }
11250 +diff --git a/drivers/gpu/drm/amd/display/dc/dml/dcn32/dcn32_fpu.c b/drivers/gpu/drm/amd/display/dc/dml/dcn32/dcn32_fpu.c
11251 +index 07c56e231b045..d05df4f7139fd 100644
11252 +--- a/drivers/gpu/drm/amd/display/dc/dml/dcn32/dcn32_fpu.c
11253 ++++ b/drivers/gpu/drm/amd/display/dc/dml/dcn32/dcn32_fpu.c
11254 +@@ -485,9 +485,11 @@ void dcn32_set_phantom_stream_timing(struct dc *dc,
11255 + unsigned int i, pipe_idx;
11256 + struct pipe_ctx *pipe;
11257 + uint32_t phantom_vactive, phantom_bp, pstate_width_fw_delay_lines;
11258 ++ unsigned int num_dpp;
11259 + unsigned int vlevel = context->bw_ctx.dml.vba.VoltageLevel;
11260 + unsigned int dcfclk = context->bw_ctx.dml.vba.DCFCLKState[vlevel][context->bw_ctx.dml.vba.maxMpcComb];
11261 + unsigned int socclk = context->bw_ctx.dml.vba.SOCCLKPerState[vlevel];
11262 ++ struct vba_vars_st *vba = &context->bw_ctx.dml.vba;
11263 +
11264 + dc_assert_fp_enabled();
11265 +
11266 +@@ -523,6 +525,11 @@ void dcn32_set_phantom_stream_timing(struct dc *dc,
11267 + phantom_vactive = get_subviewport_lines_needed_in_mall(&context->bw_ctx.dml, pipes, pipe_cnt, pipe_idx) +
11268 + pstate_width_fw_delay_lines + dc->caps.subvp_swath_height_margin_lines;
11269 +
11270 ++ // W/A for DCC corruption with certain high resolution timings.
11271 ++ // Determing if pipesplit is used. If so, add meta_row_height to the phantom vactive.
11272 ++ num_dpp = vba->NoOfDPP[vba->VoltageLevel][vba->maxMpcComb][vba->pipe_plane[pipe_idx]];
11273 ++ phantom_vactive += num_dpp > 1 ? vba->meta_row_height[vba->pipe_plane[pipe_idx]] : 0;
11274 ++
11275 + // For backporch of phantom pipe, use vstartup of the main pipe
11276 + phantom_bp = get_vstartup(&context->bw_ctx.dml, pipes, pipe_cnt, pipe_idx);
11277 +
11278 +diff --git a/drivers/gpu/drm/amd/include/kgd_pp_interface.h b/drivers/gpu/drm/amd/include/kgd_pp_interface.h
11279 +index 7e3231c2191ca..ffe19883b2ee9 100644
11280 +--- a/drivers/gpu/drm/amd/include/kgd_pp_interface.h
11281 ++++ b/drivers/gpu/drm/amd/include/kgd_pp_interface.h
11282 +@@ -354,7 +354,8 @@ struct amd_pm_funcs {
11283 + int (*get_power_profile_mode)(void *handle, char *buf);
11284 + int (*set_power_profile_mode)(void *handle, long *input, uint32_t size);
11285 + int (*set_fine_grain_clk_vol)(void *handle, uint32_t type, long *input, uint32_t size);
11286 +- int (*odn_edit_dpm_table)(void *handle, uint32_t type, long *input, uint32_t size);
11287 ++ int (*odn_edit_dpm_table)(void *handle, enum PP_OD_DPM_TABLE_COMMAND type,
11288 ++ long *input, uint32_t size);
11289 + int (*set_mp1_state)(void *handle, enum pp_mp1_state mp1_state);
11290 + int (*smu_i2c_bus_access)(void *handle, bool acquire);
11291 + int (*gfx_state_change_set)(void *handle, uint32_t state);
11292 +diff --git a/drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c b/drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c
11293 +index 1eb4e613b27a5..6562978de84a0 100644
11294 +--- a/drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c
11295 ++++ b/drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c
11296 +@@ -838,7 +838,8 @@ static int pp_set_fine_grain_clk_vol(void *handle, uint32_t type, long *input, u
11297 + return hwmgr->hwmgr_func->set_fine_grain_clk_vol(hwmgr, type, input, size);
11298 + }
11299 +
11300 +-static int pp_odn_edit_dpm_table(void *handle, uint32_t type, long *input, uint32_t size)
11301 ++static int pp_odn_edit_dpm_table(void *handle, enum PP_OD_DPM_TABLE_COMMAND type,
11302 ++ long *input, uint32_t size)
11303 + {
11304 + struct pp_hwmgr *hwmgr = handle;
11305 +
11306 +diff --git a/drivers/gpu/drm/amd/pm/powerplay/hwmgr/pp_psm.c b/drivers/gpu/drm/amd/pm/powerplay/hwmgr/pp_psm.c
11307 +index 67d7da0b6fed5..1d829402cd2e2 100644
11308 +--- a/drivers/gpu/drm/amd/pm/powerplay/hwmgr/pp_psm.c
11309 ++++ b/drivers/gpu/drm/amd/pm/powerplay/hwmgr/pp_psm.c
11310 +@@ -75,8 +75,10 @@ int psm_init_power_state_table(struct pp_hwmgr *hwmgr)
11311 + for (i = 0; i < table_entries; i++) {
11312 + result = hwmgr->hwmgr_func->get_pp_table_entry(hwmgr, i, state);
11313 + if (result) {
11314 ++ kfree(hwmgr->current_ps);
11315 + kfree(hwmgr->request_ps);
11316 + kfree(hwmgr->ps);
11317 ++ hwmgr->current_ps = NULL;
11318 + hwmgr->request_ps = NULL;
11319 + hwmgr->ps = NULL;
11320 + return -EINVAL;
11321 +diff --git a/drivers/gpu/drm/amd/pm/powerplay/hwmgr/vega20_hwmgr.c b/drivers/gpu/drm/amd/pm/powerplay/hwmgr/vega20_hwmgr.c
11322 +index 97b3ad3690467..b30684c84e20e 100644
11323 +--- a/drivers/gpu/drm/amd/pm/powerplay/hwmgr/vega20_hwmgr.c
11324 ++++ b/drivers/gpu/drm/amd/pm/powerplay/hwmgr/vega20_hwmgr.c
11325 +@@ -2961,7 +2961,8 @@ static int vega20_odn_edit_dpm_table(struct pp_hwmgr *hwmgr,
11326 + data->od8_settings.od8_settings_array;
11327 + OverDriveTable_t *od_table =
11328 + &(data->smc_state_table.overdrive_table);
11329 +- int32_t input_index, input_clk, input_vol, i;
11330 ++ int32_t input_clk, input_vol, i;
11331 ++ uint32_t input_index;
11332 + int od8_id;
11333 + int ret;
11334 +
11335 +diff --git a/drivers/gpu/drm/amd/pm/swsmu/smu11/smu_v11_0.c b/drivers/gpu/drm/amd/pm/swsmu/smu11/smu_v11_0.c
11336 +index 70b560737687e..ad5f6a15a1d7d 100644
11337 +--- a/drivers/gpu/drm/amd/pm/swsmu/smu11/smu_v11_0.c
11338 ++++ b/drivers/gpu/drm/amd/pm/swsmu/smu11/smu_v11_0.c
11339 +@@ -1588,6 +1588,10 @@ bool smu_v11_0_baco_is_support(struct smu_context *smu)
11340 + if (amdgpu_sriov_vf(smu->adev) || !smu_baco->platform_support)
11341 + return false;
11342 +
11343 ++ /* return true if ASIC is in BACO state already */
11344 ++ if (smu_v11_0_baco_get_state(smu) == SMU_BACO_STATE_ENTER)
11345 ++ return true;
11346 ++
11347 + /* Arcturus does not support this bit mask */
11348 + if (smu_cmn_feature_is_supported(smu, SMU_FEATURE_BACO_BIT) &&
11349 + !smu_cmn_feature_is_enabled(smu, SMU_FEATURE_BACO_BIT))
11350 +diff --git a/drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c b/drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c
11351 +index d74debc584f89..39deb06a86ba3 100644
11352 +--- a/drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c
11353 ++++ b/drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c
11354 +@@ -1436,7 +1436,7 @@ static int smu_v13_0_7_get_power_limit(struct smu_context *smu,
11355 +
11356 + static int smu_v13_0_7_get_power_profile_mode(struct smu_context *smu, char *buf)
11357 + {
11358 +- DpmActivityMonitorCoeffIntExternal_t activity_monitor_external[PP_SMC_POWER_PROFILE_COUNT];
11359 ++ DpmActivityMonitorCoeffIntExternal_t *activity_monitor_external;
11360 + uint32_t i, j, size = 0;
11361 + int16_t workload_type = 0;
11362 + int result = 0;
11363 +@@ -1444,6 +1444,12 @@ static int smu_v13_0_7_get_power_profile_mode(struct smu_context *smu, char *buf
11364 + if (!buf)
11365 + return -EINVAL;
11366 +
11367 ++ activity_monitor_external = kcalloc(PP_SMC_POWER_PROFILE_COUNT,
11368 ++ sizeof(*activity_monitor_external),
11369 ++ GFP_KERNEL);
11370 ++ if (!activity_monitor_external)
11371 ++ return -ENOMEM;
11372 ++
11373 + size += sysfs_emit_at(buf, size, " ");
11374 + for (i = 0; i <= PP_SMC_POWER_PROFILE_WINDOW3D; i++)
11375 + size += sysfs_emit_at(buf, size, "%-14s%s", amdgpu_pp_profile_name[i],
11376 +@@ -1456,15 +1462,17 @@ static int smu_v13_0_7_get_power_profile_mode(struct smu_context *smu, char *buf
11377 + workload_type = smu_cmn_to_asic_specific_index(smu,
11378 + CMN2ASIC_MAPPING_WORKLOAD,
11379 + i);
11380 +- if (workload_type < 0)
11381 +- return -EINVAL;
11382 ++ if (workload_type < 0) {
11383 ++ result = -EINVAL;
11384 ++ goto out;
11385 ++ }
11386 +
11387 + result = smu_cmn_update_table(smu,
11388 + SMU_TABLE_ACTIVITY_MONITOR_COEFF, workload_type,
11389 + (void *)(&activity_monitor_external[i]), false);
11390 + if (result) {
11391 + dev_err(smu->adev->dev, "[%s] Failed to get activity monitor!", __func__);
11392 +- return result;
11393 ++ goto out;
11394 + }
11395 + }
11396 +
11397 +@@ -1492,7 +1500,10 @@ do { \
11398 + PRINT_DPM_MONITOR(Fclk_BoosterFreq);
11399 + #undef PRINT_DPM_MONITOR
11400 +
11401 +- return size;
11402 ++ result = size;
11403 ++out:
11404 ++ kfree(activity_monitor_external);
11405 ++ return result;
11406 + }
11407 +
11408 + static int smu_v13_0_7_set_power_profile_mode(struct smu_context *smu, long *input, uint32_t size)
11409 +diff --git a/drivers/gpu/drm/bridge/adv7511/adv7511.h b/drivers/gpu/drm/bridge/adv7511/adv7511.h
11410 +index 94de73cbeb2dd..17445800248dd 100644
11411 +--- a/drivers/gpu/drm/bridge/adv7511/adv7511.h
11412 ++++ b/drivers/gpu/drm/bridge/adv7511/adv7511.h
11413 +@@ -402,7 +402,8 @@ static inline int adv7511_cec_init(struct device *dev, struct adv7511 *adv7511)
11414 +
11415 + void adv7533_dsi_power_on(struct adv7511 *adv);
11416 + void adv7533_dsi_power_off(struct adv7511 *adv);
11417 +-void adv7533_mode_set(struct adv7511 *adv, const struct drm_display_mode *mode);
11418 ++enum drm_mode_status adv7533_mode_valid(struct adv7511 *adv,
11419 ++ const struct drm_display_mode *mode);
11420 + int adv7533_patch_registers(struct adv7511 *adv);
11421 + int adv7533_patch_cec_registers(struct adv7511 *adv);
11422 + int adv7533_attach_dsi(struct adv7511 *adv);
11423 +diff --git a/drivers/gpu/drm/bridge/adv7511/adv7511_drv.c b/drivers/gpu/drm/bridge/adv7511/adv7511_drv.c
11424 +index 6031bdd923420..0f0950c111960 100644
11425 +--- a/drivers/gpu/drm/bridge/adv7511/adv7511_drv.c
11426 ++++ b/drivers/gpu/drm/bridge/adv7511/adv7511_drv.c
11427 +@@ -697,7 +697,7 @@ adv7511_detect(struct adv7511 *adv7511, struct drm_connector *connector)
11428 + }
11429 +
11430 + static enum drm_mode_status adv7511_mode_valid(struct adv7511 *adv7511,
11431 +- struct drm_display_mode *mode)
11432 ++ const struct drm_display_mode *mode)
11433 + {
11434 + if (mode->clock > 165000)
11435 + return MODE_CLOCK_HIGH;
11436 +@@ -791,9 +791,6 @@ static void adv7511_mode_set(struct adv7511 *adv7511,
11437 + regmap_update_bits(adv7511->regmap, 0x17,
11438 + 0x60, (vsync_polarity << 6) | (hsync_polarity << 5));
11439 +
11440 +- if (adv7511->type == ADV7533 || adv7511->type == ADV7535)
11441 +- adv7533_mode_set(adv7511, adj_mode);
11442 +-
11443 + drm_mode_copy(&adv7511->curr_mode, adj_mode);
11444 +
11445 + /*
11446 +@@ -913,6 +910,18 @@ static void adv7511_bridge_mode_set(struct drm_bridge *bridge,
11447 + adv7511_mode_set(adv, mode, adj_mode);
11448 + }
11449 +
11450 ++static enum drm_mode_status adv7511_bridge_mode_valid(struct drm_bridge *bridge,
11451 ++ const struct drm_display_info *info,
11452 ++ const struct drm_display_mode *mode)
11453 ++{
11454 ++ struct adv7511 *adv = bridge_to_adv7511(bridge);
11455 ++
11456 ++ if (adv->type == ADV7533 || adv->type == ADV7535)
11457 ++ return adv7533_mode_valid(adv, mode);
11458 ++ else
11459 ++ return adv7511_mode_valid(adv, mode);
11460 ++}
11461 ++
11462 + static int adv7511_bridge_attach(struct drm_bridge *bridge,
11463 + enum drm_bridge_attach_flags flags)
11464 + {
11465 +@@ -960,6 +969,7 @@ static const struct drm_bridge_funcs adv7511_bridge_funcs = {
11466 + .enable = adv7511_bridge_enable,
11467 + .disable = adv7511_bridge_disable,
11468 + .mode_set = adv7511_bridge_mode_set,
11469 ++ .mode_valid = adv7511_bridge_mode_valid,
11470 + .attach = adv7511_bridge_attach,
11471 + .detect = adv7511_bridge_detect,
11472 + .get_edid = adv7511_bridge_get_edid,
11473 +diff --git a/drivers/gpu/drm/bridge/adv7511/adv7533.c b/drivers/gpu/drm/bridge/adv7511/adv7533.c
11474 +index ef6270806d1d3..258c79d4dab0a 100644
11475 +--- a/drivers/gpu/drm/bridge/adv7511/adv7533.c
11476 ++++ b/drivers/gpu/drm/bridge/adv7511/adv7533.c
11477 +@@ -100,26 +100,27 @@ void adv7533_dsi_power_off(struct adv7511 *adv)
11478 + regmap_write(adv->regmap_cec, 0x27, 0x0b);
11479 + }
11480 +
11481 +-void adv7533_mode_set(struct adv7511 *adv, const struct drm_display_mode *mode)
11482 ++enum drm_mode_status adv7533_mode_valid(struct adv7511 *adv,
11483 ++ const struct drm_display_mode *mode)
11484 + {
11485 ++ int lanes;
11486 + struct mipi_dsi_device *dsi = adv->dsi;
11487 +- int lanes, ret;
11488 +-
11489 +- if (adv->num_dsi_lanes != 4)
11490 +- return;
11491 +
11492 + if (mode->clock > 80000)
11493 + lanes = 4;
11494 + else
11495 + lanes = 3;
11496 +
11497 +- if (lanes != dsi->lanes) {
11498 +- mipi_dsi_detach(dsi);
11499 +- dsi->lanes = lanes;
11500 +- ret = mipi_dsi_attach(dsi);
11501 +- if (ret)
11502 +- dev_err(&dsi->dev, "failed to change host lanes\n");
11503 +- }
11504 ++ /*
11505 ++ * TODO: add support for dynamic switching of lanes
11506 ++ * by using the bridge pre_enable() op . Till then filter
11507 ++ * out the modes which shall need different number of lanes
11508 ++ * than what was configured in the device tree.
11509 ++ */
11510 ++ if (lanes != dsi->lanes)
11511 ++ return MODE_BAD;
11512 ++
11513 ++ return MODE_OK;
11514 + }
11515 +
11516 + int adv7533_patch_registers(struct adv7511 *adv)
11517 +diff --git a/drivers/gpu/drm/bridge/ite-it6505.c b/drivers/gpu/drm/bridge/ite-it6505.c
11518 +index a09d1a39ab0ae..711f403afe7ce 100644
11519 +--- a/drivers/gpu/drm/bridge/ite-it6505.c
11520 ++++ b/drivers/gpu/drm/bridge/ite-it6505.c
11521 +@@ -2854,10 +2854,7 @@ static int it6505_bridge_attach(struct drm_bridge *bridge,
11522 + }
11523 +
11524 + /* Register aux channel */
11525 +- it6505->aux.name = "DP-AUX";
11526 +- it6505->aux.dev = dev;
11527 + it6505->aux.drm_dev = bridge->dev;
11528 +- it6505->aux.transfer = it6505_aux_transfer;
11529 +
11530 + ret = drm_dp_aux_register(&it6505->aux);
11531 +
11532 +@@ -3310,6 +3307,11 @@ static int it6505_i2c_probe(struct i2c_client *client,
11533 + DRM_DEV_DEBUG_DRIVER(dev, "it6505 device name: %s", dev_name(dev));
11534 + debugfs_init(it6505);
11535 +
11536 ++ it6505->aux.name = "DP-AUX";
11537 ++ it6505->aux.dev = dev;
11538 ++ it6505->aux.transfer = it6505_aux_transfer;
11539 ++ drm_dp_aux_init(&it6505->aux);
11540 ++
11541 + it6505->bridge.funcs = &it6505_bridge_funcs;
11542 + it6505->bridge.type = DRM_MODE_CONNECTOR_DisplayPort;
11543 + it6505->bridge.ops = DRM_BRIDGE_OP_DETECT | DRM_BRIDGE_OP_EDID |
11544 +diff --git a/drivers/gpu/drm/drm_atomic_helper.c b/drivers/gpu/drm/drm_atomic_helper.c
11545 +index 8bf41aa240687..6526d6ade04bf 100644
11546 +--- a/drivers/gpu/drm/drm_atomic_helper.c
11547 ++++ b/drivers/gpu/drm/drm_atomic_helper.c
11548 +@@ -899,7 +899,6 @@ int drm_atomic_helper_check_crtc_state(struct drm_crtc_state *crtc_state,
11549 + bool can_disable_primary_planes)
11550 + {
11551 + struct drm_device *dev = crtc_state->crtc->dev;
11552 +- struct drm_atomic_state *state = crtc_state->state;
11553 +
11554 + if (!crtc_state->enable)
11555 + return 0;
11556 +@@ -910,14 +909,7 @@ int drm_atomic_helper_check_crtc_state(struct drm_crtc_state *crtc_state,
11557 + struct drm_plane *plane;
11558 +
11559 + drm_for_each_plane_mask(plane, dev, crtc_state->plane_mask) {
11560 +- struct drm_plane_state *plane_state;
11561 +-
11562 +- if (plane->type != DRM_PLANE_TYPE_PRIMARY)
11563 +- continue;
11564 +- plane_state = drm_atomic_get_plane_state(state, plane);
11565 +- if (IS_ERR(plane_state))
11566 +- return PTR_ERR(plane_state);
11567 +- if (plane_state->fb && plane_state->crtc) {
11568 ++ if (plane->type == DRM_PLANE_TYPE_PRIMARY) {
11569 + has_primary_plane = true;
11570 + break;
11571 + }
11572 +diff --git a/drivers/gpu/drm/drm_edid.c b/drivers/gpu/drm/drm_edid.c
11573 +index eaa819381281b..fefcfac999d99 100644
11574 +--- a/drivers/gpu/drm/drm_edid.c
11575 ++++ b/drivers/gpu/drm/drm_edid.c
11576 +@@ -87,6 +87,8 @@ static int oui(u8 first, u8 second, u8 third)
11577 + #define EDID_QUIRK_FORCE_10BPC (1 << 11)
11578 + /* Non desktop display (i.e. HMD) */
11579 + #define EDID_QUIRK_NON_DESKTOP (1 << 12)
11580 ++/* Cap the DSC target bitrate to 15bpp */
11581 ++#define EDID_QUIRK_CAP_DSC_15BPP (1 << 13)
11582 +
11583 + #define MICROSOFT_IEEE_OUI 0xca125c
11584 +
11585 +@@ -147,6 +149,12 @@ static const struct edid_quirk {
11586 + EDID_QUIRK('F', 'C', 'M', 13600, EDID_QUIRK_PREFER_LARGE_75 |
11587 + EDID_QUIRK_DETAILED_IN_CM),
11588 +
11589 ++ /* LG 27GP950 */
11590 ++ EDID_QUIRK('G', 'S', 'M', 0x5bbf, EDID_QUIRK_CAP_DSC_15BPP),
11591 ++
11592 ++ /* LG 27GN950 */
11593 ++ EDID_QUIRK('G', 'S', 'M', 0x5b9a, EDID_QUIRK_CAP_DSC_15BPP),
11594 ++
11595 + /* LGD panel of HP zBook 17 G2, eDP 10 bpc, but reports unknown bpc */
11596 + EDID_QUIRK('L', 'G', 'D', 764, EDID_QUIRK_FORCE_10BPC),
11597 +
11598 +@@ -6116,6 +6124,7 @@ static void drm_reset_display_info(struct drm_connector *connector)
11599 +
11600 + info->mso_stream_count = 0;
11601 + info->mso_pixel_overlap = 0;
11602 ++ info->max_dsc_bpp = 0;
11603 + }
11604 +
11605 + static u32 update_display_info(struct drm_connector *connector,
11606 +@@ -6202,6 +6211,9 @@ out:
11607 + info->non_desktop = true;
11608 + }
11609 +
11610 ++ if (quirks & EDID_QUIRK_CAP_DSC_15BPP)
11611 ++ info->max_dsc_bpp = 15;
11612 ++
11613 + return quirks;
11614 + }
11615 +
11616 +diff --git a/drivers/gpu/drm/drm_fourcc.c b/drivers/gpu/drm/drm_fourcc.c
11617 +index 07741b678798b..6768b7d18b6fb 100644
11618 +--- a/drivers/gpu/drm/drm_fourcc.c
11619 ++++ b/drivers/gpu/drm/drm_fourcc.c
11620 +@@ -263,12 +263,12 @@ const struct drm_format_info *__drm_format_info(u32 format)
11621 + .vsub = 2, .is_yuv = true },
11622 + { .format = DRM_FORMAT_Q410, .depth = 0,
11623 + .num_planes = 3, .char_per_block = { 2, 2, 2 },
11624 +- .block_w = { 1, 1, 1 }, .block_h = { 1, 1, 1 }, .hsub = 0,
11625 +- .vsub = 0, .is_yuv = true },
11626 ++ .block_w = { 1, 1, 1 }, .block_h = { 1, 1, 1 }, .hsub = 1,
11627 ++ .vsub = 1, .is_yuv = true },
11628 + { .format = DRM_FORMAT_Q401, .depth = 0,
11629 + .num_planes = 3, .char_per_block = { 2, 2, 2 },
11630 +- .block_w = { 1, 1, 1 }, .block_h = { 1, 1, 1 }, .hsub = 0,
11631 +- .vsub = 0, .is_yuv = true },
11632 ++ .block_w = { 1, 1, 1 }, .block_h = { 1, 1, 1 }, .hsub = 1,
11633 ++ .vsub = 1, .is_yuv = true },
11634 + { .format = DRM_FORMAT_P030, .depth = 0, .num_planes = 2,
11635 + .char_per_block = { 4, 8, 0 }, .block_w = { 3, 3, 0 }, .block_h = { 1, 1, 0 },
11636 + .hsub = 2, .vsub = 2, .is_yuv = true},
11637 +diff --git a/drivers/gpu/drm/etnaviv/etnaviv_gpu.c b/drivers/gpu/drm/etnaviv/etnaviv_gpu.c
11638 +index 37018bc55810d..f667e7906d1f4 100644
11639 +--- a/drivers/gpu/drm/etnaviv/etnaviv_gpu.c
11640 ++++ b/drivers/gpu/drm/etnaviv/etnaviv_gpu.c
11641 +@@ -416,6 +416,12 @@ static void etnaviv_hw_identify(struct etnaviv_gpu *gpu)
11642 + if (gpu->identity.model == chipModel_GC700)
11643 + gpu->identity.features &= ~chipFeatures_FAST_CLEAR;
11644 +
11645 ++ /* These models/revisions don't have the 2D pipe bit */
11646 ++ if ((gpu->identity.model == chipModel_GC500 &&
11647 ++ gpu->identity.revision <= 2) ||
11648 ++ gpu->identity.model == chipModel_GC300)
11649 ++ gpu->identity.features |= chipFeatures_PIPE_2D;
11650 ++
11651 + if ((gpu->identity.model == chipModel_GC500 &&
11652 + gpu->identity.revision < 2) ||
11653 + (gpu->identity.model == chipModel_GC300 &&
11654 +@@ -449,8 +455,9 @@ static void etnaviv_hw_identify(struct etnaviv_gpu *gpu)
11655 + gpu_read(gpu, VIVS_HI_CHIP_MINOR_FEATURE_5);
11656 + }
11657 +
11658 +- /* GC600 idle register reports zero bits where modules aren't present */
11659 +- if (gpu->identity.model == chipModel_GC600)
11660 ++ /* GC600/300 idle register reports zero bits where modules aren't present */
11661 ++ if (gpu->identity.model == chipModel_GC600 ||
11662 ++ gpu->identity.model == chipModel_GC300)
11663 + gpu->idle_mask = VIVS_HI_IDLE_STATE_TX |
11664 + VIVS_HI_IDLE_STATE_RA |
11665 + VIVS_HI_IDLE_STATE_SE |
11666 +diff --git a/drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_rgb.c b/drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_rgb.c
11667 +index 4d4a715b429d1..2c2b92324a2e9 100644
11668 +--- a/drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_rgb.c
11669 ++++ b/drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_rgb.c
11670 +@@ -60,8 +60,9 @@ static int fsl_dcu_drm_connector_get_modes(struct drm_connector *connector)
11671 + return drm_panel_get_modes(fsl_connector->panel, connector);
11672 + }
11673 +
11674 +-static int fsl_dcu_drm_connector_mode_valid(struct drm_connector *connector,
11675 +- struct drm_display_mode *mode)
11676 ++static enum drm_mode_status
11677 ++fsl_dcu_drm_connector_mode_valid(struct drm_connector *connector,
11678 ++ struct drm_display_mode *mode)
11679 + {
11680 + if (mode->hdisplay & 0xf)
11681 + return MODE_ERROR;
11682 +diff --git a/drivers/gpu/drm/i915/display/intel_bios.c b/drivers/gpu/drm/i915/display/intel_bios.c
11683 +index 459571e2cc575..2bfcfbfa52a4f 100644
11684 +--- a/drivers/gpu/drm/i915/display/intel_bios.c
11685 ++++ b/drivers/gpu/drm/i915/display/intel_bios.c
11686 +@@ -414,7 +414,7 @@ static void *generate_lfp_data_ptrs(struct drm_i915_private *i915,
11687 + ptrs->lvds_entries++;
11688 +
11689 + if (size != 0 || ptrs->lvds_entries != 3) {
11690 +- kfree(ptrs);
11691 ++ kfree(ptrs_block);
11692 + return NULL;
11693 + }
11694 +
11695 +diff --git a/drivers/gpu/drm/i915/display/intel_dp.c b/drivers/gpu/drm/i915/display/intel_dp.c
11696 +index 21ba510716b6c..d852cfd1d6eba 100644
11697 +--- a/drivers/gpu/drm/i915/display/intel_dp.c
11698 ++++ b/drivers/gpu/drm/i915/display/intel_dp.c
11699 +@@ -3641,61 +3641,6 @@ static void intel_dp_phy_pattern_update(struct intel_dp *intel_dp,
11700 + }
11701 + }
11702 +
11703 +-static void
11704 +-intel_dp_autotest_phy_ddi_disable(struct intel_dp *intel_dp,
11705 +- const struct intel_crtc_state *crtc_state)
11706 +-{
11707 +- struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
11708 +- struct drm_device *dev = dig_port->base.base.dev;
11709 +- struct drm_i915_private *dev_priv = to_i915(dev);
11710 +- struct intel_crtc *crtc = to_intel_crtc(dig_port->base.base.crtc);
11711 +- enum pipe pipe = crtc->pipe;
11712 +- u32 trans_ddi_func_ctl_value, trans_conf_value, dp_tp_ctl_value;
11713 +-
11714 +- trans_ddi_func_ctl_value = intel_de_read(dev_priv,
11715 +- TRANS_DDI_FUNC_CTL(pipe));
11716 +- trans_conf_value = intel_de_read(dev_priv, PIPECONF(pipe));
11717 +- dp_tp_ctl_value = intel_de_read(dev_priv, TGL_DP_TP_CTL(pipe));
11718 +-
11719 +- trans_ddi_func_ctl_value &= ~(TRANS_DDI_FUNC_ENABLE |
11720 +- TGL_TRANS_DDI_PORT_MASK);
11721 +- trans_conf_value &= ~PIPECONF_ENABLE;
11722 +- dp_tp_ctl_value &= ~DP_TP_CTL_ENABLE;
11723 +-
11724 +- intel_de_write(dev_priv, PIPECONF(pipe), trans_conf_value);
11725 +- intel_de_write(dev_priv, TRANS_DDI_FUNC_CTL(pipe),
11726 +- trans_ddi_func_ctl_value);
11727 +- intel_de_write(dev_priv, TGL_DP_TP_CTL(pipe), dp_tp_ctl_value);
11728 +-}
11729 +-
11730 +-static void
11731 +-intel_dp_autotest_phy_ddi_enable(struct intel_dp *intel_dp,
11732 +- const struct intel_crtc_state *crtc_state)
11733 +-{
11734 +- struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
11735 +- struct drm_device *dev = dig_port->base.base.dev;
11736 +- struct drm_i915_private *dev_priv = to_i915(dev);
11737 +- enum port port = dig_port->base.port;
11738 +- struct intel_crtc *crtc = to_intel_crtc(dig_port->base.base.crtc);
11739 +- enum pipe pipe = crtc->pipe;
11740 +- u32 trans_ddi_func_ctl_value, trans_conf_value, dp_tp_ctl_value;
11741 +-
11742 +- trans_ddi_func_ctl_value = intel_de_read(dev_priv,
11743 +- TRANS_DDI_FUNC_CTL(pipe));
11744 +- trans_conf_value = intel_de_read(dev_priv, PIPECONF(pipe));
11745 +- dp_tp_ctl_value = intel_de_read(dev_priv, TGL_DP_TP_CTL(pipe));
11746 +-
11747 +- trans_ddi_func_ctl_value |= TRANS_DDI_FUNC_ENABLE |
11748 +- TGL_TRANS_DDI_SELECT_PORT(port);
11749 +- trans_conf_value |= PIPECONF_ENABLE;
11750 +- dp_tp_ctl_value |= DP_TP_CTL_ENABLE;
11751 +-
11752 +- intel_de_write(dev_priv, PIPECONF(pipe), trans_conf_value);
11753 +- intel_de_write(dev_priv, TGL_DP_TP_CTL(pipe), dp_tp_ctl_value);
11754 +- intel_de_write(dev_priv, TRANS_DDI_FUNC_CTL(pipe),
11755 +- trans_ddi_func_ctl_value);
11756 +-}
11757 +-
11758 + static void intel_dp_process_phy_request(struct intel_dp *intel_dp,
11759 + const struct intel_crtc_state *crtc_state)
11760 + {
11761 +@@ -3714,14 +3659,10 @@ static void intel_dp_process_phy_request(struct intel_dp *intel_dp,
11762 + intel_dp_get_adjust_train(intel_dp, crtc_state, DP_PHY_DPRX,
11763 + link_status);
11764 +
11765 +- intel_dp_autotest_phy_ddi_disable(intel_dp, crtc_state);
11766 +-
11767 + intel_dp_set_signal_levels(intel_dp, crtc_state, DP_PHY_DPRX);
11768 +
11769 + intel_dp_phy_pattern_update(intel_dp, crtc_state);
11770 +
11771 +- intel_dp_autotest_phy_ddi_enable(intel_dp, crtc_state);
11772 +-
11773 + drm_dp_dpcd_write(&intel_dp->aux, DP_TRAINING_LANE0_SET,
11774 + intel_dp->train_set, crtc_state->lane_count);
11775 +
11776 +diff --git a/drivers/gpu/drm/i915/gt/intel_engine.h b/drivers/gpu/drm/i915/gt/intel_engine.h
11777 +index 04e435bce79bd..cbc8b857d5f7a 100644
11778 +--- a/drivers/gpu/drm/i915/gt/intel_engine.h
11779 ++++ b/drivers/gpu/drm/i915/gt/intel_engine.h
11780 +@@ -348,4 +348,10 @@ intel_engine_get_hung_context(struct intel_engine_cs *engine)
11781 + return engine->hung_ce;
11782 + }
11783 +
11784 ++u64 intel_clamp_heartbeat_interval_ms(struct intel_engine_cs *engine, u64 value);
11785 ++u64 intel_clamp_max_busywait_duration_ns(struct intel_engine_cs *engine, u64 value);
11786 ++u64 intel_clamp_preempt_timeout_ms(struct intel_engine_cs *engine, u64 value);
11787 ++u64 intel_clamp_stop_timeout_ms(struct intel_engine_cs *engine, u64 value);
11788 ++u64 intel_clamp_timeslice_duration_ms(struct intel_engine_cs *engine, u64 value);
11789 ++
11790 + #endif /* _INTEL_RINGBUFFER_H_ */
11791 +diff --git a/drivers/gpu/drm/i915/gt/intel_engine_cs.c b/drivers/gpu/drm/i915/gt/intel_engine_cs.c
11792 +index 37fa813af7661..3dd0af057e6b1 100644
11793 +--- a/drivers/gpu/drm/i915/gt/intel_engine_cs.c
11794 ++++ b/drivers/gpu/drm/i915/gt/intel_engine_cs.c
11795 +@@ -486,6 +486,17 @@ static int intel_engine_setup(struct intel_gt *gt, enum intel_engine_id id,
11796 + engine->logical_mask = BIT(logical_instance);
11797 + __sprint_engine_name(engine);
11798 +
11799 ++ if ((engine->class == COMPUTE_CLASS && !RCS_MASK(engine->gt) &&
11800 ++ __ffs(CCS_MASK(engine->gt)) == engine->instance) ||
11801 ++ engine->class == RENDER_CLASS)
11802 ++ engine->flags |= I915_ENGINE_FIRST_RENDER_COMPUTE;
11803 ++
11804 ++ /* features common between engines sharing EUs */
11805 ++ if (engine->class == RENDER_CLASS || engine->class == COMPUTE_CLASS) {
11806 ++ engine->flags |= I915_ENGINE_HAS_RCS_REG_STATE;
11807 ++ engine->flags |= I915_ENGINE_HAS_EU_PRIORITY;
11808 ++ }
11809 ++
11810 + engine->props.heartbeat_interval_ms =
11811 + CONFIG_DRM_I915_HEARTBEAT_INTERVAL;
11812 + engine->props.max_busywait_duration_ns =
11813 +@@ -498,19 +509,28 @@ static int intel_engine_setup(struct intel_gt *gt, enum intel_engine_id id,
11814 + CONFIG_DRM_I915_TIMESLICE_DURATION;
11815 +
11816 + /* Override to uninterruptible for OpenCL workloads. */
11817 +- if (GRAPHICS_VER(i915) == 12 && engine->class == RENDER_CLASS)
11818 ++ if (GRAPHICS_VER(i915) == 12 && (engine->flags & I915_ENGINE_HAS_RCS_REG_STATE))
11819 + engine->props.preempt_timeout_ms = 0;
11820 +
11821 +- if ((engine->class == COMPUTE_CLASS && !RCS_MASK(engine->gt) &&
11822 +- __ffs(CCS_MASK(engine->gt)) == engine->instance) ||
11823 +- engine->class == RENDER_CLASS)
11824 +- engine->flags |= I915_ENGINE_FIRST_RENDER_COMPUTE;
11825 +-
11826 +- /* features common between engines sharing EUs */
11827 +- if (engine->class == RENDER_CLASS || engine->class == COMPUTE_CLASS) {
11828 +- engine->flags |= I915_ENGINE_HAS_RCS_REG_STATE;
11829 +- engine->flags |= I915_ENGINE_HAS_EU_PRIORITY;
11830 +- }
11831 ++ /* Cap properties according to any system limits */
11832 ++#define CLAMP_PROP(field) \
11833 ++ do { \
11834 ++ u64 clamp = intel_clamp_##field(engine, engine->props.field); \
11835 ++ if (clamp != engine->props.field) { \
11836 ++ drm_notice(&engine->i915->drm, \
11837 ++ "Warning, clamping %s to %lld to prevent overflow\n", \
11838 ++ #field, clamp); \
11839 ++ engine->props.field = clamp; \
11840 ++ } \
11841 ++ } while (0)
11842 ++
11843 ++ CLAMP_PROP(heartbeat_interval_ms);
11844 ++ CLAMP_PROP(max_busywait_duration_ns);
11845 ++ CLAMP_PROP(preempt_timeout_ms);
11846 ++ CLAMP_PROP(stop_timeout_ms);
11847 ++ CLAMP_PROP(timeslice_duration_ms);
11848 ++
11849 ++#undef CLAMP_PROP
11850 +
11851 + engine->defaults = engine->props; /* never to change again */
11852 +
11853 +@@ -534,6 +554,55 @@ static int intel_engine_setup(struct intel_gt *gt, enum intel_engine_id id,
11854 + return 0;
11855 + }
11856 +
11857 ++u64 intel_clamp_heartbeat_interval_ms(struct intel_engine_cs *engine, u64 value)
11858 ++{
11859 ++ value = min_t(u64, value, jiffies_to_msecs(MAX_SCHEDULE_TIMEOUT));
11860 ++
11861 ++ return value;
11862 ++}
11863 ++
11864 ++u64 intel_clamp_max_busywait_duration_ns(struct intel_engine_cs *engine, u64 value)
11865 ++{
11866 ++ value = min(value, jiffies_to_nsecs(2));
11867 ++
11868 ++ return value;
11869 ++}
11870 ++
11871 ++u64 intel_clamp_preempt_timeout_ms(struct intel_engine_cs *engine, u64 value)
11872 ++{
11873 ++ /*
11874 ++ * NB: The GuC API only supports 32bit values. However, the limit is further
11875 ++ * reduced due to internal calculations which would otherwise overflow.
11876 ++ */
11877 ++ if (intel_guc_submission_is_wanted(&engine->gt->uc.guc))
11878 ++ value = min_t(u64, value, guc_policy_max_preempt_timeout_ms());
11879 ++
11880 ++ value = min_t(u64, value, jiffies_to_msecs(MAX_SCHEDULE_TIMEOUT));
11881 ++
11882 ++ return value;
11883 ++}
11884 ++
11885 ++u64 intel_clamp_stop_timeout_ms(struct intel_engine_cs *engine, u64 value)
11886 ++{
11887 ++ value = min_t(u64, value, jiffies_to_msecs(MAX_SCHEDULE_TIMEOUT));
11888 ++
11889 ++ return value;
11890 ++}
11891 ++
11892 ++u64 intel_clamp_timeslice_duration_ms(struct intel_engine_cs *engine, u64 value)
11893 ++{
11894 ++ /*
11895 ++ * NB: The GuC API only supports 32bit values. However, the limit is further
11896 ++ * reduced due to internal calculations which would otherwise overflow.
11897 ++ */
11898 ++ if (intel_guc_submission_is_wanted(&engine->gt->uc.guc))
11899 ++ value = min_t(u64, value, guc_policy_max_exec_quantum_ms());
11900 ++
11901 ++ value = min_t(u64, value, jiffies_to_msecs(MAX_SCHEDULE_TIMEOUT));
11902 ++
11903 ++ return value;
11904 ++}
11905 ++
11906 + static void __setup_engine_capabilities(struct intel_engine_cs *engine)
11907 + {
11908 + struct drm_i915_private *i915 = engine->i915;
11909 +diff --git a/drivers/gpu/drm/i915/gt/sysfs_engines.c b/drivers/gpu/drm/i915/gt/sysfs_engines.c
11910 +index 9670310562029..f2d9858d827c2 100644
11911 +--- a/drivers/gpu/drm/i915/gt/sysfs_engines.c
11912 ++++ b/drivers/gpu/drm/i915/gt/sysfs_engines.c
11913 +@@ -144,7 +144,7 @@ max_spin_store(struct kobject *kobj, struct kobj_attribute *attr,
11914 + const char *buf, size_t count)
11915 + {
11916 + struct intel_engine_cs *engine = kobj_to_engine(kobj);
11917 +- unsigned long long duration;
11918 ++ unsigned long long duration, clamped;
11919 + int err;
11920 +
11921 + /*
11922 +@@ -168,7 +168,8 @@ max_spin_store(struct kobject *kobj, struct kobj_attribute *attr,
11923 + if (err)
11924 + return err;
11925 +
11926 +- if (duration > jiffies_to_nsecs(2))
11927 ++ clamped = intel_clamp_max_busywait_duration_ns(engine, duration);
11928 ++ if (duration != clamped)
11929 + return -EINVAL;
11930 +
11931 + WRITE_ONCE(engine->props.max_busywait_duration_ns, duration);
11932 +@@ -203,7 +204,7 @@ timeslice_store(struct kobject *kobj, struct kobj_attribute *attr,
11933 + const char *buf, size_t count)
11934 + {
11935 + struct intel_engine_cs *engine = kobj_to_engine(kobj);
11936 +- unsigned long long duration;
11937 ++ unsigned long long duration, clamped;
11938 + int err;
11939 +
11940 + /*
11941 +@@ -218,7 +219,8 @@ timeslice_store(struct kobject *kobj, struct kobj_attribute *attr,
11942 + if (err)
11943 + return err;
11944 +
11945 +- if (duration > jiffies_to_msecs(MAX_SCHEDULE_TIMEOUT))
11946 ++ clamped = intel_clamp_timeslice_duration_ms(engine, duration);
11947 ++ if (duration != clamped)
11948 + return -EINVAL;
11949 +
11950 + WRITE_ONCE(engine->props.timeslice_duration_ms, duration);
11951 +@@ -256,7 +258,7 @@ stop_store(struct kobject *kobj, struct kobj_attribute *attr,
11952 + const char *buf, size_t count)
11953 + {
11954 + struct intel_engine_cs *engine = kobj_to_engine(kobj);
11955 +- unsigned long long duration;
11956 ++ unsigned long long duration, clamped;
11957 + int err;
11958 +
11959 + /*
11960 +@@ -272,7 +274,8 @@ stop_store(struct kobject *kobj, struct kobj_attribute *attr,
11961 + if (err)
11962 + return err;
11963 +
11964 +- if (duration > jiffies_to_msecs(MAX_SCHEDULE_TIMEOUT))
11965 ++ clamped = intel_clamp_stop_timeout_ms(engine, duration);
11966 ++ if (duration != clamped)
11967 + return -EINVAL;
11968 +
11969 + WRITE_ONCE(engine->props.stop_timeout_ms, duration);
11970 +@@ -306,7 +309,7 @@ preempt_timeout_store(struct kobject *kobj, struct kobj_attribute *attr,
11971 + const char *buf, size_t count)
11972 + {
11973 + struct intel_engine_cs *engine = kobj_to_engine(kobj);
11974 +- unsigned long long timeout;
11975 ++ unsigned long long timeout, clamped;
11976 + int err;
11977 +
11978 + /*
11979 +@@ -322,7 +325,8 @@ preempt_timeout_store(struct kobject *kobj, struct kobj_attribute *attr,
11980 + if (err)
11981 + return err;
11982 +
11983 +- if (timeout > jiffies_to_msecs(MAX_SCHEDULE_TIMEOUT))
11984 ++ clamped = intel_clamp_preempt_timeout_ms(engine, timeout);
11985 ++ if (timeout != clamped)
11986 + return -EINVAL;
11987 +
11988 + WRITE_ONCE(engine->props.preempt_timeout_ms, timeout);
11989 +@@ -362,7 +366,7 @@ heartbeat_store(struct kobject *kobj, struct kobj_attribute *attr,
11990 + const char *buf, size_t count)
11991 + {
11992 + struct intel_engine_cs *engine = kobj_to_engine(kobj);
11993 +- unsigned long long delay;
11994 ++ unsigned long long delay, clamped;
11995 + int err;
11996 +
11997 + /*
11998 +@@ -379,7 +383,8 @@ heartbeat_store(struct kobject *kobj, struct kobj_attribute *attr,
11999 + if (err)
12000 + return err;
12001 +
12002 +- if (delay >= jiffies_to_msecs(MAX_SCHEDULE_TIMEOUT))
12003 ++ clamped = intel_clamp_heartbeat_interval_ms(engine, delay);
12004 ++ if (delay != clamped)
12005 + return -EINVAL;
12006 +
12007 + err = intel_engine_set_heartbeat(engine, delay);
12008 +diff --git a/drivers/gpu/drm/i915/gt/uc/intel_guc.c b/drivers/gpu/drm/i915/gt/uc/intel_guc.c
12009 +index 2706a8c650900..7fbcfeda91951 100644
12010 +--- a/drivers/gpu/drm/i915/gt/uc/intel_guc.c
12011 ++++ b/drivers/gpu/drm/i915/gt/uc/intel_guc.c
12012 +@@ -224,53 +224,22 @@ static u32 guc_ctl_feature_flags(struct intel_guc *guc)
12013 +
12014 + static u32 guc_ctl_log_params_flags(struct intel_guc *guc)
12015 + {
12016 +- u32 offset = intel_guc_ggtt_offset(guc, guc->log.vma) >> PAGE_SHIFT;
12017 +- u32 flags;
12018 +-
12019 +- #if (((CRASH_BUFFER_SIZE) % SZ_1M) == 0)
12020 +- #define LOG_UNIT SZ_1M
12021 +- #define LOG_FLAG GUC_LOG_LOG_ALLOC_UNITS
12022 +- #else
12023 +- #define LOG_UNIT SZ_4K
12024 +- #define LOG_FLAG 0
12025 +- #endif
12026 +-
12027 +- #if (((CAPTURE_BUFFER_SIZE) % SZ_1M) == 0)
12028 +- #define CAPTURE_UNIT SZ_1M
12029 +- #define CAPTURE_FLAG GUC_LOG_CAPTURE_ALLOC_UNITS
12030 +- #else
12031 +- #define CAPTURE_UNIT SZ_4K
12032 +- #define CAPTURE_FLAG 0
12033 +- #endif
12034 +-
12035 +- BUILD_BUG_ON(!CRASH_BUFFER_SIZE);
12036 +- BUILD_BUG_ON(!IS_ALIGNED(CRASH_BUFFER_SIZE, LOG_UNIT));
12037 +- BUILD_BUG_ON(!DEBUG_BUFFER_SIZE);
12038 +- BUILD_BUG_ON(!IS_ALIGNED(DEBUG_BUFFER_SIZE, LOG_UNIT));
12039 +- BUILD_BUG_ON(!CAPTURE_BUFFER_SIZE);
12040 +- BUILD_BUG_ON(!IS_ALIGNED(CAPTURE_BUFFER_SIZE, CAPTURE_UNIT));
12041 +-
12042 +- BUILD_BUG_ON((CRASH_BUFFER_SIZE / LOG_UNIT - 1) >
12043 +- (GUC_LOG_CRASH_MASK >> GUC_LOG_CRASH_SHIFT));
12044 +- BUILD_BUG_ON((DEBUG_BUFFER_SIZE / LOG_UNIT - 1) >
12045 +- (GUC_LOG_DEBUG_MASK >> GUC_LOG_DEBUG_SHIFT));
12046 +- BUILD_BUG_ON((CAPTURE_BUFFER_SIZE / CAPTURE_UNIT - 1) >
12047 +- (GUC_LOG_CAPTURE_MASK >> GUC_LOG_CAPTURE_SHIFT));
12048 ++ struct intel_guc_log *log = &guc->log;
12049 ++ u32 offset, flags;
12050 ++
12051 ++ GEM_BUG_ON(!log->sizes_initialised);
12052 ++
12053 ++ offset = intel_guc_ggtt_offset(guc, log->vma) >> PAGE_SHIFT;
12054 +
12055 + flags = GUC_LOG_VALID |
12056 + GUC_LOG_NOTIFY_ON_HALF_FULL |
12057 +- CAPTURE_FLAG |
12058 +- LOG_FLAG |
12059 +- ((CRASH_BUFFER_SIZE / LOG_UNIT - 1) << GUC_LOG_CRASH_SHIFT) |
12060 +- ((DEBUG_BUFFER_SIZE / LOG_UNIT - 1) << GUC_LOG_DEBUG_SHIFT) |
12061 +- ((CAPTURE_BUFFER_SIZE / CAPTURE_UNIT - 1) << GUC_LOG_CAPTURE_SHIFT) |
12062 ++ log->sizes[GUC_LOG_SECTIONS_DEBUG].flag |
12063 ++ log->sizes[GUC_LOG_SECTIONS_CAPTURE].flag |
12064 ++ (log->sizes[GUC_LOG_SECTIONS_CRASH].count << GUC_LOG_CRASH_SHIFT) |
12065 ++ (log->sizes[GUC_LOG_SECTIONS_DEBUG].count << GUC_LOG_DEBUG_SHIFT) |
12066 ++ (log->sizes[GUC_LOG_SECTIONS_CAPTURE].count << GUC_LOG_CAPTURE_SHIFT) |
12067 + (offset << GUC_LOG_BUF_ADDR_SHIFT);
12068 +
12069 +- #undef LOG_UNIT
12070 +- #undef LOG_FLAG
12071 +- #undef CAPTURE_UNIT
12072 +- #undef CAPTURE_FLAG
12073 +-
12074 + return flags;
12075 + }
12076 +
12077 +diff --git a/drivers/gpu/drm/i915/gt/uc/intel_guc_capture.c b/drivers/gpu/drm/i915/gt/uc/intel_guc_capture.c
12078 +index 75257bd20ff01..4c51888fd78b4 100644
12079 +--- a/drivers/gpu/drm/i915/gt/uc/intel_guc_capture.c
12080 ++++ b/drivers/gpu/drm/i915/gt/uc/intel_guc_capture.c
12081 +@@ -165,7 +165,7 @@ static const struct __guc_mmio_reg_descr empty_regs_list[] = {
12082 + }
12083 +
12084 + /* List of lists */
12085 +-static struct __guc_mmio_reg_descr_group default_lists[] = {
12086 ++static const struct __guc_mmio_reg_descr_group default_lists[] = {
12087 + MAKE_REGLIST(default_global_regs, PF, GLOBAL, 0),
12088 + MAKE_REGLIST(default_rc_class_regs, PF, ENGINE_CLASS, GUC_RENDER_CLASS),
12089 + MAKE_REGLIST(xe_lpd_rc_inst_regs, PF, ENGINE_INSTANCE, GUC_RENDER_CLASS),
12090 +@@ -419,6 +419,44 @@ guc_capture_get_device_reglist(struct intel_guc *guc)
12091 + return default_lists;
12092 + }
12093 +
12094 ++static const char *
12095 ++__stringify_type(u32 type)
12096 ++{
12097 ++ switch (type) {
12098 ++ case GUC_CAPTURE_LIST_TYPE_GLOBAL:
12099 ++ return "Global";
12100 ++ case GUC_CAPTURE_LIST_TYPE_ENGINE_CLASS:
12101 ++ return "Class";
12102 ++ case GUC_CAPTURE_LIST_TYPE_ENGINE_INSTANCE:
12103 ++ return "Instance";
12104 ++ default:
12105 ++ break;
12106 ++ }
12107 ++
12108 ++ return "unknown";
12109 ++}
12110 ++
12111 ++static const char *
12112 ++__stringify_engclass(u32 class)
12113 ++{
12114 ++ switch (class) {
12115 ++ case GUC_RENDER_CLASS:
12116 ++ return "Render";
12117 ++ case GUC_VIDEO_CLASS:
12118 ++ return "Video";
12119 ++ case GUC_VIDEOENHANCE_CLASS:
12120 ++ return "VideoEnhance";
12121 ++ case GUC_BLITTER_CLASS:
12122 ++ return "Blitter";
12123 ++ case GUC_COMPUTE_CLASS:
12124 ++ return "Compute";
12125 ++ default:
12126 ++ break;
12127 ++ }
12128 ++
12129 ++ return "unknown";
12130 ++}
12131 ++
12132 + static int
12133 + guc_capture_list_init(struct intel_guc *guc, u32 owner, u32 type, u32 classid,
12134 + struct guc_mmio_reg *ptr, u16 num_entries)
12135 +@@ -482,32 +520,55 @@ guc_cap_list_num_regs(struct intel_guc_state_capture *gc, u32 owner, u32 type, u
12136 + return num_regs;
12137 + }
12138 +
12139 +-int
12140 +-intel_guc_capture_getlistsize(struct intel_guc *guc, u32 owner, u32 type, u32 classid,
12141 +- size_t *size)
12142 ++static int
12143 ++guc_capture_getlistsize(struct intel_guc *guc, u32 owner, u32 type, u32 classid,
12144 ++ size_t *size, bool is_purpose_est)
12145 + {
12146 + struct intel_guc_state_capture *gc = guc->capture;
12147 ++ struct drm_i915_private *i915 = guc_to_gt(guc)->i915;
12148 + struct __guc_capture_ads_cache *cache = &gc->ads_cache[owner][type][classid];
12149 + int num_regs;
12150 +
12151 +- if (!gc->reglists)
12152 ++ if (!gc->reglists) {
12153 ++ drm_warn(&i915->drm, "GuC-capture: No reglist on this device\n");
12154 + return -ENODEV;
12155 ++ }
12156 +
12157 + if (cache->is_valid) {
12158 + *size = cache->size;
12159 + return cache->status;
12160 + }
12161 +
12162 ++ if (!is_purpose_est && owner == GUC_CAPTURE_LIST_INDEX_PF &&
12163 ++ !guc_capture_get_one_list(gc->reglists, owner, type, classid)) {
12164 ++ if (type == GUC_CAPTURE_LIST_TYPE_GLOBAL)
12165 ++ drm_warn(&i915->drm, "Missing GuC-Err-Cap reglist Global!\n");
12166 ++ else
12167 ++ drm_warn(&i915->drm, "Missing GuC-Err-Cap reglist %s(%u):%s(%u)!\n",
12168 ++ __stringify_type(type), type,
12169 ++ __stringify_engclass(classid), classid);
12170 ++ return -ENODATA;
12171 ++ }
12172 ++
12173 + num_regs = guc_cap_list_num_regs(gc, owner, type, classid);
12174 ++ /* intentional empty lists can exist depending on hw config */
12175 + if (!num_regs)
12176 + return -ENODATA;
12177 +
12178 +- *size = PAGE_ALIGN((sizeof(struct guc_debug_capture_list)) +
12179 +- (num_regs * sizeof(struct guc_mmio_reg)));
12180 ++ if (size)
12181 ++ *size = PAGE_ALIGN((sizeof(struct guc_debug_capture_list)) +
12182 ++ (num_regs * sizeof(struct guc_mmio_reg)));
12183 +
12184 + return 0;
12185 + }
12186 +
12187 ++int
12188 ++intel_guc_capture_getlistsize(struct intel_guc *guc, u32 owner, u32 type, u32 classid,
12189 ++ size_t *size)
12190 ++{
12191 ++ return guc_capture_getlistsize(guc, owner, type, classid, size, false);
12192 ++}
12193 ++
12194 + static void guc_capture_create_prealloc_nodes(struct intel_guc *guc);
12195 +
12196 + int
12197 +@@ -600,15 +661,13 @@ intel_guc_capture_getnullheader(struct intel_guc *guc,
12198 + return 0;
12199 + }
12200 +
12201 +-#define GUC_CAPTURE_OVERBUFFER_MULTIPLIER 3
12202 +-
12203 +-int
12204 +-intel_guc_capture_output_min_size_est(struct intel_guc *guc)
12205 ++static int
12206 ++guc_capture_output_min_size_est(struct intel_guc *guc)
12207 + {
12208 + struct intel_gt *gt = guc_to_gt(guc);
12209 + struct intel_engine_cs *engine;
12210 + enum intel_engine_id id;
12211 +- int worst_min_size = 0, num_regs = 0;
12212 ++ int worst_min_size = 0;
12213 + size_t tmp = 0;
12214 +
12215 + if (!guc->capture)
12216 +@@ -623,33 +682,58 @@ intel_guc_capture_output_min_size_est(struct intel_guc *guc)
12217 + * For each engine instance, there would be 1 x guc_state_capture_group_t output
12218 + * followed by 3 x guc_state_capture_t lists. The latter is how the register
12219 + * dumps are split across different register types (where the '3' are global vs class
12220 +- * vs instance). Finally, let's multiply the whole thing by 3x (just so we are
12221 +- * not limited to just 1 round of data in a worst case full register dump log)
12222 +- *
12223 +- * NOTE: intel_guc_log that allocates the log buffer would round this size up to
12224 +- * a power of two.
12225 ++ * vs instance).
12226 + */
12227 +-
12228 + for_each_engine(engine, gt, id) {
12229 + worst_min_size += sizeof(struct guc_state_capture_group_header_t) +
12230 + (3 * sizeof(struct guc_state_capture_header_t));
12231 +
12232 +- if (!intel_guc_capture_getlistsize(guc, 0, GUC_CAPTURE_LIST_TYPE_GLOBAL, 0, &tmp))
12233 +- num_regs += tmp;
12234 ++ if (!guc_capture_getlistsize(guc, 0, GUC_CAPTURE_LIST_TYPE_GLOBAL, 0, &tmp, true))
12235 ++ worst_min_size += tmp;
12236 +
12237 +- if (!intel_guc_capture_getlistsize(guc, 0, GUC_CAPTURE_LIST_TYPE_ENGINE_CLASS,
12238 +- engine->class, &tmp)) {
12239 +- num_regs += tmp;
12240 ++ if (!guc_capture_getlistsize(guc, 0, GUC_CAPTURE_LIST_TYPE_ENGINE_CLASS,
12241 ++ engine->class, &tmp, true)) {
12242 ++ worst_min_size += tmp;
12243 + }
12244 +- if (!intel_guc_capture_getlistsize(guc, 0, GUC_CAPTURE_LIST_TYPE_ENGINE_INSTANCE,
12245 +- engine->class, &tmp)) {
12246 +- num_regs += tmp;
12247 ++ if (!guc_capture_getlistsize(guc, 0, GUC_CAPTURE_LIST_TYPE_ENGINE_INSTANCE,
12248 ++ engine->class, &tmp, true)) {
12249 ++ worst_min_size += tmp;
12250 + }
12251 + }
12252 +
12253 +- worst_min_size += (num_regs * sizeof(struct guc_mmio_reg));
12254 ++ return worst_min_size;
12255 ++}
12256 ++
12257 ++/*
12258 ++ * Add on a 3x multiplier to allow for multiple back-to-back captures occurring
12259 ++ * before the i915 can read the data out and process it
12260 ++ */
12261 ++#define GUC_CAPTURE_OVERBUFFER_MULTIPLIER 3
12262 +
12263 +- return (worst_min_size * GUC_CAPTURE_OVERBUFFER_MULTIPLIER);
12264 ++static void check_guc_capture_size(struct intel_guc *guc)
12265 ++{
12266 ++ struct drm_i915_private *i915 = guc_to_gt(guc)->i915;
12267 ++ int min_size = guc_capture_output_min_size_est(guc);
12268 ++ int spare_size = min_size * GUC_CAPTURE_OVERBUFFER_MULTIPLIER;
12269 ++ u32 buffer_size = intel_guc_log_section_size_capture(&guc->log);
12270 ++
12271 ++ /*
12272 ++ * NOTE: min_size is much smaller than the capture region allocation (DG2: <80K vs 1MB)
12273 ++ * Additionally, its based on space needed to fit all engines getting reset at once
12274 ++ * within the same G2H handler task slot. This is very unlikely. However, if GuC really
12275 ++ * does run out of space for whatever reason, we will see an separate warning message
12276 ++ * when processing the G2H event capture-notification, search for:
12277 ++ * INTEL_GUC_STATE_CAPTURE_EVENT_STATUS_NOSPACE.
12278 ++ */
12279 ++ if (min_size < 0)
12280 ++ drm_warn(&i915->drm, "Failed to calculate GuC error state capture buffer minimum size: %d!\n",
12281 ++ min_size);
12282 ++ else if (min_size > buffer_size)
12283 ++ drm_warn(&i915->drm, "GuC error state capture buffer maybe small: %d < %d\n",
12284 ++ buffer_size, min_size);
12285 ++ else if (spare_size > buffer_size)
12286 ++ drm_dbg(&i915->drm, "GuC error state capture buffer lacks spare size: %d < %d (min = %d)\n",
12287 ++ buffer_size, spare_size, min_size);
12288 + }
12289 +
12290 + /*
12291 +@@ -1278,7 +1362,8 @@ static void __guc_capture_process_output(struct intel_guc *guc)
12292 +
12293 + log_buf_state = guc->log.buf_addr +
12294 + (sizeof(struct guc_log_buffer_state) * GUC_CAPTURE_LOG_BUFFER);
12295 +- src_data = guc->log.buf_addr + intel_guc_get_log_buffer_offset(GUC_CAPTURE_LOG_BUFFER);
12296 ++ src_data = guc->log.buf_addr +
12297 ++ intel_guc_get_log_buffer_offset(&guc->log, GUC_CAPTURE_LOG_BUFFER);
12298 +
12299 + /*
12300 + * Make a copy of the state structure, inside GuC log buffer
12301 +@@ -1286,7 +1371,7 @@ static void __guc_capture_process_output(struct intel_guc *guc)
12302 + * from it multiple times.
12303 + */
12304 + memcpy(&log_buf_state_local, log_buf_state, sizeof(struct guc_log_buffer_state));
12305 +- buffer_size = intel_guc_get_log_buffer_size(GUC_CAPTURE_LOG_BUFFER);
12306 ++ buffer_size = intel_guc_get_log_buffer_size(&guc->log, GUC_CAPTURE_LOG_BUFFER);
12307 + read_offset = log_buf_state_local.read_ptr;
12308 + write_offset = log_buf_state_local.sampled_write_ptr;
12309 + full_count = log_buf_state_local.buffer_full_cnt;
12310 +@@ -1580,5 +1665,7 @@ int intel_guc_capture_init(struct intel_guc *guc)
12311 + INIT_LIST_HEAD(&guc->capture->outlist);
12312 + INIT_LIST_HEAD(&guc->capture->cachelist);
12313 +
12314 ++ check_guc_capture_size(guc);
12315 ++
12316 + return 0;
12317 + }
12318 +diff --git a/drivers/gpu/drm/i915/gt/uc/intel_guc_capture.h b/drivers/gpu/drm/i915/gt/uc/intel_guc_capture.h
12319 +index d3d7bd0b6db64..fbd3713c7832d 100644
12320 +--- a/drivers/gpu/drm/i915/gt/uc/intel_guc_capture.h
12321 ++++ b/drivers/gpu/drm/i915/gt/uc/intel_guc_capture.h
12322 +@@ -21,7 +21,6 @@ int intel_guc_capture_print_engine_node(struct drm_i915_error_state_buf *m,
12323 + void intel_guc_capture_get_matching_node(struct intel_gt *gt, struct intel_engine_coredump *ee,
12324 + struct intel_context *ce);
12325 + void intel_guc_capture_process(struct intel_guc *guc);
12326 +-int intel_guc_capture_output_min_size_est(struct intel_guc *guc);
12327 + int intel_guc_capture_getlist(struct intel_guc *guc, u32 owner, u32 type, u32 classid,
12328 + void **outptr);
12329 + int intel_guc_capture_getlistsize(struct intel_guc *guc, u32 owner, u32 type, u32 classid,
12330 +diff --git a/drivers/gpu/drm/i915/gt/uc/intel_guc_fwif.h b/drivers/gpu/drm/i915/gt/uc/intel_guc_fwif.h
12331 +index 323b055e5db97..502e7cb5a3025 100644
12332 +--- a/drivers/gpu/drm/i915/gt/uc/intel_guc_fwif.h
12333 ++++ b/drivers/gpu/drm/i915/gt/uc/intel_guc_fwif.h
12334 +@@ -305,6 +305,27 @@ struct guc_update_context_policy {
12335 +
12336 + #define GLOBAL_POLICY_DEFAULT_DPC_PROMOTE_TIME_US 500000
12337 +
12338 ++/*
12339 ++ * GuC converts the timeout to clock ticks internally. Different platforms have
12340 ++ * different GuC clocks. Thus, the maximum value before overflow is platform
12341 ++ * dependent. Current worst case scenario is about 110s. So, the spec says to
12342 ++ * limit to 100s to be safe.
12343 ++ */
12344 ++#define GUC_POLICY_MAX_EXEC_QUANTUM_US (100 * 1000 * 1000UL)
12345 ++#define GUC_POLICY_MAX_PREEMPT_TIMEOUT_US (100 * 1000 * 1000UL)
12346 ++
12347 ++static inline u32 guc_policy_max_exec_quantum_ms(void)
12348 ++{
12349 ++ BUILD_BUG_ON(GUC_POLICY_MAX_EXEC_QUANTUM_US >= UINT_MAX);
12350 ++ return GUC_POLICY_MAX_EXEC_QUANTUM_US / 1000;
12351 ++}
12352 ++
12353 ++static inline u32 guc_policy_max_preempt_timeout_ms(void)
12354 ++{
12355 ++ BUILD_BUG_ON(GUC_POLICY_MAX_PREEMPT_TIMEOUT_US >= UINT_MAX);
12356 ++ return GUC_POLICY_MAX_PREEMPT_TIMEOUT_US / 1000;
12357 ++}
12358 ++
12359 + struct guc_policies {
12360 + u32 submission_queue_depth[GUC_MAX_ENGINE_CLASSES];
12361 + /* In micro seconds. How much time to allow before DPC processing is
12362 +diff --git a/drivers/gpu/drm/i915/gt/uc/intel_guc_log.c b/drivers/gpu/drm/i915/gt/uc/intel_guc_log.c
12363 +index 25b2d7ce6640d..8d755d285247e 100644
12364 +--- a/drivers/gpu/drm/i915/gt/uc/intel_guc_log.c
12365 ++++ b/drivers/gpu/drm/i915/gt/uc/intel_guc_log.c
12366 +@@ -13,8 +13,187 @@
12367 + #include "intel_guc_capture.h"
12368 + #include "intel_guc_log.h"
12369 +
12370 ++#if defined(CONFIG_DRM_I915_DEBUG_GUC)
12371 ++#define GUC_LOG_DEFAULT_CRASH_BUFFER_SIZE SZ_2M
12372 ++#define GUC_LOG_DEFAULT_DEBUG_BUFFER_SIZE SZ_16M
12373 ++#define GUC_LOG_DEFAULT_CAPTURE_BUFFER_SIZE SZ_1M
12374 ++#elif defined(CONFIG_DRM_I915_DEBUG_GEM)
12375 ++#define GUC_LOG_DEFAULT_CRASH_BUFFER_SIZE SZ_1M
12376 ++#define GUC_LOG_DEFAULT_DEBUG_BUFFER_SIZE SZ_2M
12377 ++#define GUC_LOG_DEFAULT_CAPTURE_BUFFER_SIZE SZ_1M
12378 ++#else
12379 ++#define GUC_LOG_DEFAULT_CRASH_BUFFER_SIZE SZ_8K
12380 ++#define GUC_LOG_DEFAULT_DEBUG_BUFFER_SIZE SZ_64K
12381 ++#define GUC_LOG_DEFAULT_CAPTURE_BUFFER_SIZE SZ_1M
12382 ++#endif
12383 ++
12384 + static void guc_log_copy_debuglogs_for_relay(struct intel_guc_log *log);
12385 +
12386 ++struct guc_log_section {
12387 ++ u32 max;
12388 ++ u32 flag;
12389 ++ u32 default_val;
12390 ++ const char *name;
12391 ++};
12392 ++
12393 ++static s32 scale_log_param(struct intel_guc_log *log, const struct guc_log_section *section,
12394 ++ s32 param)
12395 ++{
12396 ++ /* -1 means default */
12397 ++ if (param < 0)
12398 ++ return section->default_val;
12399 ++
12400 ++ /* Check for 32-bit overflow */
12401 ++ if (param >= SZ_4K) {
12402 ++ drm_err(&guc_to_gt(log_to_guc(log))->i915->drm, "Size too large for GuC %s log: %dMB!",
12403 ++ section->name, param);
12404 ++ return section->default_val;
12405 ++ }
12406 ++
12407 ++ /* Param units are 1MB */
12408 ++ return param * SZ_1M;
12409 ++}
12410 ++
12411 ++static void _guc_log_init_sizes(struct intel_guc_log *log)
12412 ++{
12413 ++ struct intel_guc *guc = log_to_guc(log);
12414 ++ struct drm_i915_private *i915 = guc_to_gt(guc)->i915;
12415 ++ static const struct guc_log_section sections[GUC_LOG_SECTIONS_LIMIT] = {
12416 ++ {
12417 ++ GUC_LOG_CRASH_MASK >> GUC_LOG_CRASH_SHIFT,
12418 ++ GUC_LOG_LOG_ALLOC_UNITS,
12419 ++ GUC_LOG_DEFAULT_CRASH_BUFFER_SIZE,
12420 ++ "crash dump"
12421 ++ },
12422 ++ {
12423 ++ GUC_LOG_DEBUG_MASK >> GUC_LOG_DEBUG_SHIFT,
12424 ++ GUC_LOG_LOG_ALLOC_UNITS,
12425 ++ GUC_LOG_DEFAULT_DEBUG_BUFFER_SIZE,
12426 ++ "debug",
12427 ++ },
12428 ++ {
12429 ++ GUC_LOG_CAPTURE_MASK >> GUC_LOG_CAPTURE_SHIFT,
12430 ++ GUC_LOG_CAPTURE_ALLOC_UNITS,
12431 ++ GUC_LOG_DEFAULT_CAPTURE_BUFFER_SIZE,
12432 ++ "capture",
12433 ++ }
12434 ++ };
12435 ++ s32 params[GUC_LOG_SECTIONS_LIMIT] = {
12436 ++ i915->params.guc_log_size_crash,
12437 ++ i915->params.guc_log_size_debug,
12438 ++ i915->params.guc_log_size_capture,
12439 ++ };
12440 ++ int i;
12441 ++
12442 ++ for (i = 0; i < GUC_LOG_SECTIONS_LIMIT; i++)
12443 ++ log->sizes[i].bytes = scale_log_param(log, sections + i, params[i]);
12444 ++
12445 ++ /* If debug size > 1MB then bump default crash size to keep the same units */
12446 ++ if (log->sizes[GUC_LOG_SECTIONS_DEBUG].bytes >= SZ_1M &&
12447 ++ (i915->params.guc_log_size_crash == -1) &&
12448 ++ GUC_LOG_DEFAULT_CRASH_BUFFER_SIZE < SZ_1M)
12449 ++ log->sizes[GUC_LOG_SECTIONS_CRASH].bytes = SZ_1M;
12450 ++
12451 ++ /* Prepare the GuC API structure fields: */
12452 ++ for (i = 0; i < GUC_LOG_SECTIONS_LIMIT; i++) {
12453 ++ /* Convert to correct units */
12454 ++ if ((log->sizes[i].bytes % SZ_1M) == 0) {
12455 ++ log->sizes[i].units = SZ_1M;
12456 ++ log->sizes[i].flag = sections[i].flag;
12457 ++ } else {
12458 ++ log->sizes[i].units = SZ_4K;
12459 ++ log->sizes[i].flag = 0;
12460 ++ }
12461 ++
12462 ++ if (!IS_ALIGNED(log->sizes[i].bytes, log->sizes[i].units))
12463 ++ drm_err(&i915->drm, "Mis-aligned GuC log %s size: 0x%X vs 0x%X!",
12464 ++ sections[i].name, log->sizes[i].bytes, log->sizes[i].units);
12465 ++ log->sizes[i].count = log->sizes[i].bytes / log->sizes[i].units;
12466 ++
12467 ++ if (!log->sizes[i].count) {
12468 ++ drm_err(&i915->drm, "Zero GuC log %s size!", sections[i].name);
12469 ++ } else {
12470 ++ /* Size is +1 unit */
12471 ++ log->sizes[i].count--;
12472 ++ }
12473 ++
12474 ++ /* Clip to field size */
12475 ++ if (log->sizes[i].count > sections[i].max) {
12476 ++ drm_err(&i915->drm, "GuC log %s size too large: %d vs %d!",
12477 ++ sections[i].name, log->sizes[i].count + 1, sections[i].max + 1);
12478 ++ log->sizes[i].count = sections[i].max;
12479 ++ }
12480 ++ }
12481 ++
12482 ++ if (log->sizes[GUC_LOG_SECTIONS_CRASH].units != log->sizes[GUC_LOG_SECTIONS_DEBUG].units) {
12483 ++ drm_err(&i915->drm, "Unit mis-match for GuC log crash and debug sections: %d vs %d!",
12484 ++ log->sizes[GUC_LOG_SECTIONS_CRASH].units,
12485 ++ log->sizes[GUC_LOG_SECTIONS_DEBUG].units);
12486 ++ log->sizes[GUC_LOG_SECTIONS_CRASH].units = log->sizes[GUC_LOG_SECTIONS_DEBUG].units;
12487 ++ log->sizes[GUC_LOG_SECTIONS_CRASH].count = 0;
12488 ++ }
12489 ++
12490 ++ log->sizes_initialised = true;
12491 ++}
12492 ++
12493 ++static void guc_log_init_sizes(struct intel_guc_log *log)
12494 ++{
12495 ++ if (log->sizes_initialised)
12496 ++ return;
12497 ++
12498 ++ _guc_log_init_sizes(log);
12499 ++}
12500 ++
12501 ++static u32 intel_guc_log_section_size_crash(struct intel_guc_log *log)
12502 ++{
12503 ++ guc_log_init_sizes(log);
12504 ++
12505 ++ return log->sizes[GUC_LOG_SECTIONS_CRASH].bytes;
12506 ++}
12507 ++
12508 ++static u32 intel_guc_log_section_size_debug(struct intel_guc_log *log)
12509 ++{
12510 ++ guc_log_init_sizes(log);
12511 ++
12512 ++ return log->sizes[GUC_LOG_SECTIONS_DEBUG].bytes;
12513 ++}
12514 ++
12515 ++u32 intel_guc_log_section_size_capture(struct intel_guc_log *log)
12516 ++{
12517 ++ guc_log_init_sizes(log);
12518 ++
12519 ++ return log->sizes[GUC_LOG_SECTIONS_CAPTURE].bytes;
12520 ++}
12521 ++
12522 ++static u32 intel_guc_log_size(struct intel_guc_log *log)
12523 ++{
12524 ++ /*
12525 ++ * GuC Log buffer Layout:
12526 ++ *
12527 ++ * NB: Ordering must follow "enum guc_log_buffer_type".
12528 ++ *
12529 ++ * +===============================+ 00B
12530 ++ * | Debug state header |
12531 ++ * +-------------------------------+ 32B
12532 ++ * | Crash dump state header |
12533 ++ * +-------------------------------+ 64B
12534 ++ * | Capture state header |
12535 ++ * +-------------------------------+ 96B
12536 ++ * | |
12537 ++ * +===============================+ PAGE_SIZE (4KB)
12538 ++ * | Debug logs |
12539 ++ * +===============================+ + DEBUG_SIZE
12540 ++ * | Crash Dump logs |
12541 ++ * +===============================+ + CRASH_SIZE
12542 ++ * | Capture logs |
12543 ++ * +===============================+ + CAPTURE_SIZE
12544 ++ */
12545 ++ return PAGE_SIZE +
12546 ++ intel_guc_log_section_size_crash(log) +
12547 ++ intel_guc_log_section_size_debug(log) +
12548 ++ intel_guc_log_section_size_capture(log);
12549 ++}
12550 ++
12551 + /**
12552 + * DOC: GuC firmware log
12553 + *
12554 +@@ -139,7 +318,8 @@ static void guc_move_to_next_buf(struct intel_guc_log *log)
12555 + smp_wmb();
12556 +
12557 + /* All data has been written, so now move the offset of sub buffer. */
12558 +- relay_reserve(log->relay.channel, log->vma->obj->base.size - CAPTURE_BUFFER_SIZE);
12559 ++ relay_reserve(log->relay.channel, log->vma->obj->base.size -
12560 ++ intel_guc_log_section_size_capture(log));
12561 +
12562 + /* Switch to the next sub buffer */
12563 + relay_flush(log->relay.channel);
12564 +@@ -184,15 +364,16 @@ bool intel_guc_check_log_buf_overflow(struct intel_guc_log *log,
12565 + return overflow;
12566 + }
12567 +
12568 +-unsigned int intel_guc_get_log_buffer_size(enum guc_log_buffer_type type)
12569 ++unsigned int intel_guc_get_log_buffer_size(struct intel_guc_log *log,
12570 ++ enum guc_log_buffer_type type)
12571 + {
12572 + switch (type) {
12573 + case GUC_DEBUG_LOG_BUFFER:
12574 +- return DEBUG_BUFFER_SIZE;
12575 ++ return intel_guc_log_section_size_debug(log);
12576 + case GUC_CRASH_DUMP_LOG_BUFFER:
12577 +- return CRASH_BUFFER_SIZE;
12578 ++ return intel_guc_log_section_size_crash(log);
12579 + case GUC_CAPTURE_LOG_BUFFER:
12580 +- return CAPTURE_BUFFER_SIZE;
12581 ++ return intel_guc_log_section_size_capture(log);
12582 + default:
12583 + MISSING_CASE(type);
12584 + }
12585 +@@ -200,7 +381,8 @@ unsigned int intel_guc_get_log_buffer_size(enum guc_log_buffer_type type)
12586 + return 0;
12587 + }
12588 +
12589 +-size_t intel_guc_get_log_buffer_offset(enum guc_log_buffer_type type)
12590 ++size_t intel_guc_get_log_buffer_offset(struct intel_guc_log *log,
12591 ++ enum guc_log_buffer_type type)
12592 + {
12593 + enum guc_log_buffer_type i;
12594 + size_t offset = PAGE_SIZE;/* for the log_buffer_states */
12595 +@@ -208,7 +390,7 @@ size_t intel_guc_get_log_buffer_offset(enum guc_log_buffer_type type)
12596 + for (i = GUC_DEBUG_LOG_BUFFER; i < GUC_MAX_LOG_BUFFER; ++i) {
12597 + if (i == type)
12598 + break;
12599 +- offset += intel_guc_get_log_buffer_size(i);
12600 ++ offset += intel_guc_get_log_buffer_size(log, i);
12601 + }
12602 +
12603 + return offset;
12604 +@@ -259,7 +441,7 @@ static void _guc_log_copy_debuglogs_for_relay(struct intel_guc_log *log)
12605 + */
12606 + memcpy(&log_buf_state_local, log_buf_state,
12607 + sizeof(struct guc_log_buffer_state));
12608 +- buffer_size = intel_guc_get_log_buffer_size(type);
12609 ++ buffer_size = intel_guc_get_log_buffer_size(log, type);
12610 + read_offset = log_buf_state_local.read_ptr;
12611 + write_offset = log_buf_state_local.sampled_write_ptr;
12612 + full_cnt = log_buf_state_local.buffer_full_cnt;
12613 +@@ -374,7 +556,7 @@ static int guc_log_relay_create(struct intel_guc_log *log)
12614 + * Keep the size of sub buffers same as shared log buffer
12615 + * but GuC log-events excludes the error-state-capture logs
12616 + */
12617 +- subbuf_size = log->vma->size - CAPTURE_BUFFER_SIZE;
12618 ++ subbuf_size = log->vma->size - intel_guc_log_section_size_capture(log);
12619 +
12620 + /*
12621 + * Store up to 8 snapshots, which is large enough to buffer sufficient
12622 +@@ -461,32 +643,7 @@ int intel_guc_log_create(struct intel_guc_log *log)
12623 +
12624 + GEM_BUG_ON(log->vma);
12625 +
12626 +- /*
12627 +- * GuC Log buffer Layout
12628 +- * (this ordering must follow "enum guc_log_buffer_type" definition)
12629 +- *
12630 +- * +===============================+ 00B
12631 +- * | Debug state header |
12632 +- * +-------------------------------+ 32B
12633 +- * | Crash dump state header |
12634 +- * +-------------------------------+ 64B
12635 +- * | Capture state header |
12636 +- * +-------------------------------+ 96B
12637 +- * | |
12638 +- * +===============================+ PAGE_SIZE (4KB)
12639 +- * | Debug logs |
12640 +- * +===============================+ + DEBUG_SIZE
12641 +- * | Crash Dump logs |
12642 +- * +===============================+ + CRASH_SIZE
12643 +- * | Capture logs |
12644 +- * +===============================+ + CAPTURE_SIZE
12645 +- */
12646 +- if (intel_guc_capture_output_min_size_est(guc) > CAPTURE_BUFFER_SIZE)
12647 +- DRM_WARN("GuC log buffer for state_capture maybe too small. %d < %d\n",
12648 +- CAPTURE_BUFFER_SIZE, intel_guc_capture_output_min_size_est(guc));
12649 +-
12650 +- guc_log_size = PAGE_SIZE + CRASH_BUFFER_SIZE + DEBUG_BUFFER_SIZE +
12651 +- CAPTURE_BUFFER_SIZE;
12652 ++ guc_log_size = intel_guc_log_size(log);
12653 +
12654 + vma = intel_guc_allocate_vma(guc, guc_log_size);
12655 + if (IS_ERR(vma)) {
12656 +diff --git a/drivers/gpu/drm/i915/gt/uc/intel_guc_log.h b/drivers/gpu/drm/i915/gt/uc/intel_guc_log.h
12657 +index 18007e639be99..02127703be809 100644
12658 +--- a/drivers/gpu/drm/i915/gt/uc/intel_guc_log.h
12659 ++++ b/drivers/gpu/drm/i915/gt/uc/intel_guc_log.h
12660 +@@ -15,20 +15,6 @@
12661 +
12662 + struct intel_guc;
12663 +
12664 +-#if defined(CONFIG_DRM_I915_DEBUG_GUC)
12665 +-#define CRASH_BUFFER_SIZE SZ_2M
12666 +-#define DEBUG_BUFFER_SIZE SZ_16M
12667 +-#define CAPTURE_BUFFER_SIZE SZ_4M
12668 +-#elif defined(CONFIG_DRM_I915_DEBUG_GEM)
12669 +-#define CRASH_BUFFER_SIZE SZ_1M
12670 +-#define DEBUG_BUFFER_SIZE SZ_2M
12671 +-#define CAPTURE_BUFFER_SIZE SZ_1M
12672 +-#else
12673 +-#define CRASH_BUFFER_SIZE SZ_8K
12674 +-#define DEBUG_BUFFER_SIZE SZ_64K
12675 +-#define CAPTURE_BUFFER_SIZE SZ_16K
12676 +-#endif
12677 +-
12678 + /*
12679 + * While we're using plain log level in i915, GuC controls are much more...
12680 + * "elaborate"? We have a couple of bits for verbosity, separate bit for actual
12681 +@@ -46,10 +32,30 @@ struct intel_guc;
12682 + #define GUC_VERBOSITY_TO_LOG_LEVEL(x) ((x) + 2)
12683 + #define GUC_LOG_LEVEL_MAX GUC_VERBOSITY_TO_LOG_LEVEL(GUC_LOG_VERBOSITY_MAX)
12684 +
12685 ++enum {
12686 ++ GUC_LOG_SECTIONS_CRASH,
12687 ++ GUC_LOG_SECTIONS_DEBUG,
12688 ++ GUC_LOG_SECTIONS_CAPTURE,
12689 ++ GUC_LOG_SECTIONS_LIMIT
12690 ++};
12691 ++
12692 + struct intel_guc_log {
12693 + u32 level;
12694 ++
12695 ++ /* Allocation settings */
12696 ++ struct {
12697 ++ s32 bytes; /* Size in bytes */
12698 ++ s32 units; /* GuC API units - 1MB or 4KB */
12699 ++ s32 count; /* Number of API units */
12700 ++ u32 flag; /* GuC API units flag */
12701 ++ } sizes[GUC_LOG_SECTIONS_LIMIT];
12702 ++ bool sizes_initialised;
12703 ++
12704 ++ /* Combined buffer allocation */
12705 + struct i915_vma *vma;
12706 + void *buf_addr;
12707 ++
12708 ++ /* RelayFS support */
12709 + struct {
12710 + bool buf_in_use;
12711 + bool started;
12712 +@@ -58,6 +64,7 @@ struct intel_guc_log {
12713 + struct mutex lock;
12714 + u32 full_count;
12715 + } relay;
12716 ++
12717 + /* logging related stats */
12718 + struct {
12719 + u32 sampled_overflow;
12720 +@@ -69,8 +76,9 @@ struct intel_guc_log {
12721 + void intel_guc_log_init_early(struct intel_guc_log *log);
12722 + bool intel_guc_check_log_buf_overflow(struct intel_guc_log *log, enum guc_log_buffer_type type,
12723 + unsigned int full_cnt);
12724 +-unsigned int intel_guc_get_log_buffer_size(enum guc_log_buffer_type type);
12725 +-size_t intel_guc_get_log_buffer_offset(enum guc_log_buffer_type type);
12726 ++unsigned int intel_guc_get_log_buffer_size(struct intel_guc_log *log,
12727 ++ enum guc_log_buffer_type type);
12728 ++size_t intel_guc_get_log_buffer_offset(struct intel_guc_log *log, enum guc_log_buffer_type type);
12729 + int intel_guc_log_create(struct intel_guc_log *log);
12730 + void intel_guc_log_destroy(struct intel_guc_log *log);
12731 +
12732 +@@ -92,4 +100,6 @@ void intel_guc_log_info(struct intel_guc_log *log, struct drm_printer *p);
12733 + int intel_guc_log_dump(struct intel_guc_log *log, struct drm_printer *p,
12734 + bool dump_load_err);
12735 +
12736 ++u32 intel_guc_log_section_size_capture(struct intel_guc_log *log);
12737 ++
12738 + #endif
12739 +diff --git a/drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c b/drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c
12740 +index fe179146d51b9..cd0c5043863b6 100644
12741 +--- a/drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c
12742 ++++ b/drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c
12743 +@@ -2430,6 +2430,10 @@ static int guc_context_policy_init_v70(struct intel_context *ce, bool loop)
12744 + int ret;
12745 +
12746 + /* NB: For both of these, zero means disabled. */
12747 ++ GEM_BUG_ON(overflows_type(engine->props.timeslice_duration_ms * 1000,
12748 ++ execution_quantum));
12749 ++ GEM_BUG_ON(overflows_type(engine->props.preempt_timeout_ms * 1000,
12750 ++ preemption_timeout));
12751 + execution_quantum = engine->props.timeslice_duration_ms * 1000;
12752 + preemption_timeout = engine->props.preempt_timeout_ms * 1000;
12753 +
12754 +@@ -2486,6 +2490,10 @@ static void guc_context_policy_init_v69(struct intel_engine_cs *engine,
12755 + desc->policy_flags |= CONTEXT_POLICY_FLAG_PREEMPT_TO_IDLE_V69;
12756 +
12757 + /* NB: For both of these, zero means disabled. */
12758 ++ GEM_BUG_ON(overflows_type(engine->props.timeslice_duration_ms * 1000,
12759 ++ desc->execution_quantum));
12760 ++ GEM_BUG_ON(overflows_type(engine->props.preempt_timeout_ms * 1000,
12761 ++ desc->preemption_timeout));
12762 + desc->execution_quantum = engine->props.timeslice_duration_ms * 1000;
12763 + desc->preemption_timeout = engine->props.preempt_timeout_ms * 1000;
12764 + }
12765 +diff --git a/drivers/gpu/drm/i915/i915_params.c b/drivers/gpu/drm/i915/i915_params.c
12766 +index 6fc475a5db615..06ca5b8221118 100644
12767 +--- a/drivers/gpu/drm/i915/i915_params.c
12768 ++++ b/drivers/gpu/drm/i915/i915_params.c
12769 +@@ -171,6 +171,18 @@ i915_param_named(guc_log_level, int, 0400,
12770 + "GuC firmware logging level. Requires GuC to be loaded. "
12771 + "(-1=auto [default], 0=disable, 1..4=enable with verbosity min..max)");
12772 +
12773 ++i915_param_named(guc_log_size_crash, int, 0400,
12774 ++ "GuC firmware logging buffer size for crash dumps (in MB)"
12775 ++ "(-1=auto [default], NB: max = 4, other restrictions apply)");
12776 ++
12777 ++i915_param_named(guc_log_size_debug, int, 0400,
12778 ++ "GuC firmware logging buffer size for debug logs (in MB)"
12779 ++ "(-1=auto [default], NB: max = 16, other restrictions apply)");
12780 ++
12781 ++i915_param_named(guc_log_size_capture, int, 0400,
12782 ++ "GuC error capture register dump buffer size (in MB)"
12783 ++ "(-1=auto [default], NB: max = 4, other restrictions apply)");
12784 ++
12785 + i915_param_named_unsafe(guc_firmware_path, charp, 0400,
12786 + "GuC firmware path to use instead of the default one");
12787 +
12788 +diff --git a/drivers/gpu/drm/i915/i915_params.h b/drivers/gpu/drm/i915/i915_params.h
12789 +index 2733cb6cfe094..f684d1ab87078 100644
12790 +--- a/drivers/gpu/drm/i915/i915_params.h
12791 ++++ b/drivers/gpu/drm/i915/i915_params.h
12792 +@@ -61,6 +61,9 @@ struct drm_printer;
12793 + param(int, invert_brightness, 0, 0600) \
12794 + param(int, enable_guc, -1, 0400) \
12795 + param(int, guc_log_level, -1, 0400) \
12796 ++ param(int, guc_log_size_crash, -1, 0400) \
12797 ++ param(int, guc_log_size_debug, -1, 0400) \
12798 ++ param(int, guc_log_size_capture, -1, 0400) \
12799 + param(char *, guc_firmware_path, NULL, 0400) \
12800 + param(char *, huc_firmware_path, NULL, 0400) \
12801 + param(char *, dmc_firmware_path, NULL, 0400) \
12802 +diff --git a/drivers/gpu/drm/mediatek/mtk_dpi.c b/drivers/gpu/drm/mediatek/mtk_dpi.c
12803 +index 630a4e301ef6c..b11b5a2c06639 100644
12804 +--- a/drivers/gpu/drm/mediatek/mtk_dpi.c
12805 ++++ b/drivers/gpu/drm/mediatek/mtk_dpi.c
12806 +@@ -462,9 +462,6 @@ static void mtk_dpi_power_off(struct mtk_dpi *dpi)
12807 + if (--dpi->refcount != 0)
12808 + return;
12809 +
12810 +- if (dpi->pinctrl && dpi->pins_gpio)
12811 +- pinctrl_select_state(dpi->pinctrl, dpi->pins_gpio);
12812 +-
12813 + mtk_dpi_disable(dpi);
12814 + clk_disable_unprepare(dpi->pixel_clk);
12815 + clk_disable_unprepare(dpi->engine_clk);
12816 +@@ -489,9 +486,6 @@ static int mtk_dpi_power_on(struct mtk_dpi *dpi)
12817 + goto err_pixel;
12818 + }
12819 +
12820 +- if (dpi->pinctrl && dpi->pins_dpi)
12821 +- pinctrl_select_state(dpi->pinctrl, dpi->pins_dpi);
12822 +-
12823 + return 0;
12824 +
12825 + err_pixel:
12826 +@@ -722,12 +716,18 @@ static void mtk_dpi_bridge_disable(struct drm_bridge *bridge)
12827 + struct mtk_dpi *dpi = bridge_to_dpi(bridge);
12828 +
12829 + mtk_dpi_power_off(dpi);
12830 ++
12831 ++ if (dpi->pinctrl && dpi->pins_gpio)
12832 ++ pinctrl_select_state(dpi->pinctrl, dpi->pins_gpio);
12833 + }
12834 +
12835 + static void mtk_dpi_bridge_enable(struct drm_bridge *bridge)
12836 + {
12837 + struct mtk_dpi *dpi = bridge_to_dpi(bridge);
12838 +
12839 ++ if (dpi->pinctrl && dpi->pins_dpi)
12840 ++ pinctrl_select_state(dpi->pinctrl, dpi->pins_dpi);
12841 ++
12842 + mtk_dpi_power_on(dpi);
12843 + mtk_dpi_set_display_mode(dpi, &dpi->mode);
12844 + mtk_dpi_enable(dpi);
12845 +diff --git a/drivers/gpu/drm/mediatek/mtk_hdmi.c b/drivers/gpu/drm/mediatek/mtk_hdmi.c
12846 +index 3196189429bcf..7613b0fa2be6e 100644
12847 +--- a/drivers/gpu/drm/mediatek/mtk_hdmi.c
12848 ++++ b/drivers/gpu/drm/mediatek/mtk_hdmi.c
12849 +@@ -1203,9 +1203,10 @@ static enum drm_connector_status mtk_hdmi_detect(struct mtk_hdmi *hdmi)
12850 + return mtk_hdmi_update_plugged_status(hdmi);
12851 + }
12852 +
12853 +-static int mtk_hdmi_bridge_mode_valid(struct drm_bridge *bridge,
12854 +- const struct drm_display_info *info,
12855 +- const struct drm_display_mode *mode)
12856 ++static enum drm_mode_status
12857 ++mtk_hdmi_bridge_mode_valid(struct drm_bridge *bridge,
12858 ++ const struct drm_display_info *info,
12859 ++ const struct drm_display_mode *mode)
12860 + {
12861 + struct mtk_hdmi *hdmi = hdmi_ctx_from_bridge(bridge);
12862 + struct drm_bridge *next_bridge;
12863 +diff --git a/drivers/gpu/drm/meson/meson_encoder_cvbs.c b/drivers/gpu/drm/meson/meson_encoder_cvbs.c
12864 +index 5675bc2a92cf8..3f73b211fa8e3 100644
12865 +--- a/drivers/gpu/drm/meson/meson_encoder_cvbs.c
12866 ++++ b/drivers/gpu/drm/meson/meson_encoder_cvbs.c
12867 +@@ -116,9 +116,10 @@ static int meson_encoder_cvbs_get_modes(struct drm_bridge *bridge,
12868 + return i;
12869 + }
12870 +
12871 +-static int meson_encoder_cvbs_mode_valid(struct drm_bridge *bridge,
12872 +- const struct drm_display_info *display_info,
12873 +- const struct drm_display_mode *mode)
12874 ++static enum drm_mode_status
12875 ++meson_encoder_cvbs_mode_valid(struct drm_bridge *bridge,
12876 ++ const struct drm_display_info *display_info,
12877 ++ const struct drm_display_mode *mode)
12878 + {
12879 + if (meson_cvbs_get_mode(mode))
12880 + return MODE_OK;
12881 +diff --git a/drivers/gpu/drm/msm/adreno/a6xx_gpu.c b/drivers/gpu/drm/msm/adreno/a6xx_gpu.c
12882 +index 4d501100b9e45..5804c35ae74b3 100644
12883 +--- a/drivers/gpu/drm/msm/adreno/a6xx_gpu.c
12884 ++++ b/drivers/gpu/drm/msm/adreno/a6xx_gpu.c
12885 +@@ -1869,7 +1869,7 @@ static u32 fuse_to_supp_hw(struct device *dev, struct adreno_rev rev, u32 fuse)
12886 +
12887 + if (val == UINT_MAX) {
12888 + DRM_DEV_ERROR(dev,
12889 +- "missing support for speed-bin: %u. Some OPPs may not be supported by hardware",
12890 ++ "missing support for speed-bin: %u. Some OPPs may not be supported by hardware\n",
12891 + fuse);
12892 + return UINT_MAX;
12893 + }
12894 +@@ -1879,7 +1879,7 @@ static u32 fuse_to_supp_hw(struct device *dev, struct adreno_rev rev, u32 fuse)
12895 +
12896 + static int a6xx_set_supported_hw(struct device *dev, struct adreno_rev rev)
12897 + {
12898 +- u32 supp_hw = UINT_MAX;
12899 ++ u32 supp_hw;
12900 + u32 speedbin;
12901 + int ret;
12902 +
12903 +@@ -1891,15 +1891,13 @@ static int a6xx_set_supported_hw(struct device *dev, struct adreno_rev rev)
12904 + if (ret == -ENOENT) {
12905 + return 0;
12906 + } else if (ret) {
12907 +- DRM_DEV_ERROR(dev,
12908 +- "failed to read speed-bin (%d). Some OPPs may not be supported by hardware",
12909 +- ret);
12910 +- goto done;
12911 ++ dev_err_probe(dev, ret,
12912 ++ "failed to read speed-bin. Some OPPs may not be supported by hardware\n");
12913 ++ return ret;
12914 + }
12915 +
12916 + supp_hw = fuse_to_supp_hw(dev, rev, speedbin);
12917 +
12918 +-done:
12919 + ret = devm_pm_opp_set_supported_hw(dev, &supp_hw, 1);
12920 + if (ret)
12921 + return ret;
12922 +diff --git a/drivers/gpu/drm/msm/disp/dpu1/dpu_encoder.c b/drivers/gpu/drm/msm/disp/dpu1/dpu_encoder.c
12923 +index 52a626117f70f..7f5dba96b2ffa 100644
12924 +--- a/drivers/gpu/drm/msm/disp/dpu1/dpu_encoder.c
12925 ++++ b/drivers/gpu/drm/msm/disp/dpu1/dpu_encoder.c
12926 +@@ -162,7 +162,7 @@ enum dpu_enc_rc_states {
12927 + * @vsync_event_work: worker to handle vsync event for autorefresh
12928 + * @topology: topology of the display
12929 + * @idle_timeout: idle timeout duration in milliseconds
12930 +- * @dsc: msm_display_dsc_config pointer, for DSC-enabled encoders
12931 ++ * @dsc: drm_dsc_config pointer, for DSC-enabled encoders
12932 + */
12933 + struct dpu_encoder_virt {
12934 + struct drm_encoder base;
12935 +@@ -208,7 +208,7 @@ struct dpu_encoder_virt {
12936 + bool wide_bus_en;
12937 +
12938 + /* DSC configuration */
12939 +- struct msm_display_dsc_config *dsc;
12940 ++ struct drm_dsc_config *dsc;
12941 + };
12942 +
12943 + #define to_dpu_encoder_virt(x) container_of(x, struct dpu_encoder_virt, base)
12944 +@@ -1791,12 +1791,12 @@ static void dpu_encoder_vsync_event_work_handler(struct kthread_work *work)
12945 + }
12946 +
12947 + static u32
12948 +-dpu_encoder_dsc_initial_line_calc(struct msm_display_dsc_config *dsc,
12949 ++dpu_encoder_dsc_initial_line_calc(struct drm_dsc_config *dsc,
12950 + u32 enc_ip_width)
12951 + {
12952 + int ssm_delay, total_pixels, soft_slice_per_enc;
12953 +
12954 +- soft_slice_per_enc = enc_ip_width / dsc->drm->slice_width;
12955 ++ soft_slice_per_enc = enc_ip_width / dsc->slice_width;
12956 +
12957 + /*
12958 + * minimum number of initial line pixels is a sum of:
12959 +@@ -1808,16 +1808,16 @@ dpu_encoder_dsc_initial_line_calc(struct msm_display_dsc_config *dsc,
12960 + * 5. 6 additional pixels as the output of the rate buffer is
12961 + * 48 bits wide
12962 + */
12963 +- ssm_delay = ((dsc->drm->bits_per_component < 10) ? 84 : 92);
12964 +- total_pixels = ssm_delay * 3 + dsc->drm->initial_xmit_delay + 47;
12965 ++ ssm_delay = ((dsc->bits_per_component < 10) ? 84 : 92);
12966 ++ total_pixels = ssm_delay * 3 + dsc->initial_xmit_delay + 47;
12967 + if (soft_slice_per_enc > 1)
12968 + total_pixels += (ssm_delay * 3);
12969 +- return DIV_ROUND_UP(total_pixels, dsc->drm->slice_width);
12970 ++ return DIV_ROUND_UP(total_pixels, dsc->slice_width);
12971 + }
12972 +
12973 + static void dpu_encoder_dsc_pipe_cfg(struct dpu_hw_dsc *hw_dsc,
12974 + struct dpu_hw_pingpong *hw_pp,
12975 +- struct msm_display_dsc_config *dsc,
12976 ++ struct drm_dsc_config *dsc,
12977 + u32 common_mode,
12978 + u32 initial_lines)
12979 + {
12980 +@@ -1835,7 +1835,7 @@ static void dpu_encoder_dsc_pipe_cfg(struct dpu_hw_dsc *hw_dsc,
12981 + }
12982 +
12983 + static void dpu_encoder_prep_dsc(struct dpu_encoder_virt *dpu_enc,
12984 +- struct msm_display_dsc_config *dsc)
12985 ++ struct drm_dsc_config *dsc)
12986 + {
12987 + /* coding only for 2LM, 2enc, 1 dsc config */
12988 + struct dpu_encoder_phys *enc_master = dpu_enc->cur_master;
12989 +@@ -1858,14 +1858,15 @@ static void dpu_encoder_prep_dsc(struct dpu_encoder_virt *dpu_enc,
12990 + }
12991 + }
12992 +
12993 +- pic_width = dsc->drm->pic_width;
12994 ++ dsc_common_mode = 0;
12995 ++ pic_width = dsc->pic_width;
12996 +
12997 + dsc_common_mode = DSC_MODE_MULTIPLEX | DSC_MODE_SPLIT_PANEL;
12998 + if (enc_master->intf_mode == INTF_MODE_VIDEO)
12999 + dsc_common_mode |= DSC_MODE_VIDEO;
13000 +
13001 +- this_frame_slices = pic_width / dsc->drm->slice_width;
13002 +- intf_ip_w = this_frame_slices * dsc->drm->slice_width;
13003 ++ this_frame_slices = pic_width / dsc->slice_width;
13004 ++ intf_ip_w = this_frame_slices * dsc->slice_width;
13005 +
13006 + /*
13007 + * dsc merge case: when using 2 encoders for the same stream,
13008 +diff --git a/drivers/gpu/drm/msm/disp/dpu1/dpu_encoder.h b/drivers/gpu/drm/msm/disp/dpu1/dpu_encoder.h
13009 +index d4d1ecd416e39..9e7236ef34e6d 100644
13010 +--- a/drivers/gpu/drm/msm/disp/dpu1/dpu_encoder.h
13011 ++++ b/drivers/gpu/drm/msm/disp/dpu1/dpu_encoder.h
13012 +@@ -36,7 +36,7 @@ struct msm_display_info {
13013 + uint32_t h_tile_instance[MAX_H_TILES_PER_DISPLAY];
13014 + bool is_cmd_mode;
13015 + bool is_te_using_watchdog_timer;
13016 +- struct msm_display_dsc_config *dsc;
13017 ++ struct drm_dsc_config *dsc;
13018 + };
13019 +
13020 + /**
13021 +diff --git a/drivers/gpu/drm/msm/disp/dpu1/dpu_hw_dsc.c b/drivers/gpu/drm/msm/disp/dpu1/dpu_hw_dsc.c
13022 +index 411689ae63825..3662df698dae5 100644
13023 +--- a/drivers/gpu/drm/msm/disp/dpu1/dpu_hw_dsc.c
13024 ++++ b/drivers/gpu/drm/msm/disp/dpu1/dpu_hw_dsc.c
13025 +@@ -37,12 +37,12 @@ static void dpu_hw_dsc_disable(struct dpu_hw_dsc *dsc)
13026 + }
13027 +
13028 + static void dpu_hw_dsc_config(struct dpu_hw_dsc *hw_dsc,
13029 +- struct msm_display_dsc_config *dsc,
13030 ++ struct drm_dsc_config *dsc,
13031 + u32 mode,
13032 + u32 initial_lines)
13033 + {
13034 + struct dpu_hw_blk_reg_map *c = &hw_dsc->hw;
13035 +- u32 data, lsb, bpp;
13036 ++ u32 data;
13037 + u32 slice_last_group_size;
13038 + u32 det_thresh_flatness;
13039 + bool is_cmd_mode = !(mode & DSC_MODE_VIDEO);
13040 +@@ -52,89 +52,82 @@ static void dpu_hw_dsc_config(struct dpu_hw_dsc *hw_dsc,
13041 + if (is_cmd_mode)
13042 + initial_lines += 1;
13043 +
13044 +- slice_last_group_size = 3 - (dsc->drm->slice_width % 3);
13045 ++ slice_last_group_size = 3 - (dsc->slice_width % 3);
13046 + data = (initial_lines << 20);
13047 + data |= ((slice_last_group_size - 1) << 18);
13048 + /* bpp is 6.4 format, 4 LSBs bits are for fractional part */
13049 +- data |= dsc->drm->bits_per_pixel << 12;
13050 +- lsb = dsc->drm->bits_per_pixel % 4;
13051 +- bpp = dsc->drm->bits_per_pixel / 4;
13052 +- bpp *= 4;
13053 +- bpp <<= 4;
13054 +- bpp |= lsb;
13055 +-
13056 +- data |= bpp << 8;
13057 +- data |= (dsc->drm->block_pred_enable << 7);
13058 +- data |= (dsc->drm->line_buf_depth << 3);
13059 +- data |= (dsc->drm->simple_422 << 2);
13060 +- data |= (dsc->drm->convert_rgb << 1);
13061 +- data |= dsc->drm->bits_per_component;
13062 ++ data |= (dsc->bits_per_pixel << 8);
13063 ++ data |= (dsc->block_pred_enable << 7);
13064 ++ data |= (dsc->line_buf_depth << 3);
13065 ++ data |= (dsc->simple_422 << 2);
13066 ++ data |= (dsc->convert_rgb << 1);
13067 ++ data |= dsc->bits_per_component;
13068 +
13069 + DPU_REG_WRITE(c, DSC_ENC, data);
13070 +
13071 +- data = dsc->drm->pic_width << 16;
13072 +- data |= dsc->drm->pic_height;
13073 ++ data = dsc->pic_width << 16;
13074 ++ data |= dsc->pic_height;
13075 + DPU_REG_WRITE(c, DSC_PICTURE, data);
13076 +
13077 +- data = dsc->drm->slice_width << 16;
13078 +- data |= dsc->drm->slice_height;
13079 ++ data = dsc->slice_width << 16;
13080 ++ data |= dsc->slice_height;
13081 + DPU_REG_WRITE(c, DSC_SLICE, data);
13082 +
13083 +- data = dsc->drm->slice_chunk_size << 16;
13084 ++ data = dsc->slice_chunk_size << 16;
13085 + DPU_REG_WRITE(c, DSC_CHUNK_SIZE, data);
13086 +
13087 +- data = dsc->drm->initial_dec_delay << 16;
13088 +- data |= dsc->drm->initial_xmit_delay;
13089 ++ data = dsc->initial_dec_delay << 16;
13090 ++ data |= dsc->initial_xmit_delay;
13091 + DPU_REG_WRITE(c, DSC_DELAY, data);
13092 +
13093 +- data = dsc->drm->initial_scale_value;
13094 ++ data = dsc->initial_scale_value;
13095 + DPU_REG_WRITE(c, DSC_SCALE_INITIAL, data);
13096 +
13097 +- data = dsc->drm->scale_decrement_interval;
13098 ++ data = dsc->scale_decrement_interval;
13099 + DPU_REG_WRITE(c, DSC_SCALE_DEC_INTERVAL, data);
13100 +
13101 +- data = dsc->drm->scale_increment_interval;
13102 ++ data = dsc->scale_increment_interval;
13103 + DPU_REG_WRITE(c, DSC_SCALE_INC_INTERVAL, data);
13104 +
13105 +- data = dsc->drm->first_line_bpg_offset;
13106 ++ data = dsc->first_line_bpg_offset;
13107 + DPU_REG_WRITE(c, DSC_FIRST_LINE_BPG_OFFSET, data);
13108 +
13109 +- data = dsc->drm->nfl_bpg_offset << 16;
13110 +- data |= dsc->drm->slice_bpg_offset;
13111 ++ data = dsc->nfl_bpg_offset << 16;
13112 ++ data |= dsc->slice_bpg_offset;
13113 + DPU_REG_WRITE(c, DSC_BPG_OFFSET, data);
13114 +
13115 +- data = dsc->drm->initial_offset << 16;
13116 +- data |= dsc->drm->final_offset;
13117 ++ data = dsc->initial_offset << 16;
13118 ++ data |= dsc->final_offset;
13119 + DPU_REG_WRITE(c, DSC_DSC_OFFSET, data);
13120 +
13121 +- det_thresh_flatness = 7 + 2 * (dsc->drm->bits_per_component - 8);
13122 ++ det_thresh_flatness = 7 + 2 * (dsc->bits_per_component - 8);
13123 + data = det_thresh_flatness << 10;
13124 +- data |= dsc->drm->flatness_max_qp << 5;
13125 +- data |= dsc->drm->flatness_min_qp;
13126 ++ data |= dsc->flatness_max_qp << 5;
13127 ++ data |= dsc->flatness_min_qp;
13128 + DPU_REG_WRITE(c, DSC_FLATNESS, data);
13129 +
13130 +- data = dsc->drm->rc_model_size;
13131 ++ data = dsc->rc_model_size;
13132 + DPU_REG_WRITE(c, DSC_RC_MODEL_SIZE, data);
13133 +
13134 +- data = dsc->drm->rc_tgt_offset_low << 18;
13135 +- data |= dsc->drm->rc_tgt_offset_high << 14;
13136 +- data |= dsc->drm->rc_quant_incr_limit1 << 9;
13137 +- data |= dsc->drm->rc_quant_incr_limit0 << 4;
13138 +- data |= dsc->drm->rc_edge_factor;
13139 ++ data = dsc->rc_tgt_offset_low << 18;
13140 ++ data |= dsc->rc_tgt_offset_high << 14;
13141 ++ data |= dsc->rc_quant_incr_limit1 << 9;
13142 ++ data |= dsc->rc_quant_incr_limit0 << 4;
13143 ++ data |= dsc->rc_edge_factor;
13144 + DPU_REG_WRITE(c, DSC_RC, data);
13145 + }
13146 +
13147 + static void dpu_hw_dsc_config_thresh(struct dpu_hw_dsc *hw_dsc,
13148 +- struct msm_display_dsc_config *dsc)
13149 ++ struct drm_dsc_config *dsc)
13150 + {
13151 +- struct drm_dsc_rc_range_parameters *rc = dsc->drm->rc_range_params;
13152 ++ struct drm_dsc_rc_range_parameters *rc = dsc->rc_range_params;
13153 + struct dpu_hw_blk_reg_map *c = &hw_dsc->hw;
13154 + u32 off;
13155 + int i;
13156 +
13157 + off = DSC_RC_BUF_THRESH;
13158 + for (i = 0; i < DSC_NUM_BUF_RANGES - 1 ; i++) {
13159 +- DPU_REG_WRITE(c, off, dsc->drm->rc_buf_thresh[i]);
13160 ++ DPU_REG_WRITE(c, off, dsc->rc_buf_thresh[i]);
13161 + off += 4;
13162 + }
13163 +
13164 +diff --git a/drivers/gpu/drm/msm/disp/dpu1/dpu_hw_dsc.h b/drivers/gpu/drm/msm/disp/dpu1/dpu_hw_dsc.h
13165 +index 45e4118f1fa27..c0b77fe1a6968 100644
13166 +--- a/drivers/gpu/drm/msm/disp/dpu1/dpu_hw_dsc.h
13167 ++++ b/drivers/gpu/drm/msm/disp/dpu1/dpu_hw_dsc.h
13168 +@@ -31,7 +31,7 @@ struct dpu_hw_dsc_ops {
13169 + * @initial_lines: amount of initial lines to be used
13170 + */
13171 + void (*dsc_config)(struct dpu_hw_dsc *hw_dsc,
13172 +- struct msm_display_dsc_config *dsc,
13173 ++ struct drm_dsc_config *dsc,
13174 + u32 mode,
13175 + u32 initial_lines);
13176 +
13177 +@@ -41,7 +41,7 @@ struct dpu_hw_dsc_ops {
13178 + * @dsc: panel dsc parameters
13179 + */
13180 + void (*dsc_config_thresh)(struct dpu_hw_dsc *hw_dsc,
13181 +- struct msm_display_dsc_config *dsc);
13182 ++ struct drm_dsc_config *dsc);
13183 + };
13184 +
13185 + struct dpu_hw_dsc {
13186 +diff --git a/drivers/gpu/drm/msm/disp/mdp5/mdp5_kms.c b/drivers/gpu/drm/msm/disp/mdp5/mdp5_kms.c
13187 +index b0d21838a1343..29ae5c9613f36 100644
13188 +--- a/drivers/gpu/drm/msm/disp/mdp5/mdp5_kms.c
13189 ++++ b/drivers/gpu/drm/msm/disp/mdp5/mdp5_kms.c
13190 +@@ -203,7 +203,7 @@ static int mdp5_set_split_display(struct msm_kms *kms,
13191 + slave_encoder);
13192 + }
13193 +
13194 +-static void mdp5_destroy(struct platform_device *pdev);
13195 ++static void mdp5_destroy(struct mdp5_kms *mdp5_kms);
13196 +
13197 + static void mdp5_kms_destroy(struct msm_kms *kms)
13198 + {
13199 +@@ -223,7 +223,7 @@ static void mdp5_kms_destroy(struct msm_kms *kms)
13200 + }
13201 +
13202 + mdp_kms_destroy(&mdp5_kms->base);
13203 +- mdp5_destroy(mdp5_kms->pdev);
13204 ++ mdp5_destroy(mdp5_kms);
13205 + }
13206 +
13207 + #ifdef CONFIG_DEBUG_FS
13208 +@@ -559,6 +559,8 @@ static int mdp5_kms_init(struct drm_device *dev)
13209 + int irq, i, ret;
13210 +
13211 + ret = mdp5_init(to_platform_device(dev->dev), dev);
13212 ++ if (ret)
13213 ++ return ret;
13214 +
13215 + /* priv->kms would have been populated by the MDP5 driver */
13216 + kms = priv->kms;
13217 +@@ -632,9 +634,8 @@ fail:
13218 + return ret;
13219 + }
13220 +
13221 +-static void mdp5_destroy(struct platform_device *pdev)
13222 ++static void mdp5_destroy(struct mdp5_kms *mdp5_kms)
13223 + {
13224 +- struct mdp5_kms *mdp5_kms = platform_get_drvdata(pdev);
13225 + int i;
13226 +
13227 + if (mdp5_kms->ctlm)
13228 +@@ -648,7 +649,7 @@ static void mdp5_destroy(struct platform_device *pdev)
13229 + kfree(mdp5_kms->intfs[i]);
13230 +
13231 + if (mdp5_kms->rpm_enabled)
13232 +- pm_runtime_disable(&pdev->dev);
13233 ++ pm_runtime_disable(&mdp5_kms->pdev->dev);
13234 +
13235 + drm_atomic_private_obj_fini(&mdp5_kms->glob_state);
13236 + drm_modeset_lock_fini(&mdp5_kms->glob_state_lock);
13237 +@@ -797,8 +798,6 @@ static int mdp5_init(struct platform_device *pdev, struct drm_device *dev)
13238 + goto fail;
13239 + }
13240 +
13241 +- platform_set_drvdata(pdev, mdp5_kms);
13242 +-
13243 + spin_lock_init(&mdp5_kms->resource_lock);
13244 +
13245 + mdp5_kms->dev = dev;
13246 +@@ -839,6 +838,9 @@ static int mdp5_init(struct platform_device *pdev, struct drm_device *dev)
13247 + */
13248 + clk_set_rate(mdp5_kms->core_clk, 200000000);
13249 +
13250 ++ /* set uninit-ed kms */
13251 ++ priv->kms = &mdp5_kms->base.base;
13252 ++
13253 + pm_runtime_enable(&pdev->dev);
13254 + mdp5_kms->rpm_enabled = true;
13255 +
13256 +@@ -890,13 +892,10 @@ static int mdp5_init(struct platform_device *pdev, struct drm_device *dev)
13257 + if (ret)
13258 + goto fail;
13259 +
13260 +- /* set uninit-ed kms */
13261 +- priv->kms = &mdp5_kms->base.base;
13262 +-
13263 + return 0;
13264 + fail:
13265 + if (mdp5_kms)
13266 +- mdp5_destroy(pdev);
13267 ++ mdp5_destroy(mdp5_kms);
13268 + return ret;
13269 + }
13270 +
13271 +@@ -953,7 +952,8 @@ static int mdp5_dev_remove(struct platform_device *pdev)
13272 + static __maybe_unused int mdp5_runtime_suspend(struct device *dev)
13273 + {
13274 + struct platform_device *pdev = to_platform_device(dev);
13275 +- struct mdp5_kms *mdp5_kms = platform_get_drvdata(pdev);
13276 ++ struct msm_drm_private *priv = platform_get_drvdata(pdev);
13277 ++ struct mdp5_kms *mdp5_kms = to_mdp5_kms(to_mdp_kms(priv->kms));
13278 +
13279 + DBG("");
13280 +
13281 +@@ -963,7 +963,8 @@ static __maybe_unused int mdp5_runtime_suspend(struct device *dev)
13282 + static __maybe_unused int mdp5_runtime_resume(struct device *dev)
13283 + {
13284 + struct platform_device *pdev = to_platform_device(dev);
13285 +- struct mdp5_kms *mdp5_kms = platform_get_drvdata(pdev);
13286 ++ struct msm_drm_private *priv = platform_get_drvdata(pdev);
13287 ++ struct mdp5_kms *mdp5_kms = to_mdp5_kms(to_mdp_kms(priv->kms));
13288 +
13289 + DBG("");
13290 +
13291 +diff --git a/drivers/gpu/drm/msm/dp/dp_display.c b/drivers/gpu/drm/msm/dp/dp_display.c
13292 +index a49f6dbbe8883..c9d9b384ddd03 100644
13293 +--- a/drivers/gpu/drm/msm/dp/dp_display.c
13294 ++++ b/drivers/gpu/drm/msm/dp/dp_display.c
13295 +@@ -857,7 +857,7 @@ static int dp_display_set_mode(struct msm_dp *dp_display,
13296 +
13297 + dp = container_of(dp_display, struct dp_display_private, dp_display);
13298 +
13299 +- dp->panel->dp_mode.drm_mode = mode->drm_mode;
13300 ++ drm_mode_copy(&dp->panel->dp_mode.drm_mode, &mode->drm_mode);
13301 + dp->panel->dp_mode.bpp = mode->bpp;
13302 + dp->panel->dp_mode.capabilities = mode->capabilities;
13303 + dp_panel_init_panel_info(dp->panel);
13304 +diff --git a/drivers/gpu/drm/msm/dsi/dsi.c b/drivers/gpu/drm/msm/dsi/dsi.c
13305 +index 3db85b5c0febd..31e452ede71f0 100644
13306 +--- a/drivers/gpu/drm/msm/dsi/dsi.c
13307 ++++ b/drivers/gpu/drm/msm/dsi/dsi.c
13308 +@@ -21,7 +21,7 @@ bool msm_dsi_is_cmd_mode(struct msm_dsi *msm_dsi)
13309 + return !(host_flags & MIPI_DSI_MODE_VIDEO);
13310 + }
13311 +
13312 +-struct msm_display_dsc_config *msm_dsi_get_dsc_config(struct msm_dsi *msm_dsi)
13313 ++struct drm_dsc_config *msm_dsi_get_dsc_config(struct msm_dsi *msm_dsi)
13314 + {
13315 + return msm_dsi_host_get_dsc_config(msm_dsi->host);
13316 + }
13317 +diff --git a/drivers/gpu/drm/msm/dsi/dsi.h b/drivers/gpu/drm/msm/dsi/dsi.h
13318 +index 580a1e6358bfc..df46cdda1b433 100644
13319 +--- a/drivers/gpu/drm/msm/dsi/dsi.h
13320 ++++ b/drivers/gpu/drm/msm/dsi/dsi.h
13321 +@@ -154,7 +154,7 @@ int dsi_calc_clk_rate_v2(struct msm_dsi_host *msm_host, bool is_bonded_dsi);
13322 + int dsi_calc_clk_rate_6g(struct msm_dsi_host *msm_host, bool is_bonded_dsi);
13323 + void msm_dsi_host_snapshot(struct msm_disp_state *disp_state, struct mipi_dsi_host *host);
13324 + void msm_dsi_host_test_pattern_en(struct mipi_dsi_host *host);
13325 +-struct msm_display_dsc_config *msm_dsi_host_get_dsc_config(struct mipi_dsi_host *host);
13326 ++struct drm_dsc_config *msm_dsi_host_get_dsc_config(struct mipi_dsi_host *host);
13327 +
13328 + /* dsi phy */
13329 + struct msm_dsi_phy;
13330 +diff --git a/drivers/gpu/drm/msm/dsi/dsi_host.c b/drivers/gpu/drm/msm/dsi/dsi_host.c
13331 +index a34078497af12..cf7d5b69aac58 100644
13332 +--- a/drivers/gpu/drm/msm/dsi/dsi_host.c
13333 ++++ b/drivers/gpu/drm/msm/dsi/dsi_host.c
13334 +@@ -21,6 +21,7 @@
13335 +
13336 + #include <video/mipi_display.h>
13337 +
13338 ++#include <drm/display/drm_dsc_helper.h>
13339 + #include <drm/drm_of.h>
13340 +
13341 + #include "dsi.h"
13342 +@@ -33,7 +34,7 @@
13343 +
13344 + #define DSI_RESET_TOGGLE_DELAY_MS 20
13345 +
13346 +-static int dsi_populate_dsc_params(struct msm_display_dsc_config *dsc);
13347 ++static int dsi_populate_dsc_params(struct msm_dsi_host *msm_host, struct drm_dsc_config *dsc);
13348 +
13349 + static int dsi_get_version(const void __iomem *base, u32 *major, u32 *minor)
13350 + {
13351 +@@ -161,7 +162,7 @@ struct msm_dsi_host {
13352 + struct regmap *sfpb;
13353 +
13354 + struct drm_display_mode *mode;
13355 +- struct msm_display_dsc_config *dsc;
13356 ++ struct drm_dsc_config *dsc;
13357 +
13358 + /* connected device info */
13359 + struct device_node *device_node;
13360 +@@ -916,35 +917,28 @@ static void dsi_ctrl_config(struct msm_dsi_host *msm_host, bool enable,
13361 +
13362 + static void dsi_update_dsc_timing(struct msm_dsi_host *msm_host, bool is_cmd_mode, u32 hdisplay)
13363 + {
13364 +- struct msm_display_dsc_config *dsc = msm_host->dsc;
13365 +- u32 reg, intf_width, reg_ctrl, reg_ctrl2;
13366 ++ struct drm_dsc_config *dsc = msm_host->dsc;
13367 ++ u32 reg, reg_ctrl, reg_ctrl2;
13368 + u32 slice_per_intf, total_bytes_per_intf;
13369 + u32 pkt_per_line;
13370 +- u32 bytes_in_slice;
13371 + u32 eol_byte_num;
13372 +
13373 + /* first calculate dsc parameters and then program
13374 + * compress mode registers
13375 + */
13376 +- intf_width = hdisplay;
13377 +- slice_per_intf = DIV_ROUND_UP(intf_width, dsc->drm->slice_width);
13378 ++ slice_per_intf = DIV_ROUND_UP(hdisplay, dsc->slice_width);
13379 +
13380 + /* If slice_per_pkt is greater than slice_per_intf
13381 + * then default to 1. This can happen during partial
13382 + * update.
13383 + */
13384 +- if (slice_per_intf > dsc->drm->slice_count)
13385 +- dsc->drm->slice_count = 1;
13386 ++ if (slice_per_intf > dsc->slice_count)
13387 ++ dsc->slice_count = 1;
13388 +
13389 +- slice_per_intf = DIV_ROUND_UP(hdisplay, dsc->drm->slice_width);
13390 +- bytes_in_slice = DIV_ROUND_UP(dsc->drm->slice_width * dsc->drm->bits_per_pixel, 8);
13391 +-
13392 +- dsc->drm->slice_chunk_size = bytes_in_slice;
13393 +-
13394 +- total_bytes_per_intf = bytes_in_slice * slice_per_intf;
13395 ++ total_bytes_per_intf = dsc->slice_chunk_size * slice_per_intf;
13396 +
13397 + eol_byte_num = total_bytes_per_intf % 3;
13398 +- pkt_per_line = slice_per_intf / dsc->drm->slice_count;
13399 ++ pkt_per_line = slice_per_intf / dsc->slice_count;
13400 +
13401 + if (is_cmd_mode) /* packet data type */
13402 + reg = DSI_COMMAND_COMPRESSION_MODE_CTRL_STREAM0_DATATYPE(MIPI_DSI_DCS_LONG_WRITE);
13403 +@@ -967,7 +961,7 @@ static void dsi_update_dsc_timing(struct msm_dsi_host *msm_host, bool is_cmd_mod
13404 + reg_ctrl |= reg;
13405 +
13406 + reg_ctrl2 &= ~DSI_COMMAND_COMPRESSION_MODE_CTRL2_STREAM0_SLICE_WIDTH__MASK;
13407 +- reg_ctrl2 |= DSI_COMMAND_COMPRESSION_MODE_CTRL2_STREAM0_SLICE_WIDTH(bytes_in_slice);
13408 ++ reg_ctrl2 |= DSI_COMMAND_COMPRESSION_MODE_CTRL2_STREAM0_SLICE_WIDTH(dsc->slice_chunk_size);
13409 +
13410 + dsi_write(msm_host, REG_DSI_COMMAND_COMPRESSION_MODE_CTRL, reg_ctrl);
13411 + dsi_write(msm_host, REG_DSI_COMMAND_COMPRESSION_MODE_CTRL2, reg_ctrl2);
13412 +@@ -990,6 +984,7 @@ static void dsi_timing_setup(struct msm_dsi_host *msm_host, bool is_bonded_dsi)
13413 + u32 va_end = va_start + mode->vdisplay;
13414 + u32 hdisplay = mode->hdisplay;
13415 + u32 wc;
13416 ++ int ret;
13417 +
13418 + DBG("");
13419 +
13420 +@@ -1009,7 +1004,7 @@ static void dsi_timing_setup(struct msm_dsi_host *msm_host, bool is_bonded_dsi)
13421 + }
13422 +
13423 + if (msm_host->dsc) {
13424 +- struct msm_display_dsc_config *dsc = msm_host->dsc;
13425 ++ struct drm_dsc_config *dsc = msm_host->dsc;
13426 +
13427 + /* update dsc params with timing params */
13428 + if (!dsc || !mode->hdisplay || !mode->vdisplay) {
13429 +@@ -1018,14 +1013,16 @@ static void dsi_timing_setup(struct msm_dsi_host *msm_host, bool is_bonded_dsi)
13430 + return;
13431 + }
13432 +
13433 +- dsc->drm->pic_width = mode->hdisplay;
13434 +- dsc->drm->pic_height = mode->vdisplay;
13435 +- DBG("Mode %dx%d\n", dsc->drm->pic_width, dsc->drm->pic_height);
13436 ++ dsc->pic_width = mode->hdisplay;
13437 ++ dsc->pic_height = mode->vdisplay;
13438 ++ DBG("Mode %dx%d\n", dsc->pic_width, dsc->pic_height);
13439 +
13440 + /* we do the calculations for dsc parameters here so that
13441 + * panel can use these parameters
13442 + */
13443 +- dsi_populate_dsc_params(dsc);
13444 ++ ret = dsi_populate_dsc_params(msm_host, dsc);
13445 ++ if (ret)
13446 ++ return;
13447 +
13448 + /* Divide the display by 3 but keep back/font porch and
13449 + * pulse width same
13450 +@@ -1841,113 +1838,65 @@ static char bpg_offset[DSC_NUM_BUF_RANGES] = {
13451 + 2, 0, 0, -2, -4, -6, -8, -8, -8, -10, -10, -12, -12, -12, -12
13452 + };
13453 +
13454 +-static int dsi_populate_dsc_params(struct msm_display_dsc_config *dsc)
13455 +-{
13456 +- int mux_words_size;
13457 +- int groups_per_line, groups_total;
13458 +- int min_rate_buffer_size;
13459 +- int hrd_delay;
13460 +- int pre_num_extra_mux_bits, num_extra_mux_bits;
13461 +- int slice_bits;
13462 +- int target_bpp_x16;
13463 +- int data;
13464 +- int final_value, final_scale;
13465 ++static int dsi_populate_dsc_params(struct msm_dsi_host *msm_host, struct drm_dsc_config *dsc)
13466 ++{
13467 + int i;
13468 ++ u16 bpp = dsc->bits_per_pixel >> 4;
13469 ++
13470 ++ if (dsc->bits_per_pixel & 0xf) {
13471 ++ DRM_DEV_ERROR(&msm_host->pdev->dev, "DSI does not support fractional bits_per_pixel\n");
13472 ++ return -EINVAL;
13473 ++ }
13474 +
13475 +- dsc->drm->rc_model_size = 8192;
13476 +- dsc->drm->first_line_bpg_offset = 12;
13477 +- dsc->drm->rc_edge_factor = 6;
13478 +- dsc->drm->rc_tgt_offset_high = 3;
13479 +- dsc->drm->rc_tgt_offset_low = 3;
13480 +- dsc->drm->simple_422 = 0;
13481 +- dsc->drm->convert_rgb = 1;
13482 +- dsc->drm->vbr_enable = 0;
13483 ++ if (dsc->bits_per_component != 8) {
13484 ++ DRM_DEV_ERROR(&msm_host->pdev->dev, "DSI does not support bits_per_component != 8 yet\n");
13485 ++ return -EOPNOTSUPP;
13486 ++ }
13487 ++
13488 ++ dsc->rc_model_size = 8192;
13489 ++ dsc->first_line_bpg_offset = 12;
13490 ++ dsc->rc_edge_factor = 6;
13491 ++ dsc->rc_tgt_offset_high = 3;
13492 ++ dsc->rc_tgt_offset_low = 3;
13493 ++ dsc->simple_422 = 0;
13494 ++ dsc->convert_rgb = 1;
13495 ++ dsc->vbr_enable = 0;
13496 +
13497 + /* handle only bpp = bpc = 8 */
13498 + for (i = 0; i < DSC_NUM_BUF_RANGES - 1 ; i++)
13499 +- dsc->drm->rc_buf_thresh[i] = dsi_dsc_rc_buf_thresh[i];
13500 ++ dsc->rc_buf_thresh[i] = dsi_dsc_rc_buf_thresh[i];
13501 +
13502 + for (i = 0; i < DSC_NUM_BUF_RANGES; i++) {
13503 +- dsc->drm->rc_range_params[i].range_min_qp = min_qp[i];
13504 +- dsc->drm->rc_range_params[i].range_max_qp = max_qp[i];
13505 +- dsc->drm->rc_range_params[i].range_bpg_offset = bpg_offset[i];
13506 ++ dsc->rc_range_params[i].range_min_qp = min_qp[i];
13507 ++ dsc->rc_range_params[i].range_max_qp = max_qp[i];
13508 ++ /*
13509 ++ * Range BPG Offset contains two's-complement signed values that fill
13510 ++ * 8 bits, yet the registers and DCS PPS field are only 6 bits wide.
13511 ++ */
13512 ++ dsc->rc_range_params[i].range_bpg_offset = bpg_offset[i] & DSC_RANGE_BPG_OFFSET_MASK;
13513 + }
13514 +
13515 +- dsc->drm->initial_offset = 6144; /* Not bpp 12 */
13516 +- if (dsc->drm->bits_per_pixel != 8)
13517 +- dsc->drm->initial_offset = 2048; /* bpp = 12 */
13518 ++ dsc->initial_offset = 6144; /* Not bpp 12 */
13519 ++ if (bpp != 8)
13520 ++ dsc->initial_offset = 2048; /* bpp = 12 */
13521 +
13522 +- mux_words_size = 48; /* bpc == 8/10 */
13523 +- if (dsc->drm->bits_per_component == 12)
13524 +- mux_words_size = 64;
13525 ++ if (dsc->bits_per_component <= 10)
13526 ++ dsc->mux_word_size = DSC_MUX_WORD_SIZE_8_10_BPC;
13527 ++ else
13528 ++ dsc->mux_word_size = DSC_MUX_WORD_SIZE_12_BPC;
13529 +
13530 +- dsc->drm->initial_xmit_delay = 512;
13531 +- dsc->drm->initial_scale_value = 32;
13532 +- dsc->drm->first_line_bpg_offset = 12;
13533 +- dsc->drm->line_buf_depth = dsc->drm->bits_per_component + 1;
13534 ++ dsc->initial_xmit_delay = 512;
13535 ++ dsc->initial_scale_value = 32;
13536 ++ dsc->first_line_bpg_offset = 12;
13537 ++ dsc->line_buf_depth = dsc->bits_per_component + 1;
13538 +
13539 + /* bpc 8 */
13540 +- dsc->drm->flatness_min_qp = 3;
13541 +- dsc->drm->flatness_max_qp = 12;
13542 +- dsc->drm->rc_quant_incr_limit0 = 11;
13543 +- dsc->drm->rc_quant_incr_limit1 = 11;
13544 +- dsc->drm->mux_word_size = DSC_MUX_WORD_SIZE_8_10_BPC;
13545 +-
13546 +- /* FIXME: need to call drm_dsc_compute_rc_parameters() so that rest of
13547 +- * params are calculated
13548 +- */
13549 +- groups_per_line = DIV_ROUND_UP(dsc->drm->slice_width, 3);
13550 +- dsc->drm->slice_chunk_size = dsc->drm->slice_width * dsc->drm->bits_per_pixel / 8;
13551 +- if ((dsc->drm->slice_width * dsc->drm->bits_per_pixel) % 8)
13552 +- dsc->drm->slice_chunk_size++;
13553 +-
13554 +- /* rbs-min */
13555 +- min_rate_buffer_size = dsc->drm->rc_model_size - dsc->drm->initial_offset +
13556 +- dsc->drm->initial_xmit_delay * dsc->drm->bits_per_pixel +
13557 +- groups_per_line * dsc->drm->first_line_bpg_offset;
13558 +-
13559 +- hrd_delay = DIV_ROUND_UP(min_rate_buffer_size, dsc->drm->bits_per_pixel);
13560 +-
13561 +- dsc->drm->initial_dec_delay = hrd_delay - dsc->drm->initial_xmit_delay;
13562 ++ dsc->flatness_min_qp = 3;
13563 ++ dsc->flatness_max_qp = 12;
13564 ++ dsc->rc_quant_incr_limit0 = 11;
13565 ++ dsc->rc_quant_incr_limit1 = 11;
13566 +
13567 +- dsc->drm->initial_scale_value = 8 * dsc->drm->rc_model_size /
13568 +- (dsc->drm->rc_model_size - dsc->drm->initial_offset);
13569 +-
13570 +- slice_bits = 8 * dsc->drm->slice_chunk_size * dsc->drm->slice_height;
13571 +-
13572 +- groups_total = groups_per_line * dsc->drm->slice_height;
13573 +-
13574 +- data = dsc->drm->first_line_bpg_offset * 2048;
13575 +-
13576 +- dsc->drm->nfl_bpg_offset = DIV_ROUND_UP(data, (dsc->drm->slice_height - 1));
13577 +-
13578 +- pre_num_extra_mux_bits = 3 * (mux_words_size + (4 * dsc->drm->bits_per_component + 4) - 2);
13579 +-
13580 +- num_extra_mux_bits = pre_num_extra_mux_bits - (mux_words_size -
13581 +- ((slice_bits - pre_num_extra_mux_bits) % mux_words_size));
13582 +-
13583 +- data = 2048 * (dsc->drm->rc_model_size - dsc->drm->initial_offset + num_extra_mux_bits);
13584 +- dsc->drm->slice_bpg_offset = DIV_ROUND_UP(data, groups_total);
13585 +-
13586 +- /* bpp * 16 + 0.5 */
13587 +- data = dsc->drm->bits_per_pixel * 16;
13588 +- data *= 2;
13589 +- data++;
13590 +- data /= 2;
13591 +- target_bpp_x16 = data;
13592 +-
13593 +- data = (dsc->drm->initial_xmit_delay * target_bpp_x16) / 16;
13594 +- final_value = dsc->drm->rc_model_size - data + num_extra_mux_bits;
13595 +- dsc->drm->final_offset = final_value;
13596 +-
13597 +- final_scale = 8 * dsc->drm->rc_model_size / (dsc->drm->rc_model_size - final_value);
13598 +-
13599 +- data = (final_scale - 9) * (dsc->drm->nfl_bpg_offset + dsc->drm->slice_bpg_offset);
13600 +- dsc->drm->scale_increment_interval = (2048 * dsc->drm->final_offset) / data;
13601 +-
13602 +- dsc->drm->scale_decrement_interval = groups_per_line / (dsc->drm->initial_scale_value - 8);
13603 +-
13604 +- return 0;
13605 ++ return drm_dsc_compute_rc_parameters(dsc);
13606 + }
13607 +
13608 + static int dsi_host_parse_dt(struct msm_dsi_host *msm_host)
13609 +@@ -2165,17 +2114,8 @@ int msm_dsi_host_modeset_init(struct mipi_dsi_host *host,
13610 + msm_host->dev = dev;
13611 + panel = msm_dsi_host_get_panel(&msm_host->base);
13612 +
13613 +- if (!IS_ERR(panel) && panel->dsc) {
13614 +- struct msm_display_dsc_config *dsc = msm_host->dsc;
13615 +-
13616 +- if (!dsc) {
13617 +- dsc = devm_kzalloc(&msm_host->pdev->dev, sizeof(*dsc), GFP_KERNEL);
13618 +- if (!dsc)
13619 +- return -ENOMEM;
13620 +- dsc->drm = panel->dsc;
13621 +- msm_host->dsc = dsc;
13622 +- }
13623 +- }
13624 ++ if (!IS_ERR(panel) && panel->dsc)
13625 ++ msm_host->dsc = panel->dsc;
13626 +
13627 + ret = cfg_hnd->ops->tx_buf_alloc(msm_host, SZ_4K);
13628 + if (ret) {
13629 +@@ -2659,22 +2599,22 @@ enum drm_mode_status msm_dsi_host_check_dsc(struct mipi_dsi_host *host,
13630 + const struct drm_display_mode *mode)
13631 + {
13632 + struct msm_dsi_host *msm_host = to_msm_dsi_host(host);
13633 +- struct msm_display_dsc_config *dsc = msm_host->dsc;
13634 ++ struct drm_dsc_config *dsc = msm_host->dsc;
13635 + int pic_width = mode->hdisplay;
13636 + int pic_height = mode->vdisplay;
13637 +
13638 + if (!msm_host->dsc)
13639 + return MODE_OK;
13640 +
13641 +- if (pic_width % dsc->drm->slice_width) {
13642 ++ if (pic_width % dsc->slice_width) {
13643 + pr_err("DSI: pic_width %d has to be multiple of slice %d\n",
13644 +- pic_width, dsc->drm->slice_width);
13645 ++ pic_width, dsc->slice_width);
13646 + return MODE_H_ILLEGAL;
13647 + }
13648 +
13649 +- if (pic_height % dsc->drm->slice_height) {
13650 ++ if (pic_height % dsc->slice_height) {
13651 + pr_err("DSI: pic_height %d has to be multiple of slice %d\n",
13652 +- pic_height, dsc->drm->slice_height);
13653 ++ pic_height, dsc->slice_height);
13654 + return MODE_V_ILLEGAL;
13655 + }
13656 +
13657 +@@ -2771,7 +2711,7 @@ void msm_dsi_host_test_pattern_en(struct mipi_dsi_host *host)
13658 + DSI_TEST_PATTERN_GEN_CMD_STREAM0_TRIGGER_SW_TRIGGER);
13659 + }
13660 +
13661 +-struct msm_display_dsc_config *msm_dsi_host_get_dsc_config(struct mipi_dsi_host *host)
13662 ++struct drm_dsc_config *msm_dsi_host_get_dsc_config(struct mipi_dsi_host *host)
13663 + {
13664 + struct msm_dsi_host *msm_host = to_msm_dsi_host(host);
13665 +
13666 +diff --git a/drivers/gpu/drm/msm/hdmi/hdmi.c b/drivers/gpu/drm/msm/hdmi/hdmi.c
13667 +index f28fb21e38911..8cd5d50639a53 100644
13668 +--- a/drivers/gpu/drm/msm/hdmi/hdmi.c
13669 ++++ b/drivers/gpu/drm/msm/hdmi/hdmi.c
13670 +@@ -252,7 +252,7 @@ static struct hdmi *msm_hdmi_init(struct platform_device *pdev)
13671 + if (hdmi->hpd_gpiod)
13672 + gpiod_set_consumer_name(hdmi->hpd_gpiod, "HDMI_HPD");
13673 +
13674 +- pm_runtime_enable(&pdev->dev);
13675 ++ devm_pm_runtime_enable(&pdev->dev);
13676 +
13677 + hdmi->workq = alloc_ordered_workqueue("msm_hdmi", 0);
13678 +
13679 +diff --git a/drivers/gpu/drm/msm/msm_drv.h b/drivers/gpu/drm/msm/msm_drv.h
13680 +index 80da0d3cfdc13..03e5b6863319d 100644
13681 +--- a/drivers/gpu/drm/msm/msm_drv.h
13682 ++++ b/drivers/gpu/drm/msm/msm_drv.h
13683 +@@ -96,11 +96,6 @@ struct msm_drm_thread {
13684 + struct kthread_worker *worker;
13685 + };
13686 +
13687 +-/* DSC config */
13688 +-struct msm_display_dsc_config {
13689 +- struct drm_dsc_config *drm;
13690 +-};
13691 +-
13692 + struct msm_drm_private {
13693 +
13694 + struct drm_device *dev;
13695 +@@ -290,7 +285,7 @@ void msm_dsi_snapshot(struct msm_disp_state *disp_state, struct msm_dsi *msm_dsi
13696 + bool msm_dsi_is_cmd_mode(struct msm_dsi *msm_dsi);
13697 + bool msm_dsi_is_bonded_dsi(struct msm_dsi *msm_dsi);
13698 + bool msm_dsi_is_master_dsi(struct msm_dsi *msm_dsi);
13699 +-struct msm_display_dsc_config *msm_dsi_get_dsc_config(struct msm_dsi *msm_dsi);
13700 ++struct drm_dsc_config *msm_dsi_get_dsc_config(struct msm_dsi *msm_dsi);
13701 + #else
13702 + static inline void __init msm_dsi_register(void)
13703 + {
13704 +@@ -320,7 +315,7 @@ static inline bool msm_dsi_is_master_dsi(struct msm_dsi *msm_dsi)
13705 + return false;
13706 + }
13707 +
13708 +-static inline struct msm_display_dsc_config *msm_dsi_get_dsc_config(struct msm_dsi *msm_dsi)
13709 ++static inline struct drm_dsc_config *msm_dsi_get_dsc_config(struct msm_dsi *msm_dsi)
13710 + {
13711 + return NULL;
13712 + }
13713 +diff --git a/drivers/gpu/drm/mxsfb/lcdif_kms.c b/drivers/gpu/drm/mxsfb/lcdif_kms.c
13714 +index 1bec1279c8b56..d419c61c3407c 100644
13715 +--- a/drivers/gpu/drm/mxsfb/lcdif_kms.c
13716 ++++ b/drivers/gpu/drm/mxsfb/lcdif_kms.c
13717 +@@ -5,6 +5,7 @@
13718 + * This code is based on drivers/gpu/drm/mxsfb/mxsfb*
13719 + */
13720 +
13721 ++#include <linux/bitfield.h>
13722 + #include <linux/clk.h>
13723 + #include <linux/io.h>
13724 + #include <linux/iopoll.h>
13725 +@@ -53,16 +54,22 @@ static void lcdif_set_formats(struct lcdif_drm_private *lcdif,
13726 + writel(DISP_PARA_LINE_PATTERN_UYVY_H,
13727 + lcdif->base + LCDC_V8_DISP_PARA);
13728 +
13729 +- /* CSC: BT.601 Full Range RGB to YCbCr coefficients. */
13730 +- writel(CSC0_COEF0_A2(0x096) | CSC0_COEF0_A1(0x04c),
13731 ++ /*
13732 ++ * CSC: BT.601 Limited Range RGB to YCbCr coefficients.
13733 ++ *
13734 ++ * |Y | | 0.2568 0.5041 0.0979| |R| |16 |
13735 ++ * |Cb| = |-0.1482 -0.2910 0.4392| * |G| + |128|
13736 ++ * |Cr| | 0.4392 0.4392 -0.3678| |B| |128|
13737 ++ */
13738 ++ writel(CSC0_COEF0_A2(0x081) | CSC0_COEF0_A1(0x041),
13739 + lcdif->base + LCDC_V8_CSC0_COEF0);
13740 +- writel(CSC0_COEF1_B1(0x7d5) | CSC0_COEF1_A3(0x01d),
13741 ++ writel(CSC0_COEF1_B1(0x7db) | CSC0_COEF1_A3(0x019),
13742 + lcdif->base + LCDC_V8_CSC0_COEF1);
13743 +- writel(CSC0_COEF2_B3(0x080) | CSC0_COEF2_B2(0x7ac),
13744 ++ writel(CSC0_COEF2_B3(0x070) | CSC0_COEF2_B2(0x7b6),
13745 + lcdif->base + LCDC_V8_CSC0_COEF2);
13746 +- writel(CSC0_COEF3_C2(0x795) | CSC0_COEF3_C1(0x080),
13747 ++ writel(CSC0_COEF3_C2(0x7a2) | CSC0_COEF3_C1(0x070),
13748 + lcdif->base + LCDC_V8_CSC0_COEF3);
13749 +- writel(CSC0_COEF4_D1(0x000) | CSC0_COEF4_C3(0x7ec),
13750 ++ writel(CSC0_COEF4_D1(0x010) | CSC0_COEF4_C3(0x7ee),
13751 + lcdif->base + LCDC_V8_CSC0_COEF4);
13752 + writel(CSC0_COEF5_D3(0x080) | CSC0_COEF5_D2(0x080),
13753 + lcdif->base + LCDC_V8_CSC0_COEF5);
13754 +@@ -143,14 +150,36 @@ static void lcdif_set_mode(struct lcdif_drm_private *lcdif, u32 bus_flags)
13755 + CTRLDESCL0_1_WIDTH(m->crtc_hdisplay),
13756 + lcdif->base + LCDC_V8_CTRLDESCL0_1);
13757 +
13758 +- writel(CTRLDESCL0_3_PITCH(lcdif->crtc.primary->state->fb->pitches[0]),
13759 +- lcdif->base + LCDC_V8_CTRLDESCL0_3);
13760 ++ /*
13761 ++ * Undocumented P_SIZE and T_SIZE register but those written in the
13762 ++ * downstream kernel those registers control the AXI burst size. As of
13763 ++ * now there are two known values:
13764 ++ * 1 - 128Byte
13765 ++ * 2 - 256Byte
13766 ++ * Downstream set it to 256B burst size to improve the memory
13767 ++ * efficiency so set it here too.
13768 ++ */
13769 ++ ctrl = CTRLDESCL0_3_P_SIZE(2) | CTRLDESCL0_3_T_SIZE(2) |
13770 ++ CTRLDESCL0_3_PITCH(lcdif->crtc.primary->state->fb->pitches[0]);
13771 ++ writel(ctrl, lcdif->base + LCDC_V8_CTRLDESCL0_3);
13772 + }
13773 +
13774 + static void lcdif_enable_controller(struct lcdif_drm_private *lcdif)
13775 + {
13776 + u32 reg;
13777 +
13778 ++ /* Set FIFO Panic watermarks, low 1/3, high 2/3 . */
13779 ++ writel(FIELD_PREP(PANIC0_THRES_LOW_MASK, 1 * PANIC0_THRES_MAX / 3) |
13780 ++ FIELD_PREP(PANIC0_THRES_HIGH_MASK, 2 * PANIC0_THRES_MAX / 3),
13781 ++ lcdif->base + LCDC_V8_PANIC0_THRES);
13782 ++
13783 ++ /*
13784 ++ * Enable FIFO Panic, this does not generate interrupt, but
13785 ++ * boosts NoC priority based on FIFO Panic watermarks.
13786 ++ */
13787 ++ writel(INT_ENABLE_D1_PLANE_PANIC_EN,
13788 ++ lcdif->base + LCDC_V8_INT_ENABLE_D1);
13789 ++
13790 + reg = readl(lcdif->base + LCDC_V8_DISP_PARA);
13791 + reg |= DISP_PARA_DISP_ON;
13792 + writel(reg, lcdif->base + LCDC_V8_DISP_PARA);
13793 +@@ -178,6 +207,9 @@ static void lcdif_disable_controller(struct lcdif_drm_private *lcdif)
13794 + reg = readl(lcdif->base + LCDC_V8_DISP_PARA);
13795 + reg &= ~DISP_PARA_DISP_ON;
13796 + writel(reg, lcdif->base + LCDC_V8_DISP_PARA);
13797 ++
13798 ++ /* Disable FIFO Panic NoC priority booster. */
13799 ++ writel(0, lcdif->base + LCDC_V8_INT_ENABLE_D1);
13800 + }
13801 +
13802 + static void lcdif_reset_block(struct lcdif_drm_private *lcdif)
13803 +diff --git a/drivers/gpu/drm/mxsfb/lcdif_regs.h b/drivers/gpu/drm/mxsfb/lcdif_regs.h
13804 +index c70220651e3a5..37f0d9a06b104 100644
13805 +--- a/drivers/gpu/drm/mxsfb/lcdif_regs.h
13806 ++++ b/drivers/gpu/drm/mxsfb/lcdif_regs.h
13807 +@@ -190,6 +190,10 @@
13808 + #define CTRLDESCL0_1_WIDTH(n) ((n) & 0xffff)
13809 + #define CTRLDESCL0_1_WIDTH_MASK GENMASK(15, 0)
13810 +
13811 ++#define CTRLDESCL0_3_P_SIZE(n) (((n) << 20) & CTRLDESCL0_3_P_SIZE_MASK)
13812 ++#define CTRLDESCL0_3_P_SIZE_MASK GENMASK(22, 20)
13813 ++#define CTRLDESCL0_3_T_SIZE(n) (((n) << 16) & CTRLDESCL0_3_T_SIZE_MASK)
13814 ++#define CTRLDESCL0_3_T_SIZE_MASK GENMASK(17, 16)
13815 + #define CTRLDESCL0_3_PITCH(n) ((n) & 0xffff)
13816 + #define CTRLDESCL0_3_PITCH_MASK GENMASK(15, 0)
13817 +
13818 +@@ -248,6 +252,7 @@
13819 +
13820 + #define PANIC0_THRES_LOW_MASK GENMASK(24, 16)
13821 + #define PANIC0_THRES_HIGH_MASK GENMASK(8, 0)
13822 ++#define PANIC0_THRES_MAX 511
13823 +
13824 + #define LCDIF_MIN_XRES 120
13825 + #define LCDIF_MIN_YRES 120
13826 +diff --git a/drivers/gpu/drm/panel/panel-sitronix-st7701.c b/drivers/gpu/drm/panel/panel-sitronix-st7701.c
13827 +index 320a2a8fd4592..098955526b687 100644
13828 +--- a/drivers/gpu/drm/panel/panel-sitronix-st7701.c
13829 ++++ b/drivers/gpu/drm/panel/panel-sitronix-st7701.c
13830 +@@ -384,7 +384,15 @@ static int st7701_dsi_probe(struct mipi_dsi_device *dsi)
13831 + st7701->dsi = dsi;
13832 + st7701->desc = desc;
13833 +
13834 +- return mipi_dsi_attach(dsi);
13835 ++ ret = mipi_dsi_attach(dsi);
13836 ++ if (ret)
13837 ++ goto err_attach;
13838 ++
13839 ++ return 0;
13840 ++
13841 ++err_attach:
13842 ++ drm_panel_remove(&st7701->panel);
13843 ++ return ret;
13844 + }
13845 +
13846 + static int st7701_dsi_remove(struct mipi_dsi_device *dsi)
13847 +diff --git a/drivers/gpu/drm/radeon/radeon_bios.c b/drivers/gpu/drm/radeon/radeon_bios.c
13848 +index 33121655d50bb..63bdc9f6fc243 100644
13849 +--- a/drivers/gpu/drm/radeon/radeon_bios.c
13850 ++++ b/drivers/gpu/drm/radeon/radeon_bios.c
13851 +@@ -227,6 +227,7 @@ static bool radeon_atrm_get_bios(struct radeon_device *rdev)
13852 +
13853 + if (!found)
13854 + return false;
13855 ++ pci_dev_put(pdev);
13856 +
13857 + rdev->bios = kmalloc(size, GFP_KERNEL);
13858 + if (!rdev->bios) {
13859 +@@ -612,13 +613,14 @@ static bool radeon_acpi_vfct_bios(struct radeon_device *rdev)
13860 + acpi_size tbl_size;
13861 + UEFI_ACPI_VFCT *vfct;
13862 + unsigned offset;
13863 ++ bool r = false;
13864 +
13865 + if (!ACPI_SUCCESS(acpi_get_table("VFCT", 1, &hdr)))
13866 + return false;
13867 + tbl_size = hdr->length;
13868 + if (tbl_size < sizeof(UEFI_ACPI_VFCT)) {
13869 + DRM_ERROR("ACPI VFCT table present but broken (too short #1)\n");
13870 +- return false;
13871 ++ goto out;
13872 + }
13873 +
13874 + vfct = (UEFI_ACPI_VFCT *)hdr;
13875 +@@ -631,13 +633,13 @@ static bool radeon_acpi_vfct_bios(struct radeon_device *rdev)
13876 + offset += sizeof(VFCT_IMAGE_HEADER);
13877 + if (offset > tbl_size) {
13878 + DRM_ERROR("ACPI VFCT image header truncated\n");
13879 +- return false;
13880 ++ goto out;
13881 + }
13882 +
13883 + offset += vhdr->ImageLength;
13884 + if (offset > tbl_size) {
13885 + DRM_ERROR("ACPI VFCT image truncated\n");
13886 +- return false;
13887 ++ goto out;
13888 + }
13889 +
13890 + if (vhdr->ImageLength &&
13891 +@@ -649,15 +651,18 @@ static bool radeon_acpi_vfct_bios(struct radeon_device *rdev)
13892 + rdev->bios = kmemdup(&vbios->VbiosContent,
13893 + vhdr->ImageLength,
13894 + GFP_KERNEL);
13895 ++ if (rdev->bios)
13896 ++ r = true;
13897 +
13898 +- if (!rdev->bios)
13899 +- return false;
13900 +- return true;
13901 ++ goto out;
13902 + }
13903 + }
13904 +
13905 + DRM_ERROR("ACPI VFCT table present but broken (too short #2)\n");
13906 +- return false;
13907 ++
13908 ++out:
13909 ++ acpi_put_table(hdr);
13910 ++ return r;
13911 + }
13912 + #else
13913 + static inline bool radeon_acpi_vfct_bios(struct radeon_device *rdev)
13914 +diff --git a/drivers/gpu/drm/rcar-du/Kconfig b/drivers/gpu/drm/rcar-du/Kconfig
13915 +index f6e6a6d5d987b..b3c29ca7726e0 100644
13916 +--- a/drivers/gpu/drm/rcar-du/Kconfig
13917 ++++ b/drivers/gpu/drm/rcar-du/Kconfig
13918 +@@ -41,8 +41,6 @@ config DRM_RCAR_LVDS
13919 + depends on DRM_RCAR_USE_LVDS
13920 + select DRM_KMS_HELPER
13921 + select DRM_PANEL
13922 +- select OF_FLATTREE
13923 +- select OF_OVERLAY
13924 +
13925 + config DRM_RCAR_MIPI_DSI
13926 + tristate "R-Car DU MIPI DSI Encoder Support"
13927 +diff --git a/drivers/gpu/drm/rockchip/cdn-dp-core.c b/drivers/gpu/drm/rockchip/cdn-dp-core.c
13928 +index 518ee13b1d6f4..8526dda919317 100644
13929 +--- a/drivers/gpu/drm/rockchip/cdn-dp-core.c
13930 ++++ b/drivers/gpu/drm/rockchip/cdn-dp-core.c
13931 +@@ -571,7 +571,7 @@ static void cdn_dp_encoder_mode_set(struct drm_encoder *encoder,
13932 + video->v_sync_polarity = !!(mode->flags & DRM_MODE_FLAG_NVSYNC);
13933 + video->h_sync_polarity = !!(mode->flags & DRM_MODE_FLAG_NHSYNC);
13934 +
13935 +- memcpy(&dp->mode, adjusted, sizeof(*mode));
13936 ++ drm_mode_copy(&dp->mode, adjusted);
13937 + }
13938 +
13939 + static bool cdn_dp_check_link_status(struct cdn_dp_device *dp)
13940 +diff --git a/drivers/gpu/drm/rockchip/dw-mipi-dsi-rockchip.c b/drivers/gpu/drm/rockchip/dw-mipi-dsi-rockchip.c
13941 +index 1aa3700551f4d..1e1a8bc6c8567 100644
13942 +--- a/drivers/gpu/drm/rockchip/dw-mipi-dsi-rockchip.c
13943 ++++ b/drivers/gpu/drm/rockchip/dw-mipi-dsi-rockchip.c
13944 +@@ -1201,7 +1201,7 @@ static int dw_mipi_dsi_dphy_power_on(struct phy *phy)
13945 + return i;
13946 + }
13947 +
13948 +- ret = pm_runtime_get_sync(dsi->dev);
13949 ++ ret = pm_runtime_resume_and_get(dsi->dev);
13950 + if (ret < 0) {
13951 + DRM_DEV_ERROR(dsi->dev, "failed to enable device: %d\n", ret);
13952 + return ret;
13953 +diff --git a/drivers/gpu/drm/rockchip/inno_hdmi.c b/drivers/gpu/drm/rockchip/inno_hdmi.c
13954 +index 87b2243ea23e3..f51774866f412 100644
13955 +--- a/drivers/gpu/drm/rockchip/inno_hdmi.c
13956 ++++ b/drivers/gpu/drm/rockchip/inno_hdmi.c
13957 +@@ -499,7 +499,7 @@ static void inno_hdmi_encoder_mode_set(struct drm_encoder *encoder,
13958 + inno_hdmi_setup(hdmi, adj_mode);
13959 +
13960 + /* Store the display mode for plugin/DPMS poweron events */
13961 +- memcpy(&hdmi->previous_mode, adj_mode, sizeof(hdmi->previous_mode));
13962 ++ drm_mode_copy(&hdmi->previous_mode, adj_mode);
13963 + }
13964 +
13965 + static void inno_hdmi_encoder_enable(struct drm_encoder *encoder)
13966 +diff --git a/drivers/gpu/drm/rockchip/rk3066_hdmi.c b/drivers/gpu/drm/rockchip/rk3066_hdmi.c
13967 +index cf2cf51091a3e..90145ad969841 100644
13968 +--- a/drivers/gpu/drm/rockchip/rk3066_hdmi.c
13969 ++++ b/drivers/gpu/drm/rockchip/rk3066_hdmi.c
13970 +@@ -395,7 +395,7 @@ rk3066_hdmi_encoder_mode_set(struct drm_encoder *encoder,
13971 + struct rk3066_hdmi *hdmi = encoder_to_rk3066_hdmi(encoder);
13972 +
13973 + /* Store the display mode for plugin/DPMS poweron events. */
13974 +- memcpy(&hdmi->previous_mode, adj_mode, sizeof(hdmi->previous_mode));
13975 ++ drm_mode_copy(&hdmi->previous_mode, adj_mode);
13976 + }
13977 +
13978 + static void rk3066_hdmi_encoder_enable(struct drm_encoder *encoder)
13979 +diff --git a/drivers/gpu/drm/rockchip/rockchip_drm_vop.c b/drivers/gpu/drm/rockchip/rockchip_drm_vop.c
13980 +index ad3958b6f8bf3..9a039a31fe48e 100644
13981 +--- a/drivers/gpu/drm/rockchip/rockchip_drm_vop.c
13982 ++++ b/drivers/gpu/drm/rockchip/rockchip_drm_vop.c
13983 +@@ -605,7 +605,7 @@ static int vop_enable(struct drm_crtc *crtc, struct drm_crtc_state *old_state)
13984 + struct vop *vop = to_vop(crtc);
13985 + int ret, i;
13986 +
13987 +- ret = pm_runtime_get_sync(vop->dev);
13988 ++ ret = pm_runtime_resume_and_get(vop->dev);
13989 + if (ret < 0) {
13990 + DRM_DEV_ERROR(vop->dev, "failed to get pm runtime: %d\n", ret);
13991 + return ret;
13992 +@@ -1953,7 +1953,7 @@ static int vop_initial(struct vop *vop)
13993 + return PTR_ERR(vop->dclk);
13994 + }
13995 +
13996 +- ret = pm_runtime_get_sync(vop->dev);
13997 ++ ret = pm_runtime_resume_and_get(vop->dev);
13998 + if (ret < 0) {
13999 + DRM_DEV_ERROR(vop->dev, "failed to get pm runtime: %d\n", ret);
14000 + return ret;
14001 +diff --git a/drivers/gpu/drm/rockchip/rockchip_drm_vop2.c b/drivers/gpu/drm/rockchip/rockchip_drm_vop2.c
14002 +index 1fc04019dfd83..6dc14ea7f6fc8 100644
14003 +--- a/drivers/gpu/drm/rockchip/rockchip_drm_vop2.c
14004 ++++ b/drivers/gpu/drm/rockchip/rockchip_drm_vop2.c
14005 +@@ -823,7 +823,7 @@ static void vop2_enable(struct vop2 *vop2)
14006 + {
14007 + int ret;
14008 +
14009 +- ret = pm_runtime_get_sync(vop2->dev);
14010 ++ ret = pm_runtime_resume_and_get(vop2->dev);
14011 + if (ret < 0) {
14012 + drm_err(vop2->drm, "failed to get pm runtime: %d\n", ret);
14013 + return;
14014 +diff --git a/drivers/gpu/drm/rockchip/rockchip_lvds.c b/drivers/gpu/drm/rockchip/rockchip_lvds.c
14015 +index 5a284332ec49e..68f6ebb33460b 100644
14016 +--- a/drivers/gpu/drm/rockchip/rockchip_lvds.c
14017 ++++ b/drivers/gpu/drm/rockchip/rockchip_lvds.c
14018 +@@ -152,7 +152,7 @@ static int rk3288_lvds_poweron(struct rockchip_lvds *lvds)
14019 + DRM_DEV_ERROR(lvds->dev, "failed to enable lvds pclk %d\n", ret);
14020 + return ret;
14021 + }
14022 +- ret = pm_runtime_get_sync(lvds->dev);
14023 ++ ret = pm_runtime_resume_and_get(lvds->dev);
14024 + if (ret < 0) {
14025 + DRM_DEV_ERROR(lvds->dev, "failed to get pm runtime: %d\n", ret);
14026 + clk_disable(lvds->pclk);
14027 +@@ -336,16 +336,20 @@ static int px30_lvds_poweron(struct rockchip_lvds *lvds)
14028 + {
14029 + int ret;
14030 +
14031 +- ret = pm_runtime_get_sync(lvds->dev);
14032 ++ ret = pm_runtime_resume_and_get(lvds->dev);
14033 + if (ret < 0) {
14034 + DRM_DEV_ERROR(lvds->dev, "failed to get pm runtime: %d\n", ret);
14035 + return ret;
14036 + }
14037 +
14038 + /* Enable LVDS mode */
14039 +- return regmap_update_bits(lvds->grf, PX30_LVDS_GRF_PD_VO_CON1,
14040 ++ ret = regmap_update_bits(lvds->grf, PX30_LVDS_GRF_PD_VO_CON1,
14041 + PX30_LVDS_MODE_EN(1) | PX30_LVDS_P2S_EN(1),
14042 + PX30_LVDS_MODE_EN(1) | PX30_LVDS_P2S_EN(1));
14043 ++ if (ret)
14044 ++ pm_runtime_put(lvds->dev);
14045 ++
14046 ++ return ret;
14047 + }
14048 +
14049 + static void px30_lvds_poweroff(struct rockchip_lvds *lvds)
14050 +diff --git a/drivers/gpu/drm/sti/sti_dvo.c b/drivers/gpu/drm/sti/sti_dvo.c
14051 +index b6ee8a82e656c..577c477b5f467 100644
14052 +--- a/drivers/gpu/drm/sti/sti_dvo.c
14053 ++++ b/drivers/gpu/drm/sti/sti_dvo.c
14054 +@@ -288,7 +288,7 @@ static void sti_dvo_set_mode(struct drm_bridge *bridge,
14055 +
14056 + DRM_DEBUG_DRIVER("\n");
14057 +
14058 +- memcpy(&dvo->mode, mode, sizeof(struct drm_display_mode));
14059 ++ drm_mode_copy(&dvo->mode, mode);
14060 +
14061 + /* According to the path used (main or aux), the dvo clocks should
14062 + * have a different parent clock. */
14063 +@@ -346,8 +346,9 @@ static int sti_dvo_connector_get_modes(struct drm_connector *connector)
14064 +
14065 + #define CLK_TOLERANCE_HZ 50
14066 +
14067 +-static int sti_dvo_connector_mode_valid(struct drm_connector *connector,
14068 +- struct drm_display_mode *mode)
14069 ++static enum drm_mode_status
14070 ++sti_dvo_connector_mode_valid(struct drm_connector *connector,
14071 ++ struct drm_display_mode *mode)
14072 + {
14073 + int target = mode->clock * 1000;
14074 + int target_min = target - CLK_TOLERANCE_HZ;
14075 +diff --git a/drivers/gpu/drm/sti/sti_hda.c b/drivers/gpu/drm/sti/sti_hda.c
14076 +index 03cc401ed5934..15097ac679314 100644
14077 +--- a/drivers/gpu/drm/sti/sti_hda.c
14078 ++++ b/drivers/gpu/drm/sti/sti_hda.c
14079 +@@ -524,7 +524,7 @@ static void sti_hda_set_mode(struct drm_bridge *bridge,
14080 +
14081 + DRM_DEBUG_DRIVER("\n");
14082 +
14083 +- memcpy(&hda->mode, mode, sizeof(struct drm_display_mode));
14084 ++ drm_mode_copy(&hda->mode, mode);
14085 +
14086 + if (!hda_get_mode_idx(hda->mode, &mode_idx)) {
14087 + DRM_ERROR("Undefined mode\n");
14088 +@@ -601,8 +601,9 @@ static int sti_hda_connector_get_modes(struct drm_connector *connector)
14089 +
14090 + #define CLK_TOLERANCE_HZ 50
14091 +
14092 +-static int sti_hda_connector_mode_valid(struct drm_connector *connector,
14093 +- struct drm_display_mode *mode)
14094 ++static enum drm_mode_status
14095 ++sti_hda_connector_mode_valid(struct drm_connector *connector,
14096 ++ struct drm_display_mode *mode)
14097 + {
14098 + int target = mode->clock * 1000;
14099 + int target_min = target - CLK_TOLERANCE_HZ;
14100 +diff --git a/drivers/gpu/drm/sti/sti_hdmi.c b/drivers/gpu/drm/sti/sti_hdmi.c
14101 +index cb82622877d20..8539fe1fedc4c 100644
14102 +--- a/drivers/gpu/drm/sti/sti_hdmi.c
14103 ++++ b/drivers/gpu/drm/sti/sti_hdmi.c
14104 +@@ -941,7 +941,7 @@ static void sti_hdmi_set_mode(struct drm_bridge *bridge,
14105 + DRM_DEBUG_DRIVER("\n");
14106 +
14107 + /* Copy the drm display mode in the connector local structure */
14108 +- memcpy(&hdmi->mode, mode, sizeof(struct drm_display_mode));
14109 ++ drm_mode_copy(&hdmi->mode, mode);
14110 +
14111 + /* Update clock framerate according to the selected mode */
14112 + ret = clk_set_rate(hdmi->clk_pix, mode->clock * 1000);
14113 +@@ -1004,8 +1004,9 @@ fail:
14114 +
14115 + #define CLK_TOLERANCE_HZ 50
14116 +
14117 +-static int sti_hdmi_connector_mode_valid(struct drm_connector *connector,
14118 +- struct drm_display_mode *mode)
14119 ++static enum drm_mode_status
14120 ++sti_hdmi_connector_mode_valid(struct drm_connector *connector,
14121 ++ struct drm_display_mode *mode)
14122 + {
14123 + int target = mode->clock * 1000;
14124 + int target_min = target - CLK_TOLERANCE_HZ;
14125 +diff --git a/drivers/gpu/drm/tegra/dc.c b/drivers/gpu/drm/tegra/dc.c
14126 +index 747abafb6a5cf..b8035b3be3d32 100644
14127 +--- a/drivers/gpu/drm/tegra/dc.c
14128 ++++ b/drivers/gpu/drm/tegra/dc.c
14129 +@@ -3206,8 +3206,10 @@ static int tegra_dc_probe(struct platform_device *pdev)
14130 + usleep_range(2000, 4000);
14131 +
14132 + err = reset_control_assert(dc->rst);
14133 +- if (err < 0)
14134 ++ if (err < 0) {
14135 ++ clk_disable_unprepare(dc->clk);
14136 + return err;
14137 ++ }
14138 +
14139 + usleep_range(2000, 4000);
14140 +
14141 +diff --git a/drivers/hid/amd-sfh-hid/amd_sfh_client.c b/drivers/hid/amd-sfh-hid/amd_sfh_client.c
14142 +index 8275bba636119..ab125f79408f2 100644
14143 +--- a/drivers/hid/amd-sfh-hid/amd_sfh_client.c
14144 ++++ b/drivers/hid/amd-sfh-hid/amd_sfh_client.c
14145 +@@ -237,6 +237,10 @@ int amd_sfh_hid_client_init(struct amd_mp2_dev *privdata)
14146 + in_data->sensor_virt_addr[i] = dma_alloc_coherent(dev, sizeof(int) * 8,
14147 + &cl_data->sensor_dma_addr[i],
14148 + GFP_KERNEL);
14149 ++ if (!in_data->sensor_virt_addr[i]) {
14150 ++ rc = -ENOMEM;
14151 ++ goto cleanup;
14152 ++ }
14153 + cl_data->sensor_sts[i] = SENSOR_DISABLED;
14154 + cl_data->sensor_requested_cnt[i] = 0;
14155 + cl_data->cur_hid_dev = i;
14156 +diff --git a/drivers/hid/hid-apple.c b/drivers/hid/hid-apple.c
14157 +index 6970797cdc56d..c671ce94671ca 100644
14158 +--- a/drivers/hid/hid-apple.c
14159 ++++ b/drivers/hid/hid-apple.c
14160 +@@ -314,6 +314,7 @@ static const struct apple_key_translation swapped_option_cmd_keys[] = {
14161 +
14162 + static const struct apple_key_translation swapped_fn_leftctrl_keys[] = {
14163 + { KEY_FN, KEY_LEFTCTRL },
14164 ++ { KEY_LEFTCTRL, KEY_FN },
14165 + { }
14166 + };
14167 +
14168 +@@ -375,24 +376,40 @@ static int hidinput_apple_event(struct hid_device *hid, struct input_dev *input,
14169 + struct apple_sc *asc = hid_get_drvdata(hid);
14170 + const struct apple_key_translation *trans, *table;
14171 + bool do_translate;
14172 +- u16 code = 0;
14173 ++ u16 code = usage->code;
14174 + unsigned int real_fnmode;
14175 +
14176 +- u16 fn_keycode = (swap_fn_leftctrl) ? (KEY_LEFTCTRL) : (KEY_FN);
14177 +-
14178 +- if (usage->code == fn_keycode) {
14179 +- asc->fn_on = !!value;
14180 +- input_event_with_scancode(input, usage->type, KEY_FN,
14181 +- usage->hid, value);
14182 +- return 1;
14183 +- }
14184 +-
14185 + if (fnmode == 3) {
14186 + real_fnmode = (asc->quirks & APPLE_IS_NON_APPLE) ? 2 : 1;
14187 + } else {
14188 + real_fnmode = fnmode;
14189 + }
14190 +
14191 ++ if (swap_fn_leftctrl) {
14192 ++ trans = apple_find_translation(swapped_fn_leftctrl_keys, code);
14193 ++
14194 ++ if (trans)
14195 ++ code = trans->to;
14196 ++ }
14197 ++
14198 ++ if (iso_layout > 0 || (iso_layout < 0 && (asc->quirks & APPLE_ISO_TILDE_QUIRK) &&
14199 ++ hid->country == HID_COUNTRY_INTERNATIONAL_ISO)) {
14200 ++ trans = apple_find_translation(apple_iso_keyboard, code);
14201 ++
14202 ++ if (trans)
14203 ++ code = trans->to;
14204 ++ }
14205 ++
14206 ++ if (swap_opt_cmd) {
14207 ++ trans = apple_find_translation(swapped_option_cmd_keys, code);
14208 ++
14209 ++ if (trans)
14210 ++ code = trans->to;
14211 ++ }
14212 ++
14213 ++ if (code == KEY_FN)
14214 ++ asc->fn_on = !!value;
14215 ++
14216 + if (real_fnmode) {
14217 + if (hid->product == USB_DEVICE_ID_APPLE_ALU_WIRELESS_ANSI ||
14218 + hid->product == USB_DEVICE_ID_APPLE_ALU_WIRELESS_ISO ||
14219 +@@ -430,15 +447,18 @@ static int hidinput_apple_event(struct hid_device *hid, struct input_dev *input,
14220 + else
14221 + table = apple_fn_keys;
14222 +
14223 +- trans = apple_find_translation (table, usage->code);
14224 ++ trans = apple_find_translation(table, code);
14225 +
14226 + if (trans) {
14227 +- if (test_bit(trans->from, input->key))
14228 ++ bool from_is_set = test_bit(trans->from, input->key);
14229 ++ bool to_is_set = test_bit(trans->to, input->key);
14230 ++
14231 ++ if (from_is_set)
14232 + code = trans->from;
14233 +- else if (test_bit(trans->to, input->key))
14234 ++ else if (to_is_set)
14235 + code = trans->to;
14236 +
14237 +- if (!code) {
14238 ++ if (!(from_is_set || to_is_set)) {
14239 + if (trans->flags & APPLE_FLAG_FKEY) {
14240 + switch (real_fnmode) {
14241 + case 1:
14242 +@@ -455,62 +475,31 @@ static int hidinput_apple_event(struct hid_device *hid, struct input_dev *input,
14243 + do_translate = asc->fn_on;
14244 + }
14245 +
14246 +- code = do_translate ? trans->to : trans->from;
14247 ++ if (do_translate)
14248 ++ code = trans->to;
14249 + }
14250 +-
14251 +- input_event_with_scancode(input, usage->type, code,
14252 +- usage->hid, value);
14253 +- return 1;
14254 + }
14255 +
14256 + if (asc->quirks & APPLE_NUMLOCK_EMULATION &&
14257 +- (test_bit(usage->code, asc->pressed_numlock) ||
14258 ++ (test_bit(code, asc->pressed_numlock) ||
14259 + test_bit(LED_NUML, input->led))) {
14260 +- trans = apple_find_translation(powerbook_numlock_keys,
14261 +- usage->code);
14262 ++ trans = apple_find_translation(powerbook_numlock_keys, code);
14263 +
14264 + if (trans) {
14265 + if (value)
14266 +- set_bit(usage->code,
14267 +- asc->pressed_numlock);
14268 ++ set_bit(code, asc->pressed_numlock);
14269 + else
14270 +- clear_bit(usage->code,
14271 +- asc->pressed_numlock);
14272 ++ clear_bit(code, asc->pressed_numlock);
14273 +
14274 +- input_event_with_scancode(input, usage->type,
14275 +- trans->to, usage->hid, value);
14276 ++ code = trans->to;
14277 + }
14278 +-
14279 +- return 1;
14280 + }
14281 + }
14282 +
14283 +- if (iso_layout > 0 || (iso_layout < 0 && (asc->quirks & APPLE_ISO_TILDE_QUIRK) &&
14284 +- hid->country == HID_COUNTRY_INTERNATIONAL_ISO)) {
14285 +- trans = apple_find_translation(apple_iso_keyboard, usage->code);
14286 +- if (trans) {
14287 +- input_event_with_scancode(input, usage->type,
14288 +- trans->to, usage->hid, value);
14289 +- return 1;
14290 +- }
14291 +- }
14292 +-
14293 +- if (swap_opt_cmd) {
14294 +- trans = apple_find_translation(swapped_option_cmd_keys, usage->code);
14295 +- if (trans) {
14296 +- input_event_with_scancode(input, usage->type,
14297 +- trans->to, usage->hid, value);
14298 +- return 1;
14299 +- }
14300 +- }
14301 ++ if (usage->code != code) {
14302 ++ input_event_with_scancode(input, usage->type, code, usage->hid, value);
14303 +
14304 +- if (swap_fn_leftctrl) {
14305 +- trans = apple_find_translation(swapped_fn_leftctrl_keys, usage->code);
14306 +- if (trans) {
14307 +- input_event_with_scancode(input, usage->type,
14308 +- trans->to, usage->hid, value);
14309 +- return 1;
14310 +- }
14311 ++ return 1;
14312 + }
14313 +
14314 + return 0;
14315 +@@ -640,9 +629,6 @@ static void apple_setup_input(struct input_dev *input)
14316 + apple_setup_key_translation(input, apple2021_fn_keys);
14317 + apple_setup_key_translation(input, macbookpro_no_esc_fn_keys);
14318 + apple_setup_key_translation(input, macbookpro_dedicated_esc_fn_keys);
14319 +-
14320 +- if (swap_fn_leftctrl)
14321 +- apple_setup_key_translation(input, swapped_fn_leftctrl_keys);
14322 + }
14323 +
14324 + static int apple_input_mapping(struct hid_device *hdev, struct hid_input *hi,
14325 +@@ -1011,21 +997,21 @@ static const struct hid_device_id apple_devices[] = {
14326 + { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING9_JIS),
14327 + .driver_data = APPLE_HAS_FN | APPLE_RDESC_JIS },
14328 + { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRINGT2_J140K),
14329 +- .driver_data = APPLE_HAS_FN | APPLE_BACKLIGHT_CTL },
14330 ++ .driver_data = APPLE_HAS_FN | APPLE_BACKLIGHT_CTL | APPLE_ISO_TILDE_QUIRK },
14331 + { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRINGT2_J132),
14332 +- .driver_data = APPLE_HAS_FN | APPLE_BACKLIGHT_CTL },
14333 ++ .driver_data = APPLE_HAS_FN | APPLE_BACKLIGHT_CTL | APPLE_ISO_TILDE_QUIRK },
14334 + { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRINGT2_J680),
14335 +- .driver_data = APPLE_HAS_FN | APPLE_BACKLIGHT_CTL },
14336 ++ .driver_data = APPLE_HAS_FN | APPLE_BACKLIGHT_CTL | APPLE_ISO_TILDE_QUIRK },
14337 + { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRINGT2_J213),
14338 +- .driver_data = APPLE_HAS_FN | APPLE_BACKLIGHT_CTL },
14339 ++ .driver_data = APPLE_HAS_FN | APPLE_BACKLIGHT_CTL | APPLE_ISO_TILDE_QUIRK },
14340 + { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRINGT2_J214K),
14341 +- .driver_data = APPLE_HAS_FN },
14342 ++ .driver_data = APPLE_HAS_FN | APPLE_ISO_TILDE_QUIRK },
14343 + { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRINGT2_J223),
14344 +- .driver_data = APPLE_HAS_FN },
14345 ++ .driver_data = APPLE_HAS_FN | APPLE_ISO_TILDE_QUIRK },
14346 + { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRINGT2_J230K),
14347 +- .driver_data = APPLE_HAS_FN },
14348 ++ .driver_data = APPLE_HAS_FN | APPLE_ISO_TILDE_QUIRK },
14349 + { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRINGT2_J152F),
14350 +- .driver_data = APPLE_HAS_FN },
14351 ++ .driver_data = APPLE_HAS_FN | APPLE_ISO_TILDE_QUIRK },
14352 + { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_ANSI),
14353 + .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
14354 + { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_ISO),
14355 +diff --git a/drivers/hid/hid-input.c b/drivers/hid/hid-input.c
14356 +index 859aeb07542e3..d728a94c642eb 100644
14357 +--- a/drivers/hid/hid-input.c
14358 ++++ b/drivers/hid/hid-input.c
14359 +@@ -340,6 +340,7 @@ static enum power_supply_property hidinput_battery_props[] = {
14360 + #define HID_BATTERY_QUIRK_PERCENT (1 << 0) /* always reports percent */
14361 + #define HID_BATTERY_QUIRK_FEATURE (1 << 1) /* ask for feature report */
14362 + #define HID_BATTERY_QUIRK_IGNORE (1 << 2) /* completely ignore the battery */
14363 ++#define HID_BATTERY_QUIRK_AVOID_QUERY (1 << 3) /* do not query the battery */
14364 +
14365 + static const struct hid_device_id hid_battery_quirks[] = {
14366 + { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE,
14367 +@@ -373,6 +374,8 @@ static const struct hid_device_id hid_battery_quirks[] = {
14368 + HID_BATTERY_QUIRK_IGNORE },
14369 + { HID_USB_DEVICE(USB_VENDOR_ID_ELAN, USB_DEVICE_ID_ASUS_UX550VE_TOUCHSCREEN),
14370 + HID_BATTERY_QUIRK_IGNORE },
14371 ++ { HID_USB_DEVICE(USB_VENDOR_ID_UGEE, USB_DEVICE_ID_UGEE_XPPEN_TABLET_DECO_L),
14372 ++ HID_BATTERY_QUIRK_AVOID_QUERY },
14373 + { HID_I2C_DEVICE(USB_VENDOR_ID_ELAN, I2C_DEVICE_ID_HP_ENVY_X360_15),
14374 + HID_BATTERY_QUIRK_IGNORE },
14375 + { HID_I2C_DEVICE(USB_VENDOR_ID_ELAN, I2C_DEVICE_ID_HP_ENVY_X360_15T_DR100),
14376 +@@ -554,6 +557,9 @@ static int hidinput_setup_battery(struct hid_device *dev, unsigned report_type,
14377 + dev->battery_avoid_query = report_type == HID_INPUT_REPORT &&
14378 + field->physical == HID_DG_STYLUS;
14379 +
14380 ++ if (quirks & HID_BATTERY_QUIRK_AVOID_QUERY)
14381 ++ dev->battery_avoid_query = true;
14382 ++
14383 + dev->battery = power_supply_register(&dev->dev, psy_desc, &psy_cfg);
14384 + if (IS_ERR(dev->battery)) {
14385 + error = PTR_ERR(dev->battery);
14386 +diff --git a/drivers/hid/hid-logitech-hidpp.c b/drivers/hid/hid-logitech-hidpp.c
14387 +index 68f9e9d207f42..ba14b6f69ff7a 100644
14388 +--- a/drivers/hid/hid-logitech-hidpp.c
14389 ++++ b/drivers/hid/hid-logitech-hidpp.c
14390 +@@ -2545,12 +2545,17 @@ static int hidpp_ff_init(struct hidpp_device *hidpp,
14391 + struct hid_device *hid = hidpp->hid_dev;
14392 + struct hid_input *hidinput;
14393 + struct input_dev *dev;
14394 +- const struct usb_device_descriptor *udesc = &(hid_to_usb_dev(hid)->descriptor);
14395 +- const u16 bcdDevice = le16_to_cpu(udesc->bcdDevice);
14396 ++ struct usb_device_descriptor *udesc;
14397 ++ u16 bcdDevice;
14398 + struct ff_device *ff;
14399 + int error, j, num_slots = data->num_effects;
14400 + u8 version;
14401 +
14402 ++ if (!hid_is_usb(hid)) {
14403 ++ hid_err(hid, "device is not USB\n");
14404 ++ return -ENODEV;
14405 ++ }
14406 ++
14407 + if (list_empty(&hid->inputs)) {
14408 + hid_err(hid, "no inputs found\n");
14409 + return -ENODEV;
14410 +@@ -2564,6 +2569,8 @@ static int hidpp_ff_init(struct hidpp_device *hidpp,
14411 + }
14412 +
14413 + /* Get firmware release */
14414 ++ udesc = &(hid_to_usb_dev(hid)->descriptor);
14415 ++ bcdDevice = le16_to_cpu(udesc->bcdDevice);
14416 + version = bcdDevice & 255;
14417 +
14418 + /* Set supported force feedback capabilities */
14419 +diff --git a/drivers/hid/hid-mcp2221.c b/drivers/hid/hid-mcp2221.c
14420 +index de52e9f7bb8cb..560eeec4035aa 100644
14421 +--- a/drivers/hid/hid-mcp2221.c
14422 ++++ b/drivers/hid/hid-mcp2221.c
14423 +@@ -840,12 +840,19 @@ static int mcp2221_probe(struct hid_device *hdev,
14424 + return ret;
14425 + }
14426 +
14427 +- ret = hid_hw_start(hdev, HID_CONNECT_HIDRAW);
14428 ++ /*
14429 ++ * This driver uses the .raw_event callback and therefore does not need any
14430 ++ * HID_CONNECT_xxx flags.
14431 ++ */
14432 ++ ret = hid_hw_start(hdev, 0);
14433 + if (ret) {
14434 + hid_err(hdev, "can't start hardware\n");
14435 + return ret;
14436 + }
14437 +
14438 ++ hid_info(hdev, "USB HID v%x.%02x Device [%s] on %s\n", hdev->version >> 8,
14439 ++ hdev->version & 0xff, hdev->name, hdev->phys);
14440 ++
14441 + ret = hid_hw_open(hdev);
14442 + if (ret) {
14443 + hid_err(hdev, "can't open device\n");
14444 +@@ -870,8 +877,7 @@ static int mcp2221_probe(struct hid_device *hdev,
14445 + mcp->adapter.retries = 1;
14446 + mcp->adapter.dev.parent = &hdev->dev;
14447 + snprintf(mcp->adapter.name, sizeof(mcp->adapter.name),
14448 +- "MCP2221 usb-i2c bridge on hidraw%d",
14449 +- ((struct hidraw *)hdev->hidraw)->minor);
14450 ++ "MCP2221 usb-i2c bridge");
14451 +
14452 + ret = i2c_add_adapter(&mcp->adapter);
14453 + if (ret) {
14454 +diff --git a/drivers/hid/hid-rmi.c b/drivers/hid/hid-rmi.c
14455 +index 311eee599ce97..b2bf588d18c39 100644
14456 +--- a/drivers/hid/hid-rmi.c
14457 ++++ b/drivers/hid/hid-rmi.c
14458 +@@ -327,6 +327,8 @@ static int rmi_input_event(struct hid_device *hdev, u8 *data, int size)
14459 + if (!(test_bit(RMI_STARTED, &hdata->flags)))
14460 + return 0;
14461 +
14462 ++ pm_wakeup_event(hdev->dev.parent, 0);
14463 ++
14464 + local_irq_save(flags);
14465 +
14466 + rmi_set_attn_data(rmi_dev, data[1], &data[2], size - 2);
14467 +diff --git a/drivers/hid/hid-sensor-custom.c b/drivers/hid/hid-sensor-custom.c
14468 +index 32c2306e240d6..602465ad27458 100644
14469 +--- a/drivers/hid/hid-sensor-custom.c
14470 ++++ b/drivers/hid/hid-sensor-custom.c
14471 +@@ -62,7 +62,7 @@ struct hid_sensor_sample {
14472 + u32 raw_len;
14473 + } __packed;
14474 +
14475 +-static struct attribute hid_custom_attrs[] = {
14476 ++static struct attribute hid_custom_attrs[HID_CUSTOM_TOTAL_ATTRS] = {
14477 + {.name = "name", .mode = S_IRUGO},
14478 + {.name = "units", .mode = S_IRUGO},
14479 + {.name = "unit-expo", .mode = S_IRUGO},
14480 +diff --git a/drivers/hid/i2c-hid/i2c-hid-core.c b/drivers/hid/i2c-hid/i2c-hid-core.c
14481 +index c078f09a2318a..5a365648206e7 100644
14482 +--- a/drivers/hid/i2c-hid/i2c-hid-core.c
14483 ++++ b/drivers/hid/i2c-hid/i2c-hid-core.c
14484 +@@ -554,7 +554,8 @@ static void i2c_hid_get_input(struct i2c_hid *ihid)
14485 + i2c_hid_dbg(ihid, "input: %*ph\n", ret_size, ihid->inbuf);
14486 +
14487 + if (test_bit(I2C_HID_STARTED, &ihid->flags)) {
14488 +- pm_wakeup_event(&ihid->client->dev, 0);
14489 ++ if (ihid->hid->group != HID_GROUP_RMI)
14490 ++ pm_wakeup_event(&ihid->client->dev, 0);
14491 +
14492 + hid_input_report(ihid->hid, HID_INPUT_REPORT,
14493 + ihid->inbuf + sizeof(__le16),
14494 +diff --git a/drivers/hid/wacom_sys.c b/drivers/hid/wacom_sys.c
14495 +index 194a2e3275914..45aee464e31ab 100644
14496 +--- a/drivers/hid/wacom_sys.c
14497 ++++ b/drivers/hid/wacom_sys.c
14498 +@@ -160,6 +160,9 @@ static int wacom_raw_event(struct hid_device *hdev, struct hid_report *report,
14499 + {
14500 + struct wacom *wacom = hid_get_drvdata(hdev);
14501 +
14502 ++ if (wacom->wacom_wac.features.type == BOOTLOADER)
14503 ++ return 0;
14504 ++
14505 + if (size > WACOM_PKGLEN_MAX)
14506 + return 1;
14507 +
14508 +@@ -2790,6 +2793,11 @@ static int wacom_probe(struct hid_device *hdev,
14509 + return error;
14510 + }
14511 +
14512 ++ if (features->type == BOOTLOADER) {
14513 ++ hid_warn(hdev, "Using device in hidraw-only mode");
14514 ++ return hid_hw_start(hdev, HID_CONNECT_HIDRAW);
14515 ++ }
14516 ++
14517 + error = wacom_parse_and_register(wacom, false);
14518 + if (error)
14519 + return error;
14520 +diff --git a/drivers/hid/wacom_wac.c b/drivers/hid/wacom_wac.c
14521 +index 2bd1a43021c92..dc5478dc855be 100644
14522 +--- a/drivers/hid/wacom_wac.c
14523 ++++ b/drivers/hid/wacom_wac.c
14524 +@@ -4880,6 +4880,9 @@ static const struct wacom_features wacom_features_0x3c8 =
14525 + static const struct wacom_features wacom_features_HID_ANY_ID =
14526 + { "Wacom HID", .type = HID_GENERIC, .oVid = HID_ANY_ID, .oPid = HID_ANY_ID };
14527 +
14528 ++static const struct wacom_features wacom_features_0x94 =
14529 ++ { "Wacom Bootloader", .type = BOOTLOADER };
14530 ++
14531 + #define USB_DEVICE_WACOM(prod) \
14532 + HID_DEVICE(BUS_USB, HID_GROUP_WACOM, USB_VENDOR_ID_WACOM, prod),\
14533 + .driver_data = (kernel_ulong_t)&wacom_features_##prod
14534 +@@ -4953,6 +4956,7 @@ const struct hid_device_id wacom_ids[] = {
14535 + { USB_DEVICE_WACOM(0x84) },
14536 + { USB_DEVICE_WACOM(0x90) },
14537 + { USB_DEVICE_WACOM(0x93) },
14538 ++ { USB_DEVICE_WACOM(0x94) },
14539 + { USB_DEVICE_WACOM(0x97) },
14540 + { USB_DEVICE_WACOM(0x9A) },
14541 + { USB_DEVICE_WACOM(0x9F) },
14542 +diff --git a/drivers/hid/wacom_wac.h b/drivers/hid/wacom_wac.h
14543 +index fef1538005b5d..174b300c49ddb 100644
14544 +--- a/drivers/hid/wacom_wac.h
14545 ++++ b/drivers/hid/wacom_wac.h
14546 +@@ -245,6 +245,7 @@ enum {
14547 + MTTPC,
14548 + MTTPC_B,
14549 + HID_GENERIC,
14550 ++ BOOTLOADER,
14551 + MAX_TYPE
14552 + };
14553 +
14554 +diff --git a/drivers/hsi/controllers/omap_ssi_core.c b/drivers/hsi/controllers/omap_ssi_core.c
14555 +index eb98201583185..26f2c3c012978 100644
14556 +--- a/drivers/hsi/controllers/omap_ssi_core.c
14557 ++++ b/drivers/hsi/controllers/omap_ssi_core.c
14558 +@@ -502,8 +502,10 @@ static int ssi_probe(struct platform_device *pd)
14559 + platform_set_drvdata(pd, ssi);
14560 +
14561 + err = ssi_add_controller(ssi, pd);
14562 +- if (err < 0)
14563 ++ if (err < 0) {
14564 ++ hsi_put_controller(ssi);
14565 + goto out1;
14566 ++ }
14567 +
14568 + pm_runtime_enable(&pd->dev);
14569 +
14570 +@@ -536,9 +538,9 @@ out3:
14571 + device_for_each_child(&pd->dev, NULL, ssi_remove_ports);
14572 + out2:
14573 + ssi_remove_controller(ssi);
14574 ++ pm_runtime_disable(&pd->dev);
14575 + out1:
14576 + platform_set_drvdata(pd, NULL);
14577 +- pm_runtime_disable(&pd->dev);
14578 +
14579 + return err;
14580 + }
14581 +@@ -629,7 +631,13 @@ static int __init ssi_init(void) {
14582 + if (ret)
14583 + return ret;
14584 +
14585 +- return platform_driver_register(&ssi_port_pdriver);
14586 ++ ret = platform_driver_register(&ssi_port_pdriver);
14587 ++ if (ret) {
14588 ++ platform_driver_unregister(&ssi_pdriver);
14589 ++ return ret;
14590 ++ }
14591 ++
14592 ++ return 0;
14593 + }
14594 + module_init(ssi_init);
14595 +
14596 +diff --git a/drivers/hv/ring_buffer.c b/drivers/hv/ring_buffer.c
14597 +index 59a4aa86d1f35..c6692fd5ab155 100644
14598 +--- a/drivers/hv/ring_buffer.c
14599 ++++ b/drivers/hv/ring_buffer.c
14600 +@@ -280,6 +280,19 @@ void hv_ringbuffer_cleanup(struct hv_ring_buffer_info *ring_info)
14601 + ring_info->pkt_buffer_size = 0;
14602 + }
14603 +
14604 ++/*
14605 ++ * Check if the ring buffer spinlock is available to take or not; used on
14606 ++ * atomic contexts, like panic path (see the Hyper-V framebuffer driver).
14607 ++ */
14608 ++
14609 ++bool hv_ringbuffer_spinlock_busy(struct vmbus_channel *channel)
14610 ++{
14611 ++ struct hv_ring_buffer_info *rinfo = &channel->outbound;
14612 ++
14613 ++ return spin_is_locked(&rinfo->ring_lock);
14614 ++}
14615 ++EXPORT_SYMBOL_GPL(hv_ringbuffer_spinlock_busy);
14616 ++
14617 + /* Write to the ring buffer. */
14618 + int hv_ringbuffer_write(struct vmbus_channel *channel,
14619 + const struct kvec *kv_list, u32 kv_count,
14620 +diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig
14621 +index e70d9614bec2c..1533127960e7e 100644
14622 +--- a/drivers/hwmon/Kconfig
14623 ++++ b/drivers/hwmon/Kconfig
14624 +@@ -798,6 +798,7 @@ config SENSORS_IT87
14625 + config SENSORS_JC42
14626 + tristate "JEDEC JC42.4 compliant memory module temperature sensors"
14627 + depends on I2C
14628 ++ select REGMAP_I2C
14629 + help
14630 + If you say yes here, you get support for JEDEC JC42.4 compliant
14631 + temperature sensors, which are used on many DDR3 memory modules for
14632 +diff --git a/drivers/hwmon/jc42.c b/drivers/hwmon/jc42.c
14633 +index 07f7f8b5b73d7..50aea882ac09b 100644
14634 +--- a/drivers/hwmon/jc42.c
14635 ++++ b/drivers/hwmon/jc42.c
14636 +@@ -19,6 +19,7 @@
14637 + #include <linux/err.h>
14638 + #include <linux/mutex.h>
14639 + #include <linux/of.h>
14640 ++#include <linux/regmap.h>
14641 +
14642 + /* Addresses to scan */
14643 + static const unsigned short normal_i2c[] = {
14644 +@@ -199,31 +200,14 @@ static struct jc42_chips jc42_chips[] = {
14645 + { STM_MANID, STTS3000_DEVID, STTS3000_DEVID_MASK },
14646 + };
14647 +
14648 +-enum temp_index {
14649 +- t_input = 0,
14650 +- t_crit,
14651 +- t_min,
14652 +- t_max,
14653 +- t_num_temp
14654 +-};
14655 +-
14656 +-static const u8 temp_regs[t_num_temp] = {
14657 +- [t_input] = JC42_REG_TEMP,
14658 +- [t_crit] = JC42_REG_TEMP_CRITICAL,
14659 +- [t_min] = JC42_REG_TEMP_LOWER,
14660 +- [t_max] = JC42_REG_TEMP_UPPER,
14661 +-};
14662 +-
14663 + /* Each client has this additional data */
14664 + struct jc42_data {
14665 +- struct i2c_client *client;
14666 + struct mutex update_lock; /* protect register access */
14667 ++ struct regmap *regmap;
14668 + bool extended; /* true if extended range supported */
14669 + bool valid;
14670 +- unsigned long last_updated; /* In jiffies */
14671 + u16 orig_config; /* original configuration */
14672 + u16 config; /* current configuration */
14673 +- u16 temp[t_num_temp];/* Temperatures */
14674 + };
14675 +
14676 + #define JC42_TEMP_MIN_EXTENDED (-40000)
14677 +@@ -248,85 +232,102 @@ static int jc42_temp_from_reg(s16 reg)
14678 + return reg * 125 / 2;
14679 + }
14680 +
14681 +-static struct jc42_data *jc42_update_device(struct device *dev)
14682 +-{
14683 +- struct jc42_data *data = dev_get_drvdata(dev);
14684 +- struct i2c_client *client = data->client;
14685 +- struct jc42_data *ret = data;
14686 +- int i, val;
14687 +-
14688 +- mutex_lock(&data->update_lock);
14689 +-
14690 +- if (time_after(jiffies, data->last_updated + HZ) || !data->valid) {
14691 +- for (i = 0; i < t_num_temp; i++) {
14692 +- val = i2c_smbus_read_word_swapped(client, temp_regs[i]);
14693 +- if (val < 0) {
14694 +- ret = ERR_PTR(val);
14695 +- goto abort;
14696 +- }
14697 +- data->temp[i] = val;
14698 +- }
14699 +- data->last_updated = jiffies;
14700 +- data->valid = true;
14701 +- }
14702 +-abort:
14703 +- mutex_unlock(&data->update_lock);
14704 +- return ret;
14705 +-}
14706 +-
14707 + static int jc42_read(struct device *dev, enum hwmon_sensor_types type,
14708 + u32 attr, int channel, long *val)
14709 + {
14710 +- struct jc42_data *data = jc42_update_device(dev);
14711 +- int temp, hyst;
14712 ++ struct jc42_data *data = dev_get_drvdata(dev);
14713 ++ unsigned int regval;
14714 ++ int ret, temp, hyst;
14715 +
14716 +- if (IS_ERR(data))
14717 +- return PTR_ERR(data);
14718 ++ mutex_lock(&data->update_lock);
14719 +
14720 + switch (attr) {
14721 + case hwmon_temp_input:
14722 +- *val = jc42_temp_from_reg(data->temp[t_input]);
14723 +- return 0;
14724 ++ ret = regmap_read(data->regmap, JC42_REG_TEMP, &regval);
14725 ++ if (ret)
14726 ++ break;
14727 ++
14728 ++ *val = jc42_temp_from_reg(regval);
14729 ++ break;
14730 + case hwmon_temp_min:
14731 +- *val = jc42_temp_from_reg(data->temp[t_min]);
14732 +- return 0;
14733 ++ ret = regmap_read(data->regmap, JC42_REG_TEMP_LOWER, &regval);
14734 ++ if (ret)
14735 ++ break;
14736 ++
14737 ++ *val = jc42_temp_from_reg(regval);
14738 ++ break;
14739 + case hwmon_temp_max:
14740 +- *val = jc42_temp_from_reg(data->temp[t_max]);
14741 +- return 0;
14742 ++ ret = regmap_read(data->regmap, JC42_REG_TEMP_UPPER, &regval);
14743 ++ if (ret)
14744 ++ break;
14745 ++
14746 ++ *val = jc42_temp_from_reg(regval);
14747 ++ break;
14748 + case hwmon_temp_crit:
14749 +- *val = jc42_temp_from_reg(data->temp[t_crit]);
14750 +- return 0;
14751 ++ ret = regmap_read(data->regmap, JC42_REG_TEMP_CRITICAL,
14752 ++ &regval);
14753 ++ if (ret)
14754 ++ break;
14755 ++
14756 ++ *val = jc42_temp_from_reg(regval);
14757 ++ break;
14758 + case hwmon_temp_max_hyst:
14759 +- temp = jc42_temp_from_reg(data->temp[t_max]);
14760 ++ ret = regmap_read(data->regmap, JC42_REG_TEMP_UPPER, &regval);
14761 ++ if (ret)
14762 ++ break;
14763 ++
14764 ++ temp = jc42_temp_from_reg(regval);
14765 + hyst = jc42_hysteresis[(data->config & JC42_CFG_HYST_MASK)
14766 + >> JC42_CFG_HYST_SHIFT];
14767 + *val = temp - hyst;
14768 +- return 0;
14769 ++ break;
14770 + case hwmon_temp_crit_hyst:
14771 +- temp = jc42_temp_from_reg(data->temp[t_crit]);
14772 ++ ret = regmap_read(data->regmap, JC42_REG_TEMP_CRITICAL,
14773 ++ &regval);
14774 ++ if (ret)
14775 ++ break;
14776 ++
14777 ++ temp = jc42_temp_from_reg(regval);
14778 + hyst = jc42_hysteresis[(data->config & JC42_CFG_HYST_MASK)
14779 + >> JC42_CFG_HYST_SHIFT];
14780 + *val = temp - hyst;
14781 +- return 0;
14782 ++ break;
14783 + case hwmon_temp_min_alarm:
14784 +- *val = (data->temp[t_input] >> JC42_ALARM_MIN_BIT) & 1;
14785 +- return 0;
14786 ++ ret = regmap_read(data->regmap, JC42_REG_TEMP, &regval);
14787 ++ if (ret)
14788 ++ break;
14789 ++
14790 ++ *val = (regval >> JC42_ALARM_MIN_BIT) & 1;
14791 ++ break;
14792 + case hwmon_temp_max_alarm:
14793 +- *val = (data->temp[t_input] >> JC42_ALARM_MAX_BIT) & 1;
14794 +- return 0;
14795 ++ ret = regmap_read(data->regmap, JC42_REG_TEMP, &regval);
14796 ++ if (ret)
14797 ++ break;
14798 ++
14799 ++ *val = (regval >> JC42_ALARM_MAX_BIT) & 1;
14800 ++ break;
14801 + case hwmon_temp_crit_alarm:
14802 +- *val = (data->temp[t_input] >> JC42_ALARM_CRIT_BIT) & 1;
14803 +- return 0;
14804 ++ ret = regmap_read(data->regmap, JC42_REG_TEMP, &regval);
14805 ++ if (ret)
14806 ++ break;
14807 ++
14808 ++ *val = (regval >> JC42_ALARM_CRIT_BIT) & 1;
14809 ++ break;
14810 + default:
14811 +- return -EOPNOTSUPP;
14812 ++ ret = -EOPNOTSUPP;
14813 ++ break;
14814 + }
14815 ++
14816 ++ mutex_unlock(&data->update_lock);
14817 ++
14818 ++ return ret;
14819 + }
14820 +
14821 + static int jc42_write(struct device *dev, enum hwmon_sensor_types type,
14822 + u32 attr, int channel, long val)
14823 + {
14824 + struct jc42_data *data = dev_get_drvdata(dev);
14825 +- struct i2c_client *client = data->client;
14826 ++ unsigned int regval;
14827 + int diff, hyst;
14828 + int ret;
14829 +
14830 +@@ -334,21 +335,23 @@ static int jc42_write(struct device *dev, enum hwmon_sensor_types type,
14831 +
14832 + switch (attr) {
14833 + case hwmon_temp_min:
14834 +- data->temp[t_min] = jc42_temp_to_reg(val, data->extended);
14835 +- ret = i2c_smbus_write_word_swapped(client, temp_regs[t_min],
14836 +- data->temp[t_min]);
14837 ++ ret = regmap_write(data->regmap, JC42_REG_TEMP_LOWER,
14838 ++ jc42_temp_to_reg(val, data->extended));
14839 + break;
14840 + case hwmon_temp_max:
14841 +- data->temp[t_max] = jc42_temp_to_reg(val, data->extended);
14842 +- ret = i2c_smbus_write_word_swapped(client, temp_regs[t_max],
14843 +- data->temp[t_max]);
14844 ++ ret = regmap_write(data->regmap, JC42_REG_TEMP_UPPER,
14845 ++ jc42_temp_to_reg(val, data->extended));
14846 + break;
14847 + case hwmon_temp_crit:
14848 +- data->temp[t_crit] = jc42_temp_to_reg(val, data->extended);
14849 +- ret = i2c_smbus_write_word_swapped(client, temp_regs[t_crit],
14850 +- data->temp[t_crit]);
14851 ++ ret = regmap_write(data->regmap, JC42_REG_TEMP_CRITICAL,
14852 ++ jc42_temp_to_reg(val, data->extended));
14853 + break;
14854 + case hwmon_temp_crit_hyst:
14855 ++ ret = regmap_read(data->regmap, JC42_REG_TEMP_CRITICAL,
14856 ++ &regval);
14857 ++ if (ret)
14858 ++ break;
14859 ++
14860 + /*
14861 + * JC42.4 compliant chips only support four hysteresis values.
14862 + * Pick best choice and go from there.
14863 +@@ -356,7 +359,7 @@ static int jc42_write(struct device *dev, enum hwmon_sensor_types type,
14864 + val = clamp_val(val, (data->extended ? JC42_TEMP_MIN_EXTENDED
14865 + : JC42_TEMP_MIN) - 6000,
14866 + JC42_TEMP_MAX);
14867 +- diff = jc42_temp_from_reg(data->temp[t_crit]) - val;
14868 ++ diff = jc42_temp_from_reg(regval) - val;
14869 + hyst = 0;
14870 + if (diff > 0) {
14871 + if (diff < 2250)
14872 +@@ -368,9 +371,8 @@ static int jc42_write(struct device *dev, enum hwmon_sensor_types type,
14873 + }
14874 + data->config = (data->config & ~JC42_CFG_HYST_MASK) |
14875 + (hyst << JC42_CFG_HYST_SHIFT);
14876 +- ret = i2c_smbus_write_word_swapped(data->client,
14877 +- JC42_REG_CONFIG,
14878 +- data->config);
14879 ++ ret = regmap_write(data->regmap, JC42_REG_CONFIG,
14880 ++ data->config);
14881 + break;
14882 + default:
14883 + ret = -EOPNOTSUPP;
14884 +@@ -470,51 +472,80 @@ static const struct hwmon_chip_info jc42_chip_info = {
14885 + .info = jc42_info,
14886 + };
14887 +
14888 ++static bool jc42_readable_reg(struct device *dev, unsigned int reg)
14889 ++{
14890 ++ return (reg >= JC42_REG_CAP && reg <= JC42_REG_DEVICEID) ||
14891 ++ reg == JC42_REG_SMBUS;
14892 ++}
14893 ++
14894 ++static bool jc42_writable_reg(struct device *dev, unsigned int reg)
14895 ++{
14896 ++ return (reg >= JC42_REG_CONFIG && reg <= JC42_REG_TEMP_CRITICAL) ||
14897 ++ reg == JC42_REG_SMBUS;
14898 ++}
14899 ++
14900 ++static bool jc42_volatile_reg(struct device *dev, unsigned int reg)
14901 ++{
14902 ++ return reg == JC42_REG_CONFIG || reg == JC42_REG_TEMP;
14903 ++}
14904 ++
14905 ++static const struct regmap_config jc42_regmap_config = {
14906 ++ .reg_bits = 8,
14907 ++ .val_bits = 16,
14908 ++ .val_format_endian = REGMAP_ENDIAN_BIG,
14909 ++ .max_register = JC42_REG_SMBUS,
14910 ++ .writeable_reg = jc42_writable_reg,
14911 ++ .readable_reg = jc42_readable_reg,
14912 ++ .volatile_reg = jc42_volatile_reg,
14913 ++ .cache_type = REGCACHE_RBTREE,
14914 ++};
14915 ++
14916 + static int jc42_probe(struct i2c_client *client)
14917 + {
14918 + struct device *dev = &client->dev;
14919 + struct device *hwmon_dev;
14920 ++ unsigned int config, cap;
14921 + struct jc42_data *data;
14922 +- int config, cap;
14923 ++ int ret;
14924 +
14925 + data = devm_kzalloc(dev, sizeof(struct jc42_data), GFP_KERNEL);
14926 + if (!data)
14927 + return -ENOMEM;
14928 +
14929 +- data->client = client;
14930 ++ data->regmap = devm_regmap_init_i2c(client, &jc42_regmap_config);
14931 ++ if (IS_ERR(data->regmap))
14932 ++ return PTR_ERR(data->regmap);
14933 ++
14934 + i2c_set_clientdata(client, data);
14935 + mutex_init(&data->update_lock);
14936 +
14937 +- cap = i2c_smbus_read_word_swapped(client, JC42_REG_CAP);
14938 +- if (cap < 0)
14939 +- return cap;
14940 ++ ret = regmap_read(data->regmap, JC42_REG_CAP, &cap);
14941 ++ if (ret)
14942 ++ return ret;
14943 +
14944 + data->extended = !!(cap & JC42_CAP_RANGE);
14945 +
14946 + if (device_property_read_bool(dev, "smbus-timeout-disable")) {
14947 +- int smbus;
14948 +-
14949 + /*
14950 + * Not all chips support this register, but from a
14951 + * quick read of various datasheets no chip appears
14952 + * incompatible with the below attempt to disable
14953 + * the timeout. And the whole thing is opt-in...
14954 + */
14955 +- smbus = i2c_smbus_read_word_swapped(client, JC42_REG_SMBUS);
14956 +- if (smbus < 0)
14957 +- return smbus;
14958 +- i2c_smbus_write_word_swapped(client, JC42_REG_SMBUS,
14959 +- smbus | SMBUS_STMOUT);
14960 ++ ret = regmap_set_bits(data->regmap, JC42_REG_SMBUS,
14961 ++ SMBUS_STMOUT);
14962 ++ if (ret)
14963 ++ return ret;
14964 + }
14965 +
14966 +- config = i2c_smbus_read_word_swapped(client, JC42_REG_CONFIG);
14967 +- if (config < 0)
14968 +- return config;
14969 ++ ret = regmap_read(data->regmap, JC42_REG_CONFIG, &config);
14970 ++ if (ret)
14971 ++ return ret;
14972 +
14973 + data->orig_config = config;
14974 + if (config & JC42_CFG_SHUTDOWN) {
14975 + config &= ~JC42_CFG_SHUTDOWN;
14976 +- i2c_smbus_write_word_swapped(client, JC42_REG_CONFIG, config);
14977 ++ regmap_write(data->regmap, JC42_REG_CONFIG, config);
14978 + }
14979 + data->config = config;
14980 +
14981 +@@ -535,7 +566,7 @@ static int jc42_remove(struct i2c_client *client)
14982 +
14983 + config = (data->orig_config & ~JC42_CFG_HYST_MASK)
14984 + | (data->config & JC42_CFG_HYST_MASK);
14985 +- i2c_smbus_write_word_swapped(client, JC42_REG_CONFIG, config);
14986 ++ regmap_write(data->regmap, JC42_REG_CONFIG, config);
14987 + }
14988 + return 0;
14989 + }
14990 +@@ -547,8 +578,11 @@ static int jc42_suspend(struct device *dev)
14991 + struct jc42_data *data = dev_get_drvdata(dev);
14992 +
14993 + data->config |= JC42_CFG_SHUTDOWN;
14994 +- i2c_smbus_write_word_swapped(data->client, JC42_REG_CONFIG,
14995 +- data->config);
14996 ++ regmap_write(data->regmap, JC42_REG_CONFIG, data->config);
14997 ++
14998 ++ regcache_cache_only(data->regmap, true);
14999 ++ regcache_mark_dirty(data->regmap);
15000 ++
15001 + return 0;
15002 + }
15003 +
15004 +@@ -556,10 +590,13 @@ static int jc42_resume(struct device *dev)
15005 + {
15006 + struct jc42_data *data = dev_get_drvdata(dev);
15007 +
15008 ++ regcache_cache_only(data->regmap, false);
15009 ++
15010 + data->config &= ~JC42_CFG_SHUTDOWN;
15011 +- i2c_smbus_write_word_swapped(data->client, JC42_REG_CONFIG,
15012 +- data->config);
15013 +- return 0;
15014 ++ regmap_write(data->regmap, JC42_REG_CONFIG, data->config);
15015 ++
15016 ++ /* Restore cached register values to hardware */
15017 ++ return regcache_sync(data->regmap);
15018 + }
15019 +
15020 + static const struct dev_pm_ops jc42_dev_pm_ops = {
15021 +diff --git a/drivers/hwmon/nct6775-platform.c b/drivers/hwmon/nct6775-platform.c
15022 +index 41c97cfacfb8c..50fe9533cf439 100644
15023 +--- a/drivers/hwmon/nct6775-platform.c
15024 ++++ b/drivers/hwmon/nct6775-platform.c
15025 +@@ -1043,7 +1043,9 @@ static struct platform_device *pdev[2];
15026 +
15027 + static const char * const asus_wmi_boards[] = {
15028 + "PRO H410T",
15029 ++ "ProArt B550-CREATOR",
15030 + "ProArt X570-CREATOR WIFI",
15031 ++ "ProArt Z490-CREATOR 10G",
15032 + "Pro B550M-C",
15033 + "Pro WS X570-ACE",
15034 + "PRIME B360-PLUS",
15035 +@@ -1055,8 +1057,10 @@ static const char * const asus_wmi_boards[] = {
15036 + "PRIME X570-P",
15037 + "PRIME X570-PRO",
15038 + "ROG CROSSHAIR VIII DARK HERO",
15039 ++ "ROG CROSSHAIR VIII EXTREME",
15040 + "ROG CROSSHAIR VIII FORMULA",
15041 + "ROG CROSSHAIR VIII HERO",
15042 ++ "ROG CROSSHAIR VIII HERO (WI-FI)",
15043 + "ROG CROSSHAIR VIII IMPACT",
15044 + "ROG STRIX B550-A GAMING",
15045 + "ROG STRIX B550-E GAMING",
15046 +@@ -1080,8 +1084,11 @@ static const char * const asus_wmi_boards[] = {
15047 + "ROG STRIX Z490-G GAMING (WI-FI)",
15048 + "ROG STRIX Z490-H GAMING",
15049 + "ROG STRIX Z490-I GAMING",
15050 ++ "TUF GAMING B550M-E",
15051 ++ "TUF GAMING B550M-E (WI-FI)",
15052 + "TUF GAMING B550M-PLUS",
15053 + "TUF GAMING B550M-PLUS (WI-FI)",
15054 ++ "TUF GAMING B550M-PLUS WIFI II",
15055 + "TUF GAMING B550-PLUS",
15056 + "TUF GAMING B550-PLUS WIFI II",
15057 + "TUF GAMING B550-PRO",
15058 +diff --git a/drivers/hwtracing/coresight/coresight-trbe.c b/drivers/hwtracing/coresight/coresight-trbe.c
15059 +index 2b386bb848f8d..1fc4fd79a1c69 100644
15060 +--- a/drivers/hwtracing/coresight/coresight-trbe.c
15061 ++++ b/drivers/hwtracing/coresight/coresight-trbe.c
15062 +@@ -1434,6 +1434,7 @@ static int arm_trbe_probe_cpuhp(struct trbe_drvdata *drvdata)
15063 +
15064 + static void arm_trbe_remove_cpuhp(struct trbe_drvdata *drvdata)
15065 + {
15066 ++ cpuhp_state_remove_instance(drvdata->trbe_online, &drvdata->hotplug_node);
15067 + cpuhp_remove_multi_state(drvdata->trbe_online);
15068 + }
15069 +
15070 +diff --git a/drivers/i2c/busses/i2c-ismt.c b/drivers/i2c/busses/i2c-ismt.c
15071 +index 6078fa0c0d488..63120c41354c0 100644
15072 +--- a/drivers/i2c/busses/i2c-ismt.c
15073 ++++ b/drivers/i2c/busses/i2c-ismt.c
15074 +@@ -509,6 +509,9 @@ static int ismt_access(struct i2c_adapter *adap, u16 addr,
15075 + if (read_write == I2C_SMBUS_WRITE) {
15076 + /* Block Write */
15077 + dev_dbg(dev, "I2C_SMBUS_BLOCK_DATA: WRITE\n");
15078 ++ if (data->block[0] < 1 || data->block[0] > I2C_SMBUS_BLOCK_MAX)
15079 ++ return -EINVAL;
15080 ++
15081 + dma_size = data->block[0] + 1;
15082 + dma_direction = DMA_TO_DEVICE;
15083 + desc->wr_len_cmd = dma_size;
15084 +diff --git a/drivers/i2c/busses/i2c-pxa-pci.c b/drivers/i2c/busses/i2c-pxa-pci.c
15085 +index f614cade432bb..30e38bc8b6db8 100644
15086 +--- a/drivers/i2c/busses/i2c-pxa-pci.c
15087 ++++ b/drivers/i2c/busses/i2c-pxa-pci.c
15088 +@@ -105,7 +105,7 @@ static int ce4100_i2c_probe(struct pci_dev *dev,
15089 + int i;
15090 + struct ce4100_devices *sds;
15091 +
15092 +- ret = pci_enable_device_mem(dev);
15093 ++ ret = pcim_enable_device(dev);
15094 + if (ret)
15095 + return ret;
15096 +
15097 +@@ -114,10 +114,8 @@ static int ce4100_i2c_probe(struct pci_dev *dev,
15098 + return -EINVAL;
15099 + }
15100 + sds = kzalloc(sizeof(*sds), GFP_KERNEL);
15101 +- if (!sds) {
15102 +- ret = -ENOMEM;
15103 +- goto err_mem;
15104 +- }
15105 ++ if (!sds)
15106 ++ return -ENOMEM;
15107 +
15108 + for (i = 0; i < ARRAY_SIZE(sds->pdev); i++) {
15109 + sds->pdev[i] = add_i2c_device(dev, i);
15110 +@@ -133,8 +131,6 @@ static int ce4100_i2c_probe(struct pci_dev *dev,
15111 +
15112 + err_dev_add:
15113 + kfree(sds);
15114 +-err_mem:
15115 +- pci_disable_device(dev);
15116 + return ret;
15117 + }
15118 +
15119 +diff --git a/drivers/i2c/muxes/i2c-mux-reg.c b/drivers/i2c/muxes/i2c-mux-reg.c
15120 +index 0e0679f65cf77..30a6de1694e07 100644
15121 +--- a/drivers/i2c/muxes/i2c-mux-reg.c
15122 ++++ b/drivers/i2c/muxes/i2c-mux-reg.c
15123 +@@ -183,13 +183,12 @@ static int i2c_mux_reg_probe(struct platform_device *pdev)
15124 + if (!mux->data.reg) {
15125 + dev_info(&pdev->dev,
15126 + "Register not set, using platform resource\n");
15127 +- res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
15128 +- mux->data.reg_size = resource_size(res);
15129 +- mux->data.reg = devm_ioremap_resource(&pdev->dev, res);
15130 ++ mux->data.reg = devm_platform_get_and_ioremap_resource(pdev, 0, &res);
15131 + if (IS_ERR(mux->data.reg)) {
15132 + ret = PTR_ERR(mux->data.reg);
15133 + goto err_put_parent;
15134 + }
15135 ++ mux->data.reg_size = resource_size(res);
15136 + }
15137 +
15138 + if (mux->data.reg_size != 4 && mux->data.reg_size != 2 &&
15139 +diff --git a/drivers/iio/adc/ad_sigma_delta.c b/drivers/iio/adc/ad_sigma_delta.c
15140 +index 261a9a6b45e15..d8570f620785a 100644
15141 +--- a/drivers/iio/adc/ad_sigma_delta.c
15142 ++++ b/drivers/iio/adc/ad_sigma_delta.c
15143 +@@ -281,10 +281,10 @@ int ad_sigma_delta_single_conversion(struct iio_dev *indio_dev,
15144 + unsigned int data_reg;
15145 + int ret = 0;
15146 +
15147 +- if (iio_buffer_enabled(indio_dev))
15148 +- return -EBUSY;
15149 ++ ret = iio_device_claim_direct_mode(indio_dev);
15150 ++ if (ret)
15151 ++ return ret;
15152 +
15153 +- mutex_lock(&indio_dev->mlock);
15154 + ad_sigma_delta_set_channel(sigma_delta, chan->address);
15155 +
15156 + spi_bus_lock(sigma_delta->spi->master);
15157 +@@ -323,7 +323,7 @@ out:
15158 + ad_sigma_delta_set_mode(sigma_delta, AD_SD_MODE_IDLE);
15159 + sigma_delta->bus_locked = false;
15160 + spi_bus_unlock(sigma_delta->spi->master);
15161 +- mutex_unlock(&indio_dev->mlock);
15162 ++ iio_device_release_direct_mode(indio_dev);
15163 +
15164 + if (ret)
15165 + return ret;
15166 +diff --git a/drivers/iio/adc/ti-adc128s052.c b/drivers/iio/adc/ti-adc128s052.c
15167 +index 622fd384983c7..b3d5b9b7255bc 100644
15168 +--- a/drivers/iio/adc/ti-adc128s052.c
15169 ++++ b/drivers/iio/adc/ti-adc128s052.c
15170 +@@ -181,13 +181,13 @@ static int adc128_probe(struct spi_device *spi)
15171 + }
15172 +
15173 + static const struct of_device_id adc128_of_match[] = {
15174 +- { .compatible = "ti,adc128s052", },
15175 +- { .compatible = "ti,adc122s021", },
15176 +- { .compatible = "ti,adc122s051", },
15177 +- { .compatible = "ti,adc122s101", },
15178 +- { .compatible = "ti,adc124s021", },
15179 +- { .compatible = "ti,adc124s051", },
15180 +- { .compatible = "ti,adc124s101", },
15181 ++ { .compatible = "ti,adc128s052", .data = (void*)0L, },
15182 ++ { .compatible = "ti,adc122s021", .data = (void*)1L, },
15183 ++ { .compatible = "ti,adc122s051", .data = (void*)1L, },
15184 ++ { .compatible = "ti,adc122s101", .data = (void*)1L, },
15185 ++ { .compatible = "ti,adc124s021", .data = (void*)2L, },
15186 ++ { .compatible = "ti,adc124s051", .data = (void*)2L, },
15187 ++ { .compatible = "ti,adc124s101", .data = (void*)2L, },
15188 + { /* sentinel */ },
15189 + };
15190 + MODULE_DEVICE_TABLE(of, adc128_of_match);
15191 +diff --git a/drivers/iio/addac/ad74413r.c b/drivers/iio/addac/ad74413r.c
15192 +index 899bcd83f40bc..e0e130ba9d3ec 100644
15193 +--- a/drivers/iio/addac/ad74413r.c
15194 ++++ b/drivers/iio/addac/ad74413r.c
15195 +@@ -691,7 +691,7 @@ static int ad74413_get_input_current_offset(struct ad74413r_state *st,
15196 + if (ret)
15197 + return ret;
15198 +
15199 +- *val = voltage_offset * AD74413R_ADC_RESULT_MAX / voltage_range;
15200 ++ *val = voltage_offset * (int)AD74413R_ADC_RESULT_MAX / voltage_range;
15201 +
15202 + return IIO_VAL_INT;
15203 + }
15204 +diff --git a/drivers/iio/imu/adis.c b/drivers/iio/imu/adis.c
15205 +index f7fcfd04f659d..bc40240b29e26 100644
15206 +--- a/drivers/iio/imu/adis.c
15207 ++++ b/drivers/iio/imu/adis.c
15208 +@@ -270,23 +270,19 @@ EXPORT_SYMBOL_NS(adis_debugfs_reg_access, IIO_ADISLIB);
15209 + #endif
15210 +
15211 + /**
15212 +- * adis_enable_irq() - Enable or disable data ready IRQ
15213 ++ * __adis_enable_irq() - Enable or disable data ready IRQ (unlocked)
15214 + * @adis: The adis device
15215 + * @enable: Whether to enable the IRQ
15216 + *
15217 + * Returns 0 on success, negative error code otherwise
15218 + */
15219 +-int adis_enable_irq(struct adis *adis, bool enable)
15220 ++int __adis_enable_irq(struct adis *adis, bool enable)
15221 + {
15222 +- int ret = 0;
15223 ++ int ret;
15224 + u16 msc;
15225 +
15226 +- mutex_lock(&adis->state_lock);
15227 +-
15228 +- if (adis->data->enable_irq) {
15229 +- ret = adis->data->enable_irq(adis, enable);
15230 +- goto out_unlock;
15231 +- }
15232 ++ if (adis->data->enable_irq)
15233 ++ return adis->data->enable_irq(adis, enable);
15234 +
15235 + if (adis->data->unmasked_drdy) {
15236 + if (enable)
15237 +@@ -294,12 +290,12 @@ int adis_enable_irq(struct adis *adis, bool enable)
15238 + else
15239 + disable_irq(adis->spi->irq);
15240 +
15241 +- goto out_unlock;
15242 ++ return 0;
15243 + }
15244 +
15245 + ret = __adis_read_reg_16(adis, adis->data->msc_ctrl_reg, &msc);
15246 + if (ret)
15247 +- goto out_unlock;
15248 ++ return ret;
15249 +
15250 + msc |= ADIS_MSC_CTRL_DATA_RDY_POL_HIGH;
15251 + msc &= ~ADIS_MSC_CTRL_DATA_RDY_DIO2;
15252 +@@ -308,13 +304,9 @@ int adis_enable_irq(struct adis *adis, bool enable)
15253 + else
15254 + msc &= ~ADIS_MSC_CTRL_DATA_RDY_EN;
15255 +
15256 +- ret = __adis_write_reg_16(adis, adis->data->msc_ctrl_reg, msc);
15257 +-
15258 +-out_unlock:
15259 +- mutex_unlock(&adis->state_lock);
15260 +- return ret;
15261 ++ return __adis_write_reg_16(adis, adis->data->msc_ctrl_reg, msc);
15262 + }
15263 +-EXPORT_SYMBOL_NS(adis_enable_irq, IIO_ADISLIB);
15264 ++EXPORT_SYMBOL_NS(__adis_enable_irq, IIO_ADISLIB);
15265 +
15266 + /**
15267 + * __adis_check_status() - Check the device for error conditions (unlocked)
15268 +@@ -445,7 +437,7 @@ int __adis_initial_startup(struct adis *adis)
15269 + * with 'IRQF_NO_AUTOEN' anyways.
15270 + */
15271 + if (!adis->data->unmasked_drdy)
15272 +- adis_enable_irq(adis, false);
15273 ++ __adis_enable_irq(adis, false);
15274 +
15275 + if (!adis->data->prod_id_reg)
15276 + return 0;
15277 +diff --git a/drivers/iio/industrialio-event.c b/drivers/iio/industrialio-event.c
15278 +index b5e059e15b0ae..ef161fa08146d 100644
15279 +--- a/drivers/iio/industrialio-event.c
15280 ++++ b/drivers/iio/industrialio-event.c
15281 +@@ -550,7 +550,7 @@ int iio_device_register_eventset(struct iio_dev *indio_dev)
15282 +
15283 + ret = iio_device_register_sysfs_group(indio_dev, &ev_int->group);
15284 + if (ret)
15285 +- goto error_free_setup_event_lines;
15286 ++ goto error_free_group_attrs;
15287 +
15288 + ev_int->ioctl_handler.ioctl = iio_event_ioctl;
15289 + iio_device_ioctl_handler_register(&iio_dev_opaque->indio_dev,
15290 +@@ -558,6 +558,8 @@ int iio_device_register_eventset(struct iio_dev *indio_dev)
15291 +
15292 + return 0;
15293 +
15294 ++error_free_group_attrs:
15295 ++ kfree(ev_int->group.attrs);
15296 + error_free_setup_event_lines:
15297 + iio_free_chan_devattr_list(&ev_int->dev_attr_list);
15298 + kfree(ev_int);
15299 +diff --git a/drivers/iio/temperature/ltc2983.c b/drivers/iio/temperature/ltc2983.c
15300 +index a60ccf1836872..1117991ca2ab6 100644
15301 +--- a/drivers/iio/temperature/ltc2983.c
15302 ++++ b/drivers/iio/temperature/ltc2983.c
15303 +@@ -209,6 +209,7 @@ struct ltc2983_data {
15304 + * Holds the converted temperature
15305 + */
15306 + __be32 temp __aligned(IIO_DMA_MINALIGN);
15307 ++ __be32 chan_val;
15308 + };
15309 +
15310 + struct ltc2983_sensor {
15311 +@@ -313,19 +314,18 @@ static int __ltc2983_fault_handler(const struct ltc2983_data *st,
15312 + return 0;
15313 + }
15314 +
15315 +-static int __ltc2983_chan_assign_common(const struct ltc2983_data *st,
15316 ++static int __ltc2983_chan_assign_common(struct ltc2983_data *st,
15317 + const struct ltc2983_sensor *sensor,
15318 + u32 chan_val)
15319 + {
15320 + u32 reg = LTC2983_CHAN_START_ADDR(sensor->chan);
15321 +- __be32 __chan_val;
15322 +
15323 + chan_val |= LTC2983_CHAN_TYPE(sensor->type);
15324 + dev_dbg(&st->spi->dev, "Assign reg:0x%04X, val:0x%08X\n", reg,
15325 + chan_val);
15326 +- __chan_val = cpu_to_be32(chan_val);
15327 +- return regmap_bulk_write(st->regmap, reg, &__chan_val,
15328 +- sizeof(__chan_val));
15329 ++ st->chan_val = cpu_to_be32(chan_val);
15330 ++ return regmap_bulk_write(st->regmap, reg, &st->chan_val,
15331 ++ sizeof(st->chan_val));
15332 + }
15333 +
15334 + static int __ltc2983_chan_custom_sensor_assign(struct ltc2983_data *st,
15335 +diff --git a/drivers/infiniband/Kconfig b/drivers/infiniband/Kconfig
15336 +index aa36ac618e729..17a2274152771 100644
15337 +--- a/drivers/infiniband/Kconfig
15338 ++++ b/drivers/infiniband/Kconfig
15339 +@@ -78,6 +78,7 @@ config INFINIBAND_VIRT_DMA
15340 + def_bool !HIGHMEM
15341 +
15342 + if INFINIBAND_USER_ACCESS || !INFINIBAND_USER_ACCESS
15343 ++if !UML
15344 + source "drivers/infiniband/hw/bnxt_re/Kconfig"
15345 + source "drivers/infiniband/hw/cxgb4/Kconfig"
15346 + source "drivers/infiniband/hw/efa/Kconfig"
15347 +@@ -94,6 +95,7 @@ source "drivers/infiniband/hw/qib/Kconfig"
15348 + source "drivers/infiniband/hw/usnic/Kconfig"
15349 + source "drivers/infiniband/hw/vmw_pvrdma/Kconfig"
15350 + source "drivers/infiniband/sw/rdmavt/Kconfig"
15351 ++endif # !UML
15352 + source "drivers/infiniband/sw/rxe/Kconfig"
15353 + source "drivers/infiniband/sw/siw/Kconfig"
15354 + endif
15355 +diff --git a/drivers/infiniband/core/device.c b/drivers/infiniband/core/device.c
15356 +index 4053a09b8d33e..267d6e7fb18e0 100644
15357 +--- a/drivers/infiniband/core/device.c
15358 ++++ b/drivers/infiniband/core/device.c
15359 +@@ -2851,8 +2851,8 @@ err:
15360 + static void __exit ib_core_cleanup(void)
15361 + {
15362 + roce_gid_mgmt_cleanup();
15363 +- nldev_exit();
15364 + rdma_nl_unregister(RDMA_NL_LS);
15365 ++ nldev_exit();
15366 + unregister_pernet_device(&rdma_dev_net_ops);
15367 + unregister_blocking_lsm_notifier(&ibdev_lsm_nb);
15368 + ib_sa_cleanup();
15369 +diff --git a/drivers/infiniband/core/mad.c b/drivers/infiniband/core/mad.c
15370 +index 1893aa613ad73..674344eb8e2f4 100644
15371 +--- a/drivers/infiniband/core/mad.c
15372 ++++ b/drivers/infiniband/core/mad.c
15373 +@@ -59,9 +59,6 @@ static void create_mad_addr_info(struct ib_mad_send_wr_private *mad_send_wr,
15374 + struct ib_mad_qp_info *qp_info,
15375 + struct trace_event_raw_ib_mad_send_template *entry)
15376 + {
15377 +- u16 pkey;
15378 +- struct ib_device *dev = qp_info->port_priv->device;
15379 +- u32 pnum = qp_info->port_priv->port_num;
15380 + struct ib_ud_wr *wr = &mad_send_wr->send_wr;
15381 + struct rdma_ah_attr attr = {};
15382 +
15383 +@@ -69,8 +66,6 @@ static void create_mad_addr_info(struct ib_mad_send_wr_private *mad_send_wr,
15384 +
15385 + /* These are common */
15386 + entry->sl = attr.sl;
15387 +- ib_query_pkey(dev, pnum, wr->pkey_index, &pkey);
15388 +- entry->pkey = pkey;
15389 + entry->rqpn = wr->remote_qpn;
15390 + entry->rqkey = wr->remote_qkey;
15391 + entry->dlid = rdma_ah_get_dlid(&attr);
15392 +diff --git a/drivers/infiniband/core/nldev.c b/drivers/infiniband/core/nldev.c
15393 +index 12dc97067ed2b..222733a83ddb7 100644
15394 +--- a/drivers/infiniband/core/nldev.c
15395 ++++ b/drivers/infiniband/core/nldev.c
15396 +@@ -513,7 +513,7 @@ static int fill_res_qp_entry(struct sk_buff *msg, bool has_cap_net_admin,
15397 +
15398 + /* In create_qp() port is not set yet */
15399 + if (qp->port && nla_put_u32(msg, RDMA_NLDEV_ATTR_PORT_INDEX, qp->port))
15400 +- return -EINVAL;
15401 ++ return -EMSGSIZE;
15402 +
15403 + ret = nla_put_u32(msg, RDMA_NLDEV_ATTR_RES_LQPN, qp->qp_num);
15404 + if (ret)
15405 +@@ -552,7 +552,7 @@ static int fill_res_cm_id_entry(struct sk_buff *msg, bool has_cap_net_admin,
15406 + struct rdma_cm_id *cm_id = &id_priv->id;
15407 +
15408 + if (port && port != cm_id->port_num)
15409 +- return 0;
15410 ++ return -EAGAIN;
15411 +
15412 + if (cm_id->port_num &&
15413 + nla_put_u32(msg, RDMA_NLDEV_ATTR_PORT_INDEX, cm_id->port_num))
15414 +@@ -894,6 +894,8 @@ static int fill_stat_counter_qps(struct sk_buff *msg,
15415 + int ret = 0;
15416 +
15417 + table_attr = nla_nest_start(msg, RDMA_NLDEV_ATTR_RES_QP);
15418 ++ if (!table_attr)
15419 ++ return -EMSGSIZE;
15420 +
15421 + rt = &counter->device->res[RDMA_RESTRACK_QP];
15422 + xa_lock(&rt->xa);
15423 +diff --git a/drivers/infiniband/core/restrack.c b/drivers/infiniband/core/restrack.c
15424 +index 1f935d9f61785..01a499a8b88db 100644
15425 +--- a/drivers/infiniband/core/restrack.c
15426 ++++ b/drivers/infiniband/core/restrack.c
15427 +@@ -343,8 +343,6 @@ void rdma_restrack_del(struct rdma_restrack_entry *res)
15428 + rt = &dev->res[res->type];
15429 +
15430 + old = xa_erase(&rt->xa, res->id);
15431 +- if (res->type == RDMA_RESTRACK_MR)
15432 +- return;
15433 + WARN_ON(old != res);
15434 +
15435 + out:
15436 +diff --git a/drivers/infiniband/core/sysfs.c b/drivers/infiniband/core/sysfs.c
15437 +index 84c53bd2a52db..ee59d73915689 100644
15438 +--- a/drivers/infiniband/core/sysfs.c
15439 ++++ b/drivers/infiniband/core/sysfs.c
15440 +@@ -1213,6 +1213,9 @@ static struct ib_port *setup_port(struct ib_core_device *coredev, int port_num,
15441 + p->port_num = port_num;
15442 + kobject_init(&p->kobj, &port_type);
15443 +
15444 ++ if (device->port_data && is_full_dev)
15445 ++ device->port_data[port_num].sysfs = p;
15446 ++
15447 + cur_group = p->groups_list;
15448 + ret = alloc_port_table_group("gids", &p->groups[0], p->attrs_list,
15449 + attr->gid_tbl_len, show_port_gid);
15450 +@@ -1258,9 +1261,6 @@ static struct ib_port *setup_port(struct ib_core_device *coredev, int port_num,
15451 + }
15452 +
15453 + list_add_tail(&p->kobj.entry, &coredev->port_list);
15454 +- if (device->port_data && is_full_dev)
15455 +- device->port_data[port_num].sysfs = p;
15456 +-
15457 + return p;
15458 +
15459 + err_groups:
15460 +@@ -1268,6 +1268,8 @@ err_groups:
15461 + err_del:
15462 + kobject_del(&p->kobj);
15463 + err_put:
15464 ++ if (device->port_data && is_full_dev)
15465 ++ device->port_data[port_num].sysfs = NULL;
15466 + kobject_put(&p->kobj);
15467 + return ERR_PTR(ret);
15468 + }
15469 +@@ -1276,14 +1278,17 @@ static void destroy_port(struct ib_core_device *coredev, struct ib_port *port)
15470 + {
15471 + bool is_full_dev = &port->ibdev->coredev == coredev;
15472 +
15473 +- if (port->ibdev->port_data &&
15474 +- port->ibdev->port_data[port->port_num].sysfs == port)
15475 +- port->ibdev->port_data[port->port_num].sysfs = NULL;
15476 + list_del(&port->kobj.entry);
15477 + if (is_full_dev)
15478 + sysfs_remove_groups(&port->kobj, port->ibdev->ops.port_groups);
15479 ++
15480 + sysfs_remove_groups(&port->kobj, port->groups_list);
15481 + kobject_del(&port->kobj);
15482 ++
15483 ++ if (port->ibdev->port_data &&
15484 ++ port->ibdev->port_data[port->port_num].sysfs == port)
15485 ++ port->ibdev->port_data[port->port_num].sysfs = NULL;
15486 ++
15487 + kobject_put(&port->kobj);
15488 + }
15489 +
15490 +diff --git a/drivers/infiniband/hw/hfi1/affinity.c b/drivers/infiniband/hw/hfi1/affinity.c
15491 +index 877f8e84a672a..77ee77d4000fb 100644
15492 +--- a/drivers/infiniband/hw/hfi1/affinity.c
15493 ++++ b/drivers/infiniband/hw/hfi1/affinity.c
15494 +@@ -177,6 +177,8 @@ out:
15495 + for (node = 0; node < node_affinity.num_possible_nodes; node++)
15496 + hfi1_per_node_cntr[node] = 1;
15497 +
15498 ++ pci_dev_put(dev);
15499 ++
15500 + return 0;
15501 + }
15502 +
15503 +diff --git a/drivers/infiniband/hw/hfi1/firmware.c b/drivers/infiniband/hw/hfi1/firmware.c
15504 +index aa15a5cc7cf3a..9705bd7ea0647 100644
15505 +--- a/drivers/infiniband/hw/hfi1/firmware.c
15506 ++++ b/drivers/infiniband/hw/hfi1/firmware.c
15507 +@@ -1743,6 +1743,7 @@ int parse_platform_config(struct hfi1_devdata *dd)
15508 +
15509 + if (!dd->platform_config.data) {
15510 + dd_dev_err(dd, "%s: Missing config file\n", __func__);
15511 ++ ret = -EINVAL;
15512 + goto bail;
15513 + }
15514 + ptr = (u32 *)dd->platform_config.data;
15515 +@@ -1751,6 +1752,7 @@ int parse_platform_config(struct hfi1_devdata *dd)
15516 + ptr++;
15517 + if (magic_num != PLATFORM_CONFIG_MAGIC_NUM) {
15518 + dd_dev_err(dd, "%s: Bad config file\n", __func__);
15519 ++ ret = -EINVAL;
15520 + goto bail;
15521 + }
15522 +
15523 +@@ -1774,6 +1776,7 @@ int parse_platform_config(struct hfi1_devdata *dd)
15524 + if (file_length > dd->platform_config.size) {
15525 + dd_dev_info(dd, "%s:File claims to be larger than read size\n",
15526 + __func__);
15527 ++ ret = -EINVAL;
15528 + goto bail;
15529 + } else if (file_length < dd->platform_config.size) {
15530 + dd_dev_info(dd,
15531 +@@ -1794,6 +1797,7 @@ int parse_platform_config(struct hfi1_devdata *dd)
15532 + dd_dev_err(dd, "%s: Failed validation at offset %ld\n",
15533 + __func__, (ptr - (u32 *)
15534 + dd->platform_config.data));
15535 ++ ret = -EINVAL;
15536 + goto bail;
15537 + }
15538 +
15539 +@@ -1837,6 +1841,7 @@ int parse_platform_config(struct hfi1_devdata *dd)
15540 + __func__, table_type,
15541 + (ptr - (u32 *)
15542 + dd->platform_config.data));
15543 ++ ret = -EINVAL;
15544 + goto bail; /* We don't trust this file now */
15545 + }
15546 + pcfgcache->config_tables[table_type].table = ptr;
15547 +@@ -1856,6 +1861,7 @@ int parse_platform_config(struct hfi1_devdata *dd)
15548 + __func__, table_type,
15549 + (ptr -
15550 + (u32 *)dd->platform_config.data));
15551 ++ ret = -EINVAL;
15552 + goto bail; /* We don't trust this file now */
15553 + }
15554 + pcfgcache->config_tables[table_type].table_metadata =
15555 +diff --git a/drivers/infiniband/hw/hns/Makefile b/drivers/infiniband/hw/hns/Makefile
15556 +index 9f04f25d96317..a7d259238305b 100644
15557 +--- a/drivers/infiniband/hw/hns/Makefile
15558 ++++ b/drivers/infiniband/hw/hns/Makefile
15559 +@@ -10,6 +10,6 @@ hns-roce-objs := hns_roce_main.o hns_roce_cmd.o hns_roce_pd.o \
15560 + hns_roce_cq.o hns_roce_alloc.o hns_roce_db.o hns_roce_srq.o hns_roce_restrack.o
15561 +
15562 + ifdef CONFIG_INFINIBAND_HNS_HIP08
15563 +-hns-roce-hw-v2-objs := hns_roce_hw_v2.o hns_roce_hw_v2_dfx.o $(hns-roce-objs)
15564 ++hns-roce-hw-v2-objs := hns_roce_hw_v2.o $(hns-roce-objs)
15565 + obj-$(CONFIG_INFINIBAND_HNS) += hns-roce-hw-v2.o
15566 + endif
15567 +diff --git a/drivers/infiniband/hw/hns/hns_roce_device.h b/drivers/infiniband/hw/hns/hns_roce_device.h
15568 +index d24996526c4d9..48db4a42b7d3f 100644
15569 +--- a/drivers/infiniband/hw/hns/hns_roce_device.h
15570 ++++ b/drivers/infiniband/hw/hns/hns_roce_device.h
15571 +@@ -202,6 +202,7 @@ struct hns_roce_ucontext {
15572 + struct list_head page_list;
15573 + struct mutex page_mutex;
15574 + struct hns_user_mmap_entry *db_mmap_entry;
15575 ++ u32 config;
15576 + };
15577 +
15578 + struct hns_roce_pd {
15579 +@@ -335,6 +336,7 @@ struct hns_roce_wq {
15580 + u32 head;
15581 + u32 tail;
15582 + void __iomem *db_reg;
15583 ++ u32 ext_sge_cnt;
15584 + };
15585 +
15586 + struct hns_roce_sge {
15587 +@@ -637,6 +639,7 @@ struct hns_roce_qp {
15588 + struct list_head rq_node; /* all recv qps are on a list */
15589 + struct list_head sq_node; /* all send qps are on a list */
15590 + struct hns_user_mmap_entry *dwqe_mmap_entry;
15591 ++ u32 config;
15592 + };
15593 +
15594 + struct hns_roce_ib_iboe {
15595 +@@ -848,11 +851,6 @@ struct hns_roce_caps {
15596 + enum cong_type cong_type;
15597 + };
15598 +
15599 +-struct hns_roce_dfx_hw {
15600 +- int (*query_cqc_info)(struct hns_roce_dev *hr_dev, u32 cqn,
15601 +- int *buffer);
15602 +-};
15603 +-
15604 + enum hns_roce_device_state {
15605 + HNS_ROCE_DEVICE_STATE_INITED,
15606 + HNS_ROCE_DEVICE_STATE_RST_DOWN,
15607 +@@ -898,6 +896,7 @@ struct hns_roce_hw {
15608 + int (*init_eq)(struct hns_roce_dev *hr_dev);
15609 + void (*cleanup_eq)(struct hns_roce_dev *hr_dev);
15610 + int (*write_srqc)(struct hns_roce_srq *srq, void *mb_buf);
15611 ++ int (*query_cqc)(struct hns_roce_dev *hr_dev, u32 cqn, void *buffer);
15612 + const struct ib_device_ops *hns_roce_dev_ops;
15613 + const struct ib_device_ops *hns_roce_dev_srq_ops;
15614 + };
15615 +@@ -959,7 +958,6 @@ struct hns_roce_dev {
15616 + void *priv;
15617 + struct workqueue_struct *irq_workq;
15618 + struct work_struct ecc_work;
15619 +- const struct hns_roce_dfx_hw *dfx;
15620 + u32 func_num;
15621 + u32 is_vf;
15622 + u32 cong_algo_tmpl_id;
15623 +@@ -1227,8 +1225,7 @@ u8 hns_get_gid_index(struct hns_roce_dev *hr_dev, u32 port, int gid_index);
15624 + void hns_roce_handle_device_err(struct hns_roce_dev *hr_dev);
15625 + int hns_roce_init(struct hns_roce_dev *hr_dev);
15626 + void hns_roce_exit(struct hns_roce_dev *hr_dev);
15627 +-int hns_roce_fill_res_cq_entry(struct sk_buff *msg,
15628 +- struct ib_cq *ib_cq);
15629 ++int hns_roce_fill_res_cq_entry(struct sk_buff *msg, struct ib_cq *ib_cq);
15630 + struct hns_user_mmap_entry *
15631 + hns_roce_user_mmap_entry_insert(struct ib_ucontext *ucontext, u64 address,
15632 + size_t length,
15633 +diff --git a/drivers/infiniband/hw/hns/hns_roce_hw_v2.c b/drivers/infiniband/hw/hns/hns_roce_hw_v2.c
15634 +index 105888c6ccb77..b55a96863d1ae 100644
15635 +--- a/drivers/infiniband/hw/hns/hns_roce_hw_v2.c
15636 ++++ b/drivers/infiniband/hw/hns/hns_roce_hw_v2.c
15637 +@@ -192,8 +192,6 @@ static int fill_ext_sge_inl_data(struct hns_roce_qp *qp,
15638 + unsigned int *sge_idx, u32 msg_len)
15639 + {
15640 + struct ib_device *ibdev = &(to_hr_dev(qp->ibqp.device))->ib_dev;
15641 +- unsigned int dseg_len = sizeof(struct hns_roce_v2_wqe_data_seg);
15642 +- unsigned int ext_sge_sz = qp->sq.max_gs * dseg_len;
15643 + unsigned int left_len_in_pg;
15644 + unsigned int idx = *sge_idx;
15645 + unsigned int i = 0;
15646 +@@ -201,7 +199,7 @@ static int fill_ext_sge_inl_data(struct hns_roce_qp *qp,
15647 + void *addr;
15648 + void *dseg;
15649 +
15650 +- if (msg_len > ext_sge_sz) {
15651 ++ if (msg_len > qp->sq.ext_sge_cnt * HNS_ROCE_SGE_SIZE) {
15652 + ibdev_err(ibdev,
15653 + "no enough extended sge space for inline data.\n");
15654 + return -EINVAL;
15655 +@@ -221,7 +219,7 @@ static int fill_ext_sge_inl_data(struct hns_roce_qp *qp,
15656 + if (len <= left_len_in_pg) {
15657 + memcpy(dseg, addr, len);
15658 +
15659 +- idx += len / dseg_len;
15660 ++ idx += len / HNS_ROCE_SGE_SIZE;
15661 +
15662 + i++;
15663 + if (i >= wr->num_sge)
15664 +@@ -236,7 +234,7 @@ static int fill_ext_sge_inl_data(struct hns_roce_qp *qp,
15665 +
15666 + len -= left_len_in_pg;
15667 + addr += left_len_in_pg;
15668 +- idx += left_len_in_pg / dseg_len;
15669 ++ idx += left_len_in_pg / HNS_ROCE_SGE_SIZE;
15670 + dseg = hns_roce_get_extend_sge(qp,
15671 + idx & (qp->sge.sge_cnt - 1));
15672 + left_len_in_pg = 1 << HNS_HW_PAGE_SHIFT;
15673 +@@ -1275,6 +1273,30 @@ static void update_cmdq_status(struct hns_roce_dev *hr_dev)
15674 + hr_dev->cmd.state = HNS_ROCE_CMDQ_STATE_FATAL_ERR;
15675 + }
15676 +
15677 ++static int hns_roce_cmd_err_convert_errno(u16 desc_ret)
15678 ++{
15679 ++ struct hns_roce_cmd_errcode errcode_table[] = {
15680 ++ {CMD_EXEC_SUCCESS, 0},
15681 ++ {CMD_NO_AUTH, -EPERM},
15682 ++ {CMD_NOT_EXIST, -EOPNOTSUPP},
15683 ++ {CMD_CRQ_FULL, -EXFULL},
15684 ++ {CMD_NEXT_ERR, -ENOSR},
15685 ++ {CMD_NOT_EXEC, -ENOTBLK},
15686 ++ {CMD_PARA_ERR, -EINVAL},
15687 ++ {CMD_RESULT_ERR, -ERANGE},
15688 ++ {CMD_TIMEOUT, -ETIME},
15689 ++ {CMD_HILINK_ERR, -ENOLINK},
15690 ++ {CMD_INFO_ILLEGAL, -ENXIO},
15691 ++ {CMD_INVALID, -EBADR},
15692 ++ };
15693 ++ u16 i;
15694 ++
15695 ++ for (i = 0; i < ARRAY_SIZE(errcode_table); i++)
15696 ++ if (desc_ret == errcode_table[i].return_status)
15697 ++ return errcode_table[i].errno;
15698 ++ return -EIO;
15699 ++}
15700 ++
15701 + static int __hns_roce_cmq_send(struct hns_roce_dev *hr_dev,
15702 + struct hns_roce_cmq_desc *desc, int num)
15703 + {
15704 +@@ -1320,7 +1342,7 @@ static int __hns_roce_cmq_send(struct hns_roce_dev *hr_dev,
15705 + dev_err_ratelimited(hr_dev->dev,
15706 + "Cmdq IO error, opcode = 0x%x, return = 0x%x.\n",
15707 + desc->opcode, desc_ret);
15708 +- ret = -EIO;
15709 ++ ret = hns_roce_cmd_err_convert_errno(desc_ret);
15710 + }
15711 + } else {
15712 + /* FW/HW reset or incorrect number of desc */
15713 +@@ -2027,13 +2049,14 @@ static void set_default_caps(struct hns_roce_dev *hr_dev)
15714 +
15715 + caps->flags |= HNS_ROCE_CAP_FLAG_ATOMIC | HNS_ROCE_CAP_FLAG_MW |
15716 + HNS_ROCE_CAP_FLAG_SRQ | HNS_ROCE_CAP_FLAG_FRMR |
15717 +- HNS_ROCE_CAP_FLAG_QP_FLOW_CTRL | HNS_ROCE_CAP_FLAG_XRC;
15718 ++ HNS_ROCE_CAP_FLAG_QP_FLOW_CTRL;
15719 +
15720 + caps->gid_table_len[0] = HNS_ROCE_V2_GID_INDEX_NUM;
15721 +
15722 + if (hr_dev->pci_dev->revision >= PCI_REVISION_ID_HIP09) {
15723 + caps->flags |= HNS_ROCE_CAP_FLAG_STASH |
15724 +- HNS_ROCE_CAP_FLAG_DIRECT_WQE;
15725 ++ HNS_ROCE_CAP_FLAG_DIRECT_WQE |
15726 ++ HNS_ROCE_CAP_FLAG_XRC;
15727 + caps->max_sq_inline = HNS_ROCE_V3_MAX_SQ_INLINE;
15728 + } else {
15729 + caps->max_sq_inline = HNS_ROCE_V2_MAX_SQ_INLINE;
15730 +@@ -2346,6 +2369,9 @@ static int hns_roce_query_pf_caps(struct hns_roce_dev *hr_dev)
15731 + caps->wqe_sge_hop_num = hr_reg_read(resp_d, PF_CAPS_D_EX_SGE_HOP_NUM);
15732 + caps->wqe_rq_hop_num = hr_reg_read(resp_d, PF_CAPS_D_RQWQE_HOP_NUM);
15733 +
15734 ++ if (!(caps->page_size_cap & PAGE_SIZE))
15735 ++ caps->page_size_cap = HNS_ROCE_V2_PAGE_SIZE_SUPPORTED;
15736 ++
15737 + return 0;
15738 + }
15739 +
15740 +@@ -2635,31 +2661,124 @@ static void free_dip_list(struct hns_roce_dev *hr_dev)
15741 + spin_unlock_irqrestore(&hr_dev->dip_list_lock, flags);
15742 + }
15743 +
15744 +-static void free_mr_exit(struct hns_roce_dev *hr_dev)
15745 ++static struct ib_pd *free_mr_init_pd(struct hns_roce_dev *hr_dev)
15746 ++{
15747 ++ struct hns_roce_v2_priv *priv = hr_dev->priv;
15748 ++ struct hns_roce_v2_free_mr *free_mr = &priv->free_mr;
15749 ++ struct ib_device *ibdev = &hr_dev->ib_dev;
15750 ++ struct hns_roce_pd *hr_pd;
15751 ++ struct ib_pd *pd;
15752 ++
15753 ++ hr_pd = kzalloc(sizeof(*hr_pd), GFP_KERNEL);
15754 ++ if (ZERO_OR_NULL_PTR(hr_pd))
15755 ++ return NULL;
15756 ++ pd = &hr_pd->ibpd;
15757 ++ pd->device = ibdev;
15758 ++
15759 ++ if (hns_roce_alloc_pd(pd, NULL)) {
15760 ++ ibdev_err(ibdev, "failed to create pd for free mr.\n");
15761 ++ kfree(hr_pd);
15762 ++ return NULL;
15763 ++ }
15764 ++ free_mr->rsv_pd = to_hr_pd(pd);
15765 ++ free_mr->rsv_pd->ibpd.device = &hr_dev->ib_dev;
15766 ++ free_mr->rsv_pd->ibpd.uobject = NULL;
15767 ++ free_mr->rsv_pd->ibpd.__internal_mr = NULL;
15768 ++ atomic_set(&free_mr->rsv_pd->ibpd.usecnt, 0);
15769 ++
15770 ++ return pd;
15771 ++}
15772 ++
15773 ++static struct ib_cq *free_mr_init_cq(struct hns_roce_dev *hr_dev)
15774 ++{
15775 ++ struct hns_roce_v2_priv *priv = hr_dev->priv;
15776 ++ struct hns_roce_v2_free_mr *free_mr = &priv->free_mr;
15777 ++ struct ib_device *ibdev = &hr_dev->ib_dev;
15778 ++ struct ib_cq_init_attr cq_init_attr = {};
15779 ++ struct hns_roce_cq *hr_cq;
15780 ++ struct ib_cq *cq;
15781 ++
15782 ++ cq_init_attr.cqe = HNS_ROCE_FREE_MR_USED_CQE_NUM;
15783 ++
15784 ++ hr_cq = kzalloc(sizeof(*hr_cq), GFP_KERNEL);
15785 ++ if (ZERO_OR_NULL_PTR(hr_cq))
15786 ++ return NULL;
15787 ++
15788 ++ cq = &hr_cq->ib_cq;
15789 ++ cq->device = ibdev;
15790 ++
15791 ++ if (hns_roce_create_cq(cq, &cq_init_attr, NULL)) {
15792 ++ ibdev_err(ibdev, "failed to create cq for free mr.\n");
15793 ++ kfree(hr_cq);
15794 ++ return NULL;
15795 ++ }
15796 ++ free_mr->rsv_cq = to_hr_cq(cq);
15797 ++ free_mr->rsv_cq->ib_cq.device = &hr_dev->ib_dev;
15798 ++ free_mr->rsv_cq->ib_cq.uobject = NULL;
15799 ++ free_mr->rsv_cq->ib_cq.comp_handler = NULL;
15800 ++ free_mr->rsv_cq->ib_cq.event_handler = NULL;
15801 ++ free_mr->rsv_cq->ib_cq.cq_context = NULL;
15802 ++ atomic_set(&free_mr->rsv_cq->ib_cq.usecnt, 0);
15803 ++
15804 ++ return cq;
15805 ++}
15806 ++
15807 ++static int free_mr_init_qp(struct hns_roce_dev *hr_dev, struct ib_cq *cq,
15808 ++ struct ib_qp_init_attr *init_attr, int i)
15809 + {
15810 + struct hns_roce_v2_priv *priv = hr_dev->priv;
15811 + struct hns_roce_v2_free_mr *free_mr = &priv->free_mr;
15812 ++ struct ib_device *ibdev = &hr_dev->ib_dev;
15813 ++ struct hns_roce_qp *hr_qp;
15814 ++ struct ib_qp *qp;
15815 + int ret;
15816 ++
15817 ++ hr_qp = kzalloc(sizeof(*hr_qp), GFP_KERNEL);
15818 ++ if (ZERO_OR_NULL_PTR(hr_qp))
15819 ++ return -ENOMEM;
15820 ++
15821 ++ qp = &hr_qp->ibqp;
15822 ++ qp->device = ibdev;
15823 ++
15824 ++ ret = hns_roce_create_qp(qp, init_attr, NULL);
15825 ++ if (ret) {
15826 ++ ibdev_err(ibdev, "failed to create qp for free mr.\n");
15827 ++ kfree(hr_qp);
15828 ++ return ret;
15829 ++ }
15830 ++
15831 ++ free_mr->rsv_qp[i] = hr_qp;
15832 ++ free_mr->rsv_qp[i]->ibqp.recv_cq = cq;
15833 ++ free_mr->rsv_qp[i]->ibqp.send_cq = cq;
15834 ++
15835 ++ return 0;
15836 ++}
15837 ++
15838 ++static void free_mr_exit(struct hns_roce_dev *hr_dev)
15839 ++{
15840 ++ struct hns_roce_v2_priv *priv = hr_dev->priv;
15841 ++ struct hns_roce_v2_free_mr *free_mr = &priv->free_mr;
15842 ++ struct ib_qp *qp;
15843 + int i;
15844 +
15845 + for (i = 0; i < ARRAY_SIZE(free_mr->rsv_qp); i++) {
15846 + if (free_mr->rsv_qp[i]) {
15847 +- ret = ib_destroy_qp(free_mr->rsv_qp[i]);
15848 +- if (ret)
15849 +- ibdev_err(&hr_dev->ib_dev,
15850 +- "failed to destroy qp in free mr.\n");
15851 +-
15852 ++ qp = &free_mr->rsv_qp[i]->ibqp;
15853 ++ hns_roce_v2_destroy_qp(qp, NULL);
15854 ++ kfree(free_mr->rsv_qp[i]);
15855 + free_mr->rsv_qp[i] = NULL;
15856 + }
15857 + }
15858 +
15859 + if (free_mr->rsv_cq) {
15860 +- ib_destroy_cq(free_mr->rsv_cq);
15861 ++ hns_roce_destroy_cq(&free_mr->rsv_cq->ib_cq, NULL);
15862 ++ kfree(free_mr->rsv_cq);
15863 + free_mr->rsv_cq = NULL;
15864 + }
15865 +
15866 + if (free_mr->rsv_pd) {
15867 +- ib_dealloc_pd(free_mr->rsv_pd);
15868 ++ hns_roce_dealloc_pd(&free_mr->rsv_pd->ibpd, NULL);
15869 ++ kfree(free_mr->rsv_pd);
15870 + free_mr->rsv_pd = NULL;
15871 + }
15872 + }
15873 +@@ -2668,55 +2787,46 @@ static int free_mr_alloc_res(struct hns_roce_dev *hr_dev)
15874 + {
15875 + struct hns_roce_v2_priv *priv = hr_dev->priv;
15876 + struct hns_roce_v2_free_mr *free_mr = &priv->free_mr;
15877 +- struct ib_device *ibdev = &hr_dev->ib_dev;
15878 +- struct ib_cq_init_attr cq_init_attr = {};
15879 + struct ib_qp_init_attr qp_init_attr = {};
15880 + struct ib_pd *pd;
15881 + struct ib_cq *cq;
15882 +- struct ib_qp *qp;
15883 + int ret;
15884 + int i;
15885 +
15886 +- pd = ib_alloc_pd(ibdev, 0);
15887 +- if (IS_ERR(pd)) {
15888 +- ibdev_err(ibdev, "failed to create pd for free mr.\n");
15889 +- return PTR_ERR(pd);
15890 +- }
15891 +- free_mr->rsv_pd = pd;
15892 ++ pd = free_mr_init_pd(hr_dev);
15893 ++ if (!pd)
15894 ++ return -ENOMEM;
15895 +
15896 +- cq_init_attr.cqe = HNS_ROCE_FREE_MR_USED_CQE_NUM;
15897 +- cq = ib_create_cq(ibdev, NULL, NULL, NULL, &cq_init_attr);
15898 +- if (IS_ERR(cq)) {
15899 +- ibdev_err(ibdev, "failed to create cq for free mr.\n");
15900 +- ret = PTR_ERR(cq);
15901 +- goto create_failed;
15902 ++ cq = free_mr_init_cq(hr_dev);
15903 ++ if (!cq) {
15904 ++ ret = -ENOMEM;
15905 ++ goto create_failed_cq;
15906 + }
15907 +- free_mr->rsv_cq = cq;
15908 +
15909 + qp_init_attr.qp_type = IB_QPT_RC;
15910 + qp_init_attr.sq_sig_type = IB_SIGNAL_ALL_WR;
15911 +- qp_init_attr.send_cq = free_mr->rsv_cq;
15912 +- qp_init_attr.recv_cq = free_mr->rsv_cq;
15913 ++ qp_init_attr.send_cq = cq;
15914 ++ qp_init_attr.recv_cq = cq;
15915 + for (i = 0; i < ARRAY_SIZE(free_mr->rsv_qp); i++) {
15916 + qp_init_attr.cap.max_send_wr = HNS_ROCE_FREE_MR_USED_SQWQE_NUM;
15917 + qp_init_attr.cap.max_send_sge = HNS_ROCE_FREE_MR_USED_SQSGE_NUM;
15918 + qp_init_attr.cap.max_recv_wr = HNS_ROCE_FREE_MR_USED_RQWQE_NUM;
15919 + qp_init_attr.cap.max_recv_sge = HNS_ROCE_FREE_MR_USED_RQSGE_NUM;
15920 +
15921 +- qp = ib_create_qp(free_mr->rsv_pd, &qp_init_attr);
15922 +- if (IS_ERR(qp)) {
15923 +- ibdev_err(ibdev, "failed to create qp for free mr.\n");
15924 +- ret = PTR_ERR(qp);
15925 +- goto create_failed;
15926 +- }
15927 +-
15928 +- free_mr->rsv_qp[i] = qp;
15929 ++ ret = free_mr_init_qp(hr_dev, cq, &qp_init_attr, i);
15930 ++ if (ret)
15931 ++ goto create_failed_qp;
15932 + }
15933 +
15934 + return 0;
15935 +
15936 +-create_failed:
15937 +- free_mr_exit(hr_dev);
15938 ++create_failed_qp:
15939 ++ hns_roce_destroy_cq(cq, NULL);
15940 ++ kfree(cq);
15941 ++
15942 ++create_failed_cq:
15943 ++ hns_roce_dealloc_pd(pd, NULL);
15944 ++ kfree(pd);
15945 +
15946 + return ret;
15947 + }
15948 +@@ -2732,14 +2842,17 @@ static int free_mr_modify_rsv_qp(struct hns_roce_dev *hr_dev,
15949 + int mask;
15950 + int ret;
15951 +
15952 +- hr_qp = to_hr_qp(free_mr->rsv_qp[sl_num]);
15953 ++ hr_qp = to_hr_qp(&free_mr->rsv_qp[sl_num]->ibqp);
15954 + hr_qp->free_mr_en = 1;
15955 ++ hr_qp->ibqp.device = ibdev;
15956 ++ hr_qp->ibqp.qp_type = IB_QPT_RC;
15957 +
15958 + mask = IB_QP_STATE | IB_QP_PKEY_INDEX | IB_QP_PORT | IB_QP_ACCESS_FLAGS;
15959 + attr->qp_state = IB_QPS_INIT;
15960 + attr->port_num = 1;
15961 + attr->qp_access_flags = IB_ACCESS_REMOTE_WRITE;
15962 +- ret = ib_modify_qp(&hr_qp->ibqp, attr, mask);
15963 ++ ret = hr_dev->hw->modify_qp(&hr_qp->ibqp, attr, mask, IB_QPS_INIT,
15964 ++ IB_QPS_INIT);
15965 + if (ret) {
15966 + ibdev_err(ibdev, "failed to modify qp to init, ret = %d.\n",
15967 + ret);
15968 +@@ -2760,7 +2873,8 @@ static int free_mr_modify_rsv_qp(struct hns_roce_dev *hr_dev,
15969 +
15970 + rdma_ah_set_sl(&attr->ah_attr, (u8)sl_num);
15971 +
15972 +- ret = ib_modify_qp(&hr_qp->ibqp, attr, mask);
15973 ++ ret = hr_dev->hw->modify_qp(&hr_qp->ibqp, attr, mask, IB_QPS_INIT,
15974 ++ IB_QPS_RTR);
15975 + hr_dev->loop_idc = loopback;
15976 + if (ret) {
15977 + ibdev_err(ibdev, "failed to modify qp to rtr, ret = %d.\n",
15978 +@@ -2774,7 +2888,8 @@ static int free_mr_modify_rsv_qp(struct hns_roce_dev *hr_dev,
15979 + attr->sq_psn = HNS_ROCE_FREE_MR_USED_PSN;
15980 + attr->retry_cnt = HNS_ROCE_FREE_MR_USED_QP_RETRY_CNT;
15981 + attr->timeout = HNS_ROCE_FREE_MR_USED_QP_TIMEOUT;
15982 +- ret = ib_modify_qp(&hr_qp->ibqp, attr, mask);
15983 ++ ret = hr_dev->hw->modify_qp(&hr_qp->ibqp, attr, mask, IB_QPS_RTR,
15984 ++ IB_QPS_RTS);
15985 + if (ret)
15986 + ibdev_err(ibdev, "failed to modify qp to rts, ret = %d.\n",
15987 + ret);
15988 +@@ -3190,7 +3305,8 @@ static int set_mtpt_pbl(struct hns_roce_dev *hr_dev,
15989 + int i, count;
15990 +
15991 + count = hns_roce_mtr_find(hr_dev, &mr->pbl_mtr, 0, pages,
15992 +- ARRAY_SIZE(pages), &pbl_ba);
15993 ++ min_t(int, ARRAY_SIZE(pages), mr->npages),
15994 ++ &pbl_ba);
15995 + if (count < 1) {
15996 + ibdev_err(ibdev, "failed to find PBL mtr, count = %d.\n",
15997 + count);
15998 +@@ -3418,7 +3534,7 @@ static void free_mr_send_cmd_to_hw(struct hns_roce_dev *hr_dev)
15999 + mutex_lock(&free_mr->mutex);
16000 +
16001 + for (i = 0; i < ARRAY_SIZE(free_mr->rsv_qp); i++) {
16002 +- hr_qp = to_hr_qp(free_mr->rsv_qp[i]);
16003 ++ hr_qp = free_mr->rsv_qp[i];
16004 +
16005 + ret = free_mr_post_send_lp_wqe(hr_qp);
16006 + if (ret) {
16007 +@@ -3433,7 +3549,7 @@ static void free_mr_send_cmd_to_hw(struct hns_roce_dev *hr_dev)
16008 +
16009 + end = msecs_to_jiffies(HNS_ROCE_V2_FREE_MR_TIMEOUT) + jiffies;
16010 + while (cqe_cnt) {
16011 +- npolled = hns_roce_v2_poll_cq(free_mr->rsv_cq, cqe_cnt, wc);
16012 ++ npolled = hns_roce_v2_poll_cq(&free_mr->rsv_cq->ib_cq, cqe_cnt, wc);
16013 + if (npolled < 0) {
16014 + ibdev_err(ibdev,
16015 + "failed to poll cqe for free mr, remain %d cqe.\n",
16016 +@@ -5383,6 +5499,8 @@ static int hns_roce_v2_query_qp(struct ib_qp *ibqp, struct ib_qp_attr *qp_attr,
16017 +
16018 + rdma_ah_set_sl(&qp_attr->ah_attr,
16019 + hr_reg_read(&context, QPC_SL));
16020 ++ rdma_ah_set_port_num(&qp_attr->ah_attr, hr_qp->port + 1);
16021 ++ rdma_ah_set_ah_flags(&qp_attr->ah_attr, IB_AH_GRH);
16022 + grh->flow_label = hr_reg_read(&context, QPC_FL);
16023 + grh->sgid_index = hr_reg_read(&context, QPC_GMV_IDX);
16024 + grh->hop_limit = hr_reg_read(&context, QPC_HOPLIMIT);
16025 +@@ -5476,7 +5594,7 @@ static int hns_roce_v2_destroy_qp_common(struct hns_roce_dev *hr_dev,
16026 + return ret;
16027 + }
16028 +
16029 +-static int hns_roce_v2_destroy_qp(struct ib_qp *ibqp, struct ib_udata *udata)
16030 ++int hns_roce_v2_destroy_qp(struct ib_qp *ibqp, struct ib_udata *udata)
16031 + {
16032 + struct hns_roce_dev *hr_dev = to_hr_dev(ibqp->device);
16033 + struct hns_roce_qp *hr_qp = to_hr_qp(ibqp);
16034 +@@ -5766,6 +5884,35 @@ static int hns_roce_v2_modify_cq(struct ib_cq *cq, u16 cq_count, u16 cq_period)
16035 + return ret;
16036 + }
16037 +
16038 ++static int hns_roce_v2_query_cqc(struct hns_roce_dev *hr_dev, u32 cqn,
16039 ++ void *buffer)
16040 ++{
16041 ++ struct hns_roce_v2_cq_context *context;
16042 ++ struct hns_roce_cmd_mailbox *mailbox;
16043 ++ int ret;
16044 ++
16045 ++ mailbox = hns_roce_alloc_cmd_mailbox(hr_dev);
16046 ++ if (IS_ERR(mailbox))
16047 ++ return PTR_ERR(mailbox);
16048 ++
16049 ++ context = mailbox->buf;
16050 ++ ret = hns_roce_cmd_mbox(hr_dev, 0, mailbox->dma,
16051 ++ HNS_ROCE_CMD_QUERY_CQC, cqn);
16052 ++ if (ret) {
16053 ++ ibdev_err(&hr_dev->ib_dev,
16054 ++ "failed to process cmd when querying CQ, ret = %d.\n",
16055 ++ ret);
16056 ++ goto err_mailbox;
16057 ++ }
16058 ++
16059 ++ memcpy(buffer, context, sizeof(*context));
16060 ++
16061 ++err_mailbox:
16062 ++ hns_roce_free_cmd_mailbox(hr_dev, mailbox);
16063 ++
16064 ++ return ret;
16065 ++}
16066 ++
16067 + static void hns_roce_irq_work_handle(struct work_struct *work)
16068 + {
16069 + struct hns_roce_work *irq_work =
16070 +@@ -6567,10 +6714,6 @@ static void hns_roce_v2_cleanup_eq_table(struct hns_roce_dev *hr_dev)
16071 + kfree(eq_table->eq);
16072 + }
16073 +
16074 +-static const struct hns_roce_dfx_hw hns_roce_dfx_hw_v2 = {
16075 +- .query_cqc_info = hns_roce_v2_query_cqc_info,
16076 +-};
16077 +-
16078 + static const struct ib_device_ops hns_roce_v2_dev_ops = {
16079 + .destroy_qp = hns_roce_v2_destroy_qp,
16080 + .modify_cq = hns_roce_v2_modify_cq,
16081 +@@ -6611,6 +6754,7 @@ static const struct hns_roce_hw hns_roce_hw_v2 = {
16082 + .init_eq = hns_roce_v2_init_eq_table,
16083 + .cleanup_eq = hns_roce_v2_cleanup_eq_table,
16084 + .write_srqc = hns_roce_v2_write_srqc,
16085 ++ .query_cqc = hns_roce_v2_query_cqc,
16086 + .hns_roce_dev_ops = &hns_roce_v2_dev_ops,
16087 + .hns_roce_dev_srq_ops = &hns_roce_v2_dev_srq_ops,
16088 + };
16089 +@@ -6642,7 +6786,6 @@ static void hns_roce_hw_v2_get_cfg(struct hns_roce_dev *hr_dev,
16090 + hr_dev->is_vf = id->driver_data;
16091 + hr_dev->dev = &handle->pdev->dev;
16092 + hr_dev->hw = &hns_roce_hw_v2;
16093 +- hr_dev->dfx = &hns_roce_dfx_hw_v2;
16094 + hr_dev->sdb_offset = ROCEE_DB_SQ_L_0_REG;
16095 + hr_dev->odb_offset = hr_dev->sdb_offset;
16096 +
16097 +diff --git a/drivers/infiniband/hw/hns/hns_roce_hw_v2.h b/drivers/infiniband/hw/hns/hns_roce_hw_v2.h
16098 +index 4544a8775ce5a..4bf89c1280dc4 100644
16099 +--- a/drivers/infiniband/hw/hns/hns_roce_hw_v2.h
16100 ++++ b/drivers/infiniband/hw/hns/hns_roce_hw_v2.h
16101 +@@ -275,6 +275,11 @@ enum hns_roce_cmd_return_status {
16102 + CMD_OTHER_ERR = 0xff
16103 + };
16104 +
16105 ++struct hns_roce_cmd_errcode {
16106 ++ enum hns_roce_cmd_return_status return_status;
16107 ++ int errno;
16108 ++};
16109 ++
16110 + enum hns_roce_sgid_type {
16111 + GID_TYPE_FLAG_ROCE_V1 = 0,
16112 + GID_TYPE_FLAG_ROCE_V2_IPV4,
16113 +@@ -1328,9 +1333,9 @@ struct hns_roce_link_table {
16114 + #define HNS_ROCE_EXT_LLM_MIN_PAGES(que_num) ((que_num) * 4 + 2)
16115 +
16116 + struct hns_roce_v2_free_mr {
16117 +- struct ib_qp *rsv_qp[HNS_ROCE_FREE_MR_USED_QP_NUM];
16118 +- struct ib_cq *rsv_cq;
16119 +- struct ib_pd *rsv_pd;
16120 ++ struct hns_roce_qp *rsv_qp[HNS_ROCE_FREE_MR_USED_QP_NUM];
16121 ++ struct hns_roce_cq *rsv_cq;
16122 ++ struct hns_roce_pd *rsv_pd;
16123 + struct mutex mutex;
16124 + };
16125 +
16126 +@@ -1460,8 +1465,7 @@ struct hns_roce_sccc_clr_done {
16127 + __le32 rsv[5];
16128 + };
16129 +
16130 +-int hns_roce_v2_query_cqc_info(struct hns_roce_dev *hr_dev, u32 cqn,
16131 +- int *buffer);
16132 ++int hns_roce_v2_destroy_qp(struct ib_qp *ibqp, struct ib_udata *udata);
16133 +
16134 + static inline void hns_roce_write64(struct hns_roce_dev *hr_dev, __le32 val[2],
16135 + void __iomem *dest)
16136 +diff --git a/drivers/infiniband/hw/hns/hns_roce_hw_v2_dfx.c b/drivers/infiniband/hw/hns/hns_roce_hw_v2_dfx.c
16137 +deleted file mode 100644
16138 +index f7a75a7cda749..0000000000000
16139 +--- a/drivers/infiniband/hw/hns/hns_roce_hw_v2_dfx.c
16140 ++++ /dev/null
16141 +@@ -1,34 +0,0 @@
16142 +-// SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
16143 +-// Copyright (c) 2019 Hisilicon Limited.
16144 +-
16145 +-#include "hnae3.h"
16146 +-#include "hns_roce_device.h"
16147 +-#include "hns_roce_cmd.h"
16148 +-#include "hns_roce_hw_v2.h"
16149 +-
16150 +-int hns_roce_v2_query_cqc_info(struct hns_roce_dev *hr_dev, u32 cqn,
16151 +- int *buffer)
16152 +-{
16153 +- struct hns_roce_v2_cq_context *cq_context;
16154 +- struct hns_roce_cmd_mailbox *mailbox;
16155 +- int ret;
16156 +-
16157 +- mailbox = hns_roce_alloc_cmd_mailbox(hr_dev);
16158 +- if (IS_ERR(mailbox))
16159 +- return PTR_ERR(mailbox);
16160 +-
16161 +- cq_context = mailbox->buf;
16162 +- ret = hns_roce_cmd_mbox(hr_dev, 0, mailbox->dma, HNS_ROCE_CMD_QUERY_CQC,
16163 +- cqn);
16164 +- if (ret) {
16165 +- dev_err(hr_dev->dev, "QUERY cqc cmd process error\n");
16166 +- goto err_mailbox;
16167 +- }
16168 +-
16169 +- memcpy(buffer, cq_context, sizeof(*cq_context));
16170 +-
16171 +-err_mailbox:
16172 +- hns_roce_free_cmd_mailbox(hr_dev, mailbox);
16173 +-
16174 +- return ret;
16175 +-}
16176 +diff --git a/drivers/infiniband/hw/hns/hns_roce_main.c b/drivers/infiniband/hw/hns/hns_roce_main.c
16177 +index 4ccb217b2841d..bf5c7729d7e84 100644
16178 +--- a/drivers/infiniband/hw/hns/hns_roce_main.c
16179 ++++ b/drivers/infiniband/hw/hns/hns_roce_main.c
16180 +@@ -354,10 +354,11 @@ static int hns_roce_alloc_uar_entry(struct ib_ucontext *uctx)
16181 + static int hns_roce_alloc_ucontext(struct ib_ucontext *uctx,
16182 + struct ib_udata *udata)
16183 + {
16184 +- int ret;
16185 + struct hns_roce_ucontext *context = to_hr_ucontext(uctx);
16186 +- struct hns_roce_ib_alloc_ucontext_resp resp = {};
16187 + struct hns_roce_dev *hr_dev = to_hr_dev(uctx->device);
16188 ++ struct hns_roce_ib_alloc_ucontext_resp resp = {};
16189 ++ struct hns_roce_ib_alloc_ucontext ucmd = {};
16190 ++ int ret;
16191 +
16192 + if (!hr_dev->active)
16193 + return -EAGAIN;
16194 +@@ -365,6 +366,19 @@ static int hns_roce_alloc_ucontext(struct ib_ucontext *uctx,
16195 + resp.qp_tab_size = hr_dev->caps.num_qps;
16196 + resp.srq_tab_size = hr_dev->caps.num_srqs;
16197 +
16198 ++ ret = ib_copy_from_udata(&ucmd, udata,
16199 ++ min(udata->inlen, sizeof(ucmd)));
16200 ++ if (ret)
16201 ++ return ret;
16202 ++
16203 ++ if (hr_dev->pci_dev->revision >= PCI_REVISION_ID_HIP09)
16204 ++ context->config = ucmd.config & HNS_ROCE_EXSGE_FLAGS;
16205 ++
16206 ++ if (context->config & HNS_ROCE_EXSGE_FLAGS) {
16207 ++ resp.config |= HNS_ROCE_RSP_EXSGE_FLAGS;
16208 ++ resp.max_inline_data = hr_dev->caps.max_sq_inline;
16209 ++ }
16210 ++
16211 + ret = hns_roce_uar_alloc(hr_dev, &context->uar);
16212 + if (ret)
16213 + goto error_fail_uar_alloc;
16214 +@@ -515,7 +529,6 @@ static const struct ib_device_ops hns_roce_dev_ops = {
16215 + .destroy_ah = hns_roce_destroy_ah,
16216 + .destroy_cq = hns_roce_destroy_cq,
16217 + .disassociate_ucontext = hns_roce_disassociate_ucontext,
16218 +- .fill_res_cq_entry = hns_roce_fill_res_cq_entry,
16219 + .get_dma_mr = hns_roce_get_dma_mr,
16220 + .get_link_layer = hns_roce_get_link_layer,
16221 + .get_port_immutable = hns_roce_port_immutable,
16222 +@@ -566,6 +579,10 @@ static const struct ib_device_ops hns_roce_dev_xrcd_ops = {
16223 + INIT_RDMA_OBJ_SIZE(ib_xrcd, hns_roce_xrcd, ibxrcd),
16224 + };
16225 +
16226 ++static const struct ib_device_ops hns_roce_dev_restrack_ops = {
16227 ++ .fill_res_cq_entry = hns_roce_fill_res_cq_entry,
16228 ++};
16229 ++
16230 + static int hns_roce_register_device(struct hns_roce_dev *hr_dev)
16231 + {
16232 + int ret;
16233 +@@ -605,6 +622,7 @@ static int hns_roce_register_device(struct hns_roce_dev *hr_dev)
16234 +
16235 + ib_set_device_ops(ib_dev, hr_dev->hw->hns_roce_dev_ops);
16236 + ib_set_device_ops(ib_dev, &hns_roce_dev_ops);
16237 ++ ib_set_device_ops(ib_dev, &hns_roce_dev_restrack_ops);
16238 + for (i = 0; i < hr_dev->caps.num_ports; i++) {
16239 + if (!hr_dev->iboe.netdevs[i])
16240 + continue;
16241 +diff --git a/drivers/infiniband/hw/hns/hns_roce_mr.c b/drivers/infiniband/hw/hns/hns_roce_mr.c
16242 +index dedfa56f57731..fb165069c8d9d 100644
16243 +--- a/drivers/infiniband/hw/hns/hns_roce_mr.c
16244 ++++ b/drivers/infiniband/hw/hns/hns_roce_mr.c
16245 +@@ -392,10 +392,10 @@ struct ib_mr *hns_roce_alloc_mr(struct ib_pd *pd, enum ib_mr_type mr_type,
16246 +
16247 + return &mr->ibmr;
16248 +
16249 +-err_key:
16250 +- free_mr_key(hr_dev, mr);
16251 + err_pbl:
16252 + free_mr_pbl(hr_dev, mr);
16253 ++err_key:
16254 ++ free_mr_key(hr_dev, mr);
16255 + err_free:
16256 + kfree(mr);
16257 + return ERR_PTR(ret);
16258 +diff --git a/drivers/infiniband/hw/hns/hns_roce_qp.c b/drivers/infiniband/hw/hns/hns_roce_qp.c
16259 +index 7bee7f6c5e702..a0040096ddb1b 100644
16260 +--- a/drivers/infiniband/hw/hns/hns_roce_qp.c
16261 ++++ b/drivers/infiniband/hw/hns/hns_roce_qp.c
16262 +@@ -479,38 +479,109 @@ static int set_rq_size(struct hns_roce_dev *hr_dev, struct ib_qp_cap *cap,
16263 + return 0;
16264 + }
16265 +
16266 +-static u32 get_wqe_ext_sge_cnt(struct hns_roce_qp *qp)
16267 ++static u32 get_max_inline_data(struct hns_roce_dev *hr_dev,
16268 ++ struct ib_qp_cap *cap)
16269 + {
16270 +- /* GSI/UD QP only has extended sge */
16271 +- if (qp->ibqp.qp_type == IB_QPT_GSI || qp->ibqp.qp_type == IB_QPT_UD)
16272 +- return qp->sq.max_gs;
16273 +-
16274 +- if (qp->sq.max_gs > HNS_ROCE_SGE_IN_WQE)
16275 +- return qp->sq.max_gs - HNS_ROCE_SGE_IN_WQE;
16276 ++ if (cap->max_inline_data) {
16277 ++ cap->max_inline_data = roundup_pow_of_two(cap->max_inline_data);
16278 ++ return min(cap->max_inline_data,
16279 ++ hr_dev->caps.max_sq_inline);
16280 ++ }
16281 +
16282 + return 0;
16283 + }
16284 +
16285 ++static void update_inline_data(struct hns_roce_qp *hr_qp,
16286 ++ struct ib_qp_cap *cap)
16287 ++{
16288 ++ u32 sge_num = hr_qp->sq.ext_sge_cnt;
16289 ++
16290 ++ if (hr_qp->config & HNS_ROCE_EXSGE_FLAGS) {
16291 ++ if (!(hr_qp->ibqp.qp_type == IB_QPT_GSI ||
16292 ++ hr_qp->ibqp.qp_type == IB_QPT_UD))
16293 ++ sge_num = max((u32)HNS_ROCE_SGE_IN_WQE, sge_num);
16294 ++
16295 ++ cap->max_inline_data = max(cap->max_inline_data,
16296 ++ sge_num * HNS_ROCE_SGE_SIZE);
16297 ++ }
16298 ++
16299 ++ hr_qp->max_inline_data = cap->max_inline_data;
16300 ++}
16301 ++
16302 ++static u32 get_sge_num_from_max_send_sge(bool is_ud_or_gsi,
16303 ++ u32 max_send_sge)
16304 ++{
16305 ++ unsigned int std_sge_num;
16306 ++ unsigned int min_sge;
16307 ++
16308 ++ std_sge_num = is_ud_or_gsi ? 0 : HNS_ROCE_SGE_IN_WQE;
16309 ++ min_sge = is_ud_or_gsi ? 1 : 0;
16310 ++ return max_send_sge > std_sge_num ? (max_send_sge - std_sge_num) :
16311 ++ min_sge;
16312 ++}
16313 ++
16314 ++static unsigned int get_sge_num_from_max_inl_data(bool is_ud_or_gsi,
16315 ++ u32 max_inline_data)
16316 ++{
16317 ++ unsigned int inline_sge;
16318 ++
16319 ++ inline_sge = roundup_pow_of_two(max_inline_data) / HNS_ROCE_SGE_SIZE;
16320 ++
16321 ++ /*
16322 ++ * if max_inline_data less than
16323 ++ * HNS_ROCE_SGE_IN_WQE * HNS_ROCE_SGE_SIZE,
16324 ++ * In addition to ud's mode, no need to extend sge.
16325 ++ */
16326 ++ if (!is_ud_or_gsi && inline_sge <= HNS_ROCE_SGE_IN_WQE)
16327 ++ inline_sge = 0;
16328 ++
16329 ++ return inline_sge;
16330 ++}
16331 ++
16332 + static void set_ext_sge_param(struct hns_roce_dev *hr_dev, u32 sq_wqe_cnt,
16333 + struct hns_roce_qp *hr_qp, struct ib_qp_cap *cap)
16334 + {
16335 ++ bool is_ud_or_gsi = (hr_qp->ibqp.qp_type == IB_QPT_GSI ||
16336 ++ hr_qp->ibqp.qp_type == IB_QPT_UD);
16337 ++ unsigned int std_sge_num;
16338 ++ u32 inline_ext_sge = 0;
16339 ++ u32 ext_wqe_sge_cnt;
16340 + u32 total_sge_cnt;
16341 +- u32 wqe_sge_cnt;
16342 ++
16343 ++ cap->max_inline_data = get_max_inline_data(hr_dev, cap);
16344 +
16345 + hr_qp->sge.sge_shift = HNS_ROCE_SGE_SHIFT;
16346 ++ std_sge_num = is_ud_or_gsi ? 0 : HNS_ROCE_SGE_IN_WQE;
16347 ++ ext_wqe_sge_cnt = get_sge_num_from_max_send_sge(is_ud_or_gsi,
16348 ++ cap->max_send_sge);
16349 +
16350 +- hr_qp->sq.max_gs = max(1U, cap->max_send_sge);
16351 ++ if (hr_qp->config & HNS_ROCE_EXSGE_FLAGS) {
16352 ++ inline_ext_sge = max(ext_wqe_sge_cnt,
16353 ++ get_sge_num_from_max_inl_data(is_ud_or_gsi,
16354 ++ cap->max_inline_data));
16355 ++ hr_qp->sq.ext_sge_cnt = inline_ext_sge ?
16356 ++ roundup_pow_of_two(inline_ext_sge) : 0;
16357 +
16358 +- wqe_sge_cnt = get_wqe_ext_sge_cnt(hr_qp);
16359 ++ hr_qp->sq.max_gs = max(1U, (hr_qp->sq.ext_sge_cnt + std_sge_num));
16360 ++ hr_qp->sq.max_gs = min(hr_qp->sq.max_gs, hr_dev->caps.max_sq_sg);
16361 ++
16362 ++ ext_wqe_sge_cnt = hr_qp->sq.ext_sge_cnt;
16363 ++ } else {
16364 ++ hr_qp->sq.max_gs = max(1U, cap->max_send_sge);
16365 ++ hr_qp->sq.max_gs = min(hr_qp->sq.max_gs, hr_dev->caps.max_sq_sg);
16366 ++ hr_qp->sq.ext_sge_cnt = hr_qp->sq.max_gs;
16367 ++ }
16368 +
16369 + /* If the number of extended sge is not zero, they MUST use the
16370 + * space of HNS_HW_PAGE_SIZE at least.
16371 + */
16372 +- if (wqe_sge_cnt) {
16373 +- total_sge_cnt = roundup_pow_of_two(sq_wqe_cnt * wqe_sge_cnt);
16374 ++ if (ext_wqe_sge_cnt) {
16375 ++ total_sge_cnt = roundup_pow_of_two(sq_wqe_cnt * ext_wqe_sge_cnt);
16376 + hr_qp->sge.sge_cnt = max(total_sge_cnt,
16377 + (u32)HNS_HW_PAGE_SIZE / HNS_ROCE_SGE_SIZE);
16378 + }
16379 ++
16380 ++ update_inline_data(hr_qp, cap);
16381 + }
16382 +
16383 + static int check_sq_size_with_integrity(struct hns_roce_dev *hr_dev,
16384 +@@ -559,6 +630,7 @@ static int set_user_sq_size(struct hns_roce_dev *hr_dev,
16385 +
16386 + hr_qp->sq.wqe_shift = ucmd->log_sq_stride;
16387 + hr_qp->sq.wqe_cnt = cnt;
16388 ++ cap->max_send_sge = hr_qp->sq.max_gs;
16389 +
16390 + return 0;
16391 + }
16392 +@@ -989,13 +1061,9 @@ static int set_qp_param(struct hns_roce_dev *hr_dev, struct hns_roce_qp *hr_qp,
16393 + struct hns_roce_ib_create_qp *ucmd)
16394 + {
16395 + struct ib_device *ibdev = &hr_dev->ib_dev;
16396 ++ struct hns_roce_ucontext *uctx;
16397 + int ret;
16398 +
16399 +- if (init_attr->cap.max_inline_data > hr_dev->caps.max_sq_inline)
16400 +- init_attr->cap.max_inline_data = hr_dev->caps.max_sq_inline;
16401 +-
16402 +- hr_qp->max_inline_data = init_attr->cap.max_inline_data;
16403 +-
16404 + if (init_attr->sq_sig_type == IB_SIGNAL_ALL_WR)
16405 + hr_qp->sq_signal_bits = IB_SIGNAL_ALL_WR;
16406 + else
16407 +@@ -1018,12 +1086,17 @@ static int set_qp_param(struct hns_roce_dev *hr_dev, struct hns_roce_qp *hr_qp,
16408 + return ret;
16409 + }
16410 +
16411 ++ uctx = rdma_udata_to_drv_context(udata, struct hns_roce_ucontext,
16412 ++ ibucontext);
16413 ++ hr_qp->config = uctx->config;
16414 + ret = set_user_sq_size(hr_dev, &init_attr->cap, hr_qp, ucmd);
16415 + if (ret)
16416 + ibdev_err(ibdev,
16417 + "failed to set user SQ size, ret = %d.\n",
16418 + ret);
16419 + } else {
16420 ++ if (hr_dev->pci_dev->revision >= PCI_REVISION_ID_HIP09)
16421 ++ hr_qp->config = HNS_ROCE_EXSGE_FLAGS;
16422 + ret = set_kernel_sq_size(hr_dev, &init_attr->cap, hr_qp);
16423 + if (ret)
16424 + ibdev_err(ibdev,
16425 +diff --git a/drivers/infiniband/hw/hns/hns_roce_restrack.c b/drivers/infiniband/hw/hns/hns_roce_restrack.c
16426 +index 24a154d646304..83417be15d3fa 100644
16427 +--- a/drivers/infiniband/hw/hns/hns_roce_restrack.c
16428 ++++ b/drivers/infiniband/hw/hns/hns_roce_restrack.c
16429 +@@ -55,45 +55,34 @@ err:
16430 + return -EMSGSIZE;
16431 + }
16432 +
16433 +-int hns_roce_fill_res_cq_entry(struct sk_buff *msg,
16434 +- struct ib_cq *ib_cq)
16435 ++int hns_roce_fill_res_cq_entry(struct sk_buff *msg, struct ib_cq *ib_cq)
16436 + {
16437 + struct hns_roce_dev *hr_dev = to_hr_dev(ib_cq->device);
16438 + struct hns_roce_cq *hr_cq = to_hr_cq(ib_cq);
16439 +- struct hns_roce_v2_cq_context *context;
16440 ++ struct hns_roce_v2_cq_context context;
16441 + struct nlattr *table_attr;
16442 + int ret;
16443 +
16444 +- if (!hr_dev->dfx->query_cqc_info)
16445 ++ if (!hr_dev->hw->query_cqc)
16446 + return -EINVAL;
16447 +
16448 +- context = kzalloc(sizeof(struct hns_roce_v2_cq_context), GFP_KERNEL);
16449 +- if (!context)
16450 +- return -ENOMEM;
16451 +-
16452 +- ret = hr_dev->dfx->query_cqc_info(hr_dev, hr_cq->cqn, (int *)context);
16453 ++ ret = hr_dev->hw->query_cqc(hr_dev, hr_cq->cqn, &context);
16454 + if (ret)
16455 +- goto err;
16456 ++ return -EINVAL;
16457 +
16458 + table_attr = nla_nest_start(msg, RDMA_NLDEV_ATTR_DRIVER);
16459 +- if (!table_attr) {
16460 +- ret = -EMSGSIZE;
16461 +- goto err;
16462 +- }
16463 ++ if (!table_attr)
16464 ++ return -EMSGSIZE;
16465 +
16466 +- if (hns_roce_fill_cq(msg, context)) {
16467 +- ret = -EMSGSIZE;
16468 +- goto err_cancel_table;
16469 +- }
16470 ++ if (hns_roce_fill_cq(msg, &context))
16471 ++ goto err;
16472 +
16473 + nla_nest_end(msg, table_attr);
16474 +- kfree(context);
16475 +
16476 + return 0;
16477 +
16478 +-err_cancel_table:
16479 +- nla_nest_cancel(msg, table_attr);
16480 + err:
16481 +- kfree(context);
16482 +- return ret;
16483 ++ nla_nest_cancel(msg, table_attr);
16484 ++
16485 ++ return -EMSGSIZE;
16486 + }
16487 +diff --git a/drivers/infiniband/hw/irdma/uk.c b/drivers/infiniband/hw/irdma/uk.c
16488 +index a6e5d350a94ce..16183e894da77 100644
16489 +--- a/drivers/infiniband/hw/irdma/uk.c
16490 ++++ b/drivers/infiniband/hw/irdma/uk.c
16491 +@@ -566,21 +566,37 @@ static void irdma_set_mw_bind_wqe_gen_1(__le64 *wqe,
16492 +
16493 + /**
16494 + * irdma_copy_inline_data_gen_1 - Copy inline data to wqe
16495 +- * @dest: pointer to wqe
16496 +- * @src: pointer to inline data
16497 +- * @len: length of inline data to copy
16498 ++ * @wqe: pointer to wqe
16499 ++ * @sge_list: table of pointers to inline data
16500 ++ * @num_sges: Total inline data length
16501 + * @polarity: compatibility parameter
16502 + */
16503 +-static void irdma_copy_inline_data_gen_1(u8 *dest, u8 *src, u32 len,
16504 +- u8 polarity)
16505 ++static void irdma_copy_inline_data_gen_1(u8 *wqe, struct ib_sge *sge_list,
16506 ++ u32 num_sges, u8 polarity)
16507 + {
16508 +- if (len <= 16) {
16509 +- memcpy(dest, src, len);
16510 +- } else {
16511 +- memcpy(dest, src, 16);
16512 +- src += 16;
16513 +- dest = dest + 32;
16514 +- memcpy(dest, src, len - 16);
16515 ++ u32 quanta_bytes_remaining = 16;
16516 ++ int i;
16517 ++
16518 ++ for (i = 0; i < num_sges; i++) {
16519 ++ u8 *cur_sge = (u8 *)(uintptr_t)sge_list[i].addr;
16520 ++ u32 sge_len = sge_list[i].length;
16521 ++
16522 ++ while (sge_len) {
16523 ++ u32 bytes_copied;
16524 ++
16525 ++ bytes_copied = min(sge_len, quanta_bytes_remaining);
16526 ++ memcpy(wqe, cur_sge, bytes_copied);
16527 ++ wqe += bytes_copied;
16528 ++ cur_sge += bytes_copied;
16529 ++ quanta_bytes_remaining -= bytes_copied;
16530 ++ sge_len -= bytes_copied;
16531 ++
16532 ++ if (!quanta_bytes_remaining) {
16533 ++ /* Remaining inline bytes reside after hdr */
16534 ++ wqe += 16;
16535 ++ quanta_bytes_remaining = 32;
16536 ++ }
16537 ++ }
16538 + }
16539 + }
16540 +
16541 +@@ -612,35 +628,51 @@ static void irdma_set_mw_bind_wqe(__le64 *wqe,
16542 +
16543 + /**
16544 + * irdma_copy_inline_data - Copy inline data to wqe
16545 +- * @dest: pointer to wqe
16546 +- * @src: pointer to inline data
16547 +- * @len: length of inline data to copy
16548 ++ * @wqe: pointer to wqe
16549 ++ * @sge_list: table of pointers to inline data
16550 ++ * @num_sges: number of SGE's
16551 + * @polarity: polarity of wqe valid bit
16552 + */
16553 +-static void irdma_copy_inline_data(u8 *dest, u8 *src, u32 len, u8 polarity)
16554 ++static void irdma_copy_inline_data(u8 *wqe, struct ib_sge *sge_list,
16555 ++ u32 num_sges, u8 polarity)
16556 + {
16557 + u8 inline_valid = polarity << IRDMA_INLINE_VALID_S;
16558 +- u32 copy_size;
16559 +-
16560 +- dest += 8;
16561 +- if (len <= 8) {
16562 +- memcpy(dest, src, len);
16563 +- return;
16564 +- }
16565 +-
16566 +- *((u64 *)dest) = *((u64 *)src);
16567 +- len -= 8;
16568 +- src += 8;
16569 +- dest += 24; /* point to additional 32 byte quanta */
16570 +-
16571 +- while (len) {
16572 +- copy_size = len < 31 ? len : 31;
16573 +- memcpy(dest, src, copy_size);
16574 +- *(dest + 31) = inline_valid;
16575 +- len -= copy_size;
16576 +- dest += 32;
16577 +- src += copy_size;
16578 ++ u32 quanta_bytes_remaining = 8;
16579 ++ bool first_quanta = true;
16580 ++ int i;
16581 ++
16582 ++ wqe += 8;
16583 ++
16584 ++ for (i = 0; i < num_sges; i++) {
16585 ++ u8 *cur_sge = (u8 *)(uintptr_t)sge_list[i].addr;
16586 ++ u32 sge_len = sge_list[i].length;
16587 ++
16588 ++ while (sge_len) {
16589 ++ u32 bytes_copied;
16590 ++
16591 ++ bytes_copied = min(sge_len, quanta_bytes_remaining);
16592 ++ memcpy(wqe, cur_sge, bytes_copied);
16593 ++ wqe += bytes_copied;
16594 ++ cur_sge += bytes_copied;
16595 ++ quanta_bytes_remaining -= bytes_copied;
16596 ++ sge_len -= bytes_copied;
16597 ++
16598 ++ if (!quanta_bytes_remaining) {
16599 ++ quanta_bytes_remaining = 31;
16600 ++
16601 ++ /* Remaining inline bytes reside after hdr */
16602 ++ if (first_quanta) {
16603 ++ first_quanta = false;
16604 ++ wqe += 16;
16605 ++ } else {
16606 ++ *wqe = inline_valid;
16607 ++ wqe++;
16608 ++ }
16609 ++ }
16610 ++ }
16611 + }
16612 ++ if (!first_quanta && quanta_bytes_remaining < 31)
16613 ++ *(wqe + quanta_bytes_remaining) = inline_valid;
16614 + }
16615 +
16616 + /**
16617 +@@ -679,20 +711,27 @@ int irdma_uk_inline_rdma_write(struct irdma_qp_uk *qp,
16618 + struct irdma_post_sq_info *info, bool post_sq)
16619 + {
16620 + __le64 *wqe;
16621 +- struct irdma_inline_rdma_write *op_info;
16622 ++ struct irdma_rdma_write *op_info;
16623 + u64 hdr = 0;
16624 + u32 wqe_idx;
16625 + bool read_fence = false;
16626 ++ u32 i, total_size = 0;
16627 + u16 quanta;
16628 +
16629 + info->push_wqe = qp->push_db ? true : false;
16630 +- op_info = &info->op.inline_rdma_write;
16631 ++ op_info = &info->op.rdma_write;
16632 ++
16633 ++ if (unlikely(qp->max_sq_frag_cnt < op_info->num_lo_sges))
16634 ++ return -EINVAL;
16635 ++
16636 ++ for (i = 0; i < op_info->num_lo_sges; i++)
16637 ++ total_size += op_info->lo_sg_list[i].length;
16638 +
16639 +- if (op_info->len > qp->max_inline_data)
16640 ++ if (unlikely(total_size > qp->max_inline_data))
16641 + return -EINVAL;
16642 +
16643 +- quanta = qp->wqe_ops.iw_inline_data_size_to_quanta(op_info->len);
16644 +- wqe = irdma_qp_get_next_send_wqe(qp, &wqe_idx, quanta, op_info->len,
16645 ++ quanta = qp->wqe_ops.iw_inline_data_size_to_quanta(total_size);
16646 ++ wqe = irdma_qp_get_next_send_wqe(qp, &wqe_idx, quanta, total_size,
16647 + info);
16648 + if (!wqe)
16649 + return -ENOMEM;
16650 +@@ -705,7 +744,7 @@ int irdma_uk_inline_rdma_write(struct irdma_qp_uk *qp,
16651 +
16652 + hdr = FIELD_PREP(IRDMAQPSQ_REMSTAG, op_info->rem_addr.lkey) |
16653 + FIELD_PREP(IRDMAQPSQ_OPCODE, info->op_type) |
16654 +- FIELD_PREP(IRDMAQPSQ_INLINEDATALEN, op_info->len) |
16655 ++ FIELD_PREP(IRDMAQPSQ_INLINEDATALEN, total_size) |
16656 + FIELD_PREP(IRDMAQPSQ_REPORTRTT, info->report_rtt ? 1 : 0) |
16657 + FIELD_PREP(IRDMAQPSQ_INLINEDATAFLAG, 1) |
16658 + FIELD_PREP(IRDMAQPSQ_IMMDATAFLAG, info->imm_data_valid ? 1 : 0) |
16659 +@@ -719,7 +758,8 @@ int irdma_uk_inline_rdma_write(struct irdma_qp_uk *qp,
16660 + set_64bit_val(wqe, 0,
16661 + FIELD_PREP(IRDMAQPSQ_IMMDATA, info->imm_data));
16662 +
16663 +- qp->wqe_ops.iw_copy_inline_data((u8 *)wqe, op_info->data, op_info->len,
16664 ++ qp->wqe_ops.iw_copy_inline_data((u8 *)wqe, op_info->lo_sg_list,
16665 ++ op_info->num_lo_sges,
16666 + qp->swqe_polarity);
16667 + dma_wmb(); /* make sure WQE is populated before valid bit is set */
16668 +
16669 +@@ -745,20 +785,27 @@ int irdma_uk_inline_send(struct irdma_qp_uk *qp,
16670 + struct irdma_post_sq_info *info, bool post_sq)
16671 + {
16672 + __le64 *wqe;
16673 +- struct irdma_post_inline_send *op_info;
16674 ++ struct irdma_post_send *op_info;
16675 + u64 hdr;
16676 + u32 wqe_idx;
16677 + bool read_fence = false;
16678 ++ u32 i, total_size = 0;
16679 + u16 quanta;
16680 +
16681 + info->push_wqe = qp->push_db ? true : false;
16682 +- op_info = &info->op.inline_send;
16683 ++ op_info = &info->op.send;
16684 ++
16685 ++ if (unlikely(qp->max_sq_frag_cnt < op_info->num_sges))
16686 ++ return -EINVAL;
16687 +
16688 +- if (op_info->len > qp->max_inline_data)
16689 ++ for (i = 0; i < op_info->num_sges; i++)
16690 ++ total_size += op_info->sg_list[i].length;
16691 ++
16692 ++ if (unlikely(total_size > qp->max_inline_data))
16693 + return -EINVAL;
16694 +
16695 +- quanta = qp->wqe_ops.iw_inline_data_size_to_quanta(op_info->len);
16696 +- wqe = irdma_qp_get_next_send_wqe(qp, &wqe_idx, quanta, op_info->len,
16697 ++ quanta = qp->wqe_ops.iw_inline_data_size_to_quanta(total_size);
16698 ++ wqe = irdma_qp_get_next_send_wqe(qp, &wqe_idx, quanta, total_size,
16699 + info);
16700 + if (!wqe)
16701 + return -ENOMEM;
16702 +@@ -773,7 +820,7 @@ int irdma_uk_inline_send(struct irdma_qp_uk *qp,
16703 + hdr = FIELD_PREP(IRDMAQPSQ_REMSTAG, info->stag_to_inv) |
16704 + FIELD_PREP(IRDMAQPSQ_AHID, op_info->ah_id) |
16705 + FIELD_PREP(IRDMAQPSQ_OPCODE, info->op_type) |
16706 +- FIELD_PREP(IRDMAQPSQ_INLINEDATALEN, op_info->len) |
16707 ++ FIELD_PREP(IRDMAQPSQ_INLINEDATALEN, total_size) |
16708 + FIELD_PREP(IRDMAQPSQ_IMMDATAFLAG,
16709 + (info->imm_data_valid ? 1 : 0)) |
16710 + FIELD_PREP(IRDMAQPSQ_REPORTRTT, (info->report_rtt ? 1 : 0)) |
16711 +@@ -789,8 +836,8 @@ int irdma_uk_inline_send(struct irdma_qp_uk *qp,
16712 + if (info->imm_data_valid)
16713 + set_64bit_val(wqe, 0,
16714 + FIELD_PREP(IRDMAQPSQ_IMMDATA, info->imm_data));
16715 +- qp->wqe_ops.iw_copy_inline_data((u8 *)wqe, op_info->data, op_info->len,
16716 +- qp->swqe_polarity);
16717 ++ qp->wqe_ops.iw_copy_inline_data((u8 *)wqe, op_info->sg_list,
16718 ++ op_info->num_sges, qp->swqe_polarity);
16719 +
16720 + dma_wmb(); /* make sure WQE is populated before valid bit is set */
16721 +
16722 +@@ -1002,11 +1049,10 @@ int irdma_uk_cq_poll_cmpl(struct irdma_cq_uk *cq,
16723 + __le64 *cqe;
16724 + struct irdma_qp_uk *qp;
16725 + struct irdma_ring *pring = NULL;
16726 +- u32 wqe_idx, q_type;
16727 ++ u32 wqe_idx;
16728 + int ret_code;
16729 + bool move_cq_head = true;
16730 + u8 polarity;
16731 +- u8 op_type;
16732 + bool ext_valid;
16733 + __le64 *ext_cqe;
16734 +
16735 +@@ -1074,7 +1120,7 @@ int irdma_uk_cq_poll_cmpl(struct irdma_cq_uk *cq,
16736 + info->ud_vlan_valid = false;
16737 + }
16738 +
16739 +- q_type = (u8)FIELD_GET(IRDMA_CQ_SQ, qword3);
16740 ++ info->q_type = (u8)FIELD_GET(IRDMA_CQ_SQ, qword3);
16741 + info->error = (bool)FIELD_GET(IRDMA_CQ_ERROR, qword3);
16742 + info->push_dropped = (bool)FIELD_GET(IRDMACQ_PSHDROP, qword3);
16743 + info->ipv4 = (bool)FIELD_GET(IRDMACQ_IPV4, qword3);
16744 +@@ -1113,8 +1159,9 @@ int irdma_uk_cq_poll_cmpl(struct irdma_cq_uk *cq,
16745 + }
16746 + wqe_idx = (u32)FIELD_GET(IRDMA_CQ_WQEIDX, qword3);
16747 + info->qp_handle = (irdma_qp_handle)(unsigned long)qp;
16748 ++ info->op_type = (u8)FIELD_GET(IRDMA_CQ_SQ, qword3);
16749 +
16750 +- if (q_type == IRDMA_CQE_QTYPE_RQ) {
16751 ++ if (info->q_type == IRDMA_CQE_QTYPE_RQ) {
16752 + u32 array_idx;
16753 +
16754 + array_idx = wqe_idx / qp->rq_wqe_size_multiplier;
16755 +@@ -1134,10 +1181,6 @@ int irdma_uk_cq_poll_cmpl(struct irdma_cq_uk *cq,
16756 +
16757 + info->bytes_xfered = (u32)FIELD_GET(IRDMACQ_PAYLDLEN, qword0);
16758 +
16759 +- if (info->imm_valid)
16760 +- info->op_type = IRDMA_OP_TYPE_REC_IMM;
16761 +- else
16762 +- info->op_type = IRDMA_OP_TYPE_REC;
16763 + if (qword3 & IRDMACQ_STAG) {
16764 + info->stag_invalid_set = true;
16765 + info->inv_stag = (u32)FIELD_GET(IRDMACQ_INVSTAG, qword2);
16766 +@@ -1195,17 +1238,18 @@ int irdma_uk_cq_poll_cmpl(struct irdma_cq_uk *cq,
16767 + sw_wqe = qp->sq_base[tail].elem;
16768 + get_64bit_val(sw_wqe, 24,
16769 + &wqe_qword);
16770 +- op_type = (u8)FIELD_GET(IRDMAQPSQ_OPCODE, wqe_qword);
16771 +- info->op_type = op_type;
16772 ++ info->op_type = (u8)FIELD_GET(IRDMAQPSQ_OPCODE,
16773 ++ wqe_qword);
16774 + IRDMA_RING_SET_TAIL(qp->sq_ring,
16775 + tail + qp->sq_wrtrk_array[tail].quanta);
16776 +- if (op_type != IRDMAQP_OP_NOP) {
16777 ++ if (info->op_type != IRDMAQP_OP_NOP) {
16778 + info->wr_id = qp->sq_wrtrk_array[tail].wrid;
16779 + info->bytes_xfered = qp->sq_wrtrk_array[tail].wr_len;
16780 + break;
16781 + }
16782 + } while (1);
16783 +- if (op_type == IRDMA_OP_TYPE_BIND_MW && info->minor_err == FLUSH_PROT_ERR)
16784 ++ if (info->op_type == IRDMA_OP_TYPE_BIND_MW &&
16785 ++ info->minor_err == FLUSH_PROT_ERR)
16786 + info->minor_err = FLUSH_MW_BIND_ERR;
16787 + qp->sq_flush_seen = true;
16788 + if (!IRDMA_RING_MORE_WORK(qp->sq_ring))
16789 +diff --git a/drivers/infiniband/hw/irdma/user.h b/drivers/infiniband/hw/irdma/user.h
16790 +index 2ef61923c9268..d0cdf609f5e06 100644
16791 +--- a/drivers/infiniband/hw/irdma/user.h
16792 ++++ b/drivers/infiniband/hw/irdma/user.h
16793 +@@ -173,14 +173,6 @@ struct irdma_post_send {
16794 + u32 ah_id;
16795 + };
16796 +
16797 +-struct irdma_post_inline_send {
16798 +- void *data;
16799 +- u32 len;
16800 +- u32 qkey;
16801 +- u32 dest_qp;
16802 +- u32 ah_id;
16803 +-};
16804 +-
16805 + struct irdma_post_rq_info {
16806 + u64 wr_id;
16807 + struct ib_sge *sg_list;
16808 +@@ -193,12 +185,6 @@ struct irdma_rdma_write {
16809 + struct ib_sge rem_addr;
16810 + };
16811 +
16812 +-struct irdma_inline_rdma_write {
16813 +- void *data;
16814 +- u32 len;
16815 +- struct ib_sge rem_addr;
16816 +-};
16817 +-
16818 + struct irdma_rdma_read {
16819 + struct ib_sge *lo_sg_list;
16820 + u32 num_lo_sges;
16821 +@@ -241,8 +227,6 @@ struct irdma_post_sq_info {
16822 + struct irdma_rdma_read rdma_read;
16823 + struct irdma_bind_window bind_window;
16824 + struct irdma_inv_local_stag inv_local_stag;
16825 +- struct irdma_inline_rdma_write inline_rdma_write;
16826 +- struct irdma_post_inline_send inline_send;
16827 + } op;
16828 + };
16829 +
16830 +@@ -261,6 +245,7 @@ struct irdma_cq_poll_info {
16831 + u16 ud_vlan;
16832 + u8 ud_smac[6];
16833 + u8 op_type;
16834 ++ u8 q_type;
16835 + bool stag_invalid_set:1; /* or L_R_Key set */
16836 + bool push_dropped:1;
16837 + bool error:1;
16838 +@@ -291,7 +276,8 @@ int irdma_uk_stag_local_invalidate(struct irdma_qp_uk *qp,
16839 + bool post_sq);
16840 +
16841 + struct irdma_wqe_uk_ops {
16842 +- void (*iw_copy_inline_data)(u8 *dest, u8 *src, u32 len, u8 polarity);
16843 ++ void (*iw_copy_inline_data)(u8 *dest, struct ib_sge *sge_list,
16844 ++ u32 num_sges, u8 polarity);
16845 + u16 (*iw_inline_data_size_to_quanta)(u32 data_size);
16846 + void (*iw_set_fragment)(__le64 *wqe, u32 offset, struct ib_sge *sge,
16847 + u8 valid);
16848 +diff --git a/drivers/infiniband/hw/irdma/utils.c b/drivers/infiniband/hw/irdma/utils.c
16849 +index 8dfc9e154d733..445e69e864097 100644
16850 +--- a/drivers/infiniband/hw/irdma/utils.c
16851 ++++ b/drivers/infiniband/hw/irdma/utils.c
16852 +@@ -2591,6 +2591,7 @@ void irdma_generate_flush_completions(struct irdma_qp *iwqp)
16853 + sw_wqe = qp->sq_base[wqe_idx].elem;
16854 + get_64bit_val(sw_wqe, 24, &wqe_qword);
16855 + cmpl->cpi.op_type = (u8)FIELD_GET(IRDMAQPSQ_OPCODE, IRDMAQPSQ_OPCODE);
16856 ++ cmpl->cpi.q_type = IRDMA_CQE_QTYPE_SQ;
16857 + /* remove the SQ WR by moving SQ tail*/
16858 + IRDMA_RING_SET_TAIL(*sq_ring,
16859 + sq_ring->tail + qp->sq_wrtrk_array[sq_ring->tail].quanta);
16860 +@@ -2629,6 +2630,7 @@ void irdma_generate_flush_completions(struct irdma_qp *iwqp)
16861 +
16862 + cmpl->cpi.wr_id = qp->rq_wrid_array[wqe_idx];
16863 + cmpl->cpi.op_type = IRDMA_OP_TYPE_REC;
16864 ++ cmpl->cpi.q_type = IRDMA_CQE_QTYPE_RQ;
16865 + /* remove the RQ WR by moving RQ tail */
16866 + IRDMA_RING_SET_TAIL(*rq_ring, rq_ring->tail + 1);
16867 + ibdev_dbg(iwqp->iwrcq->ibcq.device,
16868 +diff --git a/drivers/infiniband/hw/irdma/verbs.c b/drivers/infiniband/hw/irdma/verbs.c
16869 +index a22afbb25bc58..f6973ea55eda7 100644
16870 +--- a/drivers/infiniband/hw/irdma/verbs.c
16871 ++++ b/drivers/infiniband/hw/irdma/verbs.c
16872 +@@ -63,36 +63,6 @@ static int irdma_query_device(struct ib_device *ibdev,
16873 + return 0;
16874 + }
16875 +
16876 +-/**
16877 +- * irdma_get_eth_speed_and_width - Get IB port speed and width from netdev speed
16878 +- * @link_speed: netdev phy link speed
16879 +- * @active_speed: IB port speed
16880 +- * @active_width: IB port width
16881 +- */
16882 +-static void irdma_get_eth_speed_and_width(u32 link_speed, u16 *active_speed,
16883 +- u8 *active_width)
16884 +-{
16885 +- if (link_speed <= SPEED_1000) {
16886 +- *active_width = IB_WIDTH_1X;
16887 +- *active_speed = IB_SPEED_SDR;
16888 +- } else if (link_speed <= SPEED_10000) {
16889 +- *active_width = IB_WIDTH_1X;
16890 +- *active_speed = IB_SPEED_FDR10;
16891 +- } else if (link_speed <= SPEED_20000) {
16892 +- *active_width = IB_WIDTH_4X;
16893 +- *active_speed = IB_SPEED_DDR;
16894 +- } else if (link_speed <= SPEED_25000) {
16895 +- *active_width = IB_WIDTH_1X;
16896 +- *active_speed = IB_SPEED_EDR;
16897 +- } else if (link_speed <= SPEED_40000) {
16898 +- *active_width = IB_WIDTH_4X;
16899 +- *active_speed = IB_SPEED_FDR10;
16900 +- } else {
16901 +- *active_width = IB_WIDTH_4X;
16902 +- *active_speed = IB_SPEED_EDR;
16903 +- }
16904 +-}
16905 +-
16906 + /**
16907 + * irdma_query_port - get port attributes
16908 + * @ibdev: device pointer from stack
16909 +@@ -120,8 +90,9 @@ static int irdma_query_port(struct ib_device *ibdev, u32 port,
16910 + props->state = IB_PORT_DOWN;
16911 + props->phys_state = IB_PORT_PHYS_STATE_DISABLED;
16912 + }
16913 +- irdma_get_eth_speed_and_width(SPEED_100000, &props->active_speed,
16914 +- &props->active_width);
16915 ++
16916 ++ ib_get_eth_speed(ibdev, port, &props->active_speed,
16917 ++ &props->active_width);
16918 +
16919 + if (rdma_protocol_roce(ibdev, 1)) {
16920 + props->gid_tbl_len = 32;
16921 +@@ -1242,6 +1213,7 @@ int irdma_modify_qp_roce(struct ib_qp *ibqp, struct ib_qp_attr *attr,
16922 + av->attrs = attr->ah_attr;
16923 + rdma_gid2ip((struct sockaddr *)&av->sgid_addr, &sgid_attr->gid);
16924 + rdma_gid2ip((struct sockaddr *)&av->dgid_addr, &attr->ah_attr.grh.dgid);
16925 ++ av->net_type = rdma_gid_attr_network_type(sgid_attr);
16926 + if (av->net_type == RDMA_NETWORK_IPV6) {
16927 + __be32 *daddr =
16928 + av->dgid_addr.saddr_in6.sin6_addr.in6_u.u6_addr32;
16929 +@@ -2358,9 +2330,10 @@ static bool irdma_check_mr_contiguous(struct irdma_pble_alloc *palloc,
16930 + * @rf: RDMA PCI function
16931 + * @iwmr: mr pointer for this memory registration
16932 + * @use_pbles: flag if to use pble's
16933 ++ * @lvl_1_only: request only level 1 pble if true
16934 + */
16935 + static int irdma_setup_pbles(struct irdma_pci_f *rf, struct irdma_mr *iwmr,
16936 +- bool use_pbles)
16937 ++ bool use_pbles, bool lvl_1_only)
16938 + {
16939 + struct irdma_pbl *iwpbl = &iwmr->iwpbl;
16940 + struct irdma_pble_alloc *palloc = &iwpbl->pble_alloc;
16941 +@@ -2371,7 +2344,7 @@ static int irdma_setup_pbles(struct irdma_pci_f *rf, struct irdma_mr *iwmr,
16942 +
16943 + if (use_pbles) {
16944 + status = irdma_get_pble(rf->pble_rsrc, palloc, iwmr->page_cnt,
16945 +- false);
16946 ++ lvl_1_only);
16947 + if (status)
16948 + return status;
16949 +
16950 +@@ -2414,16 +2387,10 @@ static int irdma_handle_q_mem(struct irdma_device *iwdev,
16951 + bool ret = true;
16952 +
16953 + pg_size = iwmr->page_size;
16954 +- err = irdma_setup_pbles(iwdev->rf, iwmr, use_pbles);
16955 ++ err = irdma_setup_pbles(iwdev->rf, iwmr, use_pbles, true);
16956 + if (err)
16957 + return err;
16958 +
16959 +- if (use_pbles && palloc->level != PBLE_LEVEL_1) {
16960 +- irdma_free_pble(iwdev->rf->pble_rsrc, palloc);
16961 +- iwpbl->pbl_allocated = false;
16962 +- return -ENOMEM;
16963 +- }
16964 +-
16965 + if (use_pbles)
16966 + arr = palloc->level1.addr;
16967 +
16968 +@@ -2899,7 +2866,7 @@ static struct ib_mr *irdma_reg_user_mr(struct ib_pd *pd, u64 start, u64 len,
16969 + case IRDMA_MEMREG_TYPE_MEM:
16970 + use_pbles = (iwmr->page_cnt != 1);
16971 +
16972 +- err = irdma_setup_pbles(iwdev->rf, iwmr, use_pbles);
16973 ++ err = irdma_setup_pbles(iwdev->rf, iwmr, use_pbles, false);
16974 + if (err)
16975 + goto error;
16976 +
16977 +@@ -3165,30 +3132,20 @@ static int irdma_post_send(struct ib_qp *ibqp,
16978 + info.stag_to_inv = ib_wr->ex.invalidate_rkey;
16979 + }
16980 +
16981 +- if (ib_wr->send_flags & IB_SEND_INLINE) {
16982 +- info.op.inline_send.data = (void *)(unsigned long)
16983 +- ib_wr->sg_list[0].addr;
16984 +- info.op.inline_send.len = ib_wr->sg_list[0].length;
16985 +- if (iwqp->ibqp.qp_type == IB_QPT_UD ||
16986 +- iwqp->ibqp.qp_type == IB_QPT_GSI) {
16987 +- ah = to_iwah(ud_wr(ib_wr)->ah);
16988 +- info.op.inline_send.ah_id = ah->sc_ah.ah_info.ah_idx;
16989 +- info.op.inline_send.qkey = ud_wr(ib_wr)->remote_qkey;
16990 +- info.op.inline_send.dest_qp = ud_wr(ib_wr)->remote_qpn;
16991 +- }
16992 ++ info.op.send.num_sges = ib_wr->num_sge;
16993 ++ info.op.send.sg_list = ib_wr->sg_list;
16994 ++ if (iwqp->ibqp.qp_type == IB_QPT_UD ||
16995 ++ iwqp->ibqp.qp_type == IB_QPT_GSI) {
16996 ++ ah = to_iwah(ud_wr(ib_wr)->ah);
16997 ++ info.op.send.ah_id = ah->sc_ah.ah_info.ah_idx;
16998 ++ info.op.send.qkey = ud_wr(ib_wr)->remote_qkey;
16999 ++ info.op.send.dest_qp = ud_wr(ib_wr)->remote_qpn;
17000 ++ }
17001 ++
17002 ++ if (ib_wr->send_flags & IB_SEND_INLINE)
17003 + err = irdma_uk_inline_send(ukqp, &info, false);
17004 +- } else {
17005 +- info.op.send.num_sges = ib_wr->num_sge;
17006 +- info.op.send.sg_list = ib_wr->sg_list;
17007 +- if (iwqp->ibqp.qp_type == IB_QPT_UD ||
17008 +- iwqp->ibqp.qp_type == IB_QPT_GSI) {
17009 +- ah = to_iwah(ud_wr(ib_wr)->ah);
17010 +- info.op.send.ah_id = ah->sc_ah.ah_info.ah_idx;
17011 +- info.op.send.qkey = ud_wr(ib_wr)->remote_qkey;
17012 +- info.op.send.dest_qp = ud_wr(ib_wr)->remote_qpn;
17013 +- }
17014 ++ else
17015 + err = irdma_uk_send(ukqp, &info, false);
17016 +- }
17017 + break;
17018 + case IB_WR_RDMA_WRITE_WITH_IMM:
17019 + if (ukqp->qp_caps & IRDMA_WRITE_WITH_IMM) {
17020 +@@ -3205,22 +3162,15 @@ static int irdma_post_send(struct ib_qp *ibqp,
17021 + else
17022 + info.op_type = IRDMA_OP_TYPE_RDMA_WRITE;
17023 +
17024 +- if (ib_wr->send_flags & IB_SEND_INLINE) {
17025 +- info.op.inline_rdma_write.data = (void *)(uintptr_t)ib_wr->sg_list[0].addr;
17026 +- info.op.inline_rdma_write.len =
17027 +- ib_wr->sg_list[0].length;
17028 +- info.op.inline_rdma_write.rem_addr.addr =
17029 +- rdma_wr(ib_wr)->remote_addr;
17030 +- info.op.inline_rdma_write.rem_addr.lkey =
17031 +- rdma_wr(ib_wr)->rkey;
17032 ++ info.op.rdma_write.num_lo_sges = ib_wr->num_sge;
17033 ++ info.op.rdma_write.lo_sg_list = ib_wr->sg_list;
17034 ++ info.op.rdma_write.rem_addr.addr =
17035 ++ rdma_wr(ib_wr)->remote_addr;
17036 ++ info.op.rdma_write.rem_addr.lkey = rdma_wr(ib_wr)->rkey;
17037 ++ if (ib_wr->send_flags & IB_SEND_INLINE)
17038 + err = irdma_uk_inline_rdma_write(ukqp, &info, false);
17039 +- } else {
17040 +- info.op.rdma_write.lo_sg_list = (void *)ib_wr->sg_list;
17041 +- info.op.rdma_write.num_lo_sges = ib_wr->num_sge;
17042 +- info.op.rdma_write.rem_addr.addr = rdma_wr(ib_wr)->remote_addr;
17043 +- info.op.rdma_write.rem_addr.lkey = rdma_wr(ib_wr)->rkey;
17044 ++ else
17045 + err = irdma_uk_rdma_write(ukqp, &info, false);
17046 +- }
17047 + break;
17048 + case IB_WR_RDMA_READ_WITH_INV:
17049 + inv_stag = true;
17050 +@@ -3380,7 +3330,6 @@ static enum ib_wc_status irdma_flush_err_to_ib_wc_status(enum irdma_flush_opcode
17051 + static void irdma_process_cqe(struct ib_wc *entry,
17052 + struct irdma_cq_poll_info *cq_poll_info)
17053 + {
17054 +- struct irdma_qp *iwqp;
17055 + struct irdma_sc_qp *qp;
17056 +
17057 + entry->wc_flags = 0;
17058 +@@ -3388,7 +3337,6 @@ static void irdma_process_cqe(struct ib_wc *entry,
17059 + entry->wr_id = cq_poll_info->wr_id;
17060 +
17061 + qp = cq_poll_info->qp_handle;
17062 +- iwqp = qp->qp_uk.back_qp;
17063 + entry->qp = qp->qp_uk.back_qp;
17064 +
17065 + if (cq_poll_info->error) {
17066 +@@ -3421,42 +3369,17 @@ static void irdma_process_cqe(struct ib_wc *entry,
17067 + }
17068 + }
17069 +
17070 +- switch (cq_poll_info->op_type) {
17071 +- case IRDMA_OP_TYPE_RDMA_WRITE:
17072 +- case IRDMA_OP_TYPE_RDMA_WRITE_SOL:
17073 +- entry->opcode = IB_WC_RDMA_WRITE;
17074 +- break;
17075 +- case IRDMA_OP_TYPE_RDMA_READ_INV_STAG:
17076 +- case IRDMA_OP_TYPE_RDMA_READ:
17077 +- entry->opcode = IB_WC_RDMA_READ;
17078 +- break;
17079 +- case IRDMA_OP_TYPE_SEND_INV:
17080 +- case IRDMA_OP_TYPE_SEND_SOL:
17081 +- case IRDMA_OP_TYPE_SEND_SOL_INV:
17082 +- case IRDMA_OP_TYPE_SEND:
17083 +- entry->opcode = IB_WC_SEND;
17084 +- break;
17085 +- case IRDMA_OP_TYPE_FAST_REG_NSMR:
17086 +- entry->opcode = IB_WC_REG_MR;
17087 +- break;
17088 +- case IRDMA_OP_TYPE_INV_STAG:
17089 +- entry->opcode = IB_WC_LOCAL_INV;
17090 +- break;
17091 +- case IRDMA_OP_TYPE_REC_IMM:
17092 +- case IRDMA_OP_TYPE_REC:
17093 +- entry->opcode = cq_poll_info->op_type == IRDMA_OP_TYPE_REC_IMM ?
17094 +- IB_WC_RECV_RDMA_WITH_IMM : IB_WC_RECV;
17095 ++ if (cq_poll_info->q_type == IRDMA_CQE_QTYPE_SQ) {
17096 ++ set_ib_wc_op_sq(cq_poll_info, entry);
17097 ++ } else {
17098 ++ set_ib_wc_op_rq(cq_poll_info, entry,
17099 ++ qp->qp_uk.qp_caps & IRDMA_SEND_WITH_IMM ?
17100 ++ true : false);
17101 + if (qp->qp_uk.qp_type != IRDMA_QP_TYPE_ROCE_UD &&
17102 + cq_poll_info->stag_invalid_set) {
17103 + entry->ex.invalidate_rkey = cq_poll_info->inv_stag;
17104 + entry->wc_flags |= IB_WC_WITH_INVALIDATE;
17105 + }
17106 +- break;
17107 +- default:
17108 +- ibdev_err(&iwqp->iwdev->ibdev,
17109 +- "Invalid opcode = %d in CQE\n", cq_poll_info->op_type);
17110 +- entry->status = IB_WC_GENERAL_ERR;
17111 +- return;
17112 + }
17113 +
17114 + if (qp->qp_uk.qp_type == IRDMA_QP_TYPE_ROCE_UD) {
17115 +diff --git a/drivers/infiniband/hw/irdma/verbs.h b/drivers/infiniband/hw/irdma/verbs.h
17116 +index 4309b7159f42c..a536e9fa85ebf 100644
17117 +--- a/drivers/infiniband/hw/irdma/verbs.h
17118 ++++ b/drivers/infiniband/hw/irdma/verbs.h
17119 +@@ -232,6 +232,59 @@ static inline u16 irdma_fw_minor_ver(struct irdma_sc_dev *dev)
17120 + return (u16)FIELD_GET(IRDMA_FW_VER_MINOR, dev->feature_info[IRDMA_FEATURE_FW_INFO]);
17121 + }
17122 +
17123 ++static inline void set_ib_wc_op_sq(struct irdma_cq_poll_info *cq_poll_info,
17124 ++ struct ib_wc *entry)
17125 ++{
17126 ++ switch (cq_poll_info->op_type) {
17127 ++ case IRDMA_OP_TYPE_RDMA_WRITE:
17128 ++ case IRDMA_OP_TYPE_RDMA_WRITE_SOL:
17129 ++ entry->opcode = IB_WC_RDMA_WRITE;
17130 ++ break;
17131 ++ case IRDMA_OP_TYPE_RDMA_READ_INV_STAG:
17132 ++ case IRDMA_OP_TYPE_RDMA_READ:
17133 ++ entry->opcode = IB_WC_RDMA_READ;
17134 ++ break;
17135 ++ case IRDMA_OP_TYPE_SEND_SOL:
17136 ++ case IRDMA_OP_TYPE_SEND_SOL_INV:
17137 ++ case IRDMA_OP_TYPE_SEND_INV:
17138 ++ case IRDMA_OP_TYPE_SEND:
17139 ++ entry->opcode = IB_WC_SEND;
17140 ++ break;
17141 ++ case IRDMA_OP_TYPE_FAST_REG_NSMR:
17142 ++ entry->opcode = IB_WC_REG_MR;
17143 ++ break;
17144 ++ case IRDMA_OP_TYPE_INV_STAG:
17145 ++ entry->opcode = IB_WC_LOCAL_INV;
17146 ++ break;
17147 ++ default:
17148 ++ entry->status = IB_WC_GENERAL_ERR;
17149 ++ }
17150 ++}
17151 ++
17152 ++static inline void set_ib_wc_op_rq(struct irdma_cq_poll_info *cq_poll_info,
17153 ++ struct ib_wc *entry, bool send_imm_support)
17154 ++{
17155 ++ /**
17156 ++ * iWARP does not support sendImm, so the presence of Imm data
17157 ++ * must be WriteImm.
17158 ++ */
17159 ++ if (!send_imm_support) {
17160 ++ entry->opcode = cq_poll_info->imm_valid ?
17161 ++ IB_WC_RECV_RDMA_WITH_IMM :
17162 ++ IB_WC_RECV;
17163 ++ return;
17164 ++ }
17165 ++
17166 ++ switch (cq_poll_info->op_type) {
17167 ++ case IB_OPCODE_RDMA_WRITE_ONLY_WITH_IMMEDIATE:
17168 ++ case IB_OPCODE_RDMA_WRITE_LAST_WITH_IMMEDIATE:
17169 ++ entry->opcode = IB_WC_RECV_RDMA_WITH_IMM;
17170 ++ break;
17171 ++ default:
17172 ++ entry->opcode = IB_WC_RECV;
17173 ++ }
17174 ++}
17175 ++
17176 + void irdma_mcast_mac(u32 *ip_addr, u8 *mac, bool ipv4);
17177 + int irdma_ib_register_device(struct irdma_device *iwdev);
17178 + void irdma_ib_unregister_device(struct irdma_device *iwdev);
17179 +diff --git a/drivers/infiniband/sw/rxe/rxe_mr.c b/drivers/infiniband/sw/rxe/rxe_mr.c
17180 +index af34f198e6456..8cd6f1b165d55 100644
17181 +--- a/drivers/infiniband/sw/rxe/rxe_mr.c
17182 ++++ b/drivers/infiniband/sw/rxe/rxe_mr.c
17183 +@@ -99,6 +99,7 @@ err2:
17184 + kfree(mr->map[i]);
17185 +
17186 + kfree(mr->map);
17187 ++ mr->map = NULL;
17188 + err1:
17189 + return -ENOMEM;
17190 + }
17191 +@@ -122,7 +123,6 @@ int rxe_mr_init_user(struct rxe_dev *rxe, u64 start, u64 length, u64 iova,
17192 + int num_buf;
17193 + void *vaddr;
17194 + int err;
17195 +- int i;
17196 +
17197 + umem = ib_umem_get(&rxe->ib_dev, start, length, access);
17198 + if (IS_ERR(umem)) {
17199 +@@ -163,9 +163,8 @@ int rxe_mr_init_user(struct rxe_dev *rxe, u64 start, u64 length, u64 iova,
17200 + pr_warn("%s: Unable to get virtual address\n",
17201 + __func__);
17202 + err = -ENOMEM;
17203 +- goto err_cleanup_map;
17204 ++ goto err_release_umem;
17205 + }
17206 +-
17207 + buf->addr = (uintptr_t)vaddr;
17208 + buf->size = PAGE_SIZE;
17209 + num_buf++;
17210 +@@ -185,10 +184,6 @@ int rxe_mr_init_user(struct rxe_dev *rxe, u64 start, u64 length, u64 iova,
17211 +
17212 + return 0;
17213 +
17214 +-err_cleanup_map:
17215 +- for (i = 0; i < mr->num_map; i++)
17216 +- kfree(mr->map[i]);
17217 +- kfree(mr->map);
17218 + err_release_umem:
17219 + ib_umem_release(umem);
17220 + err_out:
17221 +diff --git a/drivers/infiniband/sw/rxe/rxe_qp.c b/drivers/infiniband/sw/rxe/rxe_qp.c
17222 +index d776dfda43b16..e9c573fe71553 100644
17223 +--- a/drivers/infiniband/sw/rxe/rxe_qp.c
17224 ++++ b/drivers/infiniband/sw/rxe/rxe_qp.c
17225 +@@ -830,12 +830,12 @@ static void rxe_qp_do_cleanup(struct work_struct *work)
17226 + if (qp->resp.mr)
17227 + rxe_put(qp->resp.mr);
17228 +
17229 +- if (qp_type(qp) == IB_QPT_RC)
17230 +- sk_dst_reset(qp->sk->sk);
17231 +-
17232 + free_rd_atomic_resources(qp);
17233 +
17234 + if (qp->sk) {
17235 ++ if (qp_type(qp) == IB_QPT_RC)
17236 ++ sk_dst_reset(qp->sk->sk);
17237 ++
17238 + kernel_sock_shutdown(qp->sk, SHUT_RDWR);
17239 + sock_release(qp->sk);
17240 + }
17241 +diff --git a/drivers/infiniband/sw/siw/siw_cq.c b/drivers/infiniband/sw/siw/siw_cq.c
17242 +index d68e37859e73b..403029de6b92d 100644
17243 +--- a/drivers/infiniband/sw/siw/siw_cq.c
17244 ++++ b/drivers/infiniband/sw/siw/siw_cq.c
17245 +@@ -56,8 +56,6 @@ int siw_reap_cqe(struct siw_cq *cq, struct ib_wc *wc)
17246 + if (READ_ONCE(cqe->flags) & SIW_WQE_VALID) {
17247 + memset(wc, 0, sizeof(*wc));
17248 + wc->wr_id = cqe->id;
17249 +- wc->status = map_cqe_status[cqe->status].ib;
17250 +- wc->opcode = map_wc_opcode[cqe->opcode];
17251 + wc->byte_len = cqe->bytes;
17252 +
17253 + /*
17254 +@@ -71,10 +69,32 @@ int siw_reap_cqe(struct siw_cq *cq, struct ib_wc *wc)
17255 + wc->wc_flags = IB_WC_WITH_INVALIDATE;
17256 + }
17257 + wc->qp = cqe->base_qp;
17258 ++ wc->opcode = map_wc_opcode[cqe->opcode];
17259 ++ wc->status = map_cqe_status[cqe->status].ib;
17260 + siw_dbg_cq(cq,
17261 + "idx %u, type %d, flags %2x, id 0x%pK\n",
17262 + cq->cq_get % cq->num_cqe, cqe->opcode,
17263 + cqe->flags, (void *)(uintptr_t)cqe->id);
17264 ++ } else {
17265 ++ /*
17266 ++ * A malicious user may set invalid opcode or
17267 ++ * status in the user mmapped CQE array.
17268 ++ * Sanity check and correct values in that case
17269 ++ * to avoid out-of-bounds access to global arrays
17270 ++ * for opcode and status mapping.
17271 ++ */
17272 ++ u8 opcode = cqe->opcode;
17273 ++ u16 status = cqe->status;
17274 ++
17275 ++ if (opcode >= SIW_NUM_OPCODES) {
17276 ++ opcode = 0;
17277 ++ status = SIW_WC_GENERAL_ERR;
17278 ++ } else if (status >= SIW_NUM_WC_STATUS) {
17279 ++ status = SIW_WC_GENERAL_ERR;
17280 ++ }
17281 ++ wc->opcode = map_wc_opcode[opcode];
17282 ++ wc->status = map_cqe_status[status].ib;
17283 ++
17284 + }
17285 + WRITE_ONCE(cqe->flags, 0);
17286 + cq->cq_get++;
17287 +diff --git a/drivers/infiniband/sw/siw/siw_qp_tx.c b/drivers/infiniband/sw/siw/siw_qp_tx.c
17288 +index 7d47b521070b1..05052b49107f2 100644
17289 +--- a/drivers/infiniband/sw/siw/siw_qp_tx.c
17290 ++++ b/drivers/infiniband/sw/siw/siw_qp_tx.c
17291 +@@ -29,7 +29,7 @@ static struct page *siw_get_pblpage(struct siw_mem *mem, u64 addr, int *idx)
17292 + dma_addr_t paddr = siw_pbl_get_buffer(pbl, offset, NULL, idx);
17293 +
17294 + if (paddr)
17295 +- return virt_to_page((void *)paddr);
17296 ++ return virt_to_page((void *)(uintptr_t)paddr);
17297 +
17298 + return NULL;
17299 + }
17300 +diff --git a/drivers/infiniband/sw/siw/siw_verbs.c b/drivers/infiniband/sw/siw/siw_verbs.c
17301 +index 3e814cfb298cf..906fde1a2a0de 100644
17302 +--- a/drivers/infiniband/sw/siw/siw_verbs.c
17303 ++++ b/drivers/infiniband/sw/siw/siw_verbs.c
17304 +@@ -676,13 +676,45 @@ static int siw_copy_inline_sgl(const struct ib_send_wr *core_wr,
17305 + static int siw_sq_flush_wr(struct siw_qp *qp, const struct ib_send_wr *wr,
17306 + const struct ib_send_wr **bad_wr)
17307 + {
17308 +- struct siw_sqe sqe = {};
17309 + int rv = 0;
17310 +
17311 + while (wr) {
17312 +- sqe.id = wr->wr_id;
17313 +- sqe.opcode = wr->opcode;
17314 +- rv = siw_sqe_complete(qp, &sqe, 0, SIW_WC_WR_FLUSH_ERR);
17315 ++ struct siw_sqe sqe = {};
17316 ++
17317 ++ switch (wr->opcode) {
17318 ++ case IB_WR_RDMA_WRITE:
17319 ++ sqe.opcode = SIW_OP_WRITE;
17320 ++ break;
17321 ++ case IB_WR_RDMA_READ:
17322 ++ sqe.opcode = SIW_OP_READ;
17323 ++ break;
17324 ++ case IB_WR_RDMA_READ_WITH_INV:
17325 ++ sqe.opcode = SIW_OP_READ_LOCAL_INV;
17326 ++ break;
17327 ++ case IB_WR_SEND:
17328 ++ sqe.opcode = SIW_OP_SEND;
17329 ++ break;
17330 ++ case IB_WR_SEND_WITH_IMM:
17331 ++ sqe.opcode = SIW_OP_SEND_WITH_IMM;
17332 ++ break;
17333 ++ case IB_WR_SEND_WITH_INV:
17334 ++ sqe.opcode = SIW_OP_SEND_REMOTE_INV;
17335 ++ break;
17336 ++ case IB_WR_LOCAL_INV:
17337 ++ sqe.opcode = SIW_OP_INVAL_STAG;
17338 ++ break;
17339 ++ case IB_WR_REG_MR:
17340 ++ sqe.opcode = SIW_OP_REG_MR;
17341 ++ break;
17342 ++ default:
17343 ++ rv = -EINVAL;
17344 ++ break;
17345 ++ }
17346 ++ if (!rv) {
17347 ++ sqe.id = wr->wr_id;
17348 ++ rv = siw_sqe_complete(qp, &sqe, 0,
17349 ++ SIW_WC_WR_FLUSH_ERR);
17350 ++ }
17351 + if (rv) {
17352 + if (bad_wr)
17353 + *bad_wr = wr;
17354 +diff --git a/drivers/infiniband/ulp/ipoib/ipoib_netlink.c b/drivers/infiniband/ulp/ipoib/ipoib_netlink.c
17355 +index ea16ba5d8da6c..9ad8d98562752 100644
17356 +--- a/drivers/infiniband/ulp/ipoib/ipoib_netlink.c
17357 ++++ b/drivers/infiniband/ulp/ipoib/ipoib_netlink.c
17358 +@@ -41,6 +41,11 @@ static const struct nla_policy ipoib_policy[IFLA_IPOIB_MAX + 1] = {
17359 + [IFLA_IPOIB_UMCAST] = { .type = NLA_U16 },
17360 + };
17361 +
17362 ++static unsigned int ipoib_get_max_num_queues(void)
17363 ++{
17364 ++ return min_t(unsigned int, num_possible_cpus(), 128);
17365 ++}
17366 ++
17367 + static int ipoib_fill_info(struct sk_buff *skb, const struct net_device *dev)
17368 + {
17369 + struct ipoib_dev_priv *priv = ipoib_priv(dev);
17370 +@@ -172,6 +177,8 @@ static struct rtnl_link_ops ipoib_link_ops __read_mostly = {
17371 + .changelink = ipoib_changelink,
17372 + .get_size = ipoib_get_size,
17373 + .fill_info = ipoib_fill_info,
17374 ++ .get_num_rx_queues = ipoib_get_max_num_queues,
17375 ++ .get_num_tx_queues = ipoib_get_max_num_queues,
17376 + };
17377 +
17378 + struct rtnl_link_ops *ipoib_get_link_ops(void)
17379 +diff --git a/drivers/infiniband/ulp/srp/ib_srp.c b/drivers/infiniband/ulp/srp/ib_srp.c
17380 +index 9c9872868aeea..4f5e49393c854 100644
17381 +--- a/drivers/infiniband/ulp/srp/ib_srp.c
17382 ++++ b/drivers/infiniband/ulp/srp/ib_srp.c
17383 +@@ -3405,7 +3405,8 @@ static int srp_parse_options(struct net *net, const char *buf,
17384 + break;
17385 +
17386 + case SRP_OPT_PKEY:
17387 +- if (match_hex(args, &token)) {
17388 ++ ret = match_hex(args, &token);
17389 ++ if (ret) {
17390 + pr_warn("bad P_Key parameter '%s'\n", p);
17391 + goto out;
17392 + }
17393 +@@ -3465,7 +3466,8 @@ static int srp_parse_options(struct net *net, const char *buf,
17394 + break;
17395 +
17396 + case SRP_OPT_MAX_SECT:
17397 +- if (match_int(args, &token)) {
17398 ++ ret = match_int(args, &token);
17399 ++ if (ret) {
17400 + pr_warn("bad max sect parameter '%s'\n", p);
17401 + goto out;
17402 + }
17403 +@@ -3473,8 +3475,15 @@ static int srp_parse_options(struct net *net, const char *buf,
17404 + break;
17405 +
17406 + case SRP_OPT_QUEUE_SIZE:
17407 +- if (match_int(args, &token) || token < 1) {
17408 ++ ret = match_int(args, &token);
17409 ++ if (ret) {
17410 ++ pr_warn("match_int() failed for queue_size parameter '%s', Error %d\n",
17411 ++ p, ret);
17412 ++ goto out;
17413 ++ }
17414 ++ if (token < 1) {
17415 + pr_warn("bad queue_size parameter '%s'\n", p);
17416 ++ ret = -EINVAL;
17417 + goto out;
17418 + }
17419 + target->scsi_host->can_queue = token;
17420 +@@ -3485,25 +3494,40 @@ static int srp_parse_options(struct net *net, const char *buf,
17421 + break;
17422 +
17423 + case SRP_OPT_MAX_CMD_PER_LUN:
17424 +- if (match_int(args, &token) || token < 1) {
17425 ++ ret = match_int(args, &token);
17426 ++ if (ret) {
17427 ++ pr_warn("match_int() failed for max cmd_per_lun parameter '%s', Error %d\n",
17428 ++ p, ret);
17429 ++ goto out;
17430 ++ }
17431 ++ if (token < 1) {
17432 + pr_warn("bad max cmd_per_lun parameter '%s'\n",
17433 + p);
17434 ++ ret = -EINVAL;
17435 + goto out;
17436 + }
17437 + target->scsi_host->cmd_per_lun = token;
17438 + break;
17439 +
17440 + case SRP_OPT_TARGET_CAN_QUEUE:
17441 +- if (match_int(args, &token) || token < 1) {
17442 ++ ret = match_int(args, &token);
17443 ++ if (ret) {
17444 ++ pr_warn("match_int() failed for max target_can_queue parameter '%s', Error %d\n",
17445 ++ p, ret);
17446 ++ goto out;
17447 ++ }
17448 ++ if (token < 1) {
17449 + pr_warn("bad max target_can_queue parameter '%s'\n",
17450 + p);
17451 ++ ret = -EINVAL;
17452 + goto out;
17453 + }
17454 + target->target_can_queue = token;
17455 + break;
17456 +
17457 + case SRP_OPT_IO_CLASS:
17458 +- if (match_hex(args, &token)) {
17459 ++ ret = match_hex(args, &token);
17460 ++ if (ret) {
17461 + pr_warn("bad IO class parameter '%s'\n", p);
17462 + goto out;
17463 + }
17464 +@@ -3512,6 +3536,7 @@ static int srp_parse_options(struct net *net, const char *buf,
17465 + pr_warn("unknown IO class parameter value %x specified (use %x or %x).\n",
17466 + token, SRP_REV10_IB_IO_CLASS,
17467 + SRP_REV16A_IB_IO_CLASS);
17468 ++ ret = -EINVAL;
17469 + goto out;
17470 + }
17471 + target->io_class = token;
17472 +@@ -3534,16 +3559,24 @@ static int srp_parse_options(struct net *net, const char *buf,
17473 + break;
17474 +
17475 + case SRP_OPT_CMD_SG_ENTRIES:
17476 +- if (match_int(args, &token) || token < 1 || token > 255) {
17477 ++ ret = match_int(args, &token);
17478 ++ if (ret) {
17479 ++ pr_warn("match_int() failed for max cmd_sg_entries parameter '%s', Error %d\n",
17480 ++ p, ret);
17481 ++ goto out;
17482 ++ }
17483 ++ if (token < 1 || token > 255) {
17484 + pr_warn("bad max cmd_sg_entries parameter '%s'\n",
17485 + p);
17486 ++ ret = -EINVAL;
17487 + goto out;
17488 + }
17489 + target->cmd_sg_cnt = token;
17490 + break;
17491 +
17492 + case SRP_OPT_ALLOW_EXT_SG:
17493 +- if (match_int(args, &token)) {
17494 ++ ret = match_int(args, &token);
17495 ++ if (ret) {
17496 + pr_warn("bad allow_ext_sg parameter '%s'\n", p);
17497 + goto out;
17498 + }
17499 +@@ -3551,43 +3584,77 @@ static int srp_parse_options(struct net *net, const char *buf,
17500 + break;
17501 +
17502 + case SRP_OPT_SG_TABLESIZE:
17503 +- if (match_int(args, &token) || token < 1 ||
17504 +- token > SG_MAX_SEGMENTS) {
17505 ++ ret = match_int(args, &token);
17506 ++ if (ret) {
17507 ++ pr_warn("match_int() failed for max sg_tablesize parameter '%s', Error %d\n",
17508 ++ p, ret);
17509 ++ goto out;
17510 ++ }
17511 ++ if (token < 1 || token > SG_MAX_SEGMENTS) {
17512 + pr_warn("bad max sg_tablesize parameter '%s'\n",
17513 + p);
17514 ++ ret = -EINVAL;
17515 + goto out;
17516 + }
17517 + target->sg_tablesize = token;
17518 + break;
17519 +
17520 + case SRP_OPT_COMP_VECTOR:
17521 +- if (match_int(args, &token) || token < 0) {
17522 ++ ret = match_int(args, &token);
17523 ++ if (ret) {
17524 ++ pr_warn("match_int() failed for comp_vector parameter '%s', Error %d\n",
17525 ++ p, ret);
17526 ++ goto out;
17527 ++ }
17528 ++ if (token < 0) {
17529 + pr_warn("bad comp_vector parameter '%s'\n", p);
17530 ++ ret = -EINVAL;
17531 + goto out;
17532 + }
17533 + target->comp_vector = token;
17534 + break;
17535 +
17536 + case SRP_OPT_TL_RETRY_COUNT:
17537 +- if (match_int(args, &token) || token < 2 || token > 7) {
17538 ++ ret = match_int(args, &token);
17539 ++ if (ret) {
17540 ++ pr_warn("match_int() failed for tl_retry_count parameter '%s', Error %d\n",
17541 ++ p, ret);
17542 ++ goto out;
17543 ++ }
17544 ++ if (token < 2 || token > 7) {
17545 + pr_warn("bad tl_retry_count parameter '%s' (must be a number between 2 and 7)\n",
17546 + p);
17547 ++ ret = -EINVAL;
17548 + goto out;
17549 + }
17550 + target->tl_retry_count = token;
17551 + break;
17552 +
17553 + case SRP_OPT_MAX_IT_IU_SIZE:
17554 +- if (match_int(args, &token) || token < 0) {
17555 ++ ret = match_int(args, &token);
17556 ++ if (ret) {
17557 ++ pr_warn("match_int() failed for max it_iu_size parameter '%s', Error %d\n",
17558 ++ p, ret);
17559 ++ goto out;
17560 ++ }
17561 ++ if (token < 0) {
17562 + pr_warn("bad maximum initiator to target IU size '%s'\n", p);
17563 ++ ret = -EINVAL;
17564 + goto out;
17565 + }
17566 + target->max_it_iu_size = token;
17567 + break;
17568 +
17569 + case SRP_OPT_CH_COUNT:
17570 +- if (match_int(args, &token) || token < 1) {
17571 ++ ret = match_int(args, &token);
17572 ++ if (ret) {
17573 ++ pr_warn("match_int() failed for channel count parameter '%s', Error %d\n",
17574 ++ p, ret);
17575 ++ goto out;
17576 ++ }
17577 ++ if (token < 1) {
17578 + pr_warn("bad channel count %s\n", p);
17579 ++ ret = -EINVAL;
17580 + goto out;
17581 + }
17582 + target->ch_count = token;
17583 +@@ -3596,6 +3663,7 @@ static int srp_parse_options(struct net *net, const char *buf,
17584 + default:
17585 + pr_warn("unknown parameter or missing value '%s' in target creation request\n",
17586 + p);
17587 ++ ret = -EINVAL;
17588 + goto out;
17589 + }
17590 + }
17591 +diff --git a/drivers/input/joystick/Kconfig b/drivers/input/joystick/Kconfig
17592 +index 9dcf3f51f2dd9..04ca3d1c28162 100644
17593 +--- a/drivers/input/joystick/Kconfig
17594 ++++ b/drivers/input/joystick/Kconfig
17595 +@@ -46,6 +46,7 @@ config JOYSTICK_A3D
17596 + config JOYSTICK_ADC
17597 + tristate "Simple joystick connected over ADC"
17598 + depends on IIO
17599 ++ select IIO_BUFFER
17600 + select IIO_BUFFER_CB
17601 + help
17602 + Say Y here if you have a simple joystick connected over ADC.
17603 +diff --git a/drivers/input/misc/Kconfig b/drivers/input/misc/Kconfig
17604 +index a18ab7358d8f3..54c116e56e9d0 100644
17605 +--- a/drivers/input/misc/Kconfig
17606 ++++ b/drivers/input/misc/Kconfig
17607 +@@ -330,7 +330,7 @@ config INPUT_CPCAP_PWRBUTTON
17608 +
17609 + config INPUT_WISTRON_BTNS
17610 + tristate "x86 Wistron laptop button interface"
17611 +- depends on X86_32
17612 ++ depends on X86_32 && !UML
17613 + select INPUT_SPARSEKMAP
17614 + select NEW_LEDS
17615 + select LEDS_CLASS
17616 +diff --git a/drivers/input/misc/iqs7222.c b/drivers/input/misc/iqs7222.c
17617 +index b2e8097a2e6d9..e47ab6c1177f5 100644
17618 +--- a/drivers/input/misc/iqs7222.c
17619 ++++ b/drivers/input/misc/iqs7222.c
17620 +@@ -86,7 +86,9 @@ enum iqs7222_reg_key_id {
17621 + IQS7222_REG_KEY_TOUCH,
17622 + IQS7222_REG_KEY_DEBOUNCE,
17623 + IQS7222_REG_KEY_TAP,
17624 ++ IQS7222_REG_KEY_TAP_LEGACY,
17625 + IQS7222_REG_KEY_AXIAL,
17626 ++ IQS7222_REG_KEY_AXIAL_LEGACY,
17627 + IQS7222_REG_KEY_WHEEL,
17628 + IQS7222_REG_KEY_NO_WHEEL,
17629 + IQS7222_REG_KEY_RESERVED
17630 +@@ -105,14 +107,14 @@ enum iqs7222_reg_grp_id {
17631 + IQS7222_NUM_REG_GRPS
17632 + };
17633 +
17634 +-static const char * const iqs7222_reg_grp_names[] = {
17635 ++static const char * const iqs7222_reg_grp_names[IQS7222_NUM_REG_GRPS] = {
17636 + [IQS7222_REG_GRP_CYCLE] = "cycle",
17637 + [IQS7222_REG_GRP_CHAN] = "channel",
17638 + [IQS7222_REG_GRP_SLDR] = "slider",
17639 + [IQS7222_REG_GRP_GPIO] = "gpio",
17640 + };
17641 +
17642 +-static const unsigned int iqs7222_max_cols[] = {
17643 ++static const unsigned int iqs7222_max_cols[IQS7222_NUM_REG_GRPS] = {
17644 + [IQS7222_REG_GRP_STAT] = IQS7222_MAX_COLS_STAT,
17645 + [IQS7222_REG_GRP_CYCLE] = IQS7222_MAX_COLS_CYCLE,
17646 + [IQS7222_REG_GRP_GLBL] = IQS7222_MAX_COLS_GLBL,
17647 +@@ -202,10 +204,68 @@ struct iqs7222_dev_desc {
17648 + int allow_offset;
17649 + int event_offset;
17650 + int comms_offset;
17651 ++ bool legacy_gesture;
17652 + struct iqs7222_reg_grp_desc reg_grps[IQS7222_NUM_REG_GRPS];
17653 + };
17654 +
17655 + static const struct iqs7222_dev_desc iqs7222_devs[] = {
17656 ++ {
17657 ++ .prod_num = IQS7222_PROD_NUM_A,
17658 ++ .fw_major = 1,
17659 ++ .fw_minor = 13,
17660 ++ .sldr_res = U8_MAX * 16,
17661 ++ .touch_link = 1768,
17662 ++ .allow_offset = 9,
17663 ++ .event_offset = 10,
17664 ++ .comms_offset = 12,
17665 ++ .reg_grps = {
17666 ++ [IQS7222_REG_GRP_STAT] = {
17667 ++ .base = IQS7222_SYS_STATUS,
17668 ++ .num_row = 1,
17669 ++ .num_col = 8,
17670 ++ },
17671 ++ [IQS7222_REG_GRP_CYCLE] = {
17672 ++ .base = 0x8000,
17673 ++ .num_row = 7,
17674 ++ .num_col = 3,
17675 ++ },
17676 ++ [IQS7222_REG_GRP_GLBL] = {
17677 ++ .base = 0x8700,
17678 ++ .num_row = 1,
17679 ++ .num_col = 3,
17680 ++ },
17681 ++ [IQS7222_REG_GRP_BTN] = {
17682 ++ .base = 0x9000,
17683 ++ .num_row = 12,
17684 ++ .num_col = 3,
17685 ++ },
17686 ++ [IQS7222_REG_GRP_CHAN] = {
17687 ++ .base = 0xA000,
17688 ++ .num_row = 12,
17689 ++ .num_col = 6,
17690 ++ },
17691 ++ [IQS7222_REG_GRP_FILT] = {
17692 ++ .base = 0xAC00,
17693 ++ .num_row = 1,
17694 ++ .num_col = 2,
17695 ++ },
17696 ++ [IQS7222_REG_GRP_SLDR] = {
17697 ++ .base = 0xB000,
17698 ++ .num_row = 2,
17699 ++ .num_col = 11,
17700 ++ },
17701 ++ [IQS7222_REG_GRP_GPIO] = {
17702 ++ .base = 0xC000,
17703 ++ .num_row = 1,
17704 ++ .num_col = 3,
17705 ++ },
17706 ++ [IQS7222_REG_GRP_SYS] = {
17707 ++ .base = IQS7222_SYS_SETUP,
17708 ++ .num_row = 1,
17709 ++ .num_col = 13,
17710 ++ },
17711 ++ },
17712 ++ },
17713 + {
17714 + .prod_num = IQS7222_PROD_NUM_A,
17715 + .fw_major = 1,
17716 +@@ -215,6 +275,7 @@ static const struct iqs7222_dev_desc iqs7222_devs[] = {
17717 + .allow_offset = 9,
17718 + .event_offset = 10,
17719 + .comms_offset = 12,
17720 ++ .legacy_gesture = true,
17721 + .reg_grps = {
17722 + [IQS7222_REG_GRP_STAT] = {
17723 + .base = IQS7222_SYS_STATUS,
17724 +@@ -874,6 +935,16 @@ static const struct iqs7222_prop_desc iqs7222_props[] = {
17725 + .reg_offset = 9,
17726 + .reg_shift = 8,
17727 + .reg_width = 8,
17728 ++ .val_pitch = 16,
17729 ++ .label = "maximum gesture time",
17730 ++ },
17731 ++ {
17732 ++ .name = "azoteq,gesture-max-ms",
17733 ++ .reg_grp = IQS7222_REG_GRP_SLDR,
17734 ++ .reg_key = IQS7222_REG_KEY_TAP_LEGACY,
17735 ++ .reg_offset = 9,
17736 ++ .reg_shift = 8,
17737 ++ .reg_width = 8,
17738 + .val_pitch = 4,
17739 + .label = "maximum gesture time",
17740 + },
17741 +@@ -884,6 +955,16 @@ static const struct iqs7222_prop_desc iqs7222_props[] = {
17742 + .reg_offset = 9,
17743 + .reg_shift = 3,
17744 + .reg_width = 5,
17745 ++ .val_pitch = 16,
17746 ++ .label = "minimum gesture time",
17747 ++ },
17748 ++ {
17749 ++ .name = "azoteq,gesture-min-ms",
17750 ++ .reg_grp = IQS7222_REG_GRP_SLDR,
17751 ++ .reg_key = IQS7222_REG_KEY_TAP_LEGACY,
17752 ++ .reg_offset = 9,
17753 ++ .reg_shift = 3,
17754 ++ .reg_width = 5,
17755 + .val_pitch = 4,
17756 + .label = "minimum gesture time",
17757 + },
17758 +@@ -897,6 +978,16 @@ static const struct iqs7222_prop_desc iqs7222_props[] = {
17759 + .val_pitch = 16,
17760 + .label = "gesture distance",
17761 + },
17762 ++ {
17763 ++ .name = "azoteq,gesture-dist",
17764 ++ .reg_grp = IQS7222_REG_GRP_SLDR,
17765 ++ .reg_key = IQS7222_REG_KEY_AXIAL_LEGACY,
17766 ++ .reg_offset = 10,
17767 ++ .reg_shift = 8,
17768 ++ .reg_width = 8,
17769 ++ .val_pitch = 16,
17770 ++ .label = "gesture distance",
17771 ++ },
17772 + {
17773 + .name = "azoteq,gesture-max-ms",
17774 + .reg_grp = IQS7222_REG_GRP_SLDR,
17775 +@@ -904,6 +995,16 @@ static const struct iqs7222_prop_desc iqs7222_props[] = {
17776 + .reg_offset = 10,
17777 + .reg_shift = 0,
17778 + .reg_width = 8,
17779 ++ .val_pitch = 16,
17780 ++ .label = "maximum gesture time",
17781 ++ },
17782 ++ {
17783 ++ .name = "azoteq,gesture-max-ms",
17784 ++ .reg_grp = IQS7222_REG_GRP_SLDR,
17785 ++ .reg_key = IQS7222_REG_KEY_AXIAL_LEGACY,
17786 ++ .reg_offset = 10,
17787 ++ .reg_shift = 0,
17788 ++ .reg_width = 8,
17789 + .val_pitch = 4,
17790 + .label = "maximum gesture time",
17791 + },
17792 +@@ -1077,7 +1178,7 @@ static int iqs7222_hard_reset(struct iqs7222_private *iqs7222)
17793 +
17794 + static int iqs7222_force_comms(struct iqs7222_private *iqs7222)
17795 + {
17796 +- u8 msg_buf[] = { 0xFF, 0x00, };
17797 ++ u8 msg_buf[] = { 0xFF, };
17798 + int ret;
17799 +
17800 + /*
17801 +@@ -1567,56 +1668,17 @@ static int iqs7222_gpio_select(struct iqs7222_private *iqs7222,
17802 + }
17803 +
17804 + static int iqs7222_parse_props(struct iqs7222_private *iqs7222,
17805 +- struct fwnode_handle **child_node,
17806 +- int child_index,
17807 ++ struct fwnode_handle *reg_grp_node,
17808 ++ int reg_grp_index,
17809 + enum iqs7222_reg_grp_id reg_grp,
17810 + enum iqs7222_reg_key_id reg_key)
17811 + {
17812 +- u16 *setup = iqs7222_setup(iqs7222, reg_grp, child_index);
17813 ++ u16 *setup = iqs7222_setup(iqs7222, reg_grp, reg_grp_index);
17814 + struct i2c_client *client = iqs7222->client;
17815 +- struct fwnode_handle *reg_grp_node;
17816 +- char reg_grp_name[16];
17817 + int i;
17818 +
17819 +- switch (reg_grp) {
17820 +- case IQS7222_REG_GRP_CYCLE:
17821 +- case IQS7222_REG_GRP_CHAN:
17822 +- case IQS7222_REG_GRP_SLDR:
17823 +- case IQS7222_REG_GRP_GPIO:
17824 +- case IQS7222_REG_GRP_BTN:
17825 +- /*
17826 +- * These groups derive a child node and return it to the caller
17827 +- * for additional group-specific processing. In some cases, the
17828 +- * child node may have already been derived.
17829 +- */
17830 +- reg_grp_node = *child_node;
17831 +- if (reg_grp_node)
17832 +- break;
17833 +-
17834 +- snprintf(reg_grp_name, sizeof(reg_grp_name), "%s-%d",
17835 +- iqs7222_reg_grp_names[reg_grp], child_index);
17836 +-
17837 +- reg_grp_node = device_get_named_child_node(&client->dev,
17838 +- reg_grp_name);
17839 +- if (!reg_grp_node)
17840 +- return 0;
17841 +-
17842 +- *child_node = reg_grp_node;
17843 +- break;
17844 +-
17845 +- case IQS7222_REG_GRP_GLBL:
17846 +- case IQS7222_REG_GRP_FILT:
17847 +- case IQS7222_REG_GRP_SYS:
17848 +- /*
17849 +- * These groups are not organized beneath a child node, nor are
17850 +- * they subject to any additional processing by the caller.
17851 +- */
17852 +- reg_grp_node = dev_fwnode(&client->dev);
17853 +- break;
17854 +-
17855 +- default:
17856 +- return -EINVAL;
17857 +- }
17858 ++ if (!setup)
17859 ++ return 0;
17860 +
17861 + for (i = 0; i < ARRAY_SIZE(iqs7222_props); i++) {
17862 + const char *name = iqs7222_props[i].name;
17863 +@@ -1686,11 +1748,66 @@ static int iqs7222_parse_props(struct iqs7222_private *iqs7222,
17864 + return 0;
17865 + }
17866 +
17867 +-static int iqs7222_parse_cycle(struct iqs7222_private *iqs7222, int cycle_index)
17868 ++static int iqs7222_parse_event(struct iqs7222_private *iqs7222,
17869 ++ struct fwnode_handle *event_node,
17870 ++ int reg_grp_index,
17871 ++ enum iqs7222_reg_grp_id reg_grp,
17872 ++ enum iqs7222_reg_key_id reg_key,
17873 ++ u16 event_enable, u16 event_link,
17874 ++ unsigned int *event_type,
17875 ++ unsigned int *event_code)
17876 ++{
17877 ++ struct i2c_client *client = iqs7222->client;
17878 ++ int error;
17879 ++
17880 ++ error = iqs7222_parse_props(iqs7222, event_node, reg_grp_index,
17881 ++ reg_grp, reg_key);
17882 ++ if (error)
17883 ++ return error;
17884 ++
17885 ++ error = iqs7222_gpio_select(iqs7222, event_node, event_enable,
17886 ++ event_link);
17887 ++ if (error)
17888 ++ return error;
17889 ++
17890 ++ error = fwnode_property_read_u32(event_node, "linux,code", event_code);
17891 ++ if (error == -EINVAL) {
17892 ++ return 0;
17893 ++ } else if (error) {
17894 ++ dev_err(&client->dev, "Failed to read %s code: %d\n",
17895 ++ fwnode_get_name(event_node), error);
17896 ++ return error;
17897 ++ }
17898 ++
17899 ++ if (!event_type) {
17900 ++ input_set_capability(iqs7222->keypad, EV_KEY, *event_code);
17901 ++ return 0;
17902 ++ }
17903 ++
17904 ++ error = fwnode_property_read_u32(event_node, "linux,input-type",
17905 ++ event_type);
17906 ++ if (error == -EINVAL) {
17907 ++ *event_type = EV_KEY;
17908 ++ } else if (error) {
17909 ++ dev_err(&client->dev, "Failed to read %s input type: %d\n",
17910 ++ fwnode_get_name(event_node), error);
17911 ++ return error;
17912 ++ } else if (*event_type != EV_KEY && *event_type != EV_SW) {
17913 ++ dev_err(&client->dev, "Invalid %s input type: %d\n",
17914 ++ fwnode_get_name(event_node), *event_type);
17915 ++ return -EINVAL;
17916 ++ }
17917 ++
17918 ++ input_set_capability(iqs7222->keypad, *event_type, *event_code);
17919 ++
17920 ++ return 0;
17921 ++}
17922 ++
17923 ++static int iqs7222_parse_cycle(struct iqs7222_private *iqs7222,
17924 ++ struct fwnode_handle *cycle_node, int cycle_index)
17925 + {
17926 + u16 *cycle_setup = iqs7222->cycle_setup[cycle_index];
17927 + struct i2c_client *client = iqs7222->client;
17928 +- struct fwnode_handle *cycle_node = NULL;
17929 + unsigned int pins[9];
17930 + int error, count, i;
17931 +
17932 +@@ -1698,17 +1815,7 @@ static int iqs7222_parse_cycle(struct iqs7222_private *iqs7222, int cycle_index)
17933 + * Each channel shares a cycle with one other channel; the mapping of
17934 + * channels to cycles is fixed. Properties defined for a cycle impact
17935 + * both channels tied to the cycle.
17936 +- */
17937 +- error = iqs7222_parse_props(iqs7222, &cycle_node, cycle_index,
17938 +- IQS7222_REG_GRP_CYCLE,
17939 +- IQS7222_REG_KEY_NONE);
17940 +- if (error)
17941 +- return error;
17942 +-
17943 +- if (!cycle_node)
17944 +- return 0;
17945 +-
17946 +- /*
17947 ++ *
17948 + * Unlike channels which are restricted to a select range of CRx pins
17949 + * based on channel number, any cycle can claim any of the device's 9
17950 + * CTx pins (CTx0-8).
17951 +@@ -1750,11 +1857,11 @@ static int iqs7222_parse_cycle(struct iqs7222_private *iqs7222, int cycle_index)
17952 + return 0;
17953 + }
17954 +
17955 +-static int iqs7222_parse_chan(struct iqs7222_private *iqs7222, int chan_index)
17956 ++static int iqs7222_parse_chan(struct iqs7222_private *iqs7222,
17957 ++ struct fwnode_handle *chan_node, int chan_index)
17958 + {
17959 + const struct iqs7222_dev_desc *dev_desc = iqs7222->dev_desc;
17960 + struct i2c_client *client = iqs7222->client;
17961 +- struct fwnode_handle *chan_node = NULL;
17962 + int num_chan = dev_desc->reg_grps[IQS7222_REG_GRP_CHAN].num_row;
17963 + int ext_chan = rounddown(num_chan, 10);
17964 + int error, i;
17965 +@@ -1762,20 +1869,9 @@ static int iqs7222_parse_chan(struct iqs7222_private *iqs7222, int chan_index)
17966 + u16 *sys_setup = iqs7222->sys_setup;
17967 + unsigned int val;
17968 +
17969 +- error = iqs7222_parse_props(iqs7222, &chan_node, chan_index,
17970 +- IQS7222_REG_GRP_CHAN,
17971 +- IQS7222_REG_KEY_NONE);
17972 +- if (error)
17973 +- return error;
17974 +-
17975 +- if (!chan_node)
17976 +- return 0;
17977 +-
17978 +- if (dev_desc->allow_offset) {
17979 +- sys_setup[dev_desc->allow_offset] |= BIT(chan_index);
17980 +- if (fwnode_property_present(chan_node, "azoteq,ulp-allow"))
17981 +- sys_setup[dev_desc->allow_offset] &= ~BIT(chan_index);
17982 +- }
17983 ++ if (dev_desc->allow_offset &&
17984 ++ fwnode_property_present(chan_node, "azoteq,ulp-allow"))
17985 ++ sys_setup[dev_desc->allow_offset] &= ~BIT(chan_index);
17986 +
17987 + chan_setup[0] |= IQS7222_CHAN_SETUP_0_CHAN_EN;
17988 +
17989 +@@ -1812,8 +1908,9 @@ static int iqs7222_parse_chan(struct iqs7222_private *iqs7222, int chan_index)
17990 + chan_setup[0] |= IQS7222_CHAN_SETUP_0_REF_MODE_FOLLOW;
17991 + chan_setup[4] = val * 42 + 1048;
17992 +
17993 +- if (!fwnode_property_read_u32(chan_node, "azoteq,ref-weight",
17994 +- &val)) {
17995 ++ error = fwnode_property_read_u32(chan_node, "azoteq,ref-weight",
17996 ++ &val);
17997 ++ if (!error) {
17998 + if (val > U16_MAX) {
17999 + dev_err(&client->dev,
18000 + "Invalid %s reference weight: %u\n",
18001 +@@ -1822,6 +1919,11 @@ static int iqs7222_parse_chan(struct iqs7222_private *iqs7222, int chan_index)
18002 + }
18003 +
18004 + chan_setup[5] = val;
18005 ++ } else if (error != -EINVAL) {
18006 ++ dev_err(&client->dev,
18007 ++ "Failed to read %s reference weight: %d\n",
18008 ++ fwnode_get_name(chan_node), error);
18009 ++ return error;
18010 + }
18011 +
18012 + /*
18013 +@@ -1894,21 +1996,10 @@ static int iqs7222_parse_chan(struct iqs7222_private *iqs7222, int chan_index)
18014 + if (!event_node)
18015 + continue;
18016 +
18017 +- error = iqs7222_parse_props(iqs7222, &event_node, chan_index,
18018 +- IQS7222_REG_GRP_BTN,
18019 +- iqs7222_kp_events[i].reg_key);
18020 +- if (error)
18021 +- return error;
18022 +-
18023 +- error = iqs7222_gpio_select(iqs7222, event_node,
18024 +- BIT(chan_index),
18025 +- dev_desc->touch_link - (i ? 0 : 2));
18026 +- if (error)
18027 +- return error;
18028 +-
18029 +- if (!fwnode_property_read_u32(event_node,
18030 +- "azoteq,timeout-press-ms",
18031 +- &val)) {
18032 ++ error = fwnode_property_read_u32(event_node,
18033 ++ "azoteq,timeout-press-ms",
18034 ++ &val);
18035 ++ if (!error) {
18036 + /*
18037 + * The IQS7222B employs a global pair of press timeout
18038 + * registers as opposed to channel-specific registers.
18039 +@@ -1921,57 +2012,31 @@ static int iqs7222_parse_chan(struct iqs7222_private *iqs7222, int chan_index)
18040 + if (val > U8_MAX * 500) {
18041 + dev_err(&client->dev,
18042 + "Invalid %s press timeout: %u\n",
18043 +- fwnode_get_name(chan_node), val);
18044 ++ fwnode_get_name(event_node), val);
18045 ++ fwnode_handle_put(event_node);
18046 + return -EINVAL;
18047 + }
18048 +
18049 + *setup &= ~(U8_MAX << i * 8);
18050 + *setup |= (val / 500 << i * 8);
18051 +- }
18052 +-
18053 +- error = fwnode_property_read_u32(event_node, "linux,code",
18054 +- &val);
18055 +- if (error) {
18056 +- dev_err(&client->dev, "Failed to read %s code: %d\n",
18057 +- fwnode_get_name(chan_node), error);
18058 ++ } else if (error != -EINVAL) {
18059 ++ dev_err(&client->dev,
18060 ++ "Failed to read %s press timeout: %d\n",
18061 ++ fwnode_get_name(event_node), error);
18062 ++ fwnode_handle_put(event_node);
18063 + return error;
18064 + }
18065 +
18066 +- iqs7222->kp_code[chan_index][i] = val;
18067 +- iqs7222->kp_type[chan_index][i] = EV_KEY;
18068 +-
18069 +- if (fwnode_property_present(event_node, "linux,input-type")) {
18070 +- error = fwnode_property_read_u32(event_node,
18071 +- "linux,input-type",
18072 +- &val);
18073 +- if (error) {
18074 +- dev_err(&client->dev,
18075 +- "Failed to read %s input type: %d\n",
18076 +- fwnode_get_name(chan_node), error);
18077 +- return error;
18078 +- }
18079 +-
18080 +- if (val != EV_KEY && val != EV_SW) {
18081 +- dev_err(&client->dev,
18082 +- "Invalid %s input type: %u\n",
18083 +- fwnode_get_name(chan_node), val);
18084 +- return -EINVAL;
18085 +- }
18086 +-
18087 +- iqs7222->kp_type[chan_index][i] = val;
18088 +- }
18089 +-
18090 +- /*
18091 +- * Reference channels can opt out of event reporting by using
18092 +- * KEY_RESERVED in place of a true key or switch code.
18093 +- */
18094 +- if (iqs7222->kp_type[chan_index][i] == EV_KEY &&
18095 +- iqs7222->kp_code[chan_index][i] == KEY_RESERVED)
18096 +- continue;
18097 +-
18098 +- input_set_capability(iqs7222->keypad,
18099 +- iqs7222->kp_type[chan_index][i],
18100 +- iqs7222->kp_code[chan_index][i]);
18101 ++ error = iqs7222_parse_event(iqs7222, event_node, chan_index,
18102 ++ IQS7222_REG_GRP_BTN,
18103 ++ iqs7222_kp_events[i].reg_key,
18104 ++ BIT(chan_index),
18105 ++ dev_desc->touch_link - (i ? 0 : 2),
18106 ++ &iqs7222->kp_type[chan_index][i],
18107 ++ &iqs7222->kp_code[chan_index][i]);
18108 ++ fwnode_handle_put(event_node);
18109 ++ if (error)
18110 ++ return error;
18111 +
18112 + if (!dev_desc->event_offset)
18113 + continue;
18114 +@@ -1983,16 +2048,16 @@ static int iqs7222_parse_chan(struct iqs7222_private *iqs7222, int chan_index)
18115 + * The following call handles a special pair of properties that apply
18116 + * to a channel node, but reside within the button (event) group.
18117 + */
18118 +- return iqs7222_parse_props(iqs7222, &chan_node, chan_index,
18119 ++ return iqs7222_parse_props(iqs7222, chan_node, chan_index,
18120 + IQS7222_REG_GRP_BTN,
18121 + IQS7222_REG_KEY_DEBOUNCE);
18122 + }
18123 +
18124 +-static int iqs7222_parse_sldr(struct iqs7222_private *iqs7222, int sldr_index)
18125 ++static int iqs7222_parse_sldr(struct iqs7222_private *iqs7222,
18126 ++ struct fwnode_handle *sldr_node, int sldr_index)
18127 + {
18128 + const struct iqs7222_dev_desc *dev_desc = iqs7222->dev_desc;
18129 + struct i2c_client *client = iqs7222->client;
18130 +- struct fwnode_handle *sldr_node = NULL;
18131 + int num_chan = dev_desc->reg_grps[IQS7222_REG_GRP_CHAN].num_row;
18132 + int ext_chan = rounddown(num_chan, 10);
18133 + int count, error, reg_offset, i;
18134 +@@ -2000,15 +2065,6 @@ static int iqs7222_parse_sldr(struct iqs7222_private *iqs7222, int sldr_index)
18135 + u16 *sldr_setup = iqs7222->sldr_setup[sldr_index];
18136 + unsigned int chan_sel[4], val;
18137 +
18138 +- error = iqs7222_parse_props(iqs7222, &sldr_node, sldr_index,
18139 +- IQS7222_REG_GRP_SLDR,
18140 +- IQS7222_REG_KEY_NONE);
18141 +- if (error)
18142 +- return error;
18143 +-
18144 +- if (!sldr_node)
18145 +- return 0;
18146 +-
18147 + /*
18148 + * Each slider can be spread across 3 to 4 channels. It is possible to
18149 + * select only 2 channels, but doing so prevents the slider from using
18150 +@@ -2067,8 +2123,9 @@ static int iqs7222_parse_sldr(struct iqs7222_private *iqs7222, int sldr_index)
18151 + if (fwnode_property_present(sldr_node, "azoteq,use-prox"))
18152 + sldr_setup[4 + reg_offset] -= 2;
18153 +
18154 +- if (!fwnode_property_read_u32(sldr_node, "azoteq,slider-size", &val)) {
18155 +- if (!val || val > dev_desc->sldr_res) {
18156 ++ error = fwnode_property_read_u32(sldr_node, "azoteq,slider-size", &val);
18157 ++ if (!error) {
18158 ++ if (val > dev_desc->sldr_res) {
18159 + dev_err(&client->dev, "Invalid %s size: %u\n",
18160 + fwnode_get_name(sldr_node), val);
18161 + return -EINVAL;
18162 +@@ -2081,9 +2138,21 @@ static int iqs7222_parse_sldr(struct iqs7222_private *iqs7222, int sldr_index)
18163 + sldr_setup[2] |= (val / 16 <<
18164 + IQS7222_SLDR_SETUP_2_RES_SHIFT);
18165 + }
18166 ++ } else if (error != -EINVAL) {
18167 ++ dev_err(&client->dev, "Failed to read %s size: %d\n",
18168 ++ fwnode_get_name(sldr_node), error);
18169 ++ return error;
18170 ++ }
18171 ++
18172 ++ if (!(reg_offset ? sldr_setup[3]
18173 ++ : sldr_setup[2] & IQS7222_SLDR_SETUP_2_RES_MASK)) {
18174 ++ dev_err(&client->dev, "Undefined %s size\n",
18175 ++ fwnode_get_name(sldr_node));
18176 ++ return -EINVAL;
18177 + }
18178 +
18179 +- if (!fwnode_property_read_u32(sldr_node, "azoteq,top-speed", &val)) {
18180 ++ error = fwnode_property_read_u32(sldr_node, "azoteq,top-speed", &val);
18181 ++ if (!error) {
18182 + if (val > (reg_offset ? U16_MAX : U8_MAX * 4)) {
18183 + dev_err(&client->dev, "Invalid %s top speed: %u\n",
18184 + fwnode_get_name(sldr_node), val);
18185 +@@ -2096,9 +2165,14 @@ static int iqs7222_parse_sldr(struct iqs7222_private *iqs7222, int sldr_index)
18186 + sldr_setup[2] &= ~IQS7222_SLDR_SETUP_2_TOP_SPEED_MASK;
18187 + sldr_setup[2] |= (val / 4);
18188 + }
18189 ++ } else if (error != -EINVAL) {
18190 ++ dev_err(&client->dev, "Failed to read %s top speed: %d\n",
18191 ++ fwnode_get_name(sldr_node), error);
18192 ++ return error;
18193 + }
18194 +
18195 +- if (!fwnode_property_read_u32(sldr_node, "linux,axis", &val)) {
18196 ++ error = fwnode_property_read_u32(sldr_node, "linux,axis", &val);
18197 ++ if (!error) {
18198 + u16 sldr_max = sldr_setup[3] - 1;
18199 +
18200 + if (!reg_offset) {
18201 +@@ -2112,6 +2186,10 @@ static int iqs7222_parse_sldr(struct iqs7222_private *iqs7222, int sldr_index)
18202 +
18203 + input_set_abs_params(iqs7222->keypad, val, 0, sldr_max, 0, 0);
18204 + iqs7222->sl_axis[sldr_index] = val;
18205 ++ } else if (error != -EINVAL) {
18206 ++ dev_err(&client->dev, "Failed to read %s axis: %d\n",
18207 ++ fwnode_get_name(sldr_node), error);
18208 ++ return error;
18209 + }
18210 +
18211 + if (dev_desc->wheel_enable) {
18212 +@@ -2132,46 +2210,47 @@ static int iqs7222_parse_sldr(struct iqs7222_private *iqs7222, int sldr_index)
18213 + for (i = 0; i < ARRAY_SIZE(iqs7222_sl_events); i++) {
18214 + const char *event_name = iqs7222_sl_events[i].name;
18215 + struct fwnode_handle *event_node;
18216 ++ enum iqs7222_reg_key_id reg_key;
18217 +
18218 + event_node = fwnode_get_named_child_node(sldr_node, event_name);
18219 + if (!event_node)
18220 + continue;
18221 +
18222 +- error = iqs7222_parse_props(iqs7222, &event_node, sldr_index,
18223 +- IQS7222_REG_GRP_SLDR,
18224 +- reg_offset ?
18225 +- IQS7222_REG_KEY_RESERVED :
18226 +- iqs7222_sl_events[i].reg_key);
18227 +- if (error)
18228 +- return error;
18229 ++ /*
18230 ++ * Depending on the device, gestures are either offered using
18231 ++ * one of two timing resolutions, or are not supported at all.
18232 ++ */
18233 ++ if (reg_offset)
18234 ++ reg_key = IQS7222_REG_KEY_RESERVED;
18235 ++ else if (dev_desc->legacy_gesture &&
18236 ++ iqs7222_sl_events[i].reg_key == IQS7222_REG_KEY_TAP)
18237 ++ reg_key = IQS7222_REG_KEY_TAP_LEGACY;
18238 ++ else if (dev_desc->legacy_gesture &&
18239 ++ iqs7222_sl_events[i].reg_key == IQS7222_REG_KEY_AXIAL)
18240 ++ reg_key = IQS7222_REG_KEY_AXIAL_LEGACY;
18241 ++ else
18242 ++ reg_key = iqs7222_sl_events[i].reg_key;
18243 +
18244 + /*
18245 + * The press/release event does not expose a direct GPIO link,
18246 + * but one can be emulated by tying each of the participating
18247 + * channels to the same GPIO.
18248 + */
18249 +- error = iqs7222_gpio_select(iqs7222, event_node,
18250 ++ error = iqs7222_parse_event(iqs7222, event_node, sldr_index,
18251 ++ IQS7222_REG_GRP_SLDR, reg_key,
18252 + i ? iqs7222_sl_events[i].enable
18253 + : sldr_setup[3 + reg_offset],
18254 + i ? 1568 + sldr_index * 30
18255 +- : sldr_setup[4 + reg_offset]);
18256 ++ : sldr_setup[4 + reg_offset],
18257 ++ NULL,
18258 ++ &iqs7222->sl_code[sldr_index][i]);
18259 ++ fwnode_handle_put(event_node);
18260 + if (error)
18261 + return error;
18262 +
18263 + if (!reg_offset)
18264 + sldr_setup[9] |= iqs7222_sl_events[i].enable;
18265 +
18266 +- error = fwnode_property_read_u32(event_node, "linux,code",
18267 +- &val);
18268 +- if (error) {
18269 +- dev_err(&client->dev, "Failed to read %s code: %d\n",
18270 +- fwnode_get_name(sldr_node), error);
18271 +- return error;
18272 +- }
18273 +-
18274 +- iqs7222->sl_code[sldr_index][i] = val;
18275 +- input_set_capability(iqs7222->keypad, EV_KEY, val);
18276 +-
18277 + if (!dev_desc->event_offset)
18278 + continue;
18279 +
18280 +@@ -2192,49 +2271,77 @@ static int iqs7222_parse_sldr(struct iqs7222_private *iqs7222, int sldr_index)
18281 + * The following call handles a special pair of properties that shift
18282 + * to make room for a wheel enable control in the case of IQS7222C.
18283 + */
18284 +- return iqs7222_parse_props(iqs7222, &sldr_node, sldr_index,
18285 ++ return iqs7222_parse_props(iqs7222, sldr_node, sldr_index,
18286 + IQS7222_REG_GRP_SLDR,
18287 + dev_desc->wheel_enable ?
18288 + IQS7222_REG_KEY_WHEEL :
18289 + IQS7222_REG_KEY_NO_WHEEL);
18290 + }
18291 +
18292 ++static int (*iqs7222_parse_extra[IQS7222_NUM_REG_GRPS])
18293 ++ (struct iqs7222_private *iqs7222,
18294 ++ struct fwnode_handle *reg_grp_node,
18295 ++ int reg_grp_index) = {
18296 ++ [IQS7222_REG_GRP_CYCLE] = iqs7222_parse_cycle,
18297 ++ [IQS7222_REG_GRP_CHAN] = iqs7222_parse_chan,
18298 ++ [IQS7222_REG_GRP_SLDR] = iqs7222_parse_sldr,
18299 ++};
18300 ++
18301 ++static int iqs7222_parse_reg_grp(struct iqs7222_private *iqs7222,
18302 ++ enum iqs7222_reg_grp_id reg_grp,
18303 ++ int reg_grp_index)
18304 ++{
18305 ++ struct i2c_client *client = iqs7222->client;
18306 ++ struct fwnode_handle *reg_grp_node;
18307 ++ int error;
18308 ++
18309 ++ if (iqs7222_reg_grp_names[reg_grp]) {
18310 ++ char reg_grp_name[16];
18311 ++
18312 ++ snprintf(reg_grp_name, sizeof(reg_grp_name), "%s-%d",
18313 ++ iqs7222_reg_grp_names[reg_grp], reg_grp_index);
18314 ++
18315 ++ reg_grp_node = device_get_named_child_node(&client->dev,
18316 ++ reg_grp_name);
18317 ++ } else {
18318 ++ reg_grp_node = fwnode_handle_get(dev_fwnode(&client->dev));
18319 ++ }
18320 ++
18321 ++ if (!reg_grp_node)
18322 ++ return 0;
18323 ++
18324 ++ error = iqs7222_parse_props(iqs7222, reg_grp_node, reg_grp_index,
18325 ++ reg_grp, IQS7222_REG_KEY_NONE);
18326 ++
18327 ++ if (!error && iqs7222_parse_extra[reg_grp])
18328 ++ error = iqs7222_parse_extra[reg_grp](iqs7222, reg_grp_node,
18329 ++ reg_grp_index);
18330 ++
18331 ++ fwnode_handle_put(reg_grp_node);
18332 ++
18333 ++ return error;
18334 ++}
18335 ++
18336 + static int iqs7222_parse_all(struct iqs7222_private *iqs7222)
18337 + {
18338 + const struct iqs7222_dev_desc *dev_desc = iqs7222->dev_desc;
18339 + const struct iqs7222_reg_grp_desc *reg_grps = dev_desc->reg_grps;
18340 + u16 *sys_setup = iqs7222->sys_setup;
18341 +- int error, i;
18342 ++ int error, i, j;
18343 ++
18344 ++ if (dev_desc->allow_offset)
18345 ++ sys_setup[dev_desc->allow_offset] = U16_MAX;
18346 +
18347 + if (dev_desc->event_offset)
18348 + sys_setup[dev_desc->event_offset] = IQS7222_EVENT_MASK_ATI;
18349 +
18350 +- for (i = 0; i < reg_grps[IQS7222_REG_GRP_CYCLE].num_row; i++) {
18351 +- error = iqs7222_parse_cycle(iqs7222, i);
18352 +- if (error)
18353 +- return error;
18354 +- }
18355 +-
18356 +- error = iqs7222_parse_props(iqs7222, NULL, 0, IQS7222_REG_GRP_GLBL,
18357 +- IQS7222_REG_KEY_NONE);
18358 +- if (error)
18359 +- return error;
18360 +-
18361 + for (i = 0; i < reg_grps[IQS7222_REG_GRP_GPIO].num_row; i++) {
18362 +- struct fwnode_handle *gpio_node = NULL;
18363 + u16 *gpio_setup = iqs7222->gpio_setup[i];
18364 +- int j;
18365 +
18366 + gpio_setup[0] &= ~IQS7222_GPIO_SETUP_0_GPIO_EN;
18367 + gpio_setup[1] = 0;
18368 + gpio_setup[2] = 0;
18369 +
18370 +- error = iqs7222_parse_props(iqs7222, &gpio_node, i,
18371 +- IQS7222_REG_GRP_GPIO,
18372 +- IQS7222_REG_KEY_NONE);
18373 +- if (error)
18374 +- return error;
18375 +-
18376 + if (reg_grps[IQS7222_REG_GRP_GPIO].num_row == 1)
18377 + continue;
18378 +
18379 +@@ -2257,29 +2364,21 @@ static int iqs7222_parse_all(struct iqs7222_private *iqs7222)
18380 + chan_setup[5] = 0;
18381 + }
18382 +
18383 +- for (i = 0; i < reg_grps[IQS7222_REG_GRP_CHAN].num_row; i++) {
18384 +- error = iqs7222_parse_chan(iqs7222, i);
18385 +- if (error)
18386 +- return error;
18387 +- }
18388 +-
18389 +- error = iqs7222_parse_props(iqs7222, NULL, 0, IQS7222_REG_GRP_FILT,
18390 +- IQS7222_REG_KEY_NONE);
18391 +- if (error)
18392 +- return error;
18393 +-
18394 + for (i = 0; i < reg_grps[IQS7222_REG_GRP_SLDR].num_row; i++) {
18395 + u16 *sldr_setup = iqs7222->sldr_setup[i];
18396 +
18397 + sldr_setup[0] &= ~IQS7222_SLDR_SETUP_0_CHAN_CNT_MASK;
18398 ++ }
18399 +
18400 +- error = iqs7222_parse_sldr(iqs7222, i);
18401 +- if (error)
18402 +- return error;
18403 ++ for (i = 0; i < IQS7222_NUM_REG_GRPS; i++) {
18404 ++ for (j = 0; j < reg_grps[i].num_row; j++) {
18405 ++ error = iqs7222_parse_reg_grp(iqs7222, i, j);
18406 ++ if (error)
18407 ++ return error;
18408 ++ }
18409 + }
18410 +
18411 +- return iqs7222_parse_props(iqs7222, NULL, 0, IQS7222_REG_GRP_SYS,
18412 +- IQS7222_REG_KEY_NONE);
18413 ++ return 0;
18414 + }
18415 +
18416 + static int iqs7222_report(struct iqs7222_private *iqs7222)
18417 +@@ -2326,6 +2425,9 @@ static int iqs7222_report(struct iqs7222_private *iqs7222)
18418 + int k = 2 + j * (num_chan > 16 ? 2 : 1);
18419 + u16 state = le16_to_cpu(status[k + i / 16]);
18420 +
18421 ++ if (!iqs7222->kp_type[i][j])
18422 ++ continue;
18423 ++
18424 + input_event(iqs7222->keypad,
18425 + iqs7222->kp_type[i][j],
18426 + iqs7222->kp_code[i][j],
18427 +diff --git a/drivers/input/touchscreen/elants_i2c.c b/drivers/input/touchscreen/elants_i2c.c
18428 +index 879a4d984c907..e1308e179dd6f 100644
18429 +--- a/drivers/input/touchscreen/elants_i2c.c
18430 ++++ b/drivers/input/touchscreen/elants_i2c.c
18431 +@@ -1329,14 +1329,12 @@ static int elants_i2c_power_on(struct elants_data *ts)
18432 + if (IS_ERR_OR_NULL(ts->reset_gpio))
18433 + return 0;
18434 +
18435 +- gpiod_set_value_cansleep(ts->reset_gpio, 1);
18436 +-
18437 + error = regulator_enable(ts->vcc33);
18438 + if (error) {
18439 + dev_err(&ts->client->dev,
18440 + "failed to enable vcc33 regulator: %d\n",
18441 + error);
18442 +- goto release_reset_gpio;
18443 ++ return error;
18444 + }
18445 +
18446 + error = regulator_enable(ts->vccio);
18447 +@@ -1345,7 +1343,7 @@ static int elants_i2c_power_on(struct elants_data *ts)
18448 + "failed to enable vccio regulator: %d\n",
18449 + error);
18450 + regulator_disable(ts->vcc33);
18451 +- goto release_reset_gpio;
18452 ++ return error;
18453 + }
18454 +
18455 + /*
18456 +@@ -1354,7 +1352,6 @@ static int elants_i2c_power_on(struct elants_data *ts)
18457 + */
18458 + udelay(ELAN_POWERON_DELAY_USEC);
18459 +
18460 +-release_reset_gpio:
18461 + gpiod_set_value_cansleep(ts->reset_gpio, 0);
18462 + if (error)
18463 + return error;
18464 +@@ -1462,7 +1459,7 @@ static int elants_i2c_probe(struct i2c_client *client)
18465 + return error;
18466 + }
18467 +
18468 +- ts->reset_gpio = devm_gpiod_get(&client->dev, "reset", GPIOD_OUT_LOW);
18469 ++ ts->reset_gpio = devm_gpiod_get(&client->dev, "reset", GPIOD_OUT_HIGH);
18470 + if (IS_ERR(ts->reset_gpio)) {
18471 + error = PTR_ERR(ts->reset_gpio);
18472 +
18473 +diff --git a/drivers/interconnect/qcom/sc7180.c b/drivers/interconnect/qcom/sc7180.c
18474 +index 35cd448efdfbe..82d5e8a8c19ea 100644
18475 +--- a/drivers/interconnect/qcom/sc7180.c
18476 ++++ b/drivers/interconnect/qcom/sc7180.c
18477 +@@ -369,7 +369,7 @@ static const struct qcom_icc_desc sc7180_gem_noc = {
18478 + .num_bcms = ARRAY_SIZE(gem_noc_bcms),
18479 + };
18480 +
18481 +-static struct qcom_icc_bcm *mc_virt_bcms[] = {
18482 ++static struct qcom_icc_bcm * const mc_virt_bcms[] = {
18483 + &bcm_acv,
18484 + &bcm_mc0,
18485 + };
18486 +diff --git a/drivers/iommu/amd/iommu_v2.c b/drivers/iommu/amd/iommu_v2.c
18487 +index 6a1f02c62dffc..9f7fab49a5a90 100644
18488 +--- a/drivers/iommu/amd/iommu_v2.c
18489 ++++ b/drivers/iommu/amd/iommu_v2.c
18490 +@@ -587,6 +587,7 @@ out_drop_state:
18491 + put_device_state(dev_state);
18492 +
18493 + out:
18494 ++ pci_dev_put(pdev);
18495 + return ret;
18496 + }
18497 +
18498 +diff --git a/drivers/iommu/fsl_pamu.c b/drivers/iommu/fsl_pamu.c
18499 +index 0d03f837a5d4e..7a1a413f75ab2 100644
18500 +--- a/drivers/iommu/fsl_pamu.c
18501 ++++ b/drivers/iommu/fsl_pamu.c
18502 +@@ -868,7 +868,7 @@ static int fsl_pamu_probe(struct platform_device *pdev)
18503 + ret = create_csd(ppaact_phys, mem_size, csd_port_id);
18504 + if (ret) {
18505 + dev_err(dev, "could not create coherence subdomain\n");
18506 +- return ret;
18507 ++ goto error;
18508 + }
18509 + }
18510 +
18511 +diff --git a/drivers/iommu/mtk_iommu.c b/drivers/iommu/mtk_iommu.c
18512 +index 7e363b1f24dfe..ec73720e239b2 100644
18513 +--- a/drivers/iommu/mtk_iommu.c
18514 ++++ b/drivers/iommu/mtk_iommu.c
18515 +@@ -1041,20 +1041,24 @@ static int mtk_iommu_mm_dts_parse(struct device *dev, struct component_match **m
18516 + struct mtk_iommu_data *data)
18517 + {
18518 + struct device_node *larbnode, *smicomm_node, *smi_subcomm_node;
18519 +- struct platform_device *plarbdev;
18520 ++ struct platform_device *plarbdev, *pcommdev;
18521 + struct device_link *link;
18522 + int i, larb_nr, ret;
18523 +
18524 + larb_nr = of_count_phandle_with_args(dev->of_node, "mediatek,larbs", NULL);
18525 + if (larb_nr < 0)
18526 + return larb_nr;
18527 ++ if (larb_nr == 0 || larb_nr > MTK_LARB_NR_MAX)
18528 ++ return -EINVAL;
18529 +
18530 + for (i = 0; i < larb_nr; i++) {
18531 + u32 id;
18532 +
18533 + larbnode = of_parse_phandle(dev->of_node, "mediatek,larbs", i);
18534 +- if (!larbnode)
18535 +- return -EINVAL;
18536 ++ if (!larbnode) {
18537 ++ ret = -EINVAL;
18538 ++ goto err_larbdev_put;
18539 ++ }
18540 +
18541 + if (!of_device_is_available(larbnode)) {
18542 + of_node_put(larbnode);
18543 +@@ -1064,20 +1068,32 @@ static int mtk_iommu_mm_dts_parse(struct device *dev, struct component_match **m
18544 + ret = of_property_read_u32(larbnode, "mediatek,larb-id", &id);
18545 + if (ret)/* The id is consecutive if there is no this property */
18546 + id = i;
18547 ++ if (id >= MTK_LARB_NR_MAX) {
18548 ++ of_node_put(larbnode);
18549 ++ ret = -EINVAL;
18550 ++ goto err_larbdev_put;
18551 ++ }
18552 +
18553 + plarbdev = of_find_device_by_node(larbnode);
18554 ++ of_node_put(larbnode);
18555 + if (!plarbdev) {
18556 +- of_node_put(larbnode);
18557 +- return -ENODEV;
18558 ++ ret = -ENODEV;
18559 ++ goto err_larbdev_put;
18560 + }
18561 +- if (!plarbdev->dev.driver) {
18562 +- of_node_put(larbnode);
18563 +- return -EPROBE_DEFER;
18564 ++ if (data->larb_imu[id].dev) {
18565 ++ platform_device_put(plarbdev);
18566 ++ ret = -EEXIST;
18567 ++ goto err_larbdev_put;
18568 + }
18569 + data->larb_imu[id].dev = &plarbdev->dev;
18570 +
18571 +- component_match_add_release(dev, match, component_release_of,
18572 +- component_compare_of, larbnode);
18573 ++ if (!plarbdev->dev.driver) {
18574 ++ ret = -EPROBE_DEFER;
18575 ++ goto err_larbdev_put;
18576 ++ }
18577 ++
18578 ++ component_match_add(dev, match, component_compare_dev, &plarbdev->dev);
18579 ++ platform_device_put(plarbdev);
18580 + }
18581 +
18582 + /* Get smi-(sub)-common dev from the last larb. */
18583 +@@ -1095,17 +1111,28 @@ static int mtk_iommu_mm_dts_parse(struct device *dev, struct component_match **m
18584 + else
18585 + smicomm_node = smi_subcomm_node;
18586 +
18587 +- plarbdev = of_find_device_by_node(smicomm_node);
18588 ++ pcommdev = of_find_device_by_node(smicomm_node);
18589 + of_node_put(smicomm_node);
18590 +- data->smicomm_dev = &plarbdev->dev;
18591 ++ if (!pcommdev)
18592 ++ return -ENODEV;
18593 ++ data->smicomm_dev = &pcommdev->dev;
18594 +
18595 + link = device_link_add(data->smicomm_dev, dev,
18596 + DL_FLAG_STATELESS | DL_FLAG_PM_RUNTIME);
18597 ++ platform_device_put(pcommdev);
18598 + if (!link) {
18599 + dev_err(dev, "Unable to link %s.\n", dev_name(data->smicomm_dev));
18600 + return -EINVAL;
18601 + }
18602 + return 0;
18603 ++
18604 ++err_larbdev_put:
18605 ++ for (i = MTK_LARB_NR_MAX - 1; i >= 0; i--) {
18606 ++ if (!data->larb_imu[i].dev)
18607 ++ continue;
18608 ++ put_device(data->larb_imu[i].dev);
18609 ++ }
18610 ++ return ret;
18611 + }
18612 +
18613 + static int mtk_iommu_probe(struct platform_device *pdev)
18614 +@@ -1170,6 +1197,8 @@ static int mtk_iommu_probe(struct platform_device *pdev)
18615 +
18616 + banks_num = data->plat_data->banks_num;
18617 + res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
18618 ++ if (!res)
18619 ++ return -EINVAL;
18620 + if (resource_size(res) < banks_num * MTK_IOMMU_BANK_SZ) {
18621 + dev_err(dev, "banknr %d. res %pR is not enough.\n", banks_num, res);
18622 + return -EINVAL;
18623 +diff --git a/drivers/iommu/rockchip-iommu.c b/drivers/iommu/rockchip-iommu.c
18624 +index ab57c4b8fade2..a0652e9a7db34 100644
18625 +--- a/drivers/iommu/rockchip-iommu.c
18626 ++++ b/drivers/iommu/rockchip-iommu.c
18627 +@@ -280,19 +280,17 @@ static u32 rk_mk_pte(phys_addr_t page, int prot)
18628 + * 11:9 - Page address bit 34:32
18629 + * 8:4 - Page address bit 39:35
18630 + * 3 - Security
18631 +- * 2 - Readable
18632 +- * 1 - Writable
18633 ++ * 2 - Writable
18634 ++ * 1 - Readable
18635 + * 0 - 1 if Page @ Page address is valid
18636 + */
18637 +-#define RK_PTE_PAGE_READABLE_V2 BIT(2)
18638 +-#define RK_PTE_PAGE_WRITABLE_V2 BIT(1)
18639 +
18640 + static u32 rk_mk_pte_v2(phys_addr_t page, int prot)
18641 + {
18642 + u32 flags = 0;
18643 +
18644 +- flags |= (prot & IOMMU_READ) ? RK_PTE_PAGE_READABLE_V2 : 0;
18645 +- flags |= (prot & IOMMU_WRITE) ? RK_PTE_PAGE_WRITABLE_V2 : 0;
18646 ++ flags |= (prot & IOMMU_READ) ? RK_PTE_PAGE_READABLE : 0;
18647 ++ flags |= (prot & IOMMU_WRITE) ? RK_PTE_PAGE_WRITABLE : 0;
18648 +
18649 + return rk_mk_dte_v2(page) | flags;
18650 + }
18651 +diff --git a/drivers/iommu/s390-iommu.c b/drivers/iommu/s390-iommu.c
18652 +index c898bcbbce118..96173cfee3249 100644
18653 +--- a/drivers/iommu/s390-iommu.c
18654 ++++ b/drivers/iommu/s390-iommu.c
18655 +@@ -79,10 +79,36 @@ static void s390_domain_free(struct iommu_domain *domain)
18656 + {
18657 + struct s390_domain *s390_domain = to_s390_domain(domain);
18658 +
18659 ++ WARN_ON(!list_empty(&s390_domain->devices));
18660 + dma_cleanup_tables(s390_domain->dma_table);
18661 + kfree(s390_domain);
18662 + }
18663 +
18664 ++static void __s390_iommu_detach_device(struct zpci_dev *zdev)
18665 ++{
18666 ++ struct s390_domain *s390_domain = zdev->s390_domain;
18667 ++ struct s390_domain_device *domain_device, *tmp;
18668 ++ unsigned long flags;
18669 ++
18670 ++ if (!s390_domain)
18671 ++ return;
18672 ++
18673 ++ spin_lock_irqsave(&s390_domain->list_lock, flags);
18674 ++ list_for_each_entry_safe(domain_device, tmp, &s390_domain->devices,
18675 ++ list) {
18676 ++ if (domain_device->zdev == zdev) {
18677 ++ list_del(&domain_device->list);
18678 ++ kfree(domain_device);
18679 ++ break;
18680 ++ }
18681 ++ }
18682 ++ spin_unlock_irqrestore(&s390_domain->list_lock, flags);
18683 ++
18684 ++ zpci_unregister_ioat(zdev, 0);
18685 ++ zdev->s390_domain = NULL;
18686 ++ zdev->dma_table = NULL;
18687 ++}
18688 ++
18689 + static int s390_iommu_attach_device(struct iommu_domain *domain,
18690 + struct device *dev)
18691 + {
18692 +@@ -90,7 +116,7 @@ static int s390_iommu_attach_device(struct iommu_domain *domain,
18693 + struct zpci_dev *zdev = to_zpci_dev(dev);
18694 + struct s390_domain_device *domain_device;
18695 + unsigned long flags;
18696 +- int cc, rc;
18697 ++ int cc, rc = 0;
18698 +
18699 + if (!zdev)
18700 + return -ENODEV;
18701 +@@ -99,24 +125,18 @@ static int s390_iommu_attach_device(struct iommu_domain *domain,
18702 + if (!domain_device)
18703 + return -ENOMEM;
18704 +
18705 +- if (zdev->dma_table && !zdev->s390_domain) {
18706 +- cc = zpci_dma_exit_device(zdev);
18707 +- if (cc) {
18708 +- rc = -EIO;
18709 +- goto out_free;
18710 +- }
18711 +- }
18712 +-
18713 + if (zdev->s390_domain)
18714 +- zpci_unregister_ioat(zdev, 0);
18715 ++ __s390_iommu_detach_device(zdev);
18716 ++ else if (zdev->dma_table)
18717 ++ zpci_dma_exit_device(zdev);
18718 +
18719 +- zdev->dma_table = s390_domain->dma_table;
18720 + cc = zpci_register_ioat(zdev, 0, zdev->start_dma, zdev->end_dma,
18721 +- virt_to_phys(zdev->dma_table));
18722 ++ virt_to_phys(s390_domain->dma_table));
18723 + if (cc) {
18724 + rc = -EIO;
18725 +- goto out_restore;
18726 ++ goto out_free;
18727 + }
18728 ++ zdev->dma_table = s390_domain->dma_table;
18729 +
18730 + spin_lock_irqsave(&s390_domain->list_lock, flags);
18731 + /* First device defines the DMA range limits */
18732 +@@ -127,9 +147,9 @@ static int s390_iommu_attach_device(struct iommu_domain *domain,
18733 + /* Allow only devices with identical DMA range limits */
18734 + } else if (domain->geometry.aperture_start != zdev->start_dma ||
18735 + domain->geometry.aperture_end != zdev->end_dma) {
18736 +- rc = -EINVAL;
18737 + spin_unlock_irqrestore(&s390_domain->list_lock, flags);
18738 +- goto out_restore;
18739 ++ rc = -EINVAL;
18740 ++ goto out_unregister;
18741 + }
18742 + domain_device->zdev = zdev;
18743 + zdev->s390_domain = s390_domain;
18744 +@@ -138,14 +158,9 @@ static int s390_iommu_attach_device(struct iommu_domain *domain,
18745 +
18746 + return 0;
18747 +
18748 +-out_restore:
18749 +- if (!zdev->s390_domain) {
18750 +- zpci_dma_init_device(zdev);
18751 +- } else {
18752 +- zdev->dma_table = zdev->s390_domain->dma_table;
18753 +- zpci_register_ioat(zdev, 0, zdev->start_dma, zdev->end_dma,
18754 +- virt_to_phys(zdev->dma_table));
18755 +- }
18756 ++out_unregister:
18757 ++ zpci_unregister_ioat(zdev, 0);
18758 ++ zdev->dma_table = NULL;
18759 + out_free:
18760 + kfree(domain_device);
18761 +
18762 +@@ -155,32 +170,12 @@ out_free:
18763 + static void s390_iommu_detach_device(struct iommu_domain *domain,
18764 + struct device *dev)
18765 + {
18766 +- struct s390_domain *s390_domain = to_s390_domain(domain);
18767 + struct zpci_dev *zdev = to_zpci_dev(dev);
18768 +- struct s390_domain_device *domain_device, *tmp;
18769 +- unsigned long flags;
18770 +- int found = 0;
18771 +
18772 +- if (!zdev)
18773 +- return;
18774 ++ WARN_ON(zdev->s390_domain != to_s390_domain(domain));
18775 +
18776 +- spin_lock_irqsave(&s390_domain->list_lock, flags);
18777 +- list_for_each_entry_safe(domain_device, tmp, &s390_domain->devices,
18778 +- list) {
18779 +- if (domain_device->zdev == zdev) {
18780 +- list_del(&domain_device->list);
18781 +- kfree(domain_device);
18782 +- found = 1;
18783 +- break;
18784 +- }
18785 +- }
18786 +- spin_unlock_irqrestore(&s390_domain->list_lock, flags);
18787 +-
18788 +- if (found && (zdev->s390_domain == s390_domain)) {
18789 +- zdev->s390_domain = NULL;
18790 +- zpci_unregister_ioat(zdev, 0);
18791 +- zpci_dma_init_device(zdev);
18792 +- }
18793 ++ __s390_iommu_detach_device(zdev);
18794 ++ zpci_dma_init_device(zdev);
18795 + }
18796 +
18797 + static struct iommu_device *s390_iommu_probe_device(struct device *dev)
18798 +@@ -193,24 +188,13 @@ static struct iommu_device *s390_iommu_probe_device(struct device *dev)
18799 + static void s390_iommu_release_device(struct device *dev)
18800 + {
18801 + struct zpci_dev *zdev = to_zpci_dev(dev);
18802 +- struct iommu_domain *domain;
18803 +
18804 + /*
18805 +- * This is a workaround for a scenario where the IOMMU API common code
18806 +- * "forgets" to call the detach_dev callback: After binding a device
18807 +- * to vfio-pci and completing the VFIO_SET_IOMMU ioctl (which triggers
18808 +- * the attach_dev), removing the device via
18809 +- * "echo 1 > /sys/bus/pci/devices/.../remove" won't trigger detach_dev,
18810 +- * only release_device will be called via the BUS_NOTIFY_REMOVED_DEVICE
18811 +- * notifier.
18812 +- *
18813 +- * So let's call detach_dev from here if it hasn't been called before.
18814 ++ * release_device is expected to detach any domain currently attached
18815 ++ * to the device, but keep it attached to other devices in the group.
18816 + */
18817 +- if (zdev && zdev->s390_domain) {
18818 +- domain = iommu_get_domain_for_dev(dev);
18819 +- if (domain)
18820 +- s390_iommu_detach_device(domain, dev);
18821 +- }
18822 ++ if (zdev)
18823 ++ __s390_iommu_detach_device(zdev);
18824 + }
18825 +
18826 + static int s390_iommu_update_trans(struct s390_domain *s390_domain,
18827 +diff --git a/drivers/iommu/sun50i-iommu.c b/drivers/iommu/sun50i-iommu.c
18828 +index a84c63518773a..1d81a6aa939bf 100644
18829 +--- a/drivers/iommu/sun50i-iommu.c
18830 ++++ b/drivers/iommu/sun50i-iommu.c
18831 +@@ -27,6 +27,7 @@
18832 + #include <linux/types.h>
18833 +
18834 + #define IOMMU_RESET_REG 0x010
18835 ++#define IOMMU_RESET_RELEASE_ALL 0xffffffff
18836 + #define IOMMU_ENABLE_REG 0x020
18837 + #define IOMMU_ENABLE_ENABLE BIT(0)
18838 +
18839 +@@ -92,6 +93,8 @@
18840 + #define NUM_PT_ENTRIES 256
18841 + #define PT_SIZE (NUM_PT_ENTRIES * PT_ENTRY_SIZE)
18842 +
18843 ++#define SPAGE_SIZE 4096
18844 ++
18845 + struct sun50i_iommu {
18846 + struct iommu_device iommu;
18847 +
18848 +@@ -270,7 +273,7 @@ static u32 sun50i_mk_pte(phys_addr_t page, int prot)
18849 + enum sun50i_iommu_aci aci;
18850 + u32 flags = 0;
18851 +
18852 +- if (prot & (IOMMU_READ | IOMMU_WRITE))
18853 ++ if ((prot & (IOMMU_READ | IOMMU_WRITE)) == (IOMMU_READ | IOMMU_WRITE))
18854 + aci = SUN50I_IOMMU_ACI_RD_WR;
18855 + else if (prot & IOMMU_READ)
18856 + aci = SUN50I_IOMMU_ACI_RD;
18857 +@@ -294,6 +297,62 @@ static void sun50i_table_flush(struct sun50i_iommu_domain *sun50i_domain,
18858 + dma_sync_single_for_device(iommu->dev, dma, size, DMA_TO_DEVICE);
18859 + }
18860 +
18861 ++static void sun50i_iommu_zap_iova(struct sun50i_iommu *iommu,
18862 ++ unsigned long iova)
18863 ++{
18864 ++ u32 reg;
18865 ++ int ret;
18866 ++
18867 ++ iommu_write(iommu, IOMMU_TLB_IVLD_ADDR_REG, iova);
18868 ++ iommu_write(iommu, IOMMU_TLB_IVLD_ADDR_MASK_REG, GENMASK(31, 12));
18869 ++ iommu_write(iommu, IOMMU_TLB_IVLD_ENABLE_REG,
18870 ++ IOMMU_TLB_IVLD_ENABLE_ENABLE);
18871 ++
18872 ++ ret = readl_poll_timeout_atomic(iommu->base + IOMMU_TLB_IVLD_ENABLE_REG,
18873 ++ reg, !reg, 1, 2000);
18874 ++ if (ret)
18875 ++ dev_warn(iommu->dev, "TLB invalidation timed out!\n");
18876 ++}
18877 ++
18878 ++static void sun50i_iommu_zap_ptw_cache(struct sun50i_iommu *iommu,
18879 ++ unsigned long iova)
18880 ++{
18881 ++ u32 reg;
18882 ++ int ret;
18883 ++
18884 ++ iommu_write(iommu, IOMMU_PC_IVLD_ADDR_REG, iova);
18885 ++ iommu_write(iommu, IOMMU_PC_IVLD_ENABLE_REG,
18886 ++ IOMMU_PC_IVLD_ENABLE_ENABLE);
18887 ++
18888 ++ ret = readl_poll_timeout_atomic(iommu->base + IOMMU_PC_IVLD_ENABLE_REG,
18889 ++ reg, !reg, 1, 2000);
18890 ++ if (ret)
18891 ++ dev_warn(iommu->dev, "PTW cache invalidation timed out!\n");
18892 ++}
18893 ++
18894 ++static void sun50i_iommu_zap_range(struct sun50i_iommu *iommu,
18895 ++ unsigned long iova, size_t size)
18896 ++{
18897 ++ assert_spin_locked(&iommu->iommu_lock);
18898 ++
18899 ++ iommu_write(iommu, IOMMU_AUTO_GATING_REG, 0);
18900 ++
18901 ++ sun50i_iommu_zap_iova(iommu, iova);
18902 ++ sun50i_iommu_zap_iova(iommu, iova + SPAGE_SIZE);
18903 ++ if (size > SPAGE_SIZE) {
18904 ++ sun50i_iommu_zap_iova(iommu, iova + size);
18905 ++ sun50i_iommu_zap_iova(iommu, iova + size + SPAGE_SIZE);
18906 ++ }
18907 ++ sun50i_iommu_zap_ptw_cache(iommu, iova);
18908 ++ sun50i_iommu_zap_ptw_cache(iommu, iova + SZ_1M);
18909 ++ if (size > SZ_1M) {
18910 ++ sun50i_iommu_zap_ptw_cache(iommu, iova + size);
18911 ++ sun50i_iommu_zap_ptw_cache(iommu, iova + size + SZ_1M);
18912 ++ }
18913 ++
18914 ++ iommu_write(iommu, IOMMU_AUTO_GATING_REG, IOMMU_AUTO_GATING_ENABLE);
18915 ++}
18916 ++
18917 + static int sun50i_iommu_flush_all_tlb(struct sun50i_iommu *iommu)
18918 + {
18919 + u32 reg;
18920 +@@ -343,6 +402,18 @@ static void sun50i_iommu_flush_iotlb_all(struct iommu_domain *domain)
18921 + spin_unlock_irqrestore(&iommu->iommu_lock, flags);
18922 + }
18923 +
18924 ++static void sun50i_iommu_iotlb_sync_map(struct iommu_domain *domain,
18925 ++ unsigned long iova, size_t size)
18926 ++{
18927 ++ struct sun50i_iommu_domain *sun50i_domain = to_sun50i_domain(domain);
18928 ++ struct sun50i_iommu *iommu = sun50i_domain->iommu;
18929 ++ unsigned long flags;
18930 ++
18931 ++ spin_lock_irqsave(&iommu->iommu_lock, flags);
18932 ++ sun50i_iommu_zap_range(iommu, iova, size);
18933 ++ spin_unlock_irqrestore(&iommu->iommu_lock, flags);
18934 ++}
18935 ++
18936 + static void sun50i_iommu_iotlb_sync(struct iommu_domain *domain,
18937 + struct iommu_iotlb_gather *gather)
18938 + {
18939 +@@ -511,7 +582,7 @@ static u32 *sun50i_dte_get_page_table(struct sun50i_iommu_domain *sun50i_domain,
18940 + sun50i_iommu_free_page_table(iommu, drop_pt);
18941 + }
18942 +
18943 +- sun50i_table_flush(sun50i_domain, page_table, PT_SIZE);
18944 ++ sun50i_table_flush(sun50i_domain, page_table, NUM_PT_ENTRIES);
18945 + sun50i_table_flush(sun50i_domain, dte_addr, 1);
18946 +
18947 + return page_table;
18948 +@@ -601,7 +672,6 @@ static struct iommu_domain *sun50i_iommu_domain_alloc(unsigned type)
18949 + struct sun50i_iommu_domain *sun50i_domain;
18950 +
18951 + if (type != IOMMU_DOMAIN_DMA &&
18952 +- type != IOMMU_DOMAIN_IDENTITY &&
18953 + type != IOMMU_DOMAIN_UNMANAGED)
18954 + return NULL;
18955 +
18956 +@@ -766,6 +836,7 @@ static const struct iommu_ops sun50i_iommu_ops = {
18957 + .attach_dev = sun50i_iommu_attach_device,
18958 + .detach_dev = sun50i_iommu_detach_device,
18959 + .flush_iotlb_all = sun50i_iommu_flush_iotlb_all,
18960 ++ .iotlb_sync_map = sun50i_iommu_iotlb_sync_map,
18961 + .iotlb_sync = sun50i_iommu_iotlb_sync,
18962 + .iova_to_phys = sun50i_iommu_iova_to_phys,
18963 + .map = sun50i_iommu_map,
18964 +@@ -785,6 +856,8 @@ static void sun50i_iommu_report_fault(struct sun50i_iommu *iommu,
18965 + report_iommu_fault(iommu->domain, iommu->dev, iova, prot);
18966 + else
18967 + dev_err(iommu->dev, "Page fault while iommu not attached to any domain?\n");
18968 ++
18969 ++ sun50i_iommu_zap_range(iommu, iova, SPAGE_SIZE);
18970 + }
18971 +
18972 + static phys_addr_t sun50i_iommu_handle_pt_irq(struct sun50i_iommu *iommu,
18973 +@@ -868,8 +941,8 @@ static phys_addr_t sun50i_iommu_handle_perm_irq(struct sun50i_iommu *iommu)
18974 +
18975 + static irqreturn_t sun50i_iommu_irq(int irq, void *dev_id)
18976 + {
18977 ++ u32 status, l1_status, l2_status, resets;
18978 + struct sun50i_iommu *iommu = dev_id;
18979 +- u32 status;
18980 +
18981 + spin_lock(&iommu->iommu_lock);
18982 +
18983 +@@ -879,6 +952,9 @@ static irqreturn_t sun50i_iommu_irq(int irq, void *dev_id)
18984 + return IRQ_NONE;
18985 + }
18986 +
18987 ++ l1_status = iommu_read(iommu, IOMMU_L1PG_INT_REG);
18988 ++ l2_status = iommu_read(iommu, IOMMU_L2PG_INT_REG);
18989 ++
18990 + if (status & IOMMU_INT_INVALID_L2PG)
18991 + sun50i_iommu_handle_pt_irq(iommu,
18992 + IOMMU_INT_ERR_ADDR_L2_REG,
18993 +@@ -892,8 +968,9 @@ static irqreturn_t sun50i_iommu_irq(int irq, void *dev_id)
18994 +
18995 + iommu_write(iommu, IOMMU_INT_CLR_REG, status);
18996 +
18997 +- iommu_write(iommu, IOMMU_RESET_REG, ~status);
18998 +- iommu_write(iommu, IOMMU_RESET_REG, status);
18999 ++ resets = (status | l1_status | l2_status) & IOMMU_INT_MASTER_MASK;
19000 ++ iommu_write(iommu, IOMMU_RESET_REG, ~resets);
19001 ++ iommu_write(iommu, IOMMU_RESET_REG, IOMMU_RESET_RELEASE_ALL);
19002 +
19003 + spin_unlock(&iommu->iommu_lock);
19004 +
19005 +diff --git a/drivers/irqchip/irq-gic-pm.c b/drivers/irqchip/irq-gic-pm.c
19006 +index b60e1853593f4..3989d16f997b3 100644
19007 +--- a/drivers/irqchip/irq-gic-pm.c
19008 ++++ b/drivers/irqchip/irq-gic-pm.c
19009 +@@ -102,7 +102,7 @@ static int gic_probe(struct platform_device *pdev)
19010 +
19011 + pm_runtime_enable(dev);
19012 +
19013 +- ret = pm_runtime_get_sync(dev);
19014 ++ ret = pm_runtime_resume_and_get(dev);
19015 + if (ret < 0)
19016 + goto rpm_disable;
19017 +
19018 +diff --git a/drivers/irqchip/irq-loongson-liointc.c b/drivers/irqchip/irq-loongson-liointc.c
19019 +index 0da8716f8f24b..c4584e2f0ad3d 100644
19020 +--- a/drivers/irqchip/irq-loongson-liointc.c
19021 ++++ b/drivers/irqchip/irq-loongson-liointc.c
19022 +@@ -207,10 +207,13 @@ static int liointc_init(phys_addr_t addr, unsigned long size, int revision,
19023 + "reg-names", core_reg_names[i]);
19024 +
19025 + if (index < 0)
19026 +- goto out_iounmap;
19027 ++ continue;
19028 +
19029 + priv->core_isr[i] = of_iomap(node, index);
19030 + }
19031 ++
19032 ++ if (!priv->core_isr[0])
19033 ++ goto out_iounmap;
19034 + }
19035 +
19036 + /* Setup IRQ domain */
19037 +diff --git a/drivers/irqchip/irq-loongson-pch-pic.c b/drivers/irqchip/irq-loongson-pch-pic.c
19038 +index c01b9c2570053..03493cda65a37 100644
19039 +--- a/drivers/irqchip/irq-loongson-pch-pic.c
19040 ++++ b/drivers/irqchip/irq-loongson-pch-pic.c
19041 +@@ -159,6 +159,9 @@ static int pch_pic_domain_translate(struct irq_domain *d,
19042 + return -EINVAL;
19043 +
19044 + if (of_node) {
19045 ++ if (fwspec->param_count < 2)
19046 ++ return -EINVAL;
19047 ++
19048 + *hwirq = fwspec->param[0] + priv->ht_vec_base;
19049 + *type = fwspec->param[1] & IRQ_TYPE_SENSE_MASK;
19050 + } else {
19051 +diff --git a/drivers/irqchip/irq-wpcm450-aic.c b/drivers/irqchip/irq-wpcm450-aic.c
19052 +index 0dcbeb1a05a1f..91df62a64cd91 100644
19053 +--- a/drivers/irqchip/irq-wpcm450-aic.c
19054 ++++ b/drivers/irqchip/irq-wpcm450-aic.c
19055 +@@ -146,6 +146,7 @@ static int __init wpcm450_aic_of_init(struct device_node *node,
19056 + aic->regs = of_iomap(node, 0);
19057 + if (!aic->regs) {
19058 + pr_err("Failed to map WPCM450 AIC registers\n");
19059 ++ kfree(aic);
19060 + return -ENOMEM;
19061 + }
19062 +
19063 +diff --git a/drivers/isdn/hardware/mISDN/hfcmulti.c b/drivers/isdn/hardware/mISDN/hfcmulti.c
19064 +index 4f7eaa17fb274..e840609c50eb7 100644
19065 +--- a/drivers/isdn/hardware/mISDN/hfcmulti.c
19066 ++++ b/drivers/isdn/hardware/mISDN/hfcmulti.c
19067 +@@ -3217,6 +3217,7 @@ static int
19068 + hfcm_l1callback(struct dchannel *dch, u_int cmd)
19069 + {
19070 + struct hfc_multi *hc = dch->hw;
19071 ++ struct sk_buff_head free_queue;
19072 + u_long flags;
19073 +
19074 + switch (cmd) {
19075 +@@ -3245,6 +3246,7 @@ hfcm_l1callback(struct dchannel *dch, u_int cmd)
19076 + l1_event(dch->l1, HW_POWERUP_IND);
19077 + break;
19078 + case HW_DEACT_REQ:
19079 ++ __skb_queue_head_init(&free_queue);
19080 + /* start deactivation */
19081 + spin_lock_irqsave(&hc->lock, flags);
19082 + if (hc->ctype == HFC_TYPE_E1) {
19083 +@@ -3264,20 +3266,21 @@ hfcm_l1callback(struct dchannel *dch, u_int cmd)
19084 + plxsd_checksync(hc, 0);
19085 + }
19086 + }
19087 +- skb_queue_purge(&dch->squeue);
19088 ++ skb_queue_splice_init(&dch->squeue, &free_queue);
19089 + if (dch->tx_skb) {
19090 +- dev_kfree_skb(dch->tx_skb);
19091 ++ __skb_queue_tail(&free_queue, dch->tx_skb);
19092 + dch->tx_skb = NULL;
19093 + }
19094 + dch->tx_idx = 0;
19095 + if (dch->rx_skb) {
19096 +- dev_kfree_skb(dch->rx_skb);
19097 ++ __skb_queue_tail(&free_queue, dch->rx_skb);
19098 + dch->rx_skb = NULL;
19099 + }
19100 + test_and_clear_bit(FLG_TX_BUSY, &dch->Flags);
19101 + if (test_and_clear_bit(FLG_BUSY_TIMER, &dch->Flags))
19102 + del_timer(&dch->timer);
19103 + spin_unlock_irqrestore(&hc->lock, flags);
19104 ++ __skb_queue_purge(&free_queue);
19105 + break;
19106 + case HW_POWERUP_REQ:
19107 + spin_lock_irqsave(&hc->lock, flags);
19108 +@@ -3384,6 +3387,9 @@ handle_dmsg(struct mISDNchannel *ch, struct sk_buff *skb)
19109 + case PH_DEACTIVATE_REQ:
19110 + test_and_clear_bit(FLG_L2_ACTIVATED, &dch->Flags);
19111 + if (dch->dev.D.protocol != ISDN_P_TE_S0) {
19112 ++ struct sk_buff_head free_queue;
19113 ++
19114 ++ __skb_queue_head_init(&free_queue);
19115 + spin_lock_irqsave(&hc->lock, flags);
19116 + if (debug & DEBUG_HFCMULTI_MSG)
19117 + printk(KERN_DEBUG
19118 +@@ -3405,14 +3411,14 @@ handle_dmsg(struct mISDNchannel *ch, struct sk_buff *skb)
19119 + /* deactivate */
19120 + dch->state = 1;
19121 + }
19122 +- skb_queue_purge(&dch->squeue);
19123 ++ skb_queue_splice_init(&dch->squeue, &free_queue);
19124 + if (dch->tx_skb) {
19125 +- dev_kfree_skb(dch->tx_skb);
19126 ++ __skb_queue_tail(&free_queue, dch->tx_skb);
19127 + dch->tx_skb = NULL;
19128 + }
19129 + dch->tx_idx = 0;
19130 + if (dch->rx_skb) {
19131 +- dev_kfree_skb(dch->rx_skb);
19132 ++ __skb_queue_tail(&free_queue, dch->rx_skb);
19133 + dch->rx_skb = NULL;
19134 + }
19135 + test_and_clear_bit(FLG_TX_BUSY, &dch->Flags);
19136 +@@ -3424,6 +3430,7 @@ handle_dmsg(struct mISDNchannel *ch, struct sk_buff *skb)
19137 + #endif
19138 + ret = 0;
19139 + spin_unlock_irqrestore(&hc->lock, flags);
19140 ++ __skb_queue_purge(&free_queue);
19141 + } else
19142 + ret = l1_event(dch->l1, hh->prim);
19143 + break;
19144 +diff --git a/drivers/isdn/hardware/mISDN/hfcpci.c b/drivers/isdn/hardware/mISDN/hfcpci.c
19145 +index af17459c1a5c0..eba58b99cd29d 100644
19146 +--- a/drivers/isdn/hardware/mISDN/hfcpci.c
19147 ++++ b/drivers/isdn/hardware/mISDN/hfcpci.c
19148 +@@ -1617,16 +1617,19 @@ hfcpci_l2l1D(struct mISDNchannel *ch, struct sk_buff *skb)
19149 + test_and_clear_bit(FLG_L2_ACTIVATED, &dch->Flags);
19150 + spin_lock_irqsave(&hc->lock, flags);
19151 + if (hc->hw.protocol == ISDN_P_NT_S0) {
19152 ++ struct sk_buff_head free_queue;
19153 ++
19154 ++ __skb_queue_head_init(&free_queue);
19155 + /* prepare deactivation */
19156 + Write_hfc(hc, HFCPCI_STATES, 0x40);
19157 +- skb_queue_purge(&dch->squeue);
19158 ++ skb_queue_splice_init(&dch->squeue, &free_queue);
19159 + if (dch->tx_skb) {
19160 +- dev_kfree_skb(dch->tx_skb);
19161 ++ __skb_queue_tail(&free_queue, dch->tx_skb);
19162 + dch->tx_skb = NULL;
19163 + }
19164 + dch->tx_idx = 0;
19165 + if (dch->rx_skb) {
19166 +- dev_kfree_skb(dch->rx_skb);
19167 ++ __skb_queue_tail(&free_queue, dch->rx_skb);
19168 + dch->rx_skb = NULL;
19169 + }
19170 + test_and_clear_bit(FLG_TX_BUSY, &dch->Flags);
19171 +@@ -1639,10 +1642,12 @@ hfcpci_l2l1D(struct mISDNchannel *ch, struct sk_buff *skb)
19172 + hc->hw.mst_m &= ~HFCPCI_MASTER;
19173 + Write_hfc(hc, HFCPCI_MST_MODE, hc->hw.mst_m);
19174 + ret = 0;
19175 ++ spin_unlock_irqrestore(&hc->lock, flags);
19176 ++ __skb_queue_purge(&free_queue);
19177 + } else {
19178 + ret = l1_event(dch->l1, hh->prim);
19179 ++ spin_unlock_irqrestore(&hc->lock, flags);
19180 + }
19181 +- spin_unlock_irqrestore(&hc->lock, flags);
19182 + break;
19183 + }
19184 + if (!ret)
19185 +diff --git a/drivers/isdn/hardware/mISDN/hfcsusb.c b/drivers/isdn/hardware/mISDN/hfcsusb.c
19186 +index 651f2f8f685b7..1efd17979f240 100644
19187 +--- a/drivers/isdn/hardware/mISDN/hfcsusb.c
19188 ++++ b/drivers/isdn/hardware/mISDN/hfcsusb.c
19189 +@@ -326,20 +326,24 @@ hfcusb_l2l1D(struct mISDNchannel *ch, struct sk_buff *skb)
19190 + test_and_clear_bit(FLG_L2_ACTIVATED, &dch->Flags);
19191 +
19192 + if (hw->protocol == ISDN_P_NT_S0) {
19193 ++ struct sk_buff_head free_queue;
19194 ++
19195 ++ __skb_queue_head_init(&free_queue);
19196 + hfcsusb_ph_command(hw, HFC_L1_DEACTIVATE_NT);
19197 + spin_lock_irqsave(&hw->lock, flags);
19198 +- skb_queue_purge(&dch->squeue);
19199 ++ skb_queue_splice_init(&dch->squeue, &free_queue);
19200 + if (dch->tx_skb) {
19201 +- dev_kfree_skb(dch->tx_skb);
19202 ++ __skb_queue_tail(&free_queue, dch->tx_skb);
19203 + dch->tx_skb = NULL;
19204 + }
19205 + dch->tx_idx = 0;
19206 + if (dch->rx_skb) {
19207 +- dev_kfree_skb(dch->rx_skb);
19208 ++ __skb_queue_tail(&free_queue, dch->rx_skb);
19209 + dch->rx_skb = NULL;
19210 + }
19211 + test_and_clear_bit(FLG_TX_BUSY, &dch->Flags);
19212 + spin_unlock_irqrestore(&hw->lock, flags);
19213 ++ __skb_queue_purge(&free_queue);
19214 + #ifdef FIXME
19215 + if (test_and_clear_bit(FLG_L1_BUSY, &dch->Flags))
19216 + dchannel_sched_event(&hc->dch, D_CLEARBUSY);
19217 +@@ -1330,7 +1334,7 @@ tx_iso_complete(struct urb *urb)
19218 + printk("\n");
19219 + }
19220 +
19221 +- dev_kfree_skb(tx_skb);
19222 ++ dev_consume_skb_irq(tx_skb);
19223 + tx_skb = NULL;
19224 + if (fifo->dch && get_next_dframe(fifo->dch))
19225 + tx_skb = fifo->dch->tx_skb;
19226 +diff --git a/drivers/leds/leds-is31fl319x.c b/drivers/leds/leds-is31fl319x.c
19227 +index 52b59b62f437c..b2f4c4ec7c567 100644
19228 +--- a/drivers/leds/leds-is31fl319x.c
19229 ++++ b/drivers/leds/leds-is31fl319x.c
19230 +@@ -38,6 +38,7 @@
19231 + #define IS31FL3190_CURRENT_uA_MIN 5000
19232 + #define IS31FL3190_CURRENT_uA_DEFAULT 42000
19233 + #define IS31FL3190_CURRENT_uA_MAX 42000
19234 ++#define IS31FL3190_CURRENT_SHIFT 2
19235 + #define IS31FL3190_CURRENT_MASK GENMASK(4, 2)
19236 + #define IS31FL3190_CURRENT_5_mA 0x02
19237 + #define IS31FL3190_CURRENT_10_mA 0x01
19238 +@@ -553,7 +554,7 @@ static int is31fl319x_probe(struct i2c_client *client)
19239 + is31fl3196_db_to_gain(is31->audio_gain_db));
19240 + else
19241 + regmap_update_bits(is31->regmap, IS31FL3190_CURRENT, IS31FL3190_CURRENT_MASK,
19242 +- is31fl3190_microamp_to_cs(dev, aggregated_led_microamp));
19243 ++ is31fl3190_microamp_to_cs(dev, aggregated_led_microamp) << IS31FL3190_CURRENT_SHIFT);
19244 +
19245 + for (i = 0; i < is31->cdef->num_leds; i++) {
19246 + struct is31fl319x_led *led = &is31->leds[i];
19247 +diff --git a/drivers/leds/rgb/leds-qcom-lpg.c b/drivers/leds/rgb/leds-qcom-lpg.c
19248 +index 02f51cc618376..c1a56259226fb 100644
19249 +--- a/drivers/leds/rgb/leds-qcom-lpg.c
19250 ++++ b/drivers/leds/rgb/leds-qcom-lpg.c
19251 +@@ -602,8 +602,8 @@ static void lpg_brightness_set(struct lpg_led *led, struct led_classdev *cdev,
19252 + lpg_lut_sync(lpg, lut_mask);
19253 + }
19254 +
19255 +-static void lpg_brightness_single_set(struct led_classdev *cdev,
19256 +- enum led_brightness value)
19257 ++static int lpg_brightness_single_set(struct led_classdev *cdev,
19258 ++ enum led_brightness value)
19259 + {
19260 + struct lpg_led *led = container_of(cdev, struct lpg_led, cdev);
19261 + struct mc_subled info;
19262 +@@ -614,10 +614,12 @@ static void lpg_brightness_single_set(struct led_classdev *cdev,
19263 + lpg_brightness_set(led, cdev, &info);
19264 +
19265 + mutex_unlock(&led->lpg->lock);
19266 ++
19267 ++ return 0;
19268 + }
19269 +
19270 +-static void lpg_brightness_mc_set(struct led_classdev *cdev,
19271 +- enum led_brightness value)
19272 ++static int lpg_brightness_mc_set(struct led_classdev *cdev,
19273 ++ enum led_brightness value)
19274 + {
19275 + struct led_classdev_mc *mc = lcdev_to_mccdev(cdev);
19276 + struct lpg_led *led = container_of(mc, struct lpg_led, mcdev);
19277 +@@ -628,6 +630,8 @@ static void lpg_brightness_mc_set(struct led_classdev *cdev,
19278 + lpg_brightness_set(led, cdev, mc->subled_info);
19279 +
19280 + mutex_unlock(&led->lpg->lock);
19281 ++
19282 ++ return 0;
19283 + }
19284 +
19285 + static int lpg_blink_set(struct lpg_led *led,
19286 +@@ -1118,7 +1122,7 @@ static int lpg_add_led(struct lpg *lpg, struct device_node *np)
19287 + led->mcdev.num_colors = num_channels;
19288 +
19289 + cdev = &led->mcdev.led_cdev;
19290 +- cdev->brightness_set = lpg_brightness_mc_set;
19291 ++ cdev->brightness_set_blocking = lpg_brightness_mc_set;
19292 + cdev->blink_set = lpg_blink_mc_set;
19293 +
19294 + /* Register pattern accessors only if we have a LUT block */
19295 +@@ -1132,7 +1136,7 @@ static int lpg_add_led(struct lpg *lpg, struct device_node *np)
19296 + return ret;
19297 +
19298 + cdev = &led->cdev;
19299 +- cdev->brightness_set = lpg_brightness_single_set;
19300 ++ cdev->brightness_set_blocking = lpg_brightness_single_set;
19301 + cdev->blink_set = lpg_blink_single_set;
19302 +
19303 + /* Register pattern accessors only if we have a LUT block */
19304 +@@ -1151,7 +1155,7 @@ static int lpg_add_led(struct lpg *lpg, struct device_node *np)
19305 + else
19306 + cdev->brightness = LED_OFF;
19307 +
19308 +- cdev->brightness_set(cdev, cdev->brightness);
19309 ++ cdev->brightness_set_blocking(cdev, cdev->brightness);
19310 +
19311 + init_data.fwnode = of_fwnode_handle(np);
19312 +
19313 +diff --git a/drivers/macintosh/macio-adb.c b/drivers/macintosh/macio-adb.c
19314 +index 9b63bd2551c63..cd4e34d15c26b 100644
19315 +--- a/drivers/macintosh/macio-adb.c
19316 ++++ b/drivers/macintosh/macio-adb.c
19317 +@@ -108,6 +108,10 @@ int macio_init(void)
19318 + return -ENXIO;
19319 + }
19320 + adb = ioremap(r.start, sizeof(struct adb_regs));
19321 ++ if (!adb) {
19322 ++ of_node_put(adbs);
19323 ++ return -ENOMEM;
19324 ++ }
19325 +
19326 + out_8(&adb->ctrl.r, 0);
19327 + out_8(&adb->intr.r, 0);
19328 +diff --git a/drivers/macintosh/macio_asic.c b/drivers/macintosh/macio_asic.c
19329 +index 1ec1e5984563f..3bc1f374e6577 100644
19330 +--- a/drivers/macintosh/macio_asic.c
19331 ++++ b/drivers/macintosh/macio_asic.c
19332 +@@ -424,7 +424,7 @@ static struct macio_dev * macio_add_one_device(struct macio_chip *chip,
19333 + if (of_device_register(&dev->ofdev) != 0) {
19334 + printk(KERN_DEBUG"macio: device registration error for %s!\n",
19335 + dev_name(&dev->ofdev.dev));
19336 +- kfree(dev);
19337 ++ put_device(&dev->ofdev.dev);
19338 + return NULL;
19339 + }
19340 +
19341 +diff --git a/drivers/mailbox/arm_mhuv2.c b/drivers/mailbox/arm_mhuv2.c
19342 +index a47aef8df52fd..c6d4957c4da83 100644
19343 +--- a/drivers/mailbox/arm_mhuv2.c
19344 ++++ b/drivers/mailbox/arm_mhuv2.c
19345 +@@ -1062,8 +1062,8 @@ static int mhuv2_probe(struct amba_device *adev, const struct amba_id *id)
19346 + int ret = -EINVAL;
19347 +
19348 + reg = devm_of_iomap(dev, dev->of_node, 0, NULL);
19349 +- if (!reg)
19350 +- return -ENOMEM;
19351 ++ if (IS_ERR(reg))
19352 ++ return PTR_ERR(reg);
19353 +
19354 + mhu = devm_kzalloc(dev, sizeof(*mhu), GFP_KERNEL);
19355 + if (!mhu)
19356 +diff --git a/drivers/mailbox/mailbox-mpfs.c b/drivers/mailbox/mailbox-mpfs.c
19357 +index cfacb3f320a64..853901acaeec2 100644
19358 +--- a/drivers/mailbox/mailbox-mpfs.c
19359 ++++ b/drivers/mailbox/mailbox-mpfs.c
19360 +@@ -2,7 +2,7 @@
19361 + /*
19362 + * Microchip PolarFire SoC (MPFS) system controller/mailbox controller driver
19363 + *
19364 +- * Copyright (c) 2020 Microchip Corporation. All rights reserved.
19365 ++ * Copyright (c) 2020-2022 Microchip Corporation. All rights reserved.
19366 + *
19367 + * Author: Conor Dooley <conor.dooley@×××××××××.com>
19368 + *
19369 +@@ -56,7 +56,7 @@
19370 + #define SCB_STATUS_NOTIFY_MASK BIT(SCB_STATUS_NOTIFY)
19371 +
19372 + #define SCB_STATUS_POS (16)
19373 +-#define SCB_STATUS_MASK GENMASK_ULL(SCB_STATUS_POS + SCB_MASK_WIDTH, SCB_STATUS_POS)
19374 ++#define SCB_STATUS_MASK GENMASK(SCB_STATUS_POS + SCB_MASK_WIDTH - 1, SCB_STATUS_POS)
19375 +
19376 + struct mpfs_mbox {
19377 + struct mbox_controller controller;
19378 +@@ -130,13 +130,38 @@ static void mpfs_mbox_rx_data(struct mbox_chan *chan)
19379 + struct mpfs_mbox *mbox = (struct mpfs_mbox *)chan->con_priv;
19380 + struct mpfs_mss_response *response = mbox->response;
19381 + u16 num_words = ALIGN((response->resp_size), (4)) / 4U;
19382 +- u32 i;
19383 ++ u32 i, status;
19384 +
19385 + if (!response->resp_msg) {
19386 + dev_err(mbox->dev, "failed to assign memory for response %d\n", -ENOMEM);
19387 + return;
19388 + }
19389 +
19390 ++ /*
19391 ++ * The status is stored in bits 31:16 of the SERVICES_SR register.
19392 ++ * It is only valid when BUSY == 0.
19393 ++ * We should *never* get an interrupt while the controller is
19394 ++ * still in the busy state. If we do, something has gone badly
19395 ++ * wrong & the content of the mailbox would not be valid.
19396 ++ */
19397 ++ if (mpfs_mbox_busy(mbox)) {
19398 ++ dev_err(mbox->dev, "got an interrupt but system controller is busy\n");
19399 ++ response->resp_status = 0xDEAD;
19400 ++ return;
19401 ++ }
19402 ++
19403 ++ status = readl_relaxed(mbox->ctrl_base + SERVICES_SR_OFFSET);
19404 ++
19405 ++ /*
19406 ++ * If the status of the individual servers is non-zero, the service has
19407 ++ * failed. The contents of the mailbox at this point are not be valid,
19408 ++ * so don't bother reading them. Set the status so that the driver
19409 ++ * implementing the service can handle the result.
19410 ++ */
19411 ++ response->resp_status = (status & SCB_STATUS_MASK) >> SCB_STATUS_POS;
19412 ++ if (response->resp_status)
19413 ++ return;
19414 ++
19415 + if (!mpfs_mbox_busy(mbox)) {
19416 + for (i = 0; i < num_words; i++) {
19417 + response->resp_msg[i] =
19418 +diff --git a/drivers/mailbox/pcc.c b/drivers/mailbox/pcc.c
19419 +index ebfa33a40fceb..5e232b3fb72a9 100644
19420 +--- a/drivers/mailbox/pcc.c
19421 ++++ b/drivers/mailbox/pcc.c
19422 +@@ -743,6 +743,7 @@ static int __init pcc_init(void)
19423 +
19424 + if (IS_ERR(pcc_pdev)) {
19425 + pr_debug("Err creating PCC platform bundle\n");
19426 ++ pcc_chan_count = 0;
19427 + return PTR_ERR(pcc_pdev);
19428 + }
19429 +
19430 +diff --git a/drivers/mailbox/zynqmp-ipi-mailbox.c b/drivers/mailbox/zynqmp-ipi-mailbox.c
19431 +index 31a0fa9142744..12e004ff1a147 100644
19432 +--- a/drivers/mailbox/zynqmp-ipi-mailbox.c
19433 ++++ b/drivers/mailbox/zynqmp-ipi-mailbox.c
19434 +@@ -493,6 +493,7 @@ static int zynqmp_ipi_mbox_probe(struct zynqmp_ipi_mbox *ipi_mbox,
19435 + ret = device_register(&ipi_mbox->dev);
19436 + if (ret) {
19437 + dev_err(dev, "Failed to register ipi mbox dev.\n");
19438 ++ put_device(&ipi_mbox->dev);
19439 + return ret;
19440 + }
19441 + mdev = &ipi_mbox->dev;
19442 +@@ -619,7 +620,8 @@ static void zynqmp_ipi_free_mboxes(struct zynqmp_ipi_pdata *pdata)
19443 + ipi_mbox = &pdata->ipi_mboxes[i];
19444 + if (ipi_mbox->dev.parent) {
19445 + mbox_controller_unregister(&ipi_mbox->mbox);
19446 +- device_unregister(&ipi_mbox->dev);
19447 ++ if (device_is_registered(&ipi_mbox->dev))
19448 ++ device_unregister(&ipi_mbox->dev);
19449 + }
19450 + }
19451 + }
19452 +diff --git a/drivers/mcb/mcb-core.c b/drivers/mcb/mcb-core.c
19453 +index 338fc889b357a..b8ad4f16b4acd 100644
19454 +--- a/drivers/mcb/mcb-core.c
19455 ++++ b/drivers/mcb/mcb-core.c
19456 +@@ -71,8 +71,10 @@ static int mcb_probe(struct device *dev)
19457 +
19458 + get_device(dev);
19459 + ret = mdrv->probe(mdev, found_id);
19460 +- if (ret)
19461 ++ if (ret) {
19462 + module_put(carrier_mod);
19463 ++ put_device(dev);
19464 ++ }
19465 +
19466 + return ret;
19467 + }
19468 +diff --git a/drivers/mcb/mcb-parse.c b/drivers/mcb/mcb-parse.c
19469 +index 0266bfddfbe27..aa6938da0db85 100644
19470 +--- a/drivers/mcb/mcb-parse.c
19471 ++++ b/drivers/mcb/mcb-parse.c
19472 +@@ -108,7 +108,7 @@ static int chameleon_parse_gdd(struct mcb_bus *bus,
19473 + return 0;
19474 +
19475 + err:
19476 +- mcb_free_dev(mdev);
19477 ++ put_device(&mdev->dev);
19478 +
19479 + return ret;
19480 + }
19481 +diff --git a/drivers/md/dm.c b/drivers/md/dm.c
19482 +index b4a2cb5333fcc..bbde744f7dbaa 100644
19483 +--- a/drivers/md/dm.c
19484 ++++ b/drivers/md/dm.c
19485 +@@ -732,28 +732,48 @@ static char *_dm_claim_ptr = "I belong to device-mapper";
19486 + /*
19487 + * Open a table device so we can use it as a map destination.
19488 + */
19489 +-static int open_table_device(struct table_device *td, dev_t dev,
19490 +- struct mapped_device *md)
19491 ++static struct table_device *open_table_device(struct mapped_device *md,
19492 ++ dev_t dev, fmode_t mode)
19493 + {
19494 ++ struct table_device *td;
19495 + struct block_device *bdev;
19496 + u64 part_off;
19497 + int r;
19498 +
19499 +- BUG_ON(td->dm_dev.bdev);
19500 ++ td = kmalloc_node(sizeof(*td), GFP_KERNEL, md->numa_node_id);
19501 ++ if (!td)
19502 ++ return ERR_PTR(-ENOMEM);
19503 ++ refcount_set(&td->count, 1);
19504 +
19505 +- bdev = blkdev_get_by_dev(dev, td->dm_dev.mode | FMODE_EXCL, _dm_claim_ptr);
19506 +- if (IS_ERR(bdev))
19507 +- return PTR_ERR(bdev);
19508 ++ bdev = blkdev_get_by_dev(dev, mode | FMODE_EXCL, _dm_claim_ptr);
19509 ++ if (IS_ERR(bdev)) {
19510 ++ r = PTR_ERR(bdev);
19511 ++ goto out_free_td;
19512 ++ }
19513 +
19514 +- r = bd_link_disk_holder(bdev, dm_disk(md));
19515 +- if (r) {
19516 +- blkdev_put(bdev, td->dm_dev.mode | FMODE_EXCL);
19517 +- return r;
19518 ++ /*
19519 ++ * We can be called before the dm disk is added. In that case we can't
19520 ++ * register the holder relation here. It will be done once add_disk was
19521 ++ * called.
19522 ++ */
19523 ++ if (md->disk->slave_dir) {
19524 ++ r = bd_link_disk_holder(bdev, md->disk);
19525 ++ if (r)
19526 ++ goto out_blkdev_put;
19527 + }
19528 +
19529 ++ td->dm_dev.mode = mode;
19530 + td->dm_dev.bdev = bdev;
19531 + td->dm_dev.dax_dev = fs_dax_get_by_bdev(bdev, &part_off, NULL, NULL);
19532 +- return 0;
19533 ++ format_dev_t(td->dm_dev.name, dev);
19534 ++ list_add(&td->list, &md->table_devices);
19535 ++ return td;
19536 ++
19537 ++out_blkdev_put:
19538 ++ blkdev_put(bdev, mode | FMODE_EXCL);
19539 ++out_free_td:
19540 ++ kfree(td);
19541 ++ return ERR_PTR(r);
19542 + }
19543 +
19544 + /*
19545 +@@ -761,14 +781,12 @@ static int open_table_device(struct table_device *td, dev_t dev,
19546 + */
19547 + static void close_table_device(struct table_device *td, struct mapped_device *md)
19548 + {
19549 +- if (!td->dm_dev.bdev)
19550 +- return;
19551 +-
19552 +- bd_unlink_disk_holder(td->dm_dev.bdev, dm_disk(md));
19553 ++ if (md->disk->slave_dir)
19554 ++ bd_unlink_disk_holder(td->dm_dev.bdev, md->disk);
19555 + blkdev_put(td->dm_dev.bdev, td->dm_dev.mode | FMODE_EXCL);
19556 + put_dax(td->dm_dev.dax_dev);
19557 +- td->dm_dev.bdev = NULL;
19558 +- td->dm_dev.dax_dev = NULL;
19559 ++ list_del(&td->list);
19560 ++ kfree(td);
19561 + }
19562 +
19563 + static struct table_device *find_table_device(struct list_head *l, dev_t dev,
19564 +@@ -786,31 +804,16 @@ static struct table_device *find_table_device(struct list_head *l, dev_t dev,
19565 + int dm_get_table_device(struct mapped_device *md, dev_t dev, fmode_t mode,
19566 + struct dm_dev **result)
19567 + {
19568 +- int r;
19569 + struct table_device *td;
19570 +
19571 + mutex_lock(&md->table_devices_lock);
19572 + td = find_table_device(&md->table_devices, dev, mode);
19573 + if (!td) {
19574 +- td = kmalloc_node(sizeof(*td), GFP_KERNEL, md->numa_node_id);
19575 +- if (!td) {
19576 ++ td = open_table_device(md, dev, mode);
19577 ++ if (IS_ERR(td)) {
19578 + mutex_unlock(&md->table_devices_lock);
19579 +- return -ENOMEM;
19580 ++ return PTR_ERR(td);
19581 + }
19582 +-
19583 +- td->dm_dev.mode = mode;
19584 +- td->dm_dev.bdev = NULL;
19585 +-
19586 +- if ((r = open_table_device(td, dev, md))) {
19587 +- mutex_unlock(&md->table_devices_lock);
19588 +- kfree(td);
19589 +- return r;
19590 +- }
19591 +-
19592 +- format_dev_t(td->dm_dev.name, dev);
19593 +-
19594 +- refcount_set(&td->count, 1);
19595 +- list_add(&td->list, &md->table_devices);
19596 + } else {
19597 + refcount_inc(&td->count);
19598 + }
19599 +@@ -825,11 +828,8 @@ void dm_put_table_device(struct mapped_device *md, struct dm_dev *d)
19600 + struct table_device *td = container_of(d, struct table_device, dm_dev);
19601 +
19602 + mutex_lock(&md->table_devices_lock);
19603 +- if (refcount_dec_and_test(&td->count)) {
19604 ++ if (refcount_dec_and_test(&td->count))
19605 + close_table_device(td, md);
19606 +- list_del(&td->list);
19607 +- kfree(td);
19608 +- }
19609 + mutex_unlock(&md->table_devices_lock);
19610 + }
19611 +
19612 +@@ -1972,8 +1972,21 @@ static void cleanup_mapped_device(struct mapped_device *md)
19613 + md->disk->private_data = NULL;
19614 + spin_unlock(&_minor_lock);
19615 + if (dm_get_md_type(md) != DM_TYPE_NONE) {
19616 ++ struct table_device *td;
19617 ++
19618 + dm_sysfs_exit(md);
19619 ++ list_for_each_entry(td, &md->table_devices, list) {
19620 ++ bd_unlink_disk_holder(td->dm_dev.bdev,
19621 ++ md->disk);
19622 ++ }
19623 ++
19624 ++ /*
19625 ++ * Hold lock to make sure del_gendisk() won't concurrent
19626 ++ * with open/close_table_device().
19627 ++ */
19628 ++ mutex_lock(&md->table_devices_lock);
19629 + del_gendisk(md->disk);
19630 ++ mutex_unlock(&md->table_devices_lock);
19631 + }
19632 + dm_queue_destroy_crypto_profile(md->queue);
19633 + put_disk(md->disk);
19634 +@@ -2305,6 +2318,7 @@ int dm_setup_md_queue(struct mapped_device *md, struct dm_table *t)
19635 + {
19636 + enum dm_queue_mode type = dm_table_get_type(t);
19637 + struct queue_limits limits;
19638 ++ struct table_device *td;
19639 + int r;
19640 +
19641 + switch (type) {
19642 +@@ -2333,17 +2347,40 @@ int dm_setup_md_queue(struct mapped_device *md, struct dm_table *t)
19643 + if (r)
19644 + return r;
19645 +
19646 ++ /*
19647 ++ * Hold lock to make sure add_disk() and del_gendisk() won't concurrent
19648 ++ * with open_table_device() and close_table_device().
19649 ++ */
19650 ++ mutex_lock(&md->table_devices_lock);
19651 + r = add_disk(md->disk);
19652 ++ mutex_unlock(&md->table_devices_lock);
19653 + if (r)
19654 + return r;
19655 +
19656 +- r = dm_sysfs_init(md);
19657 +- if (r) {
19658 +- del_gendisk(md->disk);
19659 +- return r;
19660 ++ /*
19661 ++ * Register the holder relationship for devices added before the disk
19662 ++ * was live.
19663 ++ */
19664 ++ list_for_each_entry(td, &md->table_devices, list) {
19665 ++ r = bd_link_disk_holder(td->dm_dev.bdev, md->disk);
19666 ++ if (r)
19667 ++ goto out_undo_holders;
19668 + }
19669 ++
19670 ++ r = dm_sysfs_init(md);
19671 ++ if (r)
19672 ++ goto out_undo_holders;
19673 ++
19674 + md->type = type;
19675 + return 0;
19676 ++
19677 ++out_undo_holders:
19678 ++ list_for_each_entry_continue_reverse(td, &md->table_devices, list)
19679 ++ bd_unlink_disk_holder(td->dm_dev.bdev, md->disk);
19680 ++ mutex_lock(&md->table_devices_lock);
19681 ++ del_gendisk(md->disk);
19682 ++ mutex_unlock(&md->table_devices_lock);
19683 ++ return r;
19684 + }
19685 +
19686 + struct mapped_device *dm_get_md(dev_t dev)
19687 +diff --git a/drivers/md/md-bitmap.c b/drivers/md/md-bitmap.c
19688 +index bf6dffadbe6f6..63ece30114e53 100644
19689 +--- a/drivers/md/md-bitmap.c
19690 ++++ b/drivers/md/md-bitmap.c
19691 +@@ -2195,20 +2195,23 @@ int md_bitmap_resize(struct bitmap *bitmap, sector_t blocks,
19692 +
19693 + if (set) {
19694 + bmc_new = md_bitmap_get_counter(&bitmap->counts, block, &new_blocks, 1);
19695 +- if (*bmc_new == 0) {
19696 +- /* need to set on-disk bits too. */
19697 +- sector_t end = block + new_blocks;
19698 +- sector_t start = block >> chunkshift;
19699 +- start <<= chunkshift;
19700 +- while (start < end) {
19701 +- md_bitmap_file_set_bit(bitmap, block);
19702 +- start += 1 << chunkshift;
19703 ++ if (bmc_new) {
19704 ++ if (*bmc_new == 0) {
19705 ++ /* need to set on-disk bits too. */
19706 ++ sector_t end = block + new_blocks;
19707 ++ sector_t start = block >> chunkshift;
19708 ++
19709 ++ start <<= chunkshift;
19710 ++ while (start < end) {
19711 ++ md_bitmap_file_set_bit(bitmap, block);
19712 ++ start += 1 << chunkshift;
19713 ++ }
19714 ++ *bmc_new = 2;
19715 ++ md_bitmap_count_page(&bitmap->counts, block, 1);
19716 ++ md_bitmap_set_pending(&bitmap->counts, block);
19717 + }
19718 +- *bmc_new = 2;
19719 +- md_bitmap_count_page(&bitmap->counts, block, 1);
19720 +- md_bitmap_set_pending(&bitmap->counts, block);
19721 ++ *bmc_new |= NEEDED_MASK;
19722 + }
19723 +- *bmc_new |= NEEDED_MASK;
19724 + if (new_blocks < old_blocks)
19725 + old_blocks = new_blocks;
19726 + }
19727 +diff --git a/drivers/md/raid0.c b/drivers/md/raid0.c
19728 +index 857c49399c28e..b536befd88988 100644
19729 +--- a/drivers/md/raid0.c
19730 ++++ b/drivers/md/raid0.c
19731 +@@ -398,7 +398,6 @@ static int raid0_run(struct mddev *mddev)
19732 +
19733 + blk_queue_max_hw_sectors(mddev->queue, mddev->chunk_sectors);
19734 + blk_queue_max_write_zeroes_sectors(mddev->queue, mddev->chunk_sectors);
19735 +- blk_queue_max_discard_sectors(mddev->queue, UINT_MAX);
19736 +
19737 + blk_queue_io_min(mddev->queue, mddev->chunk_sectors << 9);
19738 + blk_queue_io_opt(mddev->queue,
19739 +diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
19740 +index 05d8438cfec88..58f705f429480 100644
19741 +--- a/drivers/md/raid1.c
19742 ++++ b/drivers/md/raid1.c
19743 +@@ -3159,6 +3159,7 @@ static int raid1_run(struct mddev *mddev)
19744 + * RAID1 needs at least one disk in active
19745 + */
19746 + if (conf->raid_disks - mddev->degraded < 1) {
19747 ++ md_unregister_thread(&conf->thread);
19748 + ret = -EINVAL;
19749 + goto abort;
19750 + }
19751 +diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
19752 +index 64d6e4cd8a3a0..b19c6ce89d5ea 100644
19753 +--- a/drivers/md/raid10.c
19754 ++++ b/drivers/md/raid10.c
19755 +@@ -4104,8 +4104,6 @@ static int raid10_run(struct mddev *mddev)
19756 + conf->thread = NULL;
19757 +
19758 + if (mddev->queue) {
19759 +- blk_queue_max_discard_sectors(mddev->queue,
19760 +- UINT_MAX);
19761 + blk_queue_max_write_zeroes_sectors(mddev->queue, 0);
19762 + blk_queue_io_min(mddev->queue, mddev->chunk_sectors << 9);
19763 + raid10_set_io_opt(conf);
19764 +diff --git a/drivers/media/dvb-core/dvb_ca_en50221.c b/drivers/media/dvb-core/dvb_ca_en50221.c
19765 +index 15a08d8c69ef8..c2d2792227f86 100644
19766 +--- a/drivers/media/dvb-core/dvb_ca_en50221.c
19767 ++++ b/drivers/media/dvb-core/dvb_ca_en50221.c
19768 +@@ -157,7 +157,7 @@ static void dvb_ca_private_free(struct dvb_ca_private *ca)
19769 + {
19770 + unsigned int i;
19771 +
19772 +- dvb_free_device(ca->dvbdev);
19773 ++ dvb_device_put(ca->dvbdev);
19774 + for (i = 0; i < ca->slot_count; i++)
19775 + vfree(ca->slot_info[i].rx_buffer.data);
19776 +
19777 +diff --git a/drivers/media/dvb-core/dvb_frontend.c b/drivers/media/dvb-core/dvb_frontend.c
19778 +index 48e735cdbe6bb..c41a7e5c2b928 100644
19779 +--- a/drivers/media/dvb-core/dvb_frontend.c
19780 ++++ b/drivers/media/dvb-core/dvb_frontend.c
19781 +@@ -136,7 +136,7 @@ static void __dvb_frontend_free(struct dvb_frontend *fe)
19782 + struct dvb_frontend_private *fepriv = fe->frontend_priv;
19783 +
19784 + if (fepriv)
19785 +- dvb_free_device(fepriv->dvbdev);
19786 ++ dvb_device_put(fepriv->dvbdev);
19787 +
19788 + dvb_frontend_invoke_release(fe, fe->ops.release);
19789 +
19790 +@@ -2986,6 +2986,7 @@ int dvb_register_frontend(struct dvb_adapter *dvb,
19791 + .name = fe->ops.info.name,
19792 + #endif
19793 + };
19794 ++ int ret;
19795 +
19796 + dev_dbg(dvb->device, "%s:\n", __func__);
19797 +
19798 +@@ -3019,8 +3020,13 @@ int dvb_register_frontend(struct dvb_adapter *dvb,
19799 + "DVB: registering adapter %i frontend %i (%s)...\n",
19800 + fe->dvb->num, fe->id, fe->ops.info.name);
19801 +
19802 +- dvb_register_device(fe->dvb, &fepriv->dvbdev, &dvbdev_template,
19803 ++ ret = dvb_register_device(fe->dvb, &fepriv->dvbdev, &dvbdev_template,
19804 + fe, DVB_DEVICE_FRONTEND, 0);
19805 ++ if (ret) {
19806 ++ dvb_frontend_put(fe);
19807 ++ mutex_unlock(&frontend_mutex);
19808 ++ return ret;
19809 ++ }
19810 +
19811 + /*
19812 + * Initialize the cache to the proper values according with the
19813 +diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
19814 +index 675d877a67b25..9934728734af9 100644
19815 +--- a/drivers/media/dvb-core/dvbdev.c
19816 ++++ b/drivers/media/dvb-core/dvbdev.c
19817 +@@ -97,7 +97,7 @@ static int dvb_device_open(struct inode *inode, struct file *file)
19818 + new_fops = fops_get(dvbdev->fops);
19819 + if (!new_fops)
19820 + goto fail;
19821 +- file->private_data = dvbdev;
19822 ++ file->private_data = dvb_device_get(dvbdev);
19823 + replace_fops(file, new_fops);
19824 + if (file->f_op->open)
19825 + err = file->f_op->open(inode, file);
19826 +@@ -161,6 +161,9 @@ int dvb_generic_release(struct inode *inode, struct file *file)
19827 + }
19828 +
19829 + dvbdev->users++;
19830 ++
19831 ++ dvb_device_put(dvbdev);
19832 ++
19833 + return 0;
19834 + }
19835 + EXPORT_SYMBOL(dvb_generic_release);
19836 +@@ -478,6 +481,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
19837 + }
19838 +
19839 + memcpy(dvbdev, template, sizeof(struct dvb_device));
19840 ++ kref_init(&dvbdev->ref);
19841 + dvbdev->type = type;
19842 + dvbdev->id = id;
19843 + dvbdev->adapter = adap;
19844 +@@ -508,7 +512,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
19845 + #endif
19846 +
19847 + dvbdev->minor = minor;
19848 +- dvb_minors[minor] = dvbdev;
19849 ++ dvb_minors[minor] = dvb_device_get(dvbdev);
19850 + up_write(&minor_rwsem);
19851 +
19852 + ret = dvb_register_media_device(dvbdev, type, minor, demux_sink_pads);
19853 +@@ -553,6 +557,7 @@ void dvb_remove_device(struct dvb_device *dvbdev)
19854 +
19855 + down_write(&minor_rwsem);
19856 + dvb_minors[dvbdev->minor] = NULL;
19857 ++ dvb_device_put(dvbdev);
19858 + up_write(&minor_rwsem);
19859 +
19860 + dvb_media_device_free(dvbdev);
19861 +@@ -564,21 +569,34 @@ void dvb_remove_device(struct dvb_device *dvbdev)
19862 + EXPORT_SYMBOL(dvb_remove_device);
19863 +
19864 +
19865 +-void dvb_free_device(struct dvb_device *dvbdev)
19866 ++static void dvb_free_device(struct kref *ref)
19867 + {
19868 +- if (!dvbdev)
19869 +- return;
19870 ++ struct dvb_device *dvbdev = container_of(ref, struct dvb_device, ref);
19871 +
19872 + kfree (dvbdev->fops);
19873 + kfree (dvbdev);
19874 + }
19875 +-EXPORT_SYMBOL(dvb_free_device);
19876 ++
19877 ++
19878 ++struct dvb_device *dvb_device_get(struct dvb_device *dvbdev)
19879 ++{
19880 ++ kref_get(&dvbdev->ref);
19881 ++ return dvbdev;
19882 ++}
19883 ++EXPORT_SYMBOL(dvb_device_get);
19884 ++
19885 ++
19886 ++void dvb_device_put(struct dvb_device *dvbdev)
19887 ++{
19888 ++ if (dvbdev)
19889 ++ kref_put(&dvbdev->ref, dvb_free_device);
19890 ++}
19891 +
19892 +
19893 + void dvb_unregister_device(struct dvb_device *dvbdev)
19894 + {
19895 + dvb_remove_device(dvbdev);
19896 +- dvb_free_device(dvbdev);
19897 ++ dvb_device_put(dvbdev);
19898 + }
19899 + EXPORT_SYMBOL(dvb_unregister_device);
19900 +
19901 +diff --git a/drivers/media/dvb-frontends/bcm3510.c b/drivers/media/dvb-frontends/bcm3510.c
19902 +index da0ff7b44da41..68b92b4419cff 100644
19903 +--- a/drivers/media/dvb-frontends/bcm3510.c
19904 ++++ b/drivers/media/dvb-frontends/bcm3510.c
19905 +@@ -649,6 +649,7 @@ static int bcm3510_download_firmware(struct dvb_frontend* fe)
19906 + deb_info("firmware chunk, addr: 0x%04x, len: 0x%04x, total length: 0x%04zx\n",addr,len,fw->size);
19907 + if ((ret = bcm3510_write_ram(st,addr,&b[i+4],len)) < 0) {
19908 + err("firmware download failed: %d\n",ret);
19909 ++ release_firmware(fw);
19910 + return ret;
19911 + }
19912 + i += 4 + len;
19913 +diff --git a/drivers/media/i2c/ad5820.c b/drivers/media/i2c/ad5820.c
19914 +index 2958a46944614..07639ecc85aa8 100644
19915 +--- a/drivers/media/i2c/ad5820.c
19916 ++++ b/drivers/media/i2c/ad5820.c
19917 +@@ -327,18 +327,18 @@ static int ad5820_probe(struct i2c_client *client,
19918 +
19919 + ret = media_entity_pads_init(&coil->subdev.entity, 0, NULL);
19920 + if (ret < 0)
19921 +- goto cleanup2;
19922 ++ goto clean_mutex;
19923 +
19924 + ret = v4l2_async_register_subdev(&coil->subdev);
19925 + if (ret < 0)
19926 +- goto cleanup;
19927 ++ goto clean_entity;
19928 +
19929 + return ret;
19930 +
19931 +-cleanup2:
19932 +- mutex_destroy(&coil->power_lock);
19933 +-cleanup:
19934 ++clean_entity:
19935 + media_entity_cleanup(&coil->subdev.entity);
19936 ++clean_mutex:
19937 ++ mutex_destroy(&coil->power_lock);
19938 + return ret;
19939 + }
19940 +
19941 +diff --git a/drivers/media/i2c/adv748x/adv748x-afe.c b/drivers/media/i2c/adv748x/adv748x-afe.c
19942 +index 02eabe10ab970..00095c7762c24 100644
19943 +--- a/drivers/media/i2c/adv748x/adv748x-afe.c
19944 ++++ b/drivers/media/i2c/adv748x/adv748x-afe.c
19945 +@@ -521,6 +521,10 @@ int adv748x_afe_init(struct adv748x_afe *afe)
19946 + }
19947 + }
19948 +
19949 ++ adv748x_afe_s_input(afe, afe->input);
19950 ++
19951 ++ adv_dbg(state, "AFE Default input set to %d\n", afe->input);
19952 ++
19953 + /* Entity pads and sinks are 0-indexed to match the pads */
19954 + for (i = ADV748X_AFE_SINK_AIN0; i <= ADV748X_AFE_SINK_AIN7; i++)
19955 + afe->pads[i].flags = MEDIA_PAD_FL_SINK;
19956 +diff --git a/drivers/media/i2c/dw9768.c b/drivers/media/i2c/dw9768.c
19957 +index c086580efac78..60ae0adf51744 100644
19958 +--- a/drivers/media/i2c/dw9768.c
19959 ++++ b/drivers/media/i2c/dw9768.c
19960 +@@ -414,6 +414,7 @@ static int dw9768_probe(struct i2c_client *client)
19961 + {
19962 + struct device *dev = &client->dev;
19963 + struct dw9768 *dw9768;
19964 ++ bool full_power;
19965 + unsigned int i;
19966 + int ret;
19967 +
19968 +@@ -469,13 +470,23 @@ static int dw9768_probe(struct i2c_client *client)
19969 +
19970 + dw9768->sd.entity.function = MEDIA_ENT_F_LENS;
19971 +
19972 ++ /*
19973 ++ * Figure out whether we're going to power up the device here. Generally
19974 ++ * this is done if CONFIG_PM is disabled in a DT system or the device is
19975 ++ * to be powered on in an ACPI system. Similarly for power off in
19976 ++ * remove.
19977 ++ */
19978 + pm_runtime_enable(dev);
19979 +- if (!pm_runtime_enabled(dev)) {
19980 ++ full_power = (is_acpi_node(dev_fwnode(dev)) &&
19981 ++ acpi_dev_state_d0(dev)) ||
19982 ++ (is_of_node(dev_fwnode(dev)) && !pm_runtime_enabled(dev));
19983 ++ if (full_power) {
19984 + ret = dw9768_runtime_resume(dev);
19985 + if (ret < 0) {
19986 + dev_err(dev, "failed to power on: %d\n", ret);
19987 + goto err_clean_entity;
19988 + }
19989 ++ pm_runtime_set_active(dev);
19990 + }
19991 +
19992 + ret = v4l2_async_register_subdev(&dw9768->sd);
19993 +@@ -484,14 +495,17 @@ static int dw9768_probe(struct i2c_client *client)
19994 + goto err_power_off;
19995 + }
19996 +
19997 ++ pm_runtime_idle(dev);
19998 ++
19999 + return 0;
20000 +
20001 + err_power_off:
20002 +- if (pm_runtime_enabled(dev))
20003 +- pm_runtime_disable(dev);
20004 +- else
20005 ++ if (full_power) {
20006 + dw9768_runtime_suspend(dev);
20007 ++ pm_runtime_set_suspended(dev);
20008 ++ }
20009 + err_clean_entity:
20010 ++ pm_runtime_disable(dev);
20011 + media_entity_cleanup(&dw9768->sd.entity);
20012 + err_free_handler:
20013 + v4l2_ctrl_handler_free(&dw9768->ctrls);
20014 +@@ -503,14 +517,17 @@ static int dw9768_remove(struct i2c_client *client)
20015 + {
20016 + struct v4l2_subdev *sd = i2c_get_clientdata(client);
20017 + struct dw9768 *dw9768 = sd_to_dw9768(sd);
20018 ++ struct device *dev = &client->dev;
20019 +
20020 + v4l2_async_unregister_subdev(&dw9768->sd);
20021 + v4l2_ctrl_handler_free(&dw9768->ctrls);
20022 + media_entity_cleanup(&dw9768->sd.entity);
20023 +- pm_runtime_disable(&client->dev);
20024 +- if (!pm_runtime_status_suspended(&client->dev))
20025 +- dw9768_runtime_suspend(&client->dev);
20026 +- pm_runtime_set_suspended(&client->dev);
20027 ++ if ((is_acpi_node(dev_fwnode(dev)) && acpi_dev_state_d0(dev)) ||
20028 ++ (is_of_node(dev_fwnode(dev)) && !pm_runtime_enabled(dev))) {
20029 ++ dw9768_runtime_suspend(dev);
20030 ++ pm_runtime_set_suspended(dev);
20031 ++ }
20032 ++ pm_runtime_disable(dev);
20033 +
20034 + return 0;
20035 + }
20036 +diff --git a/drivers/media/i2c/hi846.c b/drivers/media/i2c/hi846.c
20037 +index ad35c3ff36115..254031503c728 100644
20038 +--- a/drivers/media/i2c/hi846.c
20039 ++++ b/drivers/media/i2c/hi846.c
20040 +@@ -2008,22 +2008,24 @@ static int hi846_parse_dt(struct hi846 *hi846, struct device *dev)
20041 + bus_cfg.bus.mipi_csi2.num_data_lanes != 4) {
20042 + dev_err(dev, "number of CSI2 data lanes %d is not supported",
20043 + bus_cfg.bus.mipi_csi2.num_data_lanes);
20044 +- v4l2_fwnode_endpoint_free(&bus_cfg);
20045 +- return -EINVAL;
20046 ++ ret = -EINVAL;
20047 ++ goto check_hwcfg_error;
20048 + }
20049 +
20050 + hi846->nr_lanes = bus_cfg.bus.mipi_csi2.num_data_lanes;
20051 +
20052 + if (!bus_cfg.nr_of_link_frequencies) {
20053 + dev_err(dev, "link-frequency property not found in DT\n");
20054 +- return -EINVAL;
20055 ++ ret = -EINVAL;
20056 ++ goto check_hwcfg_error;
20057 + }
20058 +
20059 + /* Check that link frequences for all the modes are in device tree */
20060 + fq = hi846_check_link_freqs(hi846, &bus_cfg);
20061 + if (fq) {
20062 + dev_err(dev, "Link frequency of %lld is not supported\n", fq);
20063 +- return -EINVAL;
20064 ++ ret = -EINVAL;
20065 ++ goto check_hwcfg_error;
20066 + }
20067 +
20068 + v4l2_fwnode_endpoint_free(&bus_cfg);
20069 +@@ -2044,6 +2046,10 @@ static int hi846_parse_dt(struct hi846 *hi846, struct device *dev)
20070 + }
20071 +
20072 + return 0;
20073 ++
20074 ++check_hwcfg_error:
20075 ++ v4l2_fwnode_endpoint_free(&bus_cfg);
20076 ++ return ret;
20077 + }
20078 +
20079 + static int hi846_probe(struct i2c_client *client)
20080 +diff --git a/drivers/media/i2c/mt9p031.c b/drivers/media/i2c/mt9p031.c
20081 +index 1fd4dc6e4726f..92f4e184353f8 100644
20082 +--- a/drivers/media/i2c/mt9p031.c
20083 ++++ b/drivers/media/i2c/mt9p031.c
20084 +@@ -702,7 +702,6 @@ static int mt9p031_init_cfg(struct v4l2_subdev *subdev,
20085 + V4L2_SUBDEV_FORMAT_TRY;
20086 +
20087 + crop = __mt9p031_get_pad_crop(mt9p031, sd_state, 0, which);
20088 +- v4l2_subdev_get_try_crop(subdev, sd_state, 0);
20089 + crop->left = MT9P031_COLUMN_START_DEF;
20090 + crop->top = MT9P031_ROW_START_DEF;
20091 + crop->width = MT9P031_WINDOW_WIDTH_DEF;
20092 +diff --git a/drivers/media/i2c/ov5640.c b/drivers/media/i2c/ov5640.c
20093 +index 502f0b62e9505..7e72e7c7b0ddc 100644
20094 +--- a/drivers/media/i2c/ov5640.c
20095 ++++ b/drivers/media/i2c/ov5640.c
20096 +@@ -3816,7 +3816,8 @@ static int ov5640_probe(struct i2c_client *client)
20097 + sensor->current_mode =
20098 + &ov5640_mode_data[OV5640_MODE_VGA_640_480];
20099 + sensor->last_mode = sensor->current_mode;
20100 +- sensor->current_link_freq = OV5640_DEFAULT_LINK_FREQ;
20101 ++ sensor->current_link_freq =
20102 ++ ov5640_csi2_link_freqs[OV5640_DEFAULT_LINK_FREQ];
20103 +
20104 + sensor->ae_target = 52;
20105 +
20106 +diff --git a/drivers/media/i2c/ov5648.c b/drivers/media/i2c/ov5648.c
20107 +index dfcd33e9ee136..220c53565b0a7 100644
20108 +--- a/drivers/media/i2c/ov5648.c
20109 ++++ b/drivers/media/i2c/ov5648.c
20110 +@@ -2597,6 +2597,7 @@ static int ov5648_remove(struct i2c_client *client)
20111 + v4l2_ctrl_handler_free(&sensor->ctrls.handler);
20112 + mutex_destroy(&sensor->mutex);
20113 + media_entity_cleanup(&subdev->entity);
20114 ++ v4l2_fwnode_endpoint_free(&sensor->endpoint);
20115 +
20116 + return 0;
20117 + }
20118 +diff --git a/drivers/media/pci/saa7164/saa7164-core.c b/drivers/media/pci/saa7164/saa7164-core.c
20119 +index 7973ae42873a6..c10997e2271d2 100644
20120 +--- a/drivers/media/pci/saa7164/saa7164-core.c
20121 ++++ b/drivers/media/pci/saa7164/saa7164-core.c
20122 +@@ -1259,7 +1259,7 @@ static int saa7164_initdev(struct pci_dev *pci_dev,
20123 +
20124 + if (saa7164_dev_setup(dev) < 0) {
20125 + err = -EINVAL;
20126 +- goto fail_free;
20127 ++ goto fail_dev;
20128 + }
20129 +
20130 + /* print pci info */
20131 +@@ -1427,6 +1427,8 @@ fail_fw:
20132 +
20133 + fail_irq:
20134 + saa7164_dev_unregister(dev);
20135 ++fail_dev:
20136 ++ pci_disable_device(pci_dev);
20137 + fail_free:
20138 + v4l2_device_unregister(&dev->v4l2_dev);
20139 + kfree(dev);
20140 +diff --git a/drivers/media/pci/solo6x10/solo6x10-core.c b/drivers/media/pci/solo6x10/solo6x10-core.c
20141 +index 4a546eeefe38f..6d87fbb0ee04a 100644
20142 +--- a/drivers/media/pci/solo6x10/solo6x10-core.c
20143 ++++ b/drivers/media/pci/solo6x10/solo6x10-core.c
20144 +@@ -420,6 +420,7 @@ static int solo_sysfs_init(struct solo_dev *solo_dev)
20145 + solo_dev->nr_chans);
20146 +
20147 + if (device_register(dev)) {
20148 ++ put_device(dev);
20149 + dev->parent = NULL;
20150 + return -ENOMEM;
20151 + }
20152 +diff --git a/drivers/media/platform/amphion/vdec.c b/drivers/media/platform/amphion/vdec.c
20153 +index feb75dc204de8..b27e6bed85f0f 100644
20154 +--- a/drivers/media/platform/amphion/vdec.c
20155 ++++ b/drivers/media/platform/amphion/vdec.c
20156 +@@ -286,6 +286,7 @@ static int vdec_g_fmt(struct file *file, void *fh, struct v4l2_format *f)
20157 + struct vpu_format *cur_fmt;
20158 + int i;
20159 +
20160 ++ vpu_inst_lock(inst);
20161 + cur_fmt = vpu_get_format(inst, f->type);
20162 +
20163 + pixmp->pixelformat = cur_fmt->pixfmt;
20164 +@@ -303,6 +304,7 @@ static int vdec_g_fmt(struct file *file, void *fh, struct v4l2_format *f)
20165 + f->fmt.pix_mp.xfer_func = vdec->codec_info.transfer_chars;
20166 + f->fmt.pix_mp.ycbcr_enc = vdec->codec_info.matrix_coeffs;
20167 + f->fmt.pix_mp.quantization = vdec->codec_info.full_range;
20168 ++ vpu_inst_unlock(inst);
20169 +
20170 + return 0;
20171 + }
20172 +@@ -753,6 +755,9 @@ static bool vdec_check_source_change(struct vpu_inst *inst)
20173 + if (!inst->fh.m2m_ctx)
20174 + return false;
20175 +
20176 ++ if (vdec->reset_codec)
20177 ++ return false;
20178 ++
20179 + if (!vb2_is_streaming(v4l2_m2m_get_dst_vq(inst->fh.m2m_ctx)))
20180 + return true;
20181 + fmt = vpu_helper_find_format(inst, inst->cap_format.type, vdec->codec_info.pixfmt);
20182 +@@ -1088,7 +1093,8 @@ static void vdec_event_seq_hdr(struct vpu_inst *inst, struct vpu_dec_codec_info
20183 + vdec->seq_tag = vdec->codec_info.tag;
20184 + if (vdec->is_source_changed) {
20185 + vdec_update_state(inst, VPU_CODEC_STATE_DYAMIC_RESOLUTION_CHANGE, 0);
20186 +- vpu_notify_source_change(inst);
20187 ++ vdec->source_change++;
20188 ++ vdec_handle_resolution_change(inst);
20189 + vdec->is_source_changed = false;
20190 + }
20191 + }
20192 +@@ -1335,6 +1341,8 @@ static void vdec_abort(struct vpu_inst *inst)
20193 + vdec->decoded_frame_count,
20194 + vdec->display_frame_count,
20195 + vdec->sequence);
20196 ++ if (!vdec->seq_hdr_found)
20197 ++ vdec->reset_codec = true;
20198 + vdec->params.end_flag = 0;
20199 + vdec->drain = 0;
20200 + vdec->params.frame_count = 0;
20201 +@@ -1342,6 +1350,7 @@ static void vdec_abort(struct vpu_inst *inst)
20202 + vdec->display_frame_count = 0;
20203 + vdec->sequence = 0;
20204 + vdec->aborting = false;
20205 ++ inst->extra_size = 0;
20206 + }
20207 +
20208 + static void vdec_stop(struct vpu_inst *inst, bool free)
20209 +@@ -1464,8 +1473,7 @@ static int vdec_start_session(struct vpu_inst *inst, u32 type)
20210 + }
20211 +
20212 + if (V4L2_TYPE_IS_OUTPUT(type)) {
20213 +- if (inst->state == VPU_CODEC_STATE_SEEK)
20214 +- vdec_update_state(inst, vdec->state, 1);
20215 ++ vdec_update_state(inst, vdec->state, 1);
20216 + vdec->eos_received = 0;
20217 + vpu_process_output_buffer(inst);
20218 + } else {
20219 +@@ -1629,6 +1637,7 @@ static int vdec_open(struct file *file)
20220 + return ret;
20221 +
20222 + vdec->fixed_fmt = false;
20223 ++ vdec->state = VPU_CODEC_STATE_ACTIVE;
20224 + inst->min_buffer_cap = VDEC_MIN_BUFFER_CAP;
20225 + inst->min_buffer_out = VDEC_MIN_BUFFER_OUT;
20226 + vdec_init(file);
20227 +diff --git a/drivers/media/platform/amphion/vpu.h b/drivers/media/platform/amphion/vpu.h
20228 +index beac0309ca8d9..048c23c2bf4db 100644
20229 +--- a/drivers/media/platform/amphion/vpu.h
20230 ++++ b/drivers/media/platform/amphion/vpu.h
20231 +@@ -13,6 +13,7 @@
20232 + #include <linux/mailbox_controller.h>
20233 + #include <linux/kfifo.h>
20234 +
20235 ++#define VPU_TIMEOUT_WAKEUP msecs_to_jiffies(200)
20236 + #define VPU_TIMEOUT msecs_to_jiffies(1000)
20237 + #define VPU_INST_NULL_ID (-1L)
20238 + #define VPU_MSG_BUFFER_SIZE (8192)
20239 +diff --git a/drivers/media/platform/amphion/vpu_cmds.c b/drivers/media/platform/amphion/vpu_cmds.c
20240 +index f4d7ca78a6212..fa581ba6bab2d 100644
20241 +--- a/drivers/media/platform/amphion/vpu_cmds.c
20242 ++++ b/drivers/media/platform/amphion/vpu_cmds.c
20243 +@@ -269,7 +269,7 @@ exit:
20244 + return flag;
20245 + }
20246 +
20247 +-static int sync_session_response(struct vpu_inst *inst, unsigned long key)
20248 ++static int sync_session_response(struct vpu_inst *inst, unsigned long key, long timeout, int try)
20249 + {
20250 + struct vpu_core *core;
20251 +
20252 +@@ -279,10 +279,12 @@ static int sync_session_response(struct vpu_inst *inst, unsigned long key)
20253 + core = inst->core;
20254 +
20255 + call_void_vop(inst, wait_prepare);
20256 +- wait_event_timeout(core->ack_wq, check_is_responsed(inst, key), VPU_TIMEOUT);
20257 ++ wait_event_timeout(core->ack_wq, check_is_responsed(inst, key), timeout);
20258 + call_void_vop(inst, wait_finish);
20259 +
20260 + if (!check_is_responsed(inst, key)) {
20261 ++ if (try)
20262 ++ return -EINVAL;
20263 + dev_err(inst->dev, "[%d] sync session timeout\n", inst->id);
20264 + set_bit(inst->id, &core->hang_mask);
20265 + mutex_lock(&inst->core->cmd_lock);
20266 +@@ -294,6 +296,19 @@ static int sync_session_response(struct vpu_inst *inst, unsigned long key)
20267 + return 0;
20268 + }
20269 +
20270 ++static void vpu_core_keep_active(struct vpu_core *core)
20271 ++{
20272 ++ struct vpu_rpc_event pkt;
20273 ++
20274 ++ memset(&pkt, 0, sizeof(pkt));
20275 ++ vpu_iface_pack_cmd(core, &pkt, 0, VPU_CMD_ID_NOOP, NULL);
20276 ++
20277 ++ dev_dbg(core->dev, "try to wake up\n");
20278 ++ mutex_lock(&core->cmd_lock);
20279 ++ vpu_cmd_send(core, &pkt);
20280 ++ mutex_unlock(&core->cmd_lock);
20281 ++}
20282 ++
20283 + static int vpu_session_send_cmd(struct vpu_inst *inst, u32 id, void *data)
20284 + {
20285 + unsigned long key;
20286 +@@ -304,9 +319,25 @@ static int vpu_session_send_cmd(struct vpu_inst *inst, u32 id, void *data)
20287 + return -EINVAL;
20288 +
20289 + ret = vpu_request_cmd(inst, id, data, &key, &sync);
20290 +- if (!ret && sync)
20291 +- ret = sync_session_response(inst, key);
20292 ++ if (ret)
20293 ++ goto exit;
20294 ++
20295 ++ /* workaround for a firmware issue,
20296 ++ * firmware should be waked up by start or configure command,
20297 ++ * but there is a very small change that firmware failed to wakeup.
20298 ++ * in such case, try to wakeup firmware again by sending a noop command
20299 ++ */
20300 ++ if (sync && (id == VPU_CMD_ID_CONFIGURE_CODEC || id == VPU_CMD_ID_START)) {
20301 ++ if (sync_session_response(inst, key, VPU_TIMEOUT_WAKEUP, 1))
20302 ++ vpu_core_keep_active(inst->core);
20303 ++ else
20304 ++ goto exit;
20305 ++ }
20306 ++
20307 ++ if (sync)
20308 ++ ret = sync_session_response(inst, key, VPU_TIMEOUT, 0);
20309 +
20310 ++exit:
20311 + if (ret)
20312 + dev_err(inst->dev, "[%d] send cmd(0x%x) fail\n", inst->id, id);
20313 +
20314 +diff --git a/drivers/media/platform/amphion/vpu_drv.c b/drivers/media/platform/amphion/vpu_drv.c
20315 +index 9d5a5075343d3..f01ce49d27e80 100644
20316 +--- a/drivers/media/platform/amphion/vpu_drv.c
20317 ++++ b/drivers/media/platform/amphion/vpu_drv.c
20318 +@@ -245,7 +245,11 @@ static int __init vpu_driver_init(void)
20319 + if (ret)
20320 + return ret;
20321 +
20322 +- return vpu_core_driver_init();
20323 ++ ret = vpu_core_driver_init();
20324 ++ if (ret)
20325 ++ platform_driver_unregister(&amphion_vpu_driver);
20326 ++
20327 ++ return ret;
20328 + }
20329 +
20330 + static void __exit vpu_driver_exit(void)
20331 +diff --git a/drivers/media/platform/amphion/vpu_malone.c b/drivers/media/platform/amphion/vpu_malone.c
20332 +index 51e0702f9ae17..9f2890730fd70 100644
20333 +--- a/drivers/media/platform/amphion/vpu_malone.c
20334 ++++ b/drivers/media/platform/amphion/vpu_malone.c
20335 +@@ -692,6 +692,7 @@ int vpu_malone_set_decode_params(struct vpu_shared_addr *shared,
20336 + }
20337 +
20338 + static struct vpu_pair malone_cmds[] = {
20339 ++ {VPU_CMD_ID_NOOP, VID_API_CMD_NULL},
20340 + {VPU_CMD_ID_START, VID_API_CMD_START},
20341 + {VPU_CMD_ID_STOP, VID_API_CMD_STOP},
20342 + {VPU_CMD_ID_ABORT, VID_API_CMD_ABORT},
20343 +diff --git a/drivers/media/platform/amphion/vpu_msgs.c b/drivers/media/platform/amphion/vpu_msgs.c
20344 +index d8247f36d84ba..92672a802b492 100644
20345 +--- a/drivers/media/platform/amphion/vpu_msgs.c
20346 ++++ b/drivers/media/platform/amphion/vpu_msgs.c
20347 +@@ -43,6 +43,7 @@ static void vpu_session_handle_mem_request(struct vpu_inst *inst, struct vpu_rpc
20348 + req_data.ref_frame_num,
20349 + req_data.act_buf_size,
20350 + req_data.act_buf_num);
20351 ++ vpu_inst_lock(inst);
20352 + call_void_vop(inst, mem_request,
20353 + req_data.enc_frame_size,
20354 + req_data.enc_frame_num,
20355 +@@ -50,6 +51,7 @@ static void vpu_session_handle_mem_request(struct vpu_inst *inst, struct vpu_rpc
20356 + req_data.ref_frame_num,
20357 + req_data.act_buf_size,
20358 + req_data.act_buf_num);
20359 ++ vpu_inst_unlock(inst);
20360 + }
20361 +
20362 + static void vpu_session_handle_stop_done(struct vpu_inst *inst, struct vpu_rpc_event *pkt)
20363 +diff --git a/drivers/media/platform/amphion/vpu_v4l2.c b/drivers/media/platform/amphion/vpu_v4l2.c
20364 +index b779e0ba916ca..590d1084e5a5d 100644
20365 +--- a/drivers/media/platform/amphion/vpu_v4l2.c
20366 ++++ b/drivers/media/platform/amphion/vpu_v4l2.c
20367 +@@ -65,18 +65,11 @@ unsigned int vpu_get_buffer_state(struct vb2_v4l2_buffer *vbuf)
20368 +
20369 + void vpu_v4l2_set_error(struct vpu_inst *inst)
20370 + {
20371 +- struct vb2_queue *src_q;
20372 +- struct vb2_queue *dst_q;
20373 +-
20374 + vpu_inst_lock(inst);
20375 + dev_err(inst->dev, "some error occurs in codec\n");
20376 + if (inst->fh.m2m_ctx) {
20377 +- src_q = v4l2_m2m_get_src_vq(inst->fh.m2m_ctx);
20378 +- dst_q = v4l2_m2m_get_dst_vq(inst->fh.m2m_ctx);
20379 +- src_q->error = 1;
20380 +- dst_q->error = 1;
20381 +- wake_up(&src_q->done_wq);
20382 +- wake_up(&dst_q->done_wq);
20383 ++ vb2_queue_error(v4l2_m2m_get_src_vq(inst->fh.m2m_ctx));
20384 ++ vb2_queue_error(v4l2_m2m_get_dst_vq(inst->fh.m2m_ctx));
20385 + }
20386 + vpu_inst_unlock(inst);
20387 + }
20388 +@@ -249,8 +242,12 @@ int vpu_process_capture_buffer(struct vpu_inst *inst)
20389 +
20390 + struct vb2_v4l2_buffer *vpu_next_src_buf(struct vpu_inst *inst)
20391 + {
20392 +- struct vb2_v4l2_buffer *src_buf = v4l2_m2m_next_src_buf(inst->fh.m2m_ctx);
20393 ++ struct vb2_v4l2_buffer *src_buf = NULL;
20394 ++
20395 ++ if (!inst->fh.m2m_ctx)
20396 ++ return NULL;
20397 +
20398 ++ src_buf = v4l2_m2m_next_src_buf(inst->fh.m2m_ctx);
20399 + if (!src_buf || vpu_get_buffer_state(src_buf) == VPU_BUF_STATE_IDLE)
20400 + return NULL;
20401 +
20402 +@@ -273,7 +270,7 @@ void vpu_skip_frame(struct vpu_inst *inst, int count)
20403 + enum vb2_buffer_state state;
20404 + int i = 0;
20405 +
20406 +- if (count <= 0)
20407 ++ if (count <= 0 || !inst->fh.m2m_ctx)
20408 + return;
20409 +
20410 + while (i < count) {
20411 +@@ -603,10 +600,6 @@ static int vpu_v4l2_release(struct vpu_inst *inst)
20412 + inst->workqueue = NULL;
20413 + }
20414 +
20415 +- if (inst->fh.m2m_ctx) {
20416 +- v4l2_m2m_ctx_release(inst->fh.m2m_ctx);
20417 +- inst->fh.m2m_ctx = NULL;
20418 +- }
20419 + v4l2_ctrl_handler_free(&inst->ctrl_handler);
20420 + mutex_destroy(&inst->lock);
20421 + v4l2_fh_del(&inst->fh);
20422 +@@ -689,6 +682,13 @@ int vpu_v4l2_close(struct file *file)
20423 +
20424 + vpu_trace(vpu->dev, "tgid = %d, pid = %d, inst = %p\n", inst->tgid, inst->pid, inst);
20425 +
20426 ++ vpu_inst_lock(inst);
20427 ++ if (inst->fh.m2m_ctx) {
20428 ++ v4l2_m2m_ctx_release(inst->fh.m2m_ctx);
20429 ++ inst->fh.m2m_ctx = NULL;
20430 ++ }
20431 ++ vpu_inst_unlock(inst);
20432 ++
20433 + call_void_vop(inst, release);
20434 + vpu_inst_unregister(inst);
20435 + vpu_inst_put(inst);
20436 +diff --git a/drivers/media/platform/amphion/vpu_windsor.c b/drivers/media/platform/amphion/vpu_windsor.c
20437 +index 1526af2ef9da4..b93c8cfdee7f5 100644
20438 +--- a/drivers/media/platform/amphion/vpu_windsor.c
20439 ++++ b/drivers/media/platform/amphion/vpu_windsor.c
20440 +@@ -658,6 +658,7 @@ int vpu_windsor_get_stream_buffer_size(struct vpu_shared_addr *shared)
20441 + }
20442 +
20443 + static struct vpu_pair windsor_cmds[] = {
20444 ++ {VPU_CMD_ID_NOOP, GTB_ENC_CMD_NOOP},
20445 + {VPU_CMD_ID_CONFIGURE_CODEC, GTB_ENC_CMD_CONFIGURE_CODEC},
20446 + {VPU_CMD_ID_START, GTB_ENC_CMD_STREAM_START},
20447 + {VPU_CMD_ID_STOP, GTB_ENC_CMD_STREAM_STOP},
20448 +diff --git a/drivers/media/platform/chips-media/coda-bit.c b/drivers/media/platform/chips-media/coda-bit.c
20449 +index 2736a902e3df3..ed47d5bd8d61e 100644
20450 +--- a/drivers/media/platform/chips-media/coda-bit.c
20451 ++++ b/drivers/media/platform/chips-media/coda-bit.c
20452 +@@ -854,7 +854,7 @@ static void coda_setup_iram(struct coda_ctx *ctx)
20453 + /* Only H.264BP and H.263P3 are considered */
20454 + iram_info->buf_dbk_y_use = coda_iram_alloc(iram_info, w64);
20455 + iram_info->buf_dbk_c_use = coda_iram_alloc(iram_info, w64);
20456 +- if (!iram_info->buf_dbk_c_use)
20457 ++ if (!iram_info->buf_dbk_y_use || !iram_info->buf_dbk_c_use)
20458 + goto out;
20459 + iram_info->axi_sram_use |= dbk_bits;
20460 +
20461 +@@ -878,7 +878,7 @@ static void coda_setup_iram(struct coda_ctx *ctx)
20462 +
20463 + iram_info->buf_dbk_y_use = coda_iram_alloc(iram_info, w128);
20464 + iram_info->buf_dbk_c_use = coda_iram_alloc(iram_info, w128);
20465 +- if (!iram_info->buf_dbk_c_use)
20466 ++ if (!iram_info->buf_dbk_y_use || !iram_info->buf_dbk_c_use)
20467 + goto out;
20468 + iram_info->axi_sram_use |= dbk_bits;
20469 +
20470 +@@ -1084,10 +1084,16 @@ static int coda_start_encoding(struct coda_ctx *ctx)
20471 + }
20472 +
20473 + if (dst_fourcc == V4L2_PIX_FMT_JPEG) {
20474 +- if (!ctx->params.jpeg_qmat_tab[0])
20475 ++ if (!ctx->params.jpeg_qmat_tab[0]) {
20476 + ctx->params.jpeg_qmat_tab[0] = kmalloc(64, GFP_KERNEL);
20477 +- if (!ctx->params.jpeg_qmat_tab[1])
20478 ++ if (!ctx->params.jpeg_qmat_tab[0])
20479 ++ return -ENOMEM;
20480 ++ }
20481 ++ if (!ctx->params.jpeg_qmat_tab[1]) {
20482 + ctx->params.jpeg_qmat_tab[1] = kmalloc(64, GFP_KERNEL);
20483 ++ if (!ctx->params.jpeg_qmat_tab[1])
20484 ++ return -ENOMEM;
20485 ++ }
20486 + coda_set_jpeg_compression_quality(ctx, ctx->params.jpeg_quality);
20487 + }
20488 +
20489 +diff --git a/drivers/media/platform/chips-media/coda-jpeg.c b/drivers/media/platform/chips-media/coda-jpeg.c
20490 +index a0b22b07f69ac..2284e04209348 100644
20491 +--- a/drivers/media/platform/chips-media/coda-jpeg.c
20492 ++++ b/drivers/media/platform/chips-media/coda-jpeg.c
20493 +@@ -1053,10 +1053,16 @@ static int coda9_jpeg_start_encoding(struct coda_ctx *ctx)
20494 + v4l2_err(&dev->v4l2_dev, "error loading Huffman tables\n");
20495 + return ret;
20496 + }
20497 +- if (!ctx->params.jpeg_qmat_tab[0])
20498 ++ if (!ctx->params.jpeg_qmat_tab[0]) {
20499 + ctx->params.jpeg_qmat_tab[0] = kmalloc(64, GFP_KERNEL);
20500 +- if (!ctx->params.jpeg_qmat_tab[1])
20501 ++ if (!ctx->params.jpeg_qmat_tab[0])
20502 ++ return -ENOMEM;
20503 ++ }
20504 ++ if (!ctx->params.jpeg_qmat_tab[1]) {
20505 + ctx->params.jpeg_qmat_tab[1] = kmalloc(64, GFP_KERNEL);
20506 ++ if (!ctx->params.jpeg_qmat_tab[1])
20507 ++ return -ENOMEM;
20508 ++ }
20509 + coda_set_jpeg_compression_quality(ctx, ctx->params.jpeg_quality);
20510 +
20511 + return 0;
20512 +diff --git a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_stateless.c b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_stateless.c
20513 +index c45bd2599bb2d..ffbcee04dc26f 100644
20514 +--- a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_stateless.c
20515 ++++ b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_stateless.c
20516 +@@ -138,10 +138,13 @@ static void mtk_vdec_stateless_cap_to_disp(struct mtk_vcodec_ctx *ctx, int error
20517 + state = VB2_BUF_STATE_DONE;
20518 +
20519 + vb2_dst = v4l2_m2m_dst_buf_remove(ctx->m2m_ctx);
20520 +- v4l2_m2m_buf_done(vb2_dst, state);
20521 +-
20522 +- mtk_v4l2_debug(2, "free frame buffer id:%d to done list",
20523 +- vb2_dst->vb2_buf.index);
20524 ++ if (vb2_dst) {
20525 ++ v4l2_m2m_buf_done(vb2_dst, state);
20526 ++ mtk_v4l2_debug(2, "free frame buffer id:%d to done list",
20527 ++ vb2_dst->vb2_buf.index);
20528 ++ } else {
20529 ++ mtk_v4l2_err("dst buffer is NULL");
20530 ++ }
20531 +
20532 + if (src_buf_req)
20533 + v4l2_ctrl_request_complete(src_buf_req, &ctx->ctrl_hdl);
20534 +@@ -250,7 +253,7 @@ static void mtk_vdec_worker(struct work_struct *work)
20535 +
20536 + state = ret ? VB2_BUF_STATE_ERROR : VB2_BUF_STATE_DONE;
20537 + if (!IS_VDEC_LAT_ARCH(dev->vdec_pdata->hw_arch) ||
20538 +- ctx->current_codec == V4L2_PIX_FMT_VP8_FRAME || ret) {
20539 ++ ctx->current_codec == V4L2_PIX_FMT_VP8_FRAME) {
20540 + v4l2_m2m_buf_done_and_job_finish(dev->m2m_dev_dec, ctx->m2m_ctx, state);
20541 + if (src_buf_req)
20542 + v4l2_ctrl_request_complete(src_buf_req, &ctx->ctrl_hdl);
20543 +diff --git a/drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_req_multi_if.c b/drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_req_multi_if.c
20544 +index 4cc92700692b3..955b2d0c8f53f 100644
20545 +--- a/drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_req_multi_if.c
20546 ++++ b/drivers/media/platform/mediatek/vcodec/vdec/vdec_h264_req_multi_if.c
20547 +@@ -471,14 +471,19 @@ static int vdec_h264_slice_core_decode(struct vdec_lat_buf *lat_buf)
20548 + sizeof(share_info->h264_slice_params));
20549 +
20550 + fb = ctx->dev->vdec_pdata->get_cap_buffer(ctx);
20551 +- y_fb_dma = fb ? (u64)fb->base_y.dma_addr : 0;
20552 +- vdec_fb_va = (unsigned long)fb;
20553 ++ if (!fb) {
20554 ++ err = -EBUSY;
20555 ++ mtk_vcodec_err(inst, "fb buffer is NULL");
20556 ++ goto vdec_dec_end;
20557 ++ }
20558 +
20559 ++ vdec_fb_va = (unsigned long)fb;
20560 ++ y_fb_dma = (u64)fb->base_y.dma_addr;
20561 + if (ctx->q_data[MTK_Q_DATA_DST].fmt->num_planes == 1)
20562 + c_fb_dma =
20563 + y_fb_dma + inst->ctx->picinfo.buf_w * inst->ctx->picinfo.buf_h;
20564 + else
20565 +- c_fb_dma = fb ? (u64)fb->base_c.dma_addr : 0;
20566 ++ c_fb_dma = (u64)fb->base_c.dma_addr;
20567 +
20568 + mtk_vcodec_debug(inst, "[h264-core] y/c addr = 0x%llx 0x%llx", y_fb_dma,
20569 + c_fb_dma);
20570 +@@ -539,6 +544,29 @@ vdec_dec_end:
20571 + return 0;
20572 + }
20573 +
20574 ++static void vdec_h264_insert_startcode(struct mtk_vcodec_dev *vcodec_dev, unsigned char *buf,
20575 ++ size_t *bs_size, struct mtk_h264_pps_param *pps)
20576 ++{
20577 ++ struct device *dev = &vcodec_dev->plat_dev->dev;
20578 ++
20579 ++ /* Need to add pending data at the end of bitstream when bs_sz is small than
20580 ++ * 20 bytes for cavlc bitstream, or lat will decode fail. This pending data is
20581 ++ * useful for mt8192 and mt8195 platform.
20582 ++ *
20583 ++ * cavlc bitstream when entropy_coding_mode_flag is false.
20584 ++ */
20585 ++ if (pps->entropy_coding_mode_flag || *bs_size > 20 ||
20586 ++ !(of_device_is_compatible(dev->of_node, "mediatek,mt8192-vcodec-dec") ||
20587 ++ of_device_is_compatible(dev->of_node, "mediatek,mt8195-vcodec-dec")))
20588 ++ return;
20589 ++
20590 ++ buf[*bs_size] = 0;
20591 ++ buf[*bs_size + 1] = 0;
20592 ++ buf[*bs_size + 2] = 1;
20593 ++ buf[*bs_size + 3] = 0xff;
20594 ++ (*bs_size) += 4;
20595 ++}
20596 ++
20597 + static int vdec_h264_slice_lat_decode(void *h_vdec, struct mtk_vcodec_mem *bs,
20598 + struct vdec_fb *fb, bool *res_chg)
20599 + {
20600 +@@ -582,9 +610,6 @@ static int vdec_h264_slice_lat_decode(void *h_vdec, struct mtk_vcodec_mem *bs,
20601 + }
20602 +
20603 + inst->vsi->dec.nal_info = buf[nal_start_idx];
20604 +- inst->vsi->dec.bs_buf_addr = (u64)bs->dma_addr;
20605 +- inst->vsi->dec.bs_buf_size = bs->size;
20606 +-
20607 + lat_buf->src_buf_req = src_buf_info->m2m_buf.vb.vb2_buf.req_obj.req;
20608 + v4l2_m2m_buf_copy_metadata(&src_buf_info->m2m_buf.vb, &lat_buf->ts_info, true);
20609 +
20610 +@@ -592,6 +617,12 @@ static int vdec_h264_slice_lat_decode(void *h_vdec, struct mtk_vcodec_mem *bs,
20611 + if (err)
20612 + goto err_free_fb_out;
20613 +
20614 ++ vdec_h264_insert_startcode(inst->ctx->dev, buf, &bs->size,
20615 ++ &share_info->h264_slice_params.pps);
20616 ++
20617 ++ inst->vsi->dec.bs_buf_addr = (uint64_t)bs->dma_addr;
20618 ++ inst->vsi->dec.bs_buf_size = bs->size;
20619 ++
20620 + *res_chg = inst->resolution_changed;
20621 + if (inst->resolution_changed) {
20622 + mtk_vcodec_debug(inst, "- resolution changed -");
20623 +@@ -630,7 +661,7 @@ static int vdec_h264_slice_lat_decode(void *h_vdec, struct mtk_vcodec_mem *bs,
20624 + err = vpu_dec_start(vpu, data, 2);
20625 + if (err) {
20626 + mtk_vcodec_debug(inst, "lat decode err: %d", err);
20627 +- goto err_scp_decode;
20628 ++ goto err_free_fb_out;
20629 + }
20630 +
20631 + share_info->trans_end = inst->ctx->msg_queue.wdma_addr.dma_addr +
20632 +@@ -647,12 +678,17 @@ static int vdec_h264_slice_lat_decode(void *h_vdec, struct mtk_vcodec_mem *bs,
20633 + /* wait decoder done interrupt */
20634 + timeout = mtk_vcodec_wait_for_done_ctx(inst->ctx, MTK_INST_IRQ_RECEIVED,
20635 + WAIT_INTR_TIMEOUT_MS, MTK_VDEC_LAT0);
20636 ++ if (timeout)
20637 ++ mtk_vcodec_err(inst, "lat decode timeout: pic_%d", inst->slice_dec_num);
20638 + inst->vsi->dec.timeout = !!timeout;
20639 +
20640 + err = vpu_dec_end(vpu);
20641 +- if (err == SLICE_HEADER_FULL || timeout || err == TRANS_BUFFER_FULL) {
20642 +- err = -EINVAL;
20643 +- goto err_scp_decode;
20644 ++ if (err == SLICE_HEADER_FULL || err == TRANS_BUFFER_FULL) {
20645 ++ if (!IS_VDEC_INNER_RACING(inst->ctx->dev->dec_capability))
20646 ++ vdec_msg_queue_qbuf(&inst->ctx->msg_queue.lat_ctx, lat_buf);
20647 ++ inst->slice_dec_num++;
20648 ++ mtk_vcodec_err(inst, "lat dec fail: pic_%d err:%d", inst->slice_dec_num, err);
20649 ++ return -EINVAL;
20650 + }
20651 +
20652 + share_info->trans_end = inst->ctx->msg_queue.wdma_addr.dma_addr +
20653 +@@ -669,10 +705,6 @@ static int vdec_h264_slice_lat_decode(void *h_vdec, struct mtk_vcodec_mem *bs,
20654 +
20655 + inst->slice_dec_num++;
20656 + return 0;
20657 +-
20658 +-err_scp_decode:
20659 +- if (!IS_VDEC_INNER_RACING(inst->ctx->dev->dec_capability))
20660 +- vdec_msg_queue_qbuf(&inst->ctx->msg_queue.lat_ctx, lat_buf);
20661 + err_free_fb_out:
20662 + vdec_msg_queue_qbuf(&inst->ctx->msg_queue.lat_ctx, lat_buf);
20663 + mtk_vcodec_err(inst, "slice dec number: %d err: %d", inst->slice_dec_num, err);
20664 +diff --git a/drivers/media/platform/mediatek/vcodec/vdec/vdec_vp9_req_lat_if.c b/drivers/media/platform/mediatek/vcodec/vdec/vdec_vp9_req_lat_if.c
20665 +index fb1c36a3592d1..cbb6728b8a40b 100644
20666 +--- a/drivers/media/platform/mediatek/vcodec/vdec/vdec_vp9_req_lat_if.c
20667 ++++ b/drivers/media/platform/mediatek/vcodec/vdec/vdec_vp9_req_lat_if.c
20668 +@@ -2073,21 +2073,23 @@ static int vdec_vp9_slice_lat_decode(void *h_vdec, struct mtk_vcodec_mem *bs,
20669 + return -EBUSY;
20670 + }
20671 + pfc = (struct vdec_vp9_slice_pfc *)lat_buf->private_data;
20672 +- if (!pfc)
20673 +- return -EINVAL;
20674 ++ if (!pfc) {
20675 ++ ret = -EINVAL;
20676 ++ goto err_free_fb_out;
20677 ++ }
20678 + vsi = &pfc->vsi;
20679 +
20680 + ret = vdec_vp9_slice_setup_lat(instance, bs, lat_buf, pfc);
20681 + if (ret) {
20682 + mtk_vcodec_err(instance, "Failed to setup VP9 lat ret %d\n", ret);
20683 +- return ret;
20684 ++ goto err_free_fb_out;
20685 + }
20686 + vdec_vp9_slice_vsi_to_remote(vsi, instance->vsi);
20687 +
20688 + ret = vpu_dec_start(&instance->vpu, NULL, 0);
20689 + if (ret) {
20690 + mtk_vcodec_err(instance, "Failed to dec VP9 ret %d\n", ret);
20691 +- return ret;
20692 ++ goto err_free_fb_out;
20693 + }
20694 +
20695 + if (instance->irq) {
20696 +@@ -2107,7 +2109,7 @@ static int vdec_vp9_slice_lat_decode(void *h_vdec, struct mtk_vcodec_mem *bs,
20697 + /* LAT trans full, no more UBE or decode timeout */
20698 + if (ret) {
20699 + mtk_vcodec_err(instance, "VP9 decode error: %d\n", ret);
20700 +- return ret;
20701 ++ goto err_free_fb_out;
20702 + }
20703 +
20704 + mtk_vcodec_debug(instance, "lat dma addr: 0x%lx 0x%lx\n",
20705 +@@ -2120,6 +2122,9 @@ static int vdec_vp9_slice_lat_decode(void *h_vdec, struct mtk_vcodec_mem *bs,
20706 + vdec_msg_queue_qbuf(&ctx->dev->msg_queue_core_ctx, lat_buf);
20707 +
20708 + return 0;
20709 ++err_free_fb_out:
20710 ++ vdec_msg_queue_qbuf(&ctx->msg_queue.lat_ctx, lat_buf);
20711 ++ return ret;
20712 + }
20713 +
20714 + static int vdec_vp9_slice_decode(void *h_vdec, struct mtk_vcodec_mem *bs,
20715 +diff --git a/drivers/media/platform/mediatek/vcodec/vdec_msg_queue.c b/drivers/media/platform/mediatek/vcodec/vdec_msg_queue.c
20716 +index ae500980ad45c..dc2004790a472 100644
20717 +--- a/drivers/media/platform/mediatek/vcodec/vdec_msg_queue.c
20718 ++++ b/drivers/media/platform/mediatek/vcodec/vdec_msg_queue.c
20719 +@@ -221,7 +221,7 @@ static void vdec_msg_queue_core_work(struct work_struct *work)
20720 + mtk_vcodec_dec_disable_hardware(ctx, MTK_VDEC_CORE);
20721 + vdec_msg_queue_qbuf(&ctx->msg_queue.lat_ctx, lat_buf);
20722 +
20723 +- if (!list_empty(&ctx->msg_queue.lat_ctx.ready_queue)) {
20724 ++ if (!list_empty(&dev->msg_queue_core_ctx.ready_queue)) {
20725 + mtk_v4l2_debug(3, "re-schedule to decode for core: %d",
20726 + dev->msg_queue_core_ctx.ready_num);
20727 + queue_work(dev->core_workqueue, &msg_queue->core_work);
20728 +diff --git a/drivers/media/platform/nxp/imx-jpeg/mxc-jpeg-hw.c b/drivers/media/platform/nxp/imx-jpeg/mxc-jpeg-hw.c
20729 +index 9418fcf740a82..ef28122a5ed49 100644
20730 +--- a/drivers/media/platform/nxp/imx-jpeg/mxc-jpeg-hw.c
20731 ++++ b/drivers/media/platform/nxp/imx-jpeg/mxc-jpeg-hw.c
20732 +@@ -76,12 +76,14 @@ void print_wrapper_info(struct device *dev, void __iomem *reg)
20733 +
20734 + void mxc_jpeg_enable_irq(void __iomem *reg, int slot)
20735 + {
20736 +- writel(0xFFFFFFFF, reg + MXC_SLOT_OFFSET(slot, SLOT_IRQ_EN));
20737 ++ writel(0xFFFFFFFF, reg + MXC_SLOT_OFFSET(slot, SLOT_STATUS));
20738 ++ writel(0xF0C, reg + MXC_SLOT_OFFSET(slot, SLOT_IRQ_EN));
20739 + }
20740 +
20741 + void mxc_jpeg_disable_irq(void __iomem *reg, int slot)
20742 + {
20743 + writel(0x0, reg + MXC_SLOT_OFFSET(slot, SLOT_IRQ_EN));
20744 ++ writel(0xFFFFFFFF, reg + MXC_SLOT_OFFSET(slot, SLOT_STATUS));
20745 + }
20746 +
20747 + void mxc_jpeg_sw_reset(void __iomem *reg)
20748 +diff --git a/drivers/media/platform/qcom/camss/camss-video.c b/drivers/media/platform/qcom/camss/camss-video.c
20749 +index 290df04c4d02c..a25fffb0b8ec5 100644
20750 +--- a/drivers/media/platform/qcom/camss/camss-video.c
20751 ++++ b/drivers/media/platform/qcom/camss/camss-video.c
20752 +@@ -495,7 +495,7 @@ static int video_start_streaming(struct vb2_queue *q, unsigned int count)
20753 +
20754 + ret = media_pipeline_start(&vdev->entity, &video->pipe);
20755 + if (ret < 0)
20756 +- return ret;
20757 ++ goto flush_buffers;
20758 +
20759 + ret = video_check_format(video);
20760 + if (ret < 0)
20761 +@@ -524,6 +524,7 @@ static int video_start_streaming(struct vb2_queue *q, unsigned int count)
20762 + error:
20763 + media_pipeline_stop(&vdev->entity);
20764 +
20765 ++flush_buffers:
20766 + video->ops->flush_buffers(video, VB2_BUF_STATE_QUEUED);
20767 +
20768 + return ret;
20769 +diff --git a/drivers/media/platform/qcom/camss/camss.c b/drivers/media/platform/qcom/camss/camss.c
20770 +index 1118c40886d52..a157cac72e0ab 100644
20771 +--- a/drivers/media/platform/qcom/camss/camss.c
20772 ++++ b/drivers/media/platform/qcom/camss/camss.c
20773 +@@ -1465,6 +1465,14 @@ static int camss_configure_pd(struct camss *camss)
20774 + return camss->genpd_num;
20775 + }
20776 +
20777 ++ /*
20778 ++ * If a platform device has just one power domain, then it is attached
20779 ++ * at platform_probe() level, thus there shall be no need and even no
20780 ++ * option to attach it again, this is the case for CAMSS on MSM8916.
20781 ++ */
20782 ++ if (camss->genpd_num == 1)
20783 ++ return 0;
20784 ++
20785 + camss->genpd = devm_kmalloc_array(dev, camss->genpd_num,
20786 + sizeof(*camss->genpd), GFP_KERNEL);
20787 + if (!camss->genpd)
20788 +@@ -1698,6 +1706,9 @@ void camss_delete(struct camss *camss)
20789 +
20790 + pm_runtime_disable(camss->dev);
20791 +
20792 ++ if (camss->genpd_num == 1)
20793 ++ return;
20794 ++
20795 + for (i = 0; i < camss->genpd_num; i++) {
20796 + device_link_del(camss->genpd_link[i]);
20797 + dev_pm_domain_detach(camss->genpd[i], true);
20798 +diff --git a/drivers/media/platform/qcom/venus/pm_helpers.c b/drivers/media/platform/qcom/venus/pm_helpers.c
20799 +index c93d2906e4c7d..48c9084bb4dba 100644
20800 +--- a/drivers/media/platform/qcom/venus/pm_helpers.c
20801 ++++ b/drivers/media/platform/qcom/venus/pm_helpers.c
20802 +@@ -869,8 +869,8 @@ static int vcodec_domains_get(struct venus_core *core)
20803 + for (i = 0; i < res->vcodec_pmdomains_num; i++) {
20804 + pd = dev_pm_domain_attach_by_name(dev,
20805 + res->vcodec_pmdomains[i]);
20806 +- if (IS_ERR(pd))
20807 +- return PTR_ERR(pd);
20808 ++ if (IS_ERR_OR_NULL(pd))
20809 ++ return PTR_ERR(pd) ? : -ENODATA;
20810 + core->pmdomains[i] = pd;
20811 + }
20812 +
20813 +diff --git a/drivers/media/platform/samsung/exynos4-is/fimc-core.c b/drivers/media/platform/samsung/exynos4-is/fimc-core.c
20814 +index 91cc8d58a663b..1791100b69353 100644
20815 +--- a/drivers/media/platform/samsung/exynos4-is/fimc-core.c
20816 ++++ b/drivers/media/platform/samsung/exynos4-is/fimc-core.c
20817 +@@ -1173,7 +1173,7 @@ int __init fimc_register_driver(void)
20818 + return platform_driver_register(&fimc_driver);
20819 + }
20820 +
20821 +-void __exit fimc_unregister_driver(void)
20822 ++void fimc_unregister_driver(void)
20823 + {
20824 + platform_driver_unregister(&fimc_driver);
20825 + }
20826 +diff --git a/drivers/media/platform/samsung/exynos4-is/media-dev.c b/drivers/media/platform/samsung/exynos4-is/media-dev.c
20827 +index 52b43ea040302..2f3071acb9c97 100644
20828 +--- a/drivers/media/platform/samsung/exynos4-is/media-dev.c
20829 ++++ b/drivers/media/platform/samsung/exynos4-is/media-dev.c
20830 +@@ -1380,9 +1380,7 @@ static int subdev_notifier_bound(struct v4l2_async_notifier *notifier,
20831 +
20832 + /* Find platform data for this sensor subdev */
20833 + for (i = 0; i < ARRAY_SIZE(fmd->sensor); i++)
20834 +- if (fmd->sensor[i].asd &&
20835 +- fmd->sensor[i].asd->match.fwnode ==
20836 +- of_fwnode_handle(subdev->dev->of_node))
20837 ++ if (fmd->sensor[i].asd == asd)
20838 + si = &fmd->sensor[i];
20839 +
20840 + if (si == NULL)
20841 +@@ -1474,7 +1472,7 @@ static int fimc_md_probe(struct platform_device *pdev)
20842 + pinctrl = devm_pinctrl_get(dev);
20843 + if (IS_ERR(pinctrl)) {
20844 + ret = PTR_ERR(pinctrl);
20845 +- if (ret != EPROBE_DEFER)
20846 ++ if (ret != -EPROBE_DEFER)
20847 + dev_err(dev, "Failed to get pinctrl: %d\n", ret);
20848 + goto err_clk;
20849 + }
20850 +@@ -1586,7 +1584,11 @@ static int __init fimc_md_init(void)
20851 + if (ret)
20852 + return ret;
20853 +
20854 +- return platform_driver_register(&fimc_md_driver);
20855 ++ ret = platform_driver_register(&fimc_md_driver);
20856 ++ if (ret)
20857 ++ fimc_unregister_driver();
20858 ++
20859 ++ return ret;
20860 + }
20861 +
20862 + static void __exit fimc_md_exit(void)
20863 +diff --git a/drivers/media/platform/samsung/s5p-mfc/s5p_mfc.c b/drivers/media/platform/samsung/s5p-mfc/s5p_mfc.c
20864 +index f85d1eebaface..7bdbe767500e6 100644
20865 +--- a/drivers/media/platform/samsung/s5p-mfc/s5p_mfc.c
20866 ++++ b/drivers/media/platform/samsung/s5p-mfc/s5p_mfc.c
20867 +@@ -1576,8 +1576,18 @@ static struct s5p_mfc_variant mfc_drvdata_v7 = {
20868 + .port_num = MFC_NUM_PORTS_V7,
20869 + .buf_size = &buf_size_v7,
20870 + .fw_name[0] = "s5p-mfc-v7.fw",
20871 +- .clk_names = {"mfc", "sclk_mfc"},
20872 +- .num_clocks = 2,
20873 ++ .clk_names = {"mfc"},
20874 ++ .num_clocks = 1,
20875 ++};
20876 ++
20877 ++static struct s5p_mfc_variant mfc_drvdata_v7_3250 = {
20878 ++ .version = MFC_VERSION_V7,
20879 ++ .version_bit = MFC_V7_BIT,
20880 ++ .port_num = MFC_NUM_PORTS_V7,
20881 ++ .buf_size = &buf_size_v7,
20882 ++ .fw_name[0] = "s5p-mfc-v7.fw",
20883 ++ .clk_names = {"mfc", "sclk_mfc"},
20884 ++ .num_clocks = 2,
20885 + };
20886 +
20887 + static struct s5p_mfc_buf_size_v6 mfc_buf_size_v8 = {
20888 +@@ -1647,6 +1657,9 @@ static const struct of_device_id exynos_mfc_match[] = {
20889 + }, {
20890 + .compatible = "samsung,mfc-v7",
20891 + .data = &mfc_drvdata_v7,
20892 ++ }, {
20893 ++ .compatible = "samsung,exynos3250-mfc",
20894 ++ .data = &mfc_drvdata_v7_3250,
20895 + }, {
20896 + .compatible = "samsung,mfc-v8",
20897 + .data = &mfc_drvdata_v8,
20898 +diff --git a/drivers/media/platform/st/sti/c8sectpfe/c8sectpfe-core.c b/drivers/media/platform/st/sti/c8sectpfe/c8sectpfe-core.c
20899 +index cefe6b7bfdc4e..1dbb89f0ddb8c 100644
20900 +--- a/drivers/media/platform/st/sti/c8sectpfe/c8sectpfe-core.c
20901 ++++ b/drivers/media/platform/st/sti/c8sectpfe/c8sectpfe-core.c
20902 +@@ -925,6 +925,7 @@ static int configure_channels(struct c8sectpfei *fei)
20903 + if (ret) {
20904 + dev_err(fei->dev,
20905 + "configure_memdma_and_inputblock failed\n");
20906 ++ of_node_put(child);
20907 + goto err_unmap;
20908 + }
20909 + index++;
20910 +diff --git a/drivers/media/platform/sunxi/sun6i-mipi-csi2/sun6i_mipi_csi2.c b/drivers/media/platform/sunxi/sun6i-mipi-csi2/sun6i_mipi_csi2.c
20911 +index 30d6c0c5161f4..484ac5f054d53 100644
20912 +--- a/drivers/media/platform/sunxi/sun6i-mipi-csi2/sun6i_mipi_csi2.c
20913 ++++ b/drivers/media/platform/sunxi/sun6i-mipi-csi2/sun6i_mipi_csi2.c
20914 +@@ -498,6 +498,7 @@ static int sun6i_mipi_csi2_bridge_setup(struct sun6i_mipi_csi2_device *csi2_dev)
20915 + struct v4l2_async_notifier *notifier = &bridge->notifier;
20916 + struct media_pad *pads = bridge->pads;
20917 + struct device *dev = csi2_dev->dev;
20918 ++ bool notifier_registered = false;
20919 + int ret;
20920 +
20921 + mutex_init(&bridge->lock);
20922 +@@ -519,8 +520,10 @@ static int sun6i_mipi_csi2_bridge_setup(struct sun6i_mipi_csi2_device *csi2_dev)
20923 +
20924 + /* Media Pads */
20925 +
20926 +- pads[SUN6I_MIPI_CSI2_PAD_SINK].flags = MEDIA_PAD_FL_SINK;
20927 +- pads[SUN6I_MIPI_CSI2_PAD_SOURCE].flags = MEDIA_PAD_FL_SOURCE;
20928 ++ pads[SUN6I_MIPI_CSI2_PAD_SINK].flags = MEDIA_PAD_FL_SINK |
20929 ++ MEDIA_PAD_FL_MUST_CONNECT;
20930 ++ pads[SUN6I_MIPI_CSI2_PAD_SOURCE].flags = MEDIA_PAD_FL_SOURCE |
20931 ++ MEDIA_PAD_FL_MUST_CONNECT;
20932 +
20933 + ret = media_entity_pads_init(&subdev->entity, SUN6I_MIPI_CSI2_PAD_COUNT,
20934 + pads);
20935 +@@ -533,12 +536,17 @@ static int sun6i_mipi_csi2_bridge_setup(struct sun6i_mipi_csi2_device *csi2_dev)
20936 + notifier->ops = &sun6i_mipi_csi2_notifier_ops;
20937 +
20938 + ret = sun6i_mipi_csi2_bridge_source_setup(csi2_dev);
20939 +- if (ret)
20940 ++ if (ret && ret != -ENODEV)
20941 + goto error_v4l2_notifier_cleanup;
20942 +
20943 +- ret = v4l2_async_subdev_nf_register(subdev, notifier);
20944 +- if (ret < 0)
20945 +- goto error_v4l2_notifier_cleanup;
20946 ++ /* Only register the notifier when a sensor is connected. */
20947 ++ if (ret != -ENODEV) {
20948 ++ ret = v4l2_async_subdev_nf_register(subdev, notifier);
20949 ++ if (ret < 0)
20950 ++ goto error_v4l2_notifier_cleanup;
20951 ++
20952 ++ notifier_registered = true;
20953 ++ }
20954 +
20955 + /* V4L2 Subdev */
20956 +
20957 +@@ -549,7 +557,8 @@ static int sun6i_mipi_csi2_bridge_setup(struct sun6i_mipi_csi2_device *csi2_dev)
20958 + return 0;
20959 +
20960 + error_v4l2_notifier_unregister:
20961 +- v4l2_async_nf_unregister(notifier);
20962 ++ if (notifier_registered)
20963 ++ v4l2_async_nf_unregister(notifier);
20964 +
20965 + error_v4l2_notifier_cleanup:
20966 + v4l2_async_nf_cleanup(notifier);
20967 +diff --git a/drivers/media/platform/sunxi/sun8i-a83t-mipi-csi2/sun8i_a83t_mipi_csi2.c b/drivers/media/platform/sunxi/sun8i-a83t-mipi-csi2/sun8i_a83t_mipi_csi2.c
20968 +index b032ec13a683a..d993c09a48202 100644
20969 +--- a/drivers/media/platform/sunxi/sun8i-a83t-mipi-csi2/sun8i_a83t_mipi_csi2.c
20970 ++++ b/drivers/media/platform/sunxi/sun8i-a83t-mipi-csi2/sun8i_a83t_mipi_csi2.c
20971 +@@ -536,6 +536,7 @@ sun8i_a83t_mipi_csi2_bridge_setup(struct sun8i_a83t_mipi_csi2_device *csi2_dev)
20972 + struct v4l2_async_notifier *notifier = &bridge->notifier;
20973 + struct media_pad *pads = bridge->pads;
20974 + struct device *dev = csi2_dev->dev;
20975 ++ bool notifier_registered = false;
20976 + int ret;
20977 +
20978 + mutex_init(&bridge->lock);
20979 +@@ -557,8 +558,10 @@ sun8i_a83t_mipi_csi2_bridge_setup(struct sun8i_a83t_mipi_csi2_device *csi2_dev)
20980 +
20981 + /* Media Pads */
20982 +
20983 +- pads[SUN8I_A83T_MIPI_CSI2_PAD_SINK].flags = MEDIA_PAD_FL_SINK;
20984 +- pads[SUN8I_A83T_MIPI_CSI2_PAD_SOURCE].flags = MEDIA_PAD_FL_SOURCE;
20985 ++ pads[SUN8I_A83T_MIPI_CSI2_PAD_SINK].flags = MEDIA_PAD_FL_SINK |
20986 ++ MEDIA_PAD_FL_MUST_CONNECT;
20987 ++ pads[SUN8I_A83T_MIPI_CSI2_PAD_SOURCE].flags = MEDIA_PAD_FL_SOURCE |
20988 ++ MEDIA_PAD_FL_MUST_CONNECT;
20989 +
20990 + ret = media_entity_pads_init(&subdev->entity,
20991 + SUN8I_A83T_MIPI_CSI2_PAD_COUNT, pads);
20992 +@@ -571,12 +574,17 @@ sun8i_a83t_mipi_csi2_bridge_setup(struct sun8i_a83t_mipi_csi2_device *csi2_dev)
20993 + notifier->ops = &sun8i_a83t_mipi_csi2_notifier_ops;
20994 +
20995 + ret = sun8i_a83t_mipi_csi2_bridge_source_setup(csi2_dev);
20996 +- if (ret)
20997 ++ if (ret && ret != -ENODEV)
20998 + goto error_v4l2_notifier_cleanup;
20999 +
21000 +- ret = v4l2_async_subdev_nf_register(subdev, notifier);
21001 +- if (ret < 0)
21002 +- goto error_v4l2_notifier_cleanup;
21003 ++ /* Only register the notifier when a sensor is connected. */
21004 ++ if (ret != -ENODEV) {
21005 ++ ret = v4l2_async_subdev_nf_register(subdev, notifier);
21006 ++ if (ret < 0)
21007 ++ goto error_v4l2_notifier_cleanup;
21008 ++
21009 ++ notifier_registered = true;
21010 ++ }
21011 +
21012 + /* V4L2 Subdev */
21013 +
21014 +@@ -587,7 +595,8 @@ sun8i_a83t_mipi_csi2_bridge_setup(struct sun8i_a83t_mipi_csi2_device *csi2_dev)
21015 + return 0;
21016 +
21017 + error_v4l2_notifier_unregister:
21018 +- v4l2_async_nf_unregister(notifier);
21019 ++ if (notifier_registered)
21020 ++ v4l2_async_nf_unregister(notifier);
21021 +
21022 + error_v4l2_notifier_cleanup:
21023 + v4l2_async_nf_cleanup(notifier);
21024 +diff --git a/drivers/media/radio/si470x/radio-si470x-usb.c b/drivers/media/radio/si470x/radio-si470x-usb.c
21025 +index 6b2768623c883..aa7a580dbecc0 100644
21026 +--- a/drivers/media/radio/si470x/radio-si470x-usb.c
21027 ++++ b/drivers/media/radio/si470x/radio-si470x-usb.c
21028 +@@ -727,8 +727,10 @@ static int si470x_usb_driver_probe(struct usb_interface *intf,
21029 +
21030 + /* start radio */
21031 + retval = si470x_start_usb(radio);
21032 +- if (retval < 0)
21033 ++ if (retval < 0 && !radio->int_in_running)
21034 + goto err_buf;
21035 ++ else if (retval < 0) /* in case of radio->int_in_running == 1 */
21036 ++ goto err_all;
21037 +
21038 + /* set initial frequency */
21039 + si470x_set_freq(radio, 87.5 * FREQ_MUL); /* available in all regions */
21040 +diff --git a/drivers/media/rc/imon.c b/drivers/media/rc/imon.c
21041 +index 735b925da9984..91d8056666ec8 100644
21042 +--- a/drivers/media/rc/imon.c
21043 ++++ b/drivers/media/rc/imon.c
21044 +@@ -646,15 +646,14 @@ static int send_packet(struct imon_context *ictx)
21045 + pr_err_ratelimited("error submitting urb(%d)\n", retval);
21046 + } else {
21047 + /* Wait for transmission to complete (or abort) */
21048 +- mutex_unlock(&ictx->lock);
21049 + retval = wait_for_completion_interruptible(
21050 + &ictx->tx.finished);
21051 + if (retval) {
21052 + usb_kill_urb(ictx->tx_urb);
21053 + pr_err_ratelimited("task interrupted\n");
21054 + }
21055 +- mutex_lock(&ictx->lock);
21056 +
21057 ++ ictx->tx.busy = false;
21058 + retval = ictx->tx.status;
21059 + if (retval)
21060 + pr_err_ratelimited("packet tx failed (%d)\n", retval);
21061 +@@ -955,7 +954,8 @@ static ssize_t vfd_write(struct file *file, const char __user *buf,
21062 + if (ictx->disconnected)
21063 + return -ENODEV;
21064 +
21065 +- mutex_lock(&ictx->lock);
21066 ++ if (mutex_lock_interruptible(&ictx->lock))
21067 ++ return -ERESTARTSYS;
21068 +
21069 + if (!ictx->dev_present_intf0) {
21070 + pr_err_ratelimited("no iMON device present\n");
21071 +diff --git a/drivers/media/test-drivers/vidtv/vidtv_bridge.c b/drivers/media/test-drivers/vidtv/vidtv_bridge.c
21072 +index 82620613d56b8..dff7265a42ca2 100644
21073 +--- a/drivers/media/test-drivers/vidtv/vidtv_bridge.c
21074 ++++ b/drivers/media/test-drivers/vidtv/vidtv_bridge.c
21075 +@@ -459,26 +459,20 @@ fail_dmx_conn:
21076 + for (j = j - 1; j >= 0; --j)
21077 + dvb->demux.dmx.remove_frontend(&dvb->demux.dmx,
21078 + &dvb->dmx_fe[j]);
21079 +-fail_dmx_dev:
21080 + dvb_dmxdev_release(&dvb->dmx_dev);
21081 +-fail_dmx:
21082 ++fail_dmx_dev:
21083 + dvb_dmx_release(&dvb->demux);
21084 ++fail_dmx:
21085 ++fail_demod_probe:
21086 ++ for (i = i - 1; i >= 0; --i) {
21087 ++ dvb_unregister_frontend(dvb->fe[i]);
21088 + fail_fe:
21089 +- for (j = i; j >= 0; --j)
21090 +- dvb_unregister_frontend(dvb->fe[j]);
21091 ++ dvb_module_release(dvb->i2c_client_tuner[i]);
21092 + fail_tuner_probe:
21093 +- for (j = i; j >= 0; --j)
21094 +- if (dvb->i2c_client_tuner[j])
21095 +- dvb_module_release(dvb->i2c_client_tuner[j]);
21096 +-
21097 +-fail_demod_probe:
21098 +- for (j = i; j >= 0; --j)
21099 +- if (dvb->i2c_client_demod[j])
21100 +- dvb_module_release(dvb->i2c_client_demod[j]);
21101 +-
21102 ++ dvb_module_release(dvb->i2c_client_demod[i]);
21103 ++ }
21104 + fail_adapter:
21105 + dvb_unregister_adapter(&dvb->adapter);
21106 +-
21107 + fail_i2c:
21108 + i2c_del_adapter(&dvb->i2c_adapter);
21109 +
21110 +diff --git a/drivers/media/test-drivers/vimc/vimc-core.c b/drivers/media/test-drivers/vimc/vimc-core.c
21111 +index 2ae7a0f11ebfc..e82cfa5ffbf47 100644
21112 +--- a/drivers/media/test-drivers/vimc/vimc-core.c
21113 ++++ b/drivers/media/test-drivers/vimc/vimc-core.c
21114 +@@ -433,7 +433,7 @@ static int __init vimc_init(void)
21115 + if (ret) {
21116 + dev_err(&vimc_pdev.dev,
21117 + "platform driver registration failed (err=%d)\n", ret);
21118 +- platform_driver_unregister(&vimc_pdrv);
21119 ++ platform_device_unregister(&vimc_pdev);
21120 + return ret;
21121 + }
21122 +
21123 +diff --git a/drivers/media/test-drivers/vivid/vivid-vid-cap.c b/drivers/media/test-drivers/vivid/vivid-vid-cap.c
21124 +index 99139a8cd4c4f..331a3f4286d2e 100644
21125 +--- a/drivers/media/test-drivers/vivid/vivid-vid-cap.c
21126 ++++ b/drivers/media/test-drivers/vivid/vivid-vid-cap.c
21127 +@@ -961,6 +961,7 @@ int vivid_vid_cap_s_selection(struct file *file, void *fh, struct v4l2_selection
21128 + if (dev->has_compose_cap) {
21129 + v4l2_rect_set_min_size(compose, &min_rect);
21130 + v4l2_rect_set_max_size(compose, &max_rect);
21131 ++ v4l2_rect_map_inside(compose, &fmt);
21132 + }
21133 + dev->fmt_cap_rect = fmt;
21134 + tpg_s_buf_height(&dev->tpg, fmt.height);
21135 +diff --git a/drivers/media/usb/dvb-usb/az6027.c b/drivers/media/usb/dvb-usb/az6027.c
21136 +index cf15988dfb510..7d78ee09be5e1 100644
21137 +--- a/drivers/media/usb/dvb-usb/az6027.c
21138 ++++ b/drivers/media/usb/dvb-usb/az6027.c
21139 +@@ -975,6 +975,10 @@ static int az6027_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[], int n
21140 + if (msg[i].addr == 0x99) {
21141 + req = 0xBE;
21142 + index = 0;
21143 ++ if (msg[i].len < 1) {
21144 ++ i = -EOPNOTSUPP;
21145 ++ break;
21146 ++ }
21147 + value = msg[i].buf[0] & 0x00ff;
21148 + length = 1;
21149 + az6027_usb_out_op(d, req, value, index, data, length);
21150 +diff --git a/drivers/media/usb/dvb-usb/dvb-usb-init.c b/drivers/media/usb/dvb-usb/dvb-usb-init.c
21151 +index 61439c8f33cab..58eea8ab54779 100644
21152 +--- a/drivers/media/usb/dvb-usb/dvb-usb-init.c
21153 ++++ b/drivers/media/usb/dvb-usb/dvb-usb-init.c
21154 +@@ -81,7 +81,7 @@ static int dvb_usb_adapter_init(struct dvb_usb_device *d, short *adapter_nrs)
21155 +
21156 + ret = dvb_usb_adapter_stream_init(adap);
21157 + if (ret)
21158 +- return ret;
21159 ++ goto stream_init_err;
21160 +
21161 + ret = dvb_usb_adapter_dvb_init(adap, adapter_nrs);
21162 + if (ret)
21163 +@@ -114,6 +114,8 @@ frontend_init_err:
21164 + dvb_usb_adapter_dvb_exit(adap);
21165 + dvb_init_err:
21166 + dvb_usb_adapter_stream_exit(adap);
21167 ++stream_init_err:
21168 ++ kfree(adap->priv);
21169 + return ret;
21170 + }
21171 +
21172 +diff --git a/drivers/media/v4l2-core/v4l2-ctrls-api.c b/drivers/media/v4l2-core/v4l2-ctrls-api.c
21173 +index 50d012ba3c02e..7781ebd7ee95f 100644
21174 +--- a/drivers/media/v4l2-core/v4l2-ctrls-api.c
21175 ++++ b/drivers/media/v4l2-core/v4l2-ctrls-api.c
21176 +@@ -155,6 +155,7 @@ static int user_to_new(struct v4l2_ext_control *c, struct v4l2_ctrl *ctrl)
21177 + * then return an error.
21178 + */
21179 + if (strlen(ctrl->p_new.p_char) == ctrl->maximum && last)
21180 ++ ctrl->is_new = 1;
21181 + return -ERANGE;
21182 + }
21183 + return ret;
21184 +diff --git a/drivers/media/v4l2-core/v4l2-ctrls-core.c b/drivers/media/v4l2-core/v4l2-ctrls-core.c
21185 +index 1f85828d6694d..322f9f715b65b 100644
21186 +--- a/drivers/media/v4l2-core/v4l2-ctrls-core.c
21187 ++++ b/drivers/media/v4l2-core/v4l2-ctrls-core.c
21188 +@@ -1762,7 +1762,7 @@ struct v4l2_ctrl *v4l2_ctrl_new_std_menu(struct v4l2_ctrl_handler *hdl,
21189 + else if (type == V4L2_CTRL_TYPE_INTEGER_MENU)
21190 + qmenu_int = v4l2_ctrl_get_int_menu(id, &qmenu_int_len);
21191 +
21192 +- if ((!qmenu && !qmenu_int) || (qmenu_int && max > qmenu_int_len)) {
21193 ++ if ((!qmenu && !qmenu_int) || (qmenu_int && max >= qmenu_int_len)) {
21194 + handler_set_err(hdl, -EINVAL);
21195 + return NULL;
21196 + }
21197 +diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c
21198 +index e6fd355a2e92c..de83714f0d403 100644
21199 +--- a/drivers/media/v4l2-core/v4l2-ioctl.c
21200 ++++ b/drivers/media/v4l2-core/v4l2-ioctl.c
21201 +@@ -1347,23 +1347,23 @@ static void v4l_fill_fmtdesc(struct v4l2_fmtdesc *fmt)
21202 + case V4L2_PIX_FMT_YUV420: descr = "Planar YUV 4:2:0"; break;
21203 + case V4L2_PIX_FMT_HI240: descr = "8-bit Dithered RGB (BTTV)"; break;
21204 + case V4L2_PIX_FMT_M420: descr = "YUV 4:2:0 (M420)"; break;
21205 +- case V4L2_PIX_FMT_NV12: descr = "Y/CbCr 4:2:0"; break;
21206 +- case V4L2_PIX_FMT_NV21: descr = "Y/CrCb 4:2:0"; break;
21207 +- case V4L2_PIX_FMT_NV16: descr = "Y/CbCr 4:2:2"; break;
21208 +- case V4L2_PIX_FMT_NV61: descr = "Y/CrCb 4:2:2"; break;
21209 +- case V4L2_PIX_FMT_NV24: descr = "Y/CbCr 4:4:4"; break;
21210 +- case V4L2_PIX_FMT_NV42: descr = "Y/CrCb 4:4:4"; break;
21211 +- case V4L2_PIX_FMT_P010: descr = "10-bit Y/CbCr 4:2:0"; break;
21212 +- case V4L2_PIX_FMT_NV12_4L4: descr = "Y/CbCr 4:2:0 (4x4 Linear)"; break;
21213 +- case V4L2_PIX_FMT_NV12_16L16: descr = "Y/CbCr 4:2:0 (16x16 Linear)"; break;
21214 +- case V4L2_PIX_FMT_NV12_32L32: descr = "Y/CbCr 4:2:0 (32x32 Linear)"; break;
21215 +- case V4L2_PIX_FMT_P010_4L4: descr = "10-bit Y/CbCr 4:2:0 (4x4 Linear)"; break;
21216 +- case V4L2_PIX_FMT_NV12M: descr = "Y/CbCr 4:2:0 (N-C)"; break;
21217 +- case V4L2_PIX_FMT_NV21M: descr = "Y/CrCb 4:2:0 (N-C)"; break;
21218 +- case V4L2_PIX_FMT_NV16M: descr = "Y/CbCr 4:2:2 (N-C)"; break;
21219 +- case V4L2_PIX_FMT_NV61M: descr = "Y/CrCb 4:2:2 (N-C)"; break;
21220 +- case V4L2_PIX_FMT_NV12MT: descr = "Y/CbCr 4:2:0 (64x32 MB, N-C)"; break;
21221 +- case V4L2_PIX_FMT_NV12MT_16X16: descr = "Y/CbCr 4:2:0 (16x16 MB, N-C)"; break;
21222 ++ case V4L2_PIX_FMT_NV12: descr = "Y/UV 4:2:0"; break;
21223 ++ case V4L2_PIX_FMT_NV21: descr = "Y/VU 4:2:0"; break;
21224 ++ case V4L2_PIX_FMT_NV16: descr = "Y/UV 4:2:2"; break;
21225 ++ case V4L2_PIX_FMT_NV61: descr = "Y/VU 4:2:2"; break;
21226 ++ case V4L2_PIX_FMT_NV24: descr = "Y/UV 4:4:4"; break;
21227 ++ case V4L2_PIX_FMT_NV42: descr = "Y/VU 4:4:4"; break;
21228 ++ case V4L2_PIX_FMT_P010: descr = "10-bit Y/UV 4:2:0"; break;
21229 ++ case V4L2_PIX_FMT_NV12_4L4: descr = "Y/UV 4:2:0 (4x4 Linear)"; break;
21230 ++ case V4L2_PIX_FMT_NV12_16L16: descr = "Y/UV 4:2:0 (16x16 Linear)"; break;
21231 ++ case V4L2_PIX_FMT_NV12_32L32: descr = "Y/UV 4:2:0 (32x32 Linear)"; break;
21232 ++ case V4L2_PIX_FMT_P010_4L4: descr = "10-bit Y/UV 4:2:0 (4x4 Linear)"; break;
21233 ++ case V4L2_PIX_FMT_NV12M: descr = "Y/UV 4:2:0 (N-C)"; break;
21234 ++ case V4L2_PIX_FMT_NV21M: descr = "Y/VU 4:2:0 (N-C)"; break;
21235 ++ case V4L2_PIX_FMT_NV16M: descr = "Y/UV 4:2:2 (N-C)"; break;
21236 ++ case V4L2_PIX_FMT_NV61M: descr = "Y/VU 4:2:2 (N-C)"; break;
21237 ++ case V4L2_PIX_FMT_NV12MT: descr = "Y/UV 4:2:0 (64x32 MB, N-C)"; break;
21238 ++ case V4L2_PIX_FMT_NV12MT_16X16: descr = "Y/UV 4:2:0 (16x16 MB, N-C)"; break;
21239 + case V4L2_PIX_FMT_YUV420M: descr = "Planar YUV 4:2:0 (N-C)"; break;
21240 + case V4L2_PIX_FMT_YVU420M: descr = "Planar YVU 4:2:0 (N-C)"; break;
21241 + case V4L2_PIX_FMT_YUV422M: descr = "Planar YUV 4:2:2 (N-C)"; break;
21242 +diff --git a/drivers/media/v4l2-core/videobuf-dma-contig.c b/drivers/media/v4l2-core/videobuf-dma-contig.c
21243 +index 52312ce2ba056..f2c4393595574 100644
21244 +--- a/drivers/media/v4l2-core/videobuf-dma-contig.c
21245 ++++ b/drivers/media/v4l2-core/videobuf-dma-contig.c
21246 +@@ -36,12 +36,11 @@ struct videobuf_dma_contig_memory {
21247 +
21248 + static int __videobuf_dc_alloc(struct device *dev,
21249 + struct videobuf_dma_contig_memory *mem,
21250 +- unsigned long size, gfp_t flags)
21251 ++ unsigned long size)
21252 + {
21253 + mem->size = size;
21254 +- mem->vaddr = dma_alloc_coherent(dev, mem->size,
21255 +- &mem->dma_handle, flags);
21256 +-
21257 ++ mem->vaddr = dma_alloc_coherent(dev, mem->size, &mem->dma_handle,
21258 ++ GFP_KERNEL);
21259 + if (!mem->vaddr) {
21260 + dev_err(dev, "memory alloc size %ld failed\n", mem->size);
21261 + return -ENOMEM;
21262 +@@ -258,8 +257,7 @@ static int __videobuf_iolock(struct videobuf_queue *q,
21263 + return videobuf_dma_contig_user_get(mem, vb);
21264 +
21265 + /* allocate memory for the read() method */
21266 +- if (__videobuf_dc_alloc(q->dev, mem, PAGE_ALIGN(vb->size),
21267 +- GFP_KERNEL))
21268 ++ if (__videobuf_dc_alloc(q->dev, mem, PAGE_ALIGN(vb->size)))
21269 + return -ENOMEM;
21270 + break;
21271 + case V4L2_MEMORY_OVERLAY:
21272 +@@ -295,22 +293,18 @@ static int __videobuf_mmap_mapper(struct videobuf_queue *q,
21273 + BUG_ON(!mem);
21274 + MAGIC_CHECK(mem->magic, MAGIC_DC_MEM);
21275 +
21276 +- if (__videobuf_dc_alloc(q->dev, mem, PAGE_ALIGN(buf->bsize),
21277 +- GFP_KERNEL | __GFP_COMP))
21278 ++ if (__videobuf_dc_alloc(q->dev, mem, PAGE_ALIGN(buf->bsize)))
21279 + goto error;
21280 +
21281 +- /* Try to remap memory */
21282 +- vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
21283 +-
21284 + /* the "vm_pgoff" is just used in v4l2 to find the
21285 + * corresponding buffer data structure which is allocated
21286 + * earlier and it does not mean the offset from the physical
21287 + * buffer start address as usual. So set it to 0 to pass
21288 +- * the sanity check in vm_iomap_memory().
21289 ++ * the sanity check in dma_mmap_coherent().
21290 + */
21291 + vma->vm_pgoff = 0;
21292 +-
21293 +- retval = vm_iomap_memory(vma, mem->dma_handle, mem->size);
21294 ++ retval = dma_mmap_coherent(q->dev, vma, mem->vaddr, mem->dma_handle,
21295 ++ mem->size);
21296 + if (retval) {
21297 + dev_err(q->dev, "mmap: remap failed with error %d. ",
21298 + retval);
21299 +diff --git a/drivers/memory/renesas-rpc-if.c b/drivers/memory/renesas-rpc-if.c
21300 +index 4316988d791a5..61c288d403750 100644
21301 +--- a/drivers/memory/renesas-rpc-if.c
21302 ++++ b/drivers/memory/renesas-rpc-if.c
21303 +@@ -317,6 +317,9 @@ int rpcif_hw_init(struct rpcif *rpc, bool hyperflash)
21304 + regmap_update_bits(rpc->regmap, RPCIF_PHYCNT, RPCIF_PHYCNT_PHYMEM_MASK,
21305 + RPCIF_PHYCNT_PHYMEM(hyperflash ? 3 : 0));
21306 +
21307 ++ /* DMA Transfer is not supported */
21308 ++ regmap_update_bits(rpc->regmap, RPCIF_PHYCNT, RPCIF_PHYCNT_HS, 0);
21309 ++
21310 + if (rpc->type == RPCIF_RCAR_GEN3)
21311 + regmap_update_bits(rpc->regmap, RPCIF_PHYCNT,
21312 + RPCIF_PHYCNT_STRTIM(7), RPCIF_PHYCNT_STRTIM(7));
21313 +diff --git a/drivers/memstick/core/ms_block.c b/drivers/memstick/core/ms_block.c
21314 +index ba84145195158..04115cd92433b 100644
21315 +--- a/drivers/memstick/core/ms_block.c
21316 ++++ b/drivers/memstick/core/ms_block.c
21317 +@@ -2116,6 +2116,11 @@ static int msb_init_disk(struct memstick_dev *card)
21318 + dbg("Set total disk size to %lu sectors", capacity);
21319 +
21320 + msb->io_queue = alloc_ordered_workqueue("ms_block", WQ_MEM_RECLAIM);
21321 ++ if (!msb->io_queue) {
21322 ++ rc = -ENOMEM;
21323 ++ goto out_cleanup_disk;
21324 ++ }
21325 ++
21326 + INIT_WORK(&msb->io_work, msb_io_work);
21327 + sg_init_table(msb->prealloc_sg, MS_BLOCK_MAX_SEGS+1);
21328 +
21329 +@@ -2125,10 +2130,12 @@ static int msb_init_disk(struct memstick_dev *card)
21330 + msb_start(card);
21331 + rc = device_add_disk(&card->dev, msb->disk, NULL);
21332 + if (rc)
21333 +- goto out_cleanup_disk;
21334 ++ goto out_destroy_workqueue;
21335 + dbg("Disk added");
21336 + return 0;
21337 +
21338 ++out_destroy_workqueue:
21339 ++ destroy_workqueue(msb->io_queue);
21340 + out_cleanup_disk:
21341 + put_disk(msb->disk);
21342 + out_free_tag_set:
21343 +diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
21344 +index abb58ab1a1a4f..3e8becef3cb05 100644
21345 +--- a/drivers/mfd/Kconfig
21346 ++++ b/drivers/mfd/Kconfig
21347 +@@ -1968,6 +1968,7 @@ config MFD_ROHM_BD957XMUF
21348 + depends on I2C=y
21349 + depends on OF
21350 + select REGMAP_I2C
21351 ++ select REGMAP_IRQ
21352 + select MFD_CORE
21353 + help
21354 + Select this option to get support for the ROHM BD9576MUF and
21355 +diff --git a/drivers/mfd/axp20x.c b/drivers/mfd/axp20x.c
21356 +index 88a212a8168cf..880c41fa7021b 100644
21357 +--- a/drivers/mfd/axp20x.c
21358 ++++ b/drivers/mfd/axp20x.c
21359 +@@ -842,7 +842,7 @@ static void axp20x_power_off(void)
21360 + AXP20X_OFF);
21361 +
21362 + /* Give capacitors etc. time to drain to avoid kernel panic msg. */
21363 +- msleep(500);
21364 ++ mdelay(500);
21365 + }
21366 +
21367 + int axp20x_match_device(struct axp20x_dev *axp20x)
21368 +diff --git a/drivers/mfd/qcom-pm8008.c b/drivers/mfd/qcom-pm8008.c
21369 +index 4b8ff947762f2..9f3c4a01b4c1c 100644
21370 +--- a/drivers/mfd/qcom-pm8008.c
21371 ++++ b/drivers/mfd/qcom-pm8008.c
21372 +@@ -215,8 +215,8 @@ static int pm8008_probe(struct i2c_client *client)
21373 +
21374 + dev = &client->dev;
21375 + regmap = devm_regmap_init_i2c(client, &qcom_mfd_regmap_cfg);
21376 +- if (!regmap)
21377 +- return -ENODEV;
21378 ++ if (IS_ERR(regmap))
21379 ++ return PTR_ERR(regmap);
21380 +
21381 + i2c_set_clientdata(client, regmap);
21382 +
21383 +diff --git a/drivers/mfd/qcom_rpm.c b/drivers/mfd/qcom_rpm.c
21384 +index 71bc34b74bc9c..8fea0e511550a 100644
21385 +--- a/drivers/mfd/qcom_rpm.c
21386 ++++ b/drivers/mfd/qcom_rpm.c
21387 +@@ -547,7 +547,7 @@ static int qcom_rpm_probe(struct platform_device *pdev)
21388 + init_completion(&rpm->ack);
21389 +
21390 + /* Enable message RAM clock */
21391 +- rpm->ramclk = devm_clk_get(&pdev->dev, "ram");
21392 ++ rpm->ramclk = devm_clk_get_enabled(&pdev->dev, "ram");
21393 + if (IS_ERR(rpm->ramclk)) {
21394 + ret = PTR_ERR(rpm->ramclk);
21395 + if (ret == -EPROBE_DEFER)
21396 +@@ -558,7 +558,6 @@ static int qcom_rpm_probe(struct platform_device *pdev)
21397 + */
21398 + rpm->ramclk = NULL;
21399 + }
21400 +- clk_prepare_enable(rpm->ramclk); /* Accepts NULL */
21401 +
21402 + irq_ack = platform_get_irq_byname(pdev, "ack");
21403 + if (irq_ack < 0)
21404 +@@ -673,22 +672,11 @@ static int qcom_rpm_probe(struct platform_device *pdev)
21405 + if (ret)
21406 + dev_warn(&pdev->dev, "failed to mark wakeup irq as wakeup\n");
21407 +
21408 +- return of_platform_populate(pdev->dev.of_node, NULL, NULL, &pdev->dev);
21409 +-}
21410 +-
21411 +-static int qcom_rpm_remove(struct platform_device *pdev)
21412 +-{
21413 +- struct qcom_rpm *rpm = dev_get_drvdata(&pdev->dev);
21414 +-
21415 +- of_platform_depopulate(&pdev->dev);
21416 +- clk_disable_unprepare(rpm->ramclk);
21417 +-
21418 +- return 0;
21419 ++ return devm_of_platform_populate(&pdev->dev);
21420 + }
21421 +
21422 + static struct platform_driver qcom_rpm_driver = {
21423 + .probe = qcom_rpm_probe,
21424 +- .remove = qcom_rpm_remove,
21425 + .driver = {
21426 + .name = "qcom_rpm",
21427 + .of_match_table = qcom_rpm_of_match,
21428 +diff --git a/drivers/misc/cxl/guest.c b/drivers/misc/cxl/guest.c
21429 +index 375f692ae9d68..fb95a2d5cef48 100644
21430 +--- a/drivers/misc/cxl/guest.c
21431 ++++ b/drivers/misc/cxl/guest.c
21432 +@@ -965,10 +965,10 @@ int cxl_guest_init_afu(struct cxl *adapter, int slice, struct device_node *afu_n
21433 + * if it returns an error!
21434 + */
21435 + if ((rc = cxl_register_afu(afu)))
21436 +- goto err_put1;
21437 ++ goto err_put_dev;
21438 +
21439 + if ((rc = cxl_sysfs_afu_add(afu)))
21440 +- goto err_put1;
21441 ++ goto err_del_dev;
21442 +
21443 + /*
21444 + * pHyp doesn't expose the programming models supported by the
21445 +@@ -984,7 +984,7 @@ int cxl_guest_init_afu(struct cxl *adapter, int slice, struct device_node *afu_n
21446 + afu->modes_supported = CXL_MODE_DIRECTED;
21447 +
21448 + if ((rc = cxl_afu_select_best_mode(afu)))
21449 +- goto err_put2;
21450 ++ goto err_remove_sysfs;
21451 +
21452 + adapter->afu[afu->slice] = afu;
21453 +
21454 +@@ -1004,10 +1004,12 @@ int cxl_guest_init_afu(struct cxl *adapter, int slice, struct device_node *afu_n
21455 +
21456 + return 0;
21457 +
21458 +-err_put2:
21459 ++err_remove_sysfs:
21460 + cxl_sysfs_afu_remove(afu);
21461 +-err_put1:
21462 +- device_unregister(&afu->dev);
21463 ++err_del_dev:
21464 ++ device_del(&afu->dev);
21465 ++err_put_dev:
21466 ++ put_device(&afu->dev);
21467 + free = false;
21468 + guest_release_serr_irq(afu);
21469 + err2:
21470 +@@ -1141,18 +1143,20 @@ struct cxl *cxl_guest_init_adapter(struct device_node *np, struct platform_devic
21471 + * even if it returns an error!
21472 + */
21473 + if ((rc = cxl_register_adapter(adapter)))
21474 +- goto err_put1;
21475 ++ goto err_put_dev;
21476 +
21477 + if ((rc = cxl_sysfs_adapter_add(adapter)))
21478 +- goto err_put1;
21479 ++ goto err_del_dev;
21480 +
21481 + /* release the context lock as the adapter is configured */
21482 + cxl_adapter_context_unlock(adapter);
21483 +
21484 + return adapter;
21485 +
21486 +-err_put1:
21487 +- device_unregister(&adapter->dev);
21488 ++err_del_dev:
21489 ++ device_del(&adapter->dev);
21490 ++err_put_dev:
21491 ++ put_device(&adapter->dev);
21492 + free = false;
21493 + cxl_guest_remove_chardev(adapter);
21494 + err1:
21495 +diff --git a/drivers/misc/cxl/pci.c b/drivers/misc/cxl/pci.c
21496 +index 3de0aea62ade4..0ff944860dda9 100644
21497 +--- a/drivers/misc/cxl/pci.c
21498 ++++ b/drivers/misc/cxl/pci.c
21499 +@@ -387,6 +387,7 @@ int cxl_calc_capp_routing(struct pci_dev *dev, u64 *chipid,
21500 + rc = get_phb_index(np, phb_index);
21501 + if (rc) {
21502 + pr_err("cxl: invalid phb index\n");
21503 ++ of_node_put(np);
21504 + return rc;
21505 + }
21506 +
21507 +@@ -1164,10 +1165,10 @@ static int pci_init_afu(struct cxl *adapter, int slice, struct pci_dev *dev)
21508 + * if it returns an error!
21509 + */
21510 + if ((rc = cxl_register_afu(afu)))
21511 +- goto err_put1;
21512 ++ goto err_put_dev;
21513 +
21514 + if ((rc = cxl_sysfs_afu_add(afu)))
21515 +- goto err_put1;
21516 ++ goto err_del_dev;
21517 +
21518 + adapter->afu[afu->slice] = afu;
21519 +
21520 +@@ -1176,10 +1177,12 @@ static int pci_init_afu(struct cxl *adapter, int slice, struct pci_dev *dev)
21521 +
21522 + return 0;
21523 +
21524 +-err_put1:
21525 ++err_del_dev:
21526 ++ device_del(&afu->dev);
21527 ++err_put_dev:
21528 + pci_deconfigure_afu(afu);
21529 + cxl_debugfs_afu_remove(afu);
21530 +- device_unregister(&afu->dev);
21531 ++ put_device(&afu->dev);
21532 + return rc;
21533 +
21534 + err_free_native:
21535 +@@ -1667,23 +1670,25 @@ static struct cxl *cxl_pci_init_adapter(struct pci_dev *dev)
21536 + * even if it returns an error!
21537 + */
21538 + if ((rc = cxl_register_adapter(adapter)))
21539 +- goto err_put1;
21540 ++ goto err_put_dev;
21541 +
21542 + if ((rc = cxl_sysfs_adapter_add(adapter)))
21543 +- goto err_put1;
21544 ++ goto err_del_dev;
21545 +
21546 + /* Release the context lock as adapter is configured */
21547 + cxl_adapter_context_unlock(adapter);
21548 +
21549 + return adapter;
21550 +
21551 +-err_put1:
21552 ++err_del_dev:
21553 ++ device_del(&adapter->dev);
21554 ++err_put_dev:
21555 + /* This should mirror cxl_remove_adapter, except without the
21556 + * sysfs parts
21557 + */
21558 + cxl_debugfs_adapter_remove(adapter);
21559 + cxl_deconfigure_adapter(adapter);
21560 +- device_unregister(&adapter->dev);
21561 ++ put_device(&adapter->dev);
21562 + return ERR_PTR(rc);
21563 +
21564 + err_release:
21565 +diff --git a/drivers/misc/lkdtm/cfi.c b/drivers/misc/lkdtm/cfi.c
21566 +index 71483cb1e422a..f4fd30f7a9a0e 100644
21567 +--- a/drivers/misc/lkdtm/cfi.c
21568 ++++ b/drivers/misc/lkdtm/cfi.c
21569 +@@ -51,7 +51,11 @@ static void lkdtm_CFI_FORWARD_PROTO(void)
21570 + # ifdef CONFIG_ARM64_BTI_KERNEL
21571 + # define __no_pac "branch-protection=bti"
21572 + # else
21573 +-# define __no_pac "branch-protection=none"
21574 ++# ifdef CONFIG_CC_HAS_BRANCH_PROT_PAC_RET
21575 ++# define __no_pac "branch-protection=none"
21576 ++# else
21577 ++# define __no_pac "sign-return-address=none"
21578 ++# endif
21579 + # endif
21580 + # define __no_ret_protection __noscs __attribute__((__target__(__no_pac)))
21581 + #else
21582 +diff --git a/drivers/misc/ocxl/config.c b/drivers/misc/ocxl/config.c
21583 +index e401a51596b9c..92ab49705f645 100644
21584 +--- a/drivers/misc/ocxl/config.c
21585 ++++ b/drivers/misc/ocxl/config.c
21586 +@@ -193,6 +193,18 @@ static int read_dvsec_vendor(struct pci_dev *dev)
21587 + return 0;
21588 + }
21589 +
21590 ++/**
21591 ++ * get_dvsec_vendor0() - Find a related PCI device (function 0)
21592 ++ * @dev: PCI device to match
21593 ++ * @dev0: The PCI device (function 0) found
21594 ++ * @out_pos: The position of PCI device (function 0)
21595 ++ *
21596 ++ * Returns 0 on success, negative on failure.
21597 ++ *
21598 ++ * NOTE: If it's successful, the reference of dev0 is increased,
21599 ++ * so after using it, the callers must call pci_dev_put() to give
21600 ++ * up the reference.
21601 ++ */
21602 + static int get_dvsec_vendor0(struct pci_dev *dev, struct pci_dev **dev0,
21603 + int *out_pos)
21604 + {
21605 +@@ -202,10 +214,14 @@ static int get_dvsec_vendor0(struct pci_dev *dev, struct pci_dev **dev0,
21606 + dev = get_function_0(dev);
21607 + if (!dev)
21608 + return -1;
21609 ++ } else {
21610 ++ dev = pci_dev_get(dev);
21611 + }
21612 + pos = find_dvsec(dev, OCXL_DVSEC_VENDOR_ID);
21613 +- if (!pos)
21614 ++ if (!pos) {
21615 ++ pci_dev_put(dev);
21616 + return -1;
21617 ++ }
21618 + *dev0 = dev;
21619 + *out_pos = pos;
21620 + return 0;
21621 +@@ -222,6 +238,7 @@ int ocxl_config_get_reset_reload(struct pci_dev *dev, int *val)
21622 +
21623 + pci_read_config_dword(dev0, pos + OCXL_DVSEC_VENDOR_RESET_RELOAD,
21624 + &reset_reload);
21625 ++ pci_dev_put(dev0);
21626 + *val = !!(reset_reload & BIT(0));
21627 + return 0;
21628 + }
21629 +@@ -243,6 +260,7 @@ int ocxl_config_set_reset_reload(struct pci_dev *dev, int val)
21630 + reset_reload &= ~BIT(0);
21631 + pci_write_config_dword(dev0, pos + OCXL_DVSEC_VENDOR_RESET_RELOAD,
21632 + reset_reload);
21633 ++ pci_dev_put(dev0);
21634 + return 0;
21635 + }
21636 +
21637 +diff --git a/drivers/misc/ocxl/file.c b/drivers/misc/ocxl/file.c
21638 +index d46dba2df5a10..452d5777a0e4c 100644
21639 +--- a/drivers/misc/ocxl/file.c
21640 ++++ b/drivers/misc/ocxl/file.c
21641 +@@ -541,8 +541,11 @@ int ocxl_file_register_afu(struct ocxl_afu *afu)
21642 + goto err_put;
21643 +
21644 + rc = device_register(&info->dev);
21645 +- if (rc)
21646 +- goto err_put;
21647 ++ if (rc) {
21648 ++ free_minor(info);
21649 ++ put_device(&info->dev);
21650 ++ return rc;
21651 ++ }
21652 +
21653 + rc = ocxl_sysfs_register_afu(info);
21654 + if (rc)
21655 +diff --git a/drivers/misc/sgi-gru/grufault.c b/drivers/misc/sgi-gru/grufault.c
21656 +index d7ef61e602ede..b836936e97471 100644
21657 +--- a/drivers/misc/sgi-gru/grufault.c
21658 ++++ b/drivers/misc/sgi-gru/grufault.c
21659 +@@ -648,6 +648,7 @@ int gru_handle_user_call_os(unsigned long cb)
21660 + if ((cb & (GRU_HANDLE_STRIDE - 1)) || ucbnum >= GRU_NUM_CB)
21661 + return -EINVAL;
21662 +
21663 ++again:
21664 + gts = gru_find_lock_gts(cb);
21665 + if (!gts)
21666 + return -EINVAL;
21667 +@@ -656,7 +657,11 @@ int gru_handle_user_call_os(unsigned long cb)
21668 + if (ucbnum >= gts->ts_cbr_au_count * GRU_CBR_AU_SIZE)
21669 + goto exit;
21670 +
21671 +- gru_check_context_placement(gts);
21672 ++ if (gru_check_context_placement(gts)) {
21673 ++ gru_unlock_gts(gts);
21674 ++ gru_unload_context(gts, 1);
21675 ++ goto again;
21676 ++ }
21677 +
21678 + /*
21679 + * CCH may contain stale data if ts_force_cch_reload is set.
21680 +@@ -874,7 +879,11 @@ int gru_set_context_option(unsigned long arg)
21681 + } else {
21682 + gts->ts_user_blade_id = req.val1;
21683 + gts->ts_user_chiplet_id = req.val0;
21684 +- gru_check_context_placement(gts);
21685 ++ if (gru_check_context_placement(gts)) {
21686 ++ gru_unlock_gts(gts);
21687 ++ gru_unload_context(gts, 1);
21688 ++ return ret;
21689 ++ }
21690 + }
21691 + break;
21692 + case sco_gseg_owner:
21693 +diff --git a/drivers/misc/sgi-gru/grumain.c b/drivers/misc/sgi-gru/grumain.c
21694 +index 9afda47efbf2e..3a16eb8e03f73 100644
21695 +--- a/drivers/misc/sgi-gru/grumain.c
21696 ++++ b/drivers/misc/sgi-gru/grumain.c
21697 +@@ -716,9 +716,10 @@ static int gru_check_chiplet_assignment(struct gru_state *gru,
21698 + * chiplet. Misassignment can occur if the process migrates to a different
21699 + * blade or if the user changes the selected blade/chiplet.
21700 + */
21701 +-void gru_check_context_placement(struct gru_thread_state *gts)
21702 ++int gru_check_context_placement(struct gru_thread_state *gts)
21703 + {
21704 + struct gru_state *gru;
21705 ++ int ret = 0;
21706 +
21707 + /*
21708 + * If the current task is the context owner, verify that the
21709 +@@ -726,15 +727,23 @@ void gru_check_context_placement(struct gru_thread_state *gts)
21710 + * references. Pthread apps use non-owner references to the CBRs.
21711 + */
21712 + gru = gts->ts_gru;
21713 ++ /*
21714 ++ * If gru or gts->ts_tgid_owner isn't initialized properly, return
21715 ++ * success to indicate that the caller does not need to unload the
21716 ++ * gru context.The caller is responsible for their inspection and
21717 ++ * reinitialization if needed.
21718 ++ */
21719 + if (!gru || gts->ts_tgid_owner != current->tgid)
21720 +- return;
21721 ++ return ret;
21722 +
21723 + if (!gru_check_chiplet_assignment(gru, gts)) {
21724 + STAT(check_context_unload);
21725 +- gru_unload_context(gts, 1);
21726 ++ ret = -EINVAL;
21727 + } else if (gru_retarget_intr(gts)) {
21728 + STAT(check_context_retarget_intr);
21729 + }
21730 ++
21731 ++ return ret;
21732 + }
21733 +
21734 +
21735 +@@ -934,7 +943,12 @@ again:
21736 + mutex_lock(&gts->ts_ctxlock);
21737 + preempt_disable();
21738 +
21739 +- gru_check_context_placement(gts);
21740 ++ if (gru_check_context_placement(gts)) {
21741 ++ preempt_enable();
21742 ++ mutex_unlock(&gts->ts_ctxlock);
21743 ++ gru_unload_context(gts, 1);
21744 ++ return VM_FAULT_NOPAGE;
21745 ++ }
21746 +
21747 + if (!gts->ts_gru) {
21748 + STAT(load_user_context);
21749 +diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
21750 +index 5efc869fe59a0..f4a5a787685fb 100644
21751 +--- a/drivers/misc/sgi-gru/grutables.h
21752 ++++ b/drivers/misc/sgi-gru/grutables.h
21753 +@@ -632,7 +632,7 @@ extern int gru_user_flush_tlb(unsigned long arg);
21754 + extern int gru_user_unload_context(unsigned long arg);
21755 + extern int gru_get_exception_detail(unsigned long arg);
21756 + extern int gru_set_context_option(unsigned long address);
21757 +-extern void gru_check_context_placement(struct gru_thread_state *gts);
21758 ++extern int gru_check_context_placement(struct gru_thread_state *gts);
21759 + extern int gru_cpu_fault_map_id(void);
21760 + extern struct vm_area_struct *gru_find_vma(unsigned long vaddr);
21761 + extern void gru_flush_all_tlb(struct gru_state *gru);
21762 +diff --git a/drivers/misc/tifm_7xx1.c b/drivers/misc/tifm_7xx1.c
21763 +index 017c2f7d62871..7dd86a9858aba 100644
21764 +--- a/drivers/misc/tifm_7xx1.c
21765 ++++ b/drivers/misc/tifm_7xx1.c
21766 +@@ -190,7 +190,7 @@ static void tifm_7xx1_switch_media(struct work_struct *work)
21767 + spin_unlock_irqrestore(&fm->lock, flags);
21768 + }
21769 + if (sock)
21770 +- tifm_free_device(&sock->dev);
21771 ++ put_device(&sock->dev);
21772 + }
21773 + spin_lock_irqsave(&fm->lock, flags);
21774 + }
21775 +diff --git a/drivers/mmc/core/sd.c b/drivers/mmc/core/sd.c
21776 +index 3662bf5320ce5..72b664ed90cf6 100644
21777 +--- a/drivers/mmc/core/sd.c
21778 ++++ b/drivers/mmc/core/sd.c
21779 +@@ -1259,7 +1259,7 @@ static int sd_read_ext_regs(struct mmc_card *card)
21780 + */
21781 + err = sd_read_ext_reg(card, 0, 0, 0, 512, gen_info_buf);
21782 + if (err) {
21783 +- pr_warn("%s: error %d reading general info of SD ext reg\n",
21784 ++ pr_err("%s: error %d reading general info of SD ext reg\n",
21785 + mmc_hostname(card->host), err);
21786 + goto out;
21787 + }
21788 +@@ -1273,7 +1273,12 @@ static int sd_read_ext_regs(struct mmc_card *card)
21789 + /* Number of extensions to be find. */
21790 + num_ext = gen_info_buf[4];
21791 +
21792 +- /* We support revision 0, but limit it to 512 bytes for simplicity. */
21793 ++ /*
21794 ++ * We only support revision 0 and limit it to 512 bytes for simplicity.
21795 ++ * No matter what, let's return zero to allow us to continue using the
21796 ++ * card, even if we can't support the features from the SD function
21797 ++ * extensions registers.
21798 ++ */
21799 + if (rev != 0 || len > 512) {
21800 + pr_warn("%s: non-supported SD ext reg layout\n",
21801 + mmc_hostname(card->host));
21802 +@@ -1288,7 +1293,7 @@ static int sd_read_ext_regs(struct mmc_card *card)
21803 + for (i = 0; i < num_ext; i++) {
21804 + err = sd_parse_ext_reg(card, gen_info_buf, &next_ext_addr);
21805 + if (err) {
21806 +- pr_warn("%s: error %d parsing SD ext reg\n",
21807 ++ pr_err("%s: error %d parsing SD ext reg\n",
21808 + mmc_hostname(card->host), err);
21809 + goto out;
21810 + }
21811 +diff --git a/drivers/mmc/host/alcor.c b/drivers/mmc/host/alcor.c
21812 +index bfb8efeb7eb80..d01df01d4b4d1 100644
21813 +--- a/drivers/mmc/host/alcor.c
21814 ++++ b/drivers/mmc/host/alcor.c
21815 +@@ -1114,7 +1114,10 @@ static int alcor_pci_sdmmc_drv_probe(struct platform_device *pdev)
21816 + alcor_hw_init(host);
21817 +
21818 + dev_set_drvdata(&pdev->dev, host);
21819 +- mmc_add_host(mmc);
21820 ++ ret = mmc_add_host(mmc);
21821 ++ if (ret)
21822 ++ goto free_host;
21823 ++
21824 + return 0;
21825 +
21826 + free_host:
21827 +diff --git a/drivers/mmc/host/atmel-mci.c b/drivers/mmc/host/atmel-mci.c
21828 +index 91d52ba7a39fc..bb9bbf1c927b6 100644
21829 +--- a/drivers/mmc/host/atmel-mci.c
21830 ++++ b/drivers/mmc/host/atmel-mci.c
21831 +@@ -2222,6 +2222,7 @@ static int atmci_init_slot(struct atmel_mci *host,
21832 + {
21833 + struct mmc_host *mmc;
21834 + struct atmel_mci_slot *slot;
21835 ++ int ret;
21836 +
21837 + mmc = mmc_alloc_host(sizeof(struct atmel_mci_slot), &host->pdev->dev);
21838 + if (!mmc)
21839 +@@ -2305,11 +2306,13 @@ static int atmci_init_slot(struct atmel_mci *host,
21840 +
21841 + host->slot[id] = slot;
21842 + mmc_regulator_get_supply(mmc);
21843 +- mmc_add_host(mmc);
21844 ++ ret = mmc_add_host(mmc);
21845 ++ if (ret) {
21846 ++ mmc_free_host(mmc);
21847 ++ return ret;
21848 ++ }
21849 +
21850 + if (gpio_is_valid(slot->detect_pin)) {
21851 +- int ret;
21852 +-
21853 + timer_setup(&slot->detect_timer, atmci_detect_change, 0);
21854 +
21855 + ret = request_irq(gpio_to_irq(slot->detect_pin),
21856 +diff --git a/drivers/mmc/host/litex_mmc.c b/drivers/mmc/host/litex_mmc.c
21857 +index 6ba0d63b8c078..39c6707fdfdbc 100644
21858 +--- a/drivers/mmc/host/litex_mmc.c
21859 ++++ b/drivers/mmc/host/litex_mmc.c
21860 +@@ -502,6 +502,7 @@ static int litex_mmc_irq_init(struct platform_device *pdev,
21861 +
21862 + use_polling:
21863 + host->mmc->caps |= MMC_CAP_NEEDS_POLL;
21864 ++ host->irq = 0;
21865 + return 0;
21866 + }
21867 +
21868 +diff --git a/drivers/mmc/host/meson-gx-mmc.c b/drivers/mmc/host/meson-gx-mmc.c
21869 +index fc462995cf94a..4fd3d545e4081 100644
21870 +--- a/drivers/mmc/host/meson-gx-mmc.c
21871 ++++ b/drivers/mmc/host/meson-gx-mmc.c
21872 +@@ -1291,7 +1291,9 @@ static int meson_mmc_probe(struct platform_device *pdev)
21873 + }
21874 +
21875 + mmc->ops = &meson_mmc_ops;
21876 +- mmc_add_host(mmc);
21877 ++ ret = mmc_add_host(mmc);
21878 ++ if (ret)
21879 ++ goto err_free_irq;
21880 +
21881 + return 0;
21882 +
21883 +diff --git a/drivers/mmc/host/mmci.c b/drivers/mmc/host/mmci.c
21884 +index 012aa85489d86..b9e5dfe74e5c7 100644
21885 +--- a/drivers/mmc/host/mmci.c
21886 ++++ b/drivers/mmc/host/mmci.c
21887 +@@ -2256,7 +2256,9 @@ static int mmci_probe(struct amba_device *dev,
21888 + pm_runtime_set_autosuspend_delay(&dev->dev, 50);
21889 + pm_runtime_use_autosuspend(&dev->dev);
21890 +
21891 +- mmc_add_host(mmc);
21892 ++ ret = mmc_add_host(mmc);
21893 ++ if (ret)
21894 ++ goto clk_disable;
21895 +
21896 + pm_runtime_put(&dev->dev);
21897 + return 0;
21898 +diff --git a/drivers/mmc/host/moxart-mmc.c b/drivers/mmc/host/moxart-mmc.c
21899 +index dfc3ffd5b1f8c..52ed30f2d9f4f 100644
21900 +--- a/drivers/mmc/host/moxart-mmc.c
21901 ++++ b/drivers/mmc/host/moxart-mmc.c
21902 +@@ -665,7 +665,9 @@ static int moxart_probe(struct platform_device *pdev)
21903 + goto out;
21904 +
21905 + dev_set_drvdata(dev, mmc);
21906 +- mmc_add_host(mmc);
21907 ++ ret = mmc_add_host(mmc);
21908 ++ if (ret)
21909 ++ goto out;
21910 +
21911 + dev_dbg(dev, "IRQ=%d, FIFO is %d bytes\n", irq, host->fifo_width);
21912 +
21913 +diff --git a/drivers/mmc/host/mxcmmc.c b/drivers/mmc/host/mxcmmc.c
21914 +index 2cf0413407ea2..668f865f3efb0 100644
21915 +--- a/drivers/mmc/host/mxcmmc.c
21916 ++++ b/drivers/mmc/host/mxcmmc.c
21917 +@@ -1143,7 +1143,9 @@ static int mxcmci_probe(struct platform_device *pdev)
21918 +
21919 + timer_setup(&host->watchdog, mxcmci_watchdog, 0);
21920 +
21921 +- mmc_add_host(mmc);
21922 ++ ret = mmc_add_host(mmc);
21923 ++ if (ret)
21924 ++ goto out_free_dma;
21925 +
21926 + return 0;
21927 +
21928 +diff --git a/drivers/mmc/host/omap_hsmmc.c b/drivers/mmc/host/omap_hsmmc.c
21929 +index fca30add563e9..4bd7447552055 100644
21930 +--- a/drivers/mmc/host/omap_hsmmc.c
21931 ++++ b/drivers/mmc/host/omap_hsmmc.c
21932 +@@ -1946,7 +1946,9 @@ static int omap_hsmmc_probe(struct platform_device *pdev)
21933 + if (!ret)
21934 + mmc->caps |= MMC_CAP_SDIO_IRQ;
21935 +
21936 +- mmc_add_host(mmc);
21937 ++ ret = mmc_add_host(mmc);
21938 ++ if (ret)
21939 ++ goto err_irq;
21940 +
21941 + if (mmc_pdata(host)->name != NULL) {
21942 + ret = device_create_file(&mmc->class_dev, &dev_attr_slot_name);
21943 +diff --git a/drivers/mmc/host/pxamci.c b/drivers/mmc/host/pxamci.c
21944 +index e4003f6058eb5..2a988f942b6ca 100644
21945 +--- a/drivers/mmc/host/pxamci.c
21946 ++++ b/drivers/mmc/host/pxamci.c
21947 +@@ -763,7 +763,12 @@ static int pxamci_probe(struct platform_device *pdev)
21948 + dev_warn(dev, "gpio_ro and get_ro() both defined\n");
21949 + }
21950 +
21951 +- mmc_add_host(mmc);
21952 ++ ret = mmc_add_host(mmc);
21953 ++ if (ret) {
21954 ++ if (host->pdata && host->pdata->exit)
21955 ++ host->pdata->exit(dev, mmc);
21956 ++ goto out;
21957 ++ }
21958 +
21959 + return 0;
21960 +
21961 +diff --git a/drivers/mmc/host/renesas_sdhi.h b/drivers/mmc/host/renesas_sdhi.h
21962 +index c4abfee1ebae1..e4c490729c98e 100644
21963 +--- a/drivers/mmc/host/renesas_sdhi.h
21964 ++++ b/drivers/mmc/host/renesas_sdhi.h
21965 +@@ -44,6 +44,7 @@ struct renesas_sdhi_quirks {
21966 + bool fixed_addr_mode;
21967 + bool dma_one_rx_only;
21968 + bool manual_tap_correction;
21969 ++ bool old_info1_layout;
21970 + u32 hs400_bad_taps;
21971 + const u8 (*hs400_calib_table)[SDHI_CALIB_TABLE_MAX];
21972 + };
21973 +diff --git a/drivers/mmc/host/renesas_sdhi_core.c b/drivers/mmc/host/renesas_sdhi_core.c
21974 +index b970699743e0a..e38d0e8b8e0ed 100644
21975 +--- a/drivers/mmc/host/renesas_sdhi_core.c
21976 ++++ b/drivers/mmc/host/renesas_sdhi_core.c
21977 +@@ -546,7 +546,7 @@ static void renesas_sdhi_reset_hs400_mode(struct tmio_mmc_host *host,
21978 + SH_MOBILE_SDHI_SCC_TMPPORT2_HS400OSEL) &
21979 + sd_scc_read32(host, priv, SH_MOBILE_SDHI_SCC_TMPPORT2));
21980 +
21981 +- if (priv->adjust_hs400_calib_table)
21982 ++ if (priv->quirks && (priv->quirks->hs400_calib_table || priv->quirks->hs400_bad_taps))
21983 + renesas_sdhi_adjust_hs400_mode_disable(host);
21984 +
21985 + sd_ctrl_write16(host, CTL_SD_CARD_CLK_CTL, CLK_CTL_SCLKEN |
21986 +@@ -1068,11 +1068,14 @@ int renesas_sdhi_probe(struct platform_device *pdev,
21987 + if (ver >= SDHI_VER_GEN3_SD)
21988 + host->get_timeout_cycles = renesas_sdhi_gen3_get_cycles;
21989 +
21990 ++ /* Check for SCC so we can reset it if needed */
21991 ++ if (of_data && of_data->scc_offset && ver >= SDHI_VER_GEN2_SDR104)
21992 ++ priv->scc_ctl = host->ctl + of_data->scc_offset;
21993 ++
21994 + /* Enable tuning iff we have an SCC and a supported mode */
21995 +- if (of_data && of_data->scc_offset &&
21996 +- (host->mmc->caps & MMC_CAP_UHS_SDR104 ||
21997 +- host->mmc->caps2 & (MMC_CAP2_HS200_1_8V_SDR |
21998 +- MMC_CAP2_HS400_1_8V))) {
21999 ++ if (priv->scc_ctl && (host->mmc->caps & MMC_CAP_UHS_SDR104 ||
22000 ++ host->mmc->caps2 & (MMC_CAP2_HS200_1_8V_SDR |
22001 ++ MMC_CAP2_HS400_1_8V))) {
22002 + const struct renesas_sdhi_scc *taps = of_data->taps;
22003 + bool use_4tap = quirks && quirks->hs400_4taps;
22004 + bool hit = false;
22005 +@@ -1092,7 +1095,6 @@ int renesas_sdhi_probe(struct platform_device *pdev,
22006 + if (!hit)
22007 + dev_warn(&host->pdev->dev, "Unknown clock rate for tuning\n");
22008 +
22009 +- priv->scc_ctl = host->ctl + of_data->scc_offset;
22010 + host->check_retune = renesas_sdhi_check_scc_error;
22011 + host->ops.execute_tuning = renesas_sdhi_execute_tuning;
22012 + host->ops.prepare_hs400_tuning = renesas_sdhi_prepare_hs400_tuning;
22013 +diff --git a/drivers/mmc/host/renesas_sdhi_internal_dmac.c b/drivers/mmc/host/renesas_sdhi_internal_dmac.c
22014 +index 42937596c4c41..7c81c2680701f 100644
22015 +--- a/drivers/mmc/host/renesas_sdhi_internal_dmac.c
22016 ++++ b/drivers/mmc/host/renesas_sdhi_internal_dmac.c
22017 +@@ -49,7 +49,8 @@
22018 + /* DM_CM_INFO1 and DM_CM_INFO1_MASK */
22019 + #define INFO1_CLEAR 0
22020 + #define INFO1_MASK_CLEAR GENMASK_ULL(31, 0)
22021 +-#define INFO1_DTRANEND1 BIT(17)
22022 ++#define INFO1_DTRANEND1 BIT(20)
22023 ++#define INFO1_DTRANEND1_OLD BIT(17)
22024 + #define INFO1_DTRANEND0 BIT(16)
22025 +
22026 + /* DM_CM_INFO2 and DM_CM_INFO2_MASK */
22027 +@@ -165,6 +166,7 @@ static const struct renesas_sdhi_quirks sdhi_quirks_4tap_nohs400_one_rx = {
22028 + .hs400_disabled = true,
22029 + .hs400_4taps = true,
22030 + .dma_one_rx_only = true,
22031 ++ .old_info1_layout = true,
22032 + };
22033 +
22034 + static const struct renesas_sdhi_quirks sdhi_quirks_4tap = {
22035 +diff --git a/drivers/mmc/host/rtsx_pci_sdmmc.c b/drivers/mmc/host/rtsx_pci_sdmmc.c
22036 +index e1580f78c6b2d..8098726dcc0bf 100644
22037 +--- a/drivers/mmc/host/rtsx_pci_sdmmc.c
22038 ++++ b/drivers/mmc/host/rtsx_pci_sdmmc.c
22039 +@@ -1474,6 +1474,7 @@ static int rtsx_pci_sdmmc_drv_probe(struct platform_device *pdev)
22040 + struct realtek_pci_sdmmc *host;
22041 + struct rtsx_pcr *pcr;
22042 + struct pcr_handle *handle = pdev->dev.platform_data;
22043 ++ int ret;
22044 +
22045 + if (!handle)
22046 + return -ENXIO;
22047 +@@ -1511,7 +1512,13 @@ static int rtsx_pci_sdmmc_drv_probe(struct platform_device *pdev)
22048 + pm_runtime_mark_last_busy(&pdev->dev);
22049 + pm_runtime_use_autosuspend(&pdev->dev);
22050 +
22051 +- mmc_add_host(mmc);
22052 ++ ret = mmc_add_host(mmc);
22053 ++ if (ret) {
22054 ++ pm_runtime_dont_use_autosuspend(&pdev->dev);
22055 ++ pm_runtime_disable(&pdev->dev);
22056 ++ mmc_free_host(mmc);
22057 ++ return ret;
22058 ++ }
22059 +
22060 + return 0;
22061 + }
22062 +diff --git a/drivers/mmc/host/rtsx_usb_sdmmc.c b/drivers/mmc/host/rtsx_usb_sdmmc.c
22063 +index 5fe4528e296e6..1be3a355f10d5 100644
22064 +--- a/drivers/mmc/host/rtsx_usb_sdmmc.c
22065 ++++ b/drivers/mmc/host/rtsx_usb_sdmmc.c
22066 +@@ -1332,6 +1332,7 @@ static int rtsx_usb_sdmmc_drv_probe(struct platform_device *pdev)
22067 + #ifdef RTSX_USB_USE_LEDS_CLASS
22068 + int err;
22069 + #endif
22070 ++ int ret;
22071 +
22072 + ucr = usb_get_intfdata(to_usb_interface(pdev->dev.parent));
22073 + if (!ucr)
22074 +@@ -1368,7 +1369,15 @@ static int rtsx_usb_sdmmc_drv_probe(struct platform_device *pdev)
22075 + INIT_WORK(&host->led_work, rtsx_usb_update_led);
22076 +
22077 + #endif
22078 +- mmc_add_host(mmc);
22079 ++ ret = mmc_add_host(mmc);
22080 ++ if (ret) {
22081 ++#ifdef RTSX_USB_USE_LEDS_CLASS
22082 ++ led_classdev_unregister(&host->led);
22083 ++#endif
22084 ++ mmc_free_host(mmc);
22085 ++ pm_runtime_disable(&pdev->dev);
22086 ++ return ret;
22087 ++ }
22088 +
22089 + return 0;
22090 + }
22091 +diff --git a/drivers/mmc/host/sdhci_f_sdh30.c b/drivers/mmc/host/sdhci_f_sdh30.c
22092 +index 3f5977979cf25..6c4f43e112826 100644
22093 +--- a/drivers/mmc/host/sdhci_f_sdh30.c
22094 ++++ b/drivers/mmc/host/sdhci_f_sdh30.c
22095 +@@ -168,6 +168,9 @@ static int sdhci_f_sdh30_probe(struct platform_device *pdev)
22096 + if (reg & SDHCI_CAN_DO_8BIT)
22097 + priv->vendor_hs200 = F_SDH30_EMMC_HS200;
22098 +
22099 ++ if (!(reg & SDHCI_TIMEOUT_CLK_MASK))
22100 ++ host->quirks |= SDHCI_QUIRK_DATA_TIMEOUT_USES_SDCLK;
22101 ++
22102 + ret = sdhci_add_host(host);
22103 + if (ret)
22104 + goto err_add_host;
22105 +diff --git a/drivers/mmc/host/toshsd.c b/drivers/mmc/host/toshsd.c
22106 +index 8d037c2071abc..497791ffada6d 100644
22107 +--- a/drivers/mmc/host/toshsd.c
22108 ++++ b/drivers/mmc/host/toshsd.c
22109 +@@ -651,7 +651,9 @@ static int toshsd_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
22110 + if (ret)
22111 + goto unmap;
22112 +
22113 +- mmc_add_host(mmc);
22114 ++ ret = mmc_add_host(mmc);
22115 ++ if (ret)
22116 ++ goto free_irq;
22117 +
22118 + base = pci_resource_start(pdev, 0);
22119 + dev_dbg(&pdev->dev, "MMIO %pa, IRQ %d\n", &base, pdev->irq);
22120 +@@ -660,6 +662,8 @@ static int toshsd_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
22121 +
22122 + return 0;
22123 +
22124 ++free_irq:
22125 ++ free_irq(pdev->irq, host);
22126 + unmap:
22127 + pci_iounmap(pdev, host->ioaddr);
22128 + release:
22129 +diff --git a/drivers/mmc/host/via-sdmmc.c b/drivers/mmc/host/via-sdmmc.c
22130 +index 88662a90ed960..a2b0d9461665b 100644
22131 +--- a/drivers/mmc/host/via-sdmmc.c
22132 ++++ b/drivers/mmc/host/via-sdmmc.c
22133 +@@ -1151,7 +1151,9 @@ static int via_sd_probe(struct pci_dev *pcidev,
22134 + pcidev->subsystem_device == 0x3891)
22135 + sdhost->quirks = VIA_CRDR_QUIRK_300MS_PWRDELAY;
22136 +
22137 +- mmc_add_host(mmc);
22138 ++ ret = mmc_add_host(mmc);
22139 ++ if (ret)
22140 ++ goto unmap;
22141 +
22142 + return 0;
22143 +
22144 +diff --git a/drivers/mmc/host/vub300.c b/drivers/mmc/host/vub300.c
22145 +index 97beece62fec4..ab36ec4797478 100644
22146 +--- a/drivers/mmc/host/vub300.c
22147 ++++ b/drivers/mmc/host/vub300.c
22148 +@@ -2299,14 +2299,14 @@ static int vub300_probe(struct usb_interface *interface,
22149 + 0x0000, 0x0000, &vub300->system_port_status,
22150 + sizeof(vub300->system_port_status), 1000);
22151 + if (retval < 0) {
22152 +- goto error4;
22153 ++ goto error5;
22154 + } else if (sizeof(vub300->system_port_status) == retval) {
22155 + vub300->card_present =
22156 + (0x0001 & vub300->system_port_status.port_flags) ? 1 : 0;
22157 + vub300->read_only =
22158 + (0x0010 & vub300->system_port_status.port_flags) ? 1 : 0;
22159 + } else {
22160 +- goto error4;
22161 ++ goto error5;
22162 + }
22163 + usb_set_intfdata(interface, vub300);
22164 + INIT_DELAYED_WORK(&vub300->pollwork, vub300_pollwork_thread);
22165 +@@ -2329,8 +2329,13 @@ static int vub300_probe(struct usb_interface *interface,
22166 + "USB vub300 remote SDIO host controller[%d]"
22167 + "connected with no SD/SDIO card inserted\n",
22168 + interface_to_InterfaceNumber(interface));
22169 +- mmc_add_host(mmc);
22170 ++ retval = mmc_add_host(mmc);
22171 ++ if (retval)
22172 ++ goto error6;
22173 ++
22174 + return 0;
22175 ++error6:
22176 ++ del_timer_sync(&vub300->inactivity_timer);
22177 + error5:
22178 + mmc_free_host(mmc);
22179 + /*
22180 +diff --git a/drivers/mmc/host/wbsd.c b/drivers/mmc/host/wbsd.c
22181 +index 67ecd342fe5f1..7c7ec8d10232b 100644
22182 +--- a/drivers/mmc/host/wbsd.c
22183 ++++ b/drivers/mmc/host/wbsd.c
22184 +@@ -1698,7 +1698,17 @@ static int wbsd_init(struct device *dev, int base, int irq, int dma,
22185 + */
22186 + wbsd_init_device(host);
22187 +
22188 +- mmc_add_host(mmc);
22189 ++ ret = mmc_add_host(mmc);
22190 ++ if (ret) {
22191 ++ if (!pnp)
22192 ++ wbsd_chip_poweroff(host);
22193 ++
22194 ++ wbsd_release_resources(host);
22195 ++ wbsd_free_mmc(dev);
22196 ++
22197 ++ mmc_free_host(mmc);
22198 ++ return ret;
22199 ++ }
22200 +
22201 + pr_info("%s: W83L51xD", mmc_hostname(mmc));
22202 + if (host->chip_id != 0)
22203 +diff --git a/drivers/mmc/host/wmt-sdmmc.c b/drivers/mmc/host/wmt-sdmmc.c
22204 +index 9b5c503e3a3fc..9aa3027ca25e4 100644
22205 +--- a/drivers/mmc/host/wmt-sdmmc.c
22206 ++++ b/drivers/mmc/host/wmt-sdmmc.c
22207 +@@ -856,11 +856,15 @@ static int wmt_mci_probe(struct platform_device *pdev)
22208 + /* configure the controller to a known 'ready' state */
22209 + wmt_reset_hardware(mmc);
22210 +
22211 +- mmc_add_host(mmc);
22212 ++ ret = mmc_add_host(mmc);
22213 ++ if (ret)
22214 ++ goto fail7;
22215 +
22216 + dev_info(&pdev->dev, "WMT SDHC Controller initialized\n");
22217 +
22218 + return 0;
22219 ++fail7:
22220 ++ clk_disable_unprepare(priv->clk_sdmmc);
22221 + fail6:
22222 + clk_put(priv->clk_sdmmc);
22223 + fail5_and_a_half:
22224 +diff --git a/drivers/mtd/lpddr/lpddr2_nvm.c b/drivers/mtd/lpddr/lpddr2_nvm.c
22225 +index 367e2d906de02..e71af4c490969 100644
22226 +--- a/drivers/mtd/lpddr/lpddr2_nvm.c
22227 ++++ b/drivers/mtd/lpddr/lpddr2_nvm.c
22228 +@@ -433,6 +433,8 @@ static int lpddr2_nvm_probe(struct platform_device *pdev)
22229 +
22230 + /* lpddr2_nvm address range */
22231 + add_range = platform_get_resource(pdev, IORESOURCE_MEM, 0);
22232 ++ if (!add_range)
22233 ++ return -ENODEV;
22234 +
22235 + /* Populate map_info data structure */
22236 + *map = (struct map_info) {
22237 +diff --git a/drivers/mtd/maps/pxa2xx-flash.c b/drivers/mtd/maps/pxa2xx-flash.c
22238 +index 1749dbbacc135..62a5bf41a6d72 100644
22239 +--- a/drivers/mtd/maps/pxa2xx-flash.c
22240 ++++ b/drivers/mtd/maps/pxa2xx-flash.c
22241 +@@ -64,6 +64,7 @@ static int pxa2xx_flash_probe(struct platform_device *pdev)
22242 + if (!info->map.virt) {
22243 + printk(KERN_WARNING "Failed to ioremap %s\n",
22244 + info->map.name);
22245 ++ kfree(info);
22246 + return -ENOMEM;
22247 + }
22248 + info->map.cached = ioremap_cache(info->map.phys, info->map.size);
22249 +@@ -85,6 +86,7 @@ static int pxa2xx_flash_probe(struct platform_device *pdev)
22250 + iounmap((void *)info->map.virt);
22251 + if (info->map.cached)
22252 + iounmap(info->map.cached);
22253 ++ kfree(info);
22254 + return -EIO;
22255 + }
22256 + info->mtd->dev.parent = &pdev->dev;
22257 +diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c
22258 +index 477707bcad972..c14196bbf008e 100644
22259 +--- a/drivers/mtd/mtdcore.c
22260 ++++ b/drivers/mtd/mtdcore.c
22261 +@@ -723,8 +723,10 @@ int add_mtd_device(struct mtd_info *mtd)
22262 + mtd_check_of_node(mtd);
22263 + of_node_get(mtd_get_of_node(mtd));
22264 + error = device_register(&mtd->dev);
22265 +- if (error)
22266 ++ if (error) {
22267 ++ put_device(&mtd->dev);
22268 + goto fail_added;
22269 ++ }
22270 +
22271 + /* Add the nvmem provider */
22272 + error = mtd_nvmem_add(mtd);
22273 +@@ -774,6 +776,7 @@ int del_mtd_device(struct mtd_info *mtd)
22274 + {
22275 + int ret;
22276 + struct mtd_notifier *not;
22277 ++ struct device_node *mtd_of_node;
22278 +
22279 + mutex_lock(&mtd_table_mutex);
22280 +
22281 +@@ -792,6 +795,7 @@ int del_mtd_device(struct mtd_info *mtd)
22282 + mtd->index, mtd->name, mtd->usecount);
22283 + ret = -EBUSY;
22284 + } else {
22285 ++ mtd_of_node = mtd_get_of_node(mtd);
22286 + debugfs_remove_recursive(mtd->dbg.dfs_dir);
22287 +
22288 + /* Try to remove the NVMEM provider */
22289 +@@ -803,7 +807,7 @@ int del_mtd_device(struct mtd_info *mtd)
22290 + memset(&mtd->dev, 0, sizeof(mtd->dev));
22291 +
22292 + idr_remove(&mtd_idr, mtd->index);
22293 +- of_node_put(mtd_get_of_node(mtd));
22294 ++ of_node_put(mtd_of_node);
22295 +
22296 + module_put(THIS_MODULE);
22297 + ret = 0;
22298 +@@ -2450,6 +2454,7 @@ static int __init init_mtd(void)
22299 + out_procfs:
22300 + if (proc_mtd)
22301 + remove_proc_entry("mtd", NULL);
22302 ++ bdi_unregister(mtd_bdi);
22303 + bdi_put(mtd_bdi);
22304 + err_bdi:
22305 + class_unregister(&mtd_class);
22306 +diff --git a/drivers/mtd/spi-nor/core.c b/drivers/mtd/spi-nor/core.c
22307 +index bee8fc4c9f078..0cf1a1797ea32 100644
22308 +--- a/drivers/mtd/spi-nor/core.c
22309 ++++ b/drivers/mtd/spi-nor/core.c
22310 +@@ -1914,7 +1914,8 @@ static int spi_nor_spimem_check_readop(struct spi_nor *nor,
22311 + spi_nor_spimem_setup_op(nor, &op, read->proto);
22312 +
22313 + /* convert the dummy cycles to the number of bytes */
22314 +- op.dummy.nbytes = (nor->read_dummy * op.dummy.buswidth) / 8;
22315 ++ op.dummy.nbytes = (read->num_mode_clocks + read->num_wait_states) *
22316 ++ op.dummy.buswidth / 8;
22317 + if (spi_nor_protocol_is_dtr(nor->read_proto))
22318 + op.dummy.nbytes *= 2;
22319 +
22320 +diff --git a/drivers/mtd/spi-nor/sysfs.c b/drivers/mtd/spi-nor/sysfs.c
22321 +index 9aec9d8a98ada..4c3b351aef245 100644
22322 +--- a/drivers/mtd/spi-nor/sysfs.c
22323 ++++ b/drivers/mtd/spi-nor/sysfs.c
22324 +@@ -67,6 +67,19 @@ static struct bin_attribute *spi_nor_sysfs_bin_entries[] = {
22325 + NULL
22326 + };
22327 +
22328 ++static umode_t spi_nor_sysfs_is_visible(struct kobject *kobj,
22329 ++ struct attribute *attr, int n)
22330 ++{
22331 ++ struct spi_device *spi = to_spi_device(kobj_to_dev(kobj));
22332 ++ struct spi_mem *spimem = spi_get_drvdata(spi);
22333 ++ struct spi_nor *nor = spi_mem_get_drvdata(spimem);
22334 ++
22335 ++ if (attr == &dev_attr_jedec_id.attr && !nor->info->id_len)
22336 ++ return 0;
22337 ++
22338 ++ return 0444;
22339 ++}
22340 ++
22341 + static umode_t spi_nor_sysfs_is_bin_visible(struct kobject *kobj,
22342 + struct bin_attribute *attr, int n)
22343 + {
22344 +@@ -82,6 +95,7 @@ static umode_t spi_nor_sysfs_is_bin_visible(struct kobject *kobj,
22345 +
22346 + static const struct attribute_group spi_nor_sysfs_group = {
22347 + .name = "spi-nor",
22348 ++ .is_visible = spi_nor_sysfs_is_visible,
22349 + .is_bin_visible = spi_nor_sysfs_is_bin_visible,
22350 + .attrs = spi_nor_sysfs_entries,
22351 + .bin_attrs = spi_nor_sysfs_bin_entries,
22352 +diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
22353 +index c2939621b683c..771f2a533d3f6 100644
22354 +--- a/drivers/net/bonding/bond_main.c
22355 ++++ b/drivers/net/bonding/bond_main.c
22356 +@@ -2531,12 +2531,21 @@ static int bond_slave_info_query(struct net_device *bond_dev, struct ifslave *in
22357 + /* called with rcu_read_lock() */
22358 + static int bond_miimon_inspect(struct bonding *bond)
22359 + {
22360 ++ bool ignore_updelay = false;
22361 + int link_state, commit = 0;
22362 + struct list_head *iter;
22363 + struct slave *slave;
22364 +- bool ignore_updelay;
22365 +
22366 +- ignore_updelay = !rcu_dereference(bond->curr_active_slave);
22367 ++ if (BOND_MODE(bond) == BOND_MODE_ACTIVEBACKUP) {
22368 ++ ignore_updelay = !rcu_dereference(bond->curr_active_slave);
22369 ++ } else {
22370 ++ struct bond_up_slave *usable_slaves;
22371 ++
22372 ++ usable_slaves = rcu_dereference(bond->usable_slaves);
22373 ++
22374 ++ if (usable_slaves && usable_slaves->count == 0)
22375 ++ ignore_updelay = true;
22376 ++ }
22377 +
22378 + bond_for_each_slave_rcu(bond, slave, iter) {
22379 + bond_propose_link_state(slave, BOND_LINK_NOCHANGE);
22380 +@@ -2644,8 +2653,9 @@ static void bond_miimon_link_change(struct bonding *bond,
22381 +
22382 + static void bond_miimon_commit(struct bonding *bond)
22383 + {
22384 +- struct list_head *iter;
22385 + struct slave *slave, *primary;
22386 ++ bool do_failover = false;
22387 ++ struct list_head *iter;
22388 +
22389 + bond_for_each_slave(bond, slave, iter) {
22390 + switch (slave->link_new_state) {
22391 +@@ -2689,8 +2699,9 @@ static void bond_miimon_commit(struct bonding *bond)
22392 +
22393 + bond_miimon_link_change(bond, slave, BOND_LINK_UP);
22394 +
22395 +- if (!bond->curr_active_slave || slave == primary)
22396 +- goto do_failover;
22397 ++ if (!rcu_access_pointer(bond->curr_active_slave) || slave == primary ||
22398 ++ slave->prio > rcu_dereference(bond->curr_active_slave)->prio)
22399 ++ do_failover = true;
22400 +
22401 + continue;
22402 +
22403 +@@ -2711,7 +2722,7 @@ static void bond_miimon_commit(struct bonding *bond)
22404 + bond_miimon_link_change(bond, slave, BOND_LINK_DOWN);
22405 +
22406 + if (slave == rcu_access_pointer(bond->curr_active_slave))
22407 +- goto do_failover;
22408 ++ do_failover = true;
22409 +
22410 + continue;
22411 +
22412 +@@ -2722,8 +2733,9 @@ static void bond_miimon_commit(struct bonding *bond)
22413 +
22414 + continue;
22415 + }
22416 ++ }
22417 +
22418 +-do_failover:
22419 ++ if (do_failover) {
22420 + block_netpoll_tx();
22421 + bond_select_active_slave(bond);
22422 + unblock_netpoll_tx();
22423 +@@ -3521,6 +3533,7 @@ static int bond_ab_arp_inspect(struct bonding *bond)
22424 + */
22425 + static void bond_ab_arp_commit(struct bonding *bond)
22426 + {
22427 ++ bool do_failover = false;
22428 + struct list_head *iter;
22429 + unsigned long last_tx;
22430 + struct slave *slave;
22431 +@@ -3550,8 +3563,9 @@ static void bond_ab_arp_commit(struct bonding *bond)
22432 + slave_info(bond->dev, slave->dev, "link status definitely up\n");
22433 +
22434 + if (!rtnl_dereference(bond->curr_active_slave) ||
22435 +- slave == rtnl_dereference(bond->primary_slave))
22436 +- goto do_failover;
22437 ++ slave == rtnl_dereference(bond->primary_slave) ||
22438 ++ slave->prio > rtnl_dereference(bond->curr_active_slave)->prio)
22439 ++ do_failover = true;
22440 +
22441 + }
22442 +
22443 +@@ -3570,7 +3584,7 @@ static void bond_ab_arp_commit(struct bonding *bond)
22444 +
22445 + if (slave == rtnl_dereference(bond->curr_active_slave)) {
22446 + RCU_INIT_POINTER(bond->current_arp_slave, NULL);
22447 +- goto do_failover;
22448 ++ do_failover = true;
22449 + }
22450 +
22451 + continue;
22452 +@@ -3594,8 +3608,9 @@ static void bond_ab_arp_commit(struct bonding *bond)
22453 + slave->link_new_state);
22454 + continue;
22455 + }
22456 ++ }
22457 +
22458 +-do_failover:
22459 ++ if (do_failover) {
22460 + block_netpoll_tx();
22461 + bond_select_active_slave(bond);
22462 + unblock_netpoll_tx();
22463 +diff --git a/drivers/net/can/m_can/m_can.c b/drivers/net/can/m_can/m_can.c
22464 +index 153d8fd08bd88..a562f36a99f8a 100644
22465 +--- a/drivers/net/can/m_can/m_can.c
22466 ++++ b/drivers/net/can/m_can/m_can.c
22467 +@@ -1233,10 +1233,17 @@ static int m_can_set_bittiming(struct net_device *dev)
22468 + * - setup bittiming
22469 + * - configure timestamp generation
22470 + */
22471 +-static void m_can_chip_config(struct net_device *dev)
22472 ++static int m_can_chip_config(struct net_device *dev)
22473 + {
22474 + struct m_can_classdev *cdev = netdev_priv(dev);
22475 + u32 cccr, test;
22476 ++ int err;
22477 ++
22478 ++ err = m_can_init_ram(cdev);
22479 ++ if (err) {
22480 ++ dev_err(cdev->dev, "Message RAM configuration failed\n");
22481 ++ return err;
22482 ++ }
22483 +
22484 + m_can_config_endisable(cdev, true);
22485 +
22486 +@@ -1360,18 +1367,25 @@ static void m_can_chip_config(struct net_device *dev)
22487 +
22488 + if (cdev->ops->init)
22489 + cdev->ops->init(cdev);
22490 ++
22491 ++ return 0;
22492 + }
22493 +
22494 +-static void m_can_start(struct net_device *dev)
22495 ++static int m_can_start(struct net_device *dev)
22496 + {
22497 + struct m_can_classdev *cdev = netdev_priv(dev);
22498 ++ int ret;
22499 +
22500 + /* basic m_can configuration */
22501 +- m_can_chip_config(dev);
22502 ++ ret = m_can_chip_config(dev);
22503 ++ if (ret)
22504 ++ return ret;
22505 +
22506 + cdev->can.state = CAN_STATE_ERROR_ACTIVE;
22507 +
22508 + m_can_enable_all_interrupts(cdev);
22509 ++
22510 ++ return 0;
22511 + }
22512 +
22513 + static int m_can_set_mode(struct net_device *dev, enum can_mode mode)
22514 +@@ -1800,7 +1814,9 @@ static int m_can_open(struct net_device *dev)
22515 + }
22516 +
22517 + /* start the m_can controller */
22518 +- m_can_start(dev);
22519 ++ err = m_can_start(dev);
22520 ++ if (err)
22521 ++ goto exit_irq_fail;
22522 +
22523 + if (!cdev->is_peripheral)
22524 + napi_enable(&cdev->napi);
22525 +@@ -2059,9 +2075,13 @@ int m_can_class_resume(struct device *dev)
22526 + ret = m_can_clk_start(cdev);
22527 + if (ret)
22528 + return ret;
22529 ++ ret = m_can_start(ndev);
22530 ++ if (ret) {
22531 ++ m_can_clk_stop(cdev);
22532 ++
22533 ++ return ret;
22534 ++ }
22535 +
22536 +- m_can_init_ram(cdev);
22537 +- m_can_start(ndev);
22538 + netif_device_attach(ndev);
22539 + netif_start_queue(ndev);
22540 + }
22541 +diff --git a/drivers/net/can/m_can/m_can_platform.c b/drivers/net/can/m_can/m_can_platform.c
22542 +index eee47bad05920..de6d8e01bf2e8 100644
22543 +--- a/drivers/net/can/m_can/m_can_platform.c
22544 ++++ b/drivers/net/can/m_can/m_can_platform.c
22545 +@@ -140,10 +140,6 @@ static int m_can_plat_probe(struct platform_device *pdev)
22546 +
22547 + platform_set_drvdata(pdev, mcan_class);
22548 +
22549 +- ret = m_can_init_ram(mcan_class);
22550 +- if (ret)
22551 +- goto probe_fail;
22552 +-
22553 + pm_runtime_enable(mcan_class->dev);
22554 + ret = m_can_class_register(mcan_class);
22555 + if (ret)
22556 +diff --git a/drivers/net/can/m_can/tcan4x5x-core.c b/drivers/net/can/m_can/tcan4x5x-core.c
22557 +index 41645a24384ce..2342aa011647c 100644
22558 +--- a/drivers/net/can/m_can/tcan4x5x-core.c
22559 ++++ b/drivers/net/can/m_can/tcan4x5x-core.c
22560 +@@ -10,7 +10,7 @@
22561 + #define TCAN4X5X_DEV_ID1 0x04
22562 + #define TCAN4X5X_REV 0x08
22563 + #define TCAN4X5X_STATUS 0x0C
22564 +-#define TCAN4X5X_ERROR_STATUS 0x10
22565 ++#define TCAN4X5X_ERROR_STATUS_MASK 0x10
22566 + #define TCAN4X5X_CONTROL 0x14
22567 +
22568 + #define TCAN4X5X_CONFIG 0x800
22569 +@@ -204,17 +204,7 @@ static int tcan4x5x_clear_interrupts(struct m_can_classdev *cdev)
22570 + if (ret)
22571 + return ret;
22572 +
22573 +- ret = tcan4x5x_write_tcan_reg(cdev, TCAN4X5X_MCAN_INT_REG,
22574 +- TCAN4X5X_ENABLE_MCAN_INT);
22575 +- if (ret)
22576 +- return ret;
22577 +-
22578 +- ret = tcan4x5x_write_tcan_reg(cdev, TCAN4X5X_INT_FLAGS,
22579 +- TCAN4X5X_CLEAR_ALL_INT);
22580 +- if (ret)
22581 +- return ret;
22582 +-
22583 +- return tcan4x5x_write_tcan_reg(cdev, TCAN4X5X_ERROR_STATUS,
22584 ++ return tcan4x5x_write_tcan_reg(cdev, TCAN4X5X_INT_FLAGS,
22585 + TCAN4X5X_CLEAR_ALL_INT);
22586 + }
22587 +
22588 +@@ -234,8 +224,8 @@ static int tcan4x5x_init(struct m_can_classdev *cdev)
22589 + if (ret)
22590 + return ret;
22591 +
22592 +- /* Zero out the MCAN buffers */
22593 +- ret = m_can_init_ram(cdev);
22594 ++ ret = tcan4x5x_write_tcan_reg(cdev, TCAN4X5X_ERROR_STATUS_MASK,
22595 ++ TCAN4X5X_CLEAR_ALL_INT);
22596 + if (ret)
22597 + return ret;
22598 +
22599 +diff --git a/drivers/net/can/usb/kvaser_usb/kvaser_usb.h b/drivers/net/can/usb/kvaser_usb/kvaser_usb.h
22600 +index f6c0938027ece..ff10b3790d844 100644
22601 +--- a/drivers/net/can/usb/kvaser_usb/kvaser_usb.h
22602 ++++ b/drivers/net/can/usb/kvaser_usb/kvaser_usb.h
22603 +@@ -76,6 +76,14 @@ struct kvaser_usb_tx_urb_context {
22604 + u32 echo_index;
22605 + };
22606 +
22607 ++struct kvaser_usb_busparams {
22608 ++ __le32 bitrate;
22609 ++ u8 tseg1;
22610 ++ u8 tseg2;
22611 ++ u8 sjw;
22612 ++ u8 nsamples;
22613 ++} __packed;
22614 ++
22615 + struct kvaser_usb {
22616 + struct usb_device *udev;
22617 + struct usb_interface *intf;
22618 +@@ -104,13 +112,19 @@ struct kvaser_usb_net_priv {
22619 + struct can_priv can;
22620 + struct can_berr_counter bec;
22621 +
22622 ++ /* subdriver-specific data */
22623 ++ void *sub_priv;
22624 ++
22625 + struct kvaser_usb *dev;
22626 + struct net_device *netdev;
22627 + int channel;
22628 +
22629 +- struct completion start_comp, stop_comp, flush_comp;
22630 ++ struct completion start_comp, stop_comp, flush_comp,
22631 ++ get_busparams_comp;
22632 + struct usb_anchor tx_submitted;
22633 +
22634 ++ struct kvaser_usb_busparams busparams_nominal, busparams_data;
22635 ++
22636 + spinlock_t tx_contexts_lock; /* lock for active_tx_contexts */
22637 + int active_tx_contexts;
22638 + struct kvaser_usb_tx_urb_context tx_contexts[];
22639 +@@ -120,11 +134,15 @@ struct kvaser_usb_net_priv {
22640 + * struct kvaser_usb_dev_ops - Device specific functions
22641 + * @dev_set_mode: used for can.do_set_mode
22642 + * @dev_set_bittiming: used for can.do_set_bittiming
22643 ++ * @dev_get_busparams: readback arbitration busparams
22644 + * @dev_set_data_bittiming: used for can.do_set_data_bittiming
22645 ++ * @dev_get_data_busparams: readback data busparams
22646 + * @dev_get_berr_counter: used for can.do_get_berr_counter
22647 + *
22648 + * @dev_setup_endpoints: setup USB in and out endpoints
22649 + * @dev_init_card: initialize card
22650 ++ * @dev_init_channel: initialize channel
22651 ++ * @dev_remove_channel: uninitialize channel
22652 + * @dev_get_software_info: get software info
22653 + * @dev_get_software_details: get software details
22654 + * @dev_get_card_info: get card info
22655 +@@ -140,12 +158,18 @@ struct kvaser_usb_net_priv {
22656 + */
22657 + struct kvaser_usb_dev_ops {
22658 + int (*dev_set_mode)(struct net_device *netdev, enum can_mode mode);
22659 +- int (*dev_set_bittiming)(struct net_device *netdev);
22660 +- int (*dev_set_data_bittiming)(struct net_device *netdev);
22661 ++ int (*dev_set_bittiming)(const struct net_device *netdev,
22662 ++ const struct kvaser_usb_busparams *busparams);
22663 ++ int (*dev_get_busparams)(struct kvaser_usb_net_priv *priv);
22664 ++ int (*dev_set_data_bittiming)(const struct net_device *netdev,
22665 ++ const struct kvaser_usb_busparams *busparams);
22666 ++ int (*dev_get_data_busparams)(struct kvaser_usb_net_priv *priv);
22667 + int (*dev_get_berr_counter)(const struct net_device *netdev,
22668 + struct can_berr_counter *bec);
22669 + int (*dev_setup_endpoints)(struct kvaser_usb *dev);
22670 + int (*dev_init_card)(struct kvaser_usb *dev);
22671 ++ int (*dev_init_channel)(struct kvaser_usb_net_priv *priv);
22672 ++ void (*dev_remove_channel)(struct kvaser_usb_net_priv *priv);
22673 + int (*dev_get_software_info)(struct kvaser_usb *dev);
22674 + int (*dev_get_software_details)(struct kvaser_usb *dev);
22675 + int (*dev_get_card_info)(struct kvaser_usb *dev);
22676 +diff --git a/drivers/net/can/usb/kvaser_usb/kvaser_usb_core.c b/drivers/net/can/usb/kvaser_usb/kvaser_usb_core.c
22677 +index 802e27c0ecedb..3a2bfaad14065 100644
22678 +--- a/drivers/net/can/usb/kvaser_usb/kvaser_usb_core.c
22679 ++++ b/drivers/net/can/usb/kvaser_usb/kvaser_usb_core.c
22680 +@@ -440,10 +440,6 @@ static int kvaser_usb_open(struct net_device *netdev)
22681 + if (err)
22682 + return err;
22683 +
22684 +- err = kvaser_usb_setup_rx_urbs(dev);
22685 +- if (err)
22686 +- goto error;
22687 +-
22688 + err = ops->dev_set_opt_mode(priv);
22689 + if (err)
22690 + goto error;
22691 +@@ -534,6 +530,93 @@ static int kvaser_usb_close(struct net_device *netdev)
22692 + return 0;
22693 + }
22694 +
22695 ++static int kvaser_usb_set_bittiming(struct net_device *netdev)
22696 ++{
22697 ++ struct kvaser_usb_net_priv *priv = netdev_priv(netdev);
22698 ++ struct kvaser_usb *dev = priv->dev;
22699 ++ const struct kvaser_usb_dev_ops *ops = dev->driver_info->ops;
22700 ++ struct can_bittiming *bt = &priv->can.bittiming;
22701 ++
22702 ++ struct kvaser_usb_busparams busparams;
22703 ++ int tseg1 = bt->prop_seg + bt->phase_seg1;
22704 ++ int tseg2 = bt->phase_seg2;
22705 ++ int sjw = bt->sjw;
22706 ++ int err = -EOPNOTSUPP;
22707 ++
22708 ++ busparams.bitrate = cpu_to_le32(bt->bitrate);
22709 ++ busparams.sjw = (u8)sjw;
22710 ++ busparams.tseg1 = (u8)tseg1;
22711 ++ busparams.tseg2 = (u8)tseg2;
22712 ++ if (priv->can.ctrlmode & CAN_CTRLMODE_3_SAMPLES)
22713 ++ busparams.nsamples = 3;
22714 ++ else
22715 ++ busparams.nsamples = 1;
22716 ++
22717 ++ err = ops->dev_set_bittiming(netdev, &busparams);
22718 ++ if (err)
22719 ++ return err;
22720 ++
22721 ++ err = kvaser_usb_setup_rx_urbs(priv->dev);
22722 ++ if (err)
22723 ++ return err;
22724 ++
22725 ++ err = ops->dev_get_busparams(priv);
22726 ++ if (err) {
22727 ++ /* Treat EOPNOTSUPP as success */
22728 ++ if (err == -EOPNOTSUPP)
22729 ++ err = 0;
22730 ++ return err;
22731 ++ }
22732 ++
22733 ++ if (memcmp(&busparams, &priv->busparams_nominal,
22734 ++ sizeof(priv->busparams_nominal)) != 0)
22735 ++ err = -EINVAL;
22736 ++
22737 ++ return err;
22738 ++}
22739 ++
22740 ++static int kvaser_usb_set_data_bittiming(struct net_device *netdev)
22741 ++{
22742 ++ struct kvaser_usb_net_priv *priv = netdev_priv(netdev);
22743 ++ struct kvaser_usb *dev = priv->dev;
22744 ++ const struct kvaser_usb_dev_ops *ops = dev->driver_info->ops;
22745 ++ struct can_bittiming *dbt = &priv->can.data_bittiming;
22746 ++
22747 ++ struct kvaser_usb_busparams busparams;
22748 ++ int tseg1 = dbt->prop_seg + dbt->phase_seg1;
22749 ++ int tseg2 = dbt->phase_seg2;
22750 ++ int sjw = dbt->sjw;
22751 ++ int err;
22752 ++
22753 ++ if (!ops->dev_set_data_bittiming ||
22754 ++ !ops->dev_get_data_busparams)
22755 ++ return -EOPNOTSUPP;
22756 ++
22757 ++ busparams.bitrate = cpu_to_le32(dbt->bitrate);
22758 ++ busparams.sjw = (u8)sjw;
22759 ++ busparams.tseg1 = (u8)tseg1;
22760 ++ busparams.tseg2 = (u8)tseg2;
22761 ++ busparams.nsamples = 1;
22762 ++
22763 ++ err = ops->dev_set_data_bittiming(netdev, &busparams);
22764 ++ if (err)
22765 ++ return err;
22766 ++
22767 ++ err = kvaser_usb_setup_rx_urbs(priv->dev);
22768 ++ if (err)
22769 ++ return err;
22770 ++
22771 ++ err = ops->dev_get_data_busparams(priv);
22772 ++ if (err)
22773 ++ return err;
22774 ++
22775 ++ if (memcmp(&busparams, &priv->busparams_data,
22776 ++ sizeof(priv->busparams_data)) != 0)
22777 ++ err = -EINVAL;
22778 ++
22779 ++ return err;
22780 ++}
22781 ++
22782 + static void kvaser_usb_write_bulk_callback(struct urb *urb)
22783 + {
22784 + struct kvaser_usb_tx_urb_context *context = urb->context;
22785 +@@ -684,6 +767,7 @@ static const struct ethtool_ops kvaser_usb_ethtool_ops_hwts = {
22786 +
22787 + static void kvaser_usb_remove_interfaces(struct kvaser_usb *dev)
22788 + {
22789 ++ const struct kvaser_usb_dev_ops *ops = dev->driver_info->ops;
22790 + int i;
22791 +
22792 + for (i = 0; i < dev->nchannels; i++) {
22793 +@@ -699,6 +783,9 @@ static void kvaser_usb_remove_interfaces(struct kvaser_usb *dev)
22794 + if (!dev->nets[i])
22795 + continue;
22796 +
22797 ++ if (ops->dev_remove_channel)
22798 ++ ops->dev_remove_channel(dev->nets[i]);
22799 ++
22800 + free_candev(dev->nets[i]->netdev);
22801 + }
22802 + }
22803 +@@ -730,6 +817,7 @@ static int kvaser_usb_init_one(struct kvaser_usb *dev, int channel)
22804 + init_completion(&priv->start_comp);
22805 + init_completion(&priv->stop_comp);
22806 + init_completion(&priv->flush_comp);
22807 ++ init_completion(&priv->get_busparams_comp);
22808 + priv->can.ctrlmode_supported = 0;
22809 +
22810 + priv->dev = dev;
22811 +@@ -742,7 +830,7 @@ static int kvaser_usb_init_one(struct kvaser_usb *dev, int channel)
22812 + priv->can.state = CAN_STATE_STOPPED;
22813 + priv->can.clock.freq = dev->cfg->clock.freq;
22814 + priv->can.bittiming_const = dev->cfg->bittiming_const;
22815 +- priv->can.do_set_bittiming = ops->dev_set_bittiming;
22816 ++ priv->can.do_set_bittiming = kvaser_usb_set_bittiming;
22817 + priv->can.do_set_mode = ops->dev_set_mode;
22818 + if ((driver_info->quirks & KVASER_USB_QUIRK_HAS_TXRX_ERRORS) ||
22819 + (priv->dev->card_data.capabilities & KVASER_USB_CAP_BERR_CAP))
22820 +@@ -754,7 +842,7 @@ static int kvaser_usb_init_one(struct kvaser_usb *dev, int channel)
22821 +
22822 + if (priv->can.ctrlmode_supported & CAN_CTRLMODE_FD) {
22823 + priv->can.data_bittiming_const = dev->cfg->data_bittiming_const;
22824 +- priv->can.do_set_data_bittiming = ops->dev_set_data_bittiming;
22825 ++ priv->can.do_set_data_bittiming = kvaser_usb_set_data_bittiming;
22826 + }
22827 +
22828 + netdev->flags |= IFF_ECHO;
22829 +@@ -772,17 +860,26 @@ static int kvaser_usb_init_one(struct kvaser_usb *dev, int channel)
22830 +
22831 + dev->nets[channel] = priv;
22832 +
22833 ++ if (ops->dev_init_channel) {
22834 ++ err = ops->dev_init_channel(priv);
22835 ++ if (err)
22836 ++ goto err;
22837 ++ }
22838 ++
22839 + err = register_candev(netdev);
22840 + if (err) {
22841 + dev_err(&dev->intf->dev, "Failed to register CAN device\n");
22842 +- free_candev(netdev);
22843 +- dev->nets[channel] = NULL;
22844 +- return err;
22845 ++ goto err;
22846 + }
22847 +
22848 + netdev_dbg(netdev, "device registered\n");
22849 +
22850 + return 0;
22851 ++
22852 ++err:
22853 ++ free_candev(netdev);
22854 ++ dev->nets[channel] = NULL;
22855 ++ return err;
22856 + }
22857 +
22858 + static int kvaser_usb_probe(struct usb_interface *intf,
22859 +diff --git a/drivers/net/can/usb/kvaser_usb/kvaser_usb_hydra.c b/drivers/net/can/usb/kvaser_usb/kvaser_usb_hydra.c
22860 +index 3abfaa77e8935..52ef76bd9bdb8 100644
22861 +--- a/drivers/net/can/usb/kvaser_usb/kvaser_usb_hydra.c
22862 ++++ b/drivers/net/can/usb/kvaser_usb/kvaser_usb_hydra.c
22863 +@@ -45,6 +45,8 @@ static const struct kvaser_usb_dev_cfg kvaser_usb_hydra_dev_cfg_rt;
22864 +
22865 + /* Minihydra command IDs */
22866 + #define CMD_SET_BUSPARAMS_REQ 16
22867 ++#define CMD_GET_BUSPARAMS_REQ 17
22868 ++#define CMD_GET_BUSPARAMS_RESP 18
22869 + #define CMD_GET_CHIP_STATE_REQ 19
22870 + #define CMD_CHIP_STATE_EVENT 20
22871 + #define CMD_SET_DRIVERMODE_REQ 21
22872 +@@ -196,21 +198,26 @@ struct kvaser_cmd_chip_state_event {
22873 + #define KVASER_USB_HYDRA_BUS_MODE_CANFD_ISO 0x01
22874 + #define KVASER_USB_HYDRA_BUS_MODE_NONISO 0x02
22875 + struct kvaser_cmd_set_busparams {
22876 +- __le32 bitrate;
22877 +- u8 tseg1;
22878 +- u8 tseg2;
22879 +- u8 sjw;
22880 +- u8 nsamples;
22881 ++ struct kvaser_usb_busparams busparams_nominal;
22882 + u8 reserved0[4];
22883 +- __le32 bitrate_d;
22884 +- u8 tseg1_d;
22885 +- u8 tseg2_d;
22886 +- u8 sjw_d;
22887 +- u8 nsamples_d;
22888 ++ struct kvaser_usb_busparams busparams_data;
22889 + u8 canfd_mode;
22890 + u8 reserved1[7];
22891 + } __packed;
22892 +
22893 ++/* Busparam type */
22894 ++#define KVASER_USB_HYDRA_BUSPARAM_TYPE_CAN 0x00
22895 ++#define KVASER_USB_HYDRA_BUSPARAM_TYPE_CANFD 0x01
22896 ++struct kvaser_cmd_get_busparams_req {
22897 ++ u8 type;
22898 ++ u8 reserved[27];
22899 ++} __packed;
22900 ++
22901 ++struct kvaser_cmd_get_busparams_res {
22902 ++ struct kvaser_usb_busparams busparams;
22903 ++ u8 reserved[20];
22904 ++} __packed;
22905 ++
22906 + /* Ctrl modes */
22907 + #define KVASER_USB_HYDRA_CTRLMODE_NORMAL 0x01
22908 + #define KVASER_USB_HYDRA_CTRLMODE_LISTEN 0x02
22909 +@@ -281,6 +288,8 @@ struct kvaser_cmd {
22910 + struct kvaser_cmd_error_event error_event;
22911 +
22912 + struct kvaser_cmd_set_busparams set_busparams_req;
22913 ++ struct kvaser_cmd_get_busparams_req get_busparams_req;
22914 ++ struct kvaser_cmd_get_busparams_res get_busparams_res;
22915 +
22916 + struct kvaser_cmd_chip_state_event chip_state_event;
22917 +
22918 +@@ -363,6 +372,10 @@ struct kvaser_cmd_ext {
22919 + } __packed;
22920 + } __packed;
22921 +
22922 ++struct kvaser_usb_net_hydra_priv {
22923 ++ int pending_get_busparams_type;
22924 ++};
22925 ++
22926 + static const struct can_bittiming_const kvaser_usb_hydra_kcan_bittiming_c = {
22927 + .name = "kvaser_usb_kcan",
22928 + .tseg1_min = 1,
22929 +@@ -840,6 +853,39 @@ static void kvaser_usb_hydra_flush_queue_reply(const struct kvaser_usb *dev,
22930 + complete(&priv->flush_comp);
22931 + }
22932 +
22933 ++static void kvaser_usb_hydra_get_busparams_reply(const struct kvaser_usb *dev,
22934 ++ const struct kvaser_cmd *cmd)
22935 ++{
22936 ++ struct kvaser_usb_net_priv *priv;
22937 ++ struct kvaser_usb_net_hydra_priv *hydra;
22938 ++
22939 ++ priv = kvaser_usb_hydra_net_priv_from_cmd(dev, cmd);
22940 ++ if (!priv)
22941 ++ return;
22942 ++
22943 ++ hydra = priv->sub_priv;
22944 ++ if (!hydra)
22945 ++ return;
22946 ++
22947 ++ switch (hydra->pending_get_busparams_type) {
22948 ++ case KVASER_USB_HYDRA_BUSPARAM_TYPE_CAN:
22949 ++ memcpy(&priv->busparams_nominal, &cmd->get_busparams_res.busparams,
22950 ++ sizeof(priv->busparams_nominal));
22951 ++ break;
22952 ++ case KVASER_USB_HYDRA_BUSPARAM_TYPE_CANFD:
22953 ++ memcpy(&priv->busparams_data, &cmd->get_busparams_res.busparams,
22954 ++ sizeof(priv->busparams_nominal));
22955 ++ break;
22956 ++ default:
22957 ++ dev_warn(&dev->intf->dev, "Unknown get_busparams_type %d\n",
22958 ++ hydra->pending_get_busparams_type);
22959 ++ break;
22960 ++ }
22961 ++ hydra->pending_get_busparams_type = -1;
22962 ++
22963 ++ complete(&priv->get_busparams_comp);
22964 ++}
22965 ++
22966 + static void
22967 + kvaser_usb_hydra_bus_status_to_can_state(const struct kvaser_usb_net_priv *priv,
22968 + u8 bus_status,
22969 +@@ -1326,6 +1372,10 @@ static void kvaser_usb_hydra_handle_cmd_std(const struct kvaser_usb *dev,
22970 + kvaser_usb_hydra_state_event(dev, cmd);
22971 + break;
22972 +
22973 ++ case CMD_GET_BUSPARAMS_RESP:
22974 ++ kvaser_usb_hydra_get_busparams_reply(dev, cmd);
22975 ++ break;
22976 ++
22977 + case CMD_ERROR_EVENT:
22978 + kvaser_usb_hydra_error_event(dev, cmd);
22979 + break;
22980 +@@ -1522,15 +1572,58 @@ static int kvaser_usb_hydra_set_mode(struct net_device *netdev,
22981 + return err;
22982 + }
22983 +
22984 +-static int kvaser_usb_hydra_set_bittiming(struct net_device *netdev)
22985 ++static int kvaser_usb_hydra_get_busparams(struct kvaser_usb_net_priv *priv,
22986 ++ int busparams_type)
22987 ++{
22988 ++ struct kvaser_usb *dev = priv->dev;
22989 ++ struct kvaser_usb_net_hydra_priv *hydra = priv->sub_priv;
22990 ++ struct kvaser_cmd *cmd;
22991 ++ int err;
22992 ++
22993 ++ if (!hydra)
22994 ++ return -EINVAL;
22995 ++
22996 ++ cmd = kcalloc(1, sizeof(struct kvaser_cmd), GFP_KERNEL);
22997 ++ if (!cmd)
22998 ++ return -ENOMEM;
22999 ++
23000 ++ cmd->header.cmd_no = CMD_GET_BUSPARAMS_REQ;
23001 ++ kvaser_usb_hydra_set_cmd_dest_he
23002 ++ (cmd, dev->card_data.hydra.channel_to_he[priv->channel]);
23003 ++ kvaser_usb_hydra_set_cmd_transid
23004 ++ (cmd, kvaser_usb_hydra_get_next_transid(dev));
23005 ++ cmd->get_busparams_req.type = busparams_type;
23006 ++ hydra->pending_get_busparams_type = busparams_type;
23007 ++
23008 ++ reinit_completion(&priv->get_busparams_comp);
23009 ++
23010 ++ err = kvaser_usb_send_cmd(dev, cmd, kvaser_usb_hydra_cmd_size(cmd));
23011 ++ if (err)
23012 ++ return err;
23013 ++
23014 ++ if (!wait_for_completion_timeout(&priv->get_busparams_comp,
23015 ++ msecs_to_jiffies(KVASER_USB_TIMEOUT)))
23016 ++ return -ETIMEDOUT;
23017 ++
23018 ++ return err;
23019 ++}
23020 ++
23021 ++static int kvaser_usb_hydra_get_nominal_busparams(struct kvaser_usb_net_priv *priv)
23022 ++{
23023 ++ return kvaser_usb_hydra_get_busparams(priv, KVASER_USB_HYDRA_BUSPARAM_TYPE_CAN);
23024 ++}
23025 ++
23026 ++static int kvaser_usb_hydra_get_data_busparams(struct kvaser_usb_net_priv *priv)
23027 ++{
23028 ++ return kvaser_usb_hydra_get_busparams(priv, KVASER_USB_HYDRA_BUSPARAM_TYPE_CANFD);
23029 ++}
23030 ++
23031 ++static int kvaser_usb_hydra_set_bittiming(const struct net_device *netdev,
23032 ++ const struct kvaser_usb_busparams *busparams)
23033 + {
23034 + struct kvaser_cmd *cmd;
23035 + struct kvaser_usb_net_priv *priv = netdev_priv(netdev);
23036 +- struct can_bittiming *bt = &priv->can.bittiming;
23037 + struct kvaser_usb *dev = priv->dev;
23038 +- int tseg1 = bt->prop_seg + bt->phase_seg1;
23039 +- int tseg2 = bt->phase_seg2;
23040 +- int sjw = bt->sjw;
23041 + int err;
23042 +
23043 + cmd = kcalloc(1, sizeof(struct kvaser_cmd), GFP_KERNEL);
23044 +@@ -1538,11 +1631,8 @@ static int kvaser_usb_hydra_set_bittiming(struct net_device *netdev)
23045 + return -ENOMEM;
23046 +
23047 + cmd->header.cmd_no = CMD_SET_BUSPARAMS_REQ;
23048 +- cmd->set_busparams_req.bitrate = cpu_to_le32(bt->bitrate);
23049 +- cmd->set_busparams_req.sjw = (u8)sjw;
23050 +- cmd->set_busparams_req.tseg1 = (u8)tseg1;
23051 +- cmd->set_busparams_req.tseg2 = (u8)tseg2;
23052 +- cmd->set_busparams_req.nsamples = 1;
23053 ++ memcpy(&cmd->set_busparams_req.busparams_nominal, busparams,
23054 ++ sizeof(cmd->set_busparams_req.busparams_nominal));
23055 +
23056 + kvaser_usb_hydra_set_cmd_dest_he
23057 + (cmd, dev->card_data.hydra.channel_to_he[priv->channel]);
23058 +@@ -1556,15 +1646,12 @@ static int kvaser_usb_hydra_set_bittiming(struct net_device *netdev)
23059 + return err;
23060 + }
23061 +
23062 +-static int kvaser_usb_hydra_set_data_bittiming(struct net_device *netdev)
23063 ++static int kvaser_usb_hydra_set_data_bittiming(const struct net_device *netdev,
23064 ++ const struct kvaser_usb_busparams *busparams)
23065 + {
23066 + struct kvaser_cmd *cmd;
23067 + struct kvaser_usb_net_priv *priv = netdev_priv(netdev);
23068 +- struct can_bittiming *dbt = &priv->can.data_bittiming;
23069 + struct kvaser_usb *dev = priv->dev;
23070 +- int tseg1 = dbt->prop_seg + dbt->phase_seg1;
23071 +- int tseg2 = dbt->phase_seg2;
23072 +- int sjw = dbt->sjw;
23073 + int err;
23074 +
23075 + cmd = kcalloc(1, sizeof(struct kvaser_cmd), GFP_KERNEL);
23076 +@@ -1572,11 +1659,8 @@ static int kvaser_usb_hydra_set_data_bittiming(struct net_device *netdev)
23077 + return -ENOMEM;
23078 +
23079 + cmd->header.cmd_no = CMD_SET_BUSPARAMS_FD_REQ;
23080 +- cmd->set_busparams_req.bitrate_d = cpu_to_le32(dbt->bitrate);
23081 +- cmd->set_busparams_req.sjw_d = (u8)sjw;
23082 +- cmd->set_busparams_req.tseg1_d = (u8)tseg1;
23083 +- cmd->set_busparams_req.tseg2_d = (u8)tseg2;
23084 +- cmd->set_busparams_req.nsamples_d = 1;
23085 ++ memcpy(&cmd->set_busparams_req.busparams_data, busparams,
23086 ++ sizeof(cmd->set_busparams_req.busparams_data));
23087 +
23088 + if (priv->can.ctrlmode & CAN_CTRLMODE_FD) {
23089 + if (priv->can.ctrlmode & CAN_CTRLMODE_FD_NON_ISO)
23090 +@@ -1683,6 +1767,19 @@ static int kvaser_usb_hydra_init_card(struct kvaser_usb *dev)
23091 + return 0;
23092 + }
23093 +
23094 ++static int kvaser_usb_hydra_init_channel(struct kvaser_usb_net_priv *priv)
23095 ++{
23096 ++ struct kvaser_usb_net_hydra_priv *hydra;
23097 ++
23098 ++ hydra = devm_kzalloc(&priv->dev->intf->dev, sizeof(*hydra), GFP_KERNEL);
23099 ++ if (!hydra)
23100 ++ return -ENOMEM;
23101 ++
23102 ++ priv->sub_priv = hydra;
23103 ++
23104 ++ return 0;
23105 ++}
23106 ++
23107 + static int kvaser_usb_hydra_get_software_info(struct kvaser_usb *dev)
23108 + {
23109 + struct kvaser_cmd cmd;
23110 +@@ -2027,10 +2124,13 @@ kvaser_usb_hydra_frame_to_cmd(const struct kvaser_usb_net_priv *priv,
23111 + const struct kvaser_usb_dev_ops kvaser_usb_hydra_dev_ops = {
23112 + .dev_set_mode = kvaser_usb_hydra_set_mode,
23113 + .dev_set_bittiming = kvaser_usb_hydra_set_bittiming,
23114 ++ .dev_get_busparams = kvaser_usb_hydra_get_nominal_busparams,
23115 + .dev_set_data_bittiming = kvaser_usb_hydra_set_data_bittiming,
23116 ++ .dev_get_data_busparams = kvaser_usb_hydra_get_data_busparams,
23117 + .dev_get_berr_counter = kvaser_usb_hydra_get_berr_counter,
23118 + .dev_setup_endpoints = kvaser_usb_hydra_setup_endpoints,
23119 + .dev_init_card = kvaser_usb_hydra_init_card,
23120 ++ .dev_init_channel = kvaser_usb_hydra_init_channel,
23121 + .dev_get_software_info = kvaser_usb_hydra_get_software_info,
23122 + .dev_get_software_details = kvaser_usb_hydra_get_software_details,
23123 + .dev_get_card_info = kvaser_usb_hydra_get_card_info,
23124 +diff --git a/drivers/net/can/usb/kvaser_usb/kvaser_usb_leaf.c b/drivers/net/can/usb/kvaser_usb/kvaser_usb_leaf.c
23125 +index 19958037720f4..b423fd4c79890 100644
23126 +--- a/drivers/net/can/usb/kvaser_usb/kvaser_usb_leaf.c
23127 ++++ b/drivers/net/can/usb/kvaser_usb/kvaser_usb_leaf.c
23128 +@@ -21,6 +21,7 @@
23129 + #include <linux/types.h>
23130 + #include <linux/units.h>
23131 + #include <linux/usb.h>
23132 ++#include <linux/workqueue.h>
23133 +
23134 + #include <linux/can.h>
23135 + #include <linux/can/dev.h>
23136 +@@ -56,6 +57,9 @@
23137 + #define CMD_RX_EXT_MESSAGE 14
23138 + #define CMD_TX_EXT_MESSAGE 15
23139 + #define CMD_SET_BUS_PARAMS 16
23140 ++#define CMD_GET_BUS_PARAMS 17
23141 ++#define CMD_GET_BUS_PARAMS_REPLY 18
23142 ++#define CMD_GET_CHIP_STATE 19
23143 + #define CMD_CHIP_STATE_EVENT 20
23144 + #define CMD_SET_CTRL_MODE 21
23145 + #define CMD_RESET_CHIP 24
23146 +@@ -70,10 +74,13 @@
23147 + #define CMD_GET_CARD_INFO_REPLY 35
23148 + #define CMD_GET_SOFTWARE_INFO 38
23149 + #define CMD_GET_SOFTWARE_INFO_REPLY 39
23150 ++#define CMD_ERROR_EVENT 45
23151 + #define CMD_FLUSH_QUEUE 48
23152 + #define CMD_TX_ACKNOWLEDGE 50
23153 + #define CMD_CAN_ERROR_EVENT 51
23154 + #define CMD_FLUSH_QUEUE_REPLY 68
23155 ++#define CMD_GET_CAPABILITIES_REQ 95
23156 ++#define CMD_GET_CAPABILITIES_RESP 96
23157 +
23158 + #define CMD_LEAF_LOG_MESSAGE 106
23159 +
23160 +@@ -83,6 +90,8 @@
23161 + #define KVASER_USB_LEAF_SWOPTION_FREQ_32_MHZ_CLK BIT(5)
23162 + #define KVASER_USB_LEAF_SWOPTION_FREQ_24_MHZ_CLK BIT(6)
23163 +
23164 ++#define KVASER_USB_LEAF_SWOPTION_EXT_CAP BIT(12)
23165 ++
23166 + /* error factors */
23167 + #define M16C_EF_ACKE BIT(0)
23168 + #define M16C_EF_CRCE BIT(1)
23169 +@@ -157,11 +166,7 @@ struct usbcan_cmd_softinfo {
23170 + struct kvaser_cmd_busparams {
23171 + u8 tid;
23172 + u8 channel;
23173 +- __le32 bitrate;
23174 +- u8 tseg1;
23175 +- u8 tseg2;
23176 +- u8 sjw;
23177 +- u8 no_samp;
23178 ++ struct kvaser_usb_busparams busparams;
23179 + } __packed;
23180 +
23181 + struct kvaser_cmd_tx_can {
23182 +@@ -230,7 +235,7 @@ struct kvaser_cmd_tx_acknowledge_header {
23183 + u8 tid;
23184 + } __packed;
23185 +
23186 +-struct leaf_cmd_error_event {
23187 ++struct leaf_cmd_can_error_event {
23188 + u8 tid;
23189 + u8 flags;
23190 + __le16 time[3];
23191 +@@ -242,7 +247,7 @@ struct leaf_cmd_error_event {
23192 + u8 error_factor;
23193 + } __packed;
23194 +
23195 +-struct usbcan_cmd_error_event {
23196 ++struct usbcan_cmd_can_error_event {
23197 + u8 tid;
23198 + u8 padding;
23199 + u8 tx_errors_count_ch0;
23200 +@@ -254,6 +259,28 @@ struct usbcan_cmd_error_event {
23201 + __le16 time;
23202 + } __packed;
23203 +
23204 ++/* CMD_ERROR_EVENT error codes */
23205 ++#define KVASER_USB_LEAF_ERROR_EVENT_TX_QUEUE_FULL 0x8
23206 ++#define KVASER_USB_LEAF_ERROR_EVENT_PARAM 0x9
23207 ++
23208 ++struct leaf_cmd_error_event {
23209 ++ u8 tid;
23210 ++ u8 error_code;
23211 ++ __le16 timestamp[3];
23212 ++ __le16 padding;
23213 ++ __le16 info1;
23214 ++ __le16 info2;
23215 ++} __packed;
23216 ++
23217 ++struct usbcan_cmd_error_event {
23218 ++ u8 tid;
23219 ++ u8 error_code;
23220 ++ __le16 info1;
23221 ++ __le16 info2;
23222 ++ __le16 timestamp;
23223 ++ __le16 padding;
23224 ++} __packed;
23225 ++
23226 + struct kvaser_cmd_ctrl_mode {
23227 + u8 tid;
23228 + u8 channel;
23229 +@@ -278,6 +305,28 @@ struct leaf_cmd_log_message {
23230 + u8 data[8];
23231 + } __packed;
23232 +
23233 ++/* Sub commands for cap_req and cap_res */
23234 ++#define KVASER_USB_LEAF_CAP_CMD_LISTEN_MODE 0x02
23235 ++#define KVASER_USB_LEAF_CAP_CMD_ERR_REPORT 0x05
23236 ++struct kvaser_cmd_cap_req {
23237 ++ __le16 padding0;
23238 ++ __le16 cap_cmd;
23239 ++ __le16 padding1;
23240 ++ __le16 channel;
23241 ++} __packed;
23242 ++
23243 ++/* Status codes for cap_res */
23244 ++#define KVASER_USB_LEAF_CAP_STAT_OK 0x00
23245 ++#define KVASER_USB_LEAF_CAP_STAT_NOT_IMPL 0x01
23246 ++#define KVASER_USB_LEAF_CAP_STAT_UNAVAIL 0x02
23247 ++struct kvaser_cmd_cap_res {
23248 ++ __le16 padding;
23249 ++ __le16 cap_cmd;
23250 ++ __le16 status;
23251 ++ __le32 mask;
23252 ++ __le32 value;
23253 ++} __packed;
23254 ++
23255 + struct kvaser_cmd {
23256 + u8 len;
23257 + u8 id;
23258 +@@ -293,14 +342,18 @@ struct kvaser_cmd {
23259 + struct leaf_cmd_softinfo softinfo;
23260 + struct leaf_cmd_rx_can rx_can;
23261 + struct leaf_cmd_chip_state_event chip_state_event;
23262 +- struct leaf_cmd_error_event error_event;
23263 ++ struct leaf_cmd_can_error_event can_error_event;
23264 + struct leaf_cmd_log_message log_message;
23265 ++ struct leaf_cmd_error_event error_event;
23266 ++ struct kvaser_cmd_cap_req cap_req;
23267 ++ struct kvaser_cmd_cap_res cap_res;
23268 + } __packed leaf;
23269 +
23270 + union {
23271 + struct usbcan_cmd_softinfo softinfo;
23272 + struct usbcan_cmd_rx_can rx_can;
23273 + struct usbcan_cmd_chip_state_event chip_state_event;
23274 ++ struct usbcan_cmd_can_error_event can_error_event;
23275 + struct usbcan_cmd_error_event error_event;
23276 + } __packed usbcan;
23277 +
23278 +@@ -323,7 +376,10 @@ static const u8 kvaser_usb_leaf_cmd_sizes_leaf[] = {
23279 + [CMD_RX_EXT_MESSAGE] = kvaser_fsize(u.leaf.rx_can),
23280 + [CMD_LEAF_LOG_MESSAGE] = kvaser_fsize(u.leaf.log_message),
23281 + [CMD_CHIP_STATE_EVENT] = kvaser_fsize(u.leaf.chip_state_event),
23282 +- [CMD_CAN_ERROR_EVENT] = kvaser_fsize(u.leaf.error_event),
23283 ++ [CMD_CAN_ERROR_EVENT] = kvaser_fsize(u.leaf.can_error_event),
23284 ++ [CMD_GET_CAPABILITIES_RESP] = kvaser_fsize(u.leaf.cap_res),
23285 ++ [CMD_GET_BUS_PARAMS_REPLY] = kvaser_fsize(u.busparams),
23286 ++ [CMD_ERROR_EVENT] = kvaser_fsize(u.leaf.error_event),
23287 + /* ignored events: */
23288 + [CMD_FLUSH_QUEUE_REPLY] = CMD_SIZE_ANY,
23289 + };
23290 +@@ -337,7 +393,8 @@ static const u8 kvaser_usb_leaf_cmd_sizes_usbcan[] = {
23291 + [CMD_RX_STD_MESSAGE] = kvaser_fsize(u.usbcan.rx_can),
23292 + [CMD_RX_EXT_MESSAGE] = kvaser_fsize(u.usbcan.rx_can),
23293 + [CMD_CHIP_STATE_EVENT] = kvaser_fsize(u.usbcan.chip_state_event),
23294 +- [CMD_CAN_ERROR_EVENT] = kvaser_fsize(u.usbcan.error_event),
23295 ++ [CMD_CAN_ERROR_EVENT] = kvaser_fsize(u.usbcan.can_error_event),
23296 ++ [CMD_ERROR_EVENT] = kvaser_fsize(u.usbcan.error_event),
23297 + /* ignored events: */
23298 + [CMD_USBCAN_CLOCK_OVERFLOW_EVENT] = CMD_SIZE_ANY,
23299 + };
23300 +@@ -365,6 +422,12 @@ struct kvaser_usb_err_summary {
23301 + };
23302 + };
23303 +
23304 ++struct kvaser_usb_net_leaf_priv {
23305 ++ struct kvaser_usb_net_priv *net;
23306 ++
23307 ++ struct delayed_work chip_state_req_work;
23308 ++};
23309 ++
23310 + static const struct can_bittiming_const kvaser_usb_leaf_m16c_bittiming_const = {
23311 + .name = "kvaser_usb_ucii",
23312 + .tseg1_min = 4,
23313 +@@ -606,6 +669,9 @@ static void kvaser_usb_leaf_get_software_info_leaf(struct kvaser_usb *dev,
23314 + dev->fw_version = le32_to_cpu(softinfo->fw_version);
23315 + dev->max_tx_urbs = le16_to_cpu(softinfo->max_outstanding_tx);
23316 +
23317 ++ if (sw_options & KVASER_USB_LEAF_SWOPTION_EXT_CAP)
23318 ++ dev->card_data.capabilities |= KVASER_USB_CAP_EXT_CAP;
23319 ++
23320 + if (dev->driver_info->quirks & KVASER_USB_QUIRK_IGNORE_CLK_FREQ) {
23321 + /* Firmware expects bittiming parameters calculated for 16MHz
23322 + * clock, regardless of the actual clock
23323 +@@ -693,6 +759,116 @@ static int kvaser_usb_leaf_get_card_info(struct kvaser_usb *dev)
23324 + return 0;
23325 + }
23326 +
23327 ++static int kvaser_usb_leaf_get_single_capability(struct kvaser_usb *dev,
23328 ++ u16 cap_cmd_req, u16 *status)
23329 ++{
23330 ++ struct kvaser_usb_dev_card_data *card_data = &dev->card_data;
23331 ++ struct kvaser_cmd *cmd;
23332 ++ u32 value = 0;
23333 ++ u32 mask = 0;
23334 ++ u16 cap_cmd_res;
23335 ++ int err;
23336 ++ int i;
23337 ++
23338 ++ cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
23339 ++ if (!cmd)
23340 ++ return -ENOMEM;
23341 ++
23342 ++ cmd->id = CMD_GET_CAPABILITIES_REQ;
23343 ++ cmd->u.leaf.cap_req.cap_cmd = cpu_to_le16(cap_cmd_req);
23344 ++ cmd->len = CMD_HEADER_LEN + sizeof(struct kvaser_cmd_cap_req);
23345 ++
23346 ++ err = kvaser_usb_send_cmd(dev, cmd, cmd->len);
23347 ++ if (err)
23348 ++ goto end;
23349 ++
23350 ++ err = kvaser_usb_leaf_wait_cmd(dev, CMD_GET_CAPABILITIES_RESP, cmd);
23351 ++ if (err)
23352 ++ goto end;
23353 ++
23354 ++ *status = le16_to_cpu(cmd->u.leaf.cap_res.status);
23355 ++
23356 ++ if (*status != KVASER_USB_LEAF_CAP_STAT_OK)
23357 ++ goto end;
23358 ++
23359 ++ cap_cmd_res = le16_to_cpu(cmd->u.leaf.cap_res.cap_cmd);
23360 ++ switch (cap_cmd_res) {
23361 ++ case KVASER_USB_LEAF_CAP_CMD_LISTEN_MODE:
23362 ++ case KVASER_USB_LEAF_CAP_CMD_ERR_REPORT:
23363 ++ value = le32_to_cpu(cmd->u.leaf.cap_res.value);
23364 ++ mask = le32_to_cpu(cmd->u.leaf.cap_res.mask);
23365 ++ break;
23366 ++ default:
23367 ++ dev_warn(&dev->intf->dev, "Unknown capability command %u\n",
23368 ++ cap_cmd_res);
23369 ++ break;
23370 ++ }
23371 ++
23372 ++ for (i = 0; i < dev->nchannels; i++) {
23373 ++ if (BIT(i) & (value & mask)) {
23374 ++ switch (cap_cmd_res) {
23375 ++ case KVASER_USB_LEAF_CAP_CMD_LISTEN_MODE:
23376 ++ card_data->ctrlmode_supported |=
23377 ++ CAN_CTRLMODE_LISTENONLY;
23378 ++ break;
23379 ++ case KVASER_USB_LEAF_CAP_CMD_ERR_REPORT:
23380 ++ card_data->capabilities |=
23381 ++ KVASER_USB_CAP_BERR_CAP;
23382 ++ break;
23383 ++ }
23384 ++ }
23385 ++ }
23386 ++
23387 ++end:
23388 ++ kfree(cmd);
23389 ++
23390 ++ return err;
23391 ++}
23392 ++
23393 ++static int kvaser_usb_leaf_get_capabilities_leaf(struct kvaser_usb *dev)
23394 ++{
23395 ++ int err;
23396 ++ u16 status;
23397 ++
23398 ++ if (!(dev->card_data.capabilities & KVASER_USB_CAP_EXT_CAP)) {
23399 ++ dev_info(&dev->intf->dev,
23400 ++ "No extended capability support. Upgrade device firmware.\n");
23401 ++ return 0;
23402 ++ }
23403 ++
23404 ++ err = kvaser_usb_leaf_get_single_capability(dev,
23405 ++ KVASER_USB_LEAF_CAP_CMD_LISTEN_MODE,
23406 ++ &status);
23407 ++ if (err)
23408 ++ return err;
23409 ++ if (status)
23410 ++ dev_info(&dev->intf->dev,
23411 ++ "KVASER_USB_LEAF_CAP_CMD_LISTEN_MODE failed %u\n",
23412 ++ status);
23413 ++
23414 ++ err = kvaser_usb_leaf_get_single_capability(dev,
23415 ++ KVASER_USB_LEAF_CAP_CMD_ERR_REPORT,
23416 ++ &status);
23417 ++ if (err)
23418 ++ return err;
23419 ++ if (status)
23420 ++ dev_info(&dev->intf->dev,
23421 ++ "KVASER_USB_LEAF_CAP_CMD_ERR_REPORT failed %u\n",
23422 ++ status);
23423 ++
23424 ++ return 0;
23425 ++}
23426 ++
23427 ++static int kvaser_usb_leaf_get_capabilities(struct kvaser_usb *dev)
23428 ++{
23429 ++ int err = 0;
23430 ++
23431 ++ if (dev->driver_info->family == KVASER_LEAF)
23432 ++ err = kvaser_usb_leaf_get_capabilities_leaf(dev);
23433 ++
23434 ++ return err;
23435 ++}
23436 ++
23437 + static void kvaser_usb_leaf_tx_acknowledge(const struct kvaser_usb *dev,
23438 + const struct kvaser_cmd *cmd)
23439 + {
23440 +@@ -721,7 +897,7 @@ static void kvaser_usb_leaf_tx_acknowledge(const struct kvaser_usb *dev,
23441 + context = &priv->tx_contexts[tid % dev->max_tx_urbs];
23442 +
23443 + /* Sometimes the state change doesn't come after a bus-off event */
23444 +- if (priv->can.restart_ms && priv->can.state >= CAN_STATE_BUS_OFF) {
23445 ++ if (priv->can.restart_ms && priv->can.state == CAN_STATE_BUS_OFF) {
23446 + struct sk_buff *skb;
23447 + struct can_frame *cf;
23448 +
23449 +@@ -774,6 +950,16 @@ static int kvaser_usb_leaf_simple_cmd_async(struct kvaser_usb_net_priv *priv,
23450 + return err;
23451 + }
23452 +
23453 ++static void kvaser_usb_leaf_chip_state_req_work(struct work_struct *work)
23454 ++{
23455 ++ struct kvaser_usb_net_leaf_priv *leaf =
23456 ++ container_of(work, struct kvaser_usb_net_leaf_priv,
23457 ++ chip_state_req_work.work);
23458 ++ struct kvaser_usb_net_priv *priv = leaf->net;
23459 ++
23460 ++ kvaser_usb_leaf_simple_cmd_async(priv, CMD_GET_CHIP_STATE);
23461 ++}
23462 ++
23463 + static void
23464 + kvaser_usb_leaf_rx_error_update_can_state(struct kvaser_usb_net_priv *priv,
23465 + const struct kvaser_usb_err_summary *es,
23466 +@@ -792,20 +978,16 @@ kvaser_usb_leaf_rx_error_update_can_state(struct kvaser_usb_net_priv *priv,
23467 + new_state = CAN_STATE_BUS_OFF;
23468 + } else if (es->status & M16C_STATE_BUS_PASSIVE) {
23469 + new_state = CAN_STATE_ERROR_PASSIVE;
23470 +- } else if (es->status & M16C_STATE_BUS_ERROR) {
23471 ++ } else if ((es->status & M16C_STATE_BUS_ERROR) &&
23472 ++ cur_state >= CAN_STATE_BUS_OFF) {
23473 + /* Guard against spurious error events after a busoff */
23474 +- if (cur_state < CAN_STATE_BUS_OFF) {
23475 +- if (es->txerr >= 128 || es->rxerr >= 128)
23476 +- new_state = CAN_STATE_ERROR_PASSIVE;
23477 +- else if (es->txerr >= 96 || es->rxerr >= 96)
23478 +- new_state = CAN_STATE_ERROR_WARNING;
23479 +- else if (cur_state > CAN_STATE_ERROR_ACTIVE)
23480 +- new_state = CAN_STATE_ERROR_ACTIVE;
23481 +- }
23482 +- }
23483 +-
23484 +- if (!es->status)
23485 ++ } else if (es->txerr >= 128 || es->rxerr >= 128) {
23486 ++ new_state = CAN_STATE_ERROR_PASSIVE;
23487 ++ } else if (es->txerr >= 96 || es->rxerr >= 96) {
23488 ++ new_state = CAN_STATE_ERROR_WARNING;
23489 ++ } else {
23490 + new_state = CAN_STATE_ERROR_ACTIVE;
23491 ++ }
23492 +
23493 + if (new_state != cur_state) {
23494 + tx_state = (es->txerr >= es->rxerr) ? new_state : 0;
23495 +@@ -815,7 +997,7 @@ kvaser_usb_leaf_rx_error_update_can_state(struct kvaser_usb_net_priv *priv,
23496 + }
23497 +
23498 + if (priv->can.restart_ms &&
23499 +- cur_state >= CAN_STATE_BUS_OFF &&
23500 ++ cur_state == CAN_STATE_BUS_OFF &&
23501 + new_state < CAN_STATE_BUS_OFF)
23502 + priv->can.can_stats.restarts++;
23503 +
23504 +@@ -849,6 +1031,7 @@ static void kvaser_usb_leaf_rx_error(const struct kvaser_usb *dev,
23505 + struct sk_buff *skb;
23506 + struct net_device_stats *stats;
23507 + struct kvaser_usb_net_priv *priv;
23508 ++ struct kvaser_usb_net_leaf_priv *leaf;
23509 + enum can_state old_state, new_state;
23510 +
23511 + if (es->channel >= dev->nchannels) {
23512 +@@ -858,8 +1041,13 @@ static void kvaser_usb_leaf_rx_error(const struct kvaser_usb *dev,
23513 + }
23514 +
23515 + priv = dev->nets[es->channel];
23516 ++ leaf = priv->sub_priv;
23517 + stats = &priv->netdev->stats;
23518 +
23519 ++ /* Ignore e.g. state change to bus-off reported just after stopping */
23520 ++ if (!netif_running(priv->netdev))
23521 ++ return;
23522 ++
23523 + /* Update all of the CAN interface's state and error counters before
23524 + * trying any memory allocation that can actually fail with -ENOMEM.
23525 + *
23526 +@@ -874,6 +1062,14 @@ static void kvaser_usb_leaf_rx_error(const struct kvaser_usb *dev,
23527 + kvaser_usb_leaf_rx_error_update_can_state(priv, es, &tmp_cf);
23528 + new_state = priv->can.state;
23529 +
23530 ++ /* If there are errors, request status updates periodically as we do
23531 ++ * not get automatic notifications of improved state.
23532 ++ */
23533 ++ if (new_state < CAN_STATE_BUS_OFF &&
23534 ++ (es->rxerr || es->txerr || new_state == CAN_STATE_ERROR_PASSIVE))
23535 ++ schedule_delayed_work(&leaf->chip_state_req_work,
23536 ++ msecs_to_jiffies(500));
23537 ++
23538 + skb = alloc_can_err_skb(priv->netdev, &cf);
23539 + if (!skb) {
23540 + stats->rx_dropped++;
23541 +@@ -891,7 +1087,7 @@ static void kvaser_usb_leaf_rx_error(const struct kvaser_usb *dev,
23542 + }
23543 +
23544 + if (priv->can.restart_ms &&
23545 +- old_state >= CAN_STATE_BUS_OFF &&
23546 ++ old_state == CAN_STATE_BUS_OFF &&
23547 + new_state < CAN_STATE_BUS_OFF) {
23548 + cf->can_id |= CAN_ERR_RESTARTED;
23549 + netif_carrier_on(priv->netdev);
23550 +@@ -990,11 +1186,11 @@ static void kvaser_usb_leaf_usbcan_rx_error(const struct kvaser_usb *dev,
23551 +
23552 + case CMD_CAN_ERROR_EVENT:
23553 + es.channel = 0;
23554 +- es.status = cmd->u.usbcan.error_event.status_ch0;
23555 +- es.txerr = cmd->u.usbcan.error_event.tx_errors_count_ch0;
23556 +- es.rxerr = cmd->u.usbcan.error_event.rx_errors_count_ch0;
23557 ++ es.status = cmd->u.usbcan.can_error_event.status_ch0;
23558 ++ es.txerr = cmd->u.usbcan.can_error_event.tx_errors_count_ch0;
23559 ++ es.rxerr = cmd->u.usbcan.can_error_event.rx_errors_count_ch0;
23560 + es.usbcan.other_ch_status =
23561 +- cmd->u.usbcan.error_event.status_ch1;
23562 ++ cmd->u.usbcan.can_error_event.status_ch1;
23563 + kvaser_usb_leaf_usbcan_conditionally_rx_error(dev, &es);
23564 +
23565 + /* The USBCAN firmware supports up to 2 channels.
23566 +@@ -1002,13 +1198,13 @@ static void kvaser_usb_leaf_usbcan_rx_error(const struct kvaser_usb *dev,
23567 + */
23568 + if (dev->nchannels == MAX_USBCAN_NET_DEVICES) {
23569 + es.channel = 1;
23570 +- es.status = cmd->u.usbcan.error_event.status_ch1;
23571 ++ es.status = cmd->u.usbcan.can_error_event.status_ch1;
23572 + es.txerr =
23573 +- cmd->u.usbcan.error_event.tx_errors_count_ch1;
23574 ++ cmd->u.usbcan.can_error_event.tx_errors_count_ch1;
23575 + es.rxerr =
23576 +- cmd->u.usbcan.error_event.rx_errors_count_ch1;
23577 ++ cmd->u.usbcan.can_error_event.rx_errors_count_ch1;
23578 + es.usbcan.other_ch_status =
23579 +- cmd->u.usbcan.error_event.status_ch0;
23580 ++ cmd->u.usbcan.can_error_event.status_ch0;
23581 + kvaser_usb_leaf_usbcan_conditionally_rx_error(dev, &es);
23582 + }
23583 + break;
23584 +@@ -1025,11 +1221,11 @@ static void kvaser_usb_leaf_leaf_rx_error(const struct kvaser_usb *dev,
23585 +
23586 + switch (cmd->id) {
23587 + case CMD_CAN_ERROR_EVENT:
23588 +- es.channel = cmd->u.leaf.error_event.channel;
23589 +- es.status = cmd->u.leaf.error_event.status;
23590 +- es.txerr = cmd->u.leaf.error_event.tx_errors_count;
23591 +- es.rxerr = cmd->u.leaf.error_event.rx_errors_count;
23592 +- es.leaf.error_factor = cmd->u.leaf.error_event.error_factor;
23593 ++ es.channel = cmd->u.leaf.can_error_event.channel;
23594 ++ es.status = cmd->u.leaf.can_error_event.status;
23595 ++ es.txerr = cmd->u.leaf.can_error_event.tx_errors_count;
23596 ++ es.rxerr = cmd->u.leaf.can_error_event.rx_errors_count;
23597 ++ es.leaf.error_factor = cmd->u.leaf.can_error_event.error_factor;
23598 + break;
23599 + case CMD_LEAF_LOG_MESSAGE:
23600 + es.channel = cmd->u.leaf.log_message.channel;
23601 +@@ -1162,6 +1358,74 @@ static void kvaser_usb_leaf_rx_can_msg(const struct kvaser_usb *dev,
23602 + netif_rx(skb);
23603 + }
23604 +
23605 ++static void kvaser_usb_leaf_error_event_parameter(const struct kvaser_usb *dev,
23606 ++ const struct kvaser_cmd *cmd)
23607 ++{
23608 ++ u16 info1 = 0;
23609 ++
23610 ++ switch (dev->driver_info->family) {
23611 ++ case KVASER_LEAF:
23612 ++ info1 = le16_to_cpu(cmd->u.leaf.error_event.info1);
23613 ++ break;
23614 ++ case KVASER_USBCAN:
23615 ++ info1 = le16_to_cpu(cmd->u.usbcan.error_event.info1);
23616 ++ break;
23617 ++ }
23618 ++
23619 ++ /* info1 will contain the offending cmd_no */
23620 ++ switch (info1) {
23621 ++ case CMD_SET_CTRL_MODE:
23622 ++ dev_warn(&dev->intf->dev,
23623 ++ "CMD_SET_CTRL_MODE error in parameter\n");
23624 ++ break;
23625 ++
23626 ++ case CMD_SET_BUS_PARAMS:
23627 ++ dev_warn(&dev->intf->dev,
23628 ++ "CMD_SET_BUS_PARAMS error in parameter\n");
23629 ++ break;
23630 ++
23631 ++ default:
23632 ++ dev_warn(&dev->intf->dev,
23633 ++ "Unhandled parameter error event cmd_no (%u)\n",
23634 ++ info1);
23635 ++ break;
23636 ++ }
23637 ++}
23638 ++
23639 ++static void kvaser_usb_leaf_error_event(const struct kvaser_usb *dev,
23640 ++ const struct kvaser_cmd *cmd)
23641 ++{
23642 ++ u8 error_code = 0;
23643 ++
23644 ++ switch (dev->driver_info->family) {
23645 ++ case KVASER_LEAF:
23646 ++ error_code = cmd->u.leaf.error_event.error_code;
23647 ++ break;
23648 ++ case KVASER_USBCAN:
23649 ++ error_code = cmd->u.usbcan.error_event.error_code;
23650 ++ break;
23651 ++ }
23652 ++
23653 ++ switch (error_code) {
23654 ++ case KVASER_USB_LEAF_ERROR_EVENT_TX_QUEUE_FULL:
23655 ++ /* Received additional CAN message, when firmware TX queue is
23656 ++ * already full. Something is wrong with the driver.
23657 ++ * This should never happen!
23658 ++ */
23659 ++ dev_err(&dev->intf->dev,
23660 ++ "Received error event TX_QUEUE_FULL\n");
23661 ++ break;
23662 ++ case KVASER_USB_LEAF_ERROR_EVENT_PARAM:
23663 ++ kvaser_usb_leaf_error_event_parameter(dev, cmd);
23664 ++ break;
23665 ++
23666 ++ default:
23667 ++ dev_warn(&dev->intf->dev,
23668 ++ "Unhandled error event (%d)\n", error_code);
23669 ++ break;
23670 ++ }
23671 ++}
23672 ++
23673 + static void kvaser_usb_leaf_start_chip_reply(const struct kvaser_usb *dev,
23674 + const struct kvaser_cmd *cmd)
23675 + {
23676 +@@ -1202,6 +1466,25 @@ static void kvaser_usb_leaf_stop_chip_reply(const struct kvaser_usb *dev,
23677 + complete(&priv->stop_comp);
23678 + }
23679 +
23680 ++static void kvaser_usb_leaf_get_busparams_reply(const struct kvaser_usb *dev,
23681 ++ const struct kvaser_cmd *cmd)
23682 ++{
23683 ++ struct kvaser_usb_net_priv *priv;
23684 ++ u8 channel = cmd->u.busparams.channel;
23685 ++
23686 ++ if (channel >= dev->nchannels) {
23687 ++ dev_err(&dev->intf->dev,
23688 ++ "Invalid channel number (%d)\n", channel);
23689 ++ return;
23690 ++ }
23691 ++
23692 ++ priv = dev->nets[channel];
23693 ++ memcpy(&priv->busparams_nominal, &cmd->u.busparams.busparams,
23694 ++ sizeof(priv->busparams_nominal));
23695 ++
23696 ++ complete(&priv->get_busparams_comp);
23697 ++}
23698 ++
23699 + static void kvaser_usb_leaf_handle_command(const struct kvaser_usb *dev,
23700 + const struct kvaser_cmd *cmd)
23701 + {
23702 +@@ -1240,6 +1523,14 @@ static void kvaser_usb_leaf_handle_command(const struct kvaser_usb *dev,
23703 + kvaser_usb_leaf_tx_acknowledge(dev, cmd);
23704 + break;
23705 +
23706 ++ case CMD_ERROR_EVENT:
23707 ++ kvaser_usb_leaf_error_event(dev, cmd);
23708 ++ break;
23709 ++
23710 ++ case CMD_GET_BUS_PARAMS_REPLY:
23711 ++ kvaser_usb_leaf_get_busparams_reply(dev, cmd);
23712 ++ break;
23713 ++
23714 + /* Ignored commands */
23715 + case CMD_USBCAN_CLOCK_OVERFLOW_EVENT:
23716 + if (dev->driver_info->family != KVASER_USBCAN)
23717 +@@ -1336,10 +1627,13 @@ static int kvaser_usb_leaf_start_chip(struct kvaser_usb_net_priv *priv)
23718 +
23719 + static int kvaser_usb_leaf_stop_chip(struct kvaser_usb_net_priv *priv)
23720 + {
23721 ++ struct kvaser_usb_net_leaf_priv *leaf = priv->sub_priv;
23722 + int err;
23723 +
23724 + reinit_completion(&priv->stop_comp);
23725 +
23726 ++ cancel_delayed_work(&leaf->chip_state_req_work);
23727 ++
23728 + err = kvaser_usb_leaf_send_simple_cmd(priv->dev, CMD_STOP_CHIP,
23729 + priv->channel);
23730 + if (err)
23731 +@@ -1386,10 +1680,35 @@ static int kvaser_usb_leaf_init_card(struct kvaser_usb *dev)
23732 + return 0;
23733 + }
23734 +
23735 +-static int kvaser_usb_leaf_set_bittiming(struct net_device *netdev)
23736 ++static int kvaser_usb_leaf_init_channel(struct kvaser_usb_net_priv *priv)
23737 ++{
23738 ++ struct kvaser_usb_net_leaf_priv *leaf;
23739 ++
23740 ++ leaf = devm_kzalloc(&priv->dev->intf->dev, sizeof(*leaf), GFP_KERNEL);
23741 ++ if (!leaf)
23742 ++ return -ENOMEM;
23743 ++
23744 ++ leaf->net = priv;
23745 ++ INIT_DELAYED_WORK(&leaf->chip_state_req_work,
23746 ++ kvaser_usb_leaf_chip_state_req_work);
23747 ++
23748 ++ priv->sub_priv = leaf;
23749 ++
23750 ++ return 0;
23751 ++}
23752 ++
23753 ++static void kvaser_usb_leaf_remove_channel(struct kvaser_usb_net_priv *priv)
23754 ++{
23755 ++ struct kvaser_usb_net_leaf_priv *leaf = priv->sub_priv;
23756 ++
23757 ++ if (leaf)
23758 ++ cancel_delayed_work_sync(&leaf->chip_state_req_work);
23759 ++}
23760 ++
23761 ++static int kvaser_usb_leaf_set_bittiming(const struct net_device *netdev,
23762 ++ const struct kvaser_usb_busparams *busparams)
23763 + {
23764 + struct kvaser_usb_net_priv *priv = netdev_priv(netdev);
23765 +- struct can_bittiming *bt = &priv->can.bittiming;
23766 + struct kvaser_usb *dev = priv->dev;
23767 + struct kvaser_cmd *cmd;
23768 + int rc;
23769 +@@ -1402,15 +1721,8 @@ static int kvaser_usb_leaf_set_bittiming(struct net_device *netdev)
23770 + cmd->len = CMD_HEADER_LEN + sizeof(struct kvaser_cmd_busparams);
23771 + cmd->u.busparams.channel = priv->channel;
23772 + cmd->u.busparams.tid = 0xff;
23773 +- cmd->u.busparams.bitrate = cpu_to_le32(bt->bitrate);
23774 +- cmd->u.busparams.sjw = bt->sjw;
23775 +- cmd->u.busparams.tseg1 = bt->prop_seg + bt->phase_seg1;
23776 +- cmd->u.busparams.tseg2 = bt->phase_seg2;
23777 +-
23778 +- if (priv->can.ctrlmode & CAN_CTRLMODE_3_SAMPLES)
23779 +- cmd->u.busparams.no_samp = 3;
23780 +- else
23781 +- cmd->u.busparams.no_samp = 1;
23782 ++ memcpy(&cmd->u.busparams.busparams, busparams,
23783 ++ sizeof(cmd->u.busparams.busparams));
23784 +
23785 + rc = kvaser_usb_send_cmd(dev, cmd, cmd->len);
23786 +
23787 +@@ -1418,6 +1730,27 @@ static int kvaser_usb_leaf_set_bittiming(struct net_device *netdev)
23788 + return rc;
23789 + }
23790 +
23791 ++static int kvaser_usb_leaf_get_busparams(struct kvaser_usb_net_priv *priv)
23792 ++{
23793 ++ int err;
23794 ++
23795 ++ if (priv->dev->driver_info->family == KVASER_USBCAN)
23796 ++ return -EOPNOTSUPP;
23797 ++
23798 ++ reinit_completion(&priv->get_busparams_comp);
23799 ++
23800 ++ err = kvaser_usb_leaf_send_simple_cmd(priv->dev, CMD_GET_BUS_PARAMS,
23801 ++ priv->channel);
23802 ++ if (err)
23803 ++ return err;
23804 ++
23805 ++ if (!wait_for_completion_timeout(&priv->get_busparams_comp,
23806 ++ msecs_to_jiffies(KVASER_USB_TIMEOUT)))
23807 ++ return -ETIMEDOUT;
23808 ++
23809 ++ return 0;
23810 ++}
23811 ++
23812 + static int kvaser_usb_leaf_set_mode(struct net_device *netdev,
23813 + enum can_mode mode)
23814 + {
23815 +@@ -1479,14 +1812,18 @@ static int kvaser_usb_leaf_setup_endpoints(struct kvaser_usb *dev)
23816 + const struct kvaser_usb_dev_ops kvaser_usb_leaf_dev_ops = {
23817 + .dev_set_mode = kvaser_usb_leaf_set_mode,
23818 + .dev_set_bittiming = kvaser_usb_leaf_set_bittiming,
23819 ++ .dev_get_busparams = kvaser_usb_leaf_get_busparams,
23820 + .dev_set_data_bittiming = NULL,
23821 ++ .dev_get_data_busparams = NULL,
23822 + .dev_get_berr_counter = kvaser_usb_leaf_get_berr_counter,
23823 + .dev_setup_endpoints = kvaser_usb_leaf_setup_endpoints,
23824 + .dev_init_card = kvaser_usb_leaf_init_card,
23825 ++ .dev_init_channel = kvaser_usb_leaf_init_channel,
23826 ++ .dev_remove_channel = kvaser_usb_leaf_remove_channel,
23827 + .dev_get_software_info = kvaser_usb_leaf_get_software_info,
23828 + .dev_get_software_details = NULL,
23829 + .dev_get_card_info = kvaser_usb_leaf_get_card_info,
23830 +- .dev_get_capabilities = NULL,
23831 ++ .dev_get_capabilities = kvaser_usb_leaf_get_capabilities,
23832 + .dev_set_opt_mode = kvaser_usb_leaf_set_opt_mode,
23833 + .dev_start_chip = kvaser_usb_leaf_start_chip,
23834 + .dev_stop_chip = kvaser_usb_leaf_stop_chip,
23835 +diff --git a/drivers/net/dsa/lan9303-core.c b/drivers/net/dsa/lan9303-core.c
23836 +index 1de62604434d8..2ed64fa19d020 100644
23837 +--- a/drivers/net/dsa/lan9303-core.c
23838 ++++ b/drivers/net/dsa/lan9303-core.c
23839 +@@ -1003,9 +1003,11 @@ static void lan9303_get_ethtool_stats(struct dsa_switch *ds, int port,
23840 + ret = lan9303_read_switch_port(
23841 + chip, port, lan9303_mib[u].offset, &reg);
23842 +
23843 +- if (ret)
23844 ++ if (ret) {
23845 + dev_warn(chip->dev, "Reading status port %d reg %u failed\n",
23846 + port, lan9303_mib[u].offset);
23847 ++ reg = 0;
23848 ++ }
23849 + data[u] = reg;
23850 + }
23851 + }
23852 +diff --git a/drivers/net/dsa/mv88e6xxx/chip.c b/drivers/net/dsa/mv88e6xxx/chip.c
23853 +index 546d90dae9331..0fd978e3ce2de 100644
23854 +--- a/drivers/net/dsa/mv88e6xxx/chip.c
23855 ++++ b/drivers/net/dsa/mv88e6xxx/chip.c
23856 +@@ -689,13 +689,12 @@ static void mv88e6352_phylink_get_caps(struct mv88e6xxx_chip *chip, int port,
23857 +
23858 + /* Port 4 supports automedia if the serdes is associated with it. */
23859 + if (port == 4) {
23860 +- mv88e6xxx_reg_lock(chip);
23861 + err = mv88e6352_g2_scratch_port_has_serdes(chip, port);
23862 + if (err < 0)
23863 + dev_err(chip->dev, "p%d: failed to read scratch\n",
23864 + port);
23865 + if (err <= 0)
23866 +- goto unlock;
23867 ++ return;
23868 +
23869 + cmode = mv88e6352_get_port4_serdes_cmode(chip);
23870 + if (cmode < 0)
23871 +@@ -703,8 +702,6 @@ static void mv88e6352_phylink_get_caps(struct mv88e6xxx_chip *chip, int port,
23872 + port);
23873 + else
23874 + mv88e6xxx_translate_cmode(cmode, supported);
23875 +-unlock:
23876 +- mv88e6xxx_reg_unlock(chip);
23877 + }
23878 + }
23879 +
23880 +@@ -823,7 +820,9 @@ static void mv88e6xxx_get_caps(struct dsa_switch *ds, int port,
23881 + {
23882 + struct mv88e6xxx_chip *chip = ds->priv;
23883 +
23884 ++ mv88e6xxx_reg_lock(chip);
23885 + chip->info->ops->phylink_get_caps(chip, port, config);
23886 ++ mv88e6xxx_reg_unlock(chip);
23887 +
23888 + if (mv88e6xxx_phy_is_internal(ds, port)) {
23889 + __set_bit(PHY_INTERFACE_MODE_INTERNAL,
23890 +@@ -3299,7 +3298,7 @@ static int mv88e6xxx_setup_port(struct mv88e6xxx_chip *chip, int port)
23891 + struct phylink_config pl_config = {};
23892 + unsigned long caps;
23893 +
23894 +- mv88e6xxx_get_caps(ds, port, &pl_config);
23895 ++ chip->info->ops->phylink_get_caps(chip, port, &pl_config);
23896 +
23897 + caps = pl_config.mac_capabilities;
23898 +
23899 +diff --git a/drivers/net/ethernet/amd/atarilance.c b/drivers/net/ethernet/amd/atarilance.c
23900 +index 27869164c6e62..ca12f9f488390 100644
23901 +--- a/drivers/net/ethernet/amd/atarilance.c
23902 ++++ b/drivers/net/ethernet/amd/atarilance.c
23903 +@@ -824,7 +824,7 @@ lance_start_xmit(struct sk_buff *skb, struct net_device *dev)
23904 + lp->memcpy_f( PKTBUF_ADDR(head), (void *)skb->data, skb->len );
23905 + head->flag = TMD1_OWN_CHIP | TMD1_ENP | TMD1_STP;
23906 + dev->stats.tx_bytes += skb->len;
23907 +- dev_kfree_skb( skb );
23908 ++ dev_consume_skb_irq(skb);
23909 + lp->cur_tx++;
23910 + while( lp->cur_tx >= TX_RING_SIZE && lp->dirty_tx >= TX_RING_SIZE ) {
23911 + lp->cur_tx -= TX_RING_SIZE;
23912 +diff --git a/drivers/net/ethernet/amd/lance.c b/drivers/net/ethernet/amd/lance.c
23913 +index 462016666752c..e3b8de9fc728f 100644
23914 +--- a/drivers/net/ethernet/amd/lance.c
23915 ++++ b/drivers/net/ethernet/amd/lance.c
23916 +@@ -1001,7 +1001,7 @@ static netdev_tx_t lance_start_xmit(struct sk_buff *skb,
23917 + skb_copy_from_linear_data(skb, &lp->tx_bounce_buffs[entry], skb->len);
23918 + lp->tx_ring[entry].base =
23919 + ((u32)isa_virt_to_bus((lp->tx_bounce_buffs + entry)) & 0xffffff) | 0x83000000;
23920 +- dev_kfree_skb(skb);
23921 ++ dev_consume_skb_irq(skb);
23922 + } else {
23923 + lp->tx_skbuff[entry] = skb;
23924 + lp->tx_ring[entry].base = ((u32)isa_virt_to_bus(skb->data) & 0xffffff) | 0x83000000;
23925 +diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-phy-v2.c b/drivers/net/ethernet/amd/xgbe/xgbe-phy-v2.c
23926 +index 601a9f2fa9bfc..1ef04326a5727 100644
23927 +--- a/drivers/net/ethernet/amd/xgbe/xgbe-phy-v2.c
23928 ++++ b/drivers/net/ethernet/amd/xgbe/xgbe-phy-v2.c
23929 +@@ -189,6 +189,7 @@ enum xgbe_sfp_cable {
23930 + XGBE_SFP_CABLE_UNKNOWN = 0,
23931 + XGBE_SFP_CABLE_ACTIVE,
23932 + XGBE_SFP_CABLE_PASSIVE,
23933 ++ XGBE_SFP_CABLE_FIBER,
23934 + };
23935 +
23936 + enum xgbe_sfp_base {
23937 +@@ -236,10 +237,7 @@ enum xgbe_sfp_speed {
23938 +
23939 + #define XGBE_SFP_BASE_BR 12
23940 + #define XGBE_SFP_BASE_BR_1GBE_MIN 0x0a
23941 +-#define XGBE_SFP_BASE_BR_1GBE_MAX 0x0d
23942 + #define XGBE_SFP_BASE_BR_10GBE_MIN 0x64
23943 +-#define XGBE_SFP_BASE_BR_10GBE_MAX 0x68
23944 +-#define XGBE_MOLEX_SFP_BASE_BR_10GBE_MAX 0x78
23945 +
23946 + #define XGBE_SFP_BASE_CU_CABLE_LEN 18
23947 +
23948 +@@ -826,29 +824,22 @@ static void xgbe_phy_sfp_phy_settings(struct xgbe_prv_data *pdata)
23949 + static bool xgbe_phy_sfp_bit_rate(struct xgbe_sfp_eeprom *sfp_eeprom,
23950 + enum xgbe_sfp_speed sfp_speed)
23951 + {
23952 +- u8 *sfp_base, min, max;
23953 ++ u8 *sfp_base, min;
23954 +
23955 + sfp_base = sfp_eeprom->base;
23956 +
23957 + switch (sfp_speed) {
23958 + case XGBE_SFP_SPEED_1000:
23959 + min = XGBE_SFP_BASE_BR_1GBE_MIN;
23960 +- max = XGBE_SFP_BASE_BR_1GBE_MAX;
23961 + break;
23962 + case XGBE_SFP_SPEED_10000:
23963 + min = XGBE_SFP_BASE_BR_10GBE_MIN;
23964 +- if (memcmp(&sfp_eeprom->base[XGBE_SFP_BASE_VENDOR_NAME],
23965 +- XGBE_MOLEX_VENDOR, XGBE_SFP_BASE_VENDOR_NAME_LEN) == 0)
23966 +- max = XGBE_MOLEX_SFP_BASE_BR_10GBE_MAX;
23967 +- else
23968 +- max = XGBE_SFP_BASE_BR_10GBE_MAX;
23969 + break;
23970 + default:
23971 + return false;
23972 + }
23973 +
23974 +- return ((sfp_base[XGBE_SFP_BASE_BR] >= min) &&
23975 +- (sfp_base[XGBE_SFP_BASE_BR] <= max));
23976 ++ return sfp_base[XGBE_SFP_BASE_BR] >= min;
23977 + }
23978 +
23979 + static void xgbe_phy_free_phy_device(struct xgbe_prv_data *pdata)
23980 +@@ -1149,16 +1140,18 @@ static void xgbe_phy_sfp_parse_eeprom(struct xgbe_prv_data *pdata)
23981 + phy_data->sfp_tx_fault = xgbe_phy_check_sfp_tx_fault(phy_data);
23982 + phy_data->sfp_rx_los = xgbe_phy_check_sfp_rx_los(phy_data);
23983 +
23984 +- /* Assume ACTIVE cable unless told it is PASSIVE */
23985 ++ /* Assume FIBER cable unless told otherwise */
23986 + if (sfp_base[XGBE_SFP_BASE_CABLE] & XGBE_SFP_BASE_CABLE_PASSIVE) {
23987 + phy_data->sfp_cable = XGBE_SFP_CABLE_PASSIVE;
23988 + phy_data->sfp_cable_len = sfp_base[XGBE_SFP_BASE_CU_CABLE_LEN];
23989 +- } else {
23990 ++ } else if (sfp_base[XGBE_SFP_BASE_CABLE] & XGBE_SFP_BASE_CABLE_ACTIVE) {
23991 + phy_data->sfp_cable = XGBE_SFP_CABLE_ACTIVE;
23992 ++ } else {
23993 ++ phy_data->sfp_cable = XGBE_SFP_CABLE_FIBER;
23994 + }
23995 +
23996 + /* Determine the type of SFP */
23997 +- if (phy_data->sfp_cable == XGBE_SFP_CABLE_PASSIVE &&
23998 ++ if (phy_data->sfp_cable != XGBE_SFP_CABLE_FIBER &&
23999 + xgbe_phy_sfp_bit_rate(sfp_eeprom, XGBE_SFP_SPEED_10000))
24000 + phy_data->sfp_base = XGBE_SFP_BASE_10000_CR;
24001 + else if (sfp_base[XGBE_SFP_BASE_10GBE_CC] & XGBE_SFP_BASE_10GBE_CC_SR)
24002 +diff --git a/drivers/net/ethernet/apple/bmac.c b/drivers/net/ethernet/apple/bmac.c
24003 +index 334de0d93c899..9e653e2925f78 100644
24004 +--- a/drivers/net/ethernet/apple/bmac.c
24005 ++++ b/drivers/net/ethernet/apple/bmac.c
24006 +@@ -1510,7 +1510,7 @@ static void bmac_tx_timeout(struct timer_list *t)
24007 + i = bp->tx_empty;
24008 + ++dev->stats.tx_errors;
24009 + if (i != bp->tx_fill) {
24010 +- dev_kfree_skb(bp->tx_bufs[i]);
24011 ++ dev_kfree_skb_irq(bp->tx_bufs[i]);
24012 + bp->tx_bufs[i] = NULL;
24013 + if (++i >= N_TX_RING) i = 0;
24014 + bp->tx_empty = i;
24015 +diff --git a/drivers/net/ethernet/apple/mace.c b/drivers/net/ethernet/apple/mace.c
24016 +index d0a771b65e888..fd1b008b7208c 100644
24017 +--- a/drivers/net/ethernet/apple/mace.c
24018 ++++ b/drivers/net/ethernet/apple/mace.c
24019 +@@ -846,7 +846,7 @@ static void mace_tx_timeout(struct timer_list *t)
24020 + if (mp->tx_bad_runt) {
24021 + mp->tx_bad_runt = 0;
24022 + } else if (i != mp->tx_fill) {
24023 +- dev_kfree_skb(mp->tx_bufs[i]);
24024 ++ dev_kfree_skb_irq(mp->tx_bufs[i]);
24025 + if (++i >= N_TX_RING)
24026 + i = 0;
24027 + mp->tx_empty = i;
24028 +diff --git a/drivers/net/ethernet/dnet.c b/drivers/net/ethernet/dnet.c
24029 +index 92462ed87bc43..d9f0c297ae2a0 100644
24030 +--- a/drivers/net/ethernet/dnet.c
24031 ++++ b/drivers/net/ethernet/dnet.c
24032 +@@ -550,11 +550,11 @@ static netdev_tx_t dnet_start_xmit(struct sk_buff *skb, struct net_device *dev)
24033 +
24034 + skb_tx_timestamp(skb);
24035 +
24036 ++ spin_unlock_irqrestore(&bp->lock, flags);
24037 ++
24038 + /* free the buffer */
24039 + dev_kfree_skb(skb);
24040 +
24041 +- spin_unlock_irqrestore(&bp->lock, flags);
24042 +-
24043 + return NETDEV_TX_OK;
24044 + }
24045 +
24046 +diff --git a/drivers/net/ethernet/freescale/enetc/enetc.c b/drivers/net/ethernet/freescale/enetc/enetc.c
24047 +index 1d8ec1b120a13..525d506797fcf 100644
24048 +--- a/drivers/net/ethernet/freescale/enetc/enetc.c
24049 ++++ b/drivers/net/ethernet/freescale/enetc/enetc.c
24050 +@@ -1489,23 +1489,6 @@ static void enetc_xdp_drop(struct enetc_bdr *rx_ring, int rx_ring_first,
24051 + rx_ring->stats.xdp_drops++;
24052 + }
24053 +
24054 +-static void enetc_xdp_free(struct enetc_bdr *rx_ring, int rx_ring_first,
24055 +- int rx_ring_last)
24056 +-{
24057 +- while (rx_ring_first != rx_ring_last) {
24058 +- struct enetc_rx_swbd *rx_swbd = &rx_ring->rx_swbd[rx_ring_first];
24059 +-
24060 +- if (rx_swbd->page) {
24061 +- dma_unmap_page(rx_ring->dev, rx_swbd->dma, PAGE_SIZE,
24062 +- rx_swbd->dir);
24063 +- __free_page(rx_swbd->page);
24064 +- rx_swbd->page = NULL;
24065 +- }
24066 +- enetc_bdr_idx_inc(rx_ring, &rx_ring_first);
24067 +- }
24068 +- rx_ring->stats.xdp_redirect_failures++;
24069 +-}
24070 +-
24071 + static int enetc_clean_rx_ring_xdp(struct enetc_bdr *rx_ring,
24072 + struct napi_struct *napi, int work_limit,
24073 + struct bpf_prog *prog)
24074 +@@ -1527,8 +1510,8 @@ static int enetc_clean_rx_ring_xdp(struct enetc_bdr *rx_ring,
24075 + int orig_i, orig_cleaned_cnt;
24076 + struct xdp_buff xdp_buff;
24077 + struct sk_buff *skb;
24078 +- int tmp_orig_i, err;
24079 + u32 bd_status;
24080 ++ int err;
24081 +
24082 + rxbd = enetc_rxbd(rx_ring, i);
24083 + bd_status = le32_to_cpu(rxbd->r.lstatus);
24084 +@@ -1615,18 +1598,16 @@ static int enetc_clean_rx_ring_xdp(struct enetc_bdr *rx_ring,
24085 + break;
24086 + }
24087 +
24088 +- tmp_orig_i = orig_i;
24089 +-
24090 +- while (orig_i != i) {
24091 +- enetc_flip_rx_buff(rx_ring,
24092 +- &rx_ring->rx_swbd[orig_i]);
24093 +- enetc_bdr_idx_inc(rx_ring, &orig_i);
24094 +- }
24095 +-
24096 + err = xdp_do_redirect(rx_ring->ndev, &xdp_buff, prog);
24097 + if (unlikely(err)) {
24098 +- enetc_xdp_free(rx_ring, tmp_orig_i, i);
24099 ++ enetc_xdp_drop(rx_ring, orig_i, i);
24100 ++ rx_ring->stats.xdp_redirect_failures++;
24101 + } else {
24102 ++ while (orig_i != i) {
24103 ++ enetc_flip_rx_buff(rx_ring,
24104 ++ &rx_ring->rx_swbd[orig_i]);
24105 ++ enetc_bdr_idx_inc(rx_ring, &orig_i);
24106 ++ }
24107 + xdp_redirect_frm_cnt++;
24108 + rx_ring->stats.xdp_redirect++;
24109 + }
24110 +diff --git a/drivers/net/ethernet/intel/i40e/i40e_main.c b/drivers/net/ethernet/intel/i40e/i40e_main.c
24111 +index e53ea7ed0b1d2..8c07d92a6574c 100644
24112 +--- a/drivers/net/ethernet/intel/i40e/i40e_main.c
24113 ++++ b/drivers/net/ethernet/intel/i40e/i40e_main.c
24114 +@@ -3692,6 +3692,24 @@ static int i40e_vsi_configure_tx(struct i40e_vsi *vsi)
24115 + return err;
24116 + }
24117 +
24118 ++/**
24119 ++ * i40e_calculate_vsi_rx_buf_len - Calculates buffer length
24120 ++ *
24121 ++ * @vsi: VSI to calculate rx_buf_len from
24122 ++ */
24123 ++static u16 i40e_calculate_vsi_rx_buf_len(struct i40e_vsi *vsi)
24124 ++{
24125 ++ if (!vsi->netdev || (vsi->back->flags & I40E_FLAG_LEGACY_RX))
24126 ++ return I40E_RXBUFFER_2048;
24127 ++
24128 ++#if (PAGE_SIZE < 8192)
24129 ++ if (!I40E_2K_TOO_SMALL_WITH_PADDING && vsi->netdev->mtu <= ETH_DATA_LEN)
24130 ++ return I40E_RXBUFFER_1536 - NET_IP_ALIGN;
24131 ++#endif
24132 ++
24133 ++ return PAGE_SIZE < 8192 ? I40E_RXBUFFER_3072 : I40E_RXBUFFER_2048;
24134 ++}
24135 ++
24136 + /**
24137 + * i40e_vsi_configure_rx - Configure the VSI for Rx
24138 + * @vsi: the VSI being configured
24139 +@@ -3703,20 +3721,14 @@ static int i40e_vsi_configure_rx(struct i40e_vsi *vsi)
24140 + int err = 0;
24141 + u16 i;
24142 +
24143 +- if (!vsi->netdev || (vsi->back->flags & I40E_FLAG_LEGACY_RX)) {
24144 +- vsi->max_frame = I40E_MAX_RXBUFFER;
24145 +- vsi->rx_buf_len = I40E_RXBUFFER_2048;
24146 ++ vsi->max_frame = I40E_MAX_RXBUFFER;
24147 ++ vsi->rx_buf_len = i40e_calculate_vsi_rx_buf_len(vsi);
24148 ++
24149 + #if (PAGE_SIZE < 8192)
24150 +- } else if (!I40E_2K_TOO_SMALL_WITH_PADDING &&
24151 +- (vsi->netdev->mtu <= ETH_DATA_LEN)) {
24152 ++ if (vsi->netdev && !I40E_2K_TOO_SMALL_WITH_PADDING &&
24153 ++ vsi->netdev->mtu <= ETH_DATA_LEN)
24154 + vsi->max_frame = I40E_RXBUFFER_1536 - NET_IP_ALIGN;
24155 +- vsi->rx_buf_len = I40E_RXBUFFER_1536 - NET_IP_ALIGN;
24156 + #endif
24157 +- } else {
24158 +- vsi->max_frame = I40E_MAX_RXBUFFER;
24159 +- vsi->rx_buf_len = (PAGE_SIZE < 8192) ? I40E_RXBUFFER_3072 :
24160 +- I40E_RXBUFFER_2048;
24161 +- }
24162 +
24163 + /* set up individual rings */
24164 + for (i = 0; i < vsi->num_queue_pairs && !err; i++)
24165 +@@ -13290,7 +13302,7 @@ static int i40e_xdp_setup(struct i40e_vsi *vsi, struct bpf_prog *prog,
24166 + int i;
24167 +
24168 + /* Don't allow frames that span over multiple buffers */
24169 +- if (frame_size > vsi->rx_buf_len) {
24170 ++ if (frame_size > i40e_calculate_vsi_rx_buf_len(vsi)) {
24171 + NL_SET_ERR_MSG_MOD(extack, "MTU too large to enable XDP");
24172 + return -EINVAL;
24173 + }
24174 +diff --git a/drivers/net/ethernet/intel/igb/igb_main.c b/drivers/net/ethernet/intel/igb/igb_main.c
24175 +index ea46649b2ed3e..0e36894db9863 100644
24176 +--- a/drivers/net/ethernet/intel/igb/igb_main.c
24177 ++++ b/drivers/net/ethernet/intel/igb/igb_main.c
24178 +@@ -1202,8 +1202,12 @@ static int igb_alloc_q_vector(struct igb_adapter *adapter,
24179 + if (!q_vector) {
24180 + q_vector = kzalloc(size, GFP_KERNEL);
24181 + } else if (size > ksize(q_vector)) {
24182 +- kfree_rcu(q_vector, rcu);
24183 +- q_vector = kzalloc(size, GFP_KERNEL);
24184 ++ struct igb_q_vector *new_q_vector;
24185 ++
24186 ++ new_q_vector = kzalloc(size, GFP_KERNEL);
24187 ++ if (new_q_vector)
24188 ++ kfree_rcu(q_vector, rcu);
24189 ++ q_vector = new_q_vector;
24190 + } else {
24191 + memset(q_vector, 0, size);
24192 + }
24193 +diff --git a/drivers/net/ethernet/intel/igc/igc.h b/drivers/net/ethernet/intel/igc/igc.h
24194 +index 1e7e7071f64d2..df3e26c0cf01a 100644
24195 +--- a/drivers/net/ethernet/intel/igc/igc.h
24196 ++++ b/drivers/net/ethernet/intel/igc/igc.h
24197 +@@ -94,6 +94,8 @@ struct igc_ring {
24198 + u8 queue_index; /* logical index of the ring*/
24199 + u8 reg_idx; /* physical index of the ring */
24200 + bool launchtime_enable; /* true if LaunchTime is enabled */
24201 ++ ktime_t last_tx_cycle; /* end of the cycle with a launchtime transmission */
24202 ++ ktime_t last_ff_cycle; /* Last cycle with an active first flag */
24203 +
24204 + u32 start_time;
24205 + u32 end_time;
24206 +@@ -182,6 +184,7 @@ struct igc_adapter {
24207 +
24208 + ktime_t base_time;
24209 + ktime_t cycle_time;
24210 ++ bool qbv_enable;
24211 +
24212 + /* OS defined structs */
24213 + struct pci_dev *pdev;
24214 +diff --git a/drivers/net/ethernet/intel/igc/igc_defines.h b/drivers/net/ethernet/intel/igc/igc_defines.h
24215 +index 5c66b97c0cfac..4f2c446ace4d9 100644
24216 +--- a/drivers/net/ethernet/intel/igc/igc_defines.h
24217 ++++ b/drivers/net/ethernet/intel/igc/igc_defines.h
24218 +@@ -321,6 +321,8 @@
24219 + #define IGC_ADVTXD_L4LEN_SHIFT 8 /* Adv ctxt L4LEN shift */
24220 + #define IGC_ADVTXD_MSS_SHIFT 16 /* Adv ctxt MSS shift */
24221 +
24222 ++#define IGC_ADVTXD_TSN_CNTX_FIRST 0x00000080
24223 ++
24224 + /* Transmit Control */
24225 + #define IGC_TCTL_EN 0x00000002 /* enable Tx */
24226 + #define IGC_TCTL_PSP 0x00000008 /* pad short packets */
24227 +diff --git a/drivers/net/ethernet/intel/igc/igc_main.c b/drivers/net/ethernet/intel/igc/igc_main.c
24228 +index ebff0e04045d6..76f015196fbf4 100644
24229 +--- a/drivers/net/ethernet/intel/igc/igc_main.c
24230 ++++ b/drivers/net/ethernet/intel/igc/igc_main.c
24231 +@@ -1000,25 +1000,118 @@ static int igc_write_mc_addr_list(struct net_device *netdev)
24232 + return netdev_mc_count(netdev);
24233 + }
24234 +
24235 +-static __le32 igc_tx_launchtime(struct igc_adapter *adapter, ktime_t txtime)
24236 ++static __le32 igc_tx_launchtime(struct igc_ring *ring, ktime_t txtime,
24237 ++ bool *first_flag, bool *insert_empty)
24238 + {
24239 ++ struct igc_adapter *adapter = netdev_priv(ring->netdev);
24240 + ktime_t cycle_time = adapter->cycle_time;
24241 + ktime_t base_time = adapter->base_time;
24242 ++ ktime_t now = ktime_get_clocktai();
24243 ++ ktime_t baset_est, end_of_cycle;
24244 + u32 launchtime;
24245 ++ s64 n;
24246 +
24247 +- /* FIXME: when using ETF together with taprio, we may have a
24248 +- * case where 'delta' is larger than the cycle_time, this may
24249 +- * cause problems if we don't read the current value of
24250 +- * IGC_BASET, as the value writen into the launchtime
24251 +- * descriptor field may be misinterpreted.
24252 ++ n = div64_s64(ktime_sub_ns(now, base_time), cycle_time);
24253 ++
24254 ++ baset_est = ktime_add_ns(base_time, cycle_time * (n));
24255 ++ end_of_cycle = ktime_add_ns(baset_est, cycle_time);
24256 ++
24257 ++ if (ktime_compare(txtime, end_of_cycle) >= 0) {
24258 ++ if (baset_est != ring->last_ff_cycle) {
24259 ++ *first_flag = true;
24260 ++ ring->last_ff_cycle = baset_est;
24261 ++
24262 ++ if (ktime_compare(txtime, ring->last_tx_cycle) > 0)
24263 ++ *insert_empty = true;
24264 ++ }
24265 ++ }
24266 ++
24267 ++ /* Introducing a window at end of cycle on which packets
24268 ++ * potentially not honor launchtime. Window of 5us chosen
24269 ++ * considering software update the tail pointer and packets
24270 ++ * are dma'ed to packet buffer.
24271 + */
24272 +- div_s64_rem(ktime_sub_ns(txtime, base_time), cycle_time, &launchtime);
24273 ++ if ((ktime_sub_ns(end_of_cycle, now) < 5 * NSEC_PER_USEC))
24274 ++ netdev_warn(ring->netdev, "Packet with txtime=%llu may not be honoured\n",
24275 ++ txtime);
24276 ++
24277 ++ ring->last_tx_cycle = end_of_cycle;
24278 ++
24279 ++ launchtime = ktime_sub_ns(txtime, baset_est);
24280 ++ if (launchtime > 0)
24281 ++ div_s64_rem(launchtime, cycle_time, &launchtime);
24282 ++ else
24283 ++ launchtime = 0;
24284 +
24285 + return cpu_to_le32(launchtime);
24286 + }
24287 +
24288 ++static int igc_init_empty_frame(struct igc_ring *ring,
24289 ++ struct igc_tx_buffer *buffer,
24290 ++ struct sk_buff *skb)
24291 ++{
24292 ++ unsigned int size;
24293 ++ dma_addr_t dma;
24294 ++
24295 ++ size = skb_headlen(skb);
24296 ++
24297 ++ dma = dma_map_single(ring->dev, skb->data, size, DMA_TO_DEVICE);
24298 ++ if (dma_mapping_error(ring->dev, dma)) {
24299 ++ netdev_err_once(ring->netdev, "Failed to map DMA for TX\n");
24300 ++ return -ENOMEM;
24301 ++ }
24302 ++
24303 ++ buffer->skb = skb;
24304 ++ buffer->protocol = 0;
24305 ++ buffer->bytecount = skb->len;
24306 ++ buffer->gso_segs = 1;
24307 ++ buffer->time_stamp = jiffies;
24308 ++ dma_unmap_len_set(buffer, len, skb->len);
24309 ++ dma_unmap_addr_set(buffer, dma, dma);
24310 ++
24311 ++ return 0;
24312 ++}
24313 ++
24314 ++static int igc_init_tx_empty_descriptor(struct igc_ring *ring,
24315 ++ struct sk_buff *skb,
24316 ++ struct igc_tx_buffer *first)
24317 ++{
24318 ++ union igc_adv_tx_desc *desc;
24319 ++ u32 cmd_type, olinfo_status;
24320 ++ int err;
24321 ++
24322 ++ if (!igc_desc_unused(ring))
24323 ++ return -EBUSY;
24324 ++
24325 ++ err = igc_init_empty_frame(ring, first, skb);
24326 ++ if (err)
24327 ++ return err;
24328 ++
24329 ++ cmd_type = IGC_ADVTXD_DTYP_DATA | IGC_ADVTXD_DCMD_DEXT |
24330 ++ IGC_ADVTXD_DCMD_IFCS | IGC_TXD_DCMD |
24331 ++ first->bytecount;
24332 ++ olinfo_status = first->bytecount << IGC_ADVTXD_PAYLEN_SHIFT;
24333 ++
24334 ++ desc = IGC_TX_DESC(ring, ring->next_to_use);
24335 ++ desc->read.cmd_type_len = cpu_to_le32(cmd_type);
24336 ++ desc->read.olinfo_status = cpu_to_le32(olinfo_status);
24337 ++ desc->read.buffer_addr = cpu_to_le64(dma_unmap_addr(first, dma));
24338 ++
24339 ++ netdev_tx_sent_queue(txring_txq(ring), skb->len);
24340 ++
24341 ++ first->next_to_watch = desc;
24342 ++
24343 ++ ring->next_to_use++;
24344 ++ if (ring->next_to_use == ring->count)
24345 ++ ring->next_to_use = 0;
24346 ++
24347 ++ return 0;
24348 ++}
24349 ++
24350 ++#define IGC_EMPTY_FRAME_SIZE 60
24351 ++
24352 + static void igc_tx_ctxtdesc(struct igc_ring *tx_ring,
24353 +- struct igc_tx_buffer *first,
24354 ++ __le32 launch_time, bool first_flag,
24355 + u32 vlan_macip_lens, u32 type_tucmd,
24356 + u32 mss_l4len_idx)
24357 + {
24358 +@@ -1037,26 +1130,17 @@ static void igc_tx_ctxtdesc(struct igc_ring *tx_ring,
24359 + if (test_bit(IGC_RING_FLAG_TX_CTX_IDX, &tx_ring->flags))
24360 + mss_l4len_idx |= tx_ring->reg_idx << 4;
24361 +
24362 ++ if (first_flag)
24363 ++ mss_l4len_idx |= IGC_ADVTXD_TSN_CNTX_FIRST;
24364 ++
24365 + context_desc->vlan_macip_lens = cpu_to_le32(vlan_macip_lens);
24366 + context_desc->type_tucmd_mlhl = cpu_to_le32(type_tucmd);
24367 + context_desc->mss_l4len_idx = cpu_to_le32(mss_l4len_idx);
24368 +-
24369 +- /* We assume there is always a valid Tx time available. Invalid times
24370 +- * should have been handled by the upper layers.
24371 +- */
24372 +- if (tx_ring->launchtime_enable) {
24373 +- struct igc_adapter *adapter = netdev_priv(tx_ring->netdev);
24374 +- ktime_t txtime = first->skb->tstamp;
24375 +-
24376 +- skb_txtime_consumed(first->skb);
24377 +- context_desc->launch_time = igc_tx_launchtime(adapter,
24378 +- txtime);
24379 +- } else {
24380 +- context_desc->launch_time = 0;
24381 +- }
24382 ++ context_desc->launch_time = launch_time;
24383 + }
24384 +
24385 +-static void igc_tx_csum(struct igc_ring *tx_ring, struct igc_tx_buffer *first)
24386 ++static void igc_tx_csum(struct igc_ring *tx_ring, struct igc_tx_buffer *first,
24387 ++ __le32 launch_time, bool first_flag)
24388 + {
24389 + struct sk_buff *skb = first->skb;
24390 + u32 vlan_macip_lens = 0;
24391 +@@ -1096,7 +1180,8 @@ no_csum:
24392 + vlan_macip_lens |= skb_network_offset(skb) << IGC_ADVTXD_MACLEN_SHIFT;
24393 + vlan_macip_lens |= first->tx_flags & IGC_TX_FLAGS_VLAN_MASK;
24394 +
24395 +- igc_tx_ctxtdesc(tx_ring, first, vlan_macip_lens, type_tucmd, 0);
24396 ++ igc_tx_ctxtdesc(tx_ring, launch_time, first_flag,
24397 ++ vlan_macip_lens, type_tucmd, 0);
24398 + }
24399 +
24400 + static int __igc_maybe_stop_tx(struct igc_ring *tx_ring, const u16 size)
24401 +@@ -1320,6 +1405,7 @@ dma_error:
24402 +
24403 + static int igc_tso(struct igc_ring *tx_ring,
24404 + struct igc_tx_buffer *first,
24405 ++ __le32 launch_time, bool first_flag,
24406 + u8 *hdr_len)
24407 + {
24408 + u32 vlan_macip_lens, type_tucmd, mss_l4len_idx;
24409 +@@ -1406,8 +1492,8 @@ static int igc_tso(struct igc_ring *tx_ring,
24410 + vlan_macip_lens |= (ip.hdr - skb->data) << IGC_ADVTXD_MACLEN_SHIFT;
24411 + vlan_macip_lens |= first->tx_flags & IGC_TX_FLAGS_VLAN_MASK;
24412 +
24413 +- igc_tx_ctxtdesc(tx_ring, first, vlan_macip_lens,
24414 +- type_tucmd, mss_l4len_idx);
24415 ++ igc_tx_ctxtdesc(tx_ring, launch_time, first_flag,
24416 ++ vlan_macip_lens, type_tucmd, mss_l4len_idx);
24417 +
24418 + return 1;
24419 + }
24420 +@@ -1415,11 +1501,14 @@ static int igc_tso(struct igc_ring *tx_ring,
24421 + static netdev_tx_t igc_xmit_frame_ring(struct sk_buff *skb,
24422 + struct igc_ring *tx_ring)
24423 + {
24424 ++ bool first_flag = false, insert_empty = false;
24425 + u16 count = TXD_USE_COUNT(skb_headlen(skb));
24426 + __be16 protocol = vlan_get_protocol(skb);
24427 + struct igc_tx_buffer *first;
24428 ++ __le32 launch_time = 0;
24429 + u32 tx_flags = 0;
24430 + unsigned short f;
24431 ++ ktime_t txtime;
24432 + u8 hdr_len = 0;
24433 + int tso = 0;
24434 +
24435 +@@ -1433,11 +1522,40 @@ static netdev_tx_t igc_xmit_frame_ring(struct sk_buff *skb,
24436 + count += TXD_USE_COUNT(skb_frag_size(
24437 + &skb_shinfo(skb)->frags[f]));
24438 +
24439 +- if (igc_maybe_stop_tx(tx_ring, count + 3)) {
24440 ++ if (igc_maybe_stop_tx(tx_ring, count + 5)) {
24441 + /* this is a hard error */
24442 + return NETDEV_TX_BUSY;
24443 + }
24444 +
24445 ++ if (!tx_ring->launchtime_enable)
24446 ++ goto done;
24447 ++
24448 ++ txtime = skb->tstamp;
24449 ++ skb->tstamp = ktime_set(0, 0);
24450 ++ launch_time = igc_tx_launchtime(tx_ring, txtime, &first_flag, &insert_empty);
24451 ++
24452 ++ if (insert_empty) {
24453 ++ struct igc_tx_buffer *empty_info;
24454 ++ struct sk_buff *empty;
24455 ++ void *data;
24456 ++
24457 ++ empty_info = &tx_ring->tx_buffer_info[tx_ring->next_to_use];
24458 ++ empty = alloc_skb(IGC_EMPTY_FRAME_SIZE, GFP_ATOMIC);
24459 ++ if (!empty)
24460 ++ goto done;
24461 ++
24462 ++ data = skb_put(empty, IGC_EMPTY_FRAME_SIZE);
24463 ++ memset(data, 0, IGC_EMPTY_FRAME_SIZE);
24464 ++
24465 ++ igc_tx_ctxtdesc(tx_ring, 0, false, 0, 0, 0);
24466 ++
24467 ++ if (igc_init_tx_empty_descriptor(tx_ring,
24468 ++ empty,
24469 ++ empty_info) < 0)
24470 ++ dev_kfree_skb_any(empty);
24471 ++ }
24472 ++
24473 ++done:
24474 + /* record the location of the first descriptor for this packet */
24475 + first = &tx_ring->tx_buffer_info[tx_ring->next_to_use];
24476 + first->type = IGC_TX_BUFFER_TYPE_SKB;
24477 +@@ -1474,11 +1592,11 @@ static netdev_tx_t igc_xmit_frame_ring(struct sk_buff *skb,
24478 + first->tx_flags = tx_flags;
24479 + first->protocol = protocol;
24480 +
24481 +- tso = igc_tso(tx_ring, first, &hdr_len);
24482 ++ tso = igc_tso(tx_ring, first, launch_time, first_flag, &hdr_len);
24483 + if (tso < 0)
24484 + goto out_drop;
24485 + else if (!tso)
24486 +- igc_tx_csum(tx_ring, first);
24487 ++ igc_tx_csum(tx_ring, first, launch_time, first_flag);
24488 +
24489 + igc_tx_map(tx_ring, first, hdr_len);
24490 +
24491 +@@ -5881,10 +5999,16 @@ static int igc_save_qbv_schedule(struct igc_adapter *adapter,
24492 + bool queue_configured[IGC_MAX_TX_QUEUES] = { };
24493 + u32 start_time = 0, end_time = 0;
24494 + size_t n;
24495 ++ int i;
24496 ++
24497 ++ adapter->qbv_enable = qopt->enable;
24498 +
24499 + if (!qopt->enable)
24500 + return igc_tsn_clear_schedule(adapter);
24501 +
24502 ++ if (qopt->base_time < 0)
24503 ++ return -ERANGE;
24504 ++
24505 + if (adapter->base_time)
24506 + return -EALREADY;
24507 +
24508 +@@ -5896,10 +6020,24 @@ static int igc_save_qbv_schedule(struct igc_adapter *adapter,
24509 +
24510 + for (n = 0; n < qopt->num_entries; n++) {
24511 + struct tc_taprio_sched_entry *e = &qopt->entries[n];
24512 +- int i;
24513 +
24514 + end_time += e->interval;
24515 +
24516 ++ /* If any of the conditions below are true, we need to manually
24517 ++ * control the end time of the cycle.
24518 ++ * 1. Qbv users can specify a cycle time that is not equal
24519 ++ * to the total GCL intervals. Hence, recalculation is
24520 ++ * necessary here to exclude the time interval that
24521 ++ * exceeds the cycle time.
24522 ++ * 2. According to IEEE Std. 802.1Q-2018 section 8.6.9.2,
24523 ++ * once the end of the list is reached, it will switch
24524 ++ * to the END_OF_CYCLE state and leave the gates in the
24525 ++ * same state until the next cycle is started.
24526 ++ */
24527 ++ if (end_time > adapter->cycle_time ||
24528 ++ n + 1 == qopt->num_entries)
24529 ++ end_time = adapter->cycle_time;
24530 ++
24531 + for (i = 0; i < adapter->num_tx_queues; i++) {
24532 + struct igc_ring *ring = adapter->tx_ring[i];
24533 +
24534 +@@ -5920,6 +6058,18 @@ static int igc_save_qbv_schedule(struct igc_adapter *adapter,
24535 + start_time += e->interval;
24536 + }
24537 +
24538 ++ /* Check whether a queue gets configured.
24539 ++ * If not, set the start and end time to be end time.
24540 ++ */
24541 ++ for (i = 0; i < adapter->num_tx_queues; i++) {
24542 ++ if (!queue_configured[i]) {
24543 ++ struct igc_ring *ring = adapter->tx_ring[i];
24544 ++
24545 ++ ring->start_time = end_time;
24546 ++ ring->end_time = end_time;
24547 ++ }
24548 ++ }
24549 ++
24550 + return 0;
24551 + }
24552 +
24553 +diff --git a/drivers/net/ethernet/intel/igc/igc_tsn.c b/drivers/net/ethernet/intel/igc/igc_tsn.c
24554 +index 0fce22de2ab85..356c7455c5cee 100644
24555 +--- a/drivers/net/ethernet/intel/igc/igc_tsn.c
24556 ++++ b/drivers/net/ethernet/intel/igc/igc_tsn.c
24557 +@@ -36,7 +36,7 @@ static unsigned int igc_tsn_new_flags(struct igc_adapter *adapter)
24558 + {
24559 + unsigned int new_flags = adapter->flags & ~IGC_FLAG_TSN_ANY_ENABLED;
24560 +
24561 +- if (adapter->base_time)
24562 ++ if (adapter->qbv_enable)
24563 + new_flags |= IGC_FLAG_TSN_QBV_ENABLED;
24564 +
24565 + if (is_any_launchtime(adapter))
24566 +@@ -110,15 +110,8 @@ static int igc_tsn_enable_offload(struct igc_adapter *adapter)
24567 + wr32(IGC_STQT(i), ring->start_time);
24568 + wr32(IGC_ENDQT(i), ring->end_time);
24569 +
24570 +- if (adapter->base_time) {
24571 +- /* If we have a base_time we are in "taprio"
24572 +- * mode and we need to be strict about the
24573 +- * cycles: only transmit a packet if it can be
24574 +- * completed during that cycle.
24575 +- */
24576 +- txqctl |= IGC_TXQCTL_STRICT_CYCLE |
24577 +- IGC_TXQCTL_STRICT_END;
24578 +- }
24579 ++ txqctl |= IGC_TXQCTL_STRICT_CYCLE |
24580 ++ IGC_TXQCTL_STRICT_END;
24581 +
24582 + if (ring->launchtime_enable)
24583 + txqctl |= IGC_TXQCTL_QUEUE_MODE_LAUNCHT;
24584 +diff --git a/drivers/net/ethernet/mediatek/mtk_eth_soc.c b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
24585 +index 5380caf0acc2f..559c7a42c1c9c 100644
24586 +--- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
24587 ++++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
24588 +@@ -3209,6 +3209,30 @@ static void mtk_dim_tx(struct work_struct *work)
24589 + dim->state = DIM_START_MEASURE;
24590 + }
24591 +
24592 ++static void mtk_set_mcr_max_rx(struct mtk_mac *mac, u32 val)
24593 ++{
24594 ++ struct mtk_eth *eth = mac->hw;
24595 ++ u32 mcr_cur, mcr_new;
24596 ++
24597 ++ if (MTK_HAS_CAPS(eth->soc->caps, MTK_SOC_MT7628))
24598 ++ return;
24599 ++
24600 ++ mcr_cur = mtk_r32(mac->hw, MTK_MAC_MCR(mac->id));
24601 ++ mcr_new = mcr_cur & ~MAC_MCR_MAX_RX_MASK;
24602 ++
24603 ++ if (val <= 1518)
24604 ++ mcr_new |= MAC_MCR_MAX_RX(MAC_MCR_MAX_RX_1518);
24605 ++ else if (val <= 1536)
24606 ++ mcr_new |= MAC_MCR_MAX_RX(MAC_MCR_MAX_RX_1536);
24607 ++ else if (val <= 1552)
24608 ++ mcr_new |= MAC_MCR_MAX_RX(MAC_MCR_MAX_RX_1552);
24609 ++ else
24610 ++ mcr_new |= MAC_MCR_MAX_RX(MAC_MCR_MAX_RX_2048);
24611 ++
24612 ++ if (mcr_new != mcr_cur)
24613 ++ mtk_w32(mac->hw, mcr_new, MTK_MAC_MCR(mac->id));
24614 ++}
24615 ++
24616 + static int mtk_hw_init(struct mtk_eth *eth)
24617 + {
24618 + u32 dma_mask = ETHSYS_DMA_AG_MAP_PDMA | ETHSYS_DMA_AG_MAP_QDMA |
24619 +@@ -3248,16 +3272,17 @@ static int mtk_hw_init(struct mtk_eth *eth)
24620 + return 0;
24621 + }
24622 +
24623 +- val = RSTCTRL_FE | RSTCTRL_PPE;
24624 + if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V2)) {
24625 + regmap_write(eth->ethsys, ETHSYS_FE_RST_CHK_IDLE_EN, 0);
24626 +-
24627 +- val |= RSTCTRL_ETH;
24628 +- if (MTK_HAS_CAPS(eth->soc->caps, MTK_RSTCTRL_PPE1))
24629 +- val |= RSTCTRL_PPE1;
24630 ++ val = RSTCTRL_PPE0_V2;
24631 ++ } else {
24632 ++ val = RSTCTRL_PPE0;
24633 + }
24634 +
24635 +- ethsys_reset(eth, val);
24636 ++ if (MTK_HAS_CAPS(eth->soc->caps, MTK_RSTCTRL_PPE1))
24637 ++ val |= RSTCTRL_PPE1;
24638 ++
24639 ++ ethsys_reset(eth, RSTCTRL_ETH | RSTCTRL_FE | val);
24640 +
24641 + if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V2)) {
24642 + regmap_write(eth->ethsys, ETHSYS_FE_RST_CHK_IDLE_EN,
24643 +@@ -3283,8 +3308,16 @@ static int mtk_hw_init(struct mtk_eth *eth)
24644 + * up with the more appropriate value when mtk_mac_config call is being
24645 + * invoked.
24646 + */
24647 +- for (i = 0; i < MTK_MAC_COUNT; i++)
24648 ++ for (i = 0; i < MTK_MAC_COUNT; i++) {
24649 ++ struct net_device *dev = eth->netdev[i];
24650 ++
24651 + mtk_w32(eth, MAC_MCR_FORCE_LINK_DOWN, MTK_MAC_MCR(i));
24652 ++ if (dev) {
24653 ++ struct mtk_mac *mac = netdev_priv(dev);
24654 ++
24655 ++ mtk_set_mcr_max_rx(mac, dev->mtu + MTK_RX_ETH_HLEN);
24656 ++ }
24657 ++ }
24658 +
24659 + /* Indicates CDM to parse the MTK special tag from CPU
24660 + * which also is working out for untag packets.
24661 +@@ -3311,9 +3344,12 @@ static int mtk_hw_init(struct mtk_eth *eth)
24662 + mtk_w32(eth, 0x21021000, MTK_FE_INT_GRP);
24663 +
24664 + if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V2)) {
24665 +- /* PSE should not drop port8 and port9 packets */
24666 ++ /* PSE should not drop port8 and port9 packets from WDMA Tx */
24667 + mtk_w32(eth, 0x00000300, PSE_DROP_CFG);
24668 +
24669 ++ /* PSE should drop packets to port 8/9 on WDMA Rx ring full */
24670 ++ mtk_w32(eth, 0x00000300, PSE_PPE0_DROP);
24671 ++
24672 + /* PSE Free Queue Flow Control */
24673 + mtk_w32(eth, 0x01fa01f4, PSE_FQFC_CFG2);
24674 +
24675 +@@ -3400,7 +3436,6 @@ static int mtk_change_mtu(struct net_device *dev, int new_mtu)
24676 + int length = new_mtu + MTK_RX_ETH_HLEN;
24677 + struct mtk_mac *mac = netdev_priv(dev);
24678 + struct mtk_eth *eth = mac->hw;
24679 +- u32 mcr_cur, mcr_new;
24680 +
24681 + if (rcu_access_pointer(eth->prog) &&
24682 + length > MTK_PP_MAX_BUF_SIZE) {
24683 +@@ -3408,23 +3443,7 @@ static int mtk_change_mtu(struct net_device *dev, int new_mtu)
24684 + return -EINVAL;
24685 + }
24686 +
24687 +- if (!MTK_HAS_CAPS(eth->soc->caps, MTK_SOC_MT7628)) {
24688 +- mcr_cur = mtk_r32(mac->hw, MTK_MAC_MCR(mac->id));
24689 +- mcr_new = mcr_cur & ~MAC_MCR_MAX_RX_MASK;
24690 +-
24691 +- if (length <= 1518)
24692 +- mcr_new |= MAC_MCR_MAX_RX(MAC_MCR_MAX_RX_1518);
24693 +- else if (length <= 1536)
24694 +- mcr_new |= MAC_MCR_MAX_RX(MAC_MCR_MAX_RX_1536);
24695 +- else if (length <= 1552)
24696 +- mcr_new |= MAC_MCR_MAX_RX(MAC_MCR_MAX_RX_1552);
24697 +- else
24698 +- mcr_new |= MAC_MCR_MAX_RX(MAC_MCR_MAX_RX_2048);
24699 +-
24700 +- if (mcr_new != mcr_cur)
24701 +- mtk_w32(mac->hw, mcr_new, MTK_MAC_MCR(mac->id));
24702 +- }
24703 +-
24704 ++ mtk_set_mcr_max_rx(mac, length);
24705 + dev->mtu = new_mtu;
24706 +
24707 + return 0;
24708 +diff --git a/drivers/net/ethernet/mediatek/mtk_eth_soc.h b/drivers/net/ethernet/mediatek/mtk_eth_soc.h
24709 +index 0f9668a4079d9..df8e6e95254ec 100644
24710 +--- a/drivers/net/ethernet/mediatek/mtk_eth_soc.h
24711 ++++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.h
24712 +@@ -121,6 +121,7 @@
24713 + #define PSE_FQFC_CFG1 0x100
24714 + #define PSE_FQFC_CFG2 0x104
24715 + #define PSE_DROP_CFG 0x108
24716 ++#define PSE_PPE0_DROP 0x110
24717 +
24718 + /* PSE Input Queue Reservation Register*/
24719 + #define PSE_IQ_REV(x) (0x140 + (((x) - 1) << 2))
24720 +@@ -451,18 +452,14 @@
24721 + /* ethernet reset control register */
24722 + #define ETHSYS_RSTCTRL 0x34
24723 + #define RSTCTRL_FE BIT(6)
24724 +-#define RSTCTRL_PPE BIT(31)
24725 +-#define RSTCTRL_PPE1 BIT(30)
24726 ++#define RSTCTRL_PPE0 BIT(31)
24727 ++#define RSTCTRL_PPE0_V2 BIT(30)
24728 ++#define RSTCTRL_PPE1 BIT(31)
24729 + #define RSTCTRL_ETH BIT(23)
24730 +
24731 + /* ethernet reset check idle register */
24732 + #define ETHSYS_FE_RST_CHK_IDLE_EN 0x28
24733 +
24734 +-/* ethernet reset control register */
24735 +-#define ETHSYS_RSTCTRL 0x34
24736 +-#define RSTCTRL_FE BIT(6)
24737 +-#define RSTCTRL_PPE BIT(31)
24738 +-
24739 + /* ethernet dma channel agent map */
24740 + #define ETHSYS_DMA_AG_MAP 0x408
24741 + #define ETHSYS_DMA_AG_MAP_PDMA BIT(0)
24742 +diff --git a/drivers/net/ethernet/myricom/myri10ge/myri10ge.c b/drivers/net/ethernet/myricom/myri10ge/myri10ge.c
24743 +index 971dde8c32864..35410c9a3ecf0 100644
24744 +--- a/drivers/net/ethernet/myricom/myri10ge/myri10ge.c
24745 ++++ b/drivers/net/ethernet/myricom/myri10ge/myri10ge.c
24746 +@@ -3913,6 +3913,7 @@ abort_with_slices:
24747 + myri10ge_free_slices(mgp);
24748 +
24749 + abort_with_firmware:
24750 ++ kfree(mgp->msix_vectors);
24751 + myri10ge_dummy_rdma(mgp, 0);
24752 +
24753 + abort_with_ioremap:
24754 +diff --git a/drivers/net/ethernet/neterion/s2io.c b/drivers/net/ethernet/neterion/s2io.c
24755 +index 8f74c039b3be2..29d39e5b9cf53 100644
24756 +--- a/drivers/net/ethernet/neterion/s2io.c
24757 ++++ b/drivers/net/ethernet/neterion/s2io.c
24758 +@@ -2386,7 +2386,7 @@ static void free_tx_buffers(struct s2io_nic *nic)
24759 + skb = s2io_txdl_getskb(&mac_control->fifos[i], txdp, j);
24760 + if (skb) {
24761 + swstats->mem_freed += skb->truesize;
24762 +- dev_kfree_skb(skb);
24763 ++ dev_kfree_skb_irq(skb);
24764 + cnt++;
24765 + }
24766 + }
24767 +diff --git a/drivers/net/ethernet/qlogic/qed/qed_debug.c b/drivers/net/ethernet/qlogic/qed/qed_debug.c
24768 +index 5250d1d1e49ca..86ecb080b1536 100644
24769 +--- a/drivers/net/ethernet/qlogic/qed/qed_debug.c
24770 ++++ b/drivers/net/ethernet/qlogic/qed/qed_debug.c
24771 +@@ -1972,9 +1972,10 @@ static u32 qed_grc_dump_addr_range(struct qed_hwfn *p_hwfn,
24772 + u8 split_id)
24773 + {
24774 + struct dbg_tools_data *dev_data = &p_hwfn->dbg_info;
24775 +- u8 port_id = 0, pf_id = 0, vf_id = 0, fid = 0;
24776 ++ u8 port_id = 0, pf_id = 0, vf_id = 0;
24777 + bool read_using_dmae = false;
24778 + u32 thresh;
24779 ++ u16 fid;
24780 +
24781 + if (!dump)
24782 + return len;
24783 +diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_sriov_common.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_sriov_common.c
24784 +index 9282321c2e7fb..f9dd50152b1e3 100644
24785 +--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_sriov_common.c
24786 ++++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_sriov_common.c
24787 +@@ -221,6 +221,8 @@ int qlcnic_sriov_init(struct qlcnic_adapter *adapter, int num_vfs)
24788 + return 0;
24789 +
24790 + qlcnic_destroy_async_wq:
24791 ++ while (i--)
24792 ++ kfree(sriov->vf_info[i].vp);
24793 + destroy_workqueue(bc->bc_async_wq);
24794 +
24795 + qlcnic_destroy_trans_wq:
24796 +diff --git a/drivers/net/ethernet/rdc/r6040.c b/drivers/net/ethernet/rdc/r6040.c
24797 +index a6bf7d5051786..322d4d72d2e05 100644
24798 +--- a/drivers/net/ethernet/rdc/r6040.c
24799 ++++ b/drivers/net/ethernet/rdc/r6040.c
24800 +@@ -1159,10 +1159,12 @@ static int r6040_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
24801 + err = register_netdev(dev);
24802 + if (err) {
24803 + dev_err(&pdev->dev, "Failed to register net device\n");
24804 +- goto err_out_mdio_unregister;
24805 ++ goto err_out_phy_disconnect;
24806 + }
24807 + return 0;
24808 +
24809 ++err_out_phy_disconnect:
24810 ++ phy_disconnect(dev->phydev);
24811 + err_out_mdio_unregister:
24812 + mdiobus_unregister(lp->mii_bus);
24813 + err_out_mdio:
24814 +@@ -1186,6 +1188,7 @@ static void r6040_remove_one(struct pci_dev *pdev)
24815 + struct r6040_private *lp = netdev_priv(dev);
24816 +
24817 + unregister_netdev(dev);
24818 ++ phy_disconnect(dev->phydev);
24819 + mdiobus_unregister(lp->mii_bus);
24820 + mdiobus_free(lp->mii_bus);
24821 + netif_napi_del(&lp->napi);
24822 +diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_hwtstamp.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_hwtstamp.c
24823 +index 764832f4dae1a..8b50f03056b7b 100644
24824 +--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_hwtstamp.c
24825 ++++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_hwtstamp.c
24826 +@@ -47,7 +47,8 @@ static void config_sub_second_increment(void __iomem *ioaddr,
24827 + if (!(value & PTP_TCR_TSCTRLSSR))
24828 + data = (data * 1000) / 465;
24829 +
24830 +- data &= PTP_SSIR_SSINC_MASK;
24831 ++ if (data > PTP_SSIR_SSINC_MAX)
24832 ++ data = PTP_SSIR_SSINC_MAX;
24833 +
24834 + reg_value = data;
24835 + if (gmac4)
24836 +diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
24837 +index 0f080bfe8b176..bc4be1157aba7 100644
24838 +--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
24839 ++++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
24840 +@@ -7115,7 +7115,8 @@ int stmmac_dvr_probe(struct device *device,
24841 + priv->wq = create_singlethread_workqueue("stmmac_wq");
24842 + if (!priv->wq) {
24843 + dev_err(priv->device, "failed to create workqueue\n");
24844 +- return -ENOMEM;
24845 ++ ret = -ENOMEM;
24846 ++ goto error_wq_init;
24847 + }
24848 +
24849 + INIT_WORK(&priv->service_task, stmmac_service_task);
24850 +@@ -7343,6 +7344,7 @@ error_mdio_register:
24851 + stmmac_napi_del(ndev);
24852 + error_hw_init:
24853 + destroy_workqueue(priv->wq);
24854 ++error_wq_init:
24855 + bitmap_free(priv->af_xdp_zc_qps);
24856 +
24857 + return ret;
24858 +diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.h b/drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.h
24859 +index 53172a4398101..bf619295d079f 100644
24860 +--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.h
24861 ++++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.h
24862 +@@ -64,7 +64,7 @@
24863 + #define PTP_TCR_TSENMACADDR BIT(18)
24864 +
24865 + /* SSIR defines */
24866 +-#define PTP_SSIR_SSINC_MASK 0xff
24867 ++#define PTP_SSIR_SSINC_MAX 0xff
24868 + #define GMAC4_PTP_SSIR_SSINC_SHIFT 16
24869 +
24870 + /* Auxiliary Control defines */
24871 +diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c
24872 +index 49af7e78b7f59..687f43cd466c6 100644
24873 +--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c
24874 ++++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c
24875 +@@ -1654,12 +1654,16 @@ static int stmmac_test_arpoffload(struct stmmac_priv *priv)
24876 + }
24877 +
24878 + ret = stmmac_set_arp_offload(priv, priv->hw, true, ip_addr);
24879 +- if (ret)
24880 ++ if (ret) {
24881 ++ kfree_skb(skb);
24882 + goto cleanup;
24883 ++ }
24884 +
24885 + ret = dev_set_promiscuity(priv->dev, 1);
24886 +- if (ret)
24887 ++ if (ret) {
24888 ++ kfree_skb(skb);
24889 + goto cleanup;
24890 ++ }
24891 +
24892 + ret = dev_direct_xmit(skb, 0);
24893 + if (ret)
24894 +diff --git a/drivers/net/ethernet/ti/am65-cpsw-nuss.c b/drivers/net/ethernet/ti/am65-cpsw-nuss.c
24895 +index 47da11b9ac286..58678843d7948 100644
24896 +--- a/drivers/net/ethernet/ti/am65-cpsw-nuss.c
24897 ++++ b/drivers/net/ethernet/ti/am65-cpsw-nuss.c
24898 +@@ -562,13 +562,13 @@ static int am65_cpsw_nuss_ndo_slave_open(struct net_device *ndev)
24899 + ret = netif_set_real_num_tx_queues(ndev, common->tx_ch_num);
24900 + if (ret) {
24901 + dev_err(common->dev, "cannot set real number of tx queues\n");
24902 +- return ret;
24903 ++ goto runtime_put;
24904 + }
24905 +
24906 + ret = netif_set_real_num_rx_queues(ndev, AM65_CPSW_MAX_RX_QUEUES);
24907 + if (ret) {
24908 + dev_err(common->dev, "cannot set real number of rx queues\n");
24909 +- return ret;
24910 ++ goto runtime_put;
24911 + }
24912 +
24913 + for (i = 0; i < common->tx_ch_num; i++)
24914 +@@ -576,7 +576,7 @@ static int am65_cpsw_nuss_ndo_slave_open(struct net_device *ndev)
24915 +
24916 + ret = am65_cpsw_nuss_common_open(common, ndev->features);
24917 + if (ret)
24918 +- return ret;
24919 ++ goto runtime_put;
24920 +
24921 + common->usage_count++;
24922 +
24923 +@@ -609,6 +609,10 @@ static int am65_cpsw_nuss_ndo_slave_open(struct net_device *ndev)
24924 + error_cleanup:
24925 + am65_cpsw_nuss_ndo_slave_stop(ndev);
24926 + return ret;
24927 ++
24928 ++runtime_put:
24929 ++ pm_runtime_put(common->dev);
24930 ++ return ret;
24931 + }
24932 +
24933 + static void am65_cpsw_nuss_rx_cleanup(void *data, dma_addr_t desc_dma)
24934 +diff --git a/drivers/net/ethernet/ti/netcp_core.c b/drivers/net/ethernet/ti/netcp_core.c
24935 +index b15d44261e766..2672525609425 100644
24936 +--- a/drivers/net/ethernet/ti/netcp_core.c
24937 ++++ b/drivers/net/ethernet/ti/netcp_core.c
24938 +@@ -1261,7 +1261,7 @@ out:
24939 + }
24940 +
24941 + /* Submit the packet */
24942 +-static int netcp_ndo_start_xmit(struct sk_buff *skb, struct net_device *ndev)
24943 ++static netdev_tx_t netcp_ndo_start_xmit(struct sk_buff *skb, struct net_device *ndev)
24944 + {
24945 + struct netcp_intf *netcp = netdev_priv(ndev);
24946 + struct netcp_stats *tx_stats = &netcp->stats;
24947 +diff --git a/drivers/net/ethernet/xilinx/xilinx_emaclite.c b/drivers/net/ethernet/xilinx/xilinx_emaclite.c
24948 +index 016a9c4f2c6c7..ce0444b09664f 100644
24949 +--- a/drivers/net/ethernet/xilinx/xilinx_emaclite.c
24950 ++++ b/drivers/net/ethernet/xilinx/xilinx_emaclite.c
24951 +@@ -536,7 +536,7 @@ static void xemaclite_tx_timeout(struct net_device *dev, unsigned int txqueue)
24952 + xemaclite_enable_interrupts(lp);
24953 +
24954 + if (lp->deferred_skb) {
24955 +- dev_kfree_skb(lp->deferred_skb);
24956 ++ dev_kfree_skb_irq(lp->deferred_skb);
24957 + lp->deferred_skb = NULL;
24958 + dev->stats.tx_errors++;
24959 + }
24960 +diff --git a/drivers/net/fddi/defxx.c b/drivers/net/fddi/defxx.c
24961 +index b584ffe38ad68..1fef8a9b1a0fd 100644
24962 +--- a/drivers/net/fddi/defxx.c
24963 ++++ b/drivers/net/fddi/defxx.c
24964 +@@ -3831,10 +3831,24 @@ static int dfx_init(void)
24965 + int status;
24966 +
24967 + status = pci_register_driver(&dfx_pci_driver);
24968 +- if (!status)
24969 +- status = eisa_driver_register(&dfx_eisa_driver);
24970 +- if (!status)
24971 +- status = tc_register_driver(&dfx_tc_driver);
24972 ++ if (status)
24973 ++ goto err_pci_register;
24974 ++
24975 ++ status = eisa_driver_register(&dfx_eisa_driver);
24976 ++ if (status)
24977 ++ goto err_eisa_register;
24978 ++
24979 ++ status = tc_register_driver(&dfx_tc_driver);
24980 ++ if (status)
24981 ++ goto err_tc_register;
24982 ++
24983 ++ return 0;
24984 ++
24985 ++err_tc_register:
24986 ++ eisa_driver_unregister(&dfx_eisa_driver);
24987 ++err_eisa_register:
24988 ++ pci_unregister_driver(&dfx_pci_driver);
24989 ++err_pci_register:
24990 + return status;
24991 + }
24992 +
24993 +diff --git a/drivers/net/hamradio/baycom_epp.c b/drivers/net/hamradio/baycom_epp.c
24994 +index 3e69079ed694b..94720f8a8ba5e 100644
24995 +--- a/drivers/net/hamradio/baycom_epp.c
24996 ++++ b/drivers/net/hamradio/baycom_epp.c
24997 +@@ -758,7 +758,7 @@ static void epp_bh(struct work_struct *work)
24998 + * ===================== network driver interface =========================
24999 + */
25000 +
25001 +-static int baycom_send_packet(struct sk_buff *skb, struct net_device *dev)
25002 ++static netdev_tx_t baycom_send_packet(struct sk_buff *skb, struct net_device *dev)
25003 + {
25004 + struct baycom_state *bc = netdev_priv(dev);
25005 +
25006 +diff --git a/drivers/net/hamradio/scc.c b/drivers/net/hamradio/scc.c
25007 +index f90830d3dfa69..a9184a78650b0 100644
25008 +--- a/drivers/net/hamradio/scc.c
25009 ++++ b/drivers/net/hamradio/scc.c
25010 +@@ -302,12 +302,12 @@ static inline void scc_discard_buffers(struct scc_channel *scc)
25011 + spin_lock_irqsave(&scc->lock, flags);
25012 + if (scc->tx_buff != NULL)
25013 + {
25014 +- dev_kfree_skb(scc->tx_buff);
25015 ++ dev_kfree_skb_irq(scc->tx_buff);
25016 + scc->tx_buff = NULL;
25017 + }
25018 +
25019 + while (!skb_queue_empty(&scc->tx_queue))
25020 +- dev_kfree_skb(skb_dequeue(&scc->tx_queue));
25021 ++ dev_kfree_skb_irq(skb_dequeue(&scc->tx_queue));
25022 +
25023 + spin_unlock_irqrestore(&scc->lock, flags);
25024 + }
25025 +@@ -1668,7 +1668,7 @@ static netdev_tx_t scc_net_tx(struct sk_buff *skb, struct net_device *dev)
25026 + if (skb_queue_len(&scc->tx_queue) > scc->dev->tx_queue_len) {
25027 + struct sk_buff *skb_del;
25028 + skb_del = skb_dequeue(&scc->tx_queue);
25029 +- dev_kfree_skb(skb_del);
25030 ++ dev_kfree_skb_irq(skb_del);
25031 + }
25032 + skb_queue_tail(&scc->tx_queue, skb);
25033 + netif_trans_update(dev);
25034 +diff --git a/drivers/net/macsec.c b/drivers/net/macsec.c
25035 +index 8dafc814282cb..022b2daabd74d 100644
25036 +--- a/drivers/net/macsec.c
25037 ++++ b/drivers/net/macsec.c
25038 +@@ -2621,7 +2621,7 @@ static int macsec_upd_offload(struct sk_buff *skb, struct genl_info *info)
25039 + const struct macsec_ops *ops;
25040 + struct macsec_context ctx;
25041 + struct macsec_dev *macsec;
25042 +- int ret;
25043 ++ int ret = 0;
25044 +
25045 + if (!attrs[MACSEC_ATTR_IFINDEX])
25046 + return -EINVAL;
25047 +@@ -2634,28 +2634,36 @@ static int macsec_upd_offload(struct sk_buff *skb, struct genl_info *info)
25048 + macsec_genl_offload_policy, NULL))
25049 + return -EINVAL;
25050 +
25051 ++ rtnl_lock();
25052 ++
25053 + dev = get_dev_from_nl(genl_info_net(info), attrs);
25054 +- if (IS_ERR(dev))
25055 +- return PTR_ERR(dev);
25056 ++ if (IS_ERR(dev)) {
25057 ++ ret = PTR_ERR(dev);
25058 ++ goto out;
25059 ++ }
25060 + macsec = macsec_priv(dev);
25061 +
25062 +- if (!tb_offload[MACSEC_OFFLOAD_ATTR_TYPE])
25063 +- return -EINVAL;
25064 ++ if (!tb_offload[MACSEC_OFFLOAD_ATTR_TYPE]) {
25065 ++ ret = -EINVAL;
25066 ++ goto out;
25067 ++ }
25068 +
25069 + offload = nla_get_u8(tb_offload[MACSEC_OFFLOAD_ATTR_TYPE]);
25070 + if (macsec->offload == offload)
25071 +- return 0;
25072 ++ goto out;
25073 +
25074 + /* Check if the offloading mode is supported by the underlying layers */
25075 + if (offload != MACSEC_OFFLOAD_OFF &&
25076 +- !macsec_check_offload(offload, macsec))
25077 +- return -EOPNOTSUPP;
25078 ++ !macsec_check_offload(offload, macsec)) {
25079 ++ ret = -EOPNOTSUPP;
25080 ++ goto out;
25081 ++ }
25082 +
25083 + /* Check if the net device is busy. */
25084 +- if (netif_running(dev))
25085 +- return -EBUSY;
25086 +-
25087 +- rtnl_lock();
25088 ++ if (netif_running(dev)) {
25089 ++ ret = -EBUSY;
25090 ++ goto out;
25091 ++ }
25092 +
25093 + prev_offload = macsec->offload;
25094 + macsec->offload = offload;
25095 +@@ -2690,7 +2698,7 @@ static int macsec_upd_offload(struct sk_buff *skb, struct genl_info *info)
25096 +
25097 + rollback:
25098 + macsec->offload = prev_offload;
25099 +-
25100 ++out:
25101 + rtnl_unlock();
25102 + return ret;
25103 + }
25104 +diff --git a/drivers/net/mctp/mctp-serial.c b/drivers/net/mctp/mctp-serial.c
25105 +index 7cd103fd34ef7..9f9eaf896047c 100644
25106 +--- a/drivers/net/mctp/mctp-serial.c
25107 ++++ b/drivers/net/mctp/mctp-serial.c
25108 +@@ -35,6 +35,8 @@
25109 + #define BYTE_FRAME 0x7e
25110 + #define BYTE_ESC 0x7d
25111 +
25112 ++#define FCS_INIT 0xffff
25113 ++
25114 + static DEFINE_IDA(mctp_serial_ida);
25115 +
25116 + enum mctp_serial_state {
25117 +@@ -123,7 +125,7 @@ static void mctp_serial_tx_work(struct work_struct *work)
25118 + buf[2] = dev->txlen;
25119 +
25120 + if (!dev->txpos)
25121 +- dev->txfcs = crc_ccitt(0, buf + 1, 2);
25122 ++ dev->txfcs = crc_ccitt(FCS_INIT, buf + 1, 2);
25123 +
25124 + txlen = write_chunk(dev, buf + dev->txpos, 3 - dev->txpos);
25125 + if (txlen <= 0) {
25126 +@@ -303,7 +305,7 @@ static void mctp_serial_push_header(struct mctp_serial *dev, unsigned char c)
25127 + case 1:
25128 + if (c == MCTP_SERIAL_VERSION) {
25129 + dev->rxpos++;
25130 +- dev->rxfcs = crc_ccitt_byte(0, c);
25131 ++ dev->rxfcs = crc_ccitt_byte(FCS_INIT, c);
25132 + } else {
25133 + dev->rxstate = STATE_ERR;
25134 + }
25135 +diff --git a/drivers/net/ntb_netdev.c b/drivers/net/ntb_netdev.c
25136 +index dd7e273c90cbd..29b198472a2ca 100644
25137 +--- a/drivers/net/ntb_netdev.c
25138 ++++ b/drivers/net/ntb_netdev.c
25139 +@@ -137,7 +137,7 @@ static void ntb_netdev_rx_handler(struct ntb_transport_qp *qp, void *qp_data,
25140 + enqueue_again:
25141 + rc = ntb_transport_rx_enqueue(qp, skb, skb->data, ndev->mtu + ETH_HLEN);
25142 + if (rc) {
25143 +- dev_kfree_skb(skb);
25144 ++ dev_kfree_skb_any(skb);
25145 + ndev->stats.rx_errors++;
25146 + ndev->stats.rx_fifo_errors++;
25147 + }
25148 +@@ -192,7 +192,7 @@ static void ntb_netdev_tx_handler(struct ntb_transport_qp *qp, void *qp_data,
25149 + ndev->stats.tx_aborted_errors++;
25150 + }
25151 +
25152 +- dev_kfree_skb(skb);
25153 ++ dev_kfree_skb_any(skb);
25154 +
25155 + if (ntb_transport_tx_free_entry(dev->qp) >= tx_start) {
25156 + /* Make sure anybody stopping the queue after this sees the new
25157 +diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
25158 +index 9206c660a72ed..d4c821c8cf57c 100644
25159 +--- a/drivers/net/ppp/ppp_generic.c
25160 ++++ b/drivers/net/ppp/ppp_generic.c
25161 +@@ -1743,6 +1743,8 @@ ppp_send_frame(struct ppp *ppp, struct sk_buff *skb)
25162 + int len;
25163 + unsigned char *cp;
25164 +
25165 ++ skb->dev = ppp->dev;
25166 ++
25167 + if (proto < 0x8000) {
25168 + #ifdef CONFIG_PPP_FILTER
25169 + /* check if we should pass this packet */
25170 +diff --git a/drivers/net/wan/farsync.c b/drivers/net/wan/farsync.c
25171 +index 6a212c085435b..5b01642ca44e0 100644
25172 +--- a/drivers/net/wan/farsync.c
25173 ++++ b/drivers/net/wan/farsync.c
25174 +@@ -2545,6 +2545,7 @@ fst_remove_one(struct pci_dev *pdev)
25175 + struct net_device *dev = port_to_dev(&card->ports[i]);
25176 +
25177 + unregister_hdlc_device(dev);
25178 ++ free_netdev(dev);
25179 + }
25180 +
25181 + fst_disable_intr(card);
25182 +@@ -2564,6 +2565,7 @@ fst_remove_one(struct pci_dev *pdev)
25183 + card->tx_dma_handle_card);
25184 + }
25185 + fst_card_array[card->card_no] = NULL;
25186 ++ kfree(card);
25187 + }
25188 +
25189 + static struct pci_driver fst_driver = {
25190 +diff --git a/drivers/net/wireless/ath/ar5523/ar5523.c b/drivers/net/wireless/ath/ar5523/ar5523.c
25191 +index 6f937d2cc1263..ce3d613fa36c4 100644
25192 +--- a/drivers/net/wireless/ath/ar5523/ar5523.c
25193 ++++ b/drivers/net/wireless/ath/ar5523/ar5523.c
25194 +@@ -241,6 +241,11 @@ static void ar5523_cmd_tx_cb(struct urb *urb)
25195 + }
25196 + }
25197 +
25198 ++static void ar5523_cancel_tx_cmd(struct ar5523 *ar)
25199 ++{
25200 ++ usb_kill_urb(ar->tx_cmd.urb_tx);
25201 ++}
25202 ++
25203 + static int ar5523_cmd(struct ar5523 *ar, u32 code, const void *idata,
25204 + int ilen, void *odata, int olen, int flags)
25205 + {
25206 +@@ -280,6 +285,7 @@ static int ar5523_cmd(struct ar5523 *ar, u32 code, const void *idata,
25207 + }
25208 +
25209 + if (!wait_for_completion_timeout(&cmd->done, 2 * HZ)) {
25210 ++ ar5523_cancel_tx_cmd(ar);
25211 + cmd->odata = NULL;
25212 + ar5523_err(ar, "timeout waiting for command %02x reply\n",
25213 + code);
25214 +diff --git a/drivers/net/wireless/ath/ath10k/core.c b/drivers/net/wireless/ath/ath10k/core.c
25215 +index d1ac64026cb31..9a8ea7231a9ee 100644
25216 +--- a/drivers/net/wireless/ath/ath10k/core.c
25217 ++++ b/drivers/net/wireless/ath/ath10k/core.c
25218 +@@ -99,6 +99,7 @@ static const struct ath10k_hw_params ath10k_hw_params_list[] = {
25219 + .dynamic_sar_support = false,
25220 + .hw_restart_disconnect = false,
25221 + .use_fw_tx_credits = true,
25222 ++ .delay_unmap_buffer = false,
25223 + },
25224 + {
25225 + .id = QCA988X_HW_2_0_VERSION,
25226 +@@ -138,6 +139,7 @@ static const struct ath10k_hw_params ath10k_hw_params_list[] = {
25227 + .dynamic_sar_support = false,
25228 + .hw_restart_disconnect = false,
25229 + .use_fw_tx_credits = true,
25230 ++ .delay_unmap_buffer = false,
25231 + },
25232 + {
25233 + .id = QCA9887_HW_1_0_VERSION,
25234 +@@ -178,6 +180,7 @@ static const struct ath10k_hw_params ath10k_hw_params_list[] = {
25235 + .dynamic_sar_support = false,
25236 + .hw_restart_disconnect = false,
25237 + .use_fw_tx_credits = true,
25238 ++ .delay_unmap_buffer = false,
25239 + },
25240 + {
25241 + .id = QCA6174_HW_3_2_VERSION,
25242 +@@ -213,6 +216,7 @@ static const struct ath10k_hw_params ath10k_hw_params_list[] = {
25243 + .dynamic_sar_support = true,
25244 + .hw_restart_disconnect = false,
25245 + .use_fw_tx_credits = true,
25246 ++ .delay_unmap_buffer = false,
25247 + },
25248 + {
25249 + .id = QCA6174_HW_2_1_VERSION,
25250 +@@ -252,6 +256,7 @@ static const struct ath10k_hw_params ath10k_hw_params_list[] = {
25251 + .dynamic_sar_support = false,
25252 + .hw_restart_disconnect = false,
25253 + .use_fw_tx_credits = true,
25254 ++ .delay_unmap_buffer = false,
25255 + },
25256 + {
25257 + .id = QCA6174_HW_2_1_VERSION,
25258 +@@ -291,6 +296,7 @@ static const struct ath10k_hw_params ath10k_hw_params_list[] = {
25259 + .dynamic_sar_support = false,
25260 + .hw_restart_disconnect = false,
25261 + .use_fw_tx_credits = true,
25262 ++ .delay_unmap_buffer = false,
25263 + },
25264 + {
25265 + .id = QCA6174_HW_3_0_VERSION,
25266 +@@ -330,6 +336,7 @@ static const struct ath10k_hw_params ath10k_hw_params_list[] = {
25267 + .dynamic_sar_support = false,
25268 + .hw_restart_disconnect = false,
25269 + .use_fw_tx_credits = true,
25270 ++ .delay_unmap_buffer = false,
25271 + },
25272 + {
25273 + .id = QCA6174_HW_3_2_VERSION,
25274 +@@ -373,6 +380,7 @@ static const struct ath10k_hw_params ath10k_hw_params_list[] = {
25275 + .dynamic_sar_support = true,
25276 + .hw_restart_disconnect = false,
25277 + .use_fw_tx_credits = true,
25278 ++ .delay_unmap_buffer = false,
25279 + },
25280 + {
25281 + .id = QCA99X0_HW_2_0_DEV_VERSION,
25282 +@@ -418,6 +426,7 @@ static const struct ath10k_hw_params ath10k_hw_params_list[] = {
25283 + .dynamic_sar_support = false,
25284 + .hw_restart_disconnect = false,
25285 + .use_fw_tx_credits = true,
25286 ++ .delay_unmap_buffer = false,
25287 + },
25288 + {
25289 + .id = QCA9984_HW_1_0_DEV_VERSION,
25290 +@@ -470,6 +479,7 @@ static const struct ath10k_hw_params ath10k_hw_params_list[] = {
25291 + .dynamic_sar_support = false,
25292 + .hw_restart_disconnect = false,
25293 + .use_fw_tx_credits = true,
25294 ++ .delay_unmap_buffer = false,
25295 + },
25296 + {
25297 + .id = QCA9888_HW_2_0_DEV_VERSION,
25298 +@@ -519,6 +529,7 @@ static const struct ath10k_hw_params ath10k_hw_params_list[] = {
25299 + .dynamic_sar_support = false,
25300 + .hw_restart_disconnect = false,
25301 + .use_fw_tx_credits = true,
25302 ++ .delay_unmap_buffer = false,
25303 + },
25304 + {
25305 + .id = QCA9377_HW_1_0_DEV_VERSION,
25306 +@@ -558,6 +569,7 @@ static const struct ath10k_hw_params ath10k_hw_params_list[] = {
25307 + .dynamic_sar_support = false,
25308 + .hw_restart_disconnect = false,
25309 + .use_fw_tx_credits = true,
25310 ++ .delay_unmap_buffer = false,
25311 + },
25312 + {
25313 + .id = QCA9377_HW_1_1_DEV_VERSION,
25314 +@@ -599,6 +611,7 @@ static const struct ath10k_hw_params ath10k_hw_params_list[] = {
25315 + .dynamic_sar_support = false,
25316 + .hw_restart_disconnect = false,
25317 + .use_fw_tx_credits = true,
25318 ++ .delay_unmap_buffer = false,
25319 + },
25320 + {
25321 + .id = QCA9377_HW_1_1_DEV_VERSION,
25322 +@@ -631,6 +644,7 @@ static const struct ath10k_hw_params ath10k_hw_params_list[] = {
25323 + .dynamic_sar_support = false,
25324 + .hw_restart_disconnect = false,
25325 + .use_fw_tx_credits = true,
25326 ++ .delay_unmap_buffer = false,
25327 + },
25328 + {
25329 + .id = QCA4019_HW_1_0_DEV_VERSION,
25330 +@@ -677,6 +691,7 @@ static const struct ath10k_hw_params ath10k_hw_params_list[] = {
25331 + .dynamic_sar_support = false,
25332 + .hw_restart_disconnect = false,
25333 + .use_fw_tx_credits = true,
25334 ++ .delay_unmap_buffer = false,
25335 + },
25336 + {
25337 + .id = WCN3990_HW_1_0_DEV_VERSION,
25338 +@@ -709,6 +724,7 @@ static const struct ath10k_hw_params ath10k_hw_params_list[] = {
25339 + .dynamic_sar_support = true,
25340 + .hw_restart_disconnect = true,
25341 + .use_fw_tx_credits = false,
25342 ++ .delay_unmap_buffer = true,
25343 + },
25344 + };
25345 +
25346 +diff --git a/drivers/net/wireless/ath/ath10k/htc.c b/drivers/net/wireless/ath/ath10k/htc.c
25347 +index 6d1784f74bea4..5bfeecb95fca2 100644
25348 +--- a/drivers/net/wireless/ath/ath10k/htc.c
25349 ++++ b/drivers/net/wireless/ath/ath10k/htc.c
25350 +@@ -56,6 +56,15 @@ void ath10k_htc_notify_tx_completion(struct ath10k_htc_ep *ep,
25351 + ath10k_dbg(ar, ATH10K_DBG_HTC, "%s: ep %d skb %pK\n", __func__,
25352 + ep->eid, skb);
25353 +
25354 ++ /* A corner case where the copy completion is reaching to host but still
25355 ++ * copy engine is processing it due to which host unmaps corresponding
25356 ++ * memory and causes SMMU fault, hence as workaround adding delay
25357 ++ * the unmapping memory to avoid SMMU faults.
25358 ++ */
25359 ++ if (ar->hw_params.delay_unmap_buffer &&
25360 ++ ep->ul_pipe_id == 3)
25361 ++ mdelay(2);
25362 ++
25363 + hdr = (struct ath10k_htc_hdr *)skb->data;
25364 + ath10k_htc_restore_tx_skb(ep->htc, skb);
25365 +
25366 +diff --git a/drivers/net/wireless/ath/ath10k/hw.h b/drivers/net/wireless/ath/ath10k/hw.h
25367 +index 1b99f3a39a113..9643031a4427a 100644
25368 +--- a/drivers/net/wireless/ath/ath10k/hw.h
25369 ++++ b/drivers/net/wireless/ath/ath10k/hw.h
25370 +@@ -637,6 +637,8 @@ struct ath10k_hw_params {
25371 + bool hw_restart_disconnect;
25372 +
25373 + bool use_fw_tx_credits;
25374 ++
25375 ++ bool delay_unmap_buffer;
25376 + };
25377 +
25378 + struct htt_resp;
25379 +diff --git a/drivers/net/wireless/ath/ath10k/pci.c b/drivers/net/wireless/ath/ath10k/pci.c
25380 +index bf1c938be7d0a..8015b457a870f 100644
25381 +--- a/drivers/net/wireless/ath/ath10k/pci.c
25382 ++++ b/drivers/net/wireless/ath/ath10k/pci.c
25383 +@@ -3793,18 +3793,22 @@ static struct pci_driver ath10k_pci_driver = {
25384 +
25385 + static int __init ath10k_pci_init(void)
25386 + {
25387 +- int ret;
25388 ++ int ret1, ret2;
25389 +
25390 +- ret = pci_register_driver(&ath10k_pci_driver);
25391 +- if (ret)
25392 ++ ret1 = pci_register_driver(&ath10k_pci_driver);
25393 ++ if (ret1)
25394 + printk(KERN_ERR "failed to register ath10k pci driver: %d\n",
25395 +- ret);
25396 ++ ret1);
25397 +
25398 +- ret = ath10k_ahb_init();
25399 +- if (ret)
25400 +- printk(KERN_ERR "ahb init failed: %d\n", ret);
25401 ++ ret2 = ath10k_ahb_init();
25402 ++ if (ret2)
25403 ++ printk(KERN_ERR "ahb init failed: %d\n", ret2);
25404 +
25405 +- return ret;
25406 ++ if (ret1 && ret2)
25407 ++ return ret1;
25408 ++
25409 ++ /* registered to at least one bus */
25410 ++ return 0;
25411 + }
25412 + module_init(ath10k_pci_init);
25413 +
25414 +diff --git a/drivers/net/wireless/ath/ath11k/core.c b/drivers/net/wireless/ath/ath11k/core.c
25415 +index 9df6aaae8a443..1e9e4eae7a1e0 100644
25416 +--- a/drivers/net/wireless/ath/ath11k/core.c
25417 ++++ b/drivers/net/wireless/ath/ath11k/core.c
25418 +@@ -535,6 +535,52 @@ static inline struct ath11k_pdev *ath11k_core_get_single_pdev(struct ath11k_base
25419 + return &ab->pdevs[0];
25420 + }
25421 +
25422 ++void ath11k_fw_stats_pdevs_free(struct list_head *head)
25423 ++{
25424 ++ struct ath11k_fw_stats_pdev *i, *tmp;
25425 ++
25426 ++ list_for_each_entry_safe(i, tmp, head, list) {
25427 ++ list_del(&i->list);
25428 ++ kfree(i);
25429 ++ }
25430 ++}
25431 ++
25432 ++void ath11k_fw_stats_vdevs_free(struct list_head *head)
25433 ++{
25434 ++ struct ath11k_fw_stats_vdev *i, *tmp;
25435 ++
25436 ++ list_for_each_entry_safe(i, tmp, head, list) {
25437 ++ list_del(&i->list);
25438 ++ kfree(i);
25439 ++ }
25440 ++}
25441 ++
25442 ++void ath11k_fw_stats_bcn_free(struct list_head *head)
25443 ++{
25444 ++ struct ath11k_fw_stats_bcn *i, *tmp;
25445 ++
25446 ++ list_for_each_entry_safe(i, tmp, head, list) {
25447 ++ list_del(&i->list);
25448 ++ kfree(i);
25449 ++ }
25450 ++}
25451 ++
25452 ++void ath11k_fw_stats_init(struct ath11k *ar)
25453 ++{
25454 ++ INIT_LIST_HEAD(&ar->fw_stats.pdevs);
25455 ++ INIT_LIST_HEAD(&ar->fw_stats.vdevs);
25456 ++ INIT_LIST_HEAD(&ar->fw_stats.bcn);
25457 ++
25458 ++ init_completion(&ar->fw_stats_complete);
25459 ++}
25460 ++
25461 ++void ath11k_fw_stats_free(struct ath11k_fw_stats *stats)
25462 ++{
25463 ++ ath11k_fw_stats_pdevs_free(&stats->pdevs);
25464 ++ ath11k_fw_stats_vdevs_free(&stats->vdevs);
25465 ++ ath11k_fw_stats_bcn_free(&stats->bcn);
25466 ++}
25467 ++
25468 + int ath11k_core_suspend(struct ath11k_base *ab)
25469 + {
25470 + int ret;
25471 +diff --git a/drivers/net/wireless/ath/ath11k/core.h b/drivers/net/wireless/ath/ath11k/core.h
25472 +index afad8f55e4331..8edc1f4e5694d 100644
25473 +--- a/drivers/net/wireless/ath/ath11k/core.h
25474 ++++ b/drivers/net/wireless/ath/ath11k/core.h
25475 +@@ -498,6 +498,8 @@ struct ath11k_sta {
25476 +
25477 + bool use_4addr_set;
25478 + u16 tcl_metadata;
25479 ++
25480 ++ u32 bw_prev;
25481 + };
25482 +
25483 + #define ATH11K_MIN_5G_FREQ 4150
25484 +@@ -545,9 +547,6 @@ struct ath11k_debug {
25485 + struct dentry *debugfs_pdev;
25486 + struct ath11k_dbg_htt_stats htt_stats;
25487 + u32 extd_tx_stats;
25488 +- struct ath11k_fw_stats fw_stats;
25489 +- struct completion fw_stats_complete;
25490 +- bool fw_stats_done;
25491 + u32 extd_rx_stats;
25492 + u32 pktlog_filter;
25493 + u32 pktlog_mode;
25494 +@@ -710,6 +709,9 @@ struct ath11k {
25495 + u8 twt_enabled;
25496 + bool nlo_enabled;
25497 + u8 alpha2[REG_ALPHA2_LEN + 1];
25498 ++ struct ath11k_fw_stats fw_stats;
25499 ++ struct completion fw_stats_complete;
25500 ++ bool fw_stats_done;
25501 + };
25502 +
25503 + struct ath11k_band_cap {
25504 +@@ -1112,6 +1114,12 @@ struct ath11k_fw_stats_bcn {
25505 + u32 tx_bcn_outage_cnt;
25506 + };
25507 +
25508 ++void ath11k_fw_stats_init(struct ath11k *ar);
25509 ++void ath11k_fw_stats_pdevs_free(struct list_head *head);
25510 ++void ath11k_fw_stats_vdevs_free(struct list_head *head);
25511 ++void ath11k_fw_stats_bcn_free(struct list_head *head);
25512 ++void ath11k_fw_stats_free(struct ath11k_fw_stats *stats);
25513 ++
25514 + extern const struct ce_pipe_config ath11k_target_ce_config_wlan_ipq8074[];
25515 + extern const struct service_to_pipe ath11k_target_service_to_ce_map_wlan_ipq8074[];
25516 + extern const struct service_to_pipe ath11k_target_service_to_ce_map_wlan_ipq6018[];
25517 +diff --git a/drivers/net/wireless/ath/ath11k/debugfs.c b/drivers/net/wireless/ath/ath11k/debugfs.c
25518 +index 9648e00173936..649bf4495e4ac 100644
25519 +--- a/drivers/net/wireless/ath/ath11k/debugfs.c
25520 ++++ b/drivers/net/wireless/ath/ath11k/debugfs.c
25521 +@@ -91,91 +91,35 @@ void ath11k_debugfs_add_dbring_entry(struct ath11k *ar,
25522 + spin_unlock_bh(&dbr_data->lock);
25523 + }
25524 +
25525 +-static void ath11k_fw_stats_pdevs_free(struct list_head *head)
25526 +-{
25527 +- struct ath11k_fw_stats_pdev *i, *tmp;
25528 +-
25529 +- list_for_each_entry_safe(i, tmp, head, list) {
25530 +- list_del(&i->list);
25531 +- kfree(i);
25532 +- }
25533 +-}
25534 +-
25535 +-static void ath11k_fw_stats_vdevs_free(struct list_head *head)
25536 +-{
25537 +- struct ath11k_fw_stats_vdev *i, *tmp;
25538 +-
25539 +- list_for_each_entry_safe(i, tmp, head, list) {
25540 +- list_del(&i->list);
25541 +- kfree(i);
25542 +- }
25543 +-}
25544 +-
25545 +-static void ath11k_fw_stats_bcn_free(struct list_head *head)
25546 +-{
25547 +- struct ath11k_fw_stats_bcn *i, *tmp;
25548 +-
25549 +- list_for_each_entry_safe(i, tmp, head, list) {
25550 +- list_del(&i->list);
25551 +- kfree(i);
25552 +- }
25553 +-}
25554 +-
25555 + static void ath11k_debugfs_fw_stats_reset(struct ath11k *ar)
25556 + {
25557 + spin_lock_bh(&ar->data_lock);
25558 +- ar->debug.fw_stats_done = false;
25559 +- ath11k_fw_stats_pdevs_free(&ar->debug.fw_stats.pdevs);
25560 +- ath11k_fw_stats_vdevs_free(&ar->debug.fw_stats.vdevs);
25561 ++ ar->fw_stats_done = false;
25562 ++ ath11k_fw_stats_pdevs_free(&ar->fw_stats.pdevs);
25563 ++ ath11k_fw_stats_vdevs_free(&ar->fw_stats.vdevs);
25564 + spin_unlock_bh(&ar->data_lock);
25565 + }
25566 +
25567 +-void ath11k_debugfs_fw_stats_process(struct ath11k_base *ab, struct sk_buff *skb)
25568 ++void ath11k_debugfs_fw_stats_process(struct ath11k *ar, struct ath11k_fw_stats *stats)
25569 + {
25570 +- struct ath11k_fw_stats stats = {};
25571 +- struct ath11k *ar;
25572 ++ struct ath11k_base *ab = ar->ab;
25573 + struct ath11k_pdev *pdev;
25574 + bool is_end;
25575 + static unsigned int num_vdev, num_bcn;
25576 + size_t total_vdevs_started = 0;
25577 +- int i, ret;
25578 +-
25579 +- INIT_LIST_HEAD(&stats.pdevs);
25580 +- INIT_LIST_HEAD(&stats.vdevs);
25581 +- INIT_LIST_HEAD(&stats.bcn);
25582 +-
25583 +- ret = ath11k_wmi_pull_fw_stats(ab, skb, &stats);
25584 +- if (ret) {
25585 +- ath11k_warn(ab, "failed to pull fw stats: %d\n", ret);
25586 +- goto free;
25587 +- }
25588 +-
25589 +- rcu_read_lock();
25590 +- ar = ath11k_mac_get_ar_by_pdev_id(ab, stats.pdev_id);
25591 +- if (!ar) {
25592 +- rcu_read_unlock();
25593 +- ath11k_warn(ab, "failed to get ar for pdev_id %d: %d\n",
25594 +- stats.pdev_id, ret);
25595 +- goto free;
25596 +- }
25597 ++ int i;
25598 +
25599 +- spin_lock_bh(&ar->data_lock);
25600 ++ /* WMI_REQUEST_PDEV_STAT request has been already processed */
25601 +
25602 +- if (stats.stats_id == WMI_REQUEST_PDEV_STAT) {
25603 +- list_splice_tail_init(&stats.pdevs, &ar->debug.fw_stats.pdevs);
25604 +- ar->debug.fw_stats_done = true;
25605 +- goto complete;
25606 +- }
25607 +-
25608 +- if (stats.stats_id == WMI_REQUEST_RSSI_PER_CHAIN_STAT) {
25609 +- ar->debug.fw_stats_done = true;
25610 +- goto complete;
25611 ++ if (stats->stats_id == WMI_REQUEST_RSSI_PER_CHAIN_STAT) {
25612 ++ ar->fw_stats_done = true;
25613 ++ return;
25614 + }
25615 +
25616 +- if (stats.stats_id == WMI_REQUEST_VDEV_STAT) {
25617 +- if (list_empty(&stats.vdevs)) {
25618 ++ if (stats->stats_id == WMI_REQUEST_VDEV_STAT) {
25619 ++ if (list_empty(&stats->vdevs)) {
25620 + ath11k_warn(ab, "empty vdev stats");
25621 +- goto complete;
25622 ++ return;
25623 + }
25624 + /* FW sends all the active VDEV stats irrespective of PDEV,
25625 + * hence limit until the count of all VDEVs started
25626 +@@ -188,43 +132,34 @@ void ath11k_debugfs_fw_stats_process(struct ath11k_base *ab, struct sk_buff *skb
25627 +
25628 + is_end = ((++num_vdev) == total_vdevs_started);
25629 +
25630 +- list_splice_tail_init(&stats.vdevs,
25631 +- &ar->debug.fw_stats.vdevs);
25632 ++ list_splice_tail_init(&stats->vdevs,
25633 ++ &ar->fw_stats.vdevs);
25634 +
25635 + if (is_end) {
25636 +- ar->debug.fw_stats_done = true;
25637 ++ ar->fw_stats_done = true;
25638 + num_vdev = 0;
25639 + }
25640 +- goto complete;
25641 ++ return;
25642 + }
25643 +
25644 +- if (stats.stats_id == WMI_REQUEST_BCN_STAT) {
25645 +- if (list_empty(&stats.bcn)) {
25646 ++ if (stats->stats_id == WMI_REQUEST_BCN_STAT) {
25647 ++ if (list_empty(&stats->bcn)) {
25648 + ath11k_warn(ab, "empty bcn stats");
25649 +- goto complete;
25650 ++ return;
25651 + }
25652 + /* Mark end until we reached the count of all started VDEVs
25653 + * within the PDEV
25654 + */
25655 + is_end = ((++num_bcn) == ar->num_started_vdevs);
25656 +
25657 +- list_splice_tail_init(&stats.bcn,
25658 +- &ar->debug.fw_stats.bcn);
25659 ++ list_splice_tail_init(&stats->bcn,
25660 ++ &ar->fw_stats.bcn);
25661 +
25662 + if (is_end) {
25663 +- ar->debug.fw_stats_done = true;
25664 ++ ar->fw_stats_done = true;
25665 + num_bcn = 0;
25666 + }
25667 + }
25668 +-complete:
25669 +- complete(&ar->debug.fw_stats_complete);
25670 +- rcu_read_unlock();
25671 +- spin_unlock_bh(&ar->data_lock);
25672 +-
25673 +-free:
25674 +- ath11k_fw_stats_pdevs_free(&stats.pdevs);
25675 +- ath11k_fw_stats_vdevs_free(&stats.vdevs);
25676 +- ath11k_fw_stats_bcn_free(&stats.bcn);
25677 + }
25678 +
25679 + static int ath11k_debugfs_fw_stats_request(struct ath11k *ar,
25680 +@@ -245,7 +180,7 @@ static int ath11k_debugfs_fw_stats_request(struct ath11k *ar,
25681 +
25682 + ath11k_debugfs_fw_stats_reset(ar);
25683 +
25684 +- reinit_completion(&ar->debug.fw_stats_complete);
25685 ++ reinit_completion(&ar->fw_stats_complete);
25686 +
25687 + ret = ath11k_wmi_send_stats_request_cmd(ar, req_param);
25688 +
25689 +@@ -255,9 +190,8 @@ static int ath11k_debugfs_fw_stats_request(struct ath11k *ar,
25690 + return ret;
25691 + }
25692 +
25693 +- time_left =
25694 +- wait_for_completion_timeout(&ar->debug.fw_stats_complete,
25695 +- 1 * HZ);
25696 ++ time_left = wait_for_completion_timeout(&ar->fw_stats_complete, 1 * HZ);
25697 ++
25698 + if (!time_left)
25699 + return -ETIMEDOUT;
25700 +
25701 +@@ -266,7 +200,7 @@ static int ath11k_debugfs_fw_stats_request(struct ath11k *ar,
25702 + break;
25703 +
25704 + spin_lock_bh(&ar->data_lock);
25705 +- if (ar->debug.fw_stats_done) {
25706 ++ if (ar->fw_stats_done) {
25707 + spin_unlock_bh(&ar->data_lock);
25708 + break;
25709 + }
25710 +@@ -338,8 +272,7 @@ static int ath11k_open_pdev_stats(struct inode *inode, struct file *file)
25711 + goto err_free;
25712 + }
25713 +
25714 +- ath11k_wmi_fw_stats_fill(ar, &ar->debug.fw_stats, req_param.stats_id,
25715 +- buf);
25716 ++ ath11k_wmi_fw_stats_fill(ar, &ar->fw_stats, req_param.stats_id, buf);
25717 +
25718 + file->private_data = buf;
25719 +
25720 +@@ -410,8 +343,7 @@ static int ath11k_open_vdev_stats(struct inode *inode, struct file *file)
25721 + goto err_free;
25722 + }
25723 +
25724 +- ath11k_wmi_fw_stats_fill(ar, &ar->debug.fw_stats, req_param.stats_id,
25725 +- buf);
25726 ++ ath11k_wmi_fw_stats_fill(ar, &ar->fw_stats, req_param.stats_id, buf);
25727 +
25728 + file->private_data = buf;
25729 +
25730 +@@ -488,14 +420,13 @@ static int ath11k_open_bcn_stats(struct inode *inode, struct file *file)
25731 + }
25732 + }
25733 +
25734 +- ath11k_wmi_fw_stats_fill(ar, &ar->debug.fw_stats, req_param.stats_id,
25735 +- buf);
25736 ++ ath11k_wmi_fw_stats_fill(ar, &ar->fw_stats, req_param.stats_id, buf);
25737 +
25738 + /* since beacon stats request is looped for all active VDEVs, saved fw
25739 + * stats is not freed for each request until done for all active VDEVs
25740 + */
25741 + spin_lock_bh(&ar->data_lock);
25742 +- ath11k_fw_stats_bcn_free(&ar->debug.fw_stats.bcn);
25743 ++ ath11k_fw_stats_bcn_free(&ar->fw_stats.bcn);
25744 + spin_unlock_bh(&ar->data_lock);
25745 +
25746 + file->private_data = buf;
25747 +@@ -1025,7 +956,7 @@ void ath11k_debugfs_fw_stats_init(struct ath11k *ar)
25748 + struct dentry *fwstats_dir = debugfs_create_dir("fw_stats",
25749 + ar->debug.debugfs_pdev);
25750 +
25751 +- ar->debug.fw_stats.debugfs_fwstats = fwstats_dir;
25752 ++ ar->fw_stats.debugfs_fwstats = fwstats_dir;
25753 +
25754 + /* all stats debugfs files created are under "fw_stats" directory
25755 + * created per PDEV
25756 +@@ -1036,12 +967,6 @@ void ath11k_debugfs_fw_stats_init(struct ath11k *ar)
25757 + &fops_vdev_stats);
25758 + debugfs_create_file("beacon_stats", 0600, fwstats_dir, ar,
25759 + &fops_bcn_stats);
25760 +-
25761 +- INIT_LIST_HEAD(&ar->debug.fw_stats.pdevs);
25762 +- INIT_LIST_HEAD(&ar->debug.fw_stats.vdevs);
25763 +- INIT_LIST_HEAD(&ar->debug.fw_stats.bcn);
25764 +-
25765 +- init_completion(&ar->debug.fw_stats_complete);
25766 + }
25767 +
25768 + static ssize_t ath11k_write_pktlog_filter(struct file *file,
25769 +diff --git a/drivers/net/wireless/ath/ath11k/debugfs.h b/drivers/net/wireless/ath/ath11k/debugfs.h
25770 +index 30c00cb283118..0a84645e2e063 100644
25771 +--- a/drivers/net/wireless/ath/ath11k/debugfs.h
25772 ++++ b/drivers/net/wireless/ath/ath11k/debugfs.h
25773 +@@ -269,7 +269,7 @@ int ath11k_debugfs_pdev_create(struct ath11k_base *ab);
25774 + void ath11k_debugfs_pdev_destroy(struct ath11k_base *ab);
25775 + int ath11k_debugfs_register(struct ath11k *ar);
25776 + void ath11k_debugfs_unregister(struct ath11k *ar);
25777 +-void ath11k_debugfs_fw_stats_process(struct ath11k_base *ab, struct sk_buff *skb);
25778 ++void ath11k_debugfs_fw_stats_process(struct ath11k *ar, struct ath11k_fw_stats *stats);
25779 +
25780 + void ath11k_debugfs_fw_stats_init(struct ath11k *ar);
25781 + int ath11k_debugfs_get_fw_stats(struct ath11k *ar, u32 pdev_id,
25782 +@@ -341,8 +341,8 @@ static inline void ath11k_debugfs_unregister(struct ath11k *ar)
25783 + {
25784 + }
25785 +
25786 +-static inline void ath11k_debugfs_fw_stats_process(struct ath11k_base *ab,
25787 +- struct sk_buff *skb)
25788 ++static inline void ath11k_debugfs_fw_stats_process(struct ath11k *ar,
25789 ++ struct ath11k_fw_stats *stats)
25790 + {
25791 + }
25792 +
25793 +diff --git a/drivers/net/wireless/ath/ath11k/mac.c b/drivers/net/wireless/ath/ath11k/mac.c
25794 +index 7f6521314b2d4..475ed20b495d0 100644
25795 +--- a/drivers/net/wireless/ath/ath11k/mac.c
25796 ++++ b/drivers/net/wireless/ath/ath11k/mac.c
25797 +@@ -4209,10 +4209,11 @@ static void ath11k_sta_rc_update_wk(struct work_struct *wk)
25798 + const u8 *ht_mcs_mask;
25799 + const u16 *vht_mcs_mask;
25800 + const u16 *he_mcs_mask;
25801 +- u32 changed, bw, nss, smps;
25802 ++ u32 changed, bw, nss, smps, bw_prev;
25803 + int err, num_vht_rates, num_he_rates;
25804 + const struct cfg80211_bitrate_mask *mask;
25805 + struct peer_assoc_params peer_arg;
25806 ++ enum wmi_phy_mode peer_phymode;
25807 +
25808 + arsta = container_of(wk, struct ath11k_sta, update_wk);
25809 + sta = container_of((void *)arsta, struct ieee80211_sta, drv_priv);
25810 +@@ -4233,6 +4234,7 @@ static void ath11k_sta_rc_update_wk(struct work_struct *wk)
25811 + arsta->changed = 0;
25812 +
25813 + bw = arsta->bw;
25814 ++ bw_prev = arsta->bw_prev;
25815 + nss = arsta->nss;
25816 + smps = arsta->smps;
25817 +
25818 +@@ -4246,26 +4248,57 @@ static void ath11k_sta_rc_update_wk(struct work_struct *wk)
25819 + ath11k_mac_max_he_nss(he_mcs_mask)));
25820 +
25821 + if (changed & IEEE80211_RC_BW_CHANGED) {
25822 +- /* Send peer assoc command before set peer bandwidth param to
25823 +- * avoid the mismatch between the peer phymode and the peer
25824 +- * bandwidth.
25825 +- */
25826 +- ath11k_peer_assoc_prepare(ar, arvif->vif, sta, &peer_arg, true);
25827 +-
25828 +- peer_arg.is_assoc = false;
25829 +- err = ath11k_wmi_send_peer_assoc_cmd(ar, &peer_arg);
25830 +- if (err) {
25831 +- ath11k_warn(ar->ab, "failed to send peer assoc for STA %pM vdev %i: %d\n",
25832 +- sta->addr, arvif->vdev_id, err);
25833 +- } else if (wait_for_completion_timeout(&ar->peer_assoc_done, 1 * HZ)) {
25834 ++ /* Get the peer phymode */
25835 ++ ath11k_peer_assoc_h_phymode(ar, arvif->vif, sta, &peer_arg);
25836 ++ peer_phymode = peer_arg.peer_phymode;
25837 ++
25838 ++ ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "mac update sta %pM peer bw %d phymode %d\n",
25839 ++ sta->addr, bw, peer_phymode);
25840 ++
25841 ++ if (bw > bw_prev) {
25842 ++ /* BW is upgraded. In this case we send WMI_PEER_PHYMODE
25843 ++ * followed by WMI_PEER_CHWIDTH
25844 ++ */
25845 ++ ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "mac BW upgrade for sta %pM new BW %d, old BW %d\n",
25846 ++ sta->addr, bw, bw_prev);
25847 ++
25848 ++ err = ath11k_wmi_set_peer_param(ar, sta->addr, arvif->vdev_id,
25849 ++ WMI_PEER_PHYMODE, peer_phymode);
25850 ++
25851 ++ if (err) {
25852 ++ ath11k_warn(ar->ab, "failed to update STA %pM peer phymode %d: %d\n",
25853 ++ sta->addr, peer_phymode, err);
25854 ++ goto err_rc_bw_changed;
25855 ++ }
25856 ++
25857 + err = ath11k_wmi_set_peer_param(ar, sta->addr, arvif->vdev_id,
25858 + WMI_PEER_CHWIDTH, bw);
25859 ++
25860 + if (err)
25861 + ath11k_warn(ar->ab, "failed to update STA %pM peer bw %d: %d\n",
25862 + sta->addr, bw, err);
25863 + } else {
25864 +- ath11k_warn(ar->ab, "failed to get peer assoc conf event for %pM vdev %i\n",
25865 +- sta->addr, arvif->vdev_id);
25866 ++ /* BW is downgraded. In this case we send WMI_PEER_CHWIDTH
25867 ++ * followed by WMI_PEER_PHYMODE
25868 ++ */
25869 ++ ath11k_dbg(ar->ab, ATH11K_DBG_MAC, "mac BW downgrade for sta %pM new BW %d,old BW %d\n",
25870 ++ sta->addr, bw, bw_prev);
25871 ++
25872 ++ err = ath11k_wmi_set_peer_param(ar, sta->addr, arvif->vdev_id,
25873 ++ WMI_PEER_CHWIDTH, bw);
25874 ++
25875 ++ if (err) {
25876 ++ ath11k_warn(ar->ab, "failed to update STA %pM peer bw %d: %d\n",
25877 ++ sta->addr, bw, err);
25878 ++ goto err_rc_bw_changed;
25879 ++ }
25880 ++
25881 ++ err = ath11k_wmi_set_peer_param(ar, sta->addr, arvif->vdev_id,
25882 ++ WMI_PEER_PHYMODE, peer_phymode);
25883 ++
25884 ++ if (err)
25885 ++ ath11k_warn(ar->ab, "failed to update STA %pM peer phymode %d: %d\n",
25886 ++ sta->addr, peer_phymode, err);
25887 + }
25888 + }
25889 +
25890 +@@ -4346,6 +4379,7 @@ static void ath11k_sta_rc_update_wk(struct work_struct *wk)
25891 + }
25892 + }
25893 +
25894 ++err_rc_bw_changed:
25895 + mutex_unlock(&ar->conf_mutex);
25896 + }
25897 +
25898 +@@ -4499,6 +4533,34 @@ exit:
25899 + return ret;
25900 + }
25901 +
25902 ++static u32 ath11k_mac_ieee80211_sta_bw_to_wmi(struct ath11k *ar,
25903 ++ struct ieee80211_sta *sta)
25904 ++{
25905 ++ u32 bw = WMI_PEER_CHWIDTH_20MHZ;
25906 ++
25907 ++ switch (sta->deflink.bandwidth) {
25908 ++ case IEEE80211_STA_RX_BW_20:
25909 ++ bw = WMI_PEER_CHWIDTH_20MHZ;
25910 ++ break;
25911 ++ case IEEE80211_STA_RX_BW_40:
25912 ++ bw = WMI_PEER_CHWIDTH_40MHZ;
25913 ++ break;
25914 ++ case IEEE80211_STA_RX_BW_80:
25915 ++ bw = WMI_PEER_CHWIDTH_80MHZ;
25916 ++ break;
25917 ++ case IEEE80211_STA_RX_BW_160:
25918 ++ bw = WMI_PEER_CHWIDTH_160MHZ;
25919 ++ break;
25920 ++ default:
25921 ++ ath11k_warn(ar->ab, "Invalid bandwidth %d for %pM\n",
25922 ++ sta->deflink.bandwidth, sta->addr);
25923 ++ bw = WMI_PEER_CHWIDTH_20MHZ;
25924 ++ break;
25925 ++ }
25926 ++
25927 ++ return bw;
25928 ++}
25929 ++
25930 + static int ath11k_mac_op_sta_state(struct ieee80211_hw *hw,
25931 + struct ieee80211_vif *vif,
25932 + struct ieee80211_sta *sta,
25933 +@@ -4583,6 +4645,12 @@ static int ath11k_mac_op_sta_state(struct ieee80211_hw *hw,
25934 + if (ret)
25935 + ath11k_warn(ar->ab, "Failed to associate station: %pM\n",
25936 + sta->addr);
25937 ++
25938 ++ spin_lock_bh(&ar->data_lock);
25939 ++ /* Set arsta bw and prev bw */
25940 ++ arsta->bw = ath11k_mac_ieee80211_sta_bw_to_wmi(ar, sta);
25941 ++ arsta->bw_prev = arsta->bw;
25942 ++ spin_unlock_bh(&ar->data_lock);
25943 + } else if (old_state == IEEE80211_STA_ASSOC &&
25944 + new_state == IEEE80211_STA_AUTHORIZED) {
25945 + spin_lock_bh(&ar->ab->base_lock);
25946 +@@ -4706,28 +4774,8 @@ static void ath11k_mac_op_sta_rc_update(struct ieee80211_hw *hw,
25947 + spin_lock_bh(&ar->data_lock);
25948 +
25949 + if (changed & IEEE80211_RC_BW_CHANGED) {
25950 +- bw = WMI_PEER_CHWIDTH_20MHZ;
25951 +-
25952 +- switch (sta->deflink.bandwidth) {
25953 +- case IEEE80211_STA_RX_BW_20:
25954 +- bw = WMI_PEER_CHWIDTH_20MHZ;
25955 +- break;
25956 +- case IEEE80211_STA_RX_BW_40:
25957 +- bw = WMI_PEER_CHWIDTH_40MHZ;
25958 +- break;
25959 +- case IEEE80211_STA_RX_BW_80:
25960 +- bw = WMI_PEER_CHWIDTH_80MHZ;
25961 +- break;
25962 +- case IEEE80211_STA_RX_BW_160:
25963 +- bw = WMI_PEER_CHWIDTH_160MHZ;
25964 +- break;
25965 +- default:
25966 +- ath11k_warn(ar->ab, "Invalid bandwidth %d in rc update for %pM\n",
25967 +- sta->deflink.bandwidth, sta->addr);
25968 +- bw = WMI_PEER_CHWIDTH_20MHZ;
25969 +- break;
25970 +- }
25971 +-
25972 ++ bw = ath11k_mac_ieee80211_sta_bw_to_wmi(ar, sta);
25973 ++ arsta->bw_prev = arsta->bw;
25974 + arsta->bw = bw;
25975 + }
25976 +
25977 +diff --git a/drivers/net/wireless/ath/ath11k/qmi.c b/drivers/net/wireless/ath/ath11k/qmi.c
25978 +index e6ced8597e1d6..539134a6e9d98 100644
25979 +--- a/drivers/net/wireless/ath/ath11k/qmi.c
25980 ++++ b/drivers/net/wireless/ath/ath11k/qmi.c
25981 +@@ -3083,6 +3083,9 @@ static const struct qmi_msg_handler ath11k_qmi_msg_handlers[] = {
25982 + sizeof(struct qmi_wlfw_fw_init_done_ind_msg_v01),
25983 + .fn = ath11k_qmi_msg_fw_init_done_cb,
25984 + },
25985 ++
25986 ++ /* end of list */
25987 ++ {},
25988 + };
25989 +
25990 + static int ath11k_qmi_ops_new_server(struct qmi_handle *qmi_hdl,
25991 +diff --git a/drivers/net/wireless/ath/ath11k/wmi.c b/drivers/net/wireless/ath/ath11k/wmi.c
25992 +index b658ea60dcf7d..ec9b7e954dfc8 100644
25993 +--- a/drivers/net/wireless/ath/ath11k/wmi.c
25994 ++++ b/drivers/net/wireless/ath/ath11k/wmi.c
25995 +@@ -7409,7 +7409,53 @@ static void ath11k_peer_assoc_conf_event(struct ath11k_base *ab, struct sk_buff
25996 +
25997 + static void ath11k_update_stats_event(struct ath11k_base *ab, struct sk_buff *skb)
25998 + {
25999 +- ath11k_debugfs_fw_stats_process(ab, skb);
26000 ++ struct ath11k_fw_stats stats = {};
26001 ++ struct ath11k *ar;
26002 ++ int ret;
26003 ++
26004 ++ INIT_LIST_HEAD(&stats.pdevs);
26005 ++ INIT_LIST_HEAD(&stats.vdevs);
26006 ++ INIT_LIST_HEAD(&stats.bcn);
26007 ++
26008 ++ ret = ath11k_wmi_pull_fw_stats(ab, skb, &stats);
26009 ++ if (ret) {
26010 ++ ath11k_warn(ab, "failed to pull fw stats: %d\n", ret);
26011 ++ goto free;
26012 ++ }
26013 ++
26014 ++ rcu_read_lock();
26015 ++ ar = ath11k_mac_get_ar_by_pdev_id(ab, stats.pdev_id);
26016 ++ if (!ar) {
26017 ++ rcu_read_unlock();
26018 ++ ath11k_warn(ab, "failed to get ar for pdev_id %d: %d\n",
26019 ++ stats.pdev_id, ret);
26020 ++ goto free;
26021 ++ }
26022 ++
26023 ++ spin_lock_bh(&ar->data_lock);
26024 ++
26025 ++ /* WMI_REQUEST_PDEV_STAT can be requested via .get_txpower mac ops or via
26026 ++ * debugfs fw stats. Therefore, processing it separately.
26027 ++ */
26028 ++ if (stats.stats_id == WMI_REQUEST_PDEV_STAT) {
26029 ++ list_splice_tail_init(&stats.pdevs, &ar->fw_stats.pdevs);
26030 ++ ar->fw_stats_done = true;
26031 ++ goto complete;
26032 ++ }
26033 ++
26034 ++ /* WMI_REQUEST_VDEV_STAT, WMI_REQUEST_BCN_STAT and WMI_REQUEST_RSSI_PER_CHAIN_STAT
26035 ++ * are currently requested only via debugfs fw stats. Hence, processing these
26036 ++ * in debugfs context
26037 ++ */
26038 ++ ath11k_debugfs_fw_stats_process(ar, &stats);
26039 ++
26040 ++complete:
26041 ++ complete(&ar->fw_stats_complete);
26042 ++ rcu_read_unlock();
26043 ++ spin_unlock_bh(&ar->data_lock);
26044 ++
26045 ++free:
26046 ++ ath11k_fw_stats_free(&stats);
26047 + }
26048 +
26049 + /* PDEV_CTL_FAILSAFE_CHECK_EVENT is received from FW when the frequency scanned
26050 +diff --git a/drivers/net/wireless/ath/ath9k/hif_usb.c b/drivers/net/wireless/ath/ath9k/hif_usb.c
26051 +index 4d9002a9d082c..1a2e0c7eeb023 100644
26052 +--- a/drivers/net/wireless/ath/ath9k/hif_usb.c
26053 ++++ b/drivers/net/wireless/ath/ath9k/hif_usb.c
26054 +@@ -708,14 +708,13 @@ static void ath9k_hif_usb_reg_in_cb(struct urb *urb)
26055 + struct rx_buf *rx_buf = (struct rx_buf *)urb->context;
26056 + struct hif_device_usb *hif_dev = rx_buf->hif_dev;
26057 + struct sk_buff *skb = rx_buf->skb;
26058 +- struct sk_buff *nskb;
26059 + int ret;
26060 +
26061 + if (!skb)
26062 + return;
26063 +
26064 + if (!hif_dev)
26065 +- goto free;
26066 ++ goto free_skb;
26067 +
26068 + switch (urb->status) {
26069 + case 0:
26070 +@@ -724,7 +723,7 @@ static void ath9k_hif_usb_reg_in_cb(struct urb *urb)
26071 + case -ECONNRESET:
26072 + case -ENODEV:
26073 + case -ESHUTDOWN:
26074 +- goto free;
26075 ++ goto free_skb;
26076 + default:
26077 + skb_reset_tail_pointer(skb);
26078 + skb_trim(skb, 0);
26079 +@@ -735,25 +734,27 @@ static void ath9k_hif_usb_reg_in_cb(struct urb *urb)
26080 + if (likely(urb->actual_length != 0)) {
26081 + skb_put(skb, urb->actual_length);
26082 +
26083 +- /* Process the command first */
26084 ++ /*
26085 ++ * Process the command first.
26086 ++ * skb is either freed here or passed to be
26087 ++ * managed to another callback function.
26088 ++ */
26089 + ath9k_htc_rx_msg(hif_dev->htc_handle, skb,
26090 + skb->len, USB_REG_IN_PIPE);
26091 +
26092 +-
26093 +- nskb = alloc_skb(MAX_REG_IN_BUF_SIZE, GFP_ATOMIC);
26094 +- if (!nskb) {
26095 ++ skb = alloc_skb(MAX_REG_IN_BUF_SIZE, GFP_ATOMIC);
26096 ++ if (!skb) {
26097 + dev_err(&hif_dev->udev->dev,
26098 + "ath9k_htc: REG_IN memory allocation failure\n");
26099 +- urb->context = NULL;
26100 +- return;
26101 ++ goto free_rx_buf;
26102 + }
26103 +
26104 +- rx_buf->skb = nskb;
26105 ++ rx_buf->skb = skb;
26106 +
26107 + usb_fill_int_urb(urb, hif_dev->udev,
26108 + usb_rcvintpipe(hif_dev->udev,
26109 + USB_REG_IN_PIPE),
26110 +- nskb->data, MAX_REG_IN_BUF_SIZE,
26111 ++ skb->data, MAX_REG_IN_BUF_SIZE,
26112 + ath9k_hif_usb_reg_in_cb, rx_buf, 1);
26113 + }
26114 +
26115 +@@ -762,12 +763,13 @@ resubmit:
26116 + ret = usb_submit_urb(urb, GFP_ATOMIC);
26117 + if (ret) {
26118 + usb_unanchor_urb(urb);
26119 +- goto free;
26120 ++ goto free_skb;
26121 + }
26122 +
26123 + return;
26124 +-free:
26125 ++free_skb:
26126 + kfree_skb(skb);
26127 ++free_rx_buf:
26128 + kfree(rx_buf);
26129 + urb->context = NULL;
26130 + }
26131 +@@ -780,14 +782,10 @@ static void ath9k_hif_usb_dealloc_tx_urbs(struct hif_device_usb *hif_dev)
26132 + spin_lock_irqsave(&hif_dev->tx.tx_lock, flags);
26133 + list_for_each_entry_safe(tx_buf, tx_buf_tmp,
26134 + &hif_dev->tx.tx_buf, list) {
26135 +- usb_get_urb(tx_buf->urb);
26136 +- spin_unlock_irqrestore(&hif_dev->tx.tx_lock, flags);
26137 +- usb_kill_urb(tx_buf->urb);
26138 + list_del(&tx_buf->list);
26139 + usb_free_urb(tx_buf->urb);
26140 + kfree(tx_buf->buf);
26141 + kfree(tx_buf);
26142 +- spin_lock_irqsave(&hif_dev->tx.tx_lock, flags);
26143 + }
26144 + spin_unlock_irqrestore(&hif_dev->tx.tx_lock, flags);
26145 +
26146 +@@ -1329,10 +1327,24 @@ static int send_eject_command(struct usb_interface *interface)
26147 + static int ath9k_hif_usb_probe(struct usb_interface *interface,
26148 + const struct usb_device_id *id)
26149 + {
26150 ++ struct usb_endpoint_descriptor *bulk_in, *bulk_out, *int_in, *int_out;
26151 + struct usb_device *udev = interface_to_usbdev(interface);
26152 ++ struct usb_host_interface *alt;
26153 + struct hif_device_usb *hif_dev;
26154 + int ret = 0;
26155 +
26156 ++ /* Verify the expected endpoints are present */
26157 ++ alt = interface->cur_altsetting;
26158 ++ if (usb_find_common_endpoints(alt, &bulk_in, &bulk_out, &int_in, &int_out) < 0 ||
26159 ++ usb_endpoint_num(bulk_in) != USB_WLAN_RX_PIPE ||
26160 ++ usb_endpoint_num(bulk_out) != USB_WLAN_TX_PIPE ||
26161 ++ usb_endpoint_num(int_in) != USB_REG_IN_PIPE ||
26162 ++ usb_endpoint_num(int_out) != USB_REG_OUT_PIPE) {
26163 ++ dev_err(&udev->dev,
26164 ++ "ath9k_htc: Device endpoint numbers are not the expected ones\n");
26165 ++ return -ENODEV;
26166 ++ }
26167 ++
26168 + if (id->driver_info == STORAGE_DEVICE)
26169 + return send_eject_command(interface);
26170 +
26171 +diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/firmware.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/firmware.c
26172 +index b8379e4034a4c..55d538978e9c1 100644
26173 +--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/firmware.c
26174 ++++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/firmware.c
26175 +@@ -737,6 +737,11 @@ brcmf_fw_alloc_request(u32 chip, u32 chiprev,
26176 + u32 i, j;
26177 + char end = '\0';
26178 +
26179 ++ if (chiprev >= BITS_PER_TYPE(u32)) {
26180 ++ brcmf_err("Invalid chip revision %u\n", chiprev);
26181 ++ return NULL;
26182 ++ }
26183 ++
26184 + for (i = 0; i < table_size; i++) {
26185 + if (mapping_table[i].chipid == chip &&
26186 + mapping_table[i].revmask & BIT(chiprev))
26187 +diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c
26188 +index 97f0f13dfe505..5b1813c024113 100644
26189 +--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c
26190 ++++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c
26191 +@@ -626,7 +626,7 @@ static int brcmf_pcie_exit_download_state(struct brcmf_pciedev_info *devinfo,
26192 + }
26193 +
26194 + if (!brcmf_chip_set_active(devinfo->ci, resetintr))
26195 +- return -EINVAL;
26196 ++ return -EIO;
26197 + return 0;
26198 + }
26199 +
26200 +@@ -1120,6 +1120,10 @@ static int brcmf_pcie_init_ringbuffers(struct brcmf_pciedev_info *devinfo)
26201 + BRCMF_NROF_H2D_COMMON_MSGRINGS;
26202 + max_completionrings = BRCMF_NROF_D2H_COMMON_MSGRINGS;
26203 + }
26204 ++ if (max_flowrings > 256) {
26205 ++ brcmf_err(bus, "invalid max_flowrings(%d)\n", max_flowrings);
26206 ++ return -EIO;
26207 ++ }
26208 +
26209 + if (devinfo->dma_idx_sz != 0) {
26210 + bufsz = (max_submissionrings + max_completionrings) *
26211 +diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.c
26212 +index 8968809399c7a..2e4cd8096f037 100644
26213 +--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.c
26214 ++++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.c
26215 +@@ -3412,6 +3412,7 @@ static int brcmf_sdio_download_firmware(struct brcmf_sdio *bus,
26216 + /* Take arm out of reset */
26217 + if (!brcmf_chip_set_active(bus->ci, rstvec)) {
26218 + brcmf_err("error getting out of ARM core reset\n");
26219 ++ bcmerror = -EIO;
26220 + goto err;
26221 + }
26222 +
26223 +diff --git a/drivers/net/wireless/intel/iwlwifi/mei/iwl-mei.h b/drivers/net/wireless/intel/iwlwifi/mei/iwl-mei.h
26224 +index 67122cfa22920..5409699c9a1fd 100644
26225 +--- a/drivers/net/wireless/intel/iwlwifi/mei/iwl-mei.h
26226 ++++ b/drivers/net/wireless/intel/iwlwifi/mei/iwl-mei.h
26227 +@@ -446,9 +446,10 @@ void iwl_mei_host_associated(const struct iwl_mei_conn_info *conn_info,
26228 + void iwl_mei_host_disassociated(void);
26229 +
26230 + /**
26231 +- * iwl_mei_device_down() - must be called when the device is down
26232 ++ * iwl_mei_device_state() - must be called when the device changes up/down state
26233 ++ * @up: true if the device is up, false otherwise.
26234 + */
26235 +-void iwl_mei_device_down(void);
26236 ++void iwl_mei_device_state(bool up);
26237 +
26238 + #else
26239 +
26240 +@@ -497,7 +498,7 @@ static inline void iwl_mei_host_associated(const struct iwl_mei_conn_info *conn_
26241 + static inline void iwl_mei_host_disassociated(void)
26242 + {}
26243 +
26244 +-static inline void iwl_mei_device_down(void)
26245 ++static inline void iwl_mei_device_state(bool up)
26246 + {}
26247 +
26248 + #endif /* CONFIG_IWLMEI */
26249 +diff --git a/drivers/net/wireless/intel/iwlwifi/mei/main.c b/drivers/net/wireless/intel/iwlwifi/mei/main.c
26250 +index 357f14626cf43..c0142093c7682 100644
26251 +--- a/drivers/net/wireless/intel/iwlwifi/mei/main.c
26252 ++++ b/drivers/net/wireless/intel/iwlwifi/mei/main.c
26253 +@@ -147,9 +147,13 @@ struct iwl_mei_filters {
26254 + * to send CSME_OWNERSHIP_CONFIRMED when the driver completes its down
26255 + * flow.
26256 + * @link_prot_state: true when we are in link protection PASSIVE
26257 ++ * @device_down: true if the device is down. Used to remember to send
26258 ++ * CSME_OWNERSHIP_CONFIRMED when the driver is already down.
26259 + * @csa_throttle_end_wk: used when &csa_throttled is true
26260 + * @data_q_lock: protects the access to the data queues which are
26261 + * accessed without the mutex.
26262 ++ * @netdev_work: used to defer registering and unregistering of the netdev to
26263 ++ * avoid taking the rtnl lock in the SAP messages handlers.
26264 + * @sap_seq_no: the sequence number for the SAP messages
26265 + * @seq_no: the sequence number for the SAP messages
26266 + * @dbgfs_dir: the debugfs dir entry
26267 +@@ -167,8 +171,10 @@ struct iwl_mei {
26268 + bool csa_throttled;
26269 + bool csme_taking_ownership;
26270 + bool link_prot_state;
26271 ++ bool device_down;
26272 + struct delayed_work csa_throttle_end_wk;
26273 + spinlock_t data_q_lock;
26274 ++ struct work_struct netdev_work;
26275 +
26276 + atomic_t sap_seq_no;
26277 + atomic_t seq_no;
26278 +@@ -588,13 +594,38 @@ static rx_handler_result_t iwl_mei_rx_handler(struct sk_buff **pskb)
26279 + return res;
26280 + }
26281 +
26282 ++static void iwl_mei_netdev_work(struct work_struct *wk)
26283 ++{
26284 ++ struct iwl_mei *mei =
26285 ++ container_of(wk, struct iwl_mei, netdev_work);
26286 ++ struct net_device *netdev;
26287 ++
26288 ++ /*
26289 ++ * First take rtnl and only then the mutex to avoid an ABBA
26290 ++ * with iwl_mei_set_netdev()
26291 ++ */
26292 ++ rtnl_lock();
26293 ++ mutex_lock(&iwl_mei_mutex);
26294 ++
26295 ++ netdev = rcu_dereference_protected(iwl_mei_cache.netdev,
26296 ++ lockdep_is_held(&iwl_mei_mutex));
26297 ++ if (netdev) {
26298 ++ if (mei->amt_enabled)
26299 ++ netdev_rx_handler_register(netdev, iwl_mei_rx_handler,
26300 ++ mei);
26301 ++ else
26302 ++ netdev_rx_handler_unregister(netdev);
26303 ++ }
26304 ++
26305 ++ mutex_unlock(&iwl_mei_mutex);
26306 ++ rtnl_unlock();
26307 ++}
26308 ++
26309 + static void
26310 + iwl_mei_handle_rx_start_ok(struct mei_cl_device *cldev,
26311 + const struct iwl_sap_me_msg_start_ok *rsp,
26312 + ssize_t len)
26313 + {
26314 +- struct iwl_mei *mei = mei_cldev_get_drvdata(cldev);
26315 +-
26316 + if (len != sizeof(*rsp)) {
26317 + dev_err(&cldev->dev,
26318 + "got invalid SAP_ME_MSG_START_OK from CSME firmware\n");
26319 +@@ -613,13 +644,10 @@ iwl_mei_handle_rx_start_ok(struct mei_cl_device *cldev,
26320 +
26321 + mutex_lock(&iwl_mei_mutex);
26322 + set_bit(IWL_MEI_STATUS_SAP_CONNECTED, &iwl_mei_status);
26323 +- /* wifi driver has registered already */
26324 +- if (iwl_mei_cache.ops) {
26325 +- iwl_mei_send_sap_msg(mei->cldev,
26326 +- SAP_MSG_NOTIF_WIFIDR_UP);
26327 +- iwl_mei_cache.ops->sap_connected(iwl_mei_cache.priv);
26328 +- }
26329 +-
26330 ++ /*
26331 ++ * We'll receive AMT_STATE SAP message in a bit and
26332 ++ * that will continue the flow
26333 ++ */
26334 + mutex_unlock(&iwl_mei_mutex);
26335 + }
26336 +
26337 +@@ -712,6 +740,13 @@ static void iwl_mei_set_init_conf(struct iwl_mei *mei)
26338 + .val = cpu_to_le32(iwl_mei_cache.rf_kill),
26339 + };
26340 +
26341 ++ /* wifi driver has registered already */
26342 ++ if (iwl_mei_cache.ops) {
26343 ++ iwl_mei_send_sap_msg(mei->cldev,
26344 ++ SAP_MSG_NOTIF_WIFIDR_UP);
26345 ++ iwl_mei_cache.ops->sap_connected(iwl_mei_cache.priv);
26346 ++ }
26347 ++
26348 + iwl_mei_send_sap_msg(mei->cldev, SAP_MSG_NOTIF_WHO_OWNS_NIC);
26349 +
26350 + if (iwl_mei_cache.conn_info) {
26351 +@@ -738,38 +773,23 @@ static void iwl_mei_handle_amt_state(struct mei_cl_device *cldev,
26352 + const struct iwl_sap_msg_dw *dw)
26353 + {
26354 + struct iwl_mei *mei = mei_cldev_get_drvdata(cldev);
26355 +- struct net_device *netdev;
26356 +
26357 +- /*
26358 +- * First take rtnl and only then the mutex to avoid an ABBA
26359 +- * with iwl_mei_set_netdev()
26360 +- */
26361 +- rtnl_lock();
26362 + mutex_lock(&iwl_mei_mutex);
26363 +
26364 +- netdev = rcu_dereference_protected(iwl_mei_cache.netdev,
26365 +- lockdep_is_held(&iwl_mei_mutex));
26366 +-
26367 + if (mei->amt_enabled == !!le32_to_cpu(dw->val))
26368 + goto out;
26369 +
26370 + mei->amt_enabled = dw->val;
26371 +
26372 +- if (mei->amt_enabled) {
26373 +- if (netdev)
26374 +- netdev_rx_handler_register(netdev, iwl_mei_rx_handler, mei);
26375 +-
26376 ++ if (mei->amt_enabled)
26377 + iwl_mei_set_init_conf(mei);
26378 +- } else {
26379 +- if (iwl_mei_cache.ops)
26380 +- iwl_mei_cache.ops->rfkill(iwl_mei_cache.priv, false);
26381 +- if (netdev)
26382 +- netdev_rx_handler_unregister(netdev);
26383 +- }
26384 ++ else if (iwl_mei_cache.ops)
26385 ++ iwl_mei_cache.ops->rfkill(iwl_mei_cache.priv, false, false);
26386 ++
26387 ++ schedule_work(&mei->netdev_work);
26388 +
26389 + out:
26390 + mutex_unlock(&iwl_mei_mutex);
26391 +- rtnl_unlock();
26392 + }
26393 +
26394 + static void iwl_mei_handle_nic_owner(struct mei_cl_device *cldev,
26395 +@@ -798,14 +818,18 @@ static void iwl_mei_handle_csme_taking_ownership(struct mei_cl_device *cldev,
26396 +
26397 + mei->got_ownership = false;
26398 +
26399 +- /*
26400 +- * Remember to send CSME_OWNERSHIP_CONFIRMED when the wifi driver
26401 +- * is finished taking the device down.
26402 +- */
26403 +- mei->csme_taking_ownership = true;
26404 ++ if (iwl_mei_cache.ops && !mei->device_down) {
26405 ++ /*
26406 ++ * Remember to send CSME_OWNERSHIP_CONFIRMED when the wifi
26407 ++ * driver is finished taking the device down.
26408 ++ */
26409 ++ mei->csme_taking_ownership = true;
26410 +
26411 +- if (iwl_mei_cache.ops)
26412 +- iwl_mei_cache.ops->rfkill(iwl_mei_cache.priv, true);
26413 ++ iwl_mei_cache.ops->rfkill(iwl_mei_cache.priv, true, true);
26414 ++ } else {
26415 ++ iwl_mei_send_sap_msg(cldev,
26416 ++ SAP_MSG_NOTIF_CSME_OWNERSHIP_CONFIRMED);
26417 ++ }
26418 + }
26419 +
26420 + static void iwl_mei_handle_nvm(struct mei_cl_device *cldev,
26421 +@@ -1413,10 +1437,7 @@ void iwl_mei_host_associated(const struct iwl_mei_conn_info *conn_info,
26422 +
26423 + mei = mei_cldev_get_drvdata(iwl_mei_global_cldev);
26424 +
26425 +- if (!mei)
26426 +- goto out;
26427 +-
26428 +- if (!mei->amt_enabled)
26429 ++ if (!mei && !mei->amt_enabled)
26430 + goto out;
26431 +
26432 + iwl_mei_send_sap_msg_payload(mei->cldev, &msg.hdr);
26433 +@@ -1445,7 +1466,7 @@ void iwl_mei_host_disassociated(void)
26434 +
26435 + mei = mei_cldev_get_drvdata(iwl_mei_global_cldev);
26436 +
26437 +- if (!mei)
26438 ++ if (!mei && !mei->amt_enabled)
26439 + goto out;
26440 +
26441 + iwl_mei_send_sap_msg_payload(mei->cldev, &msg.hdr);
26442 +@@ -1481,7 +1502,7 @@ void iwl_mei_set_rfkill_state(bool hw_rfkill, bool sw_rfkill)
26443 +
26444 + mei = mei_cldev_get_drvdata(iwl_mei_global_cldev);
26445 +
26446 +- if (!mei)
26447 ++ if (!mei && !mei->amt_enabled)
26448 + goto out;
26449 +
26450 + iwl_mei_send_sap_msg_payload(mei->cldev, &msg.hdr);
26451 +@@ -1510,7 +1531,7 @@ void iwl_mei_set_nic_info(const u8 *mac_address, const u8 *nvm_address)
26452 +
26453 + mei = mei_cldev_get_drvdata(iwl_mei_global_cldev);
26454 +
26455 +- if (!mei)
26456 ++ if (!mei && !mei->amt_enabled)
26457 + goto out;
26458 +
26459 + iwl_mei_send_sap_msg_payload(mei->cldev, &msg.hdr);
26460 +@@ -1538,7 +1559,7 @@ void iwl_mei_set_country_code(u16 mcc)
26461 +
26462 + mei = mei_cldev_get_drvdata(iwl_mei_global_cldev);
26463 +
26464 +- if (!mei)
26465 ++ if (!mei && !mei->amt_enabled)
26466 + goto out;
26467 +
26468 + iwl_mei_send_sap_msg_payload(mei->cldev, &msg.hdr);
26469 +@@ -1564,7 +1585,7 @@ void iwl_mei_set_power_limit(const __le16 *power_limit)
26470 +
26471 + mei = mei_cldev_get_drvdata(iwl_mei_global_cldev);
26472 +
26473 +- if (!mei)
26474 ++ if (!mei && !mei->amt_enabled)
26475 + goto out;
26476 +
26477 + memcpy(msg.sar_chain_info_table, power_limit, sizeof(msg.sar_chain_info_table));
26478 +@@ -1616,7 +1637,7 @@ out:
26479 + }
26480 + EXPORT_SYMBOL_GPL(iwl_mei_set_netdev);
26481 +
26482 +-void iwl_mei_device_down(void)
26483 ++void iwl_mei_device_state(bool up)
26484 + {
26485 + struct iwl_mei *mei;
26486 +
26487 +@@ -1630,7 +1651,9 @@ void iwl_mei_device_down(void)
26488 + if (!mei)
26489 + goto out;
26490 +
26491 +- if (!mei->csme_taking_ownership)
26492 ++ mei->device_down = !up;
26493 ++
26494 ++ if (up || !mei->csme_taking_ownership)
26495 + goto out;
26496 +
26497 + iwl_mei_send_sap_msg(mei->cldev,
26498 +@@ -1639,7 +1662,7 @@ void iwl_mei_device_down(void)
26499 + out:
26500 + mutex_unlock(&iwl_mei_mutex);
26501 + }
26502 +-EXPORT_SYMBOL_GPL(iwl_mei_device_down);
26503 ++EXPORT_SYMBOL_GPL(iwl_mei_device_state);
26504 +
26505 + int iwl_mei_register(void *priv, const struct iwl_mei_ops *ops)
26506 + {
26507 +@@ -1669,9 +1692,10 @@ int iwl_mei_register(void *priv, const struct iwl_mei_ops *ops)
26508 +
26509 + /* we have already a SAP connection */
26510 + if (iwl_mei_is_connected()) {
26511 +- iwl_mei_send_sap_msg(mei->cldev,
26512 +- SAP_MSG_NOTIF_WIFIDR_UP);
26513 +- ops->rfkill(priv, mei->link_prot_state);
26514 ++ if (mei->amt_enabled)
26515 ++ iwl_mei_send_sap_msg(mei->cldev,
26516 ++ SAP_MSG_NOTIF_WIFIDR_UP);
26517 ++ ops->rfkill(priv, mei->link_prot_state, false);
26518 + }
26519 + }
26520 + ret = 0;
26521 +@@ -1818,9 +1842,11 @@ static int iwl_mei_probe(struct mei_cl_device *cldev,
26522 + iwl_mei_csa_throttle_end_wk);
26523 + init_waitqueue_head(&mei->get_ownership_wq);
26524 + spin_lock_init(&mei->data_q_lock);
26525 ++ INIT_WORK(&mei->netdev_work, iwl_mei_netdev_work);
26526 +
26527 + mei_cldev_set_drvdata(cldev, mei);
26528 + mei->cldev = cldev;
26529 ++ mei->device_down = true;
26530 +
26531 + do {
26532 + ret = iwl_mei_alloc_shared_mem(cldev);
26533 +@@ -1921,29 +1947,32 @@ static void iwl_mei_remove(struct mei_cl_device *cldev)
26534 +
26535 + mutex_lock(&iwl_mei_mutex);
26536 +
26537 +- /*
26538 +- * Tell CSME that we are going down so that it won't access the
26539 +- * memory anymore, make sure this message goes through immediately.
26540 +- */
26541 +- mei->csa_throttled = false;
26542 +- iwl_mei_send_sap_msg(mei->cldev,
26543 +- SAP_MSG_NOTIF_HOST_GOES_DOWN);
26544 ++ if (mei->amt_enabled) {
26545 ++ /*
26546 ++ * Tell CSME that we are going down so that it won't access the
26547 ++ * memory anymore, make sure this message goes through immediately.
26548 ++ */
26549 ++ mei->csa_throttled = false;
26550 ++ iwl_mei_send_sap_msg(mei->cldev,
26551 ++ SAP_MSG_NOTIF_HOST_GOES_DOWN);
26552 +
26553 +- for (i = 0; i < SEND_SAP_MAX_WAIT_ITERATION; i++) {
26554 +- if (!iwl_mei_host_to_me_data_pending(mei))
26555 +- break;
26556 ++ for (i = 0; i < SEND_SAP_MAX_WAIT_ITERATION; i++) {
26557 ++ if (!iwl_mei_host_to_me_data_pending(mei))
26558 ++ break;
26559 +
26560 +- msleep(5);
26561 +- }
26562 ++ msleep(20);
26563 ++ }
26564 +
26565 +- /*
26566 +- * If we couldn't make sure that CSME saw the HOST_GOES_DOWN message,
26567 +- * it means that it will probably keep reading memory that we are going
26568 +- * to unmap and free, expect IOMMU error messages.
26569 +- */
26570 +- if (i == SEND_SAP_MAX_WAIT_ITERATION)
26571 +- dev_err(&mei->cldev->dev,
26572 +- "Couldn't get ACK from CSME on HOST_GOES_DOWN message\n");
26573 ++ /*
26574 ++ * If we couldn't make sure that CSME saw the HOST_GOES_DOWN
26575 ++ * message, it means that it will probably keep reading memory
26576 ++ * that we are going to unmap and free, expect IOMMU error
26577 ++ * messages.
26578 ++ */
26579 ++ if (i == SEND_SAP_MAX_WAIT_ITERATION)
26580 ++ dev_err(&mei->cldev->dev,
26581 ++ "Couldn't get ACK from CSME on HOST_GOES_DOWN message\n");
26582 ++ }
26583 +
26584 + mutex_unlock(&iwl_mei_mutex);
26585 +
26586 +@@ -1976,6 +2005,7 @@ static void iwl_mei_remove(struct mei_cl_device *cldev)
26587 + */
26588 + cancel_work_sync(&mei->send_csa_msg_wk);
26589 + cancel_delayed_work_sync(&mei->csa_throttle_end_wk);
26590 ++ cancel_work_sync(&mei->netdev_work);
26591 +
26592 + /*
26593 + * If someone waits for the ownership, let him know that we are going
26594 +diff --git a/drivers/net/wireless/intel/iwlwifi/mei/net.c b/drivers/net/wireless/intel/iwlwifi/mei/net.c
26595 +index 3472167c83707..eac46d1a397a8 100644
26596 +--- a/drivers/net/wireless/intel/iwlwifi/mei/net.c
26597 ++++ b/drivers/net/wireless/intel/iwlwifi/mei/net.c
26598 +@@ -1,6 +1,6 @@
26599 + // SPDX-License-Identifier: GPL-2.0-only
26600 + /*
26601 +- * Copyright (C) 2021 Intel Corporation
26602 ++ * Copyright (C) 2021-2022 Intel Corporation
26603 + */
26604 +
26605 + #include <uapi/linux/if_ether.h>
26606 +@@ -337,10 +337,14 @@ rx_handler_result_t iwl_mei_rx_filter(struct sk_buff *orig_skb,
26607 + if (!*pass_to_csme)
26608 + return RX_HANDLER_PASS;
26609 +
26610 +- if (ret == RX_HANDLER_PASS)
26611 ++ if (ret == RX_HANDLER_PASS) {
26612 + skb = skb_copy(orig_skb, GFP_ATOMIC);
26613 +- else
26614 ++
26615 ++ if (!skb)
26616 ++ return RX_HANDLER_PASS;
26617 ++ } else {
26618 + skb = orig_skb;
26619 ++ }
26620 +
26621 + /* CSME wants the MAC header as well, push it back */
26622 + skb_push(skb, skb->data - skb_mac_header(skb));
26623 +diff --git a/drivers/net/wireless/intel/iwlwifi/mvm/fw.c b/drivers/net/wireless/intel/iwlwifi/mvm/fw.c
26624 +index f041e77af059e..5de34edc51fe9 100644
26625 +--- a/drivers/net/wireless/intel/iwlwifi/mvm/fw.c
26626 ++++ b/drivers/net/wireless/intel/iwlwifi/mvm/fw.c
26627 +@@ -1665,6 +1665,8 @@ int iwl_mvm_up(struct iwl_mvm *mvm)
26628 + iwl_rfi_send_config_cmd(mvm, NULL);
26629 + }
26630 +
26631 ++ iwl_mvm_mei_device_state(mvm, true);
26632 ++
26633 + IWL_DEBUG_INFO(mvm, "RT uCode started.\n");
26634 + return 0;
26635 + error:
26636 +diff --git a/drivers/net/wireless/intel/iwlwifi/mvm/mvm.h b/drivers/net/wireless/intel/iwlwifi/mvm/mvm.h
26637 +index bf35e130c8765..cc71049bd9b39 100644
26638 +--- a/drivers/net/wireless/intel/iwlwifi/mvm/mvm.h
26639 ++++ b/drivers/net/wireless/intel/iwlwifi/mvm/mvm.h
26640 +@@ -2201,10 +2201,10 @@ static inline void iwl_mvm_mei_host_disassociated(struct iwl_mvm *mvm)
26641 + iwl_mei_host_disassociated();
26642 + }
26643 +
26644 +-static inline void iwl_mvm_mei_device_down(struct iwl_mvm *mvm)
26645 ++static inline void iwl_mvm_mei_device_state(struct iwl_mvm *mvm, bool up)
26646 + {
26647 + if (mvm->mei_registered)
26648 +- iwl_mei_device_down();
26649 ++ iwl_mei_device_state(up);
26650 + }
26651 +
26652 + static inline void iwl_mvm_mei_set_sw_rfkill_state(struct iwl_mvm *mvm)
26653 +diff --git a/drivers/net/wireless/intel/iwlwifi/mvm/ops.c b/drivers/net/wireless/intel/iwlwifi/mvm/ops.c
26654 +index db43c8a83a319..3fec87fb6b7b6 100644
26655 +--- a/drivers/net/wireless/intel/iwlwifi/mvm/ops.c
26656 ++++ b/drivers/net/wireless/intel/iwlwifi/mvm/ops.c
26657 +@@ -1370,7 +1370,7 @@ void iwl_mvm_stop_device(struct iwl_mvm *mvm)
26658 + iwl_trans_stop_device(mvm->trans);
26659 + iwl_free_fw_paging(&mvm->fwrt);
26660 + iwl_fw_dump_conf_clear(&mvm->fwrt);
26661 +- iwl_mvm_mei_device_down(mvm);
26662 ++ iwl_mvm_mei_device_state(mvm, false);
26663 + }
26664 +
26665 + static void iwl_op_mode_mvm_stop(struct iwl_op_mode *op_mode)
26666 +diff --git a/drivers/net/wireless/intel/iwlwifi/mvm/tx.c b/drivers/net/wireless/intel/iwlwifi/mvm/tx.c
26667 +index f9e08b339e0c4..0dd35344e64a8 100644
26668 +--- a/drivers/net/wireless/intel/iwlwifi/mvm/tx.c
26669 ++++ b/drivers/net/wireless/intel/iwlwifi/mvm/tx.c
26670 +@@ -1171,9 +1171,15 @@ static int iwl_mvm_tx_mpdu(struct iwl_mvm *mvm, struct sk_buff *skb,
26671 + /* From now on, we cannot access info->control */
26672 + iwl_mvm_skb_prepare_status(skb, dev_cmd);
26673 +
26674 ++ /*
26675 ++ * The IV is introduced by the HW for new tx api, and it is not present
26676 ++ * in the skb, hence, don't tell iwl_mvm_mei_tx_copy_to_csme about the
26677 ++ * IV for those devices.
26678 ++ */
26679 + if (ieee80211_is_data(fc))
26680 + iwl_mvm_mei_tx_copy_to_csme(mvm, skb,
26681 +- info->control.hw_key ?
26682 ++ info->control.hw_key &&
26683 ++ !iwl_mvm_has_new_tx_api(mvm) ?
26684 + info->control.hw_key->iv_len : 0);
26685 +
26686 + if (iwl_trans_tx(mvm->trans, skb, dev_cmd, txq_id))
26687 +@@ -1206,6 +1212,7 @@ int iwl_mvm_tx_skb_sta(struct iwl_mvm *mvm, struct sk_buff *skb,
26688 + struct sk_buff_head mpdus_skbs;
26689 + unsigned int payload_len;
26690 + int ret;
26691 ++ struct sk_buff *orig_skb = skb;
26692 +
26693 + if (WARN_ON_ONCE(!mvmsta))
26694 + return -1;
26695 +@@ -1238,8 +1245,17 @@ int iwl_mvm_tx_skb_sta(struct iwl_mvm *mvm, struct sk_buff *skb,
26696 +
26697 + ret = iwl_mvm_tx_mpdu(mvm, skb, &info, sta);
26698 + if (ret) {
26699 ++ /* Free skbs created as part of TSO logic that have not yet been dequeued */
26700 + __skb_queue_purge(&mpdus_skbs);
26701 +- return ret;
26702 ++ /* skb here is not necessarily same as skb that entered this method,
26703 ++ * so free it explicitly.
26704 ++ */
26705 ++ if (skb == orig_skb)
26706 ++ ieee80211_free_txskb(mvm->hw, skb);
26707 ++ else
26708 ++ kfree_skb(skb);
26709 ++ /* there was error, but we consumed skb one way or another, so return 0 */
26710 ++ return 0;
26711 + }
26712 + }
26713 +
26714 +diff --git a/drivers/net/wireless/mediatek/mt76/mt76.h b/drivers/net/wireless/mediatek/mt76/mt76.h
26715 +index 4da77d47b0a67..1f8da524a3056 100644
26716 +--- a/drivers/net/wireless/mediatek/mt76/mt76.h
26717 ++++ b/drivers/net/wireless/mediatek/mt76/mt76.h
26718 +@@ -1101,8 +1101,9 @@ static inline bool mt76_is_skb_pktid(u8 pktid)
26719 + static inline u8 mt76_tx_power_nss_delta(u8 nss)
26720 + {
26721 + static const u8 nss_delta[4] = { 0, 6, 9, 12 };
26722 ++ u8 idx = nss - 1;
26723 +
26724 +- return nss_delta[nss - 1];
26725 ++ return (idx < ARRAY_SIZE(nss_delta)) ? nss_delta[idx] : 0;
26726 + }
26727 +
26728 + static inline bool mt76_testmode_enabled(struct mt76_phy *phy)
26729 +diff --git a/drivers/net/wireless/mediatek/mt76/mt7915/eeprom.c b/drivers/net/wireless/mediatek/mt76/mt7915/eeprom.c
26730 +index 4b1a9811646fd..0bce0ce51be00 100644
26731 +--- a/drivers/net/wireless/mediatek/mt76/mt7915/eeprom.c
26732 ++++ b/drivers/net/wireless/mediatek/mt76/mt7915/eeprom.c
26733 +@@ -173,60 +173,50 @@ static void mt7915_eeprom_parse_band_config(struct mt7915_phy *phy)
26734 + void mt7915_eeprom_parse_hw_cap(struct mt7915_dev *dev,
26735 + struct mt7915_phy *phy)
26736 + {
26737 +- u8 nss, nss_band, nss_band_max, *eeprom = dev->mt76.eeprom.data;
26738 ++ u8 path, nss, nss_max = 4, *eeprom = dev->mt76.eeprom.data;
26739 + struct mt76_phy *mphy = phy->mt76;
26740 +- bool ext_phy = phy != &dev->phy;
26741 +
26742 + mt7915_eeprom_parse_band_config(phy);
26743 +
26744 +- /* read tx/rx mask from eeprom */
26745 ++ /* read tx/rx path from eeprom */
26746 + if (is_mt7915(&dev->mt76)) {
26747 +- nss = FIELD_GET(MT_EE_WIFI_CONF0_TX_PATH,
26748 +- eeprom[MT_EE_WIFI_CONF]);
26749 ++ path = FIELD_GET(MT_EE_WIFI_CONF0_TX_PATH,
26750 ++ eeprom[MT_EE_WIFI_CONF]);
26751 + } else {
26752 +- nss = FIELD_GET(MT_EE_WIFI_CONF0_TX_PATH,
26753 +- eeprom[MT_EE_WIFI_CONF + phy->band_idx]);
26754 ++ path = FIELD_GET(MT_EE_WIFI_CONF0_TX_PATH,
26755 ++ eeprom[MT_EE_WIFI_CONF + phy->band_idx]);
26756 + }
26757 +
26758 +- if (!nss || nss > 4)
26759 +- nss = 4;
26760 ++ if (!path || path > 4)
26761 ++ path = 4;
26762 +
26763 + /* read tx/rx stream */
26764 +- nss_band = nss;
26765 +-
26766 ++ nss = path;
26767 + if (dev->dbdc_support) {
26768 + if (is_mt7915(&dev->mt76)) {
26769 +- nss_band = FIELD_GET(MT_EE_WIFI_CONF3_TX_PATH_B0,
26770 +- eeprom[MT_EE_WIFI_CONF + 3]);
26771 ++ path = min_t(u8, path, 2);
26772 ++ nss = FIELD_GET(MT_EE_WIFI_CONF3_TX_PATH_B0,
26773 ++ eeprom[MT_EE_WIFI_CONF + 3]);
26774 + if (phy->band_idx)
26775 +- nss_band = FIELD_GET(MT_EE_WIFI_CONF3_TX_PATH_B1,
26776 +- eeprom[MT_EE_WIFI_CONF + 3]);
26777 ++ nss = FIELD_GET(MT_EE_WIFI_CONF3_TX_PATH_B1,
26778 ++ eeprom[MT_EE_WIFI_CONF + 3]);
26779 + } else {
26780 +- nss_band = FIELD_GET(MT_EE_WIFI_CONF_STREAM_NUM,
26781 +- eeprom[MT_EE_WIFI_CONF + 2 + phy->band_idx]);
26782 ++ nss = FIELD_GET(MT_EE_WIFI_CONF_STREAM_NUM,
26783 ++ eeprom[MT_EE_WIFI_CONF + 2 + phy->band_idx]);
26784 + }
26785 +
26786 +- nss_band_max = is_mt7986(&dev->mt76) ?
26787 +- MT_EE_NSS_MAX_DBDC_MA7986 : MT_EE_NSS_MAX_DBDC_MA7915;
26788 +- } else {
26789 +- nss_band_max = is_mt7986(&dev->mt76) ?
26790 +- MT_EE_NSS_MAX_MA7986 : MT_EE_NSS_MAX_MA7915;
26791 ++ if (!is_mt7986(&dev->mt76))
26792 ++ nss_max = 2;
26793 + }
26794 +
26795 +- if (!nss_band || nss_band > nss_band_max)
26796 +- nss_band = nss_band_max;
26797 +-
26798 +- if (nss_band > nss) {
26799 +- dev_warn(dev->mt76.dev,
26800 +- "nss mismatch, nss(%d) nss_band(%d) band(%d) ext_phy(%d)\n",
26801 +- nss, nss_band, phy->band_idx, ext_phy);
26802 +- nss = nss_band;
26803 +- }
26804 ++ if (!nss)
26805 ++ nss = nss_max;
26806 ++ nss = min_t(u8, min_t(u8, nss_max, nss), path);
26807 +
26808 +- mphy->chainmask = BIT(nss) - 1;
26809 +- if (ext_phy)
26810 ++ mphy->chainmask = BIT(path) - 1;
26811 ++ if (phy->band_idx)
26812 + mphy->chainmask <<= dev->chainshift;
26813 +- mphy->antenna_mask = BIT(nss_band) - 1;
26814 ++ mphy->antenna_mask = BIT(nss) - 1;
26815 + dev->chainmask |= mphy->chainmask;
26816 + dev->chainshift = hweight8(dev->mphy.chainmask);
26817 + }
26818 +diff --git a/drivers/net/wireless/mediatek/mt76/mt7915/eeprom.h b/drivers/net/wireless/mediatek/mt76/mt7915/eeprom.h
26819 +index 7578ac6d0be62..f3e56817d36e9 100644
26820 +--- a/drivers/net/wireless/mediatek/mt76/mt7915/eeprom.h
26821 ++++ b/drivers/net/wireless/mediatek/mt76/mt7915/eeprom.h
26822 +@@ -58,11 +58,6 @@ enum mt7915_eeprom_field {
26823 + #define MT_EE_RATE_DELTA_SIGN BIT(6)
26824 + #define MT_EE_RATE_DELTA_EN BIT(7)
26825 +
26826 +-#define MT_EE_NSS_MAX_MA7915 4
26827 +-#define MT_EE_NSS_MAX_DBDC_MA7915 2
26828 +-#define MT_EE_NSS_MAX_MA7986 4
26829 +-#define MT_EE_NSS_MAX_DBDC_MA7986 4
26830 +-
26831 + enum mt7915_adie_sku {
26832 + MT7976_ONE_ADIE_DBDC = 0x7,
26833 + MT7975_ONE_ADIE = 0x8,
26834 +diff --git a/drivers/net/wireless/mediatek/mt76/mt7915/mac.c b/drivers/net/wireless/mediatek/mt76/mt7915/mac.c
26835 +index 49aa5c056063e..853d857b17579 100644
26836 +--- a/drivers/net/wireless/mediatek/mt76/mt7915/mac.c
26837 ++++ b/drivers/net/wireless/mediatek/mt76/mt7915/mac.c
26838 +@@ -1146,7 +1146,7 @@ void mt7915_mac_set_timing(struct mt7915_phy *phy)
26839 + FIELD_PREP(MT_TIMEOUT_VAL_CCA, 48);
26840 + u32 ofdm = FIELD_PREP(MT_TIMEOUT_VAL_PLCP, 60) |
26841 + FIELD_PREP(MT_TIMEOUT_VAL_CCA, 28);
26842 +- int offset;
26843 ++ int eifs_ofdm = 360, sifs = 10, offset;
26844 + bool a_band = !(phy->mt76->chandef.chan->band == NL80211_BAND_2GHZ);
26845 +
26846 + if (!test_bit(MT76_STATE_RUNNING, &phy->mt76->state))
26847 +@@ -1164,17 +1164,26 @@ void mt7915_mac_set_timing(struct mt7915_phy *phy)
26848 + reg_offset = FIELD_PREP(MT_TIMEOUT_VAL_PLCP, offset) |
26849 + FIELD_PREP(MT_TIMEOUT_VAL_CCA, offset);
26850 +
26851 ++ if (!is_mt7915(&dev->mt76)) {
26852 ++ if (!a_band) {
26853 ++ mt76_wr(dev, MT_TMAC_ICR1(phy->band_idx),
26854 ++ FIELD_PREP(MT_IFS_EIFS_CCK, 314));
26855 ++ eifs_ofdm = 78;
26856 ++ } else {
26857 ++ eifs_ofdm = 84;
26858 ++ }
26859 ++ } else if (a_band) {
26860 ++ sifs = 16;
26861 ++ }
26862 ++
26863 + mt76_wr(dev, MT_TMAC_CDTR(phy->band_idx), cck + reg_offset);
26864 + mt76_wr(dev, MT_TMAC_ODTR(phy->band_idx), ofdm + reg_offset);
26865 + mt76_wr(dev, MT_TMAC_ICR0(phy->band_idx),
26866 +- FIELD_PREP(MT_IFS_EIFS_OFDM, a_band ? 84 : 78) |
26867 ++ FIELD_PREP(MT_IFS_EIFS_OFDM, eifs_ofdm) |
26868 + FIELD_PREP(MT_IFS_RIFS, 2) |
26869 +- FIELD_PREP(MT_IFS_SIFS, 10) |
26870 ++ FIELD_PREP(MT_IFS_SIFS, sifs) |
26871 + FIELD_PREP(MT_IFS_SLOT, phy->slottime));
26872 +
26873 +- mt76_wr(dev, MT_TMAC_ICR1(phy->band_idx),
26874 +- FIELD_PREP(MT_IFS_EIFS_CCK, 314));
26875 +-
26876 + if (phy->slottime < 20 || a_band)
26877 + val = MT7915_CFEND_RATE_DEFAULT;
26878 + else
26879 +@@ -1595,7 +1604,7 @@ void mt7915_mac_update_stats(struct mt7915_phy *phy)
26880 +
26881 + aggr0 = phy->band_idx ? ARRAY_SIZE(dev->mt76.aggr_stats) / 2 : 0;
26882 + if (is_mt7915(&dev->mt76)) {
26883 +- for (i = 0, aggr1 = aggr0 + 4; i < 4; i++) {
26884 ++ for (i = 0, aggr1 = aggr0 + 8; i < 4; i++) {
26885 + val = mt76_rr(dev, MT_MIB_MB_SDR1(phy->band_idx, (i << 4)));
26886 + mib->ba_miss_cnt +=
26887 + FIELD_GET(MT_MIB_BA_MISS_COUNT_MASK, val);
26888 +diff --git a/drivers/net/wireless/mediatek/mt76/mt7915/pci.c b/drivers/net/wireless/mediatek/mt76/mt7915/pci.c
26889 +index d74f609775d3b..7a44a4f88ccb6 100644
26890 +--- a/drivers/net/wireless/mediatek/mt76/mt7915/pci.c
26891 ++++ b/drivers/net/wireless/mediatek/mt76/mt7915/pci.c
26892 +@@ -65,10 +65,17 @@ static void mt7915_put_hif2(struct mt7915_hif *hif)
26893 +
26894 + static struct mt7915_hif *mt7915_pci_init_hif2(struct pci_dev *pdev)
26895 + {
26896 ++ struct pci_dev *tmp_pdev;
26897 ++
26898 + hif_idx++;
26899 +- if (!pci_get_device(PCI_VENDOR_ID_MEDIATEK, 0x7916, NULL) &&
26900 +- !pci_get_device(PCI_VENDOR_ID_MEDIATEK, 0x790a, NULL))
26901 +- return NULL;
26902 ++
26903 ++ tmp_pdev = pci_get_device(PCI_VENDOR_ID_MEDIATEK, 0x7916, NULL);
26904 ++ if (!tmp_pdev) {
26905 ++ tmp_pdev = pci_get_device(PCI_VENDOR_ID_MEDIATEK, 0x790a, NULL);
26906 ++ if (!tmp_pdev)
26907 ++ return NULL;
26908 ++ }
26909 ++ pci_dev_put(tmp_pdev);
26910 +
26911 + writel(hif_idx | MT_PCIE_RECOG_ID_SEM,
26912 + pcim_iomap_table(pdev)[0] + MT_PCIE_RECOG_ID);
26913 +diff --git a/drivers/net/wireless/mediatek/mt76/mt7921/mac.c b/drivers/net/wireless/mediatek/mt76/mt7921/mac.c
26914 +index e8a7a58317822..5b0eba4cb4219 100644
26915 +--- a/drivers/net/wireless/mediatek/mt76/mt7921/mac.c
26916 ++++ b/drivers/net/wireless/mediatek/mt76/mt7921/mac.c
26917 +@@ -394,6 +394,27 @@ mt7921_mac_fill_rx(struct mt7921_dev *dev, struct sk_buff *skb)
26918 + if (v0 & MT_PRXV_HT_AD_CODE)
26919 + status->enc_flags |= RX_ENC_FLAG_LDPC;
26920 +
26921 ++ ret = mt76_connac2_mac_fill_rx_rate(&dev->mt76, status, sband,
26922 ++ rxv, &mode);
26923 ++ if (ret < 0)
26924 ++ return ret;
26925 ++
26926 ++ if (rxd1 & MT_RXD1_NORMAL_GROUP_5) {
26927 ++ rxd += 6;
26928 ++ if ((u8 *)rxd - skb->data >= skb->len)
26929 ++ return -EINVAL;
26930 ++
26931 ++ rxv = rxd;
26932 ++ /* Monitor mode would use RCPI described in GROUP 5
26933 ++ * instead.
26934 ++ */
26935 ++ v1 = le32_to_cpu(rxv[0]);
26936 ++
26937 ++ rxd += 12;
26938 ++ if ((u8 *)rxd - skb->data >= skb->len)
26939 ++ return -EINVAL;
26940 ++ }
26941 ++
26942 + status->chains = mphy->antenna_mask;
26943 + status->chain_signal[0] = to_rssi(MT_PRXV_RCPI0, v1);
26944 + status->chain_signal[1] = to_rssi(MT_PRXV_RCPI1, v1);
26945 +@@ -408,17 +429,6 @@ mt7921_mac_fill_rx(struct mt7921_dev *dev, struct sk_buff *skb)
26946 + status->signal = max(status->signal,
26947 + status->chain_signal[i]);
26948 + }
26949 +-
26950 +- ret = mt76_connac2_mac_fill_rx_rate(&dev->mt76, status, sband,
26951 +- rxv, &mode);
26952 +- if (ret < 0)
26953 +- return ret;
26954 +-
26955 +- if (rxd1 & MT_RXD1_NORMAL_GROUP_5) {
26956 +- rxd += 18;
26957 +- if ((u8 *)rxd - skb->data >= skb->len)
26958 +- return -EINVAL;
26959 +- }
26960 + }
26961 +
26962 + amsdu_info = FIELD_GET(MT_RXD4_NORMAL_PAYLOAD_FORMAT, rxd4);
26963 +@@ -842,7 +852,7 @@ void mt7921_mac_update_mib_stats(struct mt7921_phy *phy)
26964 + mib->tx_amsdu_cnt += val;
26965 + }
26966 +
26967 +- for (i = 0, aggr1 = aggr0 + 4; i < 4; i++) {
26968 ++ for (i = 0, aggr1 = aggr0 + 8; i < 4; i++) {
26969 + u32 val2;
26970 +
26971 + val = mt76_rr(dev, MT_TX_AGG_CNT(0, i));
26972 +diff --git a/drivers/net/wireless/mediatek/mt76/usb.c b/drivers/net/wireless/mediatek/mt76/usb.c
26973 +index 6b8964c19f50d..446429f4d9442 100644
26974 +--- a/drivers/net/wireless/mediatek/mt76/usb.c
26975 ++++ b/drivers/net/wireless/mediatek/mt76/usb.c
26976 +@@ -761,6 +761,9 @@ static void mt76u_status_worker(struct mt76_worker *w)
26977 + struct mt76_queue *q;
26978 + int i;
26979 +
26980 ++ if (!test_bit(MT76_STATE_RUNNING, &dev->phy.state))
26981 ++ return;
26982 ++
26983 + for (i = 0; i < IEEE80211_NUM_ACS; i++) {
26984 + q = dev->phy.q_tx[i];
26985 + if (!q)
26986 +@@ -780,11 +783,11 @@ static void mt76u_status_worker(struct mt76_worker *w)
26987 + wake_up(&dev->tx_wait);
26988 +
26989 + mt76_worker_schedule(&dev->tx_worker);
26990 +-
26991 +- if (dev->drv->tx_status_data &&
26992 +- !test_and_set_bit(MT76_READING_STATS, &dev->phy.state))
26993 +- queue_work(dev->wq, &dev->usb.stat_work);
26994 + }
26995 ++
26996 ++ if (dev->drv->tx_status_data &&
26997 ++ !test_and_set_bit(MT76_READING_STATS, &dev->phy.state))
26998 ++ queue_work(dev->wq, &dev->usb.stat_work);
26999 + }
27000 +
27001 + static void mt76u_tx_status_data(struct work_struct *work)
27002 +diff --git a/drivers/net/wireless/purelifi/plfxlc/usb.c b/drivers/net/wireless/purelifi/plfxlc/usb.c
27003 +index 39e54b3787d6a..76d0a778636a4 100644
27004 +--- a/drivers/net/wireless/purelifi/plfxlc/usb.c
27005 ++++ b/drivers/net/wireless/purelifi/plfxlc/usb.c
27006 +@@ -247,6 +247,7 @@ error:
27007 + for (i = 0; i < RX_URBS_COUNT; i++)
27008 + free_rx_urb(urbs[i]);
27009 + }
27010 ++ kfree(urbs);
27011 + return r;
27012 + }
27013 +
27014 +diff --git a/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu.h b/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu.h
27015 +index 782b089a2e1ba..1ba66b8f70c95 100644
27016 +--- a/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu.h
27017 ++++ b/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu.h
27018 +@@ -1190,7 +1190,7 @@ struct rtl8723bu_c2h {
27019 + u8 bw;
27020 + } __packed ra_report;
27021 + };
27022 +-};
27023 ++} __packed;
27024 +
27025 + struct rtl8xxxu_fileops;
27026 +
27027 +diff --git a/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_core.c b/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_core.c
27028 +index 08f9d17dce12e..955fcf97b9dc1 100644
27029 +--- a/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_core.c
27030 ++++ b/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu_core.c
27031 +@@ -1608,18 +1608,18 @@ static int rtl8xxxu_identify_chip(struct rtl8xxxu_priv *priv)
27032 + {
27033 + struct device *dev = &priv->udev->dev;
27034 + struct ieee80211_hw *hw = priv->hw;
27035 +- u32 val32, bonding;
27036 ++ u32 val32, bonding, sys_cfg;
27037 + u16 val16;
27038 +
27039 +- val32 = rtl8xxxu_read32(priv, REG_SYS_CFG);
27040 +- priv->chip_cut = (val32 & SYS_CFG_CHIP_VERSION_MASK) >>
27041 ++ sys_cfg = rtl8xxxu_read32(priv, REG_SYS_CFG);
27042 ++ priv->chip_cut = (sys_cfg & SYS_CFG_CHIP_VERSION_MASK) >>
27043 + SYS_CFG_CHIP_VERSION_SHIFT;
27044 +- if (val32 & SYS_CFG_TRP_VAUX_EN) {
27045 ++ if (sys_cfg & SYS_CFG_TRP_VAUX_EN) {
27046 + dev_info(dev, "Unsupported test chip\n");
27047 + return -ENOTSUPP;
27048 + }
27049 +
27050 +- if (val32 & SYS_CFG_BT_FUNC) {
27051 ++ if (sys_cfg & SYS_CFG_BT_FUNC) {
27052 + if (priv->chip_cut >= 3) {
27053 + sprintf(priv->chip_name, "8723BU");
27054 + priv->rtl_chip = RTL8723B;
27055 +@@ -1641,7 +1641,7 @@ static int rtl8xxxu_identify_chip(struct rtl8xxxu_priv *priv)
27056 + if (val32 & MULTI_GPS_FUNC_EN)
27057 + priv->has_gps = 1;
27058 + priv->is_multi_func = 1;
27059 +- } else if (val32 & SYS_CFG_TYPE_ID) {
27060 ++ } else if (sys_cfg & SYS_CFG_TYPE_ID) {
27061 + bonding = rtl8xxxu_read32(priv, REG_HPON_FSM);
27062 + bonding &= HPON_FSM_BONDING_MASK;
27063 + if (priv->fops->tx_desc_size ==
27064 +@@ -1692,7 +1692,7 @@ static int rtl8xxxu_identify_chip(struct rtl8xxxu_priv *priv)
27065 + case RTL8188E:
27066 + case RTL8192E:
27067 + case RTL8723B:
27068 +- switch (val32 & SYS_CFG_VENDOR_EXT_MASK) {
27069 ++ switch (sys_cfg & SYS_CFG_VENDOR_EXT_MASK) {
27070 + case SYS_CFG_VENDOR_ID_TSMC:
27071 + sprintf(priv->chip_vendor, "TSMC");
27072 + break;
27073 +@@ -1709,7 +1709,7 @@ static int rtl8xxxu_identify_chip(struct rtl8xxxu_priv *priv)
27074 + }
27075 + break;
27076 + default:
27077 +- if (val32 & SYS_CFG_VENDOR_ID) {
27078 ++ if (sys_cfg & SYS_CFG_VENDOR_ID) {
27079 + sprintf(priv->chip_vendor, "UMC");
27080 + priv->vendor_umc = 1;
27081 + } else {
27082 +@@ -4654,7 +4654,6 @@ rtl8xxxu_bss_info_changed(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
27083 + if (sta->deflink.ht_cap.cap &
27084 + (IEEE80211_HT_CAP_SGI_40 | IEEE80211_HT_CAP_SGI_20))
27085 + sgi = 1;
27086 +- rcu_read_unlock();
27087 +
27088 + highest_rate = fls(ramask) - 1;
27089 + if (highest_rate < DESC_RATE_MCS0) {
27090 +@@ -4679,6 +4678,7 @@ rtl8xxxu_bss_info_changed(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
27091 + else
27092 + rarpt->txrate.bw = RATE_INFO_BW_20;
27093 + }
27094 ++ rcu_read_unlock();
27095 + bit_rate = cfg80211_calculate_bitrate(&rarpt->txrate);
27096 + rarpt->bit_rate = bit_rate;
27097 + rarpt->desc_rate = highest_rate;
27098 +@@ -5575,7 +5575,6 @@ static void rtl8xxxu_c2hcmd_callback(struct work_struct *work)
27099 + rarpt->txrate.flags = 0;
27100 + rate = c2h->ra_report.rate;
27101 + sgi = c2h->ra_report.sgi;
27102 +- bw = c2h->ra_report.bw;
27103 +
27104 + if (rate < DESC_RATE_MCS0) {
27105 + rarpt->txrate.legacy =
27106 +@@ -5592,8 +5591,13 @@ static void rtl8xxxu_c2hcmd_callback(struct work_struct *work)
27107 + RATE_INFO_FLAGS_SHORT_GI;
27108 + }
27109 +
27110 +- if (bw == RATE_INFO_BW_20)
27111 +- rarpt->txrate.bw |= RATE_INFO_BW_20;
27112 ++ if (skb->len >= offsetofend(typeof(*c2h), ra_report.bw)) {
27113 ++ if (c2h->ra_report.bw == RTL8XXXU_CHANNEL_WIDTH_40)
27114 ++ bw = RATE_INFO_BW_40;
27115 ++ else
27116 ++ bw = RATE_INFO_BW_20;
27117 ++ rarpt->txrate.bw = bw;
27118 ++ }
27119 + }
27120 + bit_rate = cfg80211_calculate_bitrate(&rarpt->txrate);
27121 + rarpt->bit_rate = bit_rate;
27122 +diff --git a/drivers/net/wireless/realtek/rtw89/core.c b/drivers/net/wireless/realtek/rtw89/core.c
27123 +index 8b338e5ce364e..732015228bd30 100644
27124 +--- a/drivers/net/wireless/realtek/rtw89/core.c
27125 ++++ b/drivers/net/wireless/realtek/rtw89/core.c
27126 +@@ -2500,7 +2500,7 @@ int rtw89_core_sta_assoc(struct rtw89_dev *rtwdev,
27127 + }
27128 +
27129 + /* update cam aid mac_id net_type */
27130 +- rtw89_fw_h2c_cam(rtwdev, rtwvif, rtwsta, NULL);
27131 ++ ret = rtw89_fw_h2c_cam(rtwdev, rtwvif, rtwsta, NULL);
27132 + if (ret) {
27133 + rtw89_warn(rtwdev, "failed to send h2c cam\n");
27134 + return ret;
27135 +diff --git a/drivers/net/wireless/realtek/rtw89/mac.c b/drivers/net/wireless/realtek/rtw89/mac.c
27136 +index 93124b815825f..1afc14531194a 100644
27137 +--- a/drivers/net/wireless/realtek/rtw89/mac.c
27138 ++++ b/drivers/net/wireless/realtek/rtw89/mac.c
27139 +@@ -1387,10 +1387,8 @@ static int dle_mix_cfg(struct rtw89_dev *rtwdev, const struct rtw89_dle_mem *cfg
27140 + #define INVALID_QT_WCPU U16_MAX
27141 + #define SET_QUOTA_VAL(_min_x, _max_x, _module, _idx) \
27142 + do { \
27143 +- val = ((_min_x) & \
27144 +- B_AX_ ## _module ## _MIN_SIZE_MASK) | \
27145 +- (((_max_x) << 16) & \
27146 +- B_AX_ ## _module ## _MAX_SIZE_MASK); \
27147 ++ val = u32_encode_bits(_min_x, B_AX_ ## _module ## _MIN_SIZE_MASK) | \
27148 ++ u32_encode_bits(_max_x, B_AX_ ## _module ## _MAX_SIZE_MASK); \
27149 + rtw89_write32(rtwdev, \
27150 + R_AX_ ## _module ## _QTA ## _idx ## _CFG, \
27151 + val); \
27152 +diff --git a/drivers/net/wireless/realtek/rtw89/phy.c b/drivers/net/wireless/realtek/rtw89/phy.c
27153 +index 1532c0a6bbc44..2925179f508c9 100644
27154 +--- a/drivers/net/wireless/realtek/rtw89/phy.c
27155 ++++ b/drivers/net/wireless/realtek/rtw89/phy.c
27156 +@@ -3045,7 +3045,7 @@ void rtw89_phy_env_monitor_track(struct rtw89_dev *rtwdev)
27157 +
27158 + static bool rtw89_physts_ie_page_valid(enum rtw89_phy_status_bitmap *ie_page)
27159 + {
27160 +- if (*ie_page > RTW89_PHYSTS_BITMAP_NUM ||
27161 ++ if (*ie_page >= RTW89_PHYSTS_BITMAP_NUM ||
27162 + *ie_page == RTW89_RSVD_9)
27163 + return false;
27164 + else if (*ie_page > RTW89_RSVD_9)
27165 +diff --git a/drivers/net/wireless/rsi/rsi_91x_core.c b/drivers/net/wireless/rsi/rsi_91x_core.c
27166 +index 0f3a80f66b61c..ead4d4e043280 100644
27167 +--- a/drivers/net/wireless/rsi/rsi_91x_core.c
27168 ++++ b/drivers/net/wireless/rsi/rsi_91x_core.c
27169 +@@ -466,7 +466,9 @@ void rsi_core_xmit(struct rsi_common *common, struct sk_buff *skb)
27170 + tid, 0);
27171 + }
27172 + }
27173 +- if (skb->protocol == cpu_to_be16(ETH_P_PAE)) {
27174 ++
27175 ++ if (IEEE80211_SKB_CB(skb)->control.flags &
27176 ++ IEEE80211_TX_CTRL_PORT_CTRL_PROTO) {
27177 + q_num = MGMT_SOFT_Q;
27178 + skb->priority = q_num;
27179 + }
27180 +diff --git a/drivers/net/wireless/rsi/rsi_91x_hal.c b/drivers/net/wireless/rsi/rsi_91x_hal.c
27181 +index c61f83a7333b6..c7460fbba0142 100644
27182 +--- a/drivers/net/wireless/rsi/rsi_91x_hal.c
27183 ++++ b/drivers/net/wireless/rsi/rsi_91x_hal.c
27184 +@@ -162,12 +162,16 @@ int rsi_prepare_data_desc(struct rsi_common *common, struct sk_buff *skb)
27185 + u8 header_size;
27186 + u8 vap_id = 0;
27187 + u8 dword_align_bytes;
27188 ++ bool tx_eapol;
27189 + u16 seq_num;
27190 +
27191 + info = IEEE80211_SKB_CB(skb);
27192 + vif = info->control.vif;
27193 + tx_params = (struct skb_info *)info->driver_data;
27194 +
27195 ++ tx_eapol = IEEE80211_SKB_CB(skb)->control.flags &
27196 ++ IEEE80211_TX_CTRL_PORT_CTRL_PROTO;
27197 ++
27198 + header_size = FRAME_DESC_SZ + sizeof(struct rsi_xtended_desc);
27199 + if (header_size > skb_headroom(skb)) {
27200 + rsi_dbg(ERR_ZONE, "%s: Unable to send pkt\n", __func__);
27201 +@@ -231,7 +235,7 @@ int rsi_prepare_data_desc(struct rsi_common *common, struct sk_buff *skb)
27202 + }
27203 + }
27204 +
27205 +- if (skb->protocol == cpu_to_be16(ETH_P_PAE)) {
27206 ++ if (tx_eapol) {
27207 + rsi_dbg(INFO_ZONE, "*** Tx EAPOL ***\n");
27208 +
27209 + data_desc->frame_info = cpu_to_le16(RATE_INFO_ENABLE);
27210 +diff --git a/drivers/nfc/pn533/pn533.c b/drivers/nfc/pn533/pn533.c
27211 +index d9f6367b9993d..f0cac19005527 100644
27212 +--- a/drivers/nfc/pn533/pn533.c
27213 ++++ b/drivers/nfc/pn533/pn533.c
27214 +@@ -1295,6 +1295,8 @@ static int pn533_poll_dep_complete(struct pn533 *dev, void *arg,
27215 + if (IS_ERR(resp))
27216 + return PTR_ERR(resp);
27217 +
27218 ++ memset(&nfc_target, 0, sizeof(struct nfc_target));
27219 ++
27220 + rsp = (struct pn533_cmd_jump_dep_response *)resp->data;
27221 +
27222 + rc = rsp->status & PN533_CMD_RET_MASK;
27223 +@@ -1926,6 +1928,8 @@ static int pn533_in_dep_link_up_complete(struct pn533 *dev, void *arg,
27224 +
27225 + dev_dbg(dev->dev, "Creating new target\n");
27226 +
27227 ++ memset(&nfc_target, 0, sizeof(struct nfc_target));
27228 ++
27229 + nfc_target.supported_protocols = NFC_PROTO_NFC_DEP_MASK;
27230 + nfc_target.nfcid1_len = 10;
27231 + memcpy(nfc_target.nfcid1, rsp->nfcid3t, nfc_target.nfcid1_len);
27232 +diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
27233 +index aca50bb937506..3582a28a1dcec 100644
27234 +--- a/drivers/nvme/host/core.c
27235 ++++ b/drivers/nvme/host/core.c
27236 +@@ -3043,7 +3043,7 @@ static int nvme_init_non_mdts_limits(struct nvme_ctrl *ctrl)
27237 +
27238 + id = kzalloc(sizeof(*id), GFP_KERNEL);
27239 + if (!id)
27240 +- return 0;
27241 ++ return -ENOMEM;
27242 +
27243 + c.identify.opcode = nvme_admin_identify;
27244 + c.identify.cns = NVME_ID_CNS_CS_CTRL;
27245 +@@ -3739,13 +3739,17 @@ static ssize_t nvme_ctrl_dhchap_secret_store(struct device *dev,
27246 + memcpy(dhchap_secret, buf, count);
27247 + nvme_auth_stop(ctrl);
27248 + if (strcmp(dhchap_secret, opts->dhchap_secret)) {
27249 ++ struct nvme_dhchap_key *key, *host_key;
27250 + int ret;
27251 +
27252 +- ret = nvme_auth_generate_key(dhchap_secret, &ctrl->host_key);
27253 ++ ret = nvme_auth_generate_key(dhchap_secret, &key);
27254 + if (ret)
27255 + return ret;
27256 + kfree(opts->dhchap_secret);
27257 + opts->dhchap_secret = dhchap_secret;
27258 ++ host_key = ctrl->host_key;
27259 ++ ctrl->host_key = key;
27260 ++ nvme_auth_free_key(host_key);
27261 + /* Key has changed; re-authentication with new key */
27262 + nvme_auth_reset(ctrl);
27263 + }
27264 +@@ -3789,13 +3793,17 @@ static ssize_t nvme_ctrl_dhchap_ctrl_secret_store(struct device *dev,
27265 + memcpy(dhchap_secret, buf, count);
27266 + nvme_auth_stop(ctrl);
27267 + if (strcmp(dhchap_secret, opts->dhchap_ctrl_secret)) {
27268 ++ struct nvme_dhchap_key *key, *ctrl_key;
27269 + int ret;
27270 +
27271 +- ret = nvme_auth_generate_key(dhchap_secret, &ctrl->ctrl_key);
27272 ++ ret = nvme_auth_generate_key(dhchap_secret, &key);
27273 + if (ret)
27274 + return ret;
27275 + kfree(opts->dhchap_ctrl_secret);
27276 + opts->dhchap_ctrl_secret = dhchap_secret;
27277 ++ ctrl_key = ctrl->ctrl_key;
27278 ++ ctrl->ctrl_key = key;
27279 ++ nvme_auth_free_key(ctrl_key);
27280 + /* Key has changed; re-authentication with new key */
27281 + nvme_auth_reset(ctrl);
27282 + }
27283 +diff --git a/drivers/nvme/target/core.c b/drivers/nvme/target/core.c
27284 +index aecb5853f8da4..683b75a992b3d 100644
27285 +--- a/drivers/nvme/target/core.c
27286 ++++ b/drivers/nvme/target/core.c
27287 +@@ -15,6 +15,7 @@
27288 +
27289 + #include "nvmet.h"
27290 +
27291 ++struct kmem_cache *nvmet_bvec_cache;
27292 + struct workqueue_struct *buffered_io_wq;
27293 + struct workqueue_struct *zbd_wq;
27294 + static const struct nvmet_fabrics_ops *nvmet_transports[NVMF_TRTYPE_MAX];
27295 +@@ -1631,26 +1632,28 @@ void nvmet_subsys_put(struct nvmet_subsys *subsys)
27296 +
27297 + static int __init nvmet_init(void)
27298 + {
27299 +- int error;
27300 ++ int error = -ENOMEM;
27301 +
27302 + nvmet_ana_group_enabled[NVMET_DEFAULT_ANA_GRPID] = 1;
27303 +
27304 ++ nvmet_bvec_cache = kmem_cache_create("nvmet-bvec",
27305 ++ NVMET_MAX_MPOOL_BVEC * sizeof(struct bio_vec), 0,
27306 ++ SLAB_HWCACHE_ALIGN, NULL);
27307 ++ if (!nvmet_bvec_cache)
27308 ++ return -ENOMEM;
27309 ++
27310 + zbd_wq = alloc_workqueue("nvmet-zbd-wq", WQ_MEM_RECLAIM, 0);
27311 + if (!zbd_wq)
27312 +- return -ENOMEM;
27313 ++ goto out_destroy_bvec_cache;
27314 +
27315 + buffered_io_wq = alloc_workqueue("nvmet-buffered-io-wq",
27316 + WQ_MEM_RECLAIM, 0);
27317 +- if (!buffered_io_wq) {
27318 +- error = -ENOMEM;
27319 ++ if (!buffered_io_wq)
27320 + goto out_free_zbd_work_queue;
27321 +- }
27322 +
27323 + nvmet_wq = alloc_workqueue("nvmet-wq", WQ_MEM_RECLAIM, 0);
27324 +- if (!nvmet_wq) {
27325 +- error = -ENOMEM;
27326 ++ if (!nvmet_wq)
27327 + goto out_free_buffered_work_queue;
27328 +- }
27329 +
27330 + error = nvmet_init_discovery();
27331 + if (error)
27332 +@@ -1669,6 +1672,8 @@ out_free_buffered_work_queue:
27333 + destroy_workqueue(buffered_io_wq);
27334 + out_free_zbd_work_queue:
27335 + destroy_workqueue(zbd_wq);
27336 ++out_destroy_bvec_cache:
27337 ++ kmem_cache_destroy(nvmet_bvec_cache);
27338 + return error;
27339 + }
27340 +
27341 +@@ -1680,6 +1685,7 @@ static void __exit nvmet_exit(void)
27342 + destroy_workqueue(nvmet_wq);
27343 + destroy_workqueue(buffered_io_wq);
27344 + destroy_workqueue(zbd_wq);
27345 ++ kmem_cache_destroy(nvmet_bvec_cache);
27346 +
27347 + BUILD_BUG_ON(sizeof(struct nvmf_disc_rsp_page_entry) != 1024);
27348 + BUILD_BUG_ON(sizeof(struct nvmf_disc_rsp_page_hdr) != 1024);
27349 +diff --git a/drivers/nvme/target/io-cmd-file.c b/drivers/nvme/target/io-cmd-file.c
27350 +index 64b47e2a46330..e55ec6fefd7f4 100644
27351 +--- a/drivers/nvme/target/io-cmd-file.c
27352 ++++ b/drivers/nvme/target/io-cmd-file.c
27353 +@@ -11,7 +11,6 @@
27354 + #include <linux/fs.h>
27355 + #include "nvmet.h"
27356 +
27357 +-#define NVMET_MAX_MPOOL_BVEC 16
27358 + #define NVMET_MIN_MPOOL_OBJ 16
27359 +
27360 + void nvmet_file_ns_revalidate(struct nvmet_ns *ns)
27361 +@@ -26,8 +25,6 @@ void nvmet_file_ns_disable(struct nvmet_ns *ns)
27362 + flush_workqueue(buffered_io_wq);
27363 + mempool_destroy(ns->bvec_pool);
27364 + ns->bvec_pool = NULL;
27365 +- kmem_cache_destroy(ns->bvec_cache);
27366 +- ns->bvec_cache = NULL;
27367 + fput(ns->file);
27368 + ns->file = NULL;
27369 + }
27370 +@@ -59,16 +56,8 @@ int nvmet_file_ns_enable(struct nvmet_ns *ns)
27371 + ns->blksize_shift = min_t(u8,
27372 + file_inode(ns->file)->i_blkbits, 12);
27373 +
27374 +- ns->bvec_cache = kmem_cache_create("nvmet-bvec",
27375 +- NVMET_MAX_MPOOL_BVEC * sizeof(struct bio_vec),
27376 +- 0, SLAB_HWCACHE_ALIGN, NULL);
27377 +- if (!ns->bvec_cache) {
27378 +- ret = -ENOMEM;
27379 +- goto err;
27380 +- }
27381 +-
27382 + ns->bvec_pool = mempool_create(NVMET_MIN_MPOOL_OBJ, mempool_alloc_slab,
27383 +- mempool_free_slab, ns->bvec_cache);
27384 ++ mempool_free_slab, nvmet_bvec_cache);
27385 +
27386 + if (!ns->bvec_pool) {
27387 + ret = -ENOMEM;
27388 +@@ -77,9 +66,10 @@ int nvmet_file_ns_enable(struct nvmet_ns *ns)
27389 +
27390 + return ret;
27391 + err:
27392 ++ fput(ns->file);
27393 ++ ns->file = NULL;
27394 + ns->size = 0;
27395 + ns->blksize_shift = 0;
27396 +- nvmet_file_ns_disable(ns);
27397 + return ret;
27398 + }
27399 +
27400 +diff --git a/drivers/nvme/target/nvmet.h b/drivers/nvme/target/nvmet.h
27401 +index dfe3894205aa7..bda1c1f71f394 100644
27402 +--- a/drivers/nvme/target/nvmet.h
27403 ++++ b/drivers/nvme/target/nvmet.h
27404 +@@ -77,7 +77,6 @@ struct nvmet_ns {
27405 +
27406 + struct completion disable_done;
27407 + mempool_t *bvec_pool;
27408 +- struct kmem_cache *bvec_cache;
27409 +
27410 + int use_p2pmem;
27411 + struct pci_dev *p2p_dev;
27412 +@@ -393,6 +392,8 @@ struct nvmet_req {
27413 + u64 error_slba;
27414 + };
27415 +
27416 ++#define NVMET_MAX_MPOOL_BVEC 16
27417 ++extern struct kmem_cache *nvmet_bvec_cache;
27418 + extern struct workqueue_struct *buffered_io_wq;
27419 + extern struct workqueue_struct *zbd_wq;
27420 + extern struct workqueue_struct *nvmet_wq;
27421 +diff --git a/drivers/of/overlay.c b/drivers/of/overlay.c
27422 +index bd8ff4df723da..ed4e6c144a681 100644
27423 +--- a/drivers/of/overlay.c
27424 ++++ b/drivers/of/overlay.c
27425 +@@ -545,7 +545,7 @@ static int find_dup_cset_node_entry(struct overlay_changeset *ovcs,
27426 +
27427 + fn_1 = kasprintf(GFP_KERNEL, "%pOF", ce_1->np);
27428 + fn_2 = kasprintf(GFP_KERNEL, "%pOF", ce_2->np);
27429 +- node_path_match = !strcmp(fn_1, fn_2);
27430 ++ node_path_match = !fn_1 || !fn_2 || !strcmp(fn_1, fn_2);
27431 + kfree(fn_1);
27432 + kfree(fn_2);
27433 + if (node_path_match) {
27434 +@@ -580,7 +580,7 @@ static int find_dup_cset_prop(struct overlay_changeset *ovcs,
27435 +
27436 + fn_1 = kasprintf(GFP_KERNEL, "%pOF", ce_1->np);
27437 + fn_2 = kasprintf(GFP_KERNEL, "%pOF", ce_2->np);
27438 +- node_path_match = !strcmp(fn_1, fn_2);
27439 ++ node_path_match = !fn_1 || !fn_2 || !strcmp(fn_1, fn_2);
27440 + kfree(fn_1);
27441 + kfree(fn_2);
27442 + if (node_path_match &&
27443 +diff --git a/drivers/pci/controller/dwc/pci-imx6.c b/drivers/pci/controller/dwc/pci-imx6.c
27444 +index 6e5debdbc55b9..6ffe95d68ae72 100644
27445 +--- a/drivers/pci/controller/dwc/pci-imx6.c
27446 ++++ b/drivers/pci/controller/dwc/pci-imx6.c
27447 +@@ -942,12 +942,6 @@ static int imx6_pcie_host_init(struct dw_pcie_rp *pp)
27448 + }
27449 + }
27450 +
27451 +- ret = imx6_pcie_deassert_core_reset(imx6_pcie);
27452 +- if (ret < 0) {
27453 +- dev_err(dev, "pcie deassert core reset failed: %d\n", ret);
27454 +- goto err_phy_off;
27455 +- }
27456 +-
27457 + if (imx6_pcie->phy) {
27458 + ret = phy_init(imx6_pcie->phy);
27459 + if (ret) {
27460 +@@ -955,6 +949,13 @@ static int imx6_pcie_host_init(struct dw_pcie_rp *pp)
27461 + goto err_phy_off;
27462 + }
27463 + }
27464 ++
27465 ++ ret = imx6_pcie_deassert_core_reset(imx6_pcie);
27466 ++ if (ret < 0) {
27467 ++ dev_err(dev, "pcie deassert core reset failed: %d\n", ret);
27468 ++ goto err_phy_off;
27469 ++ }
27470 ++
27471 + imx6_setup_phy_mpll(imx6_pcie);
27472 +
27473 + return 0;
27474 +diff --git a/drivers/pci/controller/dwc/pcie-designware.c b/drivers/pci/controller/dwc/pcie-designware.c
27475 +index c6725c519a479..9e4d96e5a3f5a 100644
27476 +--- a/drivers/pci/controller/dwc/pcie-designware.c
27477 ++++ b/drivers/pci/controller/dwc/pcie-designware.c
27478 +@@ -641,7 +641,7 @@ void dw_pcie_setup(struct dw_pcie *pci)
27479 + if (pci->n_fts[1]) {
27480 + val = dw_pcie_readl_dbi(pci, PCIE_LINK_WIDTH_SPEED_CONTROL);
27481 + val &= ~PORT_LOGIC_N_FTS_MASK;
27482 +- val |= pci->n_fts[pci->link_gen - 1];
27483 ++ val |= pci->n_fts[1];
27484 + dw_pcie_writel_dbi(pci, PCIE_LINK_WIDTH_SPEED_CONTROL, val);
27485 + }
27486 +
27487 +diff --git a/drivers/pci/controller/vmd.c b/drivers/pci/controller/vmd.c
27488 +index e06e9f4fc50f7..769eedeb8802a 100644
27489 +--- a/drivers/pci/controller/vmd.c
27490 ++++ b/drivers/pci/controller/vmd.c
27491 +@@ -719,6 +719,7 @@ static int vmd_enable_domain(struct vmd_dev *vmd, unsigned long features)
27492 + resource_size_t offset[2] = {0};
27493 + resource_size_t membar2_offset = 0x2000;
27494 + struct pci_bus *child;
27495 ++ struct pci_dev *dev;
27496 + int ret;
27497 +
27498 + /*
27499 +@@ -859,8 +860,25 @@ static int vmd_enable_domain(struct vmd_dev *vmd, unsigned long features)
27500 +
27501 + pci_scan_child_bus(vmd->bus);
27502 + vmd_domain_reset(vmd);
27503 +- list_for_each_entry(child, &vmd->bus->children, node)
27504 +- pci_reset_bus(child->self);
27505 ++
27506 ++ /* When Intel VMD is enabled, the OS does not discover the Root Ports
27507 ++ * owned by Intel VMD within the MMCFG space. pci_reset_bus() applies
27508 ++ * a reset to the parent of the PCI device supplied as argument. This
27509 ++ * is why we pass a child device, so the reset can be triggered at
27510 ++ * the Intel bridge level and propagated to all the children in the
27511 ++ * hierarchy.
27512 ++ */
27513 ++ list_for_each_entry(child, &vmd->bus->children, node) {
27514 ++ if (!list_empty(&child->devices)) {
27515 ++ dev = list_first_entry(&child->devices,
27516 ++ struct pci_dev, bus_list);
27517 ++ if (pci_reset_bus(dev))
27518 ++ pci_warn(dev, "can't reset device: %d\n", ret);
27519 ++
27520 ++ break;
27521 ++ }
27522 ++ }
27523 ++
27524 + pci_assign_unassigned_bus_resources(vmd->bus);
27525 +
27526 + /*
27527 +@@ -980,6 +998,11 @@ static int vmd_resume(struct device *dev)
27528 + struct vmd_dev *vmd = pci_get_drvdata(pdev);
27529 + int err, i;
27530 +
27531 ++ if (vmd->irq_domain)
27532 ++ vmd_set_msi_remapping(vmd, true);
27533 ++ else
27534 ++ vmd_set_msi_remapping(vmd, false);
27535 ++
27536 + for (i = 0; i < vmd->msix_count; i++) {
27537 + err = devm_request_irq(dev, vmd->irqs[i].virq,
27538 + vmd_irq, IRQF_NO_THREAD,
27539 +diff --git a/drivers/pci/endpoint/functions/pci-epf-test.c b/drivers/pci/endpoint/functions/pci-epf-test.c
27540 +index 36b1801a061b7..55283d2379a6a 100644
27541 +--- a/drivers/pci/endpoint/functions/pci-epf-test.c
27542 ++++ b/drivers/pci/endpoint/functions/pci-epf-test.c
27543 +@@ -979,7 +979,7 @@ static int pci_epf_test_bind(struct pci_epf *epf)
27544 + if (ret)
27545 + epf_test->dma_supported = false;
27546 +
27547 +- if (linkup_notifier) {
27548 ++ if (linkup_notifier || core_init_notifier) {
27549 + epf->nb.notifier_call = pci_epf_test_notifier;
27550 + pci_epc_register_notifier(epc, &epf->nb);
27551 + } else {
27552 +diff --git a/drivers/pci/endpoint/functions/pci-epf-vntb.c b/drivers/pci/endpoint/functions/pci-epf-vntb.c
27553 +index 0ea85e1d292ec..fba0179939b8f 100644
27554 +--- a/drivers/pci/endpoint/functions/pci-epf-vntb.c
27555 ++++ b/drivers/pci/endpoint/functions/pci-epf-vntb.c
27556 +@@ -557,7 +557,7 @@ static int epf_ntb_db_bar_init(struct epf_ntb *ntb)
27557 + return ret;
27558 +
27559 + err_alloc_peer_mem:
27560 +- pci_epc_mem_free_addr(ntb->epf->epc, epf_bar->phys_addr, mw_addr, epf_bar->size);
27561 ++ pci_epf_free_space(ntb->epf, mw_addr, barno, 0);
27562 + return -1;
27563 + }
27564 +
27565 +diff --git a/drivers/pci/irq.c b/drivers/pci/irq.c
27566 +index 12ecd0aaa28d6..0050e8f6814ed 100644
27567 +--- a/drivers/pci/irq.c
27568 ++++ b/drivers/pci/irq.c
27569 +@@ -44,6 +44,8 @@ int pci_request_irq(struct pci_dev *dev, unsigned int nr, irq_handler_t handler,
27570 + va_start(ap, fmt);
27571 + devname = kvasprintf(GFP_KERNEL, fmt, ap);
27572 + va_end(ap);
27573 ++ if (!devname)
27574 ++ return -ENOMEM;
27575 +
27576 + ret = request_threaded_irq(pci_irq_vector(dev, nr), handler, thread_fn,
27577 + irqflags, devname, dev_id);
27578 +diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
27579 +index c5286b027f00d..bdcad5e0f057f 100644
27580 +--- a/drivers/pci/probe.c
27581 ++++ b/drivers/pci/probe.c
27582 +@@ -1890,9 +1890,6 @@ int pci_setup_device(struct pci_dev *dev)
27583 +
27584 + dev->broken_intx_masking = pci_intx_mask_broken(dev);
27585 +
27586 +- /* Clear errors left from system firmware */
27587 +- pci_write_config_word(dev, PCI_STATUS, 0xffff);
27588 +-
27589 + switch (dev->hdr_type) { /* header type */
27590 + case PCI_HEADER_TYPE_NORMAL: /* standard header */
27591 + if (class == PCI_CLASS_BRIDGE_PCI)
27592 +diff --git a/drivers/perf/arm_dmc620_pmu.c b/drivers/perf/arm_dmc620_pmu.c
27593 +index 280a6ae3e27cf..54aa4658fb36e 100644
27594 +--- a/drivers/perf/arm_dmc620_pmu.c
27595 ++++ b/drivers/perf/arm_dmc620_pmu.c
27596 +@@ -725,6 +725,8 @@ static struct platform_driver dmc620_pmu_driver = {
27597 +
27598 + static int __init dmc620_pmu_init(void)
27599 + {
27600 ++ int ret;
27601 ++
27602 + cpuhp_state_num = cpuhp_setup_state_multi(CPUHP_AP_ONLINE_DYN,
27603 + DMC620_DRVNAME,
27604 + NULL,
27605 +@@ -732,7 +734,11 @@ static int __init dmc620_pmu_init(void)
27606 + if (cpuhp_state_num < 0)
27607 + return cpuhp_state_num;
27608 +
27609 +- return platform_driver_register(&dmc620_pmu_driver);
27610 ++ ret = platform_driver_register(&dmc620_pmu_driver);
27611 ++ if (ret)
27612 ++ cpuhp_remove_multi_state(cpuhp_state_num);
27613 ++
27614 ++ return ret;
27615 + }
27616 +
27617 + static void __exit dmc620_pmu_exit(void)
27618 +diff --git a/drivers/perf/arm_dsu_pmu.c b/drivers/perf/arm_dsu_pmu.c
27619 +index a36698a90d2f2..54b8ba032c787 100644
27620 +--- a/drivers/perf/arm_dsu_pmu.c
27621 ++++ b/drivers/perf/arm_dsu_pmu.c
27622 +@@ -858,7 +858,11 @@ static int __init dsu_pmu_init(void)
27623 + if (ret < 0)
27624 + return ret;
27625 + dsu_pmu_cpuhp_state = ret;
27626 +- return platform_driver_register(&dsu_pmu_driver);
27627 ++ ret = platform_driver_register(&dsu_pmu_driver);
27628 ++ if (ret)
27629 ++ cpuhp_remove_multi_state(dsu_pmu_cpuhp_state);
27630 ++
27631 ++ return ret;
27632 + }
27633 +
27634 + static void __exit dsu_pmu_exit(void)
27635 +diff --git a/drivers/perf/arm_smmuv3_pmu.c b/drivers/perf/arm_smmuv3_pmu.c
27636 +index 00d4c45a8017d..25a269d431e45 100644
27637 +--- a/drivers/perf/arm_smmuv3_pmu.c
27638 ++++ b/drivers/perf/arm_smmuv3_pmu.c
27639 +@@ -959,6 +959,8 @@ static struct platform_driver smmu_pmu_driver = {
27640 +
27641 + static int __init arm_smmu_pmu_init(void)
27642 + {
27643 ++ int ret;
27644 ++
27645 + cpuhp_state_num = cpuhp_setup_state_multi(CPUHP_AP_ONLINE_DYN,
27646 + "perf/arm/pmcg:online",
27647 + NULL,
27648 +@@ -966,7 +968,11 @@ static int __init arm_smmu_pmu_init(void)
27649 + if (cpuhp_state_num < 0)
27650 + return cpuhp_state_num;
27651 +
27652 +- return platform_driver_register(&smmu_pmu_driver);
27653 ++ ret = platform_driver_register(&smmu_pmu_driver);
27654 ++ if (ret)
27655 ++ cpuhp_remove_multi_state(cpuhp_state_num);
27656 ++
27657 ++ return ret;
27658 + }
27659 + module_init(arm_smmu_pmu_init);
27660 +
27661 +diff --git a/drivers/perf/hisilicon/hisi_pcie_pmu.c b/drivers/perf/hisilicon/hisi_pcie_pmu.c
27662 +index 21771708597db..071e63d9a9ac6 100644
27663 +--- a/drivers/perf/hisilicon/hisi_pcie_pmu.c
27664 ++++ b/drivers/perf/hisilicon/hisi_pcie_pmu.c
27665 +@@ -693,10 +693,10 @@ static struct attribute *hisi_pcie_pmu_events_attr[] = {
27666 + HISI_PCIE_PMU_EVENT_ATTR(rx_mrd_cnt, 0x10210),
27667 + HISI_PCIE_PMU_EVENT_ATTR(tx_mrd_latency, 0x0011),
27668 + HISI_PCIE_PMU_EVENT_ATTR(tx_mrd_cnt, 0x10011),
27669 +- HISI_PCIE_PMU_EVENT_ATTR(rx_mrd_flux, 0x1005),
27670 +- HISI_PCIE_PMU_EVENT_ATTR(rx_mrd_time, 0x11005),
27671 +- HISI_PCIE_PMU_EVENT_ATTR(tx_mrd_flux, 0x2004),
27672 +- HISI_PCIE_PMU_EVENT_ATTR(tx_mrd_time, 0x12004),
27673 ++ HISI_PCIE_PMU_EVENT_ATTR(rx_mrd_flux, 0x0804),
27674 ++ HISI_PCIE_PMU_EVENT_ATTR(rx_mrd_time, 0x10804),
27675 ++ HISI_PCIE_PMU_EVENT_ATTR(tx_mrd_flux, 0x0405),
27676 ++ HISI_PCIE_PMU_EVENT_ATTR(tx_mrd_time, 0x10405),
27677 + NULL
27678 + };
27679 +
27680 +diff --git a/drivers/perf/marvell_cn10k_tad_pmu.c b/drivers/perf/marvell_cn10k_tad_pmu.c
27681 +index 69c3050a4348b..a1166afb37024 100644
27682 +--- a/drivers/perf/marvell_cn10k_tad_pmu.c
27683 ++++ b/drivers/perf/marvell_cn10k_tad_pmu.c
27684 +@@ -408,7 +408,11 @@ static int __init tad_pmu_init(void)
27685 + if (ret < 0)
27686 + return ret;
27687 + tad_pmu_cpuhp_state = ret;
27688 +- return platform_driver_register(&tad_pmu_driver);
27689 ++ ret = platform_driver_register(&tad_pmu_driver);
27690 ++ if (ret)
27691 ++ cpuhp_remove_multi_state(tad_pmu_cpuhp_state);
27692 ++
27693 ++ return ret;
27694 + }
27695 +
27696 + static void __exit tad_pmu_exit(void)
27697 +diff --git a/drivers/phy/broadcom/phy-brcm-usb-init-synopsys.c b/drivers/phy/broadcom/phy-brcm-usb-init-synopsys.c
27698 +index d2524b70ea161..3b374b37b965b 100644
27699 +--- a/drivers/phy/broadcom/phy-brcm-usb-init-synopsys.c
27700 ++++ b/drivers/phy/broadcom/phy-brcm-usb-init-synopsys.c
27701 +@@ -331,13 +331,12 @@ static void usb_uninit_common_7216(struct brcm_usb_init_params *params)
27702 +
27703 + pr_debug("%s\n", __func__);
27704 +
27705 +- if (!params->wake_enabled) {
27706 +- USB_CTRL_SET(ctrl, USB_PM, USB_PWRDN);
27707 +-
27708 ++ if (params->wake_enabled) {
27709 + /* Switch to using slower clock during suspend to save power */
27710 + USB_CTRL_SET(ctrl, USB_PM, XHC_S2_CLK_SWITCH_EN);
27711 +- } else {
27712 + usb_wake_enable_7216(params, true);
27713 ++ } else {
27714 ++ USB_CTRL_SET(ctrl, USB_PM, USB_PWRDN);
27715 + }
27716 + }
27717 +
27718 +@@ -425,7 +424,6 @@ void brcm_usb_dvr_init_7216(struct brcm_usb_init_params *params)
27719 +
27720 + params->family_name = "7216";
27721 + params->ops = &bcm7216_ops;
27722 +- params->suspend_with_clocks = true;
27723 + }
27724 +
27725 + void brcm_usb_dvr_init_7211b0(struct brcm_usb_init_params *params)
27726 +@@ -435,5 +433,4 @@ void brcm_usb_dvr_init_7211b0(struct brcm_usb_init_params *params)
27727 +
27728 + params->family_name = "7211";
27729 + params->ops = &bcm7211b0_ops;
27730 +- params->suspend_with_clocks = true;
27731 + }
27732 +diff --git a/drivers/phy/broadcom/phy-brcm-usb-init.h b/drivers/phy/broadcom/phy-brcm-usb-init.h
27733 +index 1ccb5ddab865c..3236e94988428 100644
27734 +--- a/drivers/phy/broadcom/phy-brcm-usb-init.h
27735 ++++ b/drivers/phy/broadcom/phy-brcm-usb-init.h
27736 +@@ -61,7 +61,6 @@ struct brcm_usb_init_params {
27737 + const struct brcm_usb_init_ops *ops;
27738 + struct regmap *syscon_piarbctl;
27739 + bool wake_enabled;
27740 +- bool suspend_with_clocks;
27741 + };
27742 +
27743 + void brcm_usb_dvr_init_4908(struct brcm_usb_init_params *params);
27744 +diff --git a/drivers/phy/broadcom/phy-brcm-usb.c b/drivers/phy/broadcom/phy-brcm-usb.c
27745 +index 2cb3779fcdf82..2bfd78e2d8fd6 100644
27746 +--- a/drivers/phy/broadcom/phy-brcm-usb.c
27747 ++++ b/drivers/phy/broadcom/phy-brcm-usb.c
27748 +@@ -102,9 +102,9 @@ static int brcm_pm_notifier(struct notifier_block *notifier,
27749 +
27750 + static irqreturn_t brcm_usb_phy_wake_isr(int irq, void *dev_id)
27751 + {
27752 +- struct phy *gphy = dev_id;
27753 ++ struct device *dev = dev_id;
27754 +
27755 +- pm_wakeup_event(&gphy->dev, 0);
27756 ++ pm_wakeup_event(dev, 0);
27757 +
27758 + return IRQ_HANDLED;
27759 + }
27760 +@@ -451,7 +451,7 @@ static int brcm_usb_phy_dvr_init(struct platform_device *pdev,
27761 + if (priv->wake_irq >= 0) {
27762 + err = devm_request_irq(dev, priv->wake_irq,
27763 + brcm_usb_phy_wake_isr, 0,
27764 +- dev_name(dev), gphy);
27765 ++ dev_name(dev), dev);
27766 + if (err < 0)
27767 + return err;
27768 + device_set_wakeup_capable(dev, 1);
27769 +@@ -598,7 +598,7 @@ static int brcm_usb_phy_suspend(struct device *dev)
27770 + * and newer XHCI->2.0-clks/3.0-clks.
27771 + */
27772 +
27773 +- if (!priv->ini.suspend_with_clocks) {
27774 ++ if (!priv->ini.wake_enabled) {
27775 + if (priv->phys[BRCM_USB_PHY_3_0].inited)
27776 + clk_disable_unprepare(priv->usb_30_clk);
27777 + if (priv->phys[BRCM_USB_PHY_2_0].inited ||
27778 +@@ -615,8 +615,10 @@ static int brcm_usb_phy_resume(struct device *dev)
27779 + {
27780 + struct brcm_usb_phy_data *priv = dev_get_drvdata(dev);
27781 +
27782 +- clk_prepare_enable(priv->usb_20_clk);
27783 +- clk_prepare_enable(priv->usb_30_clk);
27784 ++ if (!priv->ini.wake_enabled) {
27785 ++ clk_prepare_enable(priv->usb_20_clk);
27786 ++ clk_prepare_enable(priv->usb_30_clk);
27787 ++ }
27788 + brcm_usb_init_ipp(&priv->ini);
27789 +
27790 + /*
27791 +diff --git a/drivers/phy/marvell/phy-mvebu-a3700-comphy.c b/drivers/phy/marvell/phy-mvebu-a3700-comphy.c
27792 +index 67712c77d806f..d641b345afa35 100644
27793 +--- a/drivers/phy/marvell/phy-mvebu-a3700-comphy.c
27794 ++++ b/drivers/phy/marvell/phy-mvebu-a3700-comphy.c
27795 +@@ -826,6 +826,9 @@ mvebu_a3700_comphy_usb3_power_on(struct mvebu_a3700_comphy_lane *lane)
27796 + if (ret)
27797 + return ret;
27798 +
27799 ++ /* COMPHY register reset (cleared automatically) */
27800 ++ comphy_lane_reg_set(lane, COMPHY_SFT_RESET, SFT_RST, SFT_RST);
27801 ++
27802 + /*
27803 + * 0. Set PHY OTG Control(0x5d034), bit 4, Power up OTG module The
27804 + * register belong to UTMI module, so it is set in UTMI phy driver.
27805 +diff --git a/drivers/phy/qualcomm/phy-qcom-qmp-pcie.c b/drivers/phy/qualcomm/phy-qcom-qmp-pcie.c
27806 +index 2d65e1f56bfc3..51dc4f2de1063 100644
27807 +--- a/drivers/phy/qualcomm/phy-qcom-qmp-pcie.c
27808 ++++ b/drivers/phy/qualcomm/phy-qcom-qmp-pcie.c
27809 +@@ -1329,10 +1329,10 @@ static const struct qmp_phy_init_tbl sm8450_qmp_gen4x2_pcie_rx_tbl[] = {
27810 + };
27811 +
27812 + static const struct qmp_phy_init_tbl sm8450_qmp_gen4x2_pcie_pcs_tbl[] = {
27813 +- QMP_PHY_INIT_CFG(QPHY_V5_PCS_EQ_CONFIG2, 0x16),
27814 +- QMP_PHY_INIT_CFG(QPHY_V5_PCS_EQ_CONFIG3, 0x22),
27815 +- QMP_PHY_INIT_CFG(QPHY_V5_PCS_G3S2_PRE_GAIN, 0x2e),
27816 +- QMP_PHY_INIT_CFG(QPHY_V5_PCS_RX_SIGDET_LVL, 0x99),
27817 ++ QMP_PHY_INIT_CFG(QPHY_V5_20_PCS_EQ_CONFIG4, 0x16),
27818 ++ QMP_PHY_INIT_CFG(QPHY_V5_20_PCS_EQ_CONFIG5, 0x22),
27819 ++ QMP_PHY_INIT_CFG(QPHY_V5_20_PCS_G3S2_PRE_GAIN, 0x2e),
27820 ++ QMP_PHY_INIT_CFG(QPHY_V5_20_PCS_RX_SIGDET_LVL, 0x99),
27821 + };
27822 +
27823 + static const struct qmp_phy_init_tbl sm8450_qmp_gen4x2_pcie_pcs_misc_tbl[] = {
27824 +@@ -1564,6 +1564,7 @@ static const struct qmp_phy_cfg ipq8074_pciephy_gen3_cfg = {
27825 +
27826 + .start_ctrl = SERDES_START | PCS_START,
27827 + .pwrdn_ctrl = SW_PWRDN | REFCLK_DRV_DSBL,
27828 ++ .phy_status = PHYSTATUS,
27829 +
27830 + .has_pwrdn_delay = true,
27831 + .pwrdn_delay_min = 995, /* us */
27832 +@@ -2077,12 +2078,6 @@ static int qcom_qmp_phy_pcie_power_on(struct phy *phy)
27833 + qcom_qmp_phy_pcie_configure(pcs_misc, cfg->regs, cfg->pcs_misc_tbl_sec,
27834 + cfg->pcs_misc_tbl_num_sec);
27835 +
27836 +- /*
27837 +- * Pull out PHY from POWER DOWN state.
27838 +- * This is active low enable signal to power-down PHY.
27839 +- */
27840 +- qphy_setbits(pcs, QPHY_V2_PCS_POWER_DOWN_CONTROL, cfg->pwrdn_ctrl);
27841 +-
27842 + if (cfg->has_pwrdn_delay)
27843 + usleep_range(cfg->pwrdn_delay_min, cfg->pwrdn_delay_max);
27844 +
27845 +diff --git a/drivers/phy/qualcomm/phy-qcom-qmp-pcs-v5_20.h b/drivers/phy/qualcomm/phy-qcom-qmp-pcs-v5_20.h
27846 +new file mode 100644
27847 +index 0000000000000..9a5a20daf62cd
27848 +--- /dev/null
27849 ++++ b/drivers/phy/qualcomm/phy-qcom-qmp-pcs-v5_20.h
27850 +@@ -0,0 +1,14 @@
27851 ++/* SPDX-License-Identifier: GPL-2.0 */
27852 ++/*
27853 ++ * Copyright (c) 2022, Linaro Ltd.
27854 ++ */
27855 ++
27856 ++#ifndef QCOM_PHY_QMP_PCS_V5_20_H_
27857 ++#define QCOM_PHY_QMP_PCS_V5_20_H_
27858 ++
27859 ++#define QPHY_V5_20_PCS_G3S2_PRE_GAIN 0x170
27860 ++#define QPHY_V5_20_PCS_RX_SIGDET_LVL 0x188
27861 ++#define QPHY_V5_20_PCS_EQ_CONFIG4 0x1e0
27862 ++#define QPHY_V5_20_PCS_EQ_CONFIG5 0x1e4
27863 ++
27864 ++#endif
27865 +diff --git a/drivers/phy/qualcomm/phy-qcom-qmp.h b/drivers/phy/qualcomm/phy-qcom-qmp.h
27866 +index b139c8af5e8b1..1a0c6c3026e37 100644
27867 +--- a/drivers/phy/qualcomm/phy-qcom-qmp.h
27868 ++++ b/drivers/phy/qualcomm/phy-qcom-qmp.h
27869 +@@ -37,6 +37,7 @@
27870 + #include "phy-qcom-qmp-pcs-pcie-v4_20.h"
27871 +
27872 + #include "phy-qcom-qmp-pcs-v5.h"
27873 ++#include "phy-qcom-qmp-pcs-v5_20.h"
27874 + #include "phy-qcom-qmp-pcs-pcie-v5.h"
27875 + #include "phy-qcom-qmp-pcs-usb-v5.h"
27876 + #include "phy-qcom-qmp-pcs-ufs-v5.h"
27877 +diff --git a/drivers/pinctrl/mediatek/pinctrl-mt7986.c b/drivers/pinctrl/mediatek/pinctrl-mt7986.c
27878 +index f26869f1a367b..5cb255455a548 100644
27879 +--- a/drivers/pinctrl/mediatek/pinctrl-mt7986.c
27880 ++++ b/drivers/pinctrl/mediatek/pinctrl-mt7986.c
27881 +@@ -316,10 +316,10 @@ static const struct mtk_pin_field_calc mt7986_pin_pupd_range[] = {
27882 + PIN_FIELD_BASE(38, 38, IOCFG_LT_BASE, 0x30, 0x10, 9, 1),
27883 + PIN_FIELD_BASE(39, 40, IOCFG_RB_BASE, 0x60, 0x10, 18, 1),
27884 + PIN_FIELD_BASE(41, 41, IOCFG_RB_BASE, 0x60, 0x10, 12, 1),
27885 +- PIN_FIELD_BASE(42, 43, IOCFG_RB_BASE, 0x60, 0x10, 22, 1),
27886 +- PIN_FIELD_BASE(44, 45, IOCFG_RB_BASE, 0x60, 0x10, 20, 1),
27887 +- PIN_FIELD_BASE(46, 47, IOCFG_RB_BASE, 0x60, 0x10, 26, 1),
27888 +- PIN_FIELD_BASE(48, 49, IOCFG_RB_BASE, 0x60, 0x10, 24, 1),
27889 ++ PIN_FIELD_BASE(42, 43, IOCFG_RB_BASE, 0x60, 0x10, 23, 1),
27890 ++ PIN_FIELD_BASE(44, 45, IOCFG_RB_BASE, 0x60, 0x10, 21, 1),
27891 ++ PIN_FIELD_BASE(46, 47, IOCFG_RB_BASE, 0x60, 0x10, 27, 1),
27892 ++ PIN_FIELD_BASE(48, 49, IOCFG_RB_BASE, 0x60, 0x10, 25, 1),
27893 + PIN_FIELD_BASE(50, 57, IOCFG_RT_BASE, 0x40, 0x10, 2, 1),
27894 + PIN_FIELD_BASE(58, 58, IOCFG_RT_BASE, 0x40, 0x10, 1, 1),
27895 + PIN_FIELD_BASE(59, 59, IOCFG_RT_BASE, 0x40, 0x10, 0, 1),
27896 +@@ -354,10 +354,10 @@ static const struct mtk_pin_field_calc mt7986_pin_r0_range[] = {
27897 + PIN_FIELD_BASE(38, 38, IOCFG_LT_BASE, 0x40, 0x10, 9, 1),
27898 + PIN_FIELD_BASE(39, 40, IOCFG_RB_BASE, 0x70, 0x10, 18, 1),
27899 + PIN_FIELD_BASE(41, 41, IOCFG_RB_BASE, 0x70, 0x10, 12, 1),
27900 +- PIN_FIELD_BASE(42, 43, IOCFG_RB_BASE, 0x70, 0x10, 22, 1),
27901 +- PIN_FIELD_BASE(44, 45, IOCFG_RB_BASE, 0x70, 0x10, 20, 1),
27902 +- PIN_FIELD_BASE(46, 47, IOCFG_RB_BASE, 0x70, 0x10, 26, 1),
27903 +- PIN_FIELD_BASE(48, 49, IOCFG_RB_BASE, 0x70, 0x10, 24, 1),
27904 ++ PIN_FIELD_BASE(42, 43, IOCFG_RB_BASE, 0x70, 0x10, 23, 1),
27905 ++ PIN_FIELD_BASE(44, 45, IOCFG_RB_BASE, 0x70, 0x10, 21, 1),
27906 ++ PIN_FIELD_BASE(46, 47, IOCFG_RB_BASE, 0x70, 0x10, 27, 1),
27907 ++ PIN_FIELD_BASE(48, 49, IOCFG_RB_BASE, 0x70, 0x10, 25, 1),
27908 + PIN_FIELD_BASE(50, 57, IOCFG_RT_BASE, 0x50, 0x10, 2, 1),
27909 + PIN_FIELD_BASE(58, 58, IOCFG_RT_BASE, 0x50, 0x10, 1, 1),
27910 + PIN_FIELD_BASE(59, 59, IOCFG_RT_BASE, 0x50, 0x10, 0, 1),
27911 +@@ -392,10 +392,10 @@ static const struct mtk_pin_field_calc mt7986_pin_r1_range[] = {
27912 + PIN_FIELD_BASE(38, 38, IOCFG_LT_BASE, 0x50, 0x10, 9, 1),
27913 + PIN_FIELD_BASE(39, 40, IOCFG_RB_BASE, 0x80, 0x10, 18, 1),
27914 + PIN_FIELD_BASE(41, 41, IOCFG_RB_BASE, 0x80, 0x10, 12, 1),
27915 +- PIN_FIELD_BASE(42, 43, IOCFG_RB_BASE, 0x80, 0x10, 22, 1),
27916 +- PIN_FIELD_BASE(44, 45, IOCFG_RB_BASE, 0x80, 0x10, 20, 1),
27917 +- PIN_FIELD_BASE(46, 47, IOCFG_RB_BASE, 0x80, 0x10, 26, 1),
27918 +- PIN_FIELD_BASE(48, 49, IOCFG_RB_BASE, 0x80, 0x10, 24, 1),
27919 ++ PIN_FIELD_BASE(42, 43, IOCFG_RB_BASE, 0x80, 0x10, 23, 1),
27920 ++ PIN_FIELD_BASE(44, 45, IOCFG_RB_BASE, 0x80, 0x10, 21, 1),
27921 ++ PIN_FIELD_BASE(46, 47, IOCFG_RB_BASE, 0x80, 0x10, 27, 1),
27922 ++ PIN_FIELD_BASE(48, 49, IOCFG_RB_BASE, 0x80, 0x10, 25, 1),
27923 + PIN_FIELD_BASE(50, 57, IOCFG_RT_BASE, 0x60, 0x10, 2, 1),
27924 + PIN_FIELD_BASE(58, 58, IOCFG_RT_BASE, 0x60, 0x10, 1, 1),
27925 + PIN_FIELD_BASE(59, 59, IOCFG_RT_BASE, 0x60, 0x10, 0, 1),
27926 +diff --git a/drivers/pinctrl/pinconf-generic.c b/drivers/pinctrl/pinconf-generic.c
27927 +index 415d1df8f46a5..365c4b0ca4654 100644
27928 +--- a/drivers/pinctrl/pinconf-generic.c
27929 ++++ b/drivers/pinctrl/pinconf-generic.c
27930 +@@ -395,8 +395,10 @@ int pinconf_generic_dt_node_to_map(struct pinctrl_dev *pctldev,
27931 + for_each_available_child_of_node(np_config, np) {
27932 + ret = pinconf_generic_dt_subnode_to_map(pctldev, np, map,
27933 + &reserved_maps, num_maps, type);
27934 +- if (ret < 0)
27935 ++ if (ret < 0) {
27936 ++ of_node_put(np);
27937 + goto exit;
27938 ++ }
27939 + }
27940 + return 0;
27941 +
27942 +diff --git a/drivers/pinctrl/pinctrl-k210.c b/drivers/pinctrl/pinctrl-k210.c
27943 +index ecab6bf63dc6d..ad4db99094a79 100644
27944 +--- a/drivers/pinctrl/pinctrl-k210.c
27945 ++++ b/drivers/pinctrl/pinctrl-k210.c
27946 +@@ -862,8 +862,10 @@ static int k210_pinctrl_dt_node_to_map(struct pinctrl_dev *pctldev,
27947 + for_each_available_child_of_node(np_config, np) {
27948 + ret = k210_pinctrl_dt_subnode_to_map(pctldev, np, map,
27949 + &reserved_maps, num_maps);
27950 +- if (ret < 0)
27951 ++ if (ret < 0) {
27952 ++ of_node_put(np);
27953 + goto err;
27954 ++ }
27955 + }
27956 + return 0;
27957 +
27958 +diff --git a/drivers/pinctrl/pinctrl-ocelot.c b/drivers/pinctrl/pinctrl-ocelot.c
27959 +index 105771ff82e62..19a61f697e99c 100644
27960 +--- a/drivers/pinctrl/pinctrl-ocelot.c
27961 ++++ b/drivers/pinctrl/pinctrl-ocelot.c
27962 +@@ -2046,6 +2046,11 @@ static struct regmap *ocelot_pinctrl_create_pincfg(struct platform_device *pdev,
27963 + return devm_regmap_init_mmio(&pdev->dev, base, &regmap_config);
27964 + }
27965 +
27966 ++static void ocelot_destroy_workqueue(void *data)
27967 ++{
27968 ++ destroy_workqueue(data);
27969 ++}
27970 ++
27971 + static int ocelot_pinctrl_probe(struct platform_device *pdev)
27972 + {
27973 + const struct ocelot_match_data *data;
27974 +@@ -2078,6 +2083,11 @@ static int ocelot_pinctrl_probe(struct platform_device *pdev)
27975 + if (!info->wq)
27976 + return -ENOMEM;
27977 +
27978 ++ ret = devm_add_action_or_reset(dev, ocelot_destroy_workqueue,
27979 ++ info->wq);
27980 ++ if (ret)
27981 ++ return ret;
27982 ++
27983 + info->pincfg_data = &data->pincfg_data;
27984 +
27985 + reset = devm_reset_control_get_optional_shared(dev, "switch");
27986 +@@ -2125,15 +2135,6 @@ static int ocelot_pinctrl_probe(struct platform_device *pdev)
27987 + return 0;
27988 + }
27989 +
27990 +-static int ocelot_pinctrl_remove(struct platform_device *pdev)
27991 +-{
27992 +- struct ocelot_pinctrl *info = platform_get_drvdata(pdev);
27993 +-
27994 +- destroy_workqueue(info->wq);
27995 +-
27996 +- return 0;
27997 +-}
27998 +-
27999 + static struct platform_driver ocelot_pinctrl_driver = {
28000 + .driver = {
28001 + .name = "pinctrl-ocelot",
28002 +@@ -2141,7 +2142,6 @@ static struct platform_driver ocelot_pinctrl_driver = {
28003 + .suppress_bind_attrs = true,
28004 + },
28005 + .probe = ocelot_pinctrl_probe,
28006 +- .remove = ocelot_pinctrl_remove,
28007 + };
28008 + module_platform_driver(ocelot_pinctrl_driver);
28009 + MODULE_LICENSE("Dual MIT/GPL");
28010 +diff --git a/drivers/pinctrl/pinctrl-thunderbay.c b/drivers/pinctrl/pinctrl-thunderbay.c
28011 +index 9328b17485cf0..590bbbf619afc 100644
28012 +--- a/drivers/pinctrl/pinctrl-thunderbay.c
28013 ++++ b/drivers/pinctrl/pinctrl-thunderbay.c
28014 +@@ -808,7 +808,7 @@ static int thunderbay_add_functions(struct thunderbay_pinctrl *tpc, struct funct
28015 + funcs[i].num_group_names,
28016 + funcs[i].data);
28017 + }
28018 +- kfree(funcs);
28019 ++
28020 + return 0;
28021 + }
28022 +
28023 +@@ -817,6 +817,7 @@ static int thunderbay_build_functions(struct thunderbay_pinctrl *tpc)
28024 + struct function_desc *thunderbay_funcs;
28025 + void *ptr;
28026 + int pin;
28027 ++ int ret;
28028 +
28029 + /*
28030 + * Allocate maximum possible number of functions. Assume every pin
28031 +@@ -860,7 +861,10 @@ static int thunderbay_build_functions(struct thunderbay_pinctrl *tpc)
28032 + return -ENOMEM;
28033 +
28034 + thunderbay_funcs = ptr;
28035 +- return thunderbay_add_functions(tpc, thunderbay_funcs);
28036 ++ ret = thunderbay_add_functions(tpc, thunderbay_funcs);
28037 ++
28038 ++ kfree(thunderbay_funcs);
28039 ++ return ret;
28040 + }
28041 +
28042 + static int thunderbay_pinconf_set_tristate(struct thunderbay_pinctrl *tpc,
28043 +diff --git a/drivers/platform/chrome/cros_ec_typec.c b/drivers/platform/chrome/cros_ec_typec.c
28044 +index dc5722db20661..a54bf964521fb 100644
28045 +--- a/drivers/platform/chrome/cros_ec_typec.c
28046 ++++ b/drivers/platform/chrome/cros_ec_typec.c
28047 +@@ -20,6 +20,7 @@
28048 + #include <linux/usb/typec_altmode.h>
28049 + #include <linux/usb/typec_dp.h>
28050 + #include <linux/usb/typec_mux.h>
28051 ++#include <linux/usb/typec_retimer.h>
28052 + #include <linux/usb/typec_tbt.h>
28053 + #include <linux/usb/role.h>
28054 +
28055 +@@ -56,6 +57,7 @@ struct cros_typec_port {
28056 + struct usb_pd_identity c_identity;
28057 + struct typec_switch *ori_sw;
28058 + struct typec_mux *mux;
28059 ++ struct typec_retimer *retimer;
28060 + struct usb_role_switch *role_sw;
28061 +
28062 + /* Variables keeping track of switch state. */
28063 +@@ -144,6 +146,12 @@ static int cros_typec_get_switch_handles(struct cros_typec_port *port,
28064 + goto mux_err;
28065 + }
28066 +
28067 ++ port->retimer = fwnode_typec_retimer_get(fwnode);
28068 ++ if (IS_ERR(port->retimer)) {
28069 ++ dev_dbg(dev, "Retimer handle not found.\n");
28070 ++ goto retimer_sw_err;
28071 ++ }
28072 ++
28073 + port->ori_sw = fwnode_typec_switch_get(fwnode);
28074 + if (IS_ERR(port->ori_sw)) {
28075 + dev_dbg(dev, "Orientation switch handle not found.\n");
28076 +@@ -159,12 +167,15 @@ static int cros_typec_get_switch_handles(struct cros_typec_port *port,
28077 + return 0;
28078 +
28079 + role_sw_err:
28080 +- usb_role_switch_put(port->role_sw);
28081 +-ori_sw_err:
28082 + typec_switch_put(port->ori_sw);
28083 +-mux_err:
28084 ++ port->ori_sw = NULL;
28085 ++ori_sw_err:
28086 ++ typec_retimer_put(port->retimer);
28087 ++ port->retimer = NULL;
28088 ++retimer_sw_err:
28089 + typec_mux_put(port->mux);
28090 +-
28091 ++ port->mux = NULL;
28092 ++mux_err:
28093 + return -ENODEV;
28094 + }
28095 +
28096 +@@ -207,6 +218,21 @@ static void cros_typec_unregister_altmodes(struct cros_typec_data *typec, int po
28097 + }
28098 + }
28099 +
28100 ++/*
28101 ++ * Map the Type-C Mux state to retimer state and call the retimer set function. We need this
28102 ++ * because we re-use the Type-C mux state for retimers.
28103 ++ */
28104 ++static int cros_typec_retimer_set(struct typec_retimer *retimer, struct typec_mux_state state)
28105 ++{
28106 ++ struct typec_retimer_state rstate = {
28107 ++ .alt = state.alt,
28108 ++ .mode = state.mode,
28109 ++ .data = state.data,
28110 ++ };
28111 ++
28112 ++ return typec_retimer_set(retimer, &rstate);
28113 ++}
28114 ++
28115 + static int cros_typec_usb_disconnect_state(struct cros_typec_port *port)
28116 + {
28117 + port->state.alt = NULL;
28118 +@@ -215,6 +241,7 @@ static int cros_typec_usb_disconnect_state(struct cros_typec_port *port)
28119 +
28120 + usb_role_switch_set_role(port->role_sw, USB_ROLE_NONE);
28121 + typec_switch_set(port->ori_sw, TYPEC_ORIENTATION_NONE);
28122 ++ cros_typec_retimer_set(port->retimer, port->state);
28123 +
28124 + return typec_mux_set(port->mux, &port->state);
28125 + }
28126 +@@ -412,9 +439,14 @@ unregister_ports:
28127 +
28128 + static int cros_typec_usb_safe_state(struct cros_typec_port *port)
28129 + {
28130 ++ int ret;
28131 + port->state.mode = TYPEC_STATE_SAFE;
28132 +
28133 +- return typec_mux_set(port->mux, &port->state);
28134 ++ ret = cros_typec_retimer_set(port->retimer, port->state);
28135 ++ if (!ret)
28136 ++ ret = typec_mux_set(port->mux, &port->state);
28137 ++
28138 ++ return ret;
28139 + }
28140 +
28141 + /*
28142 +@@ -511,7 +543,11 @@ static int cros_typec_enable_dp(struct cros_typec_data *typec,
28143 + port->state.data = &dp_data;
28144 + port->state.mode = TYPEC_MODAL_STATE(ffs(pd_ctrl->dp_mode));
28145 +
28146 +- return typec_mux_set(port->mux, &port->state);
28147 ++ ret = cros_typec_retimer_set(port->retimer, port->state);
28148 ++ if (!ret)
28149 ++ ret = typec_mux_set(port->mux, &port->state);
28150 ++
28151 ++ return ret;
28152 + }
28153 +
28154 + static int cros_typec_enable_usb4(struct cros_typec_data *typec,
28155 +@@ -600,7 +636,10 @@ static int cros_typec_configure_mux(struct cros_typec_data *typec, int port_num,
28156 + } else if (port->mux_flags & USB_PD_MUX_USB_ENABLED) {
28157 + port->state.alt = NULL;
28158 + port->state.mode = TYPEC_STATE_USB;
28159 +- ret = typec_mux_set(port->mux, &port->state);
28160 ++
28161 ++ ret = cros_typec_retimer_set(port->retimer, port->state);
28162 ++ if (!ret)
28163 ++ ret = typec_mux_set(port->mux, &port->state);
28164 + } else {
28165 + dev_dbg(typec->dev,
28166 + "Unrecognized mode requested, mux flags: %x\n",
28167 +diff --git a/drivers/platform/chrome/cros_usbpd_notify.c b/drivers/platform/chrome/cros_usbpd_notify.c
28168 +index 4b5a81c9dc6da..10670b6588e3e 100644
28169 +--- a/drivers/platform/chrome/cros_usbpd_notify.c
28170 ++++ b/drivers/platform/chrome/cros_usbpd_notify.c
28171 +@@ -239,7 +239,11 @@ static int __init cros_usbpd_notify_init(void)
28172 + return ret;
28173 +
28174 + #ifdef CONFIG_ACPI
28175 +- platform_driver_register(&cros_usbpd_notify_acpi_driver);
28176 ++ ret = platform_driver_register(&cros_usbpd_notify_acpi_driver);
28177 ++ if (ret) {
28178 ++ platform_driver_unregister(&cros_usbpd_notify_plat_driver);
28179 ++ return ret;
28180 ++ }
28181 + #endif
28182 + return 0;
28183 + }
28184 +diff --git a/drivers/platform/mellanox/mlxbf-pmc.c b/drivers/platform/mellanox/mlxbf-pmc.c
28185 +index 65b4a819f1bdf..c2c9b0d3244cb 100644
28186 +--- a/drivers/platform/mellanox/mlxbf-pmc.c
28187 ++++ b/drivers/platform/mellanox/mlxbf-pmc.c
28188 +@@ -358,7 +358,7 @@ static const struct mlxbf_pmc_events mlxbf_pmc_hnfnet_events[] = {
28189 + { 0x32, "DDN_DIAG_W_INGRESS" },
28190 + { 0x33, "DDN_DIAG_C_INGRESS" },
28191 + { 0x34, "DDN_DIAG_CORE_SENT" },
28192 +- { 0x35, "NDN_DIAG_S_OUT_OF_CRED" },
28193 ++ { 0x35, "NDN_DIAG_N_OUT_OF_CRED" },
28194 + { 0x36, "NDN_DIAG_S_OUT_OF_CRED" },
28195 + { 0x37, "NDN_DIAG_E_OUT_OF_CRED" },
28196 + { 0x38, "NDN_DIAG_W_OUT_OF_CRED" },
28197 +diff --git a/drivers/platform/x86/huawei-wmi.c b/drivers/platform/x86/huawei-wmi.c
28198 +index eac3e6b4ea113..935562c870c3d 100644
28199 +--- a/drivers/platform/x86/huawei-wmi.c
28200 ++++ b/drivers/platform/x86/huawei-wmi.c
28201 +@@ -760,6 +760,9 @@ static int huawei_wmi_input_setup(struct device *dev,
28202 + const char *guid,
28203 + struct input_dev **idev)
28204 + {
28205 ++ acpi_status status;
28206 ++ int err;
28207 ++
28208 + *idev = devm_input_allocate_device(dev);
28209 + if (!*idev)
28210 + return -ENOMEM;
28211 +@@ -769,10 +772,19 @@ static int huawei_wmi_input_setup(struct device *dev,
28212 + (*idev)->id.bustype = BUS_HOST;
28213 + (*idev)->dev.parent = dev;
28214 +
28215 +- return sparse_keymap_setup(*idev, huawei_wmi_keymap, NULL) ||
28216 +- input_register_device(*idev) ||
28217 +- wmi_install_notify_handler(guid, huawei_wmi_input_notify,
28218 +- *idev);
28219 ++ err = sparse_keymap_setup(*idev, huawei_wmi_keymap, NULL);
28220 ++ if (err)
28221 ++ return err;
28222 ++
28223 ++ err = input_register_device(*idev);
28224 ++ if (err)
28225 ++ return err;
28226 ++
28227 ++ status = wmi_install_notify_handler(guid, huawei_wmi_input_notify, *idev);
28228 ++ if (ACPI_FAILURE(status))
28229 ++ return -EIO;
28230 ++
28231 ++ return 0;
28232 + }
28233 +
28234 + static void huawei_wmi_input_exit(struct device *dev, const char *guid)
28235 +diff --git a/drivers/platform/x86/intel/int3472/clk_and_regulator.c b/drivers/platform/x86/intel/int3472/clk_and_regulator.c
28236 +index 1cf958983e868..b2342b3d78c72 100644
28237 +--- a/drivers/platform/x86/intel/int3472/clk_and_regulator.c
28238 ++++ b/drivers/platform/x86/intel/int3472/clk_and_regulator.c
28239 +@@ -185,7 +185,8 @@ int skl_int3472_register_regulator(struct int3472_discrete_device *int3472,
28240 + cfg.init_data = &init_data;
28241 + cfg.ena_gpiod = int3472->regulator.gpio;
28242 +
28243 +- int3472->regulator.rdev = regulator_register(&int3472->regulator.rdesc,
28244 ++ int3472->regulator.rdev = regulator_register(int3472->dev,
28245 ++ &int3472->regulator.rdesc,
28246 + &cfg);
28247 + if (IS_ERR(int3472->regulator.rdev)) {
28248 + ret = PTR_ERR(int3472->regulator.rdev);
28249 +diff --git a/drivers/platform/x86/intel_scu_ipc.c b/drivers/platform/x86/intel_scu_ipc.c
28250 +index 7cc9089d1e14f..e7a3e34028178 100644
28251 +--- a/drivers/platform/x86/intel_scu_ipc.c
28252 ++++ b/drivers/platform/x86/intel_scu_ipc.c
28253 +@@ -583,7 +583,6 @@ __intel_scu_ipc_register(struct device *parent,
28254 + scu->dev.parent = parent;
28255 + scu->dev.class = &intel_scu_ipc_class;
28256 + scu->dev.release = intel_scu_ipc_release;
28257 +- dev_set_name(&scu->dev, "intel_scu_ipc");
28258 +
28259 + if (!request_mem_region(scu_data->mem.start, resource_size(&scu_data->mem),
28260 + "intel_scu_ipc")) {
28261 +@@ -612,6 +611,7 @@ __intel_scu_ipc_register(struct device *parent,
28262 + * After this point intel_scu_ipc_release() takes care of
28263 + * releasing the SCU IPC resources once refcount drops to zero.
28264 + */
28265 ++ dev_set_name(&scu->dev, "intel_scu_ipc");
28266 + err = device_register(&scu->dev);
28267 + if (err) {
28268 + put_device(&scu->dev);
28269 +diff --git a/drivers/platform/x86/mxm-wmi.c b/drivers/platform/x86/mxm-wmi.c
28270 +index 9a19fbd2f7341..9a457956025a5 100644
28271 +--- a/drivers/platform/x86/mxm-wmi.c
28272 ++++ b/drivers/platform/x86/mxm-wmi.c
28273 +@@ -35,13 +35,11 @@ int mxm_wmi_call_mxds(int adapter)
28274 + .xarg = 1,
28275 + };
28276 + struct acpi_buffer input = { (acpi_size)sizeof(args), &args };
28277 +- struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL };
28278 + acpi_status status;
28279 +
28280 + printk("calling mux switch %d\n", adapter);
28281 +
28282 +- status = wmi_evaluate_method(MXM_WMMX_GUID, 0x0, adapter, &input,
28283 +- &output);
28284 ++ status = wmi_evaluate_method(MXM_WMMX_GUID, 0x0, adapter, &input, NULL);
28285 +
28286 + if (ACPI_FAILURE(status))
28287 + return status;
28288 +@@ -60,13 +58,11 @@ int mxm_wmi_call_mxmx(int adapter)
28289 + .xarg = 1,
28290 + };
28291 + struct acpi_buffer input = { (acpi_size)sizeof(args), &args };
28292 +- struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL };
28293 + acpi_status status;
28294 +
28295 + printk("calling mux switch %d\n", adapter);
28296 +
28297 +- status = wmi_evaluate_method(MXM_WMMX_GUID, 0x0, adapter, &input,
28298 +- &output);
28299 ++ status = wmi_evaluate_method(MXM_WMMX_GUID, 0x0, adapter, &input, NULL);
28300 +
28301 + if (ACPI_FAILURE(status))
28302 + return status;
28303 +diff --git a/drivers/pnp/core.c b/drivers/pnp/core.c
28304 +index 4df5aa6a309c3..6a60c5d83383b 100644
28305 +--- a/drivers/pnp/core.c
28306 ++++ b/drivers/pnp/core.c
28307 +@@ -148,14 +148,14 @@ struct pnp_dev *pnp_alloc_dev(struct pnp_protocol *protocol, int id,
28308 + dev->dev.coherent_dma_mask = dev->dma_mask;
28309 + dev->dev.release = &pnp_release_device;
28310 +
28311 +- dev_set_name(&dev->dev, "%02x:%02x", dev->protocol->number, dev->number);
28312 +-
28313 + dev_id = pnp_add_id(dev, pnpid);
28314 + if (!dev_id) {
28315 + kfree(dev);
28316 + return NULL;
28317 + }
28318 +
28319 ++ dev_set_name(&dev->dev, "%02x:%02x", dev->protocol->number, dev->number);
28320 ++
28321 + return dev;
28322 + }
28323 +
28324 +diff --git a/drivers/power/supply/ab8500_charger.c b/drivers/power/supply/ab8500_charger.c
28325 +index c19c50442761d..58757a5799f8b 100644
28326 +--- a/drivers/power/supply/ab8500_charger.c
28327 ++++ b/drivers/power/supply/ab8500_charger.c
28328 +@@ -3719,7 +3719,14 @@ static int __init ab8500_charger_init(void)
28329 + if (ret)
28330 + return ret;
28331 +
28332 +- return platform_driver_register(&ab8500_charger_driver);
28333 ++ ret = platform_driver_register(&ab8500_charger_driver);
28334 ++ if (ret) {
28335 ++ platform_unregister_drivers(ab8500_charger_component_drivers,
28336 ++ ARRAY_SIZE(ab8500_charger_component_drivers));
28337 ++ return ret;
28338 ++ }
28339 ++
28340 ++ return 0;
28341 + }
28342 +
28343 + static void __exit ab8500_charger_exit(void)
28344 +diff --git a/drivers/power/supply/bq25890_charger.c b/drivers/power/supply/bq25890_charger.c
28345 +index 852a6fec4339b..92fab662a51d4 100644
28346 +--- a/drivers/power/supply/bq25890_charger.c
28347 ++++ b/drivers/power/supply/bq25890_charger.c
28348 +@@ -1019,6 +1019,36 @@ static const struct regulator_desc bq25890_vbus_desc = {
28349 + .fixed_uV = 5000000,
28350 + .n_voltages = 1,
28351 + };
28352 ++
28353 ++static int bq25890_register_regulator(struct bq25890_device *bq)
28354 ++{
28355 ++ struct bq25890_platform_data *pdata = dev_get_platdata(bq->dev);
28356 ++ struct regulator_config cfg = {
28357 ++ .dev = bq->dev,
28358 ++ .driver_data = bq,
28359 ++ };
28360 ++ struct regulator_dev *reg;
28361 ++
28362 ++ if (!IS_ERR_OR_NULL(bq->usb_phy))
28363 ++ return 0;
28364 ++
28365 ++ if (pdata)
28366 ++ cfg.init_data = pdata->regulator_init_data;
28367 ++
28368 ++ reg = devm_regulator_register(bq->dev, &bq25890_vbus_desc, &cfg);
28369 ++ if (IS_ERR(reg)) {
28370 ++ return dev_err_probe(bq->dev, PTR_ERR(reg),
28371 ++ "registering vbus regulator");
28372 ++ }
28373 ++
28374 ++ return 0;
28375 ++}
28376 ++#else
28377 ++static inline int
28378 ++bq25890_register_regulator(struct bq25890_device *bq)
28379 ++{
28380 ++ return 0;
28381 ++}
28382 + #endif
28383 +
28384 + static int bq25890_get_chip_version(struct bq25890_device *bq)
28385 +@@ -1159,8 +1189,14 @@ static int bq25890_fw_probe(struct bq25890_device *bq)
28386 + return 0;
28387 + }
28388 +
28389 +-static int bq25890_probe(struct i2c_client *client,
28390 +- const struct i2c_device_id *id)
28391 ++static void bq25890_non_devm_cleanup(void *data)
28392 ++{
28393 ++ struct bq25890_device *bq = data;
28394 ++
28395 ++ cancel_delayed_work_sync(&bq->pump_express_work);
28396 ++}
28397 ++
28398 ++static int bq25890_probe(struct i2c_client *client)
28399 + {
28400 + struct device *dev = &client->dev;
28401 + struct bq25890_device *bq;
28402 +@@ -1214,27 +1250,24 @@ static int bq25890_probe(struct i2c_client *client,
28403 +
28404 + /* OTG reporting */
28405 + bq->usb_phy = devm_usb_get_phy(dev, USB_PHY_TYPE_USB2);
28406 ++
28407 ++ /*
28408 ++ * This must be before bq25890_power_supply_init(), so that it runs
28409 ++ * after devm unregisters the power_supply.
28410 ++ */
28411 ++ ret = devm_add_action_or_reset(dev, bq25890_non_devm_cleanup, bq);
28412 ++ if (ret)
28413 ++ return ret;
28414 ++
28415 ++ ret = bq25890_register_regulator(bq);
28416 ++ if (ret)
28417 ++ return ret;
28418 ++
28419 + if (!IS_ERR_OR_NULL(bq->usb_phy)) {
28420 + INIT_WORK(&bq->usb_work, bq25890_usb_work);
28421 + bq->usb_nb.notifier_call = bq25890_usb_notifier;
28422 + usb_register_notifier(bq->usb_phy, &bq->usb_nb);
28423 + }
28424 +-#ifdef CONFIG_REGULATOR
28425 +- else {
28426 +- struct bq25890_platform_data *pdata = dev_get_platdata(dev);
28427 +- struct regulator_config cfg = { };
28428 +- struct regulator_dev *reg;
28429 +-
28430 +- cfg.dev = dev;
28431 +- cfg.driver_data = bq;
28432 +- if (pdata)
28433 +- cfg.init_data = pdata->regulator_init_data;
28434 +-
28435 +- reg = devm_regulator_register(dev, &bq25890_vbus_desc, &cfg);
28436 +- if (IS_ERR(reg))
28437 +- return dev_err_probe(dev, PTR_ERR(reg), "registering regulator");
28438 +- }
28439 +-#endif
28440 +
28441 + ret = bq25890_power_supply_init(bq);
28442 + if (ret < 0) {
28443 +@@ -1372,7 +1405,7 @@ static struct i2c_driver bq25890_driver = {
28444 + .acpi_match_table = ACPI_PTR(bq25890_acpi_match),
28445 + .pm = &bq25890_pm,
28446 + },
28447 +- .probe = bq25890_probe,
28448 ++ .probe_new = bq25890_probe,
28449 + .remove = bq25890_remove,
28450 + .shutdown = bq25890_shutdown,
28451 + .id_table = bq25890_i2c_ids,
28452 +diff --git a/drivers/power/supply/cw2015_battery.c b/drivers/power/supply/cw2015_battery.c
28453 +index 728e2a6cc9c31..473522b4326ad 100644
28454 +--- a/drivers/power/supply/cw2015_battery.c
28455 ++++ b/drivers/power/supply/cw2015_battery.c
28456 +@@ -21,6 +21,7 @@
28457 + #include <linux/regmap.h>
28458 + #include <linux/time.h>
28459 + #include <linux/workqueue.h>
28460 ++#include <linux/devm-helpers.h>
28461 +
28462 + #define CW2015_SIZE_BATINFO 64
28463 +
28464 +@@ -698,7 +699,11 @@ static int cw_bat_probe(struct i2c_client *client)
28465 + }
28466 +
28467 + cw_bat->battery_workqueue = create_singlethread_workqueue("rk_battery");
28468 +- INIT_DELAYED_WORK(&cw_bat->battery_delay_work, cw_bat_work);
28469 ++ if (!cw_bat->battery_workqueue)
28470 ++ return -ENOMEM;
28471 ++
28472 ++ devm_delayed_work_autocancel(&client->dev,
28473 ++ &cw_bat->battery_delay_work, cw_bat_work);
28474 + queue_delayed_work(cw_bat->battery_workqueue,
28475 + &cw_bat->battery_delay_work, msecs_to_jiffies(10));
28476 + return 0;
28477 +@@ -725,15 +730,6 @@ static int __maybe_unused cw_bat_resume(struct device *dev)
28478 +
28479 + static SIMPLE_DEV_PM_OPS(cw_bat_pm_ops, cw_bat_suspend, cw_bat_resume);
28480 +
28481 +-static int cw_bat_remove(struct i2c_client *client)
28482 +-{
28483 +- struct cw_battery *cw_bat = i2c_get_clientdata(client);
28484 +-
28485 +- cancel_delayed_work_sync(&cw_bat->battery_delay_work);
28486 +- power_supply_put_battery_info(cw_bat->rk_bat, cw_bat->battery);
28487 +- return 0;
28488 +-}
28489 +-
28490 + static const struct i2c_device_id cw_bat_id_table[] = {
28491 + { "cw2015", 0 },
28492 + { }
28493 +@@ -752,7 +748,6 @@ static struct i2c_driver cw_bat_driver = {
28494 + .pm = &cw_bat_pm_ops,
28495 + },
28496 + .probe_new = cw_bat_probe,
28497 +- .remove = cw_bat_remove,
28498 + .id_table = cw_bat_id_table,
28499 + };
28500 +
28501 +diff --git a/drivers/power/supply/power_supply_core.c b/drivers/power/supply/power_supply_core.c
28502 +index 4b5fb172fa994..01d1ac79d982e 100644
28503 +--- a/drivers/power/supply/power_supply_core.c
28504 ++++ b/drivers/power/supply/power_supply_core.c
28505 +@@ -750,6 +750,11 @@ int power_supply_get_battery_info(struct power_supply *psy,
28506 + int i, tab_len, size;
28507 +
28508 + propname = kasprintf(GFP_KERNEL, "ocv-capacity-table-%d", index);
28509 ++ if (!propname) {
28510 ++ power_supply_put_battery_info(psy, info);
28511 ++ err = -ENOMEM;
28512 ++ goto out_put_node;
28513 ++ }
28514 + list = of_get_property(battery_np, propname, &size);
28515 + if (!list || !size) {
28516 + dev_err(&psy->dev, "failed to get %s\n", propname);
28517 +@@ -1387,8 +1392,8 @@ create_triggers_failed:
28518 + register_cooler_failed:
28519 + psy_unregister_thermal(psy);
28520 + register_thermal_failed:
28521 +- device_del(dev);
28522 + wakeup_init_failed:
28523 ++ device_del(dev);
28524 + device_add_failed:
28525 + check_supplies_failed:
28526 + dev_set_name_failed:
28527 +diff --git a/drivers/power/supply/z2_battery.c b/drivers/power/supply/z2_battery.c
28528 +index 7ed4e4bb26eca..fd33cdf9cf12c 100644
28529 +--- a/drivers/power/supply/z2_battery.c
28530 ++++ b/drivers/power/supply/z2_battery.c
28531 +@@ -206,10 +206,12 @@ static int z2_batt_probe(struct i2c_client *client,
28532 +
28533 + charger->charge_gpiod = devm_gpiod_get_optional(&client->dev,
28534 + NULL, GPIOD_IN);
28535 +- if (IS_ERR(charger->charge_gpiod))
28536 +- return dev_err_probe(&client->dev,
28537 ++ if (IS_ERR(charger->charge_gpiod)) {
28538 ++ ret = dev_err_probe(&client->dev,
28539 + PTR_ERR(charger->charge_gpiod),
28540 + "failed to get charge GPIO\n");
28541 ++ goto err;
28542 ++ }
28543 +
28544 + if (charger->charge_gpiod) {
28545 + gpiod_set_consumer_name(charger->charge_gpiod, "BATT CHRG");
28546 +diff --git a/drivers/pwm/pwm-mediatek.c b/drivers/pwm/pwm-mediatek.c
28547 +index 6901a44dc428d..a337b47dc2f7d 100644
28548 +--- a/drivers/pwm/pwm-mediatek.c
28549 ++++ b/drivers/pwm/pwm-mediatek.c
28550 +@@ -296,7 +296,7 @@ static const struct pwm_mediatek_of_data mt6795_pwm_data = {
28551 + static const struct pwm_mediatek_of_data mt7622_pwm_data = {
28552 + .num_pwms = 6,
28553 + .pwm45_fixup = false,
28554 +- .has_ck_26m_sel = false,
28555 ++ .has_ck_26m_sel = true,
28556 + };
28557 +
28558 + static const struct pwm_mediatek_of_data mt7623_pwm_data = {
28559 +diff --git a/drivers/pwm/pwm-mtk-disp.c b/drivers/pwm/pwm-mtk-disp.c
28560 +index c605013e4114c..3fbb4bae93a4e 100644
28561 +--- a/drivers/pwm/pwm-mtk-disp.c
28562 ++++ b/drivers/pwm/pwm-mtk-disp.c
28563 +@@ -178,7 +178,7 @@ static void mtk_disp_pwm_get_state(struct pwm_chip *chip,
28564 + {
28565 + struct mtk_disp_pwm *mdp = to_mtk_disp_pwm(chip);
28566 + u64 rate, period, high_width;
28567 +- u32 clk_div, con0, con1;
28568 ++ u32 clk_div, pwm_en, con0, con1;
28569 + int err;
28570 +
28571 + err = clk_prepare_enable(mdp->clk_main);
28572 +@@ -197,7 +197,8 @@ static void mtk_disp_pwm_get_state(struct pwm_chip *chip,
28573 + rate = clk_get_rate(mdp->clk_main);
28574 + con0 = readl(mdp->base + mdp->data->con0);
28575 + con1 = readl(mdp->base + mdp->data->con1);
28576 +- state->enabled = !!(con0 & BIT(0));
28577 ++ pwm_en = readl(mdp->base + DISP_PWM_EN);
28578 ++ state->enabled = !!(pwm_en & mdp->data->enable_mask);
28579 + clk_div = FIELD_GET(PWM_CLKDIV_MASK, con0);
28580 + period = FIELD_GET(PWM_PERIOD_MASK, con1);
28581 + /*
28582 +diff --git a/drivers/pwm/pwm-sifive.c b/drivers/pwm/pwm-sifive.c
28583 +index 2d4fa5e5fdd46..bb72393134016 100644
28584 +--- a/drivers/pwm/pwm-sifive.c
28585 ++++ b/drivers/pwm/pwm-sifive.c
28586 +@@ -204,8 +204,11 @@ static int pwm_sifive_clock_notifier(struct notifier_block *nb,
28587 + struct pwm_sifive_ddata *ddata =
28588 + container_of(nb, struct pwm_sifive_ddata, notifier);
28589 +
28590 +- if (event == POST_RATE_CHANGE)
28591 ++ if (event == POST_RATE_CHANGE) {
28592 ++ mutex_lock(&ddata->lock);
28593 + pwm_sifive_update_clock(ddata, ndata->new_rate);
28594 ++ mutex_unlock(&ddata->lock);
28595 ++ }
28596 +
28597 + return NOTIFY_OK;
28598 + }
28599 +diff --git a/drivers/pwm/pwm-tegra.c b/drivers/pwm/pwm-tegra.c
28600 +index dad9978c91861..249dc01932979 100644
28601 +--- a/drivers/pwm/pwm-tegra.c
28602 ++++ b/drivers/pwm/pwm-tegra.c
28603 +@@ -145,8 +145,19 @@ static int tegra_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
28604 + * source clock rate as required_clk_rate, PWM controller will
28605 + * be able to configure the requested period.
28606 + */
28607 +- required_clk_rate =
28608 +- (NSEC_PER_SEC / period_ns) << PWM_DUTY_WIDTH;
28609 ++ required_clk_rate = DIV_ROUND_UP_ULL((u64)NSEC_PER_SEC << PWM_DUTY_WIDTH,
28610 ++ period_ns);
28611 ++
28612 ++ if (required_clk_rate > clk_round_rate(pc->clk, required_clk_rate))
28613 ++ /*
28614 ++ * required_clk_rate is a lower bound for the input
28615 ++ * rate; for lower rates there is no value for PWM_SCALE
28616 ++ * that yields a period less than or equal to the
28617 ++ * requested period. Hence, for lower rates, double the
28618 ++ * required_clk_rate to get a clock rate that can meet
28619 ++ * the requested period.
28620 ++ */
28621 ++ required_clk_rate *= 2;
28622 +
28623 + err = dev_pm_opp_set_rate(pc->dev, required_clk_rate);
28624 + if (err < 0)
28625 +diff --git a/drivers/rapidio/devices/rio_mport_cdev.c b/drivers/rapidio/devices/rio_mport_cdev.c
28626 +index 2cdc054e53a53..43db495f19861 100644
28627 +--- a/drivers/rapidio/devices/rio_mport_cdev.c
28628 ++++ b/drivers/rapidio/devices/rio_mport_cdev.c
28629 +@@ -1804,8 +1804,11 @@ static int rio_mport_add_riodev(struct mport_cdev_priv *priv,
28630 + rio_init_dbell_res(&rdev->riores[RIO_DOORBELL_RESOURCE],
28631 + 0, 0xffff);
28632 + err = rio_add_device(rdev);
28633 +- if (err)
28634 +- goto cleanup;
28635 ++ if (err) {
28636 ++ put_device(&rdev->dev);
28637 ++ return err;
28638 ++ }
28639 ++
28640 + rio_dev_get(rdev);
28641 +
28642 + return 0;
28643 +@@ -1901,10 +1904,6 @@ static int mport_cdev_open(struct inode *inode, struct file *filp)
28644 +
28645 + priv->md = chdev;
28646 +
28647 +- mutex_lock(&chdev->file_mutex);
28648 +- list_add_tail(&priv->list, &chdev->file_list);
28649 +- mutex_unlock(&chdev->file_mutex);
28650 +-
28651 + INIT_LIST_HEAD(&priv->db_filters);
28652 + INIT_LIST_HEAD(&priv->pw_filters);
28653 + spin_lock_init(&priv->fifo_lock);
28654 +@@ -1913,6 +1912,7 @@ static int mport_cdev_open(struct inode *inode, struct file *filp)
28655 + sizeof(struct rio_event) * MPORT_EVENT_DEPTH,
28656 + GFP_KERNEL);
28657 + if (ret < 0) {
28658 ++ put_device(&chdev->dev);
28659 + dev_err(&chdev->dev, DRV_NAME ": kfifo_alloc failed\n");
28660 + ret = -ENOMEM;
28661 + goto err_fifo;
28662 +@@ -1923,6 +1923,9 @@ static int mport_cdev_open(struct inode *inode, struct file *filp)
28663 + spin_lock_init(&priv->req_lock);
28664 + mutex_init(&priv->dma_lock);
28665 + #endif
28666 ++ mutex_lock(&chdev->file_mutex);
28667 ++ list_add_tail(&priv->list, &chdev->file_list);
28668 ++ mutex_unlock(&chdev->file_mutex);
28669 +
28670 + filp->private_data = priv;
28671 + goto out;
28672 +diff --git a/drivers/rapidio/rio-scan.c b/drivers/rapidio/rio-scan.c
28673 +index 19b0c33f4a62a..fdcf742b2adbc 100644
28674 +--- a/drivers/rapidio/rio-scan.c
28675 ++++ b/drivers/rapidio/rio-scan.c
28676 +@@ -454,8 +454,12 @@ static struct rio_dev *rio_setup_device(struct rio_net *net,
28677 + 0, 0xffff);
28678 +
28679 + ret = rio_add_device(rdev);
28680 +- if (ret)
28681 +- goto cleanup;
28682 ++ if (ret) {
28683 ++ if (rswitch)
28684 ++ kfree(rswitch->route_table);
28685 ++ put_device(&rdev->dev);
28686 ++ return NULL;
28687 ++ }
28688 +
28689 + rio_dev_get(rdev);
28690 +
28691 +diff --git a/drivers/rapidio/rio.c b/drivers/rapidio/rio.c
28692 +index e74cf09eeff07..9544b8ee0c963 100644
28693 +--- a/drivers/rapidio/rio.c
28694 ++++ b/drivers/rapidio/rio.c
28695 +@@ -2186,11 +2186,16 @@ int rio_register_mport(struct rio_mport *port)
28696 + atomic_set(&port->state, RIO_DEVICE_RUNNING);
28697 +
28698 + res = device_register(&port->dev);
28699 +- if (res)
28700 ++ if (res) {
28701 + dev_err(&port->dev, "RIO: mport%d registration failed ERR=%d\n",
28702 + port->id, res);
28703 +- else
28704 ++ mutex_lock(&rio_mport_list_lock);
28705 ++ list_del(&port->node);
28706 ++ mutex_unlock(&rio_mport_list_lock);
28707 ++ put_device(&port->dev);
28708 ++ } else {
28709 + dev_dbg(&port->dev, "RIO: registered mport%d\n", port->id);
28710 ++ }
28711 +
28712 + return res;
28713 + }
28714 +diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
28715 +index c0f368f1b49f7..6829f7d8e24c8 100644
28716 +--- a/drivers/regulator/core.c
28717 ++++ b/drivers/regulator/core.c
28718 +@@ -987,7 +987,7 @@ static int drms_uA_update(struct regulator_dev *rdev)
28719 + /* get input voltage */
28720 + input_uV = 0;
28721 + if (rdev->supply)
28722 +- input_uV = regulator_get_voltage(rdev->supply);
28723 ++ input_uV = regulator_get_voltage_rdev(rdev->supply->rdev);
28724 + if (input_uV <= 0)
28725 + input_uV = rdev->constraints->input_uV;
28726 + if (input_uV <= 0) {
28727 +@@ -1578,7 +1578,13 @@ static int set_machine_constraints(struct regulator_dev *rdev)
28728 + if (rdev->supply_name && !rdev->supply)
28729 + return -EPROBE_DEFER;
28730 +
28731 +- if (rdev->supply) {
28732 ++ /* If supplying regulator has already been enabled,
28733 ++ * it's not intended to have use_count increment
28734 ++ * when rdev is only boot-on.
28735 ++ */
28736 ++ if (rdev->supply &&
28737 ++ (rdev->constraints->always_on ||
28738 ++ !regulator_is_enabled(rdev->supply))) {
28739 + ret = regulator_enable(rdev->supply);
28740 + if (ret < 0) {
28741 + _regulator_put(rdev->supply);
28742 +@@ -1622,6 +1628,7 @@ static int set_supply(struct regulator_dev *rdev,
28743 +
28744 + rdev->supply = create_regulator(supply_rdev, &rdev->dev, "SUPPLY");
28745 + if (rdev->supply == NULL) {
28746 ++ module_put(supply_rdev->owner);
28747 + err = -ENOMEM;
28748 + return err;
28749 + }
28750 +@@ -1795,7 +1802,7 @@ static struct regulator *create_regulator(struct regulator_dev *rdev,
28751 +
28752 + regulator = kzalloc(sizeof(*regulator), GFP_KERNEL);
28753 + if (regulator == NULL) {
28754 +- kfree(supply_name);
28755 ++ kfree_const(supply_name);
28756 + return NULL;
28757 + }
28758 +
28759 +@@ -1925,6 +1932,7 @@ static struct regulator_dev *regulator_dev_lookup(struct device *dev,
28760 + node = of_get_regulator(dev, supply);
28761 + if (node) {
28762 + r = of_find_regulator_by_node(node);
28763 ++ of_node_put(node);
28764 + if (r)
28765 + return r;
28766 +
28767 +@@ -5380,6 +5388,7 @@ static struct regulator_coupler generic_regulator_coupler = {
28768 +
28769 + /**
28770 + * regulator_register - register regulator
28771 ++ * @dev: the device that drive the regulator
28772 + * @regulator_desc: regulator to register
28773 + * @cfg: runtime configuration for regulator
28774 + *
28775 +@@ -5388,7 +5397,8 @@ static struct regulator_coupler generic_regulator_coupler = {
28776 + * or an ERR_PTR() on error.
28777 + */
28778 + struct regulator_dev *
28779 +-regulator_register(const struct regulator_desc *regulator_desc,
28780 ++regulator_register(struct device *dev,
28781 ++ const struct regulator_desc *regulator_desc,
28782 + const struct regulator_config *cfg)
28783 + {
28784 + const struct regulator_init_data *init_data;
28785 +@@ -5397,7 +5407,6 @@ regulator_register(const struct regulator_desc *regulator_desc,
28786 + struct regulator_dev *rdev;
28787 + bool dangling_cfg_gpiod = false;
28788 + bool dangling_of_gpiod = false;
28789 +- struct device *dev;
28790 + int ret, i;
28791 +
28792 + if (cfg == NULL)
28793 +@@ -5409,8 +5418,7 @@ regulator_register(const struct regulator_desc *regulator_desc,
28794 + goto rinse;
28795 + }
28796 +
28797 +- dev = cfg->dev;
28798 +- WARN_ON(!dev);
28799 ++ WARN_ON(!dev || !cfg->dev);
28800 +
28801 + if (regulator_desc->name == NULL || regulator_desc->ops == NULL) {
28802 + ret = -EINVAL;
28803 +@@ -5523,7 +5531,7 @@ regulator_register(const struct regulator_desc *regulator_desc,
28804 +
28805 + /* register with sysfs */
28806 + rdev->dev.class = &regulator_class;
28807 +- rdev->dev.parent = dev;
28808 ++ rdev->dev.parent = config->dev;
28809 + dev_set_name(&rdev->dev, "regulator.%lu",
28810 + (unsigned long) atomic_inc_return(&regulator_no));
28811 + dev_set_drvdata(&rdev->dev, rdev);
28812 +@@ -5613,6 +5621,7 @@ unset_supplies:
28813 + regulator_remove_coupling(rdev);
28814 + mutex_unlock(&regulator_list_mutex);
28815 + wash:
28816 ++ regulator_put(rdev->supply);
28817 + kfree(rdev->coupling_desc.coupled_rdevs);
28818 + mutex_lock(&regulator_list_mutex);
28819 + regulator_ena_gpio_free(rdev);
28820 +diff --git a/drivers/regulator/devres.c b/drivers/regulator/devres.c
28821 +index 32823a87fd409..d94db64cd490c 100644
28822 +--- a/drivers/regulator/devres.c
28823 ++++ b/drivers/regulator/devres.c
28824 +@@ -221,7 +221,7 @@ struct regulator_dev *devm_regulator_register(struct device *dev,
28825 + if (!ptr)
28826 + return ERR_PTR(-ENOMEM);
28827 +
28828 +- rdev = regulator_register(regulator_desc, config);
28829 ++ rdev = regulator_register(dev, regulator_desc, config);
28830 + if (!IS_ERR(rdev)) {
28831 + *ptr = rdev;
28832 + devres_add(dev, ptr);
28833 +diff --git a/drivers/regulator/of_regulator.c b/drivers/regulator/of_regulator.c
28834 +index e12b681c72e5e..bd0c5d1fd647c 100644
28835 +--- a/drivers/regulator/of_regulator.c
28836 ++++ b/drivers/regulator/of_regulator.c
28837 +@@ -505,7 +505,7 @@ struct regulator_init_data *regulator_of_get_init_data(struct device *dev,
28838 + struct device_node *child;
28839 + struct regulator_init_data *init_data = NULL;
28840 +
28841 +- child = regulator_of_get_init_node(dev, desc);
28842 ++ child = regulator_of_get_init_node(config->dev, desc);
28843 + if (!child)
28844 + return NULL;
28845 +
28846 +diff --git a/drivers/regulator/qcom-labibb-regulator.c b/drivers/regulator/qcom-labibb-regulator.c
28847 +index 639b71eb41ffe..bcf7140f3bc98 100644
28848 +--- a/drivers/regulator/qcom-labibb-regulator.c
28849 ++++ b/drivers/regulator/qcom-labibb-regulator.c
28850 +@@ -822,6 +822,7 @@ static int qcom_labibb_regulator_probe(struct platform_device *pdev)
28851 + if (irq == 0)
28852 + irq = -EINVAL;
28853 +
28854 ++ of_node_put(reg_node);
28855 + return dev_err_probe(vreg->dev, irq,
28856 + "Short-circuit irq not found.\n");
28857 + }
28858 +diff --git a/drivers/regulator/qcom-rpmh-regulator.c b/drivers/regulator/qcom-rpmh-regulator.c
28859 +index 561de6b2e6e36..5839e47323360 100644
28860 +--- a/drivers/regulator/qcom-rpmh-regulator.c
28861 ++++ b/drivers/regulator/qcom-rpmh-regulator.c
28862 +@@ -1188,7 +1188,7 @@ static const struct rpmh_vreg_init_data pm7325_vreg_data[] = {
28863 + static const struct rpmh_vreg_init_data pmr735a_vreg_data[] = {
28864 + RPMH_VREG("smps1", "smp%s1", &pmic5_ftsmps520, "vdd-s1"),
28865 + RPMH_VREG("smps2", "smp%s2", &pmic5_ftsmps520, "vdd-s2"),
28866 +- RPMH_VREG("smps3", "smp%s3", &pmic5_hfsmps510, "vdd-s3"),
28867 ++ RPMH_VREG("smps3", "smp%s3", &pmic5_hfsmps515, "vdd-s3"),
28868 + RPMH_VREG("ldo1", "ldo%s1", &pmic5_nldo, "vdd-l1-l2"),
28869 + RPMH_VREG("ldo2", "ldo%s2", &pmic5_nldo, "vdd-l1-l2"),
28870 + RPMH_VREG("ldo3", "ldo%s3", &pmic5_nldo, "vdd-l3"),
28871 +diff --git a/drivers/regulator/stm32-vrefbuf.c b/drivers/regulator/stm32-vrefbuf.c
28872 +index 30ea3bc8ca192..7a454b7b6eab9 100644
28873 +--- a/drivers/regulator/stm32-vrefbuf.c
28874 ++++ b/drivers/regulator/stm32-vrefbuf.c
28875 +@@ -210,7 +210,7 @@ static int stm32_vrefbuf_probe(struct platform_device *pdev)
28876 + pdev->dev.of_node,
28877 + &stm32_vrefbuf_regu);
28878 +
28879 +- rdev = regulator_register(&stm32_vrefbuf_regu, &config);
28880 ++ rdev = regulator_register(&pdev->dev, &stm32_vrefbuf_regu, &config);
28881 + if (IS_ERR(rdev)) {
28882 + ret = PTR_ERR(rdev);
28883 + dev_err(&pdev->dev, "register failed with error %d\n", ret);
28884 +diff --git a/drivers/remoteproc/qcom_q6v5_pas.c b/drivers/remoteproc/qcom_q6v5_pas.c
28885 +index 6afd0941e5524..dc6f07ca83410 100644
28886 +--- a/drivers/remoteproc/qcom_q6v5_pas.c
28887 ++++ b/drivers/remoteproc/qcom_q6v5_pas.c
28888 +@@ -449,6 +449,7 @@ static int adsp_alloc_memory_region(struct qcom_adsp *adsp)
28889 + }
28890 +
28891 + ret = of_address_to_resource(node, 0, &r);
28892 ++ of_node_put(node);
28893 + if (ret)
28894 + return ret;
28895 +
28896 +@@ -556,6 +557,7 @@ static int adsp_probe(struct platform_device *pdev)
28897 + detach_proxy_pds:
28898 + adsp_pds_detach(adsp, adsp->proxy_pds, adsp->proxy_pd_count);
28899 + free_rproc:
28900 ++ device_init_wakeup(adsp->dev, false);
28901 + rproc_free(rproc);
28902 +
28903 + return ret;
28904 +@@ -572,6 +574,8 @@ static int adsp_remove(struct platform_device *pdev)
28905 + qcom_remove_sysmon_subdev(adsp->sysmon);
28906 + qcom_remove_smd_subdev(adsp->rproc, &adsp->smd_subdev);
28907 + qcom_remove_ssr_subdev(adsp->rproc, &adsp->ssr_subdev);
28908 ++ adsp_pds_detach(adsp, adsp->proxy_pds, adsp->proxy_pd_count);
28909 ++ device_init_wakeup(adsp->dev, false);
28910 + rproc_free(adsp->rproc);
28911 +
28912 + return 0;
28913 +diff --git a/drivers/remoteproc/qcom_q6v5_wcss.c b/drivers/remoteproc/qcom_q6v5_wcss.c
28914 +index bb0947f7770ea..ba24d745b2d65 100644
28915 +--- a/drivers/remoteproc/qcom_q6v5_wcss.c
28916 ++++ b/drivers/remoteproc/qcom_q6v5_wcss.c
28917 +@@ -351,7 +351,7 @@ static int q6v5_wcss_qcs404_power_on(struct q6v5_wcss *wcss)
28918 + if (ret) {
28919 + dev_err(wcss->dev,
28920 + "xo cbcr enabling timed out (rc:%d)\n", ret);
28921 +- return ret;
28922 ++ goto disable_xo_cbcr_clk;
28923 + }
28924 +
28925 + writel(0, wcss->reg_base + Q6SS_CGC_OVERRIDE);
28926 +@@ -417,6 +417,7 @@ disable_sleep_cbcr_clk:
28927 + val = readl(wcss->reg_base + Q6SS_SLEEP_CBCR);
28928 + val &= ~Q6SS_CLK_ENABLE;
28929 + writel(val, wcss->reg_base + Q6SS_SLEEP_CBCR);
28930 ++disable_xo_cbcr_clk:
28931 + val = readl(wcss->reg_base + Q6SS_XO_CBCR);
28932 + val &= ~Q6SS_CLK_ENABLE;
28933 + writel(val, wcss->reg_base + Q6SS_XO_CBCR);
28934 +@@ -827,6 +828,9 @@ static int q6v5_wcss_init_mmio(struct q6v5_wcss *wcss,
28935 + int ret;
28936 +
28937 + res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "qdsp6");
28938 ++ if (!res)
28939 ++ return -EINVAL;
28940 ++
28941 + wcss->reg_base = devm_ioremap(&pdev->dev, res->start,
28942 + resource_size(res));
28943 + if (!wcss->reg_base)
28944 +diff --git a/drivers/remoteproc/qcom_sysmon.c b/drivers/remoteproc/qcom_sysmon.c
28945 +index 57dde2a69b9dd..15af52f8499eb 100644
28946 +--- a/drivers/remoteproc/qcom_sysmon.c
28947 ++++ b/drivers/remoteproc/qcom_sysmon.c
28948 +@@ -652,7 +652,9 @@ struct qcom_sysmon *qcom_add_sysmon_subdev(struct rproc *rproc,
28949 + if (sysmon->shutdown_irq != -ENODATA) {
28950 + dev_err(sysmon->dev,
28951 + "failed to retrieve shutdown-ack IRQ\n");
28952 +- return ERR_PTR(sysmon->shutdown_irq);
28953 ++ ret = sysmon->shutdown_irq;
28954 ++ kfree(sysmon);
28955 ++ return ERR_PTR(ret);
28956 + }
28957 + } else {
28958 + ret = devm_request_threaded_irq(sysmon->dev,
28959 +@@ -663,6 +665,7 @@ struct qcom_sysmon *qcom_add_sysmon_subdev(struct rproc *rproc,
28960 + if (ret) {
28961 + dev_err(sysmon->dev,
28962 + "failed to acquire shutdown-ack IRQ\n");
28963 ++ kfree(sysmon);
28964 + return ERR_PTR(ret);
28965 + }
28966 + }
28967 +diff --git a/drivers/rtc/class.c b/drivers/rtc/class.c
28968 +index e48223c00c672..e5b7b48cffac0 100644
28969 +--- a/drivers/rtc/class.c
28970 ++++ b/drivers/rtc/class.c
28971 +@@ -374,11 +374,11 @@ struct rtc_device *devm_rtc_allocate_device(struct device *dev)
28972 +
28973 + rtc->id = id;
28974 + rtc->dev.parent = dev;
28975 +- err = dev_set_name(&rtc->dev, "rtc%d", id);
28976 ++ err = devm_add_action_or_reset(dev, devm_rtc_release_device, rtc);
28977 + if (err)
28978 + return ERR_PTR(err);
28979 +
28980 +- err = devm_add_action_or_reset(dev, devm_rtc_release_device, rtc);
28981 ++ err = dev_set_name(&rtc->dev, "rtc%d", id);
28982 + if (err)
28983 + return ERR_PTR(err);
28984 +
28985 +diff --git a/drivers/rtc/rtc-cmos.c b/drivers/rtc/rtc-cmos.c
28986 +index 58cc2bae2f8a0..00e2ca7374ecf 100644
28987 +--- a/drivers/rtc/rtc-cmos.c
28988 ++++ b/drivers/rtc/rtc-cmos.c
28989 +@@ -744,6 +744,168 @@ static irqreturn_t cmos_interrupt(int irq, void *p)
28990 + return IRQ_NONE;
28991 + }
28992 +
28993 ++#ifdef CONFIG_ACPI
28994 ++
28995 ++#include <linux/acpi.h>
28996 ++
28997 ++static u32 rtc_handler(void *context)
28998 ++{
28999 ++ struct device *dev = context;
29000 ++ struct cmos_rtc *cmos = dev_get_drvdata(dev);
29001 ++ unsigned char rtc_control = 0;
29002 ++ unsigned char rtc_intr;
29003 ++ unsigned long flags;
29004 ++
29005 ++
29006 ++ /*
29007 ++ * Always update rtc irq when ACPI is used as RTC Alarm.
29008 ++ * Or else, ACPI SCI is enabled during suspend/resume only,
29009 ++ * update rtc irq in that case.
29010 ++ */
29011 ++ if (cmos_use_acpi_alarm())
29012 ++ cmos_interrupt(0, (void *)cmos->rtc);
29013 ++ else {
29014 ++ /* Fix me: can we use cmos_interrupt() here as well? */
29015 ++ spin_lock_irqsave(&rtc_lock, flags);
29016 ++ if (cmos_rtc.suspend_ctrl)
29017 ++ rtc_control = CMOS_READ(RTC_CONTROL);
29018 ++ if (rtc_control & RTC_AIE) {
29019 ++ cmos_rtc.suspend_ctrl &= ~RTC_AIE;
29020 ++ CMOS_WRITE(rtc_control, RTC_CONTROL);
29021 ++ rtc_intr = CMOS_READ(RTC_INTR_FLAGS);
29022 ++ rtc_update_irq(cmos->rtc, 1, rtc_intr);
29023 ++ }
29024 ++ spin_unlock_irqrestore(&rtc_lock, flags);
29025 ++ }
29026 ++
29027 ++ pm_wakeup_hard_event(dev);
29028 ++ acpi_clear_event(ACPI_EVENT_RTC);
29029 ++ acpi_disable_event(ACPI_EVENT_RTC, 0);
29030 ++ return ACPI_INTERRUPT_HANDLED;
29031 ++}
29032 ++
29033 ++static void acpi_rtc_event_setup(struct device *dev)
29034 ++{
29035 ++ if (acpi_disabled)
29036 ++ return;
29037 ++
29038 ++ acpi_install_fixed_event_handler(ACPI_EVENT_RTC, rtc_handler, dev);
29039 ++ /*
29040 ++ * After the RTC handler is installed, the Fixed_RTC event should
29041 ++ * be disabled. Only when the RTC alarm is set will it be enabled.
29042 ++ */
29043 ++ acpi_clear_event(ACPI_EVENT_RTC);
29044 ++ acpi_disable_event(ACPI_EVENT_RTC, 0);
29045 ++}
29046 ++
29047 ++static void acpi_rtc_event_cleanup(void)
29048 ++{
29049 ++ if (acpi_disabled)
29050 ++ return;
29051 ++
29052 ++ acpi_remove_fixed_event_handler(ACPI_EVENT_RTC, rtc_handler);
29053 ++}
29054 ++
29055 ++static void rtc_wake_on(struct device *dev)
29056 ++{
29057 ++ acpi_clear_event(ACPI_EVENT_RTC);
29058 ++ acpi_enable_event(ACPI_EVENT_RTC, 0);
29059 ++}
29060 ++
29061 ++static void rtc_wake_off(struct device *dev)
29062 ++{
29063 ++ acpi_disable_event(ACPI_EVENT_RTC, 0);
29064 ++}
29065 ++
29066 ++#ifdef CONFIG_X86
29067 ++/* Enable use_acpi_alarm mode for Intel platforms no earlier than 2015 */
29068 ++static void use_acpi_alarm_quirks(void)
29069 ++{
29070 ++ if (boot_cpu_data.x86_vendor != X86_VENDOR_INTEL)
29071 ++ return;
29072 ++
29073 ++ if (!is_hpet_enabled())
29074 ++ return;
29075 ++
29076 ++ if (dmi_get_bios_year() < 2015)
29077 ++ return;
29078 ++
29079 ++ use_acpi_alarm = true;
29080 ++}
29081 ++#else
29082 ++static inline void use_acpi_alarm_quirks(void) { }
29083 ++#endif
29084 ++
29085 ++static void acpi_cmos_wake_setup(struct device *dev)
29086 ++{
29087 ++ if (acpi_disabled)
29088 ++ return;
29089 ++
29090 ++ use_acpi_alarm_quirks();
29091 ++
29092 ++ cmos_rtc.wake_on = rtc_wake_on;
29093 ++ cmos_rtc.wake_off = rtc_wake_off;
29094 ++
29095 ++ /* ACPI tables bug workaround. */
29096 ++ if (acpi_gbl_FADT.month_alarm && !acpi_gbl_FADT.day_alarm) {
29097 ++ dev_dbg(dev, "bogus FADT month_alarm (%d)\n",
29098 ++ acpi_gbl_FADT.month_alarm);
29099 ++ acpi_gbl_FADT.month_alarm = 0;
29100 ++ }
29101 ++
29102 ++ cmos_rtc.day_alrm = acpi_gbl_FADT.day_alarm;
29103 ++ cmos_rtc.mon_alrm = acpi_gbl_FADT.month_alarm;
29104 ++ cmos_rtc.century = acpi_gbl_FADT.century;
29105 ++
29106 ++ if (acpi_gbl_FADT.flags & ACPI_FADT_S4_RTC_WAKE)
29107 ++ dev_info(dev, "RTC can wake from S4\n");
29108 ++
29109 ++ /* RTC always wakes from S1/S2/S3, and often S4/STD */
29110 ++ device_init_wakeup(dev, 1);
29111 ++}
29112 ++
29113 ++static void cmos_check_acpi_rtc_status(struct device *dev,
29114 ++ unsigned char *rtc_control)
29115 ++{
29116 ++ struct cmos_rtc *cmos = dev_get_drvdata(dev);
29117 ++ acpi_event_status rtc_status;
29118 ++ acpi_status status;
29119 ++
29120 ++ if (acpi_gbl_FADT.flags & ACPI_FADT_FIXED_RTC)
29121 ++ return;
29122 ++
29123 ++ status = acpi_get_event_status(ACPI_EVENT_RTC, &rtc_status);
29124 ++ if (ACPI_FAILURE(status)) {
29125 ++ dev_err(dev, "Could not get RTC status\n");
29126 ++ } else if (rtc_status & ACPI_EVENT_FLAG_SET) {
29127 ++ unsigned char mask;
29128 ++ *rtc_control &= ~RTC_AIE;
29129 ++ CMOS_WRITE(*rtc_control, RTC_CONTROL);
29130 ++ mask = CMOS_READ(RTC_INTR_FLAGS);
29131 ++ rtc_update_irq(cmos->rtc, 1, mask);
29132 ++ }
29133 ++}
29134 ++
29135 ++#else /* !CONFIG_ACPI */
29136 ++
29137 ++static inline void acpi_rtc_event_setup(struct device *dev)
29138 ++{
29139 ++}
29140 ++
29141 ++static inline void acpi_rtc_event_cleanup(void)
29142 ++{
29143 ++}
29144 ++
29145 ++static inline void acpi_cmos_wake_setup(struct device *dev)
29146 ++{
29147 ++}
29148 ++
29149 ++static inline void cmos_check_acpi_rtc_status(struct device *dev,
29150 ++ unsigned char *rtc_control)
29151 ++{
29152 ++}
29153 ++#endif /* CONFIG_ACPI */
29154 ++
29155 + #ifdef CONFIG_PNP
29156 + #define INITSECTION
29157 +
29158 +@@ -827,19 +989,27 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq)
29159 + if (info->address_space)
29160 + address_space = info->address_space;
29161 +
29162 +- if (info->rtc_day_alarm && info->rtc_day_alarm < 128)
29163 +- cmos_rtc.day_alrm = info->rtc_day_alarm;
29164 +- if (info->rtc_mon_alarm && info->rtc_mon_alarm < 128)
29165 +- cmos_rtc.mon_alrm = info->rtc_mon_alarm;
29166 +- if (info->rtc_century && info->rtc_century < 128)
29167 +- cmos_rtc.century = info->rtc_century;
29168 ++ cmos_rtc.day_alrm = info->rtc_day_alarm;
29169 ++ cmos_rtc.mon_alrm = info->rtc_mon_alarm;
29170 ++ cmos_rtc.century = info->rtc_century;
29171 +
29172 + if (info->wake_on && info->wake_off) {
29173 + cmos_rtc.wake_on = info->wake_on;
29174 + cmos_rtc.wake_off = info->wake_off;
29175 + }
29176 ++ } else {
29177 ++ acpi_cmos_wake_setup(dev);
29178 + }
29179 +
29180 ++ if (cmos_rtc.day_alrm >= 128)
29181 ++ cmos_rtc.day_alrm = 0;
29182 ++
29183 ++ if (cmos_rtc.mon_alrm >= 128)
29184 ++ cmos_rtc.mon_alrm = 0;
29185 ++
29186 ++ if (cmos_rtc.century >= 128)
29187 ++ cmos_rtc.century = 0;
29188 ++
29189 + cmos_rtc.dev = dev;
29190 + dev_set_drvdata(dev, &cmos_rtc);
29191 +
29192 +@@ -928,6 +1098,13 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq)
29193 + nvmem_cfg.size = address_space - NVRAM_OFFSET;
29194 + devm_rtc_nvmem_register(cmos_rtc.rtc, &nvmem_cfg);
29195 +
29196 ++ /*
29197 ++ * Everything has gone well so far, so by default register a handler for
29198 ++ * the ACPI RTC fixed event.
29199 ++ */
29200 ++ if (!info)
29201 ++ acpi_rtc_event_setup(dev);
29202 ++
29203 + dev_info(dev, "%s%s, %d bytes nvram%s\n",
29204 + !is_valid_irq(rtc_irq) ? "no alarms" :
29205 + cmos_rtc.mon_alrm ? "alarms up to one year" :
29206 +@@ -973,6 +1150,9 @@ static void cmos_do_remove(struct device *dev)
29207 + hpet_unregister_irq_handler(cmos_interrupt);
29208 + }
29209 +
29210 ++ if (!dev_get_platdata(dev))
29211 ++ acpi_rtc_event_cleanup();
29212 ++
29213 + cmos->rtc = NULL;
29214 +
29215 + ports = cmos->iomem;
29216 +@@ -1122,9 +1302,6 @@ static void cmos_check_wkalrm(struct device *dev)
29217 + }
29218 + }
29219 +
29220 +-static void cmos_check_acpi_rtc_status(struct device *dev,
29221 +- unsigned char *rtc_control);
29222 +-
29223 + static int __maybe_unused cmos_resume(struct device *dev)
29224 + {
29225 + struct cmos_rtc *cmos = dev_get_drvdata(dev);
29226 +@@ -1191,175 +1368,13 @@ static SIMPLE_DEV_PM_OPS(cmos_pm_ops, cmos_suspend, cmos_resume);
29227 + * predate even PNPBIOS should set up platform_bus devices.
29228 + */
29229 +
29230 +-#ifdef CONFIG_ACPI
29231 +-
29232 +-#include <linux/acpi.h>
29233 +-
29234 +-static u32 rtc_handler(void *context)
29235 +-{
29236 +- struct device *dev = context;
29237 +- struct cmos_rtc *cmos = dev_get_drvdata(dev);
29238 +- unsigned char rtc_control = 0;
29239 +- unsigned char rtc_intr;
29240 +- unsigned long flags;
29241 +-
29242 +-
29243 +- /*
29244 +- * Always update rtc irq when ACPI is used as RTC Alarm.
29245 +- * Or else, ACPI SCI is enabled during suspend/resume only,
29246 +- * update rtc irq in that case.
29247 +- */
29248 +- if (cmos_use_acpi_alarm())
29249 +- cmos_interrupt(0, (void *)cmos->rtc);
29250 +- else {
29251 +- /* Fix me: can we use cmos_interrupt() here as well? */
29252 +- spin_lock_irqsave(&rtc_lock, flags);
29253 +- if (cmos_rtc.suspend_ctrl)
29254 +- rtc_control = CMOS_READ(RTC_CONTROL);
29255 +- if (rtc_control & RTC_AIE) {
29256 +- cmos_rtc.suspend_ctrl &= ~RTC_AIE;
29257 +- CMOS_WRITE(rtc_control, RTC_CONTROL);
29258 +- rtc_intr = CMOS_READ(RTC_INTR_FLAGS);
29259 +- rtc_update_irq(cmos->rtc, 1, rtc_intr);
29260 +- }
29261 +- spin_unlock_irqrestore(&rtc_lock, flags);
29262 +- }
29263 +-
29264 +- pm_wakeup_hard_event(dev);
29265 +- acpi_clear_event(ACPI_EVENT_RTC);
29266 +- acpi_disable_event(ACPI_EVENT_RTC, 0);
29267 +- return ACPI_INTERRUPT_HANDLED;
29268 +-}
29269 +-
29270 +-static inline void rtc_wake_setup(struct device *dev)
29271 +-{
29272 +- if (acpi_disabled)
29273 +- return;
29274 +-
29275 +- acpi_install_fixed_event_handler(ACPI_EVENT_RTC, rtc_handler, dev);
29276 +- /*
29277 +- * After the RTC handler is installed, the Fixed_RTC event should
29278 +- * be disabled. Only when the RTC alarm is set will it be enabled.
29279 +- */
29280 +- acpi_clear_event(ACPI_EVENT_RTC);
29281 +- acpi_disable_event(ACPI_EVENT_RTC, 0);
29282 +-}
29283 +-
29284 +-static void rtc_wake_on(struct device *dev)
29285 +-{
29286 +- acpi_clear_event(ACPI_EVENT_RTC);
29287 +- acpi_enable_event(ACPI_EVENT_RTC, 0);
29288 +-}
29289 +-
29290 +-static void rtc_wake_off(struct device *dev)
29291 +-{
29292 +- acpi_disable_event(ACPI_EVENT_RTC, 0);
29293 +-}
29294 +-
29295 +-#ifdef CONFIG_X86
29296 +-/* Enable use_acpi_alarm mode for Intel platforms no earlier than 2015 */
29297 +-static void use_acpi_alarm_quirks(void)
29298 +-{
29299 +- if (boot_cpu_data.x86_vendor != X86_VENDOR_INTEL)
29300 +- return;
29301 +-
29302 +- if (!is_hpet_enabled())
29303 +- return;
29304 +-
29305 +- if (dmi_get_bios_year() < 2015)
29306 +- return;
29307 +-
29308 +- use_acpi_alarm = true;
29309 +-}
29310 +-#else
29311 +-static inline void use_acpi_alarm_quirks(void) { }
29312 +-#endif
29313 +-
29314 +-/* Every ACPI platform has a mc146818 compatible "cmos rtc". Here we find
29315 +- * its device node and pass extra config data. This helps its driver use
29316 +- * capabilities that the now-obsolete mc146818 didn't have, and informs it
29317 +- * that this board's RTC is wakeup-capable (per ACPI spec).
29318 +- */
29319 +-static struct cmos_rtc_board_info acpi_rtc_info;
29320 +-
29321 +-static void cmos_wake_setup(struct device *dev)
29322 +-{
29323 +- if (acpi_disabled)
29324 +- return;
29325 +-
29326 +- use_acpi_alarm_quirks();
29327 +-
29328 +- acpi_rtc_info.wake_on = rtc_wake_on;
29329 +- acpi_rtc_info.wake_off = rtc_wake_off;
29330 +-
29331 +- /* workaround bug in some ACPI tables */
29332 +- if (acpi_gbl_FADT.month_alarm && !acpi_gbl_FADT.day_alarm) {
29333 +- dev_dbg(dev, "bogus FADT month_alarm (%d)\n",
29334 +- acpi_gbl_FADT.month_alarm);
29335 +- acpi_gbl_FADT.month_alarm = 0;
29336 +- }
29337 +-
29338 +- acpi_rtc_info.rtc_day_alarm = acpi_gbl_FADT.day_alarm;
29339 +- acpi_rtc_info.rtc_mon_alarm = acpi_gbl_FADT.month_alarm;
29340 +- acpi_rtc_info.rtc_century = acpi_gbl_FADT.century;
29341 +-
29342 +- /* NOTE: S4_RTC_WAKE is NOT currently useful to Linux */
29343 +- if (acpi_gbl_FADT.flags & ACPI_FADT_S4_RTC_WAKE)
29344 +- dev_info(dev, "RTC can wake from S4\n");
29345 +-
29346 +- dev->platform_data = &acpi_rtc_info;
29347 +-
29348 +- /* RTC always wakes from S1/S2/S3, and often S4/STD */
29349 +- device_init_wakeup(dev, 1);
29350 +-}
29351 +-
29352 +-static void cmos_check_acpi_rtc_status(struct device *dev,
29353 +- unsigned char *rtc_control)
29354 +-{
29355 +- struct cmos_rtc *cmos = dev_get_drvdata(dev);
29356 +- acpi_event_status rtc_status;
29357 +- acpi_status status;
29358 +-
29359 +- if (acpi_gbl_FADT.flags & ACPI_FADT_FIXED_RTC)
29360 +- return;
29361 +-
29362 +- status = acpi_get_event_status(ACPI_EVENT_RTC, &rtc_status);
29363 +- if (ACPI_FAILURE(status)) {
29364 +- dev_err(dev, "Could not get RTC status\n");
29365 +- } else if (rtc_status & ACPI_EVENT_FLAG_SET) {
29366 +- unsigned char mask;
29367 +- *rtc_control &= ~RTC_AIE;
29368 +- CMOS_WRITE(*rtc_control, RTC_CONTROL);
29369 +- mask = CMOS_READ(RTC_INTR_FLAGS);
29370 +- rtc_update_irq(cmos->rtc, 1, mask);
29371 +- }
29372 +-}
29373 +-
29374 +-#else
29375 +-
29376 +-static void cmos_wake_setup(struct device *dev)
29377 +-{
29378 +-}
29379 +-
29380 +-static void cmos_check_acpi_rtc_status(struct device *dev,
29381 +- unsigned char *rtc_control)
29382 +-{
29383 +-}
29384 +-
29385 +-static void rtc_wake_setup(struct device *dev)
29386 +-{
29387 +-}
29388 +-#endif
29389 +-
29390 + #ifdef CONFIG_PNP
29391 +
29392 + #include <linux/pnp.h>
29393 +
29394 + static int cmos_pnp_probe(struct pnp_dev *pnp, const struct pnp_device_id *id)
29395 + {
29396 +- int irq, ret;
29397 +-
29398 +- cmos_wake_setup(&pnp->dev);
29399 ++ int irq;
29400 +
29401 + if (pnp_port_start(pnp, 0) == 0x70 && !pnp_irq_valid(pnp, 0)) {
29402 + irq = 0;
29403 +@@ -1375,13 +1390,7 @@ static int cmos_pnp_probe(struct pnp_dev *pnp, const struct pnp_device_id *id)
29404 + irq = pnp_irq(pnp, 0);
29405 + }
29406 +
29407 +- ret = cmos_do_probe(&pnp->dev, pnp_get_resource(pnp, IORESOURCE_IO, 0), irq);
29408 +- if (ret)
29409 +- return ret;
29410 +-
29411 +- rtc_wake_setup(&pnp->dev);
29412 +-
29413 +- return 0;
29414 ++ return cmos_do_probe(&pnp->dev, pnp_get_resource(pnp, IORESOURCE_IO, 0), irq);
29415 + }
29416 +
29417 + static void cmos_pnp_remove(struct pnp_dev *pnp)
29418 +@@ -1465,10 +1474,9 @@ static inline void cmos_of_init(struct platform_device *pdev) {}
29419 + static int __init cmos_platform_probe(struct platform_device *pdev)
29420 + {
29421 + struct resource *resource;
29422 +- int irq, ret;
29423 ++ int irq;
29424 +
29425 + cmos_of_init(pdev);
29426 +- cmos_wake_setup(&pdev->dev);
29427 +
29428 + if (RTC_IOMAPPED)
29429 + resource = platform_get_resource(pdev, IORESOURCE_IO, 0);
29430 +@@ -1478,13 +1486,7 @@ static int __init cmos_platform_probe(struct platform_device *pdev)
29431 + if (irq < 0)
29432 + irq = -1;
29433 +
29434 +- ret = cmos_do_probe(&pdev->dev, resource, irq);
29435 +- if (ret)
29436 +- return ret;
29437 +-
29438 +- rtc_wake_setup(&pdev->dev);
29439 +-
29440 +- return 0;
29441 ++ return cmos_do_probe(&pdev->dev, resource, irq);
29442 + }
29443 +
29444 + static int cmos_platform_remove(struct platform_device *pdev)
29445 +diff --git a/drivers/rtc/rtc-mxc_v2.c b/drivers/rtc/rtc-mxc_v2.c
29446 +index 5e03834016294..f6d2ad91ff7a9 100644
29447 +--- a/drivers/rtc/rtc-mxc_v2.c
29448 ++++ b/drivers/rtc/rtc-mxc_v2.c
29449 +@@ -336,8 +336,10 @@ static int mxc_rtc_probe(struct platform_device *pdev)
29450 + }
29451 +
29452 + pdata->rtc = devm_rtc_allocate_device(&pdev->dev);
29453 +- if (IS_ERR(pdata->rtc))
29454 ++ if (IS_ERR(pdata->rtc)) {
29455 ++ clk_disable_unprepare(pdata->clk);
29456 + return PTR_ERR(pdata->rtc);
29457 ++ }
29458 +
29459 + pdata->rtc->ops = &mxc_rtc_ops;
29460 + pdata->rtc->range_max = U32_MAX;
29461 +diff --git a/drivers/rtc/rtc-pcf85063.c b/drivers/rtc/rtc-pcf85063.c
29462 +index 095891999da11..754e03984f986 100644
29463 +--- a/drivers/rtc/rtc-pcf85063.c
29464 ++++ b/drivers/rtc/rtc-pcf85063.c
29465 +@@ -169,10 +169,10 @@ static int pcf85063_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm)
29466 + if (ret)
29467 + return ret;
29468 +
29469 +- alrm->time.tm_sec = bcd2bin(buf[0]);
29470 +- alrm->time.tm_min = bcd2bin(buf[1]);
29471 +- alrm->time.tm_hour = bcd2bin(buf[2]);
29472 +- alrm->time.tm_mday = bcd2bin(buf[3]);
29473 ++ alrm->time.tm_sec = bcd2bin(buf[0] & 0x7f);
29474 ++ alrm->time.tm_min = bcd2bin(buf[1] & 0x7f);
29475 ++ alrm->time.tm_hour = bcd2bin(buf[2] & 0x3f);
29476 ++ alrm->time.tm_mday = bcd2bin(buf[3] & 0x3f);
29477 +
29478 + ret = regmap_read(pcf85063->regmap, PCF85063_REG_CTRL2, &val);
29479 + if (ret)
29480 +@@ -424,7 +424,7 @@ static int pcf85063_clkout_control(struct clk_hw *hw, bool enable)
29481 + unsigned int buf;
29482 + int ret;
29483 +
29484 +- ret = regmap_read(pcf85063->regmap, PCF85063_REG_OFFSET, &buf);
29485 ++ ret = regmap_read(pcf85063->regmap, PCF85063_REG_CTRL2, &buf);
29486 + if (ret < 0)
29487 + return ret;
29488 + buf &= PCF85063_REG_CLKO_F_MASK;
29489 +diff --git a/drivers/rtc/rtc-pic32.c b/drivers/rtc/rtc-pic32.c
29490 +index 7fb9145c43bd5..fa351ac201587 100644
29491 +--- a/drivers/rtc/rtc-pic32.c
29492 ++++ b/drivers/rtc/rtc-pic32.c
29493 +@@ -324,16 +324,16 @@ static int pic32_rtc_probe(struct platform_device *pdev)
29494 +
29495 + spin_lock_init(&pdata->alarm_lock);
29496 +
29497 ++ pdata->rtc = devm_rtc_allocate_device(&pdev->dev);
29498 ++ if (IS_ERR(pdata->rtc))
29499 ++ return PTR_ERR(pdata->rtc);
29500 ++
29501 + clk_prepare_enable(pdata->clk);
29502 +
29503 + pic32_rtc_enable(pdata, 1);
29504 +
29505 + device_init_wakeup(&pdev->dev, 1);
29506 +
29507 +- pdata->rtc = devm_rtc_allocate_device(&pdev->dev);
29508 +- if (IS_ERR(pdata->rtc))
29509 +- return PTR_ERR(pdata->rtc);
29510 +-
29511 + pdata->rtc->ops = &pic32_rtcops;
29512 + pdata->rtc->range_min = RTC_TIMESTAMP_BEGIN_2000;
29513 + pdata->rtc->range_max = RTC_TIMESTAMP_END_2099;
29514 +diff --git a/drivers/rtc/rtc-rzn1.c b/drivers/rtc/rtc-rzn1.c
29515 +index ac788799c8e3e..0d36bc50197c1 100644
29516 +--- a/drivers/rtc/rtc-rzn1.c
29517 ++++ b/drivers/rtc/rtc-rzn1.c
29518 +@@ -355,7 +355,9 @@ static int rzn1_rtc_probe(struct platform_device *pdev)
29519 + set_bit(RTC_FEATURE_ALARM_RES_MINUTE, rtc->rtcdev->features);
29520 + clear_bit(RTC_FEATURE_UPDATE_INTERRUPT, rtc->rtcdev->features);
29521 +
29522 +- devm_pm_runtime_enable(&pdev->dev);
29523 ++ ret = devm_pm_runtime_enable(&pdev->dev);
29524 ++ if (ret < 0)
29525 ++ return ret;
29526 + ret = pm_runtime_resume_and_get(&pdev->dev);
29527 + if (ret < 0)
29528 + return ret;
29529 +diff --git a/drivers/rtc/rtc-snvs.c b/drivers/rtc/rtc-snvs.c
29530 +index bd929b0e7d7de..d82acf1af1fae 100644
29531 +--- a/drivers/rtc/rtc-snvs.c
29532 ++++ b/drivers/rtc/rtc-snvs.c
29533 +@@ -32,6 +32,14 @@
29534 + #define SNVS_LPPGDR_INIT 0x41736166
29535 + #define CNTR_TO_SECS_SH 15
29536 +
29537 ++/* The maximum RTC clock cycles that are allowed to pass between two
29538 ++ * consecutive clock counter register reads. If the values are corrupted a
29539 ++ * bigger difference is expected. The RTC frequency is 32kHz. With 320 cycles
29540 ++ * we end at 10ms which should be enough for most cases. If it once takes
29541 ++ * longer than expected we do a retry.
29542 ++ */
29543 ++#define MAX_RTC_READ_DIFF_CYCLES 320
29544 ++
29545 + struct snvs_rtc_data {
29546 + struct rtc_device *rtc;
29547 + struct regmap *regmap;
29548 +@@ -56,6 +64,7 @@ static u64 rtc_read_lpsrt(struct snvs_rtc_data *data)
29549 + static u32 rtc_read_lp_counter(struct snvs_rtc_data *data)
29550 + {
29551 + u64 read1, read2;
29552 ++ s64 diff;
29553 + unsigned int timeout = 100;
29554 +
29555 + /* As expected, the registers might update between the read of the LSB
29556 +@@ -66,7 +75,8 @@ static u32 rtc_read_lp_counter(struct snvs_rtc_data *data)
29557 + do {
29558 + read2 = read1;
29559 + read1 = rtc_read_lpsrt(data);
29560 +- } while (read1 != read2 && --timeout);
29561 ++ diff = read1 - read2;
29562 ++ } while (((diff < 0) || (diff > MAX_RTC_READ_DIFF_CYCLES)) && --timeout);
29563 + if (!timeout)
29564 + dev_err(&data->rtc->dev, "Timeout trying to get valid LPSRT Counter read\n");
29565 +
29566 +@@ -78,13 +88,15 @@ static u32 rtc_read_lp_counter(struct snvs_rtc_data *data)
29567 + static int rtc_read_lp_counter_lsb(struct snvs_rtc_data *data, u32 *lsb)
29568 + {
29569 + u32 count1, count2;
29570 ++ s32 diff;
29571 + unsigned int timeout = 100;
29572 +
29573 + regmap_read(data->regmap, data->offset + SNVS_LPSRTCLR, &count1);
29574 + do {
29575 + count2 = count1;
29576 + regmap_read(data->regmap, data->offset + SNVS_LPSRTCLR, &count1);
29577 +- } while (count1 != count2 && --timeout);
29578 ++ diff = count1 - count2;
29579 ++ } while (((diff < 0) || (diff > MAX_RTC_READ_DIFF_CYCLES)) && --timeout);
29580 + if (!timeout) {
29581 + dev_err(&data->rtc->dev, "Timeout trying to get valid LPSRT Counter read\n");
29582 + return -ETIMEDOUT;
29583 +diff --git a/drivers/rtc/rtc-st-lpc.c b/drivers/rtc/rtc-st-lpc.c
29584 +index bdb20f63254e2..0f8e4231098ef 100644
29585 +--- a/drivers/rtc/rtc-st-lpc.c
29586 ++++ b/drivers/rtc/rtc-st-lpc.c
29587 +@@ -238,6 +238,7 @@ static int st_rtc_probe(struct platform_device *pdev)
29588 +
29589 + rtc->clkrate = clk_get_rate(rtc->clk);
29590 + if (!rtc->clkrate) {
29591 ++ clk_disable_unprepare(rtc->clk);
29592 + dev_err(&pdev->dev, "Unable to fetch clock rate\n");
29593 + return -EINVAL;
29594 + }
29595 +diff --git a/drivers/s390/net/ctcm_main.c b/drivers/s390/net/ctcm_main.c
29596 +index e0fdd54bfeb70..f672c610cb24a 100644
29597 +--- a/drivers/s390/net/ctcm_main.c
29598 ++++ b/drivers/s390/net/ctcm_main.c
29599 +@@ -825,16 +825,9 @@ done:
29600 + /*
29601 + * Start transmission of a packet.
29602 + * Called from generic network device layer.
29603 +- *
29604 +- * skb Pointer to buffer containing the packet.
29605 +- * dev Pointer to interface struct.
29606 +- *
29607 +- * returns 0 if packet consumed, !0 if packet rejected.
29608 +- * Note: If we return !0, then the packet is free'd by
29609 +- * the generic network layer.
29610 + */
29611 + /* first merge version - leaving both functions separated */
29612 +-static int ctcm_tx(struct sk_buff *skb, struct net_device *dev)
29613 ++static netdev_tx_t ctcm_tx(struct sk_buff *skb, struct net_device *dev)
29614 + {
29615 + struct ctcm_priv *priv = dev->ml_priv;
29616 +
29617 +@@ -877,7 +870,7 @@ static int ctcm_tx(struct sk_buff *skb, struct net_device *dev)
29618 + }
29619 +
29620 + /* unmerged MPC variant of ctcm_tx */
29621 +-static int ctcmpc_tx(struct sk_buff *skb, struct net_device *dev)
29622 ++static netdev_tx_t ctcmpc_tx(struct sk_buff *skb, struct net_device *dev)
29623 + {
29624 + int len = 0;
29625 + struct ctcm_priv *priv = dev->ml_priv;
29626 +diff --git a/drivers/s390/net/lcs.c b/drivers/s390/net/lcs.c
29627 +index 84c8981317b46..38f312664ce72 100644
29628 +--- a/drivers/s390/net/lcs.c
29629 ++++ b/drivers/s390/net/lcs.c
29630 +@@ -1519,9 +1519,8 @@ lcs_txbuffer_cb(struct lcs_channel *channel, struct lcs_buffer *buffer)
29631 + /*
29632 + * Packet transmit function called by network stack
29633 + */
29634 +-static int
29635 +-__lcs_start_xmit(struct lcs_card *card, struct sk_buff *skb,
29636 +- struct net_device *dev)
29637 ++static netdev_tx_t __lcs_start_xmit(struct lcs_card *card, struct sk_buff *skb,
29638 ++ struct net_device *dev)
29639 + {
29640 + struct lcs_header *header;
29641 + int rc = NETDEV_TX_OK;
29642 +@@ -1582,8 +1581,7 @@ out:
29643 + return rc;
29644 + }
29645 +
29646 +-static int
29647 +-lcs_start_xmit(struct sk_buff *skb, struct net_device *dev)
29648 ++static netdev_tx_t lcs_start_xmit(struct sk_buff *skb, struct net_device *dev)
29649 + {
29650 + struct lcs_card *card;
29651 + int rc;
29652 +diff --git a/drivers/s390/net/netiucv.c b/drivers/s390/net/netiucv.c
29653 +index 65aa0a96c21de..66076cada8ae4 100644
29654 +--- a/drivers/s390/net/netiucv.c
29655 ++++ b/drivers/s390/net/netiucv.c
29656 +@@ -1248,15 +1248,8 @@ static int netiucv_close(struct net_device *dev)
29657 + /*
29658 + * Start transmission of a packet.
29659 + * Called from generic network device layer.
29660 +- *
29661 +- * @param skb Pointer to buffer containing the packet.
29662 +- * @param dev Pointer to interface struct.
29663 +- *
29664 +- * @return 0 if packet consumed, !0 if packet rejected.
29665 +- * Note: If we return !0, then the packet is free'd by
29666 +- * the generic network layer.
29667 + */
29668 +-static int netiucv_tx(struct sk_buff *skb, struct net_device *dev)
29669 ++static netdev_tx_t netiucv_tx(struct sk_buff *skb, struct net_device *dev)
29670 + {
29671 + struct netiucv_priv *privptr = netdev_priv(dev);
29672 + int rc;
29673 +diff --git a/drivers/scsi/elx/efct/efct_driver.c b/drivers/scsi/elx/efct/efct_driver.c
29674 +index b08fc8839808d..49fd2cfed70c7 100644
29675 +--- a/drivers/scsi/elx/efct/efct_driver.c
29676 ++++ b/drivers/scsi/elx/efct/efct_driver.c
29677 +@@ -42,6 +42,7 @@ efct_device_init(void)
29678 +
29679 + rc = efct_scsi_reg_fc_transport();
29680 + if (rc) {
29681 ++ efct_scsi_tgt_driver_exit();
29682 + pr_err("failed to register to FC host\n");
29683 + return rc;
29684 + }
29685 +diff --git a/drivers/scsi/elx/libefc/efclib.h b/drivers/scsi/elx/libefc/efclib.h
29686 +index dde20891c2dd7..57e3386128127 100644
29687 +--- a/drivers/scsi/elx/libefc/efclib.h
29688 ++++ b/drivers/scsi/elx/libefc/efclib.h
29689 +@@ -58,10 +58,12 @@ enum efc_node_send_ls_acc {
29690 + #define EFC_LINK_STATUS_UP 0
29691 + #define EFC_LINK_STATUS_DOWN 1
29692 +
29693 ++enum efc_sm_event;
29694 ++
29695 + /* State machine context header */
29696 + struct efc_sm_ctx {
29697 + void (*current_state)(struct efc_sm_ctx *ctx,
29698 +- u32 evt, void *arg);
29699 ++ enum efc_sm_event evt, void *arg);
29700 +
29701 + const char *description;
29702 + void *app;
29703 +@@ -365,7 +367,7 @@ struct efc_node {
29704 + int prev_evt;
29705 +
29706 + void (*nodedb_state)(struct efc_sm_ctx *ctx,
29707 +- u32 evt, void *arg);
29708 ++ enum efc_sm_event evt, void *arg);
29709 + struct timer_list gidpt_delay_timer;
29710 + u64 time_last_gidpt_msec;
29711 +
29712 +diff --git a/drivers/scsi/fcoe/fcoe.c b/drivers/scsi/fcoe/fcoe.c
29713 +index 6ec296321ffc1..38774a272e627 100644
29714 +--- a/drivers/scsi/fcoe/fcoe.c
29715 ++++ b/drivers/scsi/fcoe/fcoe.c
29716 +@@ -2491,6 +2491,7 @@ static int __init fcoe_init(void)
29717 +
29718 + out_free:
29719 + mutex_unlock(&fcoe_config_mutex);
29720 ++ fcoe_transport_detach(&fcoe_sw_transport);
29721 + out_destroy:
29722 + destroy_workqueue(fcoe_wq);
29723 + return rc;
29724 +diff --git a/drivers/scsi/fcoe/fcoe_sysfs.c b/drivers/scsi/fcoe/fcoe_sysfs.c
29725 +index af658aa38fedf..6260aa5ea6af8 100644
29726 +--- a/drivers/scsi/fcoe/fcoe_sysfs.c
29727 ++++ b/drivers/scsi/fcoe/fcoe_sysfs.c
29728 +@@ -830,14 +830,15 @@ struct fcoe_ctlr_device *fcoe_ctlr_device_add(struct device *parent,
29729 +
29730 + dev_set_name(&ctlr->dev, "ctlr_%d", ctlr->id);
29731 + error = device_register(&ctlr->dev);
29732 +- if (error)
29733 +- goto out_del_q2;
29734 ++ if (error) {
29735 ++ destroy_workqueue(ctlr->devloss_work_q);
29736 ++ destroy_workqueue(ctlr->work_q);
29737 ++ put_device(&ctlr->dev);
29738 ++ return NULL;
29739 ++ }
29740 +
29741 + return ctlr;
29742 +
29743 +-out_del_q2:
29744 +- destroy_workqueue(ctlr->devloss_work_q);
29745 +- ctlr->devloss_work_q = NULL;
29746 + out_del_q:
29747 + destroy_workqueue(ctlr->work_q);
29748 + ctlr->work_q = NULL;
29749 +@@ -1036,16 +1037,16 @@ struct fcoe_fcf_device *fcoe_fcf_device_add(struct fcoe_ctlr_device *ctlr,
29750 + fcf->selected = new_fcf->selected;
29751 +
29752 + error = device_register(&fcf->dev);
29753 +- if (error)
29754 +- goto out_del;
29755 ++ if (error) {
29756 ++ put_device(&fcf->dev);
29757 ++ goto out;
29758 ++ }
29759 +
29760 + fcf->state = FCOE_FCF_STATE_CONNECTED;
29761 + list_add_tail(&fcf->peers, &ctlr->fcfs);
29762 +
29763 + return fcf;
29764 +
29765 +-out_del:
29766 +- kfree(fcf);
29767 + out:
29768 + return NULL;
29769 + }
29770 +diff --git a/drivers/scsi/hisi_sas/hisi_sas_main.c b/drivers/scsi/hisi_sas/hisi_sas_main.c
29771 +index 33af5b8dede20..f4f9e5abee76d 100644
29772 +--- a/drivers/scsi/hisi_sas/hisi_sas_main.c
29773 ++++ b/drivers/scsi/hisi_sas/hisi_sas_main.c
29774 +@@ -1701,13 +1701,15 @@ static int hisi_sas_debug_I_T_nexus_reset(struct domain_device *device)
29775 + return rc;
29776 + }
29777 +
29778 ++ /* Remote phy */
29779 + if (rc)
29780 + return rc;
29781 +
29782 +- /* Remote phy */
29783 + if (dev_is_sata(device)) {
29784 +- rc = sas_ata_wait_after_reset(device,
29785 +- HISI_SAS_WAIT_PHYUP_TIMEOUT);
29786 ++ struct ata_link *link = &device->sata_dev.ap->link;
29787 ++
29788 ++ rc = ata_wait_after_reset(link, HISI_SAS_WAIT_PHYUP_TIMEOUT,
29789 ++ smp_ata_check_ready_type);
29790 + } else {
29791 + msleep(2000);
29792 + }
29793 +diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
29794 +index a47bcce3c9c78..796bc7aa6c8e4 100644
29795 +--- a/drivers/scsi/hpsa.c
29796 ++++ b/drivers/scsi/hpsa.c
29797 +@@ -8929,7 +8929,7 @@ clean1: /* wq/aer/h */
29798 + destroy_workqueue(h->monitor_ctlr_wq);
29799 + h->monitor_ctlr_wq = NULL;
29800 + }
29801 +- kfree(h);
29802 ++ hpda_free_ctlr_info(h);
29803 + return rc;
29804 + }
29805 +
29806 +@@ -9790,7 +9790,8 @@ static int hpsa_add_sas_host(struct ctlr_info *h)
29807 + return 0;
29808 +
29809 + free_sas_phy:
29810 +- hpsa_free_sas_phy(hpsa_sas_phy);
29811 ++ sas_phy_free(hpsa_sas_phy->phy);
29812 ++ kfree(hpsa_sas_phy);
29813 + free_sas_port:
29814 + hpsa_free_sas_port(hpsa_sas_port);
29815 + free_sas_node:
29816 +@@ -9826,10 +9827,12 @@ static int hpsa_add_sas_device(struct hpsa_sas_node *hpsa_sas_node,
29817 +
29818 + rc = hpsa_sas_port_add_rphy(hpsa_sas_port, rphy);
29819 + if (rc)
29820 +- goto free_sas_port;
29821 ++ goto free_sas_rphy;
29822 +
29823 + return 0;
29824 +
29825 ++free_sas_rphy:
29826 ++ sas_rphy_free(rphy);
29827 + free_sas_port:
29828 + hpsa_free_sas_port(hpsa_sas_port);
29829 + device->sas_port = NULL;
29830 +diff --git a/drivers/scsi/ipr.c b/drivers/scsi/ipr.c
29831 +index 9d01a3e3c26aa..2022ffb450417 100644
29832 +--- a/drivers/scsi/ipr.c
29833 ++++ b/drivers/scsi/ipr.c
29834 +@@ -10872,11 +10872,19 @@ static struct notifier_block ipr_notifier = {
29835 + **/
29836 + static int __init ipr_init(void)
29837 + {
29838 ++ int rc;
29839 ++
29840 + ipr_info("IBM Power RAID SCSI Device Driver version: %s %s\n",
29841 + IPR_DRIVER_VERSION, IPR_DRIVER_DATE);
29842 +
29843 + register_reboot_notifier(&ipr_notifier);
29844 +- return pci_register_driver(&ipr_driver);
29845 ++ rc = pci_register_driver(&ipr_driver);
29846 ++ if (rc) {
29847 ++ unregister_reboot_notifier(&ipr_notifier);
29848 ++ return rc;
29849 ++ }
29850 ++
29851 ++ return 0;
29852 + }
29853 +
29854 + /**
29855 +diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
29856 +index d35c9296f7388..2fd55ef9ffca5 100644
29857 +--- a/drivers/scsi/libsas/sas_ata.c
29858 ++++ b/drivers/scsi/libsas/sas_ata.c
29859 +@@ -287,6 +287,31 @@ static int sas_ata_clear_pending(struct domain_device *dev, struct ex_phy *phy)
29860 + return 1;
29861 + }
29862 +
29863 ++int smp_ata_check_ready_type(struct ata_link *link)
29864 ++{
29865 ++ struct domain_device *dev = link->ap->private_data;
29866 ++ struct sas_phy *phy = sas_get_local_phy(dev);
29867 ++ struct domain_device *ex_dev = dev->parent;
29868 ++ enum sas_device_type type = SAS_PHY_UNUSED;
29869 ++ u8 sas_addr[SAS_ADDR_SIZE];
29870 ++ int res;
29871 ++
29872 ++ res = sas_get_phy_attached_dev(ex_dev, phy->number, sas_addr, &type);
29873 ++ sas_put_local_phy(phy);
29874 ++ if (res)
29875 ++ return res;
29876 ++
29877 ++ switch (type) {
29878 ++ case SAS_SATA_PENDING:
29879 ++ return 0;
29880 ++ case SAS_END_DEVICE:
29881 ++ return 1;
29882 ++ default:
29883 ++ return -ENODEV;
29884 ++ }
29885 ++}
29886 ++EXPORT_SYMBOL_GPL(smp_ata_check_ready_type);
29887 ++
29888 + static int smp_ata_check_ready(struct ata_link *link)
29889 + {
29890 + int res;
29891 +diff --git a/drivers/scsi/libsas/sas_expander.c b/drivers/scsi/libsas/sas_expander.c
29892 +index 5ce2518301040..63a23251fb1d8 100644
29893 +--- a/drivers/scsi/libsas/sas_expander.c
29894 ++++ b/drivers/scsi/libsas/sas_expander.c
29895 +@@ -1693,8 +1693,8 @@ static int sas_get_phy_change_count(struct domain_device *dev,
29896 + return res;
29897 + }
29898 +
29899 +-static int sas_get_phy_attached_dev(struct domain_device *dev, int phy_id,
29900 +- u8 *sas_addr, enum sas_device_type *type)
29901 ++int sas_get_phy_attached_dev(struct domain_device *dev, int phy_id,
29902 ++ u8 *sas_addr, enum sas_device_type *type)
29903 + {
29904 + int res;
29905 + struct smp_disc_resp *disc_resp;
29906 +diff --git a/drivers/scsi/libsas/sas_internal.h b/drivers/scsi/libsas/sas_internal.h
29907 +index 8d0ad3abc7b5c..a94bd0790b055 100644
29908 +--- a/drivers/scsi/libsas/sas_internal.h
29909 ++++ b/drivers/scsi/libsas/sas_internal.h
29910 +@@ -84,6 +84,8 @@ struct domain_device *sas_ex_to_ata(struct domain_device *ex_dev, int phy_id);
29911 + int sas_ex_phy_discover(struct domain_device *dev, int single);
29912 + int sas_get_report_phy_sata(struct domain_device *dev, int phy_id,
29913 + struct smp_rps_resp *rps_resp);
29914 ++int sas_get_phy_attached_dev(struct domain_device *dev, int phy_id,
29915 ++ u8 *sas_addr, enum sas_device_type *type);
29916 + int sas_try_ata_reset(struct asd_sas_phy *phy);
29917 + void sas_hae_reset(struct work_struct *work);
29918 +
29919 +diff --git a/drivers/scsi/lpfc/lpfc_sli.c b/drivers/scsi/lpfc/lpfc_sli.c
29920 +index 03c21167fc854..c4960da4c1c40 100644
29921 +--- a/drivers/scsi/lpfc/lpfc_sli.c
29922 ++++ b/drivers/scsi/lpfc/lpfc_sli.c
29923 +@@ -8076,10 +8076,10 @@ u32 lpfc_rx_monitor_report(struct lpfc_hba *phba,
29924 + "IO_cnt", "Info", "BWutil(ms)");
29925 + }
29926 +
29927 +- /* Needs to be _bh because record is called from timer interrupt
29928 ++ /* Needs to be _irq because record is called from timer interrupt
29929 + * context
29930 + */
29931 +- spin_lock_bh(ring_lock);
29932 ++ spin_lock_irq(ring_lock);
29933 + while (*head_idx != *tail_idx) {
29934 + entry = &ring[*head_idx];
29935 +
29936 +@@ -8123,7 +8123,7 @@ u32 lpfc_rx_monitor_report(struct lpfc_hba *phba,
29937 + if (cnt >= max_read_entries)
29938 + break;
29939 + }
29940 +- spin_unlock_bh(ring_lock);
29941 ++ spin_unlock_irq(ring_lock);
29942 +
29943 + return cnt;
29944 + }
29945 +diff --git a/drivers/scsi/mpt3sas/mpt3sas_transport.c b/drivers/scsi/mpt3sas/mpt3sas_transport.c
29946 +index 0681daee6c149..e5ecd6ada6cdd 100644
29947 +--- a/drivers/scsi/mpt3sas/mpt3sas_transport.c
29948 ++++ b/drivers/scsi/mpt3sas/mpt3sas_transport.c
29949 +@@ -829,6 +829,8 @@ mpt3sas_transport_port_add(struct MPT3SAS_ADAPTER *ioc, u16 handle,
29950 + if ((sas_rphy_add(rphy))) {
29951 + ioc_err(ioc, "failure at %s:%d/%s()!\n",
29952 + __FILE__, __LINE__, __func__);
29953 ++ sas_rphy_free(rphy);
29954 ++ rphy = NULL;
29955 + }
29956 +
29957 + if (mpt3sas_port->remote_identify.device_type == SAS_END_DEVICE) {
29958 +diff --git a/drivers/scsi/qla2xxx/qla_def.h b/drivers/scsi/qla2xxx/qla_def.h
29959 +index 3ec6a200942ee..01ca440ce6203 100644
29960 +--- a/drivers/scsi/qla2xxx/qla_def.h
29961 ++++ b/drivers/scsi/qla2xxx/qla_def.h
29962 +@@ -5129,17 +5129,17 @@ struct secure_flash_update_block_pk {
29963 + (test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags) || \
29964 + test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
29965 +
29966 +-#define QLA_VHA_MARK_BUSY(__vha, __bail) do { \
29967 +- atomic_inc(&__vha->vref_count); \
29968 +- mb(); \
29969 +- if (__vha->flags.delete_progress) { \
29970 +- atomic_dec(&__vha->vref_count); \
29971 +- wake_up(&__vha->vref_waitq); \
29972 +- __bail = 1; \
29973 +- } else { \
29974 +- __bail = 0; \
29975 +- } \
29976 +-} while (0)
29977 ++static inline bool qla_vha_mark_busy(scsi_qla_host_t *vha)
29978 ++{
29979 ++ atomic_inc(&vha->vref_count);
29980 ++ mb();
29981 ++ if (vha->flags.delete_progress) {
29982 ++ atomic_dec(&vha->vref_count);
29983 ++ wake_up(&vha->vref_waitq);
29984 ++ return true;
29985 ++ }
29986 ++ return false;
29987 ++}
29988 +
29989 + #define QLA_VHA_MARK_NOT_BUSY(__vha) do { \
29990 + atomic_dec(&__vha->vref_count); \
29991 +diff --git a/drivers/scsi/qla2xxx/qla_init.c b/drivers/scsi/qla2xxx/qla_init.c
29992 +index e7fe0e52c11d4..97cf9c25adf09 100644
29993 +--- a/drivers/scsi/qla2xxx/qla_init.c
29994 ++++ b/drivers/scsi/qla2xxx/qla_init.c
29995 +@@ -110,6 +110,7 @@ static void qla24xx_abort_iocb_timeout(void *data)
29996 + struct qla_qpair *qpair = sp->qpair;
29997 + u32 handle;
29998 + unsigned long flags;
29999 ++ int sp_found = 0, cmdsp_found = 0;
30000 +
30001 + if (sp->cmd_sp)
30002 + ql_dbg(ql_dbg_async, sp->vha, 0x507c,
30003 +@@ -124,18 +125,21 @@ static void qla24xx_abort_iocb_timeout(void *data)
30004 + spin_lock_irqsave(qpair->qp_lock_ptr, flags);
30005 + for (handle = 1; handle < qpair->req->num_outstanding_cmds; handle++) {
30006 + if (sp->cmd_sp && (qpair->req->outstanding_cmds[handle] ==
30007 +- sp->cmd_sp))
30008 ++ sp->cmd_sp)) {
30009 + qpair->req->outstanding_cmds[handle] = NULL;
30010 ++ cmdsp_found = 1;
30011 ++ }
30012 +
30013 + /* removing the abort */
30014 + if (qpair->req->outstanding_cmds[handle] == sp) {
30015 + qpair->req->outstanding_cmds[handle] = NULL;
30016 ++ sp_found = 1;
30017 + break;
30018 + }
30019 + }
30020 + spin_unlock_irqrestore(qpair->qp_lock_ptr, flags);
30021 +
30022 +- if (sp->cmd_sp) {
30023 ++ if (cmdsp_found && sp->cmd_sp) {
30024 + /*
30025 + * This done function should take care of
30026 + * original command ref: INIT
30027 +@@ -143,8 +147,10 @@ static void qla24xx_abort_iocb_timeout(void *data)
30028 + sp->cmd_sp->done(sp->cmd_sp, QLA_OS_TIMER_EXPIRED);
30029 + }
30030 +
30031 +- abt->u.abt.comp_status = cpu_to_le16(CS_TIMEOUT);
30032 +- sp->done(sp, QLA_OS_TIMER_EXPIRED);
30033 ++ if (sp_found) {
30034 ++ abt->u.abt.comp_status = cpu_to_le16(CS_TIMEOUT);
30035 ++ sp->done(sp, QLA_OS_TIMER_EXPIRED);
30036 ++ }
30037 + }
30038 +
30039 + static void qla24xx_abort_sp_done(srb_t *sp, int res)
30040 +@@ -168,7 +174,6 @@ int qla24xx_async_abort_cmd(srb_t *cmd_sp, bool wait)
30041 + struct srb_iocb *abt_iocb;
30042 + srb_t *sp;
30043 + int rval = QLA_FUNCTION_FAILED;
30044 +- uint8_t bail;
30045 +
30046 + /* ref: INIT for ABTS command */
30047 + sp = qla2xxx_get_qpair_sp(cmd_sp->vha, cmd_sp->qpair, cmd_sp->fcport,
30048 +@@ -176,7 +181,7 @@ int qla24xx_async_abort_cmd(srb_t *cmd_sp, bool wait)
30049 + if (!sp)
30050 + return QLA_MEMORY_ALLOC_FAILED;
30051 +
30052 +- QLA_VHA_MARK_BUSY(vha, bail);
30053 ++ qla_vha_mark_busy(vha);
30054 + abt_iocb = &sp->u.iocb_cmd;
30055 + sp->type = SRB_ABT_CMD;
30056 + sp->name = "abort";
30057 +@@ -2020,14 +2025,13 @@ qla2x00_async_tm_cmd(fc_port_t *fcport, uint32_t flags, uint32_t lun,
30058 + struct srb_iocb *tm_iocb;
30059 + srb_t *sp;
30060 + int rval = QLA_FUNCTION_FAILED;
30061 +- uint8_t bail;
30062 +
30063 + /* ref: INIT */
30064 + sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
30065 + if (!sp)
30066 + goto done;
30067 +
30068 +- QLA_VHA_MARK_BUSY(vha, bail);
30069 ++ qla_vha_mark_busy(vha);
30070 + sp->type = SRB_TM_CMD;
30071 + sp->name = "tmf";
30072 + qla2x00_init_async_sp(sp, qla2x00_get_async_timeout(vha),
30073 +diff --git a/drivers/scsi/qla2xxx/qla_inline.h b/drivers/scsi/qla2xxx/qla_inline.h
30074 +index db17f7f410cdd..5185dc5daf80d 100644
30075 +--- a/drivers/scsi/qla2xxx/qla_inline.h
30076 ++++ b/drivers/scsi/qla2xxx/qla_inline.h
30077 +@@ -225,11 +225,9 @@ static inline srb_t *
30078 + qla2x00_get_sp(scsi_qla_host_t *vha, fc_port_t *fcport, gfp_t flag)
30079 + {
30080 + srb_t *sp = NULL;
30081 +- uint8_t bail;
30082 + struct qla_qpair *qpair;
30083 +
30084 +- QLA_VHA_MARK_BUSY(vha, bail);
30085 +- if (unlikely(bail))
30086 ++ if (unlikely(qla_vha_mark_busy(vha)))
30087 + return NULL;
30088 +
30089 + qpair = vha->hw->base_qpair;
30090 +diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
30091 +index 1c7fb6484db20..5e5d1a6c51d52 100644
30092 +--- a/drivers/scsi/qla2xxx/qla_os.c
30093 ++++ b/drivers/scsi/qla2xxx/qla_os.c
30094 +@@ -5039,13 +5039,11 @@ struct qla_work_evt *
30095 + qla2x00_alloc_work(struct scsi_qla_host *vha, enum qla_work_type type)
30096 + {
30097 + struct qla_work_evt *e;
30098 +- uint8_t bail;
30099 +
30100 + if (test_bit(UNLOADING, &vha->dpc_flags))
30101 + return NULL;
30102 +
30103 +- QLA_VHA_MARK_BUSY(vha, bail);
30104 +- if (bail)
30105 ++ if (qla_vha_mark_busy(vha))
30106 + return NULL;
30107 +
30108 + e = kzalloc(sizeof(struct qla_work_evt), GFP_ATOMIC);
30109 +diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c
30110 +index 7346098c1c68f..34eb0a9355bca 100644
30111 +--- a/drivers/scsi/scsi_debug.c
30112 ++++ b/drivers/scsi/scsi_debug.c
30113 +@@ -3785,7 +3785,7 @@ static int resp_write_scat(struct scsi_cmnd *scp,
30114 + mk_sense_buffer(scp, ILLEGAL_REQUEST, INVALID_FIELD_IN_CDB, 0);
30115 + return illegal_condition_result;
30116 + }
30117 +- lrdp = kzalloc(lbdof_blen, GFP_ATOMIC);
30118 ++ lrdp = kzalloc(lbdof_blen, GFP_ATOMIC | __GFP_NOWARN);
30119 + if (lrdp == NULL)
30120 + return SCSI_MLQUEUE_HOST_BUSY;
30121 + if (sdebug_verbose)
30122 +@@ -4436,7 +4436,7 @@ static int resp_verify(struct scsi_cmnd *scp, struct sdebug_dev_info *devip)
30123 + if (ret)
30124 + return ret;
30125 +
30126 +- arr = kcalloc(lb_size, vnum, GFP_ATOMIC);
30127 ++ arr = kcalloc(lb_size, vnum, GFP_ATOMIC | __GFP_NOWARN);
30128 + if (!arr) {
30129 + mk_sense_buffer(scp, ILLEGAL_REQUEST, INSUFF_RES_ASC,
30130 + INSUFF_RES_ASCQ);
30131 +@@ -4504,7 +4504,7 @@ static int resp_report_zones(struct scsi_cmnd *scp,
30132 +
30133 + rep_max_zones = (alloc_len - 64) >> ilog2(RZONES_DESC_HD);
30134 +
30135 +- arr = kzalloc(alloc_len, GFP_ATOMIC);
30136 ++ arr = kzalloc(alloc_len, GFP_ATOMIC | __GFP_NOWARN);
30137 + if (!arr) {
30138 + mk_sense_buffer(scp, ILLEGAL_REQUEST, INSUFF_RES_ASC,
30139 + INSUFF_RES_ASCQ);
30140 +@@ -7340,7 +7340,10 @@ clean:
30141 + kfree(sdbg_devinfo->zstate);
30142 + kfree(sdbg_devinfo);
30143 + }
30144 +- kfree(sdbg_host);
30145 ++ if (sdbg_host->dev.release)
30146 ++ put_device(&sdbg_host->dev);
30147 ++ else
30148 ++ kfree(sdbg_host);
30149 + pr_warn("%s: failed, errno=%d\n", __func__, -error);
30150 + return error;
30151 + }
30152 +diff --git a/drivers/scsi/scsi_error.c b/drivers/scsi/scsi_error.c
30153 +index 448748e3fba5e..f00212777f82c 100644
30154 +--- a/drivers/scsi/scsi_error.c
30155 ++++ b/drivers/scsi/scsi_error.c
30156 +@@ -342,19 +342,11 @@ enum blk_eh_timer_return scsi_timeout(struct request *req)
30157 +
30158 + if (rtn == BLK_EH_DONE) {
30159 + /*
30160 +- * Set the command to complete first in order to prevent a real
30161 +- * completion from releasing the command while error handling
30162 +- * is using it. If the command was already completed, then the
30163 +- * lower level driver beat the timeout handler, and it is safe
30164 +- * to return without escalating error recovery.
30165 +- *
30166 +- * If timeout handling lost the race to a real completion, the
30167 +- * block layer may ignore that due to a fake timeout injection,
30168 +- * so return RESET_TIMER to allow error handling another shot
30169 +- * at this command.
30170 ++ * If scsi_done() has already set SCMD_STATE_COMPLETE, do not
30171 ++ * modify *scmd.
30172 + */
30173 + if (test_and_set_bit(SCMD_STATE_COMPLETE, &scmd->state))
30174 +- return BLK_EH_RESET_TIMER;
30175 ++ return BLK_EH_DONE;
30176 + if (scsi_abort_command(scmd) != SUCCESS) {
30177 + set_host_byte(scmd, DID_TIME_OUT);
30178 + scsi_eh_scmd_add(scmd);
30179 +diff --git a/drivers/scsi/smartpqi/smartpqi.h b/drivers/scsi/smartpqi/smartpqi.h
30180 +index e550b12e525a1..c8235f15728bb 100644
30181 +--- a/drivers/scsi/smartpqi/smartpqi.h
30182 ++++ b/drivers/scsi/smartpqi/smartpqi.h
30183 +@@ -1130,7 +1130,7 @@ struct pqi_scsi_dev {
30184 + u8 phy_id;
30185 + u8 ncq_prio_enable;
30186 + u8 ncq_prio_support;
30187 +- u8 multi_lun_device_lun_count;
30188 ++ u8 lun_count;
30189 + bool raid_bypass_configured; /* RAID bypass configured */
30190 + bool raid_bypass_enabled; /* RAID bypass enabled */
30191 + u32 next_bypass_group[RAID_MAP_MAX_DATA_DISKS_PER_ROW];
30192 +diff --git a/drivers/scsi/smartpqi/smartpqi_init.c b/drivers/scsi/smartpqi/smartpqi_init.c
30193 +index 7a8c2c75acbaf..e011d82172d53 100644
30194 +--- a/drivers/scsi/smartpqi/smartpqi_init.c
30195 ++++ b/drivers/scsi/smartpqi/smartpqi_init.c
30196 +@@ -1610,9 +1610,7 @@ static int pqi_get_physical_device_info(struct pqi_ctrl_info *ctrl_info,
30197 + &id_phys->alternate_paths_phys_connector,
30198 + sizeof(device->phys_connector));
30199 + device->bay = id_phys->phys_bay_in_box;
30200 +- device->multi_lun_device_lun_count = id_phys->multi_lun_device_lun_count;
30201 +- if (!device->multi_lun_device_lun_count)
30202 +- device->multi_lun_device_lun_count = 1;
30203 ++ device->lun_count = id_phys->multi_lun_device_lun_count;
30204 + if ((id_phys->even_more_flags & PQI_DEVICE_PHY_MAP_SUPPORTED) &&
30205 + id_phys->phy_count)
30206 + device->phy_id =
30207 +@@ -1746,7 +1744,7 @@ out:
30208 + return offline;
30209 + }
30210 +
30211 +-static int pqi_get_device_info(struct pqi_ctrl_info *ctrl_info,
30212 ++static int pqi_get_device_info_phys_logical(struct pqi_ctrl_info *ctrl_info,
30213 + struct pqi_scsi_dev *device,
30214 + struct bmic_identify_physical_device *id_phys)
30215 + {
30216 +@@ -1763,6 +1761,20 @@ static int pqi_get_device_info(struct pqi_ctrl_info *ctrl_info,
30217 + return rc;
30218 + }
30219 +
30220 ++static int pqi_get_device_info(struct pqi_ctrl_info *ctrl_info,
30221 ++ struct pqi_scsi_dev *device,
30222 ++ struct bmic_identify_physical_device *id_phys)
30223 ++{
30224 ++ int rc;
30225 ++
30226 ++ rc = pqi_get_device_info_phys_logical(ctrl_info, device, id_phys);
30227 ++
30228 ++ if (rc == 0 && device->lun_count == 0)
30229 ++ device->lun_count = 1;
30230 ++
30231 ++ return rc;
30232 ++}
30233 ++
30234 + static void pqi_show_volume_status(struct pqi_ctrl_info *ctrl_info,
30235 + struct pqi_scsi_dev *device)
30236 + {
30237 +@@ -1897,7 +1909,7 @@ static inline void pqi_remove_device(struct pqi_ctrl_info *ctrl_info, struct pqi
30238 + int rc;
30239 + int lun;
30240 +
30241 +- for (lun = 0; lun < device->multi_lun_device_lun_count; lun++) {
30242 ++ for (lun = 0; lun < device->lun_count; lun++) {
30243 + rc = pqi_device_wait_for_pending_io(ctrl_info, device, lun,
30244 + PQI_REMOVE_DEVICE_PENDING_IO_TIMEOUT_MSECS);
30245 + if (rc)
30246 +@@ -2076,6 +2088,7 @@ static void pqi_scsi_update_device(struct pqi_ctrl_info *ctrl_info,
30247 + existing_device->sas_address = new_device->sas_address;
30248 + existing_device->queue_depth = new_device->queue_depth;
30249 + existing_device->device_offline = false;
30250 ++ existing_device->lun_count = new_device->lun_count;
30251 +
30252 + if (pqi_is_logical_device(existing_device)) {
30253 + existing_device->is_external_raid_device = new_device->is_external_raid_device;
30254 +@@ -2108,10 +2121,6 @@ static void pqi_scsi_update_device(struct pqi_ctrl_info *ctrl_info,
30255 + existing_device->phy_connected_dev_type = new_device->phy_connected_dev_type;
30256 + memcpy(existing_device->box, new_device->box, sizeof(existing_device->box));
30257 + memcpy(existing_device->phys_connector, new_device->phys_connector, sizeof(existing_device->phys_connector));
30258 +-
30259 +- existing_device->multi_lun_device_lun_count = new_device->multi_lun_device_lun_count;
30260 +- if (existing_device->multi_lun_device_lun_count == 0)
30261 +- existing_device->multi_lun_device_lun_count = 1;
30262 + }
30263 + }
30264 +
30265 +@@ -6484,6 +6493,12 @@ static void pqi_slave_destroy(struct scsi_device *sdev)
30266 + return;
30267 + }
30268 +
30269 ++ device->lun_count--;
30270 ++ if (device->lun_count > 0) {
30271 ++ mutex_unlock(&ctrl_info->scan_mutex);
30272 ++ return;
30273 ++ }
30274 ++
30275 + spin_lock_irqsave(&ctrl_info->scsi_device_list_lock, flags);
30276 + list_del(&device->scsi_device_list_entry);
30277 + spin_unlock_irqrestore(&ctrl_info->scsi_device_list_lock, flags);
30278 +@@ -9302,6 +9317,10 @@ static const struct pci_device_id pqi_pci_id_table[] = {
30279 + PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2, 0x028f,
30280 + 0x193d, 0x1109)
30281 + },
30282 ++ {
30283 ++ PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2, 0x028f,
30284 ++ 0x193d, 0x110b)
30285 ++ },
30286 + {
30287 + PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2, 0x028f,
30288 + 0x193d, 0x8460)
30289 +@@ -9402,6 +9421,22 @@ static const struct pci_device_id pqi_pci_id_table[] = {
30290 + PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2, 0x028f,
30291 + 0x1bd4, 0x0072)
30292 + },
30293 ++ {
30294 ++ PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2, 0x028f,
30295 ++ 0x1bd4, 0x0086)
30296 ++ },
30297 ++ {
30298 ++ PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2, 0x028f,
30299 ++ 0x1bd4, 0x0087)
30300 ++ },
30301 ++ {
30302 ++ PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2, 0x028f,
30303 ++ 0x1bd4, 0x0088)
30304 ++ },
30305 ++ {
30306 ++ PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2, 0x028f,
30307 ++ 0x1bd4, 0x0089)
30308 ++ },
30309 + {
30310 + PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2, 0x028f,
30311 + 0x19e5, 0xd227)
30312 +@@ -9650,6 +9685,10 @@ static const struct pci_device_id pqi_pci_id_table[] = {
30313 + PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2, 0x028f,
30314 + PCI_VENDOR_ID_ADAPTEC2, 0x1474)
30315 + },
30316 ++ {
30317 ++ PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2, 0x028f,
30318 ++ PCI_VENDOR_ID_ADAPTEC2, 0x1475)
30319 ++ },
30320 + {
30321 + PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2, 0x028f,
30322 + PCI_VENDOR_ID_ADAPTEC2, 0x1480)
30323 +@@ -9706,6 +9745,14 @@ static const struct pci_device_id pqi_pci_id_table[] = {
30324 + PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2, 0x028f,
30325 + PCI_VENDOR_ID_ADAPTEC2, 0x14c2)
30326 + },
30327 ++ {
30328 ++ PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2, 0x028f,
30329 ++ PCI_VENDOR_ID_ADAPTEC2, 0x14c3)
30330 ++ },
30331 ++ {
30332 ++ PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2, 0x028f,
30333 ++ PCI_VENDOR_ID_ADAPTEC2, 0x14c4)
30334 ++ },
30335 + {
30336 + PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2, 0x028f,
30337 + PCI_VENDOR_ID_ADAPTEC2, 0x14d0)
30338 +@@ -9942,6 +9989,18 @@ static const struct pci_device_id pqi_pci_id_table[] = {
30339 + PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2, 0x028f,
30340 + PCI_VENDOR_ID_LENOVO, 0x0623)
30341 + },
30342 ++ {
30343 ++ PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2, 0x028f,
30344 ++ 0x1e93, 0x1000)
30345 ++ },
30346 ++ {
30347 ++ PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2, 0x028f,
30348 ++ 0x1e93, 0x1001)
30349 ++ },
30350 ++ {
30351 ++ PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2, 0x028f,
30352 ++ 0x1e93, 0x1002)
30353 ++ },
30354 + {
30355 + PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2, 0x028f,
30356 + PCI_ANY_ID, PCI_ANY_ID)
30357 +diff --git a/drivers/scsi/snic/snic_disc.c b/drivers/scsi/snic/snic_disc.c
30358 +index 9b2b5f8c23b9a..8fbf3c1b1311d 100644
30359 +--- a/drivers/scsi/snic/snic_disc.c
30360 ++++ b/drivers/scsi/snic/snic_disc.c
30361 +@@ -304,6 +304,9 @@ snic_tgt_create(struct snic *snic, struct snic_tgt_id *tgtid)
30362 + ret);
30363 +
30364 + put_device(&snic->shost->shost_gendev);
30365 ++ spin_lock_irqsave(snic->shost->host_lock, flags);
30366 ++ list_del(&tgt->list);
30367 ++ spin_unlock_irqrestore(snic->shost->host_lock, flags);
30368 + kfree(tgt);
30369 + tgt = NULL;
30370 +
30371 +diff --git a/drivers/soc/apple/rtkit.c b/drivers/soc/apple/rtkit.c
30372 +index cf1129e9f76b1..d9329b4d8e1b8 100644
30373 +--- a/drivers/soc/apple/rtkit.c
30374 ++++ b/drivers/soc/apple/rtkit.c
30375 +@@ -920,8 +920,10 @@ int apple_rtkit_wake(struct apple_rtkit *rtk)
30376 + }
30377 + EXPORT_SYMBOL_GPL(apple_rtkit_wake);
30378 +
30379 +-static void apple_rtkit_free(struct apple_rtkit *rtk)
30380 ++static void apple_rtkit_free(void *data)
30381 + {
30382 ++ struct apple_rtkit *rtk = data;
30383 ++
30384 + mbox_free_channel(rtk->mbox_chan);
30385 + destroy_workqueue(rtk->wq);
30386 +
30387 +@@ -944,8 +946,7 @@ struct apple_rtkit *devm_apple_rtkit_init(struct device *dev, void *cookie,
30388 + if (IS_ERR(rtk))
30389 + return rtk;
30390 +
30391 +- ret = devm_add_action_or_reset(dev, (void (*)(void *))apple_rtkit_free,
30392 +- rtk);
30393 ++ ret = devm_add_action_or_reset(dev, apple_rtkit_free, rtk);
30394 + if (ret)
30395 + return ERR_PTR(ret);
30396 +
30397 +diff --git a/drivers/soc/apple/sart.c b/drivers/soc/apple/sart.c
30398 +index 83804b16ad03d..afa1117368997 100644
30399 +--- a/drivers/soc/apple/sart.c
30400 ++++ b/drivers/soc/apple/sart.c
30401 +@@ -164,6 +164,11 @@ static int apple_sart_probe(struct platform_device *pdev)
30402 + return 0;
30403 + }
30404 +
30405 ++static void apple_sart_put_device(void *dev)
30406 ++{
30407 ++ put_device(dev);
30408 ++}
30409 ++
30410 + struct apple_sart *devm_apple_sart_get(struct device *dev)
30411 + {
30412 + struct device_node *sart_node;
30413 +@@ -187,7 +192,7 @@ struct apple_sart *devm_apple_sart_get(struct device *dev)
30414 + return ERR_PTR(-EPROBE_DEFER);
30415 + }
30416 +
30417 +- ret = devm_add_action_or_reset(dev, (void (*)(void *))put_device,
30418 ++ ret = devm_add_action_or_reset(dev, apple_sart_put_device,
30419 + &sart_pdev->dev);
30420 + if (ret)
30421 + return ERR_PTR(ret);
30422 +diff --git a/drivers/soc/mediatek/mtk-pm-domains.c b/drivers/soc/mediatek/mtk-pm-domains.c
30423 +index 9734f1091c695..4b2046c37e6f6 100644
30424 +--- a/drivers/soc/mediatek/mtk-pm-domains.c
30425 ++++ b/drivers/soc/mediatek/mtk-pm-domains.c
30426 +@@ -275,9 +275,9 @@ static int scpsys_power_off(struct generic_pm_domain *genpd)
30427 + clk_bulk_disable_unprepare(pd->num_subsys_clks, pd->subsys_clks);
30428 +
30429 + /* subsys power off */
30430 +- regmap_clear_bits(scpsys->base, pd->data->ctl_offs, PWR_RST_B_BIT);
30431 + regmap_set_bits(scpsys->base, pd->data->ctl_offs, PWR_ISO_BIT);
30432 + regmap_set_bits(scpsys->base, pd->data->ctl_offs, PWR_CLK_DIS_BIT);
30433 ++ regmap_clear_bits(scpsys->base, pd->data->ctl_offs, PWR_RST_B_BIT);
30434 + regmap_clear_bits(scpsys->base, pd->data->ctl_offs, PWR_ON_2ND_BIT);
30435 + regmap_clear_bits(scpsys->base, pd->data->ctl_offs, PWR_ON_BIT);
30436 +
30437 +diff --git a/drivers/soc/qcom/apr.c b/drivers/soc/qcom/apr.c
30438 +index b4046f393575e..cd44f17dad3d0 100644
30439 +--- a/drivers/soc/qcom/apr.c
30440 ++++ b/drivers/soc/qcom/apr.c
30441 +@@ -454,11 +454,19 @@ static int apr_add_device(struct device *dev, struct device_node *np,
30442 + adev->dev.driver = NULL;
30443 +
30444 + spin_lock(&apr->svcs_lock);
30445 +- idr_alloc(&apr->svcs_idr, svc, svc_id, svc_id + 1, GFP_ATOMIC);
30446 ++ ret = idr_alloc(&apr->svcs_idr, svc, svc_id, svc_id + 1, GFP_ATOMIC);
30447 + spin_unlock(&apr->svcs_lock);
30448 ++ if (ret < 0) {
30449 ++ dev_err(dev, "idr_alloc failed: %d\n", ret);
30450 ++ goto out;
30451 ++ }
30452 +
30453 +- of_property_read_string_index(np, "qcom,protection-domain",
30454 +- 1, &adev->service_path);
30455 ++ ret = of_property_read_string_index(np, "qcom,protection-domain",
30456 ++ 1, &adev->service_path);
30457 ++ if (ret < 0) {
30458 ++ dev_err(dev, "Failed to read second value of qcom,protection-domain\n");
30459 ++ goto out;
30460 ++ }
30461 +
30462 + dev_info(dev, "Adding APR/GPR dev: %s\n", dev_name(&adev->dev));
30463 +
30464 +@@ -468,6 +476,7 @@ static int apr_add_device(struct device *dev, struct device_node *np,
30465 + put_device(&adev->dev);
30466 + }
30467 +
30468 ++out:
30469 + return ret;
30470 + }
30471 +
30472 +diff --git a/drivers/soc/qcom/llcc-qcom.c b/drivers/soc/qcom/llcc-qcom.c
30473 +index 38d7296315a25..5942417c7c20d 100644
30474 +--- a/drivers/soc/qcom/llcc-qcom.c
30475 ++++ b/drivers/soc/qcom/llcc-qcom.c
30476 +@@ -781,7 +781,7 @@ static int qcom_llcc_probe(struct platform_device *pdev)
30477 + if (ret)
30478 + goto err;
30479 +
30480 +- drv_data->ecc_irq = platform_get_irq(pdev, 0);
30481 ++ drv_data->ecc_irq = platform_get_irq_optional(pdev, 0);
30482 + if (drv_data->ecc_irq >= 0) {
30483 + llcc_edac = platform_device_register_data(&pdev->dev,
30484 + "qcom_llcc_edac", -1, drv_data,
30485 +diff --git a/drivers/soc/ti/knav_qmss_queue.c b/drivers/soc/ti/knav_qmss_queue.c
30486 +index 92af7d1b6f5bd..8fb76908be704 100644
30487 +--- a/drivers/soc/ti/knav_qmss_queue.c
30488 ++++ b/drivers/soc/ti/knav_qmss_queue.c
30489 +@@ -67,7 +67,7 @@ static DEFINE_MUTEX(knav_dev_lock);
30490 + * Newest followed by older ones. Search is done from start of the array
30491 + * until a firmware file is found.
30492 + */
30493 +-const char *knav_acc_firmwares[] = {"ks2_qmss_pdsp_acc48.bin"};
30494 ++static const char * const knav_acc_firmwares[] = {"ks2_qmss_pdsp_acc48.bin"};
30495 +
30496 + static bool device_ready;
30497 + bool knav_qmss_device_ready(void)
30498 +@@ -1785,6 +1785,7 @@ static int knav_queue_probe(struct platform_device *pdev)
30499 + pm_runtime_enable(&pdev->dev);
30500 + ret = pm_runtime_resume_and_get(&pdev->dev);
30501 + if (ret < 0) {
30502 ++ pm_runtime_disable(&pdev->dev);
30503 + dev_err(dev, "Failed to enable QMSS\n");
30504 + return ret;
30505 + }
30506 +diff --git a/drivers/soc/ti/smartreflex.c b/drivers/soc/ti/smartreflex.c
30507 +index ad2bb72e640c8..6a389a6444f36 100644
30508 +--- a/drivers/soc/ti/smartreflex.c
30509 ++++ b/drivers/soc/ti/smartreflex.c
30510 +@@ -932,6 +932,7 @@ static int omap_sr_probe(struct platform_device *pdev)
30511 + err_debugfs:
30512 + debugfs_remove_recursive(sr_info->dbg_dir);
30513 + err_list_del:
30514 ++ pm_runtime_disable(&pdev->dev);
30515 + list_del(&sr_info->node);
30516 + clk_unprepare(sr_info->fck);
30517 +
30518 +diff --git a/drivers/spi/spi-gpio.c b/drivers/spi/spi-gpio.c
30519 +index 4b12c4964a664..9c8c7948044ed 100644
30520 +--- a/drivers/spi/spi-gpio.c
30521 ++++ b/drivers/spi/spi-gpio.c
30522 +@@ -268,9 +268,19 @@ static int spi_gpio_set_direction(struct spi_device *spi, bool output)
30523 + if (output)
30524 + return gpiod_direction_output(spi_gpio->mosi, 1);
30525 +
30526 +- ret = gpiod_direction_input(spi_gpio->mosi);
30527 +- if (ret)
30528 +- return ret;
30529 ++ /*
30530 ++ * Only change MOSI to an input if using 3WIRE mode.
30531 ++ * Otherwise, MOSI could be left floating if there is
30532 ++ * no pull resistor connected to the I/O pin, or could
30533 ++ * be left logic high if there is a pull-up. Transmitting
30534 ++ * logic high when only clocking MISO data in can put some
30535 ++ * SPI devices in to a bad state.
30536 ++ */
30537 ++ if (spi->mode & SPI_3WIRE) {
30538 ++ ret = gpiod_direction_input(spi_gpio->mosi);
30539 ++ if (ret)
30540 ++ return ret;
30541 ++ }
30542 + /*
30543 + * Send a turnaround high impedance cycle when switching
30544 + * from output to input. Theoretically there should be
30545 +diff --git a/drivers/spi/spi-mt65xx.c b/drivers/spi/spi-mt65xx.c
30546 +index a7cc96aeb5903..d6aff909fc365 100644
30547 +--- a/drivers/spi/spi-mt65xx.c
30548 ++++ b/drivers/spi/spi-mt65xx.c
30549 +@@ -1187,6 +1187,11 @@ static int mtk_spi_probe(struct platform_device *pdev)
30550 + if (!dev->dma_mask)
30551 + dev->dma_mask = &dev->coherent_dma_mask;
30552 +
30553 ++ if (mdata->dev_comp->ipm_design)
30554 ++ dma_set_max_seg_size(dev, SZ_16M);
30555 ++ else
30556 ++ dma_set_max_seg_size(dev, SZ_256K);
30557 ++
30558 + ret = devm_request_irq(dev, irq, mtk_spi_interrupt,
30559 + IRQF_TRIGGER_NONE, dev_name(dev), master);
30560 + if (ret)
30561 +diff --git a/drivers/spi/spidev.c b/drivers/spi/spidev.c
30562 +index b2775d82d2d7b..6313e7d0cdf87 100644
30563 +--- a/drivers/spi/spidev.c
30564 ++++ b/drivers/spi/spidev.c
30565 +@@ -377,12 +377,23 @@ spidev_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
30566 + switch (cmd) {
30567 + /* read requests */
30568 + case SPI_IOC_RD_MODE:
30569 +- retval = put_user(spi->mode & SPI_MODE_MASK,
30570 +- (__u8 __user *)arg);
30571 +- break;
30572 + case SPI_IOC_RD_MODE32:
30573 +- retval = put_user(spi->mode & SPI_MODE_MASK,
30574 +- (__u32 __user *)arg);
30575 ++ tmp = spi->mode;
30576 ++
30577 ++ {
30578 ++ struct spi_controller *ctlr = spi->controller;
30579 ++
30580 ++ if (ctlr->use_gpio_descriptors && ctlr->cs_gpiods &&
30581 ++ ctlr->cs_gpiods[spi->chip_select])
30582 ++ tmp &= ~SPI_CS_HIGH;
30583 ++ }
30584 ++
30585 ++ if (cmd == SPI_IOC_RD_MODE)
30586 ++ retval = put_user(tmp & SPI_MODE_MASK,
30587 ++ (__u8 __user *)arg);
30588 ++ else
30589 ++ retval = put_user(tmp & SPI_MODE_MASK,
30590 ++ (__u32 __user *)arg);
30591 + break;
30592 + case SPI_IOC_RD_LSB_FIRST:
30593 + retval = put_user((spi->mode & SPI_LSB_FIRST) ? 1 : 0,
30594 +diff --git a/drivers/staging/media/imx/imx7-media-csi.c b/drivers/staging/media/imx/imx7-media-csi.c
30595 +index a0553c24cce4b..7eee2f8dca47e 100644
30596 +--- a/drivers/staging/media/imx/imx7-media-csi.c
30597 ++++ b/drivers/staging/media/imx/imx7-media-csi.c
30598 +@@ -521,9 +521,9 @@ static void imx7_csi_configure(struct imx7_csi *csi)
30599 + cr18 = imx7_csi_reg_read(csi, CSI_CSICR18);
30600 +
30601 + cr18 &= ~(BIT_CSI_HW_ENABLE | BIT_MIPI_DATA_FORMAT_MASK |
30602 +- BIT_DATA_FROM_MIPI | BIT_BASEADDR_CHG_ERR_EN |
30603 +- BIT_BASEADDR_SWITCH_EN | BIT_BASEADDR_SWITCH_SEL |
30604 +- BIT_DEINTERLACE_EN);
30605 ++ BIT_DATA_FROM_MIPI | BIT_MIPI_DOUBLE_CMPNT |
30606 ++ BIT_BASEADDR_CHG_ERR_EN | BIT_BASEADDR_SWITCH_SEL |
30607 ++ BIT_BASEADDR_SWITCH_EN | BIT_DEINTERLACE_EN);
30608 +
30609 + if (out_pix->field == V4L2_FIELD_INTERLACED) {
30610 + cr18 |= BIT_DEINTERLACE_EN;
30611 +diff --git a/drivers/staging/media/rkvdec/rkvdec-vp9.c b/drivers/staging/media/rkvdec/rkvdec-vp9.c
30612 +index d8c1c0db15c70..cfae99b40ccb4 100644
30613 +--- a/drivers/staging/media/rkvdec/rkvdec-vp9.c
30614 ++++ b/drivers/staging/media/rkvdec/rkvdec-vp9.c
30615 +@@ -84,6 +84,8 @@ struct rkvdec_vp9_probs {
30616 + struct rkvdec_vp9_inter_frame_probs inter;
30617 + struct rkvdec_vp9_intra_only_frame_probs intra_only;
30618 + };
30619 ++ /* 128 bit alignment */
30620 ++ u8 padding1[11];
30621 + };
30622 +
30623 + /* Data structure describing auxiliary buffer format. */
30624 +@@ -1006,6 +1008,7 @@ static int rkvdec_vp9_start(struct rkvdec_ctx *ctx)
30625 +
30626 + ctx->priv = vp9_ctx;
30627 +
30628 ++ BUILD_BUG_ON(sizeof(priv_tbl->probs) % 16); /* ensure probs size is 128-bit aligned */
30629 + priv_tbl = dma_alloc_coherent(rkvdec->dev, sizeof(*priv_tbl),
30630 + &vp9_ctx->priv_tbl.dma, GFP_KERNEL);
30631 + if (!priv_tbl) {
30632 +diff --git a/drivers/staging/media/stkwebcam/Kconfig b/drivers/staging/media/stkwebcam/Kconfig
30633 +index 4450403dff41f..7234498e634ac 100644
30634 +--- a/drivers/staging/media/stkwebcam/Kconfig
30635 ++++ b/drivers/staging/media/stkwebcam/Kconfig
30636 +@@ -2,7 +2,7 @@
30637 + config VIDEO_STKWEBCAM
30638 + tristate "USB Syntek DC1125 Camera support (DEPRECATED)"
30639 + depends on VIDEO_DEV
30640 +- depends on USB
30641 ++ depends on MEDIA_USB_SUPPORT && MEDIA_CAMERA_SUPPORT
30642 + help
30643 + Say Y here if you want to use this type of camera.
30644 + Supported devices are typically found in some Asus laptops,
30645 +diff --git a/drivers/staging/media/sunxi/cedrus/cedrus_h265.c b/drivers/staging/media/sunxi/cedrus/cedrus_h265.c
30646 +index 095b8464f37a0..a07fd28e1fcfd 100644
30647 +--- a/drivers/staging/media/sunxi/cedrus/cedrus_h265.c
30648 ++++ b/drivers/staging/media/sunxi/cedrus/cedrus_h265.c
30649 +@@ -242,6 +242,18 @@ static void cedrus_h265_skip_bits(struct cedrus_dev *dev, int num)
30650 + }
30651 + }
30652 +
30653 ++static u32 cedrus_h265_show_bits(struct cedrus_dev *dev, int num)
30654 ++{
30655 ++ cedrus_write(dev, VE_DEC_H265_TRIGGER,
30656 ++ VE_DEC_H265_TRIGGER_SHOW_BITS |
30657 ++ VE_DEC_H265_TRIGGER_TYPE_N_BITS(num));
30658 ++
30659 ++ cedrus_wait_for(dev, VE_DEC_H265_STATUS,
30660 ++ VE_DEC_H265_STATUS_VLD_BUSY);
30661 ++
30662 ++ return cedrus_read(dev, VE_DEC_H265_BITS_READ);
30663 ++}
30664 ++
30665 + static void cedrus_h265_write_scaling_list(struct cedrus_ctx *ctx,
30666 + struct cedrus_run *run)
30667 + {
30668 +@@ -406,7 +418,7 @@ static int cedrus_h265_setup(struct cedrus_ctx *ctx, struct cedrus_run *run)
30669 + u32 num_entry_point_offsets;
30670 + u32 output_pic_list_index;
30671 + u32 pic_order_cnt[2];
30672 +- u8 *padding;
30673 ++ u8 padding;
30674 + int count;
30675 + u32 reg;
30676 +
30677 +@@ -520,21 +532,22 @@ static int cedrus_h265_setup(struct cedrus_ctx *ctx, struct cedrus_run *run)
30678 + if (slice_params->data_byte_offset == 0)
30679 + return -EOPNOTSUPP;
30680 +
30681 +- padding = (u8 *)vb2_plane_vaddr(&run->src->vb2_buf, 0) +
30682 +- slice_params->data_byte_offset - 1;
30683 ++ cedrus_h265_skip_bits(dev, (slice_params->data_byte_offset - 1) * 8);
30684 ++
30685 ++ padding = cedrus_h265_show_bits(dev, 8);
30686 +
30687 + /* at least one bit must be set in that byte */
30688 +- if (*padding == 0)
30689 ++ if (padding == 0)
30690 + return -EINVAL;
30691 +
30692 + for (count = 0; count < 8; count++)
30693 +- if (*padding & (1 << count))
30694 ++ if (padding & (1 << count))
30695 + break;
30696 +
30697 + /* Include the one bit. */
30698 + count++;
30699 +
30700 +- cedrus_h265_skip_bits(dev, slice_params->data_byte_offset * 8 - count);
30701 ++ cedrus_h265_skip_bits(dev, 8 - count);
30702 +
30703 + /* Bitstream parameters. */
30704 +
30705 +diff --git a/drivers/staging/media/sunxi/cedrus/cedrus_regs.h b/drivers/staging/media/sunxi/cedrus/cedrus_regs.h
30706 +index d81f7513ade0d..655c05b389cf5 100644
30707 +--- a/drivers/staging/media/sunxi/cedrus/cedrus_regs.h
30708 ++++ b/drivers/staging/media/sunxi/cedrus/cedrus_regs.h
30709 +@@ -505,6 +505,8 @@
30710 + #define VE_DEC_H265_LOW_ADDR_ENTRY_POINTS_BUF(a) \
30711 + SHIFT_AND_MASK_BITS(a, 7, 0)
30712 +
30713 ++#define VE_DEC_H265_BITS_READ (VE_ENGINE_DEC_H265 + 0xdc)
30714 ++
30715 + #define VE_DEC_H265_SRAM_OFFSET (VE_ENGINE_DEC_H265 + 0xe0)
30716 +
30717 + #define VE_DEC_H265_SRAM_OFFSET_PRED_WEIGHT_LUMA_L0 0x00
30718 +diff --git a/drivers/staging/r8188eu/core/rtw_led.c b/drivers/staging/r8188eu/core/rtw_led.c
30719 +index d5c6c5e296215..1993c3993b3d6 100644
30720 +--- a/drivers/staging/r8188eu/core/rtw_led.c
30721 ++++ b/drivers/staging/r8188eu/core/rtw_led.c
30722 +@@ -34,40 +34,19 @@ static void ResetLedStatus(struct led_priv *pLed)
30723 +
30724 + static void SwLedOn(struct adapter *padapter, struct led_priv *pLed)
30725 + {
30726 +- u8 LedCfg;
30727 +- int res;
30728 +-
30729 +- if (padapter->bSurpriseRemoved || padapter->bDriverStopped)
30730 +- return;
30731 +-
30732 +- res = rtw_read8(padapter, REG_LEDCFG2, &LedCfg);
30733 +- if (res)
30734 ++ if (padapter->bDriverStopped)
30735 + return;
30736 +
30737 +- rtw_write8(padapter, REG_LEDCFG2, (LedCfg & 0xf0) | BIT(5) | BIT(6)); /* SW control led0 on. */
30738 ++ rtw_write8(padapter, REG_LEDCFG2, BIT(5)); /* SW control led0 on. */
30739 + pLed->bLedOn = true;
30740 + }
30741 +
30742 + static void SwLedOff(struct adapter *padapter, struct led_priv *pLed)
30743 + {
30744 +- u8 LedCfg;
30745 +- int res;
30746 +-
30747 +- if (padapter->bSurpriseRemoved || padapter->bDriverStopped)
30748 +- goto exit;
30749 +-
30750 +- res = rtw_read8(padapter, REG_LEDCFG2, &LedCfg);/* 0x4E */
30751 +- if (res)
30752 +- goto exit;
30753 +-
30754 +- LedCfg &= 0x90; /* Set to software control. */
30755 +- rtw_write8(padapter, REG_LEDCFG2, (LedCfg | BIT(3)));
30756 +- res = rtw_read8(padapter, REG_MAC_PINMUX_CFG, &LedCfg);
30757 +- if (res)
30758 ++ if (padapter->bDriverStopped)
30759 + goto exit;
30760 +
30761 +- LedCfg &= 0xFE;
30762 +- rtw_write8(padapter, REG_MAC_PINMUX_CFG, LedCfg);
30763 ++ rtw_write8(padapter, REG_LEDCFG2, BIT(5) | BIT(3));
30764 + exit:
30765 + pLed->bLedOn = false;
30766 + }
30767 +diff --git a/drivers/staging/r8188eu/core/rtw_pwrctrl.c b/drivers/staging/r8188eu/core/rtw_pwrctrl.c
30768 +index 10550bd2c16db..abfd14bfd5fb8 100644
30769 +--- a/drivers/staging/r8188eu/core/rtw_pwrctrl.c
30770 ++++ b/drivers/staging/r8188eu/core/rtw_pwrctrl.c
30771 +@@ -273,7 +273,7 @@ static s32 LPS_RF_ON_check(struct adapter *padapter, u32 delay_ms)
30772 + err = -1;
30773 + break;
30774 + }
30775 +- msleep(1);
30776 ++ mdelay(1);
30777 + }
30778 +
30779 + return err;
30780 +diff --git a/drivers/staging/rtl8192e/rtllib_rx.c b/drivers/staging/rtl8192e/rtllib_rx.c
30781 +index abe5c153f74e8..b0ef9da43bc4e 100644
30782 +--- a/drivers/staging/rtl8192e/rtllib_rx.c
30783 ++++ b/drivers/staging/rtl8192e/rtllib_rx.c
30784 +@@ -1489,9 +1489,9 @@ static int rtllib_rx_Monitor(struct rtllib_device *ieee, struct sk_buff *skb,
30785 + hdrlen += 4;
30786 + }
30787 +
30788 +- rtllib_monitor_rx(ieee, skb, rx_stats, hdrlen);
30789 + ieee->stats.rx_packets++;
30790 + ieee->stats.rx_bytes += skb->len;
30791 ++ rtllib_monitor_rx(ieee, skb, rx_stats, hdrlen);
30792 +
30793 + return 1;
30794 + }
30795 +diff --git a/drivers/staging/rtl8192u/ieee80211/ieee80211_rx.c b/drivers/staging/rtl8192u/ieee80211/ieee80211_rx.c
30796 +index b58e75932ecd5..3686b3c599ce7 100644
30797 +--- a/drivers/staging/rtl8192u/ieee80211/ieee80211_rx.c
30798 ++++ b/drivers/staging/rtl8192u/ieee80211/ieee80211_rx.c
30799 +@@ -951,9 +951,11 @@ int ieee80211_rx(struct ieee80211_device *ieee, struct sk_buff *skb,
30800 + #endif
30801 +
30802 + if (ieee->iw_mode == IW_MODE_MONITOR) {
30803 ++ unsigned int len = skb->len;
30804 ++
30805 + ieee80211_monitor_rx(ieee, skb, rx_stats);
30806 + stats->rx_packets++;
30807 +- stats->rx_bytes += skb->len;
30808 ++ stats->rx_bytes += len;
30809 + return 1;
30810 + }
30811 +
30812 +diff --git a/drivers/staging/vme_user/vme_fake.c b/drivers/staging/vme_user/vme_fake.c
30813 +index dd646b0c531d4..1ee432c223e2b 100644
30814 +--- a/drivers/staging/vme_user/vme_fake.c
30815 ++++ b/drivers/staging/vme_user/vme_fake.c
30816 +@@ -1073,6 +1073,8 @@ static int __init fake_init(void)
30817 +
30818 + /* We need a fake parent device */
30819 + vme_root = __root_device_register("vme", THIS_MODULE);
30820 ++ if (IS_ERR(vme_root))
30821 ++ return PTR_ERR(vme_root);
30822 +
30823 + /* If we want to support more than one bridge at some point, we need to
30824 + * dynamically allocate this so we get one per device.
30825 +diff --git a/drivers/staging/vme_user/vme_tsi148.c b/drivers/staging/vme_user/vme_tsi148.c
30826 +index 9564762132415..b741514e938bd 100644
30827 +--- a/drivers/staging/vme_user/vme_tsi148.c
30828 ++++ b/drivers/staging/vme_user/vme_tsi148.c
30829 +@@ -1765,6 +1765,7 @@ static int tsi148_dma_list_add(struct vme_dma_list *list,
30830 + return 0;
30831 +
30832 + err_dma:
30833 ++ list_del(&entry->list);
30834 + err_dest:
30835 + err_source:
30836 + err_align:
30837 +diff --git a/drivers/target/iscsi/iscsi_target_nego.c b/drivers/target/iscsi/iscsi_target_nego.c
30838 +index f2919319ad383..ff49c8f3fe241 100644
30839 +--- a/drivers/target/iscsi/iscsi_target_nego.c
30840 ++++ b/drivers/target/iscsi/iscsi_target_nego.c
30841 +@@ -1018,6 +1018,13 @@ static int iscsi_target_handle_csg_one(struct iscsit_conn *conn, struct iscsi_lo
30842 + return 0;
30843 + }
30844 +
30845 ++/*
30846 ++ * RETURN VALUE:
30847 ++ *
30848 ++ * 1 = Login successful
30849 ++ * -1 = Login failed
30850 ++ * 0 = More PDU exchanges required
30851 ++ */
30852 + static int iscsi_target_do_login(struct iscsit_conn *conn, struct iscsi_login *login)
30853 + {
30854 + int pdu_count = 0;
30855 +@@ -1363,12 +1370,13 @@ int iscsi_target_start_negotiation(
30856 + ret = -1;
30857 +
30858 + if (ret < 0) {
30859 +- cancel_delayed_work_sync(&conn->login_work);
30860 + iscsi_target_restore_sock_callbacks(conn);
30861 + iscsi_remove_failed_auth_entry(conn);
30862 + }
30863 +- if (ret != 0)
30864 ++ if (ret != 0) {
30865 ++ cancel_delayed_work_sync(&conn->login_work);
30866 + iscsi_target_nego_release(conn);
30867 ++ }
30868 +
30869 + return ret;
30870 + }
30871 +diff --git a/drivers/thermal/imx8mm_thermal.c b/drivers/thermal/imx8mm_thermal.c
30872 +index af666bd9e8d4d..c5cd873c6e016 100644
30873 +--- a/drivers/thermal/imx8mm_thermal.c
30874 ++++ b/drivers/thermal/imx8mm_thermal.c
30875 +@@ -65,8 +65,14 @@ static int imx8mm_tmu_get_temp(void *data, int *temp)
30876 + u32 val;
30877 +
30878 + val = readl_relaxed(tmu->base + TRITSR) & TRITSR_TEMP0_VAL_MASK;
30879 ++
30880 ++ /*
30881 ++ * Do not validate against the V bit (bit 31) due to errata
30882 ++ * ERR051272: TMU: Bit 31 of registers TMU_TSCR/TMU_TRITSR/TMU_TRATSR invalid
30883 ++ */
30884 ++
30885 + *temp = val * 1000;
30886 +- if (*temp < VER1_TEMP_LOW_LIMIT)
30887 ++ if (*temp < VER1_TEMP_LOW_LIMIT || *temp > VER2_TEMP_HIGH_LIMIT)
30888 + return -EAGAIN;
30889 +
30890 + return 0;
30891 +diff --git a/drivers/thermal/k3_j72xx_bandgap.c b/drivers/thermal/k3_j72xx_bandgap.c
30892 +index 115a44eb4fbfb..4eb4926bbdc78 100644
30893 +--- a/drivers/thermal/k3_j72xx_bandgap.c
30894 ++++ b/drivers/thermal/k3_j72xx_bandgap.c
30895 +@@ -439,7 +439,7 @@ static int k3_j72xx_bandgap_probe(struct platform_device *pdev)
30896 + workaround_needed = false;
30897 +
30898 + dev_dbg(bgp->dev, "Work around %sneeded\n",
30899 +- workaround_needed ? "not " : "");
30900 ++ workaround_needed ? "" : "not ");
30901 +
30902 + if (!workaround_needed)
30903 + init_table(5, ref_table, golden_factors);
30904 +diff --git a/drivers/thermal/qcom/lmh.c b/drivers/thermal/qcom/lmh.c
30905 +index d3d9b9fa49e81..4122a51e98741 100644
30906 +--- a/drivers/thermal/qcom/lmh.c
30907 ++++ b/drivers/thermal/qcom/lmh.c
30908 +@@ -45,7 +45,7 @@ static irqreturn_t lmh_handle_irq(int hw_irq, void *data)
30909 + if (irq)
30910 + generic_handle_irq(irq);
30911 +
30912 +- return 0;
30913 ++ return IRQ_HANDLED;
30914 + }
30915 +
30916 + static void lmh_enable_interrupt(struct irq_data *d)
30917 +diff --git a/drivers/thermal/qcom/qcom-spmi-temp-alarm.c b/drivers/thermal/qcom/qcom-spmi-temp-alarm.c
30918 +index 770f82cc9bca8..247b39d57fa7c 100644
30919 +--- a/drivers/thermal/qcom/qcom-spmi-temp-alarm.c
30920 ++++ b/drivers/thermal/qcom/qcom-spmi-temp-alarm.c
30921 +@@ -252,7 +252,8 @@ static int qpnp_tm_update_critical_trip_temp(struct qpnp_tm_chip *chip,
30922 + disable_s2_shutdown = true;
30923 + else
30924 + dev_warn(chip->dev,
30925 +- "No ADC is configured and critical temperature is above the maximum stage 2 threshold of 140 C! Configuring stage 2 shutdown at 140 C.\n");
30926 ++ "No ADC is configured and critical temperature %d mC is above the maximum stage 2 threshold of %ld mC! Configuring stage 2 shutdown at %ld mC.\n",
30927 ++ temp, stage2_threshold_max, stage2_threshold_max);
30928 + }
30929 +
30930 + skip:
30931 +diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c
30932 +index 50d50cec77740..15fb5fa1b0f2c 100644
30933 +--- a/drivers/thermal/thermal_core.c
30934 ++++ b/drivers/thermal/thermal_core.c
30935 +@@ -903,10 +903,6 @@ __thermal_cooling_device_register(struct device_node *np,
30936 + cdev->id = ret;
30937 + id = ret;
30938 +
30939 +- ret = dev_set_name(&cdev->device, "cooling_device%d", cdev->id);
30940 +- if (ret)
30941 +- goto out_ida_remove;
30942 +-
30943 + cdev->type = kstrdup(type ? type : "", GFP_KERNEL);
30944 + if (!cdev->type) {
30945 + ret = -ENOMEM;
30946 +@@ -921,6 +917,11 @@ __thermal_cooling_device_register(struct device_node *np,
30947 + cdev->device.class = &thermal_class;
30948 + cdev->devdata = devdata;
30949 + thermal_cooling_device_setup_sysfs(cdev);
30950 ++ ret = dev_set_name(&cdev->device, "cooling_device%d", cdev->id);
30951 ++ if (ret) {
30952 ++ thermal_cooling_device_destroy_sysfs(cdev);
30953 ++ goto out_kfree_type;
30954 ++ }
30955 + ret = device_register(&cdev->device);
30956 + if (ret)
30957 + goto out_kfree_type;
30958 +@@ -1241,10 +1242,6 @@ thermal_zone_device_register_with_trips(const char *type, struct thermal_trip *t
30959 + tz->id = id;
30960 + strlcpy(tz->type, type, sizeof(tz->type));
30961 +
30962 +- result = dev_set_name(&tz->device, "thermal_zone%d", tz->id);
30963 +- if (result)
30964 +- goto remove_id;
30965 +-
30966 + if (!ops->critical)
30967 + ops->critical = thermal_zone_device_critical;
30968 +
30969 +@@ -1267,6 +1264,11 @@ thermal_zone_device_register_with_trips(const char *type, struct thermal_trip *t
30970 + /* A new thermal zone needs to be updated anyway. */
30971 + atomic_set(&tz->need_update, 1);
30972 +
30973 ++ result = dev_set_name(&tz->device, "thermal_zone%d", tz->id);
30974 ++ if (result) {
30975 ++ thermal_zone_destroy_device_groups(tz);
30976 ++ goto remove_id;
30977 ++ }
30978 + result = device_register(&tz->device);
30979 + if (result)
30980 + goto release_device;
30981 +diff --git a/drivers/tty/serial/8250/8250_bcm7271.c b/drivers/tty/serial/8250/8250_bcm7271.c
30982 +index 8efdc271eb75f..5e0ffd6c47892 100644
30983 +--- a/drivers/tty/serial/8250/8250_bcm7271.c
30984 ++++ b/drivers/tty/serial/8250/8250_bcm7271.c
30985 +@@ -1212,9 +1212,17 @@ static struct platform_driver brcmuart_platform_driver = {
30986 +
30987 + static int __init brcmuart_init(void)
30988 + {
30989 ++ int ret;
30990 ++
30991 + brcmuart_debugfs_root = debugfs_create_dir(
30992 + brcmuart_platform_driver.driver.name, NULL);
30993 +- return platform_driver_register(&brcmuart_platform_driver);
30994 ++ ret = platform_driver_register(&brcmuart_platform_driver);
30995 ++ if (ret) {
30996 ++ debugfs_remove_recursive(brcmuart_debugfs_root);
30997 ++ return ret;
30998 ++ }
30999 ++
31000 ++ return 0;
31001 + }
31002 + module_init(brcmuart_init);
31003 +
31004 +diff --git a/drivers/tty/serial/altera_uart.c b/drivers/tty/serial/altera_uart.c
31005 +index 8b749ed557c67..191d737ea5632 100644
31006 +--- a/drivers/tty/serial/altera_uart.c
31007 ++++ b/drivers/tty/serial/altera_uart.c
31008 +@@ -199,9 +199,8 @@ static void altera_uart_set_termios(struct uart_port *port,
31009 + */
31010 + }
31011 +
31012 +-static void altera_uart_rx_chars(struct altera_uart *pp)
31013 ++static void altera_uart_rx_chars(struct uart_port *port)
31014 + {
31015 +- struct uart_port *port = &pp->port;
31016 + unsigned char ch, flag;
31017 + unsigned short status;
31018 +
31019 +@@ -246,9 +245,8 @@ static void altera_uart_rx_chars(struct altera_uart *pp)
31020 + tty_flip_buffer_push(&port->state->port);
31021 + }
31022 +
31023 +-static void altera_uart_tx_chars(struct altera_uart *pp)
31024 ++static void altera_uart_tx_chars(struct uart_port *port)
31025 + {
31026 +- struct uart_port *port = &pp->port;
31027 + struct circ_buf *xmit = &port->state->xmit;
31028 +
31029 + if (port->x_char) {
31030 +@@ -272,26 +270,25 @@ static void altera_uart_tx_chars(struct altera_uart *pp)
31031 + if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
31032 + uart_write_wakeup(port);
31033 +
31034 +- if (xmit->head == xmit->tail) {
31035 +- pp->imr &= ~ALTERA_UART_CONTROL_TRDY_MSK;
31036 +- altera_uart_update_ctrl_reg(pp);
31037 +- }
31038 ++ if (uart_circ_empty(xmit))
31039 ++ altera_uart_stop_tx(port);
31040 + }
31041 +
31042 + static irqreturn_t altera_uart_interrupt(int irq, void *data)
31043 + {
31044 + struct uart_port *port = data;
31045 + struct altera_uart *pp = container_of(port, struct altera_uart, port);
31046 ++ unsigned long flags;
31047 + unsigned int isr;
31048 +
31049 + isr = altera_uart_readl(port, ALTERA_UART_STATUS_REG) & pp->imr;
31050 +
31051 +- spin_lock(&port->lock);
31052 ++ spin_lock_irqsave(&port->lock, flags);
31053 + if (isr & ALTERA_UART_STATUS_RRDY_MSK)
31054 +- altera_uart_rx_chars(pp);
31055 ++ altera_uart_rx_chars(port);
31056 + if (isr & ALTERA_UART_STATUS_TRDY_MSK)
31057 +- altera_uart_tx_chars(pp);
31058 +- spin_unlock(&port->lock);
31059 ++ altera_uart_tx_chars(port);
31060 ++ spin_unlock_irqrestore(&port->lock, flags);
31061 +
31062 + return IRQ_RETVAL(isr);
31063 + }
31064 +diff --git a/drivers/tty/serial/amba-pl011.c b/drivers/tty/serial/amba-pl011.c
31065 +index 15f0e4d88c5a0..c211a1e92db7f 100644
31066 +--- a/drivers/tty/serial/amba-pl011.c
31067 ++++ b/drivers/tty/serial/amba-pl011.c
31068 +@@ -1045,6 +1045,9 @@ static void pl011_dma_rx_callback(void *data)
31069 + */
31070 + static inline void pl011_dma_rx_stop(struct uart_amba_port *uap)
31071 + {
31072 ++ if (!uap->using_rx_dma)
31073 ++ return;
31074 ++
31075 + /* FIXME. Just disable the DMA enable */
31076 + uap->dmacr &= ~UART011_RXDMAE;
31077 + pl011_write(uap->dmacr, uap, REG_DMACR);
31078 +@@ -1828,8 +1831,17 @@ static void pl011_enable_interrupts(struct uart_amba_port *uap)
31079 + static void pl011_unthrottle_rx(struct uart_port *port)
31080 + {
31081 + struct uart_amba_port *uap = container_of(port, struct uart_amba_port, port);
31082 ++ unsigned long flags;
31083 +
31084 +- pl011_enable_interrupts(uap);
31085 ++ spin_lock_irqsave(&uap->port.lock, flags);
31086 ++
31087 ++ uap->im = UART011_RTIM;
31088 ++ if (!pl011_dma_rx_running(uap))
31089 ++ uap->im |= UART011_RXIM;
31090 ++
31091 ++ pl011_write(uap->im, uap, REG_IMSC);
31092 ++
31093 ++ spin_unlock_irqrestore(&uap->port.lock, flags);
31094 + }
31095 +
31096 + static int pl011_startup(struct uart_port *port)
31097 +diff --git a/drivers/tty/serial/pch_uart.c b/drivers/tty/serial/pch_uart.c
31098 +index 8a9065e4a903b..ec501c3ce033b 100644
31099 +--- a/drivers/tty/serial/pch_uart.c
31100 ++++ b/drivers/tty/serial/pch_uart.c
31101 +@@ -694,6 +694,7 @@ static void pch_request_dma(struct uart_port *port)
31102 + if (!chan) {
31103 + dev_err(priv->port.dev, "%s:dma_request_channel FAILS(Tx)\n",
31104 + __func__);
31105 ++ pci_dev_put(dma_dev);
31106 + return;
31107 + }
31108 + priv->chan_tx = chan;
31109 +@@ -710,6 +711,7 @@ static void pch_request_dma(struct uart_port *port)
31110 + __func__);
31111 + dma_release_channel(priv->chan_tx);
31112 + priv->chan_tx = NULL;
31113 ++ pci_dev_put(dma_dev);
31114 + return;
31115 + }
31116 +
31117 +@@ -717,6 +719,8 @@ static void pch_request_dma(struct uart_port *port)
31118 + priv->rx_buf_virt = dma_alloc_coherent(port->dev, port->fifosize,
31119 + &priv->rx_buf_dma, GFP_KERNEL);
31120 + priv->chan_rx = chan;
31121 ++
31122 ++ pci_dev_put(dma_dev);
31123 + }
31124 +
31125 + static void pch_dma_rx_complete(void *arg)
31126 +diff --git a/drivers/tty/serial/serial-tegra.c b/drivers/tty/serial/serial-tegra.c
31127 +index a5748e41483ba..ab549b79fde90 100644
31128 +--- a/drivers/tty/serial/serial-tegra.c
31129 ++++ b/drivers/tty/serial/serial-tegra.c
31130 +@@ -619,8 +619,9 @@ static void tegra_uart_stop_tx(struct uart_port *u)
31131 + if (tup->tx_in_progress != TEGRA_UART_TX_DMA)
31132 + return;
31133 +
31134 +- dmaengine_terminate_all(tup->tx_dma_chan);
31135 ++ dmaengine_pause(tup->tx_dma_chan);
31136 + dmaengine_tx_status(tup->tx_dma_chan, tup->tx_cookie, &state);
31137 ++ dmaengine_terminate_all(tup->tx_dma_chan);
31138 + count = tup->tx_bytes_requested - state.residue;
31139 + async_tx_ack(tup->tx_dma_desc);
31140 + uart_xmit_advance(&tup->uport, count);
31141 +@@ -763,8 +764,9 @@ static void tegra_uart_terminate_rx_dma(struct tegra_uart_port *tup)
31142 + return;
31143 + }
31144 +
31145 +- dmaengine_terminate_all(tup->rx_dma_chan);
31146 ++ dmaengine_pause(tup->rx_dma_chan);
31147 + dmaengine_tx_status(tup->rx_dma_chan, tup->rx_cookie, &state);
31148 ++ dmaengine_terminate_all(tup->rx_dma_chan);
31149 +
31150 + tegra_uart_rx_buffer_push(tup, state.residue);
31151 + tup->rx_dma_active = false;
31152 +diff --git a/drivers/tty/serial/stm32-usart.c b/drivers/tty/serial/stm32-usart.c
31153 +index 9a875558f5ef6..1f8aad186908f 100644
31154 +--- a/drivers/tty/serial/stm32-usart.c
31155 ++++ b/drivers/tty/serial/stm32-usart.c
31156 +@@ -1681,22 +1681,10 @@ static int stm32_usart_serial_probe(struct platform_device *pdev)
31157 + if (!stm32port->info)
31158 + return -EINVAL;
31159 +
31160 +- ret = stm32_usart_init_port(stm32port, pdev);
31161 +- if (ret)
31162 +- return ret;
31163 +-
31164 +- if (stm32port->wakeup_src) {
31165 +- device_set_wakeup_capable(&pdev->dev, true);
31166 +- ret = dev_pm_set_wake_irq(&pdev->dev, stm32port->port.irq);
31167 +- if (ret)
31168 +- goto err_deinit_port;
31169 +- }
31170 +-
31171 + stm32port->rx_ch = dma_request_chan(&pdev->dev, "rx");
31172 +- if (PTR_ERR(stm32port->rx_ch) == -EPROBE_DEFER) {
31173 +- ret = -EPROBE_DEFER;
31174 +- goto err_wakeirq;
31175 +- }
31176 ++ if (PTR_ERR(stm32port->rx_ch) == -EPROBE_DEFER)
31177 ++ return -EPROBE_DEFER;
31178 ++
31179 + /* Fall back in interrupt mode for any non-deferral error */
31180 + if (IS_ERR(stm32port->rx_ch))
31181 + stm32port->rx_ch = NULL;
31182 +@@ -1710,6 +1698,17 @@ static int stm32_usart_serial_probe(struct platform_device *pdev)
31183 + if (IS_ERR(stm32port->tx_ch))
31184 + stm32port->tx_ch = NULL;
31185 +
31186 ++ ret = stm32_usart_init_port(stm32port, pdev);
31187 ++ if (ret)
31188 ++ goto err_dma_tx;
31189 ++
31190 ++ if (stm32port->wakeup_src) {
31191 ++ device_set_wakeup_capable(&pdev->dev, true);
31192 ++ ret = dev_pm_set_wake_irq(&pdev->dev, stm32port->port.irq);
31193 ++ if (ret)
31194 ++ goto err_deinit_port;
31195 ++ }
31196 ++
31197 + if (stm32port->rx_ch && stm32_usart_of_dma_rx_probe(stm32port, pdev)) {
31198 + /* Fall back in interrupt mode */
31199 + dma_release_channel(stm32port->rx_ch);
31200 +@@ -1746,19 +1745,11 @@ err_port:
31201 + pm_runtime_set_suspended(&pdev->dev);
31202 + pm_runtime_put_noidle(&pdev->dev);
31203 +
31204 +- if (stm32port->tx_ch) {
31205 ++ if (stm32port->tx_ch)
31206 + stm32_usart_of_dma_tx_remove(stm32port, pdev);
31207 +- dma_release_channel(stm32port->tx_ch);
31208 +- }
31209 +-
31210 + if (stm32port->rx_ch)
31211 + stm32_usart_of_dma_rx_remove(stm32port, pdev);
31212 +
31213 +-err_dma_rx:
31214 +- if (stm32port->rx_ch)
31215 +- dma_release_channel(stm32port->rx_ch);
31216 +-
31217 +-err_wakeirq:
31218 + if (stm32port->wakeup_src)
31219 + dev_pm_clear_wake_irq(&pdev->dev);
31220 +
31221 +@@ -1768,6 +1759,14 @@ err_deinit_port:
31222 +
31223 + stm32_usart_deinit_port(stm32port);
31224 +
31225 ++err_dma_tx:
31226 ++ if (stm32port->tx_ch)
31227 ++ dma_release_channel(stm32port->tx_ch);
31228 ++
31229 ++err_dma_rx:
31230 ++ if (stm32port->rx_ch)
31231 ++ dma_release_channel(stm32port->rx_ch);
31232 ++
31233 + return ret;
31234 + }
31235 +
31236 +diff --git a/drivers/tty/serial/sunsab.c b/drivers/tty/serial/sunsab.c
31237 +index 6ea52293d9f35..7c10715dace88 100644
31238 +--- a/drivers/tty/serial/sunsab.c
31239 ++++ b/drivers/tty/serial/sunsab.c
31240 +@@ -1137,7 +1137,13 @@ static int __init sunsab_init(void)
31241 + }
31242 + }
31243 +
31244 +- return platform_driver_register(&sab_driver);
31245 ++ err = platform_driver_register(&sab_driver);
31246 ++ if (err) {
31247 ++ kfree(sunsab_ports);
31248 ++ sunsab_ports = NULL;
31249 ++ }
31250 ++
31251 ++ return err;
31252 + }
31253 +
31254 + static void __exit sunsab_exit(void)
31255 +diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c
31256 +index a202d7d5240d8..bda89f988859e 100644
31257 +--- a/drivers/ufs/core/ufshcd.c
31258 ++++ b/drivers/ufs/core/ufshcd.c
31259 +@@ -5378,6 +5378,26 @@ static void __ufshcd_transfer_req_compl(struct ufs_hba *hba,
31260 + }
31261 + }
31262 +
31263 ++/* Any value that is not an existing queue number is fine for this constant. */
31264 ++enum {
31265 ++ UFSHCD_POLL_FROM_INTERRUPT_CONTEXT = -1
31266 ++};
31267 ++
31268 ++static void ufshcd_clear_polled(struct ufs_hba *hba,
31269 ++ unsigned long *completed_reqs)
31270 ++{
31271 ++ int tag;
31272 ++
31273 ++ for_each_set_bit(tag, completed_reqs, hba->nutrs) {
31274 ++ struct scsi_cmnd *cmd = hba->lrb[tag].cmd;
31275 ++
31276 ++ if (!cmd)
31277 ++ continue;
31278 ++ if (scsi_cmd_to_rq(cmd)->cmd_flags & REQ_POLLED)
31279 ++ __clear_bit(tag, completed_reqs);
31280 ++ }
31281 ++}
31282 ++
31283 + /*
31284 + * Returns > 0 if one or more commands have been completed or 0 if no
31285 + * requests have been completed.
31286 +@@ -5394,13 +5414,17 @@ static int ufshcd_poll(struct Scsi_Host *shost, unsigned int queue_num)
31287 + WARN_ONCE(completed_reqs & ~hba->outstanding_reqs,
31288 + "completed: %#lx; outstanding: %#lx\n", completed_reqs,
31289 + hba->outstanding_reqs);
31290 ++ if (queue_num == UFSHCD_POLL_FROM_INTERRUPT_CONTEXT) {
31291 ++ /* Do not complete polled requests from interrupt context. */
31292 ++ ufshcd_clear_polled(hba, &completed_reqs);
31293 ++ }
31294 + hba->outstanding_reqs &= ~completed_reqs;
31295 + spin_unlock_irqrestore(&hba->outstanding_lock, flags);
31296 +
31297 + if (completed_reqs)
31298 + __ufshcd_transfer_req_compl(hba, completed_reqs);
31299 +
31300 +- return completed_reqs;
31301 ++ return completed_reqs != 0;
31302 + }
31303 +
31304 + /**
31305 +@@ -5431,7 +5455,7 @@ static irqreturn_t ufshcd_transfer_req_compl(struct ufs_hba *hba)
31306 + * Ignore the ufshcd_poll() return value and return IRQ_HANDLED since we
31307 + * do not want polling to trigger spurious interrupt complaints.
31308 + */
31309 +- ufshcd_poll(hba->host, 0);
31310 ++ ufshcd_poll(hba->host, UFSHCD_POLL_FROM_INTERRUPT_CONTEXT);
31311 +
31312 + return IRQ_HANDLED;
31313 + }
31314 +@@ -8741,8 +8765,6 @@ static int ufshcd_set_dev_pwr_mode(struct ufs_hba *hba,
31315 + struct scsi_device *sdp;
31316 + unsigned long flags;
31317 + int ret, retries;
31318 +- unsigned long deadline;
31319 +- int32_t remaining;
31320 +
31321 + spin_lock_irqsave(hba->host->host_lock, flags);
31322 + sdp = hba->ufs_device_wlun;
31323 +@@ -8775,14 +8797,9 @@ static int ufshcd_set_dev_pwr_mode(struct ufs_hba *hba,
31324 + * callbacks hence set the RQF_PM flag so that it doesn't resume the
31325 + * already suspended childs.
31326 + */
31327 +- deadline = jiffies + 10 * HZ;
31328 + for (retries = 3; retries > 0; --retries) {
31329 +- ret = -ETIMEDOUT;
31330 +- remaining = deadline - jiffies;
31331 +- if (remaining <= 0)
31332 +- break;
31333 + ret = scsi_execute(sdp, cmd, DMA_NONE, NULL, 0, NULL, &sshdr,
31334 +- remaining / HZ, 0, 0, RQF_PM, NULL);
31335 ++ HZ, 0, 0, RQF_PM, NULL);
31336 + if (!scsi_status_is_check_condition(ret) ||
31337 + !scsi_sense_valid(&sshdr) ||
31338 + sshdr.sense_key != UNIT_ATTENTION)
31339 +diff --git a/drivers/uio/uio_dmem_genirq.c b/drivers/uio/uio_dmem_genirq.c
31340 +index 1106f33764047..792c3e9c9ce53 100644
31341 +--- a/drivers/uio/uio_dmem_genirq.c
31342 ++++ b/drivers/uio/uio_dmem_genirq.c
31343 +@@ -110,8 +110,10 @@ static irqreturn_t uio_dmem_genirq_handler(int irq, struct uio_info *dev_info)
31344 + * remember the state so we can allow user space to enable it later.
31345 + */
31346 +
31347 ++ spin_lock(&priv->lock);
31348 + if (!test_and_set_bit(0, &priv->flags))
31349 + disable_irq_nosync(irq);
31350 ++ spin_unlock(&priv->lock);
31351 +
31352 + return IRQ_HANDLED;
31353 + }
31354 +@@ -125,20 +127,19 @@ static int uio_dmem_genirq_irqcontrol(struct uio_info *dev_info, s32 irq_on)
31355 + * in the interrupt controller, but keep track of the
31356 + * state to prevent per-irq depth damage.
31357 + *
31358 +- * Serialize this operation to support multiple tasks.
31359 ++ * Serialize this operation to support multiple tasks and concurrency
31360 ++ * with irq handler on SMP systems.
31361 + */
31362 +
31363 + spin_lock_irqsave(&priv->lock, flags);
31364 + if (irq_on) {
31365 + if (test_and_clear_bit(0, &priv->flags))
31366 + enable_irq(dev_info->irq);
31367 +- spin_unlock_irqrestore(&priv->lock, flags);
31368 + } else {
31369 +- if (!test_and_set_bit(0, &priv->flags)) {
31370 +- spin_unlock_irqrestore(&priv->lock, flags);
31371 +- disable_irq(dev_info->irq);
31372 +- }
31373 ++ if (!test_and_set_bit(0, &priv->flags))
31374 ++ disable_irq_nosync(dev_info->irq);
31375 + }
31376 ++ spin_unlock_irqrestore(&priv->lock, flags);
31377 +
31378 + return 0;
31379 + }
31380 +diff --git a/drivers/usb/cdns3/cdnsp-ring.c b/drivers/usb/cdns3/cdnsp-ring.c
31381 +index 2f29431f612e0..b23e543b3a3d5 100644
31382 +--- a/drivers/usb/cdns3/cdnsp-ring.c
31383 ++++ b/drivers/usb/cdns3/cdnsp-ring.c
31384 +@@ -2006,10 +2006,11 @@ int cdnsp_queue_bulk_tx(struct cdnsp_device *pdev, struct cdnsp_request *preq)
31385 +
31386 + int cdnsp_queue_ctrl_tx(struct cdnsp_device *pdev, struct cdnsp_request *preq)
31387 + {
31388 +- u32 field, length_field, remainder;
31389 ++ u32 field, length_field, zlp = 0;
31390 + struct cdnsp_ep *pep = preq->pep;
31391 + struct cdnsp_ring *ep_ring;
31392 + int num_trbs;
31393 ++ u32 maxp;
31394 + int ret;
31395 +
31396 + ep_ring = cdnsp_request_to_transfer_ring(pdev, preq);
31397 +@@ -2019,26 +2020,33 @@ int cdnsp_queue_ctrl_tx(struct cdnsp_device *pdev, struct cdnsp_request *preq)
31398 + /* 1 TRB for data, 1 for status */
31399 + num_trbs = (pdev->three_stage_setup) ? 2 : 1;
31400 +
31401 ++ maxp = usb_endpoint_maxp(pep->endpoint.desc);
31402 ++
31403 ++ if (preq->request.zero && preq->request.length &&
31404 ++ (preq->request.length % maxp == 0)) {
31405 ++ num_trbs++;
31406 ++ zlp = 1;
31407 ++ }
31408 ++
31409 + ret = cdnsp_prepare_transfer(pdev, preq, num_trbs);
31410 + if (ret)
31411 + return ret;
31412 +
31413 + /* If there's data, queue data TRBs */
31414 +- if (pdev->ep0_expect_in)
31415 +- field = TRB_TYPE(TRB_DATA) | TRB_IOC;
31416 +- else
31417 +- field = TRB_ISP | TRB_TYPE(TRB_DATA) | TRB_IOC;
31418 +-
31419 + if (preq->request.length > 0) {
31420 +- remainder = cdnsp_td_remainder(pdev, 0, preq->request.length,
31421 +- preq->request.length, preq, 1, 0);
31422 ++ field = TRB_TYPE(TRB_DATA);
31423 +
31424 +- length_field = TRB_LEN(preq->request.length) |
31425 +- TRB_TD_SIZE(remainder) | TRB_INTR_TARGET(0);
31426 ++ if (zlp)
31427 ++ field |= TRB_CHAIN;
31428 ++ else
31429 ++ field |= TRB_IOC | (pdev->ep0_expect_in ? 0 : TRB_ISP);
31430 +
31431 + if (pdev->ep0_expect_in)
31432 + field |= TRB_DIR_IN;
31433 +
31434 ++ length_field = TRB_LEN(preq->request.length) |
31435 ++ TRB_TD_SIZE(zlp) | TRB_INTR_TARGET(0);
31436 ++
31437 + cdnsp_queue_trb(pdev, ep_ring, true,
31438 + lower_32_bits(preq->request.dma),
31439 + upper_32_bits(preq->request.dma), length_field,
31440 +@@ -2046,6 +2054,20 @@ int cdnsp_queue_ctrl_tx(struct cdnsp_device *pdev, struct cdnsp_request *preq)
31441 + TRB_SETUPID(pdev->setup_id) |
31442 + pdev->setup_speed);
31443 +
31444 ++ if (zlp) {
31445 ++ field = TRB_TYPE(TRB_NORMAL) | TRB_IOC;
31446 ++
31447 ++ if (!pdev->ep0_expect_in)
31448 ++ field = TRB_ISP;
31449 ++
31450 ++ cdnsp_queue_trb(pdev, ep_ring, true,
31451 ++ lower_32_bits(preq->request.dma),
31452 ++ upper_32_bits(preq->request.dma), 0,
31453 ++ field | ep_ring->cycle_state |
31454 ++ TRB_SETUPID(pdev->setup_id) |
31455 ++ pdev->setup_speed);
31456 ++ }
31457 ++
31458 + pdev->ep0_stage = CDNSP_DATA_STAGE;
31459 + }
31460 +
31461 +diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
31462 +index 94b305bbd621b..4bd9d799f1b97 100644
31463 +--- a/drivers/usb/core/hcd.c
31464 ++++ b/drivers/usb/core/hcd.c
31465 +@@ -3140,8 +3140,12 @@ int usb_hcd_setup_local_mem(struct usb_hcd *hcd, phys_addr_t phys_addr,
31466 + GFP_KERNEL,
31467 + DMA_ATTR_WRITE_COMBINE);
31468 +
31469 +- if (IS_ERR(local_mem))
31470 ++ if (IS_ERR_OR_NULL(local_mem)) {
31471 ++ if (!local_mem)
31472 ++ return -ENOMEM;
31473 ++
31474 + return PTR_ERR(local_mem);
31475 ++ }
31476 +
31477 + /*
31478 + * Here we pass a dma_addr_t but the arg type is a phys_addr_t.
31479 +diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
31480 +index 038140b1de37b..07780148ebedb 100644
31481 +--- a/drivers/usb/dwc3/core.c
31482 ++++ b/drivers/usb/dwc3/core.c
31483 +@@ -122,21 +122,25 @@ static void __dwc3_set_mode(struct work_struct *work)
31484 + unsigned long flags;
31485 + int ret;
31486 + u32 reg;
31487 ++ u32 desired_dr_role;
31488 +
31489 + mutex_lock(&dwc->mutex);
31490 ++ spin_lock_irqsave(&dwc->lock, flags);
31491 ++ desired_dr_role = dwc->desired_dr_role;
31492 ++ spin_unlock_irqrestore(&dwc->lock, flags);
31493 +
31494 + pm_runtime_get_sync(dwc->dev);
31495 +
31496 + if (dwc->current_dr_role == DWC3_GCTL_PRTCAP_OTG)
31497 + dwc3_otg_update(dwc, 0);
31498 +
31499 +- if (!dwc->desired_dr_role)
31500 ++ if (!desired_dr_role)
31501 + goto out;
31502 +
31503 +- if (dwc->desired_dr_role == dwc->current_dr_role)
31504 ++ if (desired_dr_role == dwc->current_dr_role)
31505 + goto out;
31506 +
31507 +- if (dwc->desired_dr_role == DWC3_GCTL_PRTCAP_OTG && dwc->edev)
31508 ++ if (desired_dr_role == DWC3_GCTL_PRTCAP_OTG && dwc->edev)
31509 + goto out;
31510 +
31511 + switch (dwc->current_dr_role) {
31512 +@@ -164,7 +168,7 @@ static void __dwc3_set_mode(struct work_struct *work)
31513 + */
31514 + if (dwc->current_dr_role && ((DWC3_IP_IS(DWC3) ||
31515 + DWC3_VER_IS_PRIOR(DWC31, 190A)) &&
31516 +- dwc->desired_dr_role != DWC3_GCTL_PRTCAP_OTG)) {
31517 ++ desired_dr_role != DWC3_GCTL_PRTCAP_OTG)) {
31518 + reg = dwc3_readl(dwc->regs, DWC3_GCTL);
31519 + reg |= DWC3_GCTL_CORESOFTRESET;
31520 + dwc3_writel(dwc->regs, DWC3_GCTL, reg);
31521 +@@ -184,11 +188,11 @@ static void __dwc3_set_mode(struct work_struct *work)
31522 +
31523 + spin_lock_irqsave(&dwc->lock, flags);
31524 +
31525 +- dwc3_set_prtcap(dwc, dwc->desired_dr_role);
31526 ++ dwc3_set_prtcap(dwc, desired_dr_role);
31527 +
31528 + spin_unlock_irqrestore(&dwc->lock, flags);
31529 +
31530 +- switch (dwc->desired_dr_role) {
31531 ++ switch (desired_dr_role) {
31532 + case DWC3_GCTL_PRTCAP_HOST:
31533 + ret = dwc3_host_init(dwc);
31534 + if (ret) {
31535 +@@ -1096,8 +1100,13 @@ static int dwc3_core_init(struct dwc3 *dwc)
31536 +
31537 + if (!dwc->ulpi_ready) {
31538 + ret = dwc3_core_ulpi_init(dwc);
31539 +- if (ret)
31540 ++ if (ret) {
31541 ++ if (ret == -ETIMEDOUT) {
31542 ++ dwc3_core_soft_reset(dwc);
31543 ++ ret = -EPROBE_DEFER;
31544 ++ }
31545 + goto err0;
31546 ++ }
31547 + dwc->ulpi_ready = true;
31548 + }
31549 +
31550 +diff --git a/drivers/usb/gadget/function/f_hid.c b/drivers/usb/gadget/function/f_hid.c
31551 +index ca0a7d9eaa34e..6be6009f911e1 100644
31552 +--- a/drivers/usb/gadget/function/f_hid.c
31553 ++++ b/drivers/usb/gadget/function/f_hid.c
31554 +@@ -71,7 +71,7 @@ struct f_hidg {
31555 + wait_queue_head_t write_queue;
31556 + struct usb_request *req;
31557 +
31558 +- int minor;
31559 ++ struct device dev;
31560 + struct cdev cdev;
31561 + struct usb_function func;
31562 +
31563 +@@ -84,6 +84,14 @@ static inline struct f_hidg *func_to_hidg(struct usb_function *f)
31564 + return container_of(f, struct f_hidg, func);
31565 + }
31566 +
31567 ++static void hidg_release(struct device *dev)
31568 ++{
31569 ++ struct f_hidg *hidg = container_of(dev, struct f_hidg, dev);
31570 ++
31571 ++ kfree(hidg->set_report_buf);
31572 ++ kfree(hidg);
31573 ++}
31574 ++
31575 + /*-------------------------------------------------------------------------*/
31576 + /* Static descriptors */
31577 +
31578 +@@ -904,9 +912,7 @@ static int hidg_bind(struct usb_configuration *c, struct usb_function *f)
31579 + struct usb_ep *ep;
31580 + struct f_hidg *hidg = func_to_hidg(f);
31581 + struct usb_string *us;
31582 +- struct device *device;
31583 + int status;
31584 +- dev_t dev;
31585 +
31586 + /* maybe allocate device-global string IDs, and patch descriptors */
31587 + us = usb_gstrings_attach(c->cdev, ct_func_strings,
31588 +@@ -999,21 +1005,11 @@ static int hidg_bind(struct usb_configuration *c, struct usb_function *f)
31589 +
31590 + /* create char device */
31591 + cdev_init(&hidg->cdev, &f_hidg_fops);
31592 +- dev = MKDEV(major, hidg->minor);
31593 +- status = cdev_add(&hidg->cdev, dev, 1);
31594 ++ status = cdev_device_add(&hidg->cdev, &hidg->dev);
31595 + if (status)
31596 + goto fail_free_descs;
31597 +
31598 +- device = device_create(hidg_class, NULL, dev, NULL,
31599 +- "%s%d", "hidg", hidg->minor);
31600 +- if (IS_ERR(device)) {
31601 +- status = PTR_ERR(device);
31602 +- goto del;
31603 +- }
31604 +-
31605 + return 0;
31606 +-del:
31607 +- cdev_del(&hidg->cdev);
31608 + fail_free_descs:
31609 + usb_free_all_descriptors(f);
31610 + fail:
31611 +@@ -1244,9 +1240,7 @@ static void hidg_free(struct usb_function *f)
31612 +
31613 + hidg = func_to_hidg(f);
31614 + opts = container_of(f->fi, struct f_hid_opts, func_inst);
31615 +- kfree(hidg->report_desc);
31616 +- kfree(hidg->set_report_buf);
31617 +- kfree(hidg);
31618 ++ put_device(&hidg->dev);
31619 + mutex_lock(&opts->lock);
31620 + --opts->refcnt;
31621 + mutex_unlock(&opts->lock);
31622 +@@ -1256,8 +1250,7 @@ static void hidg_unbind(struct usb_configuration *c, struct usb_function *f)
31623 + {
31624 + struct f_hidg *hidg = func_to_hidg(f);
31625 +
31626 +- device_destroy(hidg_class, MKDEV(major, hidg->minor));
31627 +- cdev_del(&hidg->cdev);
31628 ++ cdev_device_del(&hidg->cdev, &hidg->dev);
31629 +
31630 + usb_free_all_descriptors(f);
31631 + }
31632 +@@ -1266,6 +1259,7 @@ static struct usb_function *hidg_alloc(struct usb_function_instance *fi)
31633 + {
31634 + struct f_hidg *hidg;
31635 + struct f_hid_opts *opts;
31636 ++ int ret;
31637 +
31638 + /* allocate and initialize one new instance */
31639 + hidg = kzalloc(sizeof(*hidg), GFP_KERNEL);
31640 +@@ -1277,17 +1271,28 @@ static struct usb_function *hidg_alloc(struct usb_function_instance *fi)
31641 + mutex_lock(&opts->lock);
31642 + ++opts->refcnt;
31643 +
31644 +- hidg->minor = opts->minor;
31645 ++ device_initialize(&hidg->dev);
31646 ++ hidg->dev.release = hidg_release;
31647 ++ hidg->dev.class = hidg_class;
31648 ++ hidg->dev.devt = MKDEV(major, opts->minor);
31649 ++ ret = dev_set_name(&hidg->dev, "hidg%d", opts->minor);
31650 ++ if (ret) {
31651 ++ --opts->refcnt;
31652 ++ mutex_unlock(&opts->lock);
31653 ++ return ERR_PTR(ret);
31654 ++ }
31655 ++
31656 + hidg->bInterfaceSubClass = opts->subclass;
31657 + hidg->bInterfaceProtocol = opts->protocol;
31658 + hidg->report_length = opts->report_length;
31659 + hidg->report_desc_length = opts->report_desc_length;
31660 + if (opts->report_desc) {
31661 +- hidg->report_desc = kmemdup(opts->report_desc,
31662 +- opts->report_desc_length,
31663 +- GFP_KERNEL);
31664 ++ hidg->report_desc = devm_kmemdup(&hidg->dev, opts->report_desc,
31665 ++ opts->report_desc_length,
31666 ++ GFP_KERNEL);
31667 + if (!hidg->report_desc) {
31668 +- kfree(hidg);
31669 ++ put_device(&hidg->dev);
31670 ++ --opts->refcnt;
31671 + mutex_unlock(&opts->lock);
31672 + return ERR_PTR(-ENOMEM);
31673 + }
31674 +diff --git a/drivers/usb/gadget/udc/core.c b/drivers/usb/gadget/udc/core.c
31675 +index c63c0c2cf649d..bf9878e1a72a8 100644
31676 +--- a/drivers/usb/gadget/udc/core.c
31677 ++++ b/drivers/usb/gadget/udc/core.c
31678 +@@ -734,13 +734,13 @@ int usb_gadget_disconnect(struct usb_gadget *gadget)
31679 + }
31680 +
31681 + ret = gadget->ops->pullup(gadget, 0);
31682 +- if (!ret) {
31683 ++ if (!ret)
31684 + gadget->connected = 0;
31685 +- mutex_lock(&udc_lock);
31686 +- if (gadget->udc->driver)
31687 +- gadget->udc->driver->disconnect(gadget);
31688 +- mutex_unlock(&udc_lock);
31689 +- }
31690 ++
31691 ++ mutex_lock(&udc_lock);
31692 ++ if (gadget->udc->driver)
31693 ++ gadget->udc->driver->disconnect(gadget);
31694 ++ mutex_unlock(&udc_lock);
31695 +
31696 + out:
31697 + trace_usb_gadget_disconnect(gadget, ret);
31698 +diff --git a/drivers/usb/gadget/udc/fotg210-udc.c b/drivers/usb/gadget/udc/fotg210-udc.c
31699 +index fdca28e72a3b4..d0e051beb3af9 100644
31700 +--- a/drivers/usb/gadget/udc/fotg210-udc.c
31701 ++++ b/drivers/usb/gadget/udc/fotg210-udc.c
31702 +@@ -629,10 +629,10 @@ static void fotg210_request_error(struct fotg210_udc *fotg210)
31703 + static void fotg210_set_address(struct fotg210_udc *fotg210,
31704 + struct usb_ctrlrequest *ctrl)
31705 + {
31706 +- if (ctrl->wValue >= 0x0100) {
31707 ++ if (le16_to_cpu(ctrl->wValue) >= 0x0100) {
31708 + fotg210_request_error(fotg210);
31709 + } else {
31710 +- fotg210_set_dev_addr(fotg210, ctrl->wValue);
31711 ++ fotg210_set_dev_addr(fotg210, le16_to_cpu(ctrl->wValue));
31712 + fotg210_set_cxdone(fotg210);
31713 + }
31714 + }
31715 +@@ -713,17 +713,17 @@ static void fotg210_get_status(struct fotg210_udc *fotg210,
31716 +
31717 + switch (ctrl->bRequestType & USB_RECIP_MASK) {
31718 + case USB_RECIP_DEVICE:
31719 +- fotg210->ep0_data = 1 << USB_DEVICE_SELF_POWERED;
31720 ++ fotg210->ep0_data = cpu_to_le16(1 << USB_DEVICE_SELF_POWERED);
31721 + break;
31722 + case USB_RECIP_INTERFACE:
31723 +- fotg210->ep0_data = 0;
31724 ++ fotg210->ep0_data = cpu_to_le16(0);
31725 + break;
31726 + case USB_RECIP_ENDPOINT:
31727 + epnum = ctrl->wIndex & USB_ENDPOINT_NUMBER_MASK;
31728 + if (epnum)
31729 + fotg210->ep0_data =
31730 +- fotg210_is_epnstall(fotg210->ep[epnum])
31731 +- << USB_ENDPOINT_HALT;
31732 ++ cpu_to_le16(fotg210_is_epnstall(fotg210->ep[epnum])
31733 ++ << USB_ENDPOINT_HALT);
31734 + else
31735 + fotg210_request_error(fotg210);
31736 + break;
31737 +diff --git a/drivers/usb/host/xhci-mtk.c b/drivers/usb/host/xhci-mtk.c
31738 +index 01705e559c422..c61fc19ef1154 100644
31739 +--- a/drivers/usb/host/xhci-mtk.c
31740 ++++ b/drivers/usb/host/xhci-mtk.c
31741 +@@ -639,7 +639,6 @@ static int xhci_mtk_probe(struct platform_device *pdev)
31742 +
31743 + dealloc_usb3_hcd:
31744 + usb_remove_hcd(xhci->shared_hcd);
31745 +- xhci->shared_hcd = NULL;
31746 +
31747 + dealloc_usb2_hcd:
31748 + usb_remove_hcd(hcd);
31749 +diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c
31750 +index ad81e9a508b14..343709af4c16f 100644
31751 +--- a/drivers/usb/host/xhci-ring.c
31752 ++++ b/drivers/usb/host/xhci-ring.c
31753 +@@ -2458,7 +2458,7 @@ static int process_bulk_intr_td(struct xhci_hcd *xhci, struct xhci_virt_ep *ep,
31754 +
31755 + switch (trb_comp_code) {
31756 + case COMP_SUCCESS:
31757 +- ep_ring->err_count = 0;
31758 ++ ep->err_count = 0;
31759 + /* handle success with untransferred data as short packet */
31760 + if (ep_trb != td->last_trb || remaining) {
31761 + xhci_warn(xhci, "WARN Successful completion on short TX\n");
31762 +@@ -2484,7 +2484,7 @@ static int process_bulk_intr_td(struct xhci_hcd *xhci, struct xhci_virt_ep *ep,
31763 + break;
31764 + case COMP_USB_TRANSACTION_ERROR:
31765 + if (xhci->quirks & XHCI_NO_SOFT_RETRY ||
31766 +- (ep_ring->err_count++ > MAX_SOFT_RETRY) ||
31767 ++ (ep->err_count++ > MAX_SOFT_RETRY) ||
31768 + le32_to_cpu(slot_ctx->tt_info) & TT_SLOT)
31769 + break;
31770 +
31771 +@@ -2565,8 +2565,14 @@ static int handle_tx_event(struct xhci_hcd *xhci,
31772 + case COMP_USB_TRANSACTION_ERROR:
31773 + case COMP_INVALID_STREAM_TYPE_ERROR:
31774 + case COMP_INVALID_STREAM_ID_ERROR:
31775 +- xhci_handle_halted_endpoint(xhci, ep, 0, NULL,
31776 +- EP_SOFT_RESET);
31777 ++ xhci_dbg(xhci, "Stream transaction error ep %u no id\n",
31778 ++ ep_index);
31779 ++ if (ep->err_count++ > MAX_SOFT_RETRY)
31780 ++ xhci_handle_halted_endpoint(xhci, ep, 0, NULL,
31781 ++ EP_HARD_RESET);
31782 ++ else
31783 ++ xhci_handle_halted_endpoint(xhci, ep, 0, NULL,
31784 ++ EP_SOFT_RESET);
31785 + goto cleanup;
31786 + case COMP_RING_UNDERRUN:
31787 + case COMP_RING_OVERRUN:
31788 +diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h
31789 +index a6daf37ff4bf7..38941554ec55c 100644
31790 +--- a/drivers/usb/host/xhci.h
31791 ++++ b/drivers/usb/host/xhci.h
31792 +@@ -933,6 +933,7 @@ struct xhci_virt_ep {
31793 + * have to restore the device state to the previous state
31794 + */
31795 + struct xhci_ring *new_ring;
31796 ++ unsigned int err_count;
31797 + unsigned int ep_state;
31798 + #define SET_DEQ_PENDING (1 << 0)
31799 + #define EP_HALTED (1 << 1) /* For stall handling */
31800 +@@ -1627,7 +1628,6 @@ struct xhci_ring {
31801 + * if we own the TRB (if we are the consumer). See section 4.9.1.
31802 + */
31803 + u32 cycle_state;
31804 +- unsigned int err_count;
31805 + unsigned int stream_id;
31806 + unsigned int num_segs;
31807 + unsigned int num_trbs_free;
31808 +diff --git a/drivers/usb/musb/musb_gadget.c b/drivers/usb/musb/musb_gadget.c
31809 +index 6704a62a16659..ba20272d22215 100644
31810 +--- a/drivers/usb/musb/musb_gadget.c
31811 ++++ b/drivers/usb/musb/musb_gadget.c
31812 +@@ -1628,8 +1628,6 @@ static int musb_gadget_vbus_draw(struct usb_gadget *gadget, unsigned mA)
31813 + {
31814 + struct musb *musb = gadget_to_musb(gadget);
31815 +
31816 +- if (!musb->xceiv->set_power)
31817 +- return -EOPNOTSUPP;
31818 + return usb_phy_set_power(musb->xceiv, mA);
31819 + }
31820 +
31821 +diff --git a/drivers/usb/musb/omap2430.c b/drivers/usb/musb/omap2430.c
31822 +index f571a65ae6ee2..476f55d1fec30 100644
31823 +--- a/drivers/usb/musb/omap2430.c
31824 ++++ b/drivers/usb/musb/omap2430.c
31825 +@@ -15,6 +15,7 @@
31826 + #include <linux/list.h>
31827 + #include <linux/io.h>
31828 + #include <linux/of.h>
31829 ++#include <linux/of_irq.h>
31830 + #include <linux/platform_device.h>
31831 + #include <linux/dma-mapping.h>
31832 + #include <linux/pm_runtime.h>
31833 +@@ -310,6 +311,7 @@ static int omap2430_probe(struct platform_device *pdev)
31834 + struct device_node *control_node;
31835 + struct platform_device *control_pdev;
31836 + int ret = -ENOMEM, val;
31837 ++ bool populate_irqs = false;
31838 +
31839 + if (!np)
31840 + return -ENODEV;
31841 +@@ -328,6 +330,18 @@ static int omap2430_probe(struct platform_device *pdev)
31842 + musb->dev.dma_mask = &omap2430_dmamask;
31843 + musb->dev.coherent_dma_mask = omap2430_dmamask;
31844 +
31845 ++ /*
31846 ++ * Legacy SoCs using omap_device get confused if node is moved
31847 ++ * because of interconnect properties mixed into the node.
31848 ++ */
31849 ++ if (of_get_property(np, "ti,hwmods", NULL)) {
31850 ++ dev_warn(&pdev->dev, "please update to probe with ti-sysc\n");
31851 ++ populate_irqs = true;
31852 ++ } else {
31853 ++ device_set_of_node_from_dev(&musb->dev, &pdev->dev);
31854 ++ }
31855 ++ of_node_put(np);
31856 ++
31857 + glue->dev = &pdev->dev;
31858 + glue->musb = musb;
31859 + glue->status = MUSB_UNKNOWN;
31860 +@@ -389,6 +403,46 @@ static int omap2430_probe(struct platform_device *pdev)
31861 + goto err2;
31862 + }
31863 +
31864 ++ if (populate_irqs) {
31865 ++ struct resource musb_res[3];
31866 ++ struct resource *res;
31867 ++ int i = 0;
31868 ++
31869 ++ memset(musb_res, 0, sizeof(*musb_res) * ARRAY_SIZE(musb_res));
31870 ++
31871 ++ res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
31872 ++ if (!res)
31873 ++ goto err2;
31874 ++
31875 ++ musb_res[i].start = res->start;
31876 ++ musb_res[i].end = res->end;
31877 ++ musb_res[i].flags = res->flags;
31878 ++ musb_res[i].name = res->name;
31879 ++ i++;
31880 ++
31881 ++ ret = of_irq_get_byname(np, "mc");
31882 ++ if (ret > 0) {
31883 ++ musb_res[i].start = ret;
31884 ++ musb_res[i].flags = IORESOURCE_IRQ;
31885 ++ musb_res[i].name = "mc";
31886 ++ i++;
31887 ++ }
31888 ++
31889 ++ ret = of_irq_get_byname(np, "dma");
31890 ++ if (ret > 0) {
31891 ++ musb_res[i].start = ret;
31892 ++ musb_res[i].flags = IORESOURCE_IRQ;
31893 ++ musb_res[i].name = "dma";
31894 ++ i++;
31895 ++ }
31896 ++
31897 ++ ret = platform_device_add_resources(musb, musb_res, i);
31898 ++ if (ret) {
31899 ++ dev_err(&pdev->dev, "failed to add IRQ resources\n");
31900 ++ goto err2;
31901 ++ }
31902 ++ }
31903 ++
31904 + ret = platform_device_add_data(musb, pdata, sizeof(*pdata));
31905 + if (ret) {
31906 + dev_err(&pdev->dev, "failed to add platform_data\n");
31907 +diff --git a/drivers/usb/roles/class.c b/drivers/usb/roles/class.c
31908 +index dfaed7eee94fc..32e6d19f7011a 100644
31909 +--- a/drivers/usb/roles/class.c
31910 ++++ b/drivers/usb/roles/class.c
31911 +@@ -106,10 +106,13 @@ usb_role_switch_is_parent(struct fwnode_handle *fwnode)
31912 + struct fwnode_handle *parent = fwnode_get_parent(fwnode);
31913 + struct device *dev;
31914 +
31915 +- if (!parent || !fwnode_property_present(parent, "usb-role-switch"))
31916 ++ if (!fwnode_property_present(parent, "usb-role-switch")) {
31917 ++ fwnode_handle_put(parent);
31918 + return NULL;
31919 ++ }
31920 +
31921 + dev = class_find_device_by_fwnode(role_class, parent);
31922 ++ fwnode_handle_put(parent);
31923 + return dev ? to_role_switch(dev) : ERR_PTR(-EPROBE_DEFER);
31924 + }
31925 +
31926 +diff --git a/drivers/usb/storage/alauda.c b/drivers/usb/storage/alauda.c
31927 +index 747be69e5e699..5e912dd29b4c9 100644
31928 +--- a/drivers/usb/storage/alauda.c
31929 ++++ b/drivers/usb/storage/alauda.c
31930 +@@ -438,6 +438,8 @@ static int alauda_init_media(struct us_data *us)
31931 + + MEDIA_INFO(us).blockshift + MEDIA_INFO(us).pageshift);
31932 + MEDIA_INFO(us).pba_to_lba = kcalloc(num_zones, sizeof(u16*), GFP_NOIO);
31933 + MEDIA_INFO(us).lba_to_pba = kcalloc(num_zones, sizeof(u16*), GFP_NOIO);
31934 ++ if (MEDIA_INFO(us).pba_to_lba == NULL || MEDIA_INFO(us).lba_to_pba == NULL)
31935 ++ return USB_STOR_TRANSPORT_ERROR;
31936 +
31937 + if (alauda_reset_media(us) != USB_STOR_XFER_GOOD)
31938 + return USB_STOR_TRANSPORT_ERROR;
31939 +diff --git a/drivers/usb/typec/bus.c b/drivers/usb/typec/bus.c
31940 +index 26ea2fdec17dc..31c2a3130cadb 100644
31941 +--- a/drivers/usb/typec/bus.c
31942 ++++ b/drivers/usb/typec/bus.c
31943 +@@ -134,7 +134,7 @@ int typec_altmode_exit(struct typec_altmode *adev)
31944 + if (!adev || !adev->active)
31945 + return 0;
31946 +
31947 +- if (!pdev->ops || !pdev->ops->enter)
31948 ++ if (!pdev->ops || !pdev->ops->exit)
31949 + return -EOPNOTSUPP;
31950 +
31951 + /* Moving to USB Safe State */
31952 +diff --git a/drivers/usb/typec/tcpm/tcpci.c b/drivers/usb/typec/tcpm/tcpci.c
31953 +index 812784702d539..592bd4c854822 100644
31954 +--- a/drivers/usb/typec/tcpm/tcpci.c
31955 ++++ b/drivers/usb/typec/tcpm/tcpci.c
31956 +@@ -816,8 +816,10 @@ struct tcpci *tcpci_register_port(struct device *dev, struct tcpci_data *data)
31957 + return ERR_PTR(err);
31958 +
31959 + tcpci->port = tcpm_register_port(tcpci->dev, &tcpci->tcpc);
31960 +- if (IS_ERR(tcpci->port))
31961 ++ if (IS_ERR(tcpci->port)) {
31962 ++ fwnode_handle_put(tcpci->tcpc.fwnode);
31963 + return ERR_CAST(tcpci->port);
31964 ++ }
31965 +
31966 + return tcpci;
31967 + }
31968 +@@ -826,6 +828,7 @@ EXPORT_SYMBOL_GPL(tcpci_register_port);
31969 + void tcpci_unregister_port(struct tcpci *tcpci)
31970 + {
31971 + tcpm_unregister_port(tcpci->port);
31972 ++ fwnode_handle_put(tcpci->tcpc.fwnode);
31973 + }
31974 + EXPORT_SYMBOL_GPL(tcpci_unregister_port);
31975 +
31976 +diff --git a/drivers/usb/typec/tipd/core.c b/drivers/usb/typec/tipd/core.c
31977 +index 92e35e62e78c2..513ac7e141a4b 100644
31978 +--- a/drivers/usb/typec/tipd/core.c
31979 ++++ b/drivers/usb/typec/tipd/core.c
31980 +@@ -814,20 +814,19 @@ static int tps6598x_probe(struct i2c_client *client)
31981 +
31982 + ret = devm_tps6598_psy_register(tps);
31983 + if (ret)
31984 +- return ret;
31985 ++ goto err_role_put;
31986 +
31987 + tps->port = typec_register_port(&client->dev, &typec_cap);
31988 + if (IS_ERR(tps->port)) {
31989 + ret = PTR_ERR(tps->port);
31990 + goto err_role_put;
31991 + }
31992 +- fwnode_handle_put(fwnode);
31993 +
31994 + if (status & TPS_STATUS_PLUG_PRESENT) {
31995 + ret = tps6598x_read16(tps, TPS_REG_POWER_STATUS, &tps->pwr_status);
31996 + if (ret < 0) {
31997 + dev_err(tps->dev, "failed to read power status: %d\n", ret);
31998 +- goto err_role_put;
31999 ++ goto err_unregister_port;
32000 + }
32001 + ret = tps6598x_connect(tps, status);
32002 + if (ret)
32003 +@@ -840,14 +839,16 @@ static int tps6598x_probe(struct i2c_client *client)
32004 + dev_name(&client->dev), tps);
32005 + if (ret) {
32006 + tps6598x_disconnect(tps, 0);
32007 +- typec_unregister_port(tps->port);
32008 +- goto err_role_put;
32009 ++ goto err_unregister_port;
32010 + }
32011 +
32012 + i2c_set_clientdata(client, tps);
32013 ++ fwnode_handle_put(fwnode);
32014 +
32015 + return 0;
32016 +
32017 ++err_unregister_port:
32018 ++ typec_unregister_port(tps->port);
32019 + err_role_put:
32020 + usb_role_switch_put(tps->role_sw);
32021 + err_fwnode_put:
32022 +diff --git a/drivers/usb/typec/wusb3801.c b/drivers/usb/typec/wusb3801.c
32023 +index e63509f8b01ed..8e38f5d2ec896 100644
32024 +--- a/drivers/usb/typec/wusb3801.c
32025 ++++ b/drivers/usb/typec/wusb3801.c
32026 +@@ -364,7 +364,7 @@ static int wusb3801_probe(struct i2c_client *client)
32027 + /* Initialize the hardware with the devicetree settings. */
32028 + ret = wusb3801_hw_init(wusb3801);
32029 + if (ret)
32030 +- return ret;
32031 ++ goto err_put_connector;
32032 +
32033 + wusb3801->cap.revision = USB_TYPEC_REV_1_2;
32034 + wusb3801->cap.accessory[0] = TYPEC_ACCESSORY_AUDIO;
32035 +diff --git a/drivers/vfio/platform/vfio_platform_common.c b/drivers/vfio/platform/vfio_platform_common.c
32036 +index 256f55b84e70a..a8d374205a0e0 100644
32037 +--- a/drivers/vfio/platform/vfio_platform_common.c
32038 ++++ b/drivers/vfio/platform/vfio_platform_common.c
32039 +@@ -72,12 +72,11 @@ static int vfio_platform_acpi_call_reset(struct vfio_platform_device *vdev,
32040 + const char **extra_dbg)
32041 + {
32042 + #ifdef CONFIG_ACPI
32043 +- struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
32044 + struct device *dev = vdev->device;
32045 + acpi_handle handle = ACPI_HANDLE(dev);
32046 + acpi_status acpi_ret;
32047 +
32048 +- acpi_ret = acpi_evaluate_object(handle, "_RST", NULL, &buffer);
32049 ++ acpi_ret = acpi_evaluate_object(handle, "_RST", NULL, NULL);
32050 + if (ACPI_FAILURE(acpi_ret)) {
32051 + if (extra_dbg)
32052 + *extra_dbg = acpi_format_exception(acpi_ret);
32053 +diff --git a/drivers/video/fbdev/Kconfig b/drivers/video/fbdev/Kconfig
32054 +index cfc55273dc5d1..974e862cd20d6 100644
32055 +--- a/drivers/video/fbdev/Kconfig
32056 ++++ b/drivers/video/fbdev/Kconfig
32057 +@@ -601,6 +601,7 @@ config FB_TGA
32058 + config FB_UVESA
32059 + tristate "Userspace VESA VGA graphics support"
32060 + depends on FB && CONNECTOR
32061 ++ depends on !UML
32062 + select FB_CFB_FILLRECT
32063 + select FB_CFB_COPYAREA
32064 + select FB_CFB_IMAGEBLIT
32065 +@@ -2217,7 +2218,6 @@ config FB_SSD1307
32066 + select FB_SYS_COPYAREA
32067 + select FB_SYS_IMAGEBLIT
32068 + select FB_DEFERRED_IO
32069 +- select PWM
32070 + select FB_BACKLIGHT
32071 + help
32072 + This driver implements support for the Solomon SSD1307
32073 +diff --git a/drivers/video/fbdev/core/fbcon.c b/drivers/video/fbdev/core/fbcon.c
32074 +index c0143d38df83a..14a7d404062c3 100644
32075 +--- a/drivers/video/fbdev/core/fbcon.c
32076 ++++ b/drivers/video/fbdev/core/fbcon.c
32077 +@@ -2450,7 +2450,8 @@ err_out:
32078 +
32079 + if (userfont) {
32080 + p->userfont = old_userfont;
32081 +- REFCOUNT(data)--;
32082 ++ if (--REFCOUNT(data) == 0)
32083 ++ kfree(data - FONT_EXTRA_WORDS * sizeof(int));
32084 + }
32085 +
32086 + vc->vc_font.width = old_width;
32087 +diff --git a/drivers/video/fbdev/ep93xx-fb.c b/drivers/video/fbdev/ep93xx-fb.c
32088 +index 2398b3d48fedf..305f1587bd898 100644
32089 +--- a/drivers/video/fbdev/ep93xx-fb.c
32090 ++++ b/drivers/video/fbdev/ep93xx-fb.c
32091 +@@ -552,12 +552,14 @@ static int ep93xxfb_probe(struct platform_device *pdev)
32092 +
32093 + err = register_framebuffer(info);
32094 + if (err)
32095 +- goto failed_check;
32096 ++ goto failed_framebuffer;
32097 +
32098 + dev_info(info->dev, "registered. Mode = %dx%d-%d\n",
32099 + info->var.xres, info->var.yres, info->var.bits_per_pixel);
32100 + return 0;
32101 +
32102 ++failed_framebuffer:
32103 ++ clk_disable_unprepare(fbi->clk);
32104 + failed_check:
32105 + if (fbi->mach_info->teardown)
32106 + fbi->mach_info->teardown(pdev);
32107 +diff --git a/drivers/video/fbdev/geode/Kconfig b/drivers/video/fbdev/geode/Kconfig
32108 +index ac9c860592aaf..85bc14b6faf64 100644
32109 +--- a/drivers/video/fbdev/geode/Kconfig
32110 ++++ b/drivers/video/fbdev/geode/Kconfig
32111 +@@ -5,6 +5,7 @@
32112 + config FB_GEODE
32113 + bool "AMD Geode family framebuffer support"
32114 + depends on FB && PCI && (X86_32 || (X86 && COMPILE_TEST))
32115 ++ depends on !UML
32116 + help
32117 + Say 'Y' here to allow you to select framebuffer drivers for
32118 + the AMD Geode family of processors.
32119 +diff --git a/drivers/video/fbdev/hyperv_fb.c b/drivers/video/fbdev/hyperv_fb.c
32120 +index b58b445bb529b..0839ba7d3a345 100644
32121 +--- a/drivers/video/fbdev/hyperv_fb.c
32122 ++++ b/drivers/video/fbdev/hyperv_fb.c
32123 +@@ -779,12 +779,18 @@ static void hvfb_ondemand_refresh_throttle(struct hvfb_par *par,
32124 + static int hvfb_on_panic(struct notifier_block *nb,
32125 + unsigned long e, void *p)
32126 + {
32127 ++ struct hv_device *hdev;
32128 + struct hvfb_par *par;
32129 + struct fb_info *info;
32130 +
32131 + par = container_of(nb, struct hvfb_par, hvfb_panic_nb);
32132 +- par->synchronous_fb = true;
32133 + info = par->info;
32134 ++ hdev = device_to_hv_device(info->device);
32135 ++
32136 ++ if (hv_ringbuffer_spinlock_busy(hdev->channel))
32137 ++ return NOTIFY_DONE;
32138 ++
32139 ++ par->synchronous_fb = true;
32140 + if (par->need_docopy)
32141 + hvfb_docopy(par, 0, dio_fb_size);
32142 + synthvid_update(info, 0, 0, INT_MAX, INT_MAX);
32143 +diff --git a/drivers/video/fbdev/pm2fb.c b/drivers/video/fbdev/pm2fb.c
32144 +index 8fd79deb1e2ae..94f1f33f88f99 100644
32145 +--- a/drivers/video/fbdev/pm2fb.c
32146 ++++ b/drivers/video/fbdev/pm2fb.c
32147 +@@ -1528,8 +1528,10 @@ static int pm2fb_probe(struct pci_dev *pdev, const struct pci_device_id *id)
32148 + }
32149 +
32150 + info = framebuffer_alloc(sizeof(struct pm2fb_par), &pdev->dev);
32151 +- if (!info)
32152 +- return -ENOMEM;
32153 ++ if (!info) {
32154 ++ err = -ENOMEM;
32155 ++ goto err_exit_disable;
32156 ++ }
32157 + default_par = info->par;
32158 +
32159 + switch (pdev->device) {
32160 +@@ -1710,6 +1712,8 @@ static int pm2fb_probe(struct pci_dev *pdev, const struct pci_device_id *id)
32161 + release_mem_region(pm2fb_fix.mmio_start, pm2fb_fix.mmio_len);
32162 + err_exit_neither:
32163 + framebuffer_release(info);
32164 ++ err_exit_disable:
32165 ++ pci_disable_device(pdev);
32166 + return retval;
32167 + }
32168 +
32169 +@@ -1734,6 +1738,7 @@ static void pm2fb_remove(struct pci_dev *pdev)
32170 + fb_dealloc_cmap(&info->cmap);
32171 + kfree(info->pixmap.addr);
32172 + framebuffer_release(info);
32173 ++ pci_disable_device(pdev);
32174 + }
32175 +
32176 + static const struct pci_device_id pm2fb_id_table[] = {
32177 +diff --git a/drivers/video/fbdev/uvesafb.c b/drivers/video/fbdev/uvesafb.c
32178 +index 4df6772802d78..1f3b7e013568c 100644
32179 +--- a/drivers/video/fbdev/uvesafb.c
32180 ++++ b/drivers/video/fbdev/uvesafb.c
32181 +@@ -1758,6 +1758,7 @@ static int uvesafb_probe(struct platform_device *dev)
32182 + out_unmap:
32183 + iounmap(info->screen_base);
32184 + out_mem:
32185 ++ arch_phys_wc_del(par->mtrr_handle);
32186 + release_mem_region(info->fix.smem_start, info->fix.smem_len);
32187 + out_reg:
32188 + release_region(0x3c0, 32);
32189 +diff --git a/drivers/video/fbdev/vermilion/vermilion.c b/drivers/video/fbdev/vermilion/vermilion.c
32190 +index ff61605b8764f..a543643ce014d 100644
32191 +--- a/drivers/video/fbdev/vermilion/vermilion.c
32192 ++++ b/drivers/video/fbdev/vermilion/vermilion.c
32193 +@@ -277,8 +277,10 @@ static int vmlfb_get_gpu(struct vml_par *par)
32194 +
32195 + mutex_unlock(&vml_mutex);
32196 +
32197 +- if (pci_enable_device(par->gpu) < 0)
32198 ++ if (pci_enable_device(par->gpu) < 0) {
32199 ++ pci_dev_put(par->gpu);
32200 + return -ENODEV;
32201 ++ }
32202 +
32203 + return 0;
32204 + }
32205 +diff --git a/drivers/video/fbdev/via/via-core.c b/drivers/video/fbdev/via/via-core.c
32206 +index 89d75079b7307..0363b478fa3ef 100644
32207 +--- a/drivers/video/fbdev/via/via-core.c
32208 ++++ b/drivers/video/fbdev/via/via-core.c
32209 +@@ -725,7 +725,14 @@ static int __init via_core_init(void)
32210 + return ret;
32211 + viafb_i2c_init();
32212 + viafb_gpio_init();
32213 +- return pci_register_driver(&via_driver);
32214 ++ ret = pci_register_driver(&via_driver);
32215 ++ if (ret) {
32216 ++ viafb_gpio_exit();
32217 ++ viafb_i2c_exit();
32218 ++ return ret;
32219 ++ }
32220 ++
32221 ++ return 0;
32222 + }
32223 +
32224 + static void __exit via_core_exit(void)
32225 +diff --git a/drivers/virt/coco/sev-guest/sev-guest.c b/drivers/virt/coco/sev-guest/sev-guest.c
32226 +index 1ea6d2e5b2187..99d6062afe72f 100644
32227 +--- a/drivers/virt/coco/sev-guest/sev-guest.c
32228 ++++ b/drivers/virt/coco/sev-guest/sev-guest.c
32229 +@@ -800,3 +800,4 @@ MODULE_AUTHOR("Brijesh Singh <brijesh.singh@×××.com>");
32230 + MODULE_LICENSE("GPL");
32231 + MODULE_VERSION("1.0.0");
32232 + MODULE_DESCRIPTION("AMD SEV Guest Driver");
32233 ++MODULE_ALIAS("platform:sev-guest");
32234 +diff --git a/drivers/watchdog/iTCO_wdt.c b/drivers/watchdog/iTCO_wdt.c
32235 +index 34693f11385f6..e937b4dd28be7 100644
32236 +--- a/drivers/watchdog/iTCO_wdt.c
32237 ++++ b/drivers/watchdog/iTCO_wdt.c
32238 +@@ -423,14 +423,18 @@ static unsigned int iTCO_wdt_get_timeleft(struct watchdog_device *wd_dev)
32239 + return time_left;
32240 + }
32241 +
32242 +-static void iTCO_wdt_set_running(struct iTCO_wdt_private *p)
32243 ++/* Returns true if the watchdog was running */
32244 ++static bool iTCO_wdt_set_running(struct iTCO_wdt_private *p)
32245 + {
32246 + u16 val;
32247 +
32248 +- /* Bit 11: TCO Timer Halt -> 0 = The TCO timer is * enabled */
32249 ++ /* Bit 11: TCO Timer Halt -> 0 = The TCO timer is enabled */
32250 + val = inw(TCO1_CNT(p));
32251 +- if (!(val & BIT(11)))
32252 ++ if (!(val & BIT(11))) {
32253 + set_bit(WDOG_HW_RUNNING, &p->wddev.status);
32254 ++ return true;
32255 ++ }
32256 ++ return false;
32257 + }
32258 +
32259 + /*
32260 +@@ -518,9 +522,6 @@ static int iTCO_wdt_probe(struct platform_device *pdev)
32261 + return -ENODEV; /* Cannot reset NO_REBOOT bit */
32262 + }
32263 +
32264 +- /* Set the NO_REBOOT bit to prevent later reboots, just for sure */
32265 +- p->update_no_reboot_bit(p->no_reboot_priv, true);
32266 +-
32267 + if (turn_SMI_watchdog_clear_off >= p->iTCO_version) {
32268 + /*
32269 + * Bit 13: TCO_EN -> 0
32270 +@@ -572,7 +573,13 @@ static int iTCO_wdt_probe(struct platform_device *pdev)
32271 + watchdog_set_drvdata(&p->wddev, p);
32272 + platform_set_drvdata(pdev, p);
32273 +
32274 +- iTCO_wdt_set_running(p);
32275 ++ if (!iTCO_wdt_set_running(p)) {
32276 ++ /*
32277 ++ * If the watchdog was not running set NO_REBOOT now to
32278 ++ * prevent later reboots.
32279 ++ */
32280 ++ p->update_no_reboot_bit(p->no_reboot_priv, true);
32281 ++ }
32282 +
32283 + /* Check that the heartbeat value is within it's range;
32284 + if not reset to the default */
32285 +diff --git a/drivers/xen/privcmd.c b/drivers/xen/privcmd.c
32286 +index e88e8f6f0a334..719c5d1dda274 100644
32287 +--- a/drivers/xen/privcmd.c
32288 ++++ b/drivers/xen/privcmd.c
32289 +@@ -760,7 +760,7 @@ static long privcmd_ioctl_mmap_resource(struct file *file,
32290 + goto out;
32291 + }
32292 +
32293 +- pfns = kcalloc(kdata.num, sizeof(*pfns), GFP_KERNEL);
32294 ++ pfns = kcalloc(kdata.num, sizeof(*pfns), GFP_KERNEL | __GFP_NOWARN);
32295 + if (!pfns) {
32296 + rc = -ENOMEM;
32297 + goto out;
32298 +diff --git a/fs/afs/fs_probe.c b/fs/afs/fs_probe.c
32299 +index 3ac5fcf98d0d6..daaf3810cc925 100644
32300 +--- a/fs/afs/fs_probe.c
32301 ++++ b/fs/afs/fs_probe.c
32302 +@@ -366,12 +366,15 @@ void afs_fs_probe_dispatcher(struct work_struct *work)
32303 + unsigned long nowj, timer_at, poll_at;
32304 + bool first_pass = true, set_timer = false;
32305 +
32306 +- if (!net->live)
32307 ++ if (!net->live) {
32308 ++ afs_dec_servers_outstanding(net);
32309 + return;
32310 ++ }
32311 +
32312 + _enter("");
32313 +
32314 + if (list_empty(&net->fs_probe_fast) && list_empty(&net->fs_probe_slow)) {
32315 ++ afs_dec_servers_outstanding(net);
32316 + _leave(" [none]");
32317 + return;
32318 + }
32319 +diff --git a/fs/binfmt_misc.c b/fs/binfmt_misc.c
32320 +index e1eae7ea823ae..bb202ad369d53 100644
32321 +--- a/fs/binfmt_misc.c
32322 ++++ b/fs/binfmt_misc.c
32323 +@@ -44,10 +44,10 @@ static LIST_HEAD(entries);
32324 + static int enabled = 1;
32325 +
32326 + enum {Enabled, Magic};
32327 +-#define MISC_FMT_PRESERVE_ARGV0 (1 << 31)
32328 +-#define MISC_FMT_OPEN_BINARY (1 << 30)
32329 +-#define MISC_FMT_CREDENTIALS (1 << 29)
32330 +-#define MISC_FMT_OPEN_FILE (1 << 28)
32331 ++#define MISC_FMT_PRESERVE_ARGV0 (1UL << 31)
32332 ++#define MISC_FMT_OPEN_BINARY (1UL << 30)
32333 ++#define MISC_FMT_CREDENTIALS (1UL << 29)
32334 ++#define MISC_FMT_OPEN_FILE (1UL << 28)
32335 +
32336 + typedef struct {
32337 + struct list_head list;
32338 +diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c
32339 +index db7c6d22190de..3f6c355356044 100644
32340 +--- a/fs/btrfs/file.c
32341 ++++ b/fs/btrfs/file.c
32342 +@@ -880,7 +880,10 @@ next_slot:
32343 + args->start - extent_offset,
32344 + 0, false);
32345 + ret = btrfs_inc_extent_ref(trans, &ref);
32346 +- BUG_ON(ret); /* -ENOMEM */
32347 ++ if (ret) {
32348 ++ btrfs_abort_transaction(trans, ret);
32349 ++ break;
32350 ++ }
32351 + }
32352 + key.offset = args->start;
32353 + }
32354 +@@ -967,7 +970,10 @@ delete_extent_item:
32355 + key.offset - extent_offset, 0,
32356 + false);
32357 + ret = btrfs_free_extent(trans, &ref);
32358 +- BUG_ON(ret); /* -ENOMEM */
32359 ++ if (ret) {
32360 ++ btrfs_abort_transaction(trans, ret);
32361 ++ break;
32362 ++ }
32363 + args->bytes_found += extent_end - key.offset;
32364 + }
32365 +
32366 +diff --git a/fs/char_dev.c b/fs/char_dev.c
32367 +index ba0ded7842a77..3f667292608c0 100644
32368 +--- a/fs/char_dev.c
32369 ++++ b/fs/char_dev.c
32370 +@@ -547,7 +547,7 @@ int cdev_device_add(struct cdev *cdev, struct device *dev)
32371 + }
32372 +
32373 + rc = device_add(dev);
32374 +- if (rc)
32375 ++ if (rc && dev->devt)
32376 + cdev_del(cdev);
32377 +
32378 + return rc;
32379 +diff --git a/fs/cifs/cifsencrypt.c b/fs/cifs/cifsencrypt.c
32380 +index 46f5718754f94..d848bc0aac274 100644
32381 +--- a/fs/cifs/cifsencrypt.c
32382 ++++ b/fs/cifs/cifsencrypt.c
32383 +@@ -679,7 +679,7 @@ setup_ntlmv2_rsp(struct cifs_ses *ses, const struct nls_table *nls_cp)
32384 + unlock:
32385 + cifs_server_unlock(ses->server);
32386 + setup_ntlmv2_rsp_ret:
32387 +- kfree(tiblob);
32388 ++ kfree_sensitive(tiblob);
32389 +
32390 + return rc;
32391 + }
32392 +@@ -753,14 +753,14 @@ cifs_crypto_secmech_release(struct TCP_Server_Info *server)
32393 + server->secmech.ccmaesdecrypt = NULL;
32394 + }
32395 +
32396 +- kfree(server->secmech.sdesccmacaes);
32397 ++ kfree_sensitive(server->secmech.sdesccmacaes);
32398 + server->secmech.sdesccmacaes = NULL;
32399 +- kfree(server->secmech.sdeschmacsha256);
32400 ++ kfree_sensitive(server->secmech.sdeschmacsha256);
32401 + server->secmech.sdeschmacsha256 = NULL;
32402 +- kfree(server->secmech.sdeschmacmd5);
32403 ++ kfree_sensitive(server->secmech.sdeschmacmd5);
32404 + server->secmech.sdeschmacmd5 = NULL;
32405 +- kfree(server->secmech.sdescmd5);
32406 ++ kfree_sensitive(server->secmech.sdescmd5);
32407 + server->secmech.sdescmd5 = NULL;
32408 +- kfree(server->secmech.sdescsha512);
32409 ++ kfree_sensitive(server->secmech.sdescsha512);
32410 + server->secmech.sdescsha512 = NULL;
32411 + }
32412 +diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
32413 +index ccad85feb24e8..712a431614480 100644
32414 +--- a/fs/cifs/cifsfs.c
32415 ++++ b/fs/cifs/cifsfs.c
32416 +@@ -396,6 +396,7 @@ cifs_alloc_inode(struct super_block *sb)
32417 + cifs_inode->epoch = 0;
32418 + spin_lock_init(&cifs_inode->open_file_lock);
32419 + generate_random_uuid(cifs_inode->lease_key);
32420 ++ cifs_inode->symlink_target = NULL;
32421 +
32422 + /*
32423 + * Can not set i_flags here - they get immediately overwritten to zero
32424 +@@ -412,7 +413,11 @@ cifs_alloc_inode(struct super_block *sb)
32425 + static void
32426 + cifs_free_inode(struct inode *inode)
32427 + {
32428 +- kmem_cache_free(cifs_inode_cachep, CIFS_I(inode));
32429 ++ struct cifsInodeInfo *cinode = CIFS_I(inode);
32430 ++
32431 ++ if (S_ISLNK(inode->i_mode))
32432 ++ kfree(cinode->symlink_target);
32433 ++ kmem_cache_free(cifs_inode_cachep, cinode);
32434 + }
32435 +
32436 + static void
32437 +@@ -1138,6 +1143,30 @@ const struct inode_operations cifs_file_inode_ops = {
32438 + .fiemap = cifs_fiemap,
32439 + };
32440 +
32441 ++const char *cifs_get_link(struct dentry *dentry, struct inode *inode,
32442 ++ struct delayed_call *done)
32443 ++{
32444 ++ char *target_path;
32445 ++
32446 ++ target_path = kmalloc(PATH_MAX, GFP_KERNEL);
32447 ++ if (!target_path)
32448 ++ return ERR_PTR(-ENOMEM);
32449 ++
32450 ++ spin_lock(&inode->i_lock);
32451 ++ if (likely(CIFS_I(inode)->symlink_target)) {
32452 ++ strscpy(target_path, CIFS_I(inode)->symlink_target, PATH_MAX);
32453 ++ } else {
32454 ++ kfree(target_path);
32455 ++ target_path = ERR_PTR(-EOPNOTSUPP);
32456 ++ }
32457 ++ spin_unlock(&inode->i_lock);
32458 ++
32459 ++ if (!IS_ERR(target_path))
32460 ++ set_delayed_call(done, kfree_link, target_path);
32461 ++
32462 ++ return target_path;
32463 ++}
32464 ++
32465 + const struct inode_operations cifs_symlink_inode_ops = {
32466 + .get_link = cifs_get_link,
32467 + .permission = cifs_permission,
32468 +diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
32469 +index ae7f571a7dba2..b52dca800eac5 100644
32470 +--- a/fs/cifs/cifsglob.h
32471 ++++ b/fs/cifs/cifsglob.h
32472 +@@ -13,6 +13,8 @@
32473 + #include <linux/in6.h>
32474 + #include <linux/inet.h>
32475 + #include <linux/slab.h>
32476 ++#include <linux/scatterlist.h>
32477 ++#include <linux/mm.h>
32478 + #include <linux/mempool.h>
32479 + #include <linux/workqueue.h>
32480 + #include <linux/utsname.h>
32481 +@@ -195,6 +197,19 @@ struct cifs_cred {
32482 + struct cifs_ace *aces;
32483 + };
32484 +
32485 ++struct cifs_open_info_data {
32486 ++ char *symlink_target;
32487 ++ union {
32488 ++ struct smb2_file_all_info fi;
32489 ++ struct smb311_posix_qinfo posix_fi;
32490 ++ };
32491 ++};
32492 ++
32493 ++static inline void cifs_free_open_info(struct cifs_open_info_data *data)
32494 ++{
32495 ++ kfree(data->symlink_target);
32496 ++}
32497 ++
32498 + /*
32499 + *****************************************************************
32500 + * Except the CIFS PDUs themselves all the
32501 +@@ -317,20 +332,20 @@ struct smb_version_operations {
32502 + int (*is_path_accessible)(const unsigned int, struct cifs_tcon *,
32503 + struct cifs_sb_info *, const char *);
32504 + /* query path data from the server */
32505 +- int (*query_path_info)(const unsigned int, struct cifs_tcon *,
32506 +- struct cifs_sb_info *, const char *,
32507 +- FILE_ALL_INFO *, bool *, bool *);
32508 ++ int (*query_path_info)(const unsigned int xid, struct cifs_tcon *tcon,
32509 ++ struct cifs_sb_info *cifs_sb, const char *full_path,
32510 ++ struct cifs_open_info_data *data, bool *adjust_tz, bool *reparse);
32511 + /* query file data from the server */
32512 +- int (*query_file_info)(const unsigned int, struct cifs_tcon *,
32513 +- struct cifs_fid *, FILE_ALL_INFO *);
32514 ++ int (*query_file_info)(const unsigned int xid, struct cifs_tcon *tcon,
32515 ++ struct cifsFileInfo *cfile, struct cifs_open_info_data *data);
32516 + /* query reparse tag from srv to determine which type of special file */
32517 + int (*query_reparse_tag)(const unsigned int xid, struct cifs_tcon *tcon,
32518 + struct cifs_sb_info *cifs_sb, const char *path,
32519 + __u32 *reparse_tag);
32520 + /* get server index number */
32521 +- int (*get_srv_inum)(const unsigned int, struct cifs_tcon *,
32522 +- struct cifs_sb_info *, const char *,
32523 +- u64 *uniqueid, FILE_ALL_INFO *);
32524 ++ int (*get_srv_inum)(const unsigned int xid, struct cifs_tcon *tcon,
32525 ++ struct cifs_sb_info *cifs_sb, const char *full_path, u64 *uniqueid,
32526 ++ struct cifs_open_info_data *data);
32527 + /* set size by path */
32528 + int (*set_path_size)(const unsigned int, struct cifs_tcon *,
32529 + const char *, __u64, struct cifs_sb_info *, bool);
32530 +@@ -379,8 +394,8 @@ struct smb_version_operations {
32531 + struct cifs_sb_info *, const char *,
32532 + char **, bool);
32533 + /* open a file for non-posix mounts */
32534 +- int (*open)(const unsigned int, struct cifs_open_parms *,
32535 +- __u32 *, FILE_ALL_INFO *);
32536 ++ int (*open)(const unsigned int xid, struct cifs_open_parms *oparms, __u32 *oplock,
32537 ++ void *buf);
32538 + /* set fid protocol-specific info */
32539 + void (*set_fid)(struct cifsFileInfo *, struct cifs_fid *, __u32);
32540 + /* close a file */
32541 +@@ -1133,6 +1148,7 @@ struct cifs_fattr {
32542 + struct timespec64 cf_mtime;
32543 + struct timespec64 cf_ctime;
32544 + u32 cf_cifstag;
32545 ++ char *cf_symlink_target;
32546 + };
32547 +
32548 + /*
32549 +@@ -1395,6 +1411,7 @@ struct cifsFileInfo {
32550 + struct work_struct put; /* work for the final part of _put */
32551 + struct delayed_work deferred;
32552 + bool deferred_close_scheduled; /* Flag to indicate close is scheduled */
32553 ++ char *symlink_target;
32554 + };
32555 +
32556 + struct cifs_io_parms {
32557 +@@ -1553,6 +1570,7 @@ struct cifsInodeInfo {
32558 + struct list_head deferred_closes; /* list of deferred closes */
32559 + spinlock_t deferred_lock; /* protection on deferred list */
32560 + bool lease_granted; /* Flag to indicate whether lease or oplock is granted. */
32561 ++ char *symlink_target;
32562 + };
32563 +
32564 + static inline struct cifsInodeInfo *
32565 +@@ -2121,4 +2139,80 @@ static inline size_t ntlmssp_workstation_name_size(const struct cifs_ses *ses)
32566 + return sizeof(ses->workstation_name);
32567 + }
32568 +
32569 ++static inline void move_cifs_info_to_smb2(struct smb2_file_all_info *dst, const FILE_ALL_INFO *src)
32570 ++{
32571 ++ memcpy(dst, src, (size_t)((u8 *)&src->AccessFlags - (u8 *)src));
32572 ++ dst->AccessFlags = src->AccessFlags;
32573 ++ dst->CurrentByteOffset = src->CurrentByteOffset;
32574 ++ dst->Mode = src->Mode;
32575 ++ dst->AlignmentRequirement = src->AlignmentRequirement;
32576 ++ dst->FileNameLength = src->FileNameLength;
32577 ++}
32578 ++
32579 ++static inline unsigned int cifs_get_num_sgs(const struct smb_rqst *rqst,
32580 ++ int num_rqst,
32581 ++ const u8 *sig)
32582 ++{
32583 ++ unsigned int len, skip;
32584 ++ unsigned int nents = 0;
32585 ++ unsigned long addr;
32586 ++ int i, j;
32587 ++
32588 ++ /* Assumes the first rqst has a transform header as the first iov.
32589 ++ * I.e.
32590 ++ * rqst[0].rq_iov[0] is transform header
32591 ++ * rqst[0].rq_iov[1+] data to be encrypted/decrypted
32592 ++ * rqst[1+].rq_iov[0+] data to be encrypted/decrypted
32593 ++ */
32594 ++ for (i = 0; i < num_rqst; i++) {
32595 ++ /*
32596 ++ * The first rqst has a transform header where the
32597 ++ * first 20 bytes are not part of the encrypted blob.
32598 ++ */
32599 ++ for (j = 0; j < rqst[i].rq_nvec; j++) {
32600 ++ struct kvec *iov = &rqst[i].rq_iov[j];
32601 ++
32602 ++ skip = (i == 0) && (j == 0) ? 20 : 0;
32603 ++ addr = (unsigned long)iov->iov_base + skip;
32604 ++ if (unlikely(is_vmalloc_addr((void *)addr))) {
32605 ++ len = iov->iov_len - skip;
32606 ++ nents += DIV_ROUND_UP(offset_in_page(addr) + len,
32607 ++ PAGE_SIZE);
32608 ++ } else {
32609 ++ nents++;
32610 ++ }
32611 ++ }
32612 ++ nents += rqst[i].rq_npages;
32613 ++ }
32614 ++ nents += DIV_ROUND_UP(offset_in_page(sig) + SMB2_SIGNATURE_SIZE, PAGE_SIZE);
32615 ++ return nents;
32616 ++}
32617 ++
32618 ++/* We can not use the normal sg_set_buf() as we will sometimes pass a
32619 ++ * stack object as buf.
32620 ++ */
32621 ++static inline struct scatterlist *cifs_sg_set_buf(struct scatterlist *sg,
32622 ++ const void *buf,
32623 ++ unsigned int buflen)
32624 ++{
32625 ++ unsigned long addr = (unsigned long)buf;
32626 ++ unsigned int off = offset_in_page(addr);
32627 ++
32628 ++ addr &= PAGE_MASK;
32629 ++ if (unlikely(is_vmalloc_addr((void *)addr))) {
32630 ++ do {
32631 ++ unsigned int len = min_t(unsigned int, buflen, PAGE_SIZE - off);
32632 ++
32633 ++ sg_set_page(sg++, vmalloc_to_page((void *)addr), len, off);
32634 ++
32635 ++ off = 0;
32636 ++ addr += PAGE_SIZE;
32637 ++ buflen -= len;
32638 ++ } while (buflen);
32639 ++ } else {
32640 ++ sg_set_page(sg++, virt_to_page(addr), buflen, off);
32641 ++ }
32642 ++ return sg;
32643 ++}
32644 ++
32645 + #endif /* _CIFS_GLOB_H */
32646 +diff --git a/fs/cifs/cifsproto.h b/fs/cifs/cifsproto.h
32647 +index 71386978858eb..edf6f18ec8b73 100644
32648 +--- a/fs/cifs/cifsproto.h
32649 ++++ b/fs/cifs/cifsproto.h
32650 +@@ -182,10 +182,9 @@ extern int cifs_unlock_range(struct cifsFileInfo *cfile,
32651 + extern int cifs_push_mandatory_locks(struct cifsFileInfo *cfile);
32652 +
32653 + extern void cifs_down_write(struct rw_semaphore *sem);
32654 +-extern struct cifsFileInfo *cifs_new_fileinfo(struct cifs_fid *fid,
32655 +- struct file *file,
32656 +- struct tcon_link *tlink,
32657 +- __u32 oplock);
32658 ++struct cifsFileInfo *cifs_new_fileinfo(struct cifs_fid *fid, struct file *file,
32659 ++ struct tcon_link *tlink, __u32 oplock,
32660 ++ const char *symlink_target);
32661 + extern int cifs_posix_open(const char *full_path, struct inode **inode,
32662 + struct super_block *sb, int mode,
32663 + unsigned int f_flags, __u32 *oplock, __u16 *netfid,
32664 +@@ -200,9 +199,9 @@ extern int cifs_fattr_to_inode(struct inode *inode, struct cifs_fattr *fattr);
32665 + extern struct inode *cifs_iget(struct super_block *sb,
32666 + struct cifs_fattr *fattr);
32667 +
32668 +-extern int cifs_get_inode_info(struct inode **inode, const char *full_path,
32669 +- FILE_ALL_INFO *data, struct super_block *sb,
32670 +- int xid, const struct cifs_fid *fid);
32671 ++int cifs_get_inode_info(struct inode **inode, const char *full_path,
32672 ++ struct cifs_open_info_data *data, struct super_block *sb, int xid,
32673 ++ const struct cifs_fid *fid);
32674 + extern int smb311_posix_get_inode_info(struct inode **pinode, const char *search_path,
32675 + struct super_block *sb, unsigned int xid);
32676 + extern int cifs_get_inode_info_unix(struct inode **pinode,
32677 +@@ -602,8 +601,8 @@ int cifs_alloc_hash(const char *name, struct crypto_shash **shash,
32678 + struct sdesc **sdesc);
32679 + void cifs_free_hash(struct crypto_shash **shash, struct sdesc **sdesc);
32680 +
32681 +-extern void rqst_page_get_length(struct smb_rqst *rqst, unsigned int page,
32682 +- unsigned int *len, unsigned int *offset);
32683 ++void rqst_page_get_length(const struct smb_rqst *rqst, unsigned int page,
32684 ++ unsigned int *len, unsigned int *offset);
32685 + struct cifs_chan *
32686 + cifs_ses_find_chan(struct cifs_ses *ses, struct TCP_Server_Info *server);
32687 + int cifs_try_adding_channels(struct cifs_sb_info *cifs_sb, struct cifs_ses *ses);
32688 +diff --git a/fs/cifs/connect.c b/fs/cifs/connect.c
32689 +index 317ca1be9c4c0..816161f51b29d 100644
32690 +--- a/fs/cifs/connect.c
32691 ++++ b/fs/cifs/connect.c
32692 +@@ -311,7 +311,7 @@ cifs_abort_connection(struct TCP_Server_Info *server)
32693 + }
32694 + server->sequence_number = 0;
32695 + server->session_estab = false;
32696 +- kfree(server->session_key.response);
32697 ++ kfree_sensitive(server->session_key.response);
32698 + server->session_key.response = NULL;
32699 + server->session_key.len = 0;
32700 + server->lstrp = jiffies;
32701 +@@ -1580,7 +1580,7 @@ cifs_put_tcp_session(struct TCP_Server_Info *server, int from_reconnect)
32702 +
32703 + cifs_crypto_secmech_release(server);
32704 +
32705 +- kfree(server->session_key.response);
32706 ++ kfree_sensitive(server->session_key.response);
32707 + server->session_key.response = NULL;
32708 + server->session_key.len = 0;
32709 + kfree(server->hostname);
32710 +@@ -4141,7 +4141,7 @@ cifs_setup_session(const unsigned int xid, struct cifs_ses *ses,
32711 + if (ses->auth_key.response) {
32712 + cifs_dbg(FYI, "Free previous auth_key.response = %p\n",
32713 + ses->auth_key.response);
32714 +- kfree(ses->auth_key.response);
32715 ++ kfree_sensitive(ses->auth_key.response);
32716 + ses->auth_key.response = NULL;
32717 + ses->auth_key.len = 0;
32718 + }
32719 +diff --git a/fs/cifs/dir.c b/fs/cifs/dir.c
32720 +index 05c78a18ade07..c85816cf2d9b3 100644
32721 +--- a/fs/cifs/dir.c
32722 ++++ b/fs/cifs/dir.c
32723 +@@ -165,10 +165,9 @@ check_name(struct dentry *direntry, struct cifs_tcon *tcon)
32724 +
32725 + /* Inode operations in similar order to how they appear in Linux file fs.h */
32726 +
32727 +-static int
32728 +-cifs_do_create(struct inode *inode, struct dentry *direntry, unsigned int xid,
32729 +- struct tcon_link *tlink, unsigned oflags, umode_t mode,
32730 +- __u32 *oplock, struct cifs_fid *fid)
32731 ++static int cifs_do_create(struct inode *inode, struct dentry *direntry, unsigned int xid,
32732 ++ struct tcon_link *tlink, unsigned int oflags, umode_t mode, __u32 *oplock,
32733 ++ struct cifs_fid *fid, struct cifs_open_info_data *buf)
32734 + {
32735 + int rc = -ENOENT;
32736 + int create_options = CREATE_NOT_DIR;
32737 +@@ -177,7 +176,6 @@ cifs_do_create(struct inode *inode, struct dentry *direntry, unsigned int xid,
32738 + struct cifs_tcon *tcon = tlink_tcon(tlink);
32739 + const char *full_path;
32740 + void *page = alloc_dentry_path();
32741 +- FILE_ALL_INFO *buf = NULL;
32742 + struct inode *newinode = NULL;
32743 + int disposition;
32744 + struct TCP_Server_Info *server = tcon->ses->server;
32745 +@@ -290,12 +288,6 @@ cifs_do_create(struct inode *inode, struct dentry *direntry, unsigned int xid,
32746 + goto out;
32747 + }
32748 +
32749 +- buf = kmalloc(sizeof(FILE_ALL_INFO), GFP_KERNEL);
32750 +- if (buf == NULL) {
32751 +- rc = -ENOMEM;
32752 +- goto out;
32753 +- }
32754 +-
32755 + /*
32756 + * if we're not using unix extensions, see if we need to set
32757 + * ATTR_READONLY on the create call
32758 +@@ -364,8 +356,7 @@ cifs_create_get_file_info:
32759 + {
32760 + #endif /* CONFIG_CIFS_ALLOW_INSECURE_LEGACY */
32761 + /* TODO: Add support for calling POSIX query info here, but passing in fid */
32762 +- rc = cifs_get_inode_info(&newinode, full_path, buf, inode->i_sb,
32763 +- xid, fid);
32764 ++ rc = cifs_get_inode_info(&newinode, full_path, buf, inode->i_sb, xid, fid);
32765 + if (newinode) {
32766 + if (server->ops->set_lease_key)
32767 + server->ops->set_lease_key(newinode, fid);
32768 +@@ -402,7 +393,6 @@ cifs_create_set_dentry:
32769 + d_add(direntry, newinode);
32770 +
32771 + out:
32772 +- kfree(buf);
32773 + free_dentry_path(page);
32774 + return rc;
32775 +
32776 +@@ -427,6 +417,7 @@ cifs_atomic_open(struct inode *inode, struct dentry *direntry,
32777 + struct cifs_pending_open open;
32778 + __u32 oplock;
32779 + struct cifsFileInfo *file_info;
32780 ++ struct cifs_open_info_data buf = {};
32781 +
32782 + if (unlikely(cifs_forced_shutdown(CIFS_SB(inode->i_sb))))
32783 + return -EIO;
32784 +@@ -484,8 +475,7 @@ cifs_atomic_open(struct inode *inode, struct dentry *direntry,
32785 + cifs_add_pending_open(&fid, tlink, &open);
32786 +
32787 + rc = cifs_do_create(inode, direntry, xid, tlink, oflags, mode,
32788 +- &oplock, &fid);
32789 +-
32790 ++ &oplock, &fid, &buf);
32791 + if (rc) {
32792 + cifs_del_pending_open(&open);
32793 + goto out;
32794 +@@ -510,7 +500,7 @@ cifs_atomic_open(struct inode *inode, struct dentry *direntry,
32795 + file->f_op = &cifs_file_direct_ops;
32796 + }
32797 +
32798 +- file_info = cifs_new_fileinfo(&fid, file, tlink, oplock);
32799 ++ file_info = cifs_new_fileinfo(&fid, file, tlink, oplock, buf.symlink_target);
32800 + if (file_info == NULL) {
32801 + if (server->ops->close)
32802 + server->ops->close(xid, tcon, &fid);
32803 +@@ -526,6 +516,7 @@ out:
32804 + cifs_put_tlink(tlink);
32805 + out_free_xid:
32806 + free_xid(xid);
32807 ++ cifs_free_open_info(&buf);
32808 + return rc;
32809 + }
32810 +
32811 +@@ -547,6 +538,7 @@ int cifs_create(struct user_namespace *mnt_userns, struct inode *inode,
32812 + struct TCP_Server_Info *server;
32813 + struct cifs_fid fid;
32814 + __u32 oplock;
32815 ++ struct cifs_open_info_data buf = {};
32816 +
32817 + cifs_dbg(FYI, "cifs_create parent inode = 0x%p name is: %pd and dentry = 0x%p\n",
32818 + inode, direntry, direntry);
32819 +@@ -567,11 +559,11 @@ int cifs_create(struct user_namespace *mnt_userns, struct inode *inode,
32820 + if (server->ops->new_lease_key)
32821 + server->ops->new_lease_key(&fid);
32822 +
32823 +- rc = cifs_do_create(inode, direntry, xid, tlink, oflags, mode,
32824 +- &oplock, &fid);
32825 ++ rc = cifs_do_create(inode, direntry, xid, tlink, oflags, mode, &oplock, &fid, &buf);
32826 + if (!rc && server->ops->close)
32827 + server->ops->close(xid, tcon, &fid);
32828 +
32829 ++ cifs_free_open_info(&buf);
32830 + cifs_put_tlink(tlink);
32831 + out_free_xid:
32832 + free_xid(xid);
32833 +diff --git a/fs/cifs/file.c b/fs/cifs/file.c
32834 +index 5c045dd697846..391fd2580dabb 100644
32835 +--- a/fs/cifs/file.c
32836 ++++ b/fs/cifs/file.c
32837 +@@ -209,16 +209,14 @@ posix_open_ret:
32838 + }
32839 + #endif /* CONFIG_CIFS_ALLOW_INSECURE_LEGACY */
32840 +
32841 +-static int
32842 +-cifs_nt_open(const char *full_path, struct inode *inode, struct cifs_sb_info *cifs_sb,
32843 +- struct cifs_tcon *tcon, unsigned int f_flags, __u32 *oplock,
32844 +- struct cifs_fid *fid, unsigned int xid)
32845 ++static int cifs_nt_open(const char *full_path, struct inode *inode, struct cifs_sb_info *cifs_sb,
32846 ++ struct cifs_tcon *tcon, unsigned int f_flags, __u32 *oplock,
32847 ++ struct cifs_fid *fid, unsigned int xid, struct cifs_open_info_data *buf)
32848 + {
32849 + int rc;
32850 + int desired_access;
32851 + int disposition;
32852 + int create_options = CREATE_NOT_DIR;
32853 +- FILE_ALL_INFO *buf;
32854 + struct TCP_Server_Info *server = tcon->ses->server;
32855 + struct cifs_open_parms oparms;
32856 +
32857 +@@ -255,10 +253,6 @@ cifs_nt_open(const char *full_path, struct inode *inode, struct cifs_sb_info *ci
32858 +
32859 + /* BB pass O_SYNC flag through on file attributes .. BB */
32860 +
32861 +- buf = kmalloc(sizeof(FILE_ALL_INFO), GFP_KERNEL);
32862 +- if (!buf)
32863 +- return -ENOMEM;
32864 +-
32865 + /* O_SYNC also has bit for O_DSYNC so following check picks up either */
32866 + if (f_flags & O_SYNC)
32867 + create_options |= CREATE_WRITE_THROUGH;
32868 +@@ -276,9 +270,8 @@ cifs_nt_open(const char *full_path, struct inode *inode, struct cifs_sb_info *ci
32869 + oparms.reconnect = false;
32870 +
32871 + rc = server->ops->open(xid, &oparms, oplock, buf);
32872 +-
32873 + if (rc)
32874 +- goto out;
32875 ++ return rc;
32876 +
32877 + /* TODO: Add support for calling posix query info but with passing in fid */
32878 + if (tcon->unix_ext)
32879 +@@ -294,8 +287,6 @@ cifs_nt_open(const char *full_path, struct inode *inode, struct cifs_sb_info *ci
32880 + rc = -EOPENSTALE;
32881 + }
32882 +
32883 +-out:
32884 +- kfree(buf);
32885 + return rc;
32886 + }
32887 +
32888 +@@ -325,9 +316,9 @@ cifs_down_write(struct rw_semaphore *sem)
32889 +
32890 + static void cifsFileInfo_put_work(struct work_struct *work);
32891 +
32892 +-struct cifsFileInfo *
32893 +-cifs_new_fileinfo(struct cifs_fid *fid, struct file *file,
32894 +- struct tcon_link *tlink, __u32 oplock)
32895 ++struct cifsFileInfo *cifs_new_fileinfo(struct cifs_fid *fid, struct file *file,
32896 ++ struct tcon_link *tlink, __u32 oplock,
32897 ++ const char *symlink_target)
32898 + {
32899 + struct dentry *dentry = file_dentry(file);
32900 + struct inode *inode = d_inode(dentry);
32901 +@@ -347,6 +338,15 @@ cifs_new_fileinfo(struct cifs_fid *fid, struct file *file,
32902 + return NULL;
32903 + }
32904 +
32905 ++ if (symlink_target) {
32906 ++ cfile->symlink_target = kstrdup(symlink_target, GFP_KERNEL);
32907 ++ if (!cfile->symlink_target) {
32908 ++ kfree(fdlocks);
32909 ++ kfree(cfile);
32910 ++ return NULL;
32911 ++ }
32912 ++ }
32913 ++
32914 + INIT_LIST_HEAD(&fdlocks->locks);
32915 + fdlocks->cfile = cfile;
32916 + cfile->llist = fdlocks;
32917 +@@ -440,6 +440,7 @@ static void cifsFileInfo_put_final(struct cifsFileInfo *cifs_file)
32918 + cifs_put_tlink(cifs_file->tlink);
32919 + dput(cifs_file->dentry);
32920 + cifs_sb_deactive(sb);
32921 ++ kfree(cifs_file->symlink_target);
32922 + kfree(cifs_file);
32923 + }
32924 +
32925 +@@ -572,6 +573,7 @@ int cifs_open(struct inode *inode, struct file *file)
32926 + bool posix_open_ok = false;
32927 + struct cifs_fid fid;
32928 + struct cifs_pending_open open;
32929 ++ struct cifs_open_info_data data = {};
32930 +
32931 + xid = get_xid();
32932 +
32933 +@@ -662,15 +664,15 @@ int cifs_open(struct inode *inode, struct file *file)
32934 + if (server->ops->get_lease_key)
32935 + server->ops->get_lease_key(inode, &fid);
32936 +
32937 +- rc = cifs_nt_open(full_path, inode, cifs_sb, tcon,
32938 +- file->f_flags, &oplock, &fid, xid);
32939 ++ rc = cifs_nt_open(full_path, inode, cifs_sb, tcon, file->f_flags, &oplock, &fid,
32940 ++ xid, &data);
32941 + if (rc) {
32942 + cifs_del_pending_open(&open);
32943 + goto out;
32944 + }
32945 + }
32946 +
32947 +- cfile = cifs_new_fileinfo(&fid, file, tlink, oplock);
32948 ++ cfile = cifs_new_fileinfo(&fid, file, tlink, oplock, data.symlink_target);
32949 + if (cfile == NULL) {
32950 + if (server->ops->close)
32951 + server->ops->close(xid, tcon, &fid);
32952 +@@ -712,6 +714,7 @@ out:
32953 + free_dentry_path(page);
32954 + free_xid(xid);
32955 + cifs_put_tlink(tlink);
32956 ++ cifs_free_open_info(&data);
32957 + return rc;
32958 + }
32959 +
32960 +diff --git a/fs/cifs/fs_context.c b/fs/cifs/fs_context.c
32961 +index 0e13dec86b252..45119597c7655 100644
32962 +--- a/fs/cifs/fs_context.c
32963 ++++ b/fs/cifs/fs_context.c
32964 +@@ -791,6 +791,13 @@ do { \
32965 + cifs_sb->ctx->field = NULL; \
32966 + } while (0)
32967 +
32968 ++#define STEAL_STRING_SENSITIVE(cifs_sb, ctx, field) \
32969 ++do { \
32970 ++ kfree_sensitive(ctx->field); \
32971 ++ ctx->field = cifs_sb->ctx->field; \
32972 ++ cifs_sb->ctx->field = NULL; \
32973 ++} while (0)
32974 ++
32975 + static int smb3_reconfigure(struct fs_context *fc)
32976 + {
32977 + struct smb3_fs_context *ctx = smb3_fc2context(fc);
32978 +@@ -811,7 +818,7 @@ static int smb3_reconfigure(struct fs_context *fc)
32979 + STEAL_STRING(cifs_sb, ctx, UNC);
32980 + STEAL_STRING(cifs_sb, ctx, source);
32981 + STEAL_STRING(cifs_sb, ctx, username);
32982 +- STEAL_STRING(cifs_sb, ctx, password);
32983 ++ STEAL_STRING_SENSITIVE(cifs_sb, ctx, password);
32984 + STEAL_STRING(cifs_sb, ctx, domainname);
32985 + STEAL_STRING(cifs_sb, ctx, nodename);
32986 + STEAL_STRING(cifs_sb, ctx, iocharset);
32987 +@@ -1162,7 +1169,7 @@ static int smb3_fs_context_parse_param(struct fs_context *fc,
32988 + }
32989 + break;
32990 + case Opt_pass:
32991 +- kfree(ctx->password);
32992 ++ kfree_sensitive(ctx->password);
32993 + ctx->password = NULL;
32994 + if (strlen(param->string) == 0)
32995 + break;
32996 +@@ -1470,6 +1477,7 @@ static int smb3_fs_context_parse_param(struct fs_context *fc,
32997 + return 0;
32998 +
32999 + cifs_parse_mount_err:
33000 ++ kfree_sensitive(ctx->password);
33001 + return -EINVAL;
33002 + }
33003 +
33004 +diff --git a/fs/cifs/inode.c b/fs/cifs/inode.c
33005 +index bac08c20f559b..b4555f6e327f1 100644
33006 +--- a/fs/cifs/inode.c
33007 ++++ b/fs/cifs/inode.c
33008 +@@ -210,6 +210,12 @@ cifs_fattr_to_inode(struct inode *inode, struct cifs_fattr *fattr)
33009 + */
33010 + inode->i_blocks = (512 - 1 + fattr->cf_bytes) >> 9;
33011 + }
33012 ++
33013 ++ if (S_ISLNK(fattr->cf_mode)) {
33014 ++ kfree(cifs_i->symlink_target);
33015 ++ cifs_i->symlink_target = fattr->cf_symlink_target;
33016 ++ fattr->cf_symlink_target = NULL;
33017 ++ }
33018 + spin_unlock(&inode->i_lock);
33019 +
33020 + if (fattr->cf_flags & CIFS_FATTR_DFS_REFERRAL)
33021 +@@ -347,13 +353,22 @@ cifs_get_file_info_unix(struct file *filp)
33022 + int rc;
33023 + unsigned int xid;
33024 + FILE_UNIX_BASIC_INFO find_data;
33025 +- struct cifs_fattr fattr;
33026 ++ struct cifs_fattr fattr = {};
33027 + struct inode *inode = file_inode(filp);
33028 + struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
33029 + struct cifsFileInfo *cfile = filp->private_data;
33030 + struct cifs_tcon *tcon = tlink_tcon(cfile->tlink);
33031 +
33032 + xid = get_xid();
33033 ++
33034 ++ if (cfile->symlink_target) {
33035 ++ fattr.cf_symlink_target = kstrdup(cfile->symlink_target, GFP_KERNEL);
33036 ++ if (!fattr.cf_symlink_target) {
33037 ++ rc = -ENOMEM;
33038 ++ goto cifs_gfiunix_out;
33039 ++ }
33040 ++ }
33041 ++
33042 + rc = CIFSSMBUnixQFileInfo(xid, tcon, cfile->fid.netfid, &find_data);
33043 + if (!rc) {
33044 + cifs_unix_basic_to_fattr(&fattr, &find_data, cifs_sb);
33045 +@@ -378,6 +393,7 @@ int cifs_get_inode_info_unix(struct inode **pinode,
33046 + FILE_UNIX_BASIC_INFO find_data;
33047 + struct cifs_fattr fattr;
33048 + struct cifs_tcon *tcon;
33049 ++ struct TCP_Server_Info *server;
33050 + struct tcon_link *tlink;
33051 + struct cifs_sb_info *cifs_sb = CIFS_SB(sb);
33052 +
33053 +@@ -387,10 +403,12 @@ int cifs_get_inode_info_unix(struct inode **pinode,
33054 + if (IS_ERR(tlink))
33055 + return PTR_ERR(tlink);
33056 + tcon = tlink_tcon(tlink);
33057 ++ server = tcon->ses->server;
33058 +
33059 + /* could have done a find first instead but this returns more info */
33060 + rc = CIFSSMBUnixQPathInfo(xid, tcon, full_path, &find_data,
33061 + cifs_sb->local_nls, cifs_remap(cifs_sb));
33062 ++ cifs_dbg(FYI, "%s: query path info: rc = %d\n", __func__, rc);
33063 + cifs_put_tlink(tlink);
33064 +
33065 + if (!rc) {
33066 +@@ -410,6 +428,17 @@ int cifs_get_inode_info_unix(struct inode **pinode,
33067 + cifs_dbg(FYI, "check_mf_symlink: %d\n", tmprc);
33068 + }
33069 +
33070 ++ if (S_ISLNK(fattr.cf_mode) && !fattr.cf_symlink_target) {
33071 ++ if (!server->ops->query_symlink)
33072 ++ return -EOPNOTSUPP;
33073 ++ rc = server->ops->query_symlink(xid, tcon, cifs_sb, full_path,
33074 ++ &fattr.cf_symlink_target, false);
33075 ++ if (rc) {
33076 ++ cifs_dbg(FYI, "%s: query_symlink: %d\n", __func__, rc);
33077 ++ goto cgiiu_exit;
33078 ++ }
33079 ++ }
33080 ++
33081 + if (*pinode == NULL) {
33082 + /* get new inode */
33083 + cifs_fill_uniqueid(sb, &fattr);
33084 +@@ -432,6 +461,7 @@ int cifs_get_inode_info_unix(struct inode **pinode,
33085 + }
33086 +
33087 + cgiiu_exit:
33088 ++ kfree(fattr.cf_symlink_target);
33089 + return rc;
33090 + }
33091 + #else
33092 +@@ -601,10 +631,10 @@ static int cifs_sfu_mode(struct cifs_fattr *fattr, const unsigned char *path,
33093 + }
33094 +
33095 + /* Fill a cifs_fattr struct with info from POSIX info struct */
33096 +-static void
33097 +-smb311_posix_info_to_fattr(struct cifs_fattr *fattr, struct smb311_posix_qinfo *info,
33098 +- struct super_block *sb, bool adjust_tz, bool symlink)
33099 ++static void smb311_posix_info_to_fattr(struct cifs_fattr *fattr, struct cifs_open_info_data *data,
33100 ++ struct super_block *sb, bool adjust_tz, bool symlink)
33101 + {
33102 ++ struct smb311_posix_qinfo *info = &data->posix_fi;
33103 + struct cifs_sb_info *cifs_sb = CIFS_SB(sb);
33104 + struct cifs_tcon *tcon = cifs_sb_master_tcon(cifs_sb);
33105 +
33106 +@@ -639,6 +669,8 @@ smb311_posix_info_to_fattr(struct cifs_fattr *fattr, struct smb311_posix_qinfo *
33107 + if (symlink) {
33108 + fattr->cf_mode |= S_IFLNK;
33109 + fattr->cf_dtype = DT_LNK;
33110 ++ fattr->cf_symlink_target = data->symlink_target;
33111 ++ data->symlink_target = NULL;
33112 + } else if (fattr->cf_cifsattrs & ATTR_DIRECTORY) {
33113 + fattr->cf_mode |= S_IFDIR;
33114 + fattr->cf_dtype = DT_DIR;
33115 +@@ -655,13 +687,11 @@ smb311_posix_info_to_fattr(struct cifs_fattr *fattr, struct smb311_posix_qinfo *
33116 + fattr->cf_mode, fattr->cf_uniqueid, fattr->cf_nlink);
33117 + }
33118 +
33119 +-
33120 +-/* Fill a cifs_fattr struct with info from FILE_ALL_INFO */
33121 +-static void
33122 +-cifs_all_info_to_fattr(struct cifs_fattr *fattr, FILE_ALL_INFO *info,
33123 +- struct super_block *sb, bool adjust_tz,
33124 +- bool symlink, u32 reparse_tag)
33125 ++static void cifs_open_info_to_fattr(struct cifs_fattr *fattr, struct cifs_open_info_data *data,
33126 ++ struct super_block *sb, bool adjust_tz, bool symlink,
33127 ++ u32 reparse_tag)
33128 + {
33129 ++ struct smb2_file_all_info *info = &data->fi;
33130 + struct cifs_sb_info *cifs_sb = CIFS_SB(sb);
33131 + struct cifs_tcon *tcon = cifs_sb_master_tcon(cifs_sb);
33132 +
33133 +@@ -703,7 +733,8 @@ cifs_all_info_to_fattr(struct cifs_fattr *fattr, FILE_ALL_INFO *info,
33134 + } else if (reparse_tag == IO_REPARSE_TAG_LX_BLK) {
33135 + fattr->cf_mode |= S_IFBLK | cifs_sb->ctx->file_mode;
33136 + fattr->cf_dtype = DT_BLK;
33137 +- } else if (symlink) { /* TODO add more reparse tag checks */
33138 ++ } else if (symlink || reparse_tag == IO_REPARSE_TAG_SYMLINK ||
33139 ++ reparse_tag == IO_REPARSE_TAG_NFS) {
33140 + fattr->cf_mode = S_IFLNK;
33141 + fattr->cf_dtype = DT_LNK;
33142 + } else if (fattr->cf_cifsattrs & ATTR_DIRECTORY) {
33143 +@@ -735,6 +766,11 @@ cifs_all_info_to_fattr(struct cifs_fattr *fattr, FILE_ALL_INFO *info,
33144 + }
33145 + }
33146 +
33147 ++ if (S_ISLNK(fattr->cf_mode)) {
33148 ++ fattr->cf_symlink_target = data->symlink_target;
33149 ++ data->symlink_target = NULL;
33150 ++ }
33151 ++
33152 + fattr->cf_uid = cifs_sb->ctx->linux_uid;
33153 + fattr->cf_gid = cifs_sb->ctx->linux_gid;
33154 + }
33155 +@@ -744,23 +780,28 @@ cifs_get_file_info(struct file *filp)
33156 + {
33157 + int rc;
33158 + unsigned int xid;
33159 +- FILE_ALL_INFO find_data;
33160 ++ struct cifs_open_info_data data = {};
33161 + struct cifs_fattr fattr;
33162 + struct inode *inode = file_inode(filp);
33163 + struct cifsFileInfo *cfile = filp->private_data;
33164 + struct cifs_tcon *tcon = tlink_tcon(cfile->tlink);
33165 + struct TCP_Server_Info *server = tcon->ses->server;
33166 ++ bool symlink = false;
33167 ++ u32 tag = 0;
33168 +
33169 + if (!server->ops->query_file_info)
33170 + return -ENOSYS;
33171 +
33172 + xid = get_xid();
33173 +- rc = server->ops->query_file_info(xid, tcon, &cfile->fid, &find_data);
33174 ++ rc = server->ops->query_file_info(xid, tcon, cfile, &data);
33175 + switch (rc) {
33176 + case 0:
33177 + /* TODO: add support to query reparse tag */
33178 +- cifs_all_info_to_fattr(&fattr, &find_data, inode->i_sb, false,
33179 +- false, 0 /* no reparse tag */);
33180 ++ if (data.symlink_target) {
33181 ++ symlink = true;
33182 ++ tag = IO_REPARSE_TAG_SYMLINK;
33183 ++ }
33184 ++ cifs_open_info_to_fattr(&fattr, &data, inode->i_sb, false, symlink, tag);
33185 + break;
33186 + case -EREMOTE:
33187 + cifs_create_dfs_fattr(&fattr, inode->i_sb);
33188 +@@ -789,6 +830,7 @@ cifs_get_file_info(struct file *filp)
33189 + /* if filetype is different, return error */
33190 + rc = cifs_fattr_to_inode(inode, &fattr);
33191 + cgfi_exit:
33192 ++ cifs_free_open_info(&data);
33193 + free_xid(xid);
33194 + return rc;
33195 + }
33196 +@@ -860,14 +902,9 @@ cifs_backup_query_path_info(int xid,
33197 + }
33198 + #endif /* CONFIG_CIFS_ALLOW_INSECURE_LEGACY */
33199 +
33200 +-static void
33201 +-cifs_set_fattr_ino(int xid,
33202 +- struct cifs_tcon *tcon,
33203 +- struct super_block *sb,
33204 +- struct inode **inode,
33205 +- const char *full_path,
33206 +- FILE_ALL_INFO *data,
33207 +- struct cifs_fattr *fattr)
33208 ++static void cifs_set_fattr_ino(int xid, struct cifs_tcon *tcon, struct super_block *sb,
33209 ++ struct inode **inode, const char *full_path,
33210 ++ struct cifs_open_info_data *data, struct cifs_fattr *fattr)
33211 + {
33212 + struct cifs_sb_info *cifs_sb = CIFS_SB(sb);
33213 + struct TCP_Server_Info *server = tcon->ses->server;
33214 +@@ -885,11 +922,8 @@ cifs_set_fattr_ino(int xid,
33215 + * If we have an inode pass a NULL tcon to ensure we don't
33216 + * make a round trip to the server. This only works for SMB2+.
33217 + */
33218 +- rc = server->ops->get_srv_inum(xid,
33219 +- *inode ? NULL : tcon,
33220 +- cifs_sb, full_path,
33221 +- &fattr->cf_uniqueid,
33222 +- data);
33223 ++ rc = server->ops->get_srv_inum(xid, *inode ? NULL : tcon, cifs_sb, full_path,
33224 ++ &fattr->cf_uniqueid, data);
33225 + if (rc) {
33226 + /*
33227 + * If that fails reuse existing ino or generate one
33228 +@@ -923,14 +957,10 @@ static inline bool is_inode_cache_good(struct inode *ino)
33229 + return ino && CIFS_CACHE_READ(CIFS_I(ino)) && CIFS_I(ino)->time != 0;
33230 + }
33231 +
33232 +-int
33233 +-cifs_get_inode_info(struct inode **inode,
33234 +- const char *full_path,
33235 +- FILE_ALL_INFO *in_data,
33236 +- struct super_block *sb, int xid,
33237 +- const struct cifs_fid *fid)
33238 ++int cifs_get_inode_info(struct inode **inode, const char *full_path,
33239 ++ struct cifs_open_info_data *data, struct super_block *sb, int xid,
33240 ++ const struct cifs_fid *fid)
33241 + {
33242 +-
33243 + struct cifs_tcon *tcon;
33244 + struct TCP_Server_Info *server;
33245 + struct tcon_link *tlink;
33246 +@@ -938,8 +968,7 @@ cifs_get_inode_info(struct inode **inode,
33247 + bool adjust_tz = false;
33248 + struct cifs_fattr fattr = {0};
33249 + bool is_reparse_point = false;
33250 +- FILE_ALL_INFO *data = in_data;
33251 +- FILE_ALL_INFO *tmp_data = NULL;
33252 ++ struct cifs_open_info_data tmp_data = {};
33253 + void *smb1_backup_rsp_buf = NULL;
33254 + int rc = 0;
33255 + int tmprc = 0;
33256 +@@ -960,21 +989,15 @@ cifs_get_inode_info(struct inode **inode,
33257 + cifs_dbg(FYI, "No need to revalidate cached inode sizes\n");
33258 + goto out;
33259 + }
33260 +- tmp_data = kmalloc(sizeof(FILE_ALL_INFO), GFP_KERNEL);
33261 +- if (!tmp_data) {
33262 +- rc = -ENOMEM;
33263 +- goto out;
33264 +- }
33265 +- rc = server->ops->query_path_info(xid, tcon, cifs_sb,
33266 +- full_path, tmp_data,
33267 +- &adjust_tz, &is_reparse_point);
33268 ++ rc = server->ops->query_path_info(xid, tcon, cifs_sb, full_path, &tmp_data,
33269 ++ &adjust_tz, &is_reparse_point);
33270 + #ifdef CONFIG_CIFS_DFS_UPCALL
33271 + if (rc == -ENOENT && is_tcon_dfs(tcon))
33272 + rc = cifs_dfs_query_info_nonascii_quirk(xid, tcon,
33273 + cifs_sb,
33274 + full_path);
33275 + #endif
33276 +- data = tmp_data;
33277 ++ data = &tmp_data;
33278 + }
33279 +
33280 + /*
33281 +@@ -988,14 +1011,24 @@ cifs_get_inode_info(struct inode **inode,
33282 + * since we have to check if its reparse tag matches a known
33283 + * special file type e.g. symlink or fifo or char etc.
33284 + */
33285 +- if ((le32_to_cpu(data->Attributes) & ATTR_REPARSE) &&
33286 +- server->ops->query_reparse_tag) {
33287 +- rc = server->ops->query_reparse_tag(xid, tcon, cifs_sb,
33288 +- full_path, &reparse_tag);
33289 +- cifs_dbg(FYI, "reparse tag 0x%x\n", reparse_tag);
33290 ++ if (is_reparse_point && data->symlink_target) {
33291 ++ reparse_tag = IO_REPARSE_TAG_SYMLINK;
33292 ++ } else if ((le32_to_cpu(data->fi.Attributes) & ATTR_REPARSE) &&
33293 ++ server->ops->query_reparse_tag) {
33294 ++ tmprc = server->ops->query_reparse_tag(xid, tcon, cifs_sb, full_path,
33295 ++ &reparse_tag);
33296 ++ if (tmprc)
33297 ++ cifs_dbg(FYI, "%s: query_reparse_tag: rc = %d\n", __func__, tmprc);
33298 ++ if (server->ops->query_symlink) {
33299 ++ tmprc = server->ops->query_symlink(xid, tcon, cifs_sb, full_path,
33300 ++ &data->symlink_target,
33301 ++ is_reparse_point);
33302 ++ if (tmprc)
33303 ++ cifs_dbg(FYI, "%s: query_symlink: rc = %d\n", __func__,
33304 ++ tmprc);
33305 ++ }
33306 + }
33307 +- cifs_all_info_to_fattr(&fattr, data, sb, adjust_tz,
33308 +- is_reparse_point, reparse_tag);
33309 ++ cifs_open_info_to_fattr(&fattr, data, sb, adjust_tz, is_reparse_point, reparse_tag);
33310 + break;
33311 + case -EREMOTE:
33312 + /* DFS link, no metadata available on this server */
33313 +@@ -1014,18 +1047,20 @@ cifs_get_inode_info(struct inode **inode,
33314 + */
33315 + if (backup_cred(cifs_sb) && is_smb1_server(server)) {
33316 + /* for easier reading */
33317 ++ FILE_ALL_INFO *fi;
33318 + FILE_DIRECTORY_INFO *fdi;
33319 + SEARCH_ID_FULL_DIR_INFO *si;
33320 +
33321 + rc = cifs_backup_query_path_info(xid, tcon, sb,
33322 + full_path,
33323 + &smb1_backup_rsp_buf,
33324 +- &data);
33325 ++ &fi);
33326 + if (rc)
33327 + goto out;
33328 +
33329 +- fdi = (FILE_DIRECTORY_INFO *)data;
33330 +- si = (SEARCH_ID_FULL_DIR_INFO *)data;
33331 ++ move_cifs_info_to_smb2(&data->fi, fi);
33332 ++ fdi = (FILE_DIRECTORY_INFO *)fi;
33333 ++ si = (SEARCH_ID_FULL_DIR_INFO *)fi;
33334 +
33335 + cifs_dir_info_to_fattr(&fattr, fdi, cifs_sb);
33336 + fattr.cf_uniqueid = le64_to_cpu(si->UniqueId);
33337 +@@ -1123,7 +1158,8 @@ handle_mnt_opt:
33338 + out:
33339 + cifs_buf_release(smb1_backup_rsp_buf);
33340 + cifs_put_tlink(tlink);
33341 +- kfree(tmp_data);
33342 ++ cifs_free_open_info(&tmp_data);
33343 ++ kfree(fattr.cf_symlink_target);
33344 + return rc;
33345 + }
33346 +
33347 +@@ -1138,7 +1174,7 @@ smb311_posix_get_inode_info(struct inode **inode,
33348 + bool adjust_tz = false;
33349 + struct cifs_fattr fattr = {0};
33350 + bool symlink = false;
33351 +- struct smb311_posix_qinfo *data = NULL;
33352 ++ struct cifs_open_info_data data = {};
33353 + int rc = 0;
33354 + int tmprc = 0;
33355 +
33356 +@@ -1155,15 +1191,9 @@ smb311_posix_get_inode_info(struct inode **inode,
33357 + cifs_dbg(FYI, "No need to revalidate cached inode sizes\n");
33358 + goto out;
33359 + }
33360 +- data = kmalloc(sizeof(struct smb311_posix_qinfo), GFP_KERNEL);
33361 +- if (!data) {
33362 +- rc = -ENOMEM;
33363 +- goto out;
33364 +- }
33365 +
33366 +- rc = smb311_posix_query_path_info(xid, tcon, cifs_sb,
33367 +- full_path, data,
33368 +- &adjust_tz, &symlink);
33369 ++ rc = smb311_posix_query_path_info(xid, tcon, cifs_sb, full_path, &data, &adjust_tz,
33370 ++ &symlink);
33371 +
33372 + /*
33373 + * 2. Convert it to internal cifs metadata (fattr)
33374 +@@ -1171,7 +1201,7 @@ smb311_posix_get_inode_info(struct inode **inode,
33375 +
33376 + switch (rc) {
33377 + case 0:
33378 +- smb311_posix_info_to_fattr(&fattr, data, sb, adjust_tz, symlink);
33379 ++ smb311_posix_info_to_fattr(&fattr, &data, sb, adjust_tz, symlink);
33380 + break;
33381 + case -EREMOTE:
33382 + /* DFS link, no metadata available on this server */
33383 +@@ -1228,7 +1258,8 @@ smb311_posix_get_inode_info(struct inode **inode,
33384 + }
33385 + out:
33386 + cifs_put_tlink(tlink);
33387 +- kfree(data);
33388 ++ cifs_free_open_info(&data);
33389 ++ kfree(fattr.cf_symlink_target);
33390 + return rc;
33391 + }
33392 +
33393 +diff --git a/fs/cifs/link.c b/fs/cifs/link.c
33394 +index 6803cb27eecc3..8042dbdd182bc 100644
33395 +--- a/fs/cifs/link.c
33396 ++++ b/fs/cifs/link.c
33397 +@@ -202,40 +202,6 @@ out:
33398 + return rc;
33399 + }
33400 +
33401 +-static int
33402 +-query_mf_symlink(const unsigned int xid, struct cifs_tcon *tcon,
33403 +- struct cifs_sb_info *cifs_sb, const unsigned char *path,
33404 +- char **symlinkinfo)
33405 +-{
33406 +- int rc;
33407 +- u8 *buf = NULL;
33408 +- unsigned int link_len = 0;
33409 +- unsigned int bytes_read = 0;
33410 +-
33411 +- buf = kmalloc(CIFS_MF_SYMLINK_FILE_SIZE, GFP_KERNEL);
33412 +- if (!buf)
33413 +- return -ENOMEM;
33414 +-
33415 +- if (tcon->ses->server->ops->query_mf_symlink)
33416 +- rc = tcon->ses->server->ops->query_mf_symlink(xid, tcon,
33417 +- cifs_sb, path, buf, &bytes_read);
33418 +- else
33419 +- rc = -ENOSYS;
33420 +-
33421 +- if (rc)
33422 +- goto out;
33423 +-
33424 +- if (bytes_read == 0) { /* not a symlink */
33425 +- rc = -EINVAL;
33426 +- goto out;
33427 +- }
33428 +-
33429 +- rc = parse_mf_symlink(buf, bytes_read, &link_len, symlinkinfo);
33430 +-out:
33431 +- kfree(buf);
33432 +- return rc;
33433 +-}
33434 +-
33435 + int
33436 + check_mf_symlink(unsigned int xid, struct cifs_tcon *tcon,
33437 + struct cifs_sb_info *cifs_sb, struct cifs_fattr *fattr,
33438 +@@ -245,6 +211,7 @@ check_mf_symlink(unsigned int xid, struct cifs_tcon *tcon,
33439 + u8 *buf = NULL;
33440 + unsigned int link_len = 0;
33441 + unsigned int bytes_read = 0;
33442 ++ char *symlink = NULL;
33443 +
33444 + if (!couldbe_mf_symlink(fattr))
33445 + /* it's not a symlink */
33446 +@@ -266,7 +233,7 @@ check_mf_symlink(unsigned int xid, struct cifs_tcon *tcon,
33447 + if (bytes_read == 0) /* not a symlink */
33448 + goto out;
33449 +
33450 +- rc = parse_mf_symlink(buf, bytes_read, &link_len, NULL);
33451 ++ rc = parse_mf_symlink(buf, bytes_read, &link_len, &symlink);
33452 + if (rc == -EINVAL) {
33453 + /* it's not a symlink */
33454 + rc = 0;
33455 +@@ -281,6 +248,7 @@ check_mf_symlink(unsigned int xid, struct cifs_tcon *tcon,
33456 + fattr->cf_mode &= ~S_IFMT;
33457 + fattr->cf_mode |= S_IFLNK | S_IRWXU | S_IRWXG | S_IRWXO;
33458 + fattr->cf_dtype = DT_LNK;
33459 ++ fattr->cf_symlink_target = symlink;
33460 + out:
33461 + kfree(buf);
33462 + return rc;
33463 +@@ -600,75 +568,6 @@ cifs_hl_exit:
33464 + return rc;
33465 + }
33466 +
33467 +-const char *
33468 +-cifs_get_link(struct dentry *direntry, struct inode *inode,
33469 +- struct delayed_call *done)
33470 +-{
33471 +- int rc = -ENOMEM;
33472 +- unsigned int xid;
33473 +- const char *full_path;
33474 +- void *page;
33475 +- char *target_path = NULL;
33476 +- struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
33477 +- struct tcon_link *tlink = NULL;
33478 +- struct cifs_tcon *tcon;
33479 +- struct TCP_Server_Info *server;
33480 +-
33481 +- if (!direntry)
33482 +- return ERR_PTR(-ECHILD);
33483 +-
33484 +- xid = get_xid();
33485 +-
33486 +- tlink = cifs_sb_tlink(cifs_sb);
33487 +- if (IS_ERR(tlink)) {
33488 +- free_xid(xid);
33489 +- return ERR_CAST(tlink);
33490 +- }
33491 +- tcon = tlink_tcon(tlink);
33492 +- server = tcon->ses->server;
33493 +-
33494 +- page = alloc_dentry_path();
33495 +- full_path = build_path_from_dentry(direntry, page);
33496 +- if (IS_ERR(full_path)) {
33497 +- free_xid(xid);
33498 +- cifs_put_tlink(tlink);
33499 +- free_dentry_path(page);
33500 +- return ERR_CAST(full_path);
33501 +- }
33502 +-
33503 +- cifs_dbg(FYI, "Full path: %s inode = 0x%p\n", full_path, inode);
33504 +-
33505 +- rc = -EACCES;
33506 +- /*
33507 +- * First try Minshall+French Symlinks, if configured
33508 +- * and fallback to UNIX Extensions Symlinks.
33509 +- */
33510 +- if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MF_SYMLINKS)
33511 +- rc = query_mf_symlink(xid, tcon, cifs_sb, full_path,
33512 +- &target_path);
33513 +-
33514 +- if (rc != 0 && server->ops->query_symlink) {
33515 +- struct cifsInodeInfo *cifsi = CIFS_I(inode);
33516 +- bool reparse_point = false;
33517 +-
33518 +- if (cifsi->cifsAttrs & ATTR_REPARSE)
33519 +- reparse_point = true;
33520 +-
33521 +- rc = server->ops->query_symlink(xid, tcon, cifs_sb, full_path,
33522 +- &target_path, reparse_point);
33523 +- }
33524 +-
33525 +- free_dentry_path(page);
33526 +- free_xid(xid);
33527 +- cifs_put_tlink(tlink);
33528 +- if (rc != 0) {
33529 +- kfree(target_path);
33530 +- return ERR_PTR(rc);
33531 +- }
33532 +- set_delayed_call(done, kfree_link, target_path);
33533 +- return target_path;
33534 +-}
33535 +-
33536 + int
33537 + cifs_symlink(struct user_namespace *mnt_userns, struct inode *inode,
33538 + struct dentry *direntry, const char *symname)
33539 +diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
33540 +index 35085fa866367..1efb5ca9fd804 100644
33541 +--- a/fs/cifs/misc.c
33542 ++++ b/fs/cifs/misc.c
33543 +@@ -1123,7 +1123,7 @@ cifs_alloc_hash(const char *name,
33544 + void
33545 + cifs_free_hash(struct crypto_shash **shash, struct sdesc **sdesc)
33546 + {
33547 +- kfree(*sdesc);
33548 ++ kfree_sensitive(*sdesc);
33549 + *sdesc = NULL;
33550 + if (*shash)
33551 + crypto_free_shash(*shash);
33552 +@@ -1137,8 +1137,8 @@ cifs_free_hash(struct crypto_shash **shash, struct sdesc **sdesc)
33553 + * @len: Where to store the length for this page:
33554 + * @offset: Where to store the offset for this page
33555 + */
33556 +-void rqst_page_get_length(struct smb_rqst *rqst, unsigned int page,
33557 +- unsigned int *len, unsigned int *offset)
33558 ++void rqst_page_get_length(const struct smb_rqst *rqst, unsigned int page,
33559 ++ unsigned int *len, unsigned int *offset)
33560 + {
33561 + *len = rqst->rq_pagesz;
33562 + *offset = (page == 0) ? rqst->rq_offset : 0;
33563 +diff --git a/fs/cifs/readdir.c b/fs/cifs/readdir.c
33564 +index 8e060c00c9690..6a78bcc51e816 100644
33565 +--- a/fs/cifs/readdir.c
33566 ++++ b/fs/cifs/readdir.c
33567 +@@ -994,6 +994,8 @@ static int cifs_filldir(char *find_entry, struct file *file,
33568 + cifs_unix_basic_to_fattr(&fattr,
33569 + &((FILE_UNIX_INFO *)find_entry)->basic,
33570 + cifs_sb);
33571 ++ if (S_ISLNK(fattr.cf_mode))
33572 ++ fattr.cf_flags |= CIFS_FATTR_NEED_REVAL;
33573 + break;
33574 + case SMB_FIND_FILE_INFO_STANDARD:
33575 + cifs_std_info_to_fattr(&fattr,
33576 +diff --git a/fs/cifs/sess.c b/fs/cifs/sess.c
33577 +index 6a85136da27ce..5d93154572c01 100644
33578 +--- a/fs/cifs/sess.c
33579 ++++ b/fs/cifs/sess.c
33580 +@@ -1214,10 +1214,18 @@ out_free_smb_buf:
33581 + static void
33582 + sess_free_buffer(struct sess_data *sess_data)
33583 + {
33584 ++ struct kvec *iov = sess_data->iov;
33585 +
33586 +- free_rsp_buf(sess_data->buf0_type, sess_data->iov[0].iov_base);
33587 ++ /*
33588 ++ * Zero the session data before freeing, as it might contain sensitive info (keys, etc).
33589 ++ * Note that iov[1] is already freed by caller.
33590 ++ */
33591 ++ if (sess_data->buf0_type != CIFS_NO_BUFFER && iov[0].iov_base)
33592 ++ memzero_explicit(iov[0].iov_base, iov[0].iov_len);
33593 ++
33594 ++ free_rsp_buf(sess_data->buf0_type, iov[0].iov_base);
33595 + sess_data->buf0_type = CIFS_NO_BUFFER;
33596 +- kfree(sess_data->iov[2].iov_base);
33597 ++ kfree_sensitive(iov[2].iov_base);
33598 + }
33599 +
33600 + static int
33601 +@@ -1375,7 +1383,7 @@ out:
33602 + sess_data->result = rc;
33603 + sess_data->func = NULL;
33604 + sess_free_buffer(sess_data);
33605 +- kfree(ses->auth_key.response);
33606 ++ kfree_sensitive(ses->auth_key.response);
33607 + ses->auth_key.response = NULL;
33608 + }
33609 +
33610 +@@ -1514,7 +1522,7 @@ out:
33611 + sess_data->result = rc;
33612 + sess_data->func = NULL;
33613 + sess_free_buffer(sess_data);
33614 +- kfree(ses->auth_key.response);
33615 ++ kfree_sensitive(ses->auth_key.response);
33616 + ses->auth_key.response = NULL;
33617 + }
33618 +
33619 +@@ -1649,7 +1657,7 @@ sess_auth_rawntlmssp_negotiate(struct sess_data *sess_data)
33620 + rc = decode_ntlmssp_challenge(bcc_ptr, blob_len, ses);
33621 +
33622 + out_free_ntlmsspblob:
33623 +- kfree(ntlmsspblob);
33624 ++ kfree_sensitive(ntlmsspblob);
33625 + out:
33626 + sess_free_buffer(sess_data);
33627 +
33628 +@@ -1659,9 +1667,9 @@ out:
33629 + }
33630 +
33631 + /* Else error. Cleanup */
33632 +- kfree(ses->auth_key.response);
33633 ++ kfree_sensitive(ses->auth_key.response);
33634 + ses->auth_key.response = NULL;
33635 +- kfree(ses->ntlmssp);
33636 ++ kfree_sensitive(ses->ntlmssp);
33637 + ses->ntlmssp = NULL;
33638 +
33639 + sess_data->func = NULL;
33640 +@@ -1760,7 +1768,7 @@ sess_auth_rawntlmssp_authenticate(struct sess_data *sess_data)
33641 + }
33642 +
33643 + out_free_ntlmsspblob:
33644 +- kfree(ntlmsspblob);
33645 ++ kfree_sensitive(ntlmsspblob);
33646 + out:
33647 + sess_free_buffer(sess_data);
33648 +
33649 +@@ -1768,9 +1776,9 @@ out:
33650 + rc = sess_establish_session(sess_data);
33651 +
33652 + /* Cleanup */
33653 +- kfree(ses->auth_key.response);
33654 ++ kfree_sensitive(ses->auth_key.response);
33655 + ses->auth_key.response = NULL;
33656 +- kfree(ses->ntlmssp);
33657 ++ kfree_sensitive(ses->ntlmssp);
33658 + ses->ntlmssp = NULL;
33659 +
33660 + sess_data->func = NULL;
33661 +@@ -1846,7 +1854,7 @@ int CIFS_SessSetup(const unsigned int xid, struct cifs_ses *ses,
33662 + rc = sess_data->result;
33663 +
33664 + out:
33665 +- kfree(sess_data);
33666 ++ kfree_sensitive(sess_data);
33667 + return rc;
33668 + }
33669 + #endif /* CONFIG_CIFS_ALLOW_INSECURE_LEGACY */
33670 +diff --git a/fs/cifs/smb1ops.c b/fs/cifs/smb1ops.c
33671 +index f36b2d2d40ca3..50480751e521c 100644
33672 +--- a/fs/cifs/smb1ops.c
33673 ++++ b/fs/cifs/smb1ops.c
33674 +@@ -542,31 +542,32 @@ cifs_is_path_accessible(const unsigned int xid, struct cifs_tcon *tcon,
33675 + return rc;
33676 + }
33677 +
33678 +-static int
33679 +-cifs_query_path_info(const unsigned int xid, struct cifs_tcon *tcon,
33680 +- struct cifs_sb_info *cifs_sb, const char *full_path,
33681 +- FILE_ALL_INFO *data, bool *adjustTZ, bool *symlink)
33682 ++static int cifs_query_path_info(const unsigned int xid, struct cifs_tcon *tcon,
33683 ++ struct cifs_sb_info *cifs_sb, const char *full_path,
33684 ++ struct cifs_open_info_data *data, bool *adjustTZ, bool *symlink)
33685 + {
33686 + int rc;
33687 ++ FILE_ALL_INFO fi = {};
33688 +
33689 + *symlink = false;
33690 +
33691 + /* could do find first instead but this returns more info */
33692 +- rc = CIFSSMBQPathInfo(xid, tcon, full_path, data, 0 /* not legacy */,
33693 +- cifs_sb->local_nls, cifs_remap(cifs_sb));
33694 ++ rc = CIFSSMBQPathInfo(xid, tcon, full_path, &fi, 0 /* not legacy */, cifs_sb->local_nls,
33695 ++ cifs_remap(cifs_sb));
33696 + /*
33697 + * BB optimize code so we do not make the above call when server claims
33698 + * no NT SMB support and the above call failed at least once - set flag
33699 + * in tcon or mount.
33700 + */
33701 + if ((rc == -EOPNOTSUPP) || (rc == -EINVAL)) {
33702 +- rc = SMBQueryInformation(xid, tcon, full_path, data,
33703 +- cifs_sb->local_nls,
33704 ++ rc = SMBQueryInformation(xid, tcon, full_path, &fi, cifs_sb->local_nls,
33705 + cifs_remap(cifs_sb));
33706 ++ if (!rc)
33707 ++ move_cifs_info_to_smb2(&data->fi, &fi);
33708 + *adjustTZ = true;
33709 + }
33710 +
33711 +- if (!rc && (le32_to_cpu(data->Attributes) & ATTR_REPARSE)) {
33712 ++ if (!rc && (le32_to_cpu(fi.Attributes) & ATTR_REPARSE)) {
33713 + int tmprc;
33714 + int oplock = 0;
33715 + struct cifs_fid fid;
33716 +@@ -592,10 +593,9 @@ cifs_query_path_info(const unsigned int xid, struct cifs_tcon *tcon,
33717 + return rc;
33718 + }
33719 +
33720 +-static int
33721 +-cifs_get_srv_inum(const unsigned int xid, struct cifs_tcon *tcon,
33722 +- struct cifs_sb_info *cifs_sb, const char *full_path,
33723 +- u64 *uniqueid, FILE_ALL_INFO *data)
33724 ++static int cifs_get_srv_inum(const unsigned int xid, struct cifs_tcon *tcon,
33725 ++ struct cifs_sb_info *cifs_sb, const char *full_path,
33726 ++ u64 *uniqueid, struct cifs_open_info_data *unused)
33727 + {
33728 + /*
33729 + * We can not use the IndexNumber field by default from Windows or
33730 +@@ -613,11 +613,22 @@ cifs_get_srv_inum(const unsigned int xid, struct cifs_tcon *tcon,
33731 + cifs_remap(cifs_sb));
33732 + }
33733 +
33734 +-static int
33735 +-cifs_query_file_info(const unsigned int xid, struct cifs_tcon *tcon,
33736 +- struct cifs_fid *fid, FILE_ALL_INFO *data)
33737 ++static int cifs_query_file_info(const unsigned int xid, struct cifs_tcon *tcon,
33738 ++ struct cifsFileInfo *cfile, struct cifs_open_info_data *data)
33739 + {
33740 +- return CIFSSMBQFileInfo(xid, tcon, fid->netfid, data);
33741 ++ int rc;
33742 ++ FILE_ALL_INFO fi = {};
33743 ++
33744 ++ if (cfile->symlink_target) {
33745 ++ data->symlink_target = kstrdup(cfile->symlink_target, GFP_KERNEL);
33746 ++ if (!data->symlink_target)
33747 ++ return -ENOMEM;
33748 ++ }
33749 ++
33750 ++ rc = CIFSSMBQFileInfo(xid, tcon, cfile->fid.netfid, &fi);
33751 ++ if (!rc)
33752 ++ move_cifs_info_to_smb2(&data->fi, &fi);
33753 ++ return rc;
33754 + }
33755 +
33756 + static void
33757 +@@ -702,19 +713,20 @@ cifs_mkdir_setinfo(struct inode *inode, const char *full_path,
33758 + cifsInode->cifsAttrs = dosattrs;
33759 + }
33760 +
33761 +-static int
33762 +-cifs_open_file(const unsigned int xid, struct cifs_open_parms *oparms,
33763 +- __u32 *oplock, FILE_ALL_INFO *buf)
33764 ++static int cifs_open_file(const unsigned int xid, struct cifs_open_parms *oparms, __u32 *oplock,
33765 ++ void *buf)
33766 + {
33767 ++ FILE_ALL_INFO *fi = buf;
33768 ++
33769 + if (!(oparms->tcon->ses->capabilities & CAP_NT_SMBS))
33770 + return SMBLegacyOpen(xid, oparms->tcon, oparms->path,
33771 + oparms->disposition,
33772 + oparms->desired_access,
33773 + oparms->create_options,
33774 +- &oparms->fid->netfid, oplock, buf,
33775 ++ &oparms->fid->netfid, oplock, fi,
33776 + oparms->cifs_sb->local_nls,
33777 + cifs_remap(oparms->cifs_sb));
33778 +- return CIFS_open(xid, oparms, oplock, buf);
33779 ++ return CIFS_open(xid, oparms, oplock, fi);
33780 + }
33781 +
33782 + static void
33783 +diff --git a/fs/cifs/smb2file.c b/fs/cifs/smb2file.c
33784 +index 9dfd2dd612c25..4992b43616a7a 100644
33785 +--- a/fs/cifs/smb2file.c
33786 ++++ b/fs/cifs/smb2file.c
33787 +@@ -20,40 +20,125 @@
33788 + #include "cifs_unicode.h"
33789 + #include "fscache.h"
33790 + #include "smb2proto.h"
33791 ++#include "smb2status.h"
33792 +
33793 +-int
33794 +-smb2_open_file(const unsigned int xid, struct cifs_open_parms *oparms,
33795 +- __u32 *oplock, FILE_ALL_INFO *buf)
33796 ++static struct smb2_symlink_err_rsp *symlink_data(const struct kvec *iov)
33797 ++{
33798 ++ struct smb2_err_rsp *err = iov->iov_base;
33799 ++ struct smb2_symlink_err_rsp *sym = ERR_PTR(-EINVAL);
33800 ++ u32 len;
33801 ++
33802 ++ if (err->ErrorContextCount) {
33803 ++ struct smb2_error_context_rsp *p, *end;
33804 ++
33805 ++ len = (u32)err->ErrorContextCount * (offsetof(struct smb2_error_context_rsp,
33806 ++ ErrorContextData) +
33807 ++ sizeof(struct smb2_symlink_err_rsp));
33808 ++ if (le32_to_cpu(err->ByteCount) < len || iov->iov_len < len + sizeof(*err))
33809 ++ return ERR_PTR(-EINVAL);
33810 ++
33811 ++ p = (struct smb2_error_context_rsp *)err->ErrorData;
33812 ++ end = (struct smb2_error_context_rsp *)((u8 *)err + iov->iov_len);
33813 ++ do {
33814 ++ if (le32_to_cpu(p->ErrorId) == SMB2_ERROR_ID_DEFAULT) {
33815 ++ sym = (struct smb2_symlink_err_rsp *)&p->ErrorContextData;
33816 ++ break;
33817 ++ }
33818 ++ cifs_dbg(FYI, "%s: skipping unhandled error context: 0x%x\n",
33819 ++ __func__, le32_to_cpu(p->ErrorId));
33820 ++
33821 ++ len = ALIGN(le32_to_cpu(p->ErrorDataLength), 8);
33822 ++ p = (struct smb2_error_context_rsp *)((u8 *)&p->ErrorContextData + len);
33823 ++ } while (p < end);
33824 ++ } else if (le32_to_cpu(err->ByteCount) >= sizeof(*sym) &&
33825 ++ iov->iov_len >= SMB2_SYMLINK_STRUCT_SIZE) {
33826 ++ sym = (struct smb2_symlink_err_rsp *)err->ErrorData;
33827 ++ }
33828 ++
33829 ++ if (!IS_ERR(sym) && (le32_to_cpu(sym->SymLinkErrorTag) != SYMLINK_ERROR_TAG ||
33830 ++ le32_to_cpu(sym->ReparseTag) != IO_REPARSE_TAG_SYMLINK))
33831 ++ sym = ERR_PTR(-EINVAL);
33832 ++
33833 ++ return sym;
33834 ++}
33835 ++
33836 ++int smb2_parse_symlink_response(struct cifs_sb_info *cifs_sb, const struct kvec *iov, char **path)
33837 ++{
33838 ++ struct smb2_symlink_err_rsp *sym;
33839 ++ unsigned int sub_offs, sub_len;
33840 ++ unsigned int print_offs, print_len;
33841 ++ char *s;
33842 ++
33843 ++ if (!cifs_sb || !iov || !iov->iov_base || !iov->iov_len || !path)
33844 ++ return -EINVAL;
33845 ++
33846 ++ sym = symlink_data(iov);
33847 ++ if (IS_ERR(sym))
33848 ++ return PTR_ERR(sym);
33849 ++
33850 ++ sub_len = le16_to_cpu(sym->SubstituteNameLength);
33851 ++ sub_offs = le16_to_cpu(sym->SubstituteNameOffset);
33852 ++ print_len = le16_to_cpu(sym->PrintNameLength);
33853 ++ print_offs = le16_to_cpu(sym->PrintNameOffset);
33854 ++
33855 ++ if (iov->iov_len < SMB2_SYMLINK_STRUCT_SIZE + sub_offs + sub_len ||
33856 ++ iov->iov_len < SMB2_SYMLINK_STRUCT_SIZE + print_offs + print_len)
33857 ++ return -EINVAL;
33858 ++
33859 ++ s = cifs_strndup_from_utf16((char *)sym->PathBuffer + sub_offs, sub_len, true,
33860 ++ cifs_sb->local_nls);
33861 ++ if (!s)
33862 ++ return -ENOMEM;
33863 ++ convert_delimiter(s, '/');
33864 ++ cifs_dbg(FYI, "%s: symlink target: %s\n", __func__, s);
33865 ++
33866 ++ *path = s;
33867 ++ return 0;
33868 ++}
33869 ++
33870 ++int smb2_open_file(const unsigned int xid, struct cifs_open_parms *oparms, __u32 *oplock, void *buf)
33871 + {
33872 + int rc;
33873 + __le16 *smb2_path;
33874 +- struct smb2_file_all_info *smb2_data = NULL;
33875 + __u8 smb2_oplock;
33876 ++ struct cifs_open_info_data *data = buf;
33877 ++ struct smb2_file_all_info file_info = {};
33878 ++ struct smb2_file_all_info *smb2_data = data ? &file_info : NULL;
33879 ++ struct kvec err_iov = {};
33880 ++ int err_buftype = CIFS_NO_BUFFER;
33881 + struct cifs_fid *fid = oparms->fid;
33882 + struct network_resiliency_req nr_ioctl_req;
33883 +
33884 + smb2_path = cifs_convert_path_to_utf16(oparms->path, oparms->cifs_sb);
33885 +- if (smb2_path == NULL) {
33886 +- rc = -ENOMEM;
33887 +- goto out;
33888 +- }
33889 +-
33890 +- smb2_data = kzalloc(sizeof(struct smb2_file_all_info) + PATH_MAX * 2,
33891 +- GFP_KERNEL);
33892 +- if (smb2_data == NULL) {
33893 +- rc = -ENOMEM;
33894 +- goto out;
33895 +- }
33896 ++ if (smb2_path == NULL)
33897 ++ return -ENOMEM;
33898 +
33899 + oparms->desired_access |= FILE_READ_ATTRIBUTES;
33900 + smb2_oplock = SMB2_OPLOCK_LEVEL_BATCH;
33901 +
33902 +- rc = SMB2_open(xid, oparms, smb2_path, &smb2_oplock, smb2_data, NULL,
33903 +- NULL, NULL);
33904 ++ rc = SMB2_open(xid, oparms, smb2_path, &smb2_oplock, smb2_data, NULL, &err_iov,
33905 ++ &err_buftype);
33906 ++ if (rc && data) {
33907 ++ struct smb2_hdr *hdr = err_iov.iov_base;
33908 ++
33909 ++ if (unlikely(!err_iov.iov_base || err_buftype == CIFS_NO_BUFFER))
33910 ++ rc = -ENOMEM;
33911 ++ else if (hdr->Status == STATUS_STOPPED_ON_SYMLINK && oparms->cifs_sb) {
33912 ++ rc = smb2_parse_symlink_response(oparms->cifs_sb, &err_iov,
33913 ++ &data->symlink_target);
33914 ++ if (!rc) {
33915 ++ memset(smb2_data, 0, sizeof(*smb2_data));
33916 ++ oparms->create_options |= OPEN_REPARSE_POINT;
33917 ++ rc = SMB2_open(xid, oparms, smb2_path, &smb2_oplock, smb2_data,
33918 ++ NULL, NULL, NULL);
33919 ++ oparms->create_options &= ~OPEN_REPARSE_POINT;
33920 ++ }
33921 ++ }
33922 ++ }
33923 ++
33924 + if (rc)
33925 + goto out;
33926 +
33927 +-
33928 + if (oparms->tcon->use_resilient) {
33929 + /* default timeout is 0, servers pick default (120 seconds) */
33930 + nr_ioctl_req.Timeout =
33931 +@@ -73,7 +158,7 @@ smb2_open_file(const unsigned int xid, struct cifs_open_parms *oparms,
33932 + rc = 0;
33933 + }
33934 +
33935 +- if (buf) {
33936 ++ if (smb2_data) {
33937 + /* if open response does not have IndexNumber field - get it */
33938 + if (smb2_data->IndexNumber == 0) {
33939 + rc = SMB2_get_srv_num(xid, oparms->tcon,
33940 +@@ -89,12 +174,12 @@ smb2_open_file(const unsigned int xid, struct cifs_open_parms *oparms,
33941 + rc = 0;
33942 + }
33943 + }
33944 +- move_smb2_info_to_cifs(buf, smb2_data);
33945 ++ memcpy(&data->fi, smb2_data, sizeof(data->fi));
33946 + }
33947 +
33948 + *oplock = smb2_oplock;
33949 + out:
33950 +- kfree(smb2_data);
33951 ++ free_rsp_buf(err_buftype, err_iov.iov_base);
33952 + kfree(smb2_path);
33953 + return rc;
33954 + }
33955 +diff --git a/fs/cifs/smb2inode.c b/fs/cifs/smb2inode.c
33956 +index b83f59051b26f..fc5776e7a7824 100644
33957 +--- a/fs/cifs/smb2inode.c
33958 ++++ b/fs/cifs/smb2inode.c
33959 +@@ -24,6 +24,7 @@
33960 + #include "smb2pdu.h"
33961 + #include "smb2proto.h"
33962 + #include "cached_dir.h"
33963 ++#include "smb2status.h"
33964 +
33965 + static void
33966 + free_set_inf_compound(struct smb_rqst *rqst)
33967 +@@ -50,13 +51,15 @@ struct cop_vars {
33968 + /*
33969 + * note: If cfile is passed, the reference to it is dropped here.
33970 + * So make sure that you do not reuse cfile after return from this func.
33971 ++ *
33972 ++ * If passing @err_iov and @err_buftype, ensure to make them both large enough (>= 3) to hold all
33973 ++ * error responses. Caller is also responsible for freeing them up.
33974 + */
33975 +-static int
33976 +-smb2_compound_op(const unsigned int xid, struct cifs_tcon *tcon,
33977 +- struct cifs_sb_info *cifs_sb, const char *full_path,
33978 +- __u32 desired_access, __u32 create_disposition,
33979 +- __u32 create_options, umode_t mode, void *ptr, int command,
33980 +- struct cifsFileInfo *cfile)
33981 ++static int smb2_compound_op(const unsigned int xid, struct cifs_tcon *tcon,
33982 ++ struct cifs_sb_info *cifs_sb, const char *full_path,
33983 ++ __u32 desired_access, __u32 create_disposition, __u32 create_options,
33984 ++ umode_t mode, void *ptr, int command, struct cifsFileInfo *cfile,
33985 ++ struct kvec *err_iov, int *err_buftype)
33986 + {
33987 + struct cop_vars *vars = NULL;
33988 + struct kvec *rsp_iov;
33989 +@@ -70,6 +73,7 @@ smb2_compound_op(const unsigned int xid, struct cifs_tcon *tcon,
33990 + int num_rqst = 0;
33991 + int resp_buftype[3];
33992 + struct smb2_query_info_rsp *qi_rsp = NULL;
33993 ++ struct cifs_open_info_data *idata;
33994 + int flags = 0;
33995 + __u8 delete_pending[8] = {1, 0, 0, 0, 0, 0, 0, 0};
33996 + unsigned int size[2];
33997 +@@ -385,14 +389,19 @@ smb2_compound_op(const unsigned int xid, struct cifs_tcon *tcon,
33998 +
33999 + switch (command) {
34000 + case SMB2_OP_QUERY_INFO:
34001 ++ idata = ptr;
34002 ++ if (rc == 0 && cfile && cfile->symlink_target) {
34003 ++ idata->symlink_target = kstrdup(cfile->symlink_target, GFP_KERNEL);
34004 ++ if (!idata->symlink_target)
34005 ++ rc = -ENOMEM;
34006 ++ }
34007 + if (rc == 0) {
34008 + qi_rsp = (struct smb2_query_info_rsp *)
34009 + rsp_iov[1].iov_base;
34010 + rc = smb2_validate_and_copy_iov(
34011 + le16_to_cpu(qi_rsp->OutputBufferOffset),
34012 + le32_to_cpu(qi_rsp->OutputBufferLength),
34013 +- &rsp_iov[1], sizeof(struct smb2_file_all_info),
34014 +- ptr);
34015 ++ &rsp_iov[1], sizeof(idata->fi), (char *)&idata->fi);
34016 + }
34017 + if (rqst[1].rq_iov)
34018 + SMB2_query_info_free(&rqst[1]);
34019 +@@ -406,13 +415,20 @@ smb2_compound_op(const unsigned int xid, struct cifs_tcon *tcon,
34020 + tcon->tid);
34021 + break;
34022 + case SMB2_OP_POSIX_QUERY_INFO:
34023 ++ idata = ptr;
34024 ++ if (rc == 0 && cfile && cfile->symlink_target) {
34025 ++ idata->symlink_target = kstrdup(cfile->symlink_target, GFP_KERNEL);
34026 ++ if (!idata->symlink_target)
34027 ++ rc = -ENOMEM;
34028 ++ }
34029 + if (rc == 0) {
34030 + qi_rsp = (struct smb2_query_info_rsp *)
34031 + rsp_iov[1].iov_base;
34032 + rc = smb2_validate_and_copy_iov(
34033 + le16_to_cpu(qi_rsp->OutputBufferOffset),
34034 + le32_to_cpu(qi_rsp->OutputBufferLength),
34035 +- &rsp_iov[1], sizeof(struct smb311_posix_qinfo) /* add SIDs */, ptr);
34036 ++ &rsp_iov[1], sizeof(idata->posix_fi) /* add SIDs */,
34037 ++ (char *)&idata->posix_fi);
34038 + }
34039 + if (rqst[1].rq_iov)
34040 + SMB2_query_info_free(&rqst[1]);
34041 +@@ -477,42 +493,33 @@ smb2_compound_op(const unsigned int xid, struct cifs_tcon *tcon,
34042 + free_set_inf_compound(rqst);
34043 + break;
34044 + }
34045 +- free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base);
34046 +- free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base);
34047 +- free_rsp_buf(resp_buftype[2], rsp_iov[2].iov_base);
34048 ++
34049 ++ if (rc && err_iov && err_buftype) {
34050 ++ memcpy(err_iov, rsp_iov, 3 * sizeof(*err_iov));
34051 ++ memcpy(err_buftype, resp_buftype, 3 * sizeof(*err_buftype));
34052 ++ } else {
34053 ++ free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base);
34054 ++ free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base);
34055 ++ free_rsp_buf(resp_buftype[2], rsp_iov[2].iov_base);
34056 ++ }
34057 + kfree(vars);
34058 + return rc;
34059 + }
34060 +
34061 +-void
34062 +-move_smb2_info_to_cifs(FILE_ALL_INFO *dst, struct smb2_file_all_info *src)
34063 +-{
34064 +- memcpy(dst, src, (size_t)(&src->CurrentByteOffset) - (size_t)src);
34065 +- dst->CurrentByteOffset = src->CurrentByteOffset;
34066 +- dst->Mode = src->Mode;
34067 +- dst->AlignmentRequirement = src->AlignmentRequirement;
34068 +- dst->IndexNumber1 = 0; /* we don't use it */
34069 +-}
34070 +-
34071 +-int
34072 +-smb2_query_path_info(const unsigned int xid, struct cifs_tcon *tcon,
34073 +- struct cifs_sb_info *cifs_sb, const char *full_path,
34074 +- FILE_ALL_INFO *data, bool *adjust_tz, bool *reparse)
34075 ++int smb2_query_path_info(const unsigned int xid, struct cifs_tcon *tcon,
34076 ++ struct cifs_sb_info *cifs_sb, const char *full_path,
34077 ++ struct cifs_open_info_data *data, bool *adjust_tz, bool *reparse)
34078 + {
34079 + int rc;
34080 +- struct smb2_file_all_info *smb2_data;
34081 + __u32 create_options = 0;
34082 + struct cifsFileInfo *cfile;
34083 + struct cached_fid *cfid = NULL;
34084 ++ struct kvec err_iov[3] = {};
34085 ++ int err_buftype[3] = {};
34086 +
34087 + *adjust_tz = false;
34088 + *reparse = false;
34089 +
34090 +- smb2_data = kzalloc(sizeof(struct smb2_file_all_info) + PATH_MAX * 2,
34091 +- GFP_KERNEL);
34092 +- if (smb2_data == NULL)
34093 +- return -ENOMEM;
34094 +-
34095 + if (strcmp(full_path, ""))
34096 + rc = -ENOENT;
34097 + else
34098 +@@ -520,63 +527,58 @@ smb2_query_path_info(const unsigned int xid, struct cifs_tcon *tcon,
34099 + /* If it is a root and its handle is cached then use it */
34100 + if (!rc) {
34101 + if (cfid->file_all_info_is_valid) {
34102 +- move_smb2_info_to_cifs(data,
34103 +- &cfid->file_all_info);
34104 ++ memcpy(&data->fi, &cfid->file_all_info, sizeof(data->fi));
34105 + } else {
34106 +- rc = SMB2_query_info(xid, tcon,
34107 +- cfid->fid.persistent_fid,
34108 +- cfid->fid.volatile_fid, smb2_data);
34109 +- if (!rc)
34110 +- move_smb2_info_to_cifs(data, smb2_data);
34111 ++ rc = SMB2_query_info(xid, tcon, cfid->fid.persistent_fid,
34112 ++ cfid->fid.volatile_fid, &data->fi);
34113 + }
34114 + close_cached_dir(cfid);
34115 +- goto out;
34116 ++ return rc;
34117 + }
34118 +
34119 + cifs_get_readable_path(tcon, full_path, &cfile);
34120 +- rc = smb2_compound_op(xid, tcon, cifs_sb, full_path,
34121 +- FILE_READ_ATTRIBUTES, FILE_OPEN, create_options,
34122 +- ACL_NO_MODE, smb2_data, SMB2_OP_QUERY_INFO, cfile);
34123 ++ rc = smb2_compound_op(xid, tcon, cifs_sb, full_path, FILE_READ_ATTRIBUTES, FILE_OPEN,
34124 ++ create_options, ACL_NO_MODE, data, SMB2_OP_QUERY_INFO, cfile,
34125 ++ err_iov, err_buftype);
34126 + if (rc == -EOPNOTSUPP) {
34127 ++ if (err_iov[0].iov_base && err_buftype[0] != CIFS_NO_BUFFER &&
34128 ++ ((struct smb2_hdr *)err_iov[0].iov_base)->Command == SMB2_CREATE &&
34129 ++ ((struct smb2_hdr *)err_iov[0].iov_base)->Status == STATUS_STOPPED_ON_SYMLINK) {
34130 ++ rc = smb2_parse_symlink_response(cifs_sb, err_iov, &data->symlink_target);
34131 ++ if (rc)
34132 ++ goto out;
34133 ++ }
34134 + *reparse = true;
34135 + create_options |= OPEN_REPARSE_POINT;
34136 +
34137 + /* Failed on a symbolic link - query a reparse point info */
34138 + cifs_get_readable_path(tcon, full_path, &cfile);
34139 +- rc = smb2_compound_op(xid, tcon, cifs_sb, full_path,
34140 +- FILE_READ_ATTRIBUTES, FILE_OPEN,
34141 +- create_options, ACL_NO_MODE,
34142 +- smb2_data, SMB2_OP_QUERY_INFO, cfile);
34143 ++ rc = smb2_compound_op(xid, tcon, cifs_sb, full_path, FILE_READ_ATTRIBUTES,
34144 ++ FILE_OPEN, create_options, ACL_NO_MODE, data,
34145 ++ SMB2_OP_QUERY_INFO, cfile, NULL, NULL);
34146 + }
34147 +- if (rc)
34148 +- goto out;
34149 +
34150 +- move_smb2_info_to_cifs(data, smb2_data);
34151 + out:
34152 +- kfree(smb2_data);
34153 ++ free_rsp_buf(err_buftype[0], err_iov[0].iov_base);
34154 ++ free_rsp_buf(err_buftype[1], err_iov[1].iov_base);
34155 ++ free_rsp_buf(err_buftype[2], err_iov[2].iov_base);
34156 + return rc;
34157 + }
34158 +
34159 +
34160 +-int
34161 +-smb311_posix_query_path_info(const unsigned int xid, struct cifs_tcon *tcon,
34162 +- struct cifs_sb_info *cifs_sb, const char *full_path,
34163 +- struct smb311_posix_qinfo *data, bool *adjust_tz, bool *reparse)
34164 ++int smb311_posix_query_path_info(const unsigned int xid, struct cifs_tcon *tcon,
34165 ++ struct cifs_sb_info *cifs_sb, const char *full_path,
34166 ++ struct cifs_open_info_data *data, bool *adjust_tz, bool *reparse)
34167 + {
34168 + int rc;
34169 + __u32 create_options = 0;
34170 + struct cifsFileInfo *cfile;
34171 +- struct smb311_posix_qinfo *smb2_data;
34172 ++ struct kvec err_iov[3] = {};
34173 ++ int err_buftype[3] = {};
34174 +
34175 + *adjust_tz = false;
34176 + *reparse = false;
34177 +
34178 +- /* BB TODO: Make struct larger when add support for parsing owner SIDs */
34179 +- smb2_data = kzalloc(sizeof(struct smb311_posix_qinfo),
34180 +- GFP_KERNEL);
34181 +- if (smb2_data == NULL)
34182 +- return -ENOMEM;
34183 +-
34184 + /*
34185 + * BB TODO: Add support for using the cached root handle.
34186 + * Create SMB2_query_posix_info worker function to do non-compounded query
34187 +@@ -585,29 +587,32 @@ smb311_posix_query_path_info(const unsigned int xid, struct cifs_tcon *tcon,
34188 + */
34189 +
34190 + cifs_get_readable_path(tcon, full_path, &cfile);
34191 +- rc = smb2_compound_op(xid, tcon, cifs_sb, full_path,
34192 +- FILE_READ_ATTRIBUTES, FILE_OPEN, create_options,
34193 +- ACL_NO_MODE, smb2_data, SMB2_OP_POSIX_QUERY_INFO, cfile);
34194 ++ rc = smb2_compound_op(xid, tcon, cifs_sb, full_path, FILE_READ_ATTRIBUTES, FILE_OPEN,
34195 ++ create_options, ACL_NO_MODE, data, SMB2_OP_POSIX_QUERY_INFO, cfile,
34196 ++ err_iov, err_buftype);
34197 + if (rc == -EOPNOTSUPP) {
34198 + /* BB TODO: When support for special files added to Samba re-verify this path */
34199 ++ if (err_iov[0].iov_base && err_buftype[0] != CIFS_NO_BUFFER &&
34200 ++ ((struct smb2_hdr *)err_iov[0].iov_base)->Command == SMB2_CREATE &&
34201 ++ ((struct smb2_hdr *)err_iov[0].iov_base)->Status == STATUS_STOPPED_ON_SYMLINK) {
34202 ++ rc = smb2_parse_symlink_response(cifs_sb, err_iov, &data->symlink_target);
34203 ++ if (rc)
34204 ++ goto out;
34205 ++ }
34206 + *reparse = true;
34207 + create_options |= OPEN_REPARSE_POINT;
34208 +
34209 + /* Failed on a symbolic link - query a reparse point info */
34210 + cifs_get_readable_path(tcon, full_path, &cfile);
34211 +- rc = smb2_compound_op(xid, tcon, cifs_sb, full_path,
34212 +- FILE_READ_ATTRIBUTES, FILE_OPEN,
34213 +- create_options, ACL_NO_MODE,
34214 +- smb2_data, SMB2_OP_POSIX_QUERY_INFO, cfile);
34215 ++ rc = smb2_compound_op(xid, tcon, cifs_sb, full_path, FILE_READ_ATTRIBUTES,
34216 ++ FILE_OPEN, create_options, ACL_NO_MODE, data,
34217 ++ SMB2_OP_POSIX_QUERY_INFO, cfile, NULL, NULL);
34218 + }
34219 +- if (rc)
34220 +- goto out;
34221 +-
34222 +- /* TODO: will need to allow for the 2 SIDs when add support for getting owner UID/GID */
34223 +- memcpy(data, smb2_data, sizeof(struct smb311_posix_qinfo));
34224 +
34225 + out:
34226 +- kfree(smb2_data);
34227 ++ free_rsp_buf(err_buftype[0], err_iov[0].iov_base);
34228 ++ free_rsp_buf(err_buftype[1], err_iov[1].iov_base);
34229 ++ free_rsp_buf(err_buftype[2], err_iov[2].iov_base);
34230 + return rc;
34231 + }
34232 +
34233 +@@ -619,7 +624,7 @@ smb2_mkdir(const unsigned int xid, struct inode *parent_inode, umode_t mode,
34234 + return smb2_compound_op(xid, tcon, cifs_sb, name,
34235 + FILE_WRITE_ATTRIBUTES, FILE_CREATE,
34236 + CREATE_NOT_FILE, mode, NULL, SMB2_OP_MKDIR,
34237 +- NULL);
34238 ++ NULL, NULL, NULL);
34239 + }
34240 +
34241 + void
34242 +@@ -641,7 +646,7 @@ smb2_mkdir_setinfo(struct inode *inode, const char *name,
34243 + tmprc = smb2_compound_op(xid, tcon, cifs_sb, name,
34244 + FILE_WRITE_ATTRIBUTES, FILE_CREATE,
34245 + CREATE_NOT_FILE, ACL_NO_MODE,
34246 +- &data, SMB2_OP_SET_INFO, cfile);
34247 ++ &data, SMB2_OP_SET_INFO, cfile, NULL, NULL);
34248 + if (tmprc == 0)
34249 + cifs_i->cifsAttrs = dosattrs;
34250 + }
34251 +@@ -652,7 +657,7 @@ smb2_rmdir(const unsigned int xid, struct cifs_tcon *tcon, const char *name,
34252 + {
34253 + return smb2_compound_op(xid, tcon, cifs_sb, name, DELETE, FILE_OPEN,
34254 + CREATE_NOT_FILE, ACL_NO_MODE,
34255 +- NULL, SMB2_OP_RMDIR, NULL);
34256 ++ NULL, SMB2_OP_RMDIR, NULL, NULL, NULL);
34257 + }
34258 +
34259 + int
34260 +@@ -661,7 +666,7 @@ smb2_unlink(const unsigned int xid, struct cifs_tcon *tcon, const char *name,
34261 + {
34262 + return smb2_compound_op(xid, tcon, cifs_sb, name, DELETE, FILE_OPEN,
34263 + CREATE_DELETE_ON_CLOSE | OPEN_REPARSE_POINT,
34264 +- ACL_NO_MODE, NULL, SMB2_OP_DELETE, NULL);
34265 ++ ACL_NO_MODE, NULL, SMB2_OP_DELETE, NULL, NULL, NULL);
34266 + }
34267 +
34268 + static int
34269 +@@ -680,7 +685,7 @@ smb2_set_path_attr(const unsigned int xid, struct cifs_tcon *tcon,
34270 + }
34271 + rc = smb2_compound_op(xid, tcon, cifs_sb, from_name, access,
34272 + FILE_OPEN, 0, ACL_NO_MODE, smb2_to_name,
34273 +- command, cfile);
34274 ++ command, cfile, NULL, NULL);
34275 + smb2_rename_path:
34276 + kfree(smb2_to_name);
34277 + return rc;
34278 +@@ -720,7 +725,7 @@ smb2_set_path_size(const unsigned int xid, struct cifs_tcon *tcon,
34279 + cifs_get_writable_path(tcon, full_path, FIND_WR_ANY, &cfile);
34280 + return smb2_compound_op(xid, tcon, cifs_sb, full_path,
34281 + FILE_WRITE_DATA, FILE_OPEN, 0, ACL_NO_MODE,
34282 +- &eof, SMB2_OP_SET_EOF, cfile);
34283 ++ &eof, SMB2_OP_SET_EOF, cfile, NULL, NULL);
34284 + }
34285 +
34286 + int
34287 +@@ -746,7 +751,8 @@ smb2_set_file_info(struct inode *inode, const char *full_path,
34288 + cifs_get_writable_path(tcon, full_path, FIND_WR_ANY, &cfile);
34289 + rc = smb2_compound_op(xid, tcon, cifs_sb, full_path,
34290 + FILE_WRITE_ATTRIBUTES, FILE_OPEN,
34291 +- 0, ACL_NO_MODE, buf, SMB2_OP_SET_INFO, cfile);
34292 ++ 0, ACL_NO_MODE, buf, SMB2_OP_SET_INFO, cfile,
34293 ++ NULL, NULL);
34294 + cifs_put_tlink(tlink);
34295 + return rc;
34296 + }
34297 +diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
34298 +index b724bf42b5401..74052b51655ec 100644
34299 +--- a/fs/cifs/smb2ops.c
34300 ++++ b/fs/cifs/smb2ops.c
34301 +@@ -831,33 +831,25 @@ smb2_is_path_accessible(const unsigned int xid, struct cifs_tcon *tcon,
34302 + return rc;
34303 + }
34304 +
34305 +-static int
34306 +-smb2_get_srv_inum(const unsigned int xid, struct cifs_tcon *tcon,
34307 +- struct cifs_sb_info *cifs_sb, const char *full_path,
34308 +- u64 *uniqueid, FILE_ALL_INFO *data)
34309 ++static int smb2_get_srv_inum(const unsigned int xid, struct cifs_tcon *tcon,
34310 ++ struct cifs_sb_info *cifs_sb, const char *full_path,
34311 ++ u64 *uniqueid, struct cifs_open_info_data *data)
34312 + {
34313 +- *uniqueid = le64_to_cpu(data->IndexNumber);
34314 ++ *uniqueid = le64_to_cpu(data->fi.IndexNumber);
34315 + return 0;
34316 + }
34317 +
34318 +-static int
34319 +-smb2_query_file_info(const unsigned int xid, struct cifs_tcon *tcon,
34320 +- struct cifs_fid *fid, FILE_ALL_INFO *data)
34321 ++static int smb2_query_file_info(const unsigned int xid, struct cifs_tcon *tcon,
34322 ++ struct cifsFileInfo *cfile, struct cifs_open_info_data *data)
34323 + {
34324 +- int rc;
34325 +- struct smb2_file_all_info *smb2_data;
34326 ++ struct cifs_fid *fid = &cfile->fid;
34327 +
34328 +- smb2_data = kzalloc(sizeof(struct smb2_file_all_info) + PATH_MAX * 2,
34329 +- GFP_KERNEL);
34330 +- if (smb2_data == NULL)
34331 +- return -ENOMEM;
34332 +-
34333 +- rc = SMB2_query_info(xid, tcon, fid->persistent_fid, fid->volatile_fid,
34334 +- smb2_data);
34335 +- if (!rc)
34336 +- move_smb2_info_to_cifs(data, smb2_data);
34337 +- kfree(smb2_data);
34338 +- return rc;
34339 ++ if (cfile->symlink_target) {
34340 ++ data->symlink_target = kstrdup(cfile->symlink_target, GFP_KERNEL);
34341 ++ if (!data->symlink_target)
34342 ++ return -ENOMEM;
34343 ++ }
34344 ++ return SMB2_query_info(xid, tcon, fid->persistent_fid, fid->volatile_fid, &data->fi);
34345 + }
34346 +
34347 + #ifdef CONFIG_CIFS_XATTR
34348 +@@ -2836,9 +2828,6 @@ parse_reparse_point(struct reparse_data_buffer *buf,
34349 + }
34350 + }
34351 +
34352 +-#define SMB2_SYMLINK_STRUCT_SIZE \
34353 +- (sizeof(struct smb2_err_rsp) - 1 + sizeof(struct smb2_symlink_err_rsp))
34354 +-
34355 + static int
34356 + smb2_query_symlink(const unsigned int xid, struct cifs_tcon *tcon,
34357 + struct cifs_sb_info *cifs_sb, const char *full_path,
34358 +@@ -2850,13 +2839,7 @@ smb2_query_symlink(const unsigned int xid, struct cifs_tcon *tcon,
34359 + struct cifs_open_parms oparms;
34360 + struct cifs_fid fid;
34361 + struct kvec err_iov = {NULL, 0};
34362 +- struct smb2_err_rsp *err_buf = NULL;
34363 +- struct smb2_symlink_err_rsp *symlink;
34364 + struct TCP_Server_Info *server = cifs_pick_channel(tcon->ses);
34365 +- unsigned int sub_len;
34366 +- unsigned int sub_offset;
34367 +- unsigned int print_len;
34368 +- unsigned int print_offset;
34369 + int flags = CIFS_CP_CREATE_CLOSE_OP;
34370 + struct smb_rqst rqst[3];
34371 + int resp_buftype[3];
34372 +@@ -2973,47 +2956,7 @@ smb2_query_symlink(const unsigned int xid, struct cifs_tcon *tcon,
34373 + goto querty_exit;
34374 + }
34375 +
34376 +- err_buf = err_iov.iov_base;
34377 +- if (le32_to_cpu(err_buf->ByteCount) < sizeof(struct smb2_symlink_err_rsp) ||
34378 +- err_iov.iov_len < SMB2_SYMLINK_STRUCT_SIZE) {
34379 +- rc = -EINVAL;
34380 +- goto querty_exit;
34381 +- }
34382 +-
34383 +- symlink = (struct smb2_symlink_err_rsp *)err_buf->ErrorData;
34384 +- if (le32_to_cpu(symlink->SymLinkErrorTag) != SYMLINK_ERROR_TAG ||
34385 +- le32_to_cpu(symlink->ReparseTag) != IO_REPARSE_TAG_SYMLINK) {
34386 +- rc = -EINVAL;
34387 +- goto querty_exit;
34388 +- }
34389 +-
34390 +- /* open must fail on symlink - reset rc */
34391 +- rc = 0;
34392 +- sub_len = le16_to_cpu(symlink->SubstituteNameLength);
34393 +- sub_offset = le16_to_cpu(symlink->SubstituteNameOffset);
34394 +- print_len = le16_to_cpu(symlink->PrintNameLength);
34395 +- print_offset = le16_to_cpu(symlink->PrintNameOffset);
34396 +-
34397 +- if (err_iov.iov_len < SMB2_SYMLINK_STRUCT_SIZE + sub_offset + sub_len) {
34398 +- rc = -EINVAL;
34399 +- goto querty_exit;
34400 +- }
34401 +-
34402 +- if (err_iov.iov_len <
34403 +- SMB2_SYMLINK_STRUCT_SIZE + print_offset + print_len) {
34404 +- rc = -EINVAL;
34405 +- goto querty_exit;
34406 +- }
34407 +-
34408 +- *target_path = cifs_strndup_from_utf16(
34409 +- (char *)symlink->PathBuffer + sub_offset,
34410 +- sub_len, true, cifs_sb->local_nls);
34411 +- if (!(*target_path)) {
34412 +- rc = -ENOMEM;
34413 +- goto querty_exit;
34414 +- }
34415 +- convert_delimiter(*target_path, '/');
34416 +- cifs_dbg(FYI, "%s: target path: %s\n", __func__, *target_path);
34417 ++ rc = smb2_parse_symlink_response(cifs_sb, &err_iov, target_path);
34418 +
34419 + querty_exit:
34420 + cifs_dbg(FYI, "query symlink rc %d\n", rc);
34421 +@@ -4239,69 +4182,82 @@ fill_transform_hdr(struct smb2_transform_hdr *tr_hdr, unsigned int orig_len,
34422 + memcpy(&tr_hdr->SessionId, &shdr->SessionId, 8);
34423 + }
34424 +
34425 +-/* We can not use the normal sg_set_buf() as we will sometimes pass a
34426 +- * stack object as buf.
34427 +- */
34428 +-static inline void smb2_sg_set_buf(struct scatterlist *sg, const void *buf,
34429 +- unsigned int buflen)
34430 ++static void *smb2_aead_req_alloc(struct crypto_aead *tfm, const struct smb_rqst *rqst,
34431 ++ int num_rqst, const u8 *sig, u8 **iv,
34432 ++ struct aead_request **req, struct scatterlist **sgl,
34433 ++ unsigned int *num_sgs)
34434 + {
34435 +- void *addr;
34436 +- /*
34437 +- * VMAP_STACK (at least) puts stack into the vmalloc address space
34438 +- */
34439 +- if (is_vmalloc_addr(buf))
34440 +- addr = vmalloc_to_page(buf);
34441 +- else
34442 +- addr = virt_to_page(buf);
34443 +- sg_set_page(sg, addr, buflen, offset_in_page(buf));
34444 ++ unsigned int req_size = sizeof(**req) + crypto_aead_reqsize(tfm);
34445 ++ unsigned int iv_size = crypto_aead_ivsize(tfm);
34446 ++ unsigned int len;
34447 ++ u8 *p;
34448 ++
34449 ++ *num_sgs = cifs_get_num_sgs(rqst, num_rqst, sig);
34450 ++
34451 ++ len = iv_size;
34452 ++ len += crypto_aead_alignmask(tfm) & ~(crypto_tfm_ctx_alignment() - 1);
34453 ++ len = ALIGN(len, crypto_tfm_ctx_alignment());
34454 ++ len += req_size;
34455 ++ len = ALIGN(len, __alignof__(struct scatterlist));
34456 ++ len += *num_sgs * sizeof(**sgl);
34457 ++
34458 ++ p = kmalloc(len, GFP_ATOMIC);
34459 ++ if (!p)
34460 ++ return NULL;
34461 ++
34462 ++ *iv = (u8 *)PTR_ALIGN(p, crypto_aead_alignmask(tfm) + 1);
34463 ++ *req = (struct aead_request *)PTR_ALIGN(*iv + iv_size,
34464 ++ crypto_tfm_ctx_alignment());
34465 ++ *sgl = (struct scatterlist *)PTR_ALIGN((u8 *)*req + req_size,
34466 ++ __alignof__(struct scatterlist));
34467 ++ return p;
34468 + }
34469 +
34470 +-/* Assumes the first rqst has a transform header as the first iov.
34471 +- * I.e.
34472 +- * rqst[0].rq_iov[0] is transform header
34473 +- * rqst[0].rq_iov[1+] data to be encrypted/decrypted
34474 +- * rqst[1+].rq_iov[0+] data to be encrypted/decrypted
34475 +- */
34476 +-static struct scatterlist *
34477 +-init_sg(int num_rqst, struct smb_rqst *rqst, u8 *sign)
34478 ++static void *smb2_get_aead_req(struct crypto_aead *tfm, const struct smb_rqst *rqst,
34479 ++ int num_rqst, const u8 *sig, u8 **iv,
34480 ++ struct aead_request **req, struct scatterlist **sgl)
34481 + {
34482 +- unsigned int sg_len;
34483 ++ unsigned int off, len, skip;
34484 + struct scatterlist *sg;
34485 +- unsigned int i;
34486 +- unsigned int j;
34487 +- unsigned int idx = 0;
34488 +- int skip;
34489 +-
34490 +- sg_len = 1;
34491 +- for (i = 0; i < num_rqst; i++)
34492 +- sg_len += rqst[i].rq_nvec + rqst[i].rq_npages;
34493 ++ unsigned int num_sgs;
34494 ++ unsigned long addr;
34495 ++ int i, j;
34496 ++ void *p;
34497 +
34498 +- sg = kmalloc_array(sg_len, sizeof(struct scatterlist), GFP_KERNEL);
34499 +- if (!sg)
34500 ++ p = smb2_aead_req_alloc(tfm, rqst, num_rqst, sig, iv, req, sgl, &num_sgs);
34501 ++ if (!p)
34502 + return NULL;
34503 +
34504 +- sg_init_table(sg, sg_len);
34505 ++ sg_init_table(*sgl, num_sgs);
34506 ++ sg = *sgl;
34507 ++
34508 ++ /* Assumes the first rqst has a transform header as the first iov.
34509 ++ * I.e.
34510 ++ * rqst[0].rq_iov[0] is transform header
34511 ++ * rqst[0].rq_iov[1+] data to be encrypted/decrypted
34512 ++ * rqst[1+].rq_iov[0+] data to be encrypted/decrypted
34513 ++ */
34514 + for (i = 0; i < num_rqst; i++) {
34515 ++ /*
34516 ++ * The first rqst has a transform header where the
34517 ++ * first 20 bytes are not part of the encrypted blob.
34518 ++ */
34519 + for (j = 0; j < rqst[i].rq_nvec; j++) {
34520 +- /*
34521 +- * The first rqst has a transform header where the
34522 +- * first 20 bytes are not part of the encrypted blob
34523 +- */
34524 +- skip = (i == 0) && (j == 0) ? 20 : 0;
34525 +- smb2_sg_set_buf(&sg[idx++],
34526 +- rqst[i].rq_iov[j].iov_base + skip,
34527 +- rqst[i].rq_iov[j].iov_len - skip);
34528 +- }
34529 ++ struct kvec *iov = &rqst[i].rq_iov[j];
34530 +
34531 ++ skip = (i == 0) && (j == 0) ? 20 : 0;
34532 ++ addr = (unsigned long)iov->iov_base + skip;
34533 ++ len = iov->iov_len - skip;
34534 ++ sg = cifs_sg_set_buf(sg, (void *)addr, len);
34535 ++ }
34536 + for (j = 0; j < rqst[i].rq_npages; j++) {
34537 +- unsigned int len, offset;
34538 +-
34539 +- rqst_page_get_length(&rqst[i], j, &len, &offset);
34540 +- sg_set_page(&sg[idx++], rqst[i].rq_pages[j], len, offset);
34541 ++ rqst_page_get_length(&rqst[i], j, &len, &off);
34542 ++ sg_set_page(sg++, rqst[i].rq_pages[j], len, off);
34543 + }
34544 + }
34545 +- smb2_sg_set_buf(&sg[idx], sign, SMB2_SIGNATURE_SIZE);
34546 +- return sg;
34547 ++ cifs_sg_set_buf(sg, sig, SMB2_SIGNATURE_SIZE);
34548 ++
34549 ++ return p;
34550 + }
34551 +
34552 + static int
34553 +@@ -4347,11 +4303,11 @@ crypt_message(struct TCP_Server_Info *server, int num_rqst,
34554 + u8 sign[SMB2_SIGNATURE_SIZE] = {};
34555 + u8 key[SMB3_ENC_DEC_KEY_SIZE];
34556 + struct aead_request *req;
34557 +- char *iv;
34558 +- unsigned int iv_len;
34559 ++ u8 *iv;
34560 + DECLARE_CRYPTO_WAIT(wait);
34561 + struct crypto_aead *tfm;
34562 + unsigned int crypt_len = le32_to_cpu(tr_hdr->OriginalMessageSize);
34563 ++ void *creq;
34564 +
34565 + rc = smb2_get_enc_key(server, le64_to_cpu(tr_hdr->SessionId), enc, key);
34566 + if (rc) {
34567 +@@ -4386,32 +4342,15 @@ crypt_message(struct TCP_Server_Info *server, int num_rqst,
34568 + return rc;
34569 + }
34570 +
34571 +- req = aead_request_alloc(tfm, GFP_KERNEL);
34572 +- if (!req) {
34573 +- cifs_server_dbg(VFS, "%s: Failed to alloc aead request\n", __func__);
34574 ++ creq = smb2_get_aead_req(tfm, rqst, num_rqst, sign, &iv, &req, &sg);
34575 ++ if (unlikely(!creq))
34576 + return -ENOMEM;
34577 +- }
34578 +
34579 + if (!enc) {
34580 + memcpy(sign, &tr_hdr->Signature, SMB2_SIGNATURE_SIZE);
34581 + crypt_len += SMB2_SIGNATURE_SIZE;
34582 + }
34583 +
34584 +- sg = init_sg(num_rqst, rqst, sign);
34585 +- if (!sg) {
34586 +- cifs_server_dbg(VFS, "%s: Failed to init sg\n", __func__);
34587 +- rc = -ENOMEM;
34588 +- goto free_req;
34589 +- }
34590 +-
34591 +- iv_len = crypto_aead_ivsize(tfm);
34592 +- iv = kzalloc(iv_len, GFP_KERNEL);
34593 +- if (!iv) {
34594 +- cifs_server_dbg(VFS, "%s: Failed to alloc iv\n", __func__);
34595 +- rc = -ENOMEM;
34596 +- goto free_sg;
34597 +- }
34598 +-
34599 + if ((server->cipher_type == SMB2_ENCRYPTION_AES128_GCM) ||
34600 + (server->cipher_type == SMB2_ENCRYPTION_AES256_GCM))
34601 + memcpy(iv, (char *)tr_hdr->Nonce, SMB3_AES_GCM_NONCE);
34602 +@@ -4420,6 +4359,7 @@ crypt_message(struct TCP_Server_Info *server, int num_rqst,
34603 + memcpy(iv + 1, (char *)tr_hdr->Nonce, SMB3_AES_CCM_NONCE);
34604 + }
34605 +
34606 ++ aead_request_set_tfm(req, tfm);
34607 + aead_request_set_crypt(req, sg, sg, crypt_len, iv);
34608 + aead_request_set_ad(req, assoc_data_len);
34609 +
34610 +@@ -4432,11 +4372,7 @@ crypt_message(struct TCP_Server_Info *server, int num_rqst,
34611 + if (!rc && enc)
34612 + memcpy(&tr_hdr->Signature, sign, SMB2_SIGNATURE_SIZE);
34613 +
34614 +- kfree(iv);
34615 +-free_sg:
34616 +- kfree(sg);
34617 +-free_req:
34618 +- kfree(req);
34619 ++ kfree_sensitive(creq);
34620 + return rc;
34621 + }
34622 +
34623 +@@ -5124,7 +5060,7 @@ smb2_make_node(unsigned int xid, struct inode *inode,
34624 + {
34625 + struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
34626 + int rc = -EPERM;
34627 +- FILE_ALL_INFO *buf = NULL;
34628 ++ struct cifs_open_info_data buf = {};
34629 + struct cifs_io_parms io_parms = {0};
34630 + __u32 oplock = 0;
34631 + struct cifs_fid fid;
34632 +@@ -5140,7 +5076,7 @@ smb2_make_node(unsigned int xid, struct inode *inode,
34633 + * and was used by default in earlier versions of Windows
34634 + */
34635 + if (!(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_UNX_EMUL))
34636 +- goto out;
34637 ++ return rc;
34638 +
34639 + /*
34640 + * TODO: Add ability to create instead via reparse point. Windows (e.g.
34641 +@@ -5149,16 +5085,10 @@ smb2_make_node(unsigned int xid, struct inode *inode,
34642 + */
34643 +
34644 + if (!S_ISCHR(mode) && !S_ISBLK(mode))
34645 +- goto out;
34646 ++ return rc;
34647 +
34648 + cifs_dbg(FYI, "sfu compat create special file\n");
34649 +
34650 +- buf = kmalloc(sizeof(FILE_ALL_INFO), GFP_KERNEL);
34651 +- if (buf == NULL) {
34652 +- rc = -ENOMEM;
34653 +- goto out;
34654 +- }
34655 +-
34656 + oparms.tcon = tcon;
34657 + oparms.cifs_sb = cifs_sb;
34658 + oparms.desired_access = GENERIC_WRITE;
34659 +@@ -5173,21 +5103,21 @@ smb2_make_node(unsigned int xid, struct inode *inode,
34660 + oplock = REQ_OPLOCK;
34661 + else
34662 + oplock = 0;
34663 +- rc = tcon->ses->server->ops->open(xid, &oparms, &oplock, buf);
34664 ++ rc = tcon->ses->server->ops->open(xid, &oparms, &oplock, &buf);
34665 + if (rc)
34666 +- goto out;
34667 ++ return rc;
34668 +
34669 + /*
34670 + * BB Do not bother to decode buf since no local inode yet to put
34671 + * timestamps in, but we can reuse it safely.
34672 + */
34673 +
34674 +- pdev = (struct win_dev *)buf;
34675 ++ pdev = (struct win_dev *)&buf.fi;
34676 + io_parms.pid = current->tgid;
34677 + io_parms.tcon = tcon;
34678 + io_parms.offset = 0;
34679 + io_parms.length = sizeof(struct win_dev);
34680 +- iov[1].iov_base = buf;
34681 ++ iov[1].iov_base = &buf.fi;
34682 + iov[1].iov_len = sizeof(struct win_dev);
34683 + if (S_ISCHR(mode)) {
34684 + memcpy(pdev->type, "IntxCHR", 8);
34685 +@@ -5206,8 +5136,8 @@ smb2_make_node(unsigned int xid, struct inode *inode,
34686 + d_drop(dentry);
34687 +
34688 + /* FIXME: add code here to set EAs */
34689 +-out:
34690 +- kfree(buf);
34691 ++
34692 ++ cifs_free_open_info(&buf);
34693 + return rc;
34694 + }
34695 +
34696 +diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c
34697 +index 92a1d0695ebdf..aa0245268d40e 100644
34698 +--- a/fs/cifs/smb2pdu.c
34699 ++++ b/fs/cifs/smb2pdu.c
34700 +@@ -1345,7 +1345,13 @@ SMB2_sess_alloc_buffer(struct SMB2_sess_data *sess_data)
34701 + static void
34702 + SMB2_sess_free_buffer(struct SMB2_sess_data *sess_data)
34703 + {
34704 +- free_rsp_buf(sess_data->buf0_type, sess_data->iov[0].iov_base);
34705 ++ struct kvec *iov = sess_data->iov;
34706 ++
34707 ++ /* iov[1] is already freed by caller */
34708 ++ if (sess_data->buf0_type != CIFS_NO_BUFFER && iov[0].iov_base)
34709 ++ memzero_explicit(iov[0].iov_base, iov[0].iov_len);
34710 ++
34711 ++ free_rsp_buf(sess_data->buf0_type, iov[0].iov_base);
34712 + sess_data->buf0_type = CIFS_NO_BUFFER;
34713 + }
34714 +
34715 +@@ -1477,6 +1483,8 @@ SMB2_auth_kerberos(struct SMB2_sess_data *sess_data)
34716 + out_put_spnego_key:
34717 + key_invalidate(spnego_key);
34718 + key_put(spnego_key);
34719 ++ if (rc)
34720 ++ kfree_sensitive(ses->auth_key.response);
34721 + out:
34722 + sess_data->result = rc;
34723 + sess_data->func = NULL;
34724 +@@ -1573,7 +1581,7 @@ SMB2_sess_auth_rawntlmssp_negotiate(struct SMB2_sess_data *sess_data)
34725 + }
34726 +
34727 + out:
34728 +- kfree(ntlmssp_blob);
34729 ++ kfree_sensitive(ntlmssp_blob);
34730 + SMB2_sess_free_buffer(sess_data);
34731 + if (!rc) {
34732 + sess_data->result = 0;
34733 +@@ -1581,7 +1589,7 @@ out:
34734 + return;
34735 + }
34736 + out_err:
34737 +- kfree(ses->ntlmssp);
34738 ++ kfree_sensitive(ses->ntlmssp);
34739 + ses->ntlmssp = NULL;
34740 + sess_data->result = rc;
34741 + sess_data->func = NULL;
34742 +@@ -1657,9 +1665,9 @@ SMB2_sess_auth_rawntlmssp_authenticate(struct SMB2_sess_data *sess_data)
34743 + }
34744 + #endif
34745 + out:
34746 +- kfree(ntlmssp_blob);
34747 ++ kfree_sensitive(ntlmssp_blob);
34748 + SMB2_sess_free_buffer(sess_data);
34749 +- kfree(ses->ntlmssp);
34750 ++ kfree_sensitive(ses->ntlmssp);
34751 + ses->ntlmssp = NULL;
34752 + sess_data->result = rc;
34753 + sess_data->func = NULL;
34754 +@@ -1737,7 +1745,7 @@ SMB2_sess_setup(const unsigned int xid, struct cifs_ses *ses,
34755 + cifs_server_dbg(VFS, "signing requested but authenticated as guest\n");
34756 + rc = sess_data->result;
34757 + out:
34758 +- kfree(sess_data);
34759 ++ kfree_sensitive(sess_data);
34760 + return rc;
34761 + }
34762 +
34763 +diff --git a/fs/cifs/smb2pdu.h b/fs/cifs/smb2pdu.h
34764 +index f57881b8464fb..1237bb86e93a8 100644
34765 +--- a/fs/cifs/smb2pdu.h
34766 ++++ b/fs/cifs/smb2pdu.h
34767 +@@ -56,6 +56,9 @@ struct smb2_rdma_crypto_transform {
34768 +
34769 + #define COMPOUND_FID 0xFFFFFFFFFFFFFFFFULL
34770 +
34771 ++#define SMB2_SYMLINK_STRUCT_SIZE \
34772 ++ (sizeof(struct smb2_err_rsp) - 1 + sizeof(struct smb2_symlink_err_rsp))
34773 ++
34774 + #define SYMLINK_ERROR_TAG 0x4c4d5953
34775 +
34776 + struct smb2_symlink_err_rsp {
34777 +diff --git a/fs/cifs/smb2proto.h b/fs/cifs/smb2proto.h
34778 +index 3f740f24b96a7..7818d0b835672 100644
34779 +--- a/fs/cifs/smb2proto.h
34780 ++++ b/fs/cifs/smb2proto.h
34781 +@@ -53,16 +53,12 @@ extern bool smb2_is_valid_oplock_break(char *buffer,
34782 + struct TCP_Server_Info *srv);
34783 + extern int smb3_handle_read_data(struct TCP_Server_Info *server,
34784 + struct mid_q_entry *mid);
34785 +-
34786 +-extern void move_smb2_info_to_cifs(FILE_ALL_INFO *dst,
34787 +- struct smb2_file_all_info *src);
34788 + extern int smb2_query_reparse_tag(const unsigned int xid, struct cifs_tcon *tcon,
34789 + struct cifs_sb_info *cifs_sb, const char *path,
34790 + __u32 *reparse_tag);
34791 +-extern int smb2_query_path_info(const unsigned int xid, struct cifs_tcon *tcon,
34792 +- struct cifs_sb_info *cifs_sb,
34793 +- const char *full_path, FILE_ALL_INFO *data,
34794 +- bool *adjust_tz, bool *symlink);
34795 ++int smb2_query_path_info(const unsigned int xid, struct cifs_tcon *tcon,
34796 ++ struct cifs_sb_info *cifs_sb, const char *full_path,
34797 ++ struct cifs_open_info_data *data, bool *adjust_tz, bool *reparse);
34798 + extern int smb2_set_path_size(const unsigned int xid, struct cifs_tcon *tcon,
34799 + const char *full_path, __u64 size,
34800 + struct cifs_sb_info *cifs_sb, bool set_alloc);
34801 +@@ -95,9 +91,9 @@ extern int smb3_query_mf_symlink(unsigned int xid, struct cifs_tcon *tcon,
34802 + struct cifs_sb_info *cifs_sb,
34803 + const unsigned char *path, char *pbuf,
34804 + unsigned int *pbytes_read);
34805 +-extern int smb2_open_file(const unsigned int xid,
34806 +- struct cifs_open_parms *oparms,
34807 +- __u32 *oplock, FILE_ALL_INFO *buf);
34808 ++int smb2_parse_symlink_response(struct cifs_sb_info *cifs_sb, const struct kvec *iov, char **path);
34809 ++int smb2_open_file(const unsigned int xid, struct cifs_open_parms *oparms, __u32 *oplock,
34810 ++ void *buf);
34811 + extern int smb2_unlock_range(struct cifsFileInfo *cfile,
34812 + struct file_lock *flock, const unsigned int xid);
34813 + extern int smb2_push_mandatory_locks(struct cifsFileInfo *cfile);
34814 +@@ -278,9 +274,9 @@ extern int smb2_query_info_compound(const unsigned int xid,
34815 + struct kvec *rsp, int *buftype,
34816 + struct cifs_sb_info *cifs_sb);
34817 + /* query path info from the server using SMB311 POSIX extensions*/
34818 +-extern int smb311_posix_query_path_info(const unsigned int xid, struct cifs_tcon *tcon,
34819 +- struct cifs_sb_info *sb, const char *path, struct smb311_posix_qinfo *qinf,
34820 +- bool *adjust_tx, bool *symlink);
34821 ++int smb311_posix_query_path_info(const unsigned int xid, struct cifs_tcon *tcon,
34822 ++ struct cifs_sb_info *cifs_sb, const char *full_path,
34823 ++ struct cifs_open_info_data *data, bool *adjust_tz, bool *reparse);
34824 + int posix_info_parse(const void *beg, const void *end,
34825 + struct smb2_posix_info_parsed *out);
34826 + int posix_info_sid_size(const void *beg, const void *end);
34827 +diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
34828 +index d1f9d26322027..ec6519e1ca3bf 100644
34829 +--- a/fs/configfs/dir.c
34830 ++++ b/fs/configfs/dir.c
34831 +@@ -316,6 +316,7 @@ static int configfs_create_dir(struct config_item *item, struct dentry *dentry,
34832 + return 0;
34833 +
34834 + out_remove:
34835 ++ configfs_put(dentry->d_fsdata);
34836 + configfs_remove_dirent(dentry);
34837 + return PTR_ERR(inode);
34838 + }
34839 +@@ -382,6 +383,7 @@ int configfs_create_link(struct configfs_dirent *target, struct dentry *parent,
34840 + return 0;
34841 +
34842 + out_remove:
34843 ++ configfs_put(dentry->d_fsdata);
34844 + configfs_remove_dirent(dentry);
34845 + return PTR_ERR(inode);
34846 + }
34847 +diff --git a/fs/debugfs/file.c b/fs/debugfs/file.c
34848 +index 950c63fa4d0b2..38930d9b0bb73 100644
34849 +--- a/fs/debugfs/file.c
34850 ++++ b/fs/debugfs/file.c
34851 +@@ -378,8 +378,8 @@ ssize_t debugfs_attr_read(struct file *file, char __user *buf,
34852 + }
34853 + EXPORT_SYMBOL_GPL(debugfs_attr_read);
34854 +
34855 +-ssize_t debugfs_attr_write(struct file *file, const char __user *buf,
34856 +- size_t len, loff_t *ppos)
34857 ++static ssize_t debugfs_attr_write_xsigned(struct file *file, const char __user *buf,
34858 ++ size_t len, loff_t *ppos, bool is_signed)
34859 + {
34860 + struct dentry *dentry = F_DENTRY(file);
34861 + ssize_t ret;
34862 +@@ -387,12 +387,28 @@ ssize_t debugfs_attr_write(struct file *file, const char __user *buf,
34863 + ret = debugfs_file_get(dentry);
34864 + if (unlikely(ret))
34865 + return ret;
34866 +- ret = simple_attr_write(file, buf, len, ppos);
34867 ++ if (is_signed)
34868 ++ ret = simple_attr_write_signed(file, buf, len, ppos);
34869 ++ else
34870 ++ ret = simple_attr_write(file, buf, len, ppos);
34871 + debugfs_file_put(dentry);
34872 + return ret;
34873 + }
34874 ++
34875 ++ssize_t debugfs_attr_write(struct file *file, const char __user *buf,
34876 ++ size_t len, loff_t *ppos)
34877 ++{
34878 ++ return debugfs_attr_write_xsigned(file, buf, len, ppos, false);
34879 ++}
34880 + EXPORT_SYMBOL_GPL(debugfs_attr_write);
34881 +
34882 ++ssize_t debugfs_attr_write_signed(struct file *file, const char __user *buf,
34883 ++ size_t len, loff_t *ppos)
34884 ++{
34885 ++ return debugfs_attr_write_xsigned(file, buf, len, ppos, true);
34886 ++}
34887 ++EXPORT_SYMBOL_GPL(debugfs_attr_write_signed);
34888 ++
34889 + static struct dentry *debugfs_create_mode_unsafe(const char *name, umode_t mode,
34890 + struct dentry *parent, void *value,
34891 + const struct file_operations *fops,
34892 +@@ -738,11 +754,11 @@ static int debugfs_atomic_t_get(void *data, u64 *val)
34893 + *val = atomic_read((atomic_t *)data);
34894 + return 0;
34895 + }
34896 +-DEFINE_DEBUGFS_ATTRIBUTE(fops_atomic_t, debugfs_atomic_t_get,
34897 ++DEFINE_DEBUGFS_ATTRIBUTE_SIGNED(fops_atomic_t, debugfs_atomic_t_get,
34898 + debugfs_atomic_t_set, "%lld\n");
34899 +-DEFINE_DEBUGFS_ATTRIBUTE(fops_atomic_t_ro, debugfs_atomic_t_get, NULL,
34900 ++DEFINE_DEBUGFS_ATTRIBUTE_SIGNED(fops_atomic_t_ro, debugfs_atomic_t_get, NULL,
34901 + "%lld\n");
34902 +-DEFINE_DEBUGFS_ATTRIBUTE(fops_atomic_t_wo, NULL, debugfs_atomic_t_set,
34903 ++DEFINE_DEBUGFS_ATTRIBUTE_SIGNED(fops_atomic_t_wo, NULL, debugfs_atomic_t_set,
34904 + "%lld\n");
34905 +
34906 + /**
34907 +diff --git a/fs/erofs/decompressor.c b/fs/erofs/decompressor.c
34908 +index 2d55569f96ace..51b7ac7166d96 100644
34909 +--- a/fs/erofs/decompressor.c
34910 ++++ b/fs/erofs/decompressor.c
34911 +@@ -317,52 +317,61 @@ dstmap_out:
34912 + return ret;
34913 + }
34914 +
34915 +-static int z_erofs_shifted_transform(struct z_erofs_decompress_req *rq,
34916 +- struct page **pagepool)
34917 ++static int z_erofs_transform_plain(struct z_erofs_decompress_req *rq,
34918 ++ struct page **pagepool)
34919 + {
34920 +- const unsigned int nrpages_out =
34921 ++ const unsigned int inpages = PAGE_ALIGN(rq->inputsize) >> PAGE_SHIFT;
34922 ++ const unsigned int outpages =
34923 + PAGE_ALIGN(rq->pageofs_out + rq->outputsize) >> PAGE_SHIFT;
34924 + const unsigned int righthalf = min_t(unsigned int, rq->outputsize,
34925 + PAGE_SIZE - rq->pageofs_out);
34926 + const unsigned int lefthalf = rq->outputsize - righthalf;
34927 ++ const unsigned int interlaced_offset =
34928 ++ rq->alg == Z_EROFS_COMPRESSION_SHIFTED ? 0 : rq->pageofs_out;
34929 + unsigned char *src, *dst;
34930 +
34931 +- if (nrpages_out > 2) {
34932 ++ if (outpages > 2 && rq->alg == Z_EROFS_COMPRESSION_SHIFTED) {
34933 + DBG_BUGON(1);
34934 +- return -EIO;
34935 ++ return -EFSCORRUPTED;
34936 + }
34937 +
34938 + if (rq->out[0] == *rq->in) {
34939 +- DBG_BUGON(nrpages_out != 1);
34940 ++ DBG_BUGON(rq->pageofs_out);
34941 + return 0;
34942 + }
34943 +
34944 +- src = kmap_atomic(*rq->in) + rq->pageofs_in;
34945 ++ src = kmap_local_page(rq->in[inpages - 1]) + rq->pageofs_in;
34946 + if (rq->out[0]) {
34947 +- dst = kmap_atomic(rq->out[0]);
34948 +- memcpy(dst + rq->pageofs_out, src, righthalf);
34949 +- kunmap_atomic(dst);
34950 ++ dst = kmap_local_page(rq->out[0]);
34951 ++ memcpy(dst + rq->pageofs_out, src + interlaced_offset,
34952 ++ righthalf);
34953 ++ kunmap_local(dst);
34954 + }
34955 +
34956 +- if (nrpages_out == 2) {
34957 +- DBG_BUGON(!rq->out[1]);
34958 +- if (rq->out[1] == *rq->in) {
34959 ++ if (outpages > inpages) {
34960 ++ DBG_BUGON(!rq->out[outpages - 1]);
34961 ++ if (rq->out[outpages - 1] != rq->in[inpages - 1]) {
34962 ++ dst = kmap_local_page(rq->out[outpages - 1]);
34963 ++ memcpy(dst, interlaced_offset ? src :
34964 ++ (src + righthalf), lefthalf);
34965 ++ kunmap_local(dst);
34966 ++ } else if (!interlaced_offset) {
34967 + memmove(src, src + righthalf, lefthalf);
34968 +- } else {
34969 +- dst = kmap_atomic(rq->out[1]);
34970 +- memcpy(dst, src + righthalf, lefthalf);
34971 +- kunmap_atomic(dst);
34972 + }
34973 + }
34974 +- kunmap_atomic(src);
34975 ++ kunmap_local(src);
34976 + return 0;
34977 + }
34978 +
34979 + static struct z_erofs_decompressor decompressors[] = {
34980 + [Z_EROFS_COMPRESSION_SHIFTED] = {
34981 +- .decompress = z_erofs_shifted_transform,
34982 ++ .decompress = z_erofs_transform_plain,
34983 + .name = "shifted"
34984 + },
34985 ++ [Z_EROFS_COMPRESSION_INTERLACED] = {
34986 ++ .decompress = z_erofs_transform_plain,
34987 ++ .name = "interlaced"
34988 ++ },
34989 + [Z_EROFS_COMPRESSION_LZ4] = {
34990 + .decompress = z_erofs_lz4_decompress,
34991 + .name = "lz4"
34992 +diff --git a/fs/erofs/erofs_fs.h b/fs/erofs/erofs_fs.h
34993 +index 2b48373f690b6..5c1de6d7ad71f 100644
34994 +--- a/fs/erofs/erofs_fs.h
34995 ++++ b/fs/erofs/erofs_fs.h
34996 +@@ -295,11 +295,13 @@ struct z_erofs_lzma_cfgs {
34997 + * bit 1 : HEAD1 big pcluster (0 - off; 1 - on)
34998 + * bit 2 : HEAD2 big pcluster (0 - off; 1 - on)
34999 + * bit 3 : tailpacking inline pcluster (0 - off; 1 - on)
35000 ++ * bit 4 : interlaced plain pcluster (0 - off; 1 - on)
35001 + */
35002 + #define Z_EROFS_ADVISE_COMPACTED_2B 0x0001
35003 + #define Z_EROFS_ADVISE_BIG_PCLUSTER_1 0x0002
35004 + #define Z_EROFS_ADVISE_BIG_PCLUSTER_2 0x0004
35005 + #define Z_EROFS_ADVISE_INLINE_PCLUSTER 0x0008
35006 ++#define Z_EROFS_ADVISE_INTERLACED_PCLUSTER 0x0010
35007 +
35008 + struct z_erofs_map_header {
35009 + __le16 h_reserved1;
35010 +diff --git a/fs/erofs/internal.h b/fs/erofs/internal.h
35011 +index a01cc82795a25..12d075dfb964b 100644
35012 +--- a/fs/erofs/internal.h
35013 ++++ b/fs/erofs/internal.h
35014 +@@ -407,6 +407,7 @@ struct erofs_map_blocks {
35015 +
35016 + enum {
35017 + Z_EROFS_COMPRESSION_SHIFTED = Z_EROFS_COMPRESSION_MAX,
35018 ++ Z_EROFS_COMPRESSION_INTERLACED,
35019 + Z_EROFS_COMPRESSION_RUNTIME_MAX
35020 + };
35021 +
35022 +diff --git a/fs/erofs/zdata.c b/fs/erofs/zdata.c
35023 +index c7511b4317763..f19875d96cc1f 100644
35024 +--- a/fs/erofs/zdata.c
35025 ++++ b/fs/erofs/zdata.c
35026 +@@ -487,7 +487,8 @@ static int z_erofs_register_pcluster(struct z_erofs_decompress_frontend *fe)
35027 + struct erofs_workgroup *grp;
35028 + int err;
35029 +
35030 +- if (!(map->m_flags & EROFS_MAP_ENCODED)) {
35031 ++ if (!(map->m_flags & EROFS_MAP_ENCODED) ||
35032 ++ (!ztailpacking && !(map->m_pa >> PAGE_SHIFT))) {
35033 + DBG_BUGON(1);
35034 + return -EFSCORRUPTED;
35035 + }
35036 +diff --git a/fs/erofs/zmap.c b/fs/erofs/zmap.c
35037 +index 63fd2f1460265..720d74b5c699d 100644
35038 +--- a/fs/erofs/zmap.c
35039 ++++ b/fs/erofs/zmap.c
35040 +@@ -673,15 +673,26 @@ static int z_erofs_do_map_blocks(struct inode *inode,
35041 + map->m_pa = blknr_to_addr(m.pblk);
35042 + err = z_erofs_get_extent_compressedlen(&m, initial_lcn);
35043 + if (err)
35044 +- goto out;
35045 ++ goto unmap_out;
35046 + }
35047 +
35048 +- if (m.headtype == Z_EROFS_VLE_CLUSTER_TYPE_PLAIN)
35049 +- map->m_algorithmformat = Z_EROFS_COMPRESSION_SHIFTED;
35050 +- else if (m.headtype == Z_EROFS_VLE_CLUSTER_TYPE_HEAD2)
35051 ++ if (m.headtype == Z_EROFS_VLE_CLUSTER_TYPE_PLAIN) {
35052 ++ if (map->m_llen > map->m_plen) {
35053 ++ DBG_BUGON(1);
35054 ++ err = -EFSCORRUPTED;
35055 ++ goto unmap_out;
35056 ++ }
35057 ++ if (vi->z_advise & Z_EROFS_ADVISE_INTERLACED_PCLUSTER)
35058 ++ map->m_algorithmformat =
35059 ++ Z_EROFS_COMPRESSION_INTERLACED;
35060 ++ else
35061 ++ map->m_algorithmformat =
35062 ++ Z_EROFS_COMPRESSION_SHIFTED;
35063 ++ } else if (m.headtype == Z_EROFS_VLE_CLUSTER_TYPE_HEAD2) {
35064 + map->m_algorithmformat = vi->z_algorithmtype[1];
35065 +- else
35066 ++ } else {
35067 + map->m_algorithmformat = vi->z_algorithmtype[0];
35068 ++ }
35069 +
35070 + if ((flags & EROFS_GET_BLOCKS_FIEMAP) ||
35071 + ((flags & EROFS_GET_BLOCKS_READMORE) &&
35072 +@@ -691,14 +702,12 @@ static int z_erofs_do_map_blocks(struct inode *inode,
35073 + if (!err)
35074 + map->m_flags |= EROFS_MAP_FULL_MAPPED;
35075 + }
35076 ++
35077 + unmap_out:
35078 + erofs_unmap_metabuf(&m.map->buf);
35079 +-
35080 +-out:
35081 + erofs_dbg("%s, m_la %llu m_pa %llu m_llen %llu m_plen %llu m_flags 0%o",
35082 + __func__, map->m_la, map->m_pa,
35083 + map->m_llen, map->m_plen, map->m_flags);
35084 +-
35085 + return err;
35086 + }
35087 +
35088 +diff --git a/fs/f2fs/compress.c b/fs/f2fs/compress.c
35089 +index 70e97075e535e..e70928e92b2cd 100644
35090 +--- a/fs/f2fs/compress.c
35091 ++++ b/fs/f2fs/compress.c
35092 +@@ -346,7 +346,7 @@ static int zstd_init_compress_ctx(struct compress_ctx *cc)
35093 + if (!level)
35094 + level = F2FS_ZSTD_DEFAULT_CLEVEL;
35095 +
35096 +- params = zstd_get_params(F2FS_ZSTD_DEFAULT_CLEVEL, cc->rlen);
35097 ++ params = zstd_get_params(level, cc->rlen);
35098 + workspace_size = zstd_cstream_workspace_bound(&params.cParams);
35099 +
35100 + workspace = f2fs_kvmalloc(F2FS_I_SB(cc->inode),
35101 +diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
35102 +index 1e57b11ffe2a6..a7227640fbdf2 100644
35103 +--- a/fs/f2fs/f2fs.h
35104 ++++ b/fs/f2fs/f2fs.h
35105 +@@ -2966,7 +2966,7 @@ static inline void f2fs_change_bit(unsigned int nr, char *addr)
35106 + /* Flags that should be inherited by new inodes from their parent. */
35107 + #define F2FS_FL_INHERITED (F2FS_SYNC_FL | F2FS_NODUMP_FL | F2FS_NOATIME_FL | \
35108 + F2FS_DIRSYNC_FL | F2FS_PROJINHERIT_FL | \
35109 +- F2FS_CASEFOLD_FL | F2FS_COMPR_FL | F2FS_NOCOMP_FL)
35110 ++ F2FS_CASEFOLD_FL)
35111 +
35112 + /* Flags that are appropriate for regular files (all but dir-specific ones). */
35113 + #define F2FS_REG_FLMASK (~(F2FS_DIRSYNC_FL | F2FS_PROJINHERIT_FL | \
35114 +diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
35115 +index ce4905a073b3c..74337edcbbb09 100644
35116 +--- a/fs/f2fs/file.c
35117 ++++ b/fs/f2fs/file.c
35118 +@@ -1866,6 +1866,10 @@ static int f2fs_setflags_common(struct inode *inode, u32 iflags, u32 mask)
35119 + if (!f2fs_disable_compressed_file(inode))
35120 + return -EINVAL;
35121 + } else {
35122 ++ /* try to convert inline_data to support compression */
35123 ++ int err = f2fs_convert_inline_inode(inode);
35124 ++ if (err)
35125 ++ return err;
35126 + if (!f2fs_may_compress(inode))
35127 + return -EINVAL;
35128 + if (S_ISREG(inode->i_mode) && F2FS_HAS_BLOCKS(inode))
35129 +diff --git a/fs/f2fs/gc.c b/fs/f2fs/gc.c
35130 +index 73881314bdda8..68eb1d33128be 100644
35131 +--- a/fs/f2fs/gc.c
35132 ++++ b/fs/f2fs/gc.c
35133 +@@ -1738,8 +1738,9 @@ freed:
35134 + get_valid_blocks(sbi, segno, false) == 0)
35135 + seg_freed++;
35136 +
35137 +- if (__is_large_section(sbi) && segno + 1 < end_segno)
35138 +- sbi->next_victim_seg[gc_type] = segno + 1;
35139 ++ if (__is_large_section(sbi))
35140 ++ sbi->next_victim_seg[gc_type] =
35141 ++ (segno + 1 < end_segno) ? segno + 1 : NULL_SEGNO;
35142 + skip:
35143 + f2fs_put_page(sum_page, 0);
35144 + }
35145 +@@ -2127,8 +2128,6 @@ out_unlock:
35146 + if (err)
35147 + return err;
35148 +
35149 +- set_sbi_flag(sbi, SBI_IS_RESIZEFS);
35150 +-
35151 + freeze_super(sbi->sb);
35152 + f2fs_down_write(&sbi->gc_lock);
35153 + f2fs_down_write(&sbi->cp_global_sem);
35154 +@@ -2144,6 +2143,7 @@ out_unlock:
35155 + if (err)
35156 + goto out_err;
35157 +
35158 ++ set_sbi_flag(sbi, SBI_IS_RESIZEFS);
35159 + err = free_segment_range(sbi, secs, false);
35160 + if (err)
35161 + goto recover_out;
35162 +@@ -2167,6 +2167,7 @@ out_unlock:
35163 + f2fs_commit_super(sbi, false);
35164 + }
35165 + recover_out:
35166 ++ clear_sbi_flag(sbi, SBI_IS_RESIZEFS);
35167 + if (err) {
35168 + set_sbi_flag(sbi, SBI_NEED_FSCK);
35169 + f2fs_err(sbi, "resize_fs failed, should run fsck to repair!");
35170 +@@ -2179,6 +2180,5 @@ out_err:
35171 + f2fs_up_write(&sbi->cp_global_sem);
35172 + f2fs_up_write(&sbi->gc_lock);
35173 + thaw_super(sbi->sb);
35174 +- clear_sbi_flag(sbi, SBI_IS_RESIZEFS);
35175 + return err;
35176 + }
35177 +diff --git a/fs/f2fs/namei.c b/fs/f2fs/namei.c
35178 +index bf00d5057abb8..0073e3511b2ad 100644
35179 +--- a/fs/f2fs/namei.c
35180 ++++ b/fs/f2fs/namei.c
35181 +@@ -22,8 +22,163 @@
35182 + #include "acl.h"
35183 + #include <trace/events/f2fs.h>
35184 +
35185 ++static inline int is_extension_exist(const unsigned char *s, const char *sub,
35186 ++ bool tmp_ext)
35187 ++{
35188 ++ size_t slen = strlen(s);
35189 ++ size_t sublen = strlen(sub);
35190 ++ int i;
35191 ++
35192 ++ if (sublen == 1 && *sub == '*')
35193 ++ return 1;
35194 ++
35195 ++ /*
35196 ++ * filename format of multimedia file should be defined as:
35197 ++ * "filename + '.' + extension + (optional: '.' + temp extension)".
35198 ++ */
35199 ++ if (slen < sublen + 2)
35200 ++ return 0;
35201 ++
35202 ++ if (!tmp_ext) {
35203 ++ /* file has no temp extension */
35204 ++ if (s[slen - sublen - 1] != '.')
35205 ++ return 0;
35206 ++ return !strncasecmp(s + slen - sublen, sub, sublen);
35207 ++ }
35208 ++
35209 ++ for (i = 1; i < slen - sublen; i++) {
35210 ++ if (s[i] != '.')
35211 ++ continue;
35212 ++ if (!strncasecmp(s + i + 1, sub, sublen))
35213 ++ return 1;
35214 ++ }
35215 ++
35216 ++ return 0;
35217 ++}
35218 ++
35219 ++int f2fs_update_extension_list(struct f2fs_sb_info *sbi, const char *name,
35220 ++ bool hot, bool set)
35221 ++{
35222 ++ __u8 (*extlist)[F2FS_EXTENSION_LEN] = sbi->raw_super->extension_list;
35223 ++ int cold_count = le32_to_cpu(sbi->raw_super->extension_count);
35224 ++ int hot_count = sbi->raw_super->hot_ext_count;
35225 ++ int total_count = cold_count + hot_count;
35226 ++ int start, count;
35227 ++ int i;
35228 ++
35229 ++ if (set) {
35230 ++ if (total_count == F2FS_MAX_EXTENSION)
35231 ++ return -EINVAL;
35232 ++ } else {
35233 ++ if (!hot && !cold_count)
35234 ++ return -EINVAL;
35235 ++ if (hot && !hot_count)
35236 ++ return -EINVAL;
35237 ++ }
35238 ++
35239 ++ if (hot) {
35240 ++ start = cold_count;
35241 ++ count = total_count;
35242 ++ } else {
35243 ++ start = 0;
35244 ++ count = cold_count;
35245 ++ }
35246 ++
35247 ++ for (i = start; i < count; i++) {
35248 ++ if (strcmp(name, extlist[i]))
35249 ++ continue;
35250 ++
35251 ++ if (set)
35252 ++ return -EINVAL;
35253 ++
35254 ++ memcpy(extlist[i], extlist[i + 1],
35255 ++ F2FS_EXTENSION_LEN * (total_count - i - 1));
35256 ++ memset(extlist[total_count - 1], 0, F2FS_EXTENSION_LEN);
35257 ++ if (hot)
35258 ++ sbi->raw_super->hot_ext_count = hot_count - 1;
35259 ++ else
35260 ++ sbi->raw_super->extension_count =
35261 ++ cpu_to_le32(cold_count - 1);
35262 ++ return 0;
35263 ++ }
35264 ++
35265 ++ if (!set)
35266 ++ return -EINVAL;
35267 ++
35268 ++ if (hot) {
35269 ++ memcpy(extlist[count], name, strlen(name));
35270 ++ sbi->raw_super->hot_ext_count = hot_count + 1;
35271 ++ } else {
35272 ++ char buf[F2FS_MAX_EXTENSION][F2FS_EXTENSION_LEN];
35273 ++
35274 ++ memcpy(buf, &extlist[cold_count],
35275 ++ F2FS_EXTENSION_LEN * hot_count);
35276 ++ memset(extlist[cold_count], 0, F2FS_EXTENSION_LEN);
35277 ++ memcpy(extlist[cold_count], name, strlen(name));
35278 ++ memcpy(&extlist[cold_count + 1], buf,
35279 ++ F2FS_EXTENSION_LEN * hot_count);
35280 ++ sbi->raw_super->extension_count = cpu_to_le32(cold_count + 1);
35281 ++ }
35282 ++ return 0;
35283 ++}
35284 ++
35285 ++static void set_compress_new_inode(struct f2fs_sb_info *sbi, struct inode *dir,
35286 ++ struct inode *inode, const unsigned char *name)
35287 ++{
35288 ++ __u8 (*extlist)[F2FS_EXTENSION_LEN] = sbi->raw_super->extension_list;
35289 ++ unsigned char (*noext)[F2FS_EXTENSION_LEN] =
35290 ++ F2FS_OPTION(sbi).noextensions;
35291 ++ unsigned char (*ext)[F2FS_EXTENSION_LEN] = F2FS_OPTION(sbi).extensions;
35292 ++ unsigned char ext_cnt = F2FS_OPTION(sbi).compress_ext_cnt;
35293 ++ unsigned char noext_cnt = F2FS_OPTION(sbi).nocompress_ext_cnt;
35294 ++ int i, cold_count, hot_count;
35295 ++
35296 ++ if (!f2fs_sb_has_compression(sbi))
35297 ++ return;
35298 ++
35299 ++ if (S_ISDIR(inode->i_mode))
35300 ++ goto inherit_comp;
35301 ++
35302 ++ /* This name comes only from normal files. */
35303 ++ if (!name)
35304 ++ return;
35305 ++
35306 ++ /* Don't compress hot files. */
35307 ++ f2fs_down_read(&sbi->sb_lock);
35308 ++ cold_count = le32_to_cpu(sbi->raw_super->extension_count);
35309 ++ hot_count = sbi->raw_super->hot_ext_count;
35310 ++ for (i = cold_count; i < cold_count + hot_count; i++)
35311 ++ if (is_extension_exist(name, extlist[i], false))
35312 ++ break;
35313 ++ f2fs_up_read(&sbi->sb_lock);
35314 ++ if (i < (cold_count + hot_count))
35315 ++ return;
35316 ++
35317 ++ /* Don't compress unallowed extension. */
35318 ++ for (i = 0; i < noext_cnt; i++)
35319 ++ if (is_extension_exist(name, noext[i], false))
35320 ++ return;
35321 ++
35322 ++ /* Compress wanting extension. */
35323 ++ for (i = 0; i < ext_cnt; i++) {
35324 ++ if (is_extension_exist(name, ext[i], false)) {
35325 ++ set_compress_context(inode);
35326 ++ return;
35327 ++ }
35328 ++ }
35329 ++inherit_comp:
35330 ++ /* Inherit the {no-}compression flag in directory */
35331 ++ if (F2FS_I(dir)->i_flags & F2FS_NOCOMP_FL) {
35332 ++ F2FS_I(inode)->i_flags |= F2FS_NOCOMP_FL;
35333 ++ f2fs_mark_inode_dirty_sync(inode, true);
35334 ++ } else if (F2FS_I(dir)->i_flags & F2FS_COMPR_FL) {
35335 ++ set_compress_context(inode);
35336 ++ }
35337 ++}
35338 ++
35339 + static struct inode *f2fs_new_inode(struct user_namespace *mnt_userns,
35340 +- struct inode *dir, umode_t mode)
35341 ++ struct inode *dir, umode_t mode,
35342 ++ const char *name)
35343 + {
35344 + struct f2fs_sb_info *sbi = F2FS_I_SB(dir);
35345 + nid_t ino;
35346 +@@ -114,12 +269,8 @@ static struct inode *f2fs_new_inode(struct user_namespace *mnt_userns,
35347 + if (F2FS_I(inode)->i_flags & F2FS_PROJINHERIT_FL)
35348 + set_inode_flag(inode, FI_PROJ_INHERIT);
35349 +
35350 +- if (f2fs_sb_has_compression(sbi)) {
35351 +- /* Inherit the compression flag in directory */
35352 +- if ((F2FS_I(dir)->i_flags & F2FS_COMPR_FL) &&
35353 +- f2fs_may_compress(inode))
35354 +- set_compress_context(inode);
35355 +- }
35356 ++ /* Check compression first. */
35357 ++ set_compress_new_inode(sbi, dir, inode, name);
35358 +
35359 + /* Should enable inline_data after compression set */
35360 + if (test_opt(sbi, INLINE_DATA) && f2fs_may_inline_data(inode))
35361 +@@ -153,40 +304,6 @@ fail_drop:
35362 + return ERR_PTR(err);
35363 + }
35364 +
35365 +-static inline int is_extension_exist(const unsigned char *s, const char *sub,
35366 +- bool tmp_ext)
35367 +-{
35368 +- size_t slen = strlen(s);
35369 +- size_t sublen = strlen(sub);
35370 +- int i;
35371 +-
35372 +- if (sublen == 1 && *sub == '*')
35373 +- return 1;
35374 +-
35375 +- /*
35376 +- * filename format of multimedia file should be defined as:
35377 +- * "filename + '.' + extension + (optional: '.' + temp extension)".
35378 +- */
35379 +- if (slen < sublen + 2)
35380 +- return 0;
35381 +-
35382 +- if (!tmp_ext) {
35383 +- /* file has no temp extension */
35384 +- if (s[slen - sublen - 1] != '.')
35385 +- return 0;
35386 +- return !strncasecmp(s + slen - sublen, sub, sublen);
35387 +- }
35388 +-
35389 +- for (i = 1; i < slen - sublen; i++) {
35390 +- if (s[i] != '.')
35391 +- continue;
35392 +- if (!strncasecmp(s + i + 1, sub, sublen))
35393 +- return 1;
35394 +- }
35395 +-
35396 +- return 0;
35397 +-}
35398 +-
35399 + /*
35400 + * Set file's temperature for hot/cold data separation
35401 + */
35402 +@@ -217,124 +334,6 @@ static inline void set_file_temperature(struct f2fs_sb_info *sbi, struct inode *
35403 + file_set_hot(inode);
35404 + }
35405 +
35406 +-int f2fs_update_extension_list(struct f2fs_sb_info *sbi, const char *name,
35407 +- bool hot, bool set)
35408 +-{
35409 +- __u8 (*extlist)[F2FS_EXTENSION_LEN] = sbi->raw_super->extension_list;
35410 +- int cold_count = le32_to_cpu(sbi->raw_super->extension_count);
35411 +- int hot_count = sbi->raw_super->hot_ext_count;
35412 +- int total_count = cold_count + hot_count;
35413 +- int start, count;
35414 +- int i;
35415 +-
35416 +- if (set) {
35417 +- if (total_count == F2FS_MAX_EXTENSION)
35418 +- return -EINVAL;
35419 +- } else {
35420 +- if (!hot && !cold_count)
35421 +- return -EINVAL;
35422 +- if (hot && !hot_count)
35423 +- return -EINVAL;
35424 +- }
35425 +-
35426 +- if (hot) {
35427 +- start = cold_count;
35428 +- count = total_count;
35429 +- } else {
35430 +- start = 0;
35431 +- count = cold_count;
35432 +- }
35433 +-
35434 +- for (i = start; i < count; i++) {
35435 +- if (strcmp(name, extlist[i]))
35436 +- continue;
35437 +-
35438 +- if (set)
35439 +- return -EINVAL;
35440 +-
35441 +- memcpy(extlist[i], extlist[i + 1],
35442 +- F2FS_EXTENSION_LEN * (total_count - i - 1));
35443 +- memset(extlist[total_count - 1], 0, F2FS_EXTENSION_LEN);
35444 +- if (hot)
35445 +- sbi->raw_super->hot_ext_count = hot_count - 1;
35446 +- else
35447 +- sbi->raw_super->extension_count =
35448 +- cpu_to_le32(cold_count - 1);
35449 +- return 0;
35450 +- }
35451 +-
35452 +- if (!set)
35453 +- return -EINVAL;
35454 +-
35455 +- if (hot) {
35456 +- memcpy(extlist[count], name, strlen(name));
35457 +- sbi->raw_super->hot_ext_count = hot_count + 1;
35458 +- } else {
35459 +- char buf[F2FS_MAX_EXTENSION][F2FS_EXTENSION_LEN];
35460 +-
35461 +- memcpy(buf, &extlist[cold_count],
35462 +- F2FS_EXTENSION_LEN * hot_count);
35463 +- memset(extlist[cold_count], 0, F2FS_EXTENSION_LEN);
35464 +- memcpy(extlist[cold_count], name, strlen(name));
35465 +- memcpy(&extlist[cold_count + 1], buf,
35466 +- F2FS_EXTENSION_LEN * hot_count);
35467 +- sbi->raw_super->extension_count = cpu_to_le32(cold_count + 1);
35468 +- }
35469 +- return 0;
35470 +-}
35471 +-
35472 +-static void set_compress_inode(struct f2fs_sb_info *sbi, struct inode *inode,
35473 +- const unsigned char *name)
35474 +-{
35475 +- __u8 (*extlist)[F2FS_EXTENSION_LEN] = sbi->raw_super->extension_list;
35476 +- unsigned char (*noext)[F2FS_EXTENSION_LEN] = F2FS_OPTION(sbi).noextensions;
35477 +- unsigned char (*ext)[F2FS_EXTENSION_LEN] = F2FS_OPTION(sbi).extensions;
35478 +- unsigned char ext_cnt = F2FS_OPTION(sbi).compress_ext_cnt;
35479 +- unsigned char noext_cnt = F2FS_OPTION(sbi).nocompress_ext_cnt;
35480 +- int i, cold_count, hot_count;
35481 +-
35482 +- if (!f2fs_sb_has_compression(sbi) ||
35483 +- F2FS_I(inode)->i_flags & F2FS_NOCOMP_FL ||
35484 +- !f2fs_may_compress(inode) ||
35485 +- (!ext_cnt && !noext_cnt))
35486 +- return;
35487 +-
35488 +- f2fs_down_read(&sbi->sb_lock);
35489 +-
35490 +- cold_count = le32_to_cpu(sbi->raw_super->extension_count);
35491 +- hot_count = sbi->raw_super->hot_ext_count;
35492 +-
35493 +- for (i = cold_count; i < cold_count + hot_count; i++) {
35494 +- if (is_extension_exist(name, extlist[i], false)) {
35495 +- f2fs_up_read(&sbi->sb_lock);
35496 +- return;
35497 +- }
35498 +- }
35499 +-
35500 +- f2fs_up_read(&sbi->sb_lock);
35501 +-
35502 +- for (i = 0; i < noext_cnt; i++) {
35503 +- if (is_extension_exist(name, noext[i], false)) {
35504 +- f2fs_disable_compressed_file(inode);
35505 +- return;
35506 +- }
35507 +- }
35508 +-
35509 +- if (is_inode_flag_set(inode, FI_COMPRESSED_FILE))
35510 +- return;
35511 +-
35512 +- for (i = 0; i < ext_cnt; i++) {
35513 +- if (!is_extension_exist(name, ext[i], false))
35514 +- continue;
35515 +-
35516 +- /* Do not use inline_data with compression */
35517 +- stat_dec_inline_inode(inode);
35518 +- clear_inode_flag(inode, FI_INLINE_DATA);
35519 +- set_compress_context(inode);
35520 +- return;
35521 +- }
35522 +-}
35523 +-
35524 + static int f2fs_create(struct user_namespace *mnt_userns, struct inode *dir,
35525 + struct dentry *dentry, umode_t mode, bool excl)
35526 + {
35527 +@@ -352,15 +351,13 @@ static int f2fs_create(struct user_namespace *mnt_userns, struct inode *dir,
35528 + if (err)
35529 + return err;
35530 +
35531 +- inode = f2fs_new_inode(mnt_userns, dir, mode);
35532 ++ inode = f2fs_new_inode(mnt_userns, dir, mode, dentry->d_name.name);
35533 + if (IS_ERR(inode))
35534 + return PTR_ERR(inode);
35535 +
35536 + if (!test_opt(sbi, DISABLE_EXT_IDENTIFY))
35537 + set_file_temperature(sbi, inode, dentry->d_name.name);
35538 +
35539 +- set_compress_inode(sbi, inode, dentry->d_name.name);
35540 +-
35541 + inode->i_op = &f2fs_file_inode_operations;
35542 + inode->i_fop = &f2fs_file_operations;
35543 + inode->i_mapping->a_ops = &f2fs_dblock_aops;
35544 +@@ -689,7 +686,7 @@ static int f2fs_symlink(struct user_namespace *mnt_userns, struct inode *dir,
35545 + if (err)
35546 + return err;
35547 +
35548 +- inode = f2fs_new_inode(mnt_userns, dir, S_IFLNK | S_IRWXUGO);
35549 ++ inode = f2fs_new_inode(mnt_userns, dir, S_IFLNK | S_IRWXUGO, NULL);
35550 + if (IS_ERR(inode))
35551 + return PTR_ERR(inode);
35552 +
35553 +@@ -760,7 +757,7 @@ static int f2fs_mkdir(struct user_namespace *mnt_userns, struct inode *dir,
35554 + if (err)
35555 + return err;
35556 +
35557 +- inode = f2fs_new_inode(mnt_userns, dir, S_IFDIR | mode);
35558 ++ inode = f2fs_new_inode(mnt_userns, dir, S_IFDIR | mode, NULL);
35559 + if (IS_ERR(inode))
35560 + return PTR_ERR(inode);
35561 +
35562 +@@ -817,7 +814,7 @@ static int f2fs_mknod(struct user_namespace *mnt_userns, struct inode *dir,
35563 + if (err)
35564 + return err;
35565 +
35566 +- inode = f2fs_new_inode(mnt_userns, dir, mode);
35567 ++ inode = f2fs_new_inode(mnt_userns, dir, mode, NULL);
35568 + if (IS_ERR(inode))
35569 + return PTR_ERR(inode);
35570 +
35571 +@@ -856,7 +853,7 @@ static int __f2fs_tmpfile(struct user_namespace *mnt_userns, struct inode *dir,
35572 + if (err)
35573 + return err;
35574 +
35575 +- inode = f2fs_new_inode(mnt_userns, dir, mode);
35576 ++ inode = f2fs_new_inode(mnt_userns, dir, mode, NULL);
35577 + if (IS_ERR(inode))
35578 + return PTR_ERR(inode);
35579 +
35580 +diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c
35581 +index 84bad18ce13d5..2afed479160b8 100644
35582 +--- a/fs/f2fs/segment.c
35583 ++++ b/fs/f2fs/segment.c
35584 +@@ -1171,7 +1171,7 @@ submit:
35585 +
35586 + atomic_inc(&dcc->issued_discard);
35587 +
35588 +- f2fs_update_iostat(sbi, FS_DISCARD, 1);
35589 ++ f2fs_update_iostat(sbi, FS_DISCARD, len * F2FS_BLKSIZE);
35590 +
35591 + lstart += len;
35592 + start += len;
35593 +@@ -1449,7 +1449,7 @@ retry:
35594 + if (i + 1 < dpolicy->granularity)
35595 + break;
35596 +
35597 +- if (i < DEFAULT_DISCARD_GRANULARITY && dpolicy->ordered)
35598 ++ if (i + 1 < DEFAULT_DISCARD_GRANULARITY && dpolicy->ordered)
35599 + return __issue_discard_cmd_orderly(sbi, dpolicy);
35600 +
35601 + pend_list = &dcc->pend_list[i];
35602 +@@ -2026,8 +2026,10 @@ int f2fs_start_discard_thread(struct f2fs_sb_info *sbi)
35603 +
35604 + dcc->f2fs_issue_discard = kthread_run(issue_discard_thread, sbi,
35605 + "f2fs_discard-%u:%u", MAJOR(dev), MINOR(dev));
35606 +- if (IS_ERR(dcc->f2fs_issue_discard))
35607 ++ if (IS_ERR(dcc->f2fs_issue_discard)) {
35608 + err = PTR_ERR(dcc->f2fs_issue_discard);
35609 ++ dcc->f2fs_issue_discard = NULL;
35610 ++ }
35611 +
35612 + return err;
35613 + }
35614 +diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c
35615 +index 5415c06d8246f..1187f29dc8e0a 100644
35616 +--- a/fs/f2fs/super.c
35617 ++++ b/fs/f2fs/super.c
35618 +@@ -4460,9 +4460,9 @@ free_nm:
35619 + f2fs_destroy_node_manager(sbi);
35620 + free_sm:
35621 + f2fs_destroy_segment_manager(sbi);
35622 +- f2fs_destroy_post_read_wq(sbi);
35623 + stop_ckpt_thread:
35624 + f2fs_stop_ckpt_thread(sbi);
35625 ++ f2fs_destroy_post_read_wq(sbi);
35626 + free_devices:
35627 + destroy_device_list(sbi);
35628 + kvfree(sbi->ckpt);
35629 +diff --git a/fs/hfs/inode.c b/fs/hfs/inode.c
35630 +index c4526f16355d5..a0746be3c1de7 100644
35631 +--- a/fs/hfs/inode.c
35632 ++++ b/fs/hfs/inode.c
35633 +@@ -458,6 +458,8 @@ int hfs_write_inode(struct inode *inode, struct writeback_control *wbc)
35634 + /* panic? */
35635 + return -EIO;
35636 +
35637 ++ if (HFS_I(main_inode)->cat_key.CName.len > HFS_NAMELEN)
35638 ++ return -EIO;
35639 + fd.search_key->cat = HFS_I(main_inode)->cat_key;
35640 + if (hfs_brec_find(&fd))
35641 + /* panic? */
35642 +diff --git a/fs/hfs/trans.c b/fs/hfs/trans.c
35643 +index 39f5e343bf4d4..fdb0edb8a607d 100644
35644 +--- a/fs/hfs/trans.c
35645 ++++ b/fs/hfs/trans.c
35646 +@@ -109,7 +109,7 @@ void hfs_asc2mac(struct super_block *sb, struct hfs_name *out, const struct qstr
35647 + if (nls_io) {
35648 + wchar_t ch;
35649 +
35650 +- while (srclen > 0) {
35651 ++ while (srclen > 0 && dstlen > 0) {
35652 + size = nls_io->char2uni(src, srclen, &ch);
35653 + if (size < 0) {
35654 + ch = '?';
35655 +diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
35656 +index fbcfa6bfee805..26169d75f6cf7 100644
35657 +--- a/fs/hugetlbfs/inode.c
35658 ++++ b/fs/hugetlbfs/inode.c
35659 +@@ -1256,7 +1256,7 @@ static int hugetlbfs_parse_param(struct fs_context *fc, struct fs_parameter *par
35660 +
35661 + case Opt_size:
35662 + /* memparse() will accept a K/M/G without a digit */
35663 +- if (!isdigit(param->string[0]))
35664 ++ if (!param->string || !isdigit(param->string[0]))
35665 + goto bad_val;
35666 + ctx->max_size_opt = memparse(param->string, &rest);
35667 + ctx->max_val_type = SIZE_STD;
35668 +@@ -1266,7 +1266,7 @@ static int hugetlbfs_parse_param(struct fs_context *fc, struct fs_parameter *par
35669 +
35670 + case Opt_nr_inodes:
35671 + /* memparse() will accept a K/M/G without a digit */
35672 +- if (!isdigit(param->string[0]))
35673 ++ if (!param->string || !isdigit(param->string[0]))
35674 + goto bad_val;
35675 + ctx->nr_inodes = memparse(param->string, &rest);
35676 + return 0;
35677 +@@ -1282,7 +1282,7 @@ static int hugetlbfs_parse_param(struct fs_context *fc, struct fs_parameter *par
35678 +
35679 + case Opt_min_size:
35680 + /* memparse() will accept a K/M/G without a digit */
35681 +- if (!isdigit(param->string[0]))
35682 ++ if (!param->string || !isdigit(param->string[0]))
35683 + goto bad_val;
35684 + ctx->min_size_opt = memparse(param->string, &rest);
35685 + ctx->min_val_type = SIZE_STD;
35686 +diff --git a/fs/jfs/jfs_dmap.c b/fs/jfs/jfs_dmap.c
35687 +index 6b838d3ae7c2e..765838578a722 100644
35688 +--- a/fs/jfs/jfs_dmap.c
35689 ++++ b/fs/jfs/jfs_dmap.c
35690 +@@ -155,7 +155,7 @@ int dbMount(struct inode *ipbmap)
35691 + struct bmap *bmp;
35692 + struct dbmap_disk *dbmp_le;
35693 + struct metapage *mp;
35694 +- int i;
35695 ++ int i, err;
35696 +
35697 + /*
35698 + * allocate/initialize the in-memory bmap descriptor
35699 +@@ -170,8 +170,8 @@ int dbMount(struct inode *ipbmap)
35700 + BMAPBLKNO << JFS_SBI(ipbmap->i_sb)->l2nbperpage,
35701 + PSIZE, 0);
35702 + if (mp == NULL) {
35703 +- kfree(bmp);
35704 +- return -EIO;
35705 ++ err = -EIO;
35706 ++ goto err_kfree_bmp;
35707 + }
35708 +
35709 + /* copy the on-disk bmap descriptor to its in-memory version. */
35710 +@@ -181,9 +181,8 @@ int dbMount(struct inode *ipbmap)
35711 + bmp->db_l2nbperpage = le32_to_cpu(dbmp_le->dn_l2nbperpage);
35712 + bmp->db_numag = le32_to_cpu(dbmp_le->dn_numag);
35713 + if (!bmp->db_numag) {
35714 +- release_metapage(mp);
35715 +- kfree(bmp);
35716 +- return -EINVAL;
35717 ++ err = -EINVAL;
35718 ++ goto err_release_metapage;
35719 + }
35720 +
35721 + bmp->db_maxlevel = le32_to_cpu(dbmp_le->dn_maxlevel);
35722 +@@ -194,6 +193,16 @@ int dbMount(struct inode *ipbmap)
35723 + bmp->db_agwidth = le32_to_cpu(dbmp_le->dn_agwidth);
35724 + bmp->db_agstart = le32_to_cpu(dbmp_le->dn_agstart);
35725 + bmp->db_agl2size = le32_to_cpu(dbmp_le->dn_agl2size);
35726 ++ if (bmp->db_agl2size > L2MAXL2SIZE - L2MAXAG) {
35727 ++ err = -EINVAL;
35728 ++ goto err_release_metapage;
35729 ++ }
35730 ++
35731 ++ if (((bmp->db_mapsize - 1) >> bmp->db_agl2size) > MAXAG) {
35732 ++ err = -EINVAL;
35733 ++ goto err_release_metapage;
35734 ++ }
35735 ++
35736 + for (i = 0; i < MAXAG; i++)
35737 + bmp->db_agfree[i] = le64_to_cpu(dbmp_le->dn_agfree[i]);
35738 + bmp->db_agsize = le64_to_cpu(dbmp_le->dn_agsize);
35739 +@@ -214,6 +223,12 @@ int dbMount(struct inode *ipbmap)
35740 + BMAP_LOCK_INIT(bmp);
35741 +
35742 + return (0);
35743 ++
35744 ++err_release_metapage:
35745 ++ release_metapage(mp);
35746 ++err_kfree_bmp:
35747 ++ kfree(bmp);
35748 ++ return err;
35749 + }
35750 +
35751 +
35752 +diff --git a/fs/jfs/namei.c b/fs/jfs/namei.c
35753 +index 9db4f5789c0ec..4fbbf88435e69 100644
35754 +--- a/fs/jfs/namei.c
35755 ++++ b/fs/jfs/namei.c
35756 +@@ -946,7 +946,7 @@ static int jfs_symlink(struct user_namespace *mnt_userns, struct inode *dip,
35757 + if (ssize <= IDATASIZE) {
35758 + ip->i_op = &jfs_fast_symlink_inode_operations;
35759 +
35760 +- ip->i_link = JFS_IP(ip)->i_inline;
35761 ++ ip->i_link = JFS_IP(ip)->i_inline_all;
35762 + memcpy(ip->i_link, name, ssize);
35763 + ip->i_size = ssize - 1;
35764 +
35765 +diff --git a/fs/ksmbd/mgmt/user_session.c b/fs/ksmbd/mgmt/user_session.c
35766 +index 3fa2139a0b309..92b1603b5abeb 100644
35767 +--- a/fs/ksmbd/mgmt/user_session.c
35768 ++++ b/fs/ksmbd/mgmt/user_session.c
35769 +@@ -108,15 +108,17 @@ int ksmbd_session_rpc_open(struct ksmbd_session *sess, char *rpc_name)
35770 + entry->method = method;
35771 + entry->id = ksmbd_ipc_id_alloc();
35772 + if (entry->id < 0)
35773 +- goto error;
35774 ++ goto free_entry;
35775 +
35776 + resp = ksmbd_rpc_open(sess, entry->id);
35777 + if (!resp)
35778 +- goto error;
35779 ++ goto free_id;
35780 +
35781 + kvfree(resp);
35782 + return entry->id;
35783 +-error:
35784 ++free_id:
35785 ++ ksmbd_rpc_id_free(entry->id);
35786 ++free_entry:
35787 + list_del(&entry->list);
35788 + kfree(entry);
35789 + return -EINVAL;
35790 +diff --git a/fs/libfs.c b/fs/libfs.c
35791 +index 31b0ddf01c31d..76fb29a103a2f 100644
35792 +--- a/fs/libfs.c
35793 ++++ b/fs/libfs.c
35794 +@@ -994,8 +994,8 @@ out:
35795 + EXPORT_SYMBOL_GPL(simple_attr_read);
35796 +
35797 + /* interpret the buffer as a number to call the set function with */
35798 +-ssize_t simple_attr_write(struct file *file, const char __user *buf,
35799 +- size_t len, loff_t *ppos)
35800 ++static ssize_t simple_attr_write_xsigned(struct file *file, const char __user *buf,
35801 ++ size_t len, loff_t *ppos, bool is_signed)
35802 + {
35803 + struct simple_attr *attr;
35804 + unsigned long long val;
35805 +@@ -1016,7 +1016,10 @@ ssize_t simple_attr_write(struct file *file, const char __user *buf,
35806 + goto out;
35807 +
35808 + attr->set_buf[size] = '\0';
35809 +- ret = kstrtoull(attr->set_buf, 0, &val);
35810 ++ if (is_signed)
35811 ++ ret = kstrtoll(attr->set_buf, 0, &val);
35812 ++ else
35813 ++ ret = kstrtoull(attr->set_buf, 0, &val);
35814 + if (ret)
35815 + goto out;
35816 + ret = attr->set(attr->data, val);
35817 +@@ -1026,8 +1029,21 @@ out:
35818 + mutex_unlock(&attr->mutex);
35819 + return ret;
35820 + }
35821 ++
35822 ++ssize_t simple_attr_write(struct file *file, const char __user *buf,
35823 ++ size_t len, loff_t *ppos)
35824 ++{
35825 ++ return simple_attr_write_xsigned(file, buf, len, ppos, false);
35826 ++}
35827 + EXPORT_SYMBOL_GPL(simple_attr_write);
35828 +
35829 ++ssize_t simple_attr_write_signed(struct file *file, const char __user *buf,
35830 ++ size_t len, loff_t *ppos)
35831 ++{
35832 ++ return simple_attr_write_xsigned(file, buf, len, ppos, true);
35833 ++}
35834 ++EXPORT_SYMBOL_GPL(simple_attr_write_signed);
35835 ++
35836 + /**
35837 + * generic_fh_to_dentry - generic helper for the fh_to_dentry export operation
35838 + * @sb: filesystem to do the file handle conversion on
35839 +diff --git a/fs/lockd/svcsubs.c b/fs/lockd/svcsubs.c
35840 +index e1c4617de7714..3515f17eaf3fb 100644
35841 +--- a/fs/lockd/svcsubs.c
35842 ++++ b/fs/lockd/svcsubs.c
35843 +@@ -176,7 +176,7 @@ nlm_delete_file(struct nlm_file *file)
35844 + }
35845 + }
35846 +
35847 +-static int nlm_unlock_files(struct nlm_file *file, fl_owner_t owner)
35848 ++static int nlm_unlock_files(struct nlm_file *file, const struct file_lock *fl)
35849 + {
35850 + struct file_lock lock;
35851 +
35852 +@@ -184,12 +184,15 @@ static int nlm_unlock_files(struct nlm_file *file, fl_owner_t owner)
35853 + lock.fl_type = F_UNLCK;
35854 + lock.fl_start = 0;
35855 + lock.fl_end = OFFSET_MAX;
35856 +- lock.fl_owner = owner;
35857 +- if (file->f_file[O_RDONLY] &&
35858 +- vfs_lock_file(file->f_file[O_RDONLY], F_SETLK, &lock, NULL))
35859 ++ lock.fl_owner = fl->fl_owner;
35860 ++ lock.fl_pid = fl->fl_pid;
35861 ++ lock.fl_flags = FL_POSIX;
35862 ++
35863 ++ lock.fl_file = file->f_file[O_RDONLY];
35864 ++ if (lock.fl_file && vfs_lock_file(lock.fl_file, F_SETLK, &lock, NULL))
35865 + goto out_err;
35866 +- if (file->f_file[O_WRONLY] &&
35867 +- vfs_lock_file(file->f_file[O_WRONLY], F_SETLK, &lock, NULL))
35868 ++ lock.fl_file = file->f_file[O_WRONLY];
35869 ++ if (lock.fl_file && vfs_lock_file(lock.fl_file, F_SETLK, &lock, NULL))
35870 + goto out_err;
35871 + return 0;
35872 + out_err:
35873 +@@ -226,7 +229,7 @@ again:
35874 + if (match(lockhost, host)) {
35875 +
35876 + spin_unlock(&flctx->flc_lock);
35877 +- if (nlm_unlock_files(file, fl->fl_owner))
35878 ++ if (nlm_unlock_files(file, fl))
35879 + return 1;
35880 + goto again;
35881 + }
35882 +diff --git a/fs/nfs/fs_context.c b/fs/nfs/fs_context.c
35883 +index 4da701fd1424f..0c330bc13ef20 100644
35884 +--- a/fs/nfs/fs_context.c
35885 ++++ b/fs/nfs/fs_context.c
35886 +@@ -684,6 +684,8 @@ static int nfs_fs_context_parse_param(struct fs_context *fc,
35887 + return ret;
35888 + break;
35889 + case Opt_vers:
35890 ++ if (!param->string)
35891 ++ goto out_invalid_value;
35892 + trace_nfs_mount_assign(param->key, param->string);
35893 + ret = nfs_parse_version_string(fc, param->string);
35894 + if (ret < 0)
35895 +@@ -696,6 +698,8 @@ static int nfs_fs_context_parse_param(struct fs_context *fc,
35896 + break;
35897 +
35898 + case Opt_proto:
35899 ++ if (!param->string)
35900 ++ goto out_invalid_value;
35901 + trace_nfs_mount_assign(param->key, param->string);
35902 + protofamily = AF_INET;
35903 + switch (lookup_constant(nfs_xprt_protocol_tokens, param->string, -1)) {
35904 +@@ -732,6 +736,8 @@ static int nfs_fs_context_parse_param(struct fs_context *fc,
35905 + break;
35906 +
35907 + case Opt_mountproto:
35908 ++ if (!param->string)
35909 ++ goto out_invalid_value;
35910 + trace_nfs_mount_assign(param->key, param->string);
35911 + mountfamily = AF_INET;
35912 + switch (lookup_constant(nfs_xprt_protocol_tokens, param->string, -1)) {
35913 +diff --git a/fs/nfs/internal.h b/fs/nfs/internal.h
35914 +index 898dd95bc7a7c..c194a1e50f0bc 100644
35915 +--- a/fs/nfs/internal.h
35916 ++++ b/fs/nfs/internal.h
35917 +@@ -741,12 +741,10 @@ unsigned long nfs_io_size(unsigned long iosize, enum xprt_transports proto)
35918 + iosize = NFS_DEF_FILE_IO_SIZE;
35919 + else if (iosize >= NFS_MAX_FILE_IO_SIZE)
35920 + iosize = NFS_MAX_FILE_IO_SIZE;
35921 +- else
35922 +- iosize = iosize & PAGE_MASK;
35923 +
35924 +- if (proto == XPRT_TRANSPORT_UDP)
35925 ++ if (proto == XPRT_TRANSPORT_UDP || iosize < PAGE_SIZE)
35926 + return nfs_block_bits(iosize, NULL);
35927 +- return iosize;
35928 ++ return iosize & PAGE_MASK;
35929 + }
35930 +
35931 + /*
35932 +diff --git a/fs/nfs/namespace.c b/fs/nfs/namespace.c
35933 +index 3295af4110f1b..c7363d9e11bf2 100644
35934 +--- a/fs/nfs/namespace.c
35935 ++++ b/fs/nfs/namespace.c
35936 +@@ -147,7 +147,7 @@ struct vfsmount *nfs_d_automount(struct path *path)
35937 + struct nfs_fs_context *ctx;
35938 + struct fs_context *fc;
35939 + struct vfsmount *mnt = ERR_PTR(-ENOMEM);
35940 +- struct nfs_server *server = NFS_SERVER(d_inode(path->dentry));
35941 ++ struct nfs_server *server = NFS_SB(path->dentry->d_sb);
35942 + struct nfs_client *client = server->nfs_client;
35943 + int timeout = READ_ONCE(nfs_mountpoint_expiry_timeout);
35944 + int ret;
35945 +diff --git a/fs/nfs/nfs42xdr.c b/fs/nfs/nfs42xdr.c
35946 +index b56f05113d367..f742c7a5745e0 100644
35947 +--- a/fs/nfs/nfs42xdr.c
35948 ++++ b/fs/nfs/nfs42xdr.c
35949 +@@ -1134,7 +1134,7 @@ static int decode_read_plus(struct xdr_stream *xdr, struct nfs_pgio_res *res)
35950 + if (!segs)
35951 + return -ENOMEM;
35952 +
35953 +- xdr_set_scratch_buffer(xdr, &scratch_buf, 32);
35954 ++ xdr_set_scratch_buffer(xdr, &scratch_buf, sizeof(scratch_buf));
35955 + status = -EIO;
35956 + for (i = 0; i < segments; i++) {
35957 + status = decode_read_plus_segment(xdr, &segs[i]);
35958 +diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c
35959 +index 313e9145b6c9f..6e247647a5fb6 100644
35960 +--- a/fs/nfs/nfs4proc.c
35961 ++++ b/fs/nfs/nfs4proc.c
35962 +@@ -122,6 +122,11 @@ nfs4_label_init_security(struct inode *dir, struct dentry *dentry,
35963 + if (nfs_server_capable(dir, NFS_CAP_SECURITY_LABEL) == 0)
35964 + return NULL;
35965 +
35966 ++ label->lfs = 0;
35967 ++ label->pi = 0;
35968 ++ label->len = 0;
35969 ++ label->label = NULL;
35970 ++
35971 + err = security_dentry_init_security(dentry, sattr->ia_mode,
35972 + &dentry->d_name, NULL,
35973 + (void **)&label->label, &label->len);
35974 +@@ -2125,18 +2130,18 @@ static struct nfs4_opendata *nfs4_open_recoverdata_alloc(struct nfs_open_context
35975 + }
35976 +
35977 + static int nfs4_open_recover_helper(struct nfs4_opendata *opendata,
35978 +- fmode_t fmode)
35979 ++ fmode_t fmode)
35980 + {
35981 + struct nfs4_state *newstate;
35982 ++ struct nfs_server *server = NFS_SB(opendata->dentry->d_sb);
35983 ++ int openflags = opendata->o_arg.open_flags;
35984 + int ret;
35985 +
35986 + if (!nfs4_mode_match_open_stateid(opendata->state, fmode))
35987 + return 0;
35988 +- opendata->o_arg.open_flags = 0;
35989 + opendata->o_arg.fmode = fmode;
35990 +- opendata->o_arg.share_access = nfs4_map_atomic_open_share(
35991 +- NFS_SB(opendata->dentry->d_sb),
35992 +- fmode, 0);
35993 ++ opendata->o_arg.share_access =
35994 ++ nfs4_map_atomic_open_share(server, fmode, openflags);
35995 + memset(&opendata->o_res, 0, sizeof(opendata->o_res));
35996 + memset(&opendata->c_res, 0, sizeof(opendata->c_res));
35997 + nfs4_init_opendata_res(opendata);
35998 +@@ -2718,10 +2723,15 @@ static int _nfs4_open_expired(struct nfs_open_context *ctx, struct nfs4_state *s
35999 + struct nfs4_opendata *opendata;
36000 + int ret;
36001 +
36002 +- opendata = nfs4_open_recoverdata_alloc(ctx, state,
36003 +- NFS4_OPEN_CLAIM_FH);
36004 ++ opendata = nfs4_open_recoverdata_alloc(ctx, state, NFS4_OPEN_CLAIM_FH);
36005 + if (IS_ERR(opendata))
36006 + return PTR_ERR(opendata);
36007 ++ /*
36008 ++ * We're not recovering a delegation, so ask for no delegation.
36009 ++ * Otherwise the recovery thread could deadlock with an outstanding
36010 ++ * delegation return.
36011 ++ */
36012 ++ opendata->o_arg.open_flags = O_DIRECT;
36013 + ret = nfs4_open_recover(opendata, state);
36014 + if (ret == -ESTALE)
36015 + d_drop(ctx->dentry);
36016 +@@ -3795,7 +3805,7 @@ nfs4_atomic_open(struct inode *dir, struct nfs_open_context *ctx,
36017 + int open_flags, struct iattr *attr, int *opened)
36018 + {
36019 + struct nfs4_state *state;
36020 +- struct nfs4_label l = {0, 0, 0, NULL}, *label = NULL;
36021 ++ struct nfs4_label l, *label;
36022 +
36023 + label = nfs4_label_init_security(dir, ctx->dentry, attr, &l);
36024 +
36025 +@@ -4012,7 +4022,7 @@ static int _nfs4_discover_trunking(struct nfs_server *server,
36026 +
36027 + page = alloc_page(GFP_KERNEL);
36028 + if (!page)
36029 +- return -ENOMEM;
36030 ++ goto out_put_cred;
36031 + locations = kmalloc(sizeof(struct nfs4_fs_locations), GFP_KERNEL);
36032 + if (!locations)
36033 + goto out_free;
36034 +@@ -4034,6 +4044,8 @@ out_free_2:
36035 + kfree(locations);
36036 + out_free:
36037 + __free_page(page);
36038 ++out_put_cred:
36039 ++ put_cred(cred);
36040 + return status;
36041 + }
36042 +
36043 +@@ -4681,7 +4693,7 @@ nfs4_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr,
36044 + int flags)
36045 + {
36046 + struct nfs_server *server = NFS_SERVER(dir);
36047 +- struct nfs4_label l, *ilabel = NULL;
36048 ++ struct nfs4_label l, *ilabel;
36049 + struct nfs_open_context *ctx;
36050 + struct nfs4_state *state;
36051 + int status = 0;
36052 +@@ -5032,7 +5044,7 @@ static int nfs4_proc_symlink(struct inode *dir, struct dentry *dentry,
36053 + struct nfs4_exception exception = {
36054 + .interruptible = true,
36055 + };
36056 +- struct nfs4_label l, *label = NULL;
36057 ++ struct nfs4_label l, *label;
36058 + int err;
36059 +
36060 + label = nfs4_label_init_security(dir, dentry, sattr, &l);
36061 +@@ -5073,7 +5085,7 @@ static int nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry,
36062 + struct nfs4_exception exception = {
36063 + .interruptible = true,
36064 + };
36065 +- struct nfs4_label l, *label = NULL;
36066 ++ struct nfs4_label l, *label;
36067 + int err;
36068 +
36069 + label = nfs4_label_init_security(dir, dentry, sattr, &l);
36070 +@@ -5192,7 +5204,7 @@ static int nfs4_proc_mknod(struct inode *dir, struct dentry *dentry,
36071 + struct nfs4_exception exception = {
36072 + .interruptible = true,
36073 + };
36074 +- struct nfs4_label l, *label = NULL;
36075 ++ struct nfs4_label l, *label;
36076 + int err;
36077 +
36078 + label = nfs4_label_init_security(dir, dentry, sattr, &l);
36079 +diff --git a/fs/nfs/nfs4state.c b/fs/nfs/nfs4state.c
36080 +index a629d7db9420a..0774355249c93 100644
36081 +--- a/fs/nfs/nfs4state.c
36082 ++++ b/fs/nfs/nfs4state.c
36083 +@@ -1232,6 +1232,8 @@ void nfs4_schedule_state_manager(struct nfs_client *clp)
36084 + if (IS_ERR(task)) {
36085 + printk(KERN_ERR "%s: kthread_run: %ld\n",
36086 + __func__, PTR_ERR(task));
36087 ++ if (!nfs_client_init_is_complete(clp))
36088 ++ nfs_mark_client_ready(clp, PTR_ERR(task));
36089 + nfs4_clear_state_manager_bit(clp);
36090 + clear_bit(NFS4CLNT_MANAGER_AVAILABLE, &clp->cl_state);
36091 + nfs_put_client(clp);
36092 +diff --git a/fs/nfs/nfs4xdr.c b/fs/nfs/nfs4xdr.c
36093 +index acfe5f4bda480..deec76cf5afea 100644
36094 +--- a/fs/nfs/nfs4xdr.c
36095 ++++ b/fs/nfs/nfs4xdr.c
36096 +@@ -4234,19 +4234,17 @@ static int decode_attr_security_label(struct xdr_stream *xdr, uint32_t *bitmap,
36097 + p = xdr_inline_decode(xdr, len);
36098 + if (unlikely(!p))
36099 + return -EIO;
36100 ++ bitmap[2] &= ~FATTR4_WORD2_SECURITY_LABEL;
36101 + if (len < NFS4_MAXLABELLEN) {
36102 +- if (label) {
36103 +- if (label->len) {
36104 +- if (label->len < len)
36105 +- return -ERANGE;
36106 +- memcpy(label->label, p, len);
36107 +- }
36108 ++ if (label && label->len) {
36109 ++ if (label->len < len)
36110 ++ return -ERANGE;
36111 ++ memcpy(label->label, p, len);
36112 + label->len = len;
36113 + label->pi = pi;
36114 + label->lfs = lfs;
36115 + status = NFS_ATTR_FATTR_V4_SECURITY_LABEL;
36116 + }
36117 +- bitmap[2] &= ~FATTR4_WORD2_SECURITY_LABEL;
36118 + } else
36119 + printk(KERN_WARNING "%s: label too long (%u)!\n",
36120 + __func__, len);
36121 +@@ -4755,12 +4753,10 @@ static int decode_getfattr_attrs(struct xdr_stream *xdr, uint32_t *bitmap,
36122 + if (status < 0)
36123 + goto xdr_error;
36124 +
36125 +- if (fattr->label) {
36126 +- status = decode_attr_security_label(xdr, bitmap, fattr->label);
36127 +- if (status < 0)
36128 +- goto xdr_error;
36129 +- fattr->valid |= status;
36130 +- }
36131 ++ status = decode_attr_security_label(xdr, bitmap, fattr->label);
36132 ++ if (status < 0)
36133 ++ goto xdr_error;
36134 ++ fattr->valid |= status;
36135 +
36136 + xdr_error:
36137 + dprintk("%s: xdr returned %d\n", __func__, -status);
36138 +diff --git a/fs/nfsd/nfs2acl.c b/fs/nfsd/nfs2acl.c
36139 +index 9edd3c1a30fb1..87f224cd30a85 100644
36140 +--- a/fs/nfsd/nfs2acl.c
36141 ++++ b/fs/nfsd/nfs2acl.c
36142 +@@ -246,7 +246,6 @@ nfsaclsvc_encode_getaclres(struct svc_rqst *rqstp, struct xdr_stream *xdr)
36143 + struct nfsd3_getaclres *resp = rqstp->rq_resp;
36144 + struct dentry *dentry = resp->fh.fh_dentry;
36145 + struct inode *inode;
36146 +- int w;
36147 +
36148 + if (!svcxdr_encode_stat(xdr, resp->status))
36149 + return false;
36150 +@@ -260,15 +259,6 @@ nfsaclsvc_encode_getaclres(struct svc_rqst *rqstp, struct xdr_stream *xdr)
36151 + if (xdr_stream_encode_u32(xdr, resp->mask) < 0)
36152 + return false;
36153 +
36154 +- rqstp->rq_res.page_len = w = nfsacl_size(
36155 +- (resp->mask & NFS_ACL) ? resp->acl_access : NULL,
36156 +- (resp->mask & NFS_DFACL) ? resp->acl_default : NULL);
36157 +- while (w > 0) {
36158 +- if (!*(rqstp->rq_next_page++))
36159 +- return true;
36160 +- w -= PAGE_SIZE;
36161 +- }
36162 +-
36163 + if (!nfs_stream_encode_acl(xdr, inode, resp->acl_access,
36164 + resp->mask & NFS_ACL, 0))
36165 + return false;
36166 +diff --git a/fs/nfsd/nfs3acl.c b/fs/nfsd/nfs3acl.c
36167 +index 9446c67436649..7c798b5f4ec68 100644
36168 +--- a/fs/nfsd/nfs3acl.c
36169 ++++ b/fs/nfsd/nfs3acl.c
36170 +@@ -171,11 +171,7 @@ nfs3svc_encode_getaclres(struct svc_rqst *rqstp, struct xdr_stream *xdr)
36171 + {
36172 + struct nfsd3_getaclres *resp = rqstp->rq_resp;
36173 + struct dentry *dentry = resp->fh.fh_dentry;
36174 +- struct kvec *head = rqstp->rq_res.head;
36175 + struct inode *inode;
36176 +- unsigned int base;
36177 +- int n;
36178 +- int w;
36179 +
36180 + if (!svcxdr_encode_nfsstat3(xdr, resp->status))
36181 + return false;
36182 +@@ -187,26 +183,12 @@ nfs3svc_encode_getaclres(struct svc_rqst *rqstp, struct xdr_stream *xdr)
36183 + if (xdr_stream_encode_u32(xdr, resp->mask) < 0)
36184 + return false;
36185 +
36186 +- base = (char *)xdr->p - (char *)head->iov_base;
36187 +-
36188 +- rqstp->rq_res.page_len = w = nfsacl_size(
36189 +- (resp->mask & NFS_ACL) ? resp->acl_access : NULL,
36190 +- (resp->mask & NFS_DFACL) ? resp->acl_default : NULL);
36191 +- while (w > 0) {
36192 +- if (!*(rqstp->rq_next_page++))
36193 +- return false;
36194 +- w -= PAGE_SIZE;
36195 +- }
36196 +-
36197 +- n = nfsacl_encode(&rqstp->rq_res, base, inode,
36198 +- resp->acl_access,
36199 +- resp->mask & NFS_ACL, 0);
36200 +- if (n > 0)
36201 +- n = nfsacl_encode(&rqstp->rq_res, base + n, inode,
36202 +- resp->acl_default,
36203 +- resp->mask & NFS_DFACL,
36204 +- NFS_ACL_DEFAULT);
36205 +- if (n <= 0)
36206 ++ if (!nfs_stream_encode_acl(xdr, inode, resp->acl_access,
36207 ++ resp->mask & NFS_ACL, 0))
36208 ++ return false;
36209 ++ if (!nfs_stream_encode_acl(xdr, inode, resp->acl_default,
36210 ++ resp->mask & NFS_DFACL,
36211 ++ NFS_ACL_DEFAULT))
36212 + return false;
36213 + break;
36214 + default:
36215 +diff --git a/fs/nfsd/nfs4callback.c b/fs/nfsd/nfs4callback.c
36216 +index 4ce328209f614..775d38dc00fef 100644
36217 +--- a/fs/nfsd/nfs4callback.c
36218 ++++ b/fs/nfsd/nfs4callback.c
36219 +@@ -916,7 +916,6 @@ static int setup_callback_client(struct nfs4_client *clp, struct nfs4_cb_conn *c
36220 + } else {
36221 + if (!conn->cb_xprt)
36222 + return -EINVAL;
36223 +- clp->cl_cb_conn.cb_xprt = conn->cb_xprt;
36224 + clp->cl_cb_session = ses;
36225 + args.bc_xprt = conn->cb_xprt;
36226 + args.prognumber = clp->cl_cb_session->se_cb_prog;
36227 +@@ -936,6 +935,9 @@ static int setup_callback_client(struct nfs4_client *clp, struct nfs4_cb_conn *c
36228 + rpc_shutdown_client(client);
36229 + return -ENOMEM;
36230 + }
36231 ++
36232 ++ if (clp->cl_minorversion != 0)
36233 ++ clp->cl_cb_conn.cb_xprt = conn->cb_xprt;
36234 + clp->cl_cb_client = client;
36235 + clp->cl_cb_cred = cred;
36236 + rcu_read_lock();
36237 +diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c
36238 +index 6ba25a5b76e17..cfc2da4456587 100644
36239 +--- a/fs/nfsd/nfs4proc.c
36240 ++++ b/fs/nfsd/nfs4proc.c
36241 +@@ -1141,6 +1141,8 @@ nfsd4_setattr(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
36242 + 0, (time64_t)0);
36243 + if (!status)
36244 + status = nfserrno(attrs.na_labelerr);
36245 ++ if (!status)
36246 ++ status = nfserrno(attrs.na_aclerr);
36247 + out:
36248 + nfsd_attrs_free(&attrs);
36249 + fh_drop_write(&cstate->current_fh);
36250 +@@ -1648,6 +1650,7 @@ static ssize_t _nfsd_copy_file_range(struct nfsd4_copy *copy,
36251 + u64 src_pos = copy->cp_src_pos;
36252 + u64 dst_pos = copy->cp_dst_pos;
36253 + int status;
36254 ++ loff_t end;
36255 +
36256 + /* See RFC 7862 p.67: */
36257 + if (bytes_total == 0)
36258 +@@ -1667,8 +1670,8 @@ static ssize_t _nfsd_copy_file_range(struct nfsd4_copy *copy,
36259 + /* for a non-zero asynchronous copy do a commit of data */
36260 + if (nfsd4_copy_is_async(copy) && copy->cp_res.wr_bytes_written > 0) {
36261 + since = READ_ONCE(dst->f_wb_err);
36262 +- status = vfs_fsync_range(dst, copy->cp_dst_pos,
36263 +- copy->cp_res.wr_bytes_written, 0);
36264 ++ end = copy->cp_dst_pos + copy->cp_res.wr_bytes_written - 1;
36265 ++ status = vfs_fsync_range(dst, copy->cp_dst_pos, end, 0);
36266 + if (!status)
36267 + status = filemap_check_wb_err(dst->f_mapping, since);
36268 + if (!status)
36269 +diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c
36270 +index ddb2bf078fdaf..94420fad4c410 100644
36271 +--- a/fs/nfsd/nfs4state.c
36272 ++++ b/fs/nfsd/nfs4state.c
36273 +@@ -664,15 +664,26 @@ find_any_file(struct nfs4_file *f)
36274 + return ret;
36275 + }
36276 +
36277 +-static struct nfsd_file *find_deleg_file(struct nfs4_file *f)
36278 ++static struct nfsd_file *find_any_file_locked(struct nfs4_file *f)
36279 + {
36280 +- struct nfsd_file *ret = NULL;
36281 ++ lockdep_assert_held(&f->fi_lock);
36282 ++
36283 ++ if (f->fi_fds[O_RDWR])
36284 ++ return f->fi_fds[O_RDWR];
36285 ++ if (f->fi_fds[O_WRONLY])
36286 ++ return f->fi_fds[O_WRONLY];
36287 ++ if (f->fi_fds[O_RDONLY])
36288 ++ return f->fi_fds[O_RDONLY];
36289 ++ return NULL;
36290 ++}
36291 ++
36292 ++static struct nfsd_file *find_deleg_file_locked(struct nfs4_file *f)
36293 ++{
36294 ++ lockdep_assert_held(&f->fi_lock);
36295 +
36296 +- spin_lock(&f->fi_lock);
36297 + if (f->fi_deleg_file)
36298 +- ret = nfsd_file_get(f->fi_deleg_file);
36299 +- spin_unlock(&f->fi_lock);
36300 +- return ret;
36301 ++ return f->fi_deleg_file;
36302 ++ return NULL;
36303 + }
36304 +
36305 + static atomic_long_t num_delegations;
36306 +@@ -2606,9 +2617,11 @@ static int nfs4_show_open(struct seq_file *s, struct nfs4_stid *st)
36307 + ols = openlockstateid(st);
36308 + oo = ols->st_stateowner;
36309 + nf = st->sc_file;
36310 +- file = find_any_file(nf);
36311 ++
36312 ++ spin_lock(&nf->fi_lock);
36313 ++ file = find_any_file_locked(nf);
36314 + if (!file)
36315 +- return 0;
36316 ++ goto out;
36317 +
36318 + seq_printf(s, "- ");
36319 + nfs4_show_stateid(s, &st->sc_stateid);
36320 +@@ -2630,8 +2643,8 @@ static int nfs4_show_open(struct seq_file *s, struct nfs4_stid *st)
36321 + seq_printf(s, ", ");
36322 + nfs4_show_owner(s, oo);
36323 + seq_printf(s, " }\n");
36324 +- nfsd_file_put(file);
36325 +-
36326 ++out:
36327 ++ spin_unlock(&nf->fi_lock);
36328 + return 0;
36329 + }
36330 +
36331 +@@ -2645,9 +2658,10 @@ static int nfs4_show_lock(struct seq_file *s, struct nfs4_stid *st)
36332 + ols = openlockstateid(st);
36333 + oo = ols->st_stateowner;
36334 + nf = st->sc_file;
36335 +- file = find_any_file(nf);
36336 ++ spin_lock(&nf->fi_lock);
36337 ++ file = find_any_file_locked(nf);
36338 + if (!file)
36339 +- return 0;
36340 ++ goto out;
36341 +
36342 + seq_printf(s, "- ");
36343 + nfs4_show_stateid(s, &st->sc_stateid);
36344 +@@ -2667,8 +2681,8 @@ static int nfs4_show_lock(struct seq_file *s, struct nfs4_stid *st)
36345 + seq_printf(s, ", ");
36346 + nfs4_show_owner(s, oo);
36347 + seq_printf(s, " }\n");
36348 +- nfsd_file_put(file);
36349 +-
36350 ++out:
36351 ++ spin_unlock(&nf->fi_lock);
36352 + return 0;
36353 + }
36354 +
36355 +@@ -2680,9 +2694,10 @@ static int nfs4_show_deleg(struct seq_file *s, struct nfs4_stid *st)
36356 +
36357 + ds = delegstateid(st);
36358 + nf = st->sc_file;
36359 +- file = find_deleg_file(nf);
36360 ++ spin_lock(&nf->fi_lock);
36361 ++ file = find_deleg_file_locked(nf);
36362 + if (!file)
36363 +- return 0;
36364 ++ goto out;
36365 +
36366 + seq_printf(s, "- ");
36367 + nfs4_show_stateid(s, &st->sc_stateid);
36368 +@@ -2698,8 +2713,8 @@ static int nfs4_show_deleg(struct seq_file *s, struct nfs4_stid *st)
36369 + seq_printf(s, ", ");
36370 + nfs4_show_fname(s, file);
36371 + seq_printf(s, " }\n");
36372 +- nfsd_file_put(file);
36373 +-
36374 ++out:
36375 ++ spin_unlock(&nf->fi_lock);
36376 + return 0;
36377 + }
36378 +
36379 +diff --git a/fs/nilfs2/the_nilfs.c b/fs/nilfs2/the_nilfs.c
36380 +index c8b89b4f94e0e..2064e6473d304 100644
36381 +--- a/fs/nilfs2/the_nilfs.c
36382 ++++ b/fs/nilfs2/the_nilfs.c
36383 +@@ -13,6 +13,7 @@
36384 + #include <linux/blkdev.h>
36385 + #include <linux/backing-dev.h>
36386 + #include <linux/random.h>
36387 ++#include <linux/log2.h>
36388 + #include <linux/crc32.h>
36389 + #include "nilfs.h"
36390 + #include "segment.h"
36391 +@@ -192,6 +193,34 @@ static int nilfs_store_log_cursor(struct the_nilfs *nilfs,
36392 + return ret;
36393 + }
36394 +
36395 ++/**
36396 ++ * nilfs_get_blocksize - get block size from raw superblock data
36397 ++ * @sb: super block instance
36398 ++ * @sbp: superblock raw data buffer
36399 ++ * @blocksize: place to store block size
36400 ++ *
36401 ++ * nilfs_get_blocksize() calculates the block size from the block size
36402 ++ * exponent information written in @sbp and stores it in @blocksize,
36403 ++ * or aborts with an error message if it's too large.
36404 ++ *
36405 ++ * Return Value: On success, 0 is returned. If the block size is too
36406 ++ * large, -EINVAL is returned.
36407 ++ */
36408 ++static int nilfs_get_blocksize(struct super_block *sb,
36409 ++ struct nilfs_super_block *sbp, int *blocksize)
36410 ++{
36411 ++ unsigned int shift_bits = le32_to_cpu(sbp->s_log_block_size);
36412 ++
36413 ++ if (unlikely(shift_bits >
36414 ++ ilog2(NILFS_MAX_BLOCK_SIZE) - BLOCK_SIZE_BITS)) {
36415 ++ nilfs_err(sb, "too large filesystem blocksize: 2 ^ %u KiB",
36416 ++ shift_bits);
36417 ++ return -EINVAL;
36418 ++ }
36419 ++ *blocksize = BLOCK_SIZE << shift_bits;
36420 ++ return 0;
36421 ++}
36422 ++
36423 + /**
36424 + * load_nilfs - load and recover the nilfs
36425 + * @nilfs: the_nilfs structure to be released
36426 +@@ -245,11 +274,15 @@ int load_nilfs(struct the_nilfs *nilfs, struct super_block *sb)
36427 + nilfs->ns_sbwtime = le64_to_cpu(sbp[0]->s_wtime);
36428 +
36429 + /* verify consistency between two super blocks */
36430 +- blocksize = BLOCK_SIZE << le32_to_cpu(sbp[0]->s_log_block_size);
36431 ++ err = nilfs_get_blocksize(sb, sbp[0], &blocksize);
36432 ++ if (err)
36433 ++ goto scan_error;
36434 ++
36435 + if (blocksize != nilfs->ns_blocksize) {
36436 + nilfs_warn(sb,
36437 + "blocksize differs between two super blocks (%d != %d)",
36438 + blocksize, nilfs->ns_blocksize);
36439 ++ err = -EINVAL;
36440 + goto scan_error;
36441 + }
36442 +
36443 +@@ -443,11 +476,33 @@ static int nilfs_valid_sb(struct nilfs_super_block *sbp)
36444 + return crc == le32_to_cpu(sbp->s_sum);
36445 + }
36446 +
36447 +-static int nilfs_sb2_bad_offset(struct nilfs_super_block *sbp, u64 offset)
36448 ++/**
36449 ++ * nilfs_sb2_bad_offset - check the location of the second superblock
36450 ++ * @sbp: superblock raw data buffer
36451 ++ * @offset: byte offset of second superblock calculated from device size
36452 ++ *
36453 ++ * nilfs_sb2_bad_offset() checks if the position on the second
36454 ++ * superblock is valid or not based on the filesystem parameters
36455 ++ * stored in @sbp. If @offset points to a location within the segment
36456 ++ * area, or if the parameters themselves are not normal, it is
36457 ++ * determined to be invalid.
36458 ++ *
36459 ++ * Return Value: true if invalid, false if valid.
36460 ++ */
36461 ++static bool nilfs_sb2_bad_offset(struct nilfs_super_block *sbp, u64 offset)
36462 + {
36463 +- return offset < ((le64_to_cpu(sbp->s_nsegments) *
36464 +- le32_to_cpu(sbp->s_blocks_per_segment)) <<
36465 +- (le32_to_cpu(sbp->s_log_block_size) + 10));
36466 ++ unsigned int shift_bits = le32_to_cpu(sbp->s_log_block_size);
36467 ++ u32 blocks_per_segment = le32_to_cpu(sbp->s_blocks_per_segment);
36468 ++ u64 nsegments = le64_to_cpu(sbp->s_nsegments);
36469 ++ u64 index;
36470 ++
36471 ++ if (blocks_per_segment < NILFS_SEG_MIN_BLOCKS ||
36472 ++ shift_bits > ilog2(NILFS_MAX_BLOCK_SIZE) - BLOCK_SIZE_BITS)
36473 ++ return true;
36474 ++
36475 ++ index = offset >> (shift_bits + BLOCK_SIZE_BITS);
36476 ++ do_div(index, blocks_per_segment);
36477 ++ return index < nsegments;
36478 + }
36479 +
36480 + static void nilfs_release_super_block(struct the_nilfs *nilfs)
36481 +@@ -586,9 +641,11 @@ int init_nilfs(struct the_nilfs *nilfs, struct super_block *sb, char *data)
36482 + if (err)
36483 + goto failed_sbh;
36484 +
36485 +- blocksize = BLOCK_SIZE << le32_to_cpu(sbp->s_log_block_size);
36486 +- if (blocksize < NILFS_MIN_BLOCK_SIZE ||
36487 +- blocksize > NILFS_MAX_BLOCK_SIZE) {
36488 ++ err = nilfs_get_blocksize(sb, sbp, &blocksize);
36489 ++ if (err)
36490 ++ goto failed_sbh;
36491 ++
36492 ++ if (blocksize < NILFS_MIN_BLOCK_SIZE) {
36493 + nilfs_err(sb,
36494 + "couldn't mount because of unsupported filesystem blocksize %d",
36495 + blocksize);
36496 +diff --git a/fs/ntfs3/bitmap.c b/fs/ntfs3/bitmap.c
36497 +index 5d44ceac855b7..087282cb130b7 100644
36498 +--- a/fs/ntfs3/bitmap.c
36499 ++++ b/fs/ntfs3/bitmap.c
36500 +@@ -1424,7 +1424,7 @@ int ntfs_trim_fs(struct ntfs_sb_info *sbi, struct fstrim_range *range)
36501 +
36502 + down_read_nested(&wnd->rw_lock, BITMAP_MUTEX_CLUSTERS);
36503 +
36504 +- for (; iw < wnd->nbits; iw++, wbit = 0) {
36505 ++ for (; iw < wnd->nwnd; iw++, wbit = 0) {
36506 + CLST lcn_wnd = iw * wbits;
36507 + struct buffer_head *bh;
36508 +
36509 +diff --git a/fs/ntfs3/super.c b/fs/ntfs3/super.c
36510 +index 47012c9bf505e..adc4f73722b7c 100644
36511 +--- a/fs/ntfs3/super.c
36512 ++++ b/fs/ntfs3/super.c
36513 +@@ -672,7 +672,7 @@ static u32 true_sectors_per_clst(const struct NTFS_BOOT *boot)
36514 + if (boot->sectors_per_clusters <= 0x80)
36515 + return boot->sectors_per_clusters;
36516 + if (boot->sectors_per_clusters >= 0xf4) /* limit shift to 2MB max */
36517 +- return 1U << (0 - boot->sectors_per_clusters);
36518 ++ return 1U << -(s8)boot->sectors_per_clusters;
36519 + return -EINVAL;
36520 + }
36521 +
36522 +diff --git a/fs/ntfs3/xattr.c b/fs/ntfs3/xattr.c
36523 +index 7de8718c68a90..ea582b4fe1d9d 100644
36524 +--- a/fs/ntfs3/xattr.c
36525 ++++ b/fs/ntfs3/xattr.c
36526 +@@ -107,7 +107,7 @@ static int ntfs_read_ea(struct ntfs_inode *ni, struct EA_FULL **ea,
36527 + return -EFBIG;
36528 +
36529 + /* Allocate memory for packed Ea. */
36530 +- ea_p = kmalloc(size + add_bytes, GFP_NOFS);
36531 ++ ea_p = kmalloc(size_add(size, add_bytes), GFP_NOFS);
36532 + if (!ea_p)
36533 + return -ENOMEM;
36534 +
36535 +diff --git a/fs/ocfs2/journal.c b/fs/ocfs2/journal.c
36536 +index fa87d89cf7542..1be7d440eff37 100644
36537 +--- a/fs/ocfs2/journal.c
36538 ++++ b/fs/ocfs2/journal.c
36539 +@@ -157,7 +157,7 @@ static void ocfs2_queue_replay_slots(struct ocfs2_super *osb,
36540 + replay_map->rm_state = REPLAY_DONE;
36541 + }
36542 +
36543 +-static void ocfs2_free_replay_slots(struct ocfs2_super *osb)
36544 ++void ocfs2_free_replay_slots(struct ocfs2_super *osb)
36545 + {
36546 + struct ocfs2_replay_map *replay_map = osb->replay_map;
36547 +
36548 +diff --git a/fs/ocfs2/journal.h b/fs/ocfs2/journal.h
36549 +index 969d0aa287187..41c382f68529e 100644
36550 +--- a/fs/ocfs2/journal.h
36551 ++++ b/fs/ocfs2/journal.h
36552 +@@ -150,6 +150,7 @@ int ocfs2_recovery_init(struct ocfs2_super *osb);
36553 + void ocfs2_recovery_exit(struct ocfs2_super *osb);
36554 +
36555 + int ocfs2_compute_replay_slots(struct ocfs2_super *osb);
36556 ++void ocfs2_free_replay_slots(struct ocfs2_super *osb);
36557 + /*
36558 + * Journal Control:
36559 + * Initialize, Load, Shutdown, Wipe a journal.
36560 +diff --git a/fs/ocfs2/stackglue.c b/fs/ocfs2/stackglue.c
36561 +index dd77b7aaabf5c..3633da5f71179 100644
36562 +--- a/fs/ocfs2/stackglue.c
36563 ++++ b/fs/ocfs2/stackglue.c
36564 +@@ -669,6 +669,8 @@ static struct ctl_table_header *ocfs2_table_header;
36565 +
36566 + static int __init ocfs2_stack_glue_init(void)
36567 + {
36568 ++ int ret;
36569 ++
36570 + strcpy(cluster_stack_name, OCFS2_STACK_PLUGIN_O2CB);
36571 +
36572 + ocfs2_table_header = register_sysctl("fs/ocfs2/nm", ocfs2_nm_table);
36573 +@@ -678,7 +680,11 @@ static int __init ocfs2_stack_glue_init(void)
36574 + return -ENOMEM; /* or something. */
36575 + }
36576 +
36577 +- return ocfs2_sysfs_init();
36578 ++ ret = ocfs2_sysfs_init();
36579 ++ if (ret)
36580 ++ unregister_sysctl_table(ocfs2_table_header);
36581 ++
36582 ++ return ret;
36583 + }
36584 +
36585 + static void __exit ocfs2_stack_glue_exit(void)
36586 +diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
36587 +index e2cc9eec287c9..78441e466e6fd 100644
36588 +--- a/fs/ocfs2/super.c
36589 ++++ b/fs/ocfs2/super.c
36590 +@@ -1159,6 +1159,7 @@ static int ocfs2_fill_super(struct super_block *sb, void *data, int silent)
36591 + out_dismount:
36592 + atomic_set(&osb->vol_state, VOLUME_DISABLED);
36593 + wake_up(&osb->osb_mount_event);
36594 ++ ocfs2_free_replay_slots(osb);
36595 + ocfs2_dismount_volume(sb, 1);
36596 + goto out;
36597 +
36598 +@@ -1824,12 +1825,14 @@ static int ocfs2_mount_volume(struct super_block *sb)
36599 + status = ocfs2_truncate_log_init(osb);
36600 + if (status < 0) {
36601 + mlog_errno(status);
36602 +- goto out_system_inodes;
36603 ++ goto out_check_volume;
36604 + }
36605 +
36606 + ocfs2_super_unlock(osb, 1);
36607 + return 0;
36608 +
36609 ++out_check_volume:
36610 ++ ocfs2_free_replay_slots(osb);
36611 + out_system_inodes:
36612 + if (osb->local_alloc_state == OCFS2_LA_ENABLED)
36613 + ocfs2_shutdown_local_alloc(osb);
36614 +diff --git a/fs/orangefs/orangefs-debugfs.c b/fs/orangefs/orangefs-debugfs.c
36615 +index 29eaa45443727..1b508f5433846 100644
36616 +--- a/fs/orangefs/orangefs-debugfs.c
36617 ++++ b/fs/orangefs/orangefs-debugfs.c
36618 +@@ -194,15 +194,10 @@ void orangefs_debugfs_init(int debug_mask)
36619 + */
36620 + static void orangefs_kernel_debug_init(void)
36621 + {
36622 +- int rc = -ENOMEM;
36623 +- char *k_buffer = NULL;
36624 ++ static char k_buffer[ORANGEFS_MAX_DEBUG_STRING_LEN] = { };
36625 +
36626 + gossip_debug(GOSSIP_DEBUGFS_DEBUG, "%s: start\n", __func__);
36627 +
36628 +- k_buffer = kzalloc(ORANGEFS_MAX_DEBUG_STRING_LEN, GFP_KERNEL);
36629 +- if (!k_buffer)
36630 +- goto out;
36631 +-
36632 + if (strlen(kernel_debug_string) + 1 < ORANGEFS_MAX_DEBUG_STRING_LEN) {
36633 + strcpy(k_buffer, kernel_debug_string);
36634 + strcat(k_buffer, "\n");
36635 +@@ -213,15 +208,14 @@ static void orangefs_kernel_debug_init(void)
36636 +
36637 + debugfs_create_file(ORANGEFS_KMOD_DEBUG_FILE, 0444, debug_dir, k_buffer,
36638 + &kernel_debug_fops);
36639 +-
36640 +-out:
36641 +- gossip_debug(GOSSIP_DEBUGFS_DEBUG, "%s: rc:%d:\n", __func__, rc);
36642 + }
36643 +
36644 +
36645 + void orangefs_debugfs_cleanup(void)
36646 + {
36647 + debugfs_remove_recursive(debug_dir);
36648 ++ kfree(debug_help_string);
36649 ++ debug_help_string = NULL;
36650 + }
36651 +
36652 + /* open ORANGEFS_KMOD_DEBUG_HELP_FILE */
36653 +@@ -297,18 +291,13 @@ static int help_show(struct seq_file *m, void *v)
36654 + /*
36655 + * initialize the client-debug file.
36656 + */
36657 +-static int orangefs_client_debug_init(void)
36658 ++static void orangefs_client_debug_init(void)
36659 + {
36660 +
36661 +- int rc = -ENOMEM;
36662 +- char *c_buffer = NULL;
36663 ++ static char c_buffer[ORANGEFS_MAX_DEBUG_STRING_LEN] = { };
36664 +
36665 + gossip_debug(GOSSIP_DEBUGFS_DEBUG, "%s: start\n", __func__);
36666 +
36667 +- c_buffer = kzalloc(ORANGEFS_MAX_DEBUG_STRING_LEN, GFP_KERNEL);
36668 +- if (!c_buffer)
36669 +- goto out;
36670 +-
36671 + if (strlen(client_debug_string) + 1 < ORANGEFS_MAX_DEBUG_STRING_LEN) {
36672 + strcpy(c_buffer, client_debug_string);
36673 + strcat(c_buffer, "\n");
36674 +@@ -322,13 +311,6 @@ static int orangefs_client_debug_init(void)
36675 + debug_dir,
36676 + c_buffer,
36677 + &kernel_debug_fops);
36678 +-
36679 +- rc = 0;
36680 +-
36681 +-out:
36682 +-
36683 +- gossip_debug(GOSSIP_DEBUGFS_DEBUG, "%s: rc:%d:\n", __func__, rc);
36684 +- return rc;
36685 + }
36686 +
36687 + /* open ORANGEFS_KMOD_DEBUG_FILE or ORANGEFS_CLIENT_DEBUG_FILE.*/
36688 +@@ -671,6 +653,7 @@ int orangefs_prepare_debugfs_help_string(int at_boot)
36689 + memset(debug_help_string, 0, DEBUG_HELP_STRING_SIZE);
36690 + strlcat(debug_help_string, new, string_size);
36691 + mutex_unlock(&orangefs_help_file_lock);
36692 ++ kfree(new);
36693 + }
36694 +
36695 + rc = 0;
36696 +diff --git a/fs/orangefs/orangefs-mod.c b/fs/orangefs/orangefs-mod.c
36697 +index cd7297815f91e..5ab741c60b7e2 100644
36698 +--- a/fs/orangefs/orangefs-mod.c
36699 ++++ b/fs/orangefs/orangefs-mod.c
36700 +@@ -141,7 +141,7 @@ static int __init orangefs_init(void)
36701 + gossip_err("%s: could not initialize device subsystem %d!\n",
36702 + __func__,
36703 + ret);
36704 +- goto cleanup_device;
36705 ++ goto cleanup_sysfs;
36706 + }
36707 +
36708 + ret = register_filesystem(&orangefs_fs_type);
36709 +@@ -152,11 +152,11 @@ static int __init orangefs_init(void)
36710 + goto out;
36711 + }
36712 +
36713 +- orangefs_sysfs_exit();
36714 +-
36715 +-cleanup_device:
36716 + orangefs_dev_cleanup();
36717 +
36718 ++cleanup_sysfs:
36719 ++ orangefs_sysfs_exit();
36720 ++
36721 + sysfs_init_failed:
36722 + orangefs_debugfs_cleanup();
36723 +
36724 +diff --git a/fs/orangefs/orangefs-sysfs.c b/fs/orangefs/orangefs-sysfs.c
36725 +index de80b62553bb1..be4ba03a01a0f 100644
36726 +--- a/fs/orangefs/orangefs-sysfs.c
36727 ++++ b/fs/orangefs/orangefs-sysfs.c
36728 +@@ -896,9 +896,18 @@ static struct attribute *orangefs_default_attrs[] = {
36729 + };
36730 + ATTRIBUTE_GROUPS(orangefs_default);
36731 +
36732 ++static struct kobject *orangefs_obj;
36733 ++
36734 ++static void orangefs_obj_release(struct kobject *kobj)
36735 ++{
36736 ++ kfree(orangefs_obj);
36737 ++ orangefs_obj = NULL;
36738 ++}
36739 ++
36740 + static struct kobj_type orangefs_ktype = {
36741 + .sysfs_ops = &orangefs_sysfs_ops,
36742 + .default_groups = orangefs_default_groups,
36743 ++ .release = orangefs_obj_release,
36744 + };
36745 +
36746 + static struct orangefs_attribute acache_hard_limit_attribute =
36747 +@@ -934,9 +943,18 @@ static struct attribute *acache_orangefs_default_attrs[] = {
36748 + };
36749 + ATTRIBUTE_GROUPS(acache_orangefs_default);
36750 +
36751 ++static struct kobject *acache_orangefs_obj;
36752 ++
36753 ++static void acache_orangefs_obj_release(struct kobject *kobj)
36754 ++{
36755 ++ kfree(acache_orangefs_obj);
36756 ++ acache_orangefs_obj = NULL;
36757 ++}
36758 ++
36759 + static struct kobj_type acache_orangefs_ktype = {
36760 + .sysfs_ops = &orangefs_sysfs_ops,
36761 + .default_groups = acache_orangefs_default_groups,
36762 ++ .release = acache_orangefs_obj_release,
36763 + };
36764 +
36765 + static struct orangefs_attribute capcache_hard_limit_attribute =
36766 +@@ -972,9 +990,18 @@ static struct attribute *capcache_orangefs_default_attrs[] = {
36767 + };
36768 + ATTRIBUTE_GROUPS(capcache_orangefs_default);
36769 +
36770 ++static struct kobject *capcache_orangefs_obj;
36771 ++
36772 ++static void capcache_orangefs_obj_release(struct kobject *kobj)
36773 ++{
36774 ++ kfree(capcache_orangefs_obj);
36775 ++ capcache_orangefs_obj = NULL;
36776 ++}
36777 ++
36778 + static struct kobj_type capcache_orangefs_ktype = {
36779 + .sysfs_ops = &orangefs_sysfs_ops,
36780 + .default_groups = capcache_orangefs_default_groups,
36781 ++ .release = capcache_orangefs_obj_release,
36782 + };
36783 +
36784 + static struct orangefs_attribute ccache_hard_limit_attribute =
36785 +@@ -1010,9 +1037,18 @@ static struct attribute *ccache_orangefs_default_attrs[] = {
36786 + };
36787 + ATTRIBUTE_GROUPS(ccache_orangefs_default);
36788 +
36789 ++static struct kobject *ccache_orangefs_obj;
36790 ++
36791 ++static void ccache_orangefs_obj_release(struct kobject *kobj)
36792 ++{
36793 ++ kfree(ccache_orangefs_obj);
36794 ++ ccache_orangefs_obj = NULL;
36795 ++}
36796 ++
36797 + static struct kobj_type ccache_orangefs_ktype = {
36798 + .sysfs_ops = &orangefs_sysfs_ops,
36799 + .default_groups = ccache_orangefs_default_groups,
36800 ++ .release = ccache_orangefs_obj_release,
36801 + };
36802 +
36803 + static struct orangefs_attribute ncache_hard_limit_attribute =
36804 +@@ -1048,9 +1084,18 @@ static struct attribute *ncache_orangefs_default_attrs[] = {
36805 + };
36806 + ATTRIBUTE_GROUPS(ncache_orangefs_default);
36807 +
36808 ++static struct kobject *ncache_orangefs_obj;
36809 ++
36810 ++static void ncache_orangefs_obj_release(struct kobject *kobj)
36811 ++{
36812 ++ kfree(ncache_orangefs_obj);
36813 ++ ncache_orangefs_obj = NULL;
36814 ++}
36815 ++
36816 + static struct kobj_type ncache_orangefs_ktype = {
36817 + .sysfs_ops = &orangefs_sysfs_ops,
36818 + .default_groups = ncache_orangefs_default_groups,
36819 ++ .release = ncache_orangefs_obj_release,
36820 + };
36821 +
36822 + static struct orangefs_attribute pc_acache_attribute =
36823 +@@ -1079,9 +1124,18 @@ static struct attribute *pc_orangefs_default_attrs[] = {
36824 + };
36825 + ATTRIBUTE_GROUPS(pc_orangefs_default);
36826 +
36827 ++static struct kobject *pc_orangefs_obj;
36828 ++
36829 ++static void pc_orangefs_obj_release(struct kobject *kobj)
36830 ++{
36831 ++ kfree(pc_orangefs_obj);
36832 ++ pc_orangefs_obj = NULL;
36833 ++}
36834 ++
36835 + static struct kobj_type pc_orangefs_ktype = {
36836 + .sysfs_ops = &orangefs_sysfs_ops,
36837 + .default_groups = pc_orangefs_default_groups,
36838 ++ .release = pc_orangefs_obj_release,
36839 + };
36840 +
36841 + static struct orangefs_attribute stats_reads_attribute =
36842 +@@ -1103,19 +1157,20 @@ static struct attribute *stats_orangefs_default_attrs[] = {
36843 + };
36844 + ATTRIBUTE_GROUPS(stats_orangefs_default);
36845 +
36846 ++static struct kobject *stats_orangefs_obj;
36847 ++
36848 ++static void stats_orangefs_obj_release(struct kobject *kobj)
36849 ++{
36850 ++ kfree(stats_orangefs_obj);
36851 ++ stats_orangefs_obj = NULL;
36852 ++}
36853 ++
36854 + static struct kobj_type stats_orangefs_ktype = {
36855 + .sysfs_ops = &orangefs_sysfs_ops,
36856 + .default_groups = stats_orangefs_default_groups,
36857 ++ .release = stats_orangefs_obj_release,
36858 + };
36859 +
36860 +-static struct kobject *orangefs_obj;
36861 +-static struct kobject *acache_orangefs_obj;
36862 +-static struct kobject *capcache_orangefs_obj;
36863 +-static struct kobject *ccache_orangefs_obj;
36864 +-static struct kobject *ncache_orangefs_obj;
36865 +-static struct kobject *pc_orangefs_obj;
36866 +-static struct kobject *stats_orangefs_obj;
36867 +-
36868 + int orangefs_sysfs_init(void)
36869 + {
36870 + int rc = -EINVAL;
36871 +diff --git a/fs/overlayfs/file.c b/fs/overlayfs/file.c
36872 +index daff601b5c410..a34f8042724ce 100644
36873 +--- a/fs/overlayfs/file.c
36874 ++++ b/fs/overlayfs/file.c
36875 +@@ -517,9 +517,16 @@ static long ovl_fallocate(struct file *file, int mode, loff_t offset, loff_t len
36876 + const struct cred *old_cred;
36877 + int ret;
36878 +
36879 ++ inode_lock(inode);
36880 ++ /* Update mode */
36881 ++ ovl_copyattr(inode);
36882 ++ ret = file_remove_privs(file);
36883 ++ if (ret)
36884 ++ goto out_unlock;
36885 ++
36886 + ret = ovl_real_fdget(file, &real);
36887 + if (ret)
36888 +- return ret;
36889 ++ goto out_unlock;
36890 +
36891 + old_cred = ovl_override_creds(file_inode(file)->i_sb);
36892 + ret = vfs_fallocate(real.file, mode, offset, len);
36893 +@@ -530,6 +537,9 @@ static long ovl_fallocate(struct file *file, int mode, loff_t offset, loff_t len
36894 +
36895 + fdput(real);
36896 +
36897 ++out_unlock:
36898 ++ inode_unlock(inode);
36899 ++
36900 + return ret;
36901 + }
36902 +
36903 +@@ -567,14 +577,23 @@ static loff_t ovl_copyfile(struct file *file_in, loff_t pos_in,
36904 + const struct cred *old_cred;
36905 + loff_t ret;
36906 +
36907 ++ inode_lock(inode_out);
36908 ++ if (op != OVL_DEDUPE) {
36909 ++ /* Update mode */
36910 ++ ovl_copyattr(inode_out);
36911 ++ ret = file_remove_privs(file_out);
36912 ++ if (ret)
36913 ++ goto out_unlock;
36914 ++ }
36915 ++
36916 + ret = ovl_real_fdget(file_out, &real_out);
36917 + if (ret)
36918 +- return ret;
36919 ++ goto out_unlock;
36920 +
36921 + ret = ovl_real_fdget(file_in, &real_in);
36922 + if (ret) {
36923 + fdput(real_out);
36924 +- return ret;
36925 ++ goto out_unlock;
36926 + }
36927 +
36928 + old_cred = ovl_override_creds(file_inode(file_out)->i_sb);
36929 +@@ -603,6 +622,9 @@ static loff_t ovl_copyfile(struct file *file_in, loff_t pos_in,
36930 + fdput(real_in);
36931 + fdput(real_out);
36932 +
36933 ++out_unlock:
36934 ++ inode_unlock(inode_out);
36935 ++
36936 + return ret;
36937 + }
36938 +
36939 +diff --git a/fs/overlayfs/super.c b/fs/overlayfs/super.c
36940 +index ec746d447f1bb..79a77aa6892cb 100644
36941 +--- a/fs/overlayfs/super.c
36942 ++++ b/fs/overlayfs/super.c
36943 +@@ -138,11 +138,16 @@ static int ovl_dentry_revalidate_common(struct dentry *dentry,
36944 + unsigned int flags, bool weak)
36945 + {
36946 + struct ovl_entry *oe = dentry->d_fsdata;
36947 ++ struct inode *inode = d_inode_rcu(dentry);
36948 + struct dentry *upper;
36949 + unsigned int i;
36950 + int ret = 1;
36951 +
36952 +- upper = ovl_dentry_upper(dentry);
36953 ++ /* Careful in RCU mode */
36954 ++ if (!inode)
36955 ++ return -ECHILD;
36956 ++
36957 ++ upper = ovl_i_dentry_upper(inode);
36958 + if (upper)
36959 + ret = ovl_revalidate_real(upper, flags, weak);
36960 +
36961 +diff --git a/fs/pstore/Kconfig b/fs/pstore/Kconfig
36962 +index 8adabde685f13..c49d554cc9ae9 100644
36963 +--- a/fs/pstore/Kconfig
36964 ++++ b/fs/pstore/Kconfig
36965 +@@ -126,6 +126,7 @@ config PSTORE_CONSOLE
36966 + config PSTORE_PMSG
36967 + bool "Log user space messages"
36968 + depends on PSTORE
36969 ++ select RT_MUTEXES
36970 + help
36971 + When the option is enabled, pstore will export a character
36972 + interface /dev/pmsg0 to log user space messages. On reboot
36973 +diff --git a/fs/pstore/pmsg.c b/fs/pstore/pmsg.c
36974 +index d8542ec2f38c6..18cf94b597e05 100644
36975 +--- a/fs/pstore/pmsg.c
36976 ++++ b/fs/pstore/pmsg.c
36977 +@@ -7,9 +7,10 @@
36978 + #include <linux/device.h>
36979 + #include <linux/fs.h>
36980 + #include <linux/uaccess.h>
36981 ++#include <linux/rtmutex.h>
36982 + #include "internal.h"
36983 +
36984 +-static DEFINE_MUTEX(pmsg_lock);
36985 ++static DEFINE_RT_MUTEX(pmsg_lock);
36986 +
36987 + static ssize_t write_pmsg(struct file *file, const char __user *buf,
36988 + size_t count, loff_t *ppos)
36989 +@@ -28,9 +29,9 @@ static ssize_t write_pmsg(struct file *file, const char __user *buf,
36990 + if (!access_ok(buf, count))
36991 + return -EFAULT;
36992 +
36993 +- mutex_lock(&pmsg_lock);
36994 ++ rt_mutex_lock(&pmsg_lock);
36995 + ret = psinfo->write_user(&record, buf);
36996 +- mutex_unlock(&pmsg_lock);
36997 ++ rt_mutex_unlock(&pmsg_lock);
36998 + return ret ? ret : count;
36999 + }
37000 +
37001 +diff --git a/fs/pstore/ram.c b/fs/pstore/ram.c
37002 +index fefe3d391d3af..74e4d93f3e08d 100644
37003 +--- a/fs/pstore/ram.c
37004 ++++ b/fs/pstore/ram.c
37005 +@@ -735,6 +735,7 @@ static int ramoops_probe(struct platform_device *pdev)
37006 + /* Make sure we didn't get bogus platform data pointer. */
37007 + if (!pdata) {
37008 + pr_err("NULL platform data\n");
37009 ++ err = -EINVAL;
37010 + goto fail_out;
37011 + }
37012 +
37013 +@@ -742,6 +743,7 @@ static int ramoops_probe(struct platform_device *pdev)
37014 + !pdata->ftrace_size && !pdata->pmsg_size)) {
37015 + pr_err("The memory size and the record/console size must be "
37016 + "non-zero\n");
37017 ++ err = -EINVAL;
37018 + goto fail_out;
37019 + }
37020 +
37021 +diff --git a/fs/pstore/ram_core.c b/fs/pstore/ram_core.c
37022 +index a89e33719fcf2..8bf09886e7e66 100644
37023 +--- a/fs/pstore/ram_core.c
37024 ++++ b/fs/pstore/ram_core.c
37025 +@@ -439,7 +439,11 @@ static void *persistent_ram_vmap(phys_addr_t start, size_t size,
37026 + phys_addr_t addr = page_start + i * PAGE_SIZE;
37027 + pages[i] = pfn_to_page(addr >> PAGE_SHIFT);
37028 + }
37029 +- vaddr = vmap(pages, page_count, VM_MAP, prot);
37030 ++ /*
37031 ++ * VM_IOREMAP used here to bypass this region during vread()
37032 ++ * and kmap_atomic() (i.e. kcore) to avoid __va() failures.
37033 ++ */
37034 ++ vaddr = vmap(pages, page_count, VM_MAP | VM_IOREMAP, prot);
37035 + kfree(pages);
37036 +
37037 + /*
37038 +diff --git a/fs/reiserfs/namei.c b/fs/reiserfs/namei.c
37039 +index 3d7a35d6a18bc..b916859992ec8 100644
37040 +--- a/fs/reiserfs/namei.c
37041 ++++ b/fs/reiserfs/namei.c
37042 +@@ -696,6 +696,7 @@ static int reiserfs_create(struct user_namespace *mnt_userns, struct inode *dir,
37043 +
37044 + out_failed:
37045 + reiserfs_write_unlock(dir->i_sb);
37046 ++ reiserfs_security_free(&security);
37047 + return retval;
37048 + }
37049 +
37050 +@@ -779,6 +780,7 @@ static int reiserfs_mknod(struct user_namespace *mnt_userns, struct inode *dir,
37051 +
37052 + out_failed:
37053 + reiserfs_write_unlock(dir->i_sb);
37054 ++ reiserfs_security_free(&security);
37055 + return retval;
37056 + }
37057 +
37058 +@@ -878,6 +880,7 @@ static int reiserfs_mkdir(struct user_namespace *mnt_userns, struct inode *dir,
37059 + retval = journal_end(&th);
37060 + out_failed:
37061 + reiserfs_write_unlock(dir->i_sb);
37062 ++ reiserfs_security_free(&security);
37063 + return retval;
37064 + }
37065 +
37066 +@@ -1194,6 +1197,7 @@ static int reiserfs_symlink(struct user_namespace *mnt_userns,
37067 + retval = journal_end(&th);
37068 + out_failed:
37069 + reiserfs_write_unlock(parent_dir->i_sb);
37070 ++ reiserfs_security_free(&security);
37071 + return retval;
37072 + }
37073 +
37074 +diff --git a/fs/reiserfs/xattr_security.c b/fs/reiserfs/xattr_security.c
37075 +index 8965c8e5e172b..857a65b057264 100644
37076 +--- a/fs/reiserfs/xattr_security.c
37077 ++++ b/fs/reiserfs/xattr_security.c
37078 +@@ -50,6 +50,7 @@ int reiserfs_security_init(struct inode *dir, struct inode *inode,
37079 + int error;
37080 +
37081 + sec->name = NULL;
37082 ++ sec->value = NULL;
37083 +
37084 + /* Don't add selinux attributes on xattrs - they'll never get used */
37085 + if (IS_PRIVATE(dir))
37086 +@@ -95,7 +96,6 @@ int reiserfs_security_write(struct reiserfs_transaction_handle *th,
37087 +
37088 + void reiserfs_security_free(struct reiserfs_security_handle *sec)
37089 + {
37090 +- kfree(sec->name);
37091 + kfree(sec->value);
37092 + sec->name = NULL;
37093 + sec->value = NULL;
37094 +diff --git a/fs/sysv/itree.c b/fs/sysv/itree.c
37095 +index d4ec9bb97de95..3b8567564e7e4 100644
37096 +--- a/fs/sysv/itree.c
37097 ++++ b/fs/sysv/itree.c
37098 +@@ -438,7 +438,7 @@ static unsigned sysv_nblocks(struct super_block *s, loff_t size)
37099 + res += blocks;
37100 + direct = 1;
37101 + }
37102 +- return blocks;
37103 ++ return res;
37104 + }
37105 +
37106 + int sysv_getattr(struct user_namespace *mnt_userns, const struct path *path,
37107 +diff --git a/fs/udf/namei.c b/fs/udf/namei.c
37108 +index 865e658535b11..0e30a50060d9d 100644
37109 +--- a/fs/udf/namei.c
37110 ++++ b/fs/udf/namei.c
37111 +@@ -1091,8 +1091,9 @@ static int udf_rename(struct user_namespace *mnt_userns, struct inode *old_dir,
37112 + return -EINVAL;
37113 +
37114 + ofi = udf_find_entry(old_dir, &old_dentry->d_name, &ofibh, &ocfi);
37115 +- if (IS_ERR(ofi)) {
37116 +- retval = PTR_ERR(ofi);
37117 ++ if (!ofi || IS_ERR(ofi)) {
37118 ++ if (IS_ERR(ofi))
37119 ++ retval = PTR_ERR(ofi);
37120 + goto end_rename;
37121 + }
37122 +
37123 +@@ -1101,8 +1102,7 @@ static int udf_rename(struct user_namespace *mnt_userns, struct inode *old_dir,
37124 +
37125 + brelse(ofibh.sbh);
37126 + tloc = lelb_to_cpu(ocfi.icb.extLocation);
37127 +- if (!ofi || udf_get_lb_pblock(old_dir->i_sb, &tloc, 0)
37128 +- != old_inode->i_ino)
37129 ++ if (udf_get_lb_pblock(old_dir->i_sb, &tloc, 0) != old_inode->i_ino)
37130 + goto end_rename;
37131 +
37132 + nfi = udf_find_entry(new_dir, &new_dentry->d_name, &nfibh, &ncfi);
37133 +diff --git a/fs/xattr.c b/fs/xattr.c
37134 +index a1f4998bc6be3..8ea6b104b1063 100644
37135 +--- a/fs/xattr.c
37136 ++++ b/fs/xattr.c
37137 +@@ -1147,7 +1147,7 @@ static int xattr_list_one(char **buffer, ssize_t *remaining_size,
37138 + ssize_t simple_xattr_list(struct inode *inode, struct simple_xattrs *xattrs,
37139 + char *buffer, size_t size)
37140 + {
37141 +- bool trusted = capable(CAP_SYS_ADMIN);
37142 ++ bool trusted = ns_capable_noaudit(&init_user_ns, CAP_SYS_ADMIN);
37143 + struct simple_xattr *xattr;
37144 + ssize_t remaining_size = size;
37145 + int err = 0;
37146 +diff --git a/include/drm/drm_connector.h b/include/drm/drm_connector.h
37147 +index 7df7876b2ad56..d9879fc9ceb17 100644
37148 +--- a/include/drm/drm_connector.h
37149 ++++ b/include/drm/drm_connector.h
37150 +@@ -635,6 +635,12 @@ struct drm_display_info {
37151 + * @mso_pixel_overlap: eDP MSO segment pixel overlap, 0-8 pixels.
37152 + */
37153 + u8 mso_pixel_overlap;
37154 ++
37155 ++ /**
37156 ++ * @max_dsc_bpp: Maximum DSC target bitrate, if it is set to 0 the
37157 ++ * monitor's default value is used instead.
37158 ++ */
37159 ++ u32 max_dsc_bpp;
37160 + };
37161 +
37162 + int drm_display_info_set_bus_formats(struct drm_display_info *info,
37163 +diff --git a/include/drm/ttm/ttm_tt.h b/include/drm/ttm/ttm_tt.h
37164 +index 17a0310e8aaaf..b7d3f3843f1e6 100644
37165 +--- a/include/drm/ttm/ttm_tt.h
37166 ++++ b/include/drm/ttm/ttm_tt.h
37167 +@@ -88,7 +88,7 @@ struct ttm_tt {
37168 + #define TTM_TT_FLAG_EXTERNAL (1 << 2)
37169 + #define TTM_TT_FLAG_EXTERNAL_MAPPABLE (1 << 3)
37170 +
37171 +-#define TTM_TT_FLAG_PRIV_POPULATED (1 << 31)
37172 ++#define TTM_TT_FLAG_PRIV_POPULATED (1U << 31)
37173 + uint32_t page_flags;
37174 + /** @num_pages: Number of pages in the page array. */
37175 + uint32_t num_pages;
37176 +diff --git a/include/dt-bindings/clock/imx8mn-clock.h b/include/dt-bindings/clock/imx8mn-clock.h
37177 +index 07b8a282c2682..04809edab33cf 100644
37178 +--- a/include/dt-bindings/clock/imx8mn-clock.h
37179 ++++ b/include/dt-bindings/clock/imx8mn-clock.h
37180 +@@ -16,40 +16,48 @@
37181 + #define IMX8MN_CLK_EXT4 7
37182 + #define IMX8MN_AUDIO_PLL1_REF_SEL 8
37183 + #define IMX8MN_AUDIO_PLL2_REF_SEL 9
37184 +-#define IMX8MN_VIDEO_PLL1_REF_SEL 10
37185 ++#define IMX8MN_VIDEO_PLL_REF_SEL 10
37186 ++#define IMX8MN_VIDEO_PLL1_REF_SEL IMX8MN_VIDEO_PLL_REF_SEL
37187 + #define IMX8MN_DRAM_PLL_REF_SEL 11
37188 + #define IMX8MN_GPU_PLL_REF_SEL 12
37189 +-#define IMX8MN_VPU_PLL_REF_SEL 13
37190 ++#define IMX8MN_M7_ALT_PLL_REF_SEL 13
37191 ++#define IMX8MN_VPU_PLL_REF_SEL IMX8MN_M7_ALT_PLL_REF_SEL
37192 + #define IMX8MN_ARM_PLL_REF_SEL 14
37193 + #define IMX8MN_SYS_PLL1_REF_SEL 15
37194 + #define IMX8MN_SYS_PLL2_REF_SEL 16
37195 + #define IMX8MN_SYS_PLL3_REF_SEL 17
37196 + #define IMX8MN_AUDIO_PLL1 18
37197 + #define IMX8MN_AUDIO_PLL2 19
37198 +-#define IMX8MN_VIDEO_PLL1 20
37199 ++#define IMX8MN_VIDEO_PLL 20
37200 ++#define IMX8MN_VIDEO_PLL1 IMX8MN_VIDEO_PLL
37201 + #define IMX8MN_DRAM_PLL 21
37202 + #define IMX8MN_GPU_PLL 22
37203 +-#define IMX8MN_VPU_PLL 23
37204 ++#define IMX8MN_M7_ALT_PLL 23
37205 ++#define IMX8MN_VPU_PLL IMX8MN_M7_ALT_PLL
37206 + #define IMX8MN_ARM_PLL 24
37207 + #define IMX8MN_SYS_PLL1 25
37208 + #define IMX8MN_SYS_PLL2 26
37209 + #define IMX8MN_SYS_PLL3 27
37210 + #define IMX8MN_AUDIO_PLL1_BYPASS 28
37211 + #define IMX8MN_AUDIO_PLL2_BYPASS 29
37212 +-#define IMX8MN_VIDEO_PLL1_BYPASS 30
37213 ++#define IMX8MN_VIDEO_PLL_BYPASS 30
37214 ++#define IMX8MN_VIDEO_PLL1_BYPASS IMX8MN_VIDEO_PLL_BYPASS
37215 + #define IMX8MN_DRAM_PLL_BYPASS 31
37216 + #define IMX8MN_GPU_PLL_BYPASS 32
37217 +-#define IMX8MN_VPU_PLL_BYPASS 33
37218 ++#define IMX8MN_M7_ALT_PLL_BYPASS 33
37219 ++#define IMX8MN_VPU_PLL_BYPASS IMX8MN_M7_ALT_PLL_BYPASS
37220 + #define IMX8MN_ARM_PLL_BYPASS 34
37221 + #define IMX8MN_SYS_PLL1_BYPASS 35
37222 + #define IMX8MN_SYS_PLL2_BYPASS 36
37223 + #define IMX8MN_SYS_PLL3_BYPASS 37
37224 + #define IMX8MN_AUDIO_PLL1_OUT 38
37225 + #define IMX8MN_AUDIO_PLL2_OUT 39
37226 +-#define IMX8MN_VIDEO_PLL1_OUT 40
37227 ++#define IMX8MN_VIDEO_PLL_OUT 40
37228 ++#define IMX8MN_VIDEO_PLL1_OUT IMX8MN_VIDEO_PLL_OUT
37229 + #define IMX8MN_DRAM_PLL_OUT 41
37230 + #define IMX8MN_GPU_PLL_OUT 42
37231 +-#define IMX8MN_VPU_PLL_OUT 43
37232 ++#define IMX8MN_M7_ALT_PLL_OUT 43
37233 ++#define IMX8MN_VPU_PLL_OUT IMX8MN_M7_ALT_PLL_OUT
37234 + #define IMX8MN_ARM_PLL_OUT 44
37235 + #define IMX8MN_SYS_PLL1_OUT 45
37236 + #define IMX8MN_SYS_PLL2_OUT 46
37237 +diff --git a/include/dt-bindings/clock/imx8mp-clock.h b/include/dt-bindings/clock/imx8mp-clock.h
37238 +index 9d5cc2ddde896..1417b7b1b7dfe 100644
37239 +--- a/include/dt-bindings/clock/imx8mp-clock.h
37240 ++++ b/include/dt-bindings/clock/imx8mp-clock.h
37241 +@@ -324,8 +324,9 @@
37242 + #define IMX8MP_CLK_CLKOUT2_SEL 317
37243 + #define IMX8MP_CLK_CLKOUT2_DIV 318
37244 + #define IMX8MP_CLK_CLKOUT2 319
37245 ++#define IMX8MP_CLK_USB_SUSP 320
37246 +
37247 +-#define IMX8MP_CLK_END 320
37248 ++#define IMX8MP_CLK_END 321
37249 +
37250 + #define IMX8MP_CLK_AUDIOMIX_SAI1_IPG 0
37251 + #define IMX8MP_CLK_AUDIOMIX_SAI1_MCLK1 1
37252 +diff --git a/include/dt-bindings/clock/qcom,lpassaudiocc-sc7280.h b/include/dt-bindings/clock/qcom,lpassaudiocc-sc7280.h
37253 +index 20ef2ea673f3b..22dcd47d45139 100644
37254 +--- a/include/dt-bindings/clock/qcom,lpassaudiocc-sc7280.h
37255 ++++ b/include/dt-bindings/clock/qcom,lpassaudiocc-sc7280.h
37256 +@@ -24,6 +24,11 @@
37257 + #define LPASS_AUDIO_CC_RX_MCLK_CLK 14
37258 + #define LPASS_AUDIO_CC_RX_MCLK_CLK_SRC 15
37259 +
37260 ++/* LPASS AUDIO CC CSR */
37261 ++#define LPASS_AUDIO_SWR_RX_CGCR 0
37262 ++#define LPASS_AUDIO_SWR_TX_CGCR 1
37263 ++#define LPASS_AUDIO_SWR_WSA_CGCR 2
37264 ++
37265 + /* LPASS_AON_CC clocks */
37266 + #define LPASS_AON_CC_PLL 0
37267 + #define LPASS_AON_CC_PLL_OUT_EVEN 1
37268 +diff --git a/include/dt-bindings/clock/qcom,lpasscorecc-sc7280.h b/include/dt-bindings/clock/qcom,lpasscorecc-sc7280.h
37269 +index 28ed2a07aacc3..0324c69ce9686 100644
37270 +--- a/include/dt-bindings/clock/qcom,lpasscorecc-sc7280.h
37271 ++++ b/include/dt-bindings/clock/qcom,lpasscorecc-sc7280.h
37272 +@@ -19,6 +19,8 @@
37273 + #define LPASS_CORE_CC_LPM_CORE_CLK 9
37274 + #define LPASS_CORE_CC_LPM_MEM0_CORE_CLK 10
37275 + #define LPASS_CORE_CC_SYSNOC_MPORT_CORE_CLK 11
37276 ++#define LPASS_CORE_CC_EXT_MCLK0_CLK 12
37277 ++#define LPASS_CORE_CC_EXT_MCLK0_CLK_SRC 13
37278 +
37279 + /* LPASS_CORE_CC power domains */
37280 + #define LPASS_CORE_CC_LPASS_CORE_HM_GDSC 0
37281 +diff --git a/include/linux/btf_ids.h b/include/linux/btf_ids.h
37282 +index 2aea877d644f8..2b98720084285 100644
37283 +--- a/include/linux/btf_ids.h
37284 ++++ b/include/linux/btf_ids.h
37285 +@@ -204,7 +204,7 @@ extern struct btf_id_set8 name;
37286 +
37287 + #else
37288 +
37289 +-#define BTF_ID_LIST(name) static u32 __maybe_unused name[5];
37290 ++#define BTF_ID_LIST(name) static u32 __maybe_unused name[16];
37291 + #define BTF_ID(prefix, name)
37292 + #define BTF_ID_FLAGS(prefix, name, ...)
37293 + #define BTF_ID_UNUSED
37294 +diff --git a/include/linux/debugfs.h b/include/linux/debugfs.h
37295 +index f60674692d365..ea2d919fd9c79 100644
37296 +--- a/include/linux/debugfs.h
37297 ++++ b/include/linux/debugfs.h
37298 +@@ -45,7 +45,7 @@ struct debugfs_u32_array {
37299 +
37300 + extern struct dentry *arch_debugfs_dir;
37301 +
37302 +-#define DEFINE_DEBUGFS_ATTRIBUTE(__fops, __get, __set, __fmt) \
37303 ++#define DEFINE_DEBUGFS_ATTRIBUTE_XSIGNED(__fops, __get, __set, __fmt, __is_signed) \
37304 + static int __fops ## _open(struct inode *inode, struct file *file) \
37305 + { \
37306 + __simple_attr_check_format(__fmt, 0ull); \
37307 +@@ -56,10 +56,16 @@ static const struct file_operations __fops = { \
37308 + .open = __fops ## _open, \
37309 + .release = simple_attr_release, \
37310 + .read = debugfs_attr_read, \
37311 +- .write = debugfs_attr_write, \
37312 ++ .write = (__is_signed) ? debugfs_attr_write_signed : debugfs_attr_write, \
37313 + .llseek = no_llseek, \
37314 + }
37315 +
37316 ++#define DEFINE_DEBUGFS_ATTRIBUTE(__fops, __get, __set, __fmt) \
37317 ++ DEFINE_DEBUGFS_ATTRIBUTE_XSIGNED(__fops, __get, __set, __fmt, false)
37318 ++
37319 ++#define DEFINE_DEBUGFS_ATTRIBUTE_SIGNED(__fops, __get, __set, __fmt) \
37320 ++ DEFINE_DEBUGFS_ATTRIBUTE_XSIGNED(__fops, __get, __set, __fmt, true)
37321 ++
37322 + typedef struct vfsmount *(*debugfs_automount_t)(struct dentry *, void *);
37323 +
37324 + #if defined(CONFIG_DEBUG_FS)
37325 +@@ -102,6 +108,8 @@ ssize_t debugfs_attr_read(struct file *file, char __user *buf,
37326 + size_t len, loff_t *ppos);
37327 + ssize_t debugfs_attr_write(struct file *file, const char __user *buf,
37328 + size_t len, loff_t *ppos);
37329 ++ssize_t debugfs_attr_write_signed(struct file *file, const char __user *buf,
37330 ++ size_t len, loff_t *ppos);
37331 +
37332 + struct dentry *debugfs_rename(struct dentry *old_dir, struct dentry *old_dentry,
37333 + struct dentry *new_dir, const char *new_name);
37334 +@@ -254,6 +262,13 @@ static inline ssize_t debugfs_attr_write(struct file *file,
37335 + return -ENODEV;
37336 + }
37337 +
37338 ++static inline ssize_t debugfs_attr_write_signed(struct file *file,
37339 ++ const char __user *buf,
37340 ++ size_t len, loff_t *ppos)
37341 ++{
37342 ++ return -ENODEV;
37343 ++}
37344 ++
37345 + static inline struct dentry *debugfs_rename(struct dentry *old_dir, struct dentry *old_dentry,
37346 + struct dentry *new_dir, char *new_name)
37347 + {
37348 +diff --git a/include/linux/eventfd.h b/include/linux/eventfd.h
37349 +index 30eb30d6909b0..3cd202d3eefb3 100644
37350 +--- a/include/linux/eventfd.h
37351 ++++ b/include/linux/eventfd.h
37352 +@@ -61,7 +61,7 @@ static inline struct eventfd_ctx *eventfd_ctx_fdget(int fd)
37353 + return ERR_PTR(-ENOSYS);
37354 + }
37355 +
37356 +-static inline int eventfd_signal(struct eventfd_ctx *ctx, int n)
37357 ++static inline int eventfd_signal(struct eventfd_ctx *ctx, __u64 n)
37358 + {
37359 + return -ENOSYS;
37360 + }
37361 +diff --git a/include/linux/fortify-string.h b/include/linux/fortify-string.h
37362 +index fce2fb2fc9626..c26160fe2e34e 100644
37363 +--- a/include/linux/fortify-string.h
37364 ++++ b/include/linux/fortify-string.h
37365 +@@ -3,6 +3,7 @@
37366 + #define _LINUX_FORTIFY_STRING_H_
37367 +
37368 + #include <linux/const.h>
37369 ++#include <linux/limits.h>
37370 +
37371 + #define __FORTIFY_INLINE extern __always_inline __gnu_inline __overloadable
37372 + #define __RENAME(x) __asm__(#x)
37373 +@@ -16,10 +17,10 @@ void __write_overflow_field(size_t avail, size_t wanted) __compiletime_warning("
37374 +
37375 + #define __compiletime_strlen(p) \
37376 + ({ \
37377 +- unsigned char *__p = (unsigned char *)(p); \
37378 +- size_t __ret = (size_t)-1; \
37379 ++ char *__p = (char *)(p); \
37380 ++ size_t __ret = SIZE_MAX; \
37381 + size_t __p_size = __builtin_object_size(p, 1); \
37382 +- if (__p_size != (size_t)-1 && \
37383 ++ if (__p_size != SIZE_MAX && \
37384 + __builtin_constant_p(*__p)) { \
37385 + size_t __p_len = __p_size - 1; \
37386 + if (__builtin_constant_p(__p[__p_len]) && \
37387 +@@ -95,7 +96,7 @@ char *strcat(char * const POS p, const char *q)
37388 + {
37389 + size_t p_size = __builtin_object_size(p, 1);
37390 +
37391 +- if (p_size == (size_t)-1)
37392 ++ if (p_size == SIZE_MAX)
37393 + return __underlying_strcat(p, q);
37394 + if (strlcat(p, q, p_size) >= p_size)
37395 + fortify_panic(__func__);
37396 +@@ -110,7 +111,7 @@ __FORTIFY_INLINE __kernel_size_t strnlen(const char * const POS p, __kernel_size
37397 + size_t ret;
37398 +
37399 + /* We can take compile-time actions when maxlen is const. */
37400 +- if (__builtin_constant_p(maxlen) && p_len != (size_t)-1) {
37401 ++ if (__builtin_constant_p(maxlen) && p_len != SIZE_MAX) {
37402 + /* If p is const, we can use its compile-time-known len. */
37403 + if (maxlen >= p_size)
37404 + return p_len;
37405 +@@ -138,7 +139,7 @@ __kernel_size_t __fortify_strlen(const char * const POS p)
37406 + size_t p_size = __builtin_object_size(p, 1);
37407 +
37408 + /* Give up if we don't know how large p is. */
37409 +- if (p_size == (size_t)-1)
37410 ++ if (p_size == SIZE_MAX)
37411 + return __underlying_strlen(p);
37412 + ret = strnlen(p, p_size);
37413 + if (p_size <= ret)
37414 +@@ -155,7 +156,7 @@ __FORTIFY_INLINE size_t strlcpy(char * const POS p, const char * const POS q, si
37415 + size_t q_len; /* Full count of source string length. */
37416 + size_t len; /* Count of characters going into destination. */
37417 +
37418 +- if (p_size == (size_t)-1 && q_size == (size_t)-1)
37419 ++ if (p_size == SIZE_MAX && q_size == SIZE_MAX)
37420 + return __real_strlcpy(p, q, size);
37421 + q_len = strlen(q);
37422 + len = (q_len >= size) ? size - 1 : q_len;
37423 +@@ -183,7 +184,7 @@ __FORTIFY_INLINE ssize_t strscpy(char * const POS p, const char * const POS q, s
37424 + size_t q_size = __builtin_object_size(q, 1);
37425 +
37426 + /* If we cannot get size of p and q default to call strscpy. */
37427 +- if (p_size == (size_t) -1 && q_size == (size_t) -1)
37428 ++ if (p_size == SIZE_MAX && q_size == SIZE_MAX)
37429 + return __real_strscpy(p, q, size);
37430 +
37431 + /*
37432 +@@ -228,7 +229,7 @@ char *strncat(char * const POS p, const char * const POS q, __kernel_size_t coun
37433 + size_t p_size = __builtin_object_size(p, 1);
37434 + size_t q_size = __builtin_object_size(q, 1);
37435 +
37436 +- if (p_size == (size_t)-1 && q_size == (size_t)-1)
37437 ++ if (p_size == SIZE_MAX && q_size == SIZE_MAX)
37438 + return __underlying_strncat(p, q, count);
37439 + p_len = strlen(p);
37440 + copy_len = strnlen(q, count);
37441 +@@ -269,10 +270,10 @@ __FORTIFY_INLINE void fortify_memset_chk(__kernel_size_t size,
37442 + /*
37443 + * Always stop accesses beyond the struct that contains the
37444 + * field, when the buffer's remaining size is known.
37445 +- * (The -1 test is to optimize away checks where the buffer
37446 ++ * (The SIZE_MAX test is to optimize away checks where the buffer
37447 + * lengths are unknown.)
37448 + */
37449 +- if (p_size != (size_t)(-1) && p_size < size)
37450 ++ if (p_size != SIZE_MAX && p_size < size)
37451 + fortify_panic("memset");
37452 + }
37453 +
37454 +@@ -363,11 +364,11 @@ __FORTIFY_INLINE void fortify_memcpy_chk(__kernel_size_t size,
37455 + /*
37456 + * Always stop accesses beyond the struct that contains the
37457 + * field, when the buffer's remaining size is known.
37458 +- * (The -1 test is to optimize away checks where the buffer
37459 ++ * (The SIZE_MAX test is to optimize away checks where the buffer
37460 + * lengths are unknown.)
37461 + */
37462 +- if ((p_size != (size_t)(-1) && p_size < size) ||
37463 +- (q_size != (size_t)(-1) && q_size < size))
37464 ++ if ((p_size != SIZE_MAX && p_size < size) ||
37465 ++ (q_size != SIZE_MAX && q_size < size))
37466 + fortify_panic(func);
37467 + }
37468 +
37469 +@@ -466,7 +467,7 @@ char *strcpy(char * const POS p, const char * const POS q)
37470 + size_t size;
37471 +
37472 + /* If neither buffer size is known, immediately give up. */
37473 +- if (p_size == (size_t)-1 && q_size == (size_t)-1)
37474 ++ if (p_size == SIZE_MAX && q_size == SIZE_MAX)
37475 + return __underlying_strcpy(p, q);
37476 + size = strlen(q) + 1;
37477 + /* Compile-time check for const size overflow. */
37478 +diff --git a/include/linux/fs.h b/include/linux/fs.h
37479 +index be074b6895b97..8e79a761c56c5 100644
37480 +--- a/include/linux/fs.h
37481 ++++ b/include/linux/fs.h
37482 +@@ -3480,7 +3480,7 @@ void simple_transaction_set(struct file *file, size_t n);
37483 + * All attributes contain a text representation of a numeric value
37484 + * that are accessed with the get() and set() functions.
37485 + */
37486 +-#define DEFINE_SIMPLE_ATTRIBUTE(__fops, __get, __set, __fmt) \
37487 ++#define DEFINE_SIMPLE_ATTRIBUTE_XSIGNED(__fops, __get, __set, __fmt, __is_signed) \
37488 + static int __fops ## _open(struct inode *inode, struct file *file) \
37489 + { \
37490 + __simple_attr_check_format(__fmt, 0ull); \
37491 +@@ -3491,10 +3491,16 @@ static const struct file_operations __fops = { \
37492 + .open = __fops ## _open, \
37493 + .release = simple_attr_release, \
37494 + .read = simple_attr_read, \
37495 +- .write = simple_attr_write, \
37496 ++ .write = (__is_signed) ? simple_attr_write_signed : simple_attr_write, \
37497 + .llseek = generic_file_llseek, \
37498 + }
37499 +
37500 ++#define DEFINE_SIMPLE_ATTRIBUTE(__fops, __get, __set, __fmt) \
37501 ++ DEFINE_SIMPLE_ATTRIBUTE_XSIGNED(__fops, __get, __set, __fmt, false)
37502 ++
37503 ++#define DEFINE_SIMPLE_ATTRIBUTE_SIGNED(__fops, __get, __set, __fmt) \
37504 ++ DEFINE_SIMPLE_ATTRIBUTE_XSIGNED(__fops, __get, __set, __fmt, true)
37505 ++
37506 + static inline __printf(1, 2)
37507 + void __simple_attr_check_format(const char *fmt, ...)
37508 + {
37509 +@@ -3509,6 +3515,8 @@ ssize_t simple_attr_read(struct file *file, char __user *buf,
37510 + size_t len, loff_t *ppos);
37511 + ssize_t simple_attr_write(struct file *file, const char __user *buf,
37512 + size_t len, loff_t *ppos);
37513 ++ssize_t simple_attr_write_signed(struct file *file, const char __user *buf,
37514 ++ size_t len, loff_t *ppos);
37515 +
37516 + struct ctl_table;
37517 + int __init list_bdev_fs_names(char *buf, size_t size);
37518 +diff --git a/include/linux/hisi_acc_qm.h b/include/linux/hisi_acc_qm.h
37519 +index 116e8bd68c999..ce0c3ed67a5f4 100644
37520 +--- a/include/linux/hisi_acc_qm.h
37521 ++++ b/include/linux/hisi_acc_qm.h
37522 +@@ -168,6 +168,15 @@ enum qm_vf_state {
37523 + QM_NOT_READY,
37524 + };
37525 +
37526 ++enum qm_cap_bits {
37527 ++ QM_SUPPORT_DB_ISOLATION = 0x0,
37528 ++ QM_SUPPORT_FUNC_QOS,
37529 ++ QM_SUPPORT_STOP_QP,
37530 ++ QM_SUPPORT_MB_COMMAND,
37531 ++ QM_SUPPORT_SVA_PREFETCH,
37532 ++ QM_SUPPORT_RPM,
37533 ++};
37534 ++
37535 + struct dfx_diff_registers {
37536 + u32 *regs;
37537 + u32 reg_offset;
37538 +@@ -258,6 +267,18 @@ struct hisi_qm_err_ini {
37539 + void (*err_info_init)(struct hisi_qm *qm);
37540 + };
37541 +
37542 ++struct hisi_qm_cap_info {
37543 ++ u32 type;
37544 ++ /* Register offset */
37545 ++ u32 offset;
37546 ++ /* Bit offset in register */
37547 ++ u32 shift;
37548 ++ u32 mask;
37549 ++ u32 v1_val;
37550 ++ u32 v2_val;
37551 ++ u32 v3_val;
37552 ++};
37553 ++
37554 + struct hisi_qm_list {
37555 + struct mutex lock;
37556 + struct list_head list;
37557 +@@ -278,6 +299,9 @@ struct hisi_qm {
37558 + struct pci_dev *pdev;
37559 + void __iomem *io_base;
37560 + void __iomem *db_io_base;
37561 ++
37562 ++ /* Capbility version, 0: not supports */
37563 ++ u32 cap_ver;
37564 + u32 sqe_size;
37565 + u32 qp_base;
37566 + u32 qp_num;
37567 +@@ -304,6 +328,8 @@ struct hisi_qm {
37568 + struct hisi_qm_err_info err_info;
37569 + struct hisi_qm_err_status err_status;
37570 + unsigned long misc_ctl; /* driver removing and reset sched */
37571 ++ /* Device capability bit */
37572 ++ unsigned long caps;
37573 +
37574 + struct rw_semaphore qps_lock;
37575 + struct idr qp_idr;
37576 +@@ -326,8 +352,6 @@ struct hisi_qm {
37577 + bool use_sva;
37578 + bool is_frozen;
37579 +
37580 +- /* doorbell isolation enable */
37581 +- bool use_db_isolation;
37582 + resource_size_t phys_base;
37583 + resource_size_t db_phys_base;
37584 + struct uacce_device *uacce;
37585 +@@ -376,14 +400,14 @@ struct hisi_qp {
37586 + static inline int q_num_set(const char *val, const struct kernel_param *kp,
37587 + unsigned int device)
37588 + {
37589 +- struct pci_dev *pdev = pci_get_device(PCI_VENDOR_ID_HUAWEI,
37590 +- device, NULL);
37591 ++ struct pci_dev *pdev;
37592 + u32 n, q_num;
37593 + int ret;
37594 +
37595 + if (!val)
37596 + return -EINVAL;
37597 +
37598 ++ pdev = pci_get_device(PCI_VENDOR_ID_HUAWEI, device, NULL);
37599 + if (!pdev) {
37600 + q_num = min_t(u32, QM_QNUM_V1, QM_QNUM_V2);
37601 + pr_info("No device found currently, suppose queue number is %u\n",
37602 +@@ -393,6 +417,8 @@ static inline int q_num_set(const char *val, const struct kernel_param *kp,
37603 + q_num = QM_QNUM_V1;
37604 + else
37605 + q_num = QM_QNUM_V2;
37606 ++
37607 ++ pci_dev_put(pdev);
37608 + }
37609 +
37610 + ret = kstrtou32(val, 10, &n);
37611 +@@ -501,6 +527,9 @@ void hisi_qm_pm_init(struct hisi_qm *qm);
37612 + int hisi_qm_get_dfx_access(struct hisi_qm *qm);
37613 + void hisi_qm_put_dfx_access(struct hisi_qm *qm);
37614 + void hisi_qm_regs_dump(struct seq_file *s, struct debugfs_regset32 *regset);
37615 ++u32 hisi_qm_get_hw_info(struct hisi_qm *qm,
37616 ++ const struct hisi_qm_cap_info *info_table,
37617 ++ u32 index, bool is_read);
37618 +
37619 + /* Used by VFIO ACC live migration driver */
37620 + struct pci_driver *hisi_sec_get_pf_driver(void);
37621 +diff --git a/include/linux/hyperv.h b/include/linux/hyperv.h
37622 +index 3b42264333ef8..646f1da9f27e0 100644
37623 +--- a/include/linux/hyperv.h
37624 ++++ b/include/linux/hyperv.h
37625 +@@ -1341,6 +1341,8 @@ struct hv_ring_buffer_debug_info {
37626 + int hv_ringbuffer_get_debuginfo(struct hv_ring_buffer_info *ring_info,
37627 + struct hv_ring_buffer_debug_info *debug_info);
37628 +
37629 ++bool hv_ringbuffer_spinlock_busy(struct vmbus_channel *channel);
37630 ++
37631 + /* Vmbus interface */
37632 + #define vmbus_driver_register(driver) \
37633 + __vmbus_driver_register(driver, THIS_MODULE, KBUILD_MODNAME)
37634 +diff --git a/include/linux/ieee80211.h b/include/linux/ieee80211.h
37635 +index b6e6d5b407747..181e758c70c12 100644
37636 +--- a/include/linux/ieee80211.h
37637 ++++ b/include/linux/ieee80211.h
37638 +@@ -4588,7 +4588,7 @@ static inline u8 ieee80211_mle_common_size(const u8 *data)
37639 + return 0;
37640 + }
37641 +
37642 +- return common + mle->variable[0];
37643 ++ return sizeof(*mle) + common + mle->variable[0];
37644 + }
37645 +
37646 + /**
37647 +diff --git a/include/linux/iio/imu/adis.h b/include/linux/iio/imu/adis.h
37648 +index 515ca09764fe4..bcbefb7574751 100644
37649 +--- a/include/linux/iio/imu/adis.h
37650 ++++ b/include/linux/iio/imu/adis.h
37651 +@@ -402,9 +402,20 @@ static inline int adis_update_bits_base(struct adis *adis, unsigned int reg,
37652 + __adis_update_bits_base(adis, reg, mask, val, sizeof(val)); \
37653 + })
37654 +
37655 +-int adis_enable_irq(struct adis *adis, bool enable);
37656 + int __adis_check_status(struct adis *adis);
37657 + int __adis_initial_startup(struct adis *adis);
37658 ++int __adis_enable_irq(struct adis *adis, bool enable);
37659 ++
37660 ++static inline int adis_enable_irq(struct adis *adis, bool enable)
37661 ++{
37662 ++ int ret;
37663 ++
37664 ++ mutex_lock(&adis->state_lock);
37665 ++ ret = __adis_enable_irq(adis, enable);
37666 ++ mutex_unlock(&adis->state_lock);
37667 ++
37668 ++ return ret;
37669 ++}
37670 +
37671 + static inline int adis_check_status(struct adis *adis)
37672 + {
37673 +diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
37674 +index 05d6f3facd5a5..47b8b0ab76946 100644
37675 +--- a/include/linux/netdevice.h
37676 ++++ b/include/linux/netdevice.h
37677 +@@ -171,31 +171,38 @@ static inline bool dev_xmit_complete(int rc)
37678 + * (unsigned long) so they can be read and written atomically.
37679 + */
37680 +
37681 ++#define NET_DEV_STAT(FIELD) \
37682 ++ union { \
37683 ++ unsigned long FIELD; \
37684 ++ atomic_long_t __##FIELD; \
37685 ++ }
37686 ++
37687 + struct net_device_stats {
37688 +- unsigned long rx_packets;
37689 +- unsigned long tx_packets;
37690 +- unsigned long rx_bytes;
37691 +- unsigned long tx_bytes;
37692 +- unsigned long rx_errors;
37693 +- unsigned long tx_errors;
37694 +- unsigned long rx_dropped;
37695 +- unsigned long tx_dropped;
37696 +- unsigned long multicast;
37697 +- unsigned long collisions;
37698 +- unsigned long rx_length_errors;
37699 +- unsigned long rx_over_errors;
37700 +- unsigned long rx_crc_errors;
37701 +- unsigned long rx_frame_errors;
37702 +- unsigned long rx_fifo_errors;
37703 +- unsigned long rx_missed_errors;
37704 +- unsigned long tx_aborted_errors;
37705 +- unsigned long tx_carrier_errors;
37706 +- unsigned long tx_fifo_errors;
37707 +- unsigned long tx_heartbeat_errors;
37708 +- unsigned long tx_window_errors;
37709 +- unsigned long rx_compressed;
37710 +- unsigned long tx_compressed;
37711 ++ NET_DEV_STAT(rx_packets);
37712 ++ NET_DEV_STAT(tx_packets);
37713 ++ NET_DEV_STAT(rx_bytes);
37714 ++ NET_DEV_STAT(tx_bytes);
37715 ++ NET_DEV_STAT(rx_errors);
37716 ++ NET_DEV_STAT(tx_errors);
37717 ++ NET_DEV_STAT(rx_dropped);
37718 ++ NET_DEV_STAT(tx_dropped);
37719 ++ NET_DEV_STAT(multicast);
37720 ++ NET_DEV_STAT(collisions);
37721 ++ NET_DEV_STAT(rx_length_errors);
37722 ++ NET_DEV_STAT(rx_over_errors);
37723 ++ NET_DEV_STAT(rx_crc_errors);
37724 ++ NET_DEV_STAT(rx_frame_errors);
37725 ++ NET_DEV_STAT(rx_fifo_errors);
37726 ++ NET_DEV_STAT(rx_missed_errors);
37727 ++ NET_DEV_STAT(tx_aborted_errors);
37728 ++ NET_DEV_STAT(tx_carrier_errors);
37729 ++ NET_DEV_STAT(tx_fifo_errors);
37730 ++ NET_DEV_STAT(tx_heartbeat_errors);
37731 ++ NET_DEV_STAT(tx_window_errors);
37732 ++ NET_DEV_STAT(rx_compressed);
37733 ++ NET_DEV_STAT(tx_compressed);
37734 + };
37735 ++#undef NET_DEV_STAT
37736 +
37737 + /* per-cpu stats, allocated on demand.
37738 + * Try to fit them in a single cache line, for dev_get_stats() sake.
37739 +@@ -5143,4 +5150,9 @@ extern struct list_head ptype_base[PTYPE_HASH_SIZE] __read_mostly;
37740 +
37741 + extern struct net_device *blackhole_netdev;
37742 +
37743 ++/* Note: Avoid these macros in fast path, prefer per-cpu or per-queue counters. */
37744 ++#define DEV_STATS_INC(DEV, FIELD) atomic_long_inc(&(DEV)->stats.__##FIELD)
37745 ++#define DEV_STATS_ADD(DEV, FIELD, VAL) \
37746 ++ atomic_long_add((VAL), &(DEV)->stats.__##FIELD)
37747 ++
37748 + #endif /* _LINUX_NETDEVICE_H */
37749 +diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
37750 +index 81d6e4ec2294b..0260f5ea98fe1 100644
37751 +--- a/include/linux/proc_fs.h
37752 ++++ b/include/linux/proc_fs.h
37753 +@@ -208,8 +208,10 @@ static inline void proc_remove(struct proc_dir_entry *de) {}
37754 + static inline int remove_proc_subtree(const char *name, struct proc_dir_entry *parent) { return 0; }
37755 +
37756 + #define proc_create_net_data(name, mode, parent, ops, state_size, data) ({NULL;})
37757 ++#define proc_create_net_data_write(name, mode, parent, ops, write, state_size, data) ({NULL;})
37758 + #define proc_create_net(name, mode, parent, state_size, ops) ({NULL;})
37759 + #define proc_create_net_single(name, mode, parent, show, data) ({NULL;})
37760 ++#define proc_create_net_single_write(name, mode, parent, show, write, data) ({NULL;})
37761 +
37762 + static inline struct pid *tgid_pidfd_to_pid(const struct file *file)
37763 + {
37764 +diff --git a/include/linux/regulator/driver.h b/include/linux/regulator/driver.h
37765 +index f9a7461e72b80..d3b4a3d4514ab 100644
37766 +--- a/include/linux/regulator/driver.h
37767 ++++ b/include/linux/regulator/driver.h
37768 +@@ -687,7 +687,8 @@ static inline int regulator_err2notif(int err)
37769 +
37770 +
37771 + struct regulator_dev *
37772 +-regulator_register(const struct regulator_desc *regulator_desc,
37773 ++regulator_register(struct device *dev,
37774 ++ const struct regulator_desc *regulator_desc,
37775 + const struct regulator_config *config);
37776 + struct regulator_dev *
37777 + devm_regulator_register(struct device *dev,
37778 +diff --git a/include/linux/skmsg.h b/include/linux/skmsg.h
37779 +index 70d6cb94e5802..84f787416a54d 100644
37780 +--- a/include/linux/skmsg.h
37781 ++++ b/include/linux/skmsg.h
37782 +@@ -82,6 +82,7 @@ struct sk_psock {
37783 + u32 apply_bytes;
37784 + u32 cork_bytes;
37785 + u32 eval;
37786 ++ bool redir_ingress; /* undefined if sk_redir is null */
37787 + struct sk_msg *cork;
37788 + struct sk_psock_progs progs;
37789 + #if IS_ENABLED(CONFIG_BPF_STREAM_PARSER)
37790 +diff --git a/include/linux/timerqueue.h b/include/linux/timerqueue.h
37791 +index 93884086f3924..adc80e29168ea 100644
37792 +--- a/include/linux/timerqueue.h
37793 ++++ b/include/linux/timerqueue.h
37794 +@@ -35,7 +35,7 @@ struct timerqueue_node *timerqueue_getnext(struct timerqueue_head *head)
37795 + {
37796 + struct rb_node *leftmost = rb_first_cached(&head->rb_root);
37797 +
37798 +- return rb_entry(leftmost, struct timerqueue_node, node);
37799 ++ return rb_entry_safe(leftmost, struct timerqueue_node, node);
37800 + }
37801 +
37802 + static inline void timerqueue_init(struct timerqueue_node *node)
37803 +diff --git a/include/media/dvbdev.h b/include/media/dvbdev.h
37804 +index 2f6b0861322ae..ac60c9fcfe9a6 100644
37805 +--- a/include/media/dvbdev.h
37806 ++++ b/include/media/dvbdev.h
37807 +@@ -126,6 +126,7 @@ struct dvb_adapter {
37808 + * struct dvb_device - represents a DVB device node
37809 + *
37810 + * @list_head: List head with all DVB devices
37811 ++ * @ref: reference counter
37812 + * @fops: pointer to struct file_operations
37813 + * @adapter: pointer to the adapter that holds this device node
37814 + * @type: type of the device, as defined by &enum dvb_device_type.
37815 +@@ -156,6 +157,7 @@ struct dvb_adapter {
37816 + */
37817 + struct dvb_device {
37818 + struct list_head list_head;
37819 ++ struct kref ref;
37820 + const struct file_operations *fops;
37821 + struct dvb_adapter *adapter;
37822 + enum dvb_device_type type;
37823 +@@ -187,6 +189,20 @@ struct dvb_device {
37824 + void *priv;
37825 + };
37826 +
37827 ++/**
37828 ++ * dvb_device_get - Increase dvb_device reference
37829 ++ *
37830 ++ * @dvbdev: pointer to struct dvb_device
37831 ++ */
37832 ++struct dvb_device *dvb_device_get(struct dvb_device *dvbdev);
37833 ++
37834 ++/**
37835 ++ * dvb_device_put - Decrease dvb_device reference
37836 ++ *
37837 ++ * @dvbdev: pointer to struct dvb_device
37838 ++ */
37839 ++void dvb_device_put(struct dvb_device *dvbdev);
37840 ++
37841 + /**
37842 + * dvb_register_adapter - Registers a new DVB adapter
37843 + *
37844 +@@ -231,29 +247,17 @@ int dvb_register_device(struct dvb_adapter *adap,
37845 + /**
37846 + * dvb_remove_device - Remove a registered DVB device
37847 + *
37848 +- * This does not free memory. To do that, call dvb_free_device().
37849 ++ * This does not free memory. dvb_free_device() will do that when
37850 ++ * reference counter is empty
37851 + *
37852 + * @dvbdev: pointer to struct dvb_device
37853 + */
37854 + void dvb_remove_device(struct dvb_device *dvbdev);
37855 +
37856 +-/**
37857 +- * dvb_free_device - Free memory occupied by a DVB device.
37858 +- *
37859 +- * Call dvb_unregister_device() before calling this function.
37860 +- *
37861 +- * @dvbdev: pointer to struct dvb_device
37862 +- */
37863 +-void dvb_free_device(struct dvb_device *dvbdev);
37864 +
37865 + /**
37866 + * dvb_unregister_device - Unregisters a DVB device
37867 + *
37868 +- * This is a combination of dvb_remove_device() and dvb_free_device().
37869 +- * Using this function is usually a mistake, and is often an indicator
37870 +- * for a use-after-free bug (when a userspace process keeps a file
37871 +- * handle to a detached device).
37872 +- *
37873 + * @dvbdev: pointer to struct dvb_device
37874 + */
37875 + void dvb_unregister_device(struct dvb_device *dvbdev);
37876 +diff --git a/include/net/bluetooth/hci.h b/include/net/bluetooth/hci.h
37877 +index 4518c63e9d179..dd455ce067701 100644
37878 +--- a/include/net/bluetooth/hci.h
37879 ++++ b/include/net/bluetooth/hci.h
37880 +@@ -274,6 +274,26 @@ enum {
37881 + * during the hdev->setup vendor callback.
37882 + */
37883 + HCI_QUIRK_BROKEN_ENHANCED_SETUP_SYNC_CONN,
37884 ++
37885 ++ /*
37886 ++ * When this quirk is set, the HCI_OP_LE_SET_EXT_SCAN_ENABLE command is
37887 ++ * disabled. This is required for some Broadcom controllers which
37888 ++ * erroneously claim to support extended scanning.
37889 ++ *
37890 ++ * This quirk can be set before hci_register_dev is called or
37891 ++ * during the hdev->setup vendor callback.
37892 ++ */
37893 ++ HCI_QUIRK_BROKEN_EXT_SCAN,
37894 ++
37895 ++ /*
37896 ++ * When this quirk is set, the HCI_OP_GET_MWS_TRANSPORT_CONFIG command is
37897 ++ * disabled. This is required for some Broadcom controllers which
37898 ++ * erroneously claim to support MWS Transport Layer Configuration.
37899 ++ *
37900 ++ * This quirk can be set before hci_register_dev is called or
37901 ++ * during the hdev->setup vendor callback.
37902 ++ */
37903 ++ HCI_QUIRK_BROKEN_MWS_TRANSPORT_CONFIG,
37904 + };
37905 +
37906 + /* HCI device flags */
37907 +diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
37908 +index e7862903187d8..6afb4771ce355 100644
37909 +--- a/include/net/bluetooth/hci_core.h
37910 ++++ b/include/net/bluetooth/hci_core.h
37911 +@@ -1681,7 +1681,9 @@ void hci_conn_del_sysfs(struct hci_conn *conn);
37912 +
37913 + /* Use ext scanning if set ext scan param and ext scan enable is supported */
37914 + #define use_ext_scan(dev) (((dev)->commands[37] & 0x20) && \
37915 +- ((dev)->commands[37] & 0x40))
37916 ++ ((dev)->commands[37] & 0x40) && \
37917 ++ !test_bit(HCI_QUIRK_BROKEN_EXT_SCAN, &(dev)->quirks))
37918 ++
37919 + /* Use ext create connection if command is supported */
37920 + #define use_ext_conn(dev) ((dev)->commands[37] & 0x80)
37921 +
37922 +@@ -1709,6 +1711,9 @@ void hci_conn_del_sysfs(struct hci_conn *conn);
37923 + ((dev)->le_features[3] & HCI_LE_CIS_PERIPHERAL)
37924 + #define bis_capable(dev) ((dev)->le_features[3] & HCI_LE_ISO_BROADCASTER)
37925 +
37926 ++#define mws_transport_config_capable(dev) (((dev)->commands[30] & 0x08) && \
37927 ++ (!test_bit(HCI_QUIRK_BROKEN_MWS_TRANSPORT_CONFIG, &(dev)->quirks)))
37928 ++
37929 + /* ----- HCI protocols ----- */
37930 + #define HCI_PROTO_DEFER 0x01
37931 +
37932 +diff --git a/include/net/dst.h b/include/net/dst.h
37933 +index 6aa252c3fc55c..19af7a2713ccb 100644
37934 +--- a/include/net/dst.h
37935 ++++ b/include/net/dst.h
37936 +@@ -362,9 +362,8 @@ static inline void __skb_tunnel_rx(struct sk_buff *skb, struct net_device *dev,
37937 + static inline void skb_tunnel_rx(struct sk_buff *skb, struct net_device *dev,
37938 + struct net *net)
37939 + {
37940 +- /* TODO : stats should be SMP safe */
37941 +- dev->stats.rx_packets++;
37942 +- dev->stats.rx_bytes += skb->len;
37943 ++ DEV_STATS_INC(dev, rx_packets);
37944 ++ DEV_STATS_ADD(dev, rx_bytes, skb->len);
37945 + __skb_tunnel_rx(skb, dev, net);
37946 + }
37947 +
37948 +diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
37949 +index ff1804a0c4692..1fca6a88114ad 100644
37950 +--- a/include/net/ip_vs.h
37951 ++++ b/include/net/ip_vs.h
37952 +@@ -351,11 +351,11 @@ struct ip_vs_seq {
37953 +
37954 + /* counters per cpu */
37955 + struct ip_vs_counters {
37956 +- __u64 conns; /* connections scheduled */
37957 +- __u64 inpkts; /* incoming packets */
37958 +- __u64 outpkts; /* outgoing packets */
37959 +- __u64 inbytes; /* incoming bytes */
37960 +- __u64 outbytes; /* outgoing bytes */
37961 ++ u64_stats_t conns; /* connections scheduled */
37962 ++ u64_stats_t inpkts; /* incoming packets */
37963 ++ u64_stats_t outpkts; /* outgoing packets */
37964 ++ u64_stats_t inbytes; /* incoming bytes */
37965 ++ u64_stats_t outbytes; /* outgoing bytes */
37966 + };
37967 + /* Stats per cpu */
37968 + struct ip_vs_cpu_stats {
37969 +diff --git a/include/net/mrp.h b/include/net/mrp.h
37970 +index 92cd3fb6cf9da..b28915ffea284 100644
37971 +--- a/include/net/mrp.h
37972 ++++ b/include/net/mrp.h
37973 +@@ -124,6 +124,7 @@ struct mrp_applicant {
37974 + struct sk_buff *pdu;
37975 + struct rb_root mad;
37976 + struct rcu_head rcu;
37977 ++ bool active;
37978 + };
37979 +
37980 + struct mrp_port {
37981 +diff --git a/include/net/sock_reuseport.h b/include/net/sock_reuseport.h
37982 +index efc9085c68927..6ec140b0a61bf 100644
37983 +--- a/include/net/sock_reuseport.h
37984 ++++ b/include/net/sock_reuseport.h
37985 +@@ -16,6 +16,7 @@ struct sock_reuseport {
37986 + u16 max_socks; /* length of socks */
37987 + u16 num_socks; /* elements in socks */
37988 + u16 num_closed_socks; /* closed elements in socks */
37989 ++ u16 incoming_cpu;
37990 + /* The last synq overflow event timestamp of this
37991 + * reuse->socks[] group.
37992 + */
37993 +@@ -58,5 +59,6 @@ static inline bool reuseport_has_conns(struct sock *sk)
37994 + }
37995 +
37996 + void reuseport_has_conns_set(struct sock *sk);
37997 ++void reuseport_update_incoming_cpu(struct sock *sk, int val);
37998 +
37999 + #endif /* _SOCK_REUSEPORT_H */
38000 +diff --git a/include/net/tcp.h b/include/net/tcp.h
38001 +index 95c1d51393ac4..3cde7b4a401f2 100644
38002 +--- a/include/net/tcp.h
38003 ++++ b/include/net/tcp.h
38004 +@@ -2284,8 +2284,8 @@ int tcp_bpf_update_proto(struct sock *sk, struct sk_psock *psock, bool restore);
38005 + void tcp_bpf_clone(const struct sock *sk, struct sock *newsk);
38006 + #endif /* CONFIG_BPF_SYSCALL */
38007 +
38008 +-int tcp_bpf_sendmsg_redir(struct sock *sk, struct sk_msg *msg, u32 bytes,
38009 +- int flags);
38010 ++int tcp_bpf_sendmsg_redir(struct sock *sk, bool ingress,
38011 ++ struct sk_msg *msg, u32 bytes, int flags);
38012 + #endif /* CONFIG_NET_SOCK_MSG */
38013 +
38014 + #if !defined(CONFIG_BPF_SYSCALL) || !defined(CONFIG_NET_SOCK_MSG)
38015 +diff --git a/include/scsi/sas_ata.h b/include/scsi/sas_ata.h
38016 +index a1df4f9d57a31..ec646217e7f6e 100644
38017 +--- a/include/scsi/sas_ata.h
38018 ++++ b/include/scsi/sas_ata.h
38019 +@@ -35,6 +35,7 @@ void sas_ata_end_eh(struct ata_port *ap);
38020 + int sas_execute_ata_cmd(struct domain_device *device, u8 *fis,
38021 + int force_phy_id);
38022 + int sas_ata_wait_after_reset(struct domain_device *dev, unsigned long deadline);
38023 ++int smp_ata_check_ready_type(struct ata_link *link);
38024 + #else
38025 +
38026 +
38027 +@@ -98,6 +99,11 @@ static inline int sas_ata_wait_after_reset(struct domain_device *dev,
38028 + {
38029 + return -ETIMEDOUT;
38030 + }
38031 ++
38032 ++static inline int smp_ata_check_ready_type(struct ata_link *link)
38033 ++{
38034 ++ return 0;
38035 ++}
38036 + #endif
38037 +
38038 + #endif /* _SAS_ATA_H_ */
38039 +diff --git a/include/sound/hda_codec.h b/include/sound/hda_codec.h
38040 +index 6d3c82c4b6acd..ec2a2ba21cc39 100644
38041 +--- a/include/sound/hda_codec.h
38042 ++++ b/include/sound/hda_codec.h
38043 +@@ -258,7 +258,7 @@ struct hda_codec {
38044 + unsigned int link_down_at_suspend:1; /* link down at runtime suspend */
38045 + unsigned int relaxed_resume:1; /* don't resume forcibly for jack */
38046 + unsigned int forced_resume:1; /* forced resume for jack */
38047 +- unsigned int mst_no_extra_pcms:1; /* no backup PCMs for DP-MST */
38048 ++ unsigned int no_stream_clean_at_suspend:1; /* do not clean streams at suspend */
38049 +
38050 + #ifdef CONFIG_PM
38051 + unsigned long power_on_acct;
38052 +diff --git a/include/sound/hdaudio.h b/include/sound/hdaudio.h
38053 +index 797bf67a164db..ceaa7b7cfdc30 100644
38054 +--- a/include/sound/hdaudio.h
38055 ++++ b/include/sound/hdaudio.h
38056 +@@ -562,6 +562,7 @@ int snd_hdac_stream_set_params(struct hdac_stream *azx_dev,
38057 + void snd_hdac_stream_start(struct hdac_stream *azx_dev, bool fresh_start);
38058 + void snd_hdac_stream_clear(struct hdac_stream *azx_dev);
38059 + void snd_hdac_stream_stop(struct hdac_stream *azx_dev);
38060 ++void snd_hdac_stop_streams(struct hdac_bus *bus);
38061 + void snd_hdac_stop_streams_and_chip(struct hdac_bus *bus);
38062 + void snd_hdac_stream_reset(struct hdac_stream *azx_dev);
38063 + void snd_hdac_stream_sync_trigger(struct hdac_stream *azx_dev, bool set,
38064 +diff --git a/include/sound/pcm.h b/include/sound/pcm.h
38065 +index 8c48a5bce88c1..25695f5f795a1 100644
38066 +--- a/include/sound/pcm.h
38067 ++++ b/include/sound/pcm.h
38068 +@@ -106,24 +106,24 @@ struct snd_pcm_ops {
38069 + #define SNDRV_PCM_POS_XRUN ((snd_pcm_uframes_t)-1)
38070 +
38071 + /* If you change this don't forget to change rates[] table in pcm_native.c */
38072 +-#define SNDRV_PCM_RATE_5512 (1<<0) /* 5512Hz */
38073 +-#define SNDRV_PCM_RATE_8000 (1<<1) /* 8000Hz */
38074 +-#define SNDRV_PCM_RATE_11025 (1<<2) /* 11025Hz */
38075 +-#define SNDRV_PCM_RATE_16000 (1<<3) /* 16000Hz */
38076 +-#define SNDRV_PCM_RATE_22050 (1<<4) /* 22050Hz */
38077 +-#define SNDRV_PCM_RATE_32000 (1<<5) /* 32000Hz */
38078 +-#define SNDRV_PCM_RATE_44100 (1<<6) /* 44100Hz */
38079 +-#define SNDRV_PCM_RATE_48000 (1<<7) /* 48000Hz */
38080 +-#define SNDRV_PCM_RATE_64000 (1<<8) /* 64000Hz */
38081 +-#define SNDRV_PCM_RATE_88200 (1<<9) /* 88200Hz */
38082 +-#define SNDRV_PCM_RATE_96000 (1<<10) /* 96000Hz */
38083 +-#define SNDRV_PCM_RATE_176400 (1<<11) /* 176400Hz */
38084 +-#define SNDRV_PCM_RATE_192000 (1<<12) /* 192000Hz */
38085 +-#define SNDRV_PCM_RATE_352800 (1<<13) /* 352800Hz */
38086 +-#define SNDRV_PCM_RATE_384000 (1<<14) /* 384000Hz */
38087 +-
38088 +-#define SNDRV_PCM_RATE_CONTINUOUS (1<<30) /* continuous range */
38089 +-#define SNDRV_PCM_RATE_KNOT (1<<31) /* supports more non-continuos rates */
38090 ++#define SNDRV_PCM_RATE_5512 (1U<<0) /* 5512Hz */
38091 ++#define SNDRV_PCM_RATE_8000 (1U<<1) /* 8000Hz */
38092 ++#define SNDRV_PCM_RATE_11025 (1U<<2) /* 11025Hz */
38093 ++#define SNDRV_PCM_RATE_16000 (1U<<3) /* 16000Hz */
38094 ++#define SNDRV_PCM_RATE_22050 (1U<<4) /* 22050Hz */
38095 ++#define SNDRV_PCM_RATE_32000 (1U<<5) /* 32000Hz */
38096 ++#define SNDRV_PCM_RATE_44100 (1U<<6) /* 44100Hz */
38097 ++#define SNDRV_PCM_RATE_48000 (1U<<7) /* 48000Hz */
38098 ++#define SNDRV_PCM_RATE_64000 (1U<<8) /* 64000Hz */
38099 ++#define SNDRV_PCM_RATE_88200 (1U<<9) /* 88200Hz */
38100 ++#define SNDRV_PCM_RATE_96000 (1U<<10) /* 96000Hz */
38101 ++#define SNDRV_PCM_RATE_176400 (1U<<11) /* 176400Hz */
38102 ++#define SNDRV_PCM_RATE_192000 (1U<<12) /* 192000Hz */
38103 ++#define SNDRV_PCM_RATE_352800 (1U<<13) /* 352800Hz */
38104 ++#define SNDRV_PCM_RATE_384000 (1U<<14) /* 384000Hz */
38105 ++
38106 ++#define SNDRV_PCM_RATE_CONTINUOUS (1U<<30) /* continuous range */
38107 ++#define SNDRV_PCM_RATE_KNOT (1U<<31) /* supports more non-continuos rates */
38108 +
38109 + #define SNDRV_PCM_RATE_8000_44100 (SNDRV_PCM_RATE_8000|SNDRV_PCM_RATE_11025|\
38110 + SNDRV_PCM_RATE_16000|SNDRV_PCM_RATE_22050|\
38111 +diff --git a/include/trace/events/f2fs.h b/include/trace/events/f2fs.h
38112 +index f1e9222377368..f4556911c2347 100644
38113 +--- a/include/trace/events/f2fs.h
38114 ++++ b/include/trace/events/f2fs.h
38115 +@@ -322,7 +322,7 @@ TRACE_EVENT(f2fs_unlink_enter,
38116 + __field(ino_t, ino)
38117 + __field(loff_t, size)
38118 + __field(blkcnt_t, blocks)
38119 +- __field(const char *, name)
38120 ++ __string(name, dentry->d_name.name)
38121 + ),
38122 +
38123 + TP_fast_assign(
38124 +@@ -330,7 +330,7 @@ TRACE_EVENT(f2fs_unlink_enter,
38125 + __entry->ino = dir->i_ino;
38126 + __entry->size = dir->i_size;
38127 + __entry->blocks = dir->i_blocks;
38128 +- __entry->name = dentry->d_name.name;
38129 ++ __assign_str(name, dentry->d_name.name);
38130 + ),
38131 +
38132 + TP_printk("dev = (%d,%d), dir ino = %lu, i_size = %lld, "
38133 +@@ -338,7 +338,7 @@ TRACE_EVENT(f2fs_unlink_enter,
38134 + show_dev_ino(__entry),
38135 + __entry->size,
38136 + (unsigned long long)__entry->blocks,
38137 +- __entry->name)
38138 ++ __get_str(name))
38139 + );
38140 +
38141 + DEFINE_EVENT(f2fs__inode_exit, f2fs_unlink_exit,
38142 +@@ -940,25 +940,29 @@ TRACE_EVENT(f2fs_direct_IO_enter,
38143 + TP_STRUCT__entry(
38144 + __field(dev_t, dev)
38145 + __field(ino_t, ino)
38146 +- __field(struct kiocb *, iocb)
38147 ++ __field(loff_t, ki_pos)
38148 ++ __field(int, ki_flags)
38149 ++ __field(u16, ki_ioprio)
38150 + __field(unsigned long, len)
38151 + __field(int, rw)
38152 + ),
38153 +
38154 + TP_fast_assign(
38155 +- __entry->dev = inode->i_sb->s_dev;
38156 +- __entry->ino = inode->i_ino;
38157 +- __entry->iocb = iocb;
38158 +- __entry->len = len;
38159 +- __entry->rw = rw;
38160 ++ __entry->dev = inode->i_sb->s_dev;
38161 ++ __entry->ino = inode->i_ino;
38162 ++ __entry->ki_pos = iocb->ki_pos;
38163 ++ __entry->ki_flags = iocb->ki_flags;
38164 ++ __entry->ki_ioprio = iocb->ki_ioprio;
38165 ++ __entry->len = len;
38166 ++ __entry->rw = rw;
38167 + ),
38168 +
38169 + TP_printk("dev = (%d,%d), ino = %lu pos = %lld len = %lu ki_flags = %x ki_ioprio = %x rw = %d",
38170 + show_dev_ino(__entry),
38171 +- __entry->iocb->ki_pos,
38172 ++ __entry->ki_pos,
38173 + __entry->len,
38174 +- __entry->iocb->ki_flags,
38175 +- __entry->iocb->ki_ioprio,
38176 ++ __entry->ki_flags,
38177 ++ __entry->ki_ioprio,
38178 + __entry->rw)
38179 + );
38180 +
38181 +@@ -1407,19 +1411,19 @@ TRACE_EVENT(f2fs_write_checkpoint,
38182 + TP_STRUCT__entry(
38183 + __field(dev_t, dev)
38184 + __field(int, reason)
38185 +- __field(char *, msg)
38186 ++ __string(dest_msg, msg)
38187 + ),
38188 +
38189 + TP_fast_assign(
38190 + __entry->dev = sb->s_dev;
38191 + __entry->reason = reason;
38192 +- __entry->msg = msg;
38193 ++ __assign_str(dest_msg, msg);
38194 + ),
38195 +
38196 + TP_printk("dev = (%d,%d), checkpoint for %s, state = %s",
38197 + show_dev(__entry->dev),
38198 + show_cpreason(__entry->reason),
38199 +- __entry->msg)
38200 ++ __get_str(dest_msg))
38201 + );
38202 +
38203 + DECLARE_EVENT_CLASS(f2fs_discard,
38204 +diff --git a/include/trace/events/ib_mad.h b/include/trace/events/ib_mad.h
38205 +index 59363a083ecb9..d92691c78cff6 100644
38206 +--- a/include/trace/events/ib_mad.h
38207 ++++ b/include/trace/events/ib_mad.h
38208 +@@ -49,7 +49,6 @@ DECLARE_EVENT_CLASS(ib_mad_send_template,
38209 + __field(int, retries_left)
38210 + __field(int, max_retries)
38211 + __field(int, retry)
38212 +- __field(u16, pkey)
38213 + ),
38214 +
38215 + TP_fast_assign(
38216 +@@ -89,7 +88,7 @@ DECLARE_EVENT_CLASS(ib_mad_send_template,
38217 + "hdr : base_ver 0x%x class 0x%x class_ver 0x%x " \
38218 + "method 0x%x status 0x%x class_specific 0x%x tid 0x%llx " \
38219 + "attr_id 0x%x attr_mod 0x%x => dlid 0x%08x sl %d "\
38220 +- "pkey 0x%x rpqn 0x%x rqpkey 0x%x",
38221 ++ "rpqn 0x%x rqpkey 0x%x",
38222 + __entry->dev_index, __entry->port_num, __entry->qp_num,
38223 + __entry->agent_priv, be64_to_cpu(__entry->wrtid),
38224 + __entry->retries_left, __entry->max_retries,
38225 +@@ -100,7 +99,7 @@ DECLARE_EVENT_CLASS(ib_mad_send_template,
38226 + be16_to_cpu(__entry->class_specific),
38227 + be64_to_cpu(__entry->tid), be16_to_cpu(__entry->attr_id),
38228 + be32_to_cpu(__entry->attr_mod),
38229 +- be32_to_cpu(__entry->dlid), __entry->sl, __entry->pkey,
38230 ++ be32_to_cpu(__entry->dlid), __entry->sl,
38231 + __entry->rqpn, __entry->rqkey
38232 + )
38233 + );
38234 +@@ -204,7 +203,6 @@ TRACE_EVENT(ib_mad_recv_done_handler,
38235 + __field(u16, wc_status)
38236 + __field(u32, slid)
38237 + __field(u32, dev_index)
38238 +- __field(u16, pkey)
38239 + ),
38240 +
38241 + TP_fast_assign(
38242 +@@ -224,9 +222,6 @@ TRACE_EVENT(ib_mad_recv_done_handler,
38243 + __entry->slid = wc->slid;
38244 + __entry->src_qp = wc->src_qp;
38245 + __entry->sl = wc->sl;
38246 +- ib_query_pkey(qp_info->port_priv->device,
38247 +- qp_info->port_priv->port_num,
38248 +- wc->pkey_index, &__entry->pkey);
38249 + __entry->wc_status = wc->status;
38250 + ),
38251 +
38252 +@@ -234,7 +229,7 @@ TRACE_EVENT(ib_mad_recv_done_handler,
38253 + "base_ver 0x%02x class 0x%02x class_ver 0x%02x " \
38254 + "method 0x%02x status 0x%04x class_specific 0x%04x " \
38255 + "tid 0x%016llx attr_id 0x%04x attr_mod 0x%08x " \
38256 +- "slid 0x%08x src QP%d, sl %d pkey 0x%04x",
38257 ++ "slid 0x%08x src QP%d, sl %d",
38258 + __entry->dev_index, __entry->port_num, __entry->qp_num,
38259 + __entry->wc_status,
38260 + __entry->length,
38261 +@@ -244,7 +239,7 @@ TRACE_EVENT(ib_mad_recv_done_handler,
38262 + be16_to_cpu(__entry->class_specific),
38263 + be64_to_cpu(__entry->tid), be16_to_cpu(__entry->attr_id),
38264 + be32_to_cpu(__entry->attr_mod),
38265 +- __entry->slid, __entry->src_qp, __entry->sl, __entry->pkey
38266 ++ __entry->slid, __entry->src_qp, __entry->sl
38267 + )
38268 + );
38269 +
38270 +diff --git a/include/uapi/linux/idxd.h b/include/uapi/linux/idxd.h
38271 +index 2b9e7feba3f32..1d553bedbdb51 100644
38272 +--- a/include/uapi/linux/idxd.h
38273 ++++ b/include/uapi/linux/idxd.h
38274 +@@ -295,7 +295,7 @@ struct dsa_completion_record {
38275 + };
38276 +
38277 + uint32_t delta_rec_size;
38278 +- uint32_t crc_val;
38279 ++ uint64_t crc_val;
38280 +
38281 + /* DIF check & strip */
38282 + struct {
38283 +diff --git a/include/uapi/linux/swab.h b/include/uapi/linux/swab.h
38284 +index 0723a9cce747c..01717181339eb 100644
38285 +--- a/include/uapi/linux/swab.h
38286 ++++ b/include/uapi/linux/swab.h
38287 +@@ -3,7 +3,7 @@
38288 + #define _UAPI_LINUX_SWAB_H
38289 +
38290 + #include <linux/types.h>
38291 +-#include <linux/compiler.h>
38292 ++#include <linux/stddef.h>
38293 + #include <asm/bitsperlong.h>
38294 + #include <asm/swab.h>
38295 +
38296 +diff --git a/include/uapi/rdma/hns-abi.h b/include/uapi/rdma/hns-abi.h
38297 +index f6fde06db4b4e..745790ce3c261 100644
38298 +--- a/include/uapi/rdma/hns-abi.h
38299 ++++ b/include/uapi/rdma/hns-abi.h
38300 +@@ -85,11 +85,26 @@ struct hns_roce_ib_create_qp_resp {
38301 + __aligned_u64 dwqe_mmap_key;
38302 + };
38303 +
38304 ++enum {
38305 ++ HNS_ROCE_EXSGE_FLAGS = 1 << 0,
38306 ++};
38307 ++
38308 ++enum {
38309 ++ HNS_ROCE_RSP_EXSGE_FLAGS = 1 << 0,
38310 ++};
38311 ++
38312 + struct hns_roce_ib_alloc_ucontext_resp {
38313 + __u32 qp_tab_size;
38314 + __u32 cqe_size;
38315 + __u32 srq_tab_size;
38316 + __u32 reserved;
38317 ++ __u32 config;
38318 ++ __u32 max_inline_data;
38319 ++};
38320 ++
38321 ++struct hns_roce_ib_alloc_ucontext {
38322 ++ __u32 config;
38323 ++ __u32 reserved;
38324 + };
38325 +
38326 + struct hns_roce_ib_alloc_pd_resp {
38327 +diff --git a/include/uapi/sound/asequencer.h b/include/uapi/sound/asequencer.h
38328 +index a75e14edc957e..dbd60f48b4b01 100644
38329 +--- a/include/uapi/sound/asequencer.h
38330 ++++ b/include/uapi/sound/asequencer.h
38331 +@@ -344,10 +344,10 @@ typedef int __bitwise snd_seq_client_type_t;
38332 + #define KERNEL_CLIENT ((__force snd_seq_client_type_t) 2)
38333 +
38334 + /* event filter flags */
38335 +-#define SNDRV_SEQ_FILTER_BROADCAST (1<<0) /* accept broadcast messages */
38336 +-#define SNDRV_SEQ_FILTER_MULTICAST (1<<1) /* accept multicast messages */
38337 +-#define SNDRV_SEQ_FILTER_BOUNCE (1<<2) /* accept bounce event in error */
38338 +-#define SNDRV_SEQ_FILTER_USE_EVENT (1<<31) /* use event filter */
38339 ++#define SNDRV_SEQ_FILTER_BROADCAST (1U<<0) /* accept broadcast messages */
38340 ++#define SNDRV_SEQ_FILTER_MULTICAST (1U<<1) /* accept multicast messages */
38341 ++#define SNDRV_SEQ_FILTER_BOUNCE (1U<<2) /* accept bounce event in error */
38342 ++#define SNDRV_SEQ_FILTER_USE_EVENT (1U<<31) /* use event filter */
38343 +
38344 + struct snd_seq_client_info {
38345 + int client; /* client number to inquire */
38346 +diff --git a/io_uring/msg_ring.c b/io_uring/msg_ring.c
38347 +index 90d2fc6fd80e4..080867143f287 100644
38348 +--- a/io_uring/msg_ring.c
38349 ++++ b/io_uring/msg_ring.c
38350 +@@ -164,6 +164,8 @@ int io_msg_ring(struct io_kiocb *req, unsigned int issue_flags)
38351 + }
38352 +
38353 + done:
38354 ++ if (ret == -EAGAIN)
38355 ++ return -EAGAIN;
38356 + if (ret < 0)
38357 + req_set_fail(req);
38358 + io_req_set_res(req, ret, 0);
38359 +diff --git a/io_uring/net.c b/io_uring/net.c
38360 +index 8205cfecd647c..eaaacee91a1ff 100644
38361 +--- a/io_uring/net.c
38362 ++++ b/io_uring/net.c
38363 +@@ -772,10 +772,10 @@ retry_multishot:
38364 + goto retry_multishot;
38365 +
38366 + if (mshot_finished) {
38367 +- io_netmsg_recycle(req, issue_flags);
38368 + /* fast path, check for non-NULL to avoid function call */
38369 + if (kmsg->free_iov)
38370 + kfree(kmsg->free_iov);
38371 ++ io_netmsg_recycle(req, issue_flags);
38372 + req->flags &= ~REQ_F_NEED_CLEANUP;
38373 + }
38374 +
38375 +diff --git a/io_uring/timeout.c b/io_uring/timeout.c
38376 +index 78ea2c64b70e0..535ecaee5a0bb 100644
38377 +--- a/io_uring/timeout.c
38378 ++++ b/io_uring/timeout.c
38379 +@@ -72,10 +72,12 @@ static bool io_kill_timeout(struct io_kiocb *req, int status)
38380 + __cold void io_flush_timeouts(struct io_ring_ctx *ctx)
38381 + __must_hold(&ctx->completion_lock)
38382 + {
38383 +- u32 seq = ctx->cached_cq_tail - atomic_read(&ctx->cq_timeouts);
38384 ++ u32 seq;
38385 + struct io_timeout *timeout, *tmp;
38386 +
38387 + spin_lock_irq(&ctx->timeout_lock);
38388 ++ seq = ctx->cached_cq_tail - atomic_read(&ctx->cq_timeouts);
38389 ++
38390 + list_for_each_entry_safe(timeout, tmp, &ctx->timeout_list, list) {
38391 + struct io_kiocb *req = cmd_to_io_kiocb(timeout);
38392 + u32 events_needed, events_got;
38393 +diff --git a/ipc/mqueue.c b/ipc/mqueue.c
38394 +index 9cf314b3f079f..b258f24555534 100644
38395 +--- a/ipc/mqueue.c
38396 ++++ b/ipc/mqueue.c
38397 +@@ -1727,7 +1727,8 @@ static int __init init_mqueue_fs(void)
38398 +
38399 + if (!setup_mq_sysctls(&init_ipc_ns)) {
38400 + pr_warn("sysctl registration failed\n");
38401 +- return -ENOMEM;
38402 ++ error = -ENOMEM;
38403 ++ goto out_kmem;
38404 + }
38405 +
38406 + error = register_filesystem(&mqueue_fs_type);
38407 +@@ -1745,8 +1746,9 @@ static int __init init_mqueue_fs(void)
38408 + out_filesystem:
38409 + unregister_filesystem(&mqueue_fs_type);
38410 + out_sysctl:
38411 +- kmem_cache_destroy(mqueue_inode_cachep);
38412 + retire_mq_sysctls(&init_ipc_ns);
38413 ++out_kmem:
38414 ++ kmem_cache_destroy(mqueue_inode_cachep);
38415 + return error;
38416 + }
38417 +
38418 +diff --git a/kernel/acct.c b/kernel/acct.c
38419 +index 13706356ec54d..67bde1633d8f9 100644
38420 +--- a/kernel/acct.c
38421 ++++ b/kernel/acct.c
38422 +@@ -350,6 +350,8 @@ static comp_t encode_comp_t(unsigned long value)
38423 + exp++;
38424 + }
38425 +
38426 ++ if (exp > (((comp_t) ~0U) >> MANTSIZE))
38427 ++ return (comp_t) ~0U;
38428 + /*
38429 + * Clean it up and polish it off.
38430 + */
38431 +diff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c
38432 +index 0d23d4bcd81cc..44e93c3abebde 100644
38433 +--- a/kernel/bpf/btf.c
38434 ++++ b/kernel/bpf/btf.c
38435 +@@ -4481,6 +4481,11 @@ static int btf_func_proto_check(struct btf_verifier_env *env,
38436 + break;
38437 + }
38438 +
38439 ++ if (btf_type_is_resolve_source_only(arg_type)) {
38440 ++ btf_verifier_log_type(env, t, "Invalid arg#%u", i + 1);
38441 ++ return -EINVAL;
38442 ++ }
38443 ++
38444 + if (args[i].name_off &&
38445 + (!btf_name_offset_valid(btf, args[i].name_off) ||
38446 + !btf_name_valid_identifier(btf, args[i].name_off))) {
38447 +diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c
38448 +index 0e758911d963f..6b6fb7237ebea 100644
38449 +--- a/kernel/bpf/syscall.c
38450 ++++ b/kernel/bpf/syscall.c
38451 +@@ -3505,9 +3505,9 @@ static int bpf_prog_attach(const union bpf_attr *attr)
38452 + case BPF_PROG_TYPE_LSM:
38453 + if (ptype == BPF_PROG_TYPE_LSM &&
38454 + prog->expected_attach_type != BPF_LSM_CGROUP)
38455 +- return -EINVAL;
38456 +-
38457 +- ret = cgroup_bpf_prog_attach(attr, ptype, prog);
38458 ++ ret = -EINVAL;
38459 ++ else
38460 ++ ret = cgroup_bpf_prog_attach(attr, ptype, prog);
38461 + break;
38462 + default:
38463 + ret = -EINVAL;
38464 +diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
38465 +index b781075dd5109..57f76b597012c 100644
38466 +--- a/kernel/bpf/verifier.c
38467 ++++ b/kernel/bpf/verifier.c
38468 +@@ -2751,7 +2751,7 @@ static void mark_all_scalars_precise(struct bpf_verifier_env *env,
38469 + }
38470 + }
38471 +
38472 +-static int __mark_chain_precision(struct bpf_verifier_env *env, int regno,
38473 ++static int __mark_chain_precision(struct bpf_verifier_env *env, int frame, int regno,
38474 + int spi)
38475 + {
38476 + struct bpf_verifier_state *st = env->cur_state;
38477 +@@ -2768,7 +2768,7 @@ static int __mark_chain_precision(struct bpf_verifier_env *env, int regno,
38478 + if (!env->bpf_capable)
38479 + return 0;
38480 +
38481 +- func = st->frame[st->curframe];
38482 ++ func = st->frame[frame];
38483 + if (regno >= 0) {
38484 + reg = &func->regs[regno];
38485 + if (reg->type != SCALAR_VALUE) {
38486 +@@ -2849,7 +2849,7 @@ static int __mark_chain_precision(struct bpf_verifier_env *env, int regno,
38487 + break;
38488 +
38489 + new_marks = false;
38490 +- func = st->frame[st->curframe];
38491 ++ func = st->frame[frame];
38492 + bitmap_from_u64(mask, reg_mask);
38493 + for_each_set_bit(i, mask, 32) {
38494 + reg = &func->regs[i];
38495 +@@ -2915,12 +2915,17 @@ static int __mark_chain_precision(struct bpf_verifier_env *env, int regno,
38496 +
38497 + static int mark_chain_precision(struct bpf_verifier_env *env, int regno)
38498 + {
38499 +- return __mark_chain_precision(env, regno, -1);
38500 ++ return __mark_chain_precision(env, env->cur_state->curframe, regno, -1);
38501 + }
38502 +
38503 +-static int mark_chain_precision_stack(struct bpf_verifier_env *env, int spi)
38504 ++static int mark_chain_precision_frame(struct bpf_verifier_env *env, int frame, int regno)
38505 + {
38506 +- return __mark_chain_precision(env, -1, spi);
38507 ++ return __mark_chain_precision(env, frame, regno, -1);
38508 ++}
38509 ++
38510 ++static int mark_chain_precision_stack_frame(struct bpf_verifier_env *env, int frame, int spi)
38511 ++{
38512 ++ return __mark_chain_precision(env, frame, -1, spi);
38513 + }
38514 +
38515 + static bool is_spillable_regtype(enum bpf_reg_type type)
38516 +@@ -3169,14 +3174,17 @@ static int check_stack_write_var_off(struct bpf_verifier_env *env,
38517 + stype = &state->stack[spi].slot_type[slot % BPF_REG_SIZE];
38518 + mark_stack_slot_scratched(env, spi);
38519 +
38520 +- if (!env->allow_ptr_leaks
38521 +- && *stype != NOT_INIT
38522 +- && *stype != SCALAR_VALUE) {
38523 +- /* Reject the write if there's are spilled pointers in
38524 +- * range. If we didn't reject here, the ptr status
38525 +- * would be erased below (even though not all slots are
38526 +- * actually overwritten), possibly opening the door to
38527 +- * leaks.
38528 ++ if (!env->allow_ptr_leaks && *stype != STACK_MISC && *stype != STACK_ZERO) {
38529 ++ /* Reject the write if range we may write to has not
38530 ++ * been initialized beforehand. If we didn't reject
38531 ++ * here, the ptr status would be erased below (even
38532 ++ * though not all slots are actually overwritten),
38533 ++ * possibly opening the door to leaks.
38534 ++ *
38535 ++ * We do however catch STACK_INVALID case below, and
38536 ++ * only allow reading possibly uninitialized memory
38537 ++ * later for CAP_PERFMON, as the write may not happen to
38538 ++ * that slot.
38539 + */
38540 + verbose(env, "spilled ptr in range of var-offset stack write; insn %d, ptr off: %d",
38541 + insn_idx, i);
38542 +@@ -5142,10 +5150,6 @@ static int check_stack_range_initialized(
38543 + goto mark;
38544 + }
38545 +
38546 +- if (is_spilled_reg(&state->stack[spi]) &&
38547 +- base_type(state->stack[spi].spilled_ptr.type) == PTR_TO_BTF_ID)
38548 +- goto mark;
38549 +-
38550 + if (is_spilled_reg(&state->stack[spi]) &&
38551 + (state->stack[spi].spilled_ptr.type == SCALAR_VALUE ||
38552 + env->allow_ptr_leaks)) {
38553 +@@ -5176,6 +5180,11 @@ mark:
38554 + mark_reg_read(env, &state->stack[spi].spilled_ptr,
38555 + state->stack[spi].spilled_ptr.parent,
38556 + REG_LIVE_READ64);
38557 ++ /* We do not set REG_LIVE_WRITTEN for stack slot, as we can not
38558 ++ * be sure that whether stack slot is written to or not. Hence,
38559 ++ * we must still conservatively propagate reads upwards even if
38560 ++ * helper may write to the entire memory range.
38561 ++ */
38562 + }
38563 + return update_stack_depth(env, state, min_off);
38564 + }
38565 +@@ -9057,6 +9066,11 @@ static int adjust_reg_min_max_vals(struct bpf_verifier_env *env,
38566 + return err;
38567 + return adjust_ptr_min_max_vals(env, insn,
38568 + dst_reg, src_reg);
38569 ++ } else if (dst_reg->precise) {
38570 ++ /* if dst_reg is precise, src_reg should be precise as well */
38571 ++ err = mark_chain_precision(env, insn->src_reg);
38572 ++ if (err)
38573 ++ return err;
38574 + }
38575 + } else {
38576 + /* Pretend the src is a reg with a known value, since we only
38577 +@@ -11693,34 +11707,36 @@ static int propagate_precision(struct bpf_verifier_env *env,
38578 + {
38579 + struct bpf_reg_state *state_reg;
38580 + struct bpf_func_state *state;
38581 +- int i, err = 0;
38582 ++ int i, err = 0, fr;
38583 +
38584 +- state = old->frame[old->curframe];
38585 +- state_reg = state->regs;
38586 +- for (i = 0; i < BPF_REG_FP; i++, state_reg++) {
38587 +- if (state_reg->type != SCALAR_VALUE ||
38588 +- !state_reg->precise)
38589 +- continue;
38590 +- if (env->log.level & BPF_LOG_LEVEL2)
38591 +- verbose(env, "propagating r%d\n", i);
38592 +- err = mark_chain_precision(env, i);
38593 +- if (err < 0)
38594 +- return err;
38595 +- }
38596 ++ for (fr = old->curframe; fr >= 0; fr--) {
38597 ++ state = old->frame[fr];
38598 ++ state_reg = state->regs;
38599 ++ for (i = 0; i < BPF_REG_FP; i++, state_reg++) {
38600 ++ if (state_reg->type != SCALAR_VALUE ||
38601 ++ !state_reg->precise)
38602 ++ continue;
38603 ++ if (env->log.level & BPF_LOG_LEVEL2)
38604 ++ verbose(env, "frame %d: propagating r%d\n", i, fr);
38605 ++ err = mark_chain_precision_frame(env, fr, i);
38606 ++ if (err < 0)
38607 ++ return err;
38608 ++ }
38609 +
38610 +- for (i = 0; i < state->allocated_stack / BPF_REG_SIZE; i++) {
38611 +- if (!is_spilled_reg(&state->stack[i]))
38612 +- continue;
38613 +- state_reg = &state->stack[i].spilled_ptr;
38614 +- if (state_reg->type != SCALAR_VALUE ||
38615 +- !state_reg->precise)
38616 +- continue;
38617 +- if (env->log.level & BPF_LOG_LEVEL2)
38618 +- verbose(env, "propagating fp%d\n",
38619 +- (-i - 1) * BPF_REG_SIZE);
38620 +- err = mark_chain_precision_stack(env, i);
38621 +- if (err < 0)
38622 +- return err;
38623 ++ for (i = 0; i < state->allocated_stack / BPF_REG_SIZE; i++) {
38624 ++ if (!is_spilled_reg(&state->stack[i]))
38625 ++ continue;
38626 ++ state_reg = &state->stack[i].spilled_ptr;
38627 ++ if (state_reg->type != SCALAR_VALUE ||
38628 ++ !state_reg->precise)
38629 ++ continue;
38630 ++ if (env->log.level & BPF_LOG_LEVEL2)
38631 ++ verbose(env, "frame %d: propagating fp%d\n",
38632 ++ (-i - 1) * BPF_REG_SIZE, fr);
38633 ++ err = mark_chain_precision_stack_frame(env, fr, i);
38634 ++ if (err < 0)
38635 ++ return err;
38636 ++ }
38637 + }
38638 + return 0;
38639 + }
38640 +@@ -13283,6 +13299,10 @@ static int opt_subreg_zext_lo32_rnd_hi32(struct bpf_verifier_env *env,
38641 + if (!bpf_jit_needs_zext() && !is_cmpxchg_insn(&insn))
38642 + continue;
38643 +
38644 ++ /* Zero-extension is done by the caller. */
38645 ++ if (bpf_pseudo_kfunc_call(&insn))
38646 ++ continue;
38647 ++
38648 + if (WARN_ON(load_reg == -1)) {
38649 + verbose(env, "verifier bug. zext_dst is set, but no reg is defined\n");
38650 + return -EFAULT;
38651 +diff --git a/kernel/cpu.c b/kernel/cpu.c
38652 +index bbad5e375d3ba..98a7a7b1471b7 100644
38653 +--- a/kernel/cpu.c
38654 ++++ b/kernel/cpu.c
38655 +@@ -663,21 +663,51 @@ static bool cpuhp_next_state(bool bringup,
38656 + return true;
38657 + }
38658 +
38659 +-static int cpuhp_invoke_callback_range(bool bringup,
38660 +- unsigned int cpu,
38661 +- struct cpuhp_cpu_state *st,
38662 +- enum cpuhp_state target)
38663 ++static int __cpuhp_invoke_callback_range(bool bringup,
38664 ++ unsigned int cpu,
38665 ++ struct cpuhp_cpu_state *st,
38666 ++ enum cpuhp_state target,
38667 ++ bool nofail)
38668 + {
38669 + enum cpuhp_state state;
38670 +- int err = 0;
38671 ++ int ret = 0;
38672 +
38673 + while (cpuhp_next_state(bringup, &state, st, target)) {
38674 ++ int err;
38675 ++
38676 + err = cpuhp_invoke_callback(cpu, state, bringup, NULL, NULL);
38677 +- if (err)
38678 ++ if (!err)
38679 ++ continue;
38680 ++
38681 ++ if (nofail) {
38682 ++ pr_warn("CPU %u %s state %s (%d) failed (%d)\n",
38683 ++ cpu, bringup ? "UP" : "DOWN",
38684 ++ cpuhp_get_step(st->state)->name,
38685 ++ st->state, err);
38686 ++ ret = -1;
38687 ++ } else {
38688 ++ ret = err;
38689 + break;
38690 ++ }
38691 + }
38692 +
38693 +- return err;
38694 ++ return ret;
38695 ++}
38696 ++
38697 ++static inline int cpuhp_invoke_callback_range(bool bringup,
38698 ++ unsigned int cpu,
38699 ++ struct cpuhp_cpu_state *st,
38700 ++ enum cpuhp_state target)
38701 ++{
38702 ++ return __cpuhp_invoke_callback_range(bringup, cpu, st, target, false);
38703 ++}
38704 ++
38705 ++static inline void cpuhp_invoke_callback_range_nofail(bool bringup,
38706 ++ unsigned int cpu,
38707 ++ struct cpuhp_cpu_state *st,
38708 ++ enum cpuhp_state target)
38709 ++{
38710 ++ __cpuhp_invoke_callback_range(bringup, cpu, st, target, true);
38711 + }
38712 +
38713 + static inline bool can_rollback_cpu(struct cpuhp_cpu_state *st)
38714 +@@ -999,7 +1029,6 @@ static int take_cpu_down(void *_param)
38715 + struct cpuhp_cpu_state *st = this_cpu_ptr(&cpuhp_state);
38716 + enum cpuhp_state target = max((int)st->target, CPUHP_AP_OFFLINE);
38717 + int err, cpu = smp_processor_id();
38718 +- int ret;
38719 +
38720 + /* Ensure this CPU doesn't handle any more interrupts. */
38721 + err = __cpu_disable();
38722 +@@ -1012,13 +1041,10 @@ static int take_cpu_down(void *_param)
38723 + */
38724 + WARN_ON(st->state != (CPUHP_TEARDOWN_CPU - 1));
38725 +
38726 +- /* Invoke the former CPU_DYING callbacks */
38727 +- ret = cpuhp_invoke_callback_range(false, cpu, st, target);
38728 +-
38729 + /*
38730 +- * DYING must not fail!
38731 ++ * Invoke the former CPU_DYING callbacks. DYING must not fail!
38732 + */
38733 +- WARN_ON_ONCE(ret);
38734 ++ cpuhp_invoke_callback_range_nofail(false, cpu, st, target);
38735 +
38736 + /* Give up timekeeping duties */
38737 + tick_handover_do_timer();
38738 +@@ -1296,16 +1322,14 @@ void notify_cpu_starting(unsigned int cpu)
38739 + {
38740 + struct cpuhp_cpu_state *st = per_cpu_ptr(&cpuhp_state, cpu);
38741 + enum cpuhp_state target = min((int)st->target, CPUHP_AP_ONLINE);
38742 +- int ret;
38743 +
38744 + rcu_cpu_starting(cpu); /* Enables RCU usage on this CPU. */
38745 + cpumask_set_cpu(cpu, &cpus_booted_once_mask);
38746 +- ret = cpuhp_invoke_callback_range(true, cpu, st, target);
38747 +
38748 + /*
38749 + * STARTING must not fail!
38750 + */
38751 +- WARN_ON_ONCE(ret);
38752 ++ cpuhp_invoke_callback_range_nofail(true, cpu, st, target);
38753 + }
38754 +
38755 + /*
38756 +@@ -2326,8 +2350,10 @@ static ssize_t target_store(struct device *dev, struct device_attribute *attr,
38757 +
38758 + if (st->state < target)
38759 + ret = cpu_up(dev->id, target);
38760 +- else
38761 ++ else if (st->state > target)
38762 + ret = cpu_down(dev->id, target);
38763 ++ else if (WARN_ON(st->target != target))
38764 ++ st->target = target;
38765 + out:
38766 + unlock_device_hotplug();
38767 + return ret ? ret : count;
38768 +diff --git a/kernel/events/core.c b/kernel/events/core.c
38769 +index 91473e9f88cd9..a636fab5e381a 100644
38770 +--- a/kernel/events/core.c
38771 ++++ b/kernel/events/core.c
38772 +@@ -11136,13 +11136,15 @@ static int pmu_dev_alloc(struct pmu *pmu)
38773 +
38774 + pmu->dev->groups = pmu->attr_groups;
38775 + device_initialize(pmu->dev);
38776 +- ret = dev_set_name(pmu->dev, "%s", pmu->name);
38777 +- if (ret)
38778 +- goto free_dev;
38779 +
38780 + dev_set_drvdata(pmu->dev, pmu);
38781 + pmu->dev->bus = &pmu_bus;
38782 + pmu->dev->release = pmu_dev_release;
38783 ++
38784 ++ ret = dev_set_name(pmu->dev, "%s", pmu->name);
38785 ++ if (ret)
38786 ++ goto free_dev;
38787 ++
38788 + ret = device_add(pmu->dev);
38789 + if (ret)
38790 + goto free_dev;
38791 +diff --git a/kernel/fork.c b/kernel/fork.c
38792 +index 2b6bd511c6ed1..f925d2b96e0a9 100644
38793 +--- a/kernel/fork.c
38794 ++++ b/kernel/fork.c
38795 +@@ -537,6 +537,9 @@ void put_task_stack(struct task_struct *tsk)
38796 +
38797 + void free_task(struct task_struct *tsk)
38798 + {
38799 ++#ifdef CONFIG_SECCOMP
38800 ++ WARN_ON_ONCE(tsk->seccomp.filter);
38801 ++#endif
38802 + release_user_cpus_ptr(tsk);
38803 + scs_release(tsk);
38804 +
38805 +@@ -2407,12 +2410,6 @@ static __latent_entropy struct task_struct *copy_process(
38806 +
38807 + spin_lock(&current->sighand->siglock);
38808 +
38809 +- /*
38810 +- * Copy seccomp details explicitly here, in case they were changed
38811 +- * before holding sighand lock.
38812 +- */
38813 +- copy_seccomp(p);
38814 +-
38815 + rv_task_fork(p);
38816 +
38817 + rseq_fork(p, clone_flags);
38818 +@@ -2429,6 +2426,14 @@ static __latent_entropy struct task_struct *copy_process(
38819 + goto bad_fork_cancel_cgroup;
38820 + }
38821 +
38822 ++ /* No more failure paths after this point. */
38823 ++
38824 ++ /*
38825 ++ * Copy seccomp details explicitly here, in case they were changed
38826 ++ * before holding sighand lock.
38827 ++ */
38828 ++ copy_seccomp(p);
38829 ++
38830 + init_task_pid_links(p);
38831 + if (likely(p->pid)) {
38832 + ptrace_init_task(p, (clone_flags & CLONE_PTRACE) || trace);
38833 +diff --git a/kernel/futex/core.c b/kernel/futex/core.c
38834 +index b22ef1efe7511..514e4582b8634 100644
38835 +--- a/kernel/futex/core.c
38836 ++++ b/kernel/futex/core.c
38837 +@@ -638,6 +638,7 @@ static int handle_futex_death(u32 __user *uaddr, struct task_struct *curr,
38838 + bool pi, bool pending_op)
38839 + {
38840 + u32 uval, nval, mval;
38841 ++ pid_t owner;
38842 + int err;
38843 +
38844 + /* Futex address must be 32bit aligned */
38845 +@@ -659,6 +660,10 @@ retry:
38846 + * 2. A woken up waiter is killed before it can acquire the
38847 + * futex in user space.
38848 + *
38849 ++ * In the second case, the wake up notification could be generated
38850 ++ * by the unlock path in user space after setting the futex value
38851 ++ * to zero or by the kernel after setting the OWNER_DIED bit below.
38852 ++ *
38853 + * In both cases the TID validation below prevents a wakeup of
38854 + * potential waiters which can cause these waiters to block
38855 + * forever.
38856 +@@ -667,24 +672,27 @@ retry:
38857 + *
38858 + * 1) task->robust_list->list_op_pending != NULL
38859 + * @pending_op == true
38860 +- * 2) User space futex value == 0
38861 ++ * 2) The owner part of user space futex value == 0
38862 + * 3) Regular futex: @pi == false
38863 + *
38864 + * If these conditions are met, it is safe to attempt waking up a
38865 + * potential waiter without touching the user space futex value and
38866 +- * trying to set the OWNER_DIED bit. The user space futex value is
38867 +- * uncontended and the rest of the user space mutex state is
38868 +- * consistent, so a woken waiter will just take over the
38869 +- * uncontended futex. Setting the OWNER_DIED bit would create
38870 +- * inconsistent state and malfunction of the user space owner died
38871 +- * handling.
38872 ++ * trying to set the OWNER_DIED bit. If the futex value is zero,
38873 ++ * the rest of the user space mutex state is consistent, so a woken
38874 ++ * waiter will just take over the uncontended futex. Setting the
38875 ++ * OWNER_DIED bit would create inconsistent state and malfunction
38876 ++ * of the user space owner died handling. Otherwise, the OWNER_DIED
38877 ++ * bit is already set, and the woken waiter is expected to deal with
38878 ++ * this.
38879 + */
38880 +- if (pending_op && !pi && !uval) {
38881 ++ owner = uval & FUTEX_TID_MASK;
38882 ++
38883 ++ if (pending_op && !pi && !owner) {
38884 + futex_wake(uaddr, 1, 1, FUTEX_BITSET_MATCH_ANY);
38885 + return 0;
38886 + }
38887 +
38888 +- if ((uval & FUTEX_TID_MASK) != task_pid_vnr(curr))
38889 ++ if (owner != task_pid_vnr(curr))
38890 + return 0;
38891 +
38892 + /*
38893 +diff --git a/kernel/gcov/gcc_4_7.c b/kernel/gcov/gcc_4_7.c
38894 +index 7971e989e425b..74a4ef1da9ad7 100644
38895 +--- a/kernel/gcov/gcc_4_7.c
38896 ++++ b/kernel/gcov/gcc_4_7.c
38897 +@@ -82,6 +82,7 @@ struct gcov_fn_info {
38898 + * @version: gcov version magic indicating the gcc version used for compilation
38899 + * @next: list head for a singly-linked list
38900 + * @stamp: uniquifying time stamp
38901 ++ * @checksum: unique object checksum
38902 + * @filename: name of the associated gcov data file
38903 + * @merge: merge functions (null for unused counter type)
38904 + * @n_functions: number of instrumented functions
38905 +@@ -94,6 +95,10 @@ struct gcov_info {
38906 + unsigned int version;
38907 + struct gcov_info *next;
38908 + unsigned int stamp;
38909 ++ /* Since GCC 12.1 a checksum field is added. */
38910 ++#if (__GNUC__ >= 12)
38911 ++ unsigned int checksum;
38912 ++#endif
38913 + const char *filename;
38914 + void (*merge[GCOV_COUNTERS])(gcov_type *, unsigned int);
38915 + unsigned int n_functions;
38916 +diff --git a/kernel/irq/internals.h b/kernel/irq/internals.h
38917 +index f09c60393e559..5fdc0b5575797 100644
38918 +--- a/kernel/irq/internals.h
38919 ++++ b/kernel/irq/internals.h
38920 +@@ -52,6 +52,7 @@ enum {
38921 + * IRQS_PENDING - irq is pending and replayed later
38922 + * IRQS_SUSPENDED - irq is suspended
38923 + * IRQS_NMI - irq line is used to deliver NMIs
38924 ++ * IRQS_SYSFS - descriptor has been added to sysfs
38925 + */
38926 + enum {
38927 + IRQS_AUTODETECT = 0x00000001,
38928 +@@ -64,6 +65,7 @@ enum {
38929 + IRQS_SUSPENDED = 0x00000800,
38930 + IRQS_TIMINGS = 0x00001000,
38931 + IRQS_NMI = 0x00002000,
38932 ++ IRQS_SYSFS = 0x00004000,
38933 + };
38934 +
38935 + #include "debug.h"
38936 +diff --git a/kernel/irq/irqdesc.c b/kernel/irq/irqdesc.c
38937 +index 5db0230aa6b52..c797d4054d0e5 100644
38938 +--- a/kernel/irq/irqdesc.c
38939 ++++ b/kernel/irq/irqdesc.c
38940 +@@ -288,22 +288,25 @@ static void irq_sysfs_add(int irq, struct irq_desc *desc)
38941 + if (irq_kobj_base) {
38942 + /*
38943 + * Continue even in case of failure as this is nothing
38944 +- * crucial.
38945 ++ * crucial and failures in the late irq_sysfs_init()
38946 ++ * cannot be rolled back.
38947 + */
38948 + if (kobject_add(&desc->kobj, irq_kobj_base, "%d", irq))
38949 + pr_warn("Failed to add kobject for irq %d\n", irq);
38950 ++ else
38951 ++ desc->istate |= IRQS_SYSFS;
38952 + }
38953 + }
38954 +
38955 + static void irq_sysfs_del(struct irq_desc *desc)
38956 + {
38957 + /*
38958 +- * If irq_sysfs_init() has not yet been invoked (early boot), then
38959 +- * irq_kobj_base is NULL and the descriptor was never added.
38960 +- * kobject_del() complains about a object with no parent, so make
38961 +- * it conditional.
38962 ++ * Only invoke kobject_del() when kobject_add() was successfully
38963 ++ * invoked for the descriptor. This covers both early boot, where
38964 ++ * sysfs is not initialized yet, and the case of a failed
38965 ++ * kobject_add() invocation.
38966 + */
38967 +- if (irq_kobj_base)
38968 ++ if (desc->istate & IRQS_SYSFS)
38969 + kobject_del(&desc->kobj);
38970 + }
38971 +
38972 +diff --git a/kernel/kprobes.c b/kernel/kprobes.c
38973 +index 6d2a8623ec7b5..771fcce54fac0 100644
38974 +--- a/kernel/kprobes.c
38975 ++++ b/kernel/kprobes.c
38976 +@@ -2360,6 +2360,14 @@ static void kill_kprobe(struct kprobe *p)
38977 +
38978 + lockdep_assert_held(&kprobe_mutex);
38979 +
38980 ++ /*
38981 ++ * The module is going away. We should disarm the kprobe which
38982 ++ * is using ftrace, because ftrace framework is still available at
38983 ++ * 'MODULE_STATE_GOING' notification.
38984 ++ */
38985 ++ if (kprobe_ftrace(p) && !kprobe_disabled(p) && !kprobes_all_disarmed)
38986 ++ disarm_kprobe_ftrace(p);
38987 ++
38988 + p->flags |= KPROBE_FLAG_GONE;
38989 + if (kprobe_aggrprobe(p)) {
38990 + /*
38991 +@@ -2376,14 +2384,6 @@ static void kill_kprobe(struct kprobe *p)
38992 + * the original probed function (which will be freed soon) any more.
38993 + */
38994 + arch_remove_kprobe(p);
38995 +-
38996 +- /*
38997 +- * The module is going away. We should disarm the kprobe which
38998 +- * is using ftrace, because ftrace framework is still available at
38999 +- * 'MODULE_STATE_GOING' notification.
39000 +- */
39001 +- if (kprobe_ftrace(p) && !kprobe_disabled(p) && !kprobes_all_disarmed)
39002 +- disarm_kprobe_ftrace(p);
39003 + }
39004 +
39005 + /* Disable one kprobe */
39006 +diff --git a/kernel/module/decompress.c b/kernel/module/decompress.c
39007 +index 4d0bcb3d9e449..82c07b1d97975 100644
39008 +--- a/kernel/module/decompress.c
39009 ++++ b/kernel/module/decompress.c
39010 +@@ -114,8 +114,8 @@ static ssize_t module_gzip_decompress(struct load_info *info,
39011 + do {
39012 + struct page *page = module_get_next_page(info);
39013 +
39014 +- if (!page) {
39015 +- retval = -ENOMEM;
39016 ++ if (IS_ERR(page)) {
39017 ++ retval = PTR_ERR(page);
39018 + goto out_inflate_end;
39019 + }
39020 +
39021 +@@ -173,8 +173,8 @@ static ssize_t module_xz_decompress(struct load_info *info,
39022 + do {
39023 + struct page *page = module_get_next_page(info);
39024 +
39025 +- if (!page) {
39026 +- retval = -ENOMEM;
39027 ++ if (IS_ERR(page)) {
39028 ++ retval = PTR_ERR(page);
39029 + goto out;
39030 + }
39031 +
39032 +diff --git a/kernel/padata.c b/kernel/padata.c
39033 +index e5819bb8bd1dc..de90af5fcbe6b 100644
39034 +--- a/kernel/padata.c
39035 ++++ b/kernel/padata.c
39036 +@@ -207,14 +207,16 @@ int padata_do_parallel(struct padata_shell *ps,
39037 + pw = padata_work_alloc();
39038 + spin_unlock(&padata_works_lock);
39039 +
39040 ++ if (!pw) {
39041 ++ /* Maximum works limit exceeded, run in the current task. */
39042 ++ padata->parallel(padata);
39043 ++ }
39044 ++
39045 + rcu_read_unlock_bh();
39046 +
39047 + if (pw) {
39048 + padata_work_init(pw, padata_parallel_worker, padata, 0);
39049 + queue_work(pinst->parallel_wq, &pw->pw_work);
39050 +- } else {
39051 +- /* Maximum works limit exceeded, run in the current task. */
39052 +- padata->parallel(padata);
39053 + }
39054 +
39055 + return 0;
39056 +@@ -388,13 +390,16 @@ void padata_do_serial(struct padata_priv *padata)
39057 + int hashed_cpu = padata_cpu_hash(pd, padata->seq_nr);
39058 + struct padata_list *reorder = per_cpu_ptr(pd->reorder_list, hashed_cpu);
39059 + struct padata_priv *cur;
39060 ++ struct list_head *pos;
39061 +
39062 + spin_lock(&reorder->lock);
39063 + /* Sort in ascending order of sequence number. */
39064 +- list_for_each_entry_reverse(cur, &reorder->list, list)
39065 ++ list_for_each_prev(pos, &reorder->list) {
39066 ++ cur = list_entry(pos, struct padata_priv, list);
39067 + if (cur->seq_nr < padata->seq_nr)
39068 + break;
39069 +- list_add(&padata->list, &cur->list);
39070 ++ }
39071 ++ list_add(&padata->list, pos);
39072 + spin_unlock(&reorder->lock);
39073 +
39074 + /*
39075 +diff --git a/kernel/power/snapshot.c b/kernel/power/snapshot.c
39076 +index 2a406753af904..c20ca5fb9adc8 100644
39077 +--- a/kernel/power/snapshot.c
39078 ++++ b/kernel/power/snapshot.c
39079 +@@ -1723,8 +1723,8 @@ static unsigned long minimum_image_size(unsigned long saveable)
39080 + * /sys/power/reserved_size, respectively). To make this happen, we compute the
39081 + * total number of available page frames and allocate at least
39082 + *
39083 +- * ([page frames total] + PAGES_FOR_IO + [metadata pages]) / 2
39084 +- * + 2 * DIV_ROUND_UP(reserved_size, PAGE_SIZE)
39085 ++ * ([page frames total] - PAGES_FOR_IO - [metadata pages]) / 2
39086 ++ * - 2 * DIV_ROUND_UP(reserved_size, PAGE_SIZE)
39087 + *
39088 + * of them, which corresponds to the maximum size of a hibernation image.
39089 + *
39090 +diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c
39091 +index 5b52727dcc1c4..aedd43e1f21c4 100644
39092 +--- a/kernel/rcu/tree.c
39093 ++++ b/kernel/rcu/tree.c
39094 +@@ -2415,7 +2415,7 @@ void rcu_force_quiescent_state(void)
39095 + struct rcu_node *rnp_old = NULL;
39096 +
39097 + /* Funnel through hierarchy to reduce memory contention. */
39098 +- rnp = __this_cpu_read(rcu_data.mynode);
39099 ++ rnp = raw_cpu_read(rcu_data.mynode);
39100 + for (; rnp != NULL; rnp = rnp->parent) {
39101 + ret = (READ_ONCE(rcu_state.gp_flags) & RCU_GP_FLAG_FQS) ||
39102 + !raw_spin_trylock(&rnp->fqslock);
39103 +diff --git a/kernel/relay.c b/kernel/relay.c
39104 +index 6a611e779e958..fd1d196e04d4f 100644
39105 +--- a/kernel/relay.c
39106 ++++ b/kernel/relay.c
39107 +@@ -151,13 +151,13 @@ static struct rchan_buf *relay_create_buf(struct rchan *chan)
39108 + {
39109 + struct rchan_buf *buf;
39110 +
39111 +- if (chan->n_subbufs > KMALLOC_MAX_SIZE / sizeof(size_t *))
39112 ++ if (chan->n_subbufs > KMALLOC_MAX_SIZE / sizeof(size_t))
39113 + return NULL;
39114 +
39115 + buf = kzalloc(sizeof(struct rchan_buf), GFP_KERNEL);
39116 + if (!buf)
39117 + return NULL;
39118 +- buf->padding = kmalloc_array(chan->n_subbufs, sizeof(size_t *),
39119 ++ buf->padding = kmalloc_array(chan->n_subbufs, sizeof(size_t),
39120 + GFP_KERNEL);
39121 + if (!buf->padding)
39122 + goto free_buf;
39123 +diff --git a/kernel/sched/core.c b/kernel/sched/core.c
39124 +index ee28253c9ac0c..cb9d8ae7c4dbf 100644
39125 +--- a/kernel/sched/core.c
39126 ++++ b/kernel/sched/core.c
39127 +@@ -1398,7 +1398,7 @@ static inline void uclamp_idle_reset(struct rq *rq, enum uclamp_id clamp_id,
39128 + if (!(rq->uclamp_flags & UCLAMP_FLAG_IDLE))
39129 + return;
39130 +
39131 +- WRITE_ONCE(rq->uclamp[clamp_id].value, clamp_value);
39132 ++ uclamp_rq_set(rq, clamp_id, clamp_value);
39133 + }
39134 +
39135 + static inline
39136 +@@ -1549,8 +1549,8 @@ static inline void uclamp_rq_inc_id(struct rq *rq, struct task_struct *p,
39137 + if (bucket->tasks == 1 || uc_se->value > bucket->value)
39138 + bucket->value = uc_se->value;
39139 +
39140 +- if (uc_se->value > READ_ONCE(uc_rq->value))
39141 +- WRITE_ONCE(uc_rq->value, uc_se->value);
39142 ++ if (uc_se->value > uclamp_rq_get(rq, clamp_id))
39143 ++ uclamp_rq_set(rq, clamp_id, uc_se->value);
39144 + }
39145 +
39146 + /*
39147 +@@ -1616,7 +1616,7 @@ static inline void uclamp_rq_dec_id(struct rq *rq, struct task_struct *p,
39148 + if (likely(bucket->tasks))
39149 + return;
39150 +
39151 +- rq_clamp = READ_ONCE(uc_rq->value);
39152 ++ rq_clamp = uclamp_rq_get(rq, clamp_id);
39153 + /*
39154 + * Defensive programming: this should never happen. If it happens,
39155 + * e.g. due to future modification, warn and fixup the expected value.
39156 +@@ -1624,7 +1624,7 @@ static inline void uclamp_rq_dec_id(struct rq *rq, struct task_struct *p,
39157 + SCHED_WARN_ON(bucket->value > rq_clamp);
39158 + if (bucket->value >= rq_clamp) {
39159 + bkt_clamp = uclamp_rq_max_value(rq, clamp_id, uc_se->value);
39160 +- WRITE_ONCE(uc_rq->value, bkt_clamp);
39161 ++ uclamp_rq_set(rq, clamp_id, bkt_clamp);
39162 + }
39163 + }
39164 +
39165 +diff --git a/kernel/sched/cpudeadline.c b/kernel/sched/cpudeadline.c
39166 +index 02d970a879edd..57c92d751bcd7 100644
39167 +--- a/kernel/sched/cpudeadline.c
39168 ++++ b/kernel/sched/cpudeadline.c
39169 +@@ -123,7 +123,7 @@ int cpudl_find(struct cpudl *cp, struct task_struct *p,
39170 + unsigned long cap, max_cap = 0;
39171 + int cpu, max_cpu = -1;
39172 +
39173 +- if (!static_branch_unlikely(&sched_asym_cpucapacity))
39174 ++ if (!sched_asym_cpucap_active())
39175 + return 1;
39176 +
39177 + /* Ensure the capacity of the CPUs fits the task. */
39178 +diff --git a/kernel/sched/deadline.c b/kernel/sched/deadline.c
39179 +index 0ab79d819a0d6..8bebc36a1b71b 100644
39180 +--- a/kernel/sched/deadline.c
39181 ++++ b/kernel/sched/deadline.c
39182 +@@ -144,7 +144,7 @@ static inline unsigned long __dl_bw_capacity(int i)
39183 + */
39184 + static inline unsigned long dl_bw_capacity(int i)
39185 + {
39186 +- if (!static_branch_unlikely(&sched_asym_cpucapacity) &&
39187 ++ if (!sched_asym_cpucap_active() &&
39188 + capacity_orig_of(i) == SCHED_CAPACITY_SCALE) {
39189 + return dl_bw_cpus(i) << SCHED_CAPACITY_SHIFT;
39190 + } else {
39191 +@@ -1849,7 +1849,7 @@ select_task_rq_dl(struct task_struct *p, int cpu, int flags)
39192 + * Take the capacity of the CPU into account to
39193 + * ensure it fits the requirement of the task.
39194 + */
39195 +- if (static_branch_unlikely(&sched_asym_cpucapacity))
39196 ++ if (sched_asym_cpucap_active())
39197 + select_rq |= !dl_task_fits_capacity(p, cpu);
39198 +
39199 + if (select_rq) {
39200 +diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
39201 +index 914096c5b1ae1..532e6cdf706d6 100644
39202 +--- a/kernel/sched/fair.c
39203 ++++ b/kernel/sched/fair.c
39204 +@@ -4108,14 +4108,16 @@ static inline unsigned long task_util_est(struct task_struct *p)
39205 + }
39206 +
39207 + #ifdef CONFIG_UCLAMP_TASK
39208 +-static inline unsigned long uclamp_task_util(struct task_struct *p)
39209 ++static inline unsigned long uclamp_task_util(struct task_struct *p,
39210 ++ unsigned long uclamp_min,
39211 ++ unsigned long uclamp_max)
39212 + {
39213 +- return clamp(task_util_est(p),
39214 +- uclamp_eff_value(p, UCLAMP_MIN),
39215 +- uclamp_eff_value(p, UCLAMP_MAX));
39216 ++ return clamp(task_util_est(p), uclamp_min, uclamp_max);
39217 + }
39218 + #else
39219 +-static inline unsigned long uclamp_task_util(struct task_struct *p)
39220 ++static inline unsigned long uclamp_task_util(struct task_struct *p,
39221 ++ unsigned long uclamp_min,
39222 ++ unsigned long uclamp_max)
39223 + {
39224 + return task_util_est(p);
39225 + }
39226 +@@ -4254,15 +4256,140 @@ done:
39227 + trace_sched_util_est_se_tp(&p->se);
39228 + }
39229 +
39230 +-static inline int task_fits_capacity(struct task_struct *p,
39231 +- unsigned long capacity)
39232 ++static inline int util_fits_cpu(unsigned long util,
39233 ++ unsigned long uclamp_min,
39234 ++ unsigned long uclamp_max,
39235 ++ int cpu)
39236 + {
39237 +- return fits_capacity(uclamp_task_util(p), capacity);
39238 ++ unsigned long capacity_orig, capacity_orig_thermal;
39239 ++ unsigned long capacity = capacity_of(cpu);
39240 ++ bool fits, uclamp_max_fits;
39241 ++
39242 ++ /*
39243 ++ * Check if the real util fits without any uclamp boost/cap applied.
39244 ++ */
39245 ++ fits = fits_capacity(util, capacity);
39246 ++
39247 ++ if (!uclamp_is_used())
39248 ++ return fits;
39249 ++
39250 ++ /*
39251 ++ * We must use capacity_orig_of() for comparing against uclamp_min and
39252 ++ * uclamp_max. We only care about capacity pressure (by using
39253 ++ * capacity_of()) for comparing against the real util.
39254 ++ *
39255 ++ * If a task is boosted to 1024 for example, we don't want a tiny
39256 ++ * pressure to skew the check whether it fits a CPU or not.
39257 ++ *
39258 ++ * Similarly if a task is capped to capacity_orig_of(little_cpu), it
39259 ++ * should fit a little cpu even if there's some pressure.
39260 ++ *
39261 ++ * Only exception is for thermal pressure since it has a direct impact
39262 ++ * on available OPP of the system.
39263 ++ *
39264 ++ * We honour it for uclamp_min only as a drop in performance level
39265 ++ * could result in not getting the requested minimum performance level.
39266 ++ *
39267 ++ * For uclamp_max, we can tolerate a drop in performance level as the
39268 ++ * goal is to cap the task. So it's okay if it's getting less.
39269 ++ *
39270 ++ * In case of capacity inversion, which is not handled yet, we should
39271 ++ * honour the inverted capacity for both uclamp_min and uclamp_max all
39272 ++ * the time.
39273 ++ */
39274 ++ capacity_orig = capacity_orig_of(cpu);
39275 ++ capacity_orig_thermal = capacity_orig - arch_scale_thermal_pressure(cpu);
39276 ++
39277 ++ /*
39278 ++ * We want to force a task to fit a cpu as implied by uclamp_max.
39279 ++ * But we do have some corner cases to cater for..
39280 ++ *
39281 ++ *
39282 ++ * C=z
39283 ++ * | ___
39284 ++ * | C=y | |
39285 ++ * |_ _ _ _ _ _ _ _ _ ___ _ _ _ | _ | _ _ _ _ _ uclamp_max
39286 ++ * | C=x | | | |
39287 ++ * | ___ | | | |
39288 ++ * | | | | | | | (util somewhere in this region)
39289 ++ * | | | | | | |
39290 ++ * | | | | | | |
39291 ++ * +----------------------------------------
39292 ++ * cpu0 cpu1 cpu2
39293 ++ *
39294 ++ * In the above example if a task is capped to a specific performance
39295 ++ * point, y, then when:
39296 ++ *
39297 ++ * * util = 80% of x then it does not fit on cpu0 and should migrate
39298 ++ * to cpu1
39299 ++ * * util = 80% of y then it is forced to fit on cpu1 to honour
39300 ++ * uclamp_max request.
39301 ++ *
39302 ++ * which is what we're enforcing here. A task always fits if
39303 ++ * uclamp_max <= capacity_orig. But when uclamp_max > capacity_orig,
39304 ++ * the normal upmigration rules should withhold still.
39305 ++ *
39306 ++ * Only exception is when we are on max capacity, then we need to be
39307 ++ * careful not to block overutilized state. This is so because:
39308 ++ *
39309 ++ * 1. There's no concept of capping at max_capacity! We can't go
39310 ++ * beyond this performance level anyway.
39311 ++ * 2. The system is being saturated when we're operating near
39312 ++ * max capacity, it doesn't make sense to block overutilized.
39313 ++ */
39314 ++ uclamp_max_fits = (capacity_orig == SCHED_CAPACITY_SCALE) && (uclamp_max == SCHED_CAPACITY_SCALE);
39315 ++ uclamp_max_fits = !uclamp_max_fits && (uclamp_max <= capacity_orig);
39316 ++ fits = fits || uclamp_max_fits;
39317 ++
39318 ++ /*
39319 ++ *
39320 ++ * C=z
39321 ++ * | ___ (region a, capped, util >= uclamp_max)
39322 ++ * | C=y | |
39323 ++ * |_ _ _ _ _ _ _ _ _ ___ _ _ _ | _ | _ _ _ _ _ uclamp_max
39324 ++ * | C=x | | | |
39325 ++ * | ___ | | | | (region b, uclamp_min <= util <= uclamp_max)
39326 ++ * |_ _ _|_ _|_ _ _ _| _ | _ _ _| _ | _ _ _ _ _ uclamp_min
39327 ++ * | | | | | | |
39328 ++ * | | | | | | | (region c, boosted, util < uclamp_min)
39329 ++ * +----------------------------------------
39330 ++ * cpu0 cpu1 cpu2
39331 ++ *
39332 ++ * a) If util > uclamp_max, then we're capped, we don't care about
39333 ++ * actual fitness value here. We only care if uclamp_max fits
39334 ++ * capacity without taking margin/pressure into account.
39335 ++ * See comment above.
39336 ++ *
39337 ++ * b) If uclamp_min <= util <= uclamp_max, then the normal
39338 ++ * fits_capacity() rules apply. Except we need to ensure that we
39339 ++ * enforce we remain within uclamp_max, see comment above.
39340 ++ *
39341 ++ * c) If util < uclamp_min, then we are boosted. Same as (b) but we
39342 ++ * need to take into account the boosted value fits the CPU without
39343 ++ * taking margin/pressure into account.
39344 ++ *
39345 ++ * Cases (a) and (b) are handled in the 'fits' variable already. We
39346 ++ * just need to consider an extra check for case (c) after ensuring we
39347 ++ * handle the case uclamp_min > uclamp_max.
39348 ++ */
39349 ++ uclamp_min = min(uclamp_min, uclamp_max);
39350 ++ if (util < uclamp_min && capacity_orig != SCHED_CAPACITY_SCALE)
39351 ++ fits = fits && (uclamp_min <= capacity_orig_thermal);
39352 ++
39353 ++ return fits;
39354 ++}
39355 ++
39356 ++static inline int task_fits_cpu(struct task_struct *p, int cpu)
39357 ++{
39358 ++ unsigned long uclamp_min = uclamp_eff_value(p, UCLAMP_MIN);
39359 ++ unsigned long uclamp_max = uclamp_eff_value(p, UCLAMP_MAX);
39360 ++ unsigned long util = task_util_est(p);
39361 ++ return util_fits_cpu(util, uclamp_min, uclamp_max, cpu);
39362 + }
39363 +
39364 + static inline void update_misfit_status(struct task_struct *p, struct rq *rq)
39365 + {
39366 +- if (!static_branch_unlikely(&sched_asym_cpucapacity))
39367 ++ if (!sched_asym_cpucap_active())
39368 + return;
39369 +
39370 + if (!p || p->nr_cpus_allowed == 1) {
39371 +@@ -4270,7 +4397,7 @@ static inline void update_misfit_status(struct task_struct *p, struct rq *rq)
39372 + return;
39373 + }
39374 +
39375 +- if (task_fits_capacity(p, capacity_of(cpu_of(rq)))) {
39376 ++ if (task_fits_cpu(p, cpu_of(rq))) {
39377 + rq->misfit_task_load = 0;
39378 + return;
39379 + }
39380 +@@ -5682,7 +5809,10 @@ static inline void hrtick_update(struct rq *rq)
39381 + #ifdef CONFIG_SMP
39382 + static inline bool cpu_overutilized(int cpu)
39383 + {
39384 +- return !fits_capacity(cpu_util_cfs(cpu), capacity_of(cpu));
39385 ++ unsigned long rq_util_min = uclamp_rq_get(cpu_rq(cpu), UCLAMP_MIN);
39386 ++ unsigned long rq_util_max = uclamp_rq_get(cpu_rq(cpu), UCLAMP_MAX);
39387 ++
39388 ++ return !util_fits_cpu(cpu_util_cfs(cpu), rq_util_min, rq_util_max, cpu);
39389 + }
39390 +
39391 + static inline void update_overutilized_status(struct rq *rq)
39392 +@@ -6478,21 +6608,23 @@ static int select_idle_cpu(struct task_struct *p, struct sched_domain *sd, bool
39393 + static int
39394 + select_idle_capacity(struct task_struct *p, struct sched_domain *sd, int target)
39395 + {
39396 +- unsigned long task_util, best_cap = 0;
39397 ++ unsigned long task_util, util_min, util_max, best_cap = 0;
39398 + int cpu, best_cpu = -1;
39399 + struct cpumask *cpus;
39400 +
39401 + cpus = this_cpu_cpumask_var_ptr(select_rq_mask);
39402 + cpumask_and(cpus, sched_domain_span(sd), p->cpus_ptr);
39403 +
39404 +- task_util = uclamp_task_util(p);
39405 ++ task_util = task_util_est(p);
39406 ++ util_min = uclamp_eff_value(p, UCLAMP_MIN);
39407 ++ util_max = uclamp_eff_value(p, UCLAMP_MAX);
39408 +
39409 + for_each_cpu_wrap(cpu, cpus, target) {
39410 + unsigned long cpu_cap = capacity_of(cpu);
39411 +
39412 + if (!available_idle_cpu(cpu) && !sched_idle_cpu(cpu))
39413 + continue;
39414 +- if (fits_capacity(task_util, cpu_cap))
39415 ++ if (util_fits_cpu(task_util, util_min, util_max, cpu))
39416 + return cpu;
39417 +
39418 + if (cpu_cap > best_cap) {
39419 +@@ -6504,10 +6636,13 @@ select_idle_capacity(struct task_struct *p, struct sched_domain *sd, int target)
39420 + return best_cpu;
39421 + }
39422 +
39423 +-static inline bool asym_fits_capacity(unsigned long task_util, int cpu)
39424 ++static inline bool asym_fits_cpu(unsigned long util,
39425 ++ unsigned long util_min,
39426 ++ unsigned long util_max,
39427 ++ int cpu)
39428 + {
39429 +- if (static_branch_unlikely(&sched_asym_cpucapacity))
39430 +- return fits_capacity(task_util, capacity_of(cpu));
39431 ++ if (sched_asym_cpucap_active())
39432 ++ return util_fits_cpu(util, util_min, util_max, cpu);
39433 +
39434 + return true;
39435 + }
39436 +@@ -6519,16 +6654,18 @@ static int select_idle_sibling(struct task_struct *p, int prev, int target)
39437 + {
39438 + bool has_idle_core = false;
39439 + struct sched_domain *sd;
39440 +- unsigned long task_util;
39441 ++ unsigned long task_util, util_min, util_max;
39442 + int i, recent_used_cpu;
39443 +
39444 + /*
39445 + * On asymmetric system, update task utilization because we will check
39446 + * that the task fits with cpu's capacity.
39447 + */
39448 +- if (static_branch_unlikely(&sched_asym_cpucapacity)) {
39449 ++ if (sched_asym_cpucap_active()) {
39450 + sync_entity_load_avg(&p->se);
39451 +- task_util = uclamp_task_util(p);
39452 ++ task_util = task_util_est(p);
39453 ++ util_min = uclamp_eff_value(p, UCLAMP_MIN);
39454 ++ util_max = uclamp_eff_value(p, UCLAMP_MAX);
39455 + }
39456 +
39457 + /*
39458 +@@ -6537,7 +6674,7 @@ static int select_idle_sibling(struct task_struct *p, int prev, int target)
39459 + lockdep_assert_irqs_disabled();
39460 +
39461 + if ((available_idle_cpu(target) || sched_idle_cpu(target)) &&
39462 +- asym_fits_capacity(task_util, target))
39463 ++ asym_fits_cpu(task_util, util_min, util_max, target))
39464 + return target;
39465 +
39466 + /*
39467 +@@ -6545,7 +6682,7 @@ static int select_idle_sibling(struct task_struct *p, int prev, int target)
39468 + */
39469 + if (prev != target && cpus_share_cache(prev, target) &&
39470 + (available_idle_cpu(prev) || sched_idle_cpu(prev)) &&
39471 +- asym_fits_capacity(task_util, prev))
39472 ++ asym_fits_cpu(task_util, util_min, util_max, prev))
39473 + return prev;
39474 +
39475 + /*
39476 +@@ -6560,7 +6697,7 @@ static int select_idle_sibling(struct task_struct *p, int prev, int target)
39477 + in_task() &&
39478 + prev == smp_processor_id() &&
39479 + this_rq()->nr_running <= 1 &&
39480 +- asym_fits_capacity(task_util, prev)) {
39481 ++ asym_fits_cpu(task_util, util_min, util_max, prev)) {
39482 + return prev;
39483 + }
39484 +
39485 +@@ -6572,7 +6709,7 @@ static int select_idle_sibling(struct task_struct *p, int prev, int target)
39486 + cpus_share_cache(recent_used_cpu, target) &&
39487 + (available_idle_cpu(recent_used_cpu) || sched_idle_cpu(recent_used_cpu)) &&
39488 + cpumask_test_cpu(p->recent_used_cpu, p->cpus_ptr) &&
39489 +- asym_fits_capacity(task_util, recent_used_cpu)) {
39490 ++ asym_fits_cpu(task_util, util_min, util_max, recent_used_cpu)) {
39491 + return recent_used_cpu;
39492 + }
39493 +
39494 +@@ -6580,7 +6717,7 @@ static int select_idle_sibling(struct task_struct *p, int prev, int target)
39495 + * For asymmetric CPU capacity systems, our domain of interest is
39496 + * sd_asym_cpucapacity rather than sd_llc.
39497 + */
39498 +- if (static_branch_unlikely(&sched_asym_cpucapacity)) {
39499 ++ if (sched_asym_cpucap_active()) {
39500 + sd = rcu_dereference(per_cpu(sd_asym_cpucapacity, target));
39501 + /*
39502 + * On an asymmetric CPU capacity system where an exclusive
39503 +@@ -6868,6 +7005,8 @@ static int find_energy_efficient_cpu(struct task_struct *p, int prev_cpu)
39504 + {
39505 + struct cpumask *cpus = this_cpu_cpumask_var_ptr(select_rq_mask);
39506 + unsigned long prev_delta = ULONG_MAX, best_delta = ULONG_MAX;
39507 ++ unsigned long p_util_min = uclamp_is_used() ? uclamp_eff_value(p, UCLAMP_MIN) : 0;
39508 ++ unsigned long p_util_max = uclamp_is_used() ? uclamp_eff_value(p, UCLAMP_MAX) : 1024;
39509 + struct root_domain *rd = this_rq()->rd;
39510 + int cpu, best_energy_cpu, target = -1;
39511 + struct sched_domain *sd;
39512 +@@ -6892,7 +7031,7 @@ static int find_energy_efficient_cpu(struct task_struct *p, int prev_cpu)
39513 + target = prev_cpu;
39514 +
39515 + sync_entity_load_avg(&p->se);
39516 +- if (!task_util_est(p))
39517 ++ if (!uclamp_task_util(p, p_util_min, p_util_max))
39518 + goto unlock;
39519 +
39520 + eenv_task_busy_time(&eenv, p, prev_cpu);
39521 +@@ -6900,6 +7039,8 @@ static int find_energy_efficient_cpu(struct task_struct *p, int prev_cpu)
39522 + for (; pd; pd = pd->next) {
39523 + unsigned long cpu_cap, cpu_thermal_cap, util;
39524 + unsigned long cur_delta, max_spare_cap = 0;
39525 ++ unsigned long rq_util_min, rq_util_max;
39526 ++ unsigned long util_min, util_max;
39527 + bool compute_prev_delta = false;
39528 + int max_spare_cap_cpu = -1;
39529 + unsigned long base_energy;
39530 +@@ -6936,8 +7077,26 @@ static int find_energy_efficient_cpu(struct task_struct *p, int prev_cpu)
39531 + * much capacity we can get out of the CPU; this is
39532 + * aligned with sched_cpu_util().
39533 + */
39534 +- util = uclamp_rq_util_with(cpu_rq(cpu), util, p);
39535 +- if (!fits_capacity(util, cpu_cap))
39536 ++ if (uclamp_is_used()) {
39537 ++ if (uclamp_rq_is_idle(cpu_rq(cpu))) {
39538 ++ util_min = p_util_min;
39539 ++ util_max = p_util_max;
39540 ++ } else {
39541 ++ /*
39542 ++ * Open code uclamp_rq_util_with() except for
39543 ++ * the clamp() part. Ie: apply max aggregation
39544 ++ * only. util_fits_cpu() logic requires to
39545 ++ * operate on non clamped util but must use the
39546 ++ * max-aggregated uclamp_{min, max}.
39547 ++ */
39548 ++ rq_util_min = uclamp_rq_get(cpu_rq(cpu), UCLAMP_MIN);
39549 ++ rq_util_max = uclamp_rq_get(cpu_rq(cpu), UCLAMP_MAX);
39550 ++
39551 ++ util_min = max(rq_util_min, p_util_min);
39552 ++ util_max = max(rq_util_max, p_util_max);
39553 ++ }
39554 ++ }
39555 ++ if (!util_fits_cpu(util, util_min, util_max, cpu))
39556 + continue;
39557 +
39558 + lsub_positive(&cpu_cap, util);
39559 +@@ -8108,7 +8267,7 @@ static int detach_tasks(struct lb_env *env)
39560 +
39561 + case migrate_misfit:
39562 + /* This is not a misfit task */
39563 +- if (task_fits_capacity(p, capacity_of(env->src_cpu)))
39564 ++ if (task_fits_cpu(p, env->src_cpu))
39565 + goto next;
39566 +
39567 + env->imbalance = 0;
39568 +@@ -9113,6 +9272,10 @@ static inline void update_sg_wakeup_stats(struct sched_domain *sd,
39569 +
39570 + memset(sgs, 0, sizeof(*sgs));
39571 +
39572 ++ /* Assume that task can't fit any CPU of the group */
39573 ++ if (sd->flags & SD_ASYM_CPUCAPACITY)
39574 ++ sgs->group_misfit_task_load = 1;
39575 ++
39576 + for_each_cpu(i, sched_group_span(group)) {
39577 + struct rq *rq = cpu_rq(i);
39578 + unsigned int local;
39579 +@@ -9132,12 +9295,12 @@ static inline void update_sg_wakeup_stats(struct sched_domain *sd,
39580 + if (!nr_running && idle_cpu_without(i, p))
39581 + sgs->idle_cpus++;
39582 +
39583 +- }
39584 ++ /* Check if task fits in the CPU */
39585 ++ if (sd->flags & SD_ASYM_CPUCAPACITY &&
39586 ++ sgs->group_misfit_task_load &&
39587 ++ task_fits_cpu(p, i))
39588 ++ sgs->group_misfit_task_load = 0;
39589 +
39590 +- /* Check if task fits in the group */
39591 +- if (sd->flags & SD_ASYM_CPUCAPACITY &&
39592 +- !task_fits_capacity(p, group->sgc->max_capacity)) {
39593 +- sgs->group_misfit_task_load = 1;
39594 + }
39595 +
39596 + sgs->group_capacity = group->sgc->capacity;
39597 +diff --git a/kernel/sched/psi.c b/kernel/sched/psi.c
39598 +index ecb4b4ff4ce0a..559416a27c0ed 100644
39599 +--- a/kernel/sched/psi.c
39600 ++++ b/kernel/sched/psi.c
39601 +@@ -537,10 +537,12 @@ static u64 update_triggers(struct psi_group *group, u64 now)
39602 +
39603 + /* Calculate growth since last update */
39604 + growth = window_update(&t->win, now, total[t->state]);
39605 +- if (growth < t->threshold)
39606 +- continue;
39607 ++ if (!t->pending_event) {
39608 ++ if (growth < t->threshold)
39609 ++ continue;
39610 +
39611 +- t->pending_event = true;
39612 ++ t->pending_event = true;
39613 ++ }
39614 + }
39615 + /* Limit event signaling to once per window */
39616 + if (now < t->last_event_time + t->win.size)
39617 +diff --git a/kernel/sched/rt.c b/kernel/sched/rt.c
39618 +index 55f39c8f42032..054b6711e9619 100644
39619 +--- a/kernel/sched/rt.c
39620 ++++ b/kernel/sched/rt.c
39621 +@@ -509,7 +509,7 @@ static inline bool rt_task_fits_capacity(struct task_struct *p, int cpu)
39622 + unsigned int cpu_cap;
39623 +
39624 + /* Only heterogeneous systems can benefit from this check */
39625 +- if (!static_branch_unlikely(&sched_asym_cpucapacity))
39626 ++ if (!sched_asym_cpucap_active())
39627 + return true;
39628 +
39629 + min_cap = uclamp_eff_value(p, UCLAMP_MIN);
39630 +@@ -1897,7 +1897,7 @@ static int find_lowest_rq(struct task_struct *task)
39631 + * If we're on asym system ensure we consider the different capacities
39632 + * of the CPUs when searching for the lowest_mask.
39633 + */
39634 +- if (static_branch_unlikely(&sched_asym_cpucapacity)) {
39635 ++ if (sched_asym_cpucap_active()) {
39636 +
39637 + ret = cpupri_find_fitness(&task_rq(task)->rd->cpupri,
39638 + task, lowest_mask,
39639 +diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
39640 +index f34b489636ffb..2fcb7eb56c018 100644
39641 +--- a/kernel/sched/sched.h
39642 ++++ b/kernel/sched/sched.h
39643 +@@ -1815,6 +1815,11 @@ DECLARE_PER_CPU(struct sched_domain __rcu *, sd_asym_packing);
39644 + DECLARE_PER_CPU(struct sched_domain __rcu *, sd_asym_cpucapacity);
39645 + extern struct static_key_false sched_asym_cpucapacity;
39646 +
39647 ++static __always_inline bool sched_asym_cpucap_active(void)
39648 ++{
39649 ++ return static_branch_unlikely(&sched_asym_cpucapacity);
39650 ++}
39651 ++
39652 + struct sched_group_capacity {
39653 + atomic_t ref;
39654 + /*
39655 +@@ -2963,6 +2968,23 @@ static inline unsigned long cpu_util_rt(struct rq *rq)
39656 + #ifdef CONFIG_UCLAMP_TASK
39657 + unsigned long uclamp_eff_value(struct task_struct *p, enum uclamp_id clamp_id);
39658 +
39659 ++static inline unsigned long uclamp_rq_get(struct rq *rq,
39660 ++ enum uclamp_id clamp_id)
39661 ++{
39662 ++ return READ_ONCE(rq->uclamp[clamp_id].value);
39663 ++}
39664 ++
39665 ++static inline void uclamp_rq_set(struct rq *rq, enum uclamp_id clamp_id,
39666 ++ unsigned int value)
39667 ++{
39668 ++ WRITE_ONCE(rq->uclamp[clamp_id].value, value);
39669 ++}
39670 ++
39671 ++static inline bool uclamp_rq_is_idle(struct rq *rq)
39672 ++{
39673 ++ return rq->uclamp_flags & UCLAMP_FLAG_IDLE;
39674 ++}
39675 ++
39676 + /**
39677 + * uclamp_rq_util_with - clamp @util with @rq and @p effective uclamp values.
39678 + * @rq: The rq to clamp against. Must not be NULL.
39679 +@@ -2998,12 +3020,12 @@ unsigned long uclamp_rq_util_with(struct rq *rq, unsigned long util,
39680 + * Ignore last runnable task's max clamp, as this task will
39681 + * reset it. Similarly, no need to read the rq's min clamp.
39682 + */
39683 +- if (rq->uclamp_flags & UCLAMP_FLAG_IDLE)
39684 ++ if (uclamp_rq_is_idle(rq))
39685 + goto out;
39686 + }
39687 +
39688 +- min_util = max_t(unsigned long, min_util, READ_ONCE(rq->uclamp[UCLAMP_MIN].value));
39689 +- max_util = max_t(unsigned long, max_util, READ_ONCE(rq->uclamp[UCLAMP_MAX].value));
39690 ++ min_util = max_t(unsigned long, min_util, uclamp_rq_get(rq, UCLAMP_MIN));
39691 ++ max_util = max_t(unsigned long, max_util, uclamp_rq_get(rq, UCLAMP_MAX));
39692 + out:
39693 + /*
39694 + * Since CPU's {min,max}_util clamps are MAX aggregated considering
39695 +@@ -3044,6 +3066,15 @@ static inline bool uclamp_is_used(void)
39696 + return static_branch_likely(&sched_uclamp_used);
39697 + }
39698 + #else /* CONFIG_UCLAMP_TASK */
39699 ++static inline unsigned long uclamp_eff_value(struct task_struct *p,
39700 ++ enum uclamp_id clamp_id)
39701 ++{
39702 ++ if (clamp_id == UCLAMP_MIN)
39703 ++ return 0;
39704 ++
39705 ++ return SCHED_CAPACITY_SCALE;
39706 ++}
39707 ++
39708 + static inline
39709 + unsigned long uclamp_rq_util_with(struct rq *rq, unsigned long util,
39710 + struct task_struct *p)
39711 +@@ -3057,6 +3088,25 @@ static inline bool uclamp_is_used(void)
39712 + {
39713 + return false;
39714 + }
39715 ++
39716 ++static inline unsigned long uclamp_rq_get(struct rq *rq,
39717 ++ enum uclamp_id clamp_id)
39718 ++{
39719 ++ if (clamp_id == UCLAMP_MIN)
39720 ++ return 0;
39721 ++
39722 ++ return SCHED_CAPACITY_SCALE;
39723 ++}
39724 ++
39725 ++static inline void uclamp_rq_set(struct rq *rq, enum uclamp_id clamp_id,
39726 ++ unsigned int value)
39727 ++{
39728 ++}
39729 ++
39730 ++static inline bool uclamp_rq_is_idle(struct rq *rq)
39731 ++{
39732 ++ return false;
39733 ++}
39734 + #endif /* CONFIG_UCLAMP_TASK */
39735 +
39736 + #ifdef CONFIG_HAVE_SCHED_AVG_IRQ
39737 +diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
39738 +index 7f5eb295fe198..ee22a3b1c1816 100644
39739 +--- a/kernel/trace/blktrace.c
39740 ++++ b/kernel/trace/blktrace.c
39741 +@@ -1546,7 +1546,8 @@ blk_trace_event_print_binary(struct trace_iterator *iter, int flags,
39742 +
39743 + static enum print_line_t blk_tracer_print_line(struct trace_iterator *iter)
39744 + {
39745 +- if (!(blk_tracer_flags.val & TRACE_BLK_OPT_CLASSIC))
39746 ++ if ((iter->ent->type != TRACE_BLK) ||
39747 ++ !(blk_tracer_flags.val & TRACE_BLK_OPT_CLASSIC))
39748 + return TRACE_TYPE_UNHANDLED;
39749 +
39750 + return print_one_line(iter, true);
39751 +diff --git a/kernel/trace/trace_events_hist.c b/kernel/trace/trace_events_hist.c
39752 +index 49243e8617148..d8406f6f5d399 100644
39753 +--- a/kernel/trace/trace_events_hist.c
39754 ++++ b/kernel/trace/trace_events_hist.c
39755 +@@ -6346,7 +6346,7 @@ enable:
39756 + if (se)
39757 + se->ref++;
39758 + out:
39759 +- if (ret == 0)
39760 ++ if (ret == 0 && glob[0])
39761 + hist_err_clear();
39762 +
39763 + return ret;
39764 +diff --git a/kernel/trace/trace_events_user.c b/kernel/trace/trace_events_user.c
39765 +index a6621c52ce454..b885b6934893f 100644
39766 +--- a/kernel/trace/trace_events_user.c
39767 ++++ b/kernel/trace/trace_events_user.c
39768 +@@ -1127,6 +1127,7 @@ put_user_lock:
39769 + put_user:
39770 + user_event_destroy_fields(user);
39771 + user_event_destroy_validators(user);
39772 ++ kfree(user->call.print_fmt);
39773 + kfree(user);
39774 + return ret;
39775 + }
39776 +diff --git a/lib/debugobjects.c b/lib/debugobjects.c
39777 +index 337d797a71416..6f8e5dd1dcd0c 100644
39778 +--- a/lib/debugobjects.c
39779 ++++ b/lib/debugobjects.c
39780 +@@ -437,6 +437,7 @@ static int object_cpu_offline(unsigned int cpu)
39781 + struct debug_percpu_free *percpu_pool;
39782 + struct hlist_node *tmp;
39783 + struct debug_obj *obj;
39784 ++ unsigned long flags;
39785 +
39786 + /* Remote access is safe as the CPU is dead already */
39787 + percpu_pool = per_cpu_ptr(&percpu_obj_pool, cpu);
39788 +@@ -444,6 +445,12 @@ static int object_cpu_offline(unsigned int cpu)
39789 + hlist_del(&obj->node);
39790 + kmem_cache_free(obj_cache, obj);
39791 + }
39792 ++
39793 ++ raw_spin_lock_irqsave(&pool_lock, flags);
39794 ++ obj_pool_used -= percpu_pool->obj_free;
39795 ++ debug_objects_freed += percpu_pool->obj_free;
39796 ++ raw_spin_unlock_irqrestore(&pool_lock, flags);
39797 ++
39798 + percpu_pool->obj_free = 0;
39799 +
39800 + return 0;
39801 +@@ -1318,6 +1325,8 @@ static int __init debug_objects_replace_static_objects(void)
39802 + hlist_add_head(&obj->node, &objects);
39803 + }
39804 +
39805 ++ debug_objects_allocated += i;
39806 ++
39807 + /*
39808 + * debug_objects_mem_init() is now called early that only one CPU is up
39809 + * and interrupts have been disabled, so it is safe to replace the
39810 +@@ -1386,6 +1395,7 @@ void __init debug_objects_mem_init(void)
39811 + debug_objects_enabled = 0;
39812 + kmem_cache_destroy(obj_cache);
39813 + pr_warn("out of memory.\n");
39814 ++ return;
39815 + } else
39816 + debug_objects_selftest();
39817 +
39818 +diff --git a/lib/fonts/fonts.c b/lib/fonts/fonts.c
39819 +index 5f4b07b56cd9c..9738664386088 100644
39820 +--- a/lib/fonts/fonts.c
39821 ++++ b/lib/fonts/fonts.c
39822 +@@ -135,8 +135,8 @@ const struct font_desc *get_default_font(int xres, int yres, u32 font_w,
39823 + if (res > 20)
39824 + c += 20 - res;
39825 +
39826 +- if ((font_w & (1 << (f->width - 1))) &&
39827 +- (font_h & (1 << (f->height - 1))))
39828 ++ if ((font_w & (1U << (f->width - 1))) &&
39829 ++ (font_h & (1U << (f->height - 1))))
39830 + c += 1000;
39831 +
39832 + if (c > cc) {
39833 +diff --git a/lib/notifier-error-inject.c b/lib/notifier-error-inject.c
39834 +index 21016b32d3131..2b24ea6c94979 100644
39835 +--- a/lib/notifier-error-inject.c
39836 ++++ b/lib/notifier-error-inject.c
39837 +@@ -15,7 +15,7 @@ static int debugfs_errno_get(void *data, u64 *val)
39838 + return 0;
39839 + }
39840 +
39841 +-DEFINE_SIMPLE_ATTRIBUTE(fops_errno, debugfs_errno_get, debugfs_errno_set,
39842 ++DEFINE_SIMPLE_ATTRIBUTE_SIGNED(fops_errno, debugfs_errno_get, debugfs_errno_set,
39843 + "%lld\n");
39844 +
39845 + static struct dentry *debugfs_create_errno(const char *name, umode_t mode,
39846 +diff --git a/lib/test_firmware.c b/lib/test_firmware.c
39847 +index c82b65947ce68..1c5a2adb16ef5 100644
39848 +--- a/lib/test_firmware.c
39849 ++++ b/lib/test_firmware.c
39850 +@@ -1491,6 +1491,7 @@ static int __init test_firmware_init(void)
39851 +
39852 + rc = misc_register(&test_fw_misc_device);
39853 + if (rc) {
39854 ++ __test_firmware_config_free();
39855 + kfree(test_fw_config);
39856 + pr_err("could not register misc device: %d\n", rc);
39857 + return rc;
39858 +diff --git a/mm/gup.c b/mm/gup.c
39859 +index d7f9116fc645c..60d7213ad95b3 100644
39860 +--- a/mm/gup.c
39861 ++++ b/mm/gup.c
39862 +@@ -1058,6 +1058,9 @@ static int check_vma_flags(struct vm_area_struct *vma, unsigned long gup_flags)
39863 + if (!(vm_flags & VM_WRITE)) {
39864 + if (!(gup_flags & FOLL_FORCE))
39865 + return -EFAULT;
39866 ++ /* hugetlb does not support FOLL_FORCE|FOLL_WRITE. */
39867 ++ if (is_vm_hugetlb_page(vma))
39868 ++ return -EFAULT;
39869 + /*
39870 + * We used to let the write,force case do COW in a
39871 + * VM_MAYWRITE VM_SHARED !VM_WRITE vma, so ptrace could
39872 +diff --git a/net/802/mrp.c b/net/802/mrp.c
39873 +index 35e04cc5390c4..c10a432a5b435 100644
39874 +--- a/net/802/mrp.c
39875 ++++ b/net/802/mrp.c
39876 +@@ -606,7 +606,10 @@ static void mrp_join_timer(struct timer_list *t)
39877 + spin_unlock(&app->lock);
39878 +
39879 + mrp_queue_xmit(app);
39880 +- mrp_join_timer_arm(app);
39881 ++ spin_lock(&app->lock);
39882 ++ if (likely(app->active))
39883 ++ mrp_join_timer_arm(app);
39884 ++ spin_unlock(&app->lock);
39885 + }
39886 +
39887 + static void mrp_periodic_timer_arm(struct mrp_applicant *app)
39888 +@@ -620,11 +623,12 @@ static void mrp_periodic_timer(struct timer_list *t)
39889 + struct mrp_applicant *app = from_timer(app, t, periodic_timer);
39890 +
39891 + spin_lock(&app->lock);
39892 +- mrp_mad_event(app, MRP_EVENT_PERIODIC);
39893 +- mrp_pdu_queue(app);
39894 ++ if (likely(app->active)) {
39895 ++ mrp_mad_event(app, MRP_EVENT_PERIODIC);
39896 ++ mrp_pdu_queue(app);
39897 ++ mrp_periodic_timer_arm(app);
39898 ++ }
39899 + spin_unlock(&app->lock);
39900 +-
39901 +- mrp_periodic_timer_arm(app);
39902 + }
39903 +
39904 + static int mrp_pdu_parse_end_mark(struct sk_buff *skb, int *offset)
39905 +@@ -872,6 +876,7 @@ int mrp_init_applicant(struct net_device *dev, struct mrp_application *appl)
39906 + app->dev = dev;
39907 + app->app = appl;
39908 + app->mad = RB_ROOT;
39909 ++ app->active = true;
39910 + spin_lock_init(&app->lock);
39911 + skb_queue_head_init(&app->queue);
39912 + rcu_assign_pointer(dev->mrp_port->applicants[appl->type], app);
39913 +@@ -900,6 +905,9 @@ void mrp_uninit_applicant(struct net_device *dev, struct mrp_application *appl)
39914 +
39915 + RCU_INIT_POINTER(port->applicants[appl->type], NULL);
39916 +
39917 ++ spin_lock_bh(&app->lock);
39918 ++ app->active = false;
39919 ++ spin_unlock_bh(&app->lock);
39920 + /* Delete timer and generate a final TX event to flush out
39921 + * all pending messages before the applicant is gone.
39922 + */
39923 +diff --git a/net/8021q/vlan_dev.c b/net/8021q/vlan_dev.c
39924 +index 035812b0461cc..ecdb47712d956 100644
39925 +--- a/net/8021q/vlan_dev.c
39926 ++++ b/net/8021q/vlan_dev.c
39927 +@@ -712,13 +712,13 @@ static void vlan_dev_get_stats64(struct net_device *dev,
39928 +
39929 + p = per_cpu_ptr(vlan_dev_priv(dev)->vlan_pcpu_stats, i);
39930 + do {
39931 +- start = u64_stats_fetch_begin_irq(&p->syncp);
39932 ++ start = u64_stats_fetch_begin(&p->syncp);
39933 + rxpackets = u64_stats_read(&p->rx_packets);
39934 + rxbytes = u64_stats_read(&p->rx_bytes);
39935 + rxmulticast = u64_stats_read(&p->rx_multicast);
39936 + txpackets = u64_stats_read(&p->tx_packets);
39937 + txbytes = u64_stats_read(&p->tx_bytes);
39938 +- } while (u64_stats_fetch_retry_irq(&p->syncp, start));
39939 ++ } while (u64_stats_fetch_retry(&p->syncp, start));
39940 +
39941 + stats->rx_packets += rxpackets;
39942 + stats->rx_bytes += rxbytes;
39943 +diff --git a/net/9p/client.c b/net/9p/client.c
39944 +index 0a6110e15d0f8..8464d95805d08 100644
39945 +--- a/net/9p/client.c
39946 ++++ b/net/9p/client.c
39947 +@@ -279,6 +279,11 @@ p9_tag_alloc(struct p9_client *c, int8_t type, unsigned int max_size)
39948 + p9pdu_reset(&req->rc);
39949 + req->t_err = 0;
39950 + req->status = REQ_STATUS_ALLOC;
39951 ++ /* refcount needs to be set to 0 before inserting into the idr
39952 ++ * so p9_tag_lookup does not accept a request that is not fully
39953 ++ * initialized. refcount_set to 2 below will mark request ready.
39954 ++ */
39955 ++ refcount_set(&req->refcount, 0);
39956 + init_waitqueue_head(&req->wq);
39957 + INIT_LIST_HEAD(&req->req_list);
39958 +
39959 +diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c
39960 +index f26ed278d9e3c..67360444eee6c 100644
39961 +--- a/net/bluetooth/hci_conn.c
39962 ++++ b/net/bluetooth/hci_conn.c
39963 +@@ -1817,7 +1817,7 @@ static int hci_create_cis_sync(struct hci_dev *hdev, void *data)
39964 + continue;
39965 +
39966 + /* Check if all CIS(s) belonging to a CIG are ready */
39967 +- if (conn->link->state != BT_CONNECTED ||
39968 ++ if (!conn->link || conn->link->state != BT_CONNECTED ||
39969 + conn->state != BT_CONNECT) {
39970 + cmd.cp.num_cis = 0;
39971 + break;
39972 +diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
39973 +index c8ea03edd081f..9f8b49ff2d339 100644
39974 +--- a/net/bluetooth/hci_core.c
39975 ++++ b/net/bluetooth/hci_core.c
39976 +@@ -2653,7 +2653,7 @@ int hci_register_dev(struct hci_dev *hdev)
39977 +
39978 + error = hci_register_suspend_notifier(hdev);
39979 + if (error)
39980 +- goto err_wqueue;
39981 ++ BT_WARN("register suspend notifier failed error:%d\n", error);
39982 +
39983 + queue_work(hdev->req_workqueue, &hdev->power_on);
39984 +
39985 +@@ -3978,7 +3978,7 @@ void hci_req_cmd_complete(struct hci_dev *hdev, u16 opcode, u8 status,
39986 + *req_complete_skb = bt_cb(skb)->hci.req_complete_skb;
39987 + else
39988 + *req_complete = bt_cb(skb)->hci.req_complete;
39989 +- kfree_skb(skb);
39990 ++ dev_kfree_skb_irq(skb);
39991 + }
39992 + spin_unlock_irqrestore(&hdev->cmd_q.lock, flags);
39993 + }
39994 +diff --git a/net/bluetooth/hci_sync.c b/net/bluetooth/hci_sync.c
39995 +index a5e89e1b5452a..117537f3e7ad0 100644
39996 +--- a/net/bluetooth/hci_sync.c
39997 ++++ b/net/bluetooth/hci_sync.c
39998 +@@ -3940,7 +3940,7 @@ static int hci_read_local_pairing_opts_sync(struct hci_dev *hdev)
39999 + /* Get MWS transport configuration if the HCI command is supported */
40000 + static int hci_get_mws_transport_config_sync(struct hci_dev *hdev)
40001 + {
40002 +- if (!(hdev->commands[30] & 0x08))
40003 ++ if (!mws_transport_config_capable(hdev))
40004 + return 0;
40005 +
40006 + return __hci_cmd_sync_status(hdev, HCI_OP_GET_MWS_TRANSPORT_CONFIG,
40007 +diff --git a/net/bluetooth/lib.c b/net/bluetooth/lib.c
40008 +index 469a0c95b6e8a..53a796ac078c3 100644
40009 +--- a/net/bluetooth/lib.c
40010 ++++ b/net/bluetooth/lib.c
40011 +@@ -170,7 +170,7 @@ __u8 bt_status(int err)
40012 + case -EMLINK:
40013 + return 0x09;
40014 +
40015 +- case EALREADY:
40016 ++ case -EALREADY:
40017 + return 0x0b;
40018 +
40019 + case -EBUSY:
40020 +@@ -191,7 +191,7 @@ __u8 bt_status(int err)
40021 + case -ECONNABORTED:
40022 + return 0x16;
40023 +
40024 +- case ELOOP:
40025 ++ case -ELOOP:
40026 + return 0x17;
40027 +
40028 + case -EPROTONOSUPPORT:
40029 +diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
40030 +index 3d1cd06669688..22bfeb5b2b3bb 100644
40031 +--- a/net/bluetooth/mgmt.c
40032 ++++ b/net/bluetooth/mgmt.c
40033 +@@ -8385,7 +8385,7 @@ static int add_ext_adv_params(struct sock *sk, struct hci_dev *hdev,
40034 + * extra parameters we don't know about will be ignored in this request.
40035 + */
40036 + if (data_len < MGMT_ADD_EXT_ADV_PARAMS_MIN_SIZE)
40037 +- return mgmt_cmd_status(sk, hdev->id, MGMT_OP_ADD_ADVERTISING,
40038 ++ return mgmt_cmd_status(sk, hdev->id, MGMT_OP_ADD_EXT_ADV_PARAMS,
40039 + MGMT_STATUS_INVALID_PARAMS);
40040 +
40041 + flags = __le32_to_cpu(cp->flags);
40042 +diff --git a/net/bluetooth/rfcomm/core.c b/net/bluetooth/rfcomm/core.c
40043 +index 7324764384b67..8d6fce9005bdd 100644
40044 +--- a/net/bluetooth/rfcomm/core.c
40045 ++++ b/net/bluetooth/rfcomm/core.c
40046 +@@ -590,7 +590,7 @@ int rfcomm_dlc_send(struct rfcomm_dlc *d, struct sk_buff *skb)
40047 +
40048 + ret = rfcomm_dlc_send_frag(d, frag);
40049 + if (ret < 0) {
40050 +- kfree_skb(frag);
40051 ++ dev_kfree_skb_irq(frag);
40052 + goto unlock;
40053 + }
40054 +
40055 +diff --git a/net/bpf/test_run.c b/net/bpf/test_run.c
40056 +index b422238f9f86c..5d53332ea3c9d 100644
40057 +--- a/net/bpf/test_run.c
40058 ++++ b/net/bpf/test_run.c
40059 +@@ -939,9 +939,6 @@ static int convert___skb_to_skb(struct sk_buff *skb, struct __sk_buff *__skb)
40060 + {
40061 + struct qdisc_skb_cb *cb = (struct qdisc_skb_cb *)skb->cb;
40062 +
40063 +- if (!skb->len)
40064 +- return -EINVAL;
40065 +-
40066 + if (!__skb)
40067 + return 0;
40068 +
40069 +diff --git a/net/bridge/br_multicast.c b/net/bridge/br_multicast.c
40070 +index db4f2641d1cd1..7e2a9fb5786c9 100644
40071 +--- a/net/bridge/br_multicast.c
40072 ++++ b/net/bridge/br_multicast.c
40073 +@@ -4899,9 +4899,9 @@ void br_multicast_get_stats(const struct net_bridge *br,
40074 + unsigned int start;
40075 +
40076 + do {
40077 +- start = u64_stats_fetch_begin_irq(&cpu_stats->syncp);
40078 ++ start = u64_stats_fetch_begin(&cpu_stats->syncp);
40079 + memcpy(&temp, &cpu_stats->mstats, sizeof(temp));
40080 +- } while (u64_stats_fetch_retry_irq(&cpu_stats->syncp, start));
40081 ++ } while (u64_stats_fetch_retry(&cpu_stats->syncp, start));
40082 +
40083 + mcast_stats_add_dir(tdst.igmp_v1queries, temp.igmp_v1queries);
40084 + mcast_stats_add_dir(tdst.igmp_v2queries, temp.igmp_v2queries);
40085 +diff --git a/net/bridge/br_vlan.c b/net/bridge/br_vlan.c
40086 +index 9ffd40b8270c1..bc75fa1e4666a 100644
40087 +--- a/net/bridge/br_vlan.c
40088 ++++ b/net/bridge/br_vlan.c
40089 +@@ -1389,12 +1389,12 @@ void br_vlan_get_stats(const struct net_bridge_vlan *v,
40090 +
40091 + cpu_stats = per_cpu_ptr(v->stats, i);
40092 + do {
40093 +- start = u64_stats_fetch_begin_irq(&cpu_stats->syncp);
40094 ++ start = u64_stats_fetch_begin(&cpu_stats->syncp);
40095 + rxpackets = u64_stats_read(&cpu_stats->rx_packets);
40096 + rxbytes = u64_stats_read(&cpu_stats->rx_bytes);
40097 + txbytes = u64_stats_read(&cpu_stats->tx_bytes);
40098 + txpackets = u64_stats_read(&cpu_stats->tx_packets);
40099 +- } while (u64_stats_fetch_retry_irq(&cpu_stats->syncp, start));
40100 ++ } while (u64_stats_fetch_retry(&cpu_stats->syncp, start));
40101 +
40102 + u64_stats_add(&stats->rx_packets, rxpackets);
40103 + u64_stats_add(&stats->rx_bytes, rxbytes);
40104 +diff --git a/net/core/dev.c b/net/core/dev.c
40105 +index 2c14f48d24573..25c73f9677611 100644
40106 +--- a/net/core/dev.c
40107 ++++ b/net/core/dev.c
40108 +@@ -10398,24 +10398,16 @@ void netdev_run_todo(void)
40109 + void netdev_stats_to_stats64(struct rtnl_link_stats64 *stats64,
40110 + const struct net_device_stats *netdev_stats)
40111 + {
40112 +-#if BITS_PER_LONG == 64
40113 +- BUILD_BUG_ON(sizeof(*stats64) < sizeof(*netdev_stats));
40114 +- memcpy(stats64, netdev_stats, sizeof(*netdev_stats));
40115 +- /* zero out counters that only exist in rtnl_link_stats64 */
40116 +- memset((char *)stats64 + sizeof(*netdev_stats), 0,
40117 +- sizeof(*stats64) - sizeof(*netdev_stats));
40118 +-#else
40119 +- size_t i, n = sizeof(*netdev_stats) / sizeof(unsigned long);
40120 +- const unsigned long *src = (const unsigned long *)netdev_stats;
40121 ++ size_t i, n = sizeof(*netdev_stats) / sizeof(atomic_long_t);
40122 ++ const atomic_long_t *src = (atomic_long_t *)netdev_stats;
40123 + u64 *dst = (u64 *)stats64;
40124 +
40125 + BUILD_BUG_ON(n > sizeof(*stats64) / sizeof(u64));
40126 + for (i = 0; i < n; i++)
40127 +- dst[i] = src[i];
40128 ++ dst[i] = atomic_long_read(&src[i]);
40129 + /* zero out counters that only exist in rtnl_link_stats64 */
40130 + memset((char *)stats64 + n * sizeof(u64), 0,
40131 + sizeof(*stats64) - n * sizeof(u64));
40132 +-#endif
40133 + }
40134 + EXPORT_SYMBOL(netdev_stats_to_stats64);
40135 +
40136 +@@ -10496,12 +10488,12 @@ void dev_fetch_sw_netstats(struct rtnl_link_stats64 *s,
40137 +
40138 + stats = per_cpu_ptr(netstats, cpu);
40139 + do {
40140 +- start = u64_stats_fetch_begin_irq(&stats->syncp);
40141 ++ start = u64_stats_fetch_begin(&stats->syncp);
40142 + rx_packets = u64_stats_read(&stats->rx_packets);
40143 + rx_bytes = u64_stats_read(&stats->rx_bytes);
40144 + tx_packets = u64_stats_read(&stats->tx_packets);
40145 + tx_bytes = u64_stats_read(&stats->tx_bytes);
40146 +- } while (u64_stats_fetch_retry_irq(&stats->syncp, start));
40147 ++ } while (u64_stats_fetch_retry(&stats->syncp, start));
40148 +
40149 + s->rx_packets += rx_packets;
40150 + s->rx_bytes += rx_bytes;
40151 +diff --git a/net/core/devlink.c b/net/core/devlink.c
40152 +index b50bcc18b8d9e..5f894bd20c310 100644
40153 +--- a/net/core/devlink.c
40154 ++++ b/net/core/devlink.c
40155 +@@ -1498,10 +1498,13 @@ static int devlink_nl_cmd_get_dumpit(struct sk_buff *msg,
40156 + continue;
40157 + }
40158 +
40159 ++ devl_lock(devlink);
40160 + err = devlink_nl_fill(msg, devlink, DEVLINK_CMD_NEW,
40161 + NETLINK_CB(cb->skb).portid,
40162 + cb->nlh->nlmsg_seq, NLM_F_MULTI);
40163 ++ devl_unlock(devlink);
40164 + devlink_put(devlink);
40165 ++
40166 + if (err)
40167 + goto out;
40168 + idx++;
40169 +@@ -8268,10 +8271,10 @@ static void devlink_trap_stats_read(struct devlink_stats __percpu *trap_stats,
40170 +
40171 + cpu_stats = per_cpu_ptr(trap_stats, i);
40172 + do {
40173 +- start = u64_stats_fetch_begin_irq(&cpu_stats->syncp);
40174 ++ start = u64_stats_fetch_begin(&cpu_stats->syncp);
40175 + rx_packets = u64_stats_read(&cpu_stats->rx_packets);
40176 + rx_bytes = u64_stats_read(&cpu_stats->rx_bytes);
40177 +- } while (u64_stats_fetch_retry_irq(&cpu_stats->syncp, start));
40178 ++ } while (u64_stats_fetch_retry(&cpu_stats->syncp, start));
40179 +
40180 + u64_stats_add(&stats->rx_packets, rx_packets);
40181 + u64_stats_add(&stats->rx_bytes, rx_bytes);
40182 +@@ -11358,8 +11361,10 @@ void devl_region_destroy(struct devlink_region *region)
40183 + devl_assert_locked(devlink);
40184 +
40185 + /* Free all snapshots of region */
40186 ++ mutex_lock(&region->snapshot_lock);
40187 + list_for_each_entry_safe(snapshot, ts, &region->snapshot_list, list)
40188 + devlink_region_snapshot_del(region, snapshot);
40189 ++ mutex_unlock(&region->snapshot_lock);
40190 +
40191 + list_del(&region->list);
40192 + mutex_destroy(&region->snapshot_lock);
40193 +diff --git a/net/core/drop_monitor.c b/net/core/drop_monitor.c
40194 +index 75501e1bdd25b..dfcaf61d972c7 100644
40195 +--- a/net/core/drop_monitor.c
40196 ++++ b/net/core/drop_monitor.c
40197 +@@ -1432,9 +1432,9 @@ static void net_dm_stats_read(struct net_dm_stats *stats)
40198 + u64 dropped;
40199 +
40200 + do {
40201 +- start = u64_stats_fetch_begin_irq(&cpu_stats->syncp);
40202 ++ start = u64_stats_fetch_begin(&cpu_stats->syncp);
40203 + dropped = u64_stats_read(&cpu_stats->dropped);
40204 +- } while (u64_stats_fetch_retry_irq(&cpu_stats->syncp, start));
40205 ++ } while (u64_stats_fetch_retry(&cpu_stats->syncp, start));
40206 +
40207 + u64_stats_add(&stats->dropped, dropped);
40208 + }
40209 +@@ -1476,9 +1476,9 @@ static void net_dm_hw_stats_read(struct net_dm_stats *stats)
40210 + u64 dropped;
40211 +
40212 + do {
40213 +- start = u64_stats_fetch_begin_irq(&cpu_stats->syncp);
40214 ++ start = u64_stats_fetch_begin(&cpu_stats->syncp);
40215 + dropped = u64_stats_read(&cpu_stats->dropped);
40216 +- } while (u64_stats_fetch_retry_irq(&cpu_stats->syncp, start));
40217 ++ } while (u64_stats_fetch_retry(&cpu_stats->syncp, start));
40218 +
40219 + u64_stats_add(&stats->dropped, dropped);
40220 + }
40221 +diff --git a/net/core/filter.c b/net/core/filter.c
40222 +index c191db80ce93c..3aae1885b9702 100644
40223 +--- a/net/core/filter.c
40224 ++++ b/net/core/filter.c
40225 +@@ -2123,8 +2123,17 @@ static int __bpf_redirect_no_mac(struct sk_buff *skb, struct net_device *dev,
40226 + {
40227 + unsigned int mlen = skb_network_offset(skb);
40228 +
40229 ++ if (unlikely(skb->len <= mlen)) {
40230 ++ kfree_skb(skb);
40231 ++ return -ERANGE;
40232 ++ }
40233 ++
40234 + if (mlen) {
40235 + __skb_pull(skb, mlen);
40236 ++ if (unlikely(!skb->len)) {
40237 ++ kfree_skb(skb);
40238 ++ return -ERANGE;
40239 ++ }
40240 +
40241 + /* At ingress, the mac header has already been pulled once.
40242 + * At egress, skb_pospull_rcsum has to be done in case that
40243 +@@ -2144,7 +2153,7 @@ static int __bpf_redirect_common(struct sk_buff *skb, struct net_device *dev,
40244 + u32 flags)
40245 + {
40246 + /* Verify that a link layer header is carried */
40247 +- if (unlikely(skb->mac_header >= skb->network_header)) {
40248 ++ if (unlikely(skb->mac_header >= skb->network_header || skb->len == 0)) {
40249 + kfree_skb(skb);
40250 + return -ERANGE;
40251 + }
40252 +diff --git a/net/core/gen_stats.c b/net/core/gen_stats.c
40253 +index c8d137ef5980e..b71ccaec09914 100644
40254 +--- a/net/core/gen_stats.c
40255 ++++ b/net/core/gen_stats.c
40256 +@@ -135,10 +135,10 @@ static void gnet_stats_add_basic_cpu(struct gnet_stats_basic_sync *bstats,
40257 + u64 bytes, packets;
40258 +
40259 + do {
40260 +- start = u64_stats_fetch_begin_irq(&bcpu->syncp);
40261 ++ start = u64_stats_fetch_begin(&bcpu->syncp);
40262 + bytes = u64_stats_read(&bcpu->bytes);
40263 + packets = u64_stats_read(&bcpu->packets);
40264 +- } while (u64_stats_fetch_retry_irq(&bcpu->syncp, start));
40265 ++ } while (u64_stats_fetch_retry(&bcpu->syncp, start));
40266 +
40267 + t_bytes += bytes;
40268 + t_packets += packets;
40269 +@@ -162,10 +162,10 @@ void gnet_stats_add_basic(struct gnet_stats_basic_sync *bstats,
40270 + }
40271 + do {
40272 + if (running)
40273 +- start = u64_stats_fetch_begin_irq(&b->syncp);
40274 ++ start = u64_stats_fetch_begin(&b->syncp);
40275 + bytes = u64_stats_read(&b->bytes);
40276 + packets = u64_stats_read(&b->packets);
40277 +- } while (running && u64_stats_fetch_retry_irq(&b->syncp, start));
40278 ++ } while (running && u64_stats_fetch_retry(&b->syncp, start));
40279 +
40280 + _bstats_update(bstats, bytes, packets);
40281 + }
40282 +@@ -187,10 +187,10 @@ static void gnet_stats_read_basic(u64 *ret_bytes, u64 *ret_packets,
40283 + u64 bytes, packets;
40284 +
40285 + do {
40286 +- start = u64_stats_fetch_begin_irq(&bcpu->syncp);
40287 ++ start = u64_stats_fetch_begin(&bcpu->syncp);
40288 + bytes = u64_stats_read(&bcpu->bytes);
40289 + packets = u64_stats_read(&bcpu->packets);
40290 +- } while (u64_stats_fetch_retry_irq(&bcpu->syncp, start));
40291 ++ } while (u64_stats_fetch_retry(&bcpu->syncp, start));
40292 +
40293 + t_bytes += bytes;
40294 + t_packets += packets;
40295 +@@ -201,10 +201,10 @@ static void gnet_stats_read_basic(u64 *ret_bytes, u64 *ret_packets,
40296 + }
40297 + do {
40298 + if (running)
40299 +- start = u64_stats_fetch_begin_irq(&b->syncp);
40300 ++ start = u64_stats_fetch_begin(&b->syncp);
40301 + *ret_bytes = u64_stats_read(&b->bytes);
40302 + *ret_packets = u64_stats_read(&b->packets);
40303 +- } while (running && u64_stats_fetch_retry_irq(&b->syncp, start));
40304 ++ } while (running && u64_stats_fetch_retry(&b->syncp, start));
40305 + }
40306 +
40307 + static int
40308 +diff --git a/net/core/skbuff.c b/net/core/skbuff.c
40309 +index d9c19ae05fe67..9460998ac6d1e 100644
40310 +--- a/net/core/skbuff.c
40311 ++++ b/net/core/skbuff.c
40312 +@@ -2313,6 +2313,9 @@ void *__pskb_pull_tail(struct sk_buff *skb, int delta)
40313 + insp = list;
40314 + } else {
40315 + /* Eaten partially. */
40316 ++ if (skb_is_gso(skb) && !list->head_frag &&
40317 ++ skb_headlen(list))
40318 ++ skb_shinfo(skb)->gso_type |= SKB_GSO_DODGY;
40319 +
40320 + if (skb_shared(list)) {
40321 + /* Sucks! We need to fork list. :-( */
40322 +diff --git a/net/core/skmsg.c b/net/core/skmsg.c
40323 +index e6b9ced3eda82..53d0251788aa2 100644
40324 +--- a/net/core/skmsg.c
40325 ++++ b/net/core/skmsg.c
40326 +@@ -886,13 +886,16 @@ int sk_psock_msg_verdict(struct sock *sk, struct sk_psock *psock,
40327 + ret = sk_psock_map_verd(ret, msg->sk_redir);
40328 + psock->apply_bytes = msg->apply_bytes;
40329 + if (ret == __SK_REDIRECT) {
40330 +- if (psock->sk_redir)
40331 ++ if (psock->sk_redir) {
40332 + sock_put(psock->sk_redir);
40333 +- psock->sk_redir = msg->sk_redir;
40334 +- if (!psock->sk_redir) {
40335 ++ psock->sk_redir = NULL;
40336 ++ }
40337 ++ if (!msg->sk_redir) {
40338 + ret = __SK_DROP;
40339 + goto out;
40340 + }
40341 ++ psock->redir_ingress = sk_msg_to_ingress(msg);
40342 ++ psock->sk_redir = msg->sk_redir;
40343 + sock_hold(psock->sk_redir);
40344 + }
40345 + out:
40346 +diff --git a/net/core/sock.c b/net/core/sock.c
40347 +index 788c1372663cb..f0eaa5d406b3f 100644
40348 +--- a/net/core/sock.c
40349 ++++ b/net/core/sock.c
40350 +@@ -1400,7 +1400,7 @@ set_sndbuf:
40351 + break;
40352 + }
40353 + case SO_INCOMING_CPU:
40354 +- WRITE_ONCE(sk->sk_incoming_cpu, val);
40355 ++ reuseport_update_incoming_cpu(sk, val);
40356 + break;
40357 +
40358 + case SO_CNX_ADVICE:
40359 +diff --git a/net/core/sock_map.c b/net/core/sock_map.c
40360 +index 632df0c525625..bfc3001032129 100644
40361 +--- a/net/core/sock_map.c
40362 ++++ b/net/core/sock_map.c
40363 +@@ -349,11 +349,13 @@ static void sock_map_free(struct bpf_map *map)
40364 +
40365 + sk = xchg(psk, NULL);
40366 + if (sk) {
40367 ++ sock_hold(sk);
40368 + lock_sock(sk);
40369 + rcu_read_lock();
40370 + sock_map_unref(sk, psk);
40371 + rcu_read_unlock();
40372 + release_sock(sk);
40373 ++ sock_put(sk);
40374 + }
40375 + }
40376 +
40377 +diff --git a/net/core/sock_reuseport.c b/net/core/sock_reuseport.c
40378 +index fb90e1e00773b..5a165286e4d8e 100644
40379 +--- a/net/core/sock_reuseport.c
40380 ++++ b/net/core/sock_reuseport.c
40381 +@@ -37,6 +37,70 @@ void reuseport_has_conns_set(struct sock *sk)
40382 + }
40383 + EXPORT_SYMBOL(reuseport_has_conns_set);
40384 +
40385 ++static void __reuseport_get_incoming_cpu(struct sock_reuseport *reuse)
40386 ++{
40387 ++ /* Paired with READ_ONCE() in reuseport_select_sock_by_hash(). */
40388 ++ WRITE_ONCE(reuse->incoming_cpu, reuse->incoming_cpu + 1);
40389 ++}
40390 ++
40391 ++static void __reuseport_put_incoming_cpu(struct sock_reuseport *reuse)
40392 ++{
40393 ++ /* Paired with READ_ONCE() in reuseport_select_sock_by_hash(). */
40394 ++ WRITE_ONCE(reuse->incoming_cpu, reuse->incoming_cpu - 1);
40395 ++}
40396 ++
40397 ++static void reuseport_get_incoming_cpu(struct sock *sk, struct sock_reuseport *reuse)
40398 ++{
40399 ++ if (sk->sk_incoming_cpu >= 0)
40400 ++ __reuseport_get_incoming_cpu(reuse);
40401 ++}
40402 ++
40403 ++static void reuseport_put_incoming_cpu(struct sock *sk, struct sock_reuseport *reuse)
40404 ++{
40405 ++ if (sk->sk_incoming_cpu >= 0)
40406 ++ __reuseport_put_incoming_cpu(reuse);
40407 ++}
40408 ++
40409 ++void reuseport_update_incoming_cpu(struct sock *sk, int val)
40410 ++{
40411 ++ struct sock_reuseport *reuse;
40412 ++ int old_sk_incoming_cpu;
40413 ++
40414 ++ if (unlikely(!rcu_access_pointer(sk->sk_reuseport_cb))) {
40415 ++ /* Paired with REAE_ONCE() in sk_incoming_cpu_update()
40416 ++ * and compute_score().
40417 ++ */
40418 ++ WRITE_ONCE(sk->sk_incoming_cpu, val);
40419 ++ return;
40420 ++ }
40421 ++
40422 ++ spin_lock_bh(&reuseport_lock);
40423 ++
40424 ++ /* This must be done under reuseport_lock to avoid a race with
40425 ++ * reuseport_grow(), which accesses sk->sk_incoming_cpu without
40426 ++ * lock_sock() when detaching a shutdown()ed sk.
40427 ++ *
40428 ++ * Paired with READ_ONCE() in reuseport_select_sock_by_hash().
40429 ++ */
40430 ++ old_sk_incoming_cpu = sk->sk_incoming_cpu;
40431 ++ WRITE_ONCE(sk->sk_incoming_cpu, val);
40432 ++
40433 ++ reuse = rcu_dereference_protected(sk->sk_reuseport_cb,
40434 ++ lockdep_is_held(&reuseport_lock));
40435 ++
40436 ++ /* reuseport_grow() has detached a closed sk. */
40437 ++ if (!reuse)
40438 ++ goto out;
40439 ++
40440 ++ if (old_sk_incoming_cpu < 0 && val >= 0)
40441 ++ __reuseport_get_incoming_cpu(reuse);
40442 ++ else if (old_sk_incoming_cpu >= 0 && val < 0)
40443 ++ __reuseport_put_incoming_cpu(reuse);
40444 ++
40445 ++out:
40446 ++ spin_unlock_bh(&reuseport_lock);
40447 ++}
40448 ++
40449 + static int reuseport_sock_index(struct sock *sk,
40450 + const struct sock_reuseport *reuse,
40451 + bool closed)
40452 +@@ -64,6 +128,7 @@ static void __reuseport_add_sock(struct sock *sk,
40453 + /* paired with smp_rmb() in reuseport_(select|migrate)_sock() */
40454 + smp_wmb();
40455 + reuse->num_socks++;
40456 ++ reuseport_get_incoming_cpu(sk, reuse);
40457 + }
40458 +
40459 + static bool __reuseport_detach_sock(struct sock *sk,
40460 +@@ -76,6 +141,7 @@ static bool __reuseport_detach_sock(struct sock *sk,
40461 +
40462 + reuse->socks[i] = reuse->socks[reuse->num_socks - 1];
40463 + reuse->num_socks--;
40464 ++ reuseport_put_incoming_cpu(sk, reuse);
40465 +
40466 + return true;
40467 + }
40468 +@@ -86,6 +152,7 @@ static void __reuseport_add_closed_sock(struct sock *sk,
40469 + reuse->socks[reuse->max_socks - reuse->num_closed_socks - 1] = sk;
40470 + /* paired with READ_ONCE() in inet_csk_bind_conflict() */
40471 + WRITE_ONCE(reuse->num_closed_socks, reuse->num_closed_socks + 1);
40472 ++ reuseport_get_incoming_cpu(sk, reuse);
40473 + }
40474 +
40475 + static bool __reuseport_detach_closed_sock(struct sock *sk,
40476 +@@ -99,6 +166,7 @@ static bool __reuseport_detach_closed_sock(struct sock *sk,
40477 + reuse->socks[i] = reuse->socks[reuse->max_socks - reuse->num_closed_socks];
40478 + /* paired with READ_ONCE() in inet_csk_bind_conflict() */
40479 + WRITE_ONCE(reuse->num_closed_socks, reuse->num_closed_socks - 1);
40480 ++ reuseport_put_incoming_cpu(sk, reuse);
40481 +
40482 + return true;
40483 + }
40484 +@@ -166,6 +234,7 @@ int reuseport_alloc(struct sock *sk, bool bind_inany)
40485 + reuse->bind_inany = bind_inany;
40486 + reuse->socks[0] = sk;
40487 + reuse->num_socks = 1;
40488 ++ reuseport_get_incoming_cpu(sk, reuse);
40489 + rcu_assign_pointer(sk->sk_reuseport_cb, reuse);
40490 +
40491 + out:
40492 +@@ -209,6 +278,7 @@ static struct sock_reuseport *reuseport_grow(struct sock_reuseport *reuse)
40493 + more_reuse->reuseport_id = reuse->reuseport_id;
40494 + more_reuse->bind_inany = reuse->bind_inany;
40495 + more_reuse->has_conns = reuse->has_conns;
40496 ++ more_reuse->incoming_cpu = reuse->incoming_cpu;
40497 +
40498 + memcpy(more_reuse->socks, reuse->socks,
40499 + reuse->num_socks * sizeof(struct sock *));
40500 +@@ -458,18 +528,32 @@ static struct sock *run_bpf_filter(struct sock_reuseport *reuse, u16 socks,
40501 + static struct sock *reuseport_select_sock_by_hash(struct sock_reuseport *reuse,
40502 + u32 hash, u16 num_socks)
40503 + {
40504 ++ struct sock *first_valid_sk = NULL;
40505 + int i, j;
40506 +
40507 + i = j = reciprocal_scale(hash, num_socks);
40508 +- while (reuse->socks[i]->sk_state == TCP_ESTABLISHED) {
40509 ++ do {
40510 ++ struct sock *sk = reuse->socks[i];
40511 ++
40512 ++ if (sk->sk_state != TCP_ESTABLISHED) {
40513 ++ /* Paired with WRITE_ONCE() in __reuseport_(get|put)_incoming_cpu(). */
40514 ++ if (!READ_ONCE(reuse->incoming_cpu))
40515 ++ return sk;
40516 ++
40517 ++ /* Paired with WRITE_ONCE() in reuseport_update_incoming_cpu(). */
40518 ++ if (READ_ONCE(sk->sk_incoming_cpu) == raw_smp_processor_id())
40519 ++ return sk;
40520 ++
40521 ++ if (!first_valid_sk)
40522 ++ first_valid_sk = sk;
40523 ++ }
40524 ++
40525 + i++;
40526 + if (i >= num_socks)
40527 + i = 0;
40528 +- if (i == j)
40529 +- return NULL;
40530 +- }
40531 ++ } while (i != j);
40532 +
40533 +- return reuse->socks[i];
40534 ++ return first_valid_sk;
40535 + }
40536 +
40537 + /**
40538 +diff --git a/net/core/stream.c b/net/core/stream.c
40539 +index 1105057ce00a5..2d03810841cbc 100644
40540 +--- a/net/core/stream.c
40541 ++++ b/net/core/stream.c
40542 +@@ -196,6 +196,12 @@ void sk_stream_kill_queues(struct sock *sk)
40543 + /* First the read buffer. */
40544 + __skb_queue_purge(&sk->sk_receive_queue);
40545 +
40546 ++ /* Next, the error queue.
40547 ++ * We need to use queue lock, because other threads might
40548 ++ * add packets to the queue without socket lock being held.
40549 ++ */
40550 ++ skb_queue_purge(&sk->sk_error_queue);
40551 ++
40552 + /* Next, the write queue. */
40553 + WARN_ON_ONCE(!skb_queue_empty(&sk->sk_write_queue));
40554 +
40555 +diff --git a/net/dsa/slave.c b/net/dsa/slave.c
40556 +index 1291c2431d440..dcc550b871623 100644
40557 +--- a/net/dsa/slave.c
40558 ++++ b/net/dsa/slave.c
40559 +@@ -934,12 +934,12 @@ static void dsa_slave_get_ethtool_stats(struct net_device *dev,
40560 +
40561 + s = per_cpu_ptr(dev->tstats, i);
40562 + do {
40563 +- start = u64_stats_fetch_begin_irq(&s->syncp);
40564 ++ start = u64_stats_fetch_begin(&s->syncp);
40565 + tx_packets = u64_stats_read(&s->tx_packets);
40566 + tx_bytes = u64_stats_read(&s->tx_bytes);
40567 + rx_packets = u64_stats_read(&s->rx_packets);
40568 + rx_bytes = u64_stats_read(&s->rx_bytes);
40569 +- } while (u64_stats_fetch_retry_irq(&s->syncp, start));
40570 ++ } while (u64_stats_fetch_retry(&s->syncp, start));
40571 + data[0] += tx_packets;
40572 + data[1] += tx_bytes;
40573 + data[2] += rx_packets;
40574 +diff --git a/net/dsa/tag_8021q.c b/net/dsa/tag_8021q.c
40575 +index 01a427800797c..6de53f5b40a7a 100644
40576 +--- a/net/dsa/tag_8021q.c
40577 ++++ b/net/dsa/tag_8021q.c
40578 +@@ -400,6 +400,7 @@ static void dsa_tag_8021q_teardown(struct dsa_switch *ds)
40579 + int dsa_tag_8021q_register(struct dsa_switch *ds, __be16 proto)
40580 + {
40581 + struct dsa_8021q_context *ctx;
40582 ++ int err;
40583 +
40584 + ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
40585 + if (!ctx)
40586 +@@ -412,7 +413,15 @@ int dsa_tag_8021q_register(struct dsa_switch *ds, __be16 proto)
40587 +
40588 + ds->tag_8021q_ctx = ctx;
40589 +
40590 +- return dsa_tag_8021q_setup(ds);
40591 ++ err = dsa_tag_8021q_setup(ds);
40592 ++ if (err)
40593 ++ goto err_free;
40594 ++
40595 ++ return 0;
40596 ++
40597 ++err_free:
40598 ++ kfree(ctx);
40599 ++ return err;
40600 + }
40601 + EXPORT_SYMBOL_GPL(dsa_tag_8021q_register);
40602 +
40603 +diff --git a/net/ethtool/ioctl.c b/net/ethtool/ioctl.c
40604 +index 6a7308de192d9..6b59e7a1c9063 100644
40605 +--- a/net/ethtool/ioctl.c
40606 ++++ b/net/ethtool/ioctl.c
40607 +@@ -2007,7 +2007,8 @@ static int ethtool_phys_id(struct net_device *dev, void __user *useraddr)
40608 + } else {
40609 + /* Driver expects to be called at twice the frequency in rc */
40610 + int n = rc * 2, interval = HZ / n;
40611 +- u64 count = n * id.data, i = 0;
40612 ++ u64 count = mul_u32_u32(n, id.data);
40613 ++ u64 i = 0;
40614 +
40615 + do {
40616 + rtnl_lock();
40617 +diff --git a/net/hsr/hsr_debugfs.c b/net/hsr/hsr_debugfs.c
40618 +index de476a4176314..1a195efc79cd1 100644
40619 +--- a/net/hsr/hsr_debugfs.c
40620 ++++ b/net/hsr/hsr_debugfs.c
40621 +@@ -9,7 +9,6 @@
40622 + #include <linux/module.h>
40623 + #include <linux/errno.h>
40624 + #include <linux/debugfs.h>
40625 +-#include <linux/jhash.h>
40626 + #include "hsr_main.h"
40627 + #include "hsr_framereg.h"
40628 +
40629 +@@ -21,7 +20,6 @@ hsr_node_table_show(struct seq_file *sfp, void *data)
40630 + {
40631 + struct hsr_priv *priv = (struct hsr_priv *)sfp->private;
40632 + struct hsr_node *node;
40633 +- int i;
40634 +
40635 + seq_printf(sfp, "Node Table entries for (%s) device\n",
40636 + (priv->prot_version == PRP_V1 ? "PRP" : "HSR"));
40637 +@@ -33,28 +31,22 @@ hsr_node_table_show(struct seq_file *sfp, void *data)
40638 + seq_puts(sfp, "DAN-H\n");
40639 +
40640 + rcu_read_lock();
40641 +-
40642 +- for (i = 0 ; i < priv->hash_buckets; i++) {
40643 +- hlist_for_each_entry_rcu(node, &priv->node_db[i], mac_list) {
40644 +- /* skip self node */
40645 +- if (hsr_addr_is_self(priv, node->macaddress_A))
40646 +- continue;
40647 +- seq_printf(sfp, "%pM ", &node->macaddress_A[0]);
40648 +- seq_printf(sfp, "%pM ", &node->macaddress_B[0]);
40649 +- seq_printf(sfp, "%10lx, ",
40650 +- node->time_in[HSR_PT_SLAVE_A]);
40651 +- seq_printf(sfp, "%10lx, ",
40652 +- node->time_in[HSR_PT_SLAVE_B]);
40653 +- seq_printf(sfp, "%14x, ", node->addr_B_port);
40654 +-
40655 +- if (priv->prot_version == PRP_V1)
40656 +- seq_printf(sfp, "%5x, %5x, %5x\n",
40657 +- node->san_a, node->san_b,
40658 +- (node->san_a == 0 &&
40659 +- node->san_b == 0));
40660 +- else
40661 +- seq_printf(sfp, "%5x\n", 1);
40662 +- }
40663 ++ list_for_each_entry_rcu(node, &priv->node_db, mac_list) {
40664 ++ /* skip self node */
40665 ++ if (hsr_addr_is_self(priv, node->macaddress_A))
40666 ++ continue;
40667 ++ seq_printf(sfp, "%pM ", &node->macaddress_A[0]);
40668 ++ seq_printf(sfp, "%pM ", &node->macaddress_B[0]);
40669 ++ seq_printf(sfp, "%10lx, ", node->time_in[HSR_PT_SLAVE_A]);
40670 ++ seq_printf(sfp, "%10lx, ", node->time_in[HSR_PT_SLAVE_B]);
40671 ++ seq_printf(sfp, "%14x, ", node->addr_B_port);
40672 ++
40673 ++ if (priv->prot_version == PRP_V1)
40674 ++ seq_printf(sfp, "%5x, %5x, %5x\n",
40675 ++ node->san_a, node->san_b,
40676 ++ (node->san_a == 0 && node->san_b == 0));
40677 ++ else
40678 ++ seq_printf(sfp, "%5x\n", 1);
40679 + }
40680 + rcu_read_unlock();
40681 + return 0;
40682 +diff --git a/net/hsr/hsr_device.c b/net/hsr/hsr_device.c
40683 +index 6ffef47e9be55..b1e86a7265b32 100644
40684 +--- a/net/hsr/hsr_device.c
40685 ++++ b/net/hsr/hsr_device.c
40686 +@@ -219,7 +219,9 @@ static netdev_tx_t hsr_dev_xmit(struct sk_buff *skb, struct net_device *dev)
40687 + skb->dev = master->dev;
40688 + skb_reset_mac_header(skb);
40689 + skb_reset_mac_len(skb);
40690 ++ spin_lock_bh(&hsr->seqnr_lock);
40691 + hsr_forward_skb(skb, master);
40692 ++ spin_unlock_bh(&hsr->seqnr_lock);
40693 + } else {
40694 + dev_core_stats_tx_dropped_inc(dev);
40695 + dev_kfree_skb_any(skb);
40696 +@@ -278,7 +280,6 @@ static void send_hsr_supervision_frame(struct hsr_port *master,
40697 + __u8 type = HSR_TLV_LIFE_CHECK;
40698 + struct hsr_sup_payload *hsr_sp;
40699 + struct hsr_sup_tag *hsr_stag;
40700 +- unsigned long irqflags;
40701 + struct sk_buff *skb;
40702 +
40703 + *interval = msecs_to_jiffies(HSR_LIFE_CHECK_INTERVAL);
40704 +@@ -299,7 +300,7 @@ static void send_hsr_supervision_frame(struct hsr_port *master,
40705 + set_hsr_stag_HSR_ver(hsr_stag, hsr->prot_version);
40706 +
40707 + /* From HSRv1 on we have separate supervision sequence numbers. */
40708 +- spin_lock_irqsave(&master->hsr->seqnr_lock, irqflags);
40709 ++ spin_lock_bh(&hsr->seqnr_lock);
40710 + if (hsr->prot_version > 0) {
40711 + hsr_stag->sequence_nr = htons(hsr->sup_sequence_nr);
40712 + hsr->sup_sequence_nr++;
40713 +@@ -307,7 +308,6 @@ static void send_hsr_supervision_frame(struct hsr_port *master,
40714 + hsr_stag->sequence_nr = htons(hsr->sequence_nr);
40715 + hsr->sequence_nr++;
40716 + }
40717 +- spin_unlock_irqrestore(&master->hsr->seqnr_lock, irqflags);
40718 +
40719 + hsr_stag->tlv.HSR_TLV_type = type;
40720 + /* TODO: Why 12 in HSRv0? */
40721 +@@ -318,11 +318,13 @@ static void send_hsr_supervision_frame(struct hsr_port *master,
40722 + hsr_sp = skb_put(skb, sizeof(struct hsr_sup_payload));
40723 + ether_addr_copy(hsr_sp->macaddress_A, master->dev->dev_addr);
40724 +
40725 +- if (skb_put_padto(skb, ETH_ZLEN))
40726 ++ if (skb_put_padto(skb, ETH_ZLEN)) {
40727 ++ spin_unlock_bh(&hsr->seqnr_lock);
40728 + return;
40729 ++ }
40730 +
40731 + hsr_forward_skb(skb, master);
40732 +-
40733 ++ spin_unlock_bh(&hsr->seqnr_lock);
40734 + return;
40735 + }
40736 +
40737 +@@ -332,7 +334,6 @@ static void send_prp_supervision_frame(struct hsr_port *master,
40738 + struct hsr_priv *hsr = master->hsr;
40739 + struct hsr_sup_payload *hsr_sp;
40740 + struct hsr_sup_tag *hsr_stag;
40741 +- unsigned long irqflags;
40742 + struct sk_buff *skb;
40743 +
40744 + skb = hsr_init_skb(master);
40745 +@@ -347,7 +348,7 @@ static void send_prp_supervision_frame(struct hsr_port *master,
40746 + set_hsr_stag_HSR_ver(hsr_stag, (hsr->prot_version ? 1 : 0));
40747 +
40748 + /* From HSRv1 on we have separate supervision sequence numbers. */
40749 +- spin_lock_irqsave(&master->hsr->seqnr_lock, irqflags);
40750 ++ spin_lock_bh(&hsr->seqnr_lock);
40751 + hsr_stag->sequence_nr = htons(hsr->sup_sequence_nr);
40752 + hsr->sup_sequence_nr++;
40753 + hsr_stag->tlv.HSR_TLV_type = PRP_TLV_LIFE_CHECK_DD;
40754 +@@ -358,13 +359,12 @@ static void send_prp_supervision_frame(struct hsr_port *master,
40755 + ether_addr_copy(hsr_sp->macaddress_A, master->dev->dev_addr);
40756 +
40757 + if (skb_put_padto(skb, ETH_ZLEN)) {
40758 +- spin_unlock_irqrestore(&master->hsr->seqnr_lock, irqflags);
40759 ++ spin_unlock_bh(&hsr->seqnr_lock);
40760 + return;
40761 + }
40762 +
40763 +- spin_unlock_irqrestore(&master->hsr->seqnr_lock, irqflags);
40764 +-
40765 + hsr_forward_skb(skb, master);
40766 ++ spin_unlock_bh(&hsr->seqnr_lock);
40767 + }
40768 +
40769 + /* Announce (supervision frame) timer function
40770 +@@ -444,7 +444,7 @@ void hsr_dev_setup(struct net_device *dev)
40771 + dev->header_ops = &hsr_header_ops;
40772 + dev->netdev_ops = &hsr_device_ops;
40773 + SET_NETDEV_DEVTYPE(dev, &hsr_type);
40774 +- dev->priv_flags |= IFF_NO_QUEUE;
40775 ++ dev->priv_flags |= IFF_NO_QUEUE | IFF_DISABLE_NETPOLL;
40776 +
40777 + dev->needs_free_netdev = true;
40778 +
40779 +@@ -485,16 +485,12 @@ int hsr_dev_finalize(struct net_device *hsr_dev, struct net_device *slave[2],
40780 + {
40781 + bool unregister = false;
40782 + struct hsr_priv *hsr;
40783 +- int res, i;
40784 ++ int res;
40785 +
40786 + hsr = netdev_priv(hsr_dev);
40787 + INIT_LIST_HEAD(&hsr->ports);
40788 +- INIT_HLIST_HEAD(&hsr->self_node_db);
40789 +- hsr->hash_buckets = HSR_HSIZE;
40790 +- get_random_bytes(&hsr->hash_seed, sizeof(hsr->hash_seed));
40791 +- for (i = 0; i < hsr->hash_buckets; i++)
40792 +- INIT_HLIST_HEAD(&hsr->node_db[i]);
40793 +-
40794 ++ INIT_LIST_HEAD(&hsr->node_db);
40795 ++ INIT_LIST_HEAD(&hsr->self_node_db);
40796 + spin_lock_init(&hsr->list_lock);
40797 +
40798 + eth_hw_addr_set(hsr_dev, slave[0]->dev_addr);
40799 +diff --git a/net/hsr/hsr_forward.c b/net/hsr/hsr_forward.c
40800 +index 56bb27d67a2ee..629daacc96071 100644
40801 +--- a/net/hsr/hsr_forward.c
40802 ++++ b/net/hsr/hsr_forward.c
40803 +@@ -500,7 +500,6 @@ static void handle_std_frame(struct sk_buff *skb,
40804 + {
40805 + struct hsr_port *port = frame->port_rcv;
40806 + struct hsr_priv *hsr = port->hsr;
40807 +- unsigned long irqflags;
40808 +
40809 + frame->skb_hsr = NULL;
40810 + frame->skb_prp = NULL;
40811 +@@ -510,10 +509,9 @@ static void handle_std_frame(struct sk_buff *skb,
40812 + frame->is_from_san = true;
40813 + } else {
40814 + /* Sequence nr for the master node */
40815 +- spin_lock_irqsave(&hsr->seqnr_lock, irqflags);
40816 ++ lockdep_assert_held(&hsr->seqnr_lock);
40817 + frame->sequence_nr = hsr->sequence_nr;
40818 + hsr->sequence_nr++;
40819 +- spin_unlock_irqrestore(&hsr->seqnr_lock, irqflags);
40820 + }
40821 + }
40822 +
40823 +@@ -571,23 +569,20 @@ static int fill_frame_info(struct hsr_frame_info *frame,
40824 + struct ethhdr *ethhdr;
40825 + __be16 proto;
40826 + int ret;
40827 +- u32 hash;
40828 +
40829 + /* Check if skb contains ethhdr */
40830 + if (skb->mac_len < sizeof(struct ethhdr))
40831 + return -EINVAL;
40832 +
40833 + memset(frame, 0, sizeof(*frame));
40834 +-
40835 +- ethhdr = (struct ethhdr *)skb_mac_header(skb);
40836 +- hash = hsr_mac_hash(port->hsr, ethhdr->h_source);
40837 + frame->is_supervision = is_supervision_frame(port->hsr, skb);
40838 +- frame->node_src = hsr_get_node(port, &hsr->node_db[hash], skb,
40839 ++ frame->node_src = hsr_get_node(port, &hsr->node_db, skb,
40840 + frame->is_supervision,
40841 + port->type);
40842 + if (!frame->node_src)
40843 + return -1; /* Unknown node and !is_supervision, or no mem */
40844 +
40845 ++ ethhdr = (struct ethhdr *)skb_mac_header(skb);
40846 + frame->is_vlan = false;
40847 + proto = ethhdr->h_proto;
40848 +
40849 +@@ -617,11 +612,13 @@ void hsr_forward_skb(struct sk_buff *skb, struct hsr_port *port)
40850 + {
40851 + struct hsr_frame_info frame;
40852 +
40853 ++ rcu_read_lock();
40854 + if (fill_frame_info(&frame, skb, port) < 0)
40855 + goto out_drop;
40856 +
40857 + hsr_register_frame_in(frame.node_src, port, frame.sequence_nr);
40858 + hsr_forward_do(&frame);
40859 ++ rcu_read_unlock();
40860 + /* Gets called for ingress frames as well as egress from master port.
40861 + * So check and increment stats for master port only here.
40862 + */
40863 +@@ -636,6 +633,7 @@ void hsr_forward_skb(struct sk_buff *skb, struct hsr_port *port)
40864 + return;
40865 +
40866 + out_drop:
40867 ++ rcu_read_unlock();
40868 + port->dev->stats.tx_dropped++;
40869 + kfree_skb(skb);
40870 + }
40871 +diff --git a/net/hsr/hsr_framereg.c b/net/hsr/hsr_framereg.c
40872 +index 584e217887997..39a6088080e93 100644
40873 +--- a/net/hsr/hsr_framereg.c
40874 ++++ b/net/hsr/hsr_framereg.c
40875 +@@ -15,37 +15,10 @@
40876 + #include <linux/etherdevice.h>
40877 + #include <linux/slab.h>
40878 + #include <linux/rculist.h>
40879 +-#include <linux/jhash.h>
40880 + #include "hsr_main.h"
40881 + #include "hsr_framereg.h"
40882 + #include "hsr_netlink.h"
40883 +
40884 +-#ifdef CONFIG_LOCKDEP
40885 +-int lockdep_hsr_is_held(spinlock_t *lock)
40886 +-{
40887 +- return lockdep_is_held(lock);
40888 +-}
40889 +-#endif
40890 +-
40891 +-u32 hsr_mac_hash(struct hsr_priv *hsr, const unsigned char *addr)
40892 +-{
40893 +- u32 hash = jhash(addr, ETH_ALEN, hsr->hash_seed);
40894 +-
40895 +- return reciprocal_scale(hash, hsr->hash_buckets);
40896 +-}
40897 +-
40898 +-struct hsr_node *hsr_node_get_first(struct hlist_head *head, spinlock_t *lock)
40899 +-{
40900 +- struct hlist_node *first;
40901 +-
40902 +- first = rcu_dereference_bh_check(hlist_first_rcu(head),
40903 +- lockdep_hsr_is_held(lock));
40904 +- if (first)
40905 +- return hlist_entry(first, struct hsr_node, mac_list);
40906 +-
40907 +- return NULL;
40908 +-}
40909 +-
40910 + /* seq_nr_after(a, b) - return true if a is after (higher in sequence than) b,
40911 + * false otherwise.
40912 + */
40913 +@@ -67,7 +40,8 @@ bool hsr_addr_is_self(struct hsr_priv *hsr, unsigned char *addr)
40914 + {
40915 + struct hsr_node *node;
40916 +
40917 +- node = hsr_node_get_first(&hsr->self_node_db, &hsr->list_lock);
40918 ++ node = list_first_or_null_rcu(&hsr->self_node_db, struct hsr_node,
40919 ++ mac_list);
40920 + if (!node) {
40921 + WARN_ONCE(1, "HSR: No self node\n");
40922 + return false;
40923 +@@ -83,12 +57,12 @@ bool hsr_addr_is_self(struct hsr_priv *hsr, unsigned char *addr)
40924 +
40925 + /* Search for mac entry. Caller must hold rcu read lock.
40926 + */
40927 +-static struct hsr_node *find_node_by_addr_A(struct hlist_head *node_db,
40928 ++static struct hsr_node *find_node_by_addr_A(struct list_head *node_db,
40929 + const unsigned char addr[ETH_ALEN])
40930 + {
40931 + struct hsr_node *node;
40932 +
40933 +- hlist_for_each_entry_rcu(node, node_db, mac_list) {
40934 ++ list_for_each_entry_rcu(node, node_db, mac_list) {
40935 + if (ether_addr_equal(node->macaddress_A, addr))
40936 + return node;
40937 + }
40938 +@@ -103,7 +77,7 @@ int hsr_create_self_node(struct hsr_priv *hsr,
40939 + const unsigned char addr_a[ETH_ALEN],
40940 + const unsigned char addr_b[ETH_ALEN])
40941 + {
40942 +- struct hlist_head *self_node_db = &hsr->self_node_db;
40943 ++ struct list_head *self_node_db = &hsr->self_node_db;
40944 + struct hsr_node *node, *oldnode;
40945 +
40946 + node = kmalloc(sizeof(*node), GFP_KERNEL);
40947 +@@ -114,13 +88,14 @@ int hsr_create_self_node(struct hsr_priv *hsr,
40948 + ether_addr_copy(node->macaddress_B, addr_b);
40949 +
40950 + spin_lock_bh(&hsr->list_lock);
40951 +- oldnode = hsr_node_get_first(self_node_db, &hsr->list_lock);
40952 ++ oldnode = list_first_or_null_rcu(self_node_db,
40953 ++ struct hsr_node, mac_list);
40954 + if (oldnode) {
40955 +- hlist_replace_rcu(&oldnode->mac_list, &node->mac_list);
40956 ++ list_replace_rcu(&oldnode->mac_list, &node->mac_list);
40957 + spin_unlock_bh(&hsr->list_lock);
40958 + kfree_rcu(oldnode, rcu_head);
40959 + } else {
40960 +- hlist_add_tail_rcu(&node->mac_list, self_node_db);
40961 ++ list_add_tail_rcu(&node->mac_list, self_node_db);
40962 + spin_unlock_bh(&hsr->list_lock);
40963 + }
40964 +
40965 +@@ -129,25 +104,25 @@ int hsr_create_self_node(struct hsr_priv *hsr,
40966 +
40967 + void hsr_del_self_node(struct hsr_priv *hsr)
40968 + {
40969 +- struct hlist_head *self_node_db = &hsr->self_node_db;
40970 ++ struct list_head *self_node_db = &hsr->self_node_db;
40971 + struct hsr_node *node;
40972 +
40973 + spin_lock_bh(&hsr->list_lock);
40974 +- node = hsr_node_get_first(self_node_db, &hsr->list_lock);
40975 ++ node = list_first_or_null_rcu(self_node_db, struct hsr_node, mac_list);
40976 + if (node) {
40977 +- hlist_del_rcu(&node->mac_list);
40978 ++ list_del_rcu(&node->mac_list);
40979 + kfree_rcu(node, rcu_head);
40980 + }
40981 + spin_unlock_bh(&hsr->list_lock);
40982 + }
40983 +
40984 +-void hsr_del_nodes(struct hlist_head *node_db)
40985 ++void hsr_del_nodes(struct list_head *node_db)
40986 + {
40987 + struct hsr_node *node;
40988 +- struct hlist_node *tmp;
40989 ++ struct hsr_node *tmp;
40990 +
40991 +- hlist_for_each_entry_safe(node, tmp, node_db, mac_list)
40992 +- kfree_rcu(node, rcu_head);
40993 ++ list_for_each_entry_safe(node, tmp, node_db, mac_list)
40994 ++ kfree(node);
40995 + }
40996 +
40997 + void prp_handle_san_frame(bool san, enum hsr_port_type port,
40998 +@@ -168,7 +143,7 @@ void prp_handle_san_frame(bool san, enum hsr_port_type port,
40999 + * originating from the newly added node.
41000 + */
41001 + static struct hsr_node *hsr_add_node(struct hsr_priv *hsr,
41002 +- struct hlist_head *node_db,
41003 ++ struct list_head *node_db,
41004 + unsigned char addr[],
41005 + u16 seq_out, bool san,
41006 + enum hsr_port_type rx_port)
41007 +@@ -182,6 +157,7 @@ static struct hsr_node *hsr_add_node(struct hsr_priv *hsr,
41008 + return NULL;
41009 +
41010 + ether_addr_copy(new_node->macaddress_A, addr);
41011 ++ spin_lock_init(&new_node->seq_out_lock);
41012 +
41013 + /* We are only interested in time diffs here, so use current jiffies
41014 + * as initialization. (0 could trigger an spurious ring error warning).
41015 +@@ -198,14 +174,14 @@ static struct hsr_node *hsr_add_node(struct hsr_priv *hsr,
41016 + hsr->proto_ops->handle_san_frame(san, rx_port, new_node);
41017 +
41018 + spin_lock_bh(&hsr->list_lock);
41019 +- hlist_for_each_entry_rcu(node, node_db, mac_list,
41020 +- lockdep_hsr_is_held(&hsr->list_lock)) {
41021 ++ list_for_each_entry_rcu(node, node_db, mac_list,
41022 ++ lockdep_is_held(&hsr->list_lock)) {
41023 + if (ether_addr_equal(node->macaddress_A, addr))
41024 + goto out;
41025 + if (ether_addr_equal(node->macaddress_B, addr))
41026 + goto out;
41027 + }
41028 +- hlist_add_tail_rcu(&new_node->mac_list, node_db);
41029 ++ list_add_tail_rcu(&new_node->mac_list, node_db);
41030 + spin_unlock_bh(&hsr->list_lock);
41031 + return new_node;
41032 + out:
41033 +@@ -225,7 +201,7 @@ void prp_update_san_info(struct hsr_node *node, bool is_sup)
41034 +
41035 + /* Get the hsr_node from which 'skb' was sent.
41036 + */
41037 +-struct hsr_node *hsr_get_node(struct hsr_port *port, struct hlist_head *node_db,
41038 ++struct hsr_node *hsr_get_node(struct hsr_port *port, struct list_head *node_db,
41039 + struct sk_buff *skb, bool is_sup,
41040 + enum hsr_port_type rx_port)
41041 + {
41042 +@@ -241,7 +217,7 @@ struct hsr_node *hsr_get_node(struct hsr_port *port, struct hlist_head *node_db,
41043 +
41044 + ethhdr = (struct ethhdr *)skb_mac_header(skb);
41045 +
41046 +- hlist_for_each_entry_rcu(node, node_db, mac_list) {
41047 ++ list_for_each_entry_rcu(node, node_db, mac_list) {
41048 + if (ether_addr_equal(node->macaddress_A, ethhdr->h_source)) {
41049 + if (hsr->proto_ops->update_san_info)
41050 + hsr->proto_ops->update_san_info(node, is_sup);
41051 +@@ -291,12 +267,11 @@ void hsr_handle_sup_frame(struct hsr_frame_info *frame)
41052 + struct hsr_sup_tlv *hsr_sup_tlv;
41053 + struct hsr_node *node_real;
41054 + struct sk_buff *skb = NULL;
41055 +- struct hlist_head *node_db;
41056 ++ struct list_head *node_db;
41057 + struct ethhdr *ethhdr;
41058 + int i;
41059 + unsigned int pull_size = 0;
41060 + unsigned int total_pull_size = 0;
41061 +- u32 hash;
41062 +
41063 + /* Here either frame->skb_hsr or frame->skb_prp should be
41064 + * valid as supervision frame always will have protocol
41065 +@@ -334,13 +309,11 @@ void hsr_handle_sup_frame(struct hsr_frame_info *frame)
41066 + hsr_sp = (struct hsr_sup_payload *)skb->data;
41067 +
41068 + /* Merge node_curr (registered on macaddress_B) into node_real */
41069 +- node_db = port_rcv->hsr->node_db;
41070 +- hash = hsr_mac_hash(hsr, hsr_sp->macaddress_A);
41071 +- node_real = find_node_by_addr_A(&node_db[hash], hsr_sp->macaddress_A);
41072 ++ node_db = &port_rcv->hsr->node_db;
41073 ++ node_real = find_node_by_addr_A(node_db, hsr_sp->macaddress_A);
41074 + if (!node_real)
41075 + /* No frame received from AddrA of this node yet */
41076 +- node_real = hsr_add_node(hsr, &node_db[hash],
41077 +- hsr_sp->macaddress_A,
41078 ++ node_real = hsr_add_node(hsr, node_db, hsr_sp->macaddress_A,
41079 + HSR_SEQNR_START - 1, true,
41080 + port_rcv->type);
41081 + if (!node_real)
41082 +@@ -374,14 +347,14 @@ void hsr_handle_sup_frame(struct hsr_frame_info *frame)
41083 + hsr_sp = (struct hsr_sup_payload *)skb->data;
41084 +
41085 + /* Check if redbox mac and node mac are equal. */
41086 +- if (!ether_addr_equal(node_real->macaddress_A,
41087 +- hsr_sp->macaddress_A)) {
41088 ++ if (!ether_addr_equal(node_real->macaddress_A, hsr_sp->macaddress_A)) {
41089 + /* This is a redbox supervision frame for a VDAN! */
41090 + goto done;
41091 + }
41092 + }
41093 +
41094 + ether_addr_copy(node_real->macaddress_B, ethhdr->h_source);
41095 ++ spin_lock_bh(&node_real->seq_out_lock);
41096 + for (i = 0; i < HSR_PT_PORTS; i++) {
41097 + if (!node_curr->time_in_stale[i] &&
41098 + time_after(node_curr->time_in[i], node_real->time_in[i])) {
41099 +@@ -392,12 +365,16 @@ void hsr_handle_sup_frame(struct hsr_frame_info *frame)
41100 + if (seq_nr_after(node_curr->seq_out[i], node_real->seq_out[i]))
41101 + node_real->seq_out[i] = node_curr->seq_out[i];
41102 + }
41103 ++ spin_unlock_bh(&node_real->seq_out_lock);
41104 + node_real->addr_B_port = port_rcv->type;
41105 +
41106 + spin_lock_bh(&hsr->list_lock);
41107 +- hlist_del_rcu(&node_curr->mac_list);
41108 ++ if (!node_curr->removed) {
41109 ++ list_del_rcu(&node_curr->mac_list);
41110 ++ node_curr->removed = true;
41111 ++ kfree_rcu(node_curr, rcu_head);
41112 ++ }
41113 + spin_unlock_bh(&hsr->list_lock);
41114 +- kfree_rcu(node_curr, rcu_head);
41115 +
41116 + done:
41117 + /* Push back here */
41118 +@@ -433,7 +410,6 @@ void hsr_addr_subst_dest(struct hsr_node *node_src, struct sk_buff *skb,
41119 + struct hsr_port *port)
41120 + {
41121 + struct hsr_node *node_dst;
41122 +- u32 hash;
41123 +
41124 + if (!skb_mac_header_was_set(skb)) {
41125 + WARN_ONCE(1, "%s: Mac header not set\n", __func__);
41126 +@@ -443,8 +419,7 @@ void hsr_addr_subst_dest(struct hsr_node *node_src, struct sk_buff *skb,
41127 + if (!is_unicast_ether_addr(eth_hdr(skb)->h_dest))
41128 + return;
41129 +
41130 +- hash = hsr_mac_hash(port->hsr, eth_hdr(skb)->h_dest);
41131 +- node_dst = find_node_by_addr_A(&port->hsr->node_db[hash],
41132 ++ node_dst = find_node_by_addr_A(&port->hsr->node_db,
41133 + eth_hdr(skb)->h_dest);
41134 + if (!node_dst) {
41135 + if (net_ratelimit())
41136 +@@ -484,13 +459,17 @@ void hsr_register_frame_in(struct hsr_node *node, struct hsr_port *port,
41137 + int hsr_register_frame_out(struct hsr_port *port, struct hsr_node *node,
41138 + u16 sequence_nr)
41139 + {
41140 ++ spin_lock_bh(&node->seq_out_lock);
41141 + if (seq_nr_before_or_eq(sequence_nr, node->seq_out[port->type]) &&
41142 + time_is_after_jiffies(node->time_out[port->type] +
41143 +- msecs_to_jiffies(HSR_ENTRY_FORGET_TIME)))
41144 ++ msecs_to_jiffies(HSR_ENTRY_FORGET_TIME))) {
41145 ++ spin_unlock_bh(&node->seq_out_lock);
41146 + return 1;
41147 ++ }
41148 +
41149 + node->time_out[port->type] = jiffies;
41150 + node->seq_out[port->type] = sequence_nr;
41151 ++ spin_unlock_bh(&node->seq_out_lock);
41152 + return 0;
41153 + }
41154 +
41155 +@@ -520,71 +499,60 @@ static struct hsr_port *get_late_port(struct hsr_priv *hsr,
41156 + void hsr_prune_nodes(struct timer_list *t)
41157 + {
41158 + struct hsr_priv *hsr = from_timer(hsr, t, prune_timer);
41159 +- struct hlist_node *tmp;
41160 + struct hsr_node *node;
41161 ++ struct hsr_node *tmp;
41162 + struct hsr_port *port;
41163 + unsigned long timestamp;
41164 + unsigned long time_a, time_b;
41165 +- int i;
41166 +
41167 + spin_lock_bh(&hsr->list_lock);
41168 ++ list_for_each_entry_safe(node, tmp, &hsr->node_db, mac_list) {
41169 ++ /* Don't prune own node. Neither time_in[HSR_PT_SLAVE_A]
41170 ++ * nor time_in[HSR_PT_SLAVE_B], will ever be updated for
41171 ++ * the master port. Thus the master node will be repeatedly
41172 ++ * pruned leading to packet loss.
41173 ++ */
41174 ++ if (hsr_addr_is_self(hsr, node->macaddress_A))
41175 ++ continue;
41176 ++
41177 ++ /* Shorthand */
41178 ++ time_a = node->time_in[HSR_PT_SLAVE_A];
41179 ++ time_b = node->time_in[HSR_PT_SLAVE_B];
41180 ++
41181 ++ /* Check for timestamps old enough to risk wrap-around */
41182 ++ if (time_after(jiffies, time_a + MAX_JIFFY_OFFSET / 2))
41183 ++ node->time_in_stale[HSR_PT_SLAVE_A] = true;
41184 ++ if (time_after(jiffies, time_b + MAX_JIFFY_OFFSET / 2))
41185 ++ node->time_in_stale[HSR_PT_SLAVE_B] = true;
41186 ++
41187 ++ /* Get age of newest frame from node.
41188 ++ * At least one time_in is OK here; nodes get pruned long
41189 ++ * before both time_ins can get stale
41190 ++ */
41191 ++ timestamp = time_a;
41192 ++ if (node->time_in_stale[HSR_PT_SLAVE_A] ||
41193 ++ (!node->time_in_stale[HSR_PT_SLAVE_B] &&
41194 ++ time_after(time_b, time_a)))
41195 ++ timestamp = time_b;
41196 ++
41197 ++ /* Warn of ring error only as long as we get frames at all */
41198 ++ if (time_is_after_jiffies(timestamp +
41199 ++ msecs_to_jiffies(1.5 * MAX_SLAVE_DIFF))) {
41200 ++ rcu_read_lock();
41201 ++ port = get_late_port(hsr, node);
41202 ++ if (port)
41203 ++ hsr_nl_ringerror(hsr, node->macaddress_A, port);
41204 ++ rcu_read_unlock();
41205 ++ }
41206 +
41207 +- for (i = 0; i < hsr->hash_buckets; i++) {
41208 +- hlist_for_each_entry_safe(node, tmp, &hsr->node_db[i],
41209 +- mac_list) {
41210 +- /* Don't prune own node.
41211 +- * Neither time_in[HSR_PT_SLAVE_A]
41212 +- * nor time_in[HSR_PT_SLAVE_B], will ever be updated
41213 +- * for the master port. Thus the master node will be
41214 +- * repeatedly pruned leading to packet loss.
41215 +- */
41216 +- if (hsr_addr_is_self(hsr, node->macaddress_A))
41217 +- continue;
41218 +-
41219 +- /* Shorthand */
41220 +- time_a = node->time_in[HSR_PT_SLAVE_A];
41221 +- time_b = node->time_in[HSR_PT_SLAVE_B];
41222 +-
41223 +- /* Check for timestamps old enough to
41224 +- * risk wrap-around
41225 +- */
41226 +- if (time_after(jiffies, time_a + MAX_JIFFY_OFFSET / 2))
41227 +- node->time_in_stale[HSR_PT_SLAVE_A] = true;
41228 +- if (time_after(jiffies, time_b + MAX_JIFFY_OFFSET / 2))
41229 +- node->time_in_stale[HSR_PT_SLAVE_B] = true;
41230 +-
41231 +- /* Get age of newest frame from node.
41232 +- * At least one time_in is OK here; nodes get pruned
41233 +- * long before both time_ins can get stale
41234 +- */
41235 +- timestamp = time_a;
41236 +- if (node->time_in_stale[HSR_PT_SLAVE_A] ||
41237 +- (!node->time_in_stale[HSR_PT_SLAVE_B] &&
41238 +- time_after(time_b, time_a)))
41239 +- timestamp = time_b;
41240 +-
41241 +- /* Warn of ring error only as long as we get
41242 +- * frames at all
41243 +- */
41244 +- if (time_is_after_jiffies(timestamp +
41245 +- msecs_to_jiffies(1.5 * MAX_SLAVE_DIFF))) {
41246 +- rcu_read_lock();
41247 +- port = get_late_port(hsr, node);
41248 +- if (port)
41249 +- hsr_nl_ringerror(hsr,
41250 +- node->macaddress_A,
41251 +- port);
41252 +- rcu_read_unlock();
41253 +- }
41254 +-
41255 +- /* Prune old entries */
41256 +- if (time_is_before_jiffies(timestamp +
41257 +- msecs_to_jiffies(HSR_NODE_FORGET_TIME))) {
41258 +- hsr_nl_nodedown(hsr, node->macaddress_A);
41259 +- hlist_del_rcu(&node->mac_list);
41260 +- /* Note that we need to free this
41261 +- * entry later:
41262 +- */
41263 ++ /* Prune old entries */
41264 ++ if (time_is_before_jiffies(timestamp +
41265 ++ msecs_to_jiffies(HSR_NODE_FORGET_TIME))) {
41266 ++ hsr_nl_nodedown(hsr, node->macaddress_A);
41267 ++ if (!node->removed) {
41268 ++ list_del_rcu(&node->mac_list);
41269 ++ node->removed = true;
41270 ++ /* Note that we need to free this entry later: */
41271 + kfree_rcu(node, rcu_head);
41272 + }
41273 + }
41274 +@@ -600,20 +568,17 @@ void *hsr_get_next_node(struct hsr_priv *hsr, void *_pos,
41275 + unsigned char addr[ETH_ALEN])
41276 + {
41277 + struct hsr_node *node;
41278 +- u32 hash;
41279 +-
41280 +- hash = hsr_mac_hash(hsr, addr);
41281 +
41282 + if (!_pos) {
41283 +- node = hsr_node_get_first(&hsr->node_db[hash],
41284 +- &hsr->list_lock);
41285 ++ node = list_first_or_null_rcu(&hsr->node_db,
41286 ++ struct hsr_node, mac_list);
41287 + if (node)
41288 + ether_addr_copy(addr, node->macaddress_A);
41289 + return node;
41290 + }
41291 +
41292 + node = _pos;
41293 +- hlist_for_each_entry_continue_rcu(node, mac_list) {
41294 ++ list_for_each_entry_continue_rcu(node, &hsr->node_db, mac_list) {
41295 + ether_addr_copy(addr, node->macaddress_A);
41296 + return node;
41297 + }
41298 +@@ -633,11 +598,8 @@ int hsr_get_node_data(struct hsr_priv *hsr,
41299 + struct hsr_node *node;
41300 + struct hsr_port *port;
41301 + unsigned long tdiff;
41302 +- u32 hash;
41303 +-
41304 +- hash = hsr_mac_hash(hsr, addr);
41305 +
41306 +- node = find_node_by_addr_A(&hsr->node_db[hash], addr);
41307 ++ node = find_node_by_addr_A(&hsr->node_db, addr);
41308 + if (!node)
41309 + return -ENOENT;
41310 +
41311 +diff --git a/net/hsr/hsr_framereg.h b/net/hsr/hsr_framereg.h
41312 +index f3762e9e42b54..b23556251d621 100644
41313 +--- a/net/hsr/hsr_framereg.h
41314 ++++ b/net/hsr/hsr_framereg.h
41315 +@@ -28,17 +28,9 @@ struct hsr_frame_info {
41316 + bool is_from_san;
41317 + };
41318 +
41319 +-#ifdef CONFIG_LOCKDEP
41320 +-int lockdep_hsr_is_held(spinlock_t *lock);
41321 +-#else
41322 +-#define lockdep_hsr_is_held(lock) 1
41323 +-#endif
41324 +-
41325 +-u32 hsr_mac_hash(struct hsr_priv *hsr, const unsigned char *addr);
41326 +-struct hsr_node *hsr_node_get_first(struct hlist_head *head, spinlock_t *lock);
41327 + void hsr_del_self_node(struct hsr_priv *hsr);
41328 +-void hsr_del_nodes(struct hlist_head *node_db);
41329 +-struct hsr_node *hsr_get_node(struct hsr_port *port, struct hlist_head *node_db,
41330 ++void hsr_del_nodes(struct list_head *node_db);
41331 ++struct hsr_node *hsr_get_node(struct hsr_port *port, struct list_head *node_db,
41332 + struct sk_buff *skb, bool is_sup,
41333 + enum hsr_port_type rx_port);
41334 + void hsr_handle_sup_frame(struct hsr_frame_info *frame);
41335 +@@ -76,7 +68,9 @@ void prp_handle_san_frame(bool san, enum hsr_port_type port,
41336 + void prp_update_san_info(struct hsr_node *node, bool is_sup);
41337 +
41338 + struct hsr_node {
41339 +- struct hlist_node mac_list;
41340 ++ struct list_head mac_list;
41341 ++ /* Protect R/W access to seq_out */
41342 ++ spinlock_t seq_out_lock;
41343 + unsigned char macaddress_A[ETH_ALEN];
41344 + unsigned char macaddress_B[ETH_ALEN];
41345 + /* Local slave through which AddrB frames are received from this node */
41346 +@@ -88,6 +82,7 @@ struct hsr_node {
41347 + bool san_a;
41348 + bool san_b;
41349 + u16 seq_out[HSR_PT_PORTS];
41350 ++ bool removed;
41351 + struct rcu_head rcu_head;
41352 + };
41353 +
41354 +diff --git a/net/hsr/hsr_main.h b/net/hsr/hsr_main.h
41355 +index b158ba409f9a4..16ae9fb09ccd2 100644
41356 +--- a/net/hsr/hsr_main.h
41357 ++++ b/net/hsr/hsr_main.h
41358 +@@ -47,9 +47,6 @@
41359 +
41360 + #define HSR_V1_SUP_LSDUSIZE 52
41361 +
41362 +-#define HSR_HSIZE_SHIFT 8
41363 +-#define HSR_HSIZE BIT(HSR_HSIZE_SHIFT)
41364 +-
41365 + /* The helper functions below assumes that 'path' occupies the 4 most
41366 + * significant bits of the 16-bit field shared by 'path' and 'LSDU_size' (or
41367 + * equivalently, the 4 most significant bits of HSR tag byte 14).
41368 +@@ -188,8 +185,8 @@ struct hsr_proto_ops {
41369 + struct hsr_priv {
41370 + struct rcu_head rcu_head;
41371 + struct list_head ports;
41372 +- struct hlist_head node_db[HSR_HSIZE]; /* Known HSR nodes */
41373 +- struct hlist_head self_node_db; /* MACs of slaves */
41374 ++ struct list_head node_db; /* Known HSR nodes */
41375 ++ struct list_head self_node_db; /* MACs of slaves */
41376 + struct timer_list announce_timer; /* Supervision frame dispatch */
41377 + struct timer_list prune_timer;
41378 + int announce_count;
41379 +@@ -199,8 +196,6 @@ struct hsr_priv {
41380 + spinlock_t seqnr_lock; /* locking for sequence_nr */
41381 + spinlock_t list_lock; /* locking for node list */
41382 + struct hsr_proto_ops *proto_ops;
41383 +- u32 hash_buckets;
41384 +- u32 hash_seed;
41385 + #define PRP_LAN_ID 0x5 /* 0x1010 for A and 0x1011 for B. Bit 0 is set
41386 + * based on SLAVE_A or SLAVE_B
41387 + */
41388 +diff --git a/net/hsr/hsr_netlink.c b/net/hsr/hsr_netlink.c
41389 +index 1405c037cf7ab..f3c8f91dbe2c1 100644
41390 +--- a/net/hsr/hsr_netlink.c
41391 ++++ b/net/hsr/hsr_netlink.c
41392 +@@ -105,7 +105,6 @@ static int hsr_newlink(struct net *src_net, struct net_device *dev,
41393 + static void hsr_dellink(struct net_device *dev, struct list_head *head)
41394 + {
41395 + struct hsr_priv *hsr = netdev_priv(dev);
41396 +- int i;
41397 +
41398 + del_timer_sync(&hsr->prune_timer);
41399 + del_timer_sync(&hsr->announce_timer);
41400 +@@ -114,8 +113,7 @@ static void hsr_dellink(struct net_device *dev, struct list_head *head)
41401 + hsr_del_ports(hsr);
41402 +
41403 + hsr_del_self_node(hsr);
41404 +- for (i = 0; i < hsr->hash_buckets; i++)
41405 +- hsr_del_nodes(&hsr->node_db[i]);
41406 ++ hsr_del_nodes(&hsr->node_db);
41407 +
41408 + unregister_netdevice_queue(dev, head);
41409 + }
41410 +diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c
41411 +index 7f6d7c355e38e..31f463f46f6ed 100644
41412 +--- a/net/ipv4/af_inet.c
41413 ++++ b/net/ipv4/af_inet.c
41414 +@@ -522,9 +522,9 @@ int __inet_bind(struct sock *sk, struct sockaddr *uaddr, int addr_len,
41415 + /* Make sure we are allowed to bind here. */
41416 + if (snum || !(inet->bind_address_no_port ||
41417 + (flags & BIND_FORCE_ADDRESS_NO_PORT))) {
41418 +- if (sk->sk_prot->get_port(sk, snum)) {
41419 ++ err = sk->sk_prot->get_port(sk, snum);
41420 ++ if (err) {
41421 + inet->inet_saddr = inet->inet_rcv_saddr = 0;
41422 +- err = -EADDRINUSE;
41423 + goto out_release_sock;
41424 + }
41425 + if (!(flags & BIND_FROM_BPF)) {
41426 +@@ -1686,9 +1686,9 @@ u64 snmp_get_cpu_field64(void __percpu *mib, int cpu, int offt,
41427 + bhptr = per_cpu_ptr(mib, cpu);
41428 + syncp = (struct u64_stats_sync *)(bhptr + syncp_offset);
41429 + do {
41430 +- start = u64_stats_fetch_begin_irq(syncp);
41431 ++ start = u64_stats_fetch_begin(syncp);
41432 + v = *(((u64 *)bhptr) + offt);
41433 +- } while (u64_stats_fetch_retry_irq(syncp, start));
41434 ++ } while (u64_stats_fetch_retry(syncp, start));
41435 +
41436 + return v;
41437 + }
41438 +diff --git a/net/ipv4/inet_connection_sock.c b/net/ipv4/inet_connection_sock.c
41439 +index eb31c7158b39c..971969cc7e17f 100644
41440 +--- a/net/ipv4/inet_connection_sock.c
41441 ++++ b/net/ipv4/inet_connection_sock.c
41442 +@@ -1041,7 +1041,7 @@ int inet_csk_listen_start(struct sock *sk)
41443 + {
41444 + struct inet_connection_sock *icsk = inet_csk(sk);
41445 + struct inet_sock *inet = inet_sk(sk);
41446 +- int err = -EADDRINUSE;
41447 ++ int err;
41448 +
41449 + reqsk_queue_alloc(&icsk->icsk_accept_queue);
41450 +
41451 +@@ -1057,7 +1057,8 @@ int inet_csk_listen_start(struct sock *sk)
41452 + * after validation is complete.
41453 + */
41454 + inet_sk_state_store(sk, TCP_LISTEN);
41455 +- if (!sk->sk_prot->get_port(sk, inet->inet_num)) {
41456 ++ err = sk->sk_prot->get_port(sk, inet->inet_num);
41457 ++ if (!err) {
41458 + inet->inet_sport = htons(inet->inet_num);
41459 +
41460 + sk_dst_reset(sk);
41461 +diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
41462 +index 3b2420829c237..948f4801f993e 100644
41463 +--- a/net/ipv4/ping.c
41464 ++++ b/net/ipv4/ping.c
41465 +@@ -142,7 +142,7 @@ next_port:
41466 +
41467 + fail:
41468 + spin_unlock(&ping_table.lock);
41469 +- return 1;
41470 ++ return -EADDRINUSE;
41471 + }
41472 + EXPORT_SYMBOL_GPL(ping_get_port);
41473 +
41474 +diff --git a/net/ipv4/tcp_bpf.c b/net/ipv4/tcp_bpf.c
41475 +index cf9c3e8f7ccbf..94aad3870c5fc 100644
41476 +--- a/net/ipv4/tcp_bpf.c
41477 ++++ b/net/ipv4/tcp_bpf.c
41478 +@@ -45,8 +45,11 @@ static int bpf_tcp_ingress(struct sock *sk, struct sk_psock *psock,
41479 + tmp->sg.end = i;
41480 + if (apply) {
41481 + apply_bytes -= size;
41482 +- if (!apply_bytes)
41483 ++ if (!apply_bytes) {
41484 ++ if (sge->length)
41485 ++ sk_msg_iter_var_prev(i);
41486 + break;
41487 ++ }
41488 + }
41489 + } while (i != msg->sg.end);
41490 +
41491 +@@ -131,10 +134,9 @@ static int tcp_bpf_push_locked(struct sock *sk, struct sk_msg *msg,
41492 + return ret;
41493 + }
41494 +
41495 +-int tcp_bpf_sendmsg_redir(struct sock *sk, struct sk_msg *msg,
41496 +- u32 bytes, int flags)
41497 ++int tcp_bpf_sendmsg_redir(struct sock *sk, bool ingress,
41498 ++ struct sk_msg *msg, u32 bytes, int flags)
41499 + {
41500 +- bool ingress = sk_msg_to_ingress(msg);
41501 + struct sk_psock *psock = sk_psock_get(sk);
41502 + int ret;
41503 +
41504 +@@ -276,10 +278,10 @@ msg_bytes_ready:
41505 + static int tcp_bpf_send_verdict(struct sock *sk, struct sk_psock *psock,
41506 + struct sk_msg *msg, int *copied, int flags)
41507 + {
41508 +- bool cork = false, enospc = sk_msg_full(msg);
41509 ++ bool cork = false, enospc = sk_msg_full(msg), redir_ingress;
41510 + struct sock *sk_redir;
41511 + u32 tosend, origsize, sent, delta = 0;
41512 +- u32 eval = __SK_NONE;
41513 ++ u32 eval;
41514 + int ret;
41515 +
41516 + more_data:
41517 +@@ -310,6 +312,7 @@ more_data:
41518 + tosend = msg->sg.size;
41519 + if (psock->apply_bytes && psock->apply_bytes < tosend)
41520 + tosend = psock->apply_bytes;
41521 ++ eval = __SK_NONE;
41522 +
41523 + switch (psock->eval) {
41524 + case __SK_PASS:
41525 +@@ -321,6 +324,7 @@ more_data:
41526 + sk_msg_apply_bytes(psock, tosend);
41527 + break;
41528 + case __SK_REDIRECT:
41529 ++ redir_ingress = psock->redir_ingress;
41530 + sk_redir = psock->sk_redir;
41531 + sk_msg_apply_bytes(psock, tosend);
41532 + if (!psock->apply_bytes) {
41533 +@@ -337,7 +341,8 @@ more_data:
41534 + release_sock(sk);
41535 +
41536 + origsize = msg->sg.size;
41537 +- ret = tcp_bpf_sendmsg_redir(sk_redir, msg, tosend, flags);
41538 ++ ret = tcp_bpf_sendmsg_redir(sk_redir, redir_ingress,
41539 ++ msg, tosend, flags);
41540 + sent = origsize - msg->sg.size;
41541 +
41542 + if (eval == __SK_REDIRECT)
41543 +diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
41544 +index d9099754ac69d..7fe0ba3f0933e 100644
41545 +--- a/net/ipv4/udp.c
41546 ++++ b/net/ipv4/udp.c
41547 +@@ -232,16 +232,16 @@ static int udp_reuseport_add_sock(struct sock *sk, struct udp_hslot *hslot)
41548 + int udp_lib_get_port(struct sock *sk, unsigned short snum,
41549 + unsigned int hash2_nulladdr)
41550 + {
41551 +- struct udp_hslot *hslot, *hslot2;
41552 + struct udp_table *udptable = sk->sk_prot->h.udp_table;
41553 +- int error = 1;
41554 ++ struct udp_hslot *hslot, *hslot2;
41555 + struct net *net = sock_net(sk);
41556 ++ int error = -EADDRINUSE;
41557 +
41558 + if (!snum) {
41559 ++ DECLARE_BITMAP(bitmap, PORTS_PER_CHAIN);
41560 ++ unsigned short first, last;
41561 + int low, high, remaining;
41562 + unsigned int rand;
41563 +- unsigned short first, last;
41564 +- DECLARE_BITMAP(bitmap, PORTS_PER_CHAIN);
41565 +
41566 + inet_get_local_port_range(net, &low, &high);
41567 + remaining = (high - low) + 1;
41568 +@@ -2527,10 +2527,13 @@ static struct sock *__udp4_lib_mcast_demux_lookup(struct net *net,
41569 + __be16 rmt_port, __be32 rmt_addr,
41570 + int dif, int sdif)
41571 + {
41572 +- struct sock *sk, *result;
41573 + unsigned short hnum = ntohs(loc_port);
41574 +- unsigned int slot = udp_hashfn(net, hnum, udp_table.mask);
41575 +- struct udp_hslot *hslot = &udp_table.hash[slot];
41576 ++ struct sock *sk, *result;
41577 ++ struct udp_hslot *hslot;
41578 ++ unsigned int slot;
41579 ++
41580 ++ slot = udp_hashfn(net, hnum, udp_table.mask);
41581 ++ hslot = &udp_table.hash[slot];
41582 +
41583 + /* Do not bother scanning a too big list */
41584 + if (hslot->count > 10)
41585 +@@ -2558,14 +2561,18 @@ static struct sock *__udp4_lib_demux_lookup(struct net *net,
41586 + __be16 rmt_port, __be32 rmt_addr,
41587 + int dif, int sdif)
41588 + {
41589 +- unsigned short hnum = ntohs(loc_port);
41590 +- unsigned int hash2 = ipv4_portaddr_hash(net, loc_addr, hnum);
41591 +- unsigned int slot2 = hash2 & udp_table.mask;
41592 +- struct udp_hslot *hslot2 = &udp_table.hash2[slot2];
41593 + INET_ADDR_COOKIE(acookie, rmt_addr, loc_addr);
41594 +- const __portpair ports = INET_COMBINED_PORTS(rmt_port, hnum);
41595 ++ unsigned short hnum = ntohs(loc_port);
41596 ++ unsigned int hash2, slot2;
41597 ++ struct udp_hslot *hslot2;
41598 ++ __portpair ports;
41599 + struct sock *sk;
41600 +
41601 ++ hash2 = ipv4_portaddr_hash(net, loc_addr, hnum);
41602 ++ slot2 = hash2 & udp_table.mask;
41603 ++ hslot2 = &udp_table.hash2[slot2];
41604 ++ ports = INET_COMBINED_PORTS(rmt_port, hnum);
41605 ++
41606 + udp_portaddr_for_each_entry_rcu(sk, &hslot2->head) {
41607 + if (inet_match(net, sk, acookie, ports, dif, sdif))
41608 + return sk;
41609 +@@ -2966,10 +2973,10 @@ EXPORT_SYMBOL(udp_prot);
41610 +
41611 + static struct sock *udp_get_first(struct seq_file *seq, int start)
41612 + {
41613 +- struct sock *sk;
41614 +- struct udp_seq_afinfo *afinfo;
41615 + struct udp_iter_state *state = seq->private;
41616 + struct net *net = seq_file_net(seq);
41617 ++ struct udp_seq_afinfo *afinfo;
41618 ++ struct sock *sk;
41619 +
41620 + if (state->bpf_seq_afinfo)
41621 + afinfo = state->bpf_seq_afinfo;
41622 +@@ -3000,9 +3007,9 @@ found:
41623 +
41624 + static struct sock *udp_get_next(struct seq_file *seq, struct sock *sk)
41625 + {
41626 +- struct udp_seq_afinfo *afinfo;
41627 + struct udp_iter_state *state = seq->private;
41628 + struct net *net = seq_file_net(seq);
41629 ++ struct udp_seq_afinfo *afinfo;
41630 +
41631 + if (state->bpf_seq_afinfo)
41632 + afinfo = state->bpf_seq_afinfo;
41633 +@@ -3058,8 +3065,8 @@ EXPORT_SYMBOL(udp_seq_next);
41634 +
41635 + void udp_seq_stop(struct seq_file *seq, void *v)
41636 + {
41637 +- struct udp_seq_afinfo *afinfo;
41638 + struct udp_iter_state *state = seq->private;
41639 ++ struct udp_seq_afinfo *afinfo;
41640 +
41641 + if (state->bpf_seq_afinfo)
41642 + afinfo = state->bpf_seq_afinfo;
41643 +diff --git a/net/ipv4/udp_tunnel_core.c b/net/ipv4/udp_tunnel_core.c
41644 +index 8242c8947340e..5f8104cf082d0 100644
41645 +--- a/net/ipv4/udp_tunnel_core.c
41646 ++++ b/net/ipv4/udp_tunnel_core.c
41647 +@@ -176,6 +176,7 @@ EXPORT_SYMBOL_GPL(udp_tunnel_xmit_skb);
41648 + void udp_tunnel_sock_release(struct socket *sock)
41649 + {
41650 + rcu_assign_sk_user_data(sock->sk, NULL);
41651 ++ synchronize_rcu();
41652 + kernel_sock_shutdown(sock, SHUT_RDWR);
41653 + sock_release(sock);
41654 + }
41655 +diff --git a/net/ipv6/af_inet6.c b/net/ipv6/af_inet6.c
41656 +index dbb1430d6cc2e..cceda5c833021 100644
41657 +--- a/net/ipv6/af_inet6.c
41658 ++++ b/net/ipv6/af_inet6.c
41659 +@@ -403,10 +403,10 @@ static int __inet6_bind(struct sock *sk, struct sockaddr *uaddr, int addr_len,
41660 + /* Make sure we are allowed to bind here. */
41661 + if (snum || !(inet->bind_address_no_port ||
41662 + (flags & BIND_FORCE_ADDRESS_NO_PORT))) {
41663 +- if (sk->sk_prot->get_port(sk, snum)) {
41664 ++ err = sk->sk_prot->get_port(sk, snum);
41665 ++ if (err) {
41666 + sk->sk_ipv6only = saved_ipv6only;
41667 + inet_reset_saddr(sk);
41668 +- err = -EADDRINUSE;
41669 + goto out;
41670 + }
41671 + if (!(flags & BIND_FROM_BPF)) {
41672 +diff --git a/net/ipv6/datagram.c b/net/ipv6/datagram.c
41673 +index 5ecb56522f9d6..ba28aeb7cade0 100644
41674 +--- a/net/ipv6/datagram.c
41675 ++++ b/net/ipv6/datagram.c
41676 +@@ -42,24 +42,29 @@ static void ip6_datagram_flow_key_init(struct flowi6 *fl6, struct sock *sk)
41677 + {
41678 + struct inet_sock *inet = inet_sk(sk);
41679 + struct ipv6_pinfo *np = inet6_sk(sk);
41680 ++ int oif = sk->sk_bound_dev_if;
41681 +
41682 + memset(fl6, 0, sizeof(*fl6));
41683 + fl6->flowi6_proto = sk->sk_protocol;
41684 + fl6->daddr = sk->sk_v6_daddr;
41685 + fl6->saddr = np->saddr;
41686 +- fl6->flowi6_oif = sk->sk_bound_dev_if;
41687 + fl6->flowi6_mark = sk->sk_mark;
41688 + fl6->fl6_dport = inet->inet_dport;
41689 + fl6->fl6_sport = inet->inet_sport;
41690 + fl6->flowlabel = np->flow_label;
41691 + fl6->flowi6_uid = sk->sk_uid;
41692 +
41693 +- if (!fl6->flowi6_oif)
41694 +- fl6->flowi6_oif = np->sticky_pktinfo.ipi6_ifindex;
41695 ++ if (!oif)
41696 ++ oif = np->sticky_pktinfo.ipi6_ifindex;
41697 +
41698 +- if (!fl6->flowi6_oif && ipv6_addr_is_multicast(&fl6->daddr))
41699 +- fl6->flowi6_oif = np->mcast_oif;
41700 ++ if (!oif) {
41701 ++ if (ipv6_addr_is_multicast(&fl6->daddr))
41702 ++ oif = np->mcast_oif;
41703 ++ else
41704 ++ oif = np->ucast_oif;
41705 ++ }
41706 +
41707 ++ fl6->flowi6_oif = oif;
41708 + security_sk_classify_flow(sk, flowi6_to_flowi_common(fl6));
41709 + }
41710 +
41711 +diff --git a/net/ipv6/seg6_local.c b/net/ipv6/seg6_local.c
41712 +index b7de5e46fdd8f..f84da849819cc 100644
41713 +--- a/net/ipv6/seg6_local.c
41714 ++++ b/net/ipv6/seg6_local.c
41715 +@@ -1508,13 +1508,13 @@ static int put_nla_counters(struct sk_buff *skb, struct seg6_local_lwt *slwt)
41716 +
41717 + pcounters = per_cpu_ptr(slwt->pcpu_counters, i);
41718 + do {
41719 +- start = u64_stats_fetch_begin_irq(&pcounters->syncp);
41720 ++ start = u64_stats_fetch_begin(&pcounters->syncp);
41721 +
41722 + packets = u64_stats_read(&pcounters->packets);
41723 + bytes = u64_stats_read(&pcounters->bytes);
41724 + errors = u64_stats_read(&pcounters->errors);
41725 +
41726 +- } while (u64_stats_fetch_retry_irq(&pcounters->syncp, start));
41727 ++ } while (u64_stats_fetch_retry(&pcounters->syncp, start));
41728 +
41729 + counters.packets += packets;
41730 + counters.bytes += bytes;
41731 +diff --git a/net/ipv6/sit.c b/net/ipv6/sit.c
41732 +index 59b2d9a6210c8..ccb39b1e730f8 100644
41733 +--- a/net/ipv6/sit.c
41734 ++++ b/net/ipv6/sit.c
41735 +@@ -694,7 +694,7 @@ static int ipip6_rcv(struct sk_buff *skb)
41736 + skb->dev = tunnel->dev;
41737 +
41738 + if (packet_is_spoofed(skb, iph, tunnel)) {
41739 +- tunnel->dev->stats.rx_errors++;
41740 ++ DEV_STATS_INC(tunnel->dev, rx_errors);
41741 + goto out;
41742 + }
41743 +
41744 +@@ -714,8 +714,8 @@ static int ipip6_rcv(struct sk_buff *skb)
41745 + net_info_ratelimited("non-ECT from %pI4 with TOS=%#x\n",
41746 + &iph->saddr, iph->tos);
41747 + if (err > 1) {
41748 +- ++tunnel->dev->stats.rx_frame_errors;
41749 +- ++tunnel->dev->stats.rx_errors;
41750 ++ DEV_STATS_INC(tunnel->dev, rx_frame_errors);
41751 ++ DEV_STATS_INC(tunnel->dev, rx_errors);
41752 + goto out;
41753 + }
41754 + }
41755 +@@ -942,7 +942,7 @@ static netdev_tx_t ipip6_tunnel_xmit(struct sk_buff *skb,
41756 + if (!rt) {
41757 + rt = ip_route_output_flow(tunnel->net, &fl4, NULL);
41758 + if (IS_ERR(rt)) {
41759 +- dev->stats.tx_carrier_errors++;
41760 ++ DEV_STATS_INC(dev, tx_carrier_errors);
41761 + goto tx_error_icmp;
41762 + }
41763 + dst_cache_set_ip4(&tunnel->dst_cache, &rt->dst, fl4.saddr);
41764 +@@ -950,14 +950,14 @@ static netdev_tx_t ipip6_tunnel_xmit(struct sk_buff *skb,
41765 +
41766 + if (rt->rt_type != RTN_UNICAST && rt->rt_type != RTN_LOCAL) {
41767 + ip_rt_put(rt);
41768 +- dev->stats.tx_carrier_errors++;
41769 ++ DEV_STATS_INC(dev, tx_carrier_errors);
41770 + goto tx_error_icmp;
41771 + }
41772 + tdev = rt->dst.dev;
41773 +
41774 + if (tdev == dev) {
41775 + ip_rt_put(rt);
41776 +- dev->stats.collisions++;
41777 ++ DEV_STATS_INC(dev, collisions);
41778 + goto tx_error;
41779 + }
41780 +
41781 +@@ -970,7 +970,7 @@ static netdev_tx_t ipip6_tunnel_xmit(struct sk_buff *skb,
41782 + mtu = dst_mtu(&rt->dst) - t_hlen;
41783 +
41784 + if (mtu < IPV4_MIN_MTU) {
41785 +- dev->stats.collisions++;
41786 ++ DEV_STATS_INC(dev, collisions);
41787 + ip_rt_put(rt);
41788 + goto tx_error;
41789 + }
41790 +@@ -1009,7 +1009,7 @@ static netdev_tx_t ipip6_tunnel_xmit(struct sk_buff *skb,
41791 + struct sk_buff *new_skb = skb_realloc_headroom(skb, max_headroom);
41792 + if (!new_skb) {
41793 + ip_rt_put(rt);
41794 +- dev->stats.tx_dropped++;
41795 ++ DEV_STATS_INC(dev, tx_dropped);
41796 + kfree_skb(skb);
41797 + return NETDEV_TX_OK;
41798 + }
41799 +@@ -1039,7 +1039,7 @@ tx_error_icmp:
41800 + dst_link_failure(skb);
41801 + tx_error:
41802 + kfree_skb(skb);
41803 +- dev->stats.tx_errors++;
41804 ++ DEV_STATS_INC(dev, tx_errors);
41805 + return NETDEV_TX_OK;
41806 + }
41807 +
41808 +@@ -1058,7 +1058,7 @@ static netdev_tx_t sit_tunnel_xmit__(struct sk_buff *skb,
41809 + return NETDEV_TX_OK;
41810 + tx_error:
41811 + kfree_skb(skb);
41812 +- dev->stats.tx_errors++;
41813 ++ DEV_STATS_INC(dev, tx_errors);
41814 + return NETDEV_TX_OK;
41815 + }
41816 +
41817 +@@ -1087,7 +1087,7 @@ static netdev_tx_t sit_tunnel_xmit(struct sk_buff *skb,
41818 + return NETDEV_TX_OK;
41819 +
41820 + tx_err:
41821 +- dev->stats.tx_errors++;
41822 ++ DEV_STATS_INC(dev, tx_errors);
41823 + kfree_skb(skb);
41824 + return NETDEV_TX_OK;
41825 +
41826 +diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
41827 +index fb667e02e9760..d917d62e662d6 100644
41828 +--- a/net/ipv6/udp.c
41829 ++++ b/net/ipv6/udp.c
41830 +@@ -1039,12 +1039,16 @@ static struct sock *__udp6_lib_demux_lookup(struct net *net,
41831 + int dif, int sdif)
41832 + {
41833 + unsigned short hnum = ntohs(loc_port);
41834 +- unsigned int hash2 = ipv6_portaddr_hash(net, loc_addr, hnum);
41835 +- unsigned int slot2 = hash2 & udp_table.mask;
41836 +- struct udp_hslot *hslot2 = &udp_table.hash2[slot2];
41837 +- const __portpair ports = INET_COMBINED_PORTS(rmt_port, hnum);
41838 ++ unsigned int hash2, slot2;
41839 ++ struct udp_hslot *hslot2;
41840 ++ __portpair ports;
41841 + struct sock *sk;
41842 +
41843 ++ hash2 = ipv6_portaddr_hash(net, loc_addr, hnum);
41844 ++ slot2 = hash2 & udp_table.mask;
41845 ++ hslot2 = &udp_table.hash2[slot2];
41846 ++ ports = INET_COMBINED_PORTS(rmt_port, hnum);
41847 ++
41848 + udp_portaddr_for_each_entry_rcu(sk, &hslot2->head) {
41849 + if (sk->sk_state == TCP_ESTABLISHED &&
41850 + inet6_match(net, sk, rmt_addr, loc_addr, ports, dif, sdif))
41851 +diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
41852 +index 65f34945a7678..538f8c0dbb2b6 100644
41853 +--- a/net/mac80211/cfg.c
41854 ++++ b/net/mac80211/cfg.c
41855 +@@ -539,7 +539,7 @@ static struct ieee80211_key *
41856 + ieee80211_lookup_key(struct ieee80211_sub_if_data *sdata,
41857 + u8 key_idx, bool pairwise, const u8 *mac_addr)
41858 + {
41859 +- struct ieee80211_local *local = sdata->local;
41860 ++ struct ieee80211_local *local __maybe_unused = sdata->local;
41861 + struct ieee80211_key *key;
41862 + struct sta_info *sta;
41863 +
41864 +diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
41865 +index 9583643b70332..c7dd1f49bb351 100644
41866 +--- a/net/mac80211/ieee80211_i.h
41867 ++++ b/net/mac80211/ieee80211_i.h
41868 +@@ -389,6 +389,7 @@ struct ieee80211_mgd_auth_data {
41869 + bool done, waiting;
41870 + bool peer_confirmed;
41871 + bool timeout_started;
41872 ++ int link_id;
41873 +
41874 + u8 ap_addr[ETH_ALEN] __aligned(2);
41875 +
41876 +diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
41877 +index 95b58c5cac07f..c3eb08b5a47e3 100644
41878 +--- a/net/mac80211/iface.c
41879 ++++ b/net/mac80211/iface.c
41880 +@@ -2414,6 +2414,7 @@ int ieee80211_if_add(struct ieee80211_local *local, const char *name,
41881 +
41882 + ret = cfg80211_register_netdevice(ndev);
41883 + if (ret) {
41884 ++ ieee80211_if_free(ndev);
41885 + free_netdev(ndev);
41886 + return ret;
41887 + }
41888 +diff --git a/net/mac80211/mlme.c b/net/mac80211/mlme.c
41889 +index 654414caeb71e..0a9710747b80e 100644
41890 +--- a/net/mac80211/mlme.c
41891 ++++ b/net/mac80211/mlme.c
41892 +@@ -4955,6 +4955,7 @@ static void ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data *sdata,
41893 + struct cfg80211_rx_assoc_resp resp = {
41894 + .uapsd_queues = -1,
41895 + };
41896 ++ u8 ap_mld_addr[ETH_ALEN] __aligned(2);
41897 + unsigned int link_id;
41898 +
41899 + sdata_assert_lock(sdata);
41900 +@@ -5119,6 +5120,11 @@ static void ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data *sdata,
41901 + resp.uapsd_queues |= ieee80211_ac_to_qos_mask[ac];
41902 + }
41903 +
41904 ++ if (sdata->vif.valid_links) {
41905 ++ ether_addr_copy(ap_mld_addr, sdata->vif.cfg.ap_addr);
41906 ++ resp.ap_mld_addr = ap_mld_addr;
41907 ++ }
41908 ++
41909 + ieee80211_destroy_assoc_data(sdata,
41910 + status_code == WLAN_STATUS_SUCCESS ?
41911 + ASSOC_SUCCESS :
41912 +@@ -5128,8 +5134,6 @@ static void ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data *sdata,
41913 + resp.len = len;
41914 + resp.req_ies = ifmgd->assoc_req_ies;
41915 + resp.req_ies_len = ifmgd->assoc_req_ies_len;
41916 +- if (sdata->vif.valid_links)
41917 +- resp.ap_mld_addr = sdata->vif.cfg.ap_addr;
41918 + cfg80211_rx_assoc_resp(sdata->dev, &resp);
41919 + notify_driver:
41920 + drv_mgd_complete_tx(sdata->local, sdata, &info);
41921 +@@ -6578,6 +6582,7 @@ int ieee80211_mgd_auth(struct ieee80211_sub_if_data *sdata,
41922 + req->ap_mld_addr ?: req->bss->bssid,
41923 + ETH_ALEN);
41924 + auth_data->bss = req->bss;
41925 ++ auth_data->link_id = req->link_id;
41926 +
41927 + if (req->auth_data_len >= 4) {
41928 + if (req->auth_type == NL80211_AUTHTYPE_SAE) {
41929 +@@ -6596,7 +6601,8 @@ int ieee80211_mgd_auth(struct ieee80211_sub_if_data *sdata,
41930 + * removal and re-addition of the STA entry in
41931 + * ieee80211_prep_connection().
41932 + */
41933 +- cont_auth = ifmgd->auth_data && req->bss == ifmgd->auth_data->bss;
41934 ++ cont_auth = ifmgd->auth_data && req->bss == ifmgd->auth_data->bss &&
41935 ++ ifmgd->auth_data->link_id == req->link_id;
41936 +
41937 + if (req->ie && req->ie_len) {
41938 + memcpy(&auth_data->data[auth_data->data_len],
41939 +@@ -6933,7 +6939,8 @@ int ieee80211_mgd_assoc(struct ieee80211_sub_if_data *sdata,
41940 +
41941 + /* keep sta info, bssid if matching */
41942 + match = ether_addr_equal(ifmgd->auth_data->ap_addr,
41943 +- assoc_data->ap_addr);
41944 ++ assoc_data->ap_addr) &&
41945 ++ ifmgd->auth_data->link_id == req->link_id;
41946 + ieee80211_destroy_auth_data(sdata, match);
41947 + }
41948 +
41949 +diff --git a/net/mac80211/sta_info.c b/net/mac80211/sta_info.c
41950 +index 9d7b238a67372..965b9cb2ef3f2 100644
41951 +--- a/net/mac80211/sta_info.c
41952 ++++ b/net/mac80211/sta_info.c
41953 +@@ -2316,9 +2316,9 @@ static inline u64 sta_get_tidstats_msdu(struct ieee80211_sta_rx_stats *rxstats,
41954 + u64 value;
41955 +
41956 + do {
41957 +- start = u64_stats_fetch_begin_irq(&rxstats->syncp);
41958 ++ start = u64_stats_fetch_begin(&rxstats->syncp);
41959 + value = rxstats->msdu[tid];
41960 +- } while (u64_stats_fetch_retry_irq(&rxstats->syncp, start));
41961 ++ } while (u64_stats_fetch_retry(&rxstats->syncp, start));
41962 +
41963 + return value;
41964 + }
41965 +@@ -2384,9 +2384,9 @@ static inline u64 sta_get_stats_bytes(struct ieee80211_sta_rx_stats *rxstats)
41966 + u64 value;
41967 +
41968 + do {
41969 +- start = u64_stats_fetch_begin_irq(&rxstats->syncp);
41970 ++ start = u64_stats_fetch_begin(&rxstats->syncp);
41971 + value = rxstats->bytes;
41972 +- } while (u64_stats_fetch_retry_irq(&rxstats->syncp, start));
41973 ++ } while (u64_stats_fetch_retry(&rxstats->syncp, start));
41974 +
41975 + return value;
41976 + }
41977 +diff --git a/net/mac80211/tx.c b/net/mac80211/tx.c
41978 +index d2c4f9226f947..dafd3a480f024 100644
41979 +--- a/net/mac80211/tx.c
41980 ++++ b/net/mac80211/tx.c
41981 +@@ -2934,7 +2934,7 @@ static struct sk_buff *ieee80211_build_hdr(struct ieee80211_sub_if_data *sdata,
41982 +
41983 + if (pre_conf_link_id != link_id &&
41984 + link_id != IEEE80211_LINK_UNSPECIFIED) {
41985 +-#ifdef CPTCFG_MAC80211_VERBOSE_DEBUG
41986 ++#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
41987 + net_info_ratelimited("%s: dropped frame to %pM with bad link ID request (%d vs. %d)\n",
41988 + sdata->name, hdr.addr1,
41989 + pre_conf_link_id, link_id);
41990 +diff --git a/net/mctp/device.c b/net/mctp/device.c
41991 +index 99a3bda8852f8..acb97b2574289 100644
41992 +--- a/net/mctp/device.c
41993 ++++ b/net/mctp/device.c
41994 +@@ -429,12 +429,6 @@ static void mctp_unregister(struct net_device *dev)
41995 + struct mctp_dev *mdev;
41996 +
41997 + mdev = mctp_dev_get_rtnl(dev);
41998 +- if (mdev && !mctp_known(dev)) {
41999 +- // Sanity check, should match what was set in mctp_register
42000 +- netdev_warn(dev, "%s: BUG mctp_ptr set for unknown type %d",
42001 +- __func__, dev->type);
42002 +- return;
42003 +- }
42004 + if (!mdev)
42005 + return;
42006 +
42007 +@@ -451,14 +445,8 @@ static int mctp_register(struct net_device *dev)
42008 + struct mctp_dev *mdev;
42009 +
42010 + /* Already registered? */
42011 +- mdev = rtnl_dereference(dev->mctp_ptr);
42012 +-
42013 +- if (mdev) {
42014 +- if (!mctp_known(dev))
42015 +- netdev_warn(dev, "%s: BUG mctp_ptr set for unknown type %d",
42016 +- __func__, dev->type);
42017 ++ if (rtnl_dereference(dev->mctp_ptr))
42018 + return 0;
42019 +- }
42020 +
42021 + /* only register specific types */
42022 + if (!mctp_known(dev))
42023 +diff --git a/net/mpls/af_mpls.c b/net/mpls/af_mpls.c
42024 +index b52afe316dc41..35b5f806fdda1 100644
42025 +--- a/net/mpls/af_mpls.c
42026 ++++ b/net/mpls/af_mpls.c
42027 +@@ -1079,9 +1079,9 @@ static void mpls_get_stats(struct mpls_dev *mdev,
42028 +
42029 + p = per_cpu_ptr(mdev->stats, i);
42030 + do {
42031 +- start = u64_stats_fetch_begin_irq(&p->syncp);
42032 ++ start = u64_stats_fetch_begin(&p->syncp);
42033 + local = p->stats;
42034 +- } while (u64_stats_fetch_retry_irq(&p->syncp, start));
42035 ++ } while (u64_stats_fetch_retry(&p->syncp, start));
42036 +
42037 + stats->rx_packets += local.rx_packets;
42038 + stats->rx_bytes += local.rx_bytes;
42039 +diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
42040 +index 51ad557a525b5..b5ae419661b80 100644
42041 +--- a/net/netfilter/ipvs/ip_vs_core.c
42042 ++++ b/net/netfilter/ipvs/ip_vs_core.c
42043 +@@ -132,21 +132,21 @@ ip_vs_in_stats(struct ip_vs_conn *cp, struct sk_buff *skb)
42044 +
42045 + s = this_cpu_ptr(dest->stats.cpustats);
42046 + u64_stats_update_begin(&s->syncp);
42047 +- s->cnt.inpkts++;
42048 +- s->cnt.inbytes += skb->len;
42049 ++ u64_stats_inc(&s->cnt.inpkts);
42050 ++ u64_stats_add(&s->cnt.inbytes, skb->len);
42051 + u64_stats_update_end(&s->syncp);
42052 +
42053 + svc = rcu_dereference(dest->svc);
42054 + s = this_cpu_ptr(svc->stats.cpustats);
42055 + u64_stats_update_begin(&s->syncp);
42056 +- s->cnt.inpkts++;
42057 +- s->cnt.inbytes += skb->len;
42058 ++ u64_stats_inc(&s->cnt.inpkts);
42059 ++ u64_stats_add(&s->cnt.inbytes, skb->len);
42060 + u64_stats_update_end(&s->syncp);
42061 +
42062 + s = this_cpu_ptr(ipvs->tot_stats.cpustats);
42063 + u64_stats_update_begin(&s->syncp);
42064 +- s->cnt.inpkts++;
42065 +- s->cnt.inbytes += skb->len;
42066 ++ u64_stats_inc(&s->cnt.inpkts);
42067 ++ u64_stats_add(&s->cnt.inbytes, skb->len);
42068 + u64_stats_update_end(&s->syncp);
42069 +
42070 + local_bh_enable();
42071 +@@ -168,21 +168,21 @@ ip_vs_out_stats(struct ip_vs_conn *cp, struct sk_buff *skb)
42072 +
42073 + s = this_cpu_ptr(dest->stats.cpustats);
42074 + u64_stats_update_begin(&s->syncp);
42075 +- s->cnt.outpkts++;
42076 +- s->cnt.outbytes += skb->len;
42077 ++ u64_stats_inc(&s->cnt.outpkts);
42078 ++ u64_stats_add(&s->cnt.outbytes, skb->len);
42079 + u64_stats_update_end(&s->syncp);
42080 +
42081 + svc = rcu_dereference(dest->svc);
42082 + s = this_cpu_ptr(svc->stats.cpustats);
42083 + u64_stats_update_begin(&s->syncp);
42084 +- s->cnt.outpkts++;
42085 +- s->cnt.outbytes += skb->len;
42086 ++ u64_stats_inc(&s->cnt.outpkts);
42087 ++ u64_stats_add(&s->cnt.outbytes, skb->len);
42088 + u64_stats_update_end(&s->syncp);
42089 +
42090 + s = this_cpu_ptr(ipvs->tot_stats.cpustats);
42091 + u64_stats_update_begin(&s->syncp);
42092 +- s->cnt.outpkts++;
42093 +- s->cnt.outbytes += skb->len;
42094 ++ u64_stats_inc(&s->cnt.outpkts);
42095 ++ u64_stats_add(&s->cnt.outbytes, skb->len);
42096 + u64_stats_update_end(&s->syncp);
42097 +
42098 + local_bh_enable();
42099 +@@ -200,17 +200,17 @@ ip_vs_conn_stats(struct ip_vs_conn *cp, struct ip_vs_service *svc)
42100 +
42101 + s = this_cpu_ptr(cp->dest->stats.cpustats);
42102 + u64_stats_update_begin(&s->syncp);
42103 +- s->cnt.conns++;
42104 ++ u64_stats_inc(&s->cnt.conns);
42105 + u64_stats_update_end(&s->syncp);
42106 +
42107 + s = this_cpu_ptr(svc->stats.cpustats);
42108 + u64_stats_update_begin(&s->syncp);
42109 +- s->cnt.conns++;
42110 ++ u64_stats_inc(&s->cnt.conns);
42111 + u64_stats_update_end(&s->syncp);
42112 +
42113 + s = this_cpu_ptr(ipvs->tot_stats.cpustats);
42114 + u64_stats_update_begin(&s->syncp);
42115 +- s->cnt.conns++;
42116 ++ u64_stats_inc(&s->cnt.conns);
42117 + u64_stats_update_end(&s->syncp);
42118 +
42119 + local_bh_enable();
42120 +diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
42121 +index efab2b06d3732..65bda976845da 100644
42122 +--- a/net/netfilter/ipvs/ip_vs_ctl.c
42123 ++++ b/net/netfilter/ipvs/ip_vs_ctl.c
42124 +@@ -2296,13 +2296,13 @@ static int ip_vs_stats_percpu_show(struct seq_file *seq, void *v)
42125 + u64 conns, inpkts, outpkts, inbytes, outbytes;
42126 +
42127 + do {
42128 +- start = u64_stats_fetch_begin_irq(&u->syncp);
42129 +- conns = u->cnt.conns;
42130 +- inpkts = u->cnt.inpkts;
42131 +- outpkts = u->cnt.outpkts;
42132 +- inbytes = u->cnt.inbytes;
42133 +- outbytes = u->cnt.outbytes;
42134 +- } while (u64_stats_fetch_retry_irq(&u->syncp, start));
42135 ++ start = u64_stats_fetch_begin(&u->syncp);
42136 ++ conns = u64_stats_read(&u->cnt.conns);
42137 ++ inpkts = u64_stats_read(&u->cnt.inpkts);
42138 ++ outpkts = u64_stats_read(&u->cnt.outpkts);
42139 ++ inbytes = u64_stats_read(&u->cnt.inbytes);
42140 ++ outbytes = u64_stats_read(&u->cnt.outbytes);
42141 ++ } while (u64_stats_fetch_retry(&u->syncp, start));
42142 +
42143 + seq_printf(seq, "%3X %8LX %8LX %8LX %16LX %16LX\n",
42144 + i, (u64)conns, (u64)inpkts,
42145 +diff --git a/net/netfilter/ipvs/ip_vs_est.c b/net/netfilter/ipvs/ip_vs_est.c
42146 +index 9a1a7af6a186a..f53150d82a92d 100644
42147 +--- a/net/netfilter/ipvs/ip_vs_est.c
42148 ++++ b/net/netfilter/ipvs/ip_vs_est.c
42149 +@@ -67,11 +67,11 @@ static void ip_vs_read_cpu_stats(struct ip_vs_kstats *sum,
42150 + if (add) {
42151 + do {
42152 + start = u64_stats_fetch_begin(&s->syncp);
42153 +- conns = s->cnt.conns;
42154 +- inpkts = s->cnt.inpkts;
42155 +- outpkts = s->cnt.outpkts;
42156 +- inbytes = s->cnt.inbytes;
42157 +- outbytes = s->cnt.outbytes;
42158 ++ conns = u64_stats_read(&s->cnt.conns);
42159 ++ inpkts = u64_stats_read(&s->cnt.inpkts);
42160 ++ outpkts = u64_stats_read(&s->cnt.outpkts);
42161 ++ inbytes = u64_stats_read(&s->cnt.inbytes);
42162 ++ outbytes = u64_stats_read(&s->cnt.outbytes);
42163 + } while (u64_stats_fetch_retry(&s->syncp, start));
42164 + sum->conns += conns;
42165 + sum->inpkts += inpkts;
42166 +@@ -82,11 +82,11 @@ static void ip_vs_read_cpu_stats(struct ip_vs_kstats *sum,
42167 + add = true;
42168 + do {
42169 + start = u64_stats_fetch_begin(&s->syncp);
42170 +- sum->conns = s->cnt.conns;
42171 +- sum->inpkts = s->cnt.inpkts;
42172 +- sum->outpkts = s->cnt.outpkts;
42173 +- sum->inbytes = s->cnt.inbytes;
42174 +- sum->outbytes = s->cnt.outbytes;
42175 ++ sum->conns = u64_stats_read(&s->cnt.conns);
42176 ++ sum->inpkts = u64_stats_read(&s->cnt.inpkts);
42177 ++ sum->outpkts = u64_stats_read(&s->cnt.outpkts);
42178 ++ sum->inbytes = u64_stats_read(&s->cnt.inbytes);
42179 ++ sum->outbytes = u64_stats_read(&s->cnt.outbytes);
42180 + } while (u64_stats_fetch_retry(&s->syncp, start));
42181 + }
42182 + }
42183 +diff --git a/net/netfilter/nf_conntrack_proto_icmpv6.c b/net/netfilter/nf_conntrack_proto_icmpv6.c
42184 +index 61e3b05cf02c3..1020d67600a95 100644
42185 +--- a/net/netfilter/nf_conntrack_proto_icmpv6.c
42186 ++++ b/net/netfilter/nf_conntrack_proto_icmpv6.c
42187 +@@ -129,6 +129,56 @@ static void icmpv6_error_log(const struct sk_buff *skb,
42188 + nf_l4proto_log_invalid(skb, state, IPPROTO_ICMPV6, "%s", msg);
42189 + }
42190 +
42191 ++static noinline_for_stack int
42192 ++nf_conntrack_icmpv6_redirect(struct nf_conn *tmpl, struct sk_buff *skb,
42193 ++ unsigned int dataoff,
42194 ++ const struct nf_hook_state *state)
42195 ++{
42196 ++ u8 hl = ipv6_hdr(skb)->hop_limit;
42197 ++ union nf_inet_addr outer_daddr;
42198 ++ union {
42199 ++ struct nd_opt_hdr nd_opt;
42200 ++ struct rd_msg rd_msg;
42201 ++ } tmp;
42202 ++ const struct nd_opt_hdr *nd_opt;
42203 ++ const struct rd_msg *rd_msg;
42204 ++
42205 ++ rd_msg = skb_header_pointer(skb, dataoff, sizeof(*rd_msg), &tmp.rd_msg);
42206 ++ if (!rd_msg) {
42207 ++ icmpv6_error_log(skb, state, "short redirect");
42208 ++ return -NF_ACCEPT;
42209 ++ }
42210 ++
42211 ++ if (rd_msg->icmph.icmp6_code != 0)
42212 ++ return NF_ACCEPT;
42213 ++
42214 ++ if (hl != 255 || !(ipv6_addr_type(&ipv6_hdr(skb)->saddr) & IPV6_ADDR_LINKLOCAL)) {
42215 ++ icmpv6_error_log(skb, state, "invalid saddr or hoplimit for redirect");
42216 ++ return -NF_ACCEPT;
42217 ++ }
42218 ++
42219 ++ dataoff += sizeof(*rd_msg);
42220 ++
42221 ++ /* warning: rd_msg no longer usable after this call */
42222 ++ nd_opt = skb_header_pointer(skb, dataoff, sizeof(*nd_opt), &tmp.nd_opt);
42223 ++ if (!nd_opt || nd_opt->nd_opt_len == 0) {
42224 ++ icmpv6_error_log(skb, state, "redirect without options");
42225 ++ return -NF_ACCEPT;
42226 ++ }
42227 ++
42228 ++ /* We could call ndisc_parse_options(), but it would need
42229 ++ * skb_linearize() and a bit more work.
42230 ++ */
42231 ++ if (nd_opt->nd_opt_type != ND_OPT_REDIRECT_HDR)
42232 ++ return NF_ACCEPT;
42233 ++
42234 ++ memcpy(&outer_daddr.ip6, &ipv6_hdr(skb)->daddr,
42235 ++ sizeof(outer_daddr.ip6));
42236 ++ dataoff += 8;
42237 ++ return nf_conntrack_inet_error(tmpl, skb, dataoff, state,
42238 ++ IPPROTO_ICMPV6, &outer_daddr);
42239 ++}
42240 ++
42241 + int nf_conntrack_icmpv6_error(struct nf_conn *tmpl,
42242 + struct sk_buff *skb,
42243 + unsigned int dataoff,
42244 +@@ -159,6 +209,9 @@ int nf_conntrack_icmpv6_error(struct nf_conn *tmpl,
42245 + return NF_ACCEPT;
42246 + }
42247 +
42248 ++ if (icmp6h->icmp6_type == NDISC_REDIRECT)
42249 ++ return nf_conntrack_icmpv6_redirect(tmpl, skb, dataoff, state);
42250 ++
42251 + /* is not error message ? */
42252 + if (icmp6h->icmp6_type >= 128)
42253 + return NF_ACCEPT;
42254 +diff --git a/net/netfilter/nf_flow_table_offload.c b/net/netfilter/nf_flow_table_offload.c
42255 +index 0fdcdb2c9ae43..4d9b99abe37d6 100644
42256 +--- a/net/netfilter/nf_flow_table_offload.c
42257 ++++ b/net/netfilter/nf_flow_table_offload.c
42258 +@@ -383,12 +383,12 @@ static void flow_offload_ipv6_mangle(struct nf_flow_rule *flow_rule,
42259 + const __be32 *addr, const __be32 *mask)
42260 + {
42261 + struct flow_action_entry *entry;
42262 +- int i, j;
42263 ++ int i;
42264 +
42265 +- for (i = 0, j = 0; i < sizeof(struct in6_addr) / sizeof(u32); i += sizeof(u32), j++) {
42266 ++ for (i = 0; i < sizeof(struct in6_addr) / sizeof(u32); i++) {
42267 + entry = flow_action_entry_next(flow_rule);
42268 + flow_offload_mangle(entry, FLOW_ACT_MANGLE_HDR_TYPE_IP6,
42269 +- offset + i, &addr[j], mask);
42270 ++ offset + i * sizeof(u32), &addr[i], mask);
42271 + }
42272 + }
42273 +
42274 +diff --git a/net/netfilter/nf_tables_api.c b/net/netfilter/nf_tables_api.c
42275 +index 0a6f3c1e9ab75..7977f0422ecf6 100644
42276 +--- a/net/netfilter/nf_tables_api.c
42277 ++++ b/net/netfilter/nf_tables_api.c
42278 +@@ -1534,10 +1534,10 @@ static int nft_dump_stats(struct sk_buff *skb, struct nft_stats __percpu *stats)
42279 + for_each_possible_cpu(cpu) {
42280 + cpu_stats = per_cpu_ptr(stats, cpu);
42281 + do {
42282 +- seq = u64_stats_fetch_begin_irq(&cpu_stats->syncp);
42283 ++ seq = u64_stats_fetch_begin(&cpu_stats->syncp);
42284 + pkts = cpu_stats->pkts;
42285 + bytes = cpu_stats->bytes;
42286 +- } while (u64_stats_fetch_retry_irq(&cpu_stats->syncp, seq));
42287 ++ } while (u64_stats_fetch_retry(&cpu_stats->syncp, seq));
42288 + total.pkts += pkts;
42289 + total.bytes += bytes;
42290 + }
42291 +diff --git a/net/openvswitch/datapath.c b/net/openvswitch/datapath.c
42292 +index 8a22574ed7ad6..ac66cdc7b67b8 100644
42293 +--- a/net/openvswitch/datapath.c
42294 ++++ b/net/openvswitch/datapath.c
42295 +@@ -715,9 +715,9 @@ static void get_dp_stats(const struct datapath *dp, struct ovs_dp_stats *stats,
42296 + percpu_stats = per_cpu_ptr(dp->stats_percpu, i);
42297 +
42298 + do {
42299 +- start = u64_stats_fetch_begin_irq(&percpu_stats->syncp);
42300 ++ start = u64_stats_fetch_begin(&percpu_stats->syncp);
42301 + local_stats = *percpu_stats;
42302 +- } while (u64_stats_fetch_retry_irq(&percpu_stats->syncp, start));
42303 ++ } while (u64_stats_fetch_retry(&percpu_stats->syncp, start));
42304 +
42305 + stats->n_hit += local_stats.n_hit;
42306 + stats->n_missed += local_stats.n_missed;
42307 +@@ -947,6 +947,7 @@ static int ovs_flow_cmd_new(struct sk_buff *skb, struct genl_info *info)
42308 + struct sw_flow_mask mask;
42309 + struct sk_buff *reply;
42310 + struct datapath *dp;
42311 ++ struct sw_flow_key *key;
42312 + struct sw_flow_actions *acts;
42313 + struct sw_flow_match match;
42314 + u32 ufid_flags = ovs_nla_get_ufid_flags(a[OVS_FLOW_ATTR_UFID_FLAGS]);
42315 +@@ -974,24 +975,26 @@ static int ovs_flow_cmd_new(struct sk_buff *skb, struct genl_info *info)
42316 + }
42317 +
42318 + /* Extract key. */
42319 +- ovs_match_init(&match, &new_flow->key, false, &mask);
42320 ++ key = kzalloc(sizeof(*key), GFP_KERNEL);
42321 ++ if (!key) {
42322 ++ error = -ENOMEM;
42323 ++ goto err_kfree_key;
42324 ++ }
42325 ++
42326 ++ ovs_match_init(&match, key, false, &mask);
42327 + error = ovs_nla_get_match(net, &match, a[OVS_FLOW_ATTR_KEY],
42328 + a[OVS_FLOW_ATTR_MASK], log);
42329 + if (error)
42330 + goto err_kfree_flow;
42331 +
42332 ++ ovs_flow_mask_key(&new_flow->key, key, true, &mask);
42333 ++
42334 + /* Extract flow identifier. */
42335 + error = ovs_nla_get_identifier(&new_flow->id, a[OVS_FLOW_ATTR_UFID],
42336 +- &new_flow->key, log);
42337 ++ key, log);
42338 + if (error)
42339 + goto err_kfree_flow;
42340 +
42341 +- /* unmasked key is needed to match when ufid is not used. */
42342 +- if (ovs_identifier_is_key(&new_flow->id))
42343 +- match.key = new_flow->id.unmasked_key;
42344 +-
42345 +- ovs_flow_mask_key(&new_flow->key, &new_flow->key, true, &mask);
42346 +-
42347 + /* Validate actions. */
42348 + error = ovs_nla_copy_actions(net, a[OVS_FLOW_ATTR_ACTIONS],
42349 + &new_flow->key, &acts, log);
42350 +@@ -1018,7 +1021,7 @@ static int ovs_flow_cmd_new(struct sk_buff *skb, struct genl_info *info)
42351 + if (ovs_identifier_is_ufid(&new_flow->id))
42352 + flow = ovs_flow_tbl_lookup_ufid(&dp->table, &new_flow->id);
42353 + if (!flow)
42354 +- flow = ovs_flow_tbl_lookup(&dp->table, &new_flow->key);
42355 ++ flow = ovs_flow_tbl_lookup(&dp->table, key);
42356 + if (likely(!flow)) {
42357 + rcu_assign_pointer(new_flow->sf_acts, acts);
42358 +
42359 +@@ -1088,6 +1091,8 @@ static int ovs_flow_cmd_new(struct sk_buff *skb, struct genl_info *info)
42360 +
42361 + if (reply)
42362 + ovs_notify(&dp_flow_genl_family, reply, info);
42363 ++
42364 ++ kfree(key);
42365 + return 0;
42366 +
42367 + err_unlock_ovs:
42368 +@@ -1097,6 +1102,8 @@ err_kfree_acts:
42369 + ovs_nla_free_flow_actions(acts);
42370 + err_kfree_flow:
42371 + ovs_flow_free(new_flow, false);
42372 ++err_kfree_key:
42373 ++ kfree(key);
42374 + error:
42375 + return error;
42376 + }
42377 +diff --git a/net/openvswitch/flow_table.c b/net/openvswitch/flow_table.c
42378 +index d4a2db0b22998..0a0e4c283f02e 100644
42379 +--- a/net/openvswitch/flow_table.c
42380 ++++ b/net/openvswitch/flow_table.c
42381 +@@ -205,9 +205,9 @@ static void tbl_mask_array_reset_counters(struct mask_array *ma)
42382 +
42383 + stats = per_cpu_ptr(ma->masks_usage_stats, cpu);
42384 + do {
42385 +- start = u64_stats_fetch_begin_irq(&stats->syncp);
42386 ++ start = u64_stats_fetch_begin(&stats->syncp);
42387 + counter = stats->usage_cntrs[i];
42388 +- } while (u64_stats_fetch_retry_irq(&stats->syncp, start));
42389 ++ } while (u64_stats_fetch_retry(&stats->syncp, start));
42390 +
42391 + ma->masks_usage_zero_cntr[i] += counter;
42392 + }
42393 +@@ -1136,10 +1136,9 @@ void ovs_flow_masks_rebalance(struct flow_table *table)
42394 +
42395 + stats = per_cpu_ptr(ma->masks_usage_stats, cpu);
42396 + do {
42397 +- start = u64_stats_fetch_begin_irq(&stats->syncp);
42398 ++ start = u64_stats_fetch_begin(&stats->syncp);
42399 + counter = stats->usage_cntrs[i];
42400 +- } while (u64_stats_fetch_retry_irq(&stats->syncp,
42401 +- start));
42402 ++ } while (u64_stats_fetch_retry(&stats->syncp, start));
42403 +
42404 + masks_and_count[i].counter += counter;
42405 + }
42406 +diff --git a/net/rxrpc/output.c b/net/rxrpc/output.c
42407 +index 9683617db7049..08c117bc083ec 100644
42408 +--- a/net/rxrpc/output.c
42409 ++++ b/net/rxrpc/output.c
42410 +@@ -93,7 +93,7 @@ static size_t rxrpc_fill_out_ack(struct rxrpc_connection *conn,
42411 + *_hard_ack = hard_ack;
42412 + *_top = top;
42413 +
42414 +- pkt->ack.bufferSpace = htons(8);
42415 ++ pkt->ack.bufferSpace = htons(0);
42416 + pkt->ack.maxSkew = htons(0);
42417 + pkt->ack.firstPacket = htonl(hard_ack + 1);
42418 + pkt->ack.previousPacket = htonl(call->ackr_highest_seq);
42419 +diff --git a/net/rxrpc/sendmsg.c b/net/rxrpc/sendmsg.c
42420 +index 3c3a626459deb..d4e4e94f4f987 100644
42421 +--- a/net/rxrpc/sendmsg.c
42422 ++++ b/net/rxrpc/sendmsg.c
42423 +@@ -716,7 +716,7 @@ int rxrpc_do_sendmsg(struct rxrpc_sock *rx, struct msghdr *msg, size_t len)
42424 + if (call->tx_total_len != -1 ||
42425 + call->tx_pending ||
42426 + call->tx_top != 0)
42427 +- goto error_put;
42428 ++ goto out_put_unlock;
42429 + call->tx_total_len = p.call.tx_total_len;
42430 + }
42431 + }
42432 +diff --git a/net/sched/ematch.c b/net/sched/ematch.c
42433 +index 4ce6813618515..5c1235e6076ae 100644
42434 +--- a/net/sched/ematch.c
42435 ++++ b/net/sched/ematch.c
42436 +@@ -255,6 +255,8 @@ static int tcf_em_validate(struct tcf_proto *tp,
42437 + * the value carried.
42438 + */
42439 + if (em_hdr->flags & TCF_EM_SIMPLE) {
42440 ++ if (em->ops->datalen > 0)
42441 ++ goto errout;
42442 + if (data_len < sizeof(u32))
42443 + goto errout;
42444 + em->data = *(u32 *) data;
42445 +diff --git a/net/sctp/sysctl.c b/net/sctp/sysctl.c
42446 +index b46a416787ec3..43ebf090029d7 100644
42447 +--- a/net/sctp/sysctl.c
42448 ++++ b/net/sctp/sysctl.c
42449 +@@ -84,17 +84,18 @@ static struct ctl_table sctp_table[] = {
42450 + { /* sentinel */ }
42451 + };
42452 +
42453 ++/* The following index defines are used in sctp_sysctl_net_register().
42454 ++ * If you add new items to the sctp_net_table, please ensure that
42455 ++ * the index values of these defines hold the same meaning indicated by
42456 ++ * their macro names when they appear in sctp_net_table.
42457 ++ */
42458 ++#define SCTP_RTO_MIN_IDX 0
42459 ++#define SCTP_RTO_MAX_IDX 1
42460 ++#define SCTP_PF_RETRANS_IDX 2
42461 ++#define SCTP_PS_RETRANS_IDX 3
42462 ++
42463 + static struct ctl_table sctp_net_table[] = {
42464 +- {
42465 +- .procname = "rto_initial",
42466 +- .data = &init_net.sctp.rto_initial,
42467 +- .maxlen = sizeof(unsigned int),
42468 +- .mode = 0644,
42469 +- .proc_handler = proc_dointvec_minmax,
42470 +- .extra1 = SYSCTL_ONE,
42471 +- .extra2 = &timer_max
42472 +- },
42473 +- {
42474 ++ [SCTP_RTO_MIN_IDX] = {
42475 + .procname = "rto_min",
42476 + .data = &init_net.sctp.rto_min,
42477 + .maxlen = sizeof(unsigned int),
42478 +@@ -103,7 +104,7 @@ static struct ctl_table sctp_net_table[] = {
42479 + .extra1 = SYSCTL_ONE,
42480 + .extra2 = &init_net.sctp.rto_max
42481 + },
42482 +- {
42483 ++ [SCTP_RTO_MAX_IDX] = {
42484 + .procname = "rto_max",
42485 + .data = &init_net.sctp.rto_max,
42486 + .maxlen = sizeof(unsigned int),
42487 +@@ -112,6 +113,33 @@ static struct ctl_table sctp_net_table[] = {
42488 + .extra1 = &init_net.sctp.rto_min,
42489 + .extra2 = &timer_max
42490 + },
42491 ++ [SCTP_PF_RETRANS_IDX] = {
42492 ++ .procname = "pf_retrans",
42493 ++ .data = &init_net.sctp.pf_retrans,
42494 ++ .maxlen = sizeof(int),
42495 ++ .mode = 0644,
42496 ++ .proc_handler = proc_dointvec_minmax,
42497 ++ .extra1 = SYSCTL_ZERO,
42498 ++ .extra2 = &init_net.sctp.ps_retrans,
42499 ++ },
42500 ++ [SCTP_PS_RETRANS_IDX] = {
42501 ++ .procname = "ps_retrans",
42502 ++ .data = &init_net.sctp.ps_retrans,
42503 ++ .maxlen = sizeof(int),
42504 ++ .mode = 0644,
42505 ++ .proc_handler = proc_dointvec_minmax,
42506 ++ .extra1 = &init_net.sctp.pf_retrans,
42507 ++ .extra2 = &ps_retrans_max,
42508 ++ },
42509 ++ {
42510 ++ .procname = "rto_initial",
42511 ++ .data = &init_net.sctp.rto_initial,
42512 ++ .maxlen = sizeof(unsigned int),
42513 ++ .mode = 0644,
42514 ++ .proc_handler = proc_dointvec_minmax,
42515 ++ .extra1 = SYSCTL_ONE,
42516 ++ .extra2 = &timer_max
42517 ++ },
42518 + {
42519 + .procname = "rto_alpha_exp_divisor",
42520 + .data = &init_net.sctp.rto_alpha,
42521 +@@ -207,24 +235,6 @@ static struct ctl_table sctp_net_table[] = {
42522 + .extra1 = SYSCTL_ONE,
42523 + .extra2 = SYSCTL_INT_MAX,
42524 + },
42525 +- {
42526 +- .procname = "pf_retrans",
42527 +- .data = &init_net.sctp.pf_retrans,
42528 +- .maxlen = sizeof(int),
42529 +- .mode = 0644,
42530 +- .proc_handler = proc_dointvec_minmax,
42531 +- .extra1 = SYSCTL_ZERO,
42532 +- .extra2 = &init_net.sctp.ps_retrans,
42533 +- },
42534 +- {
42535 +- .procname = "ps_retrans",
42536 +- .data = &init_net.sctp.ps_retrans,
42537 +- .maxlen = sizeof(int),
42538 +- .mode = 0644,
42539 +- .proc_handler = proc_dointvec_minmax,
42540 +- .extra1 = &init_net.sctp.pf_retrans,
42541 +- .extra2 = &ps_retrans_max,
42542 +- },
42543 + {
42544 + .procname = "sndbuf_policy",
42545 + .data = &init_net.sctp.sndbuf_policy,
42546 +@@ -586,6 +596,11 @@ int sctp_sysctl_net_register(struct net *net)
42547 + for (i = 0; table[i].data; i++)
42548 + table[i].data += (char *)(&net->sctp) - (char *)&init_net.sctp;
42549 +
42550 ++ table[SCTP_RTO_MIN_IDX].extra2 = &net->sctp.rto_max;
42551 ++ table[SCTP_RTO_MAX_IDX].extra1 = &net->sctp.rto_min;
42552 ++ table[SCTP_PF_RETRANS_IDX].extra2 = &net->sctp.ps_retrans;
42553 ++ table[SCTP_PS_RETRANS_IDX].extra1 = &net->sctp.pf_retrans;
42554 ++
42555 + net->sctp.sysctl_header = register_net_sysctl(net, "net/sctp", table);
42556 + if (net->sctp.sysctl_header == NULL) {
42557 + kfree(table);
42558 +diff --git a/net/sunrpc/clnt.c b/net/sunrpc/clnt.c
42559 +index c284efa3d1efc..0918fa4cc9330 100644
42560 +--- a/net/sunrpc/clnt.c
42561 ++++ b/net/sunrpc/clnt.c
42562 +@@ -1391,7 +1391,7 @@ static int rpc_sockname(struct net *net, struct sockaddr *sap, size_t salen,
42563 + break;
42564 + default:
42565 + err = -EAFNOSUPPORT;
42566 +- goto out;
42567 ++ goto out_release;
42568 + }
42569 + if (err < 0) {
42570 + dprintk("RPC: can't bind UDP socket (%d)\n", err);
42571 +diff --git a/net/sunrpc/xprtrdma/verbs.c b/net/sunrpc/xprtrdma/verbs.c
42572 +index 2fbe9aaeec349..efa7bcdf6b283 100644
42573 +--- a/net/sunrpc/xprtrdma/verbs.c
42574 ++++ b/net/sunrpc/xprtrdma/verbs.c
42575 +@@ -834,7 +834,7 @@ struct rpcrdma_req *rpcrdma_req_create(struct rpcrdma_xprt *r_xprt, size_t size,
42576 + return req;
42577 +
42578 + out3:
42579 +- kfree(req->rl_sendbuf);
42580 ++ rpcrdma_regbuf_free(req->rl_sendbuf);
42581 + out2:
42582 + kfree(req);
42583 + out1:
42584 +diff --git a/net/tls/tls_sw.c b/net/tls/tls_sw.c
42585 +index fe27241cd13fc..0ee1df154fee0 100644
42586 +--- a/net/tls/tls_sw.c
42587 ++++ b/net/tls/tls_sw.c
42588 +@@ -792,7 +792,7 @@ static int bpf_exec_tx_verdict(struct sk_msg *msg, struct sock *sk,
42589 + struct sk_psock *psock;
42590 + struct sock *sk_redir;
42591 + struct tls_rec *rec;
42592 +- bool enospc, policy;
42593 ++ bool enospc, policy, redir_ingress;
42594 + int err = 0, send;
42595 + u32 delta = 0;
42596 +
42597 +@@ -837,6 +837,7 @@ more_data:
42598 + }
42599 + break;
42600 + case __SK_REDIRECT:
42601 ++ redir_ingress = psock->redir_ingress;
42602 + sk_redir = psock->sk_redir;
42603 + memcpy(&msg_redir, msg, sizeof(*msg));
42604 + if (msg->apply_bytes < send)
42605 +@@ -846,7 +847,8 @@ more_data:
42606 + sk_msg_return_zero(sk, msg, send);
42607 + msg->sg.size -= send;
42608 + release_sock(sk);
42609 +- err = tcp_bpf_sendmsg_redir(sk_redir, &msg_redir, send, flags);
42610 ++ err = tcp_bpf_sendmsg_redir(sk_redir, redir_ingress,
42611 ++ &msg_redir, send, flags);
42612 + lock_sock(sk);
42613 + if (err < 0) {
42614 + *copied -= sk_msg_free_nocharge(sk, &msg_redir);
42615 +diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
42616 +index d686804119c99..48cc8223b06be 100644
42617 +--- a/net/unix/af_unix.c
42618 ++++ b/net/unix/af_unix.c
42619 +@@ -1969,13 +1969,20 @@ restart_locked:
42620 + unix_state_lock(sk);
42621 +
42622 + err = 0;
42623 +- if (unix_peer(sk) == other) {
42624 ++ if (sk->sk_type == SOCK_SEQPACKET) {
42625 ++ /* We are here only when racing with unix_release_sock()
42626 ++ * is clearing @other. Never change state to TCP_CLOSE
42627 ++ * unlike SOCK_DGRAM wants.
42628 ++ */
42629 ++ unix_state_unlock(sk);
42630 ++ err = -EPIPE;
42631 ++ } else if (unix_peer(sk) == other) {
42632 + unix_peer(sk) = NULL;
42633 + unix_dgram_peer_wake_disconnect_wakeup(sk, other);
42634 +
42635 ++ sk->sk_state = TCP_CLOSE;
42636 + unix_state_unlock(sk);
42637 +
42638 +- sk->sk_state = TCP_CLOSE;
42639 + unix_dgram_disconnected(sk, other);
42640 + sock_put(other);
42641 + err = -ECONNREFUSED;
42642 +@@ -3724,6 +3731,7 @@ static int __init af_unix_init(void)
42643 + rc = proto_register(&unix_stream_proto, 1);
42644 + if (rc != 0) {
42645 + pr_crit("%s: Cannot create unix_sock SLAB cache!\n", __func__);
42646 ++ proto_unregister(&unix_dgram_proto);
42647 + goto out;
42648 + }
42649 +
42650 +diff --git a/net/vmw_vsock/vmci_transport.c b/net/vmw_vsock/vmci_transport.c
42651 +index b14f0ed7427bc..a794e8b011363 100644
42652 +--- a/net/vmw_vsock/vmci_transport.c
42653 ++++ b/net/vmw_vsock/vmci_transport.c
42654 +@@ -1711,7 +1711,11 @@ static int vmci_transport_dgram_enqueue(
42655 + if (!dg)
42656 + return -ENOMEM;
42657 +
42658 +- memcpy_from_msg(VMCI_DG_PAYLOAD(dg), msg, len);
42659 ++ err = memcpy_from_msg(VMCI_DG_PAYLOAD(dg), msg, len);
42660 ++ if (err) {
42661 ++ kfree(dg);
42662 ++ return err;
42663 ++ }
42664 +
42665 + dg->dst = vmci_make_handle(remote_addr->svm_cid,
42666 + remote_addr->svm_port);
42667 +diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c
42668 +index 2705e3ee8fc4e..3e41edace1ba7 100644
42669 +--- a/net/wireless/nl80211.c
42670 ++++ b/net/wireless/nl80211.c
42671 +@@ -3849,6 +3849,9 @@ static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flag
42672 + for_each_valid_link(wdev, link_id) {
42673 + struct nlattr *link = nla_nest_start(msg, link_id + 1);
42674 +
42675 ++ if (!link)
42676 ++ goto nla_put_failure;
42677 ++
42678 + if (nla_put_u8(msg, NL80211_ATTR_MLO_LINK_ID, link_id))
42679 + goto nla_put_failure;
42680 + if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN,
42681 +diff --git a/net/wireless/reg.c b/net/wireless/reg.c
42682 +index c3d950d294329..4f3f31244e8ba 100644
42683 +--- a/net/wireless/reg.c
42684 ++++ b/net/wireless/reg.c
42685 +@@ -4311,8 +4311,10 @@ static int __init regulatory_init_db(void)
42686 + return -EINVAL;
42687 +
42688 + err = load_builtin_regdb_keys();
42689 +- if (err)
42690 ++ if (err) {
42691 ++ platform_device_unregister(reg_pdev);
42692 + return err;
42693 ++ }
42694 +
42695 + /* We always try to get an update for the static regdomain */
42696 + err = regulatory_hint_core(cfg80211_world_regdom->alpha2);
42697 +diff --git a/samples/bpf/xdp1_user.c b/samples/bpf/xdp1_user.c
42698 +index ac370e638fa3d..281dc964de8da 100644
42699 +--- a/samples/bpf/xdp1_user.c
42700 ++++ b/samples/bpf/xdp1_user.c
42701 +@@ -51,7 +51,7 @@ static void poll_stats(int map_fd, int interval)
42702 +
42703 + sleep(interval);
42704 +
42705 +- while (bpf_map_get_next_key(map_fd, &key, &key) != -1) {
42706 ++ while (bpf_map_get_next_key(map_fd, &key, &key) == 0) {
42707 + __u64 sum = 0;
42708 +
42709 + assert(bpf_map_lookup_elem(map_fd, &key, values) == 0);
42710 +diff --git a/samples/bpf/xdp2_kern.c b/samples/bpf/xdp2_kern.c
42711 +index 3332ba6bb95fb..67804ecf7ce37 100644
42712 +--- a/samples/bpf/xdp2_kern.c
42713 ++++ b/samples/bpf/xdp2_kern.c
42714 +@@ -112,6 +112,10 @@ int xdp_prog1(struct xdp_md *ctx)
42715 +
42716 + if (ipproto == IPPROTO_UDP) {
42717 + swap_src_dst_mac(data);
42718 ++
42719 ++ if (bpf_xdp_store_bytes(ctx, 0, pkt, sizeof(pkt)))
42720 ++ return rc;
42721 ++
42722 + rc = XDP_TX;
42723 + }
42724 +
42725 +diff --git a/samples/vfio-mdev/mdpy-fb.c b/samples/vfio-mdev/mdpy-fb.c
42726 +index 9ec93d90e8a5a..4eb7aa11cfbb2 100644
42727 +--- a/samples/vfio-mdev/mdpy-fb.c
42728 ++++ b/samples/vfio-mdev/mdpy-fb.c
42729 +@@ -109,7 +109,7 @@ static int mdpy_fb_probe(struct pci_dev *pdev,
42730 +
42731 + ret = pci_request_regions(pdev, "mdpy-fb");
42732 + if (ret < 0)
42733 +- return ret;
42734 ++ goto err_disable_dev;
42735 +
42736 + pci_read_config_dword(pdev, MDPY_FORMAT_OFFSET, &format);
42737 + pci_read_config_dword(pdev, MDPY_WIDTH_OFFSET, &width);
42738 +@@ -191,6 +191,9 @@ err_release_fb:
42739 + err_release_regions:
42740 + pci_release_regions(pdev);
42741 +
42742 ++err_disable_dev:
42743 ++ pci_disable_device(pdev);
42744 ++
42745 + return ret;
42746 + }
42747 +
42748 +@@ -199,7 +202,10 @@ static void mdpy_fb_remove(struct pci_dev *pdev)
42749 + struct fb_info *info = pci_get_drvdata(pdev);
42750 +
42751 + unregister_framebuffer(info);
42752 ++ iounmap(info->screen_base);
42753 + framebuffer_release(info);
42754 ++ pci_release_regions(pdev);
42755 ++ pci_disable_device(pdev);
42756 + }
42757 +
42758 + static struct pci_device_id mdpy_fb_pci_table[] = {
42759 +diff --git a/security/Kconfig.hardening b/security/Kconfig.hardening
42760 +index 995bc42003e6c..254e07f34234c 100644
42761 +--- a/security/Kconfig.hardening
42762 ++++ b/security/Kconfig.hardening
42763 +@@ -253,6 +253,9 @@ config INIT_ON_FREE_DEFAULT_ON
42764 +
42765 + config CC_HAS_ZERO_CALL_USED_REGS
42766 + def_bool $(cc-option,-fzero-call-used-regs=used-gpr)
42767 ++ # https://github.com/ClangBuiltLinux/linux/issues/1766
42768 ++ # https://github.com/llvm/llvm-project/issues/59242
42769 ++ depends on !CC_IS_CLANG || CLANG_VERSION > 150006
42770 +
42771 + config ZERO_CALL_USED_REGS
42772 + bool "Enable register zeroing on function exit"
42773 +diff --git a/security/apparmor/apparmorfs.c b/security/apparmor/apparmorfs.c
42774 +index d066ccc219e2d..7160e7aa58b94 100644
42775 +--- a/security/apparmor/apparmorfs.c
42776 ++++ b/security/apparmor/apparmorfs.c
42777 +@@ -868,8 +868,10 @@ static struct multi_transaction *multi_transaction_new(struct file *file,
42778 + if (!t)
42779 + return ERR_PTR(-ENOMEM);
42780 + kref_init(&t->count);
42781 +- if (copy_from_user(t->data, buf, size))
42782 ++ if (copy_from_user(t->data, buf, size)) {
42783 ++ put_multi_transaction(t);
42784 + return ERR_PTR(-EFAULT);
42785 ++ }
42786 +
42787 + return t;
42788 + }
42789 +diff --git a/security/apparmor/label.c b/security/apparmor/label.c
42790 +index 0f36ee9074381..a67c5897ee254 100644
42791 +--- a/security/apparmor/label.c
42792 ++++ b/security/apparmor/label.c
42793 +@@ -197,15 +197,18 @@ static bool vec_is_stale(struct aa_profile **vec, int n)
42794 + return false;
42795 + }
42796 +
42797 +-static long union_vec_flags(struct aa_profile **vec, int n, long mask)
42798 ++static long accum_vec_flags(struct aa_profile **vec, int n)
42799 + {
42800 +- long u = 0;
42801 ++ long u = FLAG_UNCONFINED;
42802 + int i;
42803 +
42804 + AA_BUG(!vec);
42805 +
42806 + for (i = 0; i < n; i++) {
42807 +- u |= vec[i]->label.flags & mask;
42808 ++ u |= vec[i]->label.flags & (FLAG_DEBUG1 | FLAG_DEBUG2 |
42809 ++ FLAG_STALE);
42810 ++ if (!(u & vec[i]->label.flags & FLAG_UNCONFINED))
42811 ++ u &= ~FLAG_UNCONFINED;
42812 + }
42813 +
42814 + return u;
42815 +@@ -1097,8 +1100,7 @@ static struct aa_label *label_merge_insert(struct aa_label *new,
42816 + else if (k == b->size)
42817 + return aa_get_label(b);
42818 + }
42819 +- new->flags |= union_vec_flags(new->vec, new->size, FLAG_UNCONFINED |
42820 +- FLAG_DEBUG1 | FLAG_DEBUG2);
42821 ++ new->flags |= accum_vec_flags(new->vec, new->size);
42822 + ls = labels_set(new);
42823 + write_lock_irqsave(&ls->lock, flags);
42824 + label = __label_insert(labels_set(new), new, false);
42825 +diff --git a/security/apparmor/lsm.c b/security/apparmor/lsm.c
42826 +index e29cade7b6627..9eb7972e08e49 100644
42827 +--- a/security/apparmor/lsm.c
42828 ++++ b/security/apparmor/lsm.c
42829 +@@ -1194,10 +1194,10 @@ static int apparmor_inet_conn_request(const struct sock *sk, struct sk_buff *skb
42830 + #endif
42831 +
42832 + /*
42833 +- * The cred blob is a pointer to, not an instance of, an aa_task_ctx.
42834 ++ * The cred blob is a pointer to, not an instance of, an aa_label.
42835 + */
42836 + struct lsm_blob_sizes apparmor_blob_sizes __lsm_ro_after_init = {
42837 +- .lbs_cred = sizeof(struct aa_task_ctx *),
42838 ++ .lbs_cred = sizeof(struct aa_label *),
42839 + .lbs_file = sizeof(struct aa_file_ctx),
42840 + .lbs_task = sizeof(struct aa_task_ctx),
42841 + };
42842 +diff --git a/security/apparmor/policy.c b/security/apparmor/policy.c
42843 +index 499c0209b6a46..fbdfcef91c616 100644
42844 +--- a/security/apparmor/policy.c
42845 ++++ b/security/apparmor/policy.c
42846 +@@ -1170,7 +1170,7 @@ ssize_t aa_remove_profiles(struct aa_ns *policy_ns, struct aa_label *subj,
42847 +
42848 + if (!name) {
42849 + /* remove namespace - can only happen if fqname[0] == ':' */
42850 +- mutex_lock_nested(&ns->parent->lock, ns->level);
42851 ++ mutex_lock_nested(&ns->parent->lock, ns->parent->level);
42852 + __aa_bump_ns_revision(ns);
42853 + __aa_remove_ns(ns);
42854 + mutex_unlock(&ns->parent->lock);
42855 +diff --git a/security/apparmor/policy_ns.c b/security/apparmor/policy_ns.c
42856 +index 43beaad083feb..78700d94b4533 100644
42857 +--- a/security/apparmor/policy_ns.c
42858 ++++ b/security/apparmor/policy_ns.c
42859 +@@ -134,7 +134,7 @@ static struct aa_ns *alloc_ns(const char *prefix, const char *name)
42860 + return ns;
42861 +
42862 + fail_unconfined:
42863 +- kfree_sensitive(ns->base.hname);
42864 ++ aa_policy_destroy(&ns->base);
42865 + fail_ns:
42866 + kfree_sensitive(ns);
42867 + return NULL;
42868 +diff --git a/security/apparmor/policy_unpack.c b/security/apparmor/policy_unpack.c
42869 +index 55d31bac4f35b..9d26bbb901338 100644
42870 +--- a/security/apparmor/policy_unpack.c
42871 ++++ b/security/apparmor/policy_unpack.c
42872 +@@ -972,7 +972,7 @@ static int verify_header(struct aa_ext *e, int required, const char **ns)
42873 + * if not specified use previous version
42874 + * Mask off everything that is not kernel abi version
42875 + */
42876 +- if (VERSION_LT(e->version, v5) || VERSION_GT(e->version, v7)) {
42877 ++ if (VERSION_LT(e->version, v5) || VERSION_GT(e->version, v8)) {
42878 + audit_iface(NULL, NULL, NULL, "unsupported interface version",
42879 + e, error);
42880 + return error;
42881 +diff --git a/security/integrity/digsig.c b/security/integrity/digsig.c
42882 +index 8a82a6c7f48a4..f2193c531f4a4 100644
42883 +--- a/security/integrity/digsig.c
42884 ++++ b/security/integrity/digsig.c
42885 +@@ -126,6 +126,7 @@ int __init integrity_init_keyring(const unsigned int id)
42886 + {
42887 + struct key_restriction *restriction;
42888 + key_perm_t perm;
42889 ++ int ret;
42890 +
42891 + perm = (KEY_POS_ALL & ~KEY_POS_SETATTR) | KEY_USR_VIEW
42892 + | KEY_USR_READ | KEY_USR_SEARCH;
42893 +@@ -154,7 +155,10 @@ int __init integrity_init_keyring(const unsigned int id)
42894 + perm |= KEY_USR_WRITE;
42895 +
42896 + out:
42897 +- return __integrity_init_keyring(id, perm, restriction);
42898 ++ ret = __integrity_init_keyring(id, perm, restriction);
42899 ++ if (ret)
42900 ++ kfree(restriction);
42901 ++ return ret;
42902 + }
42903 +
42904 + static int __init integrity_add_key(const unsigned int id, const void *data,
42905 +diff --git a/security/integrity/ima/ima_policy.c b/security/integrity/ima/ima_policy.c
42906 +index a8802b8da946b..2edff7f58c25c 100644
42907 +--- a/security/integrity/ima/ima_policy.c
42908 ++++ b/security/integrity/ima/ima_policy.c
42909 +@@ -398,12 +398,6 @@ static struct ima_rule_entry *ima_lsm_copy_rule(struct ima_rule_entry *entry)
42910 +
42911 + nentry->lsm[i].type = entry->lsm[i].type;
42912 + nentry->lsm[i].args_p = entry->lsm[i].args_p;
42913 +- /*
42914 +- * Remove the reference from entry so that the associated
42915 +- * memory will not be freed during a later call to
42916 +- * ima_lsm_free_rule(entry).
42917 +- */
42918 +- entry->lsm[i].args_p = NULL;
42919 +
42920 + ima_filter_rule_init(nentry->lsm[i].type, Audit_equal,
42921 + nentry->lsm[i].args_p,
42922 +@@ -417,6 +411,7 @@ static struct ima_rule_entry *ima_lsm_copy_rule(struct ima_rule_entry *entry)
42923 +
42924 + static int ima_lsm_update_rule(struct ima_rule_entry *entry)
42925 + {
42926 ++ int i;
42927 + struct ima_rule_entry *nentry;
42928 +
42929 + nentry = ima_lsm_copy_rule(entry);
42930 +@@ -431,7 +426,8 @@ static int ima_lsm_update_rule(struct ima_rule_entry *entry)
42931 + * references and the entry itself. All other memory references will now
42932 + * be owned by nentry.
42933 + */
42934 +- ima_lsm_free_rule(entry);
42935 ++ for (i = 0; i < MAX_LSM_RULES; i++)
42936 ++ ima_filter_rule_free(entry->lsm[i].rule);
42937 + kfree(entry);
42938 +
42939 + return 0;
42940 +@@ -549,6 +545,9 @@ static bool ima_match_rules(struct ima_rule_entry *rule,
42941 + const char *func_data)
42942 + {
42943 + int i;
42944 ++ bool result = false;
42945 ++ struct ima_rule_entry *lsm_rule = rule;
42946 ++ bool rule_reinitialized = false;
42947 +
42948 + if ((rule->flags & IMA_FUNC) &&
42949 + (rule->func != func && func != POST_SETATTR))
42950 +@@ -610,35 +609,55 @@ static bool ima_match_rules(struct ima_rule_entry *rule,
42951 + int rc = 0;
42952 + u32 osid;
42953 +
42954 +- if (!rule->lsm[i].rule) {
42955 +- if (!rule->lsm[i].args_p)
42956 ++ if (!lsm_rule->lsm[i].rule) {
42957 ++ if (!lsm_rule->lsm[i].args_p)
42958 + continue;
42959 + else
42960 + return false;
42961 + }
42962 ++
42963 ++retry:
42964 + switch (i) {
42965 + case LSM_OBJ_USER:
42966 + case LSM_OBJ_ROLE:
42967 + case LSM_OBJ_TYPE:
42968 + security_inode_getsecid(inode, &osid);
42969 +- rc = ima_filter_rule_match(osid, rule->lsm[i].type,
42970 ++ rc = ima_filter_rule_match(osid, lsm_rule->lsm[i].type,
42971 + Audit_equal,
42972 +- rule->lsm[i].rule);
42973 ++ lsm_rule->lsm[i].rule);
42974 + break;
42975 + case LSM_SUBJ_USER:
42976 + case LSM_SUBJ_ROLE:
42977 + case LSM_SUBJ_TYPE:
42978 +- rc = ima_filter_rule_match(secid, rule->lsm[i].type,
42979 ++ rc = ima_filter_rule_match(secid, lsm_rule->lsm[i].type,
42980 + Audit_equal,
42981 +- rule->lsm[i].rule);
42982 ++ lsm_rule->lsm[i].rule);
42983 + break;
42984 + default:
42985 + break;
42986 + }
42987 +- if (!rc)
42988 +- return false;
42989 ++
42990 ++ if (rc == -ESTALE && !rule_reinitialized) {
42991 ++ lsm_rule = ima_lsm_copy_rule(rule);
42992 ++ if (lsm_rule) {
42993 ++ rule_reinitialized = true;
42994 ++ goto retry;
42995 ++ }
42996 ++ }
42997 ++ if (!rc) {
42998 ++ result = false;
42999 ++ goto out;
43000 ++ }
43001 + }
43002 +- return true;
43003 ++ result = true;
43004 ++
43005 ++out:
43006 ++ if (rule_reinitialized) {
43007 ++ for (i = 0; i < MAX_LSM_RULES; i++)
43008 ++ ima_filter_rule_free(lsm_rule->lsm[i].rule);
43009 ++ kfree(lsm_rule);
43010 ++ }
43011 ++ return result;
43012 + }
43013 +
43014 + /*
43015 +diff --git a/security/integrity/ima/ima_template.c b/security/integrity/ima/ima_template.c
43016 +index c25079faa2088..195ac18f09275 100644
43017 +--- a/security/integrity/ima/ima_template.c
43018 ++++ b/security/integrity/ima/ima_template.c
43019 +@@ -245,11 +245,11 @@ int template_desc_init_fields(const char *template_fmt,
43020 + }
43021 +
43022 + if (fields && num_fields) {
43023 +- *fields = kmalloc_array(i, sizeof(*fields), GFP_KERNEL);
43024 ++ *fields = kmalloc_array(i, sizeof(**fields), GFP_KERNEL);
43025 + if (*fields == NULL)
43026 + return -ENOMEM;
43027 +
43028 +- memcpy(*fields, found_fields, i * sizeof(*fields));
43029 ++ memcpy(*fields, found_fields, i * sizeof(**fields));
43030 + *num_fields = i;
43031 + }
43032 +
43033 +diff --git a/security/loadpin/loadpin.c b/security/loadpin/loadpin.c
43034 +index 44521582dcba2..d6767fddbd5a2 100644
43035 +--- a/security/loadpin/loadpin.c
43036 ++++ b/security/loadpin/loadpin.c
43037 +@@ -120,21 +120,11 @@ static void loadpin_sb_free_security(struct super_block *mnt_sb)
43038 + }
43039 + }
43040 +
43041 +-static int loadpin_read_file(struct file *file, enum kernel_read_file_id id,
43042 +- bool contents)
43043 ++static int loadpin_check(struct file *file, enum kernel_read_file_id id)
43044 + {
43045 + struct super_block *load_root;
43046 + const char *origin = kernel_read_file_id_str(id);
43047 +
43048 +- /*
43049 +- * If we will not know that we'll be seeing the full contents
43050 +- * then we cannot trust a load will be complete and unchanged
43051 +- * off disk. Treat all contents=false hooks as if there were
43052 +- * no associated file struct.
43053 +- */
43054 +- if (!contents)
43055 +- file = NULL;
43056 +-
43057 + /* If the file id is excluded, ignore the pinning. */
43058 + if ((unsigned int)id < ARRAY_SIZE(ignore_read_file_id) &&
43059 + ignore_read_file_id[id]) {
43060 +@@ -190,9 +180,25 @@ static int loadpin_read_file(struct file *file, enum kernel_read_file_id id,
43061 + return 0;
43062 + }
43063 +
43064 ++static int loadpin_read_file(struct file *file, enum kernel_read_file_id id,
43065 ++ bool contents)
43066 ++{
43067 ++ /*
43068 ++ * LoadPin only cares about the _origin_ of a file, not its
43069 ++ * contents, so we can ignore the "are full contents available"
43070 ++ * argument here.
43071 ++ */
43072 ++ return loadpin_check(file, id);
43073 ++}
43074 ++
43075 + static int loadpin_load_data(enum kernel_load_data_id id, bool contents)
43076 + {
43077 +- return loadpin_read_file(NULL, (enum kernel_read_file_id) id, contents);
43078 ++ /*
43079 ++ * LoadPin only cares about the _origin_ of a file, not its
43080 ++ * contents, so a NULL file is passed, and we can ignore the
43081 ++ * state of "contents".
43082 ++ */
43083 ++ return loadpin_check(NULL, (enum kernel_read_file_id) id);
43084 + }
43085 +
43086 + static struct security_hook_list loadpin_hooks[] __lsm_ro_after_init = {
43087 +diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
43088 +index ad0541e9e8880..ac985cec5c165 100644
43089 +--- a/sound/core/pcm_native.c
43090 ++++ b/sound/core/pcm_native.c
43091 +@@ -1432,8 +1432,10 @@ static int snd_pcm_do_start(struct snd_pcm_substream *substream,
43092 + static void snd_pcm_undo_start(struct snd_pcm_substream *substream,
43093 + snd_pcm_state_t state)
43094 + {
43095 +- if (substream->runtime->trigger_master == substream)
43096 ++ if (substream->runtime->trigger_master == substream) {
43097 + substream->ops->trigger(substream, SNDRV_PCM_TRIGGER_STOP);
43098 ++ substream->runtime->stop_operating = true;
43099 ++ }
43100 + }
43101 +
43102 + static void snd_pcm_post_start(struct snd_pcm_substream *substream,
43103 +diff --git a/sound/drivers/mts64.c b/sound/drivers/mts64.c
43104 +index d3bc9e8c407dc..f0d34cf70c3e0 100644
43105 +--- a/sound/drivers/mts64.c
43106 ++++ b/sound/drivers/mts64.c
43107 +@@ -815,6 +815,9 @@ static void snd_mts64_interrupt(void *private)
43108 + u8 status, data;
43109 + struct snd_rawmidi_substream *substream;
43110 +
43111 ++ if (!mts)
43112 ++ return;
43113 ++
43114 + spin_lock(&mts->lock);
43115 + ret = mts64_read(mts->pardev->port);
43116 + data = ret & 0x00ff;
43117 +diff --git a/sound/hda/hdac_stream.c b/sound/hda/hdac_stream.c
43118 +index f3582012d22f3..eea22cf72aefd 100644
43119 +--- a/sound/hda/hdac_stream.c
43120 ++++ b/sound/hda/hdac_stream.c
43121 +@@ -142,17 +142,28 @@ void snd_hdac_stream_stop(struct hdac_stream *azx_dev)
43122 + }
43123 + EXPORT_SYMBOL_GPL(snd_hdac_stream_stop);
43124 +
43125 ++/**
43126 ++ * snd_hdac_stop_streams - stop all streams
43127 ++ * @bus: HD-audio core bus
43128 ++ */
43129 ++void snd_hdac_stop_streams(struct hdac_bus *bus)
43130 ++{
43131 ++ struct hdac_stream *stream;
43132 ++
43133 ++ list_for_each_entry(stream, &bus->stream_list, list)
43134 ++ snd_hdac_stream_stop(stream);
43135 ++}
43136 ++EXPORT_SYMBOL_GPL(snd_hdac_stop_streams);
43137 ++
43138 + /**
43139 + * snd_hdac_stop_streams_and_chip - stop all streams and chip if running
43140 + * @bus: HD-audio core bus
43141 + */
43142 + void snd_hdac_stop_streams_and_chip(struct hdac_bus *bus)
43143 + {
43144 +- struct hdac_stream *stream;
43145 +
43146 + if (bus->chip_init) {
43147 +- list_for_each_entry(stream, &bus->stream_list, list)
43148 +- snd_hdac_stream_stop(stream);
43149 ++ snd_hdac_stop_streams(bus);
43150 + snd_hdac_bus_stop_chip(bus);
43151 + }
43152 + }
43153 +diff --git a/sound/pci/asihpi/hpioctl.c b/sound/pci/asihpi/hpioctl.c
43154 +index bb31b7fe867d6..477a5b4b50bcb 100644
43155 +--- a/sound/pci/asihpi/hpioctl.c
43156 ++++ b/sound/pci/asihpi/hpioctl.c
43157 +@@ -361,7 +361,7 @@ int asihpi_adapter_probe(struct pci_dev *pci_dev,
43158 + pci_dev->device, pci_dev->subsystem_vendor,
43159 + pci_dev->subsystem_device, pci_dev->devfn);
43160 +
43161 +- if (pci_enable_device(pci_dev) < 0) {
43162 ++ if (pcim_enable_device(pci_dev) < 0) {
43163 + dev_err(&pci_dev->dev,
43164 + "pci_enable_device failed, disabling device\n");
43165 + return -EIO;
43166 +diff --git a/sound/pci/hda/hda_codec.c b/sound/pci/hda/hda_codec.c
43167 +index 384426d7e9ddc..c853cba7fc2bf 100644
43168 +--- a/sound/pci/hda/hda_codec.c
43169 ++++ b/sound/pci/hda/hda_codec.c
43170 +@@ -2893,7 +2893,8 @@ static unsigned int hda_call_codec_suspend(struct hda_codec *codec)
43171 + snd_hdac_enter_pm(&codec->core);
43172 + if (codec->patch_ops.suspend)
43173 + codec->patch_ops.suspend(codec);
43174 +- hda_cleanup_all_streams(codec);
43175 ++ if (!codec->no_stream_clean_at_suspend)
43176 ++ hda_cleanup_all_streams(codec);
43177 + state = hda_set_power_state(codec, AC_PWRST_D3);
43178 + update_power_acct(codec, true);
43179 + snd_hdac_leave_pm(&codec->core);
43180 +diff --git a/sound/pci/hda/hda_controller.c b/sound/pci/hda/hda_controller.c
43181 +index 75dcb14ff20ad..0ff286b7b66be 100644
43182 +--- a/sound/pci/hda/hda_controller.c
43183 ++++ b/sound/pci/hda/hda_controller.c
43184 +@@ -1033,10 +1033,8 @@ EXPORT_SYMBOL_GPL(azx_init_chip);
43185 + void azx_stop_all_streams(struct azx *chip)
43186 + {
43187 + struct hdac_bus *bus = azx_bus(chip);
43188 +- struct hdac_stream *s;
43189 +
43190 +- list_for_each_entry(s, &bus->stream_list, list)
43191 +- snd_hdac_stream_stop(s);
43192 ++ snd_hdac_stop_streams(bus);
43193 + }
43194 + EXPORT_SYMBOL_GPL(azx_stop_all_streams);
43195 +
43196 +diff --git a/sound/pci/hda/patch_hdmi.c b/sound/pci/hda/patch_hdmi.c
43197 +index 287f4f78e7b1e..913509b29f938 100644
43198 +--- a/sound/pci/hda/patch_hdmi.c
43199 ++++ b/sound/pci/hda/patch_hdmi.c
43200 +@@ -167,8 +167,6 @@ struct hdmi_spec {
43201 + struct hdmi_ops ops;
43202 +
43203 + bool dyn_pin_out;
43204 +- bool dyn_pcm_assign;
43205 +- bool dyn_pcm_no_legacy;
43206 + /* hdmi interrupt trigger control flag for Nvidia codec */
43207 + bool hdmi_intr_trig_ctrl;
43208 + bool nv_dp_workaround; /* workaround DP audio infoframe for Nvidia */
43209 +@@ -1187,9 +1185,7 @@ static void pin_cvt_fixup(struct hda_codec *codec,
43210 + spec->ops.pin_cvt_fixup(codec, per_pin, cvt_nid);
43211 + }
43212 +
43213 +-/* called in hdmi_pcm_open when no pin is assigned to the PCM
43214 +- * in dyn_pcm_assign mode.
43215 +- */
43216 ++/* called in hdmi_pcm_open when no pin is assigned to the PCM */
43217 + static int hdmi_pcm_open_no_pin(struct hda_pcm_stream *hinfo,
43218 + struct hda_codec *codec,
43219 + struct snd_pcm_substream *substream)
43220 +@@ -1257,19 +1253,12 @@ static int hdmi_pcm_open(struct hda_pcm_stream *hinfo,
43221 +
43222 + mutex_lock(&spec->pcm_lock);
43223 + pin_idx = hinfo_to_pin_index(codec, hinfo);
43224 +- if (!spec->dyn_pcm_assign) {
43225 +- if (snd_BUG_ON(pin_idx < 0)) {
43226 +- err = -EINVAL;
43227 +- goto unlock;
43228 +- }
43229 +- } else {
43230 +- /* no pin is assigned to the PCM
43231 +- * PA need pcm open successfully when probe
43232 +- */
43233 +- if (pin_idx < 0) {
43234 +- err = hdmi_pcm_open_no_pin(hinfo, codec, substream);
43235 +- goto unlock;
43236 +- }
43237 ++ /* no pin is assigned to the PCM
43238 ++ * PA need pcm open successfully when probe
43239 ++ */
43240 ++ if (pin_idx < 0) {
43241 ++ err = hdmi_pcm_open_no_pin(hinfo, codec, substream);
43242 ++ goto unlock;
43243 + }
43244 +
43245 + err = hdmi_choose_cvt(codec, pin_idx, &cvt_idx, false);
43246 +@@ -1374,43 +1363,6 @@ static int hdmi_find_pcm_slot(struct hdmi_spec *spec,
43247 + {
43248 + int i;
43249 +
43250 +- /* on the new machines, try to assign the pcm slot dynamically,
43251 +- * not use the preferred fixed map (legacy way) anymore.
43252 +- */
43253 +- if (spec->dyn_pcm_no_legacy)
43254 +- goto last_try;
43255 +-
43256 +- /*
43257 +- * generic_hdmi_build_pcms() may allocate extra PCMs on some
43258 +- * platforms (with maximum of 'num_nids + dev_num - 1')
43259 +- *
43260 +- * The per_pin of pin_nid_idx=n and dev_id=m prefers to get pcm-n
43261 +- * if m==0. This guarantees that dynamic pcm assignments are compatible
43262 +- * with the legacy static per_pin-pcm assignment that existed in the
43263 +- * days before DP-MST.
43264 +- *
43265 +- * Intel DP-MST prefers this legacy behavior for compatibility, too.
43266 +- *
43267 +- * per_pin of m!=0 prefers to get pcm=(num_nids + (m - 1)).
43268 +- */
43269 +-
43270 +- if (per_pin->dev_id == 0 || spec->intel_hsw_fixup) {
43271 +- if (!test_bit(per_pin->pin_nid_idx, &spec->pcm_bitmap))
43272 +- return per_pin->pin_nid_idx;
43273 +- } else {
43274 +- i = spec->num_nids + (per_pin->dev_id - 1);
43275 +- if (i < spec->pcm_used && !(test_bit(i, &spec->pcm_bitmap)))
43276 +- return i;
43277 +- }
43278 +-
43279 +- /* have a second try; check the area over num_nids */
43280 +- for (i = spec->num_nids; i < spec->pcm_used; i++) {
43281 +- if (!test_bit(i, &spec->pcm_bitmap))
43282 +- return i;
43283 +- }
43284 +-
43285 +- last_try:
43286 +- /* the last try; check the empty slots in pins */
43287 + for (i = 0; i < spec->pcm_used; i++) {
43288 + if (!test_bit(i, &spec->pcm_bitmap))
43289 + return i;
43290 +@@ -1573,14 +1525,12 @@ static void update_eld(struct hda_codec *codec,
43291 + */
43292 + pcm_jack = pin_idx_to_pcm_jack(codec, per_pin);
43293 +
43294 +- if (spec->dyn_pcm_assign) {
43295 +- if (eld->eld_valid) {
43296 +- hdmi_attach_hda_pcm(spec, per_pin);
43297 +- hdmi_pcm_setup_pin(spec, per_pin);
43298 +- } else {
43299 +- hdmi_pcm_reset_pin(spec, per_pin);
43300 +- hdmi_detach_hda_pcm(spec, per_pin);
43301 +- }
43302 ++ if (eld->eld_valid) {
43303 ++ hdmi_attach_hda_pcm(spec, per_pin);
43304 ++ hdmi_pcm_setup_pin(spec, per_pin);
43305 ++ } else {
43306 ++ hdmi_pcm_reset_pin(spec, per_pin);
43307 ++ hdmi_detach_hda_pcm(spec, per_pin);
43308 + }
43309 + /* if pcm_idx == -1, it means this is in monitor connection event
43310 + * we can get the correct pcm_idx now.
43311 +@@ -1788,6 +1738,7 @@ static void silent_stream_enable(struct hda_codec *codec,
43312 +
43313 + switch (spec->silent_stream_type) {
43314 + case SILENT_STREAM_KAE:
43315 ++ silent_stream_enable_i915(codec, per_pin);
43316 + silent_stream_set_kae(codec, per_pin, true);
43317 + break;
43318 + case SILENT_STREAM_I915:
43319 +@@ -1942,7 +1893,7 @@ static int hdmi_add_pin(struct hda_codec *codec, hda_nid_t pin_nid)
43320 + * structures based on worst case.
43321 + */
43322 + dev_num = spec->dev_num;
43323 +- } else if (spec->dyn_pcm_assign && codec->dp_mst) {
43324 ++ } else if (codec->dp_mst) {
43325 + dev_num = snd_hda_get_num_devices(codec, pin_nid) + 1;
43326 + /*
43327 + * spec->dev_num is the maxinum number of device entries
43328 +@@ -1967,13 +1918,8 @@ static int hdmi_add_pin(struct hda_codec *codec, hda_nid_t pin_nid)
43329 + if (!per_pin)
43330 + return -ENOMEM;
43331 +
43332 +- if (spec->dyn_pcm_assign) {
43333 +- per_pin->pcm = NULL;
43334 +- per_pin->pcm_idx = -1;
43335 +- } else {
43336 +- per_pin->pcm = get_hdmi_pcm(spec, pin_idx);
43337 +- per_pin->pcm_idx = pin_idx;
43338 +- }
43339 ++ per_pin->pcm = NULL;
43340 ++ per_pin->pcm_idx = -1;
43341 + per_pin->pin_nid = pin_nid;
43342 + per_pin->pin_nid_idx = spec->num_nids;
43343 + per_pin->dev_id = i;
43344 +@@ -1982,6 +1928,8 @@ static int hdmi_add_pin(struct hda_codec *codec, hda_nid_t pin_nid)
43345 + err = hdmi_read_pin_conn(codec, pin_idx);
43346 + if (err < 0)
43347 + return err;
43348 ++ if (!is_jack_detectable(codec, pin_nid))
43349 ++ codec_warn(codec, "HDMI: pin NID 0x%x - jack not detectable\n", pin_nid);
43350 + spec->num_pins++;
43351 + }
43352 + spec->num_nids++;
43353 +@@ -2028,6 +1976,7 @@ static int hdmi_add_cvt(struct hda_codec *codec, hda_nid_t cvt_nid)
43354 + static const struct snd_pci_quirk force_connect_list[] = {
43355 + SND_PCI_QUIRK(0x103c, 0x870f, "HP", 1),
43356 + SND_PCI_QUIRK(0x103c, 0x871a, "HP", 1),
43357 ++ SND_PCI_QUIRK(0x103c, 0x8711, "HP", 1),
43358 + SND_PCI_QUIRK(0x1462, 0xec94, "MS-7C94", 1),
43359 + SND_PCI_QUIRK(0x8086, 0x2081, "Intel NUC 10", 1),
43360 + {}
43361 +@@ -2129,10 +2078,9 @@ static int generic_hdmi_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
43362 +
43363 + mutex_lock(&spec->pcm_lock);
43364 + pin_idx = hinfo_to_pin_index(codec, hinfo);
43365 +- if (spec->dyn_pcm_assign && pin_idx < 0) {
43366 +- /* when dyn_pcm_assign and pcm is not bound to a pin
43367 +- * skip pin setup and return 0 to make audio playback
43368 +- * be ongoing
43369 ++ if (pin_idx < 0) {
43370 ++ /* when pcm is not bound to a pin skip pin setup and return 0
43371 ++ * to make audio playback be ongoing
43372 + */
43373 + pin_cvt_fixup(codec, NULL, cvt_nid);
43374 + snd_hda_codec_setup_stream(codec, cvt_nid,
43375 +@@ -2235,7 +2183,7 @@ static int hdmi_pcm_close(struct hda_pcm_stream *hinfo,
43376 + snd_hda_spdif_ctls_unassign(codec, pcm_idx);
43377 + clear_bit(pcm_idx, &spec->pcm_in_use);
43378 + pin_idx = hinfo_to_pin_index(codec, hinfo);
43379 +- if (spec->dyn_pcm_assign && pin_idx < 0)
43380 ++ if (pin_idx < 0)
43381 + goto unlock;
43382 +
43383 + if (snd_BUG_ON(pin_idx < 0)) {
43384 +@@ -2333,21 +2281,8 @@ static int generic_hdmi_build_pcms(struct hda_codec *codec)
43385 + struct hdmi_spec *spec = codec->spec;
43386 + int idx, pcm_num;
43387 +
43388 +- /*
43389 +- * for non-mst mode, pcm number is the same as before
43390 +- * for DP MST mode without extra PCM, pcm number is same
43391 +- * for DP MST mode with extra PCMs, pcm number is
43392 +- * (nid number + dev_num - 1)
43393 +- * dev_num is the device entry number in a pin
43394 +- */
43395 +-
43396 +- if (spec->dyn_pcm_no_legacy && codec->mst_no_extra_pcms)
43397 +- pcm_num = spec->num_cvts;
43398 +- else if (codec->mst_no_extra_pcms)
43399 +- pcm_num = spec->num_nids;
43400 +- else
43401 +- pcm_num = spec->num_nids + spec->dev_num - 1;
43402 +-
43403 ++ /* limit the PCM devices to the codec converters */
43404 ++ pcm_num = spec->num_cvts;
43405 + codec_dbg(codec, "hdmi: pcm_num set to %d\n", pcm_num);
43406 +
43407 + for (idx = 0; idx < pcm_num; idx++) {
43408 +@@ -2386,17 +2321,12 @@ static int generic_hdmi_build_jack(struct hda_codec *codec, int pcm_idx)
43409 + {
43410 + char hdmi_str[32] = "HDMI/DP";
43411 + struct hdmi_spec *spec = codec->spec;
43412 +- struct hdmi_spec_per_pin *per_pin = get_pin(spec, pcm_idx);
43413 + struct snd_jack *jack;
43414 + int pcmdev = get_pcm_rec(spec, pcm_idx)->device;
43415 + int err;
43416 +
43417 + if (pcmdev > 0)
43418 + sprintf(hdmi_str + strlen(hdmi_str), ",pcm=%d", pcmdev);
43419 +- if (!spec->dyn_pcm_assign &&
43420 +- !is_jack_detectable(codec, per_pin->pin_nid))
43421 +- strncat(hdmi_str, " Phantom",
43422 +- sizeof(hdmi_str) - strlen(hdmi_str) - 1);
43423 +
43424 + err = snd_jack_new(codec->card, hdmi_str, SND_JACK_AVOUT, &jack,
43425 + true, false);
43426 +@@ -2429,18 +2359,9 @@ static int generic_hdmi_build_controls(struct hda_codec *codec)
43427 + /* create the spdif for each pcm
43428 + * pin will be bound when monitor is connected
43429 + */
43430 +- if (spec->dyn_pcm_assign)
43431 +- err = snd_hda_create_dig_out_ctls(codec,
43432 ++ err = snd_hda_create_dig_out_ctls(codec,
43433 + 0, spec->cvt_nids[0],
43434 + HDA_PCM_TYPE_HDMI);
43435 +- else {
43436 +- struct hdmi_spec_per_pin *per_pin =
43437 +- get_pin(spec, pcm_idx);
43438 +- err = snd_hda_create_dig_out_ctls(codec,
43439 +- per_pin->pin_nid,
43440 +- per_pin->mux_nids[0],
43441 +- HDA_PCM_TYPE_HDMI);
43442 +- }
43443 + if (err < 0)
43444 + return err;
43445 + snd_hda_spdif_ctls_unassign(codec, pcm_idx);
43446 +@@ -2560,11 +2481,7 @@ static void generic_hdmi_free(struct hda_codec *codec)
43447 + for (pcm_idx = 0; pcm_idx < spec->pcm_used; pcm_idx++) {
43448 + if (spec->pcm_rec[pcm_idx].jack == NULL)
43449 + continue;
43450 +- if (spec->dyn_pcm_assign)
43451 +- snd_device_free(codec->card,
43452 +- spec->pcm_rec[pcm_idx].jack);
43453 +- else
43454 +- spec->pcm_rec[pcm_idx].jack = NULL;
43455 ++ snd_device_free(codec->card, spec->pcm_rec[pcm_idx].jack);
43456 + }
43457 +
43458 + generic_spec_free(codec);
43459 +@@ -2963,9 +2880,33 @@ static int i915_hsw_setup_stream(struct hda_codec *codec, hda_nid_t cvt_nid,
43460 + hda_nid_t pin_nid, int dev_id, u32 stream_tag,
43461 + int format)
43462 + {
43463 ++ struct hdmi_spec *spec = codec->spec;
43464 ++ int pin_idx = pin_id_to_pin_index(codec, pin_nid, dev_id);
43465 ++ struct hdmi_spec_per_pin *per_pin;
43466 ++ int res;
43467 ++
43468 ++ if (pin_idx < 0)
43469 ++ per_pin = NULL;
43470 ++ else
43471 ++ per_pin = get_pin(spec, pin_idx);
43472 ++
43473 + haswell_verify_D0(codec, cvt_nid, pin_nid);
43474 +- return hdmi_setup_stream(codec, cvt_nid, pin_nid, dev_id,
43475 +- stream_tag, format);
43476 ++
43477 ++ if (spec->silent_stream_type == SILENT_STREAM_KAE && per_pin && per_pin->silent_stream) {
43478 ++ silent_stream_set_kae(codec, per_pin, false);
43479 ++ /* wait for pending transfers in codec to clear */
43480 ++ usleep_range(100, 200);
43481 ++ }
43482 ++
43483 ++ res = hdmi_setup_stream(codec, cvt_nid, pin_nid, dev_id,
43484 ++ stream_tag, format);
43485 ++
43486 ++ if (spec->silent_stream_type == SILENT_STREAM_KAE && per_pin && per_pin->silent_stream) {
43487 ++ usleep_range(100, 200);
43488 ++ silent_stream_set_kae(codec, per_pin, true);
43489 ++ }
43490 ++
43491 ++ return res;
43492 + }
43493 +
43494 + /* pin_cvt_fixup ops override for HSW+ and VLV+ */
43495 +@@ -2985,6 +2926,88 @@ static void i915_pin_cvt_fixup(struct hda_codec *codec,
43496 + }
43497 + }
43498 +
43499 ++#ifdef CONFIG_PM
43500 ++static int i915_adlp_hdmi_suspend(struct hda_codec *codec)
43501 ++{
43502 ++ struct hdmi_spec *spec = codec->spec;
43503 ++ bool silent_streams = false;
43504 ++ int pin_idx, res;
43505 ++
43506 ++ res = generic_hdmi_suspend(codec);
43507 ++
43508 ++ for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {
43509 ++ struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx);
43510 ++
43511 ++ if (per_pin->silent_stream) {
43512 ++ silent_streams = true;
43513 ++ break;
43514 ++ }
43515 ++ }
43516 ++
43517 ++ if (silent_streams && spec->silent_stream_type == SILENT_STREAM_KAE) {
43518 ++ /*
43519 ++ * stream-id should remain programmed when codec goes
43520 ++ * to runtime suspend
43521 ++ */
43522 ++ codec->no_stream_clean_at_suspend = 1;
43523 ++
43524 ++ /*
43525 ++ * the system might go to S3, in which case keep-alive
43526 ++ * must be reprogrammed upon resume
43527 ++ */
43528 ++ codec->forced_resume = 1;
43529 ++
43530 ++ codec_dbg(codec, "HDMI: KAE active at suspend\n");
43531 ++ } else {
43532 ++ codec->no_stream_clean_at_suspend = 0;
43533 ++ codec->forced_resume = 0;
43534 ++ }
43535 ++
43536 ++ return res;
43537 ++}
43538 ++
43539 ++static int i915_adlp_hdmi_resume(struct hda_codec *codec)
43540 ++{
43541 ++ struct hdmi_spec *spec = codec->spec;
43542 ++ int pin_idx, res;
43543 ++
43544 ++ res = generic_hdmi_resume(codec);
43545 ++
43546 ++ /* KAE not programmed at suspend, nothing to do here */
43547 ++ if (!codec->no_stream_clean_at_suspend)
43548 ++ return res;
43549 ++
43550 ++ for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {
43551 ++ struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx);
43552 ++
43553 ++ /*
43554 ++ * If system was in suspend with monitor connected,
43555 ++ * the codec setting may have been lost. Re-enable
43556 ++ * keep-alive.
43557 ++ */
43558 ++ if (per_pin->silent_stream) {
43559 ++ unsigned int param;
43560 ++
43561 ++ param = snd_hda_codec_read(codec, per_pin->cvt_nid, 0,
43562 ++ AC_VERB_GET_CONV, 0);
43563 ++ if (!param) {
43564 ++ codec_dbg(codec, "HDMI: KAE: restore stream id\n");
43565 ++ silent_stream_enable_i915(codec, per_pin);
43566 ++ }
43567 ++
43568 ++ param = snd_hda_codec_read(codec, per_pin->cvt_nid, 0,
43569 ++ AC_VERB_GET_DIGI_CONVERT_1, 0);
43570 ++ if (!(param & (AC_DIG3_KAE << 16))) {
43571 ++ codec_dbg(codec, "HDMI: KAE: restore DIG3_KAE\n");
43572 ++ silent_stream_set_kae(codec, per_pin, true);
43573 ++ }
43574 ++ }
43575 ++ }
43576 ++
43577 ++ return res;
43578 ++}
43579 ++#endif
43580 ++
43581 + /* precondition and allocation for Intel codecs */
43582 + static int alloc_intel_hdmi(struct hda_codec *codec)
43583 + {
43584 +@@ -3038,7 +3061,6 @@ static int intel_hsw_common_init(struct hda_codec *codec, hda_nid_t vendor_nid,
43585 + return err;
43586 + spec = codec->spec;
43587 + codec->dp_mst = true;
43588 +- spec->dyn_pcm_assign = true;
43589 + spec->vendor_nid = vendor_nid;
43590 + spec->port_map = port_map;
43591 + spec->port_num = port_num;
43592 +@@ -3102,17 +3124,9 @@ static int patch_i915_tgl_hdmi(struct hda_codec *codec)
43593 + * the index indicate the port number.
43594 + */
43595 + static const int map[] = {0x4, 0x6, 0x8, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf};
43596 +- int ret;
43597 +-
43598 +- ret = intel_hsw_common_init(codec, 0x02, map, ARRAY_SIZE(map), 4,
43599 +- enable_silent_stream);
43600 +- if (!ret) {
43601 +- struct hdmi_spec *spec = codec->spec;
43602 +
43603 +- spec->dyn_pcm_no_legacy = true;
43604 +- }
43605 +-
43606 +- return ret;
43607 ++ return intel_hsw_common_init(codec, 0x02, map, ARRAY_SIZE(map), 4,
43608 ++ enable_silent_stream);
43609 + }
43610 +
43611 + static int patch_i915_adlp_hdmi(struct hda_codec *codec)
43612 +@@ -3124,8 +3138,14 @@ static int patch_i915_adlp_hdmi(struct hda_codec *codec)
43613 + if (!res) {
43614 + spec = codec->spec;
43615 +
43616 +- if (spec->silent_stream_type)
43617 ++ if (spec->silent_stream_type) {
43618 + spec->silent_stream_type = SILENT_STREAM_KAE;
43619 ++
43620 ++#ifdef CONFIG_PM
43621 ++ codec->patch_ops.resume = i915_adlp_hdmi_resume;
43622 ++ codec->patch_ops.suspend = i915_adlp_hdmi_suspend;
43623 ++#endif
43624 ++ }
43625 + }
43626 +
43627 + return res;
43628 +@@ -3752,7 +3772,6 @@ static int patch_nvhdmi(struct hda_codec *codec)
43629 + codec->dp_mst = true;
43630 +
43631 + spec = codec->spec;
43632 +- spec->dyn_pcm_assign = true;
43633 +
43634 + err = hdmi_parse_codec(codec);
43635 + if (err < 0) {
43636 +@@ -4032,10 +4051,8 @@ static int patch_tegra234_hdmi(struct hda_codec *codec)
43637 + return err;
43638 +
43639 + codec->dp_mst = true;
43640 +- codec->mst_no_extra_pcms = true;
43641 + spec = codec->spec;
43642 + spec->dyn_pin_out = true;
43643 +- spec->dyn_pcm_assign = true;
43644 + spec->hdmi_intr_trig_ctrl = true;
43645 +
43646 + return tegra_hdmi_init(codec);
43647 +diff --git a/sound/pci/hda/patch_realtek.c b/sound/pci/hda/patch_realtek.c
43648 +index ce6ea8819562b..94fe842178947 100644
43649 +--- a/sound/pci/hda/patch_realtek.c
43650 ++++ b/sound/pci/hda/patch_realtek.c
43651 +@@ -10984,6 +10984,17 @@ static void alc897_fixup_lenovo_headset_mic(struct hda_codec *codec,
43652 + }
43653 + }
43654 +
43655 ++static void alc897_fixup_lenovo_headset_mode(struct hda_codec *codec,
43656 ++ const struct hda_fixup *fix, int action)
43657 ++{
43658 ++ struct alc_spec *spec = codec->spec;
43659 ++
43660 ++ if (action == HDA_FIXUP_ACT_PRE_PROBE) {
43661 ++ spec->parse_flags |= HDA_PINCFG_HEADSET_MIC;
43662 ++ spec->gen.hp_automute_hook = alc897_hp_automute_hook;
43663 ++ }
43664 ++}
43665 ++
43666 + static const struct coef_fw alc668_coefs[] = {
43667 + WRITE_COEF(0x01, 0xbebe), WRITE_COEF(0x02, 0xaaaa), WRITE_COEF(0x03, 0x0),
43668 + WRITE_COEF(0x04, 0x0180), WRITE_COEF(0x06, 0x0), WRITE_COEF(0x07, 0x0f80),
43669 +@@ -11067,6 +11078,8 @@ enum {
43670 + ALC897_FIXUP_LENOVO_HEADSET_MIC,
43671 + ALC897_FIXUP_HEADSET_MIC_PIN,
43672 + ALC897_FIXUP_HP_HSMIC_VERB,
43673 ++ ALC897_FIXUP_LENOVO_HEADSET_MODE,
43674 ++ ALC897_FIXUP_HEADSET_MIC_PIN2,
43675 + };
43676 +
43677 + static const struct hda_fixup alc662_fixups[] = {
43678 +@@ -11493,6 +11506,19 @@ static const struct hda_fixup alc662_fixups[] = {
43679 + { }
43680 + },
43681 + },
43682 ++ [ALC897_FIXUP_LENOVO_HEADSET_MODE] = {
43683 ++ .type = HDA_FIXUP_FUNC,
43684 ++ .v.func = alc897_fixup_lenovo_headset_mode,
43685 ++ },
43686 ++ [ALC897_FIXUP_HEADSET_MIC_PIN2] = {
43687 ++ .type = HDA_FIXUP_PINS,
43688 ++ .v.pins = (const struct hda_pintbl[]) {
43689 ++ { 0x1a, 0x01a11140 }, /* use as headset mic, without its own jack detect */
43690 ++ { }
43691 ++ },
43692 ++ .chained = true,
43693 ++ .chain_id = ALC897_FIXUP_LENOVO_HEADSET_MODE
43694 ++ },
43695 + };
43696 +
43697 + static const struct snd_pci_quirk alc662_fixup_tbl[] = {
43698 +@@ -11545,6 +11571,7 @@ static const struct snd_pci_quirk alc662_fixup_tbl[] = {
43699 + SND_PCI_QUIRK(0x17aa, 0x32cb, "Lenovo ThinkCentre M70", ALC897_FIXUP_HEADSET_MIC_PIN),
43700 + SND_PCI_QUIRK(0x17aa, 0x32cf, "Lenovo ThinkCentre M950", ALC897_FIXUP_HEADSET_MIC_PIN),
43701 + SND_PCI_QUIRK(0x17aa, 0x32f7, "Lenovo ThinkCentre M90", ALC897_FIXUP_HEADSET_MIC_PIN),
43702 ++ SND_PCI_QUIRK(0x17aa, 0x3742, "Lenovo TianYi510Pro-14IOB", ALC897_FIXUP_HEADSET_MIC_PIN2),
43703 + SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo Ideapad Y550P", ALC662_FIXUP_IDEAPAD),
43704 + SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Ideapad Y550", ALC662_FIXUP_IDEAPAD),
43705 + SND_PCI_QUIRK(0x1849, 0x5892, "ASRock B150M", ALC892_FIXUP_ASROCK_MOBO),
43706 +diff --git a/sound/soc/amd/yc/acp6x-mach.c b/sound/soc/amd/yc/acp6x-mach.c
43707 +index d9715bea965e1..1f0b5527c5949 100644
43708 +--- a/sound/soc/amd/yc/acp6x-mach.c
43709 ++++ b/sound/soc/amd/yc/acp6x-mach.c
43710 +@@ -213,6 +213,13 @@ static const struct dmi_system_id yc_acp_quirk_table[] = {
43711 + DMI_MATCH(DMI_PRODUCT_NAME, "Alienware m17 R5 AMD"),
43712 + }
43713 + },
43714 ++ {
43715 ++ .driver_data = &acp6x_card,
43716 ++ .matches = {
43717 ++ DMI_MATCH(DMI_BOARD_VENDOR, "TIMI"),
43718 ++ DMI_MATCH(DMI_PRODUCT_NAME, "Redmi Book Pro 14 2022"),
43719 ++ }
43720 ++ },
43721 + {}
43722 + };
43723 +
43724 +diff --git a/sound/soc/codecs/hda.c b/sound/soc/codecs/hda.c
43725 +index ad20a3dff9b7e..61e8e9be6b8d7 100644
43726 +--- a/sound/soc/codecs/hda.c
43727 ++++ b/sound/soc/codecs/hda.c
43728 +@@ -224,9 +224,6 @@ static int hda_codec_probe(struct snd_soc_component *component)
43729 + goto err;
43730 + }
43731 +
43732 +- /* configure codec for 1:1 PCM:DAI mapping */
43733 +- codec->mst_no_extra_pcms = 1;
43734 +-
43735 + ret = snd_hda_codec_parse_pcms(codec);
43736 + if (ret < 0) {
43737 + dev_err(&hdev->dev, "unable to map pcms to dai %d\n", ret);
43738 +diff --git a/sound/soc/codecs/hdac_hda.c b/sound/soc/codecs/hdac_hda.c
43739 +index 8debcee592247..7876bdd558a7a 100644
43740 +--- a/sound/soc/codecs/hdac_hda.c
43741 ++++ b/sound/soc/codecs/hdac_hda.c
43742 +@@ -461,9 +461,6 @@ static int hdac_hda_codec_probe(struct snd_soc_component *component)
43743 + dev_dbg(&hdev->dev, "no patch file found\n");
43744 + }
43745 +
43746 +- /* configure codec for 1:1 PCM:DAI mapping */
43747 +- hcodec->mst_no_extra_pcms = 1;
43748 +-
43749 + ret = snd_hda_codec_parse_pcms(hcodec);
43750 + if (ret < 0) {
43751 + dev_err(&hdev->dev, "unable to map pcms to dai %d\n", ret);
43752 +diff --git a/sound/soc/codecs/pcm512x.c b/sound/soc/codecs/pcm512x.c
43753 +index 767463e82665c..89059a673cf09 100644
43754 +--- a/sound/soc/codecs/pcm512x.c
43755 ++++ b/sound/soc/codecs/pcm512x.c
43756 +@@ -1634,7 +1634,7 @@ int pcm512x_probe(struct device *dev, struct regmap *regmap)
43757 + if (val > 6) {
43758 + dev_err(dev, "Invalid pll-in\n");
43759 + ret = -EINVAL;
43760 +- goto err_clk;
43761 ++ goto err_pm;
43762 + }
43763 + pcm512x->pll_in = val;
43764 + }
43765 +@@ -1643,7 +1643,7 @@ int pcm512x_probe(struct device *dev, struct regmap *regmap)
43766 + if (val > 6) {
43767 + dev_err(dev, "Invalid pll-out\n");
43768 + ret = -EINVAL;
43769 +- goto err_clk;
43770 ++ goto err_pm;
43771 + }
43772 + pcm512x->pll_out = val;
43773 + }
43774 +@@ -1652,12 +1652,12 @@ int pcm512x_probe(struct device *dev, struct regmap *regmap)
43775 + dev_err(dev,
43776 + "Error: both pll-in and pll-out, or none\n");
43777 + ret = -EINVAL;
43778 +- goto err_clk;
43779 ++ goto err_pm;
43780 + }
43781 + if (pcm512x->pll_in && pcm512x->pll_in == pcm512x->pll_out) {
43782 + dev_err(dev, "Error: pll-in == pll-out\n");
43783 + ret = -EINVAL;
43784 +- goto err_clk;
43785 ++ goto err_pm;
43786 + }
43787 + }
43788 + #endif
43789 +diff --git a/sound/soc/codecs/rt298.c b/sound/soc/codecs/rt298.c
43790 +index b0b53d4f07df9..5f36064ed6e6f 100644
43791 +--- a/sound/soc/codecs/rt298.c
43792 ++++ b/sound/soc/codecs/rt298.c
43793 +@@ -1166,6 +1166,13 @@ static const struct dmi_system_id force_combo_jack_table[] = {
43794 + DMI_MATCH(DMI_PRODUCT_NAME, "Geminilake")
43795 + }
43796 + },
43797 ++ {
43798 ++ .ident = "Intel Kabylake R RVP",
43799 ++ .matches = {
43800 ++ DMI_MATCH(DMI_SYS_VENDOR, "Intel Corporation"),
43801 ++ DMI_MATCH(DMI_PRODUCT_NAME, "Kabylake Client platform")
43802 ++ }
43803 ++ },
43804 + { }
43805 + };
43806 +
43807 +diff --git a/sound/soc/codecs/rt5670.c b/sound/soc/codecs/rt5670.c
43808 +index 60dbfa2a54f1b..c75045e371b20 100644
43809 +--- a/sound/soc/codecs/rt5670.c
43810 ++++ b/sound/soc/codecs/rt5670.c
43811 +@@ -3311,8 +3311,6 @@ static int rt5670_i2c_probe(struct i2c_client *i2c)
43812 + if (ret < 0)
43813 + goto err;
43814 +
43815 +- pm_runtime_put(&i2c->dev);
43816 +-
43817 + return 0;
43818 + err:
43819 + pm_runtime_disable(&i2c->dev);
43820 +diff --git a/sound/soc/codecs/wm8994.c b/sound/soc/codecs/wm8994.c
43821 +index d3cfd3788f2ab..8fe9a75d12357 100644
43822 +--- a/sound/soc/codecs/wm8994.c
43823 ++++ b/sound/soc/codecs/wm8994.c
43824 +@@ -3853,7 +3853,12 @@ static irqreturn_t wm1811_jackdet_irq(int irq, void *data)
43825 + } else {
43826 + dev_dbg(component->dev, "Jack not detected\n");
43827 +
43828 ++ /* Release wm8994->accdet_lock to avoid deadlock:
43829 ++ * cancel_delayed_work_sync() takes wm8994->mic_work internal
43830 ++ * lock and wm1811_mic_work takes wm8994->accdet_lock */
43831 ++ mutex_unlock(&wm8994->accdet_lock);
43832 + cancel_delayed_work_sync(&wm8994->mic_work);
43833 ++ mutex_lock(&wm8994->accdet_lock);
43834 +
43835 + snd_soc_component_update_bits(component, WM8958_MICBIAS2,
43836 + WM8958_MICB2_DISCH, WM8958_MICB2_DISCH);
43837 +diff --git a/sound/soc/codecs/wsa883x.c b/sound/soc/codecs/wsa883x.c
43838 +index 63e1d7aa61379..9dfa0ac08e6f0 100644
43839 +--- a/sound/soc/codecs/wsa883x.c
43840 ++++ b/sound/soc/codecs/wsa883x.c
43841 +@@ -7,7 +7,7 @@
43842 + #include <linux/debugfs.h>
43843 + #include <linux/delay.h>
43844 + #include <linux/device.h>
43845 +-#include <linux/gpio.h>
43846 ++#include <linux/gpio/consumer.h>
43847 + #include <linux/init.h>
43848 + #include <linux/kernel.h>
43849 + #include <linux/module.h>
43850 +@@ -1393,7 +1393,7 @@ static int wsa883x_probe(struct sdw_slave *pdev,
43851 + }
43852 +
43853 + wsa883x->sd_n = devm_gpiod_get_optional(&pdev->dev, "powerdown",
43854 +- GPIOD_FLAGS_BIT_NONEXCLUSIVE);
43855 ++ GPIOD_FLAGS_BIT_NONEXCLUSIVE | GPIOD_OUT_HIGH);
43856 + if (IS_ERR(wsa883x->sd_n)) {
43857 + dev_err(&pdev->dev, "Shutdown Control GPIO not found\n");
43858 + ret = PTR_ERR(wsa883x->sd_n);
43859 +@@ -1411,7 +1411,7 @@ static int wsa883x_probe(struct sdw_slave *pdev,
43860 + pdev->prop.sink_ports = GENMASK(WSA883X_MAX_SWR_PORTS, 0);
43861 + pdev->prop.sink_dpn_prop = wsa_sink_dpn_prop;
43862 + pdev->prop.scp_int1_mask = SDW_SCP_INT1_BUS_CLASH | SDW_SCP_INT1_PARITY;
43863 +- gpiod_direction_output(wsa883x->sd_n, 1);
43864 ++ gpiod_direction_output(wsa883x->sd_n, 0);
43865 +
43866 + wsa883x->regmap = devm_regmap_init_sdw(pdev, &wsa883x_regmap_config);
43867 + if (IS_ERR(wsa883x->regmap)) {
43868 +diff --git a/sound/soc/generic/audio-graph-card.c b/sound/soc/generic/audio-graph-card.c
43869 +index b327372f2e4ae..4e776c2a38a4c 100644
43870 +--- a/sound/soc/generic/audio-graph-card.c
43871 ++++ b/sound/soc/generic/audio-graph-card.c
43872 +@@ -485,8 +485,10 @@ static int __graph_for_each_link(struct asoc_simple_priv *priv,
43873 + of_node_put(codec_ep);
43874 + of_node_put(codec_port);
43875 +
43876 +- if (ret < 0)
43877 ++ if (ret < 0) {
43878 ++ of_node_put(cpu_ep);
43879 + return ret;
43880 ++ }
43881 +
43882 + codec_port_old = codec_port;
43883 + }
43884 +diff --git a/sound/soc/intel/avs/boards/rt298.c b/sound/soc/intel/avs/boards/rt298.c
43885 +index b28d36872dcba..58c9d9edecf0a 100644
43886 +--- a/sound/soc/intel/avs/boards/rt298.c
43887 ++++ b/sound/soc/intel/avs/boards/rt298.c
43888 +@@ -6,6 +6,7 @@
43889 + // Amadeusz Slawinski <amadeuszx.slawinski@×××××××××××.com>
43890 + //
43891 +
43892 ++#include <linux/dmi.h>
43893 + #include <linux/module.h>
43894 + #include <sound/jack.h>
43895 + #include <sound/pcm.h>
43896 +@@ -14,6 +15,16 @@
43897 + #include <sound/soc-acpi.h>
43898 + #include "../../../codecs/rt298.h"
43899 +
43900 ++static const struct dmi_system_id kblr_dmi_table[] = {
43901 ++ {
43902 ++ .matches = {
43903 ++ DMI_MATCH(DMI_SYS_VENDOR, "Intel Corporation"),
43904 ++ DMI_MATCH(DMI_BOARD_NAME, "Kabylake R DDR4 RVP"),
43905 ++ },
43906 ++ },
43907 ++ {}
43908 ++};
43909 ++
43910 + static const struct snd_kcontrol_new card_controls[] = {
43911 + SOC_DAPM_PIN_SWITCH("Headphone Jack"),
43912 + SOC_DAPM_PIN_SWITCH("Mic Jack"),
43913 +@@ -96,9 +107,15 @@ avs_rt298_hw_params(struct snd_pcm_substream *substream, struct snd_pcm_hw_param
43914 + {
43915 + struct snd_soc_pcm_runtime *rtd = substream->private_data;
43916 + struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
43917 ++ unsigned int clk_freq;
43918 + int ret;
43919 +
43920 +- ret = snd_soc_dai_set_sysclk(codec_dai, RT298_SCLK_S_PLL, 19200000, SND_SOC_CLOCK_IN);
43921 ++ if (dmi_first_match(kblr_dmi_table))
43922 ++ clk_freq = 24000000;
43923 ++ else
43924 ++ clk_freq = 19200000;
43925 ++
43926 ++ ret = snd_soc_dai_set_sysclk(codec_dai, RT298_SCLK_S_PLL, clk_freq, SND_SOC_CLOCK_IN);
43927 + if (ret < 0)
43928 + dev_err(rtd->dev, "Set codec sysclk failed: %d\n", ret);
43929 +
43930 +@@ -139,7 +156,10 @@ static int avs_create_dai_link(struct device *dev, const char *platform_name, in
43931 + dl->platforms = platform;
43932 + dl->num_platforms = 1;
43933 + dl->id = 0;
43934 +- dl->dai_fmt = SND_SOC_DAIFMT_DSP_A | SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBS_CFS;
43935 ++ if (dmi_first_match(kblr_dmi_table))
43936 ++ dl->dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBS_CFS;
43937 ++ else
43938 ++ dl->dai_fmt = SND_SOC_DAIFMT_DSP_A | SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBS_CFS;
43939 + dl->init = avs_rt298_codec_init;
43940 + dl->be_hw_params_fixup = avs_rt298_be_fixup;
43941 + dl->ops = &avs_rt298_ops;
43942 +diff --git a/sound/soc/intel/avs/core.c b/sound/soc/intel/avs/core.c
43943 +index c50c20fd681a1..58db133741662 100644
43944 +--- a/sound/soc/intel/avs/core.c
43945 ++++ b/sound/soc/intel/avs/core.c
43946 +@@ -440,7 +440,7 @@ static int avs_pci_probe(struct pci_dev *pci, const struct pci_device_id *id)
43947 + if (bus->mlcap)
43948 + snd_hdac_ext_bus_get_ml_capabilities(bus);
43949 +
43950 +- if (!dma_set_mask_and_coherent(dev, DMA_BIT_MASK(64)))
43951 ++ if (dma_set_mask_and_coherent(dev, DMA_BIT_MASK(64)))
43952 + dma_set_mask_and_coherent(dev, DMA_BIT_MASK(32));
43953 + dma_set_max_seg_size(dev, UINT_MAX);
43954 +
43955 +diff --git a/sound/soc/intel/avs/ipc.c b/sound/soc/intel/avs/ipc.c
43956 +index 020d85c7520de..306f0dc4eaf58 100644
43957 +--- a/sound/soc/intel/avs/ipc.c
43958 ++++ b/sound/soc/intel/avs/ipc.c
43959 +@@ -123,7 +123,10 @@ static void avs_dsp_recovery(struct avs_dev *adev)
43960 + if (!substream || !substream->runtime)
43961 + continue;
43962 +
43963 ++ /* No need for _irq() as we are in nonatomic context. */
43964 ++ snd_pcm_stream_lock(substream);
43965 + snd_pcm_stop(substream, SNDRV_PCM_STATE_DISCONNECTED);
43966 ++ snd_pcm_stream_unlock(substream);
43967 + }
43968 + }
43969 + }
43970 +@@ -192,7 +195,8 @@ static void avs_dsp_receive_rx(struct avs_dev *adev, u64 header)
43971 + /* update size in case of LARGE_CONFIG_GET */
43972 + if (msg.msg_target == AVS_MOD_MSG &&
43973 + msg.global_msg_type == AVS_MOD_LARGE_CONFIG_GET)
43974 +- ipc->rx.size = msg.ext.large_config.data_off_size;
43975 ++ ipc->rx.size = min_t(u32, AVS_MAILBOX_SIZE,
43976 ++ msg.ext.large_config.data_off_size);
43977 +
43978 + memcpy_fromio(ipc->rx.data, avs_uplink_addr(adev), ipc->rx.size);
43979 + trace_avs_msg_payload(ipc->rx.data, ipc->rx.size);
43980 +diff --git a/sound/soc/intel/boards/sof_es8336.c b/sound/soc/intel/boards/sof_es8336.c
43981 +index 5c218a39ca201..57adcefce043e 100644
43982 +--- a/sound/soc/intel/boards/sof_es8336.c
43983 ++++ b/sound/soc/intel/boards/sof_es8336.c
43984 +@@ -782,7 +782,7 @@ static int sof_es8336_remove(struct platform_device *pdev)
43985 + struct snd_soc_card *card = platform_get_drvdata(pdev);
43986 + struct sof_es8336_private *priv = snd_soc_card_get_drvdata(card);
43987 +
43988 +- cancel_delayed_work(&priv->pcm_pop_work);
43989 ++ cancel_delayed_work_sync(&priv->pcm_pop_work);
43990 + gpiod_put(priv->gpio_speakers);
43991 + device_remove_software_node(priv->codec_dev);
43992 + put_device(priv->codec_dev);
43993 +diff --git a/sound/soc/intel/skylake/skl.c b/sound/soc/intel/skylake/skl.c
43994 +index aeca58246fc77..77cd7d3e9409b 100644
43995 +--- a/sound/soc/intel/skylake/skl.c
43996 ++++ b/sound/soc/intel/skylake/skl.c
43997 +@@ -1097,7 +1097,10 @@ static void skl_shutdown(struct pci_dev *pci)
43998 + if (!skl->init_done)
43999 + return;
44000 +
44001 +- snd_hdac_stop_streams_and_chip(bus);
44002 ++ snd_hdac_stop_streams(bus);
44003 ++ snd_hdac_ext_bus_link_power_down_all(bus);
44004 ++ skl_dsp_sleep(skl->dsp);
44005 ++
44006 + list_for_each_entry(s, &bus->stream_list, list) {
44007 + stream = stream_to_hdac_ext_stream(s);
44008 + snd_hdac_ext_stream_decouple(bus, stream, false);
44009 +diff --git a/sound/soc/mediatek/common/mtk-btcvsd.c b/sound/soc/mediatek/common/mtk-btcvsd.c
44010 +index d884bb7c0fc74..1c28b41e43112 100644
44011 +--- a/sound/soc/mediatek/common/mtk-btcvsd.c
44012 ++++ b/sound/soc/mediatek/common/mtk-btcvsd.c
44013 +@@ -1038,11 +1038,9 @@ static int mtk_pcm_btcvsd_copy(struct snd_soc_component *component,
44014 + struct mtk_btcvsd_snd *bt = snd_soc_component_get_drvdata(component);
44015 +
44016 + if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
44017 +- mtk_btcvsd_snd_write(bt, buf, count);
44018 ++ return mtk_btcvsd_snd_write(bt, buf, count);
44019 + else
44020 +- mtk_btcvsd_snd_read(bt, buf, count);
44021 +-
44022 +- return 0;
44023 ++ return mtk_btcvsd_snd_read(bt, buf, count);
44024 + }
44025 +
44026 + /* kcontrol */
44027 +diff --git a/sound/soc/mediatek/mt8173/mt8173-afe-pcm.c b/sound/soc/mediatek/mt8173/mt8173-afe-pcm.c
44028 +index dcaeeeb8aac70..bc155dd937e0b 100644
44029 +--- a/sound/soc/mediatek/mt8173/mt8173-afe-pcm.c
44030 ++++ b/sound/soc/mediatek/mt8173/mt8173-afe-pcm.c
44031 +@@ -1070,16 +1070,6 @@ static int mt8173_afe_pcm_dev_probe(struct platform_device *pdev)
44032 +
44033 + afe->dev = &pdev->dev;
44034 +
44035 +- irq_id = platform_get_irq(pdev, 0);
44036 +- if (irq_id <= 0)
44037 +- return irq_id < 0 ? irq_id : -ENXIO;
44038 +- ret = devm_request_irq(afe->dev, irq_id, mt8173_afe_irq_handler,
44039 +- 0, "Afe_ISR_Handle", (void *)afe);
44040 +- if (ret) {
44041 +- dev_err(afe->dev, "could not request_irq\n");
44042 +- return ret;
44043 +- }
44044 +-
44045 + afe->base_addr = devm_platform_ioremap_resource(pdev, 0);
44046 + if (IS_ERR(afe->base_addr))
44047 + return PTR_ERR(afe->base_addr);
44048 +@@ -1185,6 +1175,16 @@ static int mt8173_afe_pcm_dev_probe(struct platform_device *pdev)
44049 + if (ret)
44050 + goto err_cleanup_components;
44051 +
44052 ++ irq_id = platform_get_irq(pdev, 0);
44053 ++ if (irq_id <= 0)
44054 ++ return irq_id < 0 ? irq_id : -ENXIO;
44055 ++ ret = devm_request_irq(afe->dev, irq_id, mt8173_afe_irq_handler,
44056 ++ 0, "Afe_ISR_Handle", (void *)afe);
44057 ++ if (ret) {
44058 ++ dev_err(afe->dev, "could not request_irq\n");
44059 ++ goto err_pm_disable;
44060 ++ }
44061 ++
44062 + dev_info(&pdev->dev, "MT8173 AFE driver initialized.\n");
44063 + return 0;
44064 +
44065 +diff --git a/sound/soc/mediatek/mt8173/mt8173-rt5650-rt5514.c b/sound/soc/mediatek/mt8173/mt8173-rt5650-rt5514.c
44066 +index 12f40c81b101e..f803f121659de 100644
44067 +--- a/sound/soc/mediatek/mt8173/mt8173-rt5650-rt5514.c
44068 ++++ b/sound/soc/mediatek/mt8173/mt8173-rt5650-rt5514.c
44069 +@@ -200,14 +200,16 @@ static int mt8173_rt5650_rt5514_dev_probe(struct platform_device *pdev)
44070 + if (!mt8173_rt5650_rt5514_dais[DAI_LINK_CODEC_I2S].codecs[0].of_node) {
44071 + dev_err(&pdev->dev,
44072 + "Property 'audio-codec' missing or invalid\n");
44073 +- return -EINVAL;
44074 ++ ret = -EINVAL;
44075 ++ goto out;
44076 + }
44077 + mt8173_rt5650_rt5514_dais[DAI_LINK_CODEC_I2S].codecs[1].of_node =
44078 + of_parse_phandle(pdev->dev.of_node, "mediatek,audio-codec", 1);
44079 + if (!mt8173_rt5650_rt5514_dais[DAI_LINK_CODEC_I2S].codecs[1].of_node) {
44080 + dev_err(&pdev->dev,
44081 + "Property 'audio-codec' missing or invalid\n");
44082 +- return -EINVAL;
44083 ++ ret = -EINVAL;
44084 ++ goto out;
44085 + }
44086 + mt8173_rt5650_rt5514_codec_conf[0].dlc.of_node =
44087 + mt8173_rt5650_rt5514_dais[DAI_LINK_CODEC_I2S].codecs[1].of_node;
44088 +@@ -216,6 +218,7 @@ static int mt8173_rt5650_rt5514_dev_probe(struct platform_device *pdev)
44089 +
44090 + ret = devm_snd_soc_register_card(&pdev->dev, card);
44091 +
44092 ++out:
44093 + of_node_put(platform_node);
44094 + return ret;
44095 + }
44096 +diff --git a/sound/soc/mediatek/mt8183/mt8183-mt6358-ts3a227-max98357.c b/sound/soc/mediatek/mt8183/mt8183-mt6358-ts3a227-max98357.c
44097 +index ab157db783350..cfb463f44af79 100644
44098 +--- a/sound/soc/mediatek/mt8183/mt8183-mt6358-ts3a227-max98357.c
44099 ++++ b/sound/soc/mediatek/mt8183/mt8183-mt6358-ts3a227-max98357.c
44100 +@@ -644,8 +644,10 @@ mt8183_mt6358_ts3a227_max98357_dev_probe(struct platform_device *pdev)
44101 + }
44102 +
44103 + card = (struct snd_soc_card *)of_device_get_match_data(&pdev->dev);
44104 +- if (!card)
44105 ++ if (!card) {
44106 ++ of_node_put(platform_node);
44107 + return -EINVAL;
44108 ++ }
44109 + card->dev = &pdev->dev;
44110 +
44111 + ec_codec = of_parse_phandle(pdev->dev.of_node, "mediatek,ec-codec", 0);
44112 +@@ -734,8 +736,10 @@ mt8183_mt6358_ts3a227_max98357_dev_probe(struct platform_device *pdev)
44113 + }
44114 +
44115 + priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
44116 +- if (!priv)
44117 +- return -ENOMEM;
44118 ++ if (!priv) {
44119 ++ ret = -ENOMEM;
44120 ++ goto out;
44121 ++ }
44122 +
44123 + snd_soc_card_set_drvdata(card, priv);
44124 +
44125 +@@ -743,7 +747,8 @@ mt8183_mt6358_ts3a227_max98357_dev_probe(struct platform_device *pdev)
44126 + if (IS_ERR(priv->pinctrl)) {
44127 + dev_err(&pdev->dev, "%s devm_pinctrl_get failed\n",
44128 + __func__);
44129 +- return PTR_ERR(priv->pinctrl);
44130 ++ ret = PTR_ERR(priv->pinctrl);
44131 ++ goto out;
44132 + }
44133 +
44134 + for (i = 0; i < PIN_STATE_MAX; i++) {
44135 +@@ -776,6 +781,7 @@ mt8183_mt6358_ts3a227_max98357_dev_probe(struct platform_device *pdev)
44136 +
44137 + ret = devm_snd_soc_register_card(&pdev->dev, card);
44138 +
44139 ++out:
44140 + of_node_put(platform_node);
44141 + of_node_put(ec_codec);
44142 + of_node_put(hdmi_codec);
44143 +diff --git a/sound/soc/pxa/mmp-pcm.c b/sound/soc/pxa/mmp-pcm.c
44144 +index 5d520e18e512f..99b245e3079a2 100644
44145 +--- a/sound/soc/pxa/mmp-pcm.c
44146 ++++ b/sound/soc/pxa/mmp-pcm.c
44147 +@@ -98,7 +98,7 @@ static bool filter(struct dma_chan *chan, void *param)
44148 +
44149 + devname = kasprintf(GFP_KERNEL, "%s.%d", dma_data->dma_res->name,
44150 + dma_data->ssp_id);
44151 +- if ((strcmp(dev_name(chan->device->dev), devname) == 0) &&
44152 ++ if (devname && (strcmp(dev_name(chan->device->dev), devname) == 0) &&
44153 + (chan->chan_id == dma_data->dma_res->start)) {
44154 + found = true;
44155 + }
44156 +diff --git a/sound/soc/qcom/lpass-sc7180.c b/sound/soc/qcom/lpass-sc7180.c
44157 +index 77a556b27cf09..24a1c121cb2e9 100644
44158 +--- a/sound/soc/qcom/lpass-sc7180.c
44159 ++++ b/sound/soc/qcom/lpass-sc7180.c
44160 +@@ -131,6 +131,9 @@ static int sc7180_lpass_init(struct platform_device *pdev)
44161 +
44162 + drvdata->clks = devm_kcalloc(dev, variant->num_clks,
44163 + sizeof(*drvdata->clks), GFP_KERNEL);
44164 ++ if (!drvdata->clks)
44165 ++ return -ENOMEM;
44166 ++
44167 + drvdata->num_clks = variant->num_clks;
44168 +
44169 + for (i = 0; i < drvdata->num_clks; i++)
44170 +diff --git a/sound/soc/rockchip/rockchip_pdm.c b/sound/soc/rockchip/rockchip_pdm.c
44171 +index a7549f8272359..5b1e47bdc376b 100644
44172 +--- a/sound/soc/rockchip/rockchip_pdm.c
44173 ++++ b/sound/soc/rockchip/rockchip_pdm.c
44174 +@@ -431,6 +431,7 @@ static int rockchip_pdm_runtime_resume(struct device *dev)
44175 +
44176 + ret = clk_prepare_enable(pdm->hclk);
44177 + if (ret) {
44178 ++ clk_disable_unprepare(pdm->clk);
44179 + dev_err(pdm->dev, "hclock enable failed %d\n", ret);
44180 + return ret;
44181 + }
44182 +diff --git a/sound/soc/rockchip/rockchip_spdif.c b/sound/soc/rockchip/rockchip_spdif.c
44183 +index 8bef572d3cbc1..5b4f004575879 100644
44184 +--- a/sound/soc/rockchip/rockchip_spdif.c
44185 ++++ b/sound/soc/rockchip/rockchip_spdif.c
44186 +@@ -88,6 +88,7 @@ static int __maybe_unused rk_spdif_runtime_resume(struct device *dev)
44187 +
44188 + ret = clk_prepare_enable(spdif->hclk);
44189 + if (ret) {
44190 ++ clk_disable_unprepare(spdif->mclk);
44191 + dev_err(spdif->dev, "hclk clock enable failed %d\n", ret);
44192 + return ret;
44193 + }
44194 +diff --git a/sound/usb/quirks-table.h b/sound/usb/quirks-table.h
44195 +index 874fcf245747f..271884e350035 100644
44196 +--- a/sound/usb/quirks-table.h
44197 ++++ b/sound/usb/quirks-table.h
44198 +@@ -76,6 +76,8 @@
44199 + { USB_DEVICE_VENDOR_SPEC(0x041e, 0x3f0a) },
44200 + /* E-Mu 0204 USB */
44201 + { USB_DEVICE_VENDOR_SPEC(0x041e, 0x3f19) },
44202 ++/* Ktmicro Usb_audio device */
44203 ++{ USB_DEVICE_VENDOR_SPEC(0x31b2, 0x0011) },
44204 +
44205 + /*
44206 + * Creative Technology, Ltd Live! Cam Sync HD [VF0770]
44207 +diff --git a/tools/bpf/bpftool/common.c b/tools/bpf/bpftool/common.c
44208 +index 3bdbc0ce75b15..e54487e4005d3 100644
44209 +--- a/tools/bpf/bpftool/common.c
44210 ++++ b/tools/bpf/bpftool/common.c
44211 +@@ -499,6 +499,7 @@ static int do_build_table_cb(const char *fpath, const struct stat *sb,
44212 + if (err) {
44213 + p_err("failed to append entry to hashmap for ID %u, path '%s': %s",
44214 + pinned_info.id, path, strerror(errno));
44215 ++ free(path);
44216 + goto out_close;
44217 + }
44218 +
44219 +diff --git a/tools/lib/bpf/bpf.h b/tools/lib/bpf/bpf.h
44220 +index 9c50beabdd145..fddc05c667b5d 100644
44221 +--- a/tools/lib/bpf/bpf.h
44222 ++++ b/tools/lib/bpf/bpf.h
44223 +@@ -393,8 +393,15 @@ LIBBPF_API int bpf_task_fd_query(int pid, int fd, __u32 flags, char *buf,
44224 + __u32 *buf_len, __u32 *prog_id, __u32 *fd_type,
44225 + __u64 *probe_offset, __u64 *probe_addr);
44226 +
44227 ++#ifdef __cplusplus
44228 ++/* forward-declaring enums in C++ isn't compatible with pure C enums, so
44229 ++ * instead define bpf_enable_stats() as accepting int as an input
44230 ++ */
44231 ++LIBBPF_API int bpf_enable_stats(int type);
44232 ++#else
44233 + enum bpf_stats_type; /* defined in up-to-date linux/bpf.h */
44234 + LIBBPF_API int bpf_enable_stats(enum bpf_stats_type type);
44235 ++#endif
44236 +
44237 + struct bpf_prog_bind_opts {
44238 + size_t sz; /* size of this struct for forward/backward compatibility */
44239 +diff --git a/tools/lib/bpf/btf.c b/tools/lib/bpf/btf.c
44240 +index 2d14f1a52d7aa..9b18cf3128acc 100644
44241 +--- a/tools/lib/bpf/btf.c
44242 ++++ b/tools/lib/bpf/btf.c
44243 +@@ -3889,14 +3889,14 @@ static inline __u16 btf_fwd_kind(struct btf_type *t)
44244 + }
44245 +
44246 + /* Check if given two types are identical ARRAY definitions */
44247 +-static int btf_dedup_identical_arrays(struct btf_dedup *d, __u32 id1, __u32 id2)
44248 ++static bool btf_dedup_identical_arrays(struct btf_dedup *d, __u32 id1, __u32 id2)
44249 + {
44250 + struct btf_type *t1, *t2;
44251 +
44252 + t1 = btf_type_by_id(d->btf, id1);
44253 + t2 = btf_type_by_id(d->btf, id2);
44254 + if (!btf_is_array(t1) || !btf_is_array(t2))
44255 +- return 0;
44256 ++ return false;
44257 +
44258 + return btf_equal_array(t1, t2);
44259 + }
44260 +@@ -3920,7 +3920,9 @@ static bool btf_dedup_identical_structs(struct btf_dedup *d, __u32 id1, __u32 id
44261 + m1 = btf_members(t1);
44262 + m2 = btf_members(t2);
44263 + for (i = 0, n = btf_vlen(t1); i < n; i++, m1++, m2++) {
44264 +- if (m1->type != m2->type)
44265 ++ if (m1->type != m2->type &&
44266 ++ !btf_dedup_identical_arrays(d, m1->type, m2->type) &&
44267 ++ !btf_dedup_identical_structs(d, m1->type, m2->type))
44268 + return false;
44269 + }
44270 + return true;
44271 +diff --git a/tools/lib/bpf/btf_dump.c b/tools/lib/bpf/btf_dump.c
44272 +index 3937f66c7f8d6..0b470169729e6 100644
44273 +--- a/tools/lib/bpf/btf_dump.c
44274 ++++ b/tools/lib/bpf/btf_dump.c
44275 +@@ -219,6 +219,17 @@ static int btf_dump_resize(struct btf_dump *d)
44276 + return 0;
44277 + }
44278 +
44279 ++static void btf_dump_free_names(struct hashmap *map)
44280 ++{
44281 ++ size_t bkt;
44282 ++ struct hashmap_entry *cur;
44283 ++
44284 ++ hashmap__for_each_entry(map, cur, bkt)
44285 ++ free((void *)cur->key);
44286 ++
44287 ++ hashmap__free(map);
44288 ++}
44289 ++
44290 + void btf_dump__free(struct btf_dump *d)
44291 + {
44292 + int i;
44293 +@@ -237,8 +248,8 @@ void btf_dump__free(struct btf_dump *d)
44294 + free(d->cached_names);
44295 + free(d->emit_queue);
44296 + free(d->decl_stack);
44297 +- hashmap__free(d->type_names);
44298 +- hashmap__free(d->ident_names);
44299 ++ btf_dump_free_names(d->type_names);
44300 ++ btf_dump_free_names(d->ident_names);
44301 +
44302 + free(d);
44303 + }
44304 +@@ -1520,11 +1531,23 @@ static void btf_dump_emit_type_cast(struct btf_dump *d, __u32 id,
44305 + static size_t btf_dump_name_dups(struct btf_dump *d, struct hashmap *name_map,
44306 + const char *orig_name)
44307 + {
44308 ++ char *old_name, *new_name;
44309 + size_t dup_cnt = 0;
44310 ++ int err;
44311 ++
44312 ++ new_name = strdup(orig_name);
44313 ++ if (!new_name)
44314 ++ return 1;
44315 +
44316 + hashmap__find(name_map, orig_name, (void **)&dup_cnt);
44317 + dup_cnt++;
44318 +- hashmap__set(name_map, orig_name, (void *)dup_cnt, NULL, NULL);
44319 ++
44320 ++ err = hashmap__set(name_map, new_name, (void *)dup_cnt,
44321 ++ (const void **)&old_name, NULL);
44322 ++ if (err)
44323 ++ free(new_name);
44324 ++
44325 ++ free(old_name);
44326 +
44327 + return dup_cnt;
44328 + }
44329 +diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
44330 +index 79ea83be21ce9..c01f57d31f89a 100644
44331 +--- a/tools/lib/bpf/libbpf.c
44332 ++++ b/tools/lib/bpf/libbpf.c
44333 +@@ -590,8 +590,7 @@ struct elf_state {
44334 + size_t shstrndx; /* section index for section name strings */
44335 + size_t strtabidx;
44336 + struct elf_sec_desc *secs;
44337 +- int sec_cnt;
44338 +- int maps_shndx;
44339 ++ size_t sec_cnt;
44340 + int btf_maps_shndx;
44341 + __u32 btf_maps_sec_btf_id;
44342 + int text_shndx;
44343 +@@ -1272,7 +1271,6 @@ static struct bpf_object *bpf_object__new(const char *path,
44344 + */
44345 + obj->efile.obj_buf = obj_buf;
44346 + obj->efile.obj_buf_sz = obj_buf_sz;
44347 +- obj->efile.maps_shndx = -1;
44348 + obj->efile.btf_maps_shndx = -1;
44349 + obj->efile.st_ops_shndx = -1;
44350 + obj->kconfig_map_idx = -1;
44351 +@@ -1401,6 +1399,10 @@ static int bpf_object__check_endianness(struct bpf_object *obj)
44352 + static int
44353 + bpf_object__init_license(struct bpf_object *obj, void *data, size_t size)
44354 + {
44355 ++ if (!data) {
44356 ++ pr_warn("invalid license section in %s\n", obj->path);
44357 ++ return -LIBBPF_ERRNO__FORMAT;
44358 ++ }
44359 + /* libbpf_strlcpy() only copies first N - 1 bytes, so size + 1 won't
44360 + * go over allowed ELF data section buffer
44361 + */
44362 +@@ -1414,7 +1416,7 @@ bpf_object__init_kversion(struct bpf_object *obj, void *data, size_t size)
44363 + {
44364 + __u32 kver;
44365 +
44366 +- if (size != sizeof(kver)) {
44367 ++ if (!data || size != sizeof(kver)) {
44368 + pr_warn("invalid kver section in %s\n", obj->path);
44369 + return -LIBBPF_ERRNO__FORMAT;
44370 + }
44371 +@@ -3284,10 +3286,15 @@ static int bpf_object__elf_collect(struct bpf_object *obj)
44372 + Elf64_Shdr *sh;
44373 +
44374 + /* ELF section indices are 0-based, but sec #0 is special "invalid"
44375 +- * section. e_shnum does include sec #0, so e_shnum is the necessary
44376 +- * size of an array to keep all the sections.
44377 ++ * section. Since section count retrieved by elf_getshdrnum() does
44378 ++ * include sec #0, it is already the necessary size of an array to keep
44379 ++ * all the sections.
44380 + */
44381 +- obj->efile.sec_cnt = obj->efile.ehdr->e_shnum;
44382 ++ if (elf_getshdrnum(obj->efile.elf, &obj->efile.sec_cnt)) {
44383 ++ pr_warn("elf: failed to get the number of sections for %s: %s\n",
44384 ++ obj->path, elf_errmsg(-1));
44385 ++ return -LIBBPF_ERRNO__FORMAT;
44386 ++ }
44387 + obj->efile.secs = calloc(obj->efile.sec_cnt, sizeof(*obj->efile.secs));
44388 + if (!obj->efile.secs)
44389 + return -ENOMEM;
44390 +@@ -3359,7 +3366,8 @@ static int bpf_object__elf_collect(struct bpf_object *obj)
44391 + if (err)
44392 + return err;
44393 + } else if (strcmp(name, "maps") == 0) {
44394 +- obj->efile.maps_shndx = idx;
44395 ++ pr_warn("elf: legacy map definitions in 'maps' section are not supported by libbpf v1.0+\n");
44396 ++ return -ENOTSUP;
44397 + } else if (strcmp(name, MAPS_ELF_SEC) == 0) {
44398 + obj->efile.btf_maps_shndx = idx;
44399 + } else if (strcmp(name, BTF_ELF_SEC) == 0) {
44400 +@@ -3891,8 +3899,7 @@ static bool bpf_object__shndx_is_data(const struct bpf_object *obj,
44401 + static bool bpf_object__shndx_is_maps(const struct bpf_object *obj,
44402 + int shndx)
44403 + {
44404 +- return shndx == obj->efile.maps_shndx ||
44405 +- shndx == obj->efile.btf_maps_shndx;
44406 ++ return shndx == obj->efile.btf_maps_shndx;
44407 + }
44408 +
44409 + static enum libbpf_map_type
44410 +@@ -4078,6 +4085,9 @@ static struct bpf_program *find_prog_by_sec_insn(const struct bpf_object *obj,
44411 + int l = 0, r = obj->nr_programs - 1, m;
44412 + struct bpf_program *prog;
44413 +
44414 ++ if (!obj->nr_programs)
44415 ++ return NULL;
44416 ++
44417 + while (l < r) {
44418 + m = l + (r - l + 1) / 2;
44419 + prog = &obj->programs[m];
44420 +diff --git a/tools/lib/bpf/usdt.c b/tools/lib/bpf/usdt.c
44421 +index d18e37982344c..2ade9c7969d72 100644
44422 +--- a/tools/lib/bpf/usdt.c
44423 ++++ b/tools/lib/bpf/usdt.c
44424 +@@ -1348,25 +1348,23 @@ static int calc_pt_regs_off(const char *reg_name)
44425 +
44426 + static int parse_usdt_arg(const char *arg_str, int arg_num, struct usdt_arg_spec *arg)
44427 + {
44428 +- char *reg_name = NULL;
44429 ++ char reg_name[16];
44430 + int arg_sz, len, reg_off;
44431 + long off;
44432 +
44433 +- if (sscanf(arg_str, " %d @ \[ %m[a-z0-9], %ld ] %n", &arg_sz, &reg_name, &off, &len) == 3) {
44434 ++ if (sscanf(arg_str, " %d @ \[ %15[a-z0-9], %ld ] %n", &arg_sz, reg_name, &off, &len) == 3) {
44435 + /* Memory dereference case, e.g., -4@[sp, 96] */
44436 + arg->arg_type = USDT_ARG_REG_DEREF;
44437 + arg->val_off = off;
44438 + reg_off = calc_pt_regs_off(reg_name);
44439 +- free(reg_name);
44440 + if (reg_off < 0)
44441 + return reg_off;
44442 + arg->reg_off = reg_off;
44443 +- } else if (sscanf(arg_str, " %d @ \[ %m[a-z0-9] ] %n", &arg_sz, &reg_name, &len) == 2) {
44444 ++ } else if (sscanf(arg_str, " %d @ \[ %15[a-z0-9] ] %n", &arg_sz, reg_name, &len) == 2) {
44445 + /* Memory dereference case, e.g., -4@[sp] */
44446 + arg->arg_type = USDT_ARG_REG_DEREF;
44447 + arg->val_off = 0;
44448 + reg_off = calc_pt_regs_off(reg_name);
44449 +- free(reg_name);
44450 + if (reg_off < 0)
44451 + return reg_off;
44452 + arg->reg_off = reg_off;
44453 +@@ -1375,12 +1373,11 @@ static int parse_usdt_arg(const char *arg_str, int arg_num, struct usdt_arg_spec
44454 + arg->arg_type = USDT_ARG_CONST;
44455 + arg->val_off = off;
44456 + arg->reg_off = 0;
44457 +- } else if (sscanf(arg_str, " %d @ %m[a-z0-9] %n", &arg_sz, &reg_name, &len) == 2) {
44458 ++ } else if (sscanf(arg_str, " %d @ %15[a-z0-9] %n", &arg_sz, reg_name, &len) == 2) {
44459 + /* Register read case, e.g., -8@x4 */
44460 + arg->arg_type = USDT_ARG_REG;
44461 + arg->val_off = 0;
44462 + reg_off = calc_pt_regs_off(reg_name);
44463 +- free(reg_name);
44464 + if (reg_off < 0)
44465 + return reg_off;
44466 + arg->reg_off = reg_off;
44467 +diff --git a/tools/objtool/check.c b/tools/objtool/check.c
44468 +index e55fdf952a3a1..67afdce3421f5 100644
44469 +--- a/tools/objtool/check.c
44470 ++++ b/tools/objtool/check.c
44471 +@@ -999,6 +999,16 @@ static const char *uaccess_safe_builtin[] = {
44472 + "__tsan_read_write4",
44473 + "__tsan_read_write8",
44474 + "__tsan_read_write16",
44475 ++ "__tsan_volatile_read1",
44476 ++ "__tsan_volatile_read2",
44477 ++ "__tsan_volatile_read4",
44478 ++ "__tsan_volatile_read8",
44479 ++ "__tsan_volatile_read16",
44480 ++ "__tsan_volatile_write1",
44481 ++ "__tsan_volatile_write2",
44482 ++ "__tsan_volatile_write4",
44483 ++ "__tsan_volatile_write8",
44484 ++ "__tsan_volatile_write16",
44485 + "__tsan_atomic8_load",
44486 + "__tsan_atomic16_load",
44487 + "__tsan_atomic32_load",
44488 +diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
44489 +index 0b4a62e4ff675..cab6b70e95e26 100644
44490 +--- a/tools/perf/builtin-stat.c
44491 ++++ b/tools/perf/builtin-stat.c
44492 +@@ -573,26 +573,14 @@ static int enable_counters(void)
44493 + return err;
44494 + }
44495 +
44496 +- if (stat_config.initial_delay < 0) {
44497 +- pr_info(EVLIST_DISABLED_MSG);
44498 +- return 0;
44499 +- }
44500 +-
44501 +- if (stat_config.initial_delay > 0) {
44502 +- pr_info(EVLIST_DISABLED_MSG);
44503 +- usleep(stat_config.initial_delay * USEC_PER_MSEC);
44504 +- }
44505 +-
44506 + /*
44507 + * We need to enable counters only if:
44508 + * - we don't have tracee (attaching to task or cpu)
44509 + * - we have initial delay configured
44510 + */
44511 +- if (!target__none(&target) || stat_config.initial_delay) {
44512 ++ if (!target__none(&target)) {
44513 + if (!all_counters_use_bpf)
44514 + evlist__enable(evsel_list);
44515 +- if (stat_config.initial_delay > 0)
44516 +- pr_info(EVLIST_ENABLED_MSG);
44517 + }
44518 + return 0;
44519 + }
44520 +@@ -967,14 +955,27 @@ try_again_reset:
44521 + return err;
44522 + }
44523 +
44524 +- err = enable_counters();
44525 +- if (err)
44526 +- return -1;
44527 ++ if (stat_config.initial_delay) {
44528 ++ pr_info(EVLIST_DISABLED_MSG);
44529 ++ } else {
44530 ++ err = enable_counters();
44531 ++ if (err)
44532 ++ return -1;
44533 ++ }
44534 +
44535 + /* Exec the command, if any */
44536 + if (forks)
44537 + evlist__start_workload(evsel_list);
44538 +
44539 ++ if (stat_config.initial_delay > 0) {
44540 ++ usleep(stat_config.initial_delay * USEC_PER_MSEC);
44541 ++ err = enable_counters();
44542 ++ if (err)
44543 ++ return -1;
44544 ++
44545 ++ pr_info(EVLIST_ENABLED_MSG);
44546 ++ }
44547 ++
44548 + t0 = rdclock();
44549 + clock_gettime(CLOCK_MONOTONIC, &ref_time);
44550 +
44551 +diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
44552 +index 0bd9d01c0df9d..73f4a83edc443 100644
44553 +--- a/tools/perf/builtin-trace.c
44554 ++++ b/tools/perf/builtin-trace.c
44555 +@@ -88,6 +88,8 @@
44556 + # define F_LINUX_SPECIFIC_BASE 1024
44557 + #endif
44558 +
44559 ++#define RAW_SYSCALL_ARGS_NUM 6
44560 ++
44561 + /*
44562 + * strtoul: Go from a string to a value, i.e. for msr: MSR_FS_BASE to 0xc0000100
44563 + */
44564 +@@ -108,7 +110,7 @@ struct syscall_fmt {
44565 + const char *sys_enter,
44566 + *sys_exit;
44567 + } bpf_prog_name;
44568 +- struct syscall_arg_fmt arg[6];
44569 ++ struct syscall_arg_fmt arg[RAW_SYSCALL_ARGS_NUM];
44570 + u8 nr_args;
44571 + bool errpid;
44572 + bool timeout;
44573 +@@ -1229,7 +1231,7 @@ struct syscall {
44574 + */
44575 + struct bpf_map_syscall_entry {
44576 + bool enabled;
44577 +- u16 string_args_len[6];
44578 ++ u16 string_args_len[RAW_SYSCALL_ARGS_NUM];
44579 + };
44580 +
44581 + /*
44582 +@@ -1661,7 +1663,7 @@ static int syscall__alloc_arg_fmts(struct syscall *sc, int nr_args)
44583 + {
44584 + int idx;
44585 +
44586 +- if (nr_args == 6 && sc->fmt && sc->fmt->nr_args != 0)
44587 ++ if (nr_args == RAW_SYSCALL_ARGS_NUM && sc->fmt && sc->fmt->nr_args != 0)
44588 + nr_args = sc->fmt->nr_args;
44589 +
44590 + sc->arg_fmt = calloc(nr_args, sizeof(*sc->arg_fmt));
44591 +@@ -1794,11 +1796,11 @@ static int trace__read_syscall_info(struct trace *trace, int id)
44592 + #endif
44593 + sc = trace->syscalls.table + id;
44594 + if (sc->nonexistent)
44595 +- return 0;
44596 ++ return -EEXIST;
44597 +
44598 + if (name == NULL) {
44599 + sc->nonexistent = true;
44600 +- return 0;
44601 ++ return -EEXIST;
44602 + }
44603 +
44604 + sc->name = name;
44605 +@@ -1812,11 +1814,18 @@ static int trace__read_syscall_info(struct trace *trace, int id)
44606 + sc->tp_format = trace_event__tp_format("syscalls", tp_name);
44607 + }
44608 +
44609 +- if (syscall__alloc_arg_fmts(sc, IS_ERR(sc->tp_format) ? 6 : sc->tp_format->format.nr_fields))
44610 +- return -ENOMEM;
44611 +-
44612 +- if (IS_ERR(sc->tp_format))
44613 ++ /*
44614 ++ * Fails to read trace point format via sysfs node, so the trace point
44615 ++ * doesn't exist. Set the 'nonexistent' flag as true.
44616 ++ */
44617 ++ if (IS_ERR(sc->tp_format)) {
44618 ++ sc->nonexistent = true;
44619 + return PTR_ERR(sc->tp_format);
44620 ++ }
44621 ++
44622 ++ if (syscall__alloc_arg_fmts(sc, IS_ERR(sc->tp_format) ?
44623 ++ RAW_SYSCALL_ARGS_NUM : sc->tp_format->format.nr_fields))
44624 ++ return -ENOMEM;
44625 +
44626 + sc->args = sc->tp_format->format.fields;
44627 + /*
44628 +@@ -2134,11 +2143,8 @@ static struct syscall *trace__syscall_info(struct trace *trace,
44629 + (err = trace__read_syscall_info(trace, id)) != 0)
44630 + goto out_cant_read;
44631 +
44632 +- if (trace->syscalls.table[id].name == NULL) {
44633 +- if (trace->syscalls.table[id].nonexistent)
44634 +- return NULL;
44635 ++ if (trace->syscalls.table && trace->syscalls.table[id].nonexistent)
44636 + goto out_cant_read;
44637 +- }
44638 +
44639 + return &trace->syscalls.table[id];
44640 +
44641 +diff --git a/tools/perf/tests/shell/stat_all_pmu.sh b/tools/perf/tests/shell/stat_all_pmu.sh
44642 +index 9c9ef33e0b3c6..c779554191731 100755
44643 +--- a/tools/perf/tests/shell/stat_all_pmu.sh
44644 ++++ b/tools/perf/tests/shell/stat_all_pmu.sh
44645 +@@ -4,17 +4,8 @@
44646 +
44647 + set -e
44648 +
44649 +-for p in $(perf list --raw-dump pmu); do
44650 +- # In powerpc, skip the events for hv_24x7 and hv_gpci.
44651 +- # These events needs input values to be filled in for
44652 +- # core, chip, partition id based on system.
44653 +- # Example: hv_24x7/CPM_ADJUNCT_INST,domain=?,core=?/
44654 +- # hv_gpci/event,partition_id=?/
44655 +- # Hence skip these events for ppc.
44656 +- if echo "$p" |grep -Eq 'hv_24x7|hv_gpci' ; then
44657 +- echo "Skipping: Event '$p' in powerpc"
44658 +- continue
44659 +- fi
44660 ++# Test all PMU events; however exclude parametrized ones (name contains '?')
44661 ++for p in $(perf list --raw-dump pmu | sed 's/[[:graph:]]\+?[[:graph:]]\+[[:space:]]//g'); do
44662 + echo "Testing $p"
44663 + result=$(perf stat -e "$p" true 2>&1)
44664 + if ! echo "$result" | grep -q "$p" && ! echo "$result" | grep -q "<not supported>" ; then
44665 +diff --git a/tools/perf/util/bpf_off_cpu.c b/tools/perf/util/bpf_off_cpu.c
44666 +index c257813e674ef..01f70b8e705a8 100644
44667 +--- a/tools/perf/util/bpf_off_cpu.c
44668 ++++ b/tools/perf/util/bpf_off_cpu.c
44669 +@@ -102,7 +102,7 @@ static void check_sched_switch_args(void)
44670 + const struct btf_type *t1, *t2, *t3;
44671 + u32 type_id;
44672 +
44673 +- type_id = btf__find_by_name_kind(btf, "bpf_trace_sched_switch",
44674 ++ type_id = btf__find_by_name_kind(btf, "btf_trace_sched_switch",
44675 + BTF_KIND_TYPEDEF);
44676 + if ((s32)type_id < 0)
44677 + return;
44678 +diff --git a/tools/perf/util/debug.c b/tools/perf/util/debug.c
44679 +index 65e6c22f38e4f..190e818a07176 100644
44680 +--- a/tools/perf/util/debug.c
44681 ++++ b/tools/perf/util/debug.c
44682 +@@ -241,6 +241,10 @@ int perf_quiet_option(void)
44683 + opt++;
44684 + }
44685 +
44686 ++ /* For debug variables that are used as bool types, set to 0. */
44687 ++ redirect_to_stderr = 0;
44688 ++ debug_peo_args = 0;
44689 ++
44690 + return 0;
44691 + }
44692 +
44693 +diff --git a/tools/perf/util/symbol-elf.c b/tools/perf/util/symbol-elf.c
44694 +index 647b7dff8ef36..80345695b1360 100644
44695 +--- a/tools/perf/util/symbol-elf.c
44696 ++++ b/tools/perf/util/symbol-elf.c
44697 +@@ -1303,7 +1303,7 @@ dso__load_sym_internal(struct dso *dso, struct map *map, struct symsrc *syms_ss,
44698 + (!used_opd && syms_ss->adjust_symbols)) {
44699 + GElf_Phdr phdr;
44700 +
44701 +- if (elf_read_program_header(syms_ss->elf,
44702 ++ if (elf_read_program_header(runtime_ss->elf,
44703 + (u64)sym.st_value, &phdr)) {
44704 + pr_debug4("%s: failed to find program header for "
44705 + "symbol: %s st_value: %#" PRIx64 "\n",
44706 +diff --git a/tools/testing/selftests/bpf/bpf_testmod/bpf_testmod.c b/tools/testing/selftests/bpf/bpf_testmod/bpf_testmod.c
44707 +index ac5d7c1396fb4..5085fea3cac5f 100644
44708 +--- a/tools/testing/selftests/bpf/bpf_testmod/bpf_testmod.c
44709 ++++ b/tools/testing/selftests/bpf/bpf_testmod/bpf_testmod.c
44710 +@@ -18,6 +18,46 @@ typedef int (*func_proto_typedef_nested1)(func_proto_typedef);
44711 + typedef int (*func_proto_typedef_nested2)(func_proto_typedef_nested1);
44712 +
44713 + DEFINE_PER_CPU(int, bpf_testmod_ksym_percpu) = 123;
44714 ++long bpf_testmod_test_struct_arg_result;
44715 ++
44716 ++struct bpf_testmod_struct_arg_1 {
44717 ++ int a;
44718 ++};
44719 ++struct bpf_testmod_struct_arg_2 {
44720 ++ long a;
44721 ++ long b;
44722 ++};
44723 ++
44724 ++noinline int
44725 ++bpf_testmod_test_struct_arg_1(struct bpf_testmod_struct_arg_2 a, int b, int c) {
44726 ++ bpf_testmod_test_struct_arg_result = a.a + a.b + b + c;
44727 ++ return bpf_testmod_test_struct_arg_result;
44728 ++}
44729 ++
44730 ++noinline int
44731 ++bpf_testmod_test_struct_arg_2(int a, struct bpf_testmod_struct_arg_2 b, int c) {
44732 ++ bpf_testmod_test_struct_arg_result = a + b.a + b.b + c;
44733 ++ return bpf_testmod_test_struct_arg_result;
44734 ++}
44735 ++
44736 ++noinline int
44737 ++bpf_testmod_test_struct_arg_3(int a, int b, struct bpf_testmod_struct_arg_2 c) {
44738 ++ bpf_testmod_test_struct_arg_result = a + b + c.a + c.b;
44739 ++ return bpf_testmod_test_struct_arg_result;
44740 ++}
44741 ++
44742 ++noinline int
44743 ++bpf_testmod_test_struct_arg_4(struct bpf_testmod_struct_arg_1 a, int b,
44744 ++ int c, int d, struct bpf_testmod_struct_arg_2 e) {
44745 ++ bpf_testmod_test_struct_arg_result = a.a + b + c + d + e.a + e.b;
44746 ++ return bpf_testmod_test_struct_arg_result;
44747 ++}
44748 ++
44749 ++noinline int
44750 ++bpf_testmod_test_struct_arg_5(void) {
44751 ++ bpf_testmod_test_struct_arg_result = 1;
44752 ++ return bpf_testmod_test_struct_arg_result;
44753 ++}
44754 +
44755 + noinline void
44756 + bpf_testmod_test_mod_kfunc(int i)
44757 +@@ -115,11 +155,19 @@ bpf_testmod_test_read(struct file *file, struct kobject *kobj,
44758 + .off = off,
44759 + .len = len,
44760 + };
44761 ++ struct bpf_testmod_struct_arg_1 struct_arg1 = {10};
44762 ++ struct bpf_testmod_struct_arg_2 struct_arg2 = {2, 3};
44763 + int i = 1;
44764 +
44765 + while (bpf_testmod_return_ptr(i))
44766 + i++;
44767 +
44768 ++ (void)bpf_testmod_test_struct_arg_1(struct_arg2, 1, 4);
44769 ++ (void)bpf_testmod_test_struct_arg_2(1, struct_arg2, 4);
44770 ++ (void)bpf_testmod_test_struct_arg_3(1, 4, struct_arg2);
44771 ++ (void)bpf_testmod_test_struct_arg_4(struct_arg1, 1, 2, 3, struct_arg2);
44772 ++ (void)bpf_testmod_test_struct_arg_5();
44773 ++
44774 + /* This is always true. Use the check to make sure the compiler
44775 + * doesn't remove bpf_testmod_loop_test.
44776 + */
44777 +diff --git a/tools/testing/selftests/bpf/config b/tools/testing/selftests/bpf/config
44778 +index fabf0c0143498..c5c5fc2a3ce7b 100644
44779 +--- a/tools/testing/selftests/bpf/config
44780 ++++ b/tools/testing/selftests/bpf/config
44781 +@@ -13,6 +13,7 @@ CONFIG_CRYPTO_USER_API_HASH=m
44782 + CONFIG_DYNAMIC_FTRACE=y
44783 + CONFIG_FPROBE=y
44784 + CONFIG_FTRACE_SYSCALLS=y
44785 ++CONFIG_FUNCTION_ERROR_INJECTION=y
44786 + CONFIG_FUNCTION_TRACER=y
44787 + CONFIG_GENEVE=y
44788 + CONFIG_IKCONFIG=y
44789 +diff --git a/tools/testing/selftests/bpf/network_helpers.c b/tools/testing/selftests/bpf/network_helpers.c
44790 +index bec15558fd938..1f37adff7632c 100644
44791 +--- a/tools/testing/selftests/bpf/network_helpers.c
44792 ++++ b/tools/testing/selftests/bpf/network_helpers.c
44793 +@@ -426,6 +426,10 @@ static int setns_by_fd(int nsfd)
44794 + if (!ASSERT_OK(err, "mount /sys/fs/bpf"))
44795 + return err;
44796 +
44797 ++ err = mount("debugfs", "/sys/kernel/debug", "debugfs", 0, NULL);
44798 ++ if (!ASSERT_OK(err, "mount /sys/kernel/debug"))
44799 ++ return err;
44800 ++
44801 + return 0;
44802 + }
44803 +
44804 +diff --git a/tools/testing/selftests/bpf/prog_tests/empty_skb.c b/tools/testing/selftests/bpf/prog_tests/empty_skb.c
44805 +new file mode 100644
44806 +index 0000000000000..0613f3bb8b5e4
44807 +--- /dev/null
44808 ++++ b/tools/testing/selftests/bpf/prog_tests/empty_skb.c
44809 +@@ -0,0 +1,146 @@
44810 ++// SPDX-License-Identifier: GPL-2.0
44811 ++#include <test_progs.h>
44812 ++#include <network_helpers.h>
44813 ++#include <net/if.h>
44814 ++#include "empty_skb.skel.h"
44815 ++
44816 ++#define SYS(cmd) ({ \
44817 ++ if (!ASSERT_OK(system(cmd), (cmd))) \
44818 ++ goto out; \
44819 ++})
44820 ++
44821 ++void serial_test_empty_skb(void)
44822 ++{
44823 ++ LIBBPF_OPTS(bpf_test_run_opts, tattr);
44824 ++ struct empty_skb *bpf_obj = NULL;
44825 ++ struct nstoken *tok = NULL;
44826 ++ struct bpf_program *prog;
44827 ++ char eth_hlen_pp[15];
44828 ++ char eth_hlen[14];
44829 ++ int veth_ifindex;
44830 ++ int ipip_ifindex;
44831 ++ int err;
44832 ++ int i;
44833 ++
44834 ++ struct {
44835 ++ const char *msg;
44836 ++ const void *data_in;
44837 ++ __u32 data_size_in;
44838 ++ int *ifindex;
44839 ++ int err;
44840 ++ int ret;
44841 ++ bool success_on_tc;
44842 ++ } tests[] = {
44843 ++ /* Empty packets are always rejected. */
44844 ++
44845 ++ {
44846 ++ /* BPF_PROG_RUN ETH_HLEN size check */
44847 ++ .msg = "veth empty ingress packet",
44848 ++ .data_in = NULL,
44849 ++ .data_size_in = 0,
44850 ++ .ifindex = &veth_ifindex,
44851 ++ .err = -EINVAL,
44852 ++ },
44853 ++ {
44854 ++ /* BPF_PROG_RUN ETH_HLEN size check */
44855 ++ .msg = "ipip empty ingress packet",
44856 ++ .data_in = NULL,
44857 ++ .data_size_in = 0,
44858 ++ .ifindex = &ipip_ifindex,
44859 ++ .err = -EINVAL,
44860 ++ },
44861 ++
44862 ++ /* ETH_HLEN-sized packets:
44863 ++ * - can not be redirected at LWT_XMIT
44864 ++ * - can be redirected at TC to non-tunneling dest
44865 ++ */
44866 ++
44867 ++ {
44868 ++ /* __bpf_redirect_common */
44869 ++ .msg = "veth ETH_HLEN packet ingress",
44870 ++ .data_in = eth_hlen,
44871 ++ .data_size_in = sizeof(eth_hlen),
44872 ++ .ifindex = &veth_ifindex,
44873 ++ .ret = -ERANGE,
44874 ++ .success_on_tc = true,
44875 ++ },
44876 ++ {
44877 ++ /* __bpf_redirect_no_mac
44878 ++ *
44879 ++ * lwt: skb->len=0 <= skb_network_offset=0
44880 ++ * tc: skb->len=14 <= skb_network_offset=14
44881 ++ */
44882 ++ .msg = "ipip ETH_HLEN packet ingress",
44883 ++ .data_in = eth_hlen,
44884 ++ .data_size_in = sizeof(eth_hlen),
44885 ++ .ifindex = &ipip_ifindex,
44886 ++ .ret = -ERANGE,
44887 ++ },
44888 ++
44889 ++ /* ETH_HLEN+1-sized packet should be redirected. */
44890 ++
44891 ++ {
44892 ++ .msg = "veth ETH_HLEN+1 packet ingress",
44893 ++ .data_in = eth_hlen_pp,
44894 ++ .data_size_in = sizeof(eth_hlen_pp),
44895 ++ .ifindex = &veth_ifindex,
44896 ++ },
44897 ++ {
44898 ++ .msg = "ipip ETH_HLEN+1 packet ingress",
44899 ++ .data_in = eth_hlen_pp,
44900 ++ .data_size_in = sizeof(eth_hlen_pp),
44901 ++ .ifindex = &ipip_ifindex,
44902 ++ },
44903 ++ };
44904 ++
44905 ++ SYS("ip netns add empty_skb");
44906 ++ tok = open_netns("empty_skb");
44907 ++ SYS("ip link add veth0 type veth peer veth1");
44908 ++ SYS("ip link set dev veth0 up");
44909 ++ SYS("ip link set dev veth1 up");
44910 ++ SYS("ip addr add 10.0.0.1/8 dev veth0");
44911 ++ SYS("ip addr add 10.0.0.2/8 dev veth1");
44912 ++ veth_ifindex = if_nametoindex("veth0");
44913 ++
44914 ++ SYS("ip link add ipip0 type ipip local 10.0.0.1 remote 10.0.0.2");
44915 ++ SYS("ip link set ipip0 up");
44916 ++ SYS("ip addr add 192.168.1.1/16 dev ipip0");
44917 ++ ipip_ifindex = if_nametoindex("ipip0");
44918 ++
44919 ++ bpf_obj = empty_skb__open_and_load();
44920 ++ if (!ASSERT_OK_PTR(bpf_obj, "open skeleton"))
44921 ++ goto out;
44922 ++
44923 ++ for (i = 0; i < ARRAY_SIZE(tests); i++) {
44924 ++ bpf_object__for_each_program(prog, bpf_obj->obj) {
44925 ++ char buf[128];
44926 ++ bool at_tc = !strncmp(bpf_program__section_name(prog), "tc", 2);
44927 ++
44928 ++ tattr.data_in = tests[i].data_in;
44929 ++ tattr.data_size_in = tests[i].data_size_in;
44930 ++
44931 ++ tattr.data_size_out = 0;
44932 ++ bpf_obj->bss->ifindex = *tests[i].ifindex;
44933 ++ bpf_obj->bss->ret = 0;
44934 ++ err = bpf_prog_test_run_opts(bpf_program__fd(prog), &tattr);
44935 ++ sprintf(buf, "err: %s [%s]", tests[i].msg, bpf_program__name(prog));
44936 ++
44937 ++ if (at_tc && tests[i].success_on_tc)
44938 ++ ASSERT_GE(err, 0, buf);
44939 ++ else
44940 ++ ASSERT_EQ(err, tests[i].err, buf);
44941 ++ sprintf(buf, "ret: %s [%s]", tests[i].msg, bpf_program__name(prog));
44942 ++ if (at_tc && tests[i].success_on_tc)
44943 ++ ASSERT_GE(bpf_obj->bss->ret, 0, buf);
44944 ++ else
44945 ++ ASSERT_EQ(bpf_obj->bss->ret, tests[i].ret, buf);
44946 ++ }
44947 ++ }
44948 ++
44949 ++out:
44950 ++ if (bpf_obj)
44951 ++ empty_skb__destroy(bpf_obj);
44952 ++ if (tok)
44953 ++ close_netns(tok);
44954 ++ system("ip netns del empty_skb");
44955 ++}
44956 +diff --git a/tools/testing/selftests/bpf/prog_tests/kprobe_multi_test.c b/tools/testing/selftests/bpf/prog_tests/kprobe_multi_test.c
44957 +index d457a55ff408e..287b3ac40227a 100644
44958 +--- a/tools/testing/selftests/bpf/prog_tests/kprobe_multi_test.c
44959 ++++ b/tools/testing/selftests/bpf/prog_tests/kprobe_multi_test.c
44960 +@@ -325,7 +325,7 @@ static bool symbol_equal(const void *key1, const void *key2, void *ctx __maybe_u
44961 + static int get_syms(char ***symsp, size_t *cntp)
44962 + {
44963 + size_t cap = 0, cnt = 0, i;
44964 +- char *name, **syms = NULL;
44965 ++ char *name = NULL, **syms = NULL;
44966 + struct hashmap *map;
44967 + char buf[256];
44968 + FILE *f;
44969 +@@ -352,6 +352,8 @@ static int get_syms(char ***symsp, size_t *cntp)
44970 + /* skip modules */
44971 + if (strchr(buf, '['))
44972 + continue;
44973 ++
44974 ++ free(name);
44975 + if (sscanf(buf, "%ms$*[^\n]\n", &name) != 1)
44976 + continue;
44977 + /*
44978 +@@ -369,32 +371,32 @@ static int get_syms(char ***symsp, size_t *cntp)
44979 + if (!strncmp(name, "__ftrace_invalid_address__",
44980 + sizeof("__ftrace_invalid_address__") - 1))
44981 + continue;
44982 ++
44983 + err = hashmap__add(map, name, NULL);
44984 +- if (err) {
44985 +- free(name);
44986 +- if (err == -EEXIST)
44987 +- continue;
44988 ++ if (err == -EEXIST)
44989 ++ continue;
44990 ++ if (err)
44991 + goto error;
44992 +- }
44993 ++
44994 + err = libbpf_ensure_mem((void **) &syms, &cap,
44995 + sizeof(*syms), cnt + 1);
44996 +- if (err) {
44997 +- free(name);
44998 ++ if (err)
44999 + goto error;
45000 +- }
45001 +- syms[cnt] = name;
45002 +- cnt++;
45003 ++
45004 ++ syms[cnt++] = name;
45005 ++ name = NULL;
45006 + }
45007 +
45008 + *symsp = syms;
45009 + *cntp = cnt;
45010 +
45011 + error:
45012 ++ free(name);
45013 + fclose(f);
45014 + hashmap__free(map);
45015 + if (err) {
45016 + for (i = 0; i < cnt; i++)
45017 +- free(syms[cnt]);
45018 ++ free(syms[i]);
45019 + free(syms);
45020 + }
45021 + return err;
45022 +diff --git a/tools/testing/selftests/bpf/prog_tests/lsm_cgroup.c b/tools/testing/selftests/bpf/prog_tests/lsm_cgroup.c
45023 +index 1102e4f42d2d4..f117bfef68a14 100644
45024 +--- a/tools/testing/selftests/bpf/prog_tests/lsm_cgroup.c
45025 ++++ b/tools/testing/selftests/bpf/prog_tests/lsm_cgroup.c
45026 +@@ -173,10 +173,12 @@ static void test_lsm_cgroup_functional(void)
45027 + ASSERT_EQ(query_prog_cnt(cgroup_fd, NULL), 4, "total prog count");
45028 + ASSERT_EQ(query_prog_cnt(cgroup_fd2, NULL), 1, "total prog count");
45029 +
45030 +- /* AF_UNIX is prohibited. */
45031 +-
45032 + fd = socket(AF_UNIX, SOCK_STREAM, 0);
45033 +- ASSERT_LT(fd, 0, "socket(AF_UNIX)");
45034 ++ if (!(skel->kconfig->CONFIG_SECURITY_APPARMOR
45035 ++ || skel->kconfig->CONFIG_SECURITY_SELINUX
45036 ++ || skel->kconfig->CONFIG_SECURITY_SMACK))
45037 ++ /* AF_UNIX is prohibited. */
45038 ++ ASSERT_LT(fd, 0, "socket(AF_UNIX)");
45039 + close(fd);
45040 +
45041 + /* AF_INET6 gets default policy (sk_priority). */
45042 +@@ -233,11 +235,18 @@ static void test_lsm_cgroup_functional(void)
45043 +
45044 + /* AF_INET6+SOCK_STREAM
45045 + * AF_PACKET+SOCK_RAW
45046 ++ * AF_UNIX+SOCK_RAW if already have non-bpf lsms installed
45047 + * listen_fd
45048 + * client_fd
45049 + * accepted_fd
45050 + */
45051 +- ASSERT_EQ(skel->bss->called_socket_post_create2, 5, "called_create2");
45052 ++ if (skel->kconfig->CONFIG_SECURITY_APPARMOR
45053 ++ || skel->kconfig->CONFIG_SECURITY_SELINUX
45054 ++ || skel->kconfig->CONFIG_SECURITY_SMACK)
45055 ++ /* AF_UNIX+SOCK_RAW if already have non-bpf lsms installed */
45056 ++ ASSERT_EQ(skel->bss->called_socket_post_create2, 6, "called_create2");
45057 ++ else
45058 ++ ASSERT_EQ(skel->bss->called_socket_post_create2, 5, "called_create2");
45059 +
45060 + /* start_server
45061 + * bind(ETH_P_ALL)
45062 +diff --git a/tools/testing/selftests/bpf/prog_tests/map_kptr.c b/tools/testing/selftests/bpf/prog_tests/map_kptr.c
45063 +index fdcea7a61491e..0d66b15242089 100644
45064 +--- a/tools/testing/selftests/bpf/prog_tests/map_kptr.c
45065 ++++ b/tools/testing/selftests/bpf/prog_tests/map_kptr.c
45066 +@@ -105,7 +105,7 @@ static void test_map_kptr_success(bool test_run)
45067 + ASSERT_OK(opts.retval, "test_map_kptr_ref2 retval");
45068 +
45069 + if (test_run)
45070 +- return;
45071 ++ goto exit;
45072 +
45073 + ret = bpf_map__update_elem(skel->maps.array_map,
45074 + &key, sizeof(key), buf, sizeof(buf), 0);
45075 +@@ -132,6 +132,7 @@ static void test_map_kptr_success(bool test_run)
45076 + ret = bpf_map__delete_elem(skel->maps.lru_hash_map, &key, sizeof(key), 0);
45077 + ASSERT_OK(ret, "lru_hash_map delete");
45078 +
45079 ++exit:
45080 + map_kptr__destroy(skel);
45081 + }
45082 +
45083 +diff --git a/tools/testing/selftests/bpf/prog_tests/tracing_struct.c b/tools/testing/selftests/bpf/prog_tests/tracing_struct.c
45084 +new file mode 100644
45085 +index 0000000000000..48dc9472e160a
45086 +--- /dev/null
45087 ++++ b/tools/testing/selftests/bpf/prog_tests/tracing_struct.c
45088 +@@ -0,0 +1,64 @@
45089 ++// SPDX-License-Identifier: GPL-2.0
45090 ++/* Copyright (c) 2022 Meta Platforms, Inc. and affiliates. */
45091 ++
45092 ++#include <test_progs.h>
45093 ++#include "tracing_struct.skel.h"
45094 ++
45095 ++static void test_fentry(void)
45096 ++{
45097 ++ struct tracing_struct *skel;
45098 ++ int err;
45099 ++
45100 ++ skel = tracing_struct__open_and_load();
45101 ++ if (!ASSERT_OK_PTR(skel, "tracing_struct__open_and_load"))
45102 ++ return;
45103 ++
45104 ++ err = tracing_struct__attach(skel);
45105 ++ if (!ASSERT_OK(err, "tracing_struct__attach"))
45106 ++ goto destroy_skel;
45107 ++
45108 ++ ASSERT_OK(trigger_module_test_read(256), "trigger_read");
45109 ++
45110 ++ ASSERT_EQ(skel->bss->t1_a_a, 2, "t1:a.a");
45111 ++ ASSERT_EQ(skel->bss->t1_a_b, 3, "t1:a.b");
45112 ++ ASSERT_EQ(skel->bss->t1_b, 1, "t1:b");
45113 ++ ASSERT_EQ(skel->bss->t1_c, 4, "t1:c");
45114 ++
45115 ++ ASSERT_EQ(skel->bss->t1_nregs, 4, "t1 nregs");
45116 ++ ASSERT_EQ(skel->bss->t1_reg0, 2, "t1 reg0");
45117 ++ ASSERT_EQ(skel->bss->t1_reg1, 3, "t1 reg1");
45118 ++ ASSERT_EQ(skel->bss->t1_reg2, 1, "t1 reg2");
45119 ++ ASSERT_EQ(skel->bss->t1_reg3, 4, "t1 reg3");
45120 ++ ASSERT_EQ(skel->bss->t1_ret, 10, "t1 ret");
45121 ++
45122 ++ ASSERT_EQ(skel->bss->t2_a, 1, "t2:a");
45123 ++ ASSERT_EQ(skel->bss->t2_b_a, 2, "t2:b.a");
45124 ++ ASSERT_EQ(skel->bss->t2_b_b, 3, "t2:b.b");
45125 ++ ASSERT_EQ(skel->bss->t2_c, 4, "t2:c");
45126 ++ ASSERT_EQ(skel->bss->t2_ret, 10, "t2 ret");
45127 ++
45128 ++ ASSERT_EQ(skel->bss->t3_a, 1, "t3:a");
45129 ++ ASSERT_EQ(skel->bss->t3_b, 4, "t3:b");
45130 ++ ASSERT_EQ(skel->bss->t3_c_a, 2, "t3:c.a");
45131 ++ ASSERT_EQ(skel->bss->t3_c_b, 3, "t3:c.b");
45132 ++ ASSERT_EQ(skel->bss->t3_ret, 10, "t3 ret");
45133 ++
45134 ++ ASSERT_EQ(skel->bss->t4_a_a, 10, "t4:a.a");
45135 ++ ASSERT_EQ(skel->bss->t4_b, 1, "t4:b");
45136 ++ ASSERT_EQ(skel->bss->t4_c, 2, "t4:c");
45137 ++ ASSERT_EQ(skel->bss->t4_d, 3, "t4:d");
45138 ++ ASSERT_EQ(skel->bss->t4_e_a, 2, "t4:e.a");
45139 ++ ASSERT_EQ(skel->bss->t4_e_b, 3, "t4:e.b");
45140 ++ ASSERT_EQ(skel->bss->t4_ret, 21, "t4 ret");
45141 ++
45142 ++ ASSERT_EQ(skel->bss->t5_ret, 1, "t5 ret");
45143 ++
45144 ++ tracing_struct__detach(skel);
45145 ++destroy_skel:
45146 ++ tracing_struct__destroy(skel);
45147 ++}
45148 ++
45149 ++void test_tracing_struct(void)
45150 ++{
45151 ++ test_fentry();
45152 ++}
45153 +diff --git a/tools/testing/selftests/bpf/prog_tests/xdp_adjust_tail.c b/tools/testing/selftests/bpf/prog_tests/xdp_adjust_tail.c
45154 +index 21ceac24e1744..8f2613267be26 100644
45155 +--- a/tools/testing/selftests/bpf/prog_tests/xdp_adjust_tail.c
45156 ++++ b/tools/testing/selftests/bpf/prog_tests/xdp_adjust_tail.c
45157 +@@ -18,7 +18,7 @@ static void test_xdp_adjust_tail_shrink(void)
45158 + );
45159 +
45160 + err = bpf_prog_test_load(file, BPF_PROG_TYPE_XDP, &obj, &prog_fd);
45161 +- if (ASSERT_OK(err, "test_xdp_adjust_tail_shrink"))
45162 ++ if (!ASSERT_OK(err, "test_xdp_adjust_tail_shrink"))
45163 + return;
45164 +
45165 + err = bpf_prog_test_run_opts(prog_fd, &topts);
45166 +@@ -53,7 +53,7 @@ static void test_xdp_adjust_tail_grow(void)
45167 + );
45168 +
45169 + err = bpf_prog_test_load(file, BPF_PROG_TYPE_XDP, &obj, &prog_fd);
45170 +- if (ASSERT_OK(err, "test_xdp_adjust_tail_grow"))
45171 ++ if (!ASSERT_OK(err, "test_xdp_adjust_tail_grow"))
45172 + return;
45173 +
45174 + err = bpf_prog_test_run_opts(prog_fd, &topts);
45175 +@@ -63,6 +63,7 @@ static void test_xdp_adjust_tail_grow(void)
45176 + expect_sz = sizeof(pkt_v6) + 40; /* Test grow with 40 bytes */
45177 + topts.data_in = &pkt_v6;
45178 + topts.data_size_in = sizeof(pkt_v6);
45179 ++ topts.data_size_out = sizeof(buf);
45180 + err = bpf_prog_test_run_opts(prog_fd, &topts);
45181 + ASSERT_OK(err, "ipv6");
45182 + ASSERT_EQ(topts.retval, XDP_TX, "ipv6 retval");
45183 +@@ -89,7 +90,7 @@ static void test_xdp_adjust_tail_grow2(void)
45184 + );
45185 +
45186 + err = bpf_prog_test_load(file, BPF_PROG_TYPE_XDP, &obj, &prog_fd);
45187 +- if (ASSERT_OK(err, "test_xdp_adjust_tail_grow"))
45188 ++ if (!ASSERT_OK(err, "test_xdp_adjust_tail_grow"))
45189 + return;
45190 +
45191 + /* Test case-64 */
45192 +diff --git a/tools/testing/selftests/bpf/prog_tests/xdp_do_redirect.c b/tools/testing/selftests/bpf/prog_tests/xdp_do_redirect.c
45193 +index a50971c6cf4a5..9ac6f6a268db2 100644
45194 +--- a/tools/testing/selftests/bpf/prog_tests/xdp_do_redirect.c
45195 ++++ b/tools/testing/selftests/bpf/prog_tests/xdp_do_redirect.c
45196 +@@ -85,7 +85,7 @@ static void test_max_pkt_size(int fd)
45197 + }
45198 +
45199 + #define NUM_PKTS 10000
45200 +-void test_xdp_do_redirect(void)
45201 ++void serial_test_xdp_do_redirect(void)
45202 + {
45203 + int err, xdp_prog_fd, tc_prog_fd, ifindex_src, ifindex_dst;
45204 + char data[sizeof(pkt_udp) + sizeof(__u32)];
45205 +diff --git a/tools/testing/selftests/bpf/prog_tests/xdp_synproxy.c b/tools/testing/selftests/bpf/prog_tests/xdp_synproxy.c
45206 +index 874a846e298ca..b49d14580e516 100644
45207 +--- a/tools/testing/selftests/bpf/prog_tests/xdp_synproxy.c
45208 ++++ b/tools/testing/selftests/bpf/prog_tests/xdp_synproxy.c
45209 +@@ -174,7 +174,7 @@ out:
45210 + system("ip netns del synproxy");
45211 + }
45212 +
45213 +-void test_xdp_synproxy(void)
45214 ++void serial_test_xdp_synproxy(void)
45215 + {
45216 + if (test__start_subtest("xdp"))
45217 + test_synproxy(true);
45218 +diff --git a/tools/testing/selftests/bpf/progs/bpf_iter_ksym.c b/tools/testing/selftests/bpf/progs/bpf_iter_ksym.c
45219 +index 285c008cbf9c2..9ba14c37bbcc9 100644
45220 +--- a/tools/testing/selftests/bpf/progs/bpf_iter_ksym.c
45221 ++++ b/tools/testing/selftests/bpf/progs/bpf_iter_ksym.c
45222 +@@ -7,14 +7,14 @@ char _license[] SEC("license") = "GPL";
45223 +
45224 + unsigned long last_sym_value = 0;
45225 +
45226 +-static inline char tolower(char c)
45227 ++static inline char to_lower(char c)
45228 + {
45229 + if (c >= 'A' && c <= 'Z')
45230 + c += ('a' - 'A');
45231 + return c;
45232 + }
45233 +
45234 +-static inline char toupper(char c)
45235 ++static inline char to_upper(char c)
45236 + {
45237 + if (c >= 'a' && c <= 'z')
45238 + c -= ('a' - 'A');
45239 +@@ -54,7 +54,7 @@ int dump_ksym(struct bpf_iter__ksym *ctx)
45240 + type = iter->type;
45241 +
45242 + if (iter->module_name[0]) {
45243 +- type = iter->exported ? toupper(type) : tolower(type);
45244 ++ type = iter->exported ? to_upper(type) : to_lower(type);
45245 + BPF_SEQ_PRINTF(seq, "0x%llx %c %s [ %s ] ",
45246 + value, type, iter->name, iter->module_name);
45247 + } else {
45248 +diff --git a/tools/testing/selftests/bpf/progs/empty_skb.c b/tools/testing/selftests/bpf/progs/empty_skb.c
45249 +new file mode 100644
45250 +index 0000000000000..4b0cd67532511
45251 +--- /dev/null
45252 ++++ b/tools/testing/selftests/bpf/progs/empty_skb.c
45253 +@@ -0,0 +1,37 @@
45254 ++// SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
45255 ++#include <linux/bpf.h>
45256 ++#include <bpf/bpf_helpers.h>
45257 ++#include <bpf/bpf_endian.h>
45258 ++
45259 ++char _license[] SEC("license") = "GPL";
45260 ++
45261 ++int ifindex;
45262 ++int ret;
45263 ++
45264 ++SEC("lwt_xmit")
45265 ++int redirect_ingress(struct __sk_buff *skb)
45266 ++{
45267 ++ ret = bpf_clone_redirect(skb, ifindex, BPF_F_INGRESS);
45268 ++ return 0;
45269 ++}
45270 ++
45271 ++SEC("lwt_xmit")
45272 ++int redirect_egress(struct __sk_buff *skb)
45273 ++{
45274 ++ ret = bpf_clone_redirect(skb, ifindex, 0);
45275 ++ return 0;
45276 ++}
45277 ++
45278 ++SEC("tc")
45279 ++int tc_redirect_ingress(struct __sk_buff *skb)
45280 ++{
45281 ++ ret = bpf_clone_redirect(skb, ifindex, BPF_F_INGRESS);
45282 ++ return 0;
45283 ++}
45284 ++
45285 ++SEC("tc")
45286 ++int tc_redirect_egress(struct __sk_buff *skb)
45287 ++{
45288 ++ ret = bpf_clone_redirect(skb, ifindex, 0);
45289 ++ return 0;
45290 ++}
45291 +diff --git a/tools/testing/selftests/bpf/progs/lsm_cgroup.c b/tools/testing/selftests/bpf/progs/lsm_cgroup.c
45292 +index 4f2d60b87b75d..02c11d16b692a 100644
45293 +--- a/tools/testing/selftests/bpf/progs/lsm_cgroup.c
45294 ++++ b/tools/testing/selftests/bpf/progs/lsm_cgroup.c
45295 +@@ -7,6 +7,10 @@
45296 +
45297 + char _license[] SEC("license") = "GPL";
45298 +
45299 ++extern bool CONFIG_SECURITY_SELINUX __kconfig __weak;
45300 ++extern bool CONFIG_SECURITY_SMACK __kconfig __weak;
45301 ++extern bool CONFIG_SECURITY_APPARMOR __kconfig __weak;
45302 ++
45303 + #ifndef AF_PACKET
45304 + #define AF_PACKET 17
45305 + #endif
45306 +@@ -140,6 +144,10 @@ SEC("lsm_cgroup/sk_alloc_security")
45307 + int BPF_PROG(socket_alloc, struct sock *sk, int family, gfp_t priority)
45308 + {
45309 + called_socket_alloc++;
45310 ++ /* if already have non-bpf lsms installed, EPERM will cause memory leak of non-bpf lsms */
45311 ++ if (CONFIG_SECURITY_SELINUX || CONFIG_SECURITY_SMACK || CONFIG_SECURITY_APPARMOR)
45312 ++ return 1;
45313 ++
45314 + if (family == AF_UNIX)
45315 + return 0; /* EPERM */
45316 +
45317 +diff --git a/tools/testing/selftests/bpf/progs/tracing_struct.c b/tools/testing/selftests/bpf/progs/tracing_struct.c
45318 +new file mode 100644
45319 +index 0000000000000..e718f0ebee7dd
45320 +--- /dev/null
45321 ++++ b/tools/testing/selftests/bpf/progs/tracing_struct.c
45322 +@@ -0,0 +1,120 @@
45323 ++// SPDX-License-Identifier: GPL-2.0
45324 ++/* Copyright (c) 2022 Meta Platforms, Inc. and affiliates. */
45325 ++
45326 ++#include <vmlinux.h>
45327 ++#include <bpf/bpf_tracing.h>
45328 ++#include <bpf/bpf_helpers.h>
45329 ++
45330 ++struct bpf_testmod_struct_arg_1 {
45331 ++ int a;
45332 ++};
45333 ++struct bpf_testmod_struct_arg_2 {
45334 ++ long a;
45335 ++ long b;
45336 ++};
45337 ++
45338 ++long t1_a_a, t1_a_b, t1_b, t1_c, t1_ret, t1_nregs;
45339 ++__u64 t1_reg0, t1_reg1, t1_reg2, t1_reg3;
45340 ++long t2_a, t2_b_a, t2_b_b, t2_c, t2_ret;
45341 ++long t3_a, t3_b, t3_c_a, t3_c_b, t3_ret;
45342 ++long t4_a_a, t4_b, t4_c, t4_d, t4_e_a, t4_e_b, t4_ret;
45343 ++long t5_ret;
45344 ++
45345 ++SEC("fentry/bpf_testmod_test_struct_arg_1")
45346 ++int BPF_PROG2(test_struct_arg_1, struct bpf_testmod_struct_arg_2, a, int, b, int, c)
45347 ++{
45348 ++ t1_a_a = a.a;
45349 ++ t1_a_b = a.b;
45350 ++ t1_b = b;
45351 ++ t1_c = c;
45352 ++ return 0;
45353 ++}
45354 ++
45355 ++SEC("fexit/bpf_testmod_test_struct_arg_1")
45356 ++int BPF_PROG2(test_struct_arg_2, struct bpf_testmod_struct_arg_2, a, int, b, int, c, int, ret)
45357 ++{
45358 ++ t1_nregs = bpf_get_func_arg_cnt(ctx);
45359 ++ /* a.a */
45360 ++ bpf_get_func_arg(ctx, 0, &t1_reg0);
45361 ++ /* a.b */
45362 ++ bpf_get_func_arg(ctx, 1, &t1_reg1);
45363 ++ /* b */
45364 ++ bpf_get_func_arg(ctx, 2, &t1_reg2);
45365 ++ t1_reg2 = (int)t1_reg2;
45366 ++ /* c */
45367 ++ bpf_get_func_arg(ctx, 3, &t1_reg3);
45368 ++ t1_reg3 = (int)t1_reg3;
45369 ++
45370 ++ t1_ret = ret;
45371 ++ return 0;
45372 ++}
45373 ++
45374 ++SEC("fentry/bpf_testmod_test_struct_arg_2")
45375 ++int BPF_PROG2(test_struct_arg_3, int, a, struct bpf_testmod_struct_arg_2, b, int, c)
45376 ++{
45377 ++ t2_a = a;
45378 ++ t2_b_a = b.a;
45379 ++ t2_b_b = b.b;
45380 ++ t2_c = c;
45381 ++ return 0;
45382 ++}
45383 ++
45384 ++SEC("fexit/bpf_testmod_test_struct_arg_2")
45385 ++int BPF_PROG2(test_struct_arg_4, int, a, struct bpf_testmod_struct_arg_2, b, int, c, int, ret)
45386 ++{
45387 ++ t2_ret = ret;
45388 ++ return 0;
45389 ++}
45390 ++
45391 ++SEC("fentry/bpf_testmod_test_struct_arg_3")
45392 ++int BPF_PROG2(test_struct_arg_5, int, a, int, b, struct bpf_testmod_struct_arg_2, c)
45393 ++{
45394 ++ t3_a = a;
45395 ++ t3_b = b;
45396 ++ t3_c_a = c.a;
45397 ++ t3_c_b = c.b;
45398 ++ return 0;
45399 ++}
45400 ++
45401 ++SEC("fexit/bpf_testmod_test_struct_arg_3")
45402 ++int BPF_PROG2(test_struct_arg_6, int, a, int, b, struct bpf_testmod_struct_arg_2, c, int, ret)
45403 ++{
45404 ++ t3_ret = ret;
45405 ++ return 0;
45406 ++}
45407 ++
45408 ++SEC("fentry/bpf_testmod_test_struct_arg_4")
45409 ++int BPF_PROG2(test_struct_arg_7, struct bpf_testmod_struct_arg_1, a, int, b,
45410 ++ int, c, int, d, struct bpf_testmod_struct_arg_2, e)
45411 ++{
45412 ++ t4_a_a = a.a;
45413 ++ t4_b = b;
45414 ++ t4_c = c;
45415 ++ t4_d = d;
45416 ++ t4_e_a = e.a;
45417 ++ t4_e_b = e.b;
45418 ++ return 0;
45419 ++}
45420 ++
45421 ++SEC("fexit/bpf_testmod_test_struct_arg_4")
45422 ++int BPF_PROG2(test_struct_arg_8, struct bpf_testmod_struct_arg_1, a, int, b,
45423 ++ int, c, int, d, struct bpf_testmod_struct_arg_2, e, int, ret)
45424 ++{
45425 ++ t4_ret = ret;
45426 ++ return 0;
45427 ++}
45428 ++
45429 ++SEC("fentry/bpf_testmod_test_struct_arg_5")
45430 ++int BPF_PROG2(test_struct_arg_9)
45431 ++{
45432 ++ return 0;
45433 ++}
45434 ++
45435 ++SEC("fexit/bpf_testmod_test_struct_arg_5")
45436 ++int BPF_PROG2(test_struct_arg_10, int, ret)
45437 ++{
45438 ++ t5_ret = ret;
45439 ++ return 0;
45440 ++}
45441 ++
45442 ++char _license[] SEC("license") = "GPL";
45443 +diff --git a/tools/testing/selftests/bpf/xdp_synproxy.c b/tools/testing/selftests/bpf/xdp_synproxy.c
45444 +index d874ddfb39c46..8432836f3be2d 100644
45445 +--- a/tools/testing/selftests/bpf/xdp_synproxy.c
45446 ++++ b/tools/testing/selftests/bpf/xdp_synproxy.c
45447 +@@ -104,7 +104,8 @@ static void parse_options(int argc, char *argv[], unsigned int *ifindex, __u32 *
45448 + { "tc", no_argument, NULL, 'c' },
45449 + { NULL, 0, NULL, 0 },
45450 + };
45451 +- unsigned long mss4, mss6, wscale, ttl;
45452 ++ unsigned long mss4, wscale, ttl;
45453 ++ unsigned long long mss6;
45454 + unsigned int tcpipopts_mask = 0;
45455 +
45456 + if (argc < 2)
45457 +@@ -286,7 +287,7 @@ static int syncookie_open_bpf_maps(__u32 prog_id, int *values_map_fd, int *ports
45458 +
45459 + prog_info = (struct bpf_prog_info) {
45460 + .nr_map_ids = 8,
45461 +- .map_ids = (__u64)map_ids,
45462 ++ .map_ids = (__u64)(unsigned long)map_ids,
45463 + };
45464 + info_len = sizeof(prog_info);
45465 +
45466 +diff --git a/tools/testing/selftests/cgroup/cgroup_util.c b/tools/testing/selftests/cgroup/cgroup_util.c
45467 +index 4c52cc6f2f9cc..e8bbbdb77e0d5 100644
45468 +--- a/tools/testing/selftests/cgroup/cgroup_util.c
45469 ++++ b/tools/testing/selftests/cgroup/cgroup_util.c
45470 +@@ -555,6 +555,7 @@ int proc_mount_contains(const char *option)
45471 + ssize_t proc_read_text(int pid, bool thread, const char *item, char *buf, size_t size)
45472 + {
45473 + char path[PATH_MAX];
45474 ++ ssize_t ret;
45475 +
45476 + if (!pid)
45477 + snprintf(path, sizeof(path), "/proc/%s/%s",
45478 +@@ -562,8 +563,8 @@ ssize_t proc_read_text(int pid, bool thread, const char *item, char *buf, size_t
45479 + else
45480 + snprintf(path, sizeof(path), "/proc/%d/%s", pid, item);
45481 +
45482 +- size = read_text(path, buf, size);
45483 +- return size < 0 ? -1 : size;
45484 ++ ret = read_text(path, buf, size);
45485 ++ return ret < 0 ? -1 : ret;
45486 + }
45487 +
45488 + int proc_read_strstr(int pid, bool thread, const char *item, const char *needle)
45489 +diff --git a/tools/testing/selftests/drivers/net/netdevsim/devlink.sh b/tools/testing/selftests/drivers/net/netdevsim/devlink.sh
45490 +index 9de1d123f4f5d..a08c02abde121 100755
45491 +--- a/tools/testing/selftests/drivers/net/netdevsim/devlink.sh
45492 ++++ b/tools/testing/selftests/drivers/net/netdevsim/devlink.sh
45493 +@@ -496,8 +496,8 @@ dummy_reporter_test()
45494 +
45495 + check_reporter_info dummy healthy 3 3 10 true
45496 +
45497 +- echo 8192> $DEBUGFS_DIR/health/binary_len
45498 +- check_fail $? "Failed set dummy reporter binary len to 8192"
45499 ++ echo 8192 > $DEBUGFS_DIR/health/binary_len
45500 ++ check_err $? "Failed set dummy reporter binary len to 8192"
45501 +
45502 + local dump=$(devlink health dump show $DL_HANDLE reporter dummy -j)
45503 + check_err $? "Failed show dump of dummy reporter"
45504 +diff --git a/tools/testing/selftests/efivarfs/efivarfs.sh b/tools/testing/selftests/efivarfs/efivarfs.sh
45505 +index a90f394f9aa90..d374878cc0ba9 100755
45506 +--- a/tools/testing/selftests/efivarfs/efivarfs.sh
45507 ++++ b/tools/testing/selftests/efivarfs/efivarfs.sh
45508 +@@ -87,6 +87,11 @@ test_create_read()
45509 + {
45510 + local file=$efivarfs_mount/$FUNCNAME-$test_guid
45511 + ./create-read $file
45512 ++ if [ $? -ne 0 ]; then
45513 ++ echo "create and read $file failed"
45514 ++ file_cleanup $file
45515 ++ exit 1
45516 ++ fi
45517 + file_cleanup $file
45518 + }
45519 +
45520 +diff --git a/tools/testing/selftests/ftrace/test.d/ftrace/func_event_triggers.tc b/tools/testing/selftests/ftrace/test.d/ftrace/func_event_triggers.tc
45521 +index 3145b0f1835c3..27a68bbe778be 100644
45522 +--- a/tools/testing/selftests/ftrace/test.d/ftrace/func_event_triggers.tc
45523 ++++ b/tools/testing/selftests/ftrace/test.d/ftrace/func_event_triggers.tc
45524 +@@ -38,11 +38,18 @@ cnt_trace() {
45525 +
45526 + test_event_enabled() {
45527 + val=$1
45528 ++ check_times=10 # wait for 10 * SLEEP_TIME at most
45529 +
45530 +- e=`cat $EVENT_ENABLE`
45531 +- if [ "$e" != $val ]; then
45532 +- fail "Expected $val but found $e"
45533 +- fi
45534 ++ while [ $check_times -ne 0 ]; do
45535 ++ e=`cat $EVENT_ENABLE`
45536 ++ if [ "$e" == $val ]; then
45537 ++ return 0
45538 ++ fi
45539 ++ sleep $SLEEP_TIME
45540 ++ check_times=$((check_times - 1))
45541 ++ done
45542 ++
45543 ++ fail "Expected $val but found $e"
45544 + }
45545 +
45546 + run_enable_disable() {
45547 +diff --git a/tools/testing/selftests/netfilter/conntrack_icmp_related.sh b/tools/testing/selftests/netfilter/conntrack_icmp_related.sh
45548 +index b48e1833bc896..76645aaf2b58f 100755
45549 +--- a/tools/testing/selftests/netfilter/conntrack_icmp_related.sh
45550 ++++ b/tools/testing/selftests/netfilter/conntrack_icmp_related.sh
45551 +@@ -35,6 +35,8 @@ cleanup() {
45552 + for i in 1 2;do ip netns del nsrouter$i;done
45553 + }
45554 +
45555 ++trap cleanup EXIT
45556 ++
45557 + ipv4() {
45558 + echo -n 192.168.$1.2
45559 + }
45560 +@@ -146,11 +148,17 @@ ip netns exec nsclient1 nft -f - <<EOF
45561 + table inet filter {
45562 + counter unknown { }
45563 + counter related { }
45564 ++ counter redir4 { }
45565 ++ counter redir6 { }
45566 + chain input {
45567 + type filter hook input priority 0; policy accept;
45568 +- meta l4proto { icmp, icmpv6 } ct state established,untracked accept
45569 +
45570 ++ icmp type "redirect" ct state "related" counter name "redir4" accept
45571 ++ icmpv6 type "nd-redirect" ct state "related" counter name "redir6" accept
45572 ++
45573 ++ meta l4proto { icmp, icmpv6 } ct state established,untracked accept
45574 + meta l4proto { icmp, icmpv6 } ct state "related" counter name "related" accept
45575 ++
45576 + counter name "unknown" drop
45577 + }
45578 + }
45579 +@@ -279,5 +287,29 @@ else
45580 + echo "ERROR: icmp error RELATED state test has failed"
45581 + fi
45582 +
45583 +-cleanup
45584 ++# add 'bad' route, expect icmp REDIRECT to be generated
45585 ++ip netns exec nsclient1 ip route add 192.168.1.42 via 192.168.1.1
45586 ++ip netns exec nsclient1 ip route add dead:1::42 via dead:1::1
45587 ++
45588 ++ip netns exec "nsclient1" ping -q -c 2 192.168.1.42 > /dev/null
45589 ++
45590 ++expect="packets 1 bytes 112"
45591 ++check_counter nsclient1 "redir4" "$expect"
45592 ++if [ $? -ne 0 ];then
45593 ++ ret=1
45594 ++fi
45595 ++
45596 ++ip netns exec "nsclient1" ping -c 1 dead:1::42 > /dev/null
45597 ++expect="packets 1 bytes 192"
45598 ++check_counter nsclient1 "redir6" "$expect"
45599 ++if [ $? -ne 0 ];then
45600 ++ ret=1
45601 ++fi
45602 ++
45603 ++if [ $ret -eq 0 ];then
45604 ++ echo "PASS: icmp redirects had RELATED state"
45605 ++else
45606 ++ echo "ERROR: icmp redirect RELATED state test has failed"
45607 ++fi
45608 ++
45609 + exit $ret
45610 +diff --git a/tools/testing/selftests/powerpc/dscr/dscr_sysfs_test.c b/tools/testing/selftests/powerpc/dscr/dscr_sysfs_test.c
45611 +index fbbdffdb2e5d2..f20d1c166d1e4 100644
45612 +--- a/tools/testing/selftests/powerpc/dscr/dscr_sysfs_test.c
45613 ++++ b/tools/testing/selftests/powerpc/dscr/dscr_sysfs_test.c
45614 +@@ -24,6 +24,7 @@ static int check_cpu_dscr_default(char *file, unsigned long val)
45615 + rc = read(fd, buf, sizeof(buf));
45616 + if (rc == -1) {
45617 + perror("read() failed");
45618 ++ close(fd);
45619 + return 1;
45620 + }
45621 + close(fd);
45622 +@@ -65,8 +66,10 @@ static int check_all_cpu_dscr_defaults(unsigned long val)
45623 + if (access(file, F_OK))
45624 + continue;
45625 +
45626 +- if (check_cpu_dscr_default(file, val))
45627 ++ if (check_cpu_dscr_default(file, val)) {
45628 ++ closedir(sysfs);
45629 + return 1;
45630 ++ }
45631 + }
45632 + closedir(sysfs);
45633 + return 0;
45634 +diff --git a/tools/testing/selftests/proc/proc-uptime-002.c b/tools/testing/selftests/proc/proc-uptime-002.c
45635 +index e7ceabed7f51f..7d0aa22bdc12b 100644
45636 +--- a/tools/testing/selftests/proc/proc-uptime-002.c
45637 ++++ b/tools/testing/selftests/proc/proc-uptime-002.c
45638 +@@ -17,6 +17,7 @@
45639 + // while shifting across CPUs.
45640 + #undef NDEBUG
45641 + #include <assert.h>
45642 ++#include <errno.h>
45643 + #include <unistd.h>
45644 + #include <sys/syscall.h>
45645 + #include <stdlib.h>
45646 +@@ -54,7 +55,7 @@ int main(void)
45647 + len += sizeof(unsigned long);
45648 + free(m);
45649 + m = malloc(len);
45650 +- } while (sys_sched_getaffinity(0, len, m) == -EINVAL);
45651 ++ } while (sys_sched_getaffinity(0, len, m) == -1 && errno == EINVAL);
45652 +
45653 + fd = open("/proc/uptime", O_RDONLY);
45654 + assert(fd >= 0);